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