The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.view; |
| 18 | |
| 19 | import android.os.Parcel; |
| 20 | import android.os.Parcelable; |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 21 | import android.text.method.MetaKeyKeyListener; |
Dianne Hackborn | 8d37426 | 2009-09-14 21:21:52 -0700 | [diff] [blame] | 22 | import android.util.Log; |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 23 | import android.util.SparseArray; |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 24 | import android.util.SparseIntArray; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | import android.view.KeyCharacterMap; |
| 26 | import android.view.KeyCharacterMap.KeyData; |
| 27 | |
| 28 | /** |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 29 | * Object used to report key and button events. |
| 30 | * <p> |
| 31 | * Each key press is described by a sequence of key events. A key press |
| 32 | * starts with a key event with {@link #ACTION_DOWN}. If the key is held |
| 33 | * sufficiently long that it repeats, then the initial down is followed |
| 34 | * additional key events with {@link #ACTION_DOWN} and a non-zero value for |
| 35 | * {@link #getRepeatCount()}. The last key event is a {@link #ACTION_UP} |
| 36 | * for the key up. If the key press is canceled, the key up event will have the |
| 37 | * {@link #FLAG_CANCELED} flag set. |
| 38 | * </p><p> |
| 39 | * Key events are generally accompanied by a key code ({@link #getKeyCode()}), |
| 40 | * scan code ({@link #getScanCode()}) and meta state ({@link #getMetaState()}). |
| 41 | * Key code constants are defined in this class. Scan code constants are raw |
| 42 | * device-specific codes obtained from the OS and so are not generally meaningful |
| 43 | * to applications unless interpreted using the {@link KeyCharacterMap}. |
| 44 | * Meta states describe the pressed state of key modifiers |
| 45 | * such as {@link #META_SHIFT_ON} or {@link #META_ALT_ON}. |
| 46 | * </p><p> |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 47 | * Key codes typically correspond one-to-one with individual keys on an input device. |
| 48 | * Many keys and key combinations serve quite different functions on different |
| 49 | * input devices so care must be taken when interpreting them. Always use the |
| 50 | * {@link KeyCharacterMap} associated with the input device when mapping keys |
| 51 | * to characters. Be aware that there may be multiple key input devices active |
| 52 | * at the same time and each will have its own key character map. |
| 53 | * </p><p> |
Jean Chalard | 405bc51 | 2012-05-29 19:12:34 +0900 | [diff] [blame] | 54 | * As soft input methods can use multiple and inventive ways of inputting text, |
| 55 | * there is no guarantee that any key press on a soft keyboard will generate a key |
| 56 | * event: this is left to the IME's discretion, and in fact sending such events is |
| 57 | * discouraged. You should never rely on receiving KeyEvents for any key on a soft |
| 58 | * input method. In particular, the default software keyboard will never send any |
| 59 | * key event to any application targetting Jelly Bean or later, and will only send |
| 60 | * events for some presses of the delete and return keys to applications targetting |
| 61 | * Ice Cream Sandwich or earlier. Be aware that other software input methods may |
| 62 | * never send key events regardless of the version. Consider using editor actions |
| 63 | * like {@link android.view.inputmethod.EditorInfo#IME_ACTION_DONE} if you need |
| 64 | * specific interaction with the software keyboard, as it gives more visibility to |
| 65 | * the user as to how your application will react to key presses. |
| 66 | * </p><p> |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 67 | * When interacting with an IME, the framework may deliver key events |
| 68 | * with the special action {@link #ACTION_MULTIPLE} that either specifies |
| 69 | * that single repeated key code or a sequence of characters to insert. |
| 70 | * </p><p> |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 71 | * In general, the framework cannot guarantee that the key events it delivers |
| 72 | * to a view always constitute complete key sequences since some events may be dropped |
| 73 | * or modified by containing views before they are delivered. The view implementation |
| 74 | * should be prepared to handle {@link #FLAG_CANCELED} and should tolerate anomalous |
| 75 | * situations such as receiving a new {@link #ACTION_DOWN} without first having |
| 76 | * received an {@link #ACTION_UP} for the prior key press. |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 77 | * </p><p> |
| 78 | * Refer to {@link InputDevice} for more information about how different kinds of |
| 79 | * input devices and sources represent keys and buttons. |
| 80 | * </p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 81 | */ |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 82 | public class KeyEvent extends InputEvent implements Parcelable { |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 83 | /** Key code constant: Unknown key code. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 84 | public static final int KEYCODE_UNKNOWN = 0; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 85 | /** Key code constant: Soft Left key. |
| 86 | * Usually situated below the display on phones and used as a multi-function |
| 87 | * feature key for selecting a software defined function shown on the bottom left |
| 88 | * of the display. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 89 | public static final int KEYCODE_SOFT_LEFT = 1; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 90 | /** Key code constant: Soft Right key. |
| 91 | * Usually situated below the display on phones and used as a multi-function |
| 92 | * feature key for selecting a software defined function shown on the bottom right |
| 93 | * of the display. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 94 | public static final int KEYCODE_SOFT_RIGHT = 2; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 95 | /** Key code constant: Home key. |
| 96 | * This key is handled by the framework and is never delivered to applications. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 97 | public static final int KEYCODE_HOME = 3; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 98 | /** Key code constant: Back key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 99 | public static final int KEYCODE_BACK = 4; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 100 | /** Key code constant: Call key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 101 | public static final int KEYCODE_CALL = 5; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 102 | /** Key code constant: End Call key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 103 | public static final int KEYCODE_ENDCALL = 6; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 104 | /** Key code constant: '0' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 105 | public static final int KEYCODE_0 = 7; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 106 | /** Key code constant: '1' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 107 | public static final int KEYCODE_1 = 8; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 108 | /** Key code constant: '2' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 109 | public static final int KEYCODE_2 = 9; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 110 | /** Key code constant: '3' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 111 | public static final int KEYCODE_3 = 10; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 112 | /** Key code constant: '4' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 113 | public static final int KEYCODE_4 = 11; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 114 | /** Key code constant: '5' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 115 | public static final int KEYCODE_5 = 12; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 116 | /** Key code constant: '6' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 117 | public static final int KEYCODE_6 = 13; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 118 | /** Key code constant: '7' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 119 | public static final int KEYCODE_7 = 14; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 120 | /** Key code constant: '8' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 121 | public static final int KEYCODE_8 = 15; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 122 | /** Key code constant: '9' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 123 | public static final int KEYCODE_9 = 16; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 124 | /** Key code constant: '*' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 125 | public static final int KEYCODE_STAR = 17; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 126 | /** Key code constant: '#' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 127 | public static final int KEYCODE_POUND = 18; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 128 | /** Key code constant: Directional Pad Up key. |
| 129 | * May also be synthesized from trackball motions. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 130 | public static final int KEYCODE_DPAD_UP = 19; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 131 | /** Key code constant: Directional Pad Down key. |
| 132 | * May also be synthesized from trackball motions. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 133 | public static final int KEYCODE_DPAD_DOWN = 20; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 134 | /** Key code constant: Directional Pad Left key. |
| 135 | * May also be synthesized from trackball motions. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 136 | public static final int KEYCODE_DPAD_LEFT = 21; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 137 | /** Key code constant: Directional Pad Right key. |
| 138 | * May also be synthesized from trackball motions. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 139 | public static final int KEYCODE_DPAD_RIGHT = 22; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 140 | /** Key code constant: Directional Pad Center key. |
| 141 | * May also be synthesized from trackball motions. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 142 | public static final int KEYCODE_DPAD_CENTER = 23; |
Jeff Brown | b0418da | 2010-11-01 15:24:01 -0700 | [diff] [blame] | 143 | /** Key code constant: Volume Up key. |
| 144 | * Adjusts the speaker volume up. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 145 | public static final int KEYCODE_VOLUME_UP = 24; |
Jeff Brown | b0418da | 2010-11-01 15:24:01 -0700 | [diff] [blame] | 146 | /** Key code constant: Volume Down key. |
| 147 | * Adjusts the speaker volume down. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 148 | public static final int KEYCODE_VOLUME_DOWN = 25; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 149 | /** Key code constant: Power key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 150 | public static final int KEYCODE_POWER = 26; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 151 | /** Key code constant: Camera key. |
| 152 | * Used to launch a camera application or take pictures. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 153 | public static final int KEYCODE_CAMERA = 27; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 154 | /** Key code constant: Clear key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 155 | public static final int KEYCODE_CLEAR = 28; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 156 | /** Key code constant: 'A' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 157 | public static final int KEYCODE_A = 29; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 158 | /** Key code constant: 'B' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 159 | public static final int KEYCODE_B = 30; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 160 | /** Key code constant: 'C' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 161 | public static final int KEYCODE_C = 31; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 162 | /** Key code constant: 'D' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 163 | public static final int KEYCODE_D = 32; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 164 | /** Key code constant: 'E' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 165 | public static final int KEYCODE_E = 33; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 166 | /** Key code constant: 'F' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 167 | public static final int KEYCODE_F = 34; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 168 | /** Key code constant: 'G' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 169 | public static final int KEYCODE_G = 35; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 170 | /** Key code constant: 'H' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 171 | public static final int KEYCODE_H = 36; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 172 | /** Key code constant: 'I' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 173 | public static final int KEYCODE_I = 37; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 174 | /** Key code constant: 'J' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 175 | public static final int KEYCODE_J = 38; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 176 | /** Key code constant: 'K' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 177 | public static final int KEYCODE_K = 39; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 178 | /** Key code constant: 'L' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 179 | public static final int KEYCODE_L = 40; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 180 | /** Key code constant: 'M' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 181 | public static final int KEYCODE_M = 41; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 182 | /** Key code constant: 'N' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 183 | public static final int KEYCODE_N = 42; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 184 | /** Key code constant: 'O' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 185 | public static final int KEYCODE_O = 43; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 186 | /** Key code constant: 'P' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 187 | public static final int KEYCODE_P = 44; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 188 | /** Key code constant: 'Q' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 189 | public static final int KEYCODE_Q = 45; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 190 | /** Key code constant: 'R' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 191 | public static final int KEYCODE_R = 46; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 192 | /** Key code constant: 'S' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 193 | public static final int KEYCODE_S = 47; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 194 | /** Key code constant: 'T' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 195 | public static final int KEYCODE_T = 48; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 196 | /** Key code constant: 'U' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 197 | public static final int KEYCODE_U = 49; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 198 | /** Key code constant: 'V' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 199 | public static final int KEYCODE_V = 50; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 200 | /** Key code constant: 'W' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 201 | public static final int KEYCODE_W = 51; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 202 | /** Key code constant: 'X' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 203 | public static final int KEYCODE_X = 52; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 204 | /** Key code constant: 'Y' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 205 | public static final int KEYCODE_Y = 53; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 206 | /** Key code constant: 'Z' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 207 | public static final int KEYCODE_Z = 54; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 208 | /** Key code constant: ',' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 209 | public static final int KEYCODE_COMMA = 55; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 210 | /** Key code constant: '.' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 211 | public static final int KEYCODE_PERIOD = 56; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 212 | /** Key code constant: Left Alt modifier key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 213 | public static final int KEYCODE_ALT_LEFT = 57; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 214 | /** Key code constant: Right Alt modifier key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 215 | public static final int KEYCODE_ALT_RIGHT = 58; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 216 | /** Key code constant: Left Shift modifier key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 217 | public static final int KEYCODE_SHIFT_LEFT = 59; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 218 | /** Key code constant: Right Shift modifier key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 219 | public static final int KEYCODE_SHIFT_RIGHT = 60; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 220 | /** Key code constant: Tab key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 221 | public static final int KEYCODE_TAB = 61; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 222 | /** Key code constant: Space key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 223 | public static final int KEYCODE_SPACE = 62; |
Jeff Brown | 224d4a1 | 2010-10-07 20:28:53 -0700 | [diff] [blame] | 224 | /** Key code constant: Symbol modifier key. |
| 225 | * Used to enter alternate symbols. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 226 | public static final int KEYCODE_SYM = 63; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 227 | /** Key code constant: Explorer special function key. |
| 228 | * Used to launch a browser application. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 229 | public static final int KEYCODE_EXPLORER = 64; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 230 | /** Key code constant: Envelope special function key. |
| 231 | * Used to launch a mail application. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 232 | public static final int KEYCODE_ENVELOPE = 65; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 233 | /** Key code constant: Enter key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 234 | public static final int KEYCODE_ENTER = 66; |
Jeff Brown | 224d4a1 | 2010-10-07 20:28:53 -0700 | [diff] [blame] | 235 | /** Key code constant: Backspace key. |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 236 | * Deletes characters before the insertion point, unlike {@link #KEYCODE_FORWARD_DEL}. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 237 | public static final int KEYCODE_DEL = 67; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 238 | /** Key code constant: '`' (backtick) key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 239 | public static final int KEYCODE_GRAVE = 68; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 240 | /** Key code constant: '-'. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 241 | public static final int KEYCODE_MINUS = 69; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 242 | /** Key code constant: '=' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 243 | public static final int KEYCODE_EQUALS = 70; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 244 | /** Key code constant: '[' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 245 | public static final int KEYCODE_LEFT_BRACKET = 71; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 246 | /** Key code constant: ']' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 247 | public static final int KEYCODE_RIGHT_BRACKET = 72; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 248 | /** Key code constant: '\' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 249 | public static final int KEYCODE_BACKSLASH = 73; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 250 | /** Key code constant: ';' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 251 | public static final int KEYCODE_SEMICOLON = 74; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 252 | /** Key code constant: ''' (apostrophe) key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 253 | public static final int KEYCODE_APOSTROPHE = 75; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 254 | /** Key code constant: '/' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 255 | public static final int KEYCODE_SLASH = 76; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 256 | /** Key code constant: '@' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 257 | public static final int KEYCODE_AT = 77; |
Jeff Brown | 224d4a1 | 2010-10-07 20:28:53 -0700 | [diff] [blame] | 258 | /** Key code constant: Number modifier key. |
| 259 | * Used to enter numeric symbols. |
| 260 | * This key is not Num Lock; it is more like {@link #KEYCODE_ALT_LEFT} and is |
| 261 | * interpreted as an ALT key by {@link android.text.method.MetaKeyKeyListener}. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 262 | public static final int KEYCODE_NUM = 78; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 263 | /** Key code constant: Headset Hook key. |
| 264 | * Used to hang up calls and stop media. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 265 | public static final int KEYCODE_HEADSETHOOK = 79; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 266 | /** Key code constant: Camera Focus key. |
| 267 | * Used to focus the camera. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 268 | public static final int KEYCODE_FOCUS = 80; // *Camera* focus |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 269 | /** Key code constant: '+' key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 270 | public static final int KEYCODE_PLUS = 81; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 271 | /** Key code constant: Menu key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 272 | public static final int KEYCODE_MENU = 82; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 273 | /** Key code constant: Notification key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 274 | public static final int KEYCODE_NOTIFICATION = 83; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 275 | /** Key code constant: Search key. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 276 | public static final int KEYCODE_SEARCH = 84; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 277 | /** Key code constant: Play/Pause media key. */ |
Dianne Hackborn | 935ae46 | 2009-04-13 16:11:55 -0700 | [diff] [blame] | 278 | public static final int KEYCODE_MEDIA_PLAY_PAUSE= 85; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 279 | /** Key code constant: Stop media key. */ |
Dianne Hackborn | 935ae46 | 2009-04-13 16:11:55 -0700 | [diff] [blame] | 280 | public static final int KEYCODE_MEDIA_STOP = 86; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 281 | /** Key code constant: Play Next media key. */ |
Dianne Hackborn | 935ae46 | 2009-04-13 16:11:55 -0700 | [diff] [blame] | 282 | public static final int KEYCODE_MEDIA_NEXT = 87; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 283 | /** Key code constant: Play Previous media key. */ |
Dianne Hackborn | 935ae46 | 2009-04-13 16:11:55 -0700 | [diff] [blame] | 284 | public static final int KEYCODE_MEDIA_PREVIOUS = 88; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 285 | /** Key code constant: Rewind media key. */ |
Dianne Hackborn | 935ae46 | 2009-04-13 16:11:55 -0700 | [diff] [blame] | 286 | public static final int KEYCODE_MEDIA_REWIND = 89; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 287 | /** Key code constant: Fast Forward media key. */ |
Dianne Hackborn | 935ae46 | 2009-04-13 16:11:55 -0700 | [diff] [blame] | 288 | public static final int KEYCODE_MEDIA_FAST_FORWARD = 90; |
Jeff Brown | b0418da | 2010-11-01 15:24:01 -0700 | [diff] [blame] | 289 | /** Key code constant: Mute key. |
| 290 | * Mutes the microphone, unlike {@link #KEYCODE_VOLUME_MUTE}. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 291 | public static final int KEYCODE_MUTE = 91; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 292 | /** Key code constant: Page Up key. */ |
Chih-Wei Huang | 4fedd80 | 2009-05-27 15:52:50 +0800 | [diff] [blame] | 293 | public static final int KEYCODE_PAGE_UP = 92; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 294 | /** Key code constant: Page Down key. */ |
Chih-Wei Huang | 4fedd80 | 2009-05-27 15:52:50 +0800 | [diff] [blame] | 295 | public static final int KEYCODE_PAGE_DOWN = 93; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 296 | /** Key code constant: Picture Symbols modifier key. |
| 297 | * Used to switch symbol sets (Emoji, Kao-moji). */ |
mogimo | b032bc0 | 2009-10-03 03:13:56 +0900 | [diff] [blame] | 298 | public static final int KEYCODE_PICTSYMBOLS = 94; // switch symbol-sets (Emoji,Kao-moji) |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 299 | /** Key code constant: Switch Charset modifier key. |
| 300 | * Used to switch character sets (Kanji, Katakana). */ |
mogimo | b032bc0 | 2009-10-03 03:13:56 +0900 | [diff] [blame] | 301 | public static final int KEYCODE_SWITCH_CHARSET = 95; // switch char-sets (Kanji,Katakana) |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 302 | /** Key code constant: A Button key. |
| 303 | * On a game controller, the A button should be either the button labeled A |
Michael Wright | 6b57bde | 2013-01-28 20:35:58 -0800 | [diff] [blame] | 304 | * or the first button on the bottom row of controller buttons. */ |
Jeff Brown | fd03582 | 2010-06-30 16:10:35 -0700 | [diff] [blame] | 305 | public static final int KEYCODE_BUTTON_A = 96; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 306 | /** Key code constant: B Button key. |
| 307 | * On a game controller, the B button should be either the button labeled B |
Michael Wright | 6b57bde | 2013-01-28 20:35:58 -0800 | [diff] [blame] | 308 | * or the second button on the bottom row of controller buttons. */ |
Jeff Brown | fd03582 | 2010-06-30 16:10:35 -0700 | [diff] [blame] | 309 | public static final int KEYCODE_BUTTON_B = 97; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 310 | /** Key code constant: C Button key. |
| 311 | * On a game controller, the C button should be either the button labeled C |
Michael Wright | 6b57bde | 2013-01-28 20:35:58 -0800 | [diff] [blame] | 312 | * or the third button on the bottom row of controller buttons. */ |
Jeff Brown | fd03582 | 2010-06-30 16:10:35 -0700 | [diff] [blame] | 313 | public static final int KEYCODE_BUTTON_C = 98; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 314 | /** Key code constant: X Button key. |
| 315 | * On a game controller, the X button should be either the button labeled X |
Michael Wright | 6b57bde | 2013-01-28 20:35:58 -0800 | [diff] [blame] | 316 | * or the first button on the upper row of controller buttons. */ |
Jeff Brown | fd03582 | 2010-06-30 16:10:35 -0700 | [diff] [blame] | 317 | public static final int KEYCODE_BUTTON_X = 99; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 318 | /** Key code constant: Y Button key. |
| 319 | * On a game controller, the Y button should be either the button labeled Y |
Michael Wright | 6b57bde | 2013-01-28 20:35:58 -0800 | [diff] [blame] | 320 | * or the second button on the upper row of controller buttons. */ |
Jeff Brown | fd03582 | 2010-06-30 16:10:35 -0700 | [diff] [blame] | 321 | public static final int KEYCODE_BUTTON_Y = 100; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 322 | /** Key code constant: Z Button key. |
| 323 | * On a game controller, the Z button should be either the button labeled Z |
Michael Wright | 6b57bde | 2013-01-28 20:35:58 -0800 | [diff] [blame] | 324 | * or the third button on the upper row of controller buttons. */ |
Jeff Brown | fd03582 | 2010-06-30 16:10:35 -0700 | [diff] [blame] | 325 | public static final int KEYCODE_BUTTON_Z = 101; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 326 | /** Key code constant: L1 Button key. |
| 327 | * On a game controller, the L1 button should be either the button labeled L1 (or L) |
| 328 | * or the top left trigger button. */ |
Jeff Brown | fd03582 | 2010-06-30 16:10:35 -0700 | [diff] [blame] | 329 | public static final int KEYCODE_BUTTON_L1 = 102; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 330 | /** Key code constant: R1 Button key. |
| 331 | * On a game controller, the R1 button should be either the button labeled R1 (or R) |
| 332 | * or the top right trigger button. */ |
Jeff Brown | fd03582 | 2010-06-30 16:10:35 -0700 | [diff] [blame] | 333 | public static final int KEYCODE_BUTTON_R1 = 103; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 334 | /** Key code constant: L2 Button key. |
| 335 | * On a game controller, the L2 button should be either the button labeled L2 |
| 336 | * or the bottom left trigger button. */ |
Jeff Brown | fd03582 | 2010-06-30 16:10:35 -0700 | [diff] [blame] | 337 | public static final int KEYCODE_BUTTON_L2 = 104; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 338 | /** Key code constant: R2 Button key. |
| 339 | * On a game controller, the R2 button should be either the button labeled R2 |
| 340 | * or the bottom right trigger button. */ |
Jeff Brown | fd03582 | 2010-06-30 16:10:35 -0700 | [diff] [blame] | 341 | public static final int KEYCODE_BUTTON_R2 = 105; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 342 | /** Key code constant: Left Thumb Button key. |
| 343 | * On a game controller, the left thumb button indicates that the left (or only) |
| 344 | * joystick is pressed. */ |
Jeff Brown | fd03582 | 2010-06-30 16:10:35 -0700 | [diff] [blame] | 345 | public static final int KEYCODE_BUTTON_THUMBL = 106; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 346 | /** Key code constant: Right Thumb Button key. |
| 347 | * On a game controller, the right thumb button indicates that the right |
| 348 | * joystick is pressed. */ |
Jeff Brown | fd03582 | 2010-06-30 16:10:35 -0700 | [diff] [blame] | 349 | public static final int KEYCODE_BUTTON_THUMBR = 107; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 350 | /** Key code constant: Start Button key. |
| 351 | * On a game controller, the button labeled Start. */ |
Jeff Brown | fd03582 | 2010-06-30 16:10:35 -0700 | [diff] [blame] | 352 | public static final int KEYCODE_BUTTON_START = 108; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 353 | /** Key code constant: Select Button key. |
| 354 | * On a game controller, the button labeled Select. */ |
Jeff Brown | fd03582 | 2010-06-30 16:10:35 -0700 | [diff] [blame] | 355 | public static final int KEYCODE_BUTTON_SELECT = 109; |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 356 | /** Key code constant: Mode Button key. |
| 357 | * On a game controller, the button labeled Mode. */ |
Jeff Brown | fd03582 | 2010-06-30 16:10:35 -0700 | [diff] [blame] | 358 | public static final int KEYCODE_BUTTON_MODE = 110; |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 359 | /** Key code constant: Escape key. */ |
| 360 | public static final int KEYCODE_ESCAPE = 111; |
| 361 | /** Key code constant: Forward Delete key. |
| 362 | * Deletes characters ahead of the insertion point, unlike {@link #KEYCODE_DEL}. */ |
| 363 | public static final int KEYCODE_FORWARD_DEL = 112; |
| 364 | /** Key code constant: Left Control modifier key. */ |
| 365 | public static final int KEYCODE_CTRL_LEFT = 113; |
| 366 | /** Key code constant: Right Control modifier key. */ |
| 367 | public static final int KEYCODE_CTRL_RIGHT = 114; |
Jeff Brown | 28cbf4b | 2010-12-13 10:33:20 -0800 | [diff] [blame] | 368 | /** Key code constant: Caps Lock key. */ |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 369 | public static final int KEYCODE_CAPS_LOCK = 115; |
| 370 | /** Key code constant: Scroll Lock key. */ |
| 371 | public static final int KEYCODE_SCROLL_LOCK = 116; |
| 372 | /** Key code constant: Left Meta modifier key. */ |
| 373 | public static final int KEYCODE_META_LEFT = 117; |
| 374 | /** Key code constant: Right Meta modifier key. */ |
| 375 | public static final int KEYCODE_META_RIGHT = 118; |
| 376 | /** Key code constant: Function modifier key. */ |
| 377 | public static final int KEYCODE_FUNCTION = 119; |
| 378 | /** Key code constant: System Request / Print Screen key. */ |
| 379 | public static final int KEYCODE_SYSRQ = 120; |
| 380 | /** Key code constant: Break / Pause key. */ |
| 381 | public static final int KEYCODE_BREAK = 121; |
| 382 | /** Key code constant: Home Movement key. |
| 383 | * Used for scrolling or moving the cursor around to the start of a line |
| 384 | * or to the top of a list. */ |
| 385 | public static final int KEYCODE_MOVE_HOME = 122; |
| 386 | /** Key code constant: End Movement key. |
| 387 | * Used for scrolling or moving the cursor around to the end of a line |
| 388 | * or to the bottom of a list. */ |
| 389 | public static final int KEYCODE_MOVE_END = 123; |
| 390 | /** Key code constant: Insert key. |
| 391 | * Toggles insert / overwrite edit mode. */ |
| 392 | public static final int KEYCODE_INSERT = 124; |
| 393 | /** Key code constant: Forward key. |
| 394 | * Navigates forward in the history stack. Complement of {@link #KEYCODE_BACK}. */ |
| 395 | public static final int KEYCODE_FORWARD = 125; |
| 396 | /** Key code constant: Play media key. */ |
| 397 | public static final int KEYCODE_MEDIA_PLAY = 126; |
| 398 | /** Key code constant: Pause media key. */ |
| 399 | public static final int KEYCODE_MEDIA_PAUSE = 127; |
| 400 | /** Key code constant: Close media key. |
| 401 | * May be used to close a CD tray, for example. */ |
| 402 | public static final int KEYCODE_MEDIA_CLOSE = 128; |
| 403 | /** Key code constant: Eject media key. |
| 404 | * May be used to eject a CD tray, for example. */ |
| 405 | public static final int KEYCODE_MEDIA_EJECT = 129; |
| 406 | /** Key code constant: Record media key. */ |
| 407 | public static final int KEYCODE_MEDIA_RECORD = 130; |
| 408 | /** Key code constant: F1 key. */ |
| 409 | public static final int KEYCODE_F1 = 131; |
| 410 | /** Key code constant: F2 key. */ |
| 411 | public static final int KEYCODE_F2 = 132; |
| 412 | /** Key code constant: F3 key. */ |
| 413 | public static final int KEYCODE_F3 = 133; |
| 414 | /** Key code constant: F4 key. */ |
| 415 | public static final int KEYCODE_F4 = 134; |
| 416 | /** Key code constant: F5 key. */ |
| 417 | public static final int KEYCODE_F5 = 135; |
| 418 | /** Key code constant: F6 key. */ |
| 419 | public static final int KEYCODE_F6 = 136; |
| 420 | /** Key code constant: F7 key. */ |
| 421 | public static final int KEYCODE_F7 = 137; |
| 422 | /** Key code constant: F8 key. */ |
| 423 | public static final int KEYCODE_F8 = 138; |
| 424 | /** Key code constant: F9 key. */ |
| 425 | public static final int KEYCODE_F9 = 139; |
| 426 | /** Key code constant: F10 key. */ |
| 427 | public static final int KEYCODE_F10 = 140; |
| 428 | /** Key code constant: F11 key. */ |
| 429 | public static final int KEYCODE_F11 = 141; |
| 430 | /** Key code constant: F12 key. */ |
| 431 | public static final int KEYCODE_F12 = 142; |
Jeff Brown | 28cbf4b | 2010-12-13 10:33:20 -0800 | [diff] [blame] | 432 | /** Key code constant: Num Lock key. |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 433 | * This is the Num Lock key; it is different from {@link #KEYCODE_NUM}. |
Jeff Brown | 28cbf4b | 2010-12-13 10:33:20 -0800 | [diff] [blame] | 434 | * This key alters the behavior of other keys on the numeric keypad. */ |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 435 | public static final int KEYCODE_NUM_LOCK = 143; |
| 436 | /** Key code constant: Numeric keypad '0' key. */ |
| 437 | public static final int KEYCODE_NUMPAD_0 = 144; |
| 438 | /** Key code constant: Numeric keypad '1' key. */ |
| 439 | public static final int KEYCODE_NUMPAD_1 = 145; |
| 440 | /** Key code constant: Numeric keypad '2' key. */ |
| 441 | public static final int KEYCODE_NUMPAD_2 = 146; |
| 442 | /** Key code constant: Numeric keypad '3' key. */ |
| 443 | public static final int KEYCODE_NUMPAD_3 = 147; |
| 444 | /** Key code constant: Numeric keypad '4' key. */ |
| 445 | public static final int KEYCODE_NUMPAD_4 = 148; |
| 446 | /** Key code constant: Numeric keypad '5' key. */ |
| 447 | public static final int KEYCODE_NUMPAD_5 = 149; |
| 448 | /** Key code constant: Numeric keypad '6' key. */ |
| 449 | public static final int KEYCODE_NUMPAD_6 = 150; |
| 450 | /** Key code constant: Numeric keypad '7' key. */ |
| 451 | public static final int KEYCODE_NUMPAD_7 = 151; |
| 452 | /** Key code constant: Numeric keypad '8' key. */ |
| 453 | public static final int KEYCODE_NUMPAD_8 = 152; |
| 454 | /** Key code constant: Numeric keypad '9' key. */ |
| 455 | public static final int KEYCODE_NUMPAD_9 = 153; |
| 456 | /** Key code constant: Numeric keypad '/' key (for division). */ |
| 457 | public static final int KEYCODE_NUMPAD_DIVIDE = 154; |
| 458 | /** Key code constant: Numeric keypad '*' key (for multiplication). */ |
| 459 | public static final int KEYCODE_NUMPAD_MULTIPLY = 155; |
| 460 | /** Key code constant: Numeric keypad '-' key (for subtraction). */ |
| 461 | public static final int KEYCODE_NUMPAD_SUBTRACT = 156; |
| 462 | /** Key code constant: Numeric keypad '+' key (for addition). */ |
| 463 | public static final int KEYCODE_NUMPAD_ADD = 157; |
| 464 | /** Key code constant: Numeric keypad '.' key (for decimals or digit grouping). */ |
| 465 | public static final int KEYCODE_NUMPAD_DOT = 158; |
| 466 | /** Key code constant: Numeric keypad ',' key (for decimals or digit grouping). */ |
| 467 | public static final int KEYCODE_NUMPAD_COMMA = 159; |
| 468 | /** Key code constant: Numeric keypad Enter key. */ |
| 469 | public static final int KEYCODE_NUMPAD_ENTER = 160; |
| 470 | /** Key code constant: Numeric keypad '=' key. */ |
| 471 | public static final int KEYCODE_NUMPAD_EQUALS = 161; |
| 472 | /** Key code constant: Numeric keypad '(' key. */ |
| 473 | public static final int KEYCODE_NUMPAD_LEFT_PAREN = 162; |
| 474 | /** Key code constant: Numeric keypad ')' key. */ |
| 475 | public static final int KEYCODE_NUMPAD_RIGHT_PAREN = 163; |
Jeff Brown | b0418da | 2010-11-01 15:24:01 -0700 | [diff] [blame] | 476 | /** Key code constant: Volume Mute key. |
| 477 | * Mutes the speaker, unlike {@link #KEYCODE_MUTE}. |
| 478 | * This key should normally be implemented as a toggle such that the first press |
| 479 | * mutes the speaker and the second press restores the original volume. */ |
| 480 | public static final int KEYCODE_VOLUME_MUTE = 164; |
Jason Bayer | 3adf490 | 2010-11-09 14:54:55 -0800 | [diff] [blame] | 481 | /** Key code constant: Info key. |
| 482 | * Common on TV remotes to show additional information related to what is |
| 483 | * currently being viewed. */ |
| 484 | public static final int KEYCODE_INFO = 165; |
| 485 | /** Key code constant: Channel up key. |
| 486 | * On TV remotes, increments the television channel. */ |
| 487 | public static final int KEYCODE_CHANNEL_UP = 166; |
| 488 | /** Key code constant: Channel down key. |
| 489 | * On TV remotes, decrements the television channel. */ |
| 490 | public static final int KEYCODE_CHANNEL_DOWN = 167; |
| 491 | /** Key code constant: Zoom in key. */ |
| 492 | public static final int KEYCODE_ZOOM_IN = 168; |
| 493 | /** Key code constant: Zoom out key. */ |
| 494 | public static final int KEYCODE_ZOOM_OUT = 169; |
| 495 | /** Key code constant: TV key. |
| 496 | * On TV remotes, switches to viewing live TV. */ |
| 497 | public static final int KEYCODE_TV = 170; |
| 498 | /** Key code constant: Window key. |
| 499 | * On TV remotes, toggles picture-in-picture mode or other windowing functions. */ |
| 500 | public static final int KEYCODE_WINDOW = 171; |
| 501 | /** Key code constant: Guide key. |
| 502 | * On TV remotes, shows a programming guide. */ |
| 503 | public static final int KEYCODE_GUIDE = 172; |
| 504 | /** Key code constant: DVR key. |
| 505 | * On some TV remotes, switches to a DVR mode for recorded shows. */ |
| 506 | public static final int KEYCODE_DVR = 173; |
| 507 | /** Key code constant: Bookmark key. |
| 508 | * On some TV remotes, bookmarks content or web pages. */ |
| 509 | public static final int KEYCODE_BOOKMARK = 174; |
| 510 | /** Key code constant: Toggle captions key. |
| 511 | * Switches the mode for closed-captioning text, for example during television shows. */ |
| 512 | public static final int KEYCODE_CAPTIONS = 175; |
| 513 | /** Key code constant: Settings key. |
| 514 | * Starts the system settings activity. */ |
| 515 | public static final int KEYCODE_SETTINGS = 176; |
| 516 | /** Key code constant: TV power key. |
| 517 | * On TV remotes, toggles the power on a television screen. */ |
| 518 | public static final int KEYCODE_TV_POWER = 177; |
| 519 | /** Key code constant: TV input key. |
| 520 | * On TV remotes, switches the input on a television screen. */ |
| 521 | public static final int KEYCODE_TV_INPUT = 178; |
| 522 | /** Key code constant: Set-top-box power key. |
| 523 | * On TV remotes, toggles the power on an external Set-top-box. */ |
| 524 | public static final int KEYCODE_STB_POWER = 179; |
| 525 | /** Key code constant: Set-top-box input key. |
| 526 | * On TV remotes, switches the input mode on an external Set-top-box. */ |
| 527 | public static final int KEYCODE_STB_INPUT = 180; |
| 528 | /** Key code constant: A/V Receiver power key. |
| 529 | * On TV remotes, toggles the power on an external A/V Receiver. */ |
| 530 | public static final int KEYCODE_AVR_POWER = 181; |
| 531 | /** Key code constant: A/V Receiver input key. |
| 532 | * On TV remotes, switches the input mode on an external A/V Receiver. */ |
| 533 | public static final int KEYCODE_AVR_INPUT = 182; |
| 534 | /** Key code constant: Red "programmable" key. |
| 535 | * On TV remotes, acts as a contextual/programmable key. */ |
| 536 | public static final int KEYCODE_PROG_RED = 183; |
| 537 | /** Key code constant: Green "programmable" key. |
| 538 | * On TV remotes, actsas a contextual/programmable key. */ |
| 539 | public static final int KEYCODE_PROG_GREEN = 184; |
| 540 | /** Key code constant: Yellow "programmable" key. |
| 541 | * On TV remotes, acts as a contextual/programmable key. */ |
| 542 | public static final int KEYCODE_PROG_YELLOW = 185; |
| 543 | /** Key code constant: Blue "programmable" key. |
| 544 | * On TV remotes, acts as a contextual/programmable key. */ |
| 545 | public static final int KEYCODE_PROG_BLUE = 186; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 546 | /** Key code constant: App switch key. |
| 547 | * Should bring up the application switcher dialog. */ |
| 548 | public static final int KEYCODE_APP_SWITCH = 187; |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 549 | /** Key code constant: Generic Game Pad Button #1.*/ |
| 550 | public static final int KEYCODE_BUTTON_1 = 188; |
| 551 | /** Key code constant: Generic Game Pad Button #2.*/ |
| 552 | public static final int KEYCODE_BUTTON_2 = 189; |
| 553 | /** Key code constant: Generic Game Pad Button #3.*/ |
| 554 | public static final int KEYCODE_BUTTON_3 = 190; |
| 555 | /** Key code constant: Generic Game Pad Button #4.*/ |
| 556 | public static final int KEYCODE_BUTTON_4 = 191; |
| 557 | /** Key code constant: Generic Game Pad Button #5.*/ |
| 558 | public static final int KEYCODE_BUTTON_5 = 192; |
| 559 | /** Key code constant: Generic Game Pad Button #6.*/ |
| 560 | public static final int KEYCODE_BUTTON_6 = 193; |
| 561 | /** Key code constant: Generic Game Pad Button #7.*/ |
| 562 | public static final int KEYCODE_BUTTON_7 = 194; |
| 563 | /** Key code constant: Generic Game Pad Button #8.*/ |
| 564 | public static final int KEYCODE_BUTTON_8 = 195; |
| 565 | /** Key code constant: Generic Game Pad Button #9.*/ |
| 566 | public static final int KEYCODE_BUTTON_9 = 196; |
| 567 | /** Key code constant: Generic Game Pad Button #10.*/ |
| 568 | public static final int KEYCODE_BUTTON_10 = 197; |
| 569 | /** Key code constant: Generic Game Pad Button #11.*/ |
| 570 | public static final int KEYCODE_BUTTON_11 = 198; |
| 571 | /** Key code constant: Generic Game Pad Button #12.*/ |
| 572 | public static final int KEYCODE_BUTTON_12 = 199; |
| 573 | /** Key code constant: Generic Game Pad Button #13.*/ |
| 574 | public static final int KEYCODE_BUTTON_13 = 200; |
| 575 | /** Key code constant: Generic Game Pad Button #14.*/ |
| 576 | public static final int KEYCODE_BUTTON_14 = 201; |
| 577 | /** Key code constant: Generic Game Pad Button #15.*/ |
| 578 | public static final int KEYCODE_BUTTON_15 = 202; |
| 579 | /** Key code constant: Generic Game Pad Button #16.*/ |
| 580 | public static final int KEYCODE_BUTTON_16 = 203; |
Jeff Brown | 9812aed | 2011-03-07 17:09:51 -0800 | [diff] [blame] | 581 | /** Key code constant: Language Switch key. |
| 582 | * Toggles the current input language such as switching between English and Japanese on |
| 583 | * a QWERTY keyboard. On some devices, the same function may be performed by |
| 584 | * pressing Shift+Spacebar. */ |
| 585 | public static final int KEYCODE_LANGUAGE_SWITCH = 204; |
| 586 | /** Key code constant: Manner Mode key. |
| 587 | * Toggles silent or vibrate mode on and off to make the device behave more politely |
| 588 | * in certain settings such as on a crowded train. On some devices, the key may only |
| 589 | * operate when long-pressed. */ |
| 590 | public static final int KEYCODE_MANNER_MODE = 205; |
| 591 | /** Key code constant: 3D Mode key. |
| 592 | * Toggles the display between 2D and 3D mode. */ |
| 593 | public static final int KEYCODE_3D_MODE = 206; |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 594 | /** Key code constant: Contacts special function key. |
| 595 | * Used to launch an address book application. */ |
| 596 | public static final int KEYCODE_CONTACTS = 207; |
| 597 | /** Key code constant: Calendar special function key. |
| 598 | * Used to launch a calendar application. */ |
| 599 | public static final int KEYCODE_CALENDAR = 208; |
| 600 | /** Key code constant: Music special function key. |
| 601 | * Used to launch a music player application. */ |
| 602 | public static final int KEYCODE_MUSIC = 209; |
| 603 | /** Key code constant: Calculator special function key. |
| 604 | * Used to launch a calculator application. */ |
| 605 | public static final int KEYCODE_CALCULATOR = 210; |
Yang Chuang | 7511f9c | 2012-02-10 15:18:26 +0800 | [diff] [blame] | 606 | /** Key code constant: Japanese full-width / half-width key. */ |
| 607 | public static final int KEYCODE_ZENKAKU_HANKAKU = 211; |
| 608 | /** Key code constant: Japanese alphanumeric key. */ |
| 609 | public static final int KEYCODE_EISU = 212; |
| 610 | /** Key code constant: Japanese non-conversion key. */ |
| 611 | public static final int KEYCODE_MUHENKAN = 213; |
| 612 | /** Key code constant: Japanese conversion key. */ |
| 613 | public static final int KEYCODE_HENKAN = 214; |
| 614 | /** Key code constant: Japanese katakana / hiragana key. */ |
| 615 | public static final int KEYCODE_KATAKANA_HIRAGANA = 215; |
| 616 | /** Key code constant: Japanese Yen key. */ |
| 617 | public static final int KEYCODE_YEN = 216; |
| 618 | /** Key code constant: Japanese Ro key. */ |
| 619 | public static final int KEYCODE_RO = 217; |
| 620 | /** Key code constant: Japanese kana key. */ |
| 621 | public static final int KEYCODE_KANA = 218; |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 622 | /** Key code constant: Assist key. |
| 623 | * Launches the global assist activity. Not delivered to applications. */ |
| 624 | public static final int KEYCODE_ASSIST = 219; |
Michael Wright | 1df477a | 2013-01-31 16:19:18 -0800 | [diff] [blame] | 625 | /** Key code constant: Brightness Down key. |
| 626 | * Adjusts the screen brightness down. */ |
| 627 | public static final int KEYCODE_BRIGHTNESS_DOWN = 220; |
| 628 | /** Key code constant: Brightness Up key. |
| 629 | * Adjusts the screen brightness up. */ |
| 630 | public static final int KEYCODE_BRIGHTNESS_UP = 221; |
Jaekyun Seok | bfdad8e | 2013-07-08 13:53:21 +0900 | [diff] [blame] | 631 | /** Key code constant: Audio Track key |
| 632 | * Switches the audio tracks. */ |
| 633 | public static final int KEYCODE_MEDIA_AUDIO_TRACK = 222; |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 634 | |
Jaekyun Seok | bfdad8e | 2013-07-08 13:53:21 +0900 | [diff] [blame] | 635 | private static final int LAST_KEYCODE = KEYCODE_MEDIA_AUDIO_TRACK; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 636 | |
| 637 | // NOTE: If you add a new keycode here you must also add it to: |
| 638 | // isSystem() |
Chirayu Desai | 61c37ae | 2013-04-15 20:11:37 +0530 | [diff] [blame] | 639 | // frameworks/native/include/android/keycodes.h |
| 640 | // frameworks/base/include/androidfw/KeycodeLabels.h |
Jeff Brown | fd03582 | 2010-06-30 16:10:35 -0700 | [diff] [blame] | 641 | // external/webkit/WebKit/android/plugins/ANPKeyCodes.h |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 642 | // frameworks/base/core/res/res/values/attrs.xml |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 643 | // emulator? |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 644 | // LAST_KEYCODE |
| 645 | // KEYCODE_SYMBOLIC_NAMES |
Dianne Hackborn | 935ae46 | 2009-04-13 16:11:55 -0700 | [diff] [blame] | 646 | // |
| 647 | // Also Android currently does not reserve code ranges for vendor- |
| 648 | // specific key codes. If you have new key codes to have, you |
| 649 | // MUST contribute a patch to the open source project to define |
| 650 | // those new codes. This is intended to maintain a consistent |
| 651 | // set of key code definitions across all Android devices. |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 652 | |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 653 | // Symbolic names of all key codes. |
| 654 | private static final SparseArray<String> KEYCODE_SYMBOLIC_NAMES = new SparseArray<String>(); |
| 655 | private static void populateKeycodeSymbolicNames() { |
| 656 | SparseArray<String> names = KEYCODE_SYMBOLIC_NAMES; |
| 657 | names.append(KEYCODE_UNKNOWN, "KEYCODE_UNKNOWN"); |
| 658 | names.append(KEYCODE_SOFT_LEFT, "KEYCODE_SOFT_LEFT"); |
| 659 | names.append(KEYCODE_SOFT_RIGHT, "KEYCODE_SOFT_RIGHT"); |
| 660 | names.append(KEYCODE_HOME, "KEYCODE_HOME"); |
| 661 | names.append(KEYCODE_BACK, "KEYCODE_BACK"); |
| 662 | names.append(KEYCODE_CALL, "KEYCODE_CALL"); |
| 663 | names.append(KEYCODE_ENDCALL, "KEYCODE_ENDCALL"); |
| 664 | names.append(KEYCODE_0, "KEYCODE_0"); |
| 665 | names.append(KEYCODE_1, "KEYCODE_1"); |
| 666 | names.append(KEYCODE_2, "KEYCODE_2"); |
| 667 | names.append(KEYCODE_3, "KEYCODE_3"); |
| 668 | names.append(KEYCODE_4, "KEYCODE_4"); |
| 669 | names.append(KEYCODE_5, "KEYCODE_5"); |
| 670 | names.append(KEYCODE_6, "KEYCODE_6"); |
| 671 | names.append(KEYCODE_7, "KEYCODE_7"); |
| 672 | names.append(KEYCODE_8, "KEYCODE_8"); |
| 673 | names.append(KEYCODE_9, "KEYCODE_9"); |
| 674 | names.append(KEYCODE_STAR, "KEYCODE_STAR"); |
| 675 | names.append(KEYCODE_POUND, "KEYCODE_POUND"); |
| 676 | names.append(KEYCODE_DPAD_UP, "KEYCODE_DPAD_UP"); |
| 677 | names.append(KEYCODE_DPAD_DOWN, "KEYCODE_DPAD_DOWN"); |
| 678 | names.append(KEYCODE_DPAD_LEFT, "KEYCODE_DPAD_LEFT"); |
| 679 | names.append(KEYCODE_DPAD_RIGHT, "KEYCODE_DPAD_RIGHT"); |
| 680 | names.append(KEYCODE_DPAD_CENTER, "KEYCODE_DPAD_CENTER"); |
| 681 | names.append(KEYCODE_VOLUME_UP, "KEYCODE_VOLUME_UP"); |
| 682 | names.append(KEYCODE_VOLUME_DOWN, "KEYCODE_VOLUME_DOWN"); |
| 683 | names.append(KEYCODE_POWER, "KEYCODE_POWER"); |
| 684 | names.append(KEYCODE_CAMERA, "KEYCODE_CAMERA"); |
| 685 | names.append(KEYCODE_CLEAR, "KEYCODE_CLEAR"); |
| 686 | names.append(KEYCODE_A, "KEYCODE_A"); |
| 687 | names.append(KEYCODE_B, "KEYCODE_B"); |
| 688 | names.append(KEYCODE_C, "KEYCODE_C"); |
| 689 | names.append(KEYCODE_D, "KEYCODE_D"); |
| 690 | names.append(KEYCODE_E, "KEYCODE_E"); |
| 691 | names.append(KEYCODE_F, "KEYCODE_F"); |
| 692 | names.append(KEYCODE_G, "KEYCODE_G"); |
| 693 | names.append(KEYCODE_H, "KEYCODE_H"); |
| 694 | names.append(KEYCODE_I, "KEYCODE_I"); |
| 695 | names.append(KEYCODE_J, "KEYCODE_J"); |
| 696 | names.append(KEYCODE_K, "KEYCODE_K"); |
| 697 | names.append(KEYCODE_L, "KEYCODE_L"); |
| 698 | names.append(KEYCODE_M, "KEYCODE_M"); |
| 699 | names.append(KEYCODE_N, "KEYCODE_N"); |
| 700 | names.append(KEYCODE_O, "KEYCODE_O"); |
| 701 | names.append(KEYCODE_P, "KEYCODE_P"); |
| 702 | names.append(KEYCODE_Q, "KEYCODE_Q"); |
| 703 | names.append(KEYCODE_R, "KEYCODE_R"); |
| 704 | names.append(KEYCODE_S, "KEYCODE_S"); |
| 705 | names.append(KEYCODE_T, "KEYCODE_T"); |
| 706 | names.append(KEYCODE_U, "KEYCODE_U"); |
| 707 | names.append(KEYCODE_V, "KEYCODE_V"); |
| 708 | names.append(KEYCODE_W, "KEYCODE_W"); |
| 709 | names.append(KEYCODE_X, "KEYCODE_X"); |
| 710 | names.append(KEYCODE_Y, "KEYCODE_Y"); |
| 711 | names.append(KEYCODE_Z, "KEYCODE_Z"); |
| 712 | names.append(KEYCODE_COMMA, "KEYCODE_COMMA"); |
| 713 | names.append(KEYCODE_PERIOD, "KEYCODE_PERIOD"); |
| 714 | names.append(KEYCODE_ALT_LEFT, "KEYCODE_ALT_LEFT"); |
| 715 | names.append(KEYCODE_ALT_RIGHT, "KEYCODE_ALT_RIGHT"); |
| 716 | names.append(KEYCODE_SHIFT_LEFT, "KEYCODE_SHIFT_LEFT"); |
| 717 | names.append(KEYCODE_SHIFT_RIGHT, "KEYCODE_SHIFT_RIGHT"); |
| 718 | names.append(KEYCODE_TAB, "KEYCODE_TAB"); |
| 719 | names.append(KEYCODE_SPACE, "KEYCODE_SPACE"); |
| 720 | names.append(KEYCODE_SYM, "KEYCODE_SYM"); |
| 721 | names.append(KEYCODE_EXPLORER, "KEYCODE_EXPLORER"); |
| 722 | names.append(KEYCODE_ENVELOPE, "KEYCODE_ENVELOPE"); |
| 723 | names.append(KEYCODE_ENTER, "KEYCODE_ENTER"); |
| 724 | names.append(KEYCODE_DEL, "KEYCODE_DEL"); |
| 725 | names.append(KEYCODE_GRAVE, "KEYCODE_GRAVE"); |
| 726 | names.append(KEYCODE_MINUS, "KEYCODE_MINUS"); |
| 727 | names.append(KEYCODE_EQUALS, "KEYCODE_EQUALS"); |
| 728 | names.append(KEYCODE_LEFT_BRACKET, "KEYCODE_LEFT_BRACKET"); |
| 729 | names.append(KEYCODE_RIGHT_BRACKET, "KEYCODE_RIGHT_BRACKET"); |
| 730 | names.append(KEYCODE_BACKSLASH, "KEYCODE_BACKSLASH"); |
| 731 | names.append(KEYCODE_SEMICOLON, "KEYCODE_SEMICOLON"); |
| 732 | names.append(KEYCODE_APOSTROPHE, "KEYCODE_APOSTROPHE"); |
| 733 | names.append(KEYCODE_SLASH, "KEYCODE_SLASH"); |
| 734 | names.append(KEYCODE_AT, "KEYCODE_AT"); |
| 735 | names.append(KEYCODE_NUM, "KEYCODE_NUM"); |
| 736 | names.append(KEYCODE_HEADSETHOOK, "KEYCODE_HEADSETHOOK"); |
| 737 | names.append(KEYCODE_FOCUS, "KEYCODE_FOCUS"); |
| 738 | names.append(KEYCODE_PLUS, "KEYCODE_PLUS"); |
| 739 | names.append(KEYCODE_MENU, "KEYCODE_MENU"); |
| 740 | names.append(KEYCODE_NOTIFICATION, "KEYCODE_NOTIFICATION"); |
| 741 | names.append(KEYCODE_SEARCH, "KEYCODE_SEARCH"); |
| 742 | names.append(KEYCODE_MEDIA_PLAY_PAUSE, "KEYCODE_MEDIA_PLAY_PAUSE"); |
| 743 | names.append(KEYCODE_MEDIA_STOP, "KEYCODE_MEDIA_STOP"); |
| 744 | names.append(KEYCODE_MEDIA_NEXT, "KEYCODE_MEDIA_NEXT"); |
| 745 | names.append(KEYCODE_MEDIA_PREVIOUS, "KEYCODE_MEDIA_PREVIOUS"); |
| 746 | names.append(KEYCODE_MEDIA_REWIND, "KEYCODE_MEDIA_REWIND"); |
| 747 | names.append(KEYCODE_MEDIA_FAST_FORWARD, "KEYCODE_MEDIA_FAST_FORWARD"); |
| 748 | names.append(KEYCODE_MUTE, "KEYCODE_MUTE"); |
| 749 | names.append(KEYCODE_PAGE_UP, "KEYCODE_PAGE_UP"); |
| 750 | names.append(KEYCODE_PAGE_DOWN, "KEYCODE_PAGE_DOWN"); |
| 751 | names.append(KEYCODE_PICTSYMBOLS, "KEYCODE_PICTSYMBOLS"); |
| 752 | names.append(KEYCODE_SWITCH_CHARSET, "KEYCODE_SWITCH_CHARSET"); |
| 753 | names.append(KEYCODE_BUTTON_A, "KEYCODE_BUTTON_A"); |
| 754 | names.append(KEYCODE_BUTTON_B, "KEYCODE_BUTTON_B"); |
| 755 | names.append(KEYCODE_BUTTON_C, "KEYCODE_BUTTON_C"); |
| 756 | names.append(KEYCODE_BUTTON_X, "KEYCODE_BUTTON_X"); |
| 757 | names.append(KEYCODE_BUTTON_Y, "KEYCODE_BUTTON_Y"); |
| 758 | names.append(KEYCODE_BUTTON_Z, "KEYCODE_BUTTON_Z"); |
| 759 | names.append(KEYCODE_BUTTON_L1, "KEYCODE_BUTTON_L1"); |
| 760 | names.append(KEYCODE_BUTTON_R1, "KEYCODE_BUTTON_R1"); |
| 761 | names.append(KEYCODE_BUTTON_L2, "KEYCODE_BUTTON_L2"); |
| 762 | names.append(KEYCODE_BUTTON_R2, "KEYCODE_BUTTON_R2"); |
| 763 | names.append(KEYCODE_BUTTON_THUMBL, "KEYCODE_BUTTON_THUMBL"); |
| 764 | names.append(KEYCODE_BUTTON_THUMBR, "KEYCODE_BUTTON_THUMBR"); |
| 765 | names.append(KEYCODE_BUTTON_START, "KEYCODE_BUTTON_START"); |
| 766 | names.append(KEYCODE_BUTTON_SELECT, "KEYCODE_BUTTON_SELECT"); |
| 767 | names.append(KEYCODE_BUTTON_MODE, "KEYCODE_BUTTON_MODE"); |
| 768 | names.append(KEYCODE_ESCAPE, "KEYCODE_ESCAPE"); |
| 769 | names.append(KEYCODE_FORWARD_DEL, "KEYCODE_FORWARD_DEL"); |
| 770 | names.append(KEYCODE_CTRL_LEFT, "KEYCODE_CTRL_LEFT"); |
| 771 | names.append(KEYCODE_CTRL_RIGHT, "KEYCODE_CTRL_RIGHT"); |
| 772 | names.append(KEYCODE_CAPS_LOCK, "KEYCODE_CAPS_LOCK"); |
| 773 | names.append(KEYCODE_SCROLL_LOCK, "KEYCODE_SCROLL_LOCK"); |
| 774 | names.append(KEYCODE_META_LEFT, "KEYCODE_META_LEFT"); |
| 775 | names.append(KEYCODE_META_RIGHT, "KEYCODE_META_RIGHT"); |
| 776 | names.append(KEYCODE_FUNCTION, "KEYCODE_FUNCTION"); |
| 777 | names.append(KEYCODE_SYSRQ, "KEYCODE_SYSRQ"); |
| 778 | names.append(KEYCODE_BREAK, "KEYCODE_BREAK"); |
| 779 | names.append(KEYCODE_MOVE_HOME, "KEYCODE_MOVE_HOME"); |
| 780 | names.append(KEYCODE_MOVE_END, "KEYCODE_MOVE_END"); |
| 781 | names.append(KEYCODE_INSERT, "KEYCODE_INSERT"); |
| 782 | names.append(KEYCODE_FORWARD, "KEYCODE_FORWARD"); |
| 783 | names.append(KEYCODE_MEDIA_PLAY, "KEYCODE_MEDIA_PLAY"); |
| 784 | names.append(KEYCODE_MEDIA_PAUSE, "KEYCODE_MEDIA_PAUSE"); |
| 785 | names.append(KEYCODE_MEDIA_CLOSE, "KEYCODE_MEDIA_CLOSE"); |
| 786 | names.append(KEYCODE_MEDIA_EJECT, "KEYCODE_MEDIA_EJECT"); |
| 787 | names.append(KEYCODE_MEDIA_RECORD, "KEYCODE_MEDIA_RECORD"); |
| 788 | names.append(KEYCODE_F1, "KEYCODE_F1"); |
| 789 | names.append(KEYCODE_F2, "KEYCODE_F2"); |
| 790 | names.append(KEYCODE_F3, "KEYCODE_F3"); |
| 791 | names.append(KEYCODE_F4, "KEYCODE_F4"); |
| 792 | names.append(KEYCODE_F5, "KEYCODE_F5"); |
| 793 | names.append(KEYCODE_F6, "KEYCODE_F6"); |
| 794 | names.append(KEYCODE_F7, "KEYCODE_F7"); |
| 795 | names.append(KEYCODE_F8, "KEYCODE_F8"); |
| 796 | names.append(KEYCODE_F9, "KEYCODE_F9"); |
| 797 | names.append(KEYCODE_F10, "KEYCODE_F10"); |
| 798 | names.append(KEYCODE_F11, "KEYCODE_F11"); |
| 799 | names.append(KEYCODE_F12, "KEYCODE_F12"); |
| 800 | names.append(KEYCODE_NUM_LOCK, "KEYCODE_NUM_LOCK"); |
| 801 | names.append(KEYCODE_NUMPAD_0, "KEYCODE_NUMPAD_0"); |
| 802 | names.append(KEYCODE_NUMPAD_1, "KEYCODE_NUMPAD_1"); |
| 803 | names.append(KEYCODE_NUMPAD_2, "KEYCODE_NUMPAD_2"); |
| 804 | names.append(KEYCODE_NUMPAD_3, "KEYCODE_NUMPAD_3"); |
| 805 | names.append(KEYCODE_NUMPAD_4, "KEYCODE_NUMPAD_4"); |
| 806 | names.append(KEYCODE_NUMPAD_5, "KEYCODE_NUMPAD_5"); |
| 807 | names.append(KEYCODE_NUMPAD_6, "KEYCODE_NUMPAD_6"); |
| 808 | names.append(KEYCODE_NUMPAD_7, "KEYCODE_NUMPAD_7"); |
| 809 | names.append(KEYCODE_NUMPAD_8, "KEYCODE_NUMPAD_8"); |
| 810 | names.append(KEYCODE_NUMPAD_9, "KEYCODE_NUMPAD_9"); |
| 811 | names.append(KEYCODE_NUMPAD_DIVIDE, "KEYCODE_NUMPAD_DIVIDE"); |
| 812 | names.append(KEYCODE_NUMPAD_MULTIPLY, "KEYCODE_NUMPAD_MULTIPLY"); |
| 813 | names.append(KEYCODE_NUMPAD_SUBTRACT, "KEYCODE_NUMPAD_SUBTRACT"); |
| 814 | names.append(KEYCODE_NUMPAD_ADD, "KEYCODE_NUMPAD_ADD"); |
| 815 | names.append(KEYCODE_NUMPAD_DOT, "KEYCODE_NUMPAD_DOT"); |
| 816 | names.append(KEYCODE_NUMPAD_COMMA, "KEYCODE_NUMPAD_COMMA"); |
| 817 | names.append(KEYCODE_NUMPAD_ENTER, "KEYCODE_NUMPAD_ENTER"); |
| 818 | names.append(KEYCODE_NUMPAD_EQUALS, "KEYCODE_NUMPAD_EQUALS"); |
| 819 | names.append(KEYCODE_NUMPAD_LEFT_PAREN, "KEYCODE_NUMPAD_LEFT_PAREN"); |
| 820 | names.append(KEYCODE_NUMPAD_RIGHT_PAREN, "KEYCODE_NUMPAD_RIGHT_PAREN"); |
| 821 | names.append(KEYCODE_VOLUME_MUTE, "KEYCODE_VOLUME_MUTE"); |
| 822 | names.append(KEYCODE_INFO, "KEYCODE_INFO"); |
| 823 | names.append(KEYCODE_CHANNEL_UP, "KEYCODE_CHANNEL_UP"); |
| 824 | names.append(KEYCODE_CHANNEL_DOWN, "KEYCODE_CHANNEL_DOWN"); |
| 825 | names.append(KEYCODE_ZOOM_IN, "KEYCODE_ZOOM_IN"); |
| 826 | names.append(KEYCODE_ZOOM_OUT, "KEYCODE_ZOOM_OUT"); |
| 827 | names.append(KEYCODE_TV, "KEYCODE_TV"); |
| 828 | names.append(KEYCODE_WINDOW, "KEYCODE_WINDOW"); |
| 829 | names.append(KEYCODE_GUIDE, "KEYCODE_GUIDE"); |
| 830 | names.append(KEYCODE_DVR, "KEYCODE_DVR"); |
| 831 | names.append(KEYCODE_BOOKMARK, "KEYCODE_BOOKMARK"); |
| 832 | names.append(KEYCODE_CAPTIONS, "KEYCODE_CAPTIONS"); |
| 833 | names.append(KEYCODE_SETTINGS, "KEYCODE_SETTINGS"); |
| 834 | names.append(KEYCODE_TV_POWER, "KEYCODE_TV_POWER"); |
| 835 | names.append(KEYCODE_TV_INPUT, "KEYCODE_TV_INPUT"); |
| 836 | names.append(KEYCODE_STB_INPUT, "KEYCODE_STB_INPUT"); |
| 837 | names.append(KEYCODE_STB_POWER, "KEYCODE_STB_POWER"); |
| 838 | names.append(KEYCODE_AVR_POWER, "KEYCODE_AVR_POWER"); |
| 839 | names.append(KEYCODE_AVR_INPUT, "KEYCODE_AVR_INPUT"); |
| 840 | names.append(KEYCODE_PROG_RED, "KEYCODE_PROG_RED"); |
| 841 | names.append(KEYCODE_PROG_GREEN, "KEYCODE_PROG_GREEN"); |
| 842 | names.append(KEYCODE_PROG_YELLOW, "KEYCODE_PROG_YELLOW"); |
| 843 | names.append(KEYCODE_PROG_BLUE, "KEYCODE_PROG_BLUE"); |
| 844 | names.append(KEYCODE_APP_SWITCH, "KEYCODE_APP_SWITCH"); |
| 845 | names.append(KEYCODE_BUTTON_1, "KEYCODE_BUTTON_1"); |
| 846 | names.append(KEYCODE_BUTTON_2, "KEYCODE_BUTTON_2"); |
| 847 | names.append(KEYCODE_BUTTON_3, "KEYCODE_BUTTON_3"); |
| 848 | names.append(KEYCODE_BUTTON_4, "KEYCODE_BUTTON_4"); |
| 849 | names.append(KEYCODE_BUTTON_5, "KEYCODE_BUTTON_5"); |
| 850 | names.append(KEYCODE_BUTTON_6, "KEYCODE_BUTTON_6"); |
| 851 | names.append(KEYCODE_BUTTON_7, "KEYCODE_BUTTON_7"); |
| 852 | names.append(KEYCODE_BUTTON_8, "KEYCODE_BUTTON_8"); |
| 853 | names.append(KEYCODE_BUTTON_9, "KEYCODE_BUTTON_9"); |
| 854 | names.append(KEYCODE_BUTTON_10, "KEYCODE_BUTTON_10"); |
| 855 | names.append(KEYCODE_BUTTON_11, "KEYCODE_BUTTON_11"); |
| 856 | names.append(KEYCODE_BUTTON_12, "KEYCODE_BUTTON_12"); |
| 857 | names.append(KEYCODE_BUTTON_13, "KEYCODE_BUTTON_13"); |
| 858 | names.append(KEYCODE_BUTTON_14, "KEYCODE_BUTTON_14"); |
| 859 | names.append(KEYCODE_BUTTON_15, "KEYCODE_BUTTON_15"); |
| 860 | names.append(KEYCODE_BUTTON_16, "KEYCODE_BUTTON_16"); |
Jeff Brown | 9812aed | 2011-03-07 17:09:51 -0800 | [diff] [blame] | 861 | names.append(KEYCODE_LANGUAGE_SWITCH, "KEYCODE_LANGUAGE_SWITCH"); |
| 862 | names.append(KEYCODE_MANNER_MODE, "KEYCODE_MANNER_MODE"); |
| 863 | names.append(KEYCODE_3D_MODE, "KEYCODE_3D_MODE"); |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 864 | names.append(KEYCODE_CONTACTS, "KEYCODE_CONTACTS"); |
| 865 | names.append(KEYCODE_CALENDAR, "KEYCODE_CALENDAR"); |
| 866 | names.append(KEYCODE_MUSIC, "KEYCODE_MUSIC"); |
| 867 | names.append(KEYCODE_CALCULATOR, "KEYCODE_CALCULATOR"); |
Yang Chuang | 7511f9c | 2012-02-10 15:18:26 +0800 | [diff] [blame] | 868 | names.append(KEYCODE_ZENKAKU_HANKAKU, "KEYCODE_ZENKAKU_HANKAKU"); |
| 869 | names.append(KEYCODE_EISU, "KEYCODE_EISU"); |
| 870 | names.append(KEYCODE_MUHENKAN, "KEYCODE_MUHENKAN"); |
| 871 | names.append(KEYCODE_HENKAN, "KEYCODE_HENKAN"); |
| 872 | names.append(KEYCODE_KATAKANA_HIRAGANA, "KEYCODE_KATAKANA_HIRAGANA"); |
| 873 | names.append(KEYCODE_YEN, "KEYCODE_YEN"); |
| 874 | names.append(KEYCODE_RO, "KEYCODE_RO"); |
| 875 | names.append(KEYCODE_KANA, "KEYCODE_KANA"); |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 876 | names.append(KEYCODE_ASSIST, "KEYCODE_ASSIST"); |
Michael Wright | 1df477a | 2013-01-31 16:19:18 -0800 | [diff] [blame] | 877 | names.append(KEYCODE_BRIGHTNESS_DOWN, "KEYCODE_BRIGHTNESS_DOWN"); |
| 878 | names.append(KEYCODE_BRIGHTNESS_UP, "KEYCODE_BRIGHTNESS_UP"); |
Jaekyun Seok | bfdad8e | 2013-07-08 13:53:21 +0900 | [diff] [blame] | 879 | names.append(KEYCODE_MEDIA_AUDIO_TRACK, "KEYCODE_MEDIA_AUDIO_TRACK"); |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 880 | }; |
| 881 | |
| 882 | // Symbolic names of all metakeys in bit order from least significant to most significant. |
| 883 | // Accordingly there are exactly 32 values in this table. |
| 884 | private static final String[] META_SYMBOLIC_NAMES = new String[] { |
| 885 | "META_SHIFT_ON", |
| 886 | "META_ALT_ON", |
| 887 | "META_SYM_ON", |
| 888 | "META_FUNCTION_ON", |
| 889 | "META_ALT_LEFT_ON", |
| 890 | "META_ALT_RIGHT_ON", |
| 891 | "META_SHIFT_LEFT_ON", |
| 892 | "META_SHIFT_RIGHT_ON", |
| 893 | "META_CAP_LOCKED", |
| 894 | "META_ALT_LOCKED", |
| 895 | "META_SYM_LOCKED", |
| 896 | "0x00000800", |
| 897 | "META_CTRL_ON", |
| 898 | "META_CTRL_LEFT_ON", |
| 899 | "META_CTRL_RIGHT_ON", |
| 900 | "0x00008000", |
| 901 | "META_META_ON", |
| 902 | "META_META_LEFT_ON", |
| 903 | "META_META_RIGHT_ON", |
| 904 | "0x00080000", |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 905 | "META_CAPS_LOCK_ON", |
| 906 | "META_NUM_LOCK_ON", |
| 907 | "META_SCROLL_LOCK_ON", |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 908 | "0x00800000", |
| 909 | "0x01000000", |
| 910 | "0x02000000", |
| 911 | "0x04000000", |
| 912 | "0x08000000", |
| 913 | "0x10000000", |
| 914 | "0x20000000", |
| 915 | "0x40000000", |
| 916 | "0x80000000", |
| 917 | }; |
| 918 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 919 | /** |
| 920 | * @deprecated There are now more than MAX_KEYCODE keycodes. |
| 921 | * Use {@link #getMaxKeyCode()} instead. |
| 922 | */ |
| 923 | @Deprecated |
| 924 | public static final int MAX_KEYCODE = 84; |
| 925 | |
| 926 | /** |
| 927 | * {@link #getAction} value: the key has been pressed down. |
| 928 | */ |
| 929 | public static final int ACTION_DOWN = 0; |
| 930 | /** |
| 931 | * {@link #getAction} value: the key has been released. |
| 932 | */ |
| 933 | public static final int ACTION_UP = 1; |
| 934 | /** |
| 935 | * {@link #getAction} value: multiple duplicate key events have |
| 936 | * occurred in a row, or a complex string is being delivered. If the |
| 937 | * key code is not {#link {@link #KEYCODE_UNKNOWN} then the |
| 938 | * {#link {@link #getRepeatCount()} method returns the number of times |
| 939 | * the given key code should be executed. |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 940 | * Otherwise, if the key code is {@link #KEYCODE_UNKNOWN}, then |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 941 | * this is a sequence of characters as returned by {@link #getCharacters}. |
| 942 | */ |
| 943 | public static final int ACTION_MULTIPLE = 2; |
| 944 | |
| 945 | /** |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 946 | * SHIFT key locked in CAPS mode. |
| 947 | * Reserved for use by {@link MetaKeyKeyListener} for a published constant in its API. |
| 948 | * @hide |
| 949 | */ |
| 950 | public static final int META_CAP_LOCKED = 0x100; |
| 951 | |
| 952 | /** |
| 953 | * ALT key locked. |
| 954 | * Reserved for use by {@link MetaKeyKeyListener} for a published constant in its API. |
| 955 | * @hide |
| 956 | */ |
| 957 | public static final int META_ALT_LOCKED = 0x200; |
| 958 | |
| 959 | /** |
| 960 | * SYM key locked. |
| 961 | * Reserved for use by {@link MetaKeyKeyListener} for a published constant in its API. |
| 962 | * @hide |
| 963 | */ |
| 964 | public static final int META_SYM_LOCKED = 0x400; |
| 965 | |
| 966 | /** |
| 967 | * Text is in selection mode. |
| 968 | * Reserved for use by {@link MetaKeyKeyListener} for a private unpublished constant |
| 969 | * in its API that is currently being retained for legacy reasons. |
| 970 | * @hide |
| 971 | */ |
| 972 | public static final int META_SELECTING = 0x800; |
| 973 | |
| 974 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 975 | * <p>This mask is used to check whether one of the ALT meta keys is pressed.</p> |
| 976 | * |
| 977 | * @see #isAltPressed() |
| 978 | * @see #getMetaState() |
| 979 | * @see #KEYCODE_ALT_LEFT |
| 980 | * @see #KEYCODE_ALT_RIGHT |
| 981 | */ |
| 982 | public static final int META_ALT_ON = 0x02; |
| 983 | |
| 984 | /** |
| 985 | * <p>This mask is used to check whether the left ALT meta key is pressed.</p> |
| 986 | * |
| 987 | * @see #isAltPressed() |
| 988 | * @see #getMetaState() |
| 989 | * @see #KEYCODE_ALT_LEFT |
| 990 | */ |
| 991 | public static final int META_ALT_LEFT_ON = 0x10; |
| 992 | |
| 993 | /** |
| 994 | * <p>This mask is used to check whether the right the ALT meta key is pressed.</p> |
| 995 | * |
| 996 | * @see #isAltPressed() |
| 997 | * @see #getMetaState() |
| 998 | * @see #KEYCODE_ALT_RIGHT |
| 999 | */ |
| 1000 | public static final int META_ALT_RIGHT_ON = 0x20; |
| 1001 | |
| 1002 | /** |
| 1003 | * <p>This mask is used to check whether one of the SHIFT meta keys is pressed.</p> |
| 1004 | * |
| 1005 | * @see #isShiftPressed() |
| 1006 | * @see #getMetaState() |
| 1007 | * @see #KEYCODE_SHIFT_LEFT |
| 1008 | * @see #KEYCODE_SHIFT_RIGHT |
| 1009 | */ |
| 1010 | public static final int META_SHIFT_ON = 0x1; |
| 1011 | |
| 1012 | /** |
| 1013 | * <p>This mask is used to check whether the left SHIFT meta key is pressed.</p> |
| 1014 | * |
| 1015 | * @see #isShiftPressed() |
| 1016 | * @see #getMetaState() |
| 1017 | * @see #KEYCODE_SHIFT_LEFT |
| 1018 | */ |
| 1019 | public static final int META_SHIFT_LEFT_ON = 0x40; |
| 1020 | |
| 1021 | /** |
| 1022 | * <p>This mask is used to check whether the right SHIFT meta key is pressed.</p> |
| 1023 | * |
| 1024 | * @see #isShiftPressed() |
| 1025 | * @see #getMetaState() |
| 1026 | * @see #KEYCODE_SHIFT_RIGHT |
| 1027 | */ |
| 1028 | public static final int META_SHIFT_RIGHT_ON = 0x80; |
| 1029 | |
| 1030 | /** |
| 1031 | * <p>This mask is used to check whether the SYM meta key is pressed.</p> |
| 1032 | * |
| 1033 | * @see #isSymPressed() |
| 1034 | * @see #getMetaState() |
| 1035 | */ |
| 1036 | public static final int META_SYM_ON = 0x4; |
| 1037 | |
| 1038 | /** |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 1039 | * <p>This mask is used to check whether the FUNCTION meta key is pressed.</p> |
| 1040 | * |
| 1041 | * @see #isFunctionPressed() |
| 1042 | * @see #getMetaState() |
| 1043 | */ |
| 1044 | public static final int META_FUNCTION_ON = 0x8; |
| 1045 | |
| 1046 | /** |
| 1047 | * <p>This mask is used to check whether one of the CTRL meta keys is pressed.</p> |
| 1048 | * |
| 1049 | * @see #isCtrlPressed() |
| 1050 | * @see #getMetaState() |
| 1051 | * @see #KEYCODE_CTRL_LEFT |
| 1052 | * @see #KEYCODE_CTRL_RIGHT |
| 1053 | */ |
| 1054 | public static final int META_CTRL_ON = 0x1000; |
| 1055 | |
| 1056 | /** |
| 1057 | * <p>This mask is used to check whether the left CTRL meta key is pressed.</p> |
| 1058 | * |
| 1059 | * @see #isCtrlPressed() |
| 1060 | * @see #getMetaState() |
| 1061 | * @see #KEYCODE_CTRL_LEFT |
| 1062 | */ |
| 1063 | public static final int META_CTRL_LEFT_ON = 0x2000; |
| 1064 | |
| 1065 | /** |
| 1066 | * <p>This mask is used to check whether the right CTRL meta key is pressed.</p> |
| 1067 | * |
| 1068 | * @see #isCtrlPressed() |
| 1069 | * @see #getMetaState() |
| 1070 | * @see #KEYCODE_CTRL_RIGHT |
| 1071 | */ |
| 1072 | public static final int META_CTRL_RIGHT_ON = 0x4000; |
| 1073 | |
| 1074 | /** |
| 1075 | * <p>This mask is used to check whether one of the META meta keys is pressed.</p> |
| 1076 | * |
| 1077 | * @see #isMetaPressed() |
| 1078 | * @see #getMetaState() |
| 1079 | * @see #KEYCODE_META_LEFT |
| 1080 | * @see #KEYCODE_META_RIGHT |
| 1081 | */ |
| 1082 | public static final int META_META_ON = 0x10000; |
| 1083 | |
| 1084 | /** |
| 1085 | * <p>This mask is used to check whether the left META meta key is pressed.</p> |
| 1086 | * |
| 1087 | * @see #isMetaPressed() |
| 1088 | * @see #getMetaState() |
| 1089 | * @see #KEYCODE_META_LEFT |
| 1090 | */ |
| 1091 | public static final int META_META_LEFT_ON = 0x20000; |
| 1092 | |
| 1093 | /** |
| 1094 | * <p>This mask is used to check whether the right META meta key is pressed.</p> |
| 1095 | * |
| 1096 | * @see #isMetaPressed() |
| 1097 | * @see #getMetaState() |
| 1098 | * @see #KEYCODE_META_RIGHT |
| 1099 | */ |
| 1100 | public static final int META_META_RIGHT_ON = 0x40000; |
| 1101 | |
| 1102 | /** |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 1103 | * <p>This mask is used to check whether the CAPS LOCK meta key is on.</p> |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 1104 | * |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 1105 | * @see #isCapsLockOn() |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 1106 | * @see #getMetaState() |
| 1107 | * @see #KEYCODE_CAPS_LOCK |
| 1108 | */ |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 1109 | public static final int META_CAPS_LOCK_ON = 0x100000; |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 1110 | |
| 1111 | /** |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 1112 | * <p>This mask is used to check whether the NUM LOCK meta key is on.</p> |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 1113 | * |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 1114 | * @see #isNumLockOn() |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 1115 | * @see #getMetaState() |
| 1116 | * @see #KEYCODE_NUM_LOCK |
| 1117 | */ |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 1118 | public static final int META_NUM_LOCK_ON = 0x200000; |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 1119 | |
| 1120 | /** |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 1121 | * <p>This mask is used to check whether the SCROLL LOCK meta key is on.</p> |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 1122 | * |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 1123 | * @see #isScrollLockOn() |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 1124 | * @see #getMetaState() |
| 1125 | * @see #KEYCODE_SCROLL_LOCK |
| 1126 | */ |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 1127 | public static final int META_SCROLL_LOCK_ON = 0x400000; |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 1128 | |
Jeff Brown | 64da12a | 2011-01-04 19:57:47 -0800 | [diff] [blame] | 1129 | /** |
| 1130 | * This mask is a combination of {@link #META_SHIFT_ON}, {@link #META_SHIFT_LEFT_ON} |
| 1131 | * and {@link #META_SHIFT_RIGHT_ON}. |
| 1132 | */ |
Jeff Brown | c1df907 | 2010-12-21 16:38:50 -0800 | [diff] [blame] | 1133 | public static final int META_SHIFT_MASK = META_SHIFT_ON |
| 1134 | | META_SHIFT_LEFT_ON | META_SHIFT_RIGHT_ON; |
| 1135 | |
Jeff Brown | 64da12a | 2011-01-04 19:57:47 -0800 | [diff] [blame] | 1136 | /** |
| 1137 | * This mask is a combination of {@link #META_ALT_ON}, {@link #META_ALT_LEFT_ON} |
| 1138 | * and {@link #META_ALT_RIGHT_ON}. |
| 1139 | */ |
Jeff Brown | c1df907 | 2010-12-21 16:38:50 -0800 | [diff] [blame] | 1140 | public static final int META_ALT_MASK = META_ALT_ON |
| 1141 | | META_ALT_LEFT_ON | META_ALT_RIGHT_ON; |
| 1142 | |
Jeff Brown | 64da12a | 2011-01-04 19:57:47 -0800 | [diff] [blame] | 1143 | /** |
| 1144 | * This mask is a combination of {@link #META_CTRL_ON}, {@link #META_CTRL_LEFT_ON} |
| 1145 | * and {@link #META_CTRL_RIGHT_ON}. |
| 1146 | */ |
Jeff Brown | c1df907 | 2010-12-21 16:38:50 -0800 | [diff] [blame] | 1147 | public static final int META_CTRL_MASK = META_CTRL_ON |
| 1148 | | META_CTRL_LEFT_ON | META_CTRL_RIGHT_ON; |
| 1149 | |
Jeff Brown | 64da12a | 2011-01-04 19:57:47 -0800 | [diff] [blame] | 1150 | /** |
| 1151 | * This mask is a combination of {@link #META_META_ON}, {@link #META_META_LEFT_ON} |
| 1152 | * and {@link #META_META_RIGHT_ON}. |
| 1153 | */ |
| 1154 | public static final int META_META_MASK = META_META_ON |
Jeff Brown | c1df907 | 2010-12-21 16:38:50 -0800 | [diff] [blame] | 1155 | | META_META_LEFT_ON | META_META_RIGHT_ON; |
| 1156 | |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 1157 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1158 | * This mask is set if the device woke because of this key event. |
| 1159 | */ |
| 1160 | public static final int FLAG_WOKE_HERE = 0x1; |
| 1161 | |
| 1162 | /** |
| 1163 | * This mask is set if the key event was generated by a software keyboard. |
| 1164 | */ |
| 1165 | public static final int FLAG_SOFT_KEYBOARD = 0x2; |
| 1166 | |
| 1167 | /** |
| 1168 | * This mask is set if we don't want the key event to cause us to leave |
| 1169 | * touch mode. |
| 1170 | */ |
| 1171 | public static final int FLAG_KEEP_TOUCH_MODE = 0x4; |
| 1172 | |
| 1173 | /** |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1174 | * This mask is set if an event was known to come from a trusted part |
| 1175 | * of the system. That is, the event is known to come from the user, |
| 1176 | * and could not have been spoofed by a third party component. |
| 1177 | */ |
| 1178 | public static final int FLAG_FROM_SYSTEM = 0x8; |
| 1179 | |
| 1180 | /** |
| 1181 | * This mask is used for compatibility, to identify enter keys that are |
| 1182 | * coming from an IME whose enter key has been auto-labelled "next" or |
| 1183 | * "done". This allows TextView to dispatch these as normal enter keys |
| 1184 | * for old applications, but still do the appropriate action when |
| 1185 | * receiving them. |
| 1186 | */ |
| 1187 | public static final int FLAG_EDITOR_ACTION = 0x10; |
| 1188 | |
| 1189 | /** |
Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 1190 | * When associated with up key events, this indicates that the key press |
| 1191 | * has been canceled. Typically this is used with virtual touch screen |
| 1192 | * keys, where the user can slide from the virtual key area on to the |
| 1193 | * display: in that case, the application will receive a canceled up |
| 1194 | * event and should not perform the action normally associated with the |
| 1195 | * key. Note that for this to work, the application can not perform an |
| 1196 | * action for a key until it receives an up or the long press timeout has |
| 1197 | * expired. |
| 1198 | */ |
| 1199 | public static final int FLAG_CANCELED = 0x20; |
| 1200 | |
| 1201 | /** |
| 1202 | * This key event was generated by a virtual (on-screen) hard key area. |
| 1203 | * Typically this is an area of the touchscreen, outside of the regular |
| 1204 | * display, dedicated to "hardware" buttons. |
| 1205 | */ |
| 1206 | public static final int FLAG_VIRTUAL_HARD_KEY = 0x40; |
| 1207 | |
| 1208 | /** |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 1209 | * This flag is set for the first key repeat that occurs after the |
| 1210 | * long press timeout. |
| 1211 | */ |
| 1212 | public static final int FLAG_LONG_PRESS = 0x80; |
| 1213 | |
| 1214 | /** |
| 1215 | * Set when a key event has {@link #FLAG_CANCELED} set because a long |
| 1216 | * press action was executed while it was down. |
| 1217 | */ |
| 1218 | public static final int FLAG_CANCELED_LONG_PRESS = 0x100; |
| 1219 | |
| 1220 | /** |
| 1221 | * Set for {@link #ACTION_UP} when this event's key code is still being |
| 1222 | * tracked from its initial down. That is, somebody requested that tracking |
| 1223 | * started on the key down and a long press has not caused |
| 1224 | * the tracking to be canceled. |
| 1225 | */ |
| 1226 | public static final int FLAG_TRACKING = 0x200; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 1227 | |
| 1228 | /** |
| 1229 | * Set when a key event has been synthesized to implement default behavior |
| 1230 | * for an event that the application did not handle. |
| 1231 | * Fallback key events are generated by unhandled trackball motions |
| 1232 | * (to emulate a directional keypad) and by certain unhandled key presses |
| 1233 | * that are declared in the key map (such as special function numeric keypad |
| 1234 | * keys when numlock is off). |
| 1235 | */ |
| 1236 | public static final int FLAG_FALLBACK = 0x400; |
| 1237 | |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 1238 | /** |
Michael Wright | a44dd26 | 2013-04-10 21:12:00 -0700 | [diff] [blame] | 1239 | * Signifies that the key is being predispatched. |
| 1240 | * @hide |
| 1241 | */ |
| 1242 | public static final int FLAG_PREDISPATCH = 0x20000000; |
| 1243 | |
| 1244 | /** |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 1245 | * Private control to determine when an app is tracking a key sequence. |
| 1246 | * @hide |
| 1247 | */ |
| 1248 | public static final int FLAG_START_TRACKING = 0x40000000; |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 1249 | |
| 1250 | /** |
| 1251 | * Private flag that indicates when the system has detected that this key event |
| 1252 | * may be inconsistent with respect to the sequence of previously delivered key events, |
| 1253 | * such as when a key up event is sent but the key was not down. |
| 1254 | * |
| 1255 | * @hide |
| 1256 | * @see #isTainted |
| 1257 | * @see #setTainted |
| 1258 | */ |
| 1259 | public static final int FLAG_TAINTED = 0x80000000; |
| 1260 | |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 1261 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1262 | * Returns the maximum keycode. |
| 1263 | */ |
| 1264 | public static int getMaxKeyCode() { |
| 1265 | return LAST_KEYCODE; |
| 1266 | } |
| 1267 | |
| 1268 | /** |
| 1269 | * Get the character that is produced by putting accent on the character |
| 1270 | * c. |
| 1271 | * For example, getDeadChar('`', 'e') returns è. |
| 1272 | */ |
| 1273 | public static int getDeadChar(int accent, int c) { |
| 1274 | return KeyCharacterMap.getDeadChar(accent, c); |
| 1275 | } |
| 1276 | |
Dianne Hackborn | 8d37426 | 2009-09-14 21:21:52 -0700 | [diff] [blame] | 1277 | static final boolean DEBUG = false; |
| 1278 | static final String TAG = "KeyEvent"; |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 1279 | |
| 1280 | private static final int MAX_RECYCLED = 10; |
| 1281 | private static final Object gRecyclerLock = new Object(); |
| 1282 | private static int gRecyclerUsed; |
| 1283 | private static KeyEvent gRecyclerTop; |
| 1284 | |
| 1285 | private KeyEvent mNext; |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 1286 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1287 | private int mDeviceId; |
| 1288 | private int mSource; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1289 | private int mMetaState; |
| 1290 | private int mAction; |
| 1291 | private int mKeyCode; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1292 | private int mScanCode; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1293 | private int mRepeatCount; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1294 | private int mFlags; |
| 1295 | private long mDownTime; |
| 1296 | private long mEventTime; |
| 1297 | private String mCharacters; |
| 1298 | |
| 1299 | public interface Callback { |
| 1300 | /** |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 1301 | * Called when a key down event has occurred. If you return true, |
| 1302 | * you can first call {@link KeyEvent#startTracking() |
| 1303 | * KeyEvent.startTracking()} to have the framework track the event |
| 1304 | * through its {@link #onKeyUp(int, KeyEvent)} and also call your |
| 1305 | * {@link #onKeyLongPress(int, KeyEvent)} if it occurs. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1306 | * |
| 1307 | * @param keyCode The value in event.getKeyCode(). |
| 1308 | * @param event Description of the key event. |
| 1309 | * |
| 1310 | * @return If you handled the event, return true. If you want to allow |
| 1311 | * the event to be handled by the next receiver, return false. |
| 1312 | */ |
| 1313 | boolean onKeyDown(int keyCode, KeyEvent event); |
| 1314 | |
| 1315 | /** |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 1316 | * Called when a long press has occurred. If you return true, |
| 1317 | * the final key up will have {@link KeyEvent#FLAG_CANCELED} and |
| 1318 | * {@link KeyEvent#FLAG_CANCELED_LONG_PRESS} set. Note that in |
| 1319 | * order to receive this callback, someone in the event change |
| 1320 | * <em>must</em> return true from {@link #onKeyDown} <em>and</em> |
| 1321 | * call {@link KeyEvent#startTracking()} on the event. |
| 1322 | * |
| 1323 | * @param keyCode The value in event.getKeyCode(). |
| 1324 | * @param event Description of the key event. |
| 1325 | * |
| 1326 | * @return If you handled the event, return true. If you want to allow |
| 1327 | * the event to be handled by the next receiver, return false. |
| 1328 | */ |
| 1329 | boolean onKeyLongPress(int keyCode, KeyEvent event); |
| 1330 | |
| 1331 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1332 | * Called when a key up event has occurred. |
| 1333 | * |
| 1334 | * @param keyCode The value in event.getKeyCode(). |
| 1335 | * @param event Description of the key event. |
| 1336 | * |
| 1337 | * @return If you handled the event, return true. If you want to allow |
| 1338 | * the event to be handled by the next receiver, return false. |
| 1339 | */ |
| 1340 | boolean onKeyUp(int keyCode, KeyEvent event); |
| 1341 | |
| 1342 | /** |
| 1343 | * Called when multiple down/up pairs of the same key have occurred |
| 1344 | * in a row. |
| 1345 | * |
| 1346 | * @param keyCode The value in event.getKeyCode(). |
| 1347 | * @param count Number of pairs as returned by event.getRepeatCount(). |
| 1348 | * @param event Description of the key event. |
| 1349 | * |
| 1350 | * @return If you handled the event, return true. If you want to allow |
| 1351 | * the event to be handled by the next receiver, return false. |
| 1352 | */ |
| 1353 | boolean onKeyMultiple(int keyCode, int count, KeyEvent event); |
| 1354 | } |
| 1355 | |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 1356 | static { |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 1357 | populateKeycodeSymbolicNames(); |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 1358 | } |
| 1359 | |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 1360 | private KeyEvent() { |
| 1361 | } |
| 1362 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1363 | /** |
| 1364 | * Create a new key event. |
| 1365 | * |
| 1366 | * @param action Action code: either {@link #ACTION_DOWN}, |
| 1367 | * {@link #ACTION_UP}, or {@link #ACTION_MULTIPLE}. |
| 1368 | * @param code The key code. |
| 1369 | */ |
| 1370 | public KeyEvent(int action, int code) { |
| 1371 | mAction = action; |
| 1372 | mKeyCode = code; |
| 1373 | mRepeatCount = 0; |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 1374 | mDeviceId = KeyCharacterMap.VIRTUAL_KEYBOARD; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1375 | } |
| 1376 | |
| 1377 | /** |
| 1378 | * Create a new key event. |
| 1379 | * |
| 1380 | * @param downTime The time (in {@link android.os.SystemClock#uptimeMillis}) |
| 1381 | * at which this key code originally went down. |
| 1382 | * @param eventTime The time (in {@link android.os.SystemClock#uptimeMillis}) |
| 1383 | * at which this event happened. |
| 1384 | * @param action Action code: either {@link #ACTION_DOWN}, |
| 1385 | * {@link #ACTION_UP}, or {@link #ACTION_MULTIPLE}. |
| 1386 | * @param code The key code. |
| 1387 | * @param repeat A repeat count for down events (> 0 if this is after the |
| 1388 | * initial down) or event count for multiple events. |
| 1389 | */ |
| 1390 | public KeyEvent(long downTime, long eventTime, int action, |
| 1391 | int code, int repeat) { |
| 1392 | mDownTime = downTime; |
| 1393 | mEventTime = eventTime; |
| 1394 | mAction = action; |
| 1395 | mKeyCode = code; |
| 1396 | mRepeatCount = repeat; |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 1397 | mDeviceId = KeyCharacterMap.VIRTUAL_KEYBOARD; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1398 | } |
| 1399 | |
| 1400 | /** |
| 1401 | * Create a new key event. |
| 1402 | * |
| 1403 | * @param downTime The time (in {@link android.os.SystemClock#uptimeMillis}) |
| 1404 | * at which this key code originally went down. |
| 1405 | * @param eventTime The time (in {@link android.os.SystemClock#uptimeMillis}) |
| 1406 | * at which this event happened. |
| 1407 | * @param action Action code: either {@link #ACTION_DOWN}, |
| 1408 | * {@link #ACTION_UP}, or {@link #ACTION_MULTIPLE}. |
| 1409 | * @param code The key code. |
| 1410 | * @param repeat A repeat count for down events (> 0 if this is after the |
| 1411 | * initial down) or event count for multiple events. |
| 1412 | * @param metaState Flags indicating which meta keys are currently pressed. |
| 1413 | */ |
| 1414 | public KeyEvent(long downTime, long eventTime, int action, |
| 1415 | int code, int repeat, int metaState) { |
| 1416 | mDownTime = downTime; |
| 1417 | mEventTime = eventTime; |
| 1418 | mAction = action; |
| 1419 | mKeyCode = code; |
| 1420 | mRepeatCount = repeat; |
| 1421 | mMetaState = metaState; |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 1422 | mDeviceId = KeyCharacterMap.VIRTUAL_KEYBOARD; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1423 | } |
| 1424 | |
| 1425 | /** |
| 1426 | * Create a new key event. |
| 1427 | * |
| 1428 | * @param downTime The time (in {@link android.os.SystemClock#uptimeMillis}) |
| 1429 | * at which this key code originally went down. |
| 1430 | * @param eventTime The time (in {@link android.os.SystemClock#uptimeMillis}) |
| 1431 | * at which this event happened. |
| 1432 | * @param action Action code: either {@link #ACTION_DOWN}, |
| 1433 | * {@link #ACTION_UP}, or {@link #ACTION_MULTIPLE}. |
| 1434 | * @param code The key code. |
| 1435 | * @param repeat A repeat count for down events (> 0 if this is after the |
| 1436 | * initial down) or event count for multiple events. |
| 1437 | * @param metaState Flags indicating which meta keys are currently pressed. |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1438 | * @param deviceId The device ID that generated the key event. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1439 | * @param scancode Raw device scan code of the event. |
| 1440 | */ |
| 1441 | public KeyEvent(long downTime, long eventTime, int action, |
| 1442 | int code, int repeat, int metaState, |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1443 | int deviceId, int scancode) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1444 | mDownTime = downTime; |
| 1445 | mEventTime = eventTime; |
| 1446 | mAction = action; |
| 1447 | mKeyCode = code; |
| 1448 | mRepeatCount = repeat; |
| 1449 | mMetaState = metaState; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1450 | mDeviceId = deviceId; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1451 | mScanCode = scancode; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1452 | } |
| 1453 | |
| 1454 | /** |
| 1455 | * Create a new key event. |
| 1456 | * |
| 1457 | * @param downTime The time (in {@link android.os.SystemClock#uptimeMillis}) |
| 1458 | * at which this key code originally went down. |
| 1459 | * @param eventTime The time (in {@link android.os.SystemClock#uptimeMillis}) |
| 1460 | * at which this event happened. |
| 1461 | * @param action Action code: either {@link #ACTION_DOWN}, |
| 1462 | * {@link #ACTION_UP}, or {@link #ACTION_MULTIPLE}. |
| 1463 | * @param code The key code. |
| 1464 | * @param repeat A repeat count for down events (> 0 if this is after the |
| 1465 | * initial down) or event count for multiple events. |
| 1466 | * @param metaState Flags indicating which meta keys are currently pressed. |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1467 | * @param deviceId The device ID that generated the key event. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1468 | * @param scancode Raw device scan code of the event. |
| 1469 | * @param flags The flags for this key event |
| 1470 | */ |
| 1471 | public KeyEvent(long downTime, long eventTime, int action, |
| 1472 | int code, int repeat, int metaState, |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1473 | int deviceId, int scancode, int flags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1474 | mDownTime = downTime; |
| 1475 | mEventTime = eventTime; |
| 1476 | mAction = action; |
| 1477 | mKeyCode = code; |
| 1478 | mRepeatCount = repeat; |
| 1479 | mMetaState = metaState; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1480 | mDeviceId = deviceId; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1481 | mScanCode = scancode; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1482 | mFlags = flags; |
| 1483 | } |
| 1484 | |
| 1485 | /** |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1486 | * Create a new key event. |
| 1487 | * |
| 1488 | * @param downTime The time (in {@link android.os.SystemClock#uptimeMillis}) |
| 1489 | * at which this key code originally went down. |
| 1490 | * @param eventTime The time (in {@link android.os.SystemClock#uptimeMillis}) |
| 1491 | * at which this event happened. |
| 1492 | * @param action Action code: either {@link #ACTION_DOWN}, |
| 1493 | * {@link #ACTION_UP}, or {@link #ACTION_MULTIPLE}. |
| 1494 | * @param code The key code. |
| 1495 | * @param repeat A repeat count for down events (> 0 if this is after the |
| 1496 | * initial down) or event count for multiple events. |
| 1497 | * @param metaState Flags indicating which meta keys are currently pressed. |
| 1498 | * @param deviceId The device ID that generated the key event. |
| 1499 | * @param scancode Raw device scan code of the event. |
| 1500 | * @param flags The flags for this key event |
| 1501 | * @param source The input source such as {@link InputDevice#SOURCE_KEYBOARD}. |
| 1502 | */ |
| 1503 | public KeyEvent(long downTime, long eventTime, int action, |
| 1504 | int code, int repeat, int metaState, |
| 1505 | int deviceId, int scancode, int flags, int source) { |
| 1506 | mDownTime = downTime; |
| 1507 | mEventTime = eventTime; |
| 1508 | mAction = action; |
| 1509 | mKeyCode = code; |
| 1510 | mRepeatCount = repeat; |
| 1511 | mMetaState = metaState; |
| 1512 | mDeviceId = deviceId; |
| 1513 | mScanCode = scancode; |
| 1514 | mFlags = flags; |
| 1515 | mSource = source; |
| 1516 | } |
| 1517 | |
| 1518 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1519 | * Create a new key event for a string of characters. The key code, |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1520 | * action, repeat count and source will automatically be set to |
| 1521 | * {@link #KEYCODE_UNKNOWN}, {@link #ACTION_MULTIPLE}, 0, and |
| 1522 | * {@link InputDevice#SOURCE_KEYBOARD} for you. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1523 | * |
| 1524 | * @param time The time (in {@link android.os.SystemClock#uptimeMillis}) |
| 1525 | * at which this event occured. |
| 1526 | * @param characters The string of characters. |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1527 | * @param deviceId The device ID that generated the key event. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1528 | * @param flags The flags for this key event |
| 1529 | */ |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1530 | public KeyEvent(long time, String characters, int deviceId, int flags) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1531 | mDownTime = time; |
| 1532 | mEventTime = time; |
| 1533 | mCharacters = characters; |
| 1534 | mAction = ACTION_MULTIPLE; |
| 1535 | mKeyCode = KEYCODE_UNKNOWN; |
| 1536 | mRepeatCount = 0; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1537 | mDeviceId = deviceId; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1538 | mFlags = flags; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1539 | mSource = InputDevice.SOURCE_KEYBOARD; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1540 | } |
| 1541 | |
| 1542 | /** |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1543 | * Make an exact copy of an existing key event. |
| 1544 | */ |
| 1545 | public KeyEvent(KeyEvent origEvent) { |
| 1546 | mDownTime = origEvent.mDownTime; |
| 1547 | mEventTime = origEvent.mEventTime; |
| 1548 | mAction = origEvent.mAction; |
| 1549 | mKeyCode = origEvent.mKeyCode; |
| 1550 | mRepeatCount = origEvent.mRepeatCount; |
| 1551 | mMetaState = origEvent.mMetaState; |
| 1552 | mDeviceId = origEvent.mDeviceId; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1553 | mSource = origEvent.mSource; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1554 | mScanCode = origEvent.mScanCode; |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1555 | mFlags = origEvent.mFlags; |
| 1556 | mCharacters = origEvent.mCharacters; |
| 1557 | } |
| 1558 | |
| 1559 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1560 | * Copy an existing key event, modifying its time and repeat count. |
| 1561 | * |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 1562 | * @deprecated Use {@link #changeTimeRepeat(KeyEvent, long, int)} |
| 1563 | * instead. |
| 1564 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1565 | * @param origEvent The existing event to be copied. |
| 1566 | * @param eventTime The new event time |
| 1567 | * (in {@link android.os.SystemClock#uptimeMillis}) of the event. |
| 1568 | * @param newRepeat The new repeat count of the event. |
| 1569 | */ |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 1570 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1571 | public KeyEvent(KeyEvent origEvent, long eventTime, int newRepeat) { |
| 1572 | mDownTime = origEvent.mDownTime; |
| 1573 | mEventTime = eventTime; |
| 1574 | mAction = origEvent.mAction; |
| 1575 | mKeyCode = origEvent.mKeyCode; |
| 1576 | mRepeatCount = newRepeat; |
| 1577 | mMetaState = origEvent.mMetaState; |
| 1578 | mDeviceId = origEvent.mDeviceId; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1579 | mSource = origEvent.mSource; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1580 | mScanCode = origEvent.mScanCode; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1581 | mFlags = origEvent.mFlags; |
| 1582 | mCharacters = origEvent.mCharacters; |
| 1583 | } |
| 1584 | |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 1585 | private static KeyEvent obtain() { |
| 1586 | final KeyEvent ev; |
| 1587 | synchronized (gRecyclerLock) { |
| 1588 | ev = gRecyclerTop; |
| 1589 | if (ev == null) { |
| 1590 | return new KeyEvent(); |
| 1591 | } |
| 1592 | gRecyclerTop = ev.mNext; |
| 1593 | gRecyclerUsed -= 1; |
| 1594 | } |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 1595 | ev.mNext = null; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 1596 | ev.prepareForReuse(); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 1597 | return ev; |
| 1598 | } |
| 1599 | |
| 1600 | /** |
| 1601 | * Obtains a (potentially recycled) key event. |
| 1602 | * |
| 1603 | * @hide |
| 1604 | */ |
| 1605 | public static KeyEvent obtain(long downTime, long eventTime, int action, |
| 1606 | int code, int repeat, int metaState, |
| 1607 | int deviceId, int scancode, int flags, int source, String characters) { |
| 1608 | KeyEvent ev = obtain(); |
| 1609 | ev.mDownTime = downTime; |
| 1610 | ev.mEventTime = eventTime; |
| 1611 | ev.mAction = action; |
| 1612 | ev.mKeyCode = code; |
| 1613 | ev.mRepeatCount = repeat; |
| 1614 | ev.mMetaState = metaState; |
| 1615 | ev.mDeviceId = deviceId; |
| 1616 | ev.mScanCode = scancode; |
| 1617 | ev.mFlags = flags; |
| 1618 | ev.mSource = source; |
| 1619 | ev.mCharacters = characters; |
| 1620 | return ev; |
| 1621 | } |
| 1622 | |
| 1623 | /** |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 1624 | * Obtains a (potentially recycled) copy of another key event. |
| 1625 | * |
| 1626 | * @hide |
| 1627 | */ |
| 1628 | public static KeyEvent obtain(KeyEvent other) { |
| 1629 | KeyEvent ev = obtain(); |
| 1630 | ev.mDownTime = other.mDownTime; |
| 1631 | ev.mEventTime = other.mEventTime; |
| 1632 | ev.mAction = other.mAction; |
| 1633 | ev.mKeyCode = other.mKeyCode; |
| 1634 | ev.mRepeatCount = other.mRepeatCount; |
| 1635 | ev.mMetaState = other.mMetaState; |
| 1636 | ev.mDeviceId = other.mDeviceId; |
| 1637 | ev.mScanCode = other.mScanCode; |
| 1638 | ev.mFlags = other.mFlags; |
| 1639 | ev.mSource = other.mSource; |
| 1640 | ev.mCharacters = other.mCharacters; |
| 1641 | return ev; |
| 1642 | } |
| 1643 | |
| 1644 | /** @hide */ |
| 1645 | @Override |
| 1646 | public KeyEvent copy() { |
| 1647 | return obtain(this); |
| 1648 | } |
| 1649 | |
| 1650 | /** |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 1651 | * Recycles a key event. |
| 1652 | * Key events should only be recycled if they are owned by the system since user |
| 1653 | * code expects them to be essentially immutable, "tracking" notwithstanding. |
| 1654 | * |
| 1655 | * @hide |
| 1656 | */ |
Jeff Brown | 92cc2d8 | 2011-12-02 01:19:47 -0800 | [diff] [blame] | 1657 | @Override |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 1658 | public final void recycle() { |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 1659 | super.recycle(); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 1660 | mCharacters = null; |
| 1661 | |
| 1662 | synchronized (gRecyclerLock) { |
| 1663 | if (gRecyclerUsed < MAX_RECYCLED) { |
| 1664 | gRecyclerUsed++; |
| 1665 | mNext = gRecyclerTop; |
| 1666 | gRecyclerTop = this; |
| 1667 | } |
| 1668 | } |
| 1669 | } |
| 1670 | |
Jeff Brown | 92cc2d8 | 2011-12-02 01:19:47 -0800 | [diff] [blame] | 1671 | /** @hide */ |
| 1672 | @Override |
| 1673 | public final void recycleIfNeededAfterDispatch() { |
| 1674 | // Do nothing. |
| 1675 | } |
| 1676 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1677 | /** |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1678 | * Create a new key event that is the same as the given one, but whose |
| 1679 | * event time and repeat count are replaced with the given value. |
| 1680 | * |
| 1681 | * @param event The existing event to be copied. This is not modified. |
| 1682 | * @param eventTime The new event time |
| 1683 | * (in {@link android.os.SystemClock#uptimeMillis}) of the event. |
| 1684 | * @param newRepeat The new repeat count of the event. |
| 1685 | */ |
| 1686 | public static KeyEvent changeTimeRepeat(KeyEvent event, long eventTime, |
| 1687 | int newRepeat) { |
| 1688 | return new KeyEvent(event, eventTime, newRepeat); |
| 1689 | } |
| 1690 | |
| 1691 | /** |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 1692 | * Create a new key event that is the same as the given one, but whose |
| 1693 | * event time and repeat count are replaced with the given value. |
| 1694 | * |
| 1695 | * @param event The existing event to be copied. This is not modified. |
| 1696 | * @param eventTime The new event time |
| 1697 | * (in {@link android.os.SystemClock#uptimeMillis}) of the event. |
| 1698 | * @param newRepeat The new repeat count of the event. |
| 1699 | * @param newFlags New flags for the event, replacing the entire value |
| 1700 | * in the original event. |
| 1701 | */ |
| 1702 | public static KeyEvent changeTimeRepeat(KeyEvent event, long eventTime, |
| 1703 | int newRepeat, int newFlags) { |
| 1704 | KeyEvent ret = new KeyEvent(event); |
| 1705 | ret.mEventTime = eventTime; |
| 1706 | ret.mRepeatCount = newRepeat; |
| 1707 | ret.mFlags = newFlags; |
| 1708 | return ret; |
| 1709 | } |
| 1710 | |
| 1711 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1712 | * Copy an existing key event, modifying its action. |
| 1713 | * |
| 1714 | * @param origEvent The existing event to be copied. |
| 1715 | * @param action The new action code of the event. |
| 1716 | */ |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1717 | private KeyEvent(KeyEvent origEvent, int action) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1718 | mDownTime = origEvent.mDownTime; |
| 1719 | mEventTime = origEvent.mEventTime; |
| 1720 | mAction = action; |
| 1721 | mKeyCode = origEvent.mKeyCode; |
| 1722 | mRepeatCount = origEvent.mRepeatCount; |
| 1723 | mMetaState = origEvent.mMetaState; |
| 1724 | mDeviceId = origEvent.mDeviceId; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1725 | mSource = origEvent.mSource; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1726 | mScanCode = origEvent.mScanCode; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1727 | mFlags = origEvent.mFlags; |
| 1728 | // Don't copy mCharacters, since one way or the other we'll lose it |
| 1729 | // when changing the action. |
| 1730 | } |
| 1731 | |
| 1732 | /** |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1733 | * Create a new key event that is the same as the given one, but whose |
| 1734 | * action is replaced with the given value. |
| 1735 | * |
| 1736 | * @param event The existing event to be copied. This is not modified. |
| 1737 | * @param action The new action code of the event. |
| 1738 | */ |
| 1739 | public static KeyEvent changeAction(KeyEvent event, int action) { |
| 1740 | return new KeyEvent(event, action); |
| 1741 | } |
| 1742 | |
| 1743 | /** |
| 1744 | * Create a new key event that is the same as the given one, but whose |
| 1745 | * flags are replaced with the given value. |
| 1746 | * |
| 1747 | * @param event The existing event to be copied. This is not modified. |
| 1748 | * @param flags The new flags constant. |
| 1749 | */ |
| 1750 | public static KeyEvent changeFlags(KeyEvent event, int flags) { |
| 1751 | event = new KeyEvent(event); |
| 1752 | event.mFlags = flags; |
| 1753 | return event; |
| 1754 | } |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 1755 | |
| 1756 | /** @hide */ |
| 1757 | @Override |
| 1758 | public final boolean isTainted() { |
| 1759 | return (mFlags & FLAG_TAINTED) != 0; |
| 1760 | } |
| 1761 | |
| 1762 | /** @hide */ |
| 1763 | @Override |
| 1764 | public final void setTainted(boolean tainted) { |
| 1765 | mFlags = tainted ? mFlags | FLAG_TAINTED : mFlags & ~FLAG_TAINTED; |
| 1766 | } |
| 1767 | |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 1768 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1769 | * Don't use in new code, instead explicitly check |
| 1770 | * {@link #getAction()}. |
| 1771 | * |
| 1772 | * @return If the action is ACTION_DOWN, returns true; else false. |
| 1773 | * |
| 1774 | * @deprecated |
| 1775 | * @hide |
| 1776 | */ |
| 1777 | @Deprecated public final boolean isDown() { |
| 1778 | return mAction == ACTION_DOWN; |
| 1779 | } |
| 1780 | |
| 1781 | /** |
| 1782 | * Is this a system key? System keys can not be used for menu shortcuts. |
| 1783 | * |
| 1784 | * TODO: this information should come from a table somewhere. |
| 1785 | * TODO: should the dpad keys be here? arguably, because they also shouldn't be menu shortcuts |
| 1786 | */ |
| 1787 | public final boolean isSystem() { |
Dianne Hackborn | 3c80a4a | 2010-06-29 19:20:40 -0700 | [diff] [blame] | 1788 | return native_isSystemKey(mKeyCode); |
| 1789 | } |
| 1790 | |
| 1791 | /** @hide */ |
| 1792 | public final boolean hasDefaultAction() { |
| 1793 | return native_hasDefaultAction(mKeyCode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1794 | } |
| 1795 | |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 1796 | /** |
| 1797 | * Returns true if the specified keycode is a gamepad button. |
| 1798 | * @return True if the keycode is a gamepad button, such as {@link #KEYCODE_BUTTON_A}. |
| 1799 | */ |
| 1800 | public static final boolean isGamepadButton(int keyCode) { |
| 1801 | switch (keyCode) { |
| 1802 | case KeyEvent.KEYCODE_BUTTON_A: |
| 1803 | case KeyEvent.KEYCODE_BUTTON_B: |
| 1804 | case KeyEvent.KEYCODE_BUTTON_C: |
| 1805 | case KeyEvent.KEYCODE_BUTTON_X: |
| 1806 | case KeyEvent.KEYCODE_BUTTON_Y: |
| 1807 | case KeyEvent.KEYCODE_BUTTON_Z: |
| 1808 | case KeyEvent.KEYCODE_BUTTON_L1: |
| 1809 | case KeyEvent.KEYCODE_BUTTON_R1: |
| 1810 | case KeyEvent.KEYCODE_BUTTON_L2: |
| 1811 | case KeyEvent.KEYCODE_BUTTON_R2: |
| 1812 | case KeyEvent.KEYCODE_BUTTON_THUMBL: |
| 1813 | case KeyEvent.KEYCODE_BUTTON_THUMBR: |
| 1814 | case KeyEvent.KEYCODE_BUTTON_START: |
| 1815 | case KeyEvent.KEYCODE_BUTTON_SELECT: |
| 1816 | case KeyEvent.KEYCODE_BUTTON_MODE: |
| 1817 | case KeyEvent.KEYCODE_BUTTON_1: |
| 1818 | case KeyEvent.KEYCODE_BUTTON_2: |
| 1819 | case KeyEvent.KEYCODE_BUTTON_3: |
| 1820 | case KeyEvent.KEYCODE_BUTTON_4: |
| 1821 | case KeyEvent.KEYCODE_BUTTON_5: |
| 1822 | case KeyEvent.KEYCODE_BUTTON_6: |
| 1823 | case KeyEvent.KEYCODE_BUTTON_7: |
| 1824 | case KeyEvent.KEYCODE_BUTTON_8: |
| 1825 | case KeyEvent.KEYCODE_BUTTON_9: |
| 1826 | case KeyEvent.KEYCODE_BUTTON_10: |
| 1827 | case KeyEvent.KEYCODE_BUTTON_11: |
| 1828 | case KeyEvent.KEYCODE_BUTTON_12: |
| 1829 | case KeyEvent.KEYCODE_BUTTON_13: |
| 1830 | case KeyEvent.KEYCODE_BUTTON_14: |
| 1831 | case KeyEvent.KEYCODE_BUTTON_15: |
| 1832 | case KeyEvent.KEYCODE_BUTTON_16: |
| 1833 | return true; |
| 1834 | default: |
| 1835 | return false; |
| 1836 | } |
| 1837 | } |
| 1838 | |
Michael Wright | 25b0c30 | 2013-07-10 12:54:06 -0700 | [diff] [blame] | 1839 | /** Whether key will, by default, trigger a click on the focused view. |
| 1840 | * @hide |
| 1841 | */ |
| 1842 | public static final boolean isConfirmKey(int keyCode) { |
| 1843 | switch (keyCode) { |
| 1844 | case KeyEvent.KEYCODE_DPAD_CENTER: |
| 1845 | case KeyEvent.KEYCODE_ENTER: |
| 1846 | return true; |
| 1847 | default: |
| 1848 | return false; |
| 1849 | } |
| 1850 | } |
| 1851 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1852 | /** {@inheritDoc} */ |
| 1853 | @Override |
| 1854 | public final int getDeviceId() { |
| 1855 | return mDeviceId; |
| 1856 | } |
| 1857 | |
| 1858 | /** {@inheritDoc} */ |
| 1859 | @Override |
| 1860 | public final int getSource() { |
| 1861 | return mSource; |
| 1862 | } |
| 1863 | |
| 1864 | /** {@inheritDoc} */ |
| 1865 | @Override |
| 1866 | public final void setSource(int source) { |
| 1867 | mSource = source; |
| 1868 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1869 | |
| 1870 | /** |
| 1871 | * <p>Returns the state of the meta keys.</p> |
| 1872 | * |
| 1873 | * @return an integer in which each bit set to 1 represents a pressed |
| 1874 | * meta key |
| 1875 | * |
| 1876 | * @see #isAltPressed() |
| 1877 | * @see #isShiftPressed() |
| 1878 | * @see #isSymPressed() |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 1879 | * @see #isCtrlPressed() |
| 1880 | * @see #isMetaPressed() |
| 1881 | * @see #isFunctionPressed() |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 1882 | * @see #isCapsLockOn() |
| 1883 | * @see #isNumLockOn() |
| 1884 | * @see #isScrollLockOn() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1885 | * @see #META_ALT_ON |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 1886 | * @see #META_ALT_LEFT_ON |
| 1887 | * @see #META_ALT_RIGHT_ON |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1888 | * @see #META_SHIFT_ON |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 1889 | * @see #META_SHIFT_LEFT_ON |
| 1890 | * @see #META_SHIFT_RIGHT_ON |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1891 | * @see #META_SYM_ON |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 1892 | * @see #META_FUNCTION_ON |
| 1893 | * @see #META_CTRL_ON |
| 1894 | * @see #META_CTRL_LEFT_ON |
| 1895 | * @see #META_CTRL_RIGHT_ON |
| 1896 | * @see #META_META_ON |
| 1897 | * @see #META_META_LEFT_ON |
| 1898 | * @see #META_META_RIGHT_ON |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 1899 | * @see #META_CAPS_LOCK_ON |
| 1900 | * @see #META_NUM_LOCK_ON |
| 1901 | * @see #META_SCROLL_LOCK_ON |
Jeff Brown | 5487500 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 1902 | * @see #getModifiers |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1903 | */ |
| 1904 | public final int getMetaState() { |
| 1905 | return mMetaState; |
| 1906 | } |
| 1907 | |
| 1908 | /** |
Jeff Brown | 5487500 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 1909 | * Returns the state of the modifier keys. |
| 1910 | * <p> |
| 1911 | * For the purposes of this function, {@link #KEYCODE_CAPS_LOCK}, |
| 1912 | * {@link #KEYCODE_SCROLL_LOCK}, and {@link #KEYCODE_NUM_LOCK} are |
| 1913 | * not considered modifier keys. Consequently, this function specifically masks out |
| 1914 | * {@link #META_CAPS_LOCK_ON}, {@link #META_SCROLL_LOCK_ON} and {@link #META_NUM_LOCK_ON}. |
| 1915 | * </p><p> |
| 1916 | * The value returned consists of the meta state (from {@link #getMetaState}) |
| 1917 | * normalized using {@link #normalizeMetaState(int)} and then masked with |
| 1918 | * {@link #getModifierMetaStateMask} so that only valid modifier bits are retained. |
| 1919 | * </p> |
| 1920 | * |
| 1921 | * @return An integer in which each bit set to 1 represents a pressed modifier key. |
| 1922 | * @see #getMetaState |
| 1923 | */ |
| 1924 | public final int getModifiers() { |
| 1925 | return normalizeMetaState(mMetaState) & META_MODIFIER_MASK; |
| 1926 | } |
| 1927 | |
| 1928 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1929 | * Returns the flags for this key event. |
| 1930 | * |
| 1931 | * @see #FLAG_WOKE_HERE |
| 1932 | */ |
| 1933 | public final int getFlags() { |
| 1934 | return mFlags; |
| 1935 | } |
| 1936 | |
Jeff Brown | 28cbf4b | 2010-12-13 10:33:20 -0800 | [diff] [blame] | 1937 | // Mask of all modifier key meta states. Specifically excludes locked keys like caps lock. |
| 1938 | private static final int META_MODIFIER_MASK = |
| 1939 | META_SHIFT_ON | META_SHIFT_LEFT_ON | META_SHIFT_RIGHT_ON |
| 1940 | | META_ALT_ON | META_ALT_LEFT_ON | META_ALT_RIGHT_ON |
| 1941 | | META_CTRL_ON | META_CTRL_LEFT_ON | META_CTRL_RIGHT_ON |
| 1942 | | META_META_ON | META_META_LEFT_ON | META_META_RIGHT_ON |
| 1943 | | META_SYM_ON | META_FUNCTION_ON; |
| 1944 | |
| 1945 | // Mask of all lock key meta states. |
| 1946 | private static final int META_LOCK_MASK = |
| 1947 | META_CAPS_LOCK_ON | META_NUM_LOCK_ON | META_SCROLL_LOCK_ON; |
| 1948 | |
| 1949 | // Mask of all valid meta states. |
| 1950 | private static final int META_ALL_MASK = META_MODIFIER_MASK | META_LOCK_MASK; |
| 1951 | |
| 1952 | // Mask of all synthetic meta states that are reserved for API compatibility with |
| 1953 | // historical uses in MetaKeyKeyListener. |
| 1954 | private static final int META_SYNTHETIC_MASK = |
| 1955 | META_CAP_LOCKED | META_ALT_LOCKED | META_SYM_LOCKED | META_SELECTING; |
| 1956 | |
| 1957 | // Mask of all meta states that are not valid use in specifying a modifier key. |
| 1958 | // These bits are known to be used for purposes other than specifying modifiers. |
| 1959 | private static final int META_INVALID_MODIFIER_MASK = |
| 1960 | META_LOCK_MASK | META_SYNTHETIC_MASK; |
| 1961 | |
| 1962 | /** |
| 1963 | * Gets a mask that includes all valid modifier key meta state bits. |
| 1964 | * <p> |
| 1965 | * For the purposes of this function, {@link #KEYCODE_CAPS_LOCK}, |
| 1966 | * {@link #KEYCODE_SCROLL_LOCK}, and {@link #KEYCODE_NUM_LOCK} are |
| 1967 | * not considered modifier keys. Consequently, the mask specifically excludes |
| 1968 | * {@link #META_CAPS_LOCK_ON}, {@link #META_SCROLL_LOCK_ON} and {@link #META_NUM_LOCK_ON}. |
| 1969 | * </p> |
| 1970 | * |
| 1971 | * @return The modifier meta state mask which is a combination of |
| 1972 | * {@link #META_SHIFT_ON}, {@link #META_SHIFT_LEFT_ON}, {@link #META_SHIFT_RIGHT_ON}, |
| 1973 | * {@link #META_ALT_ON}, {@link #META_ALT_LEFT_ON}, {@link #META_ALT_RIGHT_ON}, |
| 1974 | * {@link #META_CTRL_ON}, {@link #META_CTRL_LEFT_ON}, {@link #META_CTRL_RIGHT_ON}, |
| 1975 | * {@link #META_META_ON}, {@link #META_META_LEFT_ON}, {@link #META_META_RIGHT_ON}, |
| 1976 | * {@link #META_SYM_ON}, {@link #META_FUNCTION_ON}. |
| 1977 | */ |
| 1978 | public static int getModifierMetaStateMask() { |
| 1979 | return META_MODIFIER_MASK; |
| 1980 | } |
| 1981 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1982 | /** |
| 1983 | * Returns true if this key code is a modifier key. |
Jeff Brown | 28cbf4b | 2010-12-13 10:33:20 -0800 | [diff] [blame] | 1984 | * <p> |
| 1985 | * For the purposes of this function, {@link #KEYCODE_CAPS_LOCK}, |
| 1986 | * {@link #KEYCODE_SCROLL_LOCK}, and {@link #KEYCODE_NUM_LOCK} are |
| 1987 | * not considered modifier keys. Consequently, this function return false |
| 1988 | * for those keys. |
| 1989 | * </p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1990 | * |
Jeff Brown | 28cbf4b | 2010-12-13 10:33:20 -0800 | [diff] [blame] | 1991 | * @return True if the key code is one of |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1992 | * {@link #KEYCODE_SHIFT_LEFT} {@link #KEYCODE_SHIFT_RIGHT}, |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 1993 | * {@link #KEYCODE_ALT_LEFT}, {@link #KEYCODE_ALT_RIGHT}, |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 1994 | * {@link #KEYCODE_CTRL_LEFT}, {@link #KEYCODE_CTRL_RIGHT}, |
Jeff Brown | 28cbf4b | 2010-12-13 10:33:20 -0800 | [diff] [blame] | 1995 | * {@link #KEYCODE_META_LEFT}, or {@link #KEYCODE_META_RIGHT}, |
| 1996 | * {@link #KEYCODE_SYM}, {@link #KEYCODE_NUM}, {@link #KEYCODE_FUNCTION}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1997 | */ |
| 1998 | public static boolean isModifierKey(int keyCode) { |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 1999 | switch (keyCode) { |
| 2000 | case KEYCODE_SHIFT_LEFT: |
| 2001 | case KEYCODE_SHIFT_RIGHT: |
| 2002 | case KEYCODE_ALT_LEFT: |
| 2003 | case KEYCODE_ALT_RIGHT: |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2004 | case KEYCODE_CTRL_LEFT: |
| 2005 | case KEYCODE_CTRL_RIGHT: |
| 2006 | case KEYCODE_META_LEFT: |
| 2007 | case KEYCODE_META_RIGHT: |
Jeff Brown | 28cbf4b | 2010-12-13 10:33:20 -0800 | [diff] [blame] | 2008 | case KEYCODE_SYM: |
| 2009 | case KEYCODE_NUM: |
| 2010 | case KEYCODE_FUNCTION: |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2011 | return true; |
| 2012 | default: |
| 2013 | return false; |
| 2014 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2015 | } |
| 2016 | |
| 2017 | /** |
Jeff Brown | 28cbf4b | 2010-12-13 10:33:20 -0800 | [diff] [blame] | 2018 | * Normalizes the specified meta state. |
| 2019 | * <p> |
| 2020 | * The meta state is normalized such that if either the left or right modifier meta state |
| 2021 | * bits are set then the result will also include the universal bit for that modifier. |
| 2022 | * </p><p> |
| 2023 | * If the specified meta state contains {@link #META_ALT_LEFT_ON} then |
| 2024 | * the result will also contain {@link #META_ALT_ON} in addition to {@link #META_ALT_LEFT_ON} |
| 2025 | * and the other bits that were specified in the input. The same is process is |
| 2026 | * performed for shift, control and meta. |
| 2027 | * </p><p> |
| 2028 | * If the specified meta state contains synthetic meta states defined by |
| 2029 | * {@link MetaKeyKeyListener}, then those states are translated here and the original |
| 2030 | * synthetic meta states are removed from the result. |
| 2031 | * {@link MetaKeyKeyListener#META_CAP_LOCKED} is translated to {@link #META_CAPS_LOCK_ON}. |
| 2032 | * {@link MetaKeyKeyListener#META_ALT_LOCKED} is translated to {@link #META_ALT_ON}. |
| 2033 | * {@link MetaKeyKeyListener#META_SYM_LOCKED} is translated to {@link #META_SYM_ON}. |
| 2034 | * </p><p> |
| 2035 | * Undefined meta state bits are removed. |
| 2036 | * </p> |
| 2037 | * |
| 2038 | * @param metaState The meta state. |
| 2039 | * @return The normalized meta state. |
| 2040 | */ |
| 2041 | public static int normalizeMetaState(int metaState) { |
| 2042 | if ((metaState & (META_SHIFT_LEFT_ON | META_SHIFT_RIGHT_ON)) != 0) { |
| 2043 | metaState |= META_SHIFT_ON; |
| 2044 | } |
| 2045 | if ((metaState & (META_ALT_LEFT_ON | META_ALT_RIGHT_ON)) != 0) { |
| 2046 | metaState |= META_ALT_ON; |
| 2047 | } |
| 2048 | if ((metaState & (META_CTRL_LEFT_ON | META_CTRL_RIGHT_ON)) != 0) { |
| 2049 | metaState |= META_CTRL_ON; |
| 2050 | } |
| 2051 | if ((metaState & (META_META_LEFT_ON | META_META_RIGHT_ON)) != 0) { |
| 2052 | metaState |= META_META_ON; |
| 2053 | } |
| 2054 | if ((metaState & MetaKeyKeyListener.META_CAP_LOCKED) != 0) { |
| 2055 | metaState |= META_CAPS_LOCK_ON; |
| 2056 | } |
| 2057 | if ((metaState & MetaKeyKeyListener.META_ALT_LOCKED) != 0) { |
| 2058 | metaState |= META_ALT_ON; |
| 2059 | } |
| 2060 | if ((metaState & MetaKeyKeyListener.META_SYM_LOCKED) != 0) { |
| 2061 | metaState |= META_SYM_ON; |
| 2062 | } |
| 2063 | return metaState & META_ALL_MASK; |
| 2064 | } |
| 2065 | |
| 2066 | /** |
| 2067 | * Returns true if no modifiers keys are pressed according to the specified meta state. |
| 2068 | * <p> |
| 2069 | * For the purposes of this function, {@link #KEYCODE_CAPS_LOCK}, |
| 2070 | * {@link #KEYCODE_SCROLL_LOCK}, and {@link #KEYCODE_NUM_LOCK} are |
| 2071 | * not considered modifier keys. Consequently, this function ignores |
| 2072 | * {@link #META_CAPS_LOCK_ON}, {@link #META_SCROLL_LOCK_ON} and {@link #META_NUM_LOCK_ON}. |
| 2073 | * </p><p> |
| 2074 | * The meta state is normalized prior to comparison using {@link #normalizeMetaState(int)}. |
| 2075 | * </p> |
| 2076 | * |
| 2077 | * @param metaState The meta state to consider. |
| 2078 | * @return True if no modifier keys are pressed. |
| 2079 | * @see #hasNoModifiers() |
| 2080 | */ |
| 2081 | public static boolean metaStateHasNoModifiers(int metaState) { |
| 2082 | return (normalizeMetaState(metaState) & META_MODIFIER_MASK) == 0; |
| 2083 | } |
| 2084 | |
| 2085 | /** |
| 2086 | * Returns true if only the specified modifier keys are pressed according to |
| 2087 | * the specified meta state. Returns false if a different combination of modifier |
| 2088 | * keys are pressed. |
| 2089 | * <p> |
| 2090 | * For the purposes of this function, {@link #KEYCODE_CAPS_LOCK}, |
| 2091 | * {@link #KEYCODE_SCROLL_LOCK}, and {@link #KEYCODE_NUM_LOCK} are |
| 2092 | * not considered modifier keys. Consequently, this function ignores |
| 2093 | * {@link #META_CAPS_LOCK_ON}, {@link #META_SCROLL_LOCK_ON} and {@link #META_NUM_LOCK_ON}. |
| 2094 | * </p><p> |
| 2095 | * If the specified modifier mask includes directional modifiers, such as |
| 2096 | * {@link #META_SHIFT_LEFT_ON}, then this method ensures that the |
| 2097 | * modifier is pressed on that side. |
| 2098 | * If the specified modifier mask includes non-directional modifiers, such as |
| 2099 | * {@link #META_SHIFT_ON}, then this method ensures that the modifier |
| 2100 | * is pressed on either side. |
| 2101 | * If the specified modifier mask includes both directional and non-directional modifiers |
| 2102 | * for the same type of key, such as {@link #META_SHIFT_ON} and {@link #META_SHIFT_LEFT_ON}, |
| 2103 | * then this method throws an illegal argument exception. |
| 2104 | * </p> |
| 2105 | * |
| 2106 | * @param metaState The meta state to consider. |
| 2107 | * @param modifiers The meta state of the modifier keys to check. May be a combination |
| 2108 | * of modifier meta states as defined by {@link #getModifierMetaStateMask()}. May be 0 to |
| 2109 | * ensure that no modifier keys are pressed. |
| 2110 | * @return True if only the specified modifier keys are pressed. |
| 2111 | * @throws IllegalArgumentException if the modifiers parameter contains invalid modifiers |
| 2112 | * @see #hasModifiers |
| 2113 | */ |
| 2114 | public static boolean metaStateHasModifiers(int metaState, int modifiers) { |
| 2115 | // Note: For forward compatibility, we allow the parameter to contain meta states |
| 2116 | // that we do not recognize but we explicitly disallow meta states that |
| 2117 | // are not valid modifiers. |
| 2118 | if ((modifiers & META_INVALID_MODIFIER_MASK) != 0) { |
| 2119 | throw new IllegalArgumentException("modifiers must not contain " |
| 2120 | + "META_CAPS_LOCK_ON, META_NUM_LOCK_ON, META_SCROLL_LOCK_ON, " |
| 2121 | + "META_CAP_LOCKED, META_ALT_LOCKED, META_SYM_LOCKED, " |
| 2122 | + "or META_SELECTING"); |
| 2123 | } |
| 2124 | |
| 2125 | metaState = normalizeMetaState(metaState) & META_MODIFIER_MASK; |
| 2126 | metaState = metaStateFilterDirectionalModifiers(metaState, modifiers, |
| 2127 | META_SHIFT_ON, META_SHIFT_LEFT_ON, META_SHIFT_RIGHT_ON); |
| 2128 | metaState = metaStateFilterDirectionalModifiers(metaState, modifiers, |
| 2129 | META_ALT_ON, META_ALT_LEFT_ON, META_ALT_RIGHT_ON); |
| 2130 | metaState = metaStateFilterDirectionalModifiers(metaState, modifiers, |
| 2131 | META_CTRL_ON, META_CTRL_LEFT_ON, META_CTRL_RIGHT_ON); |
| 2132 | metaState = metaStateFilterDirectionalModifiers(metaState, modifiers, |
| 2133 | META_META_ON, META_META_LEFT_ON, META_META_RIGHT_ON); |
| 2134 | return metaState == modifiers; |
| 2135 | } |
| 2136 | |
| 2137 | private static int metaStateFilterDirectionalModifiers(int metaState, |
| 2138 | int modifiers, int basic, int left, int right) { |
| 2139 | final boolean wantBasic = (modifiers & basic) != 0; |
| 2140 | final int directional = left | right; |
| 2141 | final boolean wantLeftOrRight = (modifiers & directional) != 0; |
| 2142 | |
| 2143 | if (wantBasic) { |
| 2144 | if (wantLeftOrRight) { |
| 2145 | throw new IllegalArgumentException("modifiers must not contain " |
| 2146 | + metaStateToString(basic) + " combined with " |
| 2147 | + metaStateToString(left) + " or " + metaStateToString(right)); |
| 2148 | } |
| 2149 | return metaState & ~directional; |
| 2150 | } else if (wantLeftOrRight) { |
| 2151 | return metaState & ~basic; |
| 2152 | } else { |
| 2153 | return metaState; |
| 2154 | } |
| 2155 | } |
| 2156 | |
| 2157 | /** |
| 2158 | * Returns true if no modifier keys are pressed. |
| 2159 | * <p> |
| 2160 | * For the purposes of this function, {@link #KEYCODE_CAPS_LOCK}, |
| 2161 | * {@link #KEYCODE_SCROLL_LOCK}, and {@link #KEYCODE_NUM_LOCK} are |
| 2162 | * not considered modifier keys. Consequently, this function ignores |
| 2163 | * {@link #META_CAPS_LOCK_ON}, {@link #META_SCROLL_LOCK_ON} and {@link #META_NUM_LOCK_ON}. |
| 2164 | * </p><p> |
| 2165 | * The meta state is normalized prior to comparison using {@link #normalizeMetaState(int)}. |
| 2166 | * </p> |
| 2167 | * |
| 2168 | * @return True if no modifier keys are pressed. |
| 2169 | * @see #metaStateHasNoModifiers |
| 2170 | */ |
| 2171 | public final boolean hasNoModifiers() { |
| 2172 | return metaStateHasNoModifiers(mMetaState); |
| 2173 | } |
| 2174 | |
| 2175 | /** |
| 2176 | * Returns true if only the specified modifiers keys are pressed. |
| 2177 | * Returns false if a different combination of modifier keys are pressed. |
| 2178 | * <p> |
| 2179 | * For the purposes of this function, {@link #KEYCODE_CAPS_LOCK}, |
| 2180 | * {@link #KEYCODE_SCROLL_LOCK}, and {@link #KEYCODE_NUM_LOCK} are |
| 2181 | * not considered modifier keys. Consequently, this function ignores |
| 2182 | * {@link #META_CAPS_LOCK_ON}, {@link #META_SCROLL_LOCK_ON} and {@link #META_NUM_LOCK_ON}. |
| 2183 | * </p><p> |
| 2184 | * If the specified modifier mask includes directional modifiers, such as |
| 2185 | * {@link #META_SHIFT_LEFT_ON}, then this method ensures that the |
| 2186 | * modifier is pressed on that side. |
| 2187 | * If the specified modifier mask includes non-directional modifiers, such as |
| 2188 | * {@link #META_SHIFT_ON}, then this method ensures that the modifier |
| 2189 | * is pressed on either side. |
| 2190 | * If the specified modifier mask includes both directional and non-directional modifiers |
| 2191 | * for the same type of key, such as {@link #META_SHIFT_ON} and {@link #META_SHIFT_LEFT_ON}, |
| 2192 | * then this method throws an illegal argument exception. |
| 2193 | * </p> |
| 2194 | * |
| 2195 | * @param modifiers The meta state of the modifier keys to check. May be a combination |
| 2196 | * of modifier meta states as defined by {@link #getModifierMetaStateMask()}. May be 0 to |
| 2197 | * ensure that no modifier keys are pressed. |
| 2198 | * @return True if only the specified modifier keys are pressed. |
| 2199 | * @throws IllegalArgumentException if the modifiers parameter contains invalid modifiers |
| 2200 | * @see #metaStateHasModifiers |
| 2201 | */ |
| 2202 | public final boolean hasModifiers(int modifiers) { |
| 2203 | return metaStateHasModifiers(mMetaState, modifiers); |
| 2204 | } |
| 2205 | |
| 2206 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2207 | * <p>Returns the pressed state of the ALT meta key.</p> |
| 2208 | * |
| 2209 | * @return true if the ALT key is pressed, false otherwise |
| 2210 | * |
| 2211 | * @see #KEYCODE_ALT_LEFT |
| 2212 | * @see #KEYCODE_ALT_RIGHT |
| 2213 | * @see #META_ALT_ON |
| 2214 | */ |
| 2215 | public final boolean isAltPressed() { |
| 2216 | return (mMetaState & META_ALT_ON) != 0; |
| 2217 | } |
| 2218 | |
| 2219 | /** |
| 2220 | * <p>Returns the pressed state of the SHIFT meta key.</p> |
| 2221 | * |
| 2222 | * @return true if the SHIFT key is pressed, false otherwise |
| 2223 | * |
| 2224 | * @see #KEYCODE_SHIFT_LEFT |
| 2225 | * @see #KEYCODE_SHIFT_RIGHT |
| 2226 | * @see #META_SHIFT_ON |
| 2227 | */ |
| 2228 | public final boolean isShiftPressed() { |
| 2229 | return (mMetaState & META_SHIFT_ON) != 0; |
| 2230 | } |
| 2231 | |
| 2232 | /** |
| 2233 | * <p>Returns the pressed state of the SYM meta key.</p> |
| 2234 | * |
| 2235 | * @return true if the SYM key is pressed, false otherwise |
| 2236 | * |
| 2237 | * @see #KEYCODE_SYM |
| 2238 | * @see #META_SYM_ON |
| 2239 | */ |
| 2240 | public final boolean isSymPressed() { |
| 2241 | return (mMetaState & META_SYM_ON) != 0; |
| 2242 | } |
| 2243 | |
| 2244 | /** |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2245 | * <p>Returns the pressed state of the CTRL meta key.</p> |
| 2246 | * |
| 2247 | * @return true if the CTRL key is pressed, false otherwise |
| 2248 | * |
| 2249 | * @see #KEYCODE_CTRL_LEFT |
| 2250 | * @see #KEYCODE_CTRL_RIGHT |
| 2251 | * @see #META_CTRL_ON |
| 2252 | */ |
| 2253 | public final boolean isCtrlPressed() { |
| 2254 | return (mMetaState & META_CTRL_ON) != 0; |
| 2255 | } |
| 2256 | |
| 2257 | /** |
| 2258 | * <p>Returns the pressed state of the META meta key.</p> |
| 2259 | * |
| 2260 | * @return true if the META key is pressed, false otherwise |
| 2261 | * |
| 2262 | * @see #KEYCODE_META_LEFT |
| 2263 | * @see #KEYCODE_META_RIGHT |
| 2264 | * @see #META_META_ON |
| 2265 | */ |
| 2266 | public final boolean isMetaPressed() { |
| 2267 | return (mMetaState & META_META_ON) != 0; |
| 2268 | } |
| 2269 | |
| 2270 | /** |
| 2271 | * <p>Returns the pressed state of the FUNCTION meta key.</p> |
| 2272 | * |
| 2273 | * @return true if the FUNCTION key is pressed, false otherwise |
| 2274 | * |
| 2275 | * @see #KEYCODE_FUNCTION |
| 2276 | * @see #META_FUNCTION_ON |
| 2277 | */ |
| 2278 | public final boolean isFunctionPressed() { |
| 2279 | return (mMetaState & META_FUNCTION_ON) != 0; |
| 2280 | } |
| 2281 | |
| 2282 | /** |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 2283 | * <p>Returns the locked state of the CAPS LOCK meta key.</p> |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2284 | * |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 2285 | * @return true if the CAPS LOCK key is on, false otherwise |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2286 | * |
| 2287 | * @see #KEYCODE_CAPS_LOCK |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 2288 | * @see #META_CAPS_LOCK_ON |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2289 | */ |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 2290 | public final boolean isCapsLockOn() { |
| 2291 | return (mMetaState & META_CAPS_LOCK_ON) != 0; |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2292 | } |
| 2293 | |
| 2294 | /** |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 2295 | * <p>Returns the locked state of the NUM LOCK meta key.</p> |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2296 | * |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 2297 | * @return true if the NUM LOCK key is on, false otherwise |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2298 | * |
| 2299 | * @see #KEYCODE_NUM_LOCK |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 2300 | * @see #META_NUM_LOCK_ON |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2301 | */ |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 2302 | public final boolean isNumLockOn() { |
| 2303 | return (mMetaState & META_NUM_LOCK_ON) != 0; |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2304 | } |
| 2305 | |
| 2306 | /** |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 2307 | * <p>Returns the locked state of the SCROLL LOCK meta key.</p> |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2308 | * |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 2309 | * @return true if the SCROLL LOCK key is on, false otherwise |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2310 | * |
| 2311 | * @see #KEYCODE_SCROLL_LOCK |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 2312 | * @see #META_SCROLL_LOCK_ON |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2313 | */ |
Jeff Brown | 51e7fe7 | 2010-10-29 22:19:53 -0700 | [diff] [blame] | 2314 | public final boolean isScrollLockOn() { |
| 2315 | return (mMetaState & META_SCROLL_LOCK_ON) != 0; |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2316 | } |
| 2317 | |
| 2318 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2319 | * Retrieve the action of this key event. May be either |
| 2320 | * {@link #ACTION_DOWN}, {@link #ACTION_UP}, or {@link #ACTION_MULTIPLE}. |
| 2321 | * |
| 2322 | * @return The event action: ACTION_DOWN, ACTION_UP, or ACTION_MULTIPLE. |
| 2323 | */ |
| 2324 | public final int getAction() { |
| 2325 | return mAction; |
| 2326 | } |
| 2327 | |
| 2328 | /** |
Dianne Hackborn | ddca3ee | 2009-07-23 19:01:31 -0700 | [diff] [blame] | 2329 | * For {@link #ACTION_UP} events, indicates that the event has been |
| 2330 | * canceled as per {@link #FLAG_CANCELED}. |
| 2331 | */ |
| 2332 | public final boolean isCanceled() { |
| 2333 | return (mFlags&FLAG_CANCELED) != 0; |
| 2334 | } |
| 2335 | |
| 2336 | /** |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 2337 | * Call this during {@link Callback#onKeyDown} to have the system track |
| 2338 | * the key through its final up (possibly including a long press). Note |
| 2339 | * that only one key can be tracked at a time -- if another key down |
| 2340 | * event is received while a previous one is being tracked, tracking is |
| 2341 | * stopped on the previous event. |
| 2342 | */ |
| 2343 | public final void startTracking() { |
| 2344 | mFlags |= FLAG_START_TRACKING; |
| 2345 | } |
| 2346 | |
| 2347 | /** |
| 2348 | * For {@link #ACTION_UP} events, indicates that the event is still being |
| 2349 | * tracked from its initial down event as per |
| 2350 | * {@link #FLAG_TRACKING}. |
| 2351 | */ |
| 2352 | public final boolean isTracking() { |
| 2353 | return (mFlags&FLAG_TRACKING) != 0; |
| 2354 | } |
| 2355 | |
| 2356 | /** |
| 2357 | * For {@link #ACTION_DOWN} events, indicates that the event has been |
| 2358 | * canceled as per {@link #FLAG_LONG_PRESS}. |
| 2359 | */ |
| 2360 | public final boolean isLongPress() { |
| 2361 | return (mFlags&FLAG_LONG_PRESS) != 0; |
| 2362 | } |
| 2363 | |
| 2364 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2365 | * Retrieve the key code of the key event. This is the physical key that |
| 2366 | * was pressed, <em>not</em> the Unicode character. |
| 2367 | * |
| 2368 | * @return The key code of the event. |
| 2369 | */ |
| 2370 | public final int getKeyCode() { |
| 2371 | return mKeyCode; |
| 2372 | } |
| 2373 | |
| 2374 | /** |
| 2375 | * For the special case of a {@link #ACTION_MULTIPLE} event with key |
| 2376 | * code of {@link #KEYCODE_UNKNOWN}, this is a raw string of characters |
| 2377 | * associated with the event. In all other cases it is null. |
| 2378 | * |
| 2379 | * @return Returns a String of 1 or more characters associated with |
| 2380 | * the event. |
| 2381 | */ |
| 2382 | public final String getCharacters() { |
| 2383 | return mCharacters; |
| 2384 | } |
| 2385 | |
| 2386 | /** |
| 2387 | * Retrieve the hardware key id of this key event. These values are not |
| 2388 | * reliable and vary from device to device. |
| 2389 | * |
| 2390 | * {@more} |
| 2391 | * Mostly this is here for debugging purposes. |
| 2392 | */ |
| 2393 | public final int getScanCode() { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2394 | return mScanCode; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2395 | } |
| 2396 | |
| 2397 | /** |
| 2398 | * Retrieve the repeat count of the event. For both key up and key down |
| 2399 | * events, this is the number of times the key has repeated with the first |
| 2400 | * down starting at 0 and counting up from there. For multiple key |
| 2401 | * events, this is the number of down/up pairs that have occurred. |
| 2402 | * |
| 2403 | * @return The number of times the key has repeated. |
| 2404 | */ |
| 2405 | public final int getRepeatCount() { |
| 2406 | return mRepeatCount; |
| 2407 | } |
| 2408 | |
| 2409 | /** |
| 2410 | * Retrieve the time of the most recent key down event, |
| 2411 | * in the {@link android.os.SystemClock#uptimeMillis} time base. If this |
| 2412 | * is a down event, this will be the same as {@link #getEventTime()}. |
| 2413 | * Note that when chording keys, this value is the down time of the |
| 2414 | * most recently pressed key, which may <em>not</em> be the same physical |
| 2415 | * key of this event. |
| 2416 | * |
| 2417 | * @return Returns the most recent key down time, in the |
| 2418 | * {@link android.os.SystemClock#uptimeMillis} time base |
| 2419 | */ |
| 2420 | public final long getDownTime() { |
| 2421 | return mDownTime; |
| 2422 | } |
| 2423 | |
| 2424 | /** |
Jeff Brown | b11499d | 2012-04-20 19:54:22 -0700 | [diff] [blame] | 2425 | * Retrieve the time this event occurred, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2426 | * in the {@link android.os.SystemClock#uptimeMillis} time base. |
Jeff Brown | b11499d | 2012-04-20 19:54:22 -0700 | [diff] [blame] | 2427 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2428 | * @return Returns the time this event occurred, |
| 2429 | * in the {@link android.os.SystemClock#uptimeMillis} time base. |
| 2430 | */ |
Jeff Brown | b11499d | 2012-04-20 19:54:22 -0700 | [diff] [blame] | 2431 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2432 | public final long getEventTime() { |
| 2433 | return mEventTime; |
| 2434 | } |
| 2435 | |
Jeff Brown | b11499d | 2012-04-20 19:54:22 -0700 | [diff] [blame] | 2436 | /** |
| 2437 | * Retrieve the time this event occurred, |
| 2438 | * in the {@link android.os.SystemClock#uptimeMillis} time base but with |
| 2439 | * nanosecond (instead of millisecond) precision. |
| 2440 | * <p> |
| 2441 | * The value is in nanosecond precision but it may not have nanosecond accuracy. |
| 2442 | * </p> |
| 2443 | * |
| 2444 | * @return Returns the time this event occurred, |
| 2445 | * in the {@link android.os.SystemClock#uptimeMillis} time base but with |
| 2446 | * nanosecond (instead of millisecond) precision. |
| 2447 | * |
| 2448 | * @hide |
| 2449 | */ |
Jeff Brown | 4e91a18 | 2011-04-07 11:38:09 -0700 | [diff] [blame] | 2450 | @Override |
| 2451 | public final long getEventTimeNano() { |
| 2452 | return mEventTime * 1000000L; |
| 2453 | } |
| 2454 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2455 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2456 | * Renamed to {@link #getDeviceId}. |
| 2457 | * |
| 2458 | * @hide |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 2459 | * @deprecated use {@link #getDeviceId()} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2460 | */ |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 2461 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2462 | public final int getKeyboardDevice() { |
| 2463 | return mDeviceId; |
| 2464 | } |
| 2465 | |
| 2466 | /** |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 2467 | * Gets the {@link KeyCharacterMap} associated with the keyboard device. |
| 2468 | * |
| 2469 | * @return The associated key character map. |
Andrew Sapperstein | 8ab3dc7 | 2011-06-23 18:56:44 -0700 | [diff] [blame] | 2470 | * @throws {@link KeyCharacterMap.UnavailableException} if the key character map |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 2471 | * could not be loaded because it was malformed or the default key character map |
| 2472 | * is missing from the system. |
| 2473 | * |
Andrew Sapperstein | 8ab3dc7 | 2011-06-23 18:56:44 -0700 | [diff] [blame] | 2474 | * @see KeyCharacterMap#load |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 2475 | */ |
| 2476 | public final KeyCharacterMap getKeyCharacterMap() { |
| 2477 | return KeyCharacterMap.load(mDeviceId); |
| 2478 | } |
| 2479 | |
| 2480 | /** |
| 2481 | * Gets the primary character for this key. |
| 2482 | * In other words, the label that is physically printed on it. |
| 2483 | * |
| 2484 | * @return The display label character, or 0 if none (eg. for non-printing keys). |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2485 | */ |
| 2486 | public char getDisplayLabel() { |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 2487 | return getKeyCharacterMap().getDisplayLabel(mKeyCode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2488 | } |
| 2489 | |
| 2490 | /** |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 2491 | * Gets the Unicode character generated by the specified key and meta |
| 2492 | * key state combination. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2493 | * <p> |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 2494 | * Returns the Unicode character that the specified key would produce |
| 2495 | * when the specified meta bits (see {@link MetaKeyKeyListener}) |
| 2496 | * were active. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2497 | * </p><p> |
| 2498 | * Returns 0 if the key is not one that is used to type Unicode |
| 2499 | * characters. |
| 2500 | * </p><p> |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 2501 | * If the return value has bit {@link KeyCharacterMap#COMBINING_ACCENT} set, the |
| 2502 | * key is a "dead key" that should be combined with another to |
| 2503 | * actually produce a character -- see {@link KeyCharacterMap#getDeadChar} -- |
| 2504 | * after masking with {@link KeyCharacterMap#COMBINING_ACCENT_MASK}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2505 | * </p> |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 2506 | * |
| 2507 | * @return The associated character or combining accent, or 0 if none. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2508 | */ |
| 2509 | public int getUnicodeChar() { |
| 2510 | return getUnicodeChar(mMetaState); |
| 2511 | } |
| 2512 | |
| 2513 | /** |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 2514 | * Gets the Unicode character generated by the specified key and meta |
| 2515 | * key state combination. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2516 | * <p> |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 2517 | * Returns the Unicode character that the specified key would produce |
| 2518 | * when the specified meta bits (see {@link MetaKeyKeyListener}) |
| 2519 | * were active. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2520 | * </p><p> |
| 2521 | * Returns 0 if the key is not one that is used to type Unicode |
| 2522 | * characters. |
| 2523 | * </p><p> |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 2524 | * If the return value has bit {@link KeyCharacterMap#COMBINING_ACCENT} set, the |
| 2525 | * key is a "dead key" that should be combined with another to |
| 2526 | * actually produce a character -- see {@link KeyCharacterMap#getDeadChar} -- |
| 2527 | * after masking with {@link KeyCharacterMap#COMBINING_ACCENT_MASK}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2528 | * </p> |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 2529 | * |
| 2530 | * @param metaState The meta key modifier state. |
| 2531 | * @return The associated character or combining accent, or 0 if none. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2532 | */ |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 2533 | public int getUnicodeChar(int metaState) { |
| 2534 | return getKeyCharacterMap().get(mKeyCode, metaState); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2535 | } |
| 2536 | |
| 2537 | /** |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 2538 | * Get the character conversion data for a given key code. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2539 | * |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 2540 | * @param results A {@link KeyCharacterMap.KeyData} instance that will be |
| 2541 | * filled with the results. |
| 2542 | * @return True if the key was mapped. If the key was not mapped, results is not modified. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2543 | * |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 2544 | * @deprecated instead use {@link #getDisplayLabel()}, |
| 2545 | * {@link #getNumber()} or {@link #getUnicodeChar(int)}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2546 | */ |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 2547 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2548 | public boolean getKeyData(KeyData results) { |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 2549 | return getKeyCharacterMap().getKeyData(mKeyCode, results); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2550 | } |
| 2551 | |
| 2552 | /** |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 2553 | * Gets the first character in the character array that can be generated |
| 2554 | * by the specified key code. |
| 2555 | * <p> |
| 2556 | * This is a convenience function that returns the same value as |
| 2557 | * {@link #getMatch(char[],int) getMatch(chars, 0)}. |
| 2558 | * </p> |
| 2559 | * |
| 2560 | * @param chars The array of matching characters to consider. |
| 2561 | * @return The matching associated character, or 0 if none. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2562 | */ |
| 2563 | public char getMatch(char[] chars) { |
| 2564 | return getMatch(chars, 0); |
| 2565 | } |
| 2566 | |
| 2567 | /** |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 2568 | * Gets the first character in the character array that can be generated |
| 2569 | * by the specified key code. If there are multiple choices, prefers |
| 2570 | * the one that would be generated with the specified meta key modifier state. |
| 2571 | * |
| 2572 | * @param chars The array of matching characters to consider. |
| 2573 | * @param metaState The preferred meta key modifier state. |
| 2574 | * @return The matching associated character, or 0 if none. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2575 | */ |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 2576 | public char getMatch(char[] chars, int metaState) { |
| 2577 | return getKeyCharacterMap().getMatch(mKeyCode, chars, metaState); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2578 | } |
| 2579 | |
| 2580 | /** |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 2581 | * Gets the number or symbol associated with the key. |
| 2582 | * <p> |
| 2583 | * The character value is returned, not the numeric value. |
| 2584 | * If the key is not a number, but is a symbol, the symbol is retuned. |
| 2585 | * </p><p> |
| 2586 | * This method is intended to to support dial pads and other numeric or |
| 2587 | * symbolic entry on keyboards where certain keys serve dual function |
| 2588 | * as alphabetic and symbolic keys. This method returns the number |
| 2589 | * or symbol associated with the key independent of whether the user |
| 2590 | * has pressed the required modifier. |
| 2591 | * </p><p> |
| 2592 | * For example, on one particular keyboard the keys on the top QWERTY row generate |
| 2593 | * numbers when ALT is pressed such that ALT-Q maps to '1'. So for that keyboard |
| 2594 | * when {@link #getNumber} is called with {@link KeyEvent#KEYCODE_Q} it returns '1' |
| 2595 | * so that the user can type numbers without pressing ALT when it makes sense. |
| 2596 | * </p> |
| 2597 | * |
| 2598 | * @return The associated numeric or symbolic character, or 0 if none. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2599 | */ |
| 2600 | public char getNumber() { |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 2601 | return getKeyCharacterMap().getNumber(mKeyCode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2602 | } |
| 2603 | |
| 2604 | /** |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 2605 | * Returns true if this key produces a glyph. |
| 2606 | * |
| 2607 | * @return True if the key is a printing key. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2608 | */ |
| 2609 | public boolean isPrintingKey() { |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 2610 | return getKeyCharacterMap().isPrintingKey(mKeyCode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2611 | } |
| 2612 | |
| 2613 | /** |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 2614 | * @deprecated Use {@link #dispatch(Callback, DispatcherState, Object)} instead. |
| 2615 | */ |
| 2616 | @Deprecated |
| 2617 | public final boolean dispatch(Callback receiver) { |
| 2618 | return dispatch(receiver, null, null); |
| 2619 | } |
| 2620 | |
| 2621 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2622 | * Deliver this key event to a {@link Callback} interface. If this is |
| 2623 | * an ACTION_MULTIPLE event and it is not handled, then an attempt will |
| 2624 | * be made to deliver a single normal event. |
| 2625 | * |
| 2626 | * @param receiver The Callback that will be given the event. |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 2627 | * @param state State information retained across events. |
| 2628 | * @param target The target of the dispatch, for use in tracking. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2629 | * |
| 2630 | * @return The return value from the Callback method that was called. |
| 2631 | */ |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 2632 | public final boolean dispatch(Callback receiver, DispatcherState state, |
| 2633 | Object target) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2634 | switch (mAction) { |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 2635 | case ACTION_DOWN: { |
| 2636 | mFlags &= ~FLAG_START_TRACKING; |
Dianne Hackborn | 8d37426 | 2009-09-14 21:21:52 -0700 | [diff] [blame] | 2637 | if (DEBUG) Log.v(TAG, "Key down to " + target + " in " + state |
| 2638 | + ": " + this); |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 2639 | boolean res = receiver.onKeyDown(mKeyCode, this); |
| 2640 | if (state != null) { |
| 2641 | if (res && mRepeatCount == 0 && (mFlags&FLAG_START_TRACKING) != 0) { |
Dianne Hackborn | 8d37426 | 2009-09-14 21:21:52 -0700 | [diff] [blame] | 2642 | if (DEBUG) Log.v(TAG, " Start tracking!"); |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 2643 | state.startTracking(this, target); |
| 2644 | } else if (isLongPress() && state.isTracking(this)) { |
| 2645 | try { |
| 2646 | if (receiver.onKeyLongPress(mKeyCode, this)) { |
Dianne Hackborn | 8d37426 | 2009-09-14 21:21:52 -0700 | [diff] [blame] | 2647 | if (DEBUG) Log.v(TAG, " Clear from long press!"); |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 2648 | state.performedLongPress(this); |
| 2649 | res = true; |
| 2650 | } |
| 2651 | } catch (AbstractMethodError e) { |
| 2652 | } |
| 2653 | } |
| 2654 | } |
| 2655 | return res; |
| 2656 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2657 | case ACTION_UP: |
Dianne Hackborn | 8d37426 | 2009-09-14 21:21:52 -0700 | [diff] [blame] | 2658 | if (DEBUG) Log.v(TAG, "Key up to " + target + " in " + state |
| 2659 | + ": " + this); |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 2660 | if (state != null) { |
| 2661 | state.handleUpEvent(this); |
| 2662 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2663 | return receiver.onKeyUp(mKeyCode, this); |
| 2664 | case ACTION_MULTIPLE: |
| 2665 | final int count = mRepeatCount; |
| 2666 | final int code = mKeyCode; |
| 2667 | if (receiver.onKeyMultiple(code, count, this)) { |
| 2668 | return true; |
| 2669 | } |
| 2670 | if (code != KeyEvent.KEYCODE_UNKNOWN) { |
| 2671 | mAction = ACTION_DOWN; |
| 2672 | mRepeatCount = 0; |
| 2673 | boolean handled = receiver.onKeyDown(code, this); |
| 2674 | if (handled) { |
| 2675 | mAction = ACTION_UP; |
| 2676 | receiver.onKeyUp(code, this); |
| 2677 | } |
| 2678 | mAction = ACTION_MULTIPLE; |
| 2679 | mRepeatCount = count; |
| 2680 | return handled; |
| 2681 | } |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 2682 | return false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2683 | } |
| 2684 | return false; |
| 2685 | } |
| 2686 | |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 2687 | /** |
| 2688 | * Use with {@link KeyEvent#dispatch(Callback, DispatcherState, Object)} |
| 2689 | * for more advanced key dispatching, such as long presses. |
| 2690 | */ |
| 2691 | public static class DispatcherState { |
| 2692 | int mDownKeyCode; |
| 2693 | Object mDownTarget; |
| 2694 | SparseIntArray mActiveLongPresses = new SparseIntArray(); |
| 2695 | |
| 2696 | /** |
| 2697 | * Reset back to initial state. |
| 2698 | */ |
| 2699 | public void reset() { |
Dianne Hackborn | 8d37426 | 2009-09-14 21:21:52 -0700 | [diff] [blame] | 2700 | if (DEBUG) Log.v(TAG, "Reset: " + this); |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 2701 | mDownKeyCode = 0; |
| 2702 | mDownTarget = null; |
| 2703 | mActiveLongPresses.clear(); |
| 2704 | } |
| 2705 | |
| 2706 | /** |
| 2707 | * Stop any tracking associated with this target. |
| 2708 | */ |
| 2709 | public void reset(Object target) { |
| 2710 | if (mDownTarget == target) { |
Dianne Hackborn | 8d37426 | 2009-09-14 21:21:52 -0700 | [diff] [blame] | 2711 | if (DEBUG) Log.v(TAG, "Reset in " + target + ": " + this); |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 2712 | mDownKeyCode = 0; |
| 2713 | mDownTarget = null; |
| 2714 | } |
| 2715 | } |
| 2716 | |
| 2717 | /** |
| 2718 | * Start tracking the key code associated with the given event. This |
| 2719 | * can only be called on a key down. It will allow you to see any |
| 2720 | * long press associated with the key, and will result in |
| 2721 | * {@link KeyEvent#isTracking} return true on the long press and up |
| 2722 | * events. |
| 2723 | * |
| 2724 | * <p>This is only needed if you are directly dispatching events, rather |
| 2725 | * than handling them in {@link Callback#onKeyDown}. |
| 2726 | */ |
| 2727 | public void startTracking(KeyEvent event, Object target) { |
| 2728 | if (event.getAction() != ACTION_DOWN) { |
| 2729 | throw new IllegalArgumentException( |
| 2730 | "Can only start tracking on a down event"); |
| 2731 | } |
Dianne Hackborn | 8d37426 | 2009-09-14 21:21:52 -0700 | [diff] [blame] | 2732 | if (DEBUG) Log.v(TAG, "Start trackingt in " + target + ": " + this); |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 2733 | mDownKeyCode = event.getKeyCode(); |
| 2734 | mDownTarget = target; |
| 2735 | } |
| 2736 | |
| 2737 | /** |
| 2738 | * Return true if the key event is for a key code that is currently |
| 2739 | * being tracked by the dispatcher. |
| 2740 | */ |
| 2741 | public boolean isTracking(KeyEvent event) { |
| 2742 | return mDownKeyCode == event.getKeyCode(); |
| 2743 | } |
| 2744 | |
| 2745 | /** |
| 2746 | * Keep track of the given event's key code as having performed an |
| 2747 | * action with a long press, so no action should occur on the up. |
| 2748 | * <p>This is only needed if you are directly dispatching events, rather |
| 2749 | * than handling them in {@link Callback#onKeyLongPress}. |
| 2750 | */ |
| 2751 | public void performedLongPress(KeyEvent event) { |
| 2752 | mActiveLongPresses.put(event.getKeyCode(), 1); |
| 2753 | } |
| 2754 | |
| 2755 | /** |
| 2756 | * Handle key up event to stop tracking. This resets the dispatcher state, |
| 2757 | * and updates the key event state based on it. |
| 2758 | * <p>This is only needed if you are directly dispatching events, rather |
| 2759 | * than handling them in {@link Callback#onKeyUp}. |
| 2760 | */ |
| 2761 | public void handleUpEvent(KeyEvent event) { |
| 2762 | final int keyCode = event.getKeyCode(); |
Dianne Hackborn | 8d37426 | 2009-09-14 21:21:52 -0700 | [diff] [blame] | 2763 | if (DEBUG) Log.v(TAG, "Handle key up " + event + ": " + this); |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 2764 | int index = mActiveLongPresses.indexOfKey(keyCode); |
| 2765 | if (index >= 0) { |
Dianne Hackborn | 8d37426 | 2009-09-14 21:21:52 -0700 | [diff] [blame] | 2766 | if (DEBUG) Log.v(TAG, " Index: " + index); |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 2767 | event.mFlags |= FLAG_CANCELED | FLAG_CANCELED_LONG_PRESS; |
| 2768 | mActiveLongPresses.removeAt(index); |
| 2769 | } |
| 2770 | if (mDownKeyCode == keyCode) { |
Dianne Hackborn | 8d37426 | 2009-09-14 21:21:52 -0700 | [diff] [blame] | 2771 | if (DEBUG) Log.v(TAG, " Tracking!"); |
Dianne Hackborn | 83fe3f5 | 2009-09-12 23:38:30 -0700 | [diff] [blame] | 2772 | event.mFlags |= FLAG_TRACKING; |
| 2773 | mDownKeyCode = 0; |
| 2774 | mDownTarget = null; |
| 2775 | } |
| 2776 | } |
| 2777 | } |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2778 | |
| 2779 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2780 | public String toString() { |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 2781 | StringBuilder msg = new StringBuilder(); |
| 2782 | msg.append("KeyEvent { action=").append(actionToString(mAction)); |
| 2783 | msg.append(", keyCode=").append(keyCodeToString(mKeyCode)); |
| 2784 | msg.append(", scanCode=").append(mScanCode); |
| 2785 | if (mCharacters != null) { |
| 2786 | msg.append(", characters=\"").append(mCharacters).append("\""); |
| 2787 | } |
| 2788 | msg.append(", metaState=").append(metaStateToString(mMetaState)); |
| 2789 | msg.append(", flags=0x").append(Integer.toHexString(mFlags)); |
| 2790 | msg.append(", repeatCount=").append(mRepeatCount); |
| 2791 | msg.append(", eventTime=").append(mEventTime); |
| 2792 | msg.append(", downTime=").append(mDownTime); |
| 2793 | msg.append(", deviceId=").append(mDeviceId); |
| 2794 | msg.append(", source=0x").append(Integer.toHexString(mSource)); |
| 2795 | msg.append(" }"); |
| 2796 | return msg.toString(); |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2797 | } |
| 2798 | |
| 2799 | /** |
| 2800 | * Returns a string that represents the symbolic name of the specified action |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 2801 | * such as "ACTION_DOWN", or an equivalent numeric constant such as "35" if unknown. |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2802 | * |
| 2803 | * @param action The action. |
| 2804 | * @return The symbolic name of the specified action. |
| 2805 | * @hide |
| 2806 | */ |
| 2807 | public static String actionToString(int action) { |
| 2808 | switch (action) { |
| 2809 | case ACTION_DOWN: |
| 2810 | return "ACTION_DOWN"; |
| 2811 | case ACTION_UP: |
| 2812 | return "ACTION_UP"; |
| 2813 | case ACTION_MULTIPLE: |
| 2814 | return "ACTION_MULTIPLE"; |
| 2815 | default: |
| 2816 | return Integer.toString(action); |
| 2817 | } |
| 2818 | } |
| 2819 | |
| 2820 | /** |
| 2821 | * Returns a string that represents the symbolic name of the specified keycode |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 2822 | * such as "KEYCODE_A", "KEYCODE_DPAD_UP", or an equivalent numeric constant |
| 2823 | * such as "1001" if unknown. |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2824 | * |
| 2825 | * @param keyCode The key code. |
| 2826 | * @return The symbolic name of the specified keycode. |
| 2827 | * |
| 2828 | * @see KeyCharacterMap#getDisplayLabel |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2829 | */ |
| 2830 | public static String keyCodeToString(int keyCode) { |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 2831 | String symbolicName = KEYCODE_SYMBOLIC_NAMES.get(keyCode); |
| 2832 | return symbolicName != null ? symbolicName : Integer.toString(keyCode); |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2833 | } |
| 2834 | |
| 2835 | /** |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 2836 | * Gets a keycode by its symbolic name such as "KEYCODE_A" or an equivalent |
| 2837 | * numeric constant such as "1001". |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2838 | * |
| 2839 | * @param symbolicName The symbolic name of the keycode. |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 2840 | * @return The keycode or {@link #KEYCODE_UNKNOWN} if not found. |
Michael Wright | 072137c | 2013-04-24 20:41:20 -0700 | [diff] [blame] | 2841 | * @see #keycodeToString(int) |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2842 | */ |
| 2843 | public static int keyCodeFromString(String symbolicName) { |
| 2844 | if (symbolicName == null) { |
| 2845 | throw new IllegalArgumentException("symbolicName must not be null"); |
| 2846 | } |
| 2847 | |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 2848 | final int count = KEYCODE_SYMBOLIC_NAMES.size(); |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2849 | for (int i = 0; i < count; i++) { |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 2850 | if (symbolicName.equals(KEYCODE_SYMBOLIC_NAMES.valueAt(i))) { |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2851 | return i; |
| 2852 | } |
| 2853 | } |
| 2854 | |
| 2855 | try { |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 2856 | return Integer.parseInt(symbolicName, 10); |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2857 | } catch (NumberFormatException ex) { |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 2858 | return KEYCODE_UNKNOWN; |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2859 | } |
| 2860 | } |
| 2861 | |
| 2862 | /** |
| 2863 | * Returns a string that represents the symbolic name of the specified combined meta |
| 2864 | * key modifier state flags such as "0", "META_SHIFT_ON", |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 2865 | * "META_ALT_ON|META_SHIFT_ON" or an equivalent numeric constant such as "0x10000000" |
| 2866 | * if unknown. |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2867 | * |
| 2868 | * @param metaState The meta state. |
| 2869 | * @return The symbolic name of the specified combined meta state flags. |
| 2870 | * @hide |
| 2871 | */ |
| 2872 | public static String metaStateToString(int metaState) { |
| 2873 | if (metaState == 0) { |
| 2874 | return "0"; |
| 2875 | } |
| 2876 | StringBuilder result = null; |
| 2877 | int i = 0; |
| 2878 | while (metaState != 0) { |
| 2879 | final boolean isSet = (metaState & 1) != 0; |
| 2880 | metaState >>>= 1; // unsigned shift! |
| 2881 | if (isSet) { |
| 2882 | final String name = META_SYMBOLIC_NAMES[i]; |
| 2883 | if (result == null) { |
| 2884 | if (metaState == 0) { |
| 2885 | return name; |
| 2886 | } |
| 2887 | result = new StringBuilder(name); |
| 2888 | } else { |
| 2889 | result.append('|'); |
| 2890 | result.append(name); |
| 2891 | } |
| 2892 | } |
| 2893 | i += 1; |
| 2894 | } |
| 2895 | return result.toString(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2896 | } |
| 2897 | |
| 2898 | public static final Parcelable.Creator<KeyEvent> CREATOR |
| 2899 | = new Parcelable.Creator<KeyEvent>() { |
| 2900 | public KeyEvent createFromParcel(Parcel in) { |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 2901 | in.readInt(); // skip token, we already know this is a KeyEvent |
| 2902 | return KeyEvent.createFromParcelBody(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2903 | } |
| 2904 | |
| 2905 | public KeyEvent[] newArray(int size) { |
| 2906 | return new KeyEvent[size]; |
| 2907 | } |
| 2908 | }; |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 2909 | |
| 2910 | /** @hide */ |
| 2911 | public static KeyEvent createFromParcelBody(Parcel in) { |
| 2912 | return new KeyEvent(in); |
| 2913 | } |
| 2914 | |
| 2915 | private KeyEvent(Parcel in) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2916 | mDeviceId = in.readInt(); |
| 2917 | mSource = in.readInt(); |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 2918 | mAction = in.readInt(); |
| 2919 | mKeyCode = in.readInt(); |
| 2920 | mRepeatCount = in.readInt(); |
| 2921 | mMetaState = in.readInt(); |
| 2922 | mScanCode = in.readInt(); |
| 2923 | mFlags = in.readInt(); |
| 2924 | mDownTime = in.readLong(); |
| 2925 | mEventTime = in.readLong(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2926 | } |
| 2927 | |
| 2928 | public void writeToParcel(Parcel out, int flags) { |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 2929 | out.writeInt(PARCEL_TOKEN_KEY_EVENT); |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2930 | |
| 2931 | out.writeInt(mDeviceId); |
| 2932 | out.writeInt(mSource); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2933 | out.writeInt(mAction); |
| 2934 | out.writeInt(mKeyCode); |
| 2935 | out.writeInt(mRepeatCount); |
| 2936 | out.writeInt(mMetaState); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2937 | out.writeInt(mScanCode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2938 | out.writeInt(mFlags); |
| 2939 | out.writeLong(mDownTime); |
| 2940 | out.writeLong(mEventTime); |
| 2941 | } |
| 2942 | |
Dianne Hackborn | 3c80a4a | 2010-06-29 19:20:40 -0700 | [diff] [blame] | 2943 | private native boolean native_isSystemKey(int keyCode); |
| 2944 | private native boolean native_hasDefaultAction(int keyCode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2945 | } |