Example usage for android.view KeyEvent KEYCODE_DEL

List of usage examples for android.view KeyEvent KEYCODE_DEL

Introduction

In this page you can find the example usage for android.view KeyEvent KEYCODE_DEL.

Prototype

int KEYCODE_DEL

To view the source code for android.view KeyEvent KEYCODE_DEL.

Click Source Link

Document

Key code constant: Backspace key.

Usage

From source file:org.distantshoresmedia.keyboard.LatinIME.java

private void handleBackspace() {
    boolean deleteChar = false;
    InputConnection ic = getCurrentInputConnection();
    if (ic == null)
        return;/*from  www . j  a v a 2s .c  o  m*/

    ic.beginBatchEdit();

    if (mPredicting) {
        final int length = mComposing.length();
        if (length > 0) {
            mComposing.delete(length - 1, length);
            mWord.deleteLast();
            ic.setComposingText(mComposing, 1);
            if (mComposing.length() == 0) {
                mPredicting = false;
            }
            postUpdateSuggestions();
        } else {
            ic.deleteSurroundingText(1, 0);
        }
    } else {
        deleteChar = true;
    }
    postUpdateShiftKeyState();
    TextEntryState.backspace();
    if (TextEntryState.getState() == TextEntryState.State.UNDO_COMMIT) {
        revertLastWord(deleteChar);
        ic.endBatchEdit();
        return;
    } else if (mEnteredText != null && sameAsTextBeforeCursor(ic, mEnteredText)) {
        ic.deleteSurroundingText(mEnteredText.length(), 0);
    } else if (deleteChar) {
        if (mCandidateView != null && mCandidateView.dismissAddToDictionaryHint()) {
            // Go back to the suggestion mode if the user canceled the
            // "Touch again to save".
            // NOTE: In gerenal, we don't revert the word when backspacing
            // from a manual suggestion pick. We deliberately chose a
            // different behavior only in the case of picking the first
            // suggestion (typed word). It's intentional to have made this
            // inconsistent with backspacing after selecting other
            // suggestions.
            revertLastWord(deleteChar);
        } else {
            sendDownUpKeyEvents(KeyEvent.KEYCODE_DEL);
            if (mDeleteCount > DELETE_ACCELERATE_AT) {
                sendDownUpKeyEvents(KeyEvent.KEYCODE_DEL);
            }
        }
    }
    mJustRevertedSeparator = null;
    ic.endBatchEdit();
}

From source file:com.tct.mail.ui.AbstractActivityController.java

@Override
public final boolean onKeyDown(int keyCode, KeyEvent event) {
    //[FRETURE]-ADD-BEGIN by TSNJ.wei huang 11/24/2014 FR848855
    if (keyCode == event.KEYCODE_BACK) {
        if (mCabActionMenu != null) {
            if (mCabActionMenu.isActivated()) {
                if (mCabActionMenu.isActionModeNull()) {
                    return false;
                } else {
                    mCabActionMenu.onSetEmpty();
                }/*ww w.  j  av a  2  s  .  c o m*/
                return true;
            } else {
                return false;
            }
        }
    }
    //[FEATURE]-ADD-END by TSNJ.wei huang

    // TS: gangjin.weng 2015-4-5 EMAIL BUGFIX-968391 ADD_S
    if (keyCode == KeyEvent.KEYCODE_DEL && mCabActionMenu == null && event != null && event.getScanCode() == 0
            && event.getMetaState() == 0
            && event.getFlags() == (KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_MODE)) {
        return true;
    }
    // TS: gangjin.weng 2015-4-5 EMAIL BUGFIX-968391 ADD_E
    return false;
}

From source file:com.anysoftkeyboard.AnySoftKeyboard.java

public void revertLastWord() {
    final int length = mCommittedWord.length() + (mJustAddedAutoSpace ? 1 : 0);
    if (length > 0) {
        mAutoCorrectOn = false;//  w  w w. j a va  2  s. c o m
        //note: typedWord may be empty
        final InputConnection ic = getCurrentInputConnection();
        mUndoCommitCursorPosition = UNDO_COMMIT_NONE;
        ic.beginBatchEdit();
        ic.deleteSurroundingText(length, 0);
        final CharSequence typedWord = mWord.getTypedWord();
        ic.setComposingText(typedWord/* mComposing */, 1);
        TextEntryState.backspace();
        ic.endBatchEdit();
        performUpdateSuggestions();
        if (mJustAutoAddedWord) {
            removeFromUserDictionary(typedWord.toString());
        }
        getInputView().revertPopTextOutOfKey();
    } else {
        sendDownUpKeyEvents(KeyEvent.KEYCODE_DEL);
    }
}

