Java Code Examples for android.view.KeyEvent

The following examples show how to use android.view.KeyEvent. These examples are extracted from open source projects.
Example 1
Project: AndroidAnimationExercise   File: SuperTools.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 获取导航栏高度
 *
 * @param context
 * @return
 */
public static int getNavigationBarHeight(Context context) {

    boolean hasMenuKey = ViewConfiguration.get(context).hasPermanentMenuKey();
    boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);
    if (!hasMenuKey && !hasBackKey) {
        //没有物理按钮(虚拟导航栏)
        print("没有物理按钮(虚拟导航栏)");
        Resources resources = context.getResources();
        int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
        //获取NavigationBar的高度
        int height = resources.getDimensionPixelSize(resourceId);
        return height;
    } else {
        print("有物理导航栏,小米非全面屏");
        //有物理导航栏,小米非全面屏
        return 0;
    }
}
 
Example 2
Project: mobile-manager-tool   File: QGallery.java    License: MIT License 6 votes vote down vote up
@Override
	public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
//		int position = MyGallery.this.getSelectedItemPosition();
//		int minV = ViewConfiguration.get(context).getScaledMinimumFlingVelocity();	
//         
//		if(velocityX > minV){			
//			if(position > 0)
//				MyGallery.this.setSelection(position-1);
//		}else if(velocityX < -minV){
//			if(position < MyGallery.this.getCount()-1)
//				MyGallery.this.setSelection(position+1);
//		}
		if (e2.getX() > e1.getX()) {
			// 往左边滑动
			super.onKeyDown(KeyEvent.KEYCODE_DPAD_LEFT, null);
		} else {
			// 往右边滑动
			super.onKeyDown(KeyEvent.KEYCODE_DPAD_RIGHT, null);
		}
		return false;
	}
 
Example 3
Project: cloud-cup-android   File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Firebase.setAndroidContext(this);
    setContentView(R.layout.activity_main);

    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(Plus.API)
            .addScope(Plus.SCOPE_PLUS_LOGIN)
            .build();

    firebase = new Firebase(Consts.FIREBASE_URL);
    username = (TextView) findViewById(R.id.username);
    userImage = (ImageView) findViewById(R.id.user_image);
    code = (EditText) findViewById(R.id.code);
    code.setOnEditorActionListener(new OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            join();
            return true;
        }
    });
    code.requestFocus();
}
 
Example 4
Project: Camera2   File: CaptureModule.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
    switch (keyCode)
    {
        case KeyEvent.KEYCODE_CAMERA:
        case KeyEvent.KEYCODE_DPAD_CENTER:
            if (mUI.isCountingDown())
            {
                cancelCountDown();
            } else if (event.getRepeatCount() == 0)
            {
                onShutterButtonClick();
            }
            return true;
        case KeyEvent.KEYCODE_VOLUME_UP:
        case KeyEvent.KEYCODE_VOLUME_DOWN:
            // Prevent default.
            return true;
    }
    return false;
}
 
Example 5
Project: youqu_master   File: MaterialIntroActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    switch (keyCode) {
        case KeyEvent.KEYCODE_DPAD_CENTER:
            if (messageButtonBehaviours.get(viewPager.getCurrentItem()) != null) {
                messageButton.performClick();
            }
            break;
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            int position = viewPager.getCurrentItem();
            if (adapter.isLastSlide(position) && adapter.getItem(position).canMoveFurther()) {
                performFinish();
            } else if (adapter.shouldLockSlide(position)) {
                errorOccurred(adapter.getItem(position));
            } else {
                viewPager.moveToNextPage();
            }
            break;
        case KeyEvent.KEYCODE_DPAD_LEFT:
            moveBack();
            break;
        default:
            return super.onKeyDown(keyCode, event);
    }
    return super.onKeyDown(keyCode, event);
}
 
Example 6
Project: recent-images   File: TwoWayAbsListView.java    License: MIT License 6 votes vote down vote up
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
	if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_ENTER) {
		if (!isEnabled()) {
			return true;
		}
		if (isClickable() && isPressed() &&
				mSelectedPosition >= 0 && mAdapter != null &&
				mSelectedPosition < mAdapter.getCount()) {

			final View view = getChildAt(mSelectedPosition - mFirstPosition);
			if (view != null) {
				performItemClick(view, mSelectedPosition, mSelectedRowId);
				view.setPressed(false);
			}
			setPressed(false);
			return true;
		}
	}
	return super.onKeyUp(keyCode, event);
}
 
