Java Code Examples for android.view.KeyEvent#getAction()
The following examples show how to use
android.view.KeyEvent#getAction() .
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: VerticalViewPager.java From DoubleViewPager 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 2
Source File: BookmarkSearchView.java From delion with Apache License 2.0 | 6 votes |
@Override public boolean dispatchKeyEvent(KeyEvent event) { // To intercept hardware key, a view must have focus. if (mDelegate == null) return super.dispatchKeyEvent(event); if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) { KeyEvent.DispatcherState state = getKeyDispatcherState(); if (state != null) { if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) { state.startTracking(event, this); return true; } else if (event.getAction() == KeyEvent.ACTION_UP && !event.isCanceled() && state.isTracking(event)) { onBackPressed(); return true; } } } return super.dispatchKeyEvent(event); }
Example 3
Source File: HoverView.java From hover with Apache License 2.0 | 6 votes |
@Override public boolean dispatchKeyEventPreIme(KeyEvent event) { // Intercept the hardware back button press if needed. When it's pressed, we'll collapse. if (mState.respondsToBackButton() && KeyEvent.KEYCODE_BACK == event.getKeyCode()) { KeyEvent.DispatcherState state = getKeyDispatcherState(); if (state != null) { if (KeyEvent.ACTION_DOWN == event.getAction()) { state.startTracking(event, this); return true; } else if (KeyEvent.ACTION_UP == event.getAction()) { onBackPressed(); return true; } } } return super.dispatchKeyEventPreIme(event); }
Example 4
Source File: MediaSessionService.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
private void handleVoiceKeyEventLocked(String packageName, int pid, int uid, boolean asSystemService, KeyEvent keyEvent, boolean needWakeLock) { int action = keyEvent.getAction(); boolean isLongPress = (keyEvent.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0; if (action == KeyEvent.ACTION_DOWN) { if (keyEvent.getRepeatCount() == 0) { mVoiceButtonDown = true; mVoiceButtonHandled = false; } else if (mVoiceButtonDown && !mVoiceButtonHandled && isLongPress) { mVoiceButtonHandled = true; startVoiceInput(needWakeLock); } } else if (action == KeyEvent.ACTION_UP) { if (mVoiceButtonDown) { mVoiceButtonDown = false; if (!mVoiceButtonHandled && !keyEvent.isCanceled()) { // Resend the down then send this event through KeyEvent downEvent = KeyEvent.changeAction(keyEvent, KeyEvent.ACTION_DOWN); dispatchMediaKeyEventLocked(packageName, pid, uid, asSystemService, downEvent, needWakeLock); dispatchMediaKeyEventLocked(packageName, pid, uid, asSystemService, keyEvent, needWakeLock); } } } }
Example 5
Source File: AllAppsContainerView.java From Trebuchet with GNU General Public License v3.0 | 6 votes |
@Override public boolean dispatchKeyEvent(KeyEvent event) { // Determine if the key event was actual text, if so, focus the search bar and then dispatch // the key normally so that it can process this key event if (mSearchBarController != null && !mSearchBarController.isSearchFieldFocused() && event.getAction() == KeyEvent.ACTION_DOWN) { final int unicodeChar = event.getUnicodeChar(); final boolean isKeyNotWhitespace = unicodeChar > 0 && !Character.isWhitespace(unicodeChar) && !Character.isSpaceChar(unicodeChar); if (isKeyNotWhitespace) { boolean gotKey = TextKeyListener.getInstance().onKeyDown(this, mSearchQueryBuilder, event.getKeyCode(), event); if (gotKey && mSearchQueryBuilder.length() > 0) { mSearchBarController.focusSearchField(); } } } return super.dispatchKeyEvent(event); }
Example 6
Source File: MenuPopupHelper.java From zhangshangwuda with Apache License 2.0 | 5 votes |
public boolean onKey(View v, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_MENU) { dismiss(); return true; } return false; }
Example 7
Source File: CardNumEditText.java From PaymentKit-Droid with Apache License 2.0 | 5 votes |
@Override public boolean sendKeyEvent(KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_DEL) { int curPos = getSelectionEnd(); mLastEvent = TextEvent.KEY_PRESS; if (mMaxCardLength == FieldHolder.NON_AMEX_CARD_LENGTH && (curPos == 5 || curPos == 10 || curPos == 15)) { CardNumEditText.this.setSelection(curPos - 1); return true; } else if(mMaxCardLength == FieldHolder.AMEX_CARD_LENGTH && (curPos == 5 || curPos == 12)) { CardNumEditText.this.setSelection(curPos - 1); return true; } } return super.sendKeyEvent(event); }
Example 8
Source File: EncryptSeedDialog.java From android-wallet-app with GNU General Public License v3.0 | 5 votes |
@OnEditorAction(R.id.password_confirm) public boolean onPasswordConfirmEditorAction(int actionId, KeyEvent event) { if ((actionId == EditorInfo.IME_ACTION_DONE) || ((event.getKeyCode() == KeyEvent.KEYCODE_ENTER) && (event.getAction() == KeyEvent.ACTION_DOWN))) { encryptSeed(); } return true; }
Example 9
Source File: SearchBookContentsActivity.java From weex with Apache License 2.0 | 5 votes |
@Override public boolean onKey(View view, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_DOWN) { launchSearch(); return true; } return false; }
Example 10
Source File: AbsBaseActivity.java From VinylMusicPlayer with GNU General Public License v3.0 | 5 votes |
@Override public boolean dispatchKeyEvent(@NonNull KeyEvent event) { if (event.getKeyCode() == KeyEvent.KEYCODE_MENU && event.getAction() == KeyEvent.ACTION_UP) { showOverflowMenu(); return true; } return super.dispatchKeyEvent(event); }
Example 11
Source File: BackButtonListenerEditText.java From revolution-irc with GNU General Public License v3.0 | 5 votes |
@Override public boolean onKeyPreIme(int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN) { if (mListener != null) mListener.onBackButtonPressed(); return true; } return super.onKeyPreIme(keyCode, event); }
Example 12
Source File: DoubleVolumeButtonLongPressPatternMatcher.java From talkback with Apache License 2.0 | 5 votes |
@Override public void onKeyEvent(KeyEvent keyEvent) { if (keyEvent.getKeyCode() != KeyEvent.KEYCODE_VOLUME_DOWN && keyEvent.getKeyCode() != KeyEvent.KEYCODE_VOLUME_UP) { return; } if (keyEvent.getAction() == KeyEvent.ACTION_DOWN) { handleActionDownEvent(keyEvent); } else { handleActionUpEvent(keyEvent); } }
Example 13
Source File: MEditText.java From EditTag with MIT License | 5 votes |
@Override public boolean sendKeyEvent(KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_DEL) { // Un-comment if you wish to cancel the backspace: // return false; } return super.sendKeyEvent(event); }
Example 14
Source File: TextPicker.java From GifAssistant 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 15
Source File: CodeEditText.java From APDE with GNU General Public License v2.0 | 5 votes |
@Override public boolean onKey(View view, int keyCode, KeyEvent event) { //We don't need this check now... but I'll leave it here just in case... // //Retrieve the character that was pressed (hopefully...) // //This doesn't work for all cases, though... // char pressedChar = (char) event.getUnicodeChar(event.getMetaState()); // // if(pressedChar != 0) // pressKeys(String.valueOf(pressedChar)); //We only want to check key down events... //...otherwise we get two events for every press because we have down and up if (event.getAction() != KeyEvent.ACTION_DOWN) return false; //We don't need this check, either... // if(keyCode == KeyEvent.KEYCODE_ENTER) { // post(new Runnable() { // public void run() { // pressEnter(); // } // }); // } //Override default TAB key behavior if (keyCode == KeyEvent.KEYCODE_TAB && PreferenceManager.getDefaultSharedPreferences(context).getBoolean("override_tab", true)) { if (!FLAG_NO_UNDO_SNAPSHOT) { flagTab = true; } getText().insert(getSelectionStart(), " "); flagTab = false; return true; } return false; }
Example 16
Source File: CustomDialog.java From TvLauncher with Apache License 2.0 | 5 votes |
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN) { dialogAutoDismiss(); } return super.onKeyDown(keyCode, event); }
Example 17
Source File: EditText.java From PowerFileExplorer with GNU General Public License v3.0 | 5 votes |
@Override public boolean dispatchKeyEvent(KeyEvent event) { int keycode = event.getKeyCode(); if ( !mCtrlPreIme ){ // CTRL + KEYDOWN int meta = (int)event.getMetaState(); boolean ctrl = (meta & mShortcutCtrlKey)!=0 ; // one of meta keies is pressed if ( ctrl ){ if (event.getAction() == KeyEvent.ACTION_DOWN ){ Log.d("=================>", ""+keycode); if (doShortcut(keycode)){ return true; } }else if (event.getAction() == KeyEvent.ACTION_UP){ return true; } } } if ( IS01FullScreen.isIS01orLynx() ){ if ( keycode == KeyEvent.KEYCODE_PAGE_UP || keycode == KeyEvent.KEYCODE_PAGE_DOWN ){ return true; } } return super.dispatchKeyEvent(event); }
Example 18
Source File: UI.java From GreenBits with GNU General Public License v3.0 | 4 votes |
private static boolean isEnterKeyDown(final KeyEvent e) { return e != null && e.getAction() == KeyEvent.ACTION_DOWN && e.getKeyCode() == KeyEvent.KEYCODE_ENTER; }
Example 19
Source File: ScrollView.java From android_9.0.0_r45 with Apache License 2.0 | 4 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() && event.getKeyCode() != KeyEvent.KEYCODE_BACK) { 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); } else { handled = fullScroll(View.FOCUS_UP); } break; case KeyEvent.KEYCODE_DPAD_DOWN: if (!event.isAltPressed()) { handled = arrowScroll(View.FOCUS_DOWN); } else { handled = fullScroll(View.FOCUS_DOWN); } break; case KeyEvent.KEYCODE_SPACE: pageScroll(event.isShiftPressed() ? View.FOCUS_UP : View.FOCUS_DOWN); break; } } return handled; }
Example 20
Source File: InputImpl.java From Game with GNU General Public License v3.0 | 4 votes |
@Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (osConfig.C_VOLUME_TO_ROTATE) { if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) { mudclient.keyLeft = event.getAction() == KeyEvent.ACTION_DOWN; return true; } if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { mudclient.keyRight = event.getAction() == KeyEvent.ACTION_DOWN; return true; } } // If we are not volume to rotate, then we are volume to zoom... else { if (Config.S_ZOOM_VIEW_TOGGLE) { if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) { mudclient.keyUp = event.getAction() == KeyEvent.ACTION_DOWN; return true; } if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { mudclient.keyDown = event.getAction() == KeyEvent.ACTION_DOWN; return true; } } } if (event.getAction() == KeyEvent.ACTION_DOWN) { int key = event.getUnicodeChar(); if (keyCode == KeyEvent.KEYCODE_DEL) { key = 8; } boolean hitInputFilter = false; for (int var5 = 0; var5 < Fonts.inputFilterChars.length(); ++var5) { if (Fonts.inputFilterChars.charAt(var5) == key) { hitInputFilter = true; break; } } mudclient.handleKeyPress((byte) 126, key); if (hitInputFilter && mudclient.inputTextCurrent.length() < 20) { mudclient.inputTextCurrent = mudclient.inputTextCurrent + (char) key; } if (hitInputFilter && mudclient.chatMessageInput.length() < 80) { mudclient.chatMessageInput = mudclient.chatMessageInput + (char) key; } // Backspace if (key == '\b' && mudclient.inputTextCurrent.length() > 0) { mudclient.inputTextCurrent = mudclient.inputTextCurrent.substring(0, mudclient.inputTextCurrent.length() - 1); } // Backspace if (key == '\b' && mudclient.chatMessageInput.length() > 0) { mudclient.chatMessageInput = mudclient.chatMessageInput.substring(0, mudclient.chatMessageInput.length() - 1); } if (key == 10 || key == 13) { mudclient.inputTextFinal = mudclient.inputTextCurrent; mudclient.chatMessageInputCommit = mudclient.chatMessageInput; } return true; } return false; }