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.mozilla.gecko.tests.testBrowserSearchVisibility.java

public void testSearchSuggestions() {
    blockForGeckoReady();/*from  w  w w .j a va2 s.  com*/

    focusUrlBar();

    // search should not be visible when editing mode starts
    assertBrowserSearchVisibility(false);

    mActions.sendKeys("a");

    // search should be visible when entry is not empty
    assertBrowserSearchVisibility(true);

    mActions.sendKeys("b");

    // search continues to be visible when more text is added
    assertBrowserSearchVisibility(true);

    mActions.sendKeyCode(KeyEvent.KEYCODE_DEL);

    // search continues to be visible when not all text is deleted
    assertBrowserSearchVisibility(true);

    mActions.sendKeyCode(KeyEvent.KEYCODE_DEL);

    // search should not be visible, entry is empty now
    assertBrowserSearchVisibility(false);
}

From source file:Main.java

public static int lookupKeycode(boolean shiftDown, int keycode) {
    switch (keycode) {
    // case KeyEvent.KEYCODE_SHIFT_LEFT: return 0x00;
    // case KeyEvent.KEYCODE_SHIFT_RIGHT: return 0x00;
    case KeyEvent.KEYCODE_0:
        return shiftDown ? 0x126 : 0x27;
    case KeyEvent.KEYCODE_1:
        return 0x30;
    case KeyEvent.KEYCODE_2:
        return 0x31;
    case KeyEvent.KEYCODE_3:
        return 0x11;
    case KeyEvent.KEYCODE_4:
        return 0x12;
    case KeyEvent.KEYCODE_5:
        return 0x13;
    case KeyEvent.KEYCODE_6:
        return 0x34;
    case KeyEvent.KEYCODE_7:
        return shiftDown ? 0x134 : 0x24;
    case KeyEvent.KEYCODE_8:
        return 0x15;
    case KeyEvent.KEYCODE_9:
        return shiftDown ? 0x115 : 0x26;
    case KeyEvent.KEYCODE_A:
        return 0x41;
    case KeyEvent.KEYCODE_B:
        return 0x64;
    case KeyEvent.KEYCODE_C:
        return 0x52;
    case KeyEvent.KEYCODE_D:
        return 0x32;
    case KeyEvent.KEYCODE_E:
        return 0x22;
    case KeyEvent.KEYCODE_F:
        return 0x43;
    case KeyEvent.KEYCODE_G:
        return 0x53;
    case KeyEvent.KEYCODE_H:
        return 0x54;
    case KeyEvent.KEYCODE_I:
        return 0x25;
    case KeyEvent.KEYCODE_J:
        return 0x45;
    case KeyEvent.KEYCODE_K:
        return 0x46;
    case KeyEvent.KEYCODE_L:
        return 0x56;
    case KeyEvent.KEYCODE_M:
        return 0x65;
    case KeyEvent.KEYCODE_N:
        return 0x55;
    case KeyEvent.KEYCODE_O:
        return 0x36;
    case KeyEvent.KEYCODE_P:
        return 0x37;
    case KeyEvent.KEYCODE_Q:
        return 0x10;
    case KeyEvent.KEYCODE_R:
        return 0x33;
    case KeyEvent.KEYCODE_S:
        return 0x51;
    case KeyEvent.KEYCODE_T:
        return 0x23;
    case KeyEvent.KEYCODE_U:
        return 0x35;
    case KeyEvent.KEYCODE_V:
        return 0x63;
    case KeyEvent.KEYCODE_W:
        return 0x21;
    case KeyEvent.KEYCODE_X:
        return 0x42;
    case KeyEvent.KEYCODE_Y:
        return 0x44;
    case KeyEvent.KEYCODE_Z:
        return 0x61;
    case KeyEvent.KEYCODE_SPACE:
        return 0x62;
    case KeyEvent.KEYCODE_ENTER:
        return 0x49;
    case KeyEvent.KEYCODE_DEL:
        return 0x59;
    case KeyEvent.KEYCODE_APOSTROPHE:
        return shiftDown ? 0x31 : 0x124;
    case KeyEvent.KEYCODE_POUND:
        return 0x111; // '#' is Shift+3
    case KeyEvent.KEYCODE_MINUS:
        return shiftDown ? 0x238 : 0x17;
    case KeyEvent.KEYCODE_EQUALS:
        return 0x117;
    case KeyEvent.KEYCODE_AT:
        return 0x47;
    case KeyEvent.KEYCODE_STAR:
        return 0x148;
    case KeyEvent.KEYCODE_PERIOD:
        return shiftDown ? 0x248 : 0x67;
    case KeyEvent.KEYCODE_SEMICOLON:
        return 0x57;
    case KeyEvent.KEYCODE_SLASH:
        return 0x68;
    case KeyEvent.KEYCODE_PLUS:
        return 0x157;
    case KeyEvent.KEYCODE_COMMA:
        return 0x66;
    // case KeyEvent.KEYCODE_GRAVE: return 0x??;
    // case KeyEvent.KEYCODE_LEFT_BRACKET: return 0x??;
    // case KeyEvent.KEYCODE_RIGHT_BRACKET: return 0x??;
    }//from   www.j a v a2  s  . c o  m
    return 0xaa;
}