Example 7
Project: AndroidImageSlider   File: ViewPagerEx.java    License: MIT License 6 votes vote down vote up
/**
 * You can call this function yourself to have the scroll view perform
 * scrolling from a key event, just as if the event had been dispatched to
 * it by the view hierarchy.
 *
 * @param event The key event to execute.
 * @return Return true if the event was handled, else false.
 */
public boolean executeKeyEvent(KeyEvent event) {
    boolean handled = false;
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        switch (event.getKeyCode()) {
            case KeyEvent.KEYCODE_DPAD_LEFT:
                handled = arrowScroll(FOCUS_LEFT);
                break;
            case KeyEvent.KEYCODE_DPAD_RIGHT:
                handled = arrowScroll(FOCUS_RIGHT);
                break;
            case KeyEvent.KEYCODE_TAB:
                if (Build.VERSION.SDK_INT >= 11) {
                    // The focus finder had a bug handling FOCUS_FORWARD and FOCUS_BACKWARD
                    // before Android 3.0. Ignore the tab key on those devices.
                    if (KeyEventCompat.hasNoModifiers(event)) {
                        handled = arrowScroll(FOCUS_FORWARD);
                    } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_SHIFT_ON)) {
                        handled = arrowScroll(FOCUS_BACKWARD);
                    }
                }
                break;
        }
    }
    return handled;
}
 
Example 8
Project: android-recipes-app   File: TransportMediator.java    License: Apache License 2.0 6 votes vote down vote up
static boolean isMediaKey(int keyCode) {
    switch (keyCode) {
        case KEYCODE_MEDIA_PLAY:
        case KEYCODE_MEDIA_PAUSE:
        case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
        case KeyEvent.KEYCODE_MUTE:
        case KeyEvent.KEYCODE_HEADSETHOOK:
        case KeyEvent.KEYCODE_MEDIA_STOP:
        case KeyEvent.KEYCODE_MEDIA_NEXT:
        case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
        case KeyEvent.KEYCODE_MEDIA_REWIND:
        case KEYCODE_MEDIA_RECORD:
        case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: {
            return true;
        }
    }
    return false;
}
 
Example 9
Project: android_9.0.0_r45   File: InputMethodService.java    License: Apache License 2.0 6 votes vote down vote up
void reportExtractedMovement(int keyCode, int count) {
    int dx = 0, dy = 0;
    switch (keyCode) {
        case KeyEvent.KEYCODE_DPAD_LEFT:
            dx = -count;
            break;
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            dx = count;
            break;
        case KeyEvent.KEYCODE_DPAD_UP:
            dy = -count;
            break;
        case KeyEvent.KEYCODE_DPAD_DOWN:
            dy = count;
            break;
    }
    onExtractedCursorMovement(dx, dy);
}
 
Example 10
Project: Upchain-wallet   File: MainActivity.java    License: GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_DOWN
            && event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
        if (System.currentTimeMillis() - currentBackPressedTime > BACK_PRESSED_INTERVAL) {
            currentBackPressedTime = System.currentTimeMillis();
            ToastUtils.showToast(getString(R.string.exit_tips));
            return true;
        } else {
            finish(); // 退出
        }
    } else if (event.getKeyCode() == KeyEvent.KEYCODE_MENU) {
        return true;
    }
    return super.dispatchKeyEvent(event);
}
 
