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.philliphsu.bottomsheetpickers.time.grid.GridTimePickerDialog.java

/**
 * For keyboard mode, processes key events.
 * @param keyCode the pressed key.// w  ww.  ja va 2  s. c om
 * @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);
        }
        onTimeSet(mTimePicker, mTimePicker.getHours(), mTimePicker.getMinutes());
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_DEL) {
        if (mInKbMode) {
            if (!mTypedTimes.isEmpty()) {
                int deleted = deleteLastTypedKey();
                String deletedKeyStr;
                if (deleted == getAmOrPmKeyCode(HALF_DAY_1)) {
                    deletedKeyStr = mAmText;
                } else if (deleted == getAmOrPmKeyCode(HALF_DAY_2)) {
                    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(HALF_DAY_1) || keyCode == getAmOrPmKeyCode(HALF_DAY_2)))) {
        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.mattfred.betterpickers.radialtimepicker.RadialTimePickerDialogFragment.java

/**
 * For keyboard mode, processes key events.
 *
 * @param keyCode the pressed key./*from  w w w  . ja  va  2 s. com*/
 * @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);
        }
        if (mCallback != null) {
            mCallback.onTimeSet(RadialTimePickerDialogFragment.this, mTimePicker.getHours(),
                    mTimePicker.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));
                }
                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:org.akop.ararat.view.CrosswordView.java

@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
    boolean handled = false;
    if (event.getAction() == KeyEvent.ACTION_UP) {
        if (keyCode == KeyEvent.KEYCODE_SPACE) {
            switchWordDirection();/*from   w w  w  . j a  v a  2  s.  c om*/
            handled = true;
        } else if (keyCode == KeyEvent.KEYCODE_DEL) {
            handleBackspace();
            handled = true;
        } else {
            int uniChar = event.getUnicodeChar();
            if (uniChar != 0) {
                handleInput((char) event.getUnicodeChar());
                handled = true;
            }
        }
    }

    return handled;
}

From source file:net.evendanan.android.thumbremote.ui.RemoteUiActivity.java

/**
 * Handler an android keypress and send it to boxee if appropriate.
 *///from  w ww.j a v a2  s .c om
@Override
public boolean onKeyDown(final int keyCode, final KeyEvent event) {
    switch (keyCode) {
    case KeyEvent.KEYCODE_BACK:
        if (RemoteApplication.getConfig().getHandleBack()) {
            Log.d(TAG, "Will handle back");
            if (mBoundService != null)
                mBoundService.remoteBack();
            return true;
        } else {
            Log.d(TAG, "Will NOT handle back");
            return super.onKeyDown(keyCode, event);
        }

    case KeyEvent.KEYCODE_DPAD_CENTER:
        if (mBoundService != null)
            mBoundService.remoteSelect();
        return true;

    case KeyEvent.KEYCODE_DPAD_DOWN:
        if (mBoundService != null)
            mBoundService.remoteDown();
        return true;

    case KeyEvent.KEYCODE_DPAD_UP:
        if (mBoundService != null)
            mBoundService.remoteUp();
        return true;

    case KeyEvent.KEYCODE_DPAD_LEFT:
        if (mBoundService != null)
            mBoundService.remoteLeft();
        return true;

    case KeyEvent.KEYCODE_DPAD_RIGHT:
        if (mBoundService != null)
            mBoundService.remoteRight();
        return true;

    case KeyEvent.KEYCODE_VOLUME_UP:
    case KeyEvent.KEYCODE_VOLUME_DOWN:
        final int volumeFactor = (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) ? -1 : 1;
        final int volumeOffset = (volumeFactor * RemoteApplication.getConfig().getVolumeStep());
        if (mBoundService != null)
            mBoundService.remoteVolumeOffset(volumeOffset);
        return true;
    case KeyEvent.KEYCODE_DEL:
        if (mBoundService != null)
            mBoundService.remoteKeypress((char) 8);
        return true;
    default:
        final char unicodeChar = (char) event.getUnicodeChar();

        // Log.d(TAG, "Unicode is " + ((char)unicodeChar));

        if (Character.isLetterOrDigit(unicodeChar) || msPunctuation.contains(unicodeChar)) {
            // Log.d(TAG, "handling " + ((char)unicodeChar));
            if (mBoundService != null)
                mBoundService.remoteKeypress(unicodeChar);
            return true;
        } else {
            return super.onKeyDown(keyCode, event);
        }
    }
}

