android.view.KeyEvent#META_ALT_ON源码实例Demo

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

源代码1 项目: talkback   文件: DefaultKeyComboModel.java
private void loadTriggerModifierFromPreferences() {
  SharedPreferences prefs = SharedPreferencesUtils.getSharedPreferences(mContext);
  int defaultTriggerModifier =
      mIsArc
          ? R.string.trigger_modifier_meta_entry_value
          : R.string.trigger_modifier_alt_entry_value;

  if (!prefs.contains(getPreferenceKeyForTriggerModifier())) {
    // Store default value in preferences to show it in preferences UI.
    prefs
        .edit()
        .putString(
            getPreferenceKeyForTriggerModifier(), mContext.getString(defaultTriggerModifier))
        .apply();
  }

  String triggerModifier =
      prefs.getString(
          getPreferenceKeyForTriggerModifier(), mContext.getString(defaultTriggerModifier));
  if (triggerModifier.equals(mContext.getString(R.string.trigger_modifier_alt_entry_value))) {
    mTriggerModifier = KeyEvent.META_ALT_ON;
  } else if (triggerModifier.equals(
      mContext.getString(R.string.trigger_modifier_meta_entry_value))) {
    mTriggerModifier = KeyEvent.META_META_ON;
  }
}
 
源代码2 项目: 365browser   文件: ImeAdapter.java
private static int getModifiers(int metaState) {
    int modifiers = 0;
    if ((metaState & KeyEvent.META_SHIFT_ON) != 0) {
        modifiers |= WebInputEventModifier.SHIFT_KEY;
    }
    if ((metaState & KeyEvent.META_ALT_ON) != 0) {
        modifiers |= WebInputEventModifier.ALT_KEY;
    }
    if ((metaState & KeyEvent.META_CTRL_ON) != 0) {
        modifiers |= WebInputEventModifier.CONTROL_KEY;
    }
    if ((metaState & KeyEvent.META_CAPS_LOCK_ON) != 0) {
        modifiers |= WebInputEventModifier.CAPS_LOCK_ON;
    }
    if ((metaState & KeyEvent.META_NUM_LOCK_ON) != 0) {
        modifiers |= WebInputEventModifier.NUM_LOCK_ON;
    }
    return modifiers;
}
 
源代码3 项目: android-chromium   文件: ImeAdapter.java
private static int getModifiers(int metaState) {
    int modifiers = 0;
    if ((metaState & KeyEvent.META_SHIFT_ON) != 0) {
      modifiers |= sModifierShift;
    }
    if ((metaState & KeyEvent.META_ALT_ON) != 0) {
      modifiers |= sModifierAlt;
    }
    if ((metaState & KeyEvent.META_CTRL_ON) != 0) {
      modifiers |= sModifierCtrl;
    }
    if ((metaState & KeyEvent.META_CAPS_LOCK_ON) != 0) {
      modifiers |= sModifierCapsLockOn;
    }
    if ((metaState & KeyEvent.META_NUM_LOCK_ON) != 0) {
      modifiers |= sModifierNumLockOn;
    }
    return modifiers;
}
 
源代码4 项目: android-chromium   文件: ImeAdapter.java
private static int getModifiers(int metaState) {
    int modifiers = 0;
    if ((metaState & KeyEvent.META_SHIFT_ON) != 0) {
      modifiers |= sModifierShift;
    }
    if ((metaState & KeyEvent.META_ALT_ON) != 0) {
      modifiers |= sModifierAlt;
    }
    if ((metaState & KeyEvent.META_CTRL_ON) != 0) {
      modifiers |= sModifierCtrl;
    }
    if ((metaState & KeyEvent.META_CAPS_LOCK_ON) != 0) {
      modifiers |= sModifierCapsLockOn;
    }
    if ((metaState & KeyEvent.META_NUM_LOCK_ON) != 0) {
      modifiers |= sModifierNumLockOn;
    }
    return modifiers;
}
 
源代码5 项目: CSipSimple   文件: MenuBuilder.java
@SuppressWarnings("deprecation")
MenuItemImpl findItemWithShortcutForKey(int keyCode, KeyEvent event) {
    // Get all items that can be associated directly or indirectly with the keyCode
    ArrayList<MenuItemImpl> items = mTempShortcutItemList;
    items.clear();
    findItemsWithShortcutForKey(items, keyCode, event);

    if (items.isEmpty()) {
        return null;
    }

    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)
    event.getKeyData(possibleChars);

    // If we have only one element, we can safely returns it
    final int size = items.size();
    if (size == 1) {
        return items.get(0);
    }

    final boolean qwerty = isQwertyMode();
    // If we found more than one item associated with the key,
    // we have to return the exact match
    for (int i = 0; i < size; i++) {
        final MenuItemImpl item = items.get(i);
        final char shortcutChar = qwerty ? item.getAlphabeticShortcut() :
                item.getNumericShortcut();
        if ((shortcutChar == possibleChars.meta[0] &&
                (metaState & KeyEvent.META_ALT_ON) == 0)
            || (shortcutChar == possibleChars.meta[2] &&
                (metaState & KeyEvent.META_ALT_ON) != 0)
            || (qwerty && shortcutChar == '\b' &&
                keyCode == KeyEvent.KEYCODE_DEL)) {
            return item;
        }
    }
    return null;
}
 