Example 11
Project: android-test   File: DelegatingEditText.java    License: Apache License 2.0 6 votes vote down vote up
public DelegatingEditText(Context context, AttributeSet attrs) {
  super(context, attrs);
  setOrientation(VERTICAL);
  mContext = context;
  LayoutInflater inflater = LayoutInflater.from(context);
  inflater.inflate(R.layout.delegating_edit_text, this, /* attachToRoot */ true);
  messageView = (TextView) findViewById(R.id.edit_text_message);
  delegateEditText = (EditText) findViewById(R.id.delegate_edit_text);
  delegateEditText.setOnEditorActionListener(new OnEditorActionListener() {
    @Override
    public boolean onEditorAction(TextView v, int actionCode, KeyEvent event) {
      messageView.setText("typed: " + delegateEditText.getText());
      messageView.setVisibility(View.VISIBLE);
      InputMethodManager imm =
          (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
      imm.hideSoftInputFromWindow(delegateEditText.getWindowToken(), 0);
      return true;
    }
  });
}
 
Example 12
Project: A-week-to-develop-android-app-plan   File: SignUpActivity.java    License: Apache License 2.0 6 votes vote down vote up
private void initViews() {

        getVerifiCodeButton = getView(R.id.btn_send_verifi_code);
        getVerifiCodeButton.setOnClickListener(this);
        phoneEdit = getView(R.id.et_phone);
        phoneEdit.setImeOptions(EditorInfo.IME_ACTION_NEXT);// 下一步
        verifyCodeEdit = getView(R.id.et_verifiCode);
        verifyCodeEdit.setImeOptions(EditorInfo.IME_ACTION_NEXT);// 下一步
        passwordEdit = getView(R.id.et_password);
        passwordEdit.setImeOptions(EditorInfo.IME_ACTION_DONE);
        passwordEdit.setImeOptions(EditorInfo.IME_ACTION_GO);
        passwordEdit.setOnEditorActionListener(new OnEditorActionListener() {

            @Override
            public boolean onEditorAction(TextView v, int actionId,
                                          KeyEvent event) {
                // 点击虚拟键盘的done
                if (actionId == EditorInfo.IME_ACTION_DONE
                        || actionId == EditorInfo.IME_ACTION_GO) {
                    commit();
                }
                return false;
            }
        });
    }
 
Example 13
Project: PainlessMusicPlayer   File: PlaybackAndroidService.java    License: Apache License 2.0 5 votes vote down vote up
private void onActionMediaButton(@NonNull final Intent intent) {
    final KeyEvent keyEvent = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
    if (keyEvent != null && keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
        switch (keyEvent.getKeyCode()) {
            case KeyEvent.KEYCODE_MEDIA_PLAY:
                onActionPlayPause();
                break;

            case KeyEvent.KEYCODE_MEDIA_PAUSE:
                onActionPause();
                break;

            case KeyEvent.KEYCODE_MEDIA_NEXT:
                onActionNext();
                break;

            case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
                onActionPrev();
                break;

            case KeyEvent.KEYCODE_MEDIA_STOP:
                onActionStop();
                break;

            case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
                onActionPlayPause();
                break;
        }
    }
}
 
Example 14
Project: ki4a   File: ForwardActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == android.R.id.home) {
        //Let's go back to main Activity
        dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK));
        dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_BACK));
        return true;
    }
    return super.onOptionsItemSelected(item);
}
 
Example 15
Project: DeviceConnect-Android   File: ThetaFeatureActivity.java    License: MIT License 5 votes vote down vote up
@SuppressLint("RestrictedApi")
@Override
public boolean dispatchKeyEvent(final KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        switch (event.getKeyCode()) {
            case KeyEvent.KEYCODE_BACK:
                finish();
                break;
            default:
                break;
        }
    }
    return super.dispatchKeyEvent(event);
}
 
Example 16
Project: zapp   File: FullscreenActivity.java    License: MIT License 5 votes vote down vote up
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
	switch (keyCode) {
		case KeyEvent.KEYCODE_ENTER:
		case KeyEvent.KEYCODE_DPAD_CENTER:
			toggle();
			return true;
	}

	return super.onKeyUp(keyCode, event);
}
 
Example 17
Project: NIM_Android_UIKit   File: InputPanel.java    License: MIT License 5 votes vote down vote up
/**
 * *************** IEmojiSelectedListener ***************
 */
@Override
public void onEmojiSelected(String key) {
    Editable mEditable = messageEditText.getText();
    if (key.equals("/DEL")) {
        messageEditText.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL));
    } else {
        int start = messageEditText.getSelectionStart();
        int end = messageEditText.getSelectionEnd();
        start = (start < 0 ? 0 : start);
        end = (start < 0 ? 0 : end);
        mEditable.replace(start, end, key);
    }
}
 
Example 18
Project: AndroidChromium   File: TabWebContentsDelegateAndroid.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Redispatches unhandled media keys. This allows bluetooth headphones with play/pause or
 * other buttons to function correctly.
 */
