Example usage for android.view KeyEvent KEYCODE_FORWARD_DEL

List of usage examples for android.view KeyEvent KEYCODE_FORWARD_DEL

Introduction

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

Prototype

int KEYCODE_FORWARD_DEL

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

Click Source Link

Document

Key code constant: Forward Delete key.

Usage

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

@Override
public boolean onMappedInputEvent(BrailleInputEvent event, DisplayManager.Content content) {
    BrailleIME ime = getIME();//w ww.j av a  2s  .c  o  m

    // These commands are handled by the IME whenever it is accepting
    // input, even if it has not taken control of the display.
    if (ime != null && mState.acceptsText()) {
        switch (event.getCommand()) {
        case BrailleInputEvent.CMD_KEY_DEL:
            return ime.sendAndroidKey(KeyEvent.KEYCODE_DEL);
        case BrailleInputEvent.CMD_KEY_ENTER:
            return ime.sendAndroidKey(KeyEvent.KEYCODE_ENTER);
        case BrailleInputEvent.CMD_KEY_FORWARD_DEL:
            return ime.sendAndroidKey(KeyEvent.KEYCODE_FORWARD_DEL);
        case BrailleInputEvent.CMD_BRAILLE_KEY:
            return ime.handleBrailleKey(event.getArgument());
        }
    }

    // If navigation commands are handled by the IME in this state, then
    // move the cursor by the appropriate granularity.
    if (ime != null && mState.navigatesViaIME()) {
        switch (event.getCommand()) {
        case BrailleInputEvent.CMD_NAV_ITEM_PREVIOUS:
            return ime.moveCursor(BrailleIME.DIRECTION_BACKWARD,
                    AccessibilityNodeInfoCompat.MOVEMENT_GRANULARITY_CHARACTER);
        case BrailleInputEvent.CMD_NAV_ITEM_NEXT:
            return ime.moveCursor(BrailleIME.DIRECTION_FORWARD,
                    AccessibilityNodeInfoCompat.MOVEMENT_GRANULARITY_CHARACTER);
        case BrailleInputEvent.CMD_NAV_LINE_PREVIOUS:
            // Line navigation moves by paragraph since there's no way
            // of knowing the line extents in the edit text.
            return ime.moveCursor(BrailleIME.DIRECTION_BACKWARD,
                    AccessibilityNodeInfoCompat.MOVEMENT_GRANULARITY_PARAGRAPH);
        case BrailleInputEvent.CMD_NAV_LINE_NEXT:
            return ime.moveCursor(BrailleIME.DIRECTION_FORWARD,
                    AccessibilityNodeInfoCompat.MOVEMENT_GRANULARITY_PARAGRAPH);
        }
    }

    // Alternatively, we may handle these navigation commands by sending
    // "move by granularity" through the accessibility system.
    if (ime != null && mState.navigatesByTextGranularity()) {
        AccessibilityNodeInfoCompat focusedNode = getFocusedNode();
        switch (event.getCommand()) {
        case BrailleInputEvent.CMD_NAV_ITEM_PREVIOUS:
            return previousAtMovementGranularity(AccessibilityNodeInfoCompat.MOVEMENT_GRANULARITY_CHARACTER);
        case BrailleInputEvent.CMD_NAV_ITEM_NEXT:
            return nextAtMovementGranularity(AccessibilityNodeInfoCompat.MOVEMENT_GRANULARITY_CHARACTER);
        case BrailleInputEvent.CMD_NAV_LINE_PREVIOUS:
            return previousAtMovementGranularity(AccessibilityNodeInfoCompat.MOVEMENT_GRANULARITY_LINE);
        case BrailleInputEvent.CMD_NAV_LINE_NEXT:
            return nextAtMovementGranularity(AccessibilityNodeInfoCompat.MOVEMENT_GRANULARITY_LINE);
        }
    }

    // These commands are handled by the IME only when it has taken
    // control of the display. Otherwise, they are delegated.
    if (ime != null && mState.controlsDisplay()) {
        switch (event.getCommand()) {
        case BrailleInputEvent.CMD_ACTIVATE_CURRENT:
            return ime.sendDefaultAction();
        case BrailleInputEvent.CMD_ROUTE:
            return ime.route(event.getArgument(), content);
        }
    }

    // If all else fails, delegate the event.
    return mNext.onMappedInputEvent(event, content);
}

From source file:android.support.text.emoji.EmojiProcessor.java

/**
 * Handles onKeyDown commands from a {@link KeyListener} and if {@code keyCode} is one of
 * {@link KeyEvent#KEYCODE_DEL} or {@link KeyEvent#KEYCODE_FORWARD_DEL} it tries to delete an
 * {@link EmojiSpan} from an {@link Editable}. Returns {@code true} if an {@link EmojiSpan} is
 * deleted with the characters it covers.
 * <p/>//from w ww . ja  v a 2  s  . c o m
 * If there is a selection where selection start is not equal to selection end, does not
 * delete.
 *
 * @param editable Editable instance passed to {@link KeyListener#onKeyDown(android.view.View,
 *                 Editable, int, KeyEvent)}
 * @param keyCode keyCode passed to {@link KeyListener#onKeyDown(android.view.View, Editable,
 *                int, KeyEvent)}
 * @param event KeyEvent passed to {@link KeyListener#onKeyDown(android.view.View, Editable,
 *              int, KeyEvent)}
 *
 * @return {@code true} if an {@link EmojiSpan} is deleted
 */
static boolean handleOnKeyDown(@NonNull final Editable editable, final int keyCode, final KeyEvent event) {
    final boolean handled;
    switch (keyCode) {
    case KeyEvent.KEYCODE_DEL:
        handled = delete(editable, event, false /*forwardDelete*/);
        break;
    case KeyEvent.KEYCODE_FORWARD_DEL:
        handled = delete(editable, event, true /*forwardDelete*/);
        break;
    default:
        handled = false;
        break;
    }

    if (handled) {
        MetaKeyKeyListener.adjustMetaAfterKeypress(editable);
        return true;
    }

    return false;
}

From source file:ch.blinkenlights.android.vanilla.LibraryActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_DEL || keyCode == KeyEvent.KEYCODE_FORWARD_DEL)
        // On ICS, EditText reports backspace events as unhandled despite
        // actually handling them. To workaround, just assume the event was
        // handled if we get here.
        return true;

    if (super.onKeyDown(keyCode, event))
        return true;

    return false;
}

From source file:com.nachiket.titan.LibraryActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_DEL || keyCode == KeyEvent.KEYCODE_FORWARD_DEL)
        // On ICS, EditText reports backspace events as unhandled despite
        // actually handling them. To workaround, just assume the event was
        // handled if we get here.
        return true;

    if (super.onKeyDown(keyCode, event))
        return true;

    if (mTextFilter.onKeyDown(keyCode, event)) {
        if (!mSearchBoxVisible)
            setSearchBoxVisible(true);/*  w w  w . j  a v  a2 s . co  m*/
        else
            mTextFilter.requestFocus();
        return true;
    }

    return false;
}