源代码6 项目: hackerskeyboard   文件: LatinIME.java
private int getMetaState(boolean shifted) {
    int meta = 0;
    if (shifted) meta |= KeyEvent.META_SHIFT_ON | KeyEvent.META_SHIFT_LEFT_ON;
    if (mModCtrl) meta |= KeyEvent.META_CTRL_ON | KeyEvent.META_CTRL_LEFT_ON;
    if (mModAlt) meta |= KeyEvent.META_ALT_ON | KeyEvent.META_ALT_LEFT_ON;
    if (mModMeta) meta |= KeyEvent.META_META_ON | KeyEvent.META_META_LEFT_ON;
    return meta;
}
 
源代码7 项目: hackerskeyboard   文件: LatinIME.java
private void sendAltKey(InputConnection ic, boolean isDown, boolean chording) {
    if (chording && delayChordingAltModifier()) return;

    int key = sKeyboardSettings.chordingAltKey;
    if (key == 0) key = KeyEvent.KEYCODE_ALT_LEFT;
    int meta = KeyEvent.META_ALT_ON | KeyEvent.META_ALT_LEFT_ON;
    if (isDown) {
        sendKeyDown(ic, key, meta);
    } else {
        sendKeyUp(ic, key, meta);
    }
}
 
源代码8 项目: talkback   文件: KeyAssignmentUtils.java
/**
 * Convert a KeyEvent into a long which can be kept in settings and compared to key presses when
 * the service is in use.
 *
 * @param keyEvent The key event to convert. The (non-extended) keycode must not be a modifier.
 * @return An extended key code that includes modifier information
 */
public static long keyEventToExtendedKeyCode(KeyEvent keyEvent) {
  long returnValue = keyEvent.getKeyCode();
  returnValue |= (keyEvent.isShiftPressed()) ? (((long) KeyEvent.META_SHIFT_ON) << 32) : 0;
  returnValue |= (keyEvent.isCtrlPressed()) ? (((long) KeyEvent.META_CTRL_ON) << 32) : 0;
  returnValue |= (keyEvent.isAltPressed()) ? (((long) KeyEvent.META_ALT_ON) << 32) : 0;
  return returnValue;
}
 
源代码9 项目: CodenameOne   文件: KeyEventCompat.java
@Override
public int normalizeMetaState(int metaState) {
    if ((metaState & (KeyEvent.META_SHIFT_LEFT_ON | KeyEvent.META_SHIFT_RIGHT_ON)) != 0) {
        metaState |= KeyEvent.META_SHIFT_ON;
    }
    if ((metaState & (KeyEvent.META_ALT_LEFT_ON | KeyEvent.META_ALT_RIGHT_ON)) != 0) {
        metaState |= KeyEvent.META_ALT_ON;
    }
    return metaState & META_ALL_MASK;
}
 
源代码10 项目: adt-leanback-support   文件: KeyEventCompat.java
@Override
public int normalizeMetaState(int metaState) {
    if ((metaState & (KeyEvent.META_SHIFT_LEFT_ON | KeyEvent.META_SHIFT_RIGHT_ON)) != 0) {
        metaState |= KeyEvent.META_SHIFT_ON;
    }
    if ((metaState & (KeyEvent.META_ALT_LEFT_ON | KeyEvent.META_ALT_RIGHT_ON)) != 0) {
        metaState |= KeyEvent.META_ALT_ON;
    }
    return metaState & META_ALL_MASK;
}
 
源代码11 项目: android-apps   文件: MenuBuilder.java
@SuppressWarnings("deprecation")
MenuItemImpl findItemWithShortcutForKey(int keyCode, KeyEvent event) {
    // Get all items that can be associated directly or indirectly with the keyCode
    ArrayList<MenuItemImpl> items = mTempShortcutItemList;
    items.clear();
    findItemsWithShortcutForKey(items, keyCode, event);

    if (items.isEmpty()) {
        return null;
    }

    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)
    event.getKeyData(possibleChars);

    // If we have only one element, we can safely returns it
    final int size = items.size();
    if (size == 1) {
        return items.get(0);
    }

    final boolean qwerty = isQwertyMode();
    // If we found more than one item associated with the key,
    // we have to return the exact match
    for (int i = 0; i < size; i++) {
        final MenuItemImpl item = items.get(i);
        final char shortcutChar = qwerty ? item.getAlphabeticShortcut() :
                item.getNumericShortcut();
        if ((shortcutChar == possibleChars.meta[0] &&
                (metaState & KeyEvent.META_ALT_ON) == 0)
            || (shortcutChar == possibleChars.meta[2] &&
                (metaState & KeyEvent.META_ALT_ON) != 0)
            || (qwerty && shortcutChar == '\b' &&
                keyCode == KeyEvent.KEYCODE_DEL)) {
            return item;
        }
    }
    return null;
}
 