@TargetApi(19)
private void handleMediaKey(KeyEvent e) {
    if (Build.VERSION.SDK_INT < 19) return;
    switch (e.getKeyCode()) {
        case KeyEvent.KEYCODE_MUTE:
        case KeyEvent.KEYCODE_HEADSETHOOK:
        case KeyEvent.KEYCODE_MEDIA_PLAY:
        case KeyEvent.KEYCODE_MEDIA_PAUSE:
        case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
        case KeyEvent.KEYCODE_MEDIA_STOP:
        case KeyEvent.KEYCODE_MEDIA_NEXT:
        case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
        case KeyEvent.KEYCODE_MEDIA_REWIND:
        case KeyEvent.KEYCODE_MEDIA_RECORD:
        case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
        case KeyEvent.KEYCODE_MEDIA_CLOSE:
        case KeyEvent.KEYCODE_MEDIA_EJECT:
        case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
            AudioManager am = (AudioManager) mTab.getApplicationContext().getSystemService(
                    Context.AUDIO_SERVICE);
            am.dispatchMediaKeyEvent(e);
            break;
        default:
            break;
    }
}
 
Example 19
Project: zhizhihu   File: WebBrowserActivity.java    License: Apache License 2.0 5 votes vote down vote up
public boolean onKeyDown(int keyCoder, KeyEvent event) {
    if (mWebView.canGoBack() && keyCoder == KeyEvent.KEYCODE_BACK) {
        mWebView.goBack();   //goBack()表示返回webView的上一页面
        return true;
    }
    return super.onKeyDown(keyCoder, event);
}
 
Example 20
Project: AssistantBySDK   File: TimePickerDialog.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_UP) {
        return processKeyUp(keyCode);
    }
    return false;
}
 
Example 21
Project: Dashchan   File: DialogStack.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
	if (keyCode == KeyEvent.KEYCODE_BACK) {
		return keyBackHandler.onBackKey(event, !visibileViews.isEmpty());
	}
	return false;
}
 
Example 22
Project: mollyim-android   File: BaseActivity.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onKeyUp(int keyCode, @NonNull KeyEvent event) {
  if (keyCode == KeyEvent.KEYCODE_MENU && isMenuWorkaroundRequired()) {
    openOptionsMenu();
    return true;
  }
  return super.onKeyUp(keyCode, event);
}
 
Example 23
Project: WeCenterMobile-Android   File: MainActivity.java    License: GNU General Public License v2.0 5 votes vote down vote up
public boolean onKeyDown(int keyCode, KeyEvent event) {
	// TODO Auto-generated method stub
	if (keyCode == KeyEvent.KEYCODE_BACK) {
		ExitApp(); // ����˫���˳�����
	}
	return false;
}
 
Example 24
Project: XposedSmsCode   File: InputHelper.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static void sendKeyEvent(int inputSource, int keyCode, boolean longpress) throws Throwable {
    long now = SystemClock.uptimeMillis();
    injectKeyEvent(new KeyEvent(now, now, KeyEvent.ACTION_DOWN, keyCode, 0, 0,
            KeyCharacterMap.VIRTUAL_KEYBOARD, 0, 0, inputSource));
    if (longpress) {
        injectKeyEvent(new KeyEvent(now, now, KeyEvent.ACTION_DOWN, keyCode, 1, 0,
                KeyCharacterMap.VIRTUAL_KEYBOARD, 0, KeyEvent.FLAG_LONG_PRESS,
                inputSource));
    }
    injectKeyEvent(new KeyEvent(now, now, KeyEvent.ACTION_UP, keyCode, 0, 0,
            KeyCharacterMap.VIRTUAL_KEYBOARD, 0, 0, inputSource));
}
 
Example 25
Project: AndroidAPS   File: PlusMinusEditText.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
    boolean isKeyOfInterest = keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_ENTER;
    boolean isReleased = event.getAction() == KeyEvent.ACTION_UP;
    boolean isPressed = event.getAction() == KeyEvent.ACTION_DOWN
            && event.getAction() != KeyEvent.ACTION_MULTIPLE;

    if (isKeyOfInterest && isReleased) {
        stopUpdating();
    } else if (isKeyOfInterest && isPressed) {
        startUpdating(v == plusImage);
    }
    return false;
}
 
Example 26
Project: JianDan_OkHttpWithVolley   File: MainActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK
            && event.getAction() == KeyEvent.ACTION_DOWN) {
        if ((System.currentTimeMillis() - exitTime) > 2000) {
            ShowToast.Short("再按一次退出程序");
            exitTime = System.currentTimeMillis();
        } else {
            finish();
        }
        return true;
    }

    return super.onKeyDown(keyCode, event);
}
 
Example 27
Project: KeyboardView   File: EditView.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        hide(false);
        return true;
    }
    return super.onKeyDown(keyCode, event);
}
 