From source file:Main.java

public static String getChar(int keyCode) {
    switch (keyCode) {
    case KeyEvent.KEYCODE_0:
        return "0";
    case KeyEvent.KEYCODE_1:
        return "1";
    case KeyEvent.KEYCODE_2:
        return "2";
    case KeyEvent.KEYCODE_3:
        return "3";
    case KeyEvent.KEYCODE_4:
        return "4";
    case KeyEvent.KEYCODE_5:
        return "5";
    case KeyEvent.KEYCODE_6:
        return "6";
    case KeyEvent.KEYCODE_7:
        return "7";
    case KeyEvent.KEYCODE_8:
        return "8";
    case KeyEvent.KEYCODE_9:
        return "9";
    case KeyEvent.KEYCODE_A:
        return "a";
    case KeyEvent.KEYCODE_B:
        return "b";
    case KeyEvent.KEYCODE_C:
        return "c";
    case KeyEvent.KEYCODE_D:
        return "d";
    case KeyEvent.KEYCODE_E:
        return "e";
    case KeyEvent.KEYCODE_F:
        return "f";
    case KeyEvent.KEYCODE_G:
        return "g";
    case KeyEvent.KEYCODE_H:
        return "h";
    case KeyEvent.KEYCODE_I:
        return "i";
    case KeyEvent.KEYCODE_J:
        return "j";
    case KeyEvent.KEYCODE_K:
        return "k";
    case KeyEvent.KEYCODE_L:
        return "l";
    case KeyEvent.KEYCODE_M:
        return "m";
    case KeyEvent.KEYCODE_N:
        return "n";
    case KeyEvent.KEYCODE_O:
        return "o";
    case KeyEvent.KEYCODE_P:
        return "p";
    case KeyEvent.KEYCODE_Q:
        return "q";
    case KeyEvent.KEYCODE_R:
        return "r";
    case KeyEvent.KEYCODE_S:
        return "s";
    case KeyEvent.KEYCODE_T:
        return "t";
    case KeyEvent.KEYCODE_U:
        return "u";
    case KeyEvent.KEYCODE_V:
        return "v";
    case KeyEvent.KEYCODE_W:
        return "w";
    case KeyEvent.KEYCODE_X:
        return "x";
    case KeyEvent.KEYCODE_Y:
        return "y";
    case KeyEvent.KEYCODE_Z:
        return "z";
    case KeyEvent.KEYCODE_DEL:
        return "{BKSP}";
    case KeyEvent.KEYCODE_ENTER:
    case KeyEvent.KEYCODE_DPAD_CENTER:
        return "{ENTER}";
    case KeyEvent.KEYCODE_SPACE:
        return " ";
    case KeyEvent.KEYCODE_DPAD_DOWN:
        return "{DOWN}";
    case KeyEvent.KEYCODE_DPAD_UP:
        return "{UP}";
    case KeyEvent.KEYCODE_DPAD_LEFT:
        return "{LEFT}";
    case KeyEvent.KEYCODE_DPAD_RIGHT:
        return "{RIGHT}";
    }//from  w w w  .j a v a 2 s .  c  om
    return null;
}

