Example usage for android.text.method MetaKeyKeyListener adjustMetaAfterKeypress

List of usage examples for android.text.method MetaKeyKeyListener adjustMetaAfterKeypress

Introduction

In this page you can find the example usage for android.text.method MetaKeyKeyListener adjustMetaAfterKeypress.

Prototype

public static long adjustMetaAfterKeypress(long state) 

Source Link

Document

Call this method after you handle a keypress so that the meta state will be reset to unshifted (if it is not still down) or primed to be reset to unshifted (once it is released).

Usage

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/>/*  w  ww .  j a 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:research.sg.edu.edapp.kb.KbSoftKeyboard.java

/**
 * This translates incoming hard key events in to edit operations on an
 * InputConnection.  It is only needed when using the
 * PROCESS_HARD_KEYS option./*from  ww  w  .ja va  2s . c  om*/
 */

private boolean translateKeyDown(int keyCode, KeyEvent event) {
    mMetaState = MetaKeyKeyListener.handleKeyDown(mMetaState, keyCode, event);
    int c = event.getUnicodeChar(MetaKeyKeyListener.getMetaState(mMetaState));
    mMetaState = MetaKeyKeyListener.adjustMetaAfterKeypress(mMetaState);
    InputConnection ic = getCurrentInputConnection();
    if (c == 0 || ic == null) {
        return false;
    }

    boolean dead = false;

    if ((c & KeyCharacterMap.COMBINING_ACCENT) != 0) {
        dead = true;
        c = c & KeyCharacterMap.COMBINING_ACCENT_MASK;
    }

    if (mComposing.length() > 0) {
        char accent = mComposing.charAt(mComposing.length() - 1);
        int composed = KeyEvent.getDeadChar(accent, c);

        if (composed != 0) {
            c = composed;
            mComposing.setLength(mComposing.length() - 1);
        }
    }

    Log.d("Cum", "Cum");
    onKey(c, null);

    return true;
}

From source file:com.strathclyde.highlightingkeyboard.SoftKeyboardService.java

/**
 * This translates incoming hard key events in to edit operations on an
 * InputConnection.  It is only needed when using the
 * PROCESS_HARD_KEYS option.//from ww w.  java2 s .  co  m
 */
private boolean translateKeyDown(int keyCode, KeyEvent event) {
    mMetaState = MetaKeyKeyListener.handleKeyDown(mMetaState, keyCode, event);
    int c = event.getUnicodeChar(MetaKeyKeyListener.getMetaState(mMetaState));
    mMetaState = MetaKeyKeyListener.adjustMetaAfterKeypress(mMetaState);
    //InputConnection ic = ic;
    if (c == 0 || ic == null) {
        return false;
    }

    if ((c & KeyCharacterMap.COMBINING_ACCENT) != 0) {
        c = c & KeyCharacterMap.COMBINING_ACCENT_MASK;
    }

    if (mComposing.length() > 0) {
        char accent = mComposing.charAt(mComposing.length() - 1);
        int composed = KeyEvent.getDeadChar(accent, c);

        if (composed != 0) {
            c = composed;
            mComposing.setLength(mComposing.length() - 1);
        }
    }

    onKey(c, null);

    return true;
}