Example 28
Project: Camera2   File: PhotoModule.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
    switch (keyCode)
    {
        case KeyEvent.KEYCODE_VOLUME_UP:
        case KeyEvent.KEYCODE_VOLUME_DOWN:
        case KeyEvent.KEYCODE_FOCUS:
            if (/* TODO: mActivity.isInCameraApp() && */mFirstTimeInitialized && !mActivity.getCameraAppUI()
                    .isInIntentReview())
            {
                if (event.getRepeatCount() == 0)
                {
                    onShutterButtonFocus(true);
                }
                return true;
            }
            return false;
        case KeyEvent.KEYCODE_CAMERA:
            if (mFirstTimeInitialized && event.getRepeatCount() == 0)
            {
                onShutterButtonClick();
            }
            return true;
        case KeyEvent.KEYCODE_DPAD_CENTER:
            // If we get a dpad center event without any focused view, move
            // the focus to the shutter button and press it.
            if (mFirstTimeInitialized && event.getRepeatCount() == 0)
            {
                // Start auto-focus immediately to reduce shutter lag. After
                // the shutter button gets the focus, onShutterButtonFocus()
                // will be called again but it is fine.
                onShutterButtonFocus(true);
            }
            return true;
    }
    return false;
}
 
Example 29
Project: AndroidLinkup   File: ConfirmDialog.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * 处理返回键
 */
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        Button btn = (Button) findViewById(R.id.dialog_button_cancel);
        btn.performClick();
        return true;
    }
    return super.onKeyDown(keyCode, event);
}
 
Example 30
Project: Gizwits-SmartBuld_Android   File: GosUserLoginActivity.java    License: MIT License 5 votes vote down vote up
/**
 * 菜单、返回键响应
 */
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
	if (keyCode == KeyEvent.KEYCODE_BACK) {
		exitBy2Click(); // 调用双击退出函数
	}
	return false;
}
 
Example 31
Project: MissZzzReader   File: BaseActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK){
        back = true;//以便于判断是否按返回键触发界面劫持提示
    }
    return super.onKeyDown(keyCode, event);
}
 
Example 32
Project: LaunchEnr   File: AllAppsSearchBarController.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
    // Skip if it's not the right action
    if (actionId != EditorInfo.IME_ACTION_SEARCH) {
        return false;
    }

    // Skip if the query is empty
    String query = v.getText().toString();
    if (query.isEmpty()) {
        return false;
    }
    return mLauncher.startActivitySafely(v, createMarketSearchIntent(query), null);
}
 
Example 33
Project: BLEMeshChat   File: WelcomeFragment.java    License: Mozilla Public License 2.0 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View root = inflater.inflate(R.layout.fragment_welcome, container, false);
    ((EditText) root.findViewById(R.id.aliasEntry)).setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
            mCallback.onNameChosen(textView.getText().toString());
            return false;
        }
    });
    return root;
}
 
Example 34
Project: retrowatch   File: RetroWebViewActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
	if (keyCode == KeyEvent.KEYCODE_BACK) {
		if(mWebView.getWebViewInstance().canGoBack()) {
			mWebView.getWebViewInstance().goBack();
		} else {
			onBackPressed();
		}
		return true;
	}
	return false;
}
 
Example 35
Project: FoodOrdering   File: Activity_Login.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    //如果是返回键
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
        ActivityCollector.finishAll();
        return true;
    }
    return super.onKeyDown(keyCode, event);
}
 
Example 36
Project: crazyflie-android-client   File: MainActivity.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    // do not call super if key event comes from a gamepad, otherwise the buttons can quit the app
    if (isJoystickButton(event.getKeyCode()) && mController instanceof GamepadController) {
        mGamepadController.dealWithKeyEvent(event);
        // exception for OUYA controllers
        if (!Build.MODEL.toUpperCase(Locale.getDefault()).contains("OUYA")) {
            return true;
        }
    }
    return super.dispatchKeyEvent(event);
}
 