From source file:com.bernard.beaconportal.activities.activity.MessageList.java

/**
 * Handle hotkeys/*w  w  w. j a  v a 2  s . co  m*/
 * 
 * <p>
 * This method is called by {@link #dispatchKeyEvent(KeyEvent)} before any
 * view had the chance to consume this key event.
 * </p>
 * 
 * @param keyCode
 *            The value in {@code event.getKeyCode()}.
 * @param event
 *            Description of the key event.
 * 
 * @return {@code true} if this event was consumed.
 */
public boolean onCustomKeyDown(final int keyCode, final KeyEvent event) {
    switch (keyCode) {
    case KeyEvent.KEYCODE_VOLUME_UP: {
        if (mMessageViewFragment != null && mDisplayMode != DisplayMode.MESSAGE_LIST
                && K9.useVolumeKeysForNavigationEnabled()) {
            showPreviousMessage();
            return true;
        } else if (mDisplayMode != DisplayMode.MESSAGE_VIEW && K9.useVolumeKeysForListNavigationEnabled()) {
            mMessageListFragment.onMoveUp();
            return true;
        }

        break;
    }
    case KeyEvent.KEYCODE_VOLUME_DOWN: {
        if (mMessageViewFragment != null && mDisplayMode != DisplayMode.MESSAGE_LIST
                && K9.useVolumeKeysForNavigationEnabled()) {
            showNextMessage();
            return true;
        } else if (mDisplayMode != DisplayMode.MESSAGE_VIEW && K9.useVolumeKeysForListNavigationEnabled()) {
            mMessageListFragment.onMoveDown();
            return true;
        }

        break;
    }
    case KeyEvent.KEYCODE_C: {
        mMessageListFragment.onCompose();
        return true;
    }
    case KeyEvent.KEYCODE_Q: {
        if (mMessageListFragment != null && mMessageListFragment.isSingleAccountMode()) {
            onShowFolderList();
        }
        return true;
    }
    case KeyEvent.KEYCODE_O: {
        mMessageListFragment.onCycleSort();
        return true;
    }
    case KeyEvent.KEYCODE_I: {
        mMessageListFragment.onReverseSort();
        return true;
    }
    case KeyEvent.KEYCODE_DEL:
    case KeyEvent.KEYCODE_D: {
        if (mDisplayMode == DisplayMode.MESSAGE_LIST) {
            mMessageListFragment.onDelete();
        } else if (mMessageViewFragment != null) {
            mMessageViewFragment.onDelete();
        }
        return true;
    }
    case KeyEvent.KEYCODE_S: {
        mMessageListFragment.toggleMessageSelect();
        return true;
    }
    case KeyEvent.KEYCODE_G: {
        if (mDisplayMode == DisplayMode.MESSAGE_LIST) {
            mMessageListFragment.onToggleFlagged();
        } else if (mMessageViewFragment != null) {
            mMessageViewFragment.onToggleFlagged();
        }
        return true;
    }
    case KeyEvent.KEYCODE_M: {
        if (mDisplayMode == DisplayMode.MESSAGE_LIST) {
            mMessageListFragment.onMove();
        } else if (mMessageViewFragment != null) {
            mMessageViewFragment.onMove();
        }
        return true;
    }
    case KeyEvent.KEYCODE_V: {
        if (mDisplayMode == DisplayMode.MESSAGE_LIST) {
            mMessageListFragment.onArchive();
        } else if (mMessageViewFragment != null) {
            mMessageViewFragment.onArchive();
        }
        return true;
    }
    case KeyEvent.KEYCODE_Y: {
        if (mDisplayMode == DisplayMode.MESSAGE_LIST) {
            mMessageListFragment.onCopy();
        } else if (mMessageViewFragment != null) {
            mMessageViewFragment.onCopy();
        }
        return true;
    }
    case KeyEvent.KEYCODE_Z: {
        if (mDisplayMode == DisplayMode.MESSAGE_LIST) {
            mMessageListFragment.onToggleRead();
        } else if (mMessageViewFragment != null) {
            mMessageViewFragment.onToggleRead();
        }
        return true;
    }
    case KeyEvent.KEYCODE_F: {
        if (mMessageViewFragment != null) {
            mMessageViewFragment.onForward();
        }
        return true;
    }
    case KeyEvent.KEYCODE_A: {
        if (mMessageViewFragment != null) {
            mMessageViewFragment.onReplyAll();
        }
        return true;
    }
    case KeyEvent.KEYCODE_R: {
        if (mMessageViewFragment != null) {
            mMessageViewFragment.onReply();
        }
        return true;
    }
    case KeyEvent.KEYCODE_J:
    case KeyEvent.KEYCODE_P: {
        if (mMessageViewFragment != null) {
            showPreviousMessage();
        }
        return true;
    }
    case KeyEvent.KEYCODE_N:
    case KeyEvent.KEYCODE_K: {
        if (mMessageViewFragment != null) {
            showNextMessage();
        }
        return true;
    }
    /*
     * FIXME case KeyEvent.KEYCODE_Z: { mMessageViewFragment.zoom(event);
     * return true; }
     */
    case KeyEvent.KEYCODE_H: {
        Toast toast = Toast.makeText(this, R.string.message_list_help_key, Toast.LENGTH_LONG);
        toast.show();
        return true;
    }

    }

    return false;
}

From source file:com.android.mms.ui.ComposeMessageActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    switch (keyCode) {
    case KeyEvent.KEYCODE_DEL:
        if ((mMsgListAdapter != null) && mMsgListView.isFocused()) {
            Cursor cursor;//  w  w w.j a  va  2s  .  c  o m
            try {
                cursor = (Cursor) mMsgListView.getSelectedItem();
            } catch (ClassCastException e) {
                Log.e(TAG, "Unexpected ClassCastException.", e);
                return super.onKeyDown(keyCode, event);
            }

            if (cursor != null) {
                String type = cursor.getString(COLUMN_MSG_TYPE);
                long msgId = cursor.getLong(COLUMN_ID);
                MessageItem msgItem = mMsgListAdapter.getCachedMessageItem(type, msgId, cursor);
                if (msgItem != null) {
                    DeleteMessageListener l = new DeleteMessageListener(msgItem);
                    confirmDeleteDialog(l, msgItem.mLocked);
                }
                return true;
            }
        }
        break;
    case KeyEvent.KEYCODE_DPAD_CENTER:
    case KeyEvent.KEYCODE_ENTER:
        if (isPreparedForSending()) {
            confirmSendMessageIfNeeded();
            return true;
        }
        break;
    }

    return super.onKeyDown(keyCode, event);
}

