blob: e8291160a7f834e923c14de56a836389e37dbd52 [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;
Jeff Brownac143512012-04-05 18:57:33 -070020import android.hardware.input.InputManager;
Jeff Brown8d608662010-08-30 03:02:23 -070021import android.os.Parcel;
22import android.os.Parcelable;
Jeff Browna47425a2012-04-13 04:09:27 -070023import android.os.Vibrator;
24import android.os.NullVibrator;
Jeff Brownefd32662011-03-08 15:13:06 -080025
26import java.util.ArrayList;
27import java.util.List;
Jeff Brown8d608662010-08-30 03:02:23 -070028
Jeff Brownc5ed5912010-07-14 18:48:53 -070029/**
30 * Describes the capabilities of a particular input device.
31 * <p>
Jeff Brown9df6e7a2012-04-05 11:49:26 -070032 * Each input device may support multiple classes of input. For example, a multi-function
Jeff Brownc5ed5912010-07-14 18:48:53 -070033 * keyboard may compose the capabilities of a standard keyboard together with a track pad mouse
34 * or other pointing device.
35 * </p><p>
Jeff Browndc1ab4b2010-09-14 18:03:38 -070036 * Some input devices present multiple distinguishable sources of input.
Jeff Brownc5ed5912010-07-14 18:48:53 -070037 * Applications can query the framework about the characteristics of each distinct source.
38 * </p><p>
39 * As a further wrinkle, different kinds of input sources uses different coordinate systems
40 * to describe motion events. Refer to the comments on the input source constants for
41 * the appropriate interpretation.
Jeff Brown6d0fec22010-07-23 21:28:06 -070042 * </p>
Jeff Brownc5ed5912010-07-14 18:48:53 -070043 */
Jeff Brown8d608662010-08-30 03:02:23 -070044public final class InputDevice implements Parcelable {
Jeff Brown9f25b7f2012-04-10 14:30:49 -070045 private final int mId;
Jeff Brownaf9e8d32012-04-12 17:32:48 -070046 private final int mGeneration;
Michael Wrightac6c78b2013-07-17 13:21:45 -070047 private final int mControllerNumber;
Jeff Brown9f25b7f2012-04-10 14:30:49 -070048 private final String mName;
Michael Wright54e56942013-08-12 16:39:59 -070049 private final int mVendorId;
50 private final int mProductId;
Jeff Brown9f25b7f2012-04-10 14:30:49 -070051 private final String mDescriptor;
Jeff Browndaa37532012-05-01 15:54:03 -070052 private final boolean mIsExternal;
Jeff Brown9f25b7f2012-04-10 14:30:49 -070053 private final int mSources;
54 private final int mKeyboardType;
55 private final KeyCharacterMap mKeyCharacterMap;
Jeff Browna47425a2012-04-13 04:09:27 -070056 private final boolean mHasVibrator;
Michael Wright7ddd1102013-05-20 15:04:55 -070057 private final boolean mHasButtonUnderPad;
Jeff Brownefd32662011-03-08 15:13:06 -080058 private final ArrayList<MotionRange> mMotionRanges = new ArrayList<MotionRange>();
Jeff Brown91c69ab2011-02-14 17:03:18 -080059
Jeff Browna47425a2012-04-13 04:09:27 -070060 private Vibrator mVibrator; // guarded by mMotionRanges during initialization
61
Jeff Brownc5ed5912010-07-14 18:48:53 -070062 /**
63 * A mask for input source classes.
64 *
65 * Each distinct input source constant has one or more input source class bits set to
66 * specify the desired interpretation for its input events.
67 */
68 public static final int SOURCE_CLASS_MASK = 0x000000ff;
Michael Wrighte7a9ae82013-03-08 15:19:19 -080069
70 /**
71 * The input source has no class.
72 *
73 * It is up to the application to determine how to handle the device based on the device type.
74 */
75 public static final int SOURCE_CLASS_NONE = 0x00000000;
76
Jeff Brownc5ed5912010-07-14 18:48:53 -070077 /**
78 * The input source has buttons or keys.
Jeff Browndc1ab4b2010-09-14 18:03:38 -070079 * Examples: {@link #SOURCE_KEYBOARD}, {@link #SOURCE_DPAD}.
Jeff Brownc5ed5912010-07-14 18:48:53 -070080 *
81 * A {@link KeyEvent} should be interpreted as a button or key press.
82 *
Jeff Brown6eb5ac92010-08-30 23:29:07 -070083 * Use {@link #getKeyCharacterMap} to query the device's button and key mappings.
Jeff Brownc5ed5912010-07-14 18:48:53 -070084 */
85 public static final int SOURCE_CLASS_BUTTON = 0x00000001;
86
87 /**
88 * The input source is a pointing device associated with a display.
89 * Examples: {@link #SOURCE_TOUCHSCREEN}, {@link #SOURCE_MOUSE}.
90 *
91 * A {@link MotionEvent} should be interpreted as absolute coordinates in
92 * display units according to the {@link View} hierarchy. Pointer down/up indicated when
93 * the finger touches the display or when the selection button is pressed/released.
94 *
95 * Use {@link #getMotionRange} to query the range of the pointing device. Some devices permit
96 * touches outside the display area so the effective range may be somewhat smaller or larger
97 * than the actual display size.
98 */
99 public static final int SOURCE_CLASS_POINTER = 0x00000002;
100
101 /**
102 * The input source is a trackball navigation device.
103 * Examples: {@link #SOURCE_TRACKBALL}.
104 *
105 * A {@link MotionEvent} should be interpreted as relative movements in device-specific
106 * units used for navigation purposes. Pointer down/up indicates when the selection button
107 * is pressed/released.
108 *
109 * Use {@link #getMotionRange} to query the range of motion.
110 */
111 public static final int SOURCE_CLASS_TRACKBALL = 0x00000004;
112
113 /**
114 * The input source is an absolute positioning device not associated with a display
115 * (unlike {@link #SOURCE_CLASS_POINTER}).
116 *
117 * A {@link MotionEvent} should be interpreted as absolute coordinates in
118 * device-specific surface units.
119 *
120 * Use {@link #getMotionRange} to query the range of positions.
121 */
122 public static final int SOURCE_CLASS_POSITION = 0x00000008;
Jeff Browncb1404e2011-01-15 18:14:15 -0800123
124 /**
125 * The input source is a joystick.
126 *
127 * A {@link MotionEvent} should be interpreted as absolute joystick movements.
128 *
129 * Use {@link #getMotionRange} to query the range of positions.
130 */
131 public static final int SOURCE_CLASS_JOYSTICK = 0x00000010;
132
Jeff Brownc5ed5912010-07-14 18:48:53 -0700133 /**
Jeff Brownc5ed5912010-07-14 18:48:53 -0700134 * The input source is unknown.
135 */
136 public static final int SOURCE_UNKNOWN = 0x00000000;
137
138 /**
139 * The input source is a keyboard.
Jeff Brown9df6e7a2012-04-05 11:49:26 -0700140 *
141 * This source indicates pretty much anything that has buttons. Use
142 * {@link #getKeyboardType()} to determine whether the keyboard has alphabetic keys
143 * and can be used to enter text.
144 *
Jeff Brownc5ed5912010-07-14 18:48:53 -0700145 * @see #SOURCE_CLASS_BUTTON
146 */
147 public static final int SOURCE_KEYBOARD = 0x00000100 | SOURCE_CLASS_BUTTON;
148
149 /**
150 * The input source is a DPad.
151 *
152 * @see #SOURCE_CLASS_BUTTON
153 */
154 public static final int SOURCE_DPAD = 0x00000200 | SOURCE_CLASS_BUTTON;
Jeff Browncb1404e2011-01-15 18:14:15 -0800155
156 /**
157 * The input source is a game pad.
158 * (It may also be a {@link #SOURCE_JOYSTICK}).
159 *
160 * @see #SOURCE_CLASS_BUTTON
161 */
162 public static final int SOURCE_GAMEPAD = 0x00000400 | SOURCE_CLASS_BUTTON;
163
Jeff Brownc5ed5912010-07-14 18:48:53 -0700164 /**
Jeff Brownc5ed5912010-07-14 18:48:53 -0700165 * The input source is a touch screen pointing device.
166 *
167 * @see #SOURCE_CLASS_POINTER
168 */
169 public static final int SOURCE_TOUCHSCREEN = 0x00001000 | SOURCE_CLASS_POINTER;
170
171 /**
172 * The input source is a mouse pointing device.
173 * This code is also used for other mouse-like pointing devices such as trackpads
174 * and trackpoints.
175 *
176 * @see #SOURCE_CLASS_POINTER
177 */
178 public static final int SOURCE_MOUSE = 0x00002000 | SOURCE_CLASS_POINTER;
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700179
180 /**
181 * The input source is a stylus pointing device.
Jeff Brown00710e92012-04-19 15:18:26 -0700182 * <p>
183 * Note that this bit merely indicates that an input device is capable of obtaining
184 * input from a stylus. To determine whether a given touch event was produced
185 * by a stylus, examine the tool type returned by {@link MotionEvent#getToolType(int)}
186 * for each individual pointer.
187 * </p><p>
188 * A single touch event may multiple pointers with different tool types,
189 * such as an event that has one pointer with tool type
190 * {@link MotionEvent#TOOL_TYPE_FINGER} and another pointer with tool type
191 * {@link MotionEvent#TOOL_TYPE_STYLUS}. So it is important to examine
192 * the tool type of each pointer, regardless of the source reported
193 * by {@link MotionEvent#getSource()}.
194 * </p>
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700195 *
196 * @see #SOURCE_CLASS_POINTER
197 */
198 public static final int SOURCE_STYLUS = 0x00004000 | SOURCE_CLASS_POINTER;
199
Jeff Brownc5ed5912010-07-14 18:48:53 -0700200 /**
201 * The input source is a trackball.
202 *
203 * @see #SOURCE_CLASS_TRACKBALL
204 */
205 public static final int SOURCE_TRACKBALL = 0x00010000 | SOURCE_CLASS_TRACKBALL;
206
207 /**
208 * The input source is a touch pad or digitizer tablet that is not
Jeff Browne33348b2010-07-15 23:54:05 -0700209 * associated with a display (unlike {@link #SOURCE_TOUCHSCREEN}).
Jeff Brownc5ed5912010-07-14 18:48:53 -0700210 *
211 * @see #SOURCE_CLASS_POSITION
212 */
213 public static final int SOURCE_TOUCHPAD = 0x00100000 | SOURCE_CLASS_POSITION;
Jeff Browncb1404e2011-01-15 18:14:15 -0800214
215 /**
Michael Wrighte7a9ae82013-03-08 15:19:19 -0800216 * The input source is a touch device whose motions should be interpreted as navigation events.
217 *
218 * For example, an upward swipe should be as an upward focus traversal in the same manner as
219 * pressing up on a D-Pad would be. Swipes to the left, right and down should be treated in a
220 * similar manner.
221 *
222 * @see #SOURCE_CLASS_NONE
223 */
224 public static final int SOURCE_TOUCH_NAVIGATION = 0x00200000 | SOURCE_CLASS_NONE;
225
226 /**
Jeff Browncb1404e2011-01-15 18:14:15 -0800227 * The input source is a joystick.
228 * (It may also be a {@link #SOURCE_GAMEPAD}).
229 *
230 * @see #SOURCE_CLASS_JOYSTICK
231 */
232 public static final int SOURCE_JOYSTICK = 0x01000000 | SOURCE_CLASS_JOYSTICK;
233
Jeff Brown6d0fec22010-07-23 21:28:06 -0700234 /**
235 * A special input source constant that is used when filtering input devices
236 * to match devices that provide any type of input source.
237 */
238 public static final int SOURCE_ANY = 0xffffff00;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700239
Jeff Browne33348b2010-07-15 23:54:05 -0700240 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -0800241 * Constant for retrieving the range of values for {@link MotionEvent#AXIS_X}.
Jeff Browne33348b2010-07-15 23:54:05 -0700242 *
243 * @see #getMotionRange
Jeff Brown91c69ab2011-02-14 17:03:18 -0800244 * @deprecated Use {@link MotionEvent#AXIS_X} instead.
Jeff Browne33348b2010-07-15 23:54:05 -0700245 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800246 @Deprecated
247 public static final int MOTION_RANGE_X = MotionEvent.AXIS_X;
248
Jeff Browne33348b2010-07-15 23:54:05 -0700249 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -0800250 * Constant for retrieving the range of values for {@link MotionEvent#AXIS_Y}.
Jeff Browne33348b2010-07-15 23:54:05 -0700251 *
252 * @see #getMotionRange
Jeff Brown91c69ab2011-02-14 17:03:18 -0800253 * @deprecated Use {@link MotionEvent#AXIS_Y} instead.
Jeff Browne33348b2010-07-15 23:54:05 -0700254 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800255 @Deprecated
256 public static final int MOTION_RANGE_Y = MotionEvent.AXIS_Y;
257
Jeff Browne33348b2010-07-15 23:54:05 -0700258 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -0800259 * Constant for retrieving the range of values for {@link MotionEvent#AXIS_PRESSURE}.
Jeff Browne33348b2010-07-15 23:54:05 -0700260 *
261 * @see #getMotionRange
Jeff Brown91c69ab2011-02-14 17:03:18 -0800262 * @deprecated Use {@link MotionEvent#AXIS_PRESSURE} instead.
Jeff Browne33348b2010-07-15 23:54:05 -0700263 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800264 @Deprecated
265 public static final int MOTION_RANGE_PRESSURE = MotionEvent.AXIS_PRESSURE;
266
Jeff Browne33348b2010-07-15 23:54:05 -0700267 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -0800268 * Constant for retrieving the range of values for {@link MotionEvent#AXIS_SIZE}.
Jeff Browne33348b2010-07-15 23:54:05 -0700269 *
270 * @see #getMotionRange
Jeff Brown91c69ab2011-02-14 17:03:18 -0800271 * @deprecated Use {@link MotionEvent#AXIS_SIZE} instead.
Jeff Browne33348b2010-07-15 23:54:05 -0700272 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800273 @Deprecated
274 public static final int MOTION_RANGE_SIZE = MotionEvent.AXIS_SIZE;
275
Jeff Browne33348b2010-07-15 23:54:05 -0700276 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -0800277 * Constant for retrieving the range of values for {@link MotionEvent#AXIS_TOUCH_MAJOR}.
Jeff Browne33348b2010-07-15 23:54:05 -0700278 *
279 * @see #getMotionRange
Jeff Brown91c69ab2011-02-14 17:03:18 -0800280 * @deprecated Use {@link MotionEvent#AXIS_TOUCH_MAJOR} instead.
Jeff Browne33348b2010-07-15 23:54:05 -0700281 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800282 @Deprecated
283 public static final int MOTION_RANGE_TOUCH_MAJOR = MotionEvent.AXIS_TOUCH_MAJOR;
284
Jeff Browne33348b2010-07-15 23:54:05 -0700285 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -0800286 * Constant for retrieving the range of values for {@link MotionEvent#AXIS_TOUCH_MINOR}.
Jeff Browne33348b2010-07-15 23:54:05 -0700287 *
288 * @see #getMotionRange
Jeff Brown91c69ab2011-02-14 17:03:18 -0800289 * @deprecated Use {@link MotionEvent#AXIS_TOUCH_MINOR} instead.
Jeff Browne33348b2010-07-15 23:54:05 -0700290 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800291 @Deprecated
292 public static final int MOTION_RANGE_TOUCH_MINOR = MotionEvent.AXIS_TOUCH_MINOR;
293
Jeff Browne33348b2010-07-15 23:54:05 -0700294 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -0800295 * Constant for retrieving the range of values for {@link MotionEvent#AXIS_TOOL_MAJOR}.
Jeff Browne33348b2010-07-15 23:54:05 -0700296 *
297 * @see #getMotionRange
Jeff Brown91c69ab2011-02-14 17:03:18 -0800298 * @deprecated Use {@link MotionEvent#AXIS_TOOL_MAJOR} instead.
Jeff Browne33348b2010-07-15 23:54:05 -0700299 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800300 @Deprecated
301 public static final int MOTION_RANGE_TOOL_MAJOR = MotionEvent.AXIS_TOOL_MAJOR;
302
Jeff Browne33348b2010-07-15 23:54:05 -0700303 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -0800304 * Constant for retrieving the range of values for {@link MotionEvent#AXIS_TOOL_MINOR}.
Jeff Browne33348b2010-07-15 23:54:05 -0700305 *
306 * @see #getMotionRange
Jeff Brown91c69ab2011-02-14 17:03:18 -0800307 * @deprecated Use {@link MotionEvent#AXIS_TOOL_MINOR} instead.
Jeff Browne33348b2010-07-15 23:54:05 -0700308 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800309 @Deprecated
310 public static final int MOTION_RANGE_TOOL_MINOR = MotionEvent.AXIS_TOOL_MINOR;
311
Jeff Browne33348b2010-07-15 23:54:05 -0700312 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -0800313 * Constant for retrieving the range of values for {@link MotionEvent#AXIS_ORIENTATION}.
Jeff Browne33348b2010-07-15 23:54:05 -0700314 *
315 * @see #getMotionRange
Jeff Brown91c69ab2011-02-14 17:03:18 -0800316 * @deprecated Use {@link MotionEvent#AXIS_ORIENTATION} instead.
Jeff Browne33348b2010-07-15 23:54:05 -0700317 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800318 @Deprecated
319 public static final int MOTION_RANGE_ORIENTATION = MotionEvent.AXIS_ORIENTATION;
Jeff Brown8d608662010-08-30 03:02:23 -0700320
Jeff Brown6d0fec22010-07-23 21:28:06 -0700321 /**
322 * There is no keyboard.
323 */
324 public static final int KEYBOARD_TYPE_NONE = 0;
325
326 /**
327 * The keyboard is not fully alphabetic. It may be a numeric keypad or an assortment
328 * of buttons that are not mapped as alphabetic keys suitable for text input.
329 */
330 public static final int KEYBOARD_TYPE_NON_ALPHABETIC = 1;
331
332 /**
333 * The keyboard supports a complement of alphabetic keys.
334 */
335 public static final int KEYBOARD_TYPE_ALPHABETIC = 2;
Jeff Brown91c69ab2011-02-14 17:03:18 -0800336
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700337 public static final Parcelable.Creator<InputDevice> CREATOR =
338 new Parcelable.Creator<InputDevice>() {
339 public InputDevice createFromParcel(Parcel in) {
340 return new InputDevice(in);
341 }
342 public InputDevice[] newArray(int size) {
343 return new InputDevice[size];
344 }
345 };
346
Jeff Brown8d608662010-08-30 03:02:23 -0700347 // Called by native code.
Michael Wright54e56942013-08-12 16:39:59 -0700348 private InputDevice(int id, int generation, int controllerNumber, String name, int vendorId,
349 int productId, String descriptor, boolean isExternal, int sources, int keyboardType,
Michael Wrightac6c78b2013-07-17 13:21:45 -0700350 KeyCharacterMap keyCharacterMap, boolean hasVibrator, boolean hasButtonUnderPad) {
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700351 mId = id;
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700352 mGeneration = generation;
Michael Wrightac6c78b2013-07-17 13:21:45 -0700353 mControllerNumber = controllerNumber;
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700354 mName = name;
Michael Wright54e56942013-08-12 16:39:59 -0700355 mVendorId = vendorId;
356 mProductId = productId;
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700357 mDescriptor = descriptor;
Jeff Browndaa37532012-05-01 15:54:03 -0700358 mIsExternal = isExternal;
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700359 mSources = sources;
360 mKeyboardType = keyboardType;
361 mKeyCharacterMap = keyCharacterMap;
Jeff Browna47425a2012-04-13 04:09:27 -0700362 mHasVibrator = hasVibrator;
Michael Wright7ddd1102013-05-20 15:04:55 -0700363 mHasButtonUnderPad = hasButtonUnderPad;
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700364 }
365
366 private InputDevice(Parcel in) {
367 mId = in.readInt();
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700368 mGeneration = in.readInt();
Michael Wrightac6c78b2013-07-17 13:21:45 -0700369 mControllerNumber = in.readInt();
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700370 mName = in.readString();
Michael Wright54e56942013-08-12 16:39:59 -0700371 mVendorId = in.readInt();
372 mProductId = in.readInt();
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700373 mDescriptor = in.readString();
Jeff Browndaa37532012-05-01 15:54:03 -0700374 mIsExternal = in.readInt() != 0;
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700375 mSources = in.readInt();
376 mKeyboardType = in.readInt();
377 mKeyCharacterMap = KeyCharacterMap.CREATOR.createFromParcel(in);
Jeff Browna47425a2012-04-13 04:09:27 -0700378 mHasVibrator = in.readInt() != 0;
Michael Wright7ddd1102013-05-20 15:04:55 -0700379 mHasButtonUnderPad = in.readInt() != 0;
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700380
381 for (;;) {
382 int axis = in.readInt();
383 if (axis < 0) {
384 break;
385 }
Michael Wrightc6091c62013-04-01 20:56:04 -0700386 addMotionRange(axis, in.readInt(), in.readFloat(), in.readFloat(), in.readFloat(),
387 in.readFloat(), in.readFloat());
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700388 }
Jeff Brown8d608662010-08-30 03:02:23 -0700389 }
Jeff Browne33348b2010-07-15 23:54:05 -0700390
391 /**
392 * Gets information about the input device with the specified id.
393 * @param id The device id.
394 * @return The input device or null if not found.
395 */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700396 public static InputDevice getDevice(int id) {
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700397 return InputManager.getInstance().getInputDevice(id);
Jeff Brown8d608662010-08-30 03:02:23 -0700398 }
399
400 /**
401 * Gets the ids of all input devices in the system.
402 * @return The input device ids.
403 */
404 public static int[] getDeviceIds() {
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700405 return InputManager.getInstance().getInputDeviceIds();
Jeff Brown8d608662010-08-30 03:02:23 -0700406 }
Jeff Brown9df6e7a2012-04-05 11:49:26 -0700407
Jeff Brown8d608662010-08-30 03:02:23 -0700408 /**
409 * Gets the input device id.
Jeff Brown9df6e7a2012-04-05 11:49:26 -0700410 * <p>
411 * Each input device receives a unique id when it is first configured
412 * by the system. The input device id may change when the system is restarted or if the
413 * input device is disconnected, reconnected or reconfigured at any time.
414 * If you require a stable identifier for a device that persists across
415 * boots and reconfigurations, use {@link #getDescriptor()}.
416 * </p>
417 *
Jeff Brown8d608662010-08-30 03:02:23 -0700418 * @return The input device id.
419 */
420 public int getId() {
421 return mId;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700422 }
Jeff Brown9df6e7a2012-04-05 11:49:26 -0700423
424 /**
Michael Wrightac6c78b2013-07-17 13:21:45 -0700425 * The controller number for a given input device.
426 * <p>
Michael Wright10fac452013-09-03 12:37:12 -0700427 * Each gamepad or joystick is given a unique, positive controller number when initially
428 * configured by the system. This number may change due to events such as device disconnects /
429 * reconnects or user initiated reassignment. Any change in number will trigger an event that
430 * can be observed by registering an {@link InputManager.InputDeviceListener}.
431 * </p>
432 * <p>
433 * All input devices which are not gamepads or joysticks will be assigned a controller number
Michael Wrightac6c78b2013-07-17 13:21:45 -0700434 * of 0.
435 * </p>
Michael Wright10fac452013-09-03 12:37:12 -0700436 *
437 * @return The controller number of the device.
Michael Wrightac6c78b2013-07-17 13:21:45 -0700438 */
439 public int getControllerNumber() {
440 return mControllerNumber;
441 }
442
443 /**
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700444 * Gets a generation number for this input device.
445 * The generation number is incremented whenever the device is reconfigured and its
446 * properties may have changed.
447 *
448 * @return The generation number.
449 *
450 * @hide
451 */
452 public int getGeneration() {
453 return mGeneration;
454 }
455
456 /**
Michael Wright54e56942013-08-12 16:39:59 -0700457 * Gets the vendor id for the given device, if available.
458 * <p>
459 * A vendor id uniquely identifies the company who manufactured the device. A value of 0 will
460 * be assigned where a vendor id is not available.
461 * </p>
462 *
463 * @return The vendor id of a given device
464 */
465 public int getVendorId() {
466 return mVendorId;
467 }
468
469 /**
470 * Gets the product id for the given device, if available.
471 * <p>
472 * A product id uniquely identifies which product within the address space of a given vendor,
473 * identified by the device's vendor id. A value of 0 will be assigned where a product id is
474 * not available.
475 * </p>
476 *
477 * @return The product id of a given device
478 */
479 public int getProductId() {
480 return mProductId;
481 }
482
483 /**
Jeff Brown9df6e7a2012-04-05 11:49:26 -0700484 * Gets the input device descriptor, which is a stable identifier for an input device.
485 * <p>
486 * An input device descriptor uniquely identifies an input device. Its value
487 * is intended to be persistent across system restarts, and should not change even
488 * if the input device is disconnected, reconnected or reconfigured at any time.
Jeff Browne38fdfa2012-04-06 14:51:01 -0700489 * </p><p>
490 * It is possible for there to be multiple {@link InputDevice} instances that have the
491 * same input device descriptor. This might happen in situations where a single
492 * human input device registers multiple {@link InputDevice} instances (HID collections)
493 * that describe separate features of the device, such as a keyboard that also
494 * has a trackpad. Alternately, it may be that the input devices are simply
495 * indistinguishable, such as two keyboards made by the same manufacturer.
496 * </p><p>
Jeff Browndaa37532012-05-01 15:54:03 -0700497 * The input device descriptor returned by {@link #getDescriptor} should only be
Jeff Browne38fdfa2012-04-06 14:51:01 -0700498 * used when an application needs to remember settings associated with a particular
499 * input device. For all other purposes when referring to a logical
500 * {@link InputDevice} instance at runtime use the id returned by {@link #getId()}.
Jeff Brown9df6e7a2012-04-05 11:49:26 -0700501 * </p>
502 *
503 * @return The input device descriptor.
504 */
505 public String getDescriptor() {
Jeff Browne38fdfa2012-04-06 14:51:01 -0700506 return mDescriptor;
Jeff Brown9df6e7a2012-04-05 11:49:26 -0700507 }
508
Jeff Brownc5ed5912010-07-14 18:48:53 -0700509 /**
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700510 * Returns true if the device is a virtual input device rather than a real one,
511 * such as the virtual keyboard (see {@link KeyCharacterMap#VIRTUAL_KEYBOARD}).
512 * <p>
513 * Virtual input devices are provided to implement system-level functionality
514 * and should not be seen or configured by users.
515 * </p>
516 *
517 * @return True if the device is virtual.
518 *
519 * @see KeyCharacterMap#VIRTUAL_KEYBOARD
520 */
521 public boolean isVirtual() {
522 return mId < 0;
523 }
524
525 /**
Jeff Browndaa37532012-05-01 15:54:03 -0700526 * Returns true if the device is external (connected to USB or Bluetooth or some other
527 * peripheral bus), otherwise it is built-in.
528 *
529 * @return True if the device is external.
530 *
531 * @hide
532 */
533 public boolean isExternal() {
534 return mIsExternal;
535 }
536
537 /**
Jeff Brown7e4ff4b2012-05-30 14:32:16 -0700538 * Returns true if the device is a full keyboard.
539 *
540 * @return True if the device is a full keyboard.
541 *
542 * @hide
543 */
544 public boolean isFullKeyboard() {
545 return (mSources & SOURCE_KEYBOARD) == SOURCE_KEYBOARD
546 && mKeyboardType == KEYBOARD_TYPE_ALPHABETIC;
547 }
548
549 /**
Jeff Brownc5ed5912010-07-14 18:48:53 -0700550 * Gets the name of this input device.
551 * @return The input device name.
552 */
553 public String getName() {
554 return mName;
555 }
556
557 /**
558 * Gets the input sources supported by this input device as a combined bitfield.
559 * @return The supported input sources.
560 */
561 public int getSources() {
562 return mSources;
563 }
564
565 /**
Jeff Brown6d0fec22010-07-23 21:28:06 -0700566 * Gets the keyboard type.
567 * @return The keyboard type.
568 */
569 public int getKeyboardType() {
570 return mKeyboardType;
571 }
572
573 /**
Jeff Brownc5ed5912010-07-14 18:48:53 -0700574 * Gets the key character map associated with this input device.
575 * @return The key character map.
576 */
577 public KeyCharacterMap getKeyCharacterMap() {
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700578 return mKeyCharacterMap;
Jeff Brown1e08fe92011-11-15 17:48:10 -0800579 }
580
Jeff Browne33348b2010-07-15 23:54:05 -0700581 /**
Michael Wrightb7b2d4b2013-08-19 15:55:38 -0700582 * Gets whether the device is capable of producing the list of keycodes.
583 * @param keys The list of android keycodes to check for.
584 * @return An array of booleans where each member specifies whether the device is capable of
585 * generating the keycode given by the corresponding value at the same index in the keys array.
586 */
587 public boolean[] hasKeys(int... keys) {
588 return InputManager.getInstance().deviceHasKeys(mId, keys);
589 }
590
591 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -0800592 * Gets information about the range of values for a particular {@link MotionEvent} axis.
Jeff Brownefd32662011-03-08 15:13:06 -0800593 * If the device supports multiple sources, the same axis may have different meanings
594 * for each source. Returns information about the first axis found for any source.
595 * To obtain information about the axis for a specific source, use
596 * {@link #getMotionRange(int, int)}.
597 *
Jeff Brown91c69ab2011-02-14 17:03:18 -0800598 * @param axis The axis constant.
599 * @return The range of values, or null if the requested axis is not
Jeff Browne33348b2010-07-15 23:54:05 -0700600 * supported by the device.
Jeff Brown91c69ab2011-02-14 17:03:18 -0800601 *
602 * @see MotionEvent#AXIS_X
603 * @see MotionEvent#AXIS_Y
Jeff Browne33348b2010-07-15 23:54:05 -0700604 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800605 public MotionRange getMotionRange(int axis) {
Jeff Brownefd32662011-03-08 15:13:06 -0800606 final int numRanges = mMotionRanges.size();
607 for (int i = 0; i < numRanges; i++) {
608 final MotionRange range = mMotionRanges.get(i);
609 if (range.mAxis == axis) {
610 return range;
611 }
612 }
613 return null;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700614 }
Jeff Brown91c69ab2011-02-14 17:03:18 -0800615
Jeff Brown6f2fba42011-02-19 01:08:02 -0800616 /**
Jeff Brownefd32662011-03-08 15:13:06 -0800617 * Gets information about the range of values for a particular {@link MotionEvent} axis
618 * used by a particular source on the device.
619 * If the device supports multiple sources, the same axis may have different meanings
620 * for each source.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800621 *
Jeff Brownefd32662011-03-08 15:13:06 -0800622 * @param axis The axis constant.
623 * @param source The source for which to return information.
624 * @return The range of values, or null if the requested axis is not
625 * supported by the device.
626 *
627 * @see MotionEvent#AXIS_X
628 * @see MotionEvent#AXIS_Y
Jeff Brown6f2fba42011-02-19 01:08:02 -0800629 */
Jeff Brownefd32662011-03-08 15:13:06 -0800630 public MotionRange getMotionRange(int axis, int source) {
631 final int numRanges = mMotionRanges.size();
632 for (int i = 0; i < numRanges; i++) {
633 final MotionRange range = mMotionRanges.get(i);
634 if (range.mAxis == axis && range.mSource == source) {
635 return range;
Jeff Brown6f2fba42011-02-19 01:08:02 -0800636 }
Jeff Brown6f2fba42011-02-19 01:08:02 -0800637 }
Jeff Brownefd32662011-03-08 15:13:06 -0800638 return null;
Jeff Brown6f2fba42011-02-19 01:08:02 -0800639 }
640
Jeff Brownefd32662011-03-08 15:13:06 -0800641 /**
642 * Gets the ranges for all axes supported by the device.
643 * @return The motion ranges for the device.
644 *
645 * @see #getMotionRange(int, int)
646 */
647 public List<MotionRange> getMotionRanges() {
648 return mMotionRanges;
649 }
650
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700651 // Called from native code.
Jeff Brownefd32662011-03-08 15:13:06 -0800652 private void addMotionRange(int axis, int source,
Michael Wrightc6091c62013-04-01 20:56:04 -0700653 float min, float max, float flat, float fuzz, float resolution) {
654 mMotionRanges.add(new MotionRange(axis, source, min, max, flat, fuzz, resolution));
Jeff Brownc5ed5912010-07-14 18:48:53 -0700655 }
Jeff Brown91c69ab2011-02-14 17:03:18 -0800656
Jeff Browne33348b2010-07-15 23:54:05 -0700657 /**
Jeff Browna47425a2012-04-13 04:09:27 -0700658 * Gets the vibrator service associated with the device, if there is one.
659 * Even if the device does not have a vibrator, the result is never null.
660 * Use {@link Vibrator#hasVibrator} to determine whether a vibrator is
661 * present.
662 *
663 * Note that the vibrator associated with the device may be different from
664 * the system vibrator. To obtain an instance of the system vibrator instead, call
665 * {@link Context#getSystemService} with {@link Context#VIBRATOR_SERVICE} as argument.
666 *
667 * @return The vibrator service associated with the device, never null.
668 */
669 public Vibrator getVibrator() {
670 synchronized (mMotionRanges) {
671 if (mVibrator == null) {
672 if (mHasVibrator) {
673 mVibrator = InputManager.getInstance().getInputDeviceVibrator(mId);
674 } else {
675 mVibrator = NullVibrator.getInstance();
676 }
677 }
678 return mVibrator;
679 }
680 }
681
682 /**
Michael Wright7ddd1102013-05-20 15:04:55 -0700683 * Reports whether the device has a button under its touchpad
684 * @return Whether the device has a button under its touchpad
685 * @hide
686 */
687 public boolean hasButtonUnderPad() {
688 return mHasButtonUnderPad;
689 }
690
691 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -0800692 * Provides information about the range of values for a particular {@link MotionEvent} axis.
693 *
694 * @see InputDevice#getMotionRange(int)
Jeff Browne33348b2010-07-15 23:54:05 -0700695 */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700696 public static final class MotionRange {
Jeff Brownefd32662011-03-08 15:13:06 -0800697 private int mAxis;
698 private int mSource;
Jeff Brown8d608662010-08-30 03:02:23 -0700699 private float mMin;
700 private float mMax;
701 private float mFlat;
702 private float mFuzz;
Michael Wrightc6091c62013-04-01 20:56:04 -0700703 private float mResolution;
Jeff Brown91c69ab2011-02-14 17:03:18 -0800704
Michael Wrightc6091c62013-04-01 20:56:04 -0700705 private MotionRange(int axis, int source, float min, float max, float flat, float fuzz,
706 float resolution) {
Jeff Brownefd32662011-03-08 15:13:06 -0800707 mAxis = axis;
708 mSource = source;
Jeff Brown8d608662010-08-30 03:02:23 -0700709 mMin = min;
710 mMax = max;
711 mFlat = flat;
712 mFuzz = fuzz;
Michael Wrightc6091c62013-04-01 20:56:04 -0700713 mResolution = resolution;
Jeff Brown8d608662010-08-30 03:02:23 -0700714 }
Jeff Brown91c69ab2011-02-14 17:03:18 -0800715
Jeff Browne33348b2010-07-15 23:54:05 -0700716 /**
Jeff Brownefd32662011-03-08 15:13:06 -0800717 * Gets the axis id.
718 * @return The axis id.
719 */
720 public int getAxis() {
721 return mAxis;
722 }
723
724 /**
725 * Gets the source for which the axis is defined.
726 * @return The source.
727 */
728 public int getSource() {
729 return mSource;
730 }
731
Michael Wright74e41562013-03-08 14:58:14 -0800732
733 /**
734 * Determines whether the event is from the given source.
735 *
736 * @param source The input source to check against. This can be a specific device type,
737 * such as {@link InputDevice#SOURCE_TOUCH_NAVIGATION}, or a more generic device class,
738 * such as {@link InputDevice#SOURCE_CLASS_POINTER}.
739 * @return Whether the event is from the given source.
740 */
741 public boolean isFromSource(int source) {
742 return (getSource() & source) == source;
743 }
744
Jeff Brownefd32662011-03-08 15:13:06 -0800745 /**
Jeff Brown6f2fba42011-02-19 01:08:02 -0800746 * Gets the inclusive minimum value for the axis.
747 * @return The inclusive minimum value.
Jeff Browne33348b2010-07-15 23:54:05 -0700748 */
749 public float getMin() {
Jeff Brown8d608662010-08-30 03:02:23 -0700750 return mMin;
Jeff Browne33348b2010-07-15 23:54:05 -0700751 }
Jeff Brown91c69ab2011-02-14 17:03:18 -0800752
Jeff Browne33348b2010-07-15 23:54:05 -0700753 /**
Jeff Brown6f2fba42011-02-19 01:08:02 -0800754 * Gets the inclusive maximum value for the axis.
755 * @return The inclusive maximum value.
Jeff Browne33348b2010-07-15 23:54:05 -0700756 */
757 public float getMax() {
Jeff Brown8d608662010-08-30 03:02:23 -0700758 return mMax;
Jeff Browne33348b2010-07-15 23:54:05 -0700759 }
Jeff Brown91c69ab2011-02-14 17:03:18 -0800760
Jeff Browne33348b2010-07-15 23:54:05 -0700761 /**
Jeff Brown6f2fba42011-02-19 01:08:02 -0800762 * Gets the range of the axis (difference between maximum and minimum).
Jeff Browne33348b2010-07-15 23:54:05 -0700763 * @return The range of values.
764 */
765 public float getRange() {
Jeff Brown6f2fba42011-02-19 01:08:02 -0800766 return mMax - 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 Brown91c69ab2011-02-14 17:03:18 -0800770 * Gets the extent of the center flat position with respect to this axis.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800771 * <p>
Jeff Browne33348b2010-07-15 23:54:05 -0700772 * For example, a flat value of 8 means that the center position is between -8 and +8.
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700773 * This value is mainly useful for calibrating self-centering devices.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800774 * </p>
Jeff Browne33348b2010-07-15 23:54:05 -0700775 * @return The extent of the center flat position.
776 */
777 public float getFlat() {
Jeff Brown8d608662010-08-30 03:02:23 -0700778 return mFlat;
Jeff Browne33348b2010-07-15 23:54:05 -0700779 }
Jeff Brown91c69ab2011-02-14 17:03:18 -0800780
Jeff Browne33348b2010-07-15 23:54:05 -0700781 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -0800782 * Gets the error tolerance for input device measurements with respect to this axis.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800783 * <p>
Jeff Browne33348b2010-07-15 23:54:05 -0700784 * For example, a value of 2 indicates that the measured value may be up to +/- 2 units
785 * away from the actual value due to noise and device sensitivity limitations.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800786 * </p>
Jeff Browne33348b2010-07-15 23:54:05 -0700787 * @return The error tolerance.
788 */
789 public float getFuzz() {
Jeff Brown8d608662010-08-30 03:02:23 -0700790 return mFuzz;
791 }
Michael Wrightc6091c62013-04-01 20:56:04 -0700792
793 /**
794 * Gets the resolution for input device measurements with respect to this axis.
795 * @return The resolution in units per millimeter, or units per radian for rotational axes.
796 */
797 public float getResolution() {
798 return mResolution;
799 }
Jeff Brown8d608662010-08-30 03:02:23 -0700800 }
Jeff Brown91c69ab2011-02-14 17:03:18 -0800801
Jeff Brown8d608662010-08-30 03:02:23 -0700802 @Override
803 public void writeToParcel(Parcel out, int flags) {
804 out.writeInt(mId);
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700805 out.writeInt(mGeneration);
Michael Wrightac6c78b2013-07-17 13:21:45 -0700806 out.writeInt(mControllerNumber);
Jeff Brown8d608662010-08-30 03:02:23 -0700807 out.writeString(mName);
Michael Wright54e56942013-08-12 16:39:59 -0700808 out.writeInt(mVendorId);
809 out.writeInt(mProductId);
Jeff Browne38fdfa2012-04-06 14:51:01 -0700810 out.writeString(mDescriptor);
Jeff Browndaa37532012-05-01 15:54:03 -0700811 out.writeInt(mIsExternal ? 1 : 0);
Jeff Brown8d608662010-08-30 03:02:23 -0700812 out.writeInt(mSources);
813 out.writeInt(mKeyboardType);
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700814 mKeyCharacterMap.writeToParcel(out, flags);
Jeff Browna47425a2012-04-13 04:09:27 -0700815 out.writeInt(mHasVibrator ? 1 : 0);
Michael Wright7ddd1102013-05-20 15:04:55 -0700816 out.writeInt(mHasButtonUnderPad ? 1 : 0);
Jeff Brown91c69ab2011-02-14 17:03:18 -0800817
Jeff Brownefd32662011-03-08 15:13:06 -0800818 final int numRanges = mMotionRanges.size();
819 for (int i = 0; i < numRanges; i++) {
820 MotionRange range = mMotionRanges.get(i);
821 out.writeInt(range.mAxis);
822 out.writeInt(range.mSource);
Jeff Brown91c69ab2011-02-14 17:03:18 -0800823 out.writeFloat(range.mMin);
824 out.writeFloat(range.mMax);
825 out.writeFloat(range.mFlat);
826 out.writeFloat(range.mFuzz);
Michael Wrightc6091c62013-04-01 20:56:04 -0700827 out.writeFloat(range.mResolution);
Jeff Brown8d608662010-08-30 03:02:23 -0700828 }
829 out.writeInt(-1);
830 }
Jeff Brown91c69ab2011-02-14 17:03:18 -0800831
Jeff Brown8d608662010-08-30 03:02:23 -0700832 @Override
833 public int describeContents() {
834 return 0;
835 }
Jeff Brown91c69ab2011-02-14 17:03:18 -0800836
Jeff Brown8d608662010-08-30 03:02:23 -0700837 @Override
838 public String toString() {
839 StringBuilder description = new StringBuilder();
840 description.append("Input Device ").append(mId).append(": ").append(mName).append("\n");
Jeff Browne38fdfa2012-04-06 14:51:01 -0700841 description.append(" Descriptor: ").append(mDescriptor).append("\n");
Jeff Brownaf9e8d32012-04-12 17:32:48 -0700842 description.append(" Generation: ").append(mGeneration).append("\n");
Jeff Browndaa37532012-05-01 15:54:03 -0700843 description.append(" Location: ").append(mIsExternal ? "external" : "built-in").append("\n");
Jeff Browne38fdfa2012-04-06 14:51:01 -0700844
Jeff Brown8d608662010-08-30 03:02:23 -0700845 description.append(" Keyboard Type: ");
846 switch (mKeyboardType) {
847 case KEYBOARD_TYPE_NONE:
848 description.append("none");
849 break;
850 case KEYBOARD_TYPE_NON_ALPHABETIC:
851 description.append("non-alphabetic");
852 break;
853 case KEYBOARD_TYPE_ALPHABETIC:
854 description.append("alphabetic");
855 break;
856 }
857 description.append("\n");
Jeff Brown91c69ab2011-02-14 17:03:18 -0800858
Jeff Browna47425a2012-04-13 04:09:27 -0700859 description.append(" Has Vibrator: ").append(mHasVibrator).append("\n");
860
Jeff Brownefd32662011-03-08 15:13:06 -0800861 description.append(" Sources: 0x").append(Integer.toHexString(mSources)).append(" (");
Jeff Brown8d608662010-08-30 03:02:23 -0700862 appendSourceDescriptionIfApplicable(description, SOURCE_KEYBOARD, "keyboard");
863 appendSourceDescriptionIfApplicable(description, SOURCE_DPAD, "dpad");
Jeff Brown8d608662010-08-30 03:02:23 -0700864 appendSourceDescriptionIfApplicable(description, SOURCE_TOUCHSCREEN, "touchscreen");
865 appendSourceDescriptionIfApplicable(description, SOURCE_MOUSE, "mouse");
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700866 appendSourceDescriptionIfApplicable(description, SOURCE_STYLUS, "stylus");
Jeff Brown8d608662010-08-30 03:02:23 -0700867 appendSourceDescriptionIfApplicable(description, SOURCE_TRACKBALL, "trackball");
868 appendSourceDescriptionIfApplicable(description, SOURCE_TOUCHPAD, "touchpad");
Jeff Brown91c69ab2011-02-14 17:03:18 -0800869 appendSourceDescriptionIfApplicable(description, SOURCE_JOYSTICK, "joystick");
870 appendSourceDescriptionIfApplicable(description, SOURCE_GAMEPAD, "gamepad");
871 description.append(" )\n");
872
873 final int numAxes = mMotionRanges.size();
874 for (int i = 0; i < numAxes; i++) {
Jeff Brownefd32662011-03-08 15:13:06 -0800875 MotionRange range = mMotionRanges.get(i);
876 description.append(" ").append(MotionEvent.axisToString(range.mAxis));
877 description.append(": source=0x").append(Integer.toHexString(range.mSource));
878 description.append(" min=").append(range.mMin);
Jeff Brown91c69ab2011-02-14 17:03:18 -0800879 description.append(" max=").append(range.mMax);
880 description.append(" flat=").append(range.mFlat);
881 description.append(" fuzz=").append(range.mFuzz);
Michael Wrightc6091c62013-04-01 20:56:04 -0700882 description.append(" resolution=").append(range.mResolution);
Jeff Brown91c69ab2011-02-14 17:03:18 -0800883 description.append("\n");
884 }
Jeff Brown8d608662010-08-30 03:02:23 -0700885 return description.toString();
886 }
Jeff Brown91c69ab2011-02-14 17:03:18 -0800887
Jeff Brown8d608662010-08-30 03:02:23 -0700888 private void appendSourceDescriptionIfApplicable(StringBuilder description, int source,
889 String sourceName) {
890 if ((mSources & source) == source) {
891 description.append(" ");
892 description.append(sourceName);
893 }
894 }
Jeff Brownc5ed5912010-07-14 18:48:53 -0700895}