Example 37
Project: TelePlus-Android   File: NumberPicker.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    final int keyCode = event.getKeyCode();
    switch (keyCode) {
        case KeyEvent.KEYCODE_DPAD_CENTER:
        case KeyEvent.KEYCODE_ENTER:
            removeAllCallbacks();
            break;
        case KeyEvent.KEYCODE_DPAD_DOWN:
        case KeyEvent.KEYCODE_DPAD_UP:
            switch (event.getAction()) {
                case KeyEvent.ACTION_DOWN:
                    if (mWrapSelectorWheel || (keyCode == KeyEvent.KEYCODE_DPAD_DOWN)
                            ? getValue() < getMaxValue() : getValue() > getMinValue()) {
                        requestFocus();
                        mLastHandledDownDpadKeyCode = keyCode;
                        removeAllCallbacks();
                        if (mFlingScroller.isFinished()) {
                            changeValueByOne(keyCode == KeyEvent.KEYCODE_DPAD_DOWN);
                        }
                        return true;
                    }
                    break;
                case KeyEvent.ACTION_UP:
                    if (mLastHandledDownDpadKeyCode == keyCode) {
                        mLastHandledDownDpadKeyCode = -1;
                        return true;
                    }
                    break;
            }
    }
    return super.dispatchKeyEvent(event);
}
 
Example 38
Project: Yuan-WanAndroid   File: ArticleActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if(event.getKeyCode() == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0){
        Intent intent = new Intent();
        intent.putExtra(Constant.KEY_ARTICLE_COLLECT, isCollect);
        setResult(RESULT_OK, intent);
        finish();
    }
    return mAgentWeb.handleKeyEvent(keyCode, event) || super.onKeyDown(keyCode, event);
}
 
Example 39
Project: android_9.0.0_r45   File: HdmiCecLocalDevice.java    License: Apache License 2.0 5 votes vote down vote up
@ServiceThreadOnly
protected boolean handleUserControlPressed(HdmiCecMessage message) {
    assertRunOnServiceThread();
    mHandler.removeMessages(MSG_USER_CONTROL_RELEASE_TIMEOUT);
    if (mService.isPowerOnOrTransient() && isPowerOffOrToggleCommand(message)) {
        mService.standby();
        return true;
    } else if (mService.isPowerStandbyOrTransient() && isPowerOnOrToggleCommand(message)) {
        mService.wakeUp();
        return true;
    }

    final long downTime = SystemClock.uptimeMillis();
    final byte[] params = message.getParams();
    final int keycode = HdmiCecKeycode.cecKeycodeAndParamsToAndroidKey(params);
    int keyRepeatCount = 0;
    if (mLastKeycode != HdmiCecKeycode.UNSUPPORTED_KEYCODE) {
        if (keycode == mLastKeycode) {
            keyRepeatCount = mLastKeyRepeatCount + 1;
        } else {
            injectKeyEvent(downTime, KeyEvent.ACTION_UP, mLastKeycode, 0);
        }
    }
    mLastKeycode = keycode;
    mLastKeyRepeatCount = keyRepeatCount;

    if (keycode != HdmiCecKeycode.UNSUPPORTED_KEYCODE) {
        injectKeyEvent(downTime, KeyEvent.ACTION_DOWN, keycode, keyRepeatCount);
        mHandler.sendMessageDelayed(Message.obtain(mHandler, MSG_USER_CONTROL_RELEASE_TIMEOUT),
                FOLLOWER_SAFETY_TIMEOUT);
        return true;
    }
    return false;
}
 
Example 40
Project: Slide   File: MediaVideoView.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    boolean isKeyCodeSupported = keyCode != KeyEvent.KEYCODE_BACK
            && keyCode != KeyEvent.KEYCODE_VOLUME_UP
            && keyCode != KeyEvent.KEYCODE_VOLUME_DOWN
            && keyCode != KeyEvent.KEYCODE_VOLUME_MUTE
            && keyCode != KeyEvent.KEYCODE_MENU
            && keyCode != KeyEvent.KEYCODE_CALL
            && keyCode != KeyEvent.KEYCODE_ENDCALL;
    if (isPlaying() && isKeyCodeSupported) {
        if (keyCode == KeyEvent.KEYCODE_HEADSETHOOK
                || keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE) {
            if (isPlaying()) {
                pause();
                getVideoControls().show();
            } else {
                start();
                getVideoControls().hide();
            }
            return true;
        } else if (keyCode == KeyEvent.KEYCODE_MEDIA_PLAY) {
            if (!isPlaying()) {
                start();
                getVideoControls().hide();
            }
            return true;
        } else if (keyCode == KeyEvent.KEYCODE_MEDIA_STOP
                || keyCode == KeyEvent.KEYCODE_MEDIA_PAUSE) {
            if (isPlaying()) {
                pause();
                getVideoControls().show();
            }
            return true;
        } else {
            toggleMediaControlsVisiblity();
        }
    }

    return super.onKeyDown(keyCode, event);
}