源代码12 项目: android-recipes-app   文件: KeyEventCompat.java
@Override
public int normalizeMetaState(int metaState) {
    if ((metaState & (KeyEvent.META_SHIFT_LEFT_ON | KeyEvent.META_SHIFT_RIGHT_ON)) != 0) {
        metaState |= KeyEvent.META_SHIFT_ON;
    }
    if ((metaState & (KeyEvent.META_ALT_LEFT_ON | KeyEvent.META_ALT_RIGHT_ON)) != 0) {
        metaState |= KeyEvent.META_ALT_ON;
    }
    return metaState & META_ALL_MASK;
}
 
源代码13 项目: V.FlyoutTest   文件: KeyEventCompat.java
@Override
public int normalizeMetaState(int metaState) {
    if ((metaState & (KeyEvent.META_SHIFT_LEFT_ON | KeyEvent.META_SHIFT_RIGHT_ON)) != 0) {
        metaState |= KeyEvent.META_SHIFT_ON;
    }
    if ((metaState & (KeyEvent.META_ALT_LEFT_ON | KeyEvent.META_ALT_RIGHT_ON)) != 0) {
        metaState |= KeyEvent.META_ALT_ON;
    }
    return metaState & META_ALL_MASK;
}
 
源代码14 项目: guideshow   文件: KeyEventCompat.java
@Override
public int normalizeMetaState(int metaState) {
    if ((metaState & (KeyEvent.META_SHIFT_LEFT_ON | KeyEvent.META_SHIFT_RIGHT_ON)) != 0) {
        metaState |= KeyEvent.META_SHIFT_ON;
    }
    if ((metaState & (KeyEvent.META_ALT_LEFT_ON | KeyEvent.META_ALT_RIGHT_ON)) != 0) {
        metaState |= KeyEvent.META_ALT_ON;
    }
    return metaState & META_ALL_MASK;
}
 
源代码15 项目: zen4android   文件: MenuBuilder.java
@SuppressWarnings("deprecation")
MenuItemImpl findItemWithShortcutForKey(int keyCode, KeyEvent event) {
    // Get all items that can be associated directly or indirectly with the keyCode
    ArrayList<MenuItemImpl> items = mTempShortcutItemList;
    items.clear();
    findItemsWithShortcutForKey(items, keyCode, event);

    if (items.isEmpty()) {
        return null;
    }

    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)
    event.getKeyData(possibleChars);

    // If we have only one element, we can safely returns it
    final int size = items.size();
    if (size == 1) {
        return items.get(0);
    }

    final boolean qwerty = isQwertyMode();
    // If we found more than one item associated with the key,
    // we have to return the exact match
    for (int i = 0; i < size; i++) {
        final MenuItemImpl item = items.get(i);
        final char shortcutChar = qwerty ? item.getAlphabeticShortcut() :
                item.getNumericShortcut();
        if ((shortcutChar == possibleChars.meta[0] &&
                (metaState & KeyEvent.META_ALT_ON) == 0)
            || (shortcutChar == possibleChars.meta[2] &&
                (metaState & KeyEvent.META_ALT_ON) != 0)
            || (qwerty && shortcutChar == '\b' &&
                keyCode == KeyEvent.KEYCODE_DEL)) {
            return item;
        }
    }
    return null;
}
 
源代码16 项目: zhangshangwuda   文件: MenuBuilder.java
@SuppressWarnings("deprecation")
MenuItemImpl findItemWithShortcutForKey(int keyCode, KeyEvent event) {
    // Get all items that can be associated directly or indirectly with the keyCode
    ArrayList<MenuItemImpl> items = mTempShortcutItemList;
    items.clear();
    findItemsWithShortcutForKey(items, keyCode, event);

    if (items.isEmpty()) {
        return null;
    }

    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)
    event.getKeyData(possibleChars);

    // If we have only one element, we can safely returns it
    final int size = items.size();
    if (size == 1) {
        return items.get(0);
    }

    final boolean qwerty = isQwertyMode();
    // If we found more than one item associated with the key,
    // we have to return the exact match
    for (int i = 0; i < size; i++) {
        final MenuItemImpl item = items.get(i);
        final char shortcutChar = qwerty ? item.getAlphabeticShortcut() :
                item.getNumericShortcut();
        if ((shortcutChar == possibleChars.meta[0] &&
                (metaState & KeyEvent.META_ALT_ON) == 0)
            || (shortcutChar == possibleChars.meta[2] &&
                (metaState & KeyEvent.META_ALT_ON) != 0)
            || (qwerty && shortcutChar == '\b' &&
                keyCode == KeyEvent.KEYCODE_DEL)) {
            return item;
        }
    }
    return null;
}
 