From source file:com.king.base.util.SystemUtils.java

/**
 * /*w  ww.j a v  a  2  s .com*/
 *
 * @param et
 */
public static void deleteClick(EditText et) {
    final KeyEvent keyEventDown = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL);
    et.onKeyDown(KeyEvent.KEYCODE_DEL, keyEventDown);
}

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  .j  a v  a  2s. 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:Main.java

public static String getKeyNameByCode(int code) {
    switch (code) {
    case KeyEvent.KEYCODE_0:
        return "<0>";
    case KeyEvent.KEYCODE_1:
        return "<1>";
    case KeyEvent.KEYCODE_2:
        return "<2>";
    case KeyEvent.KEYCODE_3:
        return "<3>";
    case KeyEvent.KEYCODE_4:
        return "<4>";
    case KeyEvent.KEYCODE_5:
        return "<5>";
    case KeyEvent.KEYCODE_6:
        return "<6>";
    case KeyEvent.KEYCODE_7:
        return "<7>";
    case KeyEvent.KEYCODE_8:
        return "<8>";
    case KeyEvent.KEYCODE_9:
        return "<9>";
    case KeyEvent.KEYCODE_A:
        return "<A>";
    case KeyEvent.KEYCODE_B:
        return "<B>";
    case KeyEvent.KEYCODE_C:
        return "<C>";
    case KeyEvent.KEYCODE_D:
        return "<D>";
    case KeyEvent.KEYCODE_E:
        return "<E>";
    case KeyEvent.KEYCODE_F:
        return "<F>";
    case KeyEvent.KEYCODE_G:
        return "<G>";
    case KeyEvent.KEYCODE_H:
        return "<H>";
    case KeyEvent.KEYCODE_I:
        return "<I>";
    case KeyEvent.KEYCODE_J:
        return "<J>";
    case KeyEvent.KEYCODE_K:
        return "<K>";
    case KeyEvent.KEYCODE_L:
        return "<L>";
    case KeyEvent.KEYCODE_M:
        return "<M>";
    case KeyEvent.KEYCODE_N:
        return "<N>";
    case KeyEvent.KEYCODE_O:
        return "<O>";
    case KeyEvent.KEYCODE_P:
        return "<P>";
    case KeyEvent.KEYCODE_Q:
        return "<Q>";
    case KeyEvent.KEYCODE_R:
        return "<R>";
    case KeyEvent.KEYCODE_S:
        return "<S>";
    case KeyEvent.KEYCODE_T:
        return "<T>";
    case KeyEvent.KEYCODE_U:
        return "<U>";
    case KeyEvent.KEYCODE_V:
        return "<V>";
    case KeyEvent.KEYCODE_W:
        return "<W>";
    case KeyEvent.KEYCODE_X:
        return "<X>";
    case KeyEvent.KEYCODE_Y:
        return "<Y>";
    case KeyEvent.KEYCODE_Z:
        return "<Z>";
    case KeyEvent.KEYCODE_APOSTROPHE:
        return "<'>";
    case KeyEvent.KEYCODE_AT:
        return "<@>";
    case KeyEvent.KEYCODE_BACK:
        return "<Back>";
    case KeyEvent.KEYCODE_BACKSLASH:
        return "<\\>";
    case KeyEvent.KEYCODE_CALL:
        return "<Call>";
    case KeyEvent.KEYCODE_CAMERA:
        return "<Camera>";
    case KeyEvent.KEYCODE_CLEAR:
        return "<Clear>";
    case KeyEvent.KEYCODE_COMMA:
        return "<,>";
    case KeyEvent.KEYCODE_DEL:
        return "<Del>";
    case KeyEvent.KEYCODE_DPAD_CENTER:
        return "<PadCenter>";
    case KeyEvent.KEYCODE_DPAD_DOWN:
        return "<PadDown>";
    case KeyEvent.KEYCODE_DPAD_LEFT:
        return "<PadLeft>";
    case KeyEvent.KEYCODE_DPAD_RIGHT:
        return "<PadRight>";
    case KeyEvent.KEYCODE_DPAD_UP:
        return "<PadUp>";
    case KeyEvent.KEYCODE_ENDCALL:
        return "<EndCall>";
    case KeyEvent.KEYCODE_ENTER:
        return "<Enter>";
    case KeyEvent.KEYCODE_ENVELOPE:
        return "<Envelope>";
    case KeyEvent.KEYCODE_EQUALS:
        return "<=>";
    case KeyEvent.KEYCODE_EXPLORER:
        return "<Explorer>";
    case KeyEvent.KEYCODE_FOCUS:
        return "<??? 0>";
    case KeyEvent.KEYCODE_GRAVE:
        return "<??? 1>";
    case KeyEvent.KEYCODE_HEADSETHOOK:
        return "<??? 2>";
    case KeyEvent.KEYCODE_HOME:
        return "<Home>";
    case KeyEvent.KEYCODE_LEFT_BRACKET:
        return "<(>";
    case KeyEvent.KEYCODE_MENU:
        return "<Menu>";
    case KeyEvent.KEYCODE_MINUS:
        return "<->";
    case KeyEvent.KEYCODE_NOTIFICATION:
        return "<??? 3>";
    case KeyEvent.KEYCODE_NUM:
        return "<Num>";
    case KeyEvent.KEYCODE_PERIOD:
        return "<??? 4>";
    case KeyEvent.KEYCODE_PLUS:
        return "<+>";
    case KeyEvent.KEYCODE_POUND:
        return "<??? 5>";
    case KeyEvent.KEYCODE_POWER:
        return "<Power>";
    case KeyEvent.KEYCODE_RIGHT_BRACKET:
        return "<)>";
    case KeyEvent.KEYCODE_SEMICOLON:
        return "<;>";
    case KeyEvent.KEYCODE_SLASH:
        return "</>";
    case KeyEvent.KEYCODE_SOFT_LEFT:
        return "<??? 6>";
    case KeyEvent.KEYCODE_SOFT_RIGHT:
        return "<??? 7>";
    case KeyEvent.KEYCODE_SPACE:
        return "<Space>";
    case KeyEvent.KEYCODE_STAR:
        return "<*>";
    case KeyEvent.KEYCODE_SYM:
        return "<Sym>";
    case KeyEvent.KEYCODE_TAB:
        return "<Tab>";
    case KeyEvent.KEYCODE_VOLUME_DOWN:
        return "<VolumeDown>";
    case KeyEvent.KEYCODE_VOLUME_UP:
        return "<VolumeUp>";
    case KeyEvent.KEYCODE_UNKNOWN:
    default://from w w w.  ja  v  a  2  s  .  co m
        return "<Unknown>";
    }
}

