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