Example usage for android.view KeyEvent KeyEvent

List of usage examples for android.view KeyEvent KeyEvent

Introduction

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

Prototype

public KeyEvent(long downTime, long eventTime, int action, int code, int repeat, int metaState, int deviceId,
        int scancode, int flags) 

Source Link

Document

Create a new key event.

Usage

From source file:chat.crypt.messenger.app.keyboard.emoji.EmojiKeyboard.java

@Override
public void onBackspaceClick(View v) {
    if (messageBody == null) {
        return;//from   w w w. ja v  a  2  s .  c  om
    }
    KeyEvent event = new KeyEvent(0, 0, 0, KeyEvent.KEYCODE_DEL, 0, 0, 0, 0, KeyEvent.KEYCODE_ENDCALL);
    messageBody.dispatchKeyEvent(event);
}

From source file:com.andinrajesh.emojicon.EmojiPopup.java

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);/*from www  .j a va 2  s. c  om*/
}

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

/**
 * initialize the emojiconKeyboard//from   ww  w.j av a 2  s  .c  om
 */
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));
        }
    });
}