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:com.codetroopers.betterpickers.radialtimepicker.RadialTimePickerDialogFragment.java

/**
 * For keyboard mode, processes key events.
 *
 * @param keyCode the pressed key.//from   w  ww.ja v  a  2  s . c  o  m
 * @return true if the key was successfully processed, false otherwise.
 */
private boolean processKeyUp(int keyCode) {
    if (keyCode == KeyEvent.KEYCODE_ESCAPE || keyCode == KeyEvent.KEYCODE_BACK) {
        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);
        }
        doneClickValidateAndCallback();
        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;
}

From source file:com.googlecode.eyesfree.brailleback.IMENavigationModeTest.java

/**
 * Tests the behaviour of the "modal editor" mode.
 */// w  ww .j  av  a2 s .c  om
public void testModalEditorMode() {
    mIMENavMode.onActivate();
    verify(mNext).onActivate();
    EditorInfo ei = new EditorInfo();

    // Mock out the AccessibilityNodeInfo.
    // The class actually uses the compat variant, but on recent API
    // releases (including the test environment) they should call through.
    AccessibilityNodeInfo rawNode = mock(AccessibilityNodeInfo.class);
    when(mAccessibilityService.getRootInActiveWindow()).thenReturn(rawNode);
    when(rawNode.findFocus(AccessibilityNodeInfo.FOCUS_ACCESSIBILITY)).thenReturn(rawNode);
    when(rawNode.getClassName()).thenReturn(EditText.class.getName());
    when(rawNode.isFocused()).thenReturn(true);

    mIMENavMode.onCreateIME();
    mIMENavMode.onBindInput();

    mIMENavMode.onStartInput(ei, false /* restarting */);
    mIMENavMode.onStartInputView(ei, false /* restarting */);
    verify(mNext, times(1)).onDeactivate();

    assertEquals(mBrailleTranslator, mIMENavMode.getBrailleTranslator());
    assertEquals(mDisplayManager, mIMENavMode.getDisplayManager());
    assertEquals(mFeedbackManager, mIMENavMode.getFeedbackManager());

    AccessibilityEvent accessibilityEvent = AccessibilityEvent.obtain();
    try {
        mIMENavMode.onObserveAccessibilityEvent(accessibilityEvent);
        verify(mNext).onObserveAccessibilityEvent(accessibilityEvent);
    } finally {
        accessibilityEvent.recycle();
    }

    accessibilityEvent = AccessibilityEvent.obtain();
    try {
        mIMENavMode.onAccessibilityEvent(accessibilityEvent);
        verify(mNext, never()).onAccessibilityEvent(accessibilityEvent);
    } finally {
        accessibilityEvent.recycle();
    }

    AccessibilityNodeInfoCompat node = AccessibilityNodeInfoCompat.obtain();
    try {
        mIMENavMode.onInvalidateAccessibilityNode(node);
        verify(mNext, never()).onInvalidateAccessibilityNode(node);
    } finally {
        node.recycle();
    }

    // Move input focus away and back again.
    when(rawNode.isFocused()).thenReturn(false);
    accessibilityEvent = AccessibilityEvent.obtain();
    accessibilityEvent.setEventType(AccessibilityEvent.TYPE_VIEW_FOCUSED);
    try {
        mIMENavMode.onObserveAccessibilityEvent(accessibilityEvent);
        verify(mNext, times(2)).onActivate();
        when(rawNode.isFocused()).thenReturn(true);
        mIMENavMode.onObserveAccessibilityEvent(accessibilityEvent);
        verify(mNext, times(2)).onDeactivate();
    } finally {
        accessibilityEvent.recycle();
    }

    DisplayManager.Content content = new DisplayManager.Content("");
    mIMENavMode.onPanLeftOverflow(content);
    verify(mNext).onPanLeftOverflow(content);
    mIMENavMode.onPanRightOverflow(content);
    verify(mNext).onPanRightOverflow(content);

    BrailleInputEvent inputEvent = new BrailleInputEvent(BrailleInputEvent.CMD_KEY_ENTER, 0, 0);
    mIMENavMode.onMappedInputEvent(inputEvent, content);
    verify(mNext, never()).onMappedInputEvent(inputEvent, content);
    verify(mIME).sendAndroidKey(KeyEvent.KEYCODE_ENTER);

    inputEvent = new BrailleInputEvent(BrailleInputEvent.CMD_KEY_DEL, 0, 0);
    mIMENavMode.onMappedInputEvent(inputEvent, content);
    verify(mNext, never()).onMappedInputEvent(inputEvent, content);
    verify(mIME).sendAndroidKey(KeyEvent.KEYCODE_DEL);

    inputEvent = new BrailleInputEvent(BrailleInputEvent.CMD_BRAILLE_KEY, 0x1b, 0);
    mIMENavMode.onMappedInputEvent(inputEvent, content);
    verify(mNext, never()).onMappedInputEvent(inputEvent, content);
    verify(mIME).handleBrailleKey(0x1b);

    inputEvent = new BrailleInputEvent(BrailleInputEvent.CMD_NAV_ITEM_NEXT, 0, 0);
    mIMENavMode.onMappedInputEvent(inputEvent, content);
    verify(mNext, never()).onMappedInputEvent(inputEvent, content);
    verify(mIME).moveCursor(BrailleIME.DIRECTION_FORWARD,
            AccessibilityNodeInfoCompat.MOVEMENT_GRANULARITY_CHARACTER);

    inputEvent = new BrailleInputEvent(BrailleInputEvent.CMD_ACTIVATE_CURRENT, 0, 0);
    mIMENavMode.onMappedInputEvent(inputEvent, content);
    verify(mNext, never()).onMappedInputEvent(inputEvent, content);
    verify(mIME).sendDefaultAction();

    inputEvent = new BrailleInputEvent(BrailleInputEvent.CMD_ROUTE, 0, 0);
    mIMENavMode.onMappedInputEvent(inputEvent, content);
    verify(mNext, never()).onMappedInputEvent(inputEvent, content);
    verify(mIME).route(0, content);

    // Finishing and unbinding the input should activate the next nav mode
    // again.
    mIMENavMode.onFinishInputView(true);
    mIMENavMode.onFinishInput();
    mIMENavMode.onUnbindInput();
    verify(mNext, times(3)).onActivate();

    mIMENavMode.onDestroyIME();

    // Deactivate, but make sure it didn't happen too early.
    verify(mNext, times(2)).onDeactivate();
    mIMENavMode.onDeactivate();
    verify(mNext, times(3)).onDeactivate();
}

