MODIFIER_BEHAVIOR_CHORDED_OR_TOGGLED源码实例Demo

android.view.KeyCharacterMap#MODIFIER_BEHAVIOR_CHORDED_OR_TOGGLED源码实例Demo

下面列出了android.view.KeyCharacterMap#MODIFIER_BEHAVIOR_CHORDED_OR_TOGGLED 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: android_9.0.0_r45   文件: MetaKeyKeyListener.java
/**
 * Gets the state of a particular meta key to use with a particular key event.
 *
 * If the key event has been created by a device that does not support toggled
 * key modifiers, like a virtual keyboard for example, only the meta state in
 * the key event is considered.
 *
 * @param meta META_SHIFT_ON, META_ALT_ON, META_SYM_ON
 * @param text the buffer in which the meta key would have been pressed.
 * @param event the event for which to evaluate the meta state.
 * @return 0 if inactive, 1 if active, 2 if locked.
 */
public static final int getMetaState(final CharSequence text, final int meta,
        final KeyEvent event) {
    int metaState = event.getMetaState();
    if (event.getKeyCharacterMap().getModifierBehavior()
            == KeyCharacterMap.MODIFIER_BEHAVIOR_CHORDED_OR_TOGGLED) {
        metaState |= getMetaState(text);
    }
    if (META_SELECTING == meta) {
        // #getMetaState(long, int) does not support META_SELECTING, but we want the same
        // behavior as #getMetaState(CharSequence, int) so we need to do it here
        if ((metaState & META_SELECTING) != 0) {
            // META_SELECTING is only ever set to PRESSED and can't be LOCKED, so return 1
            return 1;
        }
        return 0;
    }
    return getMetaState(metaState, meta);
}
 
源代码2 项目: android_9.0.0_r45   文件: MetaKeyKeyListener.java
private void release(Editable content, Object what, KeyEvent event) {
    int current = content.getSpanFlags(what);

    switch (event.getKeyCharacterMap().getModifierBehavior()) {
        case KeyCharacterMap.MODIFIER_BEHAVIOR_CHORDED_OR_TOGGLED:
            if (current == USED)
                content.removeSpan(what);
            else if (current == PRESSED)
                content.setSpan(what, 0, 0, RELEASED);
            break;

        default:
            content.removeSpan(what);
            break;
    }
}
 
源代码3 项目: android_9.0.0_r45   文件: MetaKeyKeyListener.java
private static long release(long state, int what, long mask,
        long pressed, long released, long used, KeyEvent event) {
    switch (event.getKeyCharacterMap().getModifierBehavior()) {
        case KeyCharacterMap.MODIFIER_BEHAVIOR_CHORDED_OR_TOGGLED:
            if ((state & used) != 0) {
                state &= ~mask;
            } else if ((state & pressed) != 0) {
                state |= what | released;
            }
            break;

        default:
            state &= ~mask;
            break;
    }
    return state;
}
 
源代码4 项目: android_9.0.0_r45   文件: MetaKeyKeyListener.java
/**
 * Gets the state of the meta keys for a specific key event.
 *
 * For input devices that use toggled key modifiers, the `toggled' state
 * is stored into the text buffer. This method retrieves the meta state
 * for this event, accounting for the stored state. If the event has been
 * created by a device that does not support toggled key modifiers, like
 * a virtual device for example, the stored state is ignored.
 *
 * @param text the buffer in which the meta key would have been pressed.
 * @param event the event for which to evaluate the meta state.
 * @return an integer in which each bit set to one represents a pressed
 *         or locked meta key.
 */
public static final int getMetaState(final CharSequence text, final KeyEvent event) {
    int metaState = event.getMetaState();
    if (event.getKeyCharacterMap().getModifierBehavior()
            == KeyCharacterMap.MODIFIER_BEHAVIOR_CHORDED_OR_TOGGLED) {
        metaState |= getMetaState(text);
    }
    return metaState;
}