From source file:org.distantshoresmedia.keyboard.LatinIME.java

public void revertLastWord(boolean deleteChar) {
    final int length = mComposing.length();
    if (!mPredicting && length > 0) {
        final InputConnection ic = getCurrentInputConnection();
        mPredicting = true;/* w  ww.  j a  va  2 s  . c o  m*/
        mJustRevertedSeparator = ic.getTextBeforeCursor(1, 0);
        if (deleteChar)
            ic.deleteSurroundingText(1, 0);
        int toDelete = mCommittedLength;
        CharSequence toTheLeft = ic.getTextBeforeCursor(mCommittedLength, 0);
        if (toTheLeft != null && toTheLeft.length() > 0 && isWordSeparator(toTheLeft.charAt(0))) {
            toDelete--;
        }
        ic.deleteSurroundingText(toDelete, 0);
        ic.setComposingText(mComposing, 1);
        TextEntryState.backspace();
        postUpdateSuggestions();
    } else {
        sendDownUpKeyEvents(KeyEvent.KEYCODE_DEL);
        mJustRevertedSeparator = null;
    }
}

From source file:org.telegram.ui.Components.ChatActivityEnterView.java

private void createEmojiView() {
    if (emojiView != null) {
        return;// w ww .ja v  a  2  s .c om
    }
    emojiView = new EmojiView(allowStickers, allowGifs, parentActivity);
    emojiView.setVisibility(GONE);
    emojiView.setListener(new EmojiView.Listener() {
        public boolean onBackspace() {
            if (messageEditText.length() == 0) {
                return false;
            }
            messageEditText.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL));
            return true;
        }

        public void onEmojiSelected(String symbol) {
            int i = messageEditText.getSelectionEnd();
            if (i < 0) {
                i = 0;
            }
            try {
                innerTextChange = 2;
                CharSequence localCharSequence = Emoji.replaceEmoji(symbol,
                        messageEditText.getPaint().getFontMetricsInt(), AndroidUtilities.dp(20), false);
                messageEditText.setText(messageEditText.getText().insert(i, localCharSequence));
                int j = i + localCharSequence.length();
                messageEditText.setSelection(j, j);
            } catch (Exception e) {
                FileLog.e(e);
            } finally {
                innerTextChange = 0;
            }
        }

        public void onStickerSelected(TLRPC.Document sticker) {
            ChatActivityEnterView.this.onStickerSelected(sticker);
            StickersQuery.addRecentSticker(StickersQuery.TYPE_IMAGE, sticker,
                    (int) (System.currentTimeMillis() / 1000));
            if ((int) dialog_id == 0) {
                MessagesController.getInstance().saveGif(sticker);
            }
        }

        @Override
        public void onStickersSettingsClick() {
            if (parentFragment != null) {
                parentFragment.presentFragment(new StickersActivity(StickersQuery.TYPE_IMAGE));
            }
        }

        @Override
        public void onGifSelected(TLRPC.Document gif) {
            SendMessagesHelper.getInstance().sendSticker(gif, dialog_id, replyingMessageObject);
            StickersQuery.addRecentGif(gif, (int) (System.currentTimeMillis() / 1000));
            if ((int) dialog_id == 0) {
                MessagesController.getInstance().saveGif(gif);
            }
            if (delegate != null) {
                delegate.onMessageSend(null);
            }
        }

        @Override
        public void onGifTab(boolean opened) {
            if (!AndroidUtilities.usingHardwareInput) {
                if (opened) {
                    if (messageEditText.length() == 0) {
                        messageEditText.setText("@gif ");
                        messageEditText.setSelection(messageEditText.length());
                    }
                } else if (messageEditText.getText().toString().equals("@gif ")) {
                    messageEditText.setText("");
                }
            }
        }

        @Override
        public void onStickersTab(boolean opened) {
            delegate.onStickersTab(opened);
        }

        @Override
        public void onClearEmojiRecent() {
            if (parentFragment == null || parentActivity == null) {
                return;
            }
            AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity);
            builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
            builder.setMessage(LocaleController.getString("ClearRecentEmoji", R.string.ClearRecentEmoji));
            builder.setPositiveButton(
                    LocaleController.getString("ClearButton", R.string.ClearButton).toUpperCase(),
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            emojiView.clearRecentEmoji();
                        }
                    });
            builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
            parentFragment.showDialog(builder.create());
        }

        @Override
        public void onShowStickerSet(TLRPC.StickerSet stickerSet, TLRPC.InputStickerSet inputStickerSet) {
            if (parentFragment == null || parentActivity == null) {
                return;
            }
            if (stickerSet != null) {
                inputStickerSet = new TLRPC.TL_inputStickerSetID();
                inputStickerSet.access_hash = stickerSet.access_hash;
                inputStickerSet.id = stickerSet.id;
            }
            parentFragment.showDialog(new StickersAlert(parentActivity, parentFragment, inputStickerSet, null,
                    ChatActivityEnterView.this));
        }

        @Override
        public void onStickerSetAdd(TLRPC.StickerSetCovered stickerSet) {
            StickersQuery.removeStickersSet(parentActivity, stickerSet.set, 2, parentFragment, false);
        }

        @Override
        public void onStickerSetRemove(TLRPC.StickerSetCovered stickerSet) {
            StickersQuery.removeStickersSet(parentActivity, stickerSet.set, 0, parentFragment, false);
        }
    });
    emojiView.setVisibility(GONE);
    sizeNotifierLayout.addView(emojiView);
}