List of usage examples for android.view KeyEvent KEYCODE_DPAD_UP
int KEYCODE_DPAD_UP
To view the source code for android.view KeyEvent KEYCODE_DPAD_UP.
Click Source Link
From source file:og.android.tether.MainActivity.java
public Dialog openLaunchedDialog(final boolean noroot) { final long value = noroot ? 1 : 0; EasyTracker.getTracker().trackEvent("ui_action", "create_dialog", "meshclient", value); Dialog dialog = new AlertDialog.Builder(this) .setMessage(noroot ? R.string.dialog_noroot_text : R.string.dialog_launched_text) .setTitle(getString(R.string.dialog_launched_title)).setIcon(R.drawable.og_app_icon) .setCancelable(false).setOnKeyListener(new DialogInterface.OnKeyListener() { public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) MainActivity.this.finish(); if (keyCode < KeyEvent.KEYCODE_DPAD_UP || keyCode > KeyEvent.KEYCODE_DPAD_CENTER) return true; else return false; }//from w w w .j a va 2 s. c o m }).setPositiveButton(getString(R.string.main_activity_ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { EasyTracker.getTracker().trackEvent("ui_action", "button_press", "meshclient_positive", value); startGooglePlayMeshclient(noroot ? "fail_noroot" : "fail"); } }) .setNegativeButton(getString(R.string.main_activity_cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { EasyTracker.getTracker().trackEvent("ui_action", "button_press", "meshclient_negative", value); } }).create(); dialog.show(); return dialog; }
From source file:android.support.v17.leanback.widget.GridWidgetTest.java
public void testNonFocusableVertical() throws Throwable { final int numItems = 200; final int startPos = 44; final int skips = 20; final int numColumns = 3; final int endPos = startPos + numColumns * (skips + 1); mInstrumentation = getInstrumentation(); Intent intent = new Intent(mInstrumentation.getContext(), GridActivity.class); intent.putExtra(GridActivity.EXTRA_LAYOUT_RESOURCE_ID, R.layout.vertical_grid); intent.putExtra(GridActivity.EXTRA_NUM_ITEMS, numItems); intent.putExtra(GridActivity.EXTRA_STAGGERED, false); mOrientation = BaseGridView.VERTICAL; mNumRows = numColumns;/*from www. j a v a 2 s. c om*/ boolean[] focusable = new boolean[numItems]; for (int i = 0; i < focusable.length; i++) { focusable[i] = true; } for (int i = startPos + mNumRows, j = 0; j < skips; i += mNumRows, j++) { focusable[i] = false; } intent.putExtra(GridActivity.EXTRA_ITEMS_FOCUSABLE, focusable); initActivity(intent); mGridView.setSelectedPositionSmooth(startPos); waitForScrollIdle(mVerifyLayout); sendKeys(KeyEvent.KEYCODE_DPAD_DOWN); waitForScrollIdle(mVerifyLayout); assertEquals(endPos, mGridView.getSelectedPosition()); sendKeys(KeyEvent.KEYCODE_DPAD_UP); waitForScrollIdle(mVerifyLayout); assertEquals(startPos, mGridView.getSelectedPosition()); }
From source file:org.distantshoresmedia.keyboard.LatinIME.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_BACK: if (event.getRepeatCount() == 0 && mKeyboardSwitcher.getInputView() != null) { if (mKeyboardSwitcher.getInputView().handleBack()) { return true; } else if (mTutorial != null) { mTutorial.close();/* w ww. j a va 2s . co m*/ mTutorial = null; } } break; case KeyEvent.KEYCODE_DPAD_DOWN: case KeyEvent.KEYCODE_DPAD_UP: case KeyEvent.KEYCODE_DPAD_LEFT: case KeyEvent.KEYCODE_DPAD_RIGHT: // If tutorial is visible, don't allow dpad to work if (mTutorial != null) { return true; } break; case KeyEvent.KEYCODE_VOLUME_UP: if (!mVolUpAction.equals("none") && isKeyboardVisible()) { return true; } break; case KeyEvent.KEYCODE_VOLUME_DOWN: if (!mVolDownAction.equals("none") && isKeyboardVisible()) { return true; } break; } return super.onKeyDown(keyCode, event); }
From source file:org.pocketworkstation.pckeyboard.LatinIME.java
@Override public boolean onKeyUp(int keyCode, KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_DPAD_DOWN: case KeyEvent.KEYCODE_DPAD_UP: case KeyEvent.KEYCODE_DPAD_LEFT: case KeyEvent.KEYCODE_DPAD_RIGHT: LatinKeyboardView inputView = mKeyboardSwitcher.getInputView(); // Enable shift key and DPAD to do selections if (inputView != null && inputView.isShown() && inputView.getShiftState() == Keyboard.SHIFT_ON) { event = new KeyEvent(event.getDownTime(), event.getEventTime(), event.getAction(), event.getKeyCode(), event.getRepeatCount(), event.getDeviceId(), event.getScanCode(), KeyEvent.META_SHIFT_LEFT_ON | KeyEvent.META_SHIFT_ON); InputConnection ic = getCurrentInputConnection(); if (ic != null) ic.sendKeyEvent(event);/*from w w w . ja va2s.co m*/ return true; } break; case KeyEvent.KEYCODE_VOLUME_UP: if (!mVolUpAction.equals("none") && isKeyboardVisible()) { return doSwipeAction(mVolUpAction); } break; case KeyEvent.KEYCODE_VOLUME_DOWN: if (!mVolDownAction.equals("none") && isKeyboardVisible()) { return doSwipeAction(mVolDownAction); } break; } return super.onKeyUp(keyCode, event); }
From source file:org.distantshoresmedia.keyboard.LatinIME.java
@Override public boolean onKeyUp(int keyCode, KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_DPAD_DOWN: case KeyEvent.KEYCODE_DPAD_UP: case KeyEvent.KEYCODE_DPAD_LEFT: case KeyEvent.KEYCODE_DPAD_RIGHT: // If tutorial is visible, don't allow dpad to work if (mTutorial != null) { return true; }/* w w w . j a v a 2s. c o m*/ TKKeyboardView inputView = mKeyboardSwitcher.getInputView(); // Enable shift key and DPAD to do selections if (inputView != null && inputView.isShown() && inputView.getShiftState() == Keyboard.SHIFT_ON) { event = new KeyEvent(event.getDownTime(), event.getEventTime(), event.getAction(), event.getKeyCode(), event.getRepeatCount(), event.getDeviceId(), event.getScanCode(), KeyEvent.META_SHIFT_LEFT_ON | KeyEvent.META_SHIFT_ON); InputConnection ic = getCurrentInputConnection(); if (ic != null) ic.sendKeyEvent(event); return true; } break; case KeyEvent.KEYCODE_VOLUME_UP: if (!mVolUpAction.equals("none") && isKeyboardVisible()) { return doSwipeAction(mVolUpAction); } break; case KeyEvent.KEYCODE_VOLUME_DOWN: if (!mVolDownAction.equals("none") && isKeyboardVisible()) { return doSwipeAction(mVolDownAction); } break; } return super.onKeyUp(keyCode, event); }
From source file:com.fishstix.dosboxfree.DBGLSurfaceView.java
@Override public boolean onKeyUp(int keyCode, final KeyEvent event) { if (mDebug)// w ww .ja va2s.co m Log.d("DosBoxTurbo", "onKeyUp keyCode=" + keyCode); if (mEnableDpad) { switch (keyCode) { // DPAD / TRACKBALL case KeyEvent.KEYCODE_DPAD_UP: case KeyEvent.KEYCODE_DPAD_DOWN: case KeyEvent.KEYCODE_DPAD_LEFT: case KeyEvent.KEYCODE_DPAD_RIGHT: if ((mInputMode == INPUT_MODE_JOYSTICK) || (mInputMode == INPUT_MODE_REAL_JOYSTICK)) { DosBoxControl.nativeJoystick(0, 0, 2, -1); } return true; case KeyEvent.KEYCODE_DPAD_CENTER: // button if ((mInputMode == INPUT_MODE_MOUSE) || (mInputMode == INPUT_MODE_REAL_MOUSE)) { DosBoxControl.nativeMouse(0, 0, 0, 0, 1, BTN_A); } else if ((mInputMode == INPUT_MODE_JOYSTICK) || (mInputMode == INPUT_MODE_REAL_JOYSTICK)) { DosBoxControl.nativeJoystick(0, 0, 1, BTN_A); } return true; } } return handleKey(keyCode, 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 ww w . ja v a2 s . c om*/ */ 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.yek.keyboard.anysoftkeyboard.AnySoftKeyboard.java
private void onFunctionKey(final int primaryCode, final Keyboard.Key key, final int multiTapIndex, final int[] nearByKeyCodes, final boolean fromUI) { if (BuildConfig.DEBUG) Logger.d(TAG, "onFunctionKey %d", primaryCode); final InputConnection ic = getCurrentInputConnection(); switch (primaryCode) { case KeyCodes.DELETE: if (ic == null)// if we don't want to do anything, lets check null first. break; // we do backword if the shift is pressed while pressing // backspace (like in a PC) if (mAskPrefs.useBackword() && mShiftKeyState.isPressed() && !mShiftKeyState.isLocked()) { handleBackWord(ic);//from ww w. ja va 2s.c o m } else { handleDeleteLastCharacter(false); } break; case KeyCodes.SHIFT: if (fromUI) { handleShift(); } else { //not from UI (user not actually pressed that button) onPress(primaryCode); onRelease(primaryCode); } break; case KeyCodes.SHIFT_LOCK: mShiftKeyState.toggleLocked(); handleShift(); break; case KeyCodes.DELETE_WORD: if (ic == null)// if we don't want to do anything, lets check // null first. break; handleBackWord(ic); break; case KeyCodes.CLEAR_INPUT: if (ic != null) { ic.beginBatchEdit(); abortCorrectionAndResetPredictionState(false); ic.deleteSurroundingText(Integer.MAX_VALUE, Integer.MAX_VALUE); ic.endBatchEdit(); } break; case KeyCodes.CTRL: if (fromUI) { handleControl(); } else { //not from UI (user not actually pressed that button) onPress(primaryCode); onRelease(primaryCode); } break; case KeyCodes.CTRL_LOCK: mControlKeyState.toggleLocked(); handleControl(); break; case KeyCodes.ARROW_LEFT: case KeyCodes.ARROW_RIGHT: final int keyEventKeyCode = primaryCode == KeyCodes.ARROW_LEFT ? KeyEvent.KEYCODE_DPAD_LEFT : KeyEvent.KEYCODE_DPAD_RIGHT; if (!handleSelectionExpending(keyEventKeyCode, ic, mGlobalSelectionStartPosition, mGlobalCursorPosition)) { sendDownUpKeyEvents(keyEventKeyCode); } break; case KeyCodes.ARROW_UP: sendDownUpKeyEvents(KeyEvent.KEYCODE_DPAD_UP); break; case KeyCodes.ARROW_DOWN: sendDownUpKeyEvents(KeyEvent.KEYCODE_DPAD_DOWN); break; case KeyCodes.MOVE_HOME: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { sendDownUpKeyEvents(0x0000007a/*API 11:KeyEvent.KEYCODE_MOVE_HOME*/); } else { if (ic != null) { CharSequence textBefore = ic.getTextBeforeCursor(1024, 0); if (!TextUtils.isEmpty(textBefore)) { int newPosition = textBefore.length() - 1; while (newPosition > 0) { char chatAt = textBefore.charAt(newPosition - 1); if (chatAt == '\n' || chatAt == '\r') { break; } newPosition--; } if (newPosition < 0) newPosition = 0; ic.setSelection(newPosition, newPosition); } } } break; case KeyCodes.MOVE_END: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { //API 11: KeyEvent.KEYCODE_MOVE_END sendDownUpKeyEvents(0x0000007b); } else { if (ic != null) { CharSequence textAfter = ic.getTextAfterCursor(1024, 0); if (!TextUtils.isEmpty(textAfter)) { int newPosition = 1; while (newPosition < textAfter.length()) { char chatAt = textAfter.charAt(newPosition); if (chatAt == '\n' || chatAt == '\r') { break; } newPosition++; } if (newPosition > textAfter.length()) newPosition = textAfter.length(); try { CharSequence textBefore = ic.getTextBeforeCursor(Integer.MAX_VALUE, 0); if (!TextUtils.isEmpty(textBefore)) { newPosition = newPosition + textBefore.length(); } ic.setSelection(newPosition, newPosition); } catch (Throwable e/*I'm using Integer.MAX_VALUE, it's scary.*/) { Logger.w(TAG, "Failed to getTextBeforeCursor.", e); } } } } break; case KeyCodes.VOICE_INPUT: if (mVoiceRecognitionTrigger.isInstalled()) { mVoiceRecognitionTrigger .startVoiceRecognition(getCurrentAlphabetKeyboard().getDefaultDictionaryLocale()); } else { Intent voiceInputNotInstalledIntent = new Intent(getApplicationContext(), VoiceInputNotInstalledActivity.class); voiceInputNotInstalledIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(voiceInputNotInstalledIntent); } break; case KeyCodes.CANCEL: handleClose(); break; case KeyCodes.SETTINGS: showOptionsMenu(); break; case KeyCodes.SPLIT_LAYOUT: case KeyCodes.MERGE_LAYOUT: case KeyCodes.COMPACT_LAYOUT_TO_RIGHT: case KeyCodes.COMPACT_LAYOUT_TO_LEFT: if (getInputView() != null) { mKeyboardInCondensedMode = CondenseType.fromKeyCode(primaryCode); setKeyboardForView(getCurrentKeyboard()); } break; case KeyCodes.DOMAIN: onText(key, mAskPrefs.getDomainText()); break; case KeyCodes.QUICK_TEXT: onQuickTextRequested(key); break; case KeyCodes.QUICK_TEXT_POPUP: onQuickTextKeyboardRequested(key); break; case KeyCodes.MODE_SYMOBLS: nextKeyboard(getCurrentInputEditorInfo(), KeyboardSwitcher.NextKeyboardType.Symbols); break; case KeyCodes.MODE_ALPHABET: if (getKeyboardSwitcher().shouldPopupForLanguageSwitch()) { showLanguageSelectionDialog(); } else { nextKeyboard(getCurrentInputEditorInfo(), KeyboardSwitcher.NextKeyboardType.Alphabet); } break; case KeyCodes.UTILITY_KEYBOARD: getInputView().openUtilityKeyboard(); break; case KeyCodes.MODE_ALPHABET_POPUP: showLanguageSelectionDialog(); break; case KeyCodes.ALT: nextAlterKeyboard(getCurrentInputEditorInfo()); break; case KeyCodes.KEYBOARD_CYCLE: nextKeyboard(getCurrentInputEditorInfo(), KeyboardSwitcher.NextKeyboardType.Any); break; case KeyCodes.KEYBOARD_REVERSE_CYCLE: nextKeyboard(getCurrentInputEditorInfo(), KeyboardSwitcher.NextKeyboardType.PreviousAny); break; case KeyCodes.KEYBOARD_CYCLE_INSIDE_MODE: nextKeyboard(getCurrentInputEditorInfo(), KeyboardSwitcher.NextKeyboardType.AnyInsideMode); break; case KeyCodes.KEYBOARD_MODE_CHANGE: nextKeyboard(getCurrentInputEditorInfo(), KeyboardSwitcher.NextKeyboardType.OtherMode); break; case KeyCodes.CLIPBOARD_COPY: case KeyCodes.CLIPBOARD_PASTE: case KeyCodes.CLIPBOARD_CUT: case KeyCodes.CLIPBOARD_SELECT_ALL: case KeyCodes.CLIPBOARD_PASTE_POPUP: case KeyCodes.CLIPBOARD_SELECT: handleClipboardOperation(key, primaryCode, ic); //not allowing undo on-text in clipboard paste operations. if (primaryCode == KeyCodes.CLIPBOARD_PASTE) mCommittedWord = ""; break; default: if (BuildConfig.DEBUG) { //this should not happen! We should handle ALL function keys. throw new RuntimeException("UNHANDLED FUNCTION KEY! primary code " + primaryCode); } else { Logger.w(TAG, "UNHANDLED FUNCTION KEY! primary code %d. Ignoring.", primaryCode); } } }
From source file:com.anysoftkeyboard.AnySoftKeyboard.java
private void onFunctionKey(final int primaryCode, final Key key, final int multiTapIndex, final int[] nearByKeyCodes, final boolean fromUI) { if (BuildConfig.DEBUG) Logger.d(TAG, "onFunctionKey %d", primaryCode); final InputConnection ic = getCurrentInputConnection(); switch (primaryCode) { case KeyCodes.DELETE: if (ic == null)// if we don't want to do anything, lets check null first. break; // we do backword if the shift is pressed while pressing // backspace (like in a PC) if (mAskPrefs.useBackword() && mShiftKeyState.isPressed() && !mShiftKeyState.isLocked()) { handleBackWord(ic);/*from w ww.java 2 s . c o m*/ } else { handleDeleteLastCharacter(false); } break; case KeyCodes.SHIFT: if (fromUI) { handleShift(); } else { //not from UI (user not actually pressed that button) onPress(primaryCode); onRelease(primaryCode); } break; case KeyCodes.SHIFT_LOCK: mShiftKeyState.toggleLocked(); handleShift(); break; case KeyCodes.DELETE_WORD: if (ic == null)// if we don't want to do anything, lets check // null first. break; handleBackWord(ic); break; case KeyCodes.CLEAR_INPUT: if (ic != null) { ic.beginBatchEdit(); abortCorrectionAndResetPredictionState(false); ic.deleteSurroundingText(Integer.MAX_VALUE, Integer.MAX_VALUE); ic.endBatchEdit(); } break; case KeyCodes.CTRL: if (fromUI) { handleControl(); } else { //not from UI (user not actually pressed that button) onPress(primaryCode); onRelease(primaryCode); } break; case KeyCodes.CTRL_LOCK: mControlKeyState.toggleLocked(); handleControl(); break; case KeyCodes.ARROW_LEFT: case KeyCodes.ARROW_RIGHT: final int keyEventKeyCode = primaryCode == KeyCodes.ARROW_LEFT ? KeyEvent.KEYCODE_DPAD_LEFT : KeyEvent.KEYCODE_DPAD_RIGHT; if (!handleSelectionExpending(keyEventKeyCode, ic, mGlobalSelectionStartPosition, mGlobalCursorPosition)) { sendDownUpKeyEvents(keyEventKeyCode); } break; case KeyCodes.ARROW_UP: sendDownUpKeyEvents(KeyEvent.KEYCODE_DPAD_UP); break; case KeyCodes.ARROW_DOWN: sendDownUpKeyEvents(KeyEvent.KEYCODE_DPAD_DOWN); break; case KeyCodes.MOVE_HOME: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { sendDownUpKeyEvents(0x0000007a/*API 11:KeyEvent.KEYCODE_MOVE_HOME*/); } else { if (ic != null) { CharSequence textBefore = ic.getTextBeforeCursor(1024, 0); if (!TextUtils.isEmpty(textBefore)) { int newPosition = textBefore.length() - 1; while (newPosition > 0) { char chatAt = textBefore.charAt(newPosition - 1); if (chatAt == '\n' || chatAt == '\r') { break; } newPosition--; } if (newPosition < 0) newPosition = 0; ic.setSelection(newPosition, newPosition); } } } break; case KeyCodes.MOVE_END: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { //API 11: KeyEvent.KEYCODE_MOVE_END sendDownUpKeyEvents(0x0000007b); } else { if (ic != null) { CharSequence textAfter = ic.getTextAfterCursor(1024, 0); if (!TextUtils.isEmpty(textAfter)) { int newPosition = 1; while (newPosition < textAfter.length()) { char chatAt = textAfter.charAt(newPosition); if (chatAt == '\n' || chatAt == '\r') { break; } newPosition++; } if (newPosition > textAfter.length()) newPosition = textAfter.length(); try { CharSequence textBefore = ic.getTextBeforeCursor(Integer.MAX_VALUE, 0); if (!TextUtils.isEmpty(textBefore)) { newPosition = newPosition + textBefore.length(); } ic.setSelection(newPosition, newPosition); } catch (Throwable e/*I'm using Integer.MAX_VALUE, it's scary.*/) { Logger.w(TAG, "Failed to getTextBeforeCursor.", e); } } } } break; case KeyCodes.VOICE_INPUT: if (mVoiceRecognitionTrigger.isInstalled()) { mVoiceRecognitionTrigger .startVoiceRecognition(getCurrentAlphabetKeyboard().getDefaultDictionaryLocale()); } else { Intent voiceInputNotInstalledIntent = new Intent(getApplicationContext(), VoiceInputNotInstalledActivity.class); voiceInputNotInstalledIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(voiceInputNotInstalledIntent); } break; case KeyCodes.CANCEL: hideWindow(); break; case KeyCodes.SETTINGS: showOptionsMenu(); break; case KeyCodes.SPLIT_LAYOUT: case KeyCodes.MERGE_LAYOUT: case KeyCodes.COMPACT_LAYOUT_TO_RIGHT: case KeyCodes.COMPACT_LAYOUT_TO_LEFT: if (getInputView() != null) { mKeyboardInCondensedMode = CondenseType.fromKeyCode(primaryCode); setKeyboardForView(getCurrentKeyboard()); } break; case KeyCodes.DOMAIN: onText(key, mAskPrefs.getDomainText()); break; case KeyCodes.QUICK_TEXT: onQuickTextRequested(key); break; case KeyCodes.QUICK_TEXT_POPUP: onQuickTextKeyboardRequested(key); break; case KeyCodes.MODE_SYMOBLS: nextKeyboard(getCurrentInputEditorInfo(), NextKeyboardType.Symbols); break; case KeyCodes.MODE_ALPHABET: if (getKeyboardSwitcher().shouldPopupForLanguageSwitch()) { showLanguageSelectionDialog(); } else { nextKeyboard(getCurrentInputEditorInfo(), NextKeyboardType.Alphabet); } break; case KeyCodes.UTILITY_KEYBOARD: getInputView().openUtilityKeyboard(); break; case KeyCodes.MODE_ALPHABET_POPUP: showLanguageSelectionDialog(); break; case KeyCodes.ALT: nextAlterKeyboard(getCurrentInputEditorInfo()); break; case KeyCodes.KEYBOARD_CYCLE: nextKeyboard(getCurrentInputEditorInfo(), NextKeyboardType.Any); break; case KeyCodes.KEYBOARD_REVERSE_CYCLE: nextKeyboard(getCurrentInputEditorInfo(), NextKeyboardType.PreviousAny); break; case KeyCodes.KEYBOARD_CYCLE_INSIDE_MODE: nextKeyboard(getCurrentInputEditorInfo(), NextKeyboardType.AnyInsideMode); break; case KeyCodes.KEYBOARD_MODE_CHANGE: nextKeyboard(getCurrentInputEditorInfo(), NextKeyboardType.OtherMode); break; case KeyCodes.CLIPBOARD_COPY: case KeyCodes.CLIPBOARD_PASTE: case KeyCodes.CLIPBOARD_CUT: case KeyCodes.CLIPBOARD_SELECT_ALL: case KeyCodes.CLIPBOARD_PASTE_POPUP: case KeyCodes.CLIPBOARD_SELECT: handleClipboardOperation(key, primaryCode, ic); //not allowing undo on-text in clipboard paste operations. if (primaryCode == KeyCodes.CLIPBOARD_PASTE) mCommittedWord = ""; break; default: if (BuildConfig.DEBUG) { //this should not happen! We should handle ALL function keys. throw new RuntimeException("UNHANDLED FUNCTION KEY! primary code " + primaryCode); } else { Logger.w(TAG, "UNHANDLED FUNCTION KEY! primary code %d. Ignoring.", primaryCode); } } }
From source file:com.appunite.list.GridView.java
private boolean commonKey(int keyCode, int count, KeyEvent event) { if (mAdapter == null) { return false; }//from w w w. j a v a2 s . c o 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; } }