From source file:ru.orangesoftware.financisto.widget.AmountInput.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    requestId = EDIT_AMOUNT_REQUEST.incrementAndGet();

    LinearLayout v = new LinearLayout(getActivity());
    v.setOrientation(LinearLayout.HORIZONTAL);
    LinearLayout.LayoutParams lpWrapWrap = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);//from   www. j  a  va  2 s .com
    lpWrapWrap.weight = 1;

    inflater.inflate(R.layout.amount_input, v, true);
    c = new Controls(v);

    c.AmountInput.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(getActivity(), QuickAmountInput.class);
            intent.putExtra(EXTRA_AMOUNT, getAbsAmountString());
            startActivityForResult(intent, requestId);
        }
    });

    c.CalculatorInput.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(getActivity(), CalculatorInput.class);
            intent.putExtra(EXTRA_AMOUNT, getAbsAmountString());
            startActivityForResult(intent, requestId);
        }
    });

    c.primary.setKeyListener(keyListener);
    c.primary.addTextChangedListener(textWatcher);
    c.primary.setOnFocusChangeListener(selectAllOnFocusListener);

    c.secondary.setKeyListener(new DigitsKeyListener(false, false) {

        @Override
        public boolean onKeyDown(View view, Editable content, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_DEL) {
                if (content.length() == 0) {
                    c.primary.requestFocus();
                    int pos = c.primary.getText().length();
                    c.primary.setSelection(pos, pos);
                    return true;
                }
            }
            return super.onKeyDown(view, content, keyCode, event);
        }

        @Override
        public int getInputType() {
            return InputType.TYPE_CLASS_PHONE;
        }

    });
    c.secondary.addTextChangedListener(textWatcher);
    c.secondary.setOnFocusChangeListener(selectAllOnFocusListener);

    return v;
}

