Java Code Examples for android.view.KeyEvent#getKeyCode()
The following examples show how to use
android.view.KeyEvent#getKeyCode() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InputActivity.java From wearmouse with Apache License 2.0 | 6 votes |
@Override public boolean dispatchKeyEvent(KeyEvent event) { int keyCode = event.getKeyCode(); int action = event.getAction(); if (keyCode == KeyEvent.KEYCODE_STEM_1) { if (action == KeyEvent.ACTION_UP) { flipCard( currentMode == InputMode.MOUSE ? InputMode.TOUCHPAD : currentMode == InputMode.TOUCHPAD ? InputMode.KEYPAD : InputMode.MOUSE); } return true; } else if (keyCode == KeyEvent.KEYCODE_STEM_2) { if (action == KeyEvent.ACTION_UP) { Intent intent = keyboardController.getInputIntent(getPackageManager()); if (intent != null) { startActivityForResult(intent, INPUT_REQUEST_CODE); } } return true; } return super.dispatchKeyEvent(event); }
Example 2
Source File: FileManagerActivityBase.java From edslite with GNU General Public License v2.0 | 6 votes |
@Override public boolean dispatchKeyEvent(KeyEvent event) { Logger.debug(TAG + ": dispatchKeyEvent"); //Prevent selection clearing when back button is pressed while properties fragment is active if (event.getKeyCode() == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP) { if (!_isLargeScreenLayout && hasSelectedFiles()) { Fragment f = getFragmentManager().findFragmentByTag(FilePropertiesFragment.TAG); if (f != null) { hideSecondaryFragment(); return true; } } } return super.dispatchKeyEvent(event); }
Example 3
Source File: MediaControllerEx.java From SkyTube with GNU General Public License v3.0 | 6 votes |
@Override public boolean dispatchKeyEvent(KeyEvent event) { // if the user has pressed the BACK button (of the Navigation Bar), then ... if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) { if (event.getAction() == KeyEvent.ACTION_DOWN) { // Tell the Fragment to stop playback, and record the playing video's position if needed fragmentInterface.videoPlaybackStopped(); // ask the activity to finish ((Activity) getContext()).finish(); } // true means we handles the event return true; } return super.dispatchKeyEvent(event); }
Example 4
Source File: IRKitVirtualDeviceListActivity.java From DeviceConnect-Android with MIT License | 6 votes |
@Override public boolean dispatchKeyEvent(final KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN) { switch (event.getKeyCode()) { case KeyEvent.KEYCODE_BACK: FragmentManager fm = getFragmentManager(); int cnt = fm.getBackStackEntryCount(); if (cnt <= 1) { finish(); return false; } else { currentPage--; } break; default: break; } } return super.dispatchKeyEvent(event); }
Example 5
Source File: MediaController.java From NetEasyNews with GNU General Public License v3.0 | 6 votes |
@Override public boolean dispatchKeyEvent(KeyEvent event) { int keyCode = event.getKeyCode(); if (event.getRepeatCount() == 0 && (keyCode == KeyEvent.KEYCODE_HEADSETHOOK || keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE || keyCode == KeyEvent.KEYCODE_SPACE)) { doPauseResume(); show(sDefaultTimeout); if (mPauseButton != null) mPauseButton.requestFocus(); return true; } else if (keyCode == KeyEvent.KEYCODE_MEDIA_STOP) { if (mPlayer.isPlaying()) { mPlayer.pause(); updatePausePlay(); } return true; } else if (keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_MENU) { hide(); return true; } else { show(sDefaultTimeout); } return super.dispatchKeyEvent(event); }
Example 6
Source File: OrientedViewPager.java From FlippableStackView with Apache License 2.0 | 6 votes |
/** * 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 7
Source File: ViewPager.java From android-recipes-app with Apache License 2.0 | 6 votes |
/** * 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
Source File: PinViewBaseHelper.java From nono-android with GNU General Public License v3.0 | 6 votes |
/** * Keyboard back button */ @Override public boolean dispatchKeyEventPreIme(KeyEvent event) { if (mKeyboardMandatory) { if (getContext() != null) { InputMethodManager imm = (InputMethodManager) getContext() .getSystemService(Context.INPUT_METHOD_SERVICE); if (imm.isActive() && event.getKeyCode() == KeyEvent.KEYCODE_BACK) { setImeVisibility(true); return true; } } } return super.dispatchKeyEventPreIme(event); }
Example 9
Source File: FolderEditText.java From LB-Launcher with Apache License 2.0 | 5 votes |
@Override public boolean onKeyPreIme(int keyCode, KeyEvent event) { // Catch the back button on the soft keyboard so that we can just close the activity if (event.getKeyCode() == android.view.KeyEvent.KEYCODE_BACK) { mFolder.doneEditingFolderName(true); } return super.onKeyPreIme(keyCode, event); }
Example 10
Source File: ScrollViewer.java From AirFree-Client with GNU General Public License v3.0 | 5 votes |
/** * 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) { mTempRect.setEmpty(); if (!canScroll()) { if (isFocused()) { View currentFocused = findFocus(); if (currentFocused == this) currentFocused = null; View nextFocused = FocusFinder.getInstance().findNextFocus(this, currentFocused, View.FOCUS_DOWN); return nextFocused != null && nextFocused != this && nextFocused.requestFocus(View.FOCUS_DOWN); } return false; } boolean handled = false; if (event.getAction() == KeyEvent.ACTION_DOWN) { switch (event.getKeyCode()) { case KeyEvent.KEYCODE_DPAD_UP: if (!event.isAltPressed()) { handled = arrowScroll(View.FOCUS_UP, false); } else { handled = fullScroll(View.FOCUS_UP, false); } break; case KeyEvent.KEYCODE_DPAD_DOWN: if (!event.isAltPressed()) { handled = arrowScroll(View.FOCUS_DOWN, false); } else { handled = fullScroll(View.FOCUS_DOWN, false); } break; case KeyEvent.KEYCODE_DPAD_LEFT: if (!event.isAltPressed()) { handled = arrowScroll(View.FOCUS_LEFT, true); } else { handled = fullScroll(View.FOCUS_LEFT, true); } break; case KeyEvent.KEYCODE_DPAD_RIGHT: if (!event.isAltPressed()) { handled = arrowScroll(View.FOCUS_RIGHT, true); } else { handled = fullScroll(View.FOCUS_RIGHT, true); } break; } } return handled; }
Example 11
Source File: TangleExplorerSearchFragment.java From android-wallet-app with GNU General Public License v3.0 | 5 votes |
@Override public boolean onEditorAction(TextView view, int actionId, KeyEvent event) { if ((actionId == EditorInfo.IME_ACTION_DONE) || ((event.getKeyCode() == KeyEvent.KEYCODE_ENTER) && (event.getAction() == KeyEvent.ACTION_DOWN))) { searchTransactions(); return true; } return true; }
Example 12
Source File: HeadsetButtonReceiver.java From CSipSimple with GNU General Public License v3.0 | 5 votes |
@Override public void onReceive(Context context, Intent intent) { Log.d(THIS_FILE, "onReceive"); if(uaReceiver == null) { return; } // abortBroadcast(); // // Headset button has been pressed by user. Normally when // the UI is active this event will never be generated instead // a headset button press will be handled as a regular key // press event. // if (Intent.ACTION_MEDIA_BUTTON.equals(intent.getAction())) { KeyEvent event = (KeyEvent)intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT); Log.d(THIS_FILE, "Key : "+event.getKeyCode()); if (event != null && event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_HEADSETHOOK) { if (uaReceiver.handleHeadsetButton()) { // // After processing the event we will prevent other applications // from receiving the button press since we have handled it ourself // and do not want any media player to start playing for example. // /* * TODO : enable this test if api > 5 if (isOrderedBroadcast()) { */ abortBroadcast(); /* } */ } } } }
Example 13
Source File: KeyboardEditText.java From RoMote with Apache License 2.0 | 5 votes |
@Override public boolean onKeyPreIme(int keyCode, @NonNull KeyEvent event) { if (event.getKeyCode() == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP) { if (listener != null) listener.onStateChanged(this, false); } return super.onKeyPreIme(keyCode, event); }
Example 14
Source File: NumberPicker.java From iGap-Android with GNU Affero General Public License v3.0 | 5 votes |
@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 15
Source File: MediaSessionReceiver.java From Cheerleader with Apache License 2.0 | 5 votes |
@Override public void onReceive(Context context, Intent intent) { String intentAction = intent.getAction(); if (!Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) { // intent wasn't a MEDIA BUTTON event. return; } KeyEvent event = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT); int keycode = event.getKeyCode(); int action = event.getAction(); // Switch on keycode and fire action only on KeyDown event. switch (keycode) { case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: case KeyEvent.KEYCODE_HEADSETHOOK: if (action == KeyEvent.ACTION_DOWN) { sendAction(context, MediaSessionWrapper.ACTION_TOGGLE_PLAYBACK); } break; case KeyEvent.KEYCODE_MEDIA_NEXT: if (action == KeyEvent.ACTION_DOWN) { sendAction(context, MediaSessionWrapper.ACTION_NEXT_TRACK); } break; case KeyEvent.KEYCODE_MEDIA_PREVIOUS: if (action == KeyEvent.ACTION_DOWN) { sendAction(context, MediaSessionWrapper.ACTION_PREVIOUS_TRACK); } break; default: break; } }
Example 16
Source File: NumberPicker.java From ticdesign with Apache License 2.0 | 5 votes |
@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: if (!mHasSelectorWheel) { break; } 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 17
Source File: AudioStreamingReceiver.java From DMAudioStreamer with Apache License 2.0 | 4 votes |
@Override public void onReceive(Context context, Intent intent) { this.audioStreamingManager = AudioStreamingManager.getInstance(context); if(this.audioStreamingManager ==null){ return; } if (intent.getAction().equals(Intent.ACTION_MEDIA_BUTTON)) { if (intent.getExtras() == null) { return; } KeyEvent keyEvent = (KeyEvent) intent.getExtras().get(Intent.EXTRA_KEY_EVENT); if (keyEvent == null) { return; } if (keyEvent.getAction() != KeyEvent.ACTION_DOWN) return; switch (keyEvent.getKeyCode()) { case KeyEvent.KEYCODE_HEADSETHOOK: case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: if (this.audioStreamingManager .isPlaying()) { this.audioStreamingManager .onPause(); } else { this.audioStreamingManager .onPlay(this.audioStreamingManager .getCurrentAudio()); } break; case KeyEvent.KEYCODE_MEDIA_PLAY: this.audioStreamingManager .onPlay(this.audioStreamingManager .getCurrentAudio()); break; case KeyEvent.KEYCODE_MEDIA_PAUSE: this.audioStreamingManager .onPause(); break; case KeyEvent.KEYCODE_MEDIA_STOP: break; case KeyEvent.KEYCODE_MEDIA_NEXT: this.audioStreamingManager .onSkipToNext(); break; case KeyEvent.KEYCODE_MEDIA_PREVIOUS: this.audioStreamingManager .onSkipToPrevious(); break; } } else { this.audioStreamingManager = AudioStreamingManager.getInstance(context); if (intent.getAction().equals(AudioStreamingService.NOTIFY_PLAY)) { this.audioStreamingManager.onPlay(this.audioStreamingManager.getCurrentAudio()); } else if (intent.getAction().equals(AudioStreamingService.NOTIFY_PAUSE) || intent.getAction().equals(android.media.AudioManager.ACTION_AUDIO_BECOMING_NOISY)) { this.audioStreamingManager.onPause(); } else if (intent.getAction().equals(AudioStreamingService.NOTIFY_NEXT)) { this.audioStreamingManager.onSkipToNext(); } else if (intent.getAction().equals(AudioStreamingService.NOTIFY_CLOSE)) { this.audioStreamingManager.cleanupPlayer(context, true, true); } else if (intent.getAction().equals(AudioStreamingService.NOTIFY_PREVIOUS)) { this.audioStreamingManager.onSkipToPrevious(); } } }
Example 18
Source File: VolumeAccessibilityService.java From Noyze with Apache License 2.0 | 4 votes |
@Override protected boolean onKeyEvent(KeyEvent event) { if (null == event) return true; // WTF?? // Make sure we're not in the middle of a phone call. if (null != mVolumePanel && mVolumePanel.getCallState() != TelephonyManager.CALL_STATE_IDLE) return super.onKeyEvent(event); final int flags = event.getFlags(); final int code = event.getKeyCode(); final boolean system = ((flags & KeyEvent.FLAG_FROM_SYSTEM) == KeyEvent.FLAG_FROM_SYSTEM); // Specifically avoid software keys or "fake" hardware buttons. if (((flags & KeyEvent.FLAG_SOFT_KEYBOARD) == KeyEvent.FLAG_SOFT_KEYBOARD) || ((flags & KeyEvent.FLAG_VIRTUAL_HARD_KEY) == KeyEvent.FLAG_VIRTUAL_HARD_KEY)) { return super.onKeyEvent(event); } else { // Specifically avoid handling certain keys. We never want to interfere // with them or harm performance in any way. switch (code) { case KeyEvent.KEYCODE_BACK: case KeyEvent.KEYCODE_HOME: case KeyEvent.KEYCODE_MENU: case KeyEvent.KEYCODE_POWER: case KeyEvent.KEYCODE_SEARCH: return super.onKeyEvent(event); } } if (!system) return super.onKeyEvent(event); LOGI(TAG, "--onKeyEvent(code=" + event.getKeyCode() + ", action=" + event.getAction() + ", topPackage=" + mCurrentActivityPackage + ", disabledButtons=" + disabledButtons + ')'); // Check if we're supposed to disable Noyze for a Blacklisted app. if (blacklist.contains(mCurrentActivityPackage)) { if (null != mVolumePanel) mVolumePanel.setEnabled(false); return super.onKeyEvent(event); } else { // NOTE: we need a "safe" way to enable the volume panel that // takes into consideration its previous state. if (null != mVolumePanel) mVolumePanel.enable(); } // If we're told to disable one or more of the volume buttons, do so (returning true consumes the event). if (disabledButtons == code) return true; // NOTE: KeyEvent#KEYCODE_VOLUME_DOWN + KeyEvent#KEYCODE_VOLUME_UP == KeyEvent_KEYCODE_U final int upAndDown = (KeyEvent.KEYCODE_VOLUME_DOWN + KeyEvent.KEYCODE_VOLUME_UP); // 49 final int upSquared = KeyEvent.KEYCODE_VOLUME_UP * KeyEvent.KEYCODE_VOLUME_UP; // 576 if (disabledButtons == upAndDown && Utils.isVolumeKeyCode(upAndDown - code)) return true; if (disabledButtons == upSquared && mVolumePanel != null && mVolumePanel.isLocked()) return true; if (disabledButtons == upSquared && KEYGUARD.equals(mCurrentActivityPackage)) return true; // Check if the volume panel has been disabled, or shouldn't handle this event (e.g. "safe volume"). if (null != mVolumePanel && mVolumePanel.isEnabled()) { if (Utils.isVolumeKeyCode(code)) { Message.obtain(mHandler, MESSAGE_KEY_EVENT, event).sendToTarget(); // Run asynchronously return true; } } return super.onKeyEvent(event); }
Example 19
Source File: TabHost.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
@Override public boolean dispatchKeyEvent(KeyEvent event) { final boolean handled = super.dispatchKeyEvent(event); // unhandled key events change focus to tab indicator for embedded // activities when there is nothing that will take focus from default // focus searching if (!handled && (event.getAction() == KeyEvent.ACTION_DOWN) && (mCurrentView != null) && (mCurrentView.isRootNamespace()) && (mCurrentView.hasFocus())) { int keyCodeShouldChangeFocus = KeyEvent.KEYCODE_DPAD_UP; int directionShouldChangeFocus = View.FOCUS_UP; int soundEffect = SoundEffectConstants.NAVIGATION_UP; switch (getTabWidgetLocation()) { case TABWIDGET_LOCATION_LEFT: keyCodeShouldChangeFocus = KeyEvent.KEYCODE_DPAD_LEFT; directionShouldChangeFocus = View.FOCUS_LEFT; soundEffect = SoundEffectConstants.NAVIGATION_LEFT; break; case TABWIDGET_LOCATION_RIGHT: keyCodeShouldChangeFocus = KeyEvent.KEYCODE_DPAD_RIGHT; directionShouldChangeFocus = View.FOCUS_RIGHT; soundEffect = SoundEffectConstants.NAVIGATION_RIGHT; break; case TABWIDGET_LOCATION_BOTTOM: keyCodeShouldChangeFocus = KeyEvent.KEYCODE_DPAD_DOWN; directionShouldChangeFocus = View.FOCUS_DOWN; soundEffect = SoundEffectConstants.NAVIGATION_DOWN; break; case TABWIDGET_LOCATION_TOP: default: keyCodeShouldChangeFocus = KeyEvent.KEYCODE_DPAD_UP; directionShouldChangeFocus = View.FOCUS_UP; soundEffect = SoundEffectConstants.NAVIGATION_UP; break; } if (event.getKeyCode() == keyCodeShouldChangeFocus && mCurrentView.findFocus().focusSearch(directionShouldChangeFocus) == null) { mTabWidget.getChildTabViewAt(mCurrentTab).requestFocus(); playSoundEffect(soundEffect); return true; } } return handled; }
Example 20
Source File: MediaController.java From talk-android with MIT License | 4 votes |
@Override public boolean dispatchKeyEvent(KeyEvent event) { int keyCode = event.getKeyCode(); final boolean uniqueDown = event.getRepeatCount() == 0 && event.getAction() == KeyEvent.ACTION_DOWN; if (keyCode == KeyEvent.KEYCODE_HEADSETHOOK || keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE || keyCode == KeyEvent.KEYCODE_SPACE) { if (uniqueDown) { doPauseResume(); show(sDefaultTimeout); if (mTurnButton != null) { mTurnButton.requestFocus(); } } return true; } else if (keyCode == KeyEvent.KEYCODE_MEDIA_PLAY) { if (uniqueDown && !mPlayer.isPlaying()) { mPlayer.start(); updatePausePlay(); show(sDefaultTimeout); } return true; } else if (keyCode == KeyEvent.KEYCODE_MEDIA_STOP || keyCode == KeyEvent.KEYCODE_MEDIA_PAUSE) { if (uniqueDown && mPlayer.isPlaying()) { mPlayer.pause(); updatePausePlay(); show(sDefaultTimeout); } return true; } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN || keyCode == KeyEvent.KEYCODE_VOLUME_UP || keyCode == KeyEvent.KEYCODE_VOLUME_MUTE || keyCode == KeyEvent.KEYCODE_CAMERA) { // don't show the controls for volume adjustment return super.dispatchKeyEvent(event); } else if (keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_MENU) { if (uniqueDown) { hide(); } return true; } show(sDefaultTimeout); return super.dispatchKeyEvent(event); }