Java Code Examples for android.view.KeyEvent#getKeyData()

The following examples show how to use android.view.KeyEvent#getKeyData() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MenuBuilder.java    From CSipSimple with GNU General Public License v3.0 5 votes vote down vote up
@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;
    }

    // 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);
        }
    }
}
 
Example 2
Source File: MenuBuilder.java    From CSipSimple with GNU General Public License v3.0 5 votes vote down vote up
@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;
}
 
Example 3
Source File: MenuBuilder.java    From android-apps with MIT License 5 votes vote down vote up
@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;
    }

    // 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);
        }
    }
}
 
Example 4
Source File: MenuBuilder.java    From android-apps with MIT License 5 votes vote down vote up
@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;
}
 
Example 5
Source File: MenuBuilder.java    From zen4android with MIT License 5 votes vote down vote up
@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;
    }

    // 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);
        }
    }
}
 
Example 6
Source File: MenuBuilder.java    From zen4android with MIT License 5 votes vote down vote up
@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;
}
 
Example 7
Source File: MenuBuilder.java    From zhangshangwuda with Apache License 2.0 5 votes vote down vote up
@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;
    }

    // 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);
        }
    }
}
 
Example 8
Source File: MenuBuilder.java    From zhangshangwuda with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 9
Source File: MenuBuilder.java    From Libraries-for-Android-Developers with MIT License 5 votes vote down vote up
@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;
    }

    // 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);
        }
    }
}
 
Example 10
Source File: MenuBuilder.java    From Libraries-for-Android-Developers with MIT License 5 votes vote down vote up
@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;
}
 
Example 11
Source File: DialerKeyListener.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/**
 * Overrides the superclass's lookup method to prefer the number field
 * from the KeyEvent.
 */
protected int lookup(KeyEvent event, Spannable content) {
    int meta = getMetaState(content, event);
    int number = event.getNumber();

    /*
     * Prefer number if no meta key is active, or if it produces something
     * valid and the meta lookup does not.
     */
    if ((meta & (MetaKeyKeyListener.META_ALT_ON | MetaKeyKeyListener.META_SHIFT_ON)) == 0) {
        if (number != 0) {
            return number;
        }
    }

    int match = super.lookup(event, content);

    if (match != 0) {
        return match;
    } else {
        /*
         * If a meta key is active but the lookup with the meta key
         * did not produce anything, try some other meta keys, because
         * the user might have pressed SHIFT when they meant ALT,
         * or vice versa.
         */

        if (meta != 0) {
            KeyData kd = new KeyData();
            char[] accepted = getAcceptedChars();

            if (event.getKeyData(kd)) {
                for (int i = 1; i < kd.meta.length; i++) {
                    if (ok(accepted, kd.meta[i])) {
                        return kd.meta[i];
                    }
                }
            }
        }

        /*
         * Otherwise, use the number associated with the key, since
         * whatever they wanted to do with the meta key does not
         * seem to be valid here.
         */

        return number;
    }
}