From source file:com.vikingbrain.dmt.view.RemoteControlActivity.java

@Override
public boolean dispatchKeyEvent(KeyEvent event) {

    int keyaction = event.getAction();
    int keyCode = event.getKeyCode();

    //Manage key up keys
    if (keyaction == KeyEvent.ACTION_UP) {

        if (keyCode == KeyEvent.KEYCODE_BACK) {
            //Back button, exit the activity
            onBackPressed();//w  w  w  .java  2  s  .co  m
            return true;
        } else if (keyCode == KeyEvent.KEYCODE_DEL) {
            //this is for backspace
            addCharacterToSendQueue(Keyboard2RemoteKey.BACKSPACE.getKeyboardSymbol());
            return true;
        } else {
            //Any other keyboard key up         
            DmtLogger.d("key pressed", String.valueOf(event.getKeyCode()));
            char unicodeChar = (char) event.getUnicodeChar();
            String keyboardSymbol = String.valueOf(unicodeChar);

            addCharacterToSendQueue(keyboardSymbol);
            return true;
        }
    }
    return super.dispatchKeyEvent(event);
}

From source file:com.waz.zclient.pages.extendedcursor.emoji.EmojiKeyboardLayout.java

private void init() {
    currentEmojiSize = EmojiSize.MEDIUM;
    categoryPositions = new int[CATEGORY_COUNT];

    emojiAdapter = new EmojiAdapter(getContext());

    layoutManager = new GridLayoutManager(getContext(), SPAN_COUNT, LinearLayoutManager.HORIZONTAL, false);
    layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
        @Override//ww w. j av  a2 s  . c  o  m
        public int getSpanSize(int position) {
            return spaces.contains(position) ? SPAN_COUNT : 1;
        }
    });
    layoutManager.setSpanCount(SPAN_COUNT);

    recyclerView.addOnScrollListener(new EmojiScrollListener());

    tapIndicatorLayout.setShowDivider(false);
    tapIndicatorLayout.setGlyphLabels(Emojis.EMOJI_KEYBOARD_TAB_LABELS);
    tapIndicatorLayout.setTextColor(ContextCompat.getColorStateList(getContext(),
            com.waz.zclient.ui.R.color.wire__text_color_dark_selector));
    tapIndicatorLayout.setPrimaryColor(
            ContextCompat.getColor(getContext(), com.waz.zclient.ui.R.color.text__primary_dark));
    tapIndicatorLayout.setLabelHeight(getContext().getResources()
            .getDimensionPixelSize(com.waz.zclient.ui.R.dimen.sketch__emoji__keyboard__tab_label_size));
    tapIndicatorLayout.setCallback(new TabIndicatorLayout.Callback() {
        @Override
        public void onItemSelected(int pos) {
            if (pos == TAB_COUNT - 1) {
                Threading.Background().execute(new Runnable() {
                    @Override
                    public void run() {
                        Instrumentation inst = new Instrumentation();
                        inst.sendKeyDownUpSync(KeyEvent.KEYCODE_DEL);
                    }
                });
            } else {
                tapIndicatorLayout.setSelected(pos);
                layoutManager.scrollToPositionWithOffset(getCategoryByTabPosition(pos), 0);
            }
        }
    });

    recyclerView.setAdapter(emojiAdapter);
    recyclerView.setLayoutManager(layoutManager);
    setRecyclerViewPadding(recyclerView);

    emojiAdapter.setOnEmojiClickListener(new EmojiAdapter.OnEmojiClickListener() {
        @Override
        public void onEmojiClick(String emoji, EmojiSize emojiSize) {
            if (callback != null) {
                callback.onEmojiSelected(emoji);
            }
        }
    });
}