@SuppressWarnings("deprecation")
MenuItemImpl findItemWithShortcutForKey(int keyCode, KeyEvent event) {
    // Get all items that can be associated directly or indirectly with the keyCode
    ArrayList<MenuItemImpl> items = mTempShortcutItemList;
    items.clear();
    findItemsWithShortcutForKey(items, keyCode, event);

    if (items.isEmpty()) {
        return null;
    }

    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)
    event.getKeyData(possibleChars);

    // If we have only one element, we can safely returns it
    final int size = items.size();
    if (size == 1) {
        return items.get(0);
    }

    final boolean qwerty = isQwertyMode();
    // If we found more than one item associated with the key,
    // we have to return the exact match
    for (int i = 0; i < size; i++) {
        final MenuItemImpl item = items.get(i);
        final char shortcutChar = qwerty ? item.getAlphabeticShortcut() :
                item.getNumericShortcut();
        if ((shortcutChar == possibleChars.meta[0] &&
                (metaState & KeyEvent.META_ALT_ON) == 0)
            || (shortcutChar == possibleChars.meta[2] &&
                (metaState & KeyEvent.META_ALT_ON) != 0)
            || (qwerty && shortcutChar == '\b' &&
                keyCode == KeyEvent.KEYCODE_DEL)) {
            return item;
        }
    }
    return null;
}
 
源代码18 项目: java-n-IDE-for-Android   文件: TerminalKeyboard.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.
     */
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
//        Log.v("SpartacusRex","SOFT : onKeyDown "+ keyCode+" "+event.getMetaState());
        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) {
                    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);
    }
 
源代码19 项目: AndroidKeyboard   文件: SoftKeyboard.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.
 */
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    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) {
                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);
}
 
源代码20 项目: talkback   文件: KeyAssignmentUtils.java
/**
 * Create a string that describes the extended key code. This string can be shown to the user to
 * indicate the current choice of key.
 *
 * @param extendedKeyCode The key code to describe
 * @param context The current Context
 * @return A description of the key code
 */
public static String describeExtendedKeyCode(long extendedKeyCode, Context context) {
  if (extendedKeyCode == INVALID_EXTENDED_KEY_CODE) {
    return context.getString(R.string.no_key_assigned);
  }

  if (extendedKeyCode == KEYCODE_SCREEN_SWITCH) {
    return context.getString(R.string.name_of_screen_switch);
  }
  /* If meta keys are pressed, build a string to represent this combination of keys */
  StringBuilder keystrokeDescriptionBuilder = new StringBuilder();
  if ((extendedKeyCode & (((long) KeyEvent.META_CTRL_ON) << 32)) != 0) {
    keystrokeDescriptionBuilder.append(
        context.getString(R.string.key_combo_preference_control_plus));
  }
  if ((extendedKeyCode & (((long) KeyEvent.META_ALT_ON) << 32)) != 0) {
    keystrokeDescriptionBuilder.append(context.getString(R.string.key_combo_preference_alt_plus));
  }
  if ((extendedKeyCode & (((long) KeyEvent.META_SHIFT_ON) << 32)) != 0) {
    keystrokeDescriptionBuilder.append(
        context.getString(R.string.key_combo_preference_shift_plus));
  }

  /* Try to obtain a localized representation of the key */
  KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_DOWN, (int) extendedKeyCode);
  char displayLabel = keyEvent.getDisplayLabel();
  if (displayLabel != 0 && !Character.isWhitespace(displayLabel)) {
    keystrokeDescriptionBuilder.append(displayLabel);
  } else if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_SPACE) {
    keystrokeDescriptionBuilder.append(context.getString(R.string.name_of_space_bar));
  } else if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
    keystrokeDescriptionBuilder.append(context.getString(R.string.name_of_enter_key));
  } else if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_TAB) {
    keystrokeDescriptionBuilder.append(context.getString(R.string.name_of_tab_key));
  } else {
    /* Fall back on non-localized descriptions */
    keystrokeDescriptionBuilder.append(KeyEvent.keyCodeToString((int) extendedKeyCode));
  }

  return keystrokeDescriptionBuilder.toString();
}
 
 方法所在类
 同类方法