List of usage examples for android.view KeyEvent KEYCODE_SPACE
int KEYCODE_SPACE
To view the source code for android.view KeyEvent KEYCODE_SPACE.
Click Source Link
From source file:com.android.app.MediaPlaybackActivity.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { int direction = -1; int repcnt = event.getRepeatCount(); if ((seekmethod == 0) ? seekMethod1(keyCode) : seekMethod2(keyCode)) return true; switch (keyCode) { /*//from w w w. jav a 2 s .c om // image scale case KeyEvent.KEYCODE_Q: av.adjustParams(-0.05, 0.0, 0.0, 0.0, 0.0,-1.0); break; case KeyEvent.KEYCODE_E: av.adjustParams( 0.05, 0.0, 0.0, 0.0, 0.0, 1.0); break; // image translate case KeyEvent.KEYCODE_W: av.adjustParams( 0.0, 0.0,-1.0, 0.0, 0.0, 0.0); break; case KeyEvent.KEYCODE_X: av.adjustParams( 0.0, 0.0, 1.0, 0.0, 0.0, 0.0); break; case KeyEvent.KEYCODE_A: av.adjustParams( 0.0,-1.0, 0.0, 0.0, 0.0, 0.0); break; case KeyEvent.KEYCODE_D: av.adjustParams( 0.0, 1.0, 0.0, 0.0, 0.0, 0.0); break; // camera rotation case KeyEvent.KEYCODE_R: av.adjustParams( 0.0, 0.0, 0.0, 0.0, 0.0,-1.0); break; case KeyEvent.KEYCODE_U: av.adjustParams( 0.0, 0.0, 0.0, 0.0, 0.0, 1.0); break; // camera translate case KeyEvent.KEYCODE_Y: av.adjustParams( 0.0, 0.0, 0.0, 0.0,-1.0, 0.0); break; case KeyEvent.KEYCODE_N: av.adjustParams( 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); break; case KeyEvent.KEYCODE_G: av.adjustParams( 0.0, 0.0, 0.0,-1.0, 0.0, 0.0); break; case KeyEvent.KEYCODE_J: av.adjustParams( 0.0, 0.0, 0.0, 1.0, 0.0, 0.0); break; */ case KeyEvent.KEYCODE_SLASH: seekmethod = 1 - seekmethod; return true; case KeyEvent.KEYCODE_DPAD_LEFT: if (!useDpadMusicControl()) { break; } if (!mPrevButton.hasFocus()) { mPrevButton.requestFocus(); } scanBackward(repcnt, event.getEventTime() - event.getDownTime()); return true; case KeyEvent.KEYCODE_DPAD_RIGHT: if (!useDpadMusicControl()) { break; } if (!mNextButton.hasFocus()) { mNextButton.requestFocus(); } scanForward(repcnt, event.getEventTime() - event.getDownTime()); return true; case KeyEvent.KEYCODE_S: toggleShuffle(); return true; case KeyEvent.KEYCODE_DPAD_CENTER: case KeyEvent.KEYCODE_SPACE: doPauseResume(); return true; } return super.onKeyDown(keyCode, event); }
From source file:com.ichi2.anki.AbstractFlashcardViewer.java
@Override public boolean onKeyUp(int keyCode, KeyEvent event) { if (mAnswerField != null && !mAnswerField.isFocused()) { if (!sDisplayAnswer) { if (keyCode == KeyEvent.KEYCODE_SPACE || keyCode == KeyEvent.KEYCODE_ENTER || keyCode == KeyEvent.KEYCODE_NUMPAD_ENTER) { displayCardAnswer();/*from w w w .j a v a 2 s .co m*/ return true; } } } return super.onKeyUp(keyCode, event); }
From source file:com.strathclyde.highlightingkeyboard.SoftKeyboardService.java
/** * Use this to monitor key events being delivered to the application. * We get first crack at them, and can either resume them or let them * continue to the app./*ww w. j ava 2 s . c o m*/ */ @Override public boolean onKeyDown(int keyCode, KeyEvent event) { //event. //Log.i("OnKeyDown", "Keycode: "+keyCode); switch (keyCode) { case KeyEvent.KEYCODE_BACK: // The InputMethodService already takes care of the back // key for us, to dismiss the input method if it is shown. // However, our keyboard could be showing a pop-up window // that back should dismiss, so we first allow it to do that. if (event.getRepeatCount() == 0 && mInputView != null) { if (mInputView.handleBack()) { return true; } } break; case KeyEvent.KEYCODE_DEL: // Special handling of the delete key: if we currently are // composing text for the user, we want to modify that instead // of let the application to the delete itself. if (mComposing.length() > 0) { onKey(Keyboard.KEYCODE_DELETE, null); return true; } break; case -2: //123 button //Log.i("KeyDown", "Keycode: "+keyCode); event.startTracking(); return true; case KeyEvent.KEYCODE_ENTER: // Let the underlying text editor always handle these. return false; default: // For all other keys, if we want to do transformations on // text being entered with a hard keyboard, we need to process // it and do the appropriate action. if (PROCESS_HARD_KEYS) { if (keyCode == KeyEvent.KEYCODE_SPACE && (event.getMetaState() & KeyEvent.META_ALT_ON) != 0) { // A silly example: in our input method, Alt+Space // is a shortcut for 'android' in lower case. //InputConnection ic = ic; if (ic != null) { // First, tell the editor that it is no longer in the // shift state, since we are consuming this. ic.clearMetaKeyStates(KeyEvent.META_ALT_ON); keyDownUp(KeyEvent.KEYCODE_A); keyDownUp(KeyEvent.KEYCODE_N); keyDownUp(KeyEvent.KEYCODE_D); keyDownUp(KeyEvent.KEYCODE_R); keyDownUp(KeyEvent.KEYCODE_O); keyDownUp(KeyEvent.KEYCODE_I); keyDownUp(KeyEvent.KEYCODE_D); // And we consume this event. return true; } } if (mPredictionOn && translateKeyDown(keyCode, event)) { return true; } } } return super.onKeyDown(keyCode, event); }
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 a2 s. c om 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 ww w .j a v a 2 s. c om*/ 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); }
From source file:android.support.v7.widget.AbstractXpListPopupWindow.java
/** * Filter key down events. By forwarding key down events to this function, * views using non-modal ListPopupWindow can have it handle key selection of items. * * @param keyCode keyCode param passed to the host view's onKeyDown * @param event event param passed to the host view's onKeyDown * @return true if the event was handled, false if it was ignored. * @see #setModal(boolean)/*from w w w .ja va 2 s. co m*/ */ public boolean onKeyDown(int keyCode, KeyEvent event) { // when the drop down is shown, we drive it directly if (isShowing()) { // the key events are forwarded to the list in the drop down view // note that ListView handles space but we don't want that to happen // also if selection is not currently in the drop down, then don't // let center or enter presses go there since that would cause it // to select one of its items if (keyCode != KeyEvent.KEYCODE_SPACE && (mDropDownList.getSelectedItemPosition() >= 0 || !isConfirmKey(keyCode))) { int curIndex = mDropDownList.getSelectedItemPosition(); boolean consumed; final boolean below = !mPopup.isAboveAnchor(); final ListAdapter adapter = mAdapter; boolean allEnabled; int firstItem = Integer.MAX_VALUE; int lastItem = Integer.MIN_VALUE; if (adapter != null) { allEnabled = adapter.areAllItemsEnabled(); firstItem = allEnabled ? 0 : mDropDownList.lookForSelectablePosition(0, true); lastItem = allEnabled ? adapter.getCount() - 1 : mDropDownList.lookForSelectablePosition(adapter.getCount() - 1, false); } if ((below && keyCode == KeyEvent.KEYCODE_DPAD_UP && curIndex <= firstItem) || (!below && keyCode == KeyEvent.KEYCODE_DPAD_DOWN && curIndex >= lastItem)) { // When the selection is at the top, we block the key // event to prevent focus from moving. clearListSelection(); mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED); show(); return true; } else { // WARNING: Please read the comment where mListSelectionHidden // is declared mDropDownList.setListSelectionHidden(false); } consumed = mDropDownList.onKeyDown(keyCode, event); if (DEBUG) Log.v(TAG, "Key down: code=" + keyCode + " list consumed=" + consumed); if (consumed) { // If it handled the key event, then the user is // navigating in the list, so we should put it in front. mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED); // Here's a little trick we need to do to make sure that // the list view is actually showing its focus indicator, // by ensuring it has focus and getting its window out // of touch mode. mDropDownList.requestFocusFromTouch(); show(); switch (keyCode) { // avoid passing the focus from the text view to the // next component case KeyEvent.KEYCODE_ENTER: case KeyEvent.KEYCODE_DPAD_CENTER: case KeyEvent.KEYCODE_DPAD_DOWN: case KeyEvent.KEYCODE_DPAD_UP: return true; } } else { if (below && keyCode == KeyEvent.KEYCODE_DPAD_DOWN) { // when the selection is at the bottom, we block the // event to avoid going to the next focusable widget if (curIndex == lastItem) { return true; } } else if (!below && keyCode == KeyEvent.KEYCODE_DPAD_UP && curIndex == firstItem) { return true; } } } } return false; }
From source file:com.appunite.list.GridView.java
private boolean commonKey(int keyCode, int count, KeyEvent event) { if (mAdapter == null) { return false; }// w ww . j a v a2 s . co m if (mDataChanged) { layoutChildren(); } boolean handled = false; int action = event.getAction(); if (action != KeyEvent.ACTION_UP) { switch (keyCode) { case KeyEvent.KEYCODE_DPAD_LEFT: if (KeyEventCompat.hasNoModifiers(event)) { handled = resurrectSelectionIfNeeded() || arrowScroll(FOCUS_LEFT); } break; case KeyEvent.KEYCODE_DPAD_RIGHT: if (KeyEventCompat.hasNoModifiers(event)) { handled = resurrectSelectionIfNeeded() || arrowScroll(FOCUS_RIGHT); } break; case KeyEvent.KEYCODE_DPAD_UP: if (KeyEventCompat.hasNoModifiers(event)) { handled = resurrectSelectionIfNeeded() || arrowScroll(FOCUS_UP); } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_ALT_ON)) { handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_UP); } break; case KeyEvent.KEYCODE_DPAD_DOWN: if (KeyEventCompat.hasNoModifiers(event)) { handled = resurrectSelectionIfNeeded() || arrowScroll(FOCUS_DOWN); } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_ALT_ON)) { handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_DOWN); } break; case KeyEvent.KEYCODE_DPAD_CENTER: case KeyEvent.KEYCODE_ENTER: if (KeyEventCompat.hasNoModifiers(event)) { handled = resurrectSelectionIfNeeded(); if (!handled && event.getRepeatCount() == 0 && getChildCount() > 0) { keyPressed(); handled = true; } } break; case KeyEvent.KEYCODE_SPACE: if (mPopup == null || !mPopup.isShowing()) { if (KeyEventCompat.hasNoModifiers(event)) { handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_DOWN); } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_SHIFT_ON)) { handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_UP); } } break; case KeyEvent.KEYCODE_PAGE_UP: if (KeyEventCompat.hasNoModifiers(event)) { handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_UP); } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_ALT_ON)) { handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_UP); } break; case KeyEvent.KEYCODE_PAGE_DOWN: if (KeyEventCompat.hasNoModifiers(event)) { handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_DOWN); } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_ALT_ON)) { handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_DOWN); } break; case KeyEvent.KEYCODE_MOVE_HOME: if (KeyEventCompat.hasNoModifiers(event)) { handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_UP); } break; case KeyEvent.KEYCODE_MOVE_END: if (KeyEventCompat.hasNoModifiers(event)) { handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_DOWN); } break; case KeyEvent.KEYCODE_TAB: // XXX Sometimes it is useful to be able to TAB through the items in // a GridView sequentially. Unfortunately this can create an // asymmetry in TAB navigation order unless the list selection // always reverts to the top or bottom when receiving TAB focus from // another widget. Leaving this behavior disabled for now but // perhaps it should be configurable (and more comprehensive). if (false) { if (KeyEventCompat.hasNoModifiers(event)) { handled = resurrectSelectionIfNeeded() || sequenceScroll(FOCUS_FORWARD); } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_SHIFT_ON)) { handled = resurrectSelectionIfNeeded() || sequenceScroll(FOCUS_BACKWARD); } } break; } } if (handled) { return true; } if (sendToTextFilter(keyCode, count, event)) { return true; } switch (action) { case KeyEvent.ACTION_DOWN: return super.onKeyDown(keyCode, event); case KeyEvent.ACTION_UP: return super.onKeyUp(keyCode, event); case KeyEvent.ACTION_MULTIPLE: return super.onKeyMultiple(keyCode, count, event); default: return false; } }
From source file:com.zld.ui.ZldNewActivity.java
@Override public boolean dispatchKeyEvent(KeyEvent event) { // TODO Auto-generated method stub if (event.getKeyCode() == KeyEvent.KEYCODE_SPACE) { cashFragment.setFocus();/*from w w w .j a v a2 s . c o m*/ return true; } return event.getKeyCode() == KeyEvent.KEYCODE_ENTER || super.dispatchKeyEvent(event); }
From source file:org.bangbang.support.v4.widget.HListView.java
private boolean commonKey(int keyCode, int count, KeyEvent event) { if (mAdapter == null) { return false; }/*from w ww . j a v a 2 s . co m*/ if (mDataChanged) { layoutChildren(); } boolean handled = false; int action = event.getAction(); if (action != KeyEvent.ACTION_UP) { if (mSelectedPosition < 0) { switch (keyCode) { case KeyEvent.KEYCODE_DPAD_UP: case KeyEvent.KEYCODE_DPAD_DOWN: case KeyEvent.KEYCODE_DPAD_CENTER: case KeyEvent.KEYCODE_ENTER: case KeyEvent.KEYCODE_SPACE: if (resurrectSelection()) { return true; } } } switch (keyCode) { case KeyEvent.KEYCODE_DPAD_LEFT: if (!event.isAltPressed()) { while (count > 0) { handled = arrowScroll(FOCUS_LEFT); count--; } } else { handled = fullScroll(FOCUS_LEFT); } break; case KeyEvent.KEYCODE_DPAD_RIGHT: if (!event.isAltPressed()) { while (count > 0) { handled = arrowScroll(FOCUS_RIGHT); count--; } } else { handled = fullScroll(FOCUS_RIGHT); } break; case KeyEvent.KEYCODE_DPAD_UP: handled = handleHorizontalFocusWithinListItem(View.FOCUS_UP); break; case KeyEvent.KEYCODE_DPAD_DOWN: handled = handleHorizontalFocusWithinListItem(View.FOCUS_DOWN); break; case KeyEvent.KEYCODE_DPAD_CENTER: case KeyEvent.KEYCODE_ENTER: if (mItemCount > 0 && event.getRepeatCount() == 0) { keyPressed(); } handled = true; break; case KeyEvent.KEYCODE_SPACE: if (mPopup == null || !mPopup.isShowing()) { if (!event.isShiftPressed()) { pageScroll(FOCUS_DOWN); } else { pageScroll(FOCUS_UP); } handled = true; } break; } } if (!handled) { handled = sendToTextFilter(keyCode, count, event); } if (handled) { return true; } else { switch (action) { case KeyEvent.ACTION_DOWN: return super.onKeyDown(keyCode, event); case KeyEvent.ACTION_UP: return super.onKeyUp(keyCode, event); case KeyEvent.ACTION_MULTIPLE: return super.onKeyMultiple(keyCode, count, event); default: // shouldn't happen return false; } } }
From source file:com.appunite.list.HorizontalListView.java
private boolean commonKey(int keyCode, int count, KeyEvent event) { if (mAdapter == null || !mIsAttached) { return false; }//w ww . ja v a 2s . c o m // TODO I stopped swaping heare (j.m.) if (mDataChanged) { layoutChildren(); } boolean handled = false; int action = event.getAction(); if (action != KeyEvent.ACTION_UP) { switch (keyCode) { case KeyEvent.KEYCODE_DPAD_RIGHT: if (KeyEventCompat.hasNoModifiers(event)) { handled = resurrectSelectionIfNeeded(); if (!handled) { while (count-- > 0) { if (arrowScroll(FOCUS_RIGHT)) { handled = true; } else { break; } } } } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_ALT_ON)) { handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_RIGHT); } break; case KeyEvent.KEYCODE_DPAD_LEFT: if (KeyEventCompat.hasNoModifiers(event)) { handled = resurrectSelectionIfNeeded(); if (!handled) { while (count-- > 0) { if (arrowScroll(FOCUS_LEFT)) { handled = true; } else { break; } } } } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_ALT_ON)) { handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_LEFT); } break; case KeyEvent.KEYCODE_DPAD_UP: if (KeyEventCompat.hasNoModifiers(event)) { handled = handleHorizontalFocusWithinListItem(View.FOCUS_UP); } break; case KeyEvent.KEYCODE_DPAD_DOWN: if (KeyEventCompat.hasNoModifiers(event)) { handled = handleHorizontalFocusWithinListItem(View.FOCUS_DOWN); } break; case KeyEvent.KEYCODE_DPAD_CENTER: case KeyEvent.KEYCODE_ENTER: if (KeyEventCompat.hasNoModifiers(event)) { handled = resurrectSelectionIfNeeded(); if (!handled && event.getRepeatCount() == 0 && getChildCount() > 0) { keyPressed(); handled = true; } } break; case KeyEvent.KEYCODE_SPACE: if (mPopup == null || !mPopup.isShowing()) { if (KeyEventCompat.hasNoModifiers(event)) { handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_RIGHT); } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_SHIFT_ON)) { handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_LEFT); } handled = true; } break; case KeyEvent.KEYCODE_PAGE_UP: if (KeyEventCompat.hasNoModifiers(event)) { handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_LEFT); } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_ALT_ON)) { handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_LEFT); } break; case KeyEvent.KEYCODE_PAGE_DOWN: if (KeyEventCompat.hasNoModifiers(event)) { handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_RIGHT); } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_ALT_ON)) { handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_RIGHT); } break; case KeyEvent.KEYCODE_MOVE_HOME: if (KeyEventCompat.hasNoModifiers(event)) { handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_LEFT); } break; case KeyEvent.KEYCODE_MOVE_END: if (KeyEventCompat.hasNoModifiers(event)) { handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_RIGHT); } break; case KeyEvent.KEYCODE_TAB: // XXX Sometimes it is useful to be able to TAB through the items in // a ListView sequentially. Unfortunately this can create an // asymmetry in TAB navigation order unless the list selection // always reverts to the top or bottom when receiving TAB focus from // another widget. Leaving this behavior disabled for now but // perhaps it should be configurable (and more comprehensive). if (false) { if (KeyEventCompat.hasNoModifiers(event)) { handled = resurrectSelectionIfNeeded() || arrowScroll(FOCUS_RIGHT); } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_SHIFT_ON)) { handled = resurrectSelectionIfNeeded() || arrowScroll(FOCUS_LEFT); } } break; } } if (handled) { return true; } if (sendToTextFilter(keyCode, count, event)) { return true; } switch (action) { case KeyEvent.ACTION_DOWN: return super.onKeyDown(keyCode, event); case KeyEvent.ACTION_UP: return super.onKeyUp(keyCode, event); case KeyEvent.ACTION_MULTIPLE: return super.onKeyMultiple(keyCode, count, event); default: // shouldn't happen return false; } }