Java Code Examples for android.view.KeyEvent#isShiftPressed()
The following examples show how to use
android.view.KeyEvent#isShiftPressed() .
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: EditMessage.java From Conversations with GNU General Public License v3.0 | 6 votes |
@Override public boolean onKeyDown(int keyCode, KeyEvent e) { if (keyCode == KeyEvent.KEYCODE_ENTER && !e.isShiftPressed()) { lastInputWasTab = false; if (keyboardListener != null && keyboardListener.onEnterPressed()) { return true; } } else if (keyCode == KeyEvent.KEYCODE_TAB && !e.isAltPressed() && !e.isCtrlPressed()) { if (keyboardListener != null && keyboardListener.onTabPressed(this.lastInputWasTab)) { lastInputWasTab = true; return true; } } else { lastInputWasTab = false; } return super.onKeyDown(keyCode, e); }
Example 2
Source File: UI.java From GreenBits with GNU General Public License v3.0 | 6 votes |
public static TextView.OnEditorActionListener getListenerRunOnEnter(final Runnable r) { return new EditText.OnEditorActionListener() { @Override public boolean onEditorAction(final TextView v, final int actionId, final KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_DONE || actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_SEND || isEnterKeyDown(event)) { if (event == null || !event.isShiftPressed()) { r.run(); // The user is done typing. return true; // Consume. } } return false; // Pass on to other listeners. } }; }
Example 3
Source File: EditMessage.java From Pix-Art-Messenger with GNU General Public License v3.0 | 6 votes |
@Override public boolean onKeyDown(int keyCode, KeyEvent e) { if (keyCode == KeyEvent.KEYCODE_ENTER && !e.isShiftPressed()) { lastInputWasTab = false; if (keyboardListener != null && keyboardListener.onEnterPressed()) { return true; } } else if (keyCode == KeyEvent.KEYCODE_TAB && !e.isAltPressed() && !e.isCtrlPressed()) { if (keyboardListener != null && keyboardListener.onTabPressed(this.lastInputWasTab)) { lastInputWasTab = true; return true; } } else { lastInputWasTab = false; } return super.onKeyDown(keyCode, e); }
Example 4
Source File: FreeScrollingTextField.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
private void handleNavigationKey(int keyCode, KeyEvent event) { if (event.isShiftPressed() && !isSelectText()) { invalidateCaretRow(); _fieldController.setSelectText(true); } else if (!event.isShiftPressed() && isSelectText()) { invalidateSelectionRows(); _fieldController.setSelectText(false); } switch (keyCode) { case KeyEvent.KEYCODE_DPAD_RIGHT: _fieldController.moveCaretRight(false); break; case KeyEvent.KEYCODE_DPAD_LEFT: _fieldController.moveCaretLeft(false); break; case KeyEvent.KEYCODE_DPAD_DOWN: _fieldController.moveCaretDown(); break; case KeyEvent.KEYCODE_DPAD_UP: _fieldController.moveCaretUp(); break; default: break; } }
Example 5
Source File: FreeScrollingTextField.java From CodeEditor with Apache License 2.0 | 6 votes |
private void handleNavigationKey(int keyCode, KeyEvent event) { if (event.isShiftPressed() && !isSelectText()) { invalidateCaretRow(); _fieldController.setSelectText(true); } else if (!event.isShiftPressed() && isSelectText()) { invalidateSelectionRows(); _fieldController.setSelectText(false); } switch (keyCode) { case KeyEvent.KEYCODE_DPAD_RIGHT: _fieldController.moveCaretRight(false); break; case KeyEvent.KEYCODE_DPAD_LEFT: _fieldController.moveCaretLeft(false); break; case KeyEvent.KEYCODE_DPAD_DOWN: _fieldController.moveCaretDown(); break; case KeyEvent.KEYCODE_DPAD_UP: _fieldController.moveCaretUp(); break; default: break; } }
Example 6
Source File: FreeScrollingTextField.java From CodeEditor with Apache License 2.0 | 6 votes |
private void handleNavigationKey(int keyCode, KeyEvent event) { if (event.isShiftPressed() && !isSelectText()) { invalidateCaretRow(); _fieldController.setSelectText(true); } else if (!event.isShiftPressed() && isSelectText()) { invalidateSelectionRows(); _fieldController.setSelectText(false); } switch (keyCode) { case KeyEvent.KEYCODE_DPAD_RIGHT: _fieldController.moveCaretRight(false); break; case KeyEvent.KEYCODE_DPAD_LEFT: _fieldController.moveCaretLeft(false); break; case KeyEvent.KEYCODE_DPAD_DOWN: _fieldController.moveCaretDown(); break; case KeyEvent.KEYCODE_DPAD_UP: _fieldController.moveCaretUp(); break; default: break; } }
Example 7
Source File: KeyboardNavigationListener.java From AndroidChromium with Apache License 2.0 | 5 votes |
@Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_TAB && event.getAction() == KeyEvent.ACTION_DOWN) { if (event.hasNoModifiers()) { View forward = getNextFocusForward(); if (forward != null) return forward.requestFocus(); } else if (event.isShiftPressed()) { View backward = getNextFocusBackward(); if (backward != null) return backward.requestFocus(); } } else if (keyCode == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_UP) { return handleEnterKeyPress(); } return false; }
Example 8
Source File: BaseSlider.java From material-components-android with Apache License 2.0 | 5 votes |
private Boolean onKeyDownNoActiveThumb(int keyCode, @NonNull KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_TAB: if (event.hasNoModifiers()) { return moveFocus(1); } if (event.isShiftPressed()) { return moveFocus(-1); } return false; case KeyEvent.KEYCODE_DPAD_LEFT: moveFocusInAbsoluteDirection(-1); return true; case KeyEvent.KEYCODE_MINUS: moveFocus(-1); return true; case KeyEvent.KEYCODE_DPAD_RIGHT: moveFocusInAbsoluteDirection(1); return true; case KeyEvent.KEYCODE_EQUALS: // Numpad Plus == Shift + Equals, at least in AVD, so fall through. case KeyEvent.KEYCODE_PLUS: moveFocus(1); return true; case KeyEvent.KEYCODE_DPAD_CENTER: case KeyEvent.KEYCODE_ENTER: activeThumbIdx = focusedThumbIdx; postInvalidate(); return true; default: // Nothing to do in this case. } return null; }
Example 9
Source File: KeyAssignmentUtils.java From talkback with Apache License 2.0 | 5 votes |
/** * Convert a KeyEvent into a long which can be kept in settings and compared to key presses when * the service is in use. * * @param keyEvent The key event to convert. The (non-extended) keycode must not be a modifier. * @return An extended key code that includes modifier information */ public static long keyEventToExtendedKeyCode(KeyEvent keyEvent) { long returnValue = keyEvent.getKeyCode(); returnValue |= (keyEvent.isShiftPressed()) ? (((long) KeyEvent.META_SHIFT_ON) << 32) : 0; returnValue |= (keyEvent.isCtrlPressed()) ? (((long) KeyEvent.META_CTRL_ON) << 32) : 0; returnValue |= (keyEvent.isAltPressed()) ? (((long) KeyEvent.META_ALT_ON) << 32) : 0; return returnValue; }
Example 10
Source File: HardwareKeyboardEventDecoder.java From Indic-Keyboard with Apache License 2.0 | 4 votes |
@Override public Event decodeHardwareKey(final KeyEvent keyEvent) { // KeyEvent#getUnicodeChar() does not exactly returns a unicode char, but rather a value // that includes both the unicode char in the lower 21 bits and flags in the upper bits, // hence the name "codePointAndFlags". {@see KeyEvent#getUnicodeChar()} for more info. final int codePointAndFlags = keyEvent.getUnicodeChar(); // The keyCode is the abstraction used by the KeyEvent to represent different keys that // do not necessarily map to a unicode character. This represents a physical key, like // the key for 'A' or Space, but also Backspace or Ctrl or Caps Lock. final int keyCode = keyEvent.getKeyCode(); final boolean isKeyRepeat = (0 != keyEvent.getRepeatCount()); if (KeyEvent.KEYCODE_DEL == keyCode) { return Event.createHardwareKeypressEvent(Event.NOT_A_CODE_POINT, Constants.CODE_DELETE, null /* next */, isKeyRepeat); } if (keyEvent.isPrintingKey() || KeyEvent.KEYCODE_SPACE == keyCode || KeyEvent.KEYCODE_ENTER == keyCode) { if (0 != (codePointAndFlags & KeyCharacterMap.COMBINING_ACCENT)) { // A dead key. return Event.createDeadEvent( codePointAndFlags & KeyCharacterMap.COMBINING_ACCENT_MASK, keyCode, null /* next */); } if (KeyEvent.KEYCODE_ENTER == keyCode) { // The Enter key. If the Shift key is not being pressed, this should send a // CODE_ENTER to trigger the action if any, or a carriage return otherwise. If the // Shift key is being pressed, this should send a CODE_SHIFT_ENTER and let // Latin IME decide what to do with it. if (keyEvent.isShiftPressed()) { return Event.createHardwareKeypressEvent(Event.NOT_A_CODE_POINT, Constants.CODE_SHIFT_ENTER, null /* next */, isKeyRepeat); } return Event.createHardwareKeypressEvent(Constants.CODE_ENTER, keyCode, null /* next */, isKeyRepeat); } // If not Enter, then this is just a regular keypress event for a normal character // that can be committed right away, taking into account the current state. return Event.createHardwareKeypressEvent(codePointAndFlags, keyCode, null /* next */, isKeyRepeat); } return Event.createNotHandledEvent(); }
Example 11
Source File: KeyboardShortcuts.java From 365browser with Apache License 2.0 | 4 votes |
private static int getMetaState(KeyEvent event) { return (event.isCtrlPressed() ? CTRL : 0) | (event.isAltPressed() ? ALT : 0) | (event.isShiftPressed() ? SHIFT : 0); }
Example 12
Source File: KeysInterpreter.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 4 votes |
public static boolean isSwitchPanel(KeyEvent event) { return (event.isShiftPressed() && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)); }
Example 13
Source File: KeysInterpreter.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 4 votes |
private static boolean isTab(KeyEvent event) { return (event.isShiftPressed() && (event.getKeyCode() == KeyEvent.KEYCODE_SPACE)) || (event.getKeyCode() == KeyEvent.KEYCODE_TAB); }
Example 14
Source File: KeysInterpreter.java From CodeEditor with Apache License 2.0 | 4 votes |
private static boolean isTab(KeyEvent event){ return (event.isShiftPressed() && (event.getKeyCode() == KeyEvent.KEYCODE_SPACE)) || (event.getKeyCode() == KeyEvent.KEYCODE_TAB); }
Example 15
Source File: HardwareKeyboardEventDecoder.java From AOSP-Kayboard-7.1.2 with Apache License 2.0 | 4 votes |
@Override public Event decodeHardwareKey(final KeyEvent keyEvent) { // KeyEvent#getUnicodeChar() does not exactly returns a unicode char, but rather a value // that includes both the unicode char in the lower 21 bits and flags in the upper bits, // hence the name "codePointAndFlags". {@see KeyEvent#getUnicodeChar()} for more info. final int codePointAndFlags = keyEvent.getUnicodeChar(); // The keyCode is the abstraction used by the KeyEvent to represent different keys that // do not necessarily map to a unicode character. This represents a physical key, like // the key for 'A' or Space, but also Backspace or Ctrl or Caps Lock. final int keyCode = keyEvent.getKeyCode(); final boolean isKeyRepeat = (0 != keyEvent.getRepeatCount()); if (KeyEvent.KEYCODE_DEL == keyCode) { return Event.createHardwareKeypressEvent(Event.NOT_A_CODE_POINT, Constants.CODE_DELETE, null /* next */, isKeyRepeat); } if (keyEvent.isPrintingKey() || KeyEvent.KEYCODE_SPACE == keyCode || KeyEvent.KEYCODE_ENTER == keyCode) { if (0 != (codePointAndFlags & KeyCharacterMap.COMBINING_ACCENT)) { // A dead key. return Event.createDeadEvent( codePointAndFlags & KeyCharacterMap.COMBINING_ACCENT_MASK, keyCode, null /* next */); } if (KeyEvent.KEYCODE_ENTER == keyCode) { // The Enter key. If the Shift key is not being pressed, this should send a // CODE_ENTER to trigger the action if any, or a carriage return otherwise. If the // Shift key is being pressed, this should send a CODE_SHIFT_ENTER and let // Latin IME decide what to do with it. if (keyEvent.isShiftPressed()) { return Event.createHardwareKeypressEvent(Event.NOT_A_CODE_POINT, Constants.CODE_SHIFT_ENTER, null /* next */, isKeyRepeat); } return Event.createHardwareKeypressEvent(Constants.CODE_ENTER, keyCode, null /* next */, isKeyRepeat); } // If not Enter, then this is just a regular keypress event for a normal character // that can be committed right away, taking into account the current state. return Event.createHardwareKeypressEvent(codePointAndFlags, keyCode, null /* next */, isKeyRepeat); } return Event.createNotHandledEvent(); }
Example 16
Source File: KeysInterpreter.java From CodeEditor with Apache License 2.0 | 4 votes |
public static boolean isSwitchPanel(KeyEvent event){ return (event.isShiftPressed() && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)); }
Example 17
Source File: KeyboardShortcuts.java From delion with Apache License 2.0 | 4 votes |
private static int getMetaState(KeyEvent event) { return (event.isCtrlPressed() ? CTRL : 0) | (event.isAltPressed() ? ALT : 0) | (event.isShiftPressed() ? SHIFT : 0); }
Example 18
Source File: FastEdit.java From fastedit with Apache License 2.0 | 4 votes |
void onKeyEvent(KeyEvent event) { int action = event.getAction(); int keyCode = event.getKeyCode(); switch (action) { case KeyEvent.ACTION_DOWN: { //输入模式 int unicodeChar = event.getUnicodeChar(); if (unicodeChar != 0) { input((char) unicodeChar); event.cancel(); } if (!event.isCanceled() && !event.isCtrlPressed() && !event.isAltPressed() && !event.isShiftPressed()) { switch (keyCode) { case KeyEvent.KEYCODE_TAB: //tab input(tabText); event.cancel(); break; case KeyEvent.KEYCODE_SPACE: //空格 input(' '); event.cancel(); break; case KeyEvent.KEYCODE_ENTER: //enter onKeyCodeEnter(event); event.cancel(); break; case KeyEvent.KEYCODE_DEL: //del onKeyCodeDel(event); event.cancel(); break; case KeyEvent.KEYCODE_FORWARD_DEL: //del onKeyCodeForwardDel(event); event.cancel(); break; case KeyEvent.KEYCODE_DPAD_LEFT: //left onKeyCodeDpadLeft(event); event.cancel(); break; case KeyEvent.KEYCODE_DPAD_RIGHT: //right onKeyCodeDpadRight(event); event.cancel(); break; case KeyEvent.KEYCODE_DPAD_UP: //up onKeyCodeDpadUp(event); event.cancel(); break; case KeyEvent.KEYCODE_DPAD_DOWN: //down onKeyCodeDpadDown(event); event.cancel(); break; case KeyEvent.KEYCODE_VOLUME_DOWN: case KeyEvent.KEYCODE_PAGE_DOWN: //page down onKeyCodePageDown(event); event.cancel(); break; case KeyEvent.KEYCODE_VOLUME_UP: case KeyEvent.KEYCODE_PAGE_UP: //page up onKeyCodePageUp(event); event.cancel(); break; case KeyEvent.KEYCODE_MOVE_HOME: onKeyCodeMoveHome(event); event.cancel(); break; case KeyEvent.KEYCODE_MOVE_END: onKeyCodeMoveEnd(event); event.cancel(); break; } } if (!event.isCanceled()) { //快捷键模式 if (onShortKey(event.isCtrlPressed(), event.isAltPressed(), event.isShiftPressed(), keyCode)) { event.cancel(); } } break; } } }
Example 19
Source File: SudokuBoardView.java From opensudoku with GNU General Public License v3.0 | 4 votes |
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (!mReadonly) { switch (keyCode) { case KeyEvent.KEYCODE_DPAD_UP: return moveCellSelection(0, -1); case KeyEvent.KEYCODE_DPAD_RIGHT: return moveCellSelection(1, 0); case KeyEvent.KEYCODE_DPAD_DOWN: return moveCellSelection(0, 1); case KeyEvent.KEYCODE_DPAD_LEFT: return moveCellSelection(-1, 0); case KeyEvent.KEYCODE_0: case KeyEvent.KEYCODE_SPACE: case KeyEvent.KEYCODE_DEL: // clear value in selected cell // TODO: I'm not really sure that this is thread-safe if (mSelectedCell != null) { if (event.isShiftPressed() || event.isAltPressed()) { setCellNote(mSelectedCell, CellNote.EMPTY); } else { setCellValue(mSelectedCell, 0); moveCellSelectionRight(); } } return true; case KeyEvent.KEYCODE_DPAD_CENTER: if (mSelectedCell != null) { onCellTapped(mSelectedCell); } return true; } if (keyCode >= KeyEvent.KEYCODE_1 && keyCode <= KeyEvent.KEYCODE_9 && mSelectedCell != null) { int selNumber = keyCode - KeyEvent.KEYCODE_0; Cell cell = mSelectedCell; if (event.isShiftPressed() || event.isAltPressed()) { // add or remove number in cell's note setCellNote(cell, cell.getNote().toggleNumber(selNumber)); } else { // enter number in cell setCellValue(cell, selNumber); moveCellSelectionRight(); } return true; } } return false; }
Example 20
Source File: BaseSlider.java From material-components-android with Apache License 2.0 | 4 votes |
@Override public boolean onKeyDown(int keyCode, @NonNull KeyEvent event) { if (!isEnabled()) { return super.onKeyDown(keyCode, event); } // If there's only one thumb, we can select it right away. if (values.size() == 1) { activeThumbIdx = 0; } // If there is no active thumb, key events will be used to pick the thumb to change. if (activeThumbIdx == -1) { Boolean handled = onKeyDownNoActiveThumb(keyCode, event); return handled != null ? handled : super.onKeyDown(keyCode, event); } isLongPress |= event.isLongPress(); Float increment = calculateIncrementForKey(keyCode); if (increment != null) { if (snapActiveThumbToValue(values.get(activeThumbIdx) + increment)) { updateHaloHotspot(); postInvalidate(); } return true; } switch (keyCode) { case KeyEvent.KEYCODE_TAB: if (event.hasNoModifiers()) { return moveFocus(1); } if (event.isShiftPressed()) { return moveFocus(-1); } return false; case KeyEvent.KEYCODE_DPAD_CENTER: case KeyEvent.KEYCODE_ENTER: activeThumbIdx = -1; for (TooltipDrawable label : labels) { ViewUtils.getContentViewOverlay(this).remove(label); } postInvalidate(); return true; default: // Nothing to do in this case. } return super.onKeyDown(keyCode, event); }