blob: 0b12cbe9c221d7cb5e87aa8e5b90e299bbbd7573 [file] [log] [blame]
Jeff Brownc5ed5912010-07-14 18:48:53 -07001/*
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
17package android.view;
18
Jeff Browna47425a2012-04-13 04:09:27 -070019import android.content.Context;
RoboErikfb290df2013-12-16 11:27:55 -080020import android.hardware.input.InputDeviceIdentifier;
Jeff Brownac143512012-04-05 18:57:33 -070021import android.hardware.input.InputManager;
Jeff Brown8d608662010-08-30 03:02:23 -070022import android.os.Parcel;
23import android.os.Parcelable;
Jeff Browna47425a2012-04-13 04:09:27 -070024import android.os.Vibrator;
25import android.os.NullVibrator;
Jeff Brownefd32662011-03-08 15:13:06 -080026
27import java.util.ArrayList;
28import java.util.List;
Jeff Brown8d608662010-08-30 03:02:23 -070029
Jeff Brownc5ed5912010-07-14 18:48:53 -070030/**
31 * Describes the capabilities of a particular input device.
32 * <p>
Jeff Brown9df6e7a2012-04-05 11:49:26 -070033 * Each input device may support multiple classes of input. For example, a multi-function
Jeff Brownc5ed5912010-07-14 18:48:53 -070034 * keyboard may compose the capabilities of a standard keyboard together with a track pad mouse
35 * or other pointing device.
36 * </p><p>
Jeff Browndc1ab4b2010-09-14 18:03:38 -070037 * Some input devices present multiple distinguishable sources of input.
Jeff Brownc5ed5912010-07-14 18:48:53 -070038 * 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 Brown6d0fec22010-07-23 21:28:06 -070043 * </p>
Jeff Brownc5ed5912010-07-14 18:48:53 -070044 */
Jeff Brown8d608662010-08-30 03:02:23 -070045public final class InputDevice implements Parcelable {
Jeff Brown9f25b7f2012-04-10 14:30:49 -070046 private final int mId;
Jeff Brownaf9e8d32012-04-12 17:32:48 -070047 private final int mGeneration;
Michael Wrightac6c78b2013-07-17 13:21:45 -070048 private final int mControllerNumber;
Jeff Brown9f25b7f2012-04-10 14:30:49 -070049 private final String mName;
Michael Wright54e56942013-08-12 16:39:59 -070050 private final int mVendorId;
51 private final int mProductId;
Jeff Brown9f25b7f2012-04-10 14:30:49 -070052 private final String mDescriptor;
RoboErikfb290df2013-12-16 11:27:55 -080053 private final InputDeviceIdentifier mIdentifier;
Jeff Browndaa37532012-05-01 15:54:03 -070054 private final boolean mIsExternal;
Jeff Brown9f25b7f2012-04-10 14:30:49 -070055 private final int mSources;
56 private final int mKeyboardType;
57 private final KeyCharacterMap mKeyCharacterMap;
Jeff Browna47425a2012-04-13 04:09:27 -070058 private final boolean mHasVibrator;
Michael Wright7ddd1102013-05-20 15:04:55 -070059 private final boolean mHasButtonUnderPad;
Jeff Brownefd32662011-03-08 15:13:06 -080060 private final ArrayList<MotionRange> mMotionRanges = new ArrayList<MotionRange>();
Jeff Brown91c69ab2011-02-14 17:03:18 -080061
Jeff Browna47425a2012-04-13 04:09:27 -070062 private Vibrator mVibrator; // guarded by mMotionRanges during initialization
63
Jeff Brownc5ed5912010-07-14 18:48:53 -070064 /**
65 * A mask for input source classes.
RoboErikfb290df2013-12-16 11:27:55 -080066 *
Jeff Brownc5ed5912010-07-14 18:48:53 -070067 * 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 Wrighte7a9ae82013-03-08 15:19:19 -080071
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 Brownc5ed5912010-07-14 18:48:53 -070079 /**
80 * The input source has buttons or keys.
Jeff Browndc1ab4b2010-09-14 18:03:38 -070081 * Examples: {@link #SOURCE_KEYBOARD}, {@link #SOURCE_DPAD}.
RoboErikfb290df2013-12-16 11:27:55 -080082 *
Jeff Brownc5ed5912010-07-14 18:48:53 -070083 * A {@link KeyEvent} should be interpreted as a button or key press.
RoboErikfb290df2013-12-16 11:27:55 -080084 *
Jeff Brown6eb5ac92010-08-30 23:29:07 -070085 * Use {@link #getKeyCharacterMap} to query the device's button and key mappings.
Jeff Brownc5ed5912010-07-14 18:48:53 -070086 */
87 public static final int SOURCE_CLASS_BUTTON = 0x00000001;
RoboErikfb290df2013-12-16 11:27:55 -080088
Jeff Brownc5ed5912010-07-14 18:48:53 -070089 /**
90 * The input source is a pointing device associated with a display.
91 * Examples: {@link #SOURCE_TOUCHSCREEN}, {@link #SOURCE_MOUSE}.
RoboErikfb290df2013-12-16 11:27:55 -080092 *
Jeff Brownc5ed5912010-07-14 18:48:53 -070093 * 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.
RoboErikfb290df2013-12-16 11:27:55 -080096 *
Jeff Brownc5ed5912010-07-14 18:48:53 -070097 * 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;
RoboErikfb290df2013-12-16 11:27:55 -0800102
Jeff Brownc5ed5912010-07-14 18:48:53 -0700103 /**
104 * The input source is a trackball navigation device.
105 * Examples: {@link #SOURCE_TRACKBALL}.
RoboErikfb290df2013-12-16 11:27:55 -0800106 *
Jeff Brownc5ed5912010-07-14 18:48:53 -0700107 * 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.
RoboErikfb290df2013-12-16 11:27:55 -0800110 *
Jeff Brownc5ed5912010-07-14 18:48:53 -0700111 * Use {@link #getMotionRange} to query the range of motion.
112 */
113 public static final int SOURCE_CLASS_TRACKBALL = 0x00000004;
RoboErikfb290df2013-12-16 11:27:55 -0800114
Jeff Brownc5ed5912010-07-14 18:48:53 -0700115 /**
116 * The input source is an absolute positioning device not associated with a display
117 * (unlike {@link #SOURCE_CLASS_POINTER}).
RoboErikfb290df2013-12-16 11:27:55 -0800118 *
Jeff Brownc5ed5912010-07-14 18:48:53 -0700119 * A {@link MotionEvent} should be interpreted as absolute coordinates in
120 * device-specific surface units.
RoboErikfb290df2013-12-16 11:27:55 -0800121 *
Jeff Brownc5ed5912010-07-14 18:48:53 -0700122 * Use {@link #getMotionRange} to query the range of positions.
123 */
124 public static final int SOURCE_CLASS_POSITION = 0x00000008;
Jeff Browncb1404e2011-01-15 18:14:15 -0800125
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 Brownc5ed5912010-07-14 18:48:53 -0700135 /**
Jeff Brownc5ed5912010-07-14 18:48:53 -0700136 * The input source is unknown.
137 */
138 public static final int SOURCE_UNKNOWN = 0x00000000;
RoboErikfb290df2013-12-16 11:27:55 -0800139
Jeff Brownc5ed5912010-07-14 18:48:53 -0700140 /**
141 * The input source is a keyboard.
Jeff Brown9df6e7a2012-04-05 11:49:26 -0700142 *
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 Brownc5ed5912010-07-14 18:48:53 -0700147 * @see #SOURCE_CLASS_BUTTON
148 */
149 public static final int SOURCE_KEYBOARD = 0x00000100 | SOURCE_CLASS_BUTTON;
RoboErikfb290df2013-12-16 11:27:55 -0800150
Jeff Brownc5ed5912010-07-14 18:48:53 -0700151 /**
152 * The input source is a DPad.
RoboErikfb290df2013-12-16 11:27:55 -0800153 *
Jeff Brownc5ed5912010-07-14 18:48:53 -0700154 * @see #SOURCE_CLASS_BUTTON
155 */
156 public static final int SOURCE_DPAD = 0x00000200 | SOURCE_CLASS_BUTTON;
Jeff Browncb1404e2011-01-15 18:14:15 -0800157
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 Brownc5ed5912010-07-14 18:48:53 -0700166 /**
Jeff Brownc5ed5912010-07-14 18:48:53 -0700167 * The input source is a touch screen pointing device.
RoboErikfb290df2013-12-16 11:27:55 -0800168 *
Jeff Brownc5ed5912010-07-14 18:48:53 -0700169 * @see #SOURCE_CLASS_POINTER
170 */
171 public static final int SOURCE_TOUCHSCREEN = 0x00001000 | SOURCE_CLASS_POINTER;
RoboErikfb290df2013-12-16 11:27:55 -0800172
Jeff Brownc5ed5912010-07-14 18:48:53 -0700173 /**
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.
RoboErikfb290df2013-12-16 11:27:55 -0800177 *
Jeff Brownc5ed5912010-07-14 18:48:53 -0700178 * @see #SOURCE_CLASS_POINTER
179 */
180 public static final int SOURCE_MOUSE = 0x00002000 | SOURCE_CLASS_POINTER;
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700181
182 /**
183 * The input source is a stylus pointing device.
Jeff Brown00710e92012-04-19 15:18:26 -0700184 * <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 Brownfe9f8ab2011-05-06 18:20:01 -0700197 *
198 * @see #SOURCE_CLASS_POINTER
199 */
200 public static final int SOURCE_STYLUS = 0x00004000 | SOURCE_CLASS_POINTER;
201
Jeff Brownc5ed5912010-07-14 18:48:53 -0700202 /**
203 * The input source is a trackball.
RoboErikfb290df2013-12-16 11:27:55 -0800204 *
Jeff Brownc5ed5912010-07-14 18:48:53 -0700205 * @see #SOURCE_CLASS_TRACKBALL
206 */
207 public static final int SOURCE_TRACKBALL = 0x00010000 | SOURCE_CLASS_TRACKBALL;
RoboErikfb290df2013-12-16 11:27:55 -0800208
Jeff Brownc5ed5912010-07-14 18:48:53 -0700209 /**
210 * The input source is a touch pad or digitizer tablet that is not
Jeff Browne33348b2010-07-15 23:54:05 -0700211 * associated with a display (unlike {@link #SOURCE_TOUCHSCREEN}).
RoboErikfb290df2013-12-16 11:27:55 -0800212 *
Jeff Brownc5ed5912010-07-14 18:48:53 -0700213 * @see #SOURCE_CLASS_POSITION
214 */
215 public static final int SOURCE_TOUCHPAD = 0x00100000 | SOURCE_CLASS_POSITION;
Jeff Browncb1404e2011-01-15 18:14:15 -0800216
217 /**
Michael Wrighte7a9ae82013-03-08 15:19:19 -0800218 * 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 Browncb1404e2011-01-15 18:14:15 -0800229 * 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 Brown6d0fec22010-07-23 21:28:06 -0700236 /**
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 Brownc5ed5912010-07-14 18:48:53 -0700241
Jeff Browne33348b2010-07-15 23:54:05 -0700242 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -0800243 * Constant for retrieving the range of values for {@link MotionEvent#AXIS_X}.
RoboErikfb290df2013-12-16 11:27:55 -0800244 *
Jeff Browne33348b2010-07-15 23:54:05 -0700245 * @see #getMotionRange
Jeff Brown91c69ab2011-02-14 17:03:18 -0800246 * @deprecated Use {@link MotionEvent#AXIS_X} instead.
Jeff Browne33348b2010-07-15 23:54:05 -0700247 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800248 @Deprecated
249 public static final int MOTION_RANGE_X = MotionEvent.AXIS_X;
250
Jeff Browne33348b2010-07-15 23:54:05 -0700251 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -0800252 * Constant for retrieving the range of values for {@link MotionEvent#AXIS_Y}.
RoboErikfb290df2013-12-16 11:27:55 -0800253 *
Jeff Browne33348b2010-07-15 23:54:05 -0700254 * @see #getMotionRange
Jeff Brown91c69ab2011-02-14 17:03:18 -0800255 * @deprecated Use {@link MotionEvent#AXIS_Y} instead.
Jeff Browne33348b2010-07-15 23:54:05 -0700256 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800257 @Deprecated
258 public static final int MOTION_RANGE_Y = MotionEvent.AXIS_Y;
259
Jeff Browne33348b2010-07-15 23:54:05 -0700260 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -0800261 * Constant for retrieving the range of values for {@link MotionEvent#AXIS_PRESSURE}.
RoboErikfb290df2013-12-16 11:27:55 -0800262 *
Jeff Browne33348b2010-07-15 23:54:05 -0700263 * @see #getMotionRange
Jeff Brown91c69ab2011-02-14 17:03:18 -0800264 * @deprecated Use {@link MotionEvent#AXIS_PRESSURE} instead.
Jeff Browne33348b2010-07-15 23:54:05 -0700265 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800266 @Deprecated
267 public static final int MOTION_RANGE_PRESSURE = MotionEvent.AXIS_PRESSURE;
268
Jeff Browne33348b2010-07-15 23:54:05 -0700269 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -0800270 * Constant for retrieving the range of values for {@link MotionEvent#AXIS_SIZE}.
RoboErikfb290df2013-12-16 11:27:55 -0800271 *
Jeff Browne33348b2010-07-15 23:54:05 -0700272 * @see #getMotionRange
Jeff Brown91c69ab2011-02-14 17:03:18 -0800273 * @deprecated Use {@link MotionEvent#AXIS_SIZE} instead.
Jeff Browne33348b2010-07-15 23:54:05 -0700274 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800275 @Deprecated
276 public static final int MOTION_RANGE_SIZE = MotionEvent.AXIS_SIZE;
277
Jeff Browne33348b2010-07-15 23:54:05 -0700278 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -0800279 * Constant for retrieving the range of values for {@link MotionEvent#AXIS_TOUCH_MAJOR}.
RoboErikfb290df2013-12-16 11:27:55 -0800280 *
Jeff Browne33348b2010-07-15 23:54:05 -0700281 * @see #getMotionRange
Jeff Brown91c69ab2011-02-14 17:03:18 -0800282 * @deprecated Use {@link MotionEvent#AXIS_TOUCH_MAJOR} instead.
Jeff Browne33348b2010-07-15 23:54:05 -0700283 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800284 @Deprecated
285 public static final int MOTION_RANGE_TOUCH_MAJOR = MotionEvent.AXIS_TOUCH_MAJOR;
286
Jeff Browne33348b2010-07-15 23:54:05 -0700287 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -0800288 * Constant for retrieving the range of values for {@link MotionEvent#AXIS_TOUCH_MINOR}.
RoboErikfb290df2013-12-16 11:27:55 -0800289 *
Jeff Browne33348b2010-07-15 23:54:05 -0700290 * @see #getMotionRange
Jeff Brown91c69ab2011-02-14 17:03:18 -0800291 * @deprecated Use {@link MotionEvent#AXIS_TOUCH_MINOR} instead.
Jeff Browne33348b2010-07-15 23:54:05 -0700292 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800293 @Deprecated
294 public static final int MOTION_RANGE_TOUCH_MINOR = MotionEvent.AXIS_TOUCH_MINOR;
295
Jeff Browne33348b2010-07-15 23:54:05 -0700296 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -0800297 * Constant for retrieving the range of values for {@link MotionEvent#AXIS_TOOL_MAJOR}.
RoboErikfb290df2013-12-16 11:27:55 -0800298 *
Jeff Browne33348b2010-07-15 23:54:05 -0700299 * @see #getMotionRange
Jeff Brown91c69ab2011-02-14 17:03:18 -0800300 * @deprecated Use {@link MotionEvent#AXIS_TOOL_MAJOR} instead.
Jeff Browne33348b2010-07-15 23:54:05 -0700301 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800302 @Deprecated
303 public static final int MOTION_RANGE_TOOL_MAJOR = MotionEvent.AXIS_TOOL_MAJOR;
304
Jeff Browne33348b2010-07-15 23:54:05 -0700305 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -0800306 * Constant for retrieving the range of values for {@link MotionEvent#AXIS_TOOL_MINOR}.
RoboErikfb290df2013-12-16 11:27:55 -0800307 *
Jeff Browne33348b2010-07-15 23:54:05 -0700308 * @see #getMotionRange
Jeff Brown91c69ab2011-02-14 17:03:18 -0800309 * @deprecated Use {@link MotionEvent#AXIS_TOOL_MINOR} instead.
Jeff Browne33348b2010-07-15 23:54:05 -0700310 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800311 @Deprecated
312 public static final int MOTION_RANGE_TOOL_MINOR = MotionEvent.AXIS_TOOL_MINOR;
313
Jeff Browne33348b2010-07-15 23:54:05 -0700314 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -0800315 * Constant for retrieving the range of values for {@link MotionEvent#AXIS_ORIENTATION}.
RoboErikfb290df2013-12-16 11:27:55 -0800316 *
Jeff Browne33348b2010-07-15 23:54:05 -0700317 * @see #getMotionRange
Jeff Brown91c69ab2011-02-14 17:03:18 -0800318 * @deprecated Use {@link MotionEvent#AXIS_ORIENTATION} instead.
Jeff Browne33348b2010-07-15 23:54:05 -0700319 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800320 @Deprecated
321 public static final int MOTION_RANGE_ORIENTATION = MotionEvent.AXIS_ORIENTATION;
RoboErikfb290df2013-12-16 11:27:55 -0800322
Jeff Brown6d0fec22010-07-23 21:28:06 -0700323 /**
324 * There is no keyboard.
325 */
326 public static final int KEYBOARD_TYPE_NONE = 0;
RoboErikfb290df2013-12-16 11:27:55 -0800327
Jeff Brown6d0fec22010-07-23 21:28:06 -0700328 /**
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;
RoboErikfb290df2013-12-16 11:27:55 -0800333
Jeff Brown6d0fec22010-07-23 21:28:06 -0700334 /**
335 * The keyboard supports a complement of alphabetic keys.
336 */
337 public static final int KEYBOARD_TYPE_ALPHABETIC = 2;
Jeff Brown91c69ab2011-02-14 17:03:18 -0800338
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700339 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 Brown8d608662010-08-30 03:02:23 -0700349 // Called by native code.
Michael Wright54e56942013-08-12 16:39:59 -0700350 private InputDevice(int id, int generation, int controllerNumber, String name, int vendorId,
351 int productId, String descriptor, boolean isExternal, int sources, int keyboardType,
Michael Wrightac6c78b2013-07-17 13:21:45 -0700352 KeyCharacterMap keyCharacterMap, boolean hasVibrator, boolean hasButtonUnderPad) {
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700353 mId = id;
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700354 mGeneration = generation;
Michael Wrightac6c78b2013-07-17 13:21:45 -0700355 mControllerNumber = controllerNumber;
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700356 mName = name;
Michael Wright54e56942013-08-12 16:39:59 -0700357 mVendorId = vendorId;
358 mProductId = productId;
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700359 mDescriptor = descriptor;
Jeff Browndaa37532012-05-01 15:54:03 -0700360 mIsExternal = isExternal;
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700361 mSources = sources;
362 mKeyboardType = keyboardType;
363 mKeyCharacterMap = keyCharacterMap;
Jeff Browna47425a2012-04-13 04:09:27 -0700364 mHasVibrator = hasVibrator;
Michael Wright7ddd1102013-05-20 15:04:55 -0700365 mHasButtonUnderPad = hasButtonUnderPad;
RoboErikfb290df2013-12-16 11:27:55 -0800366 mIdentifier = new InputDeviceIdentifier(descriptor, vendorId, productId);
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700367 }
368
369 private InputDevice(Parcel in) {
370 mId = in.readInt();
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700371 mGeneration = in.readInt();
Michael Wrightac6c78b2013-07-17 13:21:45 -0700372 mControllerNumber = in.readInt();
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700373 mName = in.readString();
Michael Wright54e56942013-08-12 16:39:59 -0700374 mVendorId = in.readInt();
375 mProductId = in.readInt();
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700376 mDescriptor = in.readString();
Jeff Browndaa37532012-05-01 15:54:03 -0700377 mIsExternal = in.readInt() != 0;
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700378 mSources = in.readInt();
379 mKeyboardType = in.readInt();
380 mKeyCharacterMap = KeyCharacterMap.CREATOR.createFromParcel(in);
Jeff Browna47425a2012-04-13 04:09:27 -0700381 mHasVibrator = in.readInt() != 0;
Michael Wright7ddd1102013-05-20 15:04:55 -0700382 mHasButtonUnderPad = in.readInt() != 0;
RoboErikfb290df2013-12-16 11:27:55 -0800383 mIdentifier = new InputDeviceIdentifier(mDescriptor, mVendorId, mProductId);
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700384
385 for (;;) {
386 int axis = in.readInt();
387 if (axis < 0) {
388 break;
389 }
Michael Wrightc6091c62013-04-01 20:56:04 -0700390 addMotionRange(axis, in.readInt(), in.readFloat(), in.readFloat(), in.readFloat(),
391 in.readFloat(), in.readFloat());
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700392 }
Jeff Brown8d608662010-08-30 03:02:23 -0700393 }
Jeff Browne33348b2010-07-15 23:54:05 -0700394
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 Brownc5ed5912010-07-14 18:48:53 -0700400 public static InputDevice getDevice(int id) {
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700401 return InputManager.getInstance().getInputDevice(id);
Jeff Brown8d608662010-08-30 03:02:23 -0700402 }
RoboErikfb290df2013-12-16 11:27:55 -0800403
Jeff Brown8d608662010-08-30 03:02:23 -0700404 /**
405 * Gets the ids of all input devices in the system.
406 * @return The input device ids.
407 */
408 public static int[] getDeviceIds() {
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700409 return InputManager.getInstance().getInputDeviceIds();
Jeff Brown8d608662010-08-30 03:02:23 -0700410 }
Jeff Brown9df6e7a2012-04-05 11:49:26 -0700411
Jeff Brown8d608662010-08-30 03:02:23 -0700412 /**
413 * Gets the input device id.
Jeff Brown9df6e7a2012-04-05 11:49:26 -0700414 * <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 Brown8d608662010-08-30 03:02:23 -0700422 * @return The input device id.
423 */
424 public int getId() {
425 return mId;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700426 }
Jeff Brown9df6e7a2012-04-05 11:49:26 -0700427
428 /**
Michael Wrightac6c78b2013-07-17 13:21:45 -0700429 * The controller number for a given input device.
430 * <p>
Michael Wright10fac452013-09-03 12:37:12 -0700431 * 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 Wrightac6c78b2013-07-17 13:21:45 -0700438 * of 0.
439 * </p>
Michael Wright10fac452013-09-03 12:37:12 -0700440 *
441 * @return The controller number of the device.
Michael Wrightac6c78b2013-07-17 13:21:45 -0700442 */
443 public int getControllerNumber() {
444 return mControllerNumber;
445 }
446
447 /**
RoboErikfb290df2013-12-16 11:27:55 -0800448 * 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 Brownaf9e8d32012-04-12 17:32:48 -0700460 * 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 Wright54e56942013-08-12 16:39:59 -0700473 * 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 Brown9df6e7a2012-04-05 11:49:26 -0700500 * 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 Browne38fdfa2012-04-06 14:51:01 -0700505 * </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 Browndaa37532012-05-01 15:54:03 -0700513 * The input device descriptor returned by {@link #getDescriptor} should only be
Jeff Browne38fdfa2012-04-06 14:51:01 -0700514 * 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 Brown9df6e7a2012-04-05 11:49:26 -0700517 * </p>
518 *
519 * @return The input device descriptor.
520 */
521 public String getDescriptor() {
Jeff Browne38fdfa2012-04-06 14:51:01 -0700522 return mDescriptor;
Jeff Brown9df6e7a2012-04-05 11:49:26 -0700523 }
524
Jeff Brownc5ed5912010-07-14 18:48:53 -0700525 /**
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700526 * 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 Browndaa37532012-05-01 15:54:03 -0700542 * 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 Brown7e4ff4b2012-05-30 14:32:16 -0700554 * 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 Brownc5ed5912010-07-14 18:48:53 -0700566 * Gets the name of this input device.
567 * @return The input device name.
568 */
569 public String getName() {
570 return mName;
571 }
RoboErikfb290df2013-12-16 11:27:55 -0800572
Jeff Brownc5ed5912010-07-14 18:48:53 -0700573 /**
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 }
RoboErikfb290df2013-12-16 11:27:55 -0800580
Jeff Brownc5ed5912010-07-14 18:48:53 -0700581 /**
Jeff Brown6d0fec22010-07-23 21:28:06 -0700582 * Gets the keyboard type.
583 * @return The keyboard type.
584 */
585 public int getKeyboardType() {
586 return mKeyboardType;
587 }
RoboErikfb290df2013-12-16 11:27:55 -0800588
Jeff Brown6d0fec22010-07-23 21:28:06 -0700589 /**
Jeff Brownc5ed5912010-07-14 18:48:53 -0700590 * Gets the key character map associated with this input device.
591 * @return The key character map.
592 */
593 public KeyCharacterMap getKeyCharacterMap() {
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700594 return mKeyCharacterMap;
Jeff Brown1e08fe92011-11-15 17:48:10 -0800595 }
596
Jeff Browne33348b2010-07-15 23:54:05 -0700597 /**
Michael Wrightb7b2d4b2013-08-19 15:55:38 -0700598 * 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 Brown91c69ab2011-02-14 17:03:18 -0800608 * Gets information about the range of values for a particular {@link MotionEvent} axis.
Jeff Brownefd32662011-03-08 15:13:06 -0800609 * 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 Brown91c69ab2011-02-14 17:03:18 -0800614 * @param axis The axis constant.
615 * @return The range of values, or null if the requested axis is not
Jeff Browne33348b2010-07-15 23:54:05 -0700616 * supported by the device.
Jeff Brown91c69ab2011-02-14 17:03:18 -0800617 *
618 * @see MotionEvent#AXIS_X
619 * @see MotionEvent#AXIS_Y
Jeff Browne33348b2010-07-15 23:54:05 -0700620 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800621 public MotionRange getMotionRange(int axis) {
Jeff Brownefd32662011-03-08 15:13:06 -0800622 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 Brownc5ed5912010-07-14 18:48:53 -0700630 }
Jeff Brown91c69ab2011-02-14 17:03:18 -0800631
Jeff Brown6f2fba42011-02-19 01:08:02 -0800632 /**
Jeff Brownefd32662011-03-08 15:13:06 -0800633 * 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 Brown6f2fba42011-02-19 01:08:02 -0800637 *
Jeff Brownefd32662011-03-08 15:13:06 -0800638 * @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 Brown6f2fba42011-02-19 01:08:02 -0800645 */
Jeff Brownefd32662011-03-08 15:13:06 -0800646 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 Brown6f2fba42011-02-19 01:08:02 -0800652 }
Jeff Brown6f2fba42011-02-19 01:08:02 -0800653 }
Jeff Brownefd32662011-03-08 15:13:06 -0800654 return null;
Jeff Brown6f2fba42011-02-19 01:08:02 -0800655 }
656
Jeff Brownefd32662011-03-08 15:13:06 -0800657 /**
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 Brown9f25b7f2012-04-10 14:30:49 -0700667 // Called from native code.
Jeff Brownefd32662011-03-08 15:13:06 -0800668 private void addMotionRange(int axis, int source,
Michael Wrightc6091c62013-04-01 20:56:04 -0700669 float min, float max, float flat, float fuzz, float resolution) {
670 mMotionRanges.add(new MotionRange(axis, source, min, max, flat, fuzz, resolution));
Jeff Brownc5ed5912010-07-14 18:48:53 -0700671 }
Jeff Brown91c69ab2011-02-14 17:03:18 -0800672
Jeff Browne33348b2010-07-15 23:54:05 -0700673 /**
Jeff Browna47425a2012-04-13 04:09:27 -0700674 * 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 Wright7ddd1102013-05-20 15:04:55 -0700699 * 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 Brown91c69ab2011-02-14 17:03:18 -0800708 * Provides information about the range of values for a particular {@link MotionEvent} axis.
709 *
710 * @see InputDevice#getMotionRange(int)
Jeff Browne33348b2010-07-15 23:54:05 -0700711 */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700712 public static final class MotionRange {
Jeff Brownefd32662011-03-08 15:13:06 -0800713 private int mAxis;
714 private int mSource;
Jeff Brown8d608662010-08-30 03:02:23 -0700715 private float mMin;
716 private float mMax;
717 private float mFlat;
718 private float mFuzz;
Michael Wrightc6091c62013-04-01 20:56:04 -0700719 private float mResolution;
Jeff Brown91c69ab2011-02-14 17:03:18 -0800720
Michael Wrightc6091c62013-04-01 20:56:04 -0700721 private MotionRange(int axis, int source, float min, float max, float flat, float fuzz,
722 float resolution) {
Jeff Brownefd32662011-03-08 15:13:06 -0800723 mAxis = axis;
724 mSource = source;
Jeff Brown8d608662010-08-30 03:02:23 -0700725 mMin = min;
726 mMax = max;
727 mFlat = flat;
728 mFuzz = fuzz;
Michael Wrightc6091c62013-04-01 20:56:04 -0700729 mResolution = resolution;
Jeff Brown8d608662010-08-30 03:02:23 -0700730 }
Jeff Brown91c69ab2011-02-14 17:03:18 -0800731
Jeff Browne33348b2010-07-15 23:54:05 -0700732 /**
Jeff Brownefd32662011-03-08 15:13:06 -0800733 * 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 Wright74e41562013-03-08 14:58:14 -0800748
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 Brownefd32662011-03-08 15:13:06 -0800761 /**
Jeff Brown6f2fba42011-02-19 01:08:02 -0800762 * Gets the inclusive minimum value for the axis.
763 * @return The inclusive minimum value.
Jeff Browne33348b2010-07-15 23:54:05 -0700764 */
765 public float getMin() {
Jeff Brown8d608662010-08-30 03:02:23 -0700766 return mMin;
Jeff Browne33348b2010-07-15 23:54:05 -0700767 }
Jeff Brown91c69ab2011-02-14 17:03:18 -0800768
Jeff Browne33348b2010-07-15 23:54:05 -0700769 /**
Jeff Brown6f2fba42011-02-19 01:08:02 -0800770 * Gets the inclusive maximum value for the axis.
771 * @return The inclusive maximum value.
Jeff Browne33348b2010-07-15 23:54:05 -0700772 */
773 public float getMax() {
Jeff Brown8d608662010-08-30 03:02:23 -0700774 return mMax;
Jeff Browne33348b2010-07-15 23:54:05 -0700775 }
Jeff Brown91c69ab2011-02-14 17:03:18 -0800776
Jeff Browne33348b2010-07-15 23:54:05 -0700777 /**
Jeff Brown6f2fba42011-02-19 01:08:02 -0800778 * Gets the range of the axis (difference between maximum and minimum).
Jeff Browne33348b2010-07-15 23:54:05 -0700779 * @return The range of values.
780 */
781 public float getRange() {
Jeff Brown6f2fba42011-02-19 01:08:02 -0800782 return mMax - mMin;
Jeff Browne33348b2010-07-15 23:54:05 -0700783 }
Jeff Brown91c69ab2011-02-14 17:03:18 -0800784
Jeff Browne33348b2010-07-15 23:54:05 -0700785 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -0800786 * Gets the extent of the center flat position with respect to this axis.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800787 * <p>
Jeff Browne33348b2010-07-15 23:54:05 -0700788 * For example, a flat value of 8 means that the center position is between -8 and +8.
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700789 * This value is mainly useful for calibrating self-centering devices.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800790 * </p>
Jeff Browne33348b2010-07-15 23:54:05 -0700791 * @return The extent of the center flat position.
792 */
793 public float getFlat() {
Jeff Brown8d608662010-08-30 03:02:23 -0700794 return mFlat;
Jeff Browne33348b2010-07-15 23:54:05 -0700795 }
Jeff Brown91c69ab2011-02-14 17:03:18 -0800796
Jeff Browne33348b2010-07-15 23:54:05 -0700797 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -0800798 * Gets the error tolerance for input device measurements with respect to this axis.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800799 * <p>
Jeff Browne33348b2010-07-15 23:54:05 -0700800 * 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 Brown6f2fba42011-02-19 01:08:02 -0800802 * </p>
Jeff Browne33348b2010-07-15 23:54:05 -0700803 * @return The error tolerance.
804 */
805 public float getFuzz() {
Jeff Brown8d608662010-08-30 03:02:23 -0700806 return mFuzz;
807 }
Michael Wrightc6091c62013-04-01 20:56:04 -0700808
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 Brown8d608662010-08-30 03:02:23 -0700816 }
Jeff Brown91c69ab2011-02-14 17:03:18 -0800817
Jeff Brown8d608662010-08-30 03:02:23 -0700818 @Override
819 public void writeToParcel(Parcel out, int flags) {
820 out.writeInt(mId);
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700821 out.writeInt(mGeneration);
Michael Wrightac6c78b2013-07-17 13:21:45 -0700822 out.writeInt(mControllerNumber);
Jeff Brown8d608662010-08-30 03:02:23 -0700823 out.writeString(mName);
Michael Wright54e56942013-08-12 16:39:59 -0700824 out.writeInt(mVendorId);
825 out.writeInt(mProductId);
Jeff Browne38fdfa2012-04-06 14:51:01 -0700826 out.writeString(mDescriptor);
Jeff Browndaa37532012-05-01 15:54:03 -0700827 out.writeInt(mIsExternal ? 1 : 0);
Jeff Brown8d608662010-08-30 03:02:23 -0700828 out.writeInt(mSources);
829 out.writeInt(mKeyboardType);
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700830 mKeyCharacterMap.writeToParcel(out, flags);
Jeff Browna47425a2012-04-13 04:09:27 -0700831 out.writeInt(mHasVibrator ? 1 : 0);
Michael Wright7ddd1102013-05-20 15:04:55 -0700832 out.writeInt(mHasButtonUnderPad ? 1 : 0);
Jeff Brown91c69ab2011-02-14 17:03:18 -0800833
Jeff Brownefd32662011-03-08 15:13:06 -0800834 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 Brown91c69ab2011-02-14 17:03:18 -0800839 out.writeFloat(range.mMin);
840 out.writeFloat(range.mMax);
841 out.writeFloat(range.mFlat);
842 out.writeFloat(range.mFuzz);
Michael Wrightc6091c62013-04-01 20:56:04 -0700843 out.writeFloat(range.mResolution);
Jeff Brown8d608662010-08-30 03:02:23 -0700844 }
845 out.writeInt(-1);
846 }
Jeff Brown91c69ab2011-02-14 17:03:18 -0800847
Jeff Brown8d608662010-08-30 03:02:23 -0700848 @Override
849 public int describeContents() {
850 return 0;
851 }
Jeff Brown91c69ab2011-02-14 17:03:18 -0800852
Jeff Brown8d608662010-08-30 03:02:23 -0700853 @Override
854 public String toString() {
855 StringBuilder description = new StringBuilder();
856 description.append("Input Device ").append(mId).append(": ").append(mName).append("\n");
Jeff Browne38fdfa2012-04-06 14:51:01 -0700857 description.append(" Descriptor: ").append(mDescriptor).append("\n");
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700858 description.append(" Generation: ").append(mGeneration).append("\n");
Jeff Browndaa37532012-05-01 15:54:03 -0700859 description.append(" Location: ").append(mIsExternal ? "external" : "built-in").append("\n");
Jeff Browne38fdfa2012-04-06 14:51:01 -0700860
Jeff Brown8d608662010-08-30 03:02:23 -0700861 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 Brown91c69ab2011-02-14 17:03:18 -0800874
Jeff Browna47425a2012-04-13 04:09:27 -0700875 description.append(" Has Vibrator: ").append(mHasVibrator).append("\n");
876
Jeff Brownefd32662011-03-08 15:13:06 -0800877 description.append(" Sources: 0x").append(Integer.toHexString(mSources)).append(" (");
Jeff Brown8d608662010-08-30 03:02:23 -0700878 appendSourceDescriptionIfApplicable(description, SOURCE_KEYBOARD, "keyboard");
879 appendSourceDescriptionIfApplicable(description, SOURCE_DPAD, "dpad");
Jeff Brown8d608662010-08-30 03:02:23 -0700880 appendSourceDescriptionIfApplicable(description, SOURCE_TOUCHSCREEN, "touchscreen");
881 appendSourceDescriptionIfApplicable(description, SOURCE_MOUSE, "mouse");
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700882 appendSourceDescriptionIfApplicable(description, SOURCE_STYLUS, "stylus");
Jeff Brown8d608662010-08-30 03:02:23 -0700883 appendSourceDescriptionIfApplicable(description, SOURCE_TRACKBALL, "trackball");
884 appendSourceDescriptionIfApplicable(description, SOURCE_TOUCHPAD, "touchpad");
Jeff Brown91c69ab2011-02-14 17:03:18 -0800885 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 Brownefd32662011-03-08 15:13:06 -0800891 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 Brown91c69ab2011-02-14 17:03:18 -0800895 description.append(" max=").append(range.mMax);
896 description.append(" flat=").append(range.mFlat);
897 description.append(" fuzz=").append(range.mFuzz);
Michael Wrightc6091c62013-04-01 20:56:04 -0700898 description.append(" resolution=").append(range.mResolution);
Jeff Brown91c69ab2011-02-14 17:03:18 -0800899 description.append("\n");
900 }
Jeff Brown8d608662010-08-30 03:02:23 -0700901 return description.toString();
902 }
Jeff Brown91c69ab2011-02-14 17:03:18 -0800903
Jeff Brown8d608662010-08-30 03:02:23 -0700904 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 Brownc5ed5912010-07-14 18:48:53 -0700911}