List of usage examples for android.view KeyEvent isPrintingKey
public boolean isPrintingKey()
From source file:com.android.calculator2.EventListener.java
@Override public boolean onKey(View view, int keyCode, KeyEvent keyEvent) { int action = keyEvent.getAction(); // Work-around for spurious key event from IME, bug #1639445 if (action == KeyEvent.ACTION_MULTIPLE && keyCode == KeyEvent.KEYCODE_UNKNOWN) { return true; // eat it }/*from w w w.j av a 2s . c o m*/ if (keyEvent.getUnicodeChar() == '=') { if (action == KeyEvent.ACTION_UP) { mHandler.onEnter(); } return true; } if (keyCode != KeyEvent.KEYCODE_DPAD_CENTER && keyCode != KeyEvent.KEYCODE_DPAD_UP && keyCode != KeyEvent.KEYCODE_DPAD_DOWN && keyCode != KeyEvent.KEYCODE_ENTER) { if (keyEvent.isPrintingKey() && action == KeyEvent.ACTION_UP) { // Tell the handler that text was updated. mHandler.onTextChanged(); } return false; } /* * We should act on KeyEvent.ACTION_DOWN, but strangely sometimes the * DOWN event isn't received, only the UP. So the workaround is to act * on UP... http://b/issue?id=1022478 */ if (action == KeyEvent.ACTION_UP) { switch (keyCode) { case KeyEvent.KEYCODE_ENTER: case KeyEvent.KEYCODE_DPAD_CENTER: mHandler.onEnter(); break; case KeyEvent.KEYCODE_DPAD_UP: mHandler.onUp(); break; case KeyEvent.KEYCODE_DPAD_DOWN: mHandler.onDown(); break; } } return true; }
From source file:com.android2.calculator3.EventListener.java
@Override public boolean onKey(View view, int keyCode, KeyEvent keyEvent) { int action = keyEvent.getAction(); // Work-around for spurious key event from IME, bug #1639445 if (action == KeyEvent.ACTION_MULTIPLE && keyCode == KeyEvent.KEYCODE_UNKNOWN) { return true; // eat it }// www.ja va2s . c om if (keyEvent.getUnicodeChar() == '=') { if (action == KeyEvent.ACTION_UP) { mHandler.onEnter(); } return true; } if (keyCode != KeyEvent.KEYCODE_DPAD_CENTER && keyCode != KeyEvent.KEYCODE_DPAD_UP && keyCode != KeyEvent.KEYCODE_DPAD_DOWN && keyCode != KeyEvent.KEYCODE_ENTER) { if (keyEvent.isPrintingKey() && action == KeyEvent.ACTION_UP) { // Tell the handler that text was updated. mHandler.onTextChanged(); } return false; } /* * We should act on KeyEvent.ACTION_DOWN, but strangely sometimes the DOWN event isn't received, only the UP. So the workaround is to act on UP... http://b/issue?id=1022478 */ if (action == KeyEvent.ACTION_UP) { switch (keyCode) { case KeyEvent.KEYCODE_ENTER: case KeyEvent.KEYCODE_DPAD_CENTER: mHandler.onEnter(); break; case KeyEvent.KEYCODE_DPAD_UP: mHandler.onUp(); break; case KeyEvent.KEYCODE_DPAD_DOWN: mHandler.onDown(); break; } } return true; }
From source file:com.oda.calculator.EventListener.java
public boolean onKey(View view, int keyCode, KeyEvent keyEvent) { int action = keyEvent.getAction(); if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT || keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) { boolean eat = mHandler.eatHorizontalMove(keyCode == KeyEvent.KEYCODE_DPAD_LEFT); return eat; }/*from w ww . j av a2s.com*/ //Work-around for spurious key event from IME, bug #1639445 if (action == KeyEvent.ACTION_MULTIPLE && keyCode == KeyEvent.KEYCODE_UNKNOWN) { return true; // eat it } //Calculator.log("KEY " + keyCode + "; " + action); if (keyEvent.getUnicodeChar() == '=') { if (action == KeyEvent.ACTION_UP) { mHandler.onEnter(); } return true; } if (keyCode != KeyEvent.KEYCODE_DPAD_CENTER && keyCode != KeyEvent.KEYCODE_DPAD_UP && keyCode != KeyEvent.KEYCODE_DPAD_DOWN && keyCode != KeyEvent.KEYCODE_ENTER) { if (keyEvent.isPrintingKey() && action == KeyEvent.ACTION_UP) { // Tell the handler that text was updated. mHandler.onTextChanged(); } return false; } /* We should act on KeyEvent.ACTION_DOWN, but strangely sometimes the DOWN event isn't received, only the UP. So the workaround is to act on UP... http://b/issue?id=1022478 */ if (action == KeyEvent.ACTION_UP) { switch (keyCode) { case KeyEvent.KEYCODE_ENTER: case KeyEvent.KEYCODE_DPAD_CENTER: mHandler.onEnter(); break; case KeyEvent.KEYCODE_DPAD_UP: mHandler.onUp(); break; case KeyEvent.KEYCODE_DPAD_DOWN: mHandler.onDown(); break; } } return true; }
From source file:com.aman.stockcalculator.EventListener.java
@Override public boolean onKey(View view, int keyCode, KeyEvent keyEvent) { int action = keyEvent.getAction(); if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT || keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) { boolean eat = mHandler.eatHorizontalMove(keyCode == KeyEvent.KEYCODE_DPAD_LEFT); return eat; }//from www . j a v a 2 s. c om //Work-around for spurious key event from IME, bug #1639445 if (action == KeyEvent.ACTION_MULTIPLE && keyCode == KeyEvent.KEYCODE_UNKNOWN) { return true; // eat it } //Calculator.log("KEY " + keyCode + "; " + action); if (keyEvent.getUnicodeChar() == '=') { if (action == KeyEvent.ACTION_UP) { mHandler.onEnter(); } return true; } if (keyCode != KeyEvent.KEYCODE_DPAD_CENTER && keyCode != KeyEvent.KEYCODE_DPAD_UP && keyCode != KeyEvent.KEYCODE_DPAD_DOWN && keyCode != KeyEvent.KEYCODE_ENTER) { if (keyEvent.isPrintingKey() && action == KeyEvent.ACTION_UP) { // Tell the handler that text was updated. mHandler.onTextChanged(); } return false; } /* We should act on KeyEvent.ACTION_DOWN, but strangely sometimes the DOWN event isn't received, only the UP. So the workaround is to act on UP... http://b/issue?id=1022478 */ if (action == KeyEvent.ACTION_UP) { switch (keyCode) { case KeyEvent.KEYCODE_ENTER: case KeyEvent.KEYCODE_DPAD_CENTER: mHandler.onEnter(); break; case KeyEvent.KEYCODE_DPAD_UP: mHandler.onUp(); break; case KeyEvent.KEYCODE_DPAD_DOWN: mHandler.onDown(); break; } } return true; }
From source file:com.android.screenspeak.KeyboardSearchManager.java
@Override public boolean onKeyEvent(KeyEvent event) { // Only handle single-key events here. The KeyComboManager will pass us combos. if (event.getModifiers() != 0 || !mNodeSearch.isActive()) { return false; }//from w w w . j av a2 s . c o m if (event.getAction() == KeyEvent.ACTION_DOWN) { switch (event.getKeyCode()) { case KeyEvent.KEYCODE_ENTER: if (mHasNavigated || mNodeSearch.hasMatch()) { finishSearch(); mContext.getCursorController().clickCurrent(); } else { cancelSearch(); } return true; case KeyEvent.KEYCODE_DEL: resetHintTime(); final String queryText = mNodeSearch.getCurrentQuery(); if (queryText.isEmpty()) { cancelSearch(); } else { final String lastChar = queryText.substring(queryText.length() - 1); mNodeSearch.backspaceQueryText(); mSpeechController.speak(mContext.getString(R.string.template_text_removed, lastChar), SpeechController.QUEUE_MODE_FLUSH_ALL, FeedbackItem.FLAG_NO_HISTORY, null); } return true; case KeyEvent.KEYCODE_DPAD_UP: moveToEnd(NodeFocusFinder.SEARCH_BACKWARD); return true; case KeyEvent.KEYCODE_DPAD_LEFT: moveToNext(NodeFocusFinder.SEARCH_BACKWARD); return true; case KeyEvent.KEYCODE_DPAD_DOWN: moveToEnd(NodeFocusFinder.SEARCH_FORWARD); return true; case KeyEvent.KEYCODE_DPAD_RIGHT: moveToNext(NodeFocusFinder.SEARCH_FORWARD); return true; case KeyEvent.KEYCODE_SPACE: resetHintTime(); if (mNodeSearch.tryAddQueryText(" ")) { mSpeechController.speak(mContext.getString(R.string.symbol_space), SpeechController.QUEUE_MODE_FLUSH_ALL, FeedbackItem.FLAG_NO_HISTORY, null); } else { mContext.getFeedbackController().playAuditory(R.raw.complete); } return true; default: if (event.isPrintingKey()) { resetHintTime(); final String key = String.valueOf(event.getDisplayLabel()); if (mNodeSearch.tryAddQueryText(key)) { mSpeechController.speak(key.toLowerCase(), SpeechController.QUEUE_MODE_FLUSH_ALL, FeedbackItem.FLAG_NO_HISTORY, null); } else { mContext.getFeedbackController().playAuditory(R.raw.complete); } return true; } break; } } return false; }
From source file:com.yek.keyboard.anysoftkeyboard.AnySoftKeyboard.java
@Override public boolean onKeyDown(final int keyEventKeyCode, @NonNull KeyEvent event) { InputConnection ic = getCurrentInputConnection(); if (handleSelectionExpending(keyEventKeyCode, ic, mGlobalSelectionStartPosition, mGlobalCursorPosition)) return true; final boolean shouldTranslateSpecialKeys = isInputViewShown(); //greater than zero means it is a physical keyboard. //we also want to hide the view if it's a glyph (for example, not physical volume-up key) if (event.getDeviceId() > 0 && event.isPrintingKey()) onPhysicalKeyboardKeyPressed();//from ww w . j a v a 2s .com mHardKeyboardAction.initializeAction(event, mMetaState); switch (keyEventKeyCode) { /**** * SPECIAL translated HW keys If you add new keys here, do not forget * to add to the */ case KeyEvent.KEYCODE_CAMERA: if (shouldTranslateSpecialKeys && mAskPrefs.useCameraKeyForBackspaceBackword()) { handleBackWord(getCurrentInputConnection()); return true; } // DO NOT DELAY CAMERA KEY with unneeded checks in default mark return super.onKeyDown(keyEventKeyCode, event); case KeyEvent.KEYCODE_FOCUS: if (shouldTranslateSpecialKeys && mAskPrefs.useCameraKeyForBackspaceBackword()) { handleDeleteLastCharacter(false); return true; } // DO NOT DELAY FOCUS KEY with unneeded checks in default mark return super.onKeyDown(keyEventKeyCode, event); case KeyEvent.KEYCODE_VOLUME_UP: if (shouldTranslateSpecialKeys && mAskPrefs.useVolumeKeyForLeftRight()) { sendDownUpKeyEvents(KeyEvent.KEYCODE_DPAD_LEFT); return true; } // DO NOT DELAY VOLUME UP KEY with unneeded checks in default // mark return super.onKeyDown(keyEventKeyCode, event); case KeyEvent.KEYCODE_VOLUME_DOWN: if (shouldTranslateSpecialKeys && mAskPrefs.useVolumeKeyForLeftRight()) { sendDownUpKeyEvents(KeyEvent.KEYCODE_DPAD_RIGHT); return true; } // DO NOT DELAY VOLUME DOWN KEY with unneeded checks in default // mark return super.onKeyDown(keyEventKeyCode, event); /**** * END of SPECIAL translated HW keys code section */ case KeyEvent.KEYCODE_BACK: if (event.getRepeatCount() == 0 && getInputView() != null) { if (getInputView().handleBack()) { // consuming the meta keys if (ic != null) { // translated, so we also take care of the metakeys ic.clearMetaKeyStates(Integer.MAX_VALUE); } mMetaState = 0; return true; } } break; case 0x000000cc:// API 14: KeyEvent.KEYCODE_LANGUAGE_SWITCH switchToNextPhysicalKeyboard(ic); return true; case KeyEvent.KEYCODE_SHIFT_LEFT: case KeyEvent.KEYCODE_SHIFT_RIGHT: if (event.isAltPressed() && Workarounds.isAltSpaceLangSwitchNotPossible()) { switchToNextPhysicalKeyboard(ic); return true; } // NOTE: letting it fall-through to the other meta-keys case KeyEvent.KEYCODE_ALT_LEFT: case KeyEvent.KEYCODE_ALT_RIGHT: case KeyEvent.KEYCODE_SYM: Logger.d(TAG + "-meta-key", getMetaKeysStates("onKeyDown before handle")); mMetaState = MyMetaKeyKeyListener.handleKeyDown(mMetaState, keyEventKeyCode, event); Logger.d(TAG + "-meta-key", getMetaKeysStates("onKeyDown after handle")); break; case KeyEvent.KEYCODE_SPACE: if ((event.isAltPressed() && !Workarounds.isAltSpaceLangSwitchNotPossible()) || event.isShiftPressed()) { switchToNextPhysicalKeyboard(ic); return true; } // NOTE: // letting it fall through to the "default" default: // Fix issue 185, check if we should process key repeat if (!mAskPrefs.getUseRepeatingKeys() && event.getRepeatCount() > 0) return true; AnyKeyboard.HardKeyboardTranslator keyTranslator = (AnyKeyboard.HardKeyboardTranslator) getCurrentAlphabetKeyboard(); if (getKeyboardSwitcher().isCurrentKeyboardPhysical() && keyTranslator != null) { // sometimes, the physical keyboard will delete input, and then add some. // we'll try to make it nice. if (ic != null) ic.beginBatchEdit(); try { // issue 393, backword on the hw keyboard! if (mAskPrefs.useBackword() && keyEventKeyCode == KeyEvent.KEYCODE_DEL && event.isShiftPressed()) { handleBackWord(ic); return true; } else { // http://article.gmane.org/gmane.comp.handhelds.openmoko.android-freerunner/629 keyTranslator.translatePhysicalCharacter(mHardKeyboardAction, this); if (mHardKeyboardAction.getKeyCodeWasChanged()) { final int translatedChar = mHardKeyboardAction.getKeyCode(); // typing my own. onKey(translatedChar, null, -1, new int[] { translatedChar }, true/*faking from UI*/); // my handling we are at a regular key press, so we'll update // our meta-state member mMetaState = MyMetaKeyKeyListener.adjustMetaAfterKeypress(mMetaState); Logger.d(TAG + "-meta-key", getMetaKeysStates("onKeyDown after adjust - translated")); return true; } } } finally { if (ic != null) ic.endBatchEdit(); } } if (event.isPrintingKey()) { // we are at a regular key press, so we'll update our // meta-state // member mMetaState = MyMetaKeyKeyListener.adjustMetaAfterKeypress(mMetaState); Logger.d(TAG + "-meta-key", getMetaKeysStates("onKeyDown after adjust")); } } return super.onKeyDown(keyEventKeyCode, event); }
From source file:com.anysoftkeyboard.AnySoftKeyboard.java
@Override public boolean onKeyDown(final int keyEventKeyCode, @NonNull KeyEvent event) { InputConnection ic = getCurrentInputConnection(); if (handleSelectionExpending(keyEventKeyCode, ic, mGlobalSelectionStartPosition, mGlobalCursorPosition)) return true; final boolean shouldTranslateSpecialKeys = isInputViewShown(); //greater than zero means it is a physical keyboard. //we also want to hide the view if it's a glyph (for example, not physical volume-up key) if (event.getDeviceId() > 0 && event.isPrintingKey()) onPhysicalKeyboardKeyPressed();/*from w w w . j a va 2 s . c o m*/ mHardKeyboardAction.initializeAction(event, mMetaState); switch (keyEventKeyCode) { /**** * SPECIAL translated HW keys If you add new keys here, do not forget * to add to the */ case KeyEvent.KEYCODE_CAMERA: if (shouldTranslateSpecialKeys && mAskPrefs.useCameraKeyForBackspaceBackword()) { handleBackWord(getCurrentInputConnection()); return true; } // DO NOT DELAY CAMERA KEY with unneeded checks in default mark return super.onKeyDown(keyEventKeyCode, event); case KeyEvent.KEYCODE_FOCUS: if (shouldTranslateSpecialKeys && mAskPrefs.useCameraKeyForBackspaceBackword()) { handleDeleteLastCharacter(false); return true; } // DO NOT DELAY FOCUS KEY with unneeded checks in default mark return super.onKeyDown(keyEventKeyCode, event); case KeyEvent.KEYCODE_VOLUME_UP: if (shouldTranslateSpecialKeys && mAskPrefs.useVolumeKeyForLeftRight()) { sendDownUpKeyEvents(KeyEvent.KEYCODE_DPAD_LEFT); return true; } // DO NOT DELAY VOLUME UP KEY with unneeded checks in default // mark return super.onKeyDown(keyEventKeyCode, event); case KeyEvent.KEYCODE_VOLUME_DOWN: if (shouldTranslateSpecialKeys && mAskPrefs.useVolumeKeyForLeftRight()) { sendDownUpKeyEvents(KeyEvent.KEYCODE_DPAD_RIGHT); return true; } // DO NOT DELAY VOLUME DOWN KEY with unneeded checks in default // mark return super.onKeyDown(keyEventKeyCode, event); /**** * END of SPECIAL translated HW keys code section */ case KeyEvent.KEYCODE_BACK: if (event.getRepeatCount() == 0 && getInputView() != null) { if (getInputView().handleBack()) { // consuming the meta keys if (ic != null) { // translated, so we also take care of the metakeys ic.clearMetaKeyStates(Integer.MAX_VALUE); } mMetaState = 0; return true; } } break; case 0x000000cc:// API 14: KeyEvent.KEYCODE_LANGUAGE_SWITCH switchToNextPhysicalKeyboard(ic); return true; case KeyEvent.KEYCODE_SHIFT_LEFT: case KeyEvent.KEYCODE_SHIFT_RIGHT: if (event.isAltPressed() && Workarounds.isAltSpaceLangSwitchNotPossible()) { switchToNextPhysicalKeyboard(ic); return true; } // NOTE: letting it fall-through to the other meta-keys case KeyEvent.KEYCODE_ALT_LEFT: case KeyEvent.KEYCODE_ALT_RIGHT: case KeyEvent.KEYCODE_SYM: Logger.d(TAG + "-meta-key", getMetaKeysStates("onKeyDown before handle")); mMetaState = MyMetaKeyKeyListener.handleKeyDown(mMetaState, keyEventKeyCode, event); Logger.d(TAG + "-meta-key", getMetaKeysStates("onKeyDown after handle")); break; case KeyEvent.KEYCODE_SPACE: if ((event.isAltPressed() && !Workarounds.isAltSpaceLangSwitchNotPossible()) || event.isShiftPressed()) { switchToNextPhysicalKeyboard(ic); return true; } // NOTE: // letting it fall through to the "default" default: // Fix issue 185, check if we should process key repeat if (!mAskPrefs.getUseRepeatingKeys() && event.getRepeatCount() > 0) return true; HardKeyboardTranslator keyTranslator = (HardKeyboardTranslator) getCurrentAlphabetKeyboard(); if (getKeyboardSwitcher().isCurrentKeyboardPhysical() && keyTranslator != null) { // sometimes, the physical keyboard will delete input, and then add some. // we'll try to make it nice. if (ic != null) ic.beginBatchEdit(); try { // issue 393, backword on the hw keyboard! if (mAskPrefs.useBackword() && keyEventKeyCode == KeyEvent.KEYCODE_DEL && event.isShiftPressed()) { handleBackWord(ic); return true; } else { // http://article.gmane.org/gmane.comp.handhelds.openmoko.android-freerunner/629 keyTranslator.translatePhysicalCharacter(mHardKeyboardAction, this); if (mHardKeyboardAction.getKeyCodeWasChanged()) { final int translatedChar = mHardKeyboardAction.getKeyCode(); // typing my own. onKey(translatedChar, null, -1, new int[] { translatedChar }, true/*faking from UI*/); // my handling we are at a regular key press, so we'll update // our meta-state member mMetaState = MyMetaKeyKeyListener.adjustMetaAfterKeypress(mMetaState); Logger.d(TAG + "-meta-key", getMetaKeysStates("onKeyDown after adjust - translated")); return true; } } } finally { if (ic != null) ic.endBatchEdit(); } } if (event.isPrintingKey()) { // we are at a regular key press, so we'll update our // meta-state // member mMetaState = MyMetaKeyKeyListener.adjustMetaAfterKeypress(mMetaState); Logger.d(TAG + "-meta-key", getMetaKeysStates("onKeyDown after adjust")); } } return super.onKeyDown(keyEventKeyCode, event); }