blob: 8cb68f90ec4534f91551ae0aa7eccd44e7ffc20c [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 Brown8d608662010-08-30 03:02:23 -070019import android.os.Parcel;
20import android.os.Parcelable;
21import android.os.RemoteException;
22import android.os.ServiceManager;
Jeff Brownefd32662011-03-08 15:13:06 -080023
24import java.util.ArrayList;
25import java.util.List;
Jeff Brown8d608662010-08-30 03:02:23 -070026
Jeff Brownc5ed5912010-07-14 18:48:53 -070027/**
28 * Describes the capabilities of a particular input device.
29 * <p>
30 * Each input device may support multiple classes of input. For example, a multifunction
31 * keyboard may compose the capabilities of a standard keyboard together with a track pad mouse
32 * or other pointing device.
33 * </p><p>
Jeff Browndc1ab4b2010-09-14 18:03:38 -070034 * Some input devices present multiple distinguishable sources of input.
Jeff Brownc5ed5912010-07-14 18:48:53 -070035 * Applications can query the framework about the characteristics of each distinct source.
36 * </p><p>
37 * As a further wrinkle, different kinds of input sources uses different coordinate systems
38 * to describe motion events. Refer to the comments on the input source constants for
39 * the appropriate interpretation.
Jeff Brown6d0fec22010-07-23 21:28:06 -070040 * </p>
Jeff Brownc5ed5912010-07-14 18:48:53 -070041 */
Jeff Brown8d608662010-08-30 03:02:23 -070042public final class InputDevice implements Parcelable {
Jeff Brownc5ed5912010-07-14 18:48:53 -070043 private int mId;
44 private String mName;
45 private int mSources;
Jeff Brown6d0fec22010-07-23 21:28:06 -070046 private int mKeyboardType;
Jeff Brown91c69ab2011-02-14 17:03:18 -080047
Jeff Brownefd32662011-03-08 15:13:06 -080048 private final ArrayList<MotionRange> mMotionRanges = new ArrayList<MotionRange>();
Jeff Brown91c69ab2011-02-14 17:03:18 -080049
Jeff Brownc5ed5912010-07-14 18:48:53 -070050 /**
51 * A mask for input source classes.
52 *
53 * Each distinct input source constant has one or more input source class bits set to
54 * specify the desired interpretation for its input events.
55 */
56 public static final int SOURCE_CLASS_MASK = 0x000000ff;
57
58 /**
59 * The input source has buttons or keys.
Jeff Browndc1ab4b2010-09-14 18:03:38 -070060 * Examples: {@link #SOURCE_KEYBOARD}, {@link #SOURCE_DPAD}.
Jeff Brownc5ed5912010-07-14 18:48:53 -070061 *
62 * A {@link KeyEvent} should be interpreted as a button or key press.
63 *
Jeff Brown6eb5ac92010-08-30 23:29:07 -070064 * Use {@link #getKeyCharacterMap} to query the device's button and key mappings.
Jeff Brownc5ed5912010-07-14 18:48:53 -070065 */
66 public static final int SOURCE_CLASS_BUTTON = 0x00000001;
67
68 /**
69 * The input source is a pointing device associated with a display.
70 * Examples: {@link #SOURCE_TOUCHSCREEN}, {@link #SOURCE_MOUSE}.
71 *
72 * A {@link MotionEvent} should be interpreted as absolute coordinates in
73 * display units according to the {@link View} hierarchy. Pointer down/up indicated when
74 * the finger touches the display or when the selection button is pressed/released.
75 *
76 * Use {@link #getMotionRange} to query the range of the pointing device. Some devices permit
77 * touches outside the display area so the effective range may be somewhat smaller or larger
78 * than the actual display size.
79 */
80 public static final int SOURCE_CLASS_POINTER = 0x00000002;
81
82 /**
83 * The input source is a trackball navigation device.
84 * Examples: {@link #SOURCE_TRACKBALL}.
85 *
86 * A {@link MotionEvent} should be interpreted as relative movements in device-specific
87 * units used for navigation purposes. Pointer down/up indicates when the selection button
88 * is pressed/released.
89 *
90 * Use {@link #getMotionRange} to query the range of motion.
91 */
92 public static final int SOURCE_CLASS_TRACKBALL = 0x00000004;
93
94 /**
95 * The input source is an absolute positioning device not associated with a display
96 * (unlike {@link #SOURCE_CLASS_POINTER}).
97 *
98 * A {@link MotionEvent} should be interpreted as absolute coordinates in
99 * device-specific surface units.
100 *
101 * Use {@link #getMotionRange} to query the range of positions.
102 */
103 public static final int SOURCE_CLASS_POSITION = 0x00000008;
Jeff Browncb1404e2011-01-15 18:14:15 -0800104
105 /**
106 * The input source is a joystick.
107 *
108 * A {@link MotionEvent} should be interpreted as absolute joystick movements.
109 *
110 * Use {@link #getMotionRange} to query the range of positions.
111 */
112 public static final int SOURCE_CLASS_JOYSTICK = 0x00000010;
113
Jeff Brownc5ed5912010-07-14 18:48:53 -0700114 /**
Jeff Brownc5ed5912010-07-14 18:48:53 -0700115 * The input source is unknown.
116 */
117 public static final int SOURCE_UNKNOWN = 0x00000000;
118
119 /**
120 * The input source is a keyboard.
121 *
122 * @see #SOURCE_CLASS_BUTTON
123 */
124 public static final int SOURCE_KEYBOARD = 0x00000100 | SOURCE_CLASS_BUTTON;
125
126 /**
127 * The input source is a DPad.
128 *
129 * @see #SOURCE_CLASS_BUTTON
130 */
131 public static final int SOURCE_DPAD = 0x00000200 | SOURCE_CLASS_BUTTON;
Jeff Browncb1404e2011-01-15 18:14:15 -0800132
133 /**
134 * The input source is a game pad.
135 * (It may also be a {@link #SOURCE_JOYSTICK}).
136 *
137 * @see #SOURCE_CLASS_BUTTON
138 */
139 public static final int SOURCE_GAMEPAD = 0x00000400 | SOURCE_CLASS_BUTTON;
140
Jeff Brownc5ed5912010-07-14 18:48:53 -0700141 /**
Jeff Brownc5ed5912010-07-14 18:48:53 -0700142 * The input source is a touch screen pointing device.
143 *
144 * @see #SOURCE_CLASS_POINTER
145 */
146 public static final int SOURCE_TOUCHSCREEN = 0x00001000 | SOURCE_CLASS_POINTER;
147
148 /**
149 * The input source is a mouse pointing device.
150 * This code is also used for other mouse-like pointing devices such as trackpads
151 * and trackpoints.
152 *
153 * @see #SOURCE_CLASS_POINTER
154 */
155 public static final int SOURCE_MOUSE = 0x00002000 | SOURCE_CLASS_POINTER;
156
157 /**
158 * The input source is a trackball.
159 *
160 * @see #SOURCE_CLASS_TRACKBALL
161 */
162 public static final int SOURCE_TRACKBALL = 0x00010000 | SOURCE_CLASS_TRACKBALL;
163
164 /**
165 * The input source is a touch pad or digitizer tablet that is not
Jeff Browne33348b2010-07-15 23:54:05 -0700166 * associated with a display (unlike {@link #SOURCE_TOUCHSCREEN}).
Jeff Brownc5ed5912010-07-14 18:48:53 -0700167 *
168 * @see #SOURCE_CLASS_POSITION
169 */
170 public static final int SOURCE_TOUCHPAD = 0x00100000 | SOURCE_CLASS_POSITION;
Jeff Browncb1404e2011-01-15 18:14:15 -0800171
172 /**
173 * The input source is a joystick.
174 * (It may also be a {@link #SOURCE_GAMEPAD}).
175 *
176 * @see #SOURCE_CLASS_JOYSTICK
177 */
178 public static final int SOURCE_JOYSTICK = 0x01000000 | SOURCE_CLASS_JOYSTICK;
179
Jeff Brown6d0fec22010-07-23 21:28:06 -0700180 /**
181 * A special input source constant that is used when filtering input devices
182 * to match devices that provide any type of input source.
183 */
184 public static final int SOURCE_ANY = 0xffffff00;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700185
Jeff Browne33348b2010-07-15 23:54:05 -0700186 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -0800187 * Constant for retrieving the range of values for {@link MotionEvent#AXIS_X}.
Jeff Browne33348b2010-07-15 23:54:05 -0700188 *
189 * @see #getMotionRange
Jeff Brown91c69ab2011-02-14 17:03:18 -0800190 * @deprecated Use {@link MotionEvent#AXIS_X} instead.
Jeff Browne33348b2010-07-15 23:54:05 -0700191 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800192 @Deprecated
193 public static final int MOTION_RANGE_X = MotionEvent.AXIS_X;
194
Jeff Browne33348b2010-07-15 23:54:05 -0700195 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -0800196 * Constant for retrieving the range of values for {@link MotionEvent#AXIS_Y}.
Jeff Browne33348b2010-07-15 23:54:05 -0700197 *
198 * @see #getMotionRange
Jeff Brown91c69ab2011-02-14 17:03:18 -0800199 * @deprecated Use {@link MotionEvent#AXIS_Y} instead.
Jeff Browne33348b2010-07-15 23:54:05 -0700200 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800201 @Deprecated
202 public static final int MOTION_RANGE_Y = MotionEvent.AXIS_Y;
203
Jeff Browne33348b2010-07-15 23:54:05 -0700204 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -0800205 * Constant for retrieving the range of values for {@link MotionEvent#AXIS_PRESSURE}.
Jeff Browne33348b2010-07-15 23:54:05 -0700206 *
207 * @see #getMotionRange
Jeff Brown91c69ab2011-02-14 17:03:18 -0800208 * @deprecated Use {@link MotionEvent#AXIS_PRESSURE} instead.
Jeff Browne33348b2010-07-15 23:54:05 -0700209 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800210 @Deprecated
211 public static final int MOTION_RANGE_PRESSURE = MotionEvent.AXIS_PRESSURE;
212
Jeff Browne33348b2010-07-15 23:54:05 -0700213 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -0800214 * Constant for retrieving the range of values for {@link MotionEvent#AXIS_SIZE}.
Jeff Browne33348b2010-07-15 23:54:05 -0700215 *
216 * @see #getMotionRange
Jeff Brown91c69ab2011-02-14 17:03:18 -0800217 * @deprecated Use {@link MotionEvent#AXIS_SIZE} instead.
Jeff Browne33348b2010-07-15 23:54:05 -0700218 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800219 @Deprecated
220 public static final int MOTION_RANGE_SIZE = MotionEvent.AXIS_SIZE;
221
Jeff Browne33348b2010-07-15 23:54:05 -0700222 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -0800223 * Constant for retrieving the range of values for {@link MotionEvent#AXIS_TOUCH_MAJOR}.
Jeff Browne33348b2010-07-15 23:54:05 -0700224 *
225 * @see #getMotionRange
Jeff Brown91c69ab2011-02-14 17:03:18 -0800226 * @deprecated Use {@link MotionEvent#AXIS_TOUCH_MAJOR} instead.
Jeff Browne33348b2010-07-15 23:54:05 -0700227 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800228 @Deprecated
229 public static final int MOTION_RANGE_TOUCH_MAJOR = MotionEvent.AXIS_TOUCH_MAJOR;
230
Jeff Browne33348b2010-07-15 23:54:05 -0700231 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -0800232 * Constant for retrieving the range of values for {@link MotionEvent#AXIS_TOUCH_MINOR}.
Jeff Browne33348b2010-07-15 23:54:05 -0700233 *
234 * @see #getMotionRange
Jeff Brown91c69ab2011-02-14 17:03:18 -0800235 * @deprecated Use {@link MotionEvent#AXIS_TOUCH_MINOR} instead.
Jeff Browne33348b2010-07-15 23:54:05 -0700236 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800237 @Deprecated
238 public static final int MOTION_RANGE_TOUCH_MINOR = MotionEvent.AXIS_TOUCH_MINOR;
239
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_TOOL_MAJOR}.
Jeff Browne33348b2010-07-15 23:54:05 -0700242 *
243 * @see #getMotionRange
Jeff Brown91c69ab2011-02-14 17:03:18 -0800244 * @deprecated Use {@link MotionEvent#AXIS_TOOL_MAJOR} 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_TOOL_MAJOR = MotionEvent.AXIS_TOOL_MAJOR;
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_TOOL_MINOR}.
Jeff Browne33348b2010-07-15 23:54:05 -0700251 *
252 * @see #getMotionRange
Jeff Brown91c69ab2011-02-14 17:03:18 -0800253 * @deprecated Use {@link MotionEvent#AXIS_TOOL_MINOR} 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_TOOL_MINOR = MotionEvent.AXIS_TOOL_MINOR;
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_ORIENTATION}.
Jeff Browne33348b2010-07-15 23:54:05 -0700260 *
261 * @see #getMotionRange
Jeff Brown91c69ab2011-02-14 17:03:18 -0800262 * @deprecated Use {@link MotionEvent#AXIS_ORIENTATION} 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_ORIENTATION = MotionEvent.AXIS_ORIENTATION;
Jeff Brown8d608662010-08-30 03:02:23 -0700266
Jeff Brown6d0fec22010-07-23 21:28:06 -0700267 /**
268 * There is no keyboard.
269 */
270 public static final int KEYBOARD_TYPE_NONE = 0;
271
272 /**
273 * The keyboard is not fully alphabetic. It may be a numeric keypad or an assortment
274 * of buttons that are not mapped as alphabetic keys suitable for text input.
275 */
276 public static final int KEYBOARD_TYPE_NON_ALPHABETIC = 1;
277
278 /**
279 * The keyboard supports a complement of alphabetic keys.
280 */
281 public static final int KEYBOARD_TYPE_ALPHABETIC = 2;
Jeff Brown91c69ab2011-02-14 17:03:18 -0800282
Jeff Brown8d608662010-08-30 03:02:23 -0700283 // Called by native code.
284 private InputDevice() {
Jeff Brown8d608662010-08-30 03:02:23 -0700285 }
Jeff Browne33348b2010-07-15 23:54:05 -0700286
287 /**
288 * Gets information about the input device with the specified id.
289 * @param id The device id.
290 * @return The input device or null if not found.
291 */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700292 public static InputDevice getDevice(int id) {
Dianne Hackborn44bc17c2011-04-20 18:18:51 -0700293 IWindowManager wm = Display.getWindowManager();
Jeff Brown8d608662010-08-30 03:02:23 -0700294 try {
295 return wm.getInputDevice(id);
296 } catch (RemoteException ex) {
297 throw new RuntimeException(
298 "Could not get input device information from Window Manager.", ex);
299 }
300 }
301
302 /**
303 * Gets the ids of all input devices in the system.
304 * @return The input device ids.
305 */
306 public static int[] getDeviceIds() {
Dianne Hackborn44bc17c2011-04-20 18:18:51 -0700307 IWindowManager wm = Display.getWindowManager();
Jeff Brown8d608662010-08-30 03:02:23 -0700308 try {
309 return wm.getInputDeviceIds();
310 } catch (RemoteException ex) {
311 throw new RuntimeException(
312 "Could not get input device ids from Window Manager.", ex);
313 }
314 }
315
316 /**
317 * Gets the input device id.
318 * @return The input device id.
319 */
320 public int getId() {
321 return mId;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700322 }
Jeff Brownc5ed5912010-07-14 18:48:53 -0700323
324 /**
325 * Gets the name of this input device.
326 * @return The input device name.
327 */
328 public String getName() {
329 return mName;
330 }
331
332 /**
333 * Gets the input sources supported by this input device as a combined bitfield.
334 * @return The supported input sources.
335 */
336 public int getSources() {
337 return mSources;
338 }
339
340 /**
Jeff Brown6d0fec22010-07-23 21:28:06 -0700341 * Gets the keyboard type.
342 * @return The keyboard type.
343 */
344 public int getKeyboardType() {
345 return mKeyboardType;
346 }
347
348 /**
Jeff Brownc5ed5912010-07-14 18:48:53 -0700349 * Gets the key character map associated with this input device.
350 * @return The key character map.
351 */
352 public KeyCharacterMap getKeyCharacterMap() {
353 return KeyCharacterMap.load(mId);
354 }
Jeff Brown91c69ab2011-02-14 17:03:18 -0800355
Jeff Browne33348b2010-07-15 23:54:05 -0700356 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -0800357 * Gets information about the range of values for a particular {@link MotionEvent} axis.
Jeff Brownefd32662011-03-08 15:13:06 -0800358 * If the device supports multiple sources, the same axis may have different meanings
359 * for each source. Returns information about the first axis found for any source.
360 * To obtain information about the axis for a specific source, use
361 * {@link #getMotionRange(int, int)}.
362 *
Jeff Brown91c69ab2011-02-14 17:03:18 -0800363 * @param axis The axis constant.
364 * @return The range of values, or null if the requested axis is not
Jeff Browne33348b2010-07-15 23:54:05 -0700365 * supported by the device.
Jeff Brown91c69ab2011-02-14 17:03:18 -0800366 *
367 * @see MotionEvent#AXIS_X
368 * @see MotionEvent#AXIS_Y
Jeff Brown6f2fba42011-02-19 01:08:02 -0800369 * @see #getSupportedAxes()
Jeff Browne33348b2010-07-15 23:54:05 -0700370 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800371 public MotionRange getMotionRange(int axis) {
Jeff Brownefd32662011-03-08 15:13:06 -0800372 final int numRanges = mMotionRanges.size();
373 for (int i = 0; i < numRanges; i++) {
374 final MotionRange range = mMotionRanges.get(i);
375 if (range.mAxis == axis) {
376 return range;
377 }
378 }
379 return null;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700380 }
Jeff Brown91c69ab2011-02-14 17:03:18 -0800381
Jeff Brown6f2fba42011-02-19 01:08:02 -0800382 /**
Jeff Brownefd32662011-03-08 15:13:06 -0800383 * Gets information about the range of values for a particular {@link MotionEvent} axis
384 * used by a particular source on the device.
385 * If the device supports multiple sources, the same axis may have different meanings
386 * for each source.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800387 *
Jeff Brownefd32662011-03-08 15:13:06 -0800388 * @param axis The axis constant.
389 * @param source The source for which to return information.
390 * @return The range of values, or null if the requested axis is not
391 * supported by the device.
392 *
393 * @see MotionEvent#AXIS_X
394 * @see MotionEvent#AXIS_Y
395 * @see #getSupportedAxes()
Jeff Brown6f2fba42011-02-19 01:08:02 -0800396 */
Jeff Brownefd32662011-03-08 15:13:06 -0800397 public MotionRange getMotionRange(int axis, int source) {
398 final int numRanges = mMotionRanges.size();
399 for (int i = 0; i < numRanges; i++) {
400 final MotionRange range = mMotionRanges.get(i);
401 if (range.mAxis == axis && range.mSource == source) {
402 return range;
Jeff Brown6f2fba42011-02-19 01:08:02 -0800403 }
Jeff Brown6f2fba42011-02-19 01:08:02 -0800404 }
Jeff Brownefd32662011-03-08 15:13:06 -0800405 return null;
Jeff Brown6f2fba42011-02-19 01:08:02 -0800406 }
407
Jeff Brownefd32662011-03-08 15:13:06 -0800408 /**
409 * Gets the ranges for all axes supported by the device.
410 * @return The motion ranges for the device.
411 *
412 * @see #getMotionRange(int, int)
413 */
414 public List<MotionRange> getMotionRanges() {
415 return mMotionRanges;
416 }
417
418 private void addMotionRange(int axis, int source,
419 float min, float max, float flat, float fuzz) {
420 mMotionRanges.add(new MotionRange(axis, source, min, max, flat, fuzz));
Jeff Brownc5ed5912010-07-14 18:48:53 -0700421 }
Jeff Brown91c69ab2011-02-14 17:03:18 -0800422
Jeff Browne33348b2010-07-15 23:54:05 -0700423 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -0800424 * Provides information about the range of values for a particular {@link MotionEvent} axis.
425 *
426 * @see InputDevice#getMotionRange(int)
Jeff Browne33348b2010-07-15 23:54:05 -0700427 */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700428 public static final class MotionRange {
Jeff Brownefd32662011-03-08 15:13:06 -0800429 private int mAxis;
430 private int mSource;
Jeff Brown8d608662010-08-30 03:02:23 -0700431 private float mMin;
432 private float mMax;
433 private float mFlat;
434 private float mFuzz;
Jeff Brown91c69ab2011-02-14 17:03:18 -0800435
Jeff Brownefd32662011-03-08 15:13:06 -0800436 private MotionRange(int axis, int source, float min, float max, float flat, float fuzz) {
437 mAxis = axis;
438 mSource = source;
Jeff Brown8d608662010-08-30 03:02:23 -0700439 mMin = min;
440 mMax = max;
441 mFlat = flat;
442 mFuzz = fuzz;
443 }
Jeff Brown91c69ab2011-02-14 17:03:18 -0800444
Jeff Browne33348b2010-07-15 23:54:05 -0700445 /**
Jeff Brownefd32662011-03-08 15:13:06 -0800446 * Gets the axis id.
447 * @return The axis id.
448 */
449 public int getAxis() {
450 return mAxis;
451 }
452
453 /**
454 * Gets the source for which the axis is defined.
455 * @return The source.
456 */
457 public int getSource() {
458 return mSource;
459 }
460
461 /**
Jeff Brown6f2fba42011-02-19 01:08:02 -0800462 * Gets the inclusive minimum value for the axis.
463 * @return The inclusive minimum value.
Jeff Browne33348b2010-07-15 23:54:05 -0700464 */
465 public float getMin() {
Jeff Brown8d608662010-08-30 03:02:23 -0700466 return mMin;
Jeff Browne33348b2010-07-15 23:54:05 -0700467 }
Jeff Brown91c69ab2011-02-14 17:03:18 -0800468
Jeff Browne33348b2010-07-15 23:54:05 -0700469 /**
Jeff Brown6f2fba42011-02-19 01:08:02 -0800470 * Gets the inclusive maximum value for the axis.
471 * @return The inclusive maximum value.
Jeff Browne33348b2010-07-15 23:54:05 -0700472 */
473 public float getMax() {
Jeff Brown8d608662010-08-30 03:02:23 -0700474 return mMax;
Jeff Browne33348b2010-07-15 23:54:05 -0700475 }
Jeff Brown91c69ab2011-02-14 17:03:18 -0800476
Jeff Browne33348b2010-07-15 23:54:05 -0700477 /**
Jeff Brown6f2fba42011-02-19 01:08:02 -0800478 * Gets the range of the axis (difference between maximum and minimum).
Jeff Browne33348b2010-07-15 23:54:05 -0700479 * @return The range of values.
480 */
481 public float getRange() {
Jeff Brown6f2fba42011-02-19 01:08:02 -0800482 return mMax - mMin;
Jeff Browne33348b2010-07-15 23:54:05 -0700483 }
Jeff Brown91c69ab2011-02-14 17:03:18 -0800484
Jeff Browne33348b2010-07-15 23:54:05 -0700485 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -0800486 * Gets the extent of the center flat position with respect to this axis.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800487 * <p>
Jeff Browne33348b2010-07-15 23:54:05 -0700488 * For example, a flat value of 8 means that the center position is between -8 and +8.
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700489 * This value is mainly useful for calibrating self-centering devices.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800490 * </p>
Jeff Browne33348b2010-07-15 23:54:05 -0700491 * @return The extent of the center flat position.
492 */
493 public float getFlat() {
Jeff Brown8d608662010-08-30 03:02:23 -0700494 return mFlat;
Jeff Browne33348b2010-07-15 23:54:05 -0700495 }
Jeff Brown91c69ab2011-02-14 17:03:18 -0800496
Jeff Browne33348b2010-07-15 23:54:05 -0700497 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -0800498 * Gets the error tolerance for input device measurements with respect to this axis.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800499 * <p>
Jeff Browne33348b2010-07-15 23:54:05 -0700500 * For example, a value of 2 indicates that the measured value may be up to +/- 2 units
501 * away from the actual value due to noise and device sensitivity limitations.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800502 * </p>
Jeff Browne33348b2010-07-15 23:54:05 -0700503 * @return The error tolerance.
504 */
505 public float getFuzz() {
Jeff Brown8d608662010-08-30 03:02:23 -0700506 return mFuzz;
507 }
508 }
Jeff Brown91c69ab2011-02-14 17:03:18 -0800509
Jeff Brown8d608662010-08-30 03:02:23 -0700510 public static final Parcelable.Creator<InputDevice> CREATOR
511 = new Parcelable.Creator<InputDevice>() {
512 public InputDevice createFromParcel(Parcel in) {
513 InputDevice result = new InputDevice();
514 result.readFromParcel(in);
515 return result;
516 }
517
518 public InputDevice[] newArray(int size) {
519 return new InputDevice[size];
520 }
521 };
522
523 private void readFromParcel(Parcel in) {
524 mId = in.readInt();
525 mName = in.readString();
526 mSources = in.readInt();
527 mKeyboardType = in.readInt();
Jeff Brown91c69ab2011-02-14 17:03:18 -0800528
Jeff Brown8d608662010-08-30 03:02:23 -0700529 for (;;) {
Jeff Brown91c69ab2011-02-14 17:03:18 -0800530 int axis = in.readInt();
531 if (axis < 0) {
Jeff Brown8d608662010-08-30 03:02:23 -0700532 break;
533 }
Jeff Brownefd32662011-03-08 15:13:06 -0800534 addMotionRange(axis, in.readInt(),
535 in.readFloat(), in.readFloat(), in.readFloat(), in.readFloat());
Jeff Brown8d608662010-08-30 03:02:23 -0700536 }
537 }
538
539 @Override
540 public void writeToParcel(Parcel out, int flags) {
541 out.writeInt(mId);
542 out.writeString(mName);
543 out.writeInt(mSources);
544 out.writeInt(mKeyboardType);
Jeff Brown91c69ab2011-02-14 17:03:18 -0800545
Jeff Brownefd32662011-03-08 15:13:06 -0800546 final int numRanges = mMotionRanges.size();
547 for (int i = 0; i < numRanges; i++) {
548 MotionRange range = mMotionRanges.get(i);
549 out.writeInt(range.mAxis);
550 out.writeInt(range.mSource);
Jeff Brown91c69ab2011-02-14 17:03:18 -0800551 out.writeFloat(range.mMin);
552 out.writeFloat(range.mMax);
553 out.writeFloat(range.mFlat);
554 out.writeFloat(range.mFuzz);
Jeff Brown8d608662010-08-30 03:02:23 -0700555 }
556 out.writeInt(-1);
557 }
Jeff Brown91c69ab2011-02-14 17:03:18 -0800558
Jeff Brown8d608662010-08-30 03:02:23 -0700559 @Override
560 public int describeContents() {
561 return 0;
562 }
Jeff Brown91c69ab2011-02-14 17:03:18 -0800563
Jeff Brown8d608662010-08-30 03:02:23 -0700564 @Override
565 public String toString() {
566 StringBuilder description = new StringBuilder();
567 description.append("Input Device ").append(mId).append(": ").append(mName).append("\n");
568
569 description.append(" Keyboard Type: ");
570 switch (mKeyboardType) {
571 case KEYBOARD_TYPE_NONE:
572 description.append("none");
573 break;
574 case KEYBOARD_TYPE_NON_ALPHABETIC:
575 description.append("non-alphabetic");
576 break;
577 case KEYBOARD_TYPE_ALPHABETIC:
578 description.append("alphabetic");
579 break;
580 }
581 description.append("\n");
Jeff Brown91c69ab2011-02-14 17:03:18 -0800582
Jeff Brownefd32662011-03-08 15:13:06 -0800583 description.append(" Sources: 0x").append(Integer.toHexString(mSources)).append(" (");
Jeff Brown8d608662010-08-30 03:02:23 -0700584 appendSourceDescriptionIfApplicable(description, SOURCE_KEYBOARD, "keyboard");
585 appendSourceDescriptionIfApplicable(description, SOURCE_DPAD, "dpad");
Jeff Brown8d608662010-08-30 03:02:23 -0700586 appendSourceDescriptionIfApplicable(description, SOURCE_TOUCHSCREEN, "touchscreen");
587 appendSourceDescriptionIfApplicable(description, SOURCE_MOUSE, "mouse");
588 appendSourceDescriptionIfApplicable(description, SOURCE_TRACKBALL, "trackball");
589 appendSourceDescriptionIfApplicable(description, SOURCE_TOUCHPAD, "touchpad");
Jeff Brown91c69ab2011-02-14 17:03:18 -0800590 appendSourceDescriptionIfApplicable(description, SOURCE_JOYSTICK, "joystick");
591 appendSourceDescriptionIfApplicable(description, SOURCE_GAMEPAD, "gamepad");
592 description.append(" )\n");
593
594 final int numAxes = mMotionRanges.size();
595 for (int i = 0; i < numAxes; i++) {
Jeff Brownefd32662011-03-08 15:13:06 -0800596 MotionRange range = mMotionRanges.get(i);
597 description.append(" ").append(MotionEvent.axisToString(range.mAxis));
598 description.append(": source=0x").append(Integer.toHexString(range.mSource));
599 description.append(" min=").append(range.mMin);
Jeff Brown91c69ab2011-02-14 17:03:18 -0800600 description.append(" max=").append(range.mMax);
601 description.append(" flat=").append(range.mFlat);
602 description.append(" fuzz=").append(range.mFuzz);
603 description.append("\n");
604 }
Jeff Brown8d608662010-08-30 03:02:23 -0700605 return description.toString();
606 }
Jeff Brown91c69ab2011-02-14 17:03:18 -0800607
Jeff Brown8d608662010-08-30 03:02:23 -0700608 private void appendSourceDescriptionIfApplicable(StringBuilder description, int source,
609 String sourceName) {
610 if ((mSources & source) == source) {
611 description.append(" ");
612 description.append(sourceName);
613 }
614 }
Jeff Brownc5ed5912010-07-14 18:48:53 -0700615}