From source file:com.android.screenspeak.KeyboardSearchManager.java

@Override
public boolean onKeyEvent(KeyEvent event) {
    // Only handle single-key events here. The KeyComboManager will pass us combos.
    if (event.getModifiers() != 0 || !mNodeSearch.isActive()) {
        return false;
    }//from w  w  w.j  ava  2s  . c o m

    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_ENTER:
            if (mHasNavigated || mNodeSearch.hasMatch()) {
                finishSearch();
                mContext.getCursorController().clickCurrent();
            } else {
                cancelSearch();
            }
            return true;
        case KeyEvent.KEYCODE_DEL:
            resetHintTime();
            final String queryText = mNodeSearch.getCurrentQuery();
            if (queryText.isEmpty()) {
                cancelSearch();
            } else {
                final String lastChar = queryText.substring(queryText.length() - 1);
                mNodeSearch.backspaceQueryText();
                mSpeechController.speak(mContext.getString(R.string.template_text_removed, lastChar),
                        SpeechController.QUEUE_MODE_FLUSH_ALL, FeedbackItem.FLAG_NO_HISTORY, null);
            }
            return true;
        case KeyEvent.KEYCODE_DPAD_UP:
            moveToEnd(NodeFocusFinder.SEARCH_BACKWARD);
            return true;
        case KeyEvent.KEYCODE_DPAD_LEFT:
            moveToNext(NodeFocusFinder.SEARCH_BACKWARD);
            return true;
        case KeyEvent.KEYCODE_DPAD_DOWN:
            moveToEnd(NodeFocusFinder.SEARCH_FORWARD);
            return true;
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            moveToNext(NodeFocusFinder.SEARCH_FORWARD);
            return true;
        case KeyEvent.KEYCODE_SPACE:
            resetHintTime();
            if (mNodeSearch.tryAddQueryText(" ")) {
                mSpeechController.speak(mContext.getString(R.string.symbol_space),
                        SpeechController.QUEUE_MODE_FLUSH_ALL, FeedbackItem.FLAG_NO_HISTORY, null);
            } else {
                mContext.getFeedbackController().playAuditory(R.raw.complete);
            }
            return true;
        default:
            if (event.isPrintingKey()) {
                resetHintTime();
                final String key = String.valueOf(event.getDisplayLabel());
                if (mNodeSearch.tryAddQueryText(key)) {
                    mSpeechController.speak(key.toLowerCase(), SpeechController.QUEUE_MODE_FLUSH_ALL,
                            FeedbackItem.FLAG_NO_HISTORY, null);
                } else {
                    mContext.getFeedbackController().playAuditory(R.raw.complete);
                }
                return true;
            }
            break;
        }
    }

    return false;
}