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