From source file:research.sg.edu.edapp.kb.KbSoftKeyboard.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   w w w  .  ja  va2 s  . c om
 */
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    String s = "" + event.getUnicodeChar();
    Log.d("CAME HERE", "CAME HERE");
    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 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) {
            //*********added changes here
            if (event.getAction() == KeyEvent.ACTION_DOWN) {
                swipe += (char) event.getUnicodeChar();
                Log.d("msg", swipe);
                System.out.println(swipe);
                // keyDownUp(keyCode);
                //   return true;
            }
            //*********done
            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 = getCurrentInputConnection();
                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.duy.pascal.ui.view.console.ConsoleView.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (event.isSystem()) {
        return super.onKeyDown(keyCode, event);
    }/*from w  ww .j  av  a  2 s . co m*/
    mKeyBuffer.push((char) event.getUnicodeChar()); //scan code

    if (keyCode == KeyEvent.KEYCODE_DEL) {
        putString(THE_DELETE_COMMAND);
        return true;
    }
    String c = event.getCharacters();
    if (c == null) {
        c = Character.valueOf((char) event.getUnicodeChar()).toString();
    }
    putString(c);
    return true;
}

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

@SuppressWarnings("deprecation")
void findItemsWithShortcutForKey(List<MenuItemImpl> items, int keyCode, KeyEvent event) {
    final boolean qwerty = isQwertyMode();
    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)
    final boolean isKeyCodeMapped = event.getKeyData(possibleChars);
    // The delete key is not mapped to '\b' so we treat it specially
    if (!isKeyCodeMapped && (keyCode != KeyEvent.KEYCODE_DEL)) {
        return;/*  w w w .j a v a 2  s. c  o  m*/
    }

    // Look for an item whose shortcut is this key.
    final int N = mItems.size();
    for (int i = 0; i < N; i++) {
        MenuItemImpl item = mItems.get(i);
        if (item.hasSubMenu()) {
            ((MenuBuilder) item.getSubMenu()).findItemsWithShortcutForKey(items, keyCode, event);
        }
        final char shortcutChar = qwerty ? item.getAlphabeticShortcut() : item.getNumericShortcut();
        if (((metaState & (KeyEvent.META_SHIFT_ON | KeyEvent.META_SYM_ON)) == 0) && (shortcutChar != 0)
                && (shortcutChar == possibleChars.meta[0] || shortcutChar == possibleChars.meta[2]
                        || (qwerty && shortcutChar == '\b' && keyCode == KeyEvent.KEYCODE_DEL))
                && item.isEnabled()) {
            items.add(item);
        }
    }
}

From source file:io.doist.datetimepicker.time.TimePickerClockDelegate.java

/**
 * For keyboard mode, processes key events.
 *
 * @param keyCode the pressed key.//from www .ja  v a2s  .co  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));
                }
                mDelegator.announceForAccessibility(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'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.tr4android.support.extension.picker.time.AppCompatTimePickerDelegate.java

/**
 * For keyboard mode, processes key events.
 *
 * @param keyCode the pressed key.//w  w w . j a  va2  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));
                }
                ViewCompatUtils.announceForAccessibility(mDelegator,
                        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'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:androidv7.rmenu.MBuilder.java

@SuppressWarnings("deprecation")
void findItemsWithShortcutForKey(List<MenuItemImpl> items, int keyCode, KeyEvent event) {
    final boolean qwerty = isQwertyMode();
    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)
    final boolean isKeyCodeMapped = event.getKeyData(possibleChars);
    // The delete key is not mapped to '\b' so we treat it specially
    if (!isKeyCodeMapped && (keyCode != KeyEvent.KEYCODE_DEL)) {
        return;//w w w.j  a  va 2 s .  co m
    }

    // Look for an item whose shortcut is this key.
    final int N = mItems.size();
    for (int i = 0; i < N; i++) {
        MenuItemImpl item = mItems.get(i);
        if (item.hasSubMenu()) {
            ((MBuilder) item.getSubMenu()).findItemsWithShortcutForKey(items, keyCode, event);
        }
        final char shortcutChar = qwerty ? item.getAlphabeticShortcut() : item.getNumericShortcut();
        if (((metaState & (KeyEvent.META_SHIFT_ON | KeyEvent.META_SYM_ON)) == 0) && (shortcutChar != 0)
                && (shortcutChar == possibleChars.meta[0] || shortcutChar == possibleChars.meta[2]
                        || (qwerty && shortcutChar == '\b' && keyCode == KeyEvent.KEYCODE_DEL))
                && item.isEnabled()) {
            items.add(item);
        }
    }
}