Java Code Examples for android.view.KeyEvent#KEYCODE_DEL
The following examples show how to use
android.view.KeyEvent#KEYCODE_DEL .
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: TokenCompleteTextView.java From SocialTokenAutoComplete with Apache License 2.0 | 6 votes |
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { boolean handled = false; switch (keyCode) { case KeyEvent.KEYCODE_TAB: case KeyEvent.KEYCODE_ENTER: case KeyEvent.KEYCODE_DPAD_CENTER: if (event.hasNoModifiers()) { shouldFocusNext = true; handled = true; } break; case KeyEvent.KEYCODE_DEL: handled = deleteSelectedObject(false); break; } return handled || super.onKeyDown(keyCode, event); }
Example 2
Source File: BlockEditText.java From BlockEditText with Apache License 2.0 | 6 votes |
private OnKeyListener createKeyListener(final AEditText editText, final int i) { return new OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_DEL) { if (editText.getSelectionStart() == 0 && editText.getSelectionEnd() == 0) { AEditText prevEditText = editTexts.get(i - 1); if (prevEditText != null) { prevEditText.requestFocus(); if (editText.length() > 0) { prevEditText.getEditableText().delete(getText(prevEditText).length() - 1, prevEditText.getText().length()); prevEditText.setSelection(prevEditText.getText().length() - 1); } return true; } } } return false; } }; }
Example 3
Source File: CustomEditText.java From upcKeygen with GNU General Public License v2.0 | 5 votes |
@Override public boolean sendKeyEvent(KeyEvent event) { Log.i(TAG, String.format("sendKeyEvent; action=%d, keyCode=%d", event.getAction(), event.getKeyCode())); if (event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_DEL) { if (backPressedListener != null){ backPressedListener.onDeletePressed(); } // ZanyEditText.this.setRandomBackgroundColor(); // Un-comment if you wish to cancel the backspace: // return false; } return super.sendKeyEvent(event); }
Example 4
Source File: ExpirationEditText.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) { if (getSelectionStart() == 0) { mListener.onCardNumberInputReEntry(); } } return super.sendKeyEvent(event); }
Example 5
Source File: EaseChatPrimaryMenu.java From Social with Apache License 2.0 | 5 votes |
/** * 表情删除 */ public void onEmojiconDeleteEvent(){ if (!TextUtils.isEmpty(editText.getText())) { KeyEvent event = new KeyEvent(0, 0, 0, KeyEvent.KEYCODE_DEL, 0, 0, 0, 0, KeyEvent.KEYCODE_ENDCALL); editText.dispatchKeyEvent(event); } }
Example 6
Source File: RichInputConnectionWrapper.java From RichEditor with MIT License | 5 votes |
/** * 当在软件盘上点击某些按钮(比如退格键,数字键,回车键等),该方法可能会被触发(取决于输入法的开发者), * 所以也可以重写该方法并拦截这些事件,这些事件就不会被分发到输入框了 * @param event * @return */ @Override public boolean sendKeyEvent(KeyEvent event) { if (event.getKeyCode() == KeyEvent.KEYCODE_DEL && event.getAction() == KeyEvent.ACTION_DOWN) { if (mBackspaceListener != null && mBackspaceListener.onBackspace()) { return true; } } return super.sendKeyEvent(event); }
Example 7
Source File: RichEditText.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
@Override public boolean sendKeyEvent(KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_DEL) { if (!RichEditText.this.mTagSpanTextWatcher.checkKeyDel()) return false; } return super.sendKeyEvent(event); }
Example 8
Source File: Pinview.java From Pinview with MIT License | 5 votes |
/** * Monitors keyEvent. * * @param view * @param i * @param keyEvent * @return */ @Override public boolean onKey(View view, int i, KeyEvent keyEvent) { if ((keyEvent.getAction() == KeyEvent.ACTION_UP) && (i == KeyEvent.KEYCODE_DEL)) { // Perform action on Del press int currentTag = getIndexOfCurrentFocus(); //Last tile of the number pad. Clear the edit text without changing the focus. if (inputType == InputType.NUMBER && currentTag == mPinLength - 1 && finalNumberPin || (mPassword && currentTag == mPinLength - 1 && finalNumberPin)) { if (editTextList.get(currentTag).length() > 0) { editTextList.get(currentTag).setText(""); } finalNumberPin = false; } else if (currentTag > 0) { mDelPressed = true; if (editTextList.get(currentTag).length() == 0) { //Takes it back one tile editTextList.get(currentTag - 1).requestFocus(); //Clears the tile it just got to editTextList.get(currentTag).setText(""); } else { //If it has some content clear it first editTextList.get(currentTag).setText(""); } } else { //For the first cell if (editTextList.get(currentTag).getText().length() > 0) editTextList.get(currentTag).setText(""); } return true; } return false; }
Example 9
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 10
Source File: ImeDelBugFixedEditText.java From AndroidFrame with Apache License 2.0 | 5 votes |
@Override public boolean sendKeyEvent(KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_DEL) { if (delKeyEventListener != null) { delKeyEventListener.onDeleteClick(); return true; } } return super.sendKeyEvent(event); }
Example 11
Source File: MenuBuilder.java From zen4android with MIT License | 5 votes |
@SuppressWarnings("deprecation") MenuItemImpl findItemWithShortcutForKey(int keyCode, KeyEvent event) { // Get all items that can be associated directly or indirectly with the keyCode ArrayList<MenuItemImpl> items = mTempShortcutItemList; items.clear(); findItemsWithShortcutForKey(items, keyCode, event); if (items.isEmpty()) { return null; } final int metaState = event.getMetaState(); final KeyCharacterMap.KeyData possibleChars = new KeyCharacterMap.KeyData(); // Get the chars associated with the keyCode (i.e using any chording combo) event.getKeyData(possibleChars); // If we have only one element, we can safely returns it final int size = items.size(); if (size == 1) { return items.get(0); } final boolean qwerty = isQwertyMode(); // If we found more than one item associated with the key, // we have to return the exact match for (int i = 0; i < size; i++) { final MenuItemImpl item = items.get(i); final char shortcutChar = qwerty ? item.getAlphabeticShortcut() : item.getNumericShortcut(); if ((shortcutChar == possibleChars.meta[0] && (metaState & KeyEvent.META_ALT_ON) == 0) || (shortcutChar == possibleChars.meta[2] && (metaState & KeyEvent.META_ALT_ON) != 0) || (qwerty && shortcutChar == '\b' && keyCode == KeyEvent.KEYCODE_DEL)) { return item; } } return null; }
Example 12
Source File: KeyComboManager.java From talkback with Apache License 2.0 | 5 votes |
/** * Returns converted key code. This method converts the following key events. - Convert * KEYCODE_HOME with meta to KEYCODE_ENTER. - Convert KEYCODE_BACK with meta to KEYCODE_DEL. * * @param event Key event to be converted. * @return Converted key code. */ static int getConvertedKeyCode(KeyEvent event) { // We care only when meta key is pressed with. if ((event.getModifiers() & KeyEvent.META_META_ON) == 0) { return event.getKeyCode(); } if (event.getKeyCode() == KeyEvent.KEYCODE_HOME) { return KeyEvent.KEYCODE_ENTER; } else if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) { return KeyEvent.KEYCODE_DEL; } else { return event.getKeyCode(); } }
Example 13
Source File: EmojiEditText.java From hipda with GNU General Public License v2.0 | 4 votes |
public void backspace() { final KeyEvent event = new KeyEvent(0, 0, 0, KeyEvent.KEYCODE_DEL, 0, 0, 0, 0, KeyEvent.KEYCODE_ENDCALL); dispatchKeyEvent(event); }
Example 14
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 15
Source File: ExpressionTransformEngine.java From android-expression with Apache License 2.0 | 4 votes |
public static void delete(EditText editText) { KeyEvent event = new KeyEvent(0, 0, 0, KeyEvent.KEYCODE_DEL, 0, 0, 0, 0, KeyEvent.KEYCODE_ENDCALL); editText.dispatchKeyEvent(event); }
Example 16
Source File: EmojiconsFragment.java From emojicon with Apache License 2.0 | 4 votes |
public static void backspace(EditText editText) { KeyEvent event = new KeyEvent(0, 0, 0, KeyEvent.KEYCODE_DEL, 0, 0, 0, 0, KeyEvent.KEYCODE_ENDCALL); editText.dispatchKeyEvent(event); }
Example 17
Source File: EmojiconsFragment.java From EmojiChat with Apache License 2.0 | 4 votes |
public static void backspace(EditText editText) { KeyEvent event = new KeyEvent(0, 0, 0, KeyEvent.KEYCODE_DEL, 0, 0, 0, 0, KeyEvent.KEYCODE_ENDCALL); editText.dispatchKeyEvent(event); }
Example 18
Source File: TimePickerDialog.java From AlarmOn with Apache License 2.0 | 4 votes |
/** * For keyboard mode, processes key events. * @param keyCode the pressed key. * @return true if the key was successfully processed, false otherwise. */ private boolean processKeyUp(int keyCode) { if (keyCode == KeyEvent.KEYCODE_ESCAPE || keyCode == KeyEvent.KEYCODE_BACK) { if(isCancelable()) dismiss(); return true; } else if (keyCode == KeyEvent.KEYCODE_TAB) { if(mInKbMode) { if (isTypedTimeFullyLegal()) { finishKbMode(true); } return true; } } else if (keyCode == KeyEvent.KEYCODE_ENTER) { if (mInKbMode) { if (!isTypedTimeFullyLegal()) { return true; } finishKbMode(false); } if (mCallback != null) { mCallback.onTimeSet(mTimePicker, mTimePicker.getHours(), mTimePicker.getMinutes(), mTimePicker.getSeconds()); } dismiss(); return true; } else if (keyCode == KeyEvent.KEYCODE_DEL) { if (mInKbMode) { if (!mTypedTimes.isEmpty()) { int deleted = deleteLastTypedKey(); String deletedKeyStr; if (deleted == getAmOrPmKeyCode(AM)) { deletedKeyStr = mAmText; } else if (deleted == getAmOrPmKeyCode(PM)) { deletedKeyStr = mPmText; } else { deletedKeyStr = String.format("%d", getValFromKeyCode(deleted)); } Utils.tryAccessibilityAnnounce(mTimePicker, String.format(mDeletedKeyFormat, deletedKeyStr)); updateDisplay(true); } } } else if (keyCode == KeyEvent.KEYCODE_0 || keyCode == KeyEvent.KEYCODE_1 || keyCode == KeyEvent.KEYCODE_2 || keyCode == KeyEvent.KEYCODE_3 || keyCode == KeyEvent.KEYCODE_4 || keyCode == KeyEvent.KEYCODE_5 || keyCode == KeyEvent.KEYCODE_6 || keyCode == KeyEvent.KEYCODE_7 || keyCode == KeyEvent.KEYCODE_8 || keyCode == KeyEvent.KEYCODE_9 || (!mIs24HourMode && (keyCode == getAmOrPmKeyCode(AM) || keyCode == getAmOrPmKeyCode(PM)))) { if (!mInKbMode) { if (mTimePicker == null) { // Something's wrong, because time picker should definitely not be null. Log.e(TAG, "Unable to initiate keyboard mode, TimePicker was null."); return true; } mTypedTimes.clear(); tryStartingKbMode(keyCode); return true; } // We're already in keyboard mode. if (addKeyIfLegal(keyCode)) { updateDisplay(false); } return true; } return false; }
Example 19
Source File: SimpleCommonUtils.java From o2oa with GNU Affero General Public License v3.0 | 4 votes |
public static void delClick(EditText editText) { int action = KeyEvent.ACTION_DOWN; int code = KeyEvent.KEYCODE_DEL; KeyEvent event = new KeyEvent(action, code); editText.onKeyDown(KeyEvent.KEYCODE_DEL, event); }
Example 20
Source File: AdapterInputConnection.java From android-chromium with BSD 2-Clause "Simplified" License | 4 votes |
/** * @see BaseInputConnection#sendKeyEvent(android.view.KeyEvent) */ @Override public boolean sendKeyEvent(KeyEvent event) { if (DEBUG) { Log.w(TAG, "sendKeyEvent [" + event.getAction() + "] [" + event.getKeyCode() + "]"); } // If this is a key-up, and backspace/del or if the key has a character representation, // need to update the underlying Editable (i.e. the local representation of the text // being edited). if (event.getAction() == KeyEvent.ACTION_UP) { if (event.getKeyCode() == KeyEvent.KEYCODE_DEL) { deleteSurroundingText(1, 0); return true; } else if (event.getKeyCode() == KeyEvent.KEYCODE_FORWARD_DEL) { deleteSurroundingText(0, 1); return true; } else { int unicodeChar = event.getUnicodeChar(); if (unicodeChar != 0) { Editable editable = getEditable(); int selectionStart = Selection.getSelectionStart(editable); int selectionEnd = Selection.getSelectionEnd(editable); if (selectionStart > selectionEnd) { int temp = selectionStart; selectionStart = selectionEnd; selectionEnd = temp; } editable.replace(selectionStart, selectionEnd, Character.toString((char)unicodeChar)); } } } else if (event.getAction() == KeyEvent.ACTION_DOWN) { // TODO(aurimas): remove this workaround when crbug.com/278584 is fixed. if (event.getKeyCode() == KeyEvent.KEYCODE_ENTER) { beginBatchEdit(); finishComposingText(); mImeAdapter.translateAndSendNativeEvents(event); endBatchEdit(); return true; } else if (event.getKeyCode() == KeyEvent.KEYCODE_DEL) { return true; } else if (event.getKeyCode() == KeyEvent.KEYCODE_FORWARD_DEL) { return true; } } mImeAdapter.translateAndSendNativeEvents(event); return true; }