From source file:com.appeaser.sublimepickerlibrary.timepicker.SublimeTimePicker.java

/**
 * For keyboard mode, processes key events.
 *
 * @param keyCode the pressed key./*w  w  w .j  a v a 2  s. c  o m*/
 * @return true if the key was successfully processed, false otherwise.
 */
private boolean processKeyUp(int keyCode) {
    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));
                }

                AccessibilityUtils.makeAnnouncement(this, 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
            || (!mIs24HourView && (keyCode == getAmOrPmKeyCode(AM) || keyCode == getAmOrPmKeyCode(PM)))) {
        if (!mInKbMode) {
            if (mRadialTimePickerView == null) {
                // Something is 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;
}

From source file:com.kaichaohulian.baocms.ecdemo.ui.chatting.ChattingFragment.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
        LogUtil.d(TAG, "keycode back , chatfooter mode: " + mChattingFooter.getMode());
        if (!mChattingFooter.isButtomPanelNotVisibility()) {
            hideBottom();//  w  w w  .ja va  2 s  .c  o  m
            return true;
        }
        setIsFinish(true);
    } else if (keyCode == KeyEvent.KEYCODE_DEL) {
        if (event.getAction() == KeyEvent.ACTION_DOWN) {
            mHandlerDelChar = !(mChattingFooter.getCharAtCursor() != (char) (8197));
        }
        if (event.getAction() == KeyEvent.ACTION_UP && mHandlerDelChar) {
            mHandlerDelChar = false;
            CCPChattingFooter2 footer = this.mChattingFooter;
            int selectionStart = footer.getSelectionStart();
            String text = footer.getLastText().substring(0, selectionStart);
            int atIndex = text.lastIndexOf('@');
            if (atIndex < text.length() && atIndex >= 0) {
                delAtSomeBody(text.substring(atIndex, selectionStart));
                String subStartText = text.substring(0, atIndex);
                String subSecondText = footer.getLastText().substring(selectionStart);
                StringBuilder sb = new StringBuilder();
                sb.append(subStartText).append(subSecondText);
                footer.setLastText(sb.toString());
                footer.mEditText.setSelection(atIndex);
            }
        }
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.actionbarsherlock.internal.view.menu.MenuBuilder.java

@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();/*from w  w w .  ja  v a  2 s  .c  o m*/
    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;
}

From source file:com.borax12.materialdaterangepicker.time.TimePickerDialog.java

/**
 * For keyboard mode, processes key events.
 * @param keyCode the pressed key.//from  w w w. j  a  v a2  s. c o  m
 * @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(),
                    mTimePickerEnd.getHours(), mTimePickerEnd.getMinutes());
        }
        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));
                }
                if (tabHost.getCurrentTab() == 0) {
                    Utils.tryAccessibilityAnnounce(mTimePicker,
                            String.format(mDeletedKeyFormat, deletedKeyStr));
                } else {
                    Utils.tryAccessibilityAnnounce(mTimePickerEnd,
                            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;
}

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.//from   www  . ja v  a 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.borax12.materialdaterangepicker.single.time.TimePickerDialog.java

/**
 * For keyboard mode, processes key events.
 * @param keyCode the pressed key.//from  ww  w. ja v a 2s .  co  m
 * @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;
}

From source file:com.wdullaer.materialdatetimepicker.time.TimePickerView.java

/**
 * For keyboard mode, processes key events.
 * @param keyCode the pressed key.//from  ww  w . j a v  a 2 s  . c  o m
 * @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;
}

From source file:com.raspi.chatapp.ui.chatting.ChatFragment.java

/**
 * initialize the emojiconKeyboard// w  w  w .  j  a va2s .  com
 */
private void initEmoji() {
    // save the views I will use
    final EmojiconEditText emojiconEditText = (EmojiconEditText) getActivity().findViewById(R.id.chat_in);
    final ImageButton emojiBtn = (ImageButton) getActivity().findViewById(R.id.emoti_switch);
    final EmojiconPopup popup = new EmojiconPopup(getActivity().findViewById(R.id.root_view), getContext(),
            new EmojiconGridView.OnEmojiconClickedListener() {
                @Override
                public void OnEmojiconClicked(Emojicon emojicon) {
                    if (emojiconEditText == null || emojicon == null)
                        return;
                    int start = emojiconEditText.getSelectionStart();
                    int end = emojiconEditText.getSelectionEnd();
                    if (start < 0)
                        emojiconEditText.append(emojicon.getEmoji());
                    else
                        emojiconEditText.getText().replace(Math.min(start, end), Math.max(start, end),
                                emojicon.getEmoji(), 0, emojicon.getEmoji().length());
                }
            });
    popup.setSoftKeyboardSize();

    popup.setOnSoftKeyboardOpenCloseListener(new EmojiconPopup.OnSoftKeyboardOpenCloseListener() {
        @Override
        public void onKeyboardOpen(int keyboardHeight) {
        }

        @Override
        public void onKeyboardClose() {
            if (popup.isShowing())
                popup.dismiss();
        }
    });
    // open/close the emojicon keyboard when pressing the button
    emojiBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (!popup.isShowing()) {
                if (popup.isKeyboardOpen())
                    popup.showAtBottom();
                else {
                    emojiconEditText.setFocusableInTouchMode(true);
                    emojiconEditText.requestFocus();
                    popup.showAtBottomPending();
                    InputMethodManager imm = (InputMethodManager) getActivity()
                            .getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.showSoftInput(emojiconEditText, InputMethodManager.SHOW_IMPLICIT);
                }
            } else
                popup.dismiss();
        }
    });

    popup.setOnEmojiconBackspaceClickedListener(new EmojiconPopup.OnEmojiconBackspaceClickedListener() {
        @Override
        public void onEmojiconBackspaceClicked(View view) {
            emojiconEditText.dispatchKeyEvent(
                    new KeyEvent(0, 0, 0, KeyEvent.KEYCODE_DEL, 0, 0, 0, 0, KeyEvent.KEYCODE_ENDCALL));
        }
    });
}