Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 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 | |
Jeff Brown | a47425a | 2012-04-13 04:09:27 -0700 | [diff] [blame] | 19 | import android.content.Context; |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 20 | import android.hardware.input.InputManager; |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 21 | import android.os.Parcel; |
| 22 | import android.os.Parcelable; |
Jeff Brown | a47425a | 2012-04-13 04:09:27 -0700 | [diff] [blame] | 23 | import android.os.Vibrator; |
| 24 | import android.os.NullVibrator; |
Jeff Brown | efd3266 | 2011-03-08 15:13:06 -0800 | [diff] [blame] | 25 | |
| 26 | import java.util.ArrayList; |
| 27 | import java.util.List; |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 28 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 29 | /** |
| 30 | * Describes the capabilities of a particular input device. |
| 31 | * <p> |
Jeff Brown | 9df6e7a | 2012-04-05 11:49:26 -0700 | [diff] [blame] | 32 | * Each input device may support multiple classes of input. For example, a multi-function |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 33 | * keyboard may compose the capabilities of a standard keyboard together with a track pad mouse |
| 34 | * or other pointing device. |
| 35 | * </p><p> |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 36 | * Some input devices present multiple distinguishable sources of input. |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 37 | * Applications can query the framework about the characteristics of each distinct source. |
| 38 | * </p><p> |
| 39 | * As a further wrinkle, different kinds of input sources uses different coordinate systems |
| 40 | * to describe motion events. Refer to the comments on the input source constants for |
| 41 | * the appropriate interpretation. |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 42 | * </p> |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 43 | */ |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 44 | public final class InputDevice implements Parcelable { |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 45 | private final int mId; |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 46 | private final int mGeneration; |
Michael Wright | ac6c78b | 2013-07-17 13:21:45 -0700 | [diff] [blame] | 47 | private final int mControllerNumber; |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 48 | private final String mName; |
Michael Wright | 54e5694 | 2013-08-12 16:39:59 -0700 | [diff] [blame] | 49 | private final int mVendorId; |
| 50 | private final int mProductId; |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 51 | private final String mDescriptor; |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 52 | private final boolean mIsExternal; |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 53 | private final int mSources; |
| 54 | private final int mKeyboardType; |
| 55 | private final KeyCharacterMap mKeyCharacterMap; |
Jeff Brown | a47425a | 2012-04-13 04:09:27 -0700 | [diff] [blame] | 56 | private final boolean mHasVibrator; |
Michael Wright | 7ddd110 | 2013-05-20 15:04:55 -0700 | [diff] [blame] | 57 | private final boolean mHasButtonUnderPad; |
Jeff Brown | efd3266 | 2011-03-08 15:13:06 -0800 | [diff] [blame] | 58 | private final ArrayList<MotionRange> mMotionRanges = new ArrayList<MotionRange>(); |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 59 | |
Jeff Brown | a47425a | 2012-04-13 04:09:27 -0700 | [diff] [blame] | 60 | private Vibrator mVibrator; // guarded by mMotionRanges during initialization |
| 61 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 62 | /** |
| 63 | * A mask for input source classes. |
| 64 | * |
| 65 | * Each distinct input source constant has one or more input source class bits set to |
| 66 | * specify the desired interpretation for its input events. |
| 67 | */ |
| 68 | public static final int SOURCE_CLASS_MASK = 0x000000ff; |
Michael Wright | e7a9ae8 | 2013-03-08 15:19:19 -0800 | [diff] [blame] | 69 | |
| 70 | /** |
| 71 | * The input source has no class. |
| 72 | * |
| 73 | * It is up to the application to determine how to handle the device based on the device type. |
| 74 | */ |
| 75 | public static final int SOURCE_CLASS_NONE = 0x00000000; |
| 76 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 77 | /** |
| 78 | * The input source has buttons or keys. |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 79 | * Examples: {@link #SOURCE_KEYBOARD}, {@link #SOURCE_DPAD}. |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 80 | * |
| 81 | * A {@link KeyEvent} should be interpreted as a button or key press. |
| 82 | * |
Jeff Brown | 6eb5ac9 | 2010-08-30 23:29:07 -0700 | [diff] [blame] | 83 | * Use {@link #getKeyCharacterMap} to query the device's button and key mappings. |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 84 | */ |
| 85 | public static final int SOURCE_CLASS_BUTTON = 0x00000001; |
| 86 | |
| 87 | /** |
| 88 | * The input source is a pointing device associated with a display. |
| 89 | * Examples: {@link #SOURCE_TOUCHSCREEN}, {@link #SOURCE_MOUSE}. |
| 90 | * |
| 91 | * A {@link MotionEvent} should be interpreted as absolute coordinates in |
| 92 | * display units according to the {@link View} hierarchy. Pointer down/up indicated when |
| 93 | * the finger touches the display or when the selection button is pressed/released. |
| 94 | * |
| 95 | * Use {@link #getMotionRange} to query the range of the pointing device. Some devices permit |
| 96 | * touches outside the display area so the effective range may be somewhat smaller or larger |
| 97 | * than the actual display size. |
| 98 | */ |
| 99 | public static final int SOURCE_CLASS_POINTER = 0x00000002; |
| 100 | |
| 101 | /** |
| 102 | * The input source is a trackball navigation device. |
| 103 | * Examples: {@link #SOURCE_TRACKBALL}. |
| 104 | * |
| 105 | * A {@link MotionEvent} should be interpreted as relative movements in device-specific |
| 106 | * units used for navigation purposes. Pointer down/up indicates when the selection button |
| 107 | * is pressed/released. |
| 108 | * |
| 109 | * Use {@link #getMotionRange} to query the range of motion. |
| 110 | */ |
| 111 | public static final int SOURCE_CLASS_TRACKBALL = 0x00000004; |
| 112 | |
| 113 | /** |
| 114 | * The input source is an absolute positioning device not associated with a display |
| 115 | * (unlike {@link #SOURCE_CLASS_POINTER}). |
| 116 | * |
| 117 | * A {@link MotionEvent} should be interpreted as absolute coordinates in |
| 118 | * device-specific surface units. |
| 119 | * |
| 120 | * Use {@link #getMotionRange} to query the range of positions. |
| 121 | */ |
| 122 | public static final int SOURCE_CLASS_POSITION = 0x00000008; |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 123 | |
| 124 | /** |
| 125 | * The input source is a joystick. |
| 126 | * |
| 127 | * A {@link MotionEvent} should be interpreted as absolute joystick movements. |
| 128 | * |
| 129 | * Use {@link #getMotionRange} to query the range of positions. |
| 130 | */ |
| 131 | public static final int SOURCE_CLASS_JOYSTICK = 0x00000010; |
| 132 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 133 | /** |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 134 | * The input source is unknown. |
| 135 | */ |
| 136 | public static final int SOURCE_UNKNOWN = 0x00000000; |
| 137 | |
| 138 | /** |
| 139 | * The input source is a keyboard. |
Jeff Brown | 9df6e7a | 2012-04-05 11:49:26 -0700 | [diff] [blame] | 140 | * |
| 141 | * This source indicates pretty much anything that has buttons. Use |
| 142 | * {@link #getKeyboardType()} to determine whether the keyboard has alphabetic keys |
| 143 | * and can be used to enter text. |
| 144 | * |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 145 | * @see #SOURCE_CLASS_BUTTON |
| 146 | */ |
| 147 | public static final int SOURCE_KEYBOARD = 0x00000100 | SOURCE_CLASS_BUTTON; |
| 148 | |
| 149 | /** |
| 150 | * The input source is a DPad. |
| 151 | * |
| 152 | * @see #SOURCE_CLASS_BUTTON |
| 153 | */ |
| 154 | public static final int SOURCE_DPAD = 0x00000200 | SOURCE_CLASS_BUTTON; |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 155 | |
| 156 | /** |
| 157 | * The input source is a game pad. |
| 158 | * (It may also be a {@link #SOURCE_JOYSTICK}). |
| 159 | * |
| 160 | * @see #SOURCE_CLASS_BUTTON |
| 161 | */ |
| 162 | public static final int SOURCE_GAMEPAD = 0x00000400 | SOURCE_CLASS_BUTTON; |
| 163 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 164 | /** |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 165 | * The input source is a touch screen pointing device. |
| 166 | * |
| 167 | * @see #SOURCE_CLASS_POINTER |
| 168 | */ |
| 169 | public static final int SOURCE_TOUCHSCREEN = 0x00001000 | SOURCE_CLASS_POINTER; |
| 170 | |
| 171 | /** |
| 172 | * The input source is a mouse pointing device. |
| 173 | * This code is also used for other mouse-like pointing devices such as trackpads |
| 174 | * and trackpoints. |
| 175 | * |
| 176 | * @see #SOURCE_CLASS_POINTER |
| 177 | */ |
| 178 | public static final int SOURCE_MOUSE = 0x00002000 | SOURCE_CLASS_POINTER; |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 179 | |
| 180 | /** |
| 181 | * The input source is a stylus pointing device. |
Jeff Brown | 00710e9 | 2012-04-19 15:18:26 -0700 | [diff] [blame] | 182 | * <p> |
| 183 | * Note that this bit merely indicates that an input device is capable of obtaining |
| 184 | * input from a stylus. To determine whether a given touch event was produced |
| 185 | * by a stylus, examine the tool type returned by {@link MotionEvent#getToolType(int)} |
| 186 | * for each individual pointer. |
| 187 | * </p><p> |
| 188 | * A single touch event may multiple pointers with different tool types, |
| 189 | * such as an event that has one pointer with tool type |
| 190 | * {@link MotionEvent#TOOL_TYPE_FINGER} and another pointer with tool type |
| 191 | * {@link MotionEvent#TOOL_TYPE_STYLUS}. So it is important to examine |
| 192 | * the tool type of each pointer, regardless of the source reported |
| 193 | * by {@link MotionEvent#getSource()}. |
| 194 | * </p> |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 195 | * |
| 196 | * @see #SOURCE_CLASS_POINTER |
| 197 | */ |
| 198 | public static final int SOURCE_STYLUS = 0x00004000 | SOURCE_CLASS_POINTER; |
| 199 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 200 | /** |
| 201 | * The input source is a trackball. |
| 202 | * |
| 203 | * @see #SOURCE_CLASS_TRACKBALL |
| 204 | */ |
| 205 | public static final int SOURCE_TRACKBALL = 0x00010000 | SOURCE_CLASS_TRACKBALL; |
| 206 | |
| 207 | /** |
| 208 | * The input source is a touch pad or digitizer tablet that is not |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 209 | * associated with a display (unlike {@link #SOURCE_TOUCHSCREEN}). |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 210 | * |
| 211 | * @see #SOURCE_CLASS_POSITION |
| 212 | */ |
| 213 | public static final int SOURCE_TOUCHPAD = 0x00100000 | SOURCE_CLASS_POSITION; |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 214 | |
| 215 | /** |
Michael Wright | e7a9ae8 | 2013-03-08 15:19:19 -0800 | [diff] [blame] | 216 | * The input source is a touch device whose motions should be interpreted as navigation events. |
| 217 | * |
| 218 | * For example, an upward swipe should be as an upward focus traversal in the same manner as |
| 219 | * pressing up on a D-Pad would be. Swipes to the left, right and down should be treated in a |
| 220 | * similar manner. |
| 221 | * |
| 222 | * @see #SOURCE_CLASS_NONE |
| 223 | */ |
| 224 | public static final int SOURCE_TOUCH_NAVIGATION = 0x00200000 | SOURCE_CLASS_NONE; |
| 225 | |
| 226 | /** |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 227 | * The input source is a joystick. |
| 228 | * (It may also be a {@link #SOURCE_GAMEPAD}). |
| 229 | * |
| 230 | * @see #SOURCE_CLASS_JOYSTICK |
| 231 | */ |
| 232 | public static final int SOURCE_JOYSTICK = 0x01000000 | SOURCE_CLASS_JOYSTICK; |
| 233 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 234 | /** |
| 235 | * A special input source constant that is used when filtering input devices |
| 236 | * to match devices that provide any type of input source. |
| 237 | */ |
| 238 | public static final int SOURCE_ANY = 0xffffff00; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 239 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 240 | /** |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 241 | * Constant for retrieving the range of values for {@link MotionEvent#AXIS_X}. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 242 | * |
| 243 | * @see #getMotionRange |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 244 | * @deprecated Use {@link MotionEvent#AXIS_X} instead. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 245 | */ |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 246 | @Deprecated |
| 247 | public static final int MOTION_RANGE_X = MotionEvent.AXIS_X; |
| 248 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 249 | /** |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 250 | * Constant for retrieving the range of values for {@link MotionEvent#AXIS_Y}. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 251 | * |
| 252 | * @see #getMotionRange |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 253 | * @deprecated Use {@link MotionEvent#AXIS_Y} instead. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 254 | */ |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 255 | @Deprecated |
| 256 | public static final int MOTION_RANGE_Y = MotionEvent.AXIS_Y; |
| 257 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 258 | /** |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 259 | * Constant for retrieving the range of values for {@link MotionEvent#AXIS_PRESSURE}. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 260 | * |
| 261 | * @see #getMotionRange |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 262 | * @deprecated Use {@link MotionEvent#AXIS_PRESSURE} instead. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 263 | */ |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 264 | @Deprecated |
| 265 | public static final int MOTION_RANGE_PRESSURE = MotionEvent.AXIS_PRESSURE; |
| 266 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 267 | /** |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 268 | * Constant for retrieving the range of values for {@link MotionEvent#AXIS_SIZE}. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 269 | * |
| 270 | * @see #getMotionRange |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 271 | * @deprecated Use {@link MotionEvent#AXIS_SIZE} instead. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 272 | */ |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 273 | @Deprecated |
| 274 | public static final int MOTION_RANGE_SIZE = MotionEvent.AXIS_SIZE; |
| 275 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 276 | /** |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 277 | * Constant for retrieving the range of values for {@link MotionEvent#AXIS_TOUCH_MAJOR}. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 278 | * |
| 279 | * @see #getMotionRange |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 280 | * @deprecated Use {@link MotionEvent#AXIS_TOUCH_MAJOR} instead. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 281 | */ |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 282 | @Deprecated |
| 283 | public static final int MOTION_RANGE_TOUCH_MAJOR = MotionEvent.AXIS_TOUCH_MAJOR; |
| 284 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 285 | /** |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 286 | * Constant for retrieving the range of values for {@link MotionEvent#AXIS_TOUCH_MINOR}. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 287 | * |
| 288 | * @see #getMotionRange |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 289 | * @deprecated Use {@link MotionEvent#AXIS_TOUCH_MINOR} instead. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 290 | */ |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 291 | @Deprecated |
| 292 | public static final int MOTION_RANGE_TOUCH_MINOR = MotionEvent.AXIS_TOUCH_MINOR; |
| 293 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 294 | /** |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 295 | * Constant for retrieving the range of values for {@link MotionEvent#AXIS_TOOL_MAJOR}. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 296 | * |
| 297 | * @see #getMotionRange |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 298 | * @deprecated Use {@link MotionEvent#AXIS_TOOL_MAJOR} instead. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 299 | */ |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 300 | @Deprecated |
| 301 | public static final int MOTION_RANGE_TOOL_MAJOR = MotionEvent.AXIS_TOOL_MAJOR; |
| 302 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 303 | /** |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 304 | * Constant for retrieving the range of values for {@link MotionEvent#AXIS_TOOL_MINOR}. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 305 | * |
| 306 | * @see #getMotionRange |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 307 | * @deprecated Use {@link MotionEvent#AXIS_TOOL_MINOR} instead. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 308 | */ |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 309 | @Deprecated |
| 310 | public static final int MOTION_RANGE_TOOL_MINOR = MotionEvent.AXIS_TOOL_MINOR; |
| 311 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 312 | /** |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 313 | * Constant for retrieving the range of values for {@link MotionEvent#AXIS_ORIENTATION}. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 314 | * |
| 315 | * @see #getMotionRange |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 316 | * @deprecated Use {@link MotionEvent#AXIS_ORIENTATION} instead. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 317 | */ |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 318 | @Deprecated |
| 319 | public static final int MOTION_RANGE_ORIENTATION = MotionEvent.AXIS_ORIENTATION; |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 320 | |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 321 | /** |
| 322 | * There is no keyboard. |
| 323 | */ |
| 324 | public static final int KEYBOARD_TYPE_NONE = 0; |
| 325 | |
| 326 | /** |
| 327 | * The keyboard is not fully alphabetic. It may be a numeric keypad or an assortment |
| 328 | * of buttons that are not mapped as alphabetic keys suitable for text input. |
| 329 | */ |
| 330 | public static final int KEYBOARD_TYPE_NON_ALPHABETIC = 1; |
| 331 | |
| 332 | /** |
| 333 | * The keyboard supports a complement of alphabetic keys. |
| 334 | */ |
| 335 | public static final int KEYBOARD_TYPE_ALPHABETIC = 2; |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 336 | |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 337 | public static final Parcelable.Creator<InputDevice> CREATOR = |
| 338 | new Parcelable.Creator<InputDevice>() { |
| 339 | public InputDevice createFromParcel(Parcel in) { |
| 340 | return new InputDevice(in); |
| 341 | } |
| 342 | public InputDevice[] newArray(int size) { |
| 343 | return new InputDevice[size]; |
| 344 | } |
| 345 | }; |
| 346 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 347 | // Called by native code. |
Michael Wright | 54e5694 | 2013-08-12 16:39:59 -0700 | [diff] [blame] | 348 | private InputDevice(int id, int generation, int controllerNumber, String name, int vendorId, |
| 349 | int productId, String descriptor, boolean isExternal, int sources, int keyboardType, |
Michael Wright | ac6c78b | 2013-07-17 13:21:45 -0700 | [diff] [blame] | 350 | KeyCharacterMap keyCharacterMap, boolean hasVibrator, boolean hasButtonUnderPad) { |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 351 | mId = id; |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 352 | mGeneration = generation; |
Michael Wright | ac6c78b | 2013-07-17 13:21:45 -0700 | [diff] [blame] | 353 | mControllerNumber = controllerNumber; |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 354 | mName = name; |
Michael Wright | 54e5694 | 2013-08-12 16:39:59 -0700 | [diff] [blame] | 355 | mVendorId = vendorId; |
| 356 | mProductId = productId; |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 357 | mDescriptor = descriptor; |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 358 | mIsExternal = isExternal; |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 359 | mSources = sources; |
| 360 | mKeyboardType = keyboardType; |
| 361 | mKeyCharacterMap = keyCharacterMap; |
Jeff Brown | a47425a | 2012-04-13 04:09:27 -0700 | [diff] [blame] | 362 | mHasVibrator = hasVibrator; |
Michael Wright | 7ddd110 | 2013-05-20 15:04:55 -0700 | [diff] [blame] | 363 | mHasButtonUnderPad = hasButtonUnderPad; |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | private InputDevice(Parcel in) { |
| 367 | mId = in.readInt(); |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 368 | mGeneration = in.readInt(); |
Michael Wright | ac6c78b | 2013-07-17 13:21:45 -0700 | [diff] [blame] | 369 | mControllerNumber = in.readInt(); |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 370 | mName = in.readString(); |
Michael Wright | 54e5694 | 2013-08-12 16:39:59 -0700 | [diff] [blame] | 371 | mVendorId = in.readInt(); |
| 372 | mProductId = in.readInt(); |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 373 | mDescriptor = in.readString(); |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 374 | mIsExternal = in.readInt() != 0; |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 375 | mSources = in.readInt(); |
| 376 | mKeyboardType = in.readInt(); |
| 377 | mKeyCharacterMap = KeyCharacterMap.CREATOR.createFromParcel(in); |
Jeff Brown | a47425a | 2012-04-13 04:09:27 -0700 | [diff] [blame] | 378 | mHasVibrator = in.readInt() != 0; |
Michael Wright | 7ddd110 | 2013-05-20 15:04:55 -0700 | [diff] [blame] | 379 | mHasButtonUnderPad = in.readInt() != 0; |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 380 | |
| 381 | for (;;) { |
| 382 | int axis = in.readInt(); |
| 383 | if (axis < 0) { |
| 384 | break; |
| 385 | } |
Michael Wright | c6091c6 | 2013-04-01 20:56:04 -0700 | [diff] [blame] | 386 | addMotionRange(axis, in.readInt(), in.readFloat(), in.readFloat(), in.readFloat(), |
| 387 | in.readFloat(), in.readFloat()); |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 388 | } |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 389 | } |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 390 | |
| 391 | /** |
| 392 | * Gets information about the input device with the specified id. |
| 393 | * @param id The device id. |
| 394 | * @return The input device or null if not found. |
| 395 | */ |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 396 | public static InputDevice getDevice(int id) { |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 397 | return InputManager.getInstance().getInputDevice(id); |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | /** |
| 401 | * Gets the ids of all input devices in the system. |
| 402 | * @return The input device ids. |
| 403 | */ |
| 404 | public static int[] getDeviceIds() { |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 405 | return InputManager.getInstance().getInputDeviceIds(); |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 406 | } |
Jeff Brown | 9df6e7a | 2012-04-05 11:49:26 -0700 | [diff] [blame] | 407 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 408 | /** |
| 409 | * Gets the input device id. |
Jeff Brown | 9df6e7a | 2012-04-05 11:49:26 -0700 | [diff] [blame] | 410 | * <p> |
| 411 | * Each input device receives a unique id when it is first configured |
| 412 | * by the system. The input device id may change when the system is restarted or if the |
| 413 | * input device is disconnected, reconnected or reconfigured at any time. |
| 414 | * If you require a stable identifier for a device that persists across |
| 415 | * boots and reconfigurations, use {@link #getDescriptor()}. |
| 416 | * </p> |
| 417 | * |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 418 | * @return The input device id. |
| 419 | */ |
| 420 | public int getId() { |
| 421 | return mId; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 422 | } |
Jeff Brown | 9df6e7a | 2012-04-05 11:49:26 -0700 | [diff] [blame] | 423 | |
| 424 | /** |
Michael Wright | ac6c78b | 2013-07-17 13:21:45 -0700 | [diff] [blame] | 425 | * The controller number for a given input device. |
| 426 | * <p> |
Michael Wright | 10fac45 | 2013-09-03 12:37:12 -0700 | [diff] [blame] | 427 | * Each gamepad or joystick is given a unique, positive controller number when initially |
| 428 | * configured by the system. This number may change due to events such as device disconnects / |
| 429 | * reconnects or user initiated reassignment. Any change in number will trigger an event that |
| 430 | * can be observed by registering an {@link InputManager.InputDeviceListener}. |
| 431 | * </p> |
| 432 | * <p> |
| 433 | * All input devices which are not gamepads or joysticks will be assigned a controller number |
Michael Wright | ac6c78b | 2013-07-17 13:21:45 -0700 | [diff] [blame] | 434 | * of 0. |
| 435 | * </p> |
Michael Wright | 10fac45 | 2013-09-03 12:37:12 -0700 | [diff] [blame] | 436 | * |
| 437 | * @return The controller number of the device. |
Michael Wright | ac6c78b | 2013-07-17 13:21:45 -0700 | [diff] [blame] | 438 | */ |
| 439 | public int getControllerNumber() { |
| 440 | return mControllerNumber; |
| 441 | } |
| 442 | |
| 443 | /** |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 444 | * Gets a generation number for this input device. |
| 445 | * The generation number is incremented whenever the device is reconfigured and its |
| 446 | * properties may have changed. |
| 447 | * |
| 448 | * @return The generation number. |
| 449 | * |
| 450 | * @hide |
| 451 | */ |
| 452 | public int getGeneration() { |
| 453 | return mGeneration; |
| 454 | } |
| 455 | |
| 456 | /** |
Michael Wright | 54e5694 | 2013-08-12 16:39:59 -0700 | [diff] [blame] | 457 | * Gets the vendor id for the given device, if available. |
| 458 | * <p> |
| 459 | * A vendor id uniquely identifies the company who manufactured the device. A value of 0 will |
| 460 | * be assigned where a vendor id is not available. |
| 461 | * </p> |
| 462 | * |
| 463 | * @return The vendor id of a given device |
| 464 | */ |
| 465 | public int getVendorId() { |
| 466 | return mVendorId; |
| 467 | } |
| 468 | |
| 469 | /** |
| 470 | * Gets the product id for the given device, if available. |
| 471 | * <p> |
| 472 | * A product id uniquely identifies which product within the address space of a given vendor, |
| 473 | * identified by the device's vendor id. A value of 0 will be assigned where a product id is |
| 474 | * not available. |
| 475 | * </p> |
| 476 | * |
| 477 | * @return The product id of a given device |
| 478 | */ |
| 479 | public int getProductId() { |
| 480 | return mProductId; |
| 481 | } |
| 482 | |
| 483 | /** |
Jeff Brown | 9df6e7a | 2012-04-05 11:49:26 -0700 | [diff] [blame] | 484 | * Gets the input device descriptor, which is a stable identifier for an input device. |
| 485 | * <p> |
| 486 | * An input device descriptor uniquely identifies an input device. Its value |
| 487 | * is intended to be persistent across system restarts, and should not change even |
| 488 | * if the input device is disconnected, reconnected or reconfigured at any time. |
Jeff Brown | e38fdfa | 2012-04-06 14:51:01 -0700 | [diff] [blame] | 489 | * </p><p> |
| 490 | * It is possible for there to be multiple {@link InputDevice} instances that have the |
| 491 | * same input device descriptor. This might happen in situations where a single |
| 492 | * human input device registers multiple {@link InputDevice} instances (HID collections) |
| 493 | * that describe separate features of the device, such as a keyboard that also |
| 494 | * has a trackpad. Alternately, it may be that the input devices are simply |
| 495 | * indistinguishable, such as two keyboards made by the same manufacturer. |
| 496 | * </p><p> |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 497 | * The input device descriptor returned by {@link #getDescriptor} should only be |
Jeff Brown | e38fdfa | 2012-04-06 14:51:01 -0700 | [diff] [blame] | 498 | * used when an application needs to remember settings associated with a particular |
| 499 | * input device. For all other purposes when referring to a logical |
| 500 | * {@link InputDevice} instance at runtime use the id returned by {@link #getId()}. |
Jeff Brown | 9df6e7a | 2012-04-05 11:49:26 -0700 | [diff] [blame] | 501 | * </p> |
| 502 | * |
| 503 | * @return The input device descriptor. |
| 504 | */ |
| 505 | public String getDescriptor() { |
Jeff Brown | e38fdfa | 2012-04-06 14:51:01 -0700 | [diff] [blame] | 506 | return mDescriptor; |
Jeff Brown | 9df6e7a | 2012-04-05 11:49:26 -0700 | [diff] [blame] | 507 | } |
| 508 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 509 | /** |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 510 | * Returns true if the device is a virtual input device rather than a real one, |
| 511 | * such as the virtual keyboard (see {@link KeyCharacterMap#VIRTUAL_KEYBOARD}). |
| 512 | * <p> |
| 513 | * Virtual input devices are provided to implement system-level functionality |
| 514 | * and should not be seen or configured by users. |
| 515 | * </p> |
| 516 | * |
| 517 | * @return True if the device is virtual. |
| 518 | * |
| 519 | * @see KeyCharacterMap#VIRTUAL_KEYBOARD |
| 520 | */ |
| 521 | public boolean isVirtual() { |
| 522 | return mId < 0; |
| 523 | } |
| 524 | |
| 525 | /** |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 526 | * Returns true if the device is external (connected to USB or Bluetooth or some other |
| 527 | * peripheral bus), otherwise it is built-in. |
| 528 | * |
| 529 | * @return True if the device is external. |
| 530 | * |
| 531 | * @hide |
| 532 | */ |
| 533 | public boolean isExternal() { |
| 534 | return mIsExternal; |
| 535 | } |
| 536 | |
| 537 | /** |
Jeff Brown | 7e4ff4b | 2012-05-30 14:32:16 -0700 | [diff] [blame] | 538 | * Returns true if the device is a full keyboard. |
| 539 | * |
| 540 | * @return True if the device is a full keyboard. |
| 541 | * |
| 542 | * @hide |
| 543 | */ |
| 544 | public boolean isFullKeyboard() { |
| 545 | return (mSources & SOURCE_KEYBOARD) == SOURCE_KEYBOARD |
| 546 | && mKeyboardType == KEYBOARD_TYPE_ALPHABETIC; |
| 547 | } |
| 548 | |
| 549 | /** |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 550 | * Gets the name of this input device. |
| 551 | * @return The input device name. |
| 552 | */ |
| 553 | public String getName() { |
| 554 | return mName; |
| 555 | } |
| 556 | |
| 557 | /** |
| 558 | * Gets the input sources supported by this input device as a combined bitfield. |
| 559 | * @return The supported input sources. |
| 560 | */ |
| 561 | public int getSources() { |
| 562 | return mSources; |
| 563 | } |
| 564 | |
| 565 | /** |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 566 | * Gets the keyboard type. |
| 567 | * @return The keyboard type. |
| 568 | */ |
| 569 | public int getKeyboardType() { |
| 570 | return mKeyboardType; |
| 571 | } |
| 572 | |
| 573 | /** |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 574 | * Gets the key character map associated with this input device. |
| 575 | * @return The key character map. |
| 576 | */ |
| 577 | public KeyCharacterMap getKeyCharacterMap() { |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 578 | return mKeyCharacterMap; |
Jeff Brown | 1e08fe9 | 2011-11-15 17:48:10 -0800 | [diff] [blame] | 579 | } |
| 580 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 581 | /** |
Michael Wright | b7b2d4b | 2013-08-19 15:55:38 -0700 | [diff] [blame] | 582 | * Gets whether the device is capable of producing the list of keycodes. |
| 583 | * @param keys The list of android keycodes to check for. |
| 584 | * @return An array of booleans where each member specifies whether the device is capable of |
| 585 | * generating the keycode given by the corresponding value at the same index in the keys array. |
| 586 | */ |
| 587 | public boolean[] hasKeys(int... keys) { |
| 588 | return InputManager.getInstance().deviceHasKeys(mId, keys); |
| 589 | } |
| 590 | |
| 591 | /** |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 592 | * Gets information about the range of values for a particular {@link MotionEvent} axis. |
Jeff Brown | efd3266 | 2011-03-08 15:13:06 -0800 | [diff] [blame] | 593 | * If the device supports multiple sources, the same axis may have different meanings |
| 594 | * for each source. Returns information about the first axis found for any source. |
| 595 | * To obtain information about the axis for a specific source, use |
| 596 | * {@link #getMotionRange(int, int)}. |
| 597 | * |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 598 | * @param axis The axis constant. |
| 599 | * @return The range of values, or null if the requested axis is not |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 600 | * supported by the device. |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 601 | * |
| 602 | * @see MotionEvent#AXIS_X |
| 603 | * @see MotionEvent#AXIS_Y |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 604 | */ |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 605 | public MotionRange getMotionRange(int axis) { |
Jeff Brown | efd3266 | 2011-03-08 15:13:06 -0800 | [diff] [blame] | 606 | final int numRanges = mMotionRanges.size(); |
| 607 | for (int i = 0; i < numRanges; i++) { |
| 608 | final MotionRange range = mMotionRanges.get(i); |
| 609 | if (range.mAxis == axis) { |
| 610 | return range; |
| 611 | } |
| 612 | } |
| 613 | return null; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 614 | } |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 615 | |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 616 | /** |
Jeff Brown | efd3266 | 2011-03-08 15:13:06 -0800 | [diff] [blame] | 617 | * Gets information about the range of values for a particular {@link MotionEvent} axis |
| 618 | * used by a particular source on the device. |
| 619 | * If the device supports multiple sources, the same axis may have different meanings |
| 620 | * for each source. |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 621 | * |
Jeff Brown | efd3266 | 2011-03-08 15:13:06 -0800 | [diff] [blame] | 622 | * @param axis The axis constant. |
| 623 | * @param source The source for which to return information. |
| 624 | * @return The range of values, or null if the requested axis is not |
| 625 | * supported by the device. |
| 626 | * |
| 627 | * @see MotionEvent#AXIS_X |
| 628 | * @see MotionEvent#AXIS_Y |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 629 | */ |
Jeff Brown | efd3266 | 2011-03-08 15:13:06 -0800 | [diff] [blame] | 630 | public MotionRange getMotionRange(int axis, int source) { |
| 631 | final int numRanges = mMotionRanges.size(); |
| 632 | for (int i = 0; i < numRanges; i++) { |
| 633 | final MotionRange range = mMotionRanges.get(i); |
| 634 | if (range.mAxis == axis && range.mSource == source) { |
| 635 | return range; |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 636 | } |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 637 | } |
Jeff Brown | efd3266 | 2011-03-08 15:13:06 -0800 | [diff] [blame] | 638 | return null; |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 639 | } |
| 640 | |
Jeff Brown | efd3266 | 2011-03-08 15:13:06 -0800 | [diff] [blame] | 641 | /** |
| 642 | * Gets the ranges for all axes supported by the device. |
| 643 | * @return The motion ranges for the device. |
| 644 | * |
| 645 | * @see #getMotionRange(int, int) |
| 646 | */ |
| 647 | public List<MotionRange> getMotionRanges() { |
| 648 | return mMotionRanges; |
| 649 | } |
| 650 | |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 651 | // Called from native code. |
Jeff Brown | efd3266 | 2011-03-08 15:13:06 -0800 | [diff] [blame] | 652 | private void addMotionRange(int axis, int source, |
Michael Wright | c6091c6 | 2013-04-01 20:56:04 -0700 | [diff] [blame] | 653 | float min, float max, float flat, float fuzz, float resolution) { |
| 654 | mMotionRanges.add(new MotionRange(axis, source, min, max, flat, fuzz, resolution)); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 655 | } |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 656 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 657 | /** |
Jeff Brown | a47425a | 2012-04-13 04:09:27 -0700 | [diff] [blame] | 658 | * Gets the vibrator service associated with the device, if there is one. |
| 659 | * Even if the device does not have a vibrator, the result is never null. |
| 660 | * Use {@link Vibrator#hasVibrator} to determine whether a vibrator is |
| 661 | * present. |
| 662 | * |
| 663 | * Note that the vibrator associated with the device may be different from |
| 664 | * the system vibrator. To obtain an instance of the system vibrator instead, call |
| 665 | * {@link Context#getSystemService} with {@link Context#VIBRATOR_SERVICE} as argument. |
| 666 | * |
| 667 | * @return The vibrator service associated with the device, never null. |
| 668 | */ |
| 669 | public Vibrator getVibrator() { |
| 670 | synchronized (mMotionRanges) { |
| 671 | if (mVibrator == null) { |
| 672 | if (mHasVibrator) { |
| 673 | mVibrator = InputManager.getInstance().getInputDeviceVibrator(mId); |
| 674 | } else { |
| 675 | mVibrator = NullVibrator.getInstance(); |
| 676 | } |
| 677 | } |
| 678 | return mVibrator; |
| 679 | } |
| 680 | } |
| 681 | |
| 682 | /** |
Michael Wright | 7ddd110 | 2013-05-20 15:04:55 -0700 | [diff] [blame] | 683 | * Reports whether the device has a button under its touchpad |
| 684 | * @return Whether the device has a button under its touchpad |
| 685 | * @hide |
| 686 | */ |
| 687 | public boolean hasButtonUnderPad() { |
| 688 | return mHasButtonUnderPad; |
| 689 | } |
| 690 | |
| 691 | /** |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 692 | * Provides information about the range of values for a particular {@link MotionEvent} axis. |
| 693 | * |
| 694 | * @see InputDevice#getMotionRange(int) |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 695 | */ |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 696 | public static final class MotionRange { |
Jeff Brown | efd3266 | 2011-03-08 15:13:06 -0800 | [diff] [blame] | 697 | private int mAxis; |
| 698 | private int mSource; |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 699 | private float mMin; |
| 700 | private float mMax; |
| 701 | private float mFlat; |
| 702 | private float mFuzz; |
Michael Wright | c6091c6 | 2013-04-01 20:56:04 -0700 | [diff] [blame] | 703 | private float mResolution; |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 704 | |
Michael Wright | c6091c6 | 2013-04-01 20:56:04 -0700 | [diff] [blame] | 705 | private MotionRange(int axis, int source, float min, float max, float flat, float fuzz, |
| 706 | float resolution) { |
Jeff Brown | efd3266 | 2011-03-08 15:13:06 -0800 | [diff] [blame] | 707 | mAxis = axis; |
| 708 | mSource = source; |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 709 | mMin = min; |
| 710 | mMax = max; |
| 711 | mFlat = flat; |
| 712 | mFuzz = fuzz; |
Michael Wright | c6091c6 | 2013-04-01 20:56:04 -0700 | [diff] [blame] | 713 | mResolution = resolution; |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 714 | } |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 715 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 716 | /** |
Jeff Brown | efd3266 | 2011-03-08 15:13:06 -0800 | [diff] [blame] | 717 | * Gets the axis id. |
| 718 | * @return The axis id. |
| 719 | */ |
| 720 | public int getAxis() { |
| 721 | return mAxis; |
| 722 | } |
| 723 | |
| 724 | /** |
| 725 | * Gets the source for which the axis is defined. |
| 726 | * @return The source. |
| 727 | */ |
| 728 | public int getSource() { |
| 729 | return mSource; |
| 730 | } |
| 731 | |
Michael Wright | 74e4156 | 2013-03-08 14:58:14 -0800 | [diff] [blame] | 732 | |
| 733 | /** |
| 734 | * Determines whether the event is from the given source. |
| 735 | * |
| 736 | * @param source The input source to check against. This can be a specific device type, |
| 737 | * such as {@link InputDevice#SOURCE_TOUCH_NAVIGATION}, or a more generic device class, |
| 738 | * such as {@link InputDevice#SOURCE_CLASS_POINTER}. |
| 739 | * @return Whether the event is from the given source. |
| 740 | */ |
| 741 | public boolean isFromSource(int source) { |
| 742 | return (getSource() & source) == source; |
| 743 | } |
| 744 | |
Jeff Brown | efd3266 | 2011-03-08 15:13:06 -0800 | [diff] [blame] | 745 | /** |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 746 | * Gets the inclusive minimum value for the axis. |
| 747 | * @return The inclusive minimum value. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 748 | */ |
| 749 | public float getMin() { |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 750 | return mMin; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 751 | } |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 752 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 753 | /** |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 754 | * Gets the inclusive maximum value for the axis. |
| 755 | * @return The inclusive maximum value. |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 756 | */ |
| 757 | public float getMax() { |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 758 | return mMax; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 759 | } |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 760 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 761 | /** |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 762 | * Gets the range of the axis (difference between maximum and minimum). |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 763 | * @return The range of values. |
| 764 | */ |
| 765 | public float getRange() { |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 766 | return mMax - mMin; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 767 | } |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 768 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 769 | /** |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 770 | * Gets the extent of the center flat position with respect to this axis. |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 771 | * <p> |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 772 | * For example, a flat value of 8 means that the center position is between -8 and +8. |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 773 | * This value is mainly useful for calibrating self-centering devices. |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 774 | * </p> |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 775 | * @return The extent of the center flat position. |
| 776 | */ |
| 777 | public float getFlat() { |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 778 | return mFlat; |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 779 | } |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 780 | |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 781 | /** |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 782 | * Gets the error tolerance for input device measurements with respect to this axis. |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 783 | * <p> |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 784 | * For example, a value of 2 indicates that the measured value may be up to +/- 2 units |
| 785 | * away from the actual value due to noise and device sensitivity limitations. |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 786 | * </p> |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 787 | * @return The error tolerance. |
| 788 | */ |
| 789 | public float getFuzz() { |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 790 | return mFuzz; |
| 791 | } |
Michael Wright | c6091c6 | 2013-04-01 20:56:04 -0700 | [diff] [blame] | 792 | |
| 793 | /** |
| 794 | * Gets the resolution for input device measurements with respect to this axis. |
| 795 | * @return The resolution in units per millimeter, or units per radian for rotational axes. |
| 796 | */ |
| 797 | public float getResolution() { |
| 798 | return mResolution; |
| 799 | } |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 800 | } |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 801 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 802 | @Override |
| 803 | public void writeToParcel(Parcel out, int flags) { |
| 804 | out.writeInt(mId); |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 805 | out.writeInt(mGeneration); |
Michael Wright | ac6c78b | 2013-07-17 13:21:45 -0700 | [diff] [blame] | 806 | out.writeInt(mControllerNumber); |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 807 | out.writeString(mName); |
Michael Wright | 54e5694 | 2013-08-12 16:39:59 -0700 | [diff] [blame] | 808 | out.writeInt(mVendorId); |
| 809 | out.writeInt(mProductId); |
Jeff Brown | e38fdfa | 2012-04-06 14:51:01 -0700 | [diff] [blame] | 810 | out.writeString(mDescriptor); |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 811 | out.writeInt(mIsExternal ? 1 : 0); |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 812 | out.writeInt(mSources); |
| 813 | out.writeInt(mKeyboardType); |
Jeff Brown | 9f25b7f | 2012-04-10 14:30:49 -0700 | [diff] [blame] | 814 | mKeyCharacterMap.writeToParcel(out, flags); |
Jeff Brown | a47425a | 2012-04-13 04:09:27 -0700 | [diff] [blame] | 815 | out.writeInt(mHasVibrator ? 1 : 0); |
Michael Wright | 7ddd110 | 2013-05-20 15:04:55 -0700 | [diff] [blame] | 816 | out.writeInt(mHasButtonUnderPad ? 1 : 0); |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 817 | |
Jeff Brown | efd3266 | 2011-03-08 15:13:06 -0800 | [diff] [blame] | 818 | final int numRanges = mMotionRanges.size(); |
| 819 | for (int i = 0; i < numRanges; i++) { |
| 820 | MotionRange range = mMotionRanges.get(i); |
| 821 | out.writeInt(range.mAxis); |
| 822 | out.writeInt(range.mSource); |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 823 | out.writeFloat(range.mMin); |
| 824 | out.writeFloat(range.mMax); |
| 825 | out.writeFloat(range.mFlat); |
| 826 | out.writeFloat(range.mFuzz); |
Michael Wright | c6091c6 | 2013-04-01 20:56:04 -0700 | [diff] [blame] | 827 | out.writeFloat(range.mResolution); |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 828 | } |
| 829 | out.writeInt(-1); |
| 830 | } |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 831 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 832 | @Override |
| 833 | public int describeContents() { |
| 834 | return 0; |
| 835 | } |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 836 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 837 | @Override |
| 838 | public String toString() { |
| 839 | StringBuilder description = new StringBuilder(); |
| 840 | description.append("Input Device ").append(mId).append(": ").append(mName).append("\n"); |
Jeff Brown | e38fdfa | 2012-04-06 14:51:01 -0700 | [diff] [blame] | 841 | description.append(" Descriptor: ").append(mDescriptor).append("\n"); |
Jeff Brown | af9e8d3 | 2012-04-12 17:32:48 -0700 | [diff] [blame] | 842 | description.append(" Generation: ").append(mGeneration).append("\n"); |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 843 | description.append(" Location: ").append(mIsExternal ? "external" : "built-in").append("\n"); |
Jeff Brown | e38fdfa | 2012-04-06 14:51:01 -0700 | [diff] [blame] | 844 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 845 | description.append(" Keyboard Type: "); |
| 846 | switch (mKeyboardType) { |
| 847 | case KEYBOARD_TYPE_NONE: |
| 848 | description.append("none"); |
| 849 | break; |
| 850 | case KEYBOARD_TYPE_NON_ALPHABETIC: |
| 851 | description.append("non-alphabetic"); |
| 852 | break; |
| 853 | case KEYBOARD_TYPE_ALPHABETIC: |
| 854 | description.append("alphabetic"); |
| 855 | break; |
| 856 | } |
| 857 | description.append("\n"); |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 858 | |
Jeff Brown | a47425a | 2012-04-13 04:09:27 -0700 | [diff] [blame] | 859 | description.append(" Has Vibrator: ").append(mHasVibrator).append("\n"); |
| 860 | |
Jeff Brown | efd3266 | 2011-03-08 15:13:06 -0800 | [diff] [blame] | 861 | description.append(" Sources: 0x").append(Integer.toHexString(mSources)).append(" ("); |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 862 | appendSourceDescriptionIfApplicable(description, SOURCE_KEYBOARD, "keyboard"); |
| 863 | appendSourceDescriptionIfApplicable(description, SOURCE_DPAD, "dpad"); |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 864 | appendSourceDescriptionIfApplicable(description, SOURCE_TOUCHSCREEN, "touchscreen"); |
| 865 | appendSourceDescriptionIfApplicable(description, SOURCE_MOUSE, "mouse"); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 866 | appendSourceDescriptionIfApplicable(description, SOURCE_STYLUS, "stylus"); |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 867 | appendSourceDescriptionIfApplicable(description, SOURCE_TRACKBALL, "trackball"); |
| 868 | appendSourceDescriptionIfApplicable(description, SOURCE_TOUCHPAD, "touchpad"); |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 869 | appendSourceDescriptionIfApplicable(description, SOURCE_JOYSTICK, "joystick"); |
| 870 | appendSourceDescriptionIfApplicable(description, SOURCE_GAMEPAD, "gamepad"); |
| 871 | description.append(" )\n"); |
| 872 | |
| 873 | final int numAxes = mMotionRanges.size(); |
| 874 | for (int i = 0; i < numAxes; i++) { |
Jeff Brown | efd3266 | 2011-03-08 15:13:06 -0800 | [diff] [blame] | 875 | MotionRange range = mMotionRanges.get(i); |
| 876 | description.append(" ").append(MotionEvent.axisToString(range.mAxis)); |
| 877 | description.append(": source=0x").append(Integer.toHexString(range.mSource)); |
| 878 | description.append(" min=").append(range.mMin); |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 879 | description.append(" max=").append(range.mMax); |
| 880 | description.append(" flat=").append(range.mFlat); |
| 881 | description.append(" fuzz=").append(range.mFuzz); |
Michael Wright | c6091c6 | 2013-04-01 20:56:04 -0700 | [diff] [blame] | 882 | description.append(" resolution=").append(range.mResolution); |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 883 | description.append("\n"); |
| 884 | } |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 885 | return description.toString(); |
| 886 | } |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 887 | |
Jeff Brown | 8d60866 | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 888 | private void appendSourceDescriptionIfApplicable(StringBuilder description, int source, |
| 889 | String sourceName) { |
| 890 | if ((mSources & source) == source) { |
| 891 | description.append(" "); |
| 892 | description.append(sourceName); |
| 893 | } |
| 894 | } |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 895 | } |