blob: a17db5d42a4b8346ccb024e9e3ad2d94b249314b [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 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 Brown20e987b2010-08-23 12:01:02 -070019import android.graphics.Matrix;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080020import android.os.Parcel;
21import android.os.Parcelable;
22import android.os.SystemClock;
Jeff Brown6f2fba42011-02-19 01:08:02 -080023import android.util.SparseArray;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024
25/**
26 * Object used to report movement (mouse, pen, finger, trackball) events. This
27 * class may hold either absolute or relative movements, depending on what
28 * it is being used for.
Jeff Browndc1ab4b2010-09-14 18:03:38 -070029 * <p>
Jeff Browncb1404e2011-01-15 18:14:15 -080030 * On pointing devices with source class {@link InputDevice#SOURCE_CLASS_POINTER}
31 * such as touch screens, the pointer coordinates specify absolute
Jeff Browndc1ab4b2010-09-14 18:03:38 -070032 * positions such as view X/Y coordinates. Each complete gesture is represented
33 * by a sequence of motion events with actions that describe pointer state transitions
34 * and movements. A gesture starts with a motion event with {@link #ACTION_DOWN}
35 * that provides the location of the first pointer down. As each additional
36 * pointer that goes down or up, the framework will generate a motion event with
37 * {@link #ACTION_POINTER_DOWN} or {@link #ACTION_POINTER_UP} accordingly.
38 * Pointer movements are described by motion events with {@link #ACTION_MOVE}.
39 * Finally, a gesture end either when the final pointer goes up as represented
40 * by a motion event with {@link #ACTION_UP} or when gesture is canceled
41 * with {@link #ACTION_CANCEL}.
42 * </p><p>
Jeff Brown33bbfd22011-02-24 20:55:35 -080043 * Some pointing devices such as mice may support vertical and/or horizontal scrolling.
44 * A scroll event is reported as a generic motion event with {@link #ACTION_SCROLL} that
45 * includes the relative scroll offset in the {@link #AXIS_VSCROLL} and
46 * {@link #AXIS_HSCROLL} axes. See {@link #getAxisValue(int)} for information
47 * about retrieving these additional axes.
48 * </p><p>
Jeff Browncb1404e2011-01-15 18:14:15 -080049 * On trackball devices with source class {@link InputDevice#SOURCE_CLASS_TRACKBALL},
50 * the pointer coordinates specify relative movements as X/Y deltas.
Jeff Browndc1ab4b2010-09-14 18:03:38 -070051 * A trackball gesture consists of a sequence of movements described by motion
52 * events with {@link #ACTION_MOVE} interspersed with occasional {@link #ACTION_DOWN}
53 * or {@link #ACTION_UP} motion events when the trackball button is pressed or released.
54 * </p><p>
Jeff Browncb1404e2011-01-15 18:14:15 -080055 * On joystick devices with source class {@link InputDevice#SOURCE_CLASS_JOYSTICK},
56 * the pointer coordinates specify the absolute position of the joystick axes.
57 * The joystick axis values are normalized to a range of -1.0 to 1.0 where 0.0 corresponds
58 * to the center position. More information about the set of available axes and the
59 * range of motion can be obtained using {@link InputDevice#getMotionRange}.
Jeff Brown33bbfd22011-02-24 20:55:35 -080060 * Some common joystick axes are {@link #AXIS_X}, {@link #AXIS_Y},
61 * {@link #AXIS_HAT_X}, {@link #AXIS_HAT_Y}, {@link #AXIS_Z} and {@link #AXIS_RZ}.
Jeff Browncb1404e2011-01-15 18:14:15 -080062 * </p><p>
Jeff Browndc1ab4b2010-09-14 18:03:38 -070063 * Motion events always report movements for all pointers at once. The number
64 * of pointers only ever changes by one as individual pointers go up and down,
65 * except when the gesture is canceled.
66 * </p><p>
67 * The order in which individual pointers appear within a motion event can change
68 * from one event to the next. Use the {@link #getPointerId(int)} method to obtain a
69 * pointer id to track pointers across motion events in a gesture. Then for
70 * successive motion events, use the {@link #findPointerIndex(int)} method to obtain
71 * the pointer index for a given pointer id in that motion event.
72 * </p><p>
73 * For efficiency, motion events with {@link #ACTION_MOVE} may batch together
74 * multiple movement samples within a single object. The most current
75 * pointer coordinates are available using {@link #getX(int)} and {@link #getY(int)}.
76 * Earlier coordinates within the batch are accessed using {@link #getHistoricalX(int, int)}
77 * and {@link #getHistoricalY(int, int)}. The coordinates are "historical" only
78 * insofar as they are older than the current coordinates in the batch; however,
79 * they are still distinct from any other coordinates reported in prior motion events.
80 * To process all coordinates in the batch in time order, first consume the historical
81 * coordinates then consume the current coordinates.
82 * </p><p>
83 * Example: Consuming all samples for all pointers in a motion event in time order.
84 * </p><p><pre><code>
85 * void printSamples(MotionEvent ev) {
86 * final int historySize = ev.getHistorySize();
87 * final int pointerCount = ev.getPointerCount();
88 * for (int h = 0; h &lt; historySize; h++) {
89 * System.out.printf("At time %d:", ev.getHistoricalEventTime(h));
90 * for (int p = 0; p &lt; pointerCount; p++) {
91 * System.out.printf(" pointer %d: (%f,%f)",
92 * ev.getPointerId(p), ev.getHistoricalX(p, h), ev.getHistoricalY(p, h));
93 * }
94 * }
95 * System.out.printf("At time %d:", ev.getEventTime());
96 * for (int p = 0; p &lt; pointerCount; p++) {
97 * System.out.printf(" pointer %d: (%f,%f)",
98 * ev.getPointerId(p), ev.getX(p), ev.getY(p));
99 * }
100 * }
101 * </code></pre></p><p>
Jeff Brownb6997262010-10-08 22:31:17 -0700102 * In general, the framework cannot guarantee that the motion events it delivers
103 * to a view always constitute a complete motion sequences since some events may be dropped
104 * or modified by containing views before they are delivered. The view implementation
105 * should be prepared to handle {@link #ACTION_CANCEL} and should tolerate anomalous
106 * situations such as receiving a new {@link #ACTION_DOWN} without first having
107 * received an {@link #ACTION_UP} for the prior gesture.
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700108 * </p><p>
109 * Refer to {@link InputDevice} for more information about how different kinds of
Jeff Brownc5ed5912010-07-14 18:48:53 -0700110 * input devices and sources represent pointer coordinates.
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700111 * </p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800112 */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700113public final class MotionEvent extends InputEvent implements Parcelable {
Jeff Brown91c69ab2011-02-14 17:03:18 -0800114 private static final long NS_PER_MS = 1000000;
Jeff Brown85a31762010-09-01 17:01:00 -0700115 private static final boolean TRACK_RECYCLED_LOCATION = false;
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700116
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800117 /**
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700118 * Bit mask of the parts of the action code that are the action itself.
119 */
120 public static final int ACTION_MASK = 0xff;
121
122 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800123 * Constant for {@link #getAction}: A pressed gesture has started, the
124 * motion contains the initial starting location.
125 */
126 public static final int ACTION_DOWN = 0;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700127
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800128 /**
129 * Constant for {@link #getAction}: A pressed gesture has finished, the
130 * motion contains the final release location as well as any intermediate
131 * points since the last down or move event.
132 */
133 public static final int ACTION_UP = 1;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700134
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800135 /**
136 * Constant for {@link #getAction}: A change has happened during a
137 * press gesture (between {@link #ACTION_DOWN} and {@link #ACTION_UP}).
138 * The motion contains the most recent point, as well as any intermediate
139 * points since the last down or move event.
140 */
141 public static final int ACTION_MOVE = 2;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700142
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800143 /**
144 * Constant for {@link #getAction}: The current gesture has been aborted.
145 * You will not receive any more points in it. You should treat this as
146 * an up event, but not perform any action that you normally would.
147 */
148 public static final int ACTION_CANCEL = 3;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700149
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800150 /**
151 * Constant for {@link #getAction}: A movement has happened outside of the
152 * normal bounds of the UI element. This does not provide a full gesture,
153 * but only the initial location of the movement/touch.
154 */
155 public static final int ACTION_OUTSIDE = 4;
156
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700157 /**
158 * A non-primary pointer has gone down. The bits in
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700159 * {@link #ACTION_POINTER_ID_MASK} indicate which pointer changed.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700160 */
161 public static final int ACTION_POINTER_DOWN = 5;
162
163 /**
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700164 * A non-primary pointer has gone up. The bits in
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700165 * {@link #ACTION_POINTER_ID_MASK} indicate which pointer changed.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700166 */
167 public static final int ACTION_POINTER_UP = 6;
Jeff Browncc0c1592011-02-19 05:07:28 -0800168
169 /**
170 * Constant for {@link #getAction}: A change happened but the pointer
171 * is not down (unlike {@link #ACTION_MOVE}). The motion contains the most
172 * recent point, as well as any intermediate points since the last
173 * hover move event.
Jeff Brown33bbfd22011-02-24 20:55:35 -0800174 * <p>
175 * This action is not a touch event so it is delivered to
176 * {@link View#onGenericMotionEvent(MotionEvent)} rather than
177 * {@link View#onTouchEvent(MotionEvent)}.
178 * </p>
Jeff Browncc0c1592011-02-19 05:07:28 -0800179 */
180 public static final int ACTION_HOVER_MOVE = 7;
181
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700182 /**
Jeff Brown33bbfd22011-02-24 20:55:35 -0800183 * Constant for {@link #getAction}: The motion event contains relative
184 * vertical and/or horizontal scroll offsets. Use {@link #getAxisValue(int)}
185 * to retrieve the information from {@link #AXIS_VSCROLL} and {@link #AXIS_HSCROLL}.
186 * The pointer may or may not be down when this event is dispatched.
187 * This action is always delivered to the winder under the pointer, which
188 * may not be the window currently touched.
189 * <p>
190 * This action is not a touch event so it is delivered to
191 * {@link View#onGenericMotionEvent(MotionEvent)} rather than
192 * {@link View#onTouchEvent(MotionEvent)}.
193 * </p>
194 */
195 public static final int ACTION_SCROLL = 8;
196
197 /**
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800198 * Bits in the action code that represent a pointer index, used with
199 * {@link #ACTION_POINTER_DOWN} and {@link #ACTION_POINTER_UP}. Shifting
200 * down by {@link #ACTION_POINTER_INDEX_SHIFT} provides the actual pointer
201 * index where the data for the pointer going up or down can be found; you can
202 * get its identifier with {@link #getPointerId(int)} and the actual
203 * data with {@link #getX(int)} etc.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700204 */
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800205 public static final int ACTION_POINTER_INDEX_MASK = 0xff00;
206
207 /**
208 * Bit shift for the action bits holding the pointer index as
209 * defined by {@link #ACTION_POINTER_INDEX_MASK}.
210 */
211 public static final int ACTION_POINTER_INDEX_SHIFT = 8;
212
213 /**
214 * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the
215 * data index associated with {@link #ACTION_POINTER_DOWN}.
216 */
217 @Deprecated
218 public static final int ACTION_POINTER_1_DOWN = ACTION_POINTER_DOWN | 0x0000;
219
220 /**
221 * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the
222 * data index associated with {@link #ACTION_POINTER_DOWN}.
223 */
224 @Deprecated
225 public static final int ACTION_POINTER_2_DOWN = ACTION_POINTER_DOWN | 0x0100;
226
227 /**
228 * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the
229 * data index associated with {@link #ACTION_POINTER_DOWN}.
230 */
231 @Deprecated
232 public static final int ACTION_POINTER_3_DOWN = ACTION_POINTER_DOWN | 0x0200;
233
234 /**
235 * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the
236 * data index associated with {@link #ACTION_POINTER_UP}.
237 */
238 @Deprecated
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700239 public static final int ACTION_POINTER_1_UP = ACTION_POINTER_UP | 0x0000;
240
241 /**
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800242 * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the
243 * data index associated with {@link #ACTION_POINTER_UP}.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700244 */
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800245 @Deprecated
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700246 public static final int ACTION_POINTER_2_UP = ACTION_POINTER_UP | 0x0100;
247
248 /**
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800249 * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the
250 * data index associated with {@link #ACTION_POINTER_UP}.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700251 */
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800252 @Deprecated
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700253 public static final int ACTION_POINTER_3_UP = ACTION_POINTER_UP | 0x0200;
254
255 /**
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800256 * @deprecated Renamed to {@link #ACTION_POINTER_INDEX_MASK} to match
257 * the actual data contained in these bits.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700258 */
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800259 @Deprecated
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700260 public static final int ACTION_POINTER_ID_MASK = 0xff00;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700261
262 /**
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800263 * @deprecated Renamed to {@link #ACTION_POINTER_INDEX_SHIFT} to match
264 * the actual data contained in these bits.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700265 */
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800266 @Deprecated
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700267 public static final int ACTION_POINTER_ID_SHIFT = 8;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700268
Jeff Brown85a31762010-09-01 17:01:00 -0700269 /**
270 * This flag indicates that the window that received this motion event is partly
271 * or wholly obscured by another visible window above it. This flag is set to true
272 * even if the event did not directly pass through the obscured area.
273 * A security sensitive application can check this flag to identify situations in which
274 * a malicious application may have covered up part of its content for the purpose
275 * of misleading the user or hijacking touches. An appropriate response might be
276 * to drop the suspect touches or to take additional precautions to confirm the user's
277 * actual intent.
278 */
279 public static final int FLAG_WINDOW_IS_OBSCURED = 0x1;
Romain Guycafdea62009-06-12 10:51:36 -0700280
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800281 /**
282 * Flag indicating the motion event intersected the top edge of the screen.
283 */
284 public static final int EDGE_TOP = 0x00000001;
Romain Guycafdea62009-06-12 10:51:36 -0700285
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800286 /**
287 * Flag indicating the motion event intersected the bottom edge of the screen.
288 */
289 public static final int EDGE_BOTTOM = 0x00000002;
Romain Guycafdea62009-06-12 10:51:36 -0700290
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800291 /**
292 * Flag indicating the motion event intersected the left edge of the screen.
293 */
294 public static final int EDGE_LEFT = 0x00000004;
Romain Guycafdea62009-06-12 10:51:36 -0700295
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800296 /**
297 * Flag indicating the motion event intersected the right edge of the screen.
298 */
299 public static final int EDGE_RIGHT = 0x00000008;
Romain Guycafdea62009-06-12 10:51:36 -0700300
Jeff Brown91c69ab2011-02-14 17:03:18 -0800301 /**
302 * Constant used to identify the X axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800303 * <p>
304 * <ul>
305 * <li>For a touch screen, reports the absolute X screen position of the center of
306 * the touch contact area. The units are display pixels.
307 * <li>For a touch pad, reports the absolute X surface position of the center of the touch
Jeff Browncc0c1592011-02-19 05:07:28 -0800308 * contact area. The units are device-dependent; use {@link InputDevice#getMotionRange(int)}
309 * to query the effective range of values.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800310 * <li>For a mouse, reports the absolute X screen position of the mouse pointer.
311 * The units are display pixels.
312 * <li>For a trackball, reports the relative horizontal displacement of the trackball.
313 * The value is normalized to a range from -1.0 (left) to 1.0 (right).
314 * <li>For a joystick, reports the absolute X position of the joystick.
315 * The value is normalized to a range from -1.0 (left) to 1.0 (right).
316 * </ul>
317 * </p>
Jeff Brown91c69ab2011-02-14 17:03:18 -0800318 *
319 * @see #getX(int)
320 * @see #getHistoricalX(int, int)
321 * @see MotionEvent.PointerCoords#x
322 * @see InputDevice#getMotionRange
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700323 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800324 public static final int AXIS_X = 0;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700325
Jeff Brown91c69ab2011-02-14 17:03:18 -0800326 /**
327 * Constant used to identify the Y axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800328 * <p>
329 * <ul>
330 * <li>For a touch screen, reports the absolute Y screen position of the center of
331 * the touch contact area. The units are display pixels.
332 * <li>For a touch pad, reports the absolute Y surface position of the center of the touch
333 * contact area. The units are device-dependent; use {@link InputDevice#getMotionRange(int)}
334 * to query the effective range of values.
335 * <li>For a mouse, reports the absolute Y screen position of the mouse pointer.
336 * The units are display pixels.
337 * <li>For a trackball, reports the relative vertical displacement of the trackball.
338 * The value is normalized to a range from -1.0 (up) to 1.0 (down).
339 * <li>For a joystick, reports the absolute Y position of the joystick.
340 * The value is normalized to a range from -1.0 (up or far) to 1.0 (down or near).
341 * </ul>
342 * </p>
Jeff Brown91c69ab2011-02-14 17:03:18 -0800343 *
344 * @see #getY(int)
345 * @see #getHistoricalY(int, int)
346 * @see MotionEvent.PointerCoords#y
347 * @see InputDevice#getMotionRange
Jeff Brownc5ed5912010-07-14 18:48:53 -0700348 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800349 public static final int AXIS_Y = 1;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700350
Jeff Brown91c69ab2011-02-14 17:03:18 -0800351 /**
352 * Constant used to identify the Pressure axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800353 * <p>
354 * <ul>
Jeff Browncc0c1592011-02-19 05:07:28 -0800355 * <li>For a touch screen or touch pad, reports the approximate pressure applied to the surface
Jeff Brown6f2fba42011-02-19 01:08:02 -0800356 * by a finger or other tool. The value is normalized to a range from
357 * 0 (no pressure at all) to 1 (normal pressure), although values higher than 1
358 * may be generated depending on the calibration of the input device.
359 * <li>For a trackball, the value is set to 1 if the trackball button is pressed
360 * or 0 otherwise.
361 * <li>For a mouse, the value is set to 1 if the primary mouse button is pressed
362 * or 0 otherwise.
363 * </ul>
364 * </p>
Jeff Brown91c69ab2011-02-14 17:03:18 -0800365 *
366 * @see #getPressure(int)
367 * @see #getHistoricalPressure(int, int)
368 * @see MotionEvent.PointerCoords#pressure
369 * @see InputDevice#getMotionRange
Jeff Brownc5ed5912010-07-14 18:48:53 -0700370 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800371 public static final int AXIS_PRESSURE = 2;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700372
Jeff Brown91c69ab2011-02-14 17:03:18 -0800373 /**
374 * Constant used to identify the Size axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800375 * <p>
376 * <ul>
377 * <li>For a touch screen or touch pad, reports the approximate size of the contact area in
378 * relation to the maximum detectable size for the device. The value is normalized
379 * to a range from 0 (smallest detectable size) to 1 (largest detectable size),
Jeff Browncc0c1592011-02-19 05:07:28 -0800380 * although it is not a linear scale. This value is of limited use.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800381 * To obtain calibrated size information, use
382 * {@link #AXIS_TOUCH_MAJOR} or {@link #AXIS_TOOL_MAJOR}.
383 * </ul>
384 * </p>
Jeff Brown91c69ab2011-02-14 17:03:18 -0800385 *
386 * @see #getSize(int)
387 * @see #getHistoricalSize(int, int)
388 * @see MotionEvent.PointerCoords#size
389 * @see InputDevice#getMotionRange
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700390 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800391 public static final int AXIS_SIZE = 3;
392
393 /**
394 * Constant used to identify the TouchMajor axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800395 * <p>
396 * <ul>
397 * <li>For a touch screen, reports the length of the major axis of an ellipse that
398 * represents the touch area at the point of contact.
399 * The units are display pixels.
400 * <li>For a touch pad, reports the length of the major axis of an ellipse that
401 * represents the touch area at the point of contact.
402 * The units are device-dependent; use {@link InputDevice#getMotionRange(int)}
403 * to query the effective range of values.
404 * </ul>
405 * </p>
Jeff Brown91c69ab2011-02-14 17:03:18 -0800406 *
407 * @see #getTouchMajor(int)
408 * @see #getHistoricalTouchMajor(int, int)
409 * @see MotionEvent.PointerCoords#touchMajor
410 * @see InputDevice#getMotionRange
Dianne Hackborn1e8dfc72009-08-06 12:43:01 -0700411 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800412 public static final int AXIS_TOUCH_MAJOR = 4;
413
414 /**
415 * Constant used to identify the TouchMinor axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800416 * <p>
417 * <ul>
418 * <li>For a touch screen, reports the length of the minor axis of an ellipse that
419 * represents the touch area at the point of contact.
420 * The units are display pixels.
421 * <li>For a touch pad, reports the length of the minor axis of an ellipse that
422 * represents the touch area at the point of contact.
423 * The units are device-dependent; use {@link InputDevice#getMotionRange(int)}
424 * to query the effective range of values.
425 * </ul>
426 * </p><p>
427 * When the touch is circular, the major and minor axis lengths will be equal to one another.
428 * </p>
Jeff Brown91c69ab2011-02-14 17:03:18 -0800429 *
430 * @see #getTouchMinor(int)
431 * @see #getHistoricalTouchMinor(int, int)
432 * @see MotionEvent.PointerCoords#touchMinor
433 * @see InputDevice#getMotionRange
Jeff Brown9e2ad362010-07-30 19:20:11 -0700434 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800435 public static final int AXIS_TOUCH_MINOR = 5;
436
437 /**
438 * Constant used to identify the ToolMajor axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800439 * <p>
440 * <ul>
441 * <li>For a touch screen, reports the length of the major axis of an ellipse that
442 * represents the size of the approaching finger or tool used to make contact.
443 * <li>For a touch pad, reports the length of the major axis of an ellipse that
444 * represents the size of the approaching finger or tool used to make contact.
445 * The units are device-dependent; use {@link InputDevice#getMotionRange(int)}
446 * to query the effective range of values.
447 * </ul>
448 * </p><p>
449 * When the touch is circular, the major and minor axis lengths will be equal to one another.
450 * </p><p>
451 * The tool size may be larger than the touch size since the tool may not be fully
452 * in contact with the touch sensor.
453 * </p>
Jeff Brown91c69ab2011-02-14 17:03:18 -0800454 *
455 * @see #getToolMajor(int)
456 * @see #getHistoricalToolMajor(int, int)
457 * @see MotionEvent.PointerCoords#toolMajor
458 * @see InputDevice#getMotionRange
459 */
460 public static final int AXIS_TOOL_MAJOR = 6;
461
462 /**
463 * Constant used to identify the ToolMinor axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800464 * <p>
465 * <ul>
466 * <li>For a touch screen, reports the length of the minor axis of an ellipse that
467 * represents the size of the approaching finger or tool used to make contact.
468 * <li>For a touch pad, reports the length of the minor axis of an ellipse that
469 * represents the size of the approaching finger or tool used to make contact.
470 * The units are device-dependent; use {@link InputDevice#getMotionRange(int)}
471 * to query the effective range of values.
472 * </ul>
473 * </p><p>
474 * When the touch is circular, the major and minor axis lengths will be equal to one another.
475 * </p><p>
476 * The tool size may be larger than the touch size since the tool may not be fully
477 * in contact with the touch sensor.
478 * </p>
Jeff Brown91c69ab2011-02-14 17:03:18 -0800479 *
480 * @see #getToolMinor(int)
481 * @see #getHistoricalToolMinor(int, int)
482 * @see MotionEvent.PointerCoords#toolMinor
483 * @see InputDevice#getMotionRange
484 */
485 public static final int AXIS_TOOL_MINOR = 7;
486
487 /**
488 * Constant used to identify the Orientation axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800489 * <p>
490 * <ul>
491 * <li>For a touch screen or touch pad, reports the orientation of the finger
492 * or tool in radians relative to the vertical plane of the device.
493 * An angle of 0 radians indicates that the major axis of contact is oriented
Jeff Brown91c69ab2011-02-14 17:03:18 -0800494 * upwards, is perfectly circular or is of unknown orientation. A positive angle
495 * indicates that the major axis of contact is oriented to the right. A negative angle
496 * indicates that the major axis of contact is oriented to the left.
497 * The full range is from -PI/2 radians (finger pointing fully left) to PI/2 radians
498 * (finger pointing fully right).
Jeff Brown6f2fba42011-02-19 01:08:02 -0800499 * </ul>
500 * </p>
Jeff Brown91c69ab2011-02-14 17:03:18 -0800501 *
502 * @see #getOrientation(int)
503 * @see #getHistoricalOrientation(int, int)
504 * @see MotionEvent.PointerCoords#orientation
505 * @see InputDevice#getMotionRange
506 */
507 public static final int AXIS_ORIENTATION = 8;
508
Jeff Brown6f2fba42011-02-19 01:08:02 -0800509 /**
510 * Constant used to identify the Vertical Scroll axis of a motion event.
511 * <p>
512 * <ul>
Jeff Browncc0c1592011-02-19 05:07:28 -0800513 * <li>For a mouse, reports the relative movement of the vertical scroll wheel.
Jeff Brown33bbfd22011-02-24 20:55:35 -0800514 * The value is normalized to a range from -1.0 (down) to 1.0 (up).
Jeff Brown6f2fba42011-02-19 01:08:02 -0800515 * </ul>
516 * </p><p>
517 * This axis should be used to scroll views vertically.
518 * </p>
519 *
520 * @see #getAxisValue(int, int)
521 * @see #getHistoricalAxisValue(int, int, int)
522 * @see MotionEvent.PointerCoords#getAxisValue(int)
523 * @see InputDevice#getMotionRange
524 */
525 public static final int AXIS_VSCROLL = 9;
526
527 /**
528 * Constant used to identify the Horizontal Scroll axis of a motion event.
529 * <p>
530 * <ul>
Jeff Browncc0c1592011-02-19 05:07:28 -0800531 * <li>For a mouse, reports the relative movement of the horizontal scroll wheel.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800532 * The value is normalized to a range from -1.0 (left) to 1.0 (right).
533 * </ul>
534 * </p><p>
535 * This axis should be used to scroll views horizontally.
536 * </p>
537 *
538 * @see #getAxisValue(int, int)
539 * @see #getHistoricalAxisValue(int, int, int)
540 * @see MotionEvent.PointerCoords#getAxisValue(int)
541 * @see InputDevice#getMotionRange
542 */
543 public static final int AXIS_HSCROLL = 10;
544
545 /**
546 * Constant used to identify the Z axis of a motion event.
547 * <p>
548 * <ul>
549 * <li>For a joystick, reports the absolute Z position of the joystick.
550 * The value is normalized to a range from -1.0 (high) to 1.0 (low).
551 * <em>On game pads with two analog joysticks, this axis is often reinterpreted
552 * to report the absolute X position of the second joystick instead.</em>
553 * </ul>
554 * </p>
555 *
556 * @see #getAxisValue(int, int)
557 * @see #getHistoricalAxisValue(int, int, int)
558 * @see MotionEvent.PointerCoords#getAxisValue(int)
559 * @see InputDevice#getMotionRange
560 */
561 public static final int AXIS_Z = 11;
562
563 /**
564 * Constant used to identify the X Rotation axis of a motion event.
565 * <p>
566 * <ul>
567 * <li>For a joystick, reports the absolute rotation angle about the X axis.
568 * The value is normalized to a range from -1.0 (counter-clockwise) to 1.0 (clockwise).
569 * </ul>
570 * </p>
571 *
572 * @see #getAxisValue(int, int)
573 * @see #getHistoricalAxisValue(int, int, int)
574 * @see MotionEvent.PointerCoords#getAxisValue(int)
575 * @see InputDevice#getMotionRange
576 */
577 public static final int AXIS_RX = 12;
578
579 /**
580 * Constant used to identify the Y Rotation axis of a motion event.
581 * <p>
582 * <ul>
583 * <li>For a joystick, reports the absolute rotation angle about the Y axis.
584 * The value is normalized to a range from -1.0 (counter-clockwise) to 1.0 (clockwise).
585 * </ul>
586 * </p>
587 *
588 * @see #getAxisValue(int, int)
589 * @see #getHistoricalAxisValue(int, int, int)
590 * @see MotionEvent.PointerCoords#getAxisValue(int)
591 * @see InputDevice#getMotionRange
592 */
593 public static final int AXIS_RY = 13;
594
595 /**
596 * Constant used to identify the Z Rotation axis of a motion event.
597 * <p>
598 * <ul>
599 * <li>For a joystick, reports the absolute rotation angle about the Z axis.
600 * The value is normalized to a range from -1.0 (counter-clockwise) to 1.0 (clockwise).
601 * <em>On game pads with two analog joysticks, this axis is often reinterpreted
602 * to report the absolute Y position of the second joystick instead.</em>
603 * </ul>
604 * </p>
605 *
606 * @see #getAxisValue(int, int)
607 * @see #getHistoricalAxisValue(int, int, int)
608 * @see MotionEvent.PointerCoords#getAxisValue(int)
609 * @see InputDevice#getMotionRange
610 */
611 public static final int AXIS_RZ = 14;
612
613 /**
614 * Constant used to identify the Hat X axis of a motion event.
615 * <p>
616 * <ul>
617 * <li>For a joystick, reports the absolute X position of the directional hat control.
618 * The value is normalized to a range from -1.0 (left) to 1.0 (right).
619 * </ul>
620 * </p>
621 *
622 * @see #getAxisValue(int, int)
623 * @see #getHistoricalAxisValue(int, int, int)
624 * @see MotionEvent.PointerCoords#getAxisValue(int)
625 * @see InputDevice#getMotionRange
626 */
627 public static final int AXIS_HAT_X = 15;
628
629 /**
630 * Constant used to identify the Hat Y axis of a motion event.
631 * <p>
632 * <ul>
633 * <li>For a joystick, reports the absolute Y position of the directional hat control.
634 * The value is normalized to a range from -1.0 (up) to 1.0 (down).
635 * </ul>
636 * </p>
637 *
638 * @see #getAxisValue(int, int)
639 * @see #getHistoricalAxisValue(int, int, int)
640 * @see MotionEvent.PointerCoords#getAxisValue(int)
641 * @see InputDevice#getMotionRange
642 */
643 public static final int AXIS_HAT_Y = 16;
644
645 /**
646 * Constant used to identify the Left Trigger axis of a motion event.
647 * <p>
648 * <ul>
649 * <li>For a joystick, reports the absolute position of the left trigger control.
650 * The value is normalized to a range from 0.0 (released) to 1.0 (fully pressed).
651 * </ul>
652 * </p>
653 *
654 * @see #getAxisValue(int, int)
655 * @see #getHistoricalAxisValue(int, int, int)
656 * @see MotionEvent.PointerCoords#getAxisValue(int)
657 * @see InputDevice#getMotionRange
658 */
659 public static final int AXIS_LTRIGGER = 17;
660
661 /**
662 * Constant used to identify the Right Trigger axis of a motion event.
663 * <p>
664 * <ul>
665 * <li>For a joystick, reports the absolute position of the right trigger control.
666 * The value is normalized to a range from 0.0 (released) to 1.0 (fully pressed).
667 * </ul>
668 * </p>
669 *
670 * @see #getAxisValue(int, int)
671 * @see #getHistoricalAxisValue(int, int, int)
672 * @see MotionEvent.PointerCoords#getAxisValue(int)
673 * @see InputDevice#getMotionRange
674 */
675 public static final int AXIS_RTRIGGER = 18;
676
677 /**
Jeff Brown85297452011-03-04 13:07:49 -0800678 * Constant used to identify the Throttle axis of a motion event.
679 * <p>
680 * <ul>
681 * <li>For a joystick, reports the absolute position of the throttle control.
682 * The value is normalized to a range from 0.0 (fully open) to 1.0 (fully closed).
683 * </ul>
684 * </p>
685 *
686 * @see #getAxisValue(int, int)
687 * @see #getHistoricalAxisValue(int, int, int)
688 * @see MotionEvent.PointerCoords#getAxisValue(int)
689 * @see InputDevice#getMotionRange
690 */
691 public static final int AXIS_THROTTLE = 19;
692
693 /**
694 * Constant used to identify the Rudder axis of a motion event.
695 * <p>
696 * <ul>
697 * <li>For a joystick, reports the absolute position of the rudder control.
698 * The value is normalized to a range from -1.0 (turn left) to 1.0 (turn right).
699 * </ul>
700 * </p>
701 *
702 * @see #getAxisValue(int, int)
703 * @see #getHistoricalAxisValue(int, int, int)
704 * @see MotionEvent.PointerCoords#getAxisValue(int)
705 * @see InputDevice#getMotionRange
706 */
707 public static final int AXIS_RUDDER = 20;
708
709 /**
710 * Constant used to identify the Wheel axis of a motion event.
711 * <p>
712 * <ul>
713 * <li>For a joystick, reports the absolute position of the steering wheel control.
714 * The value is normalized to a range from -1.0 (turn left) to 1.0 (turn right).
715 * </ul>
716 * </p>
717 *
718 * @see #getAxisValue(int, int)
719 * @see #getHistoricalAxisValue(int, int, int)
720 * @see MotionEvent.PointerCoords#getAxisValue(int)
721 * @see InputDevice#getMotionRange
722 */
723 public static final int AXIS_WHEEL = 21;
724
725 /**
726 * Constant used to identify the Gas axis of a motion event.
727 * <p>
728 * <ul>
729 * <li>For a joystick, reports the absolute position of the gas (accelerator) control.
730 * The value is normalized to a range from 0.0 (no acceleration)
731 * to 1.0 (maximum acceleration).
732 * </ul>
733 * </p>
734 *
735 * @see #getAxisValue(int, int)
736 * @see #getHistoricalAxisValue(int, int, int)
737 * @see MotionEvent.PointerCoords#getAxisValue(int)
738 * @see InputDevice#getMotionRange
739 */
740 public static final int AXIS_GAS = 22;
741
742 /**
743 * Constant used to identify the Brake axis of a motion event.
744 * <p>
745 * <ul>
746 * <li>For a joystick, reports the absolute position of the brake control.
747 * The value is normalized to a range from 0.0 (no braking) to 1.0 (maximum braking).
748 * </ul>
749 * </p>
750 *
751 * @see #getAxisValue(int, int)
752 * @see #getHistoricalAxisValue(int, int, int)
753 * @see MotionEvent.PointerCoords#getAxisValue(int)
754 * @see InputDevice#getMotionRange
755 */
756 public static final int AXIS_BRAKE = 23;
757
758 /**
Jeff Brown6f2fba42011-02-19 01:08:02 -0800759 * Constant used to identify the Generic 1 axis of a motion event.
760 * The interpretation of a generic axis is device-specific.
761 *
762 * @see #getAxisValue(int, int)
763 * @see #getHistoricalAxisValue(int, int, int)
764 * @see MotionEvent.PointerCoords#getAxisValue(int)
765 * @see InputDevice#getMotionRange
766 */
767 public static final int AXIS_GENERIC_1 = 32;
768
769 /**
770 * Constant used to identify the Generic 2 axis of a motion event.
771 * The interpretation of a generic axis is device-specific.
772 *
773 * @see #getAxisValue(int, int)
774 * @see #getHistoricalAxisValue(int, int, int)
775 * @see MotionEvent.PointerCoords#getAxisValue(int)
776 * @see InputDevice#getMotionRange
777 */
778 public static final int AXIS_GENERIC_2 = 33;
779
780 /**
781 * Constant used to identify the Generic 3 axis of a motion event.
782 * The interpretation of a generic axis is device-specific.
783 *
784 * @see #getAxisValue(int, int)
785 * @see #getHistoricalAxisValue(int, int, int)
786 * @see MotionEvent.PointerCoords#getAxisValue(int)
787 * @see InputDevice#getMotionRange
788 */
789 public static final int AXIS_GENERIC_3 = 34;
790
791 /**
792 * Constant used to identify the Generic 4 axis of a motion event.
793 * The interpretation of a generic axis is device-specific.
794 *
795 * @see #getAxisValue(int, int)
796 * @see #getHistoricalAxisValue(int, int, int)
797 * @see MotionEvent.PointerCoords#getAxisValue(int)
798 * @see InputDevice#getMotionRange
799 */
800 public static final int AXIS_GENERIC_4 = 35;
801
802 /**
803 * Constant used to identify the Generic 5 axis of a motion event.
804 * The interpretation of a generic axis is device-specific.
805 *
806 * @see #getAxisValue(int, int)
807 * @see #getHistoricalAxisValue(int, int, int)
808 * @see MotionEvent.PointerCoords#getAxisValue(int)
809 * @see InputDevice#getMotionRange
810 */
811 public static final int AXIS_GENERIC_5 = 36;
812
813 /**
814 * Constant used to identify the Generic 6 axis of a motion event.
815 * The interpretation of a generic axis is device-specific.
816 *
817 * @see #getAxisValue(int, int)
818 * @see #getHistoricalAxisValue(int, int, int)
819 * @see MotionEvent.PointerCoords#getAxisValue(int)
820 * @see InputDevice#getMotionRange
821 */
822 public static final int AXIS_GENERIC_6 = 37;
823
824 /**
825 * Constant used to identify the Generic 7 axis of a motion event.
826 * The interpretation of a generic axis is device-specific.
827 *
828 * @see #getAxisValue(int, int)
829 * @see #getHistoricalAxisValue(int, int, int)
830 * @see MotionEvent.PointerCoords#getAxisValue(int)
831 * @see InputDevice#getMotionRange
832 */
833 public static final int AXIS_GENERIC_7 = 38;
834
835 /**
836 * Constant used to identify the Generic 8 axis of a motion event.
837 * The interpretation of a generic axis is device-specific.
838 *
839 * @see #getAxisValue(int, int)
840 * @see #getHistoricalAxisValue(int, int, int)
841 * @see MotionEvent.PointerCoords#getAxisValue(int)
842 * @see InputDevice#getMotionRange
843 */
844 public static final int AXIS_GENERIC_8 = 39;
845
846 /**
847 * Constant used to identify the Generic 9 axis of a motion event.
848 * The interpretation of a generic axis is device-specific.
849 *
850 * @see #getAxisValue(int, int)
851 * @see #getHistoricalAxisValue(int, int, int)
852 * @see MotionEvent.PointerCoords#getAxisValue(int)
853 * @see InputDevice#getMotionRange
854 */
855 public static final int AXIS_GENERIC_9 = 40;
856
857 /**
858 * Constant used to identify the Generic 10 axis of a motion event.
859 * The interpretation of a generic axis is device-specific.
860 *
861 * @see #getAxisValue(int, int)
862 * @see #getHistoricalAxisValue(int, int, int)
863 * @see MotionEvent.PointerCoords#getAxisValue(int)
864 * @see InputDevice#getMotionRange
865 */
866 public static final int AXIS_GENERIC_10 = 41;
867
868 /**
869 * Constant used to identify the Generic 11 axis of a motion event.
870 * The interpretation of a generic axis is device-specific.
871 *
872 * @see #getAxisValue(int, int)
873 * @see #getHistoricalAxisValue(int, int, int)
874 * @see MotionEvent.PointerCoords#getAxisValue(int)
875 * @see InputDevice#getMotionRange
876 */
877 public static final int AXIS_GENERIC_11 = 42;
878
879 /**
880 * Constant used to identify the Generic 12 axis of a motion event.
881 * The interpretation of a generic axis is device-specific.
882 *
883 * @see #getAxisValue(int, int)
884 * @see #getHistoricalAxisValue(int, int, int)
885 * @see MotionEvent.PointerCoords#getAxisValue(int)
886 * @see InputDevice#getMotionRange
887 */
888 public static final int AXIS_GENERIC_12 = 43;
889
890 /**
891 * Constant used to identify the Generic 13 axis of a motion event.
892 * The interpretation of a generic axis is device-specific.
893 *
894 * @see #getAxisValue(int, int)
895 * @see #getHistoricalAxisValue(int, int, int)
896 * @see MotionEvent.PointerCoords#getAxisValue(int)
897 * @see InputDevice#getMotionRange
898 */
899 public static final int AXIS_GENERIC_13 = 44;
900
901 /**
902 * Constant used to identify the Generic 14 axis of a motion event.
903 * The interpretation of a generic axis is device-specific.
904 *
905 * @see #getAxisValue(int, int)
906 * @see #getHistoricalAxisValue(int, int, int)
907 * @see MotionEvent.PointerCoords#getAxisValue(int)
908 * @see InputDevice#getMotionRange
909 */
910 public static final int AXIS_GENERIC_14 = 45;
911
912 /**
913 * Constant used to identify the Generic 15 axis of a motion event.
914 * The interpretation of a generic axis is device-specific.
915 *
916 * @see #getAxisValue(int, int)
917 * @see #getHistoricalAxisValue(int, int, int)
918 * @see MotionEvent.PointerCoords#getAxisValue(int)
919 * @see InputDevice#getMotionRange
920 */
921 public static final int AXIS_GENERIC_15 = 46;
922
923 /**
924 * Constant used to identify the Generic 16 axis of a motion event.
925 * The interpretation of a generic axis is device-specific.
926 *
927 * @see #getAxisValue(int, int)
928 * @see #getHistoricalAxisValue(int, int, int)
929 * @see MotionEvent.PointerCoords#getAxisValue(int)
930 * @see InputDevice#getMotionRange
931 */
932 public static final int AXIS_GENERIC_16 = 47;
933
934 // NOTE: If you add a new axis here you must also add it to:
935 // native/include/android/input.h
936 // frameworks/base/include/ui/KeycodeLabels.h
937
938 // Symbolic names of all axes.
939 private static final SparseArray<String> AXIS_SYMBOLIC_NAMES = new SparseArray<String>();
940 private static void populateAxisSymbolicNames() {
941 SparseArray<String> names = AXIS_SYMBOLIC_NAMES;
942 names.append(AXIS_X, "AXIS_X");
943 names.append(AXIS_Y, "AXIS_Y");
944 names.append(AXIS_PRESSURE, "AXIS_PRESSURE");
945 names.append(AXIS_SIZE, "AXIS_SIZE");
946 names.append(AXIS_TOUCH_MAJOR, "AXIS_TOUCH_MAJOR");
947 names.append(AXIS_TOUCH_MINOR, "AXIS_TOUCH_MINOR");
948 names.append(AXIS_TOOL_MAJOR, "AXIS_TOOL_MAJOR");
949 names.append(AXIS_TOOL_MINOR, "AXIS_TOOL_MINOR");
950 names.append(AXIS_ORIENTATION, "AXIS_ORIENTATION");
951 names.append(AXIS_VSCROLL, "AXIS_VSCROLL");
952 names.append(AXIS_HSCROLL, "AXIS_HSCROLL");
953 names.append(AXIS_Z, "AXIS_Z");
954 names.append(AXIS_RX, "AXIS_RX");
955 names.append(AXIS_RY, "AXIS_RY");
956 names.append(AXIS_RZ, "AXIS_RZ");
957 names.append(AXIS_HAT_X, "AXIS_HAT_X");
958 names.append(AXIS_HAT_Y, "AXIS_HAT_Y");
959 names.append(AXIS_LTRIGGER, "AXIS_LTRIGGER");
960 names.append(AXIS_RTRIGGER, "AXIS_RTRIGGER");
Jeff Brown85297452011-03-04 13:07:49 -0800961 names.append(AXIS_THROTTLE, "AXIS_THROTTLE");
962 names.append(AXIS_RUDDER, "AXIS_RUDDER");
963 names.append(AXIS_WHEEL, "AXIS_WHEEL");
964 names.append(AXIS_GAS, "AXIS_GAS");
965 names.append(AXIS_BRAKE, "AXIS_BRAKE");
Jeff Brown6f2fba42011-02-19 01:08:02 -0800966 names.append(AXIS_GENERIC_1, "AXIS_GENERIC_1");
967 names.append(AXIS_GENERIC_2, "AXIS_GENERIC_2");
968 names.append(AXIS_GENERIC_3, "AXIS_GENERIC_3");
969 names.append(AXIS_GENERIC_4, "AXIS_GENERIC_4");
970 names.append(AXIS_GENERIC_5, "AXIS_GENERIC_5");
971 names.append(AXIS_GENERIC_6, "AXIS_GENERIC_6");
972 names.append(AXIS_GENERIC_7, "AXIS_GENERIC_7");
973 names.append(AXIS_GENERIC_8, "AXIS_GENERIC_8");
974 names.append(AXIS_GENERIC_9, "AXIS_GENERIC_9");
975 names.append(AXIS_GENERIC_10, "AXIS_GENERIC_10");
976 names.append(AXIS_GENERIC_11, "AXIS_GENERIC_11");
977 names.append(AXIS_GENERIC_12, "AXIS_GENERIC_12");
978 names.append(AXIS_GENERIC_13, "AXIS_GENERIC_13");
979 names.append(AXIS_GENERIC_14, "AXIS_GENERIC_14");
980 names.append(AXIS_GENERIC_15, "AXIS_GENERIC_15");
981 names.append(AXIS_GENERIC_16, "AXIS_GENERIC_16");
982 }
983
984 static {
985 populateAxisSymbolicNames();
986 }
987
Jeff Brown91c69ab2011-02-14 17:03:18 -0800988 // Private value for history pos that obtains the current sample.
989 private static final int HISTORY_CURRENT = -0x80000000;
990
Jeff Brown1f245102010-11-18 20:53:46 -0800991 private static final int MAX_RECYCLED = 10;
992 private static final Object gRecyclerLock = new Object();
993 private static int gRecyclerUsed;
994 private static MotionEvent gRecyclerTop;
Romain Guycafdea62009-06-12 10:51:36 -0700995
Jeff Brown91c69ab2011-02-14 17:03:18 -0800996 // Shared temporary objects used when translating coordinates supplied by
997 // the caller into single element PointerCoords and pointer id arrays.
998 // Must lock gTmpPointerCoords prior to use.
999 private static final PointerCoords[] gTmpPointerCoords =
1000 new PointerCoords[] { new PointerCoords() };
1001 private static final int[] gTmpPointerIds = new int[] { 0 /*always 0*/ };
1002
1003 // Pointer to the native MotionEvent object that contains the actual data.
1004 private int mNativePtr;
Mitsuru Oshima8169dae2009-04-28 18:12:09 -07001005
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001006 private MotionEvent mNext;
1007 private RuntimeException mRecycledLocation;
1008 private boolean mRecycled;
1009
Jeff Brown91c69ab2011-02-14 17:03:18 -08001010 private static native int nativeInitialize(int nativePtr,
1011 int deviceId, int source, int action, int flags, int edgeFlags, int metaState,
1012 float xOffset, float yOffset, float xPrecision, float yPrecision,
1013 long downTimeNanos, long eventTimeNanos,
1014 int pointerCount, int[] pointerIds, PointerCoords[] pointerCoords);
1015 private static native int nativeCopy(int destNativePtr, int sourceNativePtr,
1016 boolean keepHistory);
1017 private static native void nativeDispose(int nativePtr);
1018 private static native void nativeAddBatch(int nativePtr, long eventTimeNanos,
1019 PointerCoords[] pointerCoords, int metaState);
Jeff Brown20e987b2010-08-23 12:01:02 -07001020
Jeff Brown91c69ab2011-02-14 17:03:18 -08001021 private static native int nativeGetDeviceId(int nativePtr);
1022 private static native int nativeGetSource(int nativePtr);
1023 private static native int nativeSetSource(int nativePtr, int source);
1024 private static native int nativeGetAction(int nativePtr);
1025 private static native void nativeSetAction(int nativePtr, int action);
Jeff Brown56194eb2011-03-02 19:23:13 -08001026 private static native boolean nativeIsTouchEvent(int nativePtr);
Jeff Brown91c69ab2011-02-14 17:03:18 -08001027 private static native int nativeGetFlags(int nativePtr);
1028 private static native int nativeGetEdgeFlags(int nativePtr);
1029 private static native void nativeSetEdgeFlags(int nativePtr, int action);
1030 private static native int nativeGetMetaState(int nativePtr);
1031 private static native void nativeOffsetLocation(int nativePtr, float deltaX, float deltaY);
1032 private static native float nativeGetXPrecision(int nativePtr);
1033 private static native float nativeGetYPrecision(int nativePtr);
1034 private static native long nativeGetDownTimeNanos(int nativePtr);
1035
1036 private static native int nativeGetPointerCount(int nativePtr);
1037 private static native int nativeGetPointerId(int nativePtr, int pointerIndex);
1038 private static native int nativeFindPointerIndex(int nativePtr, int pointerId);
1039
1040 private static native int nativeGetHistorySize(int nativePtr);
1041 private static native long nativeGetEventTimeNanos(int nativePtr, int historyPos);
1042 private static native float nativeGetRawAxisValue(int nativePtr,
1043 int axis, int pointerIndex, int historyPos);
1044 private static native float nativeGetAxisValue(int nativePtr,
1045 int axis, int pointerIndex, int historyPos);
1046 private static native void nativeGetPointerCoords(int nativePtr,
1047 int pointerIndex, int historyPos, PointerCoords outPointerCoords);
1048
1049 private static native void nativeScale(int nativePtr, float scale);
1050 private static native void nativeTransform(int nativePtr, Matrix matrix);
1051
1052 private static native int nativeReadFromParcel(int nativePtr, Parcel parcel);
1053 private static native void nativeWriteToParcel(int nativePtr, Parcel parcel);
1054
1055 private MotionEvent() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001056 }
Romain Guycafdea62009-06-12 10:51:36 -07001057
Jeff Brown91c69ab2011-02-14 17:03:18 -08001058 @Override
1059 protected void finalize() throws Throwable {
1060 try {
1061 if (mNativePtr != 0) {
1062 nativeDispose(mNativePtr);
1063 mNativePtr = 0;
1064 }
1065 } finally {
1066 super.finalize();
1067 }
1068 }
1069
1070 static private MotionEvent obtain() {
Jeff Brown46b9ac02010-04-22 18:58:52 -07001071 final MotionEvent ev;
1072 synchronized (gRecyclerLock) {
Jeff Brown1f245102010-11-18 20:53:46 -08001073 ev = gRecyclerTop;
1074 if (ev == null) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001075 return new MotionEvent();
Jeff Brown46b9ac02010-04-22 18:58:52 -07001076 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07001077 gRecyclerTop = ev.mNext;
Jeff Brown5c225b12010-06-16 01:53:36 -07001078 gRecyclerUsed -= 1;
Jeff Brown46b9ac02010-04-22 18:58:52 -07001079 }
1080 ev.mRecycledLocation = null;
1081 ev.mRecycled = false;
1082 ev.mNext = null;
Jeff Brown46b9ac02010-04-22 18:58:52 -07001083 return ev;
1084 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08001085
Michael Chan53071d62009-05-13 17:29:48 -07001086 /**
1087 * Create a new MotionEvent, filling in all of the basic values that
1088 * define the motion.
1089 *
1090 * @param downTime The time (in ms) when the user originally pressed down to start
1091 * a stream of position events. This must be obtained from {@link SystemClock#uptimeMillis()}.
Jeff Brownc5ed5912010-07-14 18:48:53 -07001092 * @param eventTime The the time (in ms) when this specific event was generated. This
Michael Chan53071d62009-05-13 17:29:48 -07001093 * must be obtained from {@link SystemClock#uptimeMillis()}.
Jeff Browncc0c1592011-02-19 05:07:28 -08001094 * @param action The kind of action being performed, such as {@link #ACTION_DOWN}.
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001095 * @param pointers The number of points that will be in this event.
Jeff Brownc5ed5912010-07-14 18:48:53 -07001096 * @param pointerIds An array of <em>pointers</em> values providing
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001097 * an identifier for each pointer.
Jeff Brownc5ed5912010-07-14 18:48:53 -07001098 * @param pointerCoords An array of <em>pointers</em> values providing
1099 * a {@link PointerCoords} coordinate object for each pointer.
Michael Chan53071d62009-05-13 17:29:48 -07001100 * @param metaState The state of any meta / modifier keys that were in effect when
1101 * the event was generated.
1102 * @param xPrecision The precision of the X coordinate being reported.
1103 * @param yPrecision The precision of the Y coordinate being reported.
1104 * @param deviceId The id for the device that this event came from. An id of
1105 * zero indicates that the event didn't come from a physical device; other
1106 * numbers are arbitrary and you shouldn't depend on the values.
Jeff Brown85a31762010-09-01 17:01:00 -07001107 * @param edgeFlags A bitfield indicating which edges, if any, were touched by this
Michael Chan53071d62009-05-13 17:29:48 -07001108 * MotionEvent.
Jeff Brownc5ed5912010-07-14 18:48:53 -07001109 * @param source The source of this event.
Jeff Brown85a31762010-09-01 17:01:00 -07001110 * @param flags The motion event flags.
Michael Chan53071d62009-05-13 17:29:48 -07001111 */
Jeff Brownc5ed5912010-07-14 18:48:53 -07001112 static public MotionEvent obtain(long downTime, long eventTime,
1113 int action, int pointers, int[] pointerIds, PointerCoords[] pointerCoords,
1114 int metaState, float xPrecision, float yPrecision, int deviceId,
Jeff Brown85a31762010-09-01 17:01:00 -07001115 int edgeFlags, int source, int flags) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001116 MotionEvent ev = obtain();
1117 ev.mNativePtr = nativeInitialize(ev.mNativePtr,
1118 deviceId, source, action, flags, edgeFlags, metaState,
1119 0, 0, xPrecision, yPrecision,
1120 downTime * NS_PER_MS, eventTime * NS_PER_MS,
1121 pointers, pointerIds, pointerCoords);
Michael Chan53071d62009-05-13 17:29:48 -07001122 return ev;
1123 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08001124
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001125 /**
1126 * Create a new MotionEvent, filling in all of the basic values that
1127 * define the motion.
Romain Guycafdea62009-06-12 10:51:36 -07001128 *
1129 * @param downTime The time (in ms) when the user originally pressed down to start
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001130 * a stream of position events. This must be obtained from {@link SystemClock#uptimeMillis()}.
Romain Guycafdea62009-06-12 10:51:36 -07001131 * @param eventTime The the time (in ms) when this specific event was generated. This
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001132 * must be obtained from {@link SystemClock#uptimeMillis()}.
Jeff Browncc0c1592011-02-19 05:07:28 -08001133 * @param action The kind of action being performed, such as {@link #ACTION_DOWN}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001134 * @param x The X coordinate of this event.
1135 * @param y The Y coordinate of this event.
Romain Guycafdea62009-06-12 10:51:36 -07001136 * @param pressure The current pressure of this event. The pressure generally
1137 * ranges from 0 (no pressure at all) to 1 (normal pressure), however
1138 * values higher than 1 may be generated depending on the calibration of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001139 * the input device.
1140 * @param size A scaled value of the approximate size of the area being pressed when
Romain Guycafdea62009-06-12 10:51:36 -07001141 * touched with the finger. The actual value in pixels corresponding to the finger
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001142 * touch is normalized with a device specific range of values
1143 * and scaled to a value between 0 and 1.
1144 * @param metaState The state of any meta / modifier keys that were in effect when
1145 * the event was generated.
1146 * @param xPrecision The precision of the X coordinate being reported.
1147 * @param yPrecision The precision of the Y coordinate being reported.
1148 * @param deviceId The id for the device that this event came from. An id of
1149 * zero indicates that the event didn't come from a physical device; other
1150 * numbers are arbitrary and you shouldn't depend on the values.
Jeff Brown85a31762010-09-01 17:01:00 -07001151 * @param edgeFlags A bitfield indicating which edges, if any, were touched by this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001152 * MotionEvent.
1153 */
1154 static public MotionEvent obtain(long downTime, long eventTime, int action,
1155 float x, float y, float pressure, float size, int metaState,
1156 float xPrecision, float yPrecision, int deviceId, int edgeFlags) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001157 synchronized (gTmpPointerCoords) {
1158 final PointerCoords pc = gTmpPointerCoords[0];
1159 pc.clear();
1160 pc.x = x;
1161 pc.y = y;
1162 pc.pressure = pressure;
1163 pc.size = size;
1164
1165 MotionEvent ev = obtain();
1166 ev.mNativePtr = nativeInitialize(ev.mNativePtr,
1167 deviceId, InputDevice.SOURCE_UNKNOWN, action, 0, edgeFlags, metaState,
1168 0, 0, xPrecision, yPrecision,
1169 downTime * NS_PER_MS, eventTime * NS_PER_MS,
1170 1, gTmpPointerIds, gTmpPointerCoords);
1171 return ev;
1172 }
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001173 }
1174
1175 /**
1176 * Create a new MotionEvent, filling in all of the basic values that
1177 * define the motion.
1178 *
1179 * @param downTime The time (in ms) when the user originally pressed down to start
1180 * a stream of position events. This must be obtained from {@link SystemClock#uptimeMillis()}.
1181 * @param eventTime The the time (in ms) when this specific event was generated. This
1182 * must be obtained from {@link SystemClock#uptimeMillis()}.
Jeff Browncc0c1592011-02-19 05:07:28 -08001183 * @param action The kind of action being performed, such as {@link #ACTION_DOWN}.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001184 * @param pointers The number of pointers that are active in this event.
1185 * @param x The X coordinate of this event.
1186 * @param y The Y coordinate of this event.
1187 * @param pressure The current pressure of this event. The pressure generally
1188 * ranges from 0 (no pressure at all) to 1 (normal pressure), however
1189 * values higher than 1 may be generated depending on the calibration of
1190 * the input device.
1191 * @param size A scaled value of the approximate size of the area being pressed when
1192 * touched with the finger. The actual value in pixels corresponding to the finger
1193 * touch is normalized with a device specific range of values
1194 * and scaled to a value between 0 and 1.
1195 * @param metaState The state of any meta / modifier keys that were in effect when
1196 * the event was generated.
1197 * @param xPrecision The precision of the X coordinate being reported.
1198 * @param yPrecision The precision of the Y coordinate being reported.
1199 * @param deviceId The id for the device that this event came from. An id of
1200 * zero indicates that the event didn't come from a physical device; other
1201 * numbers are arbitrary and you shouldn't depend on the values.
Jeff Brown85a31762010-09-01 17:01:00 -07001202 * @param edgeFlags A bitfield indicating which edges, if any, were touched by this
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001203 * MotionEvent.
Jeff Brown5c225b12010-06-16 01:53:36 -07001204 *
1205 * @deprecated Use {@link #obtain(long, long, int, float, float, float, float, int, float, float, int, int)}
1206 * instead.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001207 */
Jeff Brown5c225b12010-06-16 01:53:36 -07001208 @Deprecated
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001209 static public MotionEvent obtain(long downTime, long eventTime, int action,
1210 int pointers, float x, float y, float pressure, float size, int metaState,
1211 float xPrecision, float yPrecision, int deviceId, int edgeFlags) {
Jeff Brown5c225b12010-06-16 01:53:36 -07001212 return obtain(downTime, eventTime, action, x, y, pressure, size,
1213 metaState, xPrecision, yPrecision, deviceId, edgeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001214 }
Romain Guycafdea62009-06-12 10:51:36 -07001215
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001216 /**
1217 * Create a new MotionEvent, filling in a subset of the basic motion
1218 * values. Those not specified here are: device id (always 0), pressure
1219 * and size (always 1), x and y precision (always 1), and edgeFlags (always 0).
Romain Guycafdea62009-06-12 10:51:36 -07001220 *
1221 * @param downTime The time (in ms) when the user originally pressed down to start
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001222 * a stream of position events. This must be obtained from {@link SystemClock#uptimeMillis()}.
Romain Guycafdea62009-06-12 10:51:36 -07001223 * @param eventTime The the time (in ms) when this specific event was generated. This
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001224 * must be obtained from {@link SystemClock#uptimeMillis()}.
Jeff Browncc0c1592011-02-19 05:07:28 -08001225 * @param action The kind of action being performed, such as {@link #ACTION_DOWN}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001226 * @param x The X coordinate of this event.
1227 * @param y The Y coordinate of this event.
1228 * @param metaState The state of any meta / modifier keys that were in effect when
1229 * the event was generated.
1230 */
1231 static public MotionEvent obtain(long downTime, long eventTime, int action,
1232 float x, float y, int metaState) {
Jeff Brown5c225b12010-06-16 01:53:36 -07001233 return obtain(downTime, eventTime, action, x, y, 1.0f, 1.0f,
1234 metaState, 1.0f, 1.0f, 0, 0);
Mitsuru Oshima8169dae2009-04-28 18:12:09 -07001235 }
1236
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001237 /**
1238 * Create a new MotionEvent, copying from an existing one.
1239 */
Jeff Brown91c69ab2011-02-14 17:03:18 -08001240 static public MotionEvent obtain(MotionEvent other) {
1241 if (other == null) {
1242 throw new IllegalArgumentException("other motion event must not be null");
1243 }
1244
1245 MotionEvent ev = obtain();
1246 ev.mNativePtr = nativeCopy(ev.mNativePtr, other.mNativePtr, true /*keepHistory*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001247 return ev;
1248 }
Romain Guycafdea62009-06-12 10:51:36 -07001249
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001250 /**
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07001251 * Create a new MotionEvent, copying from an existing one, but not including
1252 * any historical point information.
1253 */
Jeff Brown91c69ab2011-02-14 17:03:18 -08001254 static public MotionEvent obtainNoHistory(MotionEvent other) {
1255 if (other == null) {
1256 throw new IllegalArgumentException("other motion event must not be null");
1257 }
1258
1259 MotionEvent ev = obtain();
1260 ev.mNativePtr = nativeCopy(ev.mNativePtr, other.mNativePtr, false /*keepHistory*/);
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07001261 return ev;
1262 }
1263
1264 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001265 * Recycle the MotionEvent, to be re-used by a later caller. After calling
1266 * this function you must not ever touch the event again.
1267 */
Jeff Brown5c225b12010-06-16 01:53:36 -07001268 public final void recycle() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001269 // Ensure recycle is only called once!
1270 if (TRACK_RECYCLED_LOCATION) {
1271 if (mRecycledLocation != null) {
1272 throw new RuntimeException(toString() + " recycled twice!", mRecycledLocation);
1273 }
1274 mRecycledLocation = new RuntimeException("Last recycled here");
Jeff Brownd28f4be2010-06-02 15:35:46 -07001275 //Log.w("MotionEvent", "Recycling event " + this, mRecycledLocation);
1276 } else {
1277 if (mRecycled) {
1278 throw new RuntimeException(toString() + " recycled twice!");
1279 }
1280 mRecycled = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001281 }
1282
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001283 synchronized (gRecyclerLock) {
1284 if (gRecyclerUsed < MAX_RECYCLED) {
1285 gRecyclerUsed++;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001286 mNext = gRecyclerTop;
1287 gRecyclerTop = this;
1288 }
1289 }
1290 }
Jeff Brown5c225b12010-06-16 01:53:36 -07001291
1292 /**
1293 * Scales down the coordination of this event by the given scale.
1294 *
1295 * @hide
1296 */
1297 public final void scale(float scale) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001298 nativeScale(mNativePtr, scale);
1299 }
1300
1301 /** {@inheritDoc} */
1302 @Override
1303 public final int getDeviceId() {
1304 return nativeGetDeviceId(mNativePtr);
1305 }
1306
1307 /** {@inheritDoc} */
1308 @Override
1309 public final int getSource() {
1310 return nativeGetSource(mNativePtr);
1311 }
1312
1313 /** {@inheritDoc} */
1314 @Override
1315 public final void setSource(int source) {
1316 nativeSetSource(mNativePtr, source);
Jeff Brown5c225b12010-06-16 01:53:36 -07001317 }
Romain Guycafdea62009-06-12 10:51:36 -07001318
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001319 /**
Jeff Browncc0c1592011-02-19 05:07:28 -08001320 * Return the kind of action being performed.
1321 * Consider using {@link #getActionMasked} and {@link #getActionIndex} to retrieve
1322 * the separate masked action and pointer index.
1323 * @return The action, such as {@link #ACTION_DOWN} or
1324 * the combination of {@link #ACTION_POINTER_DOWN} with a shifted pointer index.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001325 */
1326 public final int getAction() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001327 return nativeGetAction(mNativePtr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001328 }
1329
1330 /**
Jeff Browncc0c1592011-02-19 05:07:28 -08001331 * Return the masked action being performed, without pointer index information.
1332 * Use {@link #getActionIndex} to return the index associated with pointer actions.
1333 * @return The action, such as {@link #ACTION_DOWN} or {@link #ACTION_POINTER_DOWN}.
Dianne Hackbornb125dc52010-02-12 15:52:09 -08001334 */
1335 public final int getActionMasked() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001336 return nativeGetAction(mNativePtr) & ACTION_MASK;
Dianne Hackbornb125dc52010-02-12 15:52:09 -08001337 }
1338
1339 /**
1340 * For {@link #ACTION_POINTER_DOWN} or {@link #ACTION_POINTER_UP}
1341 * as returned by {@link #getActionMasked}, this returns the associated
Jeff Browncc0c1592011-02-19 05:07:28 -08001342 * pointer index.
1343 * The index may be used with {@link #getPointerId(int)},
Dianne Hackbornb125dc52010-02-12 15:52:09 -08001344 * {@link #getX(int)}, {@link #getY(int)}, {@link #getPressure(int)},
1345 * and {@link #getSize(int)} to get information about the pointer that has
1346 * gone down or up.
Jeff Browncc0c1592011-02-19 05:07:28 -08001347 * @return The index associated with the action.
Dianne Hackbornb125dc52010-02-12 15:52:09 -08001348 */
1349 public final int getActionIndex() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001350 return (nativeGetAction(mNativePtr) & ACTION_POINTER_INDEX_MASK)
1351 >> ACTION_POINTER_INDEX_SHIFT;
Dianne Hackbornb125dc52010-02-12 15:52:09 -08001352 }
1353
1354 /**
Jeff Brown33bbfd22011-02-24 20:55:35 -08001355 * Returns true if this motion event is a touch event.
1356 * <p>
1357 * Specifically excludes pointer events with action {@link #ACTION_HOVER_MOVE}
1358 * or {@link #ACTION_SCROLL} because they are not actually touch events
1359 * (the pointer is not down).
1360 * </p>
1361 * @return True if this motion event is a touch event.
1362 * @hide
1363 */
1364 public final boolean isTouchEvent() {
Jeff Brown56194eb2011-03-02 19:23:13 -08001365 return nativeIsTouchEvent(mNativePtr);
Jeff Brown33bbfd22011-02-24 20:55:35 -08001366 }
1367
1368 /**
Jeff Brown85a31762010-09-01 17:01:00 -07001369 * Gets the motion event flags.
1370 *
1371 * @see #FLAG_WINDOW_IS_OBSCURED
1372 */
1373 public final int getFlags() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001374 return nativeGetFlags(mNativePtr);
Jeff Brown85a31762010-09-01 17:01:00 -07001375 }
1376
1377 /**
Romain Guycafdea62009-06-12 10:51:36 -07001378 * Returns the time (in ms) when the user originally pressed down to start
1379 * a stream of position events.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001380 */
1381 public final long getDownTime() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001382 return nativeGetDownTimeNanos(mNativePtr) / NS_PER_MS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001383 }
1384
1385 /**
1386 * Returns the time (in ms) when this specific event was generated.
1387 */
1388 public final long getEventTime() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001389 return nativeGetEventTimeNanos(mNativePtr, HISTORY_CURRENT) / NS_PER_MS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001390 }
1391
1392 /**
Michael Chan53071d62009-05-13 17:29:48 -07001393 * Returns the time (in ns) when this specific event was generated.
1394 * The value is in nanosecond precision but it may not have nanosecond accuracy.
1395 *
1396 * @hide
1397 */
1398 public final long getEventTimeNano() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001399 return nativeGetEventTimeNanos(mNativePtr, HISTORY_CURRENT);
Michael Chan53071d62009-05-13 17:29:48 -07001400 }
1401
1402 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001403 * {@link #getX(int)} for the first pointer index (may be an
1404 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001405 *
1406 * @see #AXIS_X
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001407 */
1408 public final float getX() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001409 return nativeGetAxisValue(mNativePtr, AXIS_X, 0, HISTORY_CURRENT);
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001410 }
1411
1412 /**
1413 * {@link #getY(int)} for the first pointer index (may be an
1414 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001415 *
1416 * @see #AXIS_Y
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001417 */
1418 public final float getY() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001419 return nativeGetAxisValue(mNativePtr, AXIS_Y, 0, HISTORY_CURRENT);
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001420 }
1421
1422 /**
1423 * {@link #getPressure(int)} for the first pointer index (may be an
1424 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001425 *
1426 * @see #AXIS_PRESSURE
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001427 */
1428 public final float getPressure() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001429 return nativeGetAxisValue(mNativePtr, AXIS_PRESSURE, 0, HISTORY_CURRENT);
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001430 }
1431
1432 /**
1433 * {@link #getSize(int)} for the first pointer index (may be an
1434 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001435 *
1436 * @see #AXIS_SIZE
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001437 */
1438 public final float getSize() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001439 return nativeGetAxisValue(mNativePtr, AXIS_SIZE, 0, HISTORY_CURRENT);
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001440 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07001441
1442 /**
1443 * {@link #getTouchMajor(int)} for the first pointer index (may be an
1444 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001445 *
1446 * @see #AXIS_TOUCH_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07001447 */
1448 public final float getTouchMajor() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001449 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MAJOR, 0, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001450 }
1451
1452 /**
1453 * {@link #getTouchMinor(int)} for the first pointer index (may be an
1454 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001455 *
1456 * @see #AXIS_TOUCH_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07001457 */
1458 public final float getTouchMinor() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001459 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MINOR, 0, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001460 }
1461
1462 /**
1463 * {@link #getToolMajor(int)} for the first pointer index (may be an
1464 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001465 *
1466 * @see #AXIS_TOOL_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07001467 */
1468 public final float getToolMajor() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001469 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MAJOR, 0, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001470 }
1471
1472 /**
1473 * {@link #getToolMinor(int)} for the first pointer index (may be an
1474 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001475 *
1476 * @see #AXIS_TOOL_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07001477 */
1478 public final float getToolMinor() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001479 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MINOR, 0, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001480 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08001481
Jeff Brownc5ed5912010-07-14 18:48:53 -07001482 /**
1483 * {@link #getOrientation(int)} for the first pointer index (may be an
1484 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001485 *
1486 * @see #AXIS_ORIENTATION
Jeff Brownc5ed5912010-07-14 18:48:53 -07001487 */
1488 public final float getOrientation() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001489 return nativeGetAxisValue(mNativePtr, AXIS_ORIENTATION, 0, HISTORY_CURRENT);
1490 }
1491
1492 /**
1493 * {@link #getAxisValue(int)} for the first pointer index (may be an
1494 * arbitrary pointer identifier).
1495 *
1496 * @param axis The axis identifier for the axis value to retrieve.
1497 *
1498 * @see #AXIS_X
1499 * @see #AXIS_Y
1500 */
1501 public final float getAxisValue(int axis) {
1502 return nativeGetAxisValue(mNativePtr, axis, 0, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001503 }
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001504
1505 /**
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001506 * The number of pointers of data contained in this event. Always
1507 * >= 1.
1508 */
1509 public final int getPointerCount() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001510 return nativeGetPointerCount(mNativePtr);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001511 }
1512
1513 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001514 * Return the pointer identifier associated with a particular pointer
1515 * data index is this event. The identifier tells you the actual pointer
1516 * number associated with the data, accounting for individual pointers
1517 * going up and down since the start of the current gesture.
1518 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1519 * (the first pointer that is down) to {@link #getPointerCount()}-1.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001520 */
Dianne Hackbornd41ba662009-08-05 15:30:56 -07001521 public final int getPointerId(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001522 return nativeGetPointerId(mNativePtr, pointerIndex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001523 }
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001524
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001525 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001526 * Given a pointer identifier, find the index of its data in the event.
1527 *
1528 * @param pointerId The identifier of the pointer to be found.
1529 * @return Returns either the index of the pointer (for use with
Gilles Debunneb0d6ba12010-08-17 20:01:42 -07001530 * {@link #getX(int)} et al.), or -1 if there is no data available for
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001531 * that pointer identifier.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001532 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001533 public final int findPointerIndex(int pointerId) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001534 return nativeFindPointerIndex(mNativePtr, pointerId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001535 }
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001536
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001537 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001538 * Returns the X coordinate of this event for the given pointer
1539 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
1540 * identifier for this index).
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001541 * Whole numbers are pixels; the
1542 * value may have a fraction for input devices that are sub-pixel precise.
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001543 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1544 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08001545 *
1546 * @see #AXIS_X
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001547 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001548 public final float getX(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001549 return nativeGetAxisValue(mNativePtr, AXIS_X, pointerIndex, HISTORY_CURRENT);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001550 }
1551
1552 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001553 * Returns the Y coordinate of this event for the given pointer
1554 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
1555 * identifier for this index).
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001556 * Whole numbers are pixels; the
1557 * value may have a fraction for input devices that are sub-pixel precise.
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001558 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1559 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08001560 *
1561 * @see #AXIS_Y
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001562 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001563 public final float getY(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001564 return nativeGetAxisValue(mNativePtr, AXIS_Y, pointerIndex, HISTORY_CURRENT);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001565 }
1566
1567 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001568 * Returns the current pressure of this event for the given pointer
1569 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
1570 * identifier for this index).
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001571 * The pressure generally
Romain Guycafdea62009-06-12 10:51:36 -07001572 * ranges from 0 (no pressure at all) to 1 (normal pressure), however
1573 * values higher than 1 may be generated depending on the calibration of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001574 * the input device.
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001575 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1576 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08001577 *
1578 * @see #AXIS_PRESSURE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001579 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001580 public final float getPressure(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001581 return nativeGetAxisValue(mNativePtr, AXIS_PRESSURE, pointerIndex, HISTORY_CURRENT);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001582 }
1583
1584 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001585 * Returns a scaled value of the approximate size for the given pointer
1586 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
1587 * identifier for this index).
1588 * This represents some approximation of the area of the screen being
1589 * pressed; the actual value in pixels corresponding to the
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001590 * touch is normalized with the device specific range of values
Romain Guycafdea62009-06-12 10:51:36 -07001591 * and scaled to a value between 0 and 1. The value of size can be used to
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001592 * determine fat touch events.
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001593 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1594 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08001595 *
1596 * @see #AXIS_SIZE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001597 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001598 public final float getSize(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001599 return nativeGetAxisValue(mNativePtr, AXIS_SIZE, pointerIndex, HISTORY_CURRENT);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001600 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07001601
1602 /**
1603 * Returns the length of the major axis of an ellipse that describes the touch
1604 * area at the point of contact for the given pointer
1605 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
1606 * identifier for this index).
1607 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1608 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08001609 *
1610 * @see #AXIS_TOUCH_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07001611 */
1612 public final float getTouchMajor(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001613 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MAJOR, pointerIndex, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001614 }
1615
1616 /**
1617 * Returns the length of the minor axis of an ellipse that describes the touch
1618 * area at the point of contact for the given pointer
1619 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
1620 * identifier for this index).
1621 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1622 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08001623 *
1624 * @see #AXIS_TOUCH_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07001625 */
1626 public final float getTouchMinor(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001627 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MINOR, pointerIndex, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001628 }
1629
1630 /**
1631 * Returns the length of the major axis of an ellipse that describes the size of
1632 * the approaching tool for the given pointer
1633 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
1634 * identifier for this index).
1635 * The tool area represents the estimated size of the finger or pen that is
1636 * touching the device independent of its actual touch area at the point of contact.
1637 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1638 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08001639 *
1640 * @see #AXIS_TOOL_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07001641 */
1642 public final float getToolMajor(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001643 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MAJOR, pointerIndex, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001644 }
1645
1646 /**
1647 * Returns the length of the minor axis of an ellipse that describes the size of
1648 * the approaching tool for the given pointer
1649 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
1650 * identifier for this index).
1651 * The tool area represents the estimated size of the finger or pen that is
1652 * touching the device independent of its actual touch area at the point of contact.
1653 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1654 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08001655 *
1656 * @see #AXIS_TOOL_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07001657 */
1658 public final float getToolMinor(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001659 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MINOR, pointerIndex, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001660 }
1661
1662 /**
1663 * Returns the orientation of the touch area and tool area in radians clockwise from vertical
1664 * for the given pointer <em>index</em> (use {@link #getPointerId(int)} to find the pointer
1665 * identifier for this index).
Jeff Brown6f2fba42011-02-19 01:08:02 -08001666 * An angle of 0 radians indicates that the major axis of contact is oriented
Jeff Brownc5ed5912010-07-14 18:48:53 -07001667 * upwards, is perfectly circular or is of unknown orientation. A positive angle
1668 * indicates that the major axis of contact is oriented to the right. A negative angle
1669 * indicates that the major axis of contact is oriented to the left.
Jeff Brown6d0fec22010-07-23 21:28:06 -07001670 * The full range is from -PI/2 radians (finger pointing fully left) to PI/2 radians
Jeff Brownc5ed5912010-07-14 18:48:53 -07001671 * (finger pointing fully right).
1672 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1673 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08001674 *
1675 * @see #AXIS_ORIENTATION
Jeff Brownc5ed5912010-07-14 18:48:53 -07001676 */
1677 public final float getOrientation(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001678 return nativeGetAxisValue(mNativePtr, AXIS_ORIENTATION, pointerIndex, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001679 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08001680
1681 /**
1682 * Returns the value of the requested axis for the given pointer <em>index</em>
1683 * (use {@link #getPointerId(int)} to find the pointer identifier for this index).
1684 *
1685 * @param axis The axis identifier for the axis value to retrieve.
1686 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1687 * (the first pointer that is down) to {@link #getPointerCount()}-1.
1688 * @return The value of the axis, or 0 if the axis is not available.
1689 *
1690 * @see #AXIS_X
1691 * @see #AXIS_Y
1692 */
1693 public final float getAxisValue(int axis, int pointerIndex) {
1694 return nativeGetAxisValue(mNativePtr, axis, pointerIndex, HISTORY_CURRENT);
1695 }
1696
Jeff Brownc5ed5912010-07-14 18:48:53 -07001697 /**
1698 * Populates a {@link PointerCoords} object with pointer coordinate data for
1699 * the specified pointer index.
1700 *
1701 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1702 * (the first pointer that is down) to {@link #getPointerCount()}-1.
1703 * @param outPointerCoords The pointer coordinate object to populate.
Jeff Brown91c69ab2011-02-14 17:03:18 -08001704 *
1705 * @see PointerCoords
Jeff Brownc5ed5912010-07-14 18:48:53 -07001706 */
1707 public final void getPointerCoords(int pointerIndex, PointerCoords outPointerCoords) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001708 nativeGetPointerCoords(mNativePtr, pointerIndex, HISTORY_CURRENT, outPointerCoords);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001709 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001710
1711 /**
1712 * Returns the state of any meta / modifier keys that were in effect when
1713 * the event was generated. This is the same values as those
1714 * returned by {@link KeyEvent#getMetaState() KeyEvent.getMetaState}.
1715 *
1716 * @return an integer in which each bit set to 1 represents a pressed
1717 * meta key
1718 *
1719 * @see KeyEvent#getMetaState()
1720 */
1721 public final int getMetaState() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001722 return nativeGetMetaState(mNativePtr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001723 }
1724
1725 /**
1726 * Returns the original raw X coordinate of this event. For touch
1727 * events on the screen, this is the original location of the event
1728 * on the screen, before it had been adjusted for the containing window
1729 * and views.
Jeff Brown91c69ab2011-02-14 17:03:18 -08001730 *
1731 * @see getX()
1732 * @see #AXIS_X
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001733 */
1734 public final float getRawX() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001735 return nativeGetRawAxisValue(mNativePtr, AXIS_X, 0, HISTORY_CURRENT);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001736 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08001737
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001738 /**
1739 * Returns the original raw Y coordinate of this event. For touch
1740 * events on the screen, this is the original location of the event
1741 * on the screen, before it had been adjusted for the containing window
1742 * and views.
Jeff Brown91c69ab2011-02-14 17:03:18 -08001743 *
1744 * @see getY()
1745 * @see #AXIS_Y
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001746 */
1747 public final float getRawY() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001748 return nativeGetRawAxisValue(mNativePtr, AXIS_Y, 0, HISTORY_CURRENT);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001749 }
1750
1751 /**
1752 * Return the precision of the X coordinates being reported. You can
Jeff Brown91c69ab2011-02-14 17:03:18 -08001753 * multiply this number with {@link #getX} to find the actual hardware
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001754 * value of the X coordinate.
1755 * @return Returns the precision of X coordinates being reported.
Jeff Brown91c69ab2011-02-14 17:03:18 -08001756 *
1757 * @see #AXIS_X
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001758 */
1759 public final float getXPrecision() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001760 return nativeGetXPrecision(mNativePtr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001761 }
Romain Guycafdea62009-06-12 10:51:36 -07001762
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001763 /**
1764 * Return the precision of the Y coordinates being reported. You can
Jeff Brown91c69ab2011-02-14 17:03:18 -08001765 * multiply this number with {@link #getY} to find the actual hardware
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001766 * value of the Y coordinate.
1767 * @return Returns the precision of Y coordinates being reported.
Jeff Brown91c69ab2011-02-14 17:03:18 -08001768 *
1769 * @see #AXIS_Y
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001770 */
1771 public final float getYPrecision() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001772 return nativeGetYPrecision(mNativePtr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001773 }
Romain Guycafdea62009-06-12 10:51:36 -07001774
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001775 /**
1776 * Returns the number of historical points in this event. These are
1777 * movements that have occurred between this event and the previous event.
1778 * This only applies to ACTION_MOVE events -- all other actions will have
1779 * a size of 0.
Romain Guycafdea62009-06-12 10:51:36 -07001780 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001781 * @return Returns the number of historical points in the event.
1782 */
1783 public final int getHistorySize() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001784 return nativeGetHistorySize(mNativePtr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001785 }
Romain Guycafdea62009-06-12 10:51:36 -07001786
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001787 /**
1788 * Returns the time that a historical movement occurred between this event
1789 * and the previous event. Only applies to ACTION_MOVE events.
Romain Guycafdea62009-06-12 10:51:36 -07001790 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001791 * @param pos Which historical value to return; must be less than
1792 * {@link #getHistorySize}
Romain Guycafdea62009-06-12 10:51:36 -07001793 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001794 * @see #getHistorySize
1795 * @see #getEventTime
1796 */
1797 public final long getHistoricalEventTime(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001798 return nativeGetEventTimeNanos(mNativePtr, pos) / NS_PER_MS;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001799 }
1800
1801 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08001802 * {@link #getHistoricalX(int, int)} for the first pointer index (may be an
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001803 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001804 *
1805 * @param pos Which historical value to return; must be less than
1806 * {@link #getHistorySize}
1807 *
1808 * @see #getHistorySize
1809 * @see #getX()
1810 * @see #AXIS_X
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001811 */
1812 public final float getHistoricalX(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001813 return nativeGetAxisValue(mNativePtr, AXIS_X, 0, pos);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001814 }
1815
1816 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08001817 * {@link #getHistoricalY(int, int)} for the first pointer index (may be an
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001818 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001819 *
1820 * @param pos Which historical value to return; must be less than
1821 * {@link #getHistorySize}
1822 *
1823 * @see #getHistorySize
1824 * @see #getY()
1825 * @see #AXIS_Y
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001826 */
1827 public final float getHistoricalY(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001828 return nativeGetAxisValue(mNativePtr, AXIS_Y, 0, pos);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001829 }
1830
1831 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08001832 * {@link #getHistoricalPressure(int, int)} for the first pointer index (may be an
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001833 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001834 *
1835 * @param pos Which historical value to return; must be less than
1836 * {@link #getHistorySize}
1837 *
1838 * @see #getHistorySize
1839 * @see #getPressure()
1840 * @see #AXIS_PRESSURE
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001841 */
1842 public final float getHistoricalPressure(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001843 return nativeGetAxisValue(mNativePtr, AXIS_PRESSURE, 0, pos);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001844 }
1845
1846 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08001847 * {@link #getHistoricalSize(int, int)} for the first pointer index (may be an
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001848 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001849 *
1850 * @param pos Which historical value to return; must be less than
1851 * {@link #getHistorySize}
1852 *
1853 * @see #getHistorySize
1854 * @see #getSize()
1855 * @see #AXIS_SIZE
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001856 */
1857 public final float getHistoricalSize(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001858 return nativeGetAxisValue(mNativePtr, AXIS_SIZE, 0, pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001859 }
Romain Guycafdea62009-06-12 10:51:36 -07001860
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001861 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08001862 * {@link #getHistoricalTouchMajor(int, int)} for the first pointer index (may be an
Jeff Brownc5ed5912010-07-14 18:48:53 -07001863 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001864 *
1865 * @param pos Which historical value to return; must be less than
1866 * {@link #getHistorySize}
1867 *
1868 * @see #getHistorySize
1869 * @see #getTouchMajor()
1870 * @see #AXIS_TOUCH_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07001871 */
1872 public final float getHistoricalTouchMajor(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001873 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MAJOR, 0, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001874 }
1875
1876 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08001877 * {@link #getHistoricalTouchMinor(int, int)} for the first pointer index (may be an
Jeff Brownc5ed5912010-07-14 18:48:53 -07001878 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001879 *
1880 * @param pos Which historical value to return; must be less than
1881 * {@link #getHistorySize}
1882 *
1883 * @see #getHistorySize
1884 * @see #getTouchMinor()
1885 * @see #AXIS_TOUCH_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07001886 */
1887 public final float getHistoricalTouchMinor(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001888 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MINOR, 0, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001889 }
1890
1891 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08001892 * {@link #getHistoricalToolMajor(int, int)} for the first pointer index (may be an
Jeff Brownc5ed5912010-07-14 18:48:53 -07001893 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001894 *
1895 * @param pos Which historical value to return; must be less than
1896 * {@link #getHistorySize}
1897 *
1898 * @see #getHistorySize
1899 * @see #getToolMajor()
1900 * @see #AXIS_TOOL_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07001901 */
1902 public final float getHistoricalToolMajor(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001903 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MAJOR, 0, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001904 }
1905
1906 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08001907 * {@link #getHistoricalToolMinor(int, int)} for the first pointer index (may be an
Jeff Brownc5ed5912010-07-14 18:48:53 -07001908 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001909 *
1910 * @param pos Which historical value to return; must be less than
1911 * {@link #getHistorySize}
1912 *
1913 * @see #getHistorySize
1914 * @see #getToolMinor()
1915 * @see #AXIS_TOOL_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07001916 */
1917 public final float getHistoricalToolMinor(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001918 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MINOR, 0, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001919 }
1920
1921 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08001922 * {@link #getHistoricalOrientation(int, int)} for the first pointer index (may be an
Jeff Brownc5ed5912010-07-14 18:48:53 -07001923 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001924 *
1925 * @param pos Which historical value to return; must be less than
1926 * {@link #getHistorySize}
1927 *
1928 * @see #getHistorySize
1929 * @see #getOrientation()
1930 * @see #AXIS_ORIENTATION
Jeff Brownc5ed5912010-07-14 18:48:53 -07001931 */
1932 public final float getHistoricalOrientation(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001933 return nativeGetAxisValue(mNativePtr, AXIS_ORIENTATION, 0, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001934 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08001935
1936 /**
1937 * {@link #getHistoricalAxisValue(int, int, int)} for the first pointer index (may be an
1938 * arbitrary pointer identifier).
1939 *
1940 * @param axis The axis identifier for the axis value to retrieve.
1941 * @param pos Which historical value to return; must be less than
1942 * {@link #getHistorySize}
1943 *
1944 * @see #getHistorySize
1945 * @see #getAxisValue(int)
1946 * @see #AXIS_X
1947 * @see #AXIS_Y
1948 */
1949 public final float getHistoricalAxisValue(int axis, int pos) {
1950 return nativeGetAxisValue(mNativePtr, axis, 0, pos);
1951 }
1952
Jeff Brownc5ed5912010-07-14 18:48:53 -07001953 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001954 * Returns a historical X coordinate, as per {@link #getX(int)}, that
1955 * occurred between this event and the previous event for the given pointer.
1956 * Only applies to ACTION_MOVE events.
Romain Guycafdea62009-06-12 10:51:36 -07001957 *
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001958 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1959 * (the first pointer that is down) to {@link #getPointerCount()}-1.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001960 * @param pos Which historical value to return; must be less than
1961 * {@link #getHistorySize}
Romain Guycafdea62009-06-12 10:51:36 -07001962 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001963 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08001964 * @see #getX(int)
1965 * @see #AXIS_X
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001966 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001967 public final float getHistoricalX(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001968 return nativeGetAxisValue(mNativePtr, AXIS_X, pointerIndex, pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001969 }
Romain Guycafdea62009-06-12 10:51:36 -07001970
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001971 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001972 * Returns a historical Y coordinate, as per {@link #getY(int)}, that
1973 * occurred between this event and the previous event for the given pointer.
1974 * Only applies to ACTION_MOVE events.
Romain Guycafdea62009-06-12 10:51:36 -07001975 *
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001976 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1977 * (the first pointer that is down) to {@link #getPointerCount()}-1.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001978 * @param pos Which historical value to return; must be less than
1979 * {@link #getHistorySize}
Romain Guycafdea62009-06-12 10:51:36 -07001980 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001981 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08001982 * @see #getY(int)
1983 * @see #AXIS_Y
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001984 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001985 public final float getHistoricalY(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001986 return nativeGetAxisValue(mNativePtr, AXIS_Y, pointerIndex, pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001987 }
Romain Guycafdea62009-06-12 10:51:36 -07001988
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001989 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001990 * Returns a historical pressure coordinate, as per {@link #getPressure(int)},
1991 * that occurred between this event and the previous event for the given
1992 * pointer. Only applies to ACTION_MOVE events.
Romain Guycafdea62009-06-12 10:51:36 -07001993 *
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001994 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1995 * (the first pointer that is down) to {@link #getPointerCount()}-1.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001996 * @param pos Which historical value to return; must be less than
1997 * {@link #getHistorySize}
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001998 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001999 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08002000 * @see #getPressure(int)
2001 * @see #AXIS_PRESSURE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002002 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002003 public final float getHistoricalPressure(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002004 return nativeGetAxisValue(mNativePtr, AXIS_PRESSURE, pointerIndex, pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002005 }
Romain Guycafdea62009-06-12 10:51:36 -07002006
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002007 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002008 * Returns a historical size coordinate, as per {@link #getSize(int)}, that
2009 * occurred between this event and the previous event for the given pointer.
2010 * Only applies to ACTION_MOVE events.
Romain Guycafdea62009-06-12 10:51:36 -07002011 *
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002012 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2013 * (the first pointer that is down) to {@link #getPointerCount()}-1.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002014 * @param pos Which historical value to return; must be less than
2015 * {@link #getHistorySize}
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002016 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002017 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08002018 * @see #getSize(int)
2019 * @see #AXIS_SIZE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002020 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002021 public final float getHistoricalSize(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002022 return nativeGetAxisValue(mNativePtr, AXIS_SIZE, pointerIndex, pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002023 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002024
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002025 /**
Jeff Brownc5ed5912010-07-14 18:48:53 -07002026 * Returns a historical touch major axis coordinate, as per {@link #getTouchMajor(int)}, that
2027 * occurred between this event and the previous event for the given pointer.
2028 * Only applies to ACTION_MOVE events.
2029 *
2030 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2031 * (the first pointer that is down) to {@link #getPointerCount()}-1.
2032 * @param pos Which historical value to return; must be less than
2033 * {@link #getHistorySize}
2034 *
2035 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08002036 * @see #getTouchMajor(int)
2037 * @see #AXIS_TOUCH_MAJOR
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002038 */
Jeff Brownc5ed5912010-07-14 18:48:53 -07002039 public final float getHistoricalTouchMajor(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002040 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MAJOR, pointerIndex, pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002041 }
Romain Guycafdea62009-06-12 10:51:36 -07002042
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002043 /**
Jeff Brownc5ed5912010-07-14 18:48:53 -07002044 * Returns a historical touch minor axis coordinate, as per {@link #getTouchMinor(int)}, that
2045 * occurred between this event and the previous event for the given pointer.
2046 * Only applies to ACTION_MOVE events.
2047 *
2048 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2049 * (the first pointer that is down) to {@link #getPointerCount()}-1.
2050 * @param pos Which historical value to return; must be less than
2051 * {@link #getHistorySize}
2052 *
2053 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08002054 * @see #getTouchMinor(int)
2055 * @see #AXIS_TOUCH_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002056 */
2057 public final float getHistoricalTouchMinor(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002058 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MINOR, pointerIndex, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002059 }
2060
2061 /**
2062 * Returns a historical tool major axis coordinate, as per {@link #getToolMajor(int)}, that
2063 * occurred between this event and the previous event for the given pointer.
2064 * Only applies to ACTION_MOVE events.
2065 *
2066 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2067 * (the first pointer that is down) to {@link #getPointerCount()}-1.
2068 * @param pos Which historical value to return; must be less than
2069 * {@link #getHistorySize}
2070 *
2071 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08002072 * @see #getToolMajor(int)
2073 * @see #AXIS_TOOL_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002074 */
2075 public final float getHistoricalToolMajor(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002076 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MAJOR, pointerIndex, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002077 }
2078
2079 /**
2080 * Returns a historical tool minor axis coordinate, as per {@link #getToolMinor(int)}, that
2081 * occurred between this event and the previous event for the given pointer.
2082 * Only applies to ACTION_MOVE events.
2083 *
2084 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2085 * (the first pointer that is down) to {@link #getPointerCount()}-1.
2086 * @param pos Which historical value to return; must be less than
2087 * {@link #getHistorySize}
2088 *
2089 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08002090 * @see #getToolMinor(int)
2091 * @see #AXIS_TOOL_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002092 */
2093 public final float getHistoricalToolMinor(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002094 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MINOR, pointerIndex, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002095 }
2096
2097 /**
2098 * Returns a historical orientation coordinate, as per {@link #getOrientation(int)}, that
2099 * occurred between this event and the previous event for the given pointer.
2100 * Only applies to ACTION_MOVE events.
2101 *
2102 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2103 * (the first pointer that is down) to {@link #getPointerCount()}-1.
2104 * @param pos Which historical value to return; must be less than
2105 * {@link #getHistorySize}
2106 *
2107 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08002108 * @see #getOrientation(int)
2109 * @see #AXIS_ORIENTATION
Jeff Brownc5ed5912010-07-14 18:48:53 -07002110 */
2111 public final float getHistoricalOrientation(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002112 return nativeGetAxisValue(mNativePtr, AXIS_ORIENTATION, pointerIndex, pos);
2113 }
2114
2115 /**
2116 * Returns the historical value of the requested axis, as per {@link #getAxisValue(int, int)},
2117 * occurred between this event and the previous event for the given pointer.
2118 * Only applies to ACTION_MOVE events.
2119 *
2120 * @param axis The axis identifier for the axis value to retrieve.
2121 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2122 * (the first pointer that is down) to {@link #getPointerCount()}-1.
2123 * @param pos Which historical value to return; must be less than
2124 * {@link #getHistorySize}
2125 * @return The value of the axis, or 0 if the axis is not available.
2126 *
2127 * @see #AXIS_X
2128 * @see #AXIS_Y
2129 */
2130 public final float getHistoricalAxisValue(int axis, int pointerIndex, int pos) {
2131 return nativeGetAxisValue(mNativePtr, axis, pointerIndex, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002132 }
2133
2134 /**
2135 * Populates a {@link PointerCoords} object with historical pointer coordinate data,
2136 * as per {@link #getPointerCoords}, that occurred between this event and the previous
2137 * event for the given pointer.
2138 * Only applies to ACTION_MOVE events.
2139 *
2140 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2141 * (the first pointer that is down) to {@link #getPointerCount()}-1.
2142 * @param pos Which historical value to return; must be less than
2143 * {@link #getHistorySize}
2144 * @param outPointerCoords The pointer coordinate object to populate.
2145 *
2146 * @see #getHistorySize
2147 * @see #getPointerCoords
Jeff Brown91c69ab2011-02-14 17:03:18 -08002148 * @see PointerCoords
Jeff Brownc5ed5912010-07-14 18:48:53 -07002149 */
2150 public final void getHistoricalPointerCoords(int pointerIndex, int pos,
2151 PointerCoords outPointerCoords) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002152 nativeGetPointerCoords(mNativePtr, pointerIndex, pos, outPointerCoords);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002153 }
2154
2155 /**
Jeff Brown46b9ac02010-04-22 18:58:52 -07002156 * Returns a bitfield indicating which edges, if any, were touched by this
Romain Guycafdea62009-06-12 10:51:36 -07002157 * MotionEvent. For touch events, clients can use this to determine if the
2158 * user's finger was touching the edge of the display.
2159 *
Jeff Brownd41cff22011-03-03 02:09:54 -08002160 * This property is only set for {@link #ACTION_DOWN} events.
2161 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002162 * @see #EDGE_LEFT
2163 * @see #EDGE_TOP
2164 * @see #EDGE_RIGHT
2165 * @see #EDGE_BOTTOM
2166 */
2167 public final int getEdgeFlags() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002168 return nativeGetEdgeFlags(mNativePtr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002169 }
Romain Guycafdea62009-06-12 10:51:36 -07002170
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002171 /**
Jeff Brown85a31762010-09-01 17:01:00 -07002172 * Sets the bitfield indicating which edges, if any, were touched by this
Romain Guycafdea62009-06-12 10:51:36 -07002173 * MotionEvent.
2174 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002175 * @see #getEdgeFlags()
2176 */
2177 public final void setEdgeFlags(int flags) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002178 nativeSetEdgeFlags(mNativePtr, flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002179 }
2180
2181 /**
2182 * Sets this event's action.
2183 */
2184 public final void setAction(int action) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002185 nativeSetAction(mNativePtr, action);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002186 }
2187
2188 /**
2189 * Adjust this event's location.
2190 * @param deltaX Amount to add to the current X coordinate of the event.
2191 * @param deltaY Amount to add to the current Y coordinate of the event.
2192 */
2193 public final void offsetLocation(float deltaX, float deltaY) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002194 nativeOffsetLocation(mNativePtr, deltaX, deltaY);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002195 }
Romain Guycafdea62009-06-12 10:51:36 -07002196
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002197 /**
2198 * Set this event's location. Applies {@link #offsetLocation} with a
2199 * delta from the current location to the given new location.
Romain Guycafdea62009-06-12 10:51:36 -07002200 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002201 * @param x New absolute X location.
2202 * @param y New absolute Y location.
2203 */
2204 public final void setLocation(float x, float y) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002205 float oldX = getX();
2206 float oldY = getY();
2207 nativeOffsetLocation(mNativePtr, x - oldX, y - oldY);
Jeff Brown5c225b12010-06-16 01:53:36 -07002208 }
2209
Jeff Brown20e987b2010-08-23 12:01:02 -07002210 /**
2211 * Applies a transformation matrix to all of the points in the event.
2212 *
2213 * @param matrix The transformation matrix to apply.
2214 */
2215 public final void transform(Matrix matrix) {
2216 if (matrix == null) {
2217 throw new IllegalArgumentException("matrix must not be null");
2218 }
2219
Jeff Brown91c69ab2011-02-14 17:03:18 -08002220 nativeTransform(mNativePtr, matrix);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002221 }
Romain Guycafdea62009-06-12 10:51:36 -07002222
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002223 /**
2224 * Add a new movement to the batch of movements in this event. The event's
Jeff Brownc5ed5912010-07-14 18:48:53 -07002225 * current location, position and size is updated to the new values.
2226 * The current values in the event are added to a list of historical values.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002227 *
Jeff Browncc0c1592011-02-19 05:07:28 -08002228 * Only applies to {@link #ACTION_MOVE} or {@link #ACTION_HOVER_MOVE} events.
Romain Guycafdea62009-06-12 10:51:36 -07002229 *
Jeff Brownc5ed5912010-07-14 18:48:53 -07002230 * @param eventTime The time stamp (in ms) for this data.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002231 * @param x The new X position.
2232 * @param y The new Y position.
2233 * @param pressure The new pressure.
2234 * @param size The new size.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002235 * @param metaState Meta key state.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002236 */
2237 public final void addBatch(long eventTime, float x, float y,
2238 float pressure, float size, int metaState) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002239 synchronized (gTmpPointerCoords) {
2240 final PointerCoords pc = gTmpPointerCoords[0];
2241 pc.clear();
2242 pc.x = x;
2243 pc.y = y;
2244 pc.pressure = pressure;
2245 pc.size = size;
2246 nativeAddBatch(mNativePtr, eventTime * NS_PER_MS, gTmpPointerCoords, metaState);
2247 }
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002248 }
Romain Guycafdea62009-06-12 10:51:36 -07002249
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002250 /**
Jeff Brownc5ed5912010-07-14 18:48:53 -07002251 * Add a new movement to the batch of movements in this event. The event's
2252 * current location, position and size is updated to the new values.
2253 * The current values in the event are added to a list of historical values.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002254 *
Jeff Browncc0c1592011-02-19 05:07:28 -08002255 * Only applies to {@link #ACTION_MOVE} or {@link #ACTION_HOVER_MOVE} events.
Jeff Brownc5ed5912010-07-14 18:48:53 -07002256 *
2257 * @param eventTime The time stamp (in ms) for this data.
2258 * @param pointerCoords The new pointer coordinates.
2259 * @param metaState Meta key state.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002260 */
Jeff Brownc5ed5912010-07-14 18:48:53 -07002261 public final void addBatch(long eventTime, PointerCoords[] pointerCoords, int metaState) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002262 nativeAddBatch(mNativePtr, eventTime * NS_PER_MS, pointerCoords, metaState);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002263 }
Romain Guycafdea62009-06-12 10:51:36 -07002264
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002265 @Override
2266 public String toString() {
2267 return "MotionEvent{" + Integer.toHexString(System.identityHashCode(this))
Huahui Wue838a422011-01-13 16:03:43 -08002268 + " pointerId=" + getPointerId(0)
Jeff Brown91c69ab2011-02-14 17:03:18 -08002269 + " action=" + actionToString(getAction())
Jeff Brown497a92c2010-09-12 17:55:08 -07002270 + " x=" + getX()
2271 + " y=" + getY()
2272 + " pressure=" + getPressure()
2273 + " size=" + getSize()
2274 + " touchMajor=" + getTouchMajor()
2275 + " touchMinor=" + getTouchMinor()
2276 + " toolMajor=" + getToolMajor()
2277 + " toolMinor=" + getToolMinor()
2278 + " orientation=" + getOrientation()
Jeff Brown91c69ab2011-02-14 17:03:18 -08002279 + " meta=" + KeyEvent.metaStateToString(getMetaState())
Jeff Brown497a92c2010-09-12 17:55:08 -07002280 + " pointerCount=" + getPointerCount()
2281 + " historySize=" + getHistorySize()
Jeff Brown91c69ab2011-02-14 17:03:18 -08002282 + " flags=0x" + Integer.toHexString(getFlags())
2283 + " edgeFlags=0x" + Integer.toHexString(getEdgeFlags())
2284 + " device=" + getDeviceId()
2285 + " source=0x" + Integer.toHexString(getSource())
Huahui Wue838a422011-01-13 16:03:43 -08002286 + (getPointerCount() > 1 ?
Huahui Wuf9324692011-01-24 12:07:37 -08002287 " pointerId2=" + getPointerId(1) + " x2=" + getX(1) + " y2=" + getY(1) : "")
Jeff Brown497a92c2010-09-12 17:55:08 -07002288 + "}";
2289 }
2290
2291 /**
2292 * Returns a string that represents the symbolic name of the specified action
Jeff Brown91c69ab2011-02-14 17:03:18 -08002293 * such as "ACTION_DOWN", "ACTION_POINTER_DOWN(3)" or an equivalent numeric constant
2294 * such as "35" if unknown.
Jeff Brown497a92c2010-09-12 17:55:08 -07002295 *
2296 * @param action The action.
2297 * @return The symbolic name of the specified action.
2298 * @hide
2299 */
2300 public static String actionToString(int action) {
2301 switch (action) {
2302 case ACTION_DOWN:
2303 return "ACTION_DOWN";
2304 case ACTION_UP:
2305 return "ACTION_UP";
2306 case ACTION_CANCEL:
2307 return "ACTION_CANCEL";
Jeff Brown33bbfd22011-02-24 20:55:35 -08002308 case ACTION_OUTSIDE:
2309 return "ACTION_OUTSIDE";
Jeff Brown497a92c2010-09-12 17:55:08 -07002310 case ACTION_MOVE:
2311 return "ACTION_MOVE";
Jeff Browncc0c1592011-02-19 05:07:28 -08002312 case ACTION_HOVER_MOVE:
2313 return "ACTION_HOVER_MOVE";
Jeff Brown33bbfd22011-02-24 20:55:35 -08002314 case ACTION_SCROLL:
2315 return "ACTION_SCROLL";
Jeff Brown497a92c2010-09-12 17:55:08 -07002316 }
2317 int index = (action & ACTION_POINTER_INDEX_MASK) >> ACTION_POINTER_INDEX_SHIFT;
2318 switch (action & ACTION_MASK) {
2319 case ACTION_POINTER_DOWN:
2320 return "ACTION_POINTER_DOWN(" + index + ")";
2321 case ACTION_POINTER_UP:
2322 return "ACTION_POINTER_UP(" + index + ")";
2323 default:
2324 return Integer.toString(action);
2325 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002326 }
2327
Jeff Brown91c69ab2011-02-14 17:03:18 -08002328 /**
2329 * Returns a string that represents the symbolic name of the specified axis
Jeff Brown6f2fba42011-02-19 01:08:02 -08002330 * such as "AXIS_X" or an equivalent numeric constant such as "42" if unknown.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002331 *
2332 * @param axis The axis
2333 * @return The symbolic name of the specified axis.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002334 */
2335 public static String axisToString(int axis) {
Jeff Brown6f2fba42011-02-19 01:08:02 -08002336 String symbolicName = AXIS_SYMBOLIC_NAMES.get(axis);
2337 return symbolicName != null ? symbolicName : Integer.toString(axis);
2338 }
2339
2340 /**
Jeff Browncc0c1592011-02-19 05:07:28 -08002341 * Gets an axis by its symbolic name such as "AXIS_X" or an
2342 * equivalent numeric constant such as "42".
Jeff Brown6f2fba42011-02-19 01:08:02 -08002343 *
2344 * @param symbolicName The symbolic name of the axis.
2345 * @return The axis or -1 if not found.
2346 * @see #keycodeToString
2347 */
2348 public static int axisFromString(String symbolicName) {
2349 if (symbolicName == null) {
2350 throw new IllegalArgumentException("symbolicName must not be null");
2351 }
2352
2353 final int count = AXIS_SYMBOLIC_NAMES.size();
2354 for (int i = 0; i < count; i++) {
2355 if (symbolicName.equals(AXIS_SYMBOLIC_NAMES.valueAt(i))) {
2356 return i;
2357 }
2358 }
2359
2360 try {
2361 return Integer.parseInt(symbolicName, 10);
2362 } catch (NumberFormatException ex) {
2363 return -1;
Jeff Brown91c69ab2011-02-14 17:03:18 -08002364 }
2365 }
2366
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002367 public static final Parcelable.Creator<MotionEvent> CREATOR
2368 = new Parcelable.Creator<MotionEvent>() {
2369 public MotionEvent createFromParcel(Parcel in) {
Jeff Brown6ec402b2010-07-28 15:48:59 -07002370 in.readInt(); // skip token, we already know this is a MotionEvent
2371 return MotionEvent.createFromParcelBody(in);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002372 }
2373
2374 public MotionEvent[] newArray(int size) {
2375 return new MotionEvent[size];
2376 }
2377 };
2378
Jeff Brown6ec402b2010-07-28 15:48:59 -07002379 /** @hide */
2380 public static MotionEvent createFromParcelBody(Parcel in) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002381 MotionEvent ev = obtain();
2382 ev.mNativePtr = nativeReadFromParcel(ev.mNativePtr, in);
Jeff Brown6ec402b2010-07-28 15:48:59 -07002383 return ev;
2384 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08002385
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002386 public void writeToParcel(Parcel out, int flags) {
Jeff Brown6ec402b2010-07-28 15:48:59 -07002387 out.writeInt(PARCEL_TOKEN_MOTION_EVENT);
Jeff Brown91c69ab2011-02-14 17:03:18 -08002388 nativeWriteToParcel(mNativePtr, out);
Jeff Brown5c225b12010-06-16 01:53:36 -07002389 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08002390
Jeff Brownc5ed5912010-07-14 18:48:53 -07002391 /**
2392 * Transfer object for pointer coordinates.
2393 *
2394 * Objects of this type can be used to manufacture new {@link MotionEvent} objects
2395 * and to query pointer coordinate information in bulk.
2396 *
2397 * Refer to {@link InputDevice} for information about how different kinds of
2398 * input devices and sources represent pointer coordinates.
2399 */
2400 public static final class PointerCoords {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002401 private static final int INITIAL_PACKED_AXIS_VALUES = 8;
Jeff Brown6f2fba42011-02-19 01:08:02 -08002402 private long mPackedAxisBits;
Jeff Brown91c69ab2011-02-14 17:03:18 -08002403 private float[] mPackedAxisValues;
2404
2405 /**
2406 * Creates a pointer coords object with all axes initialized to zero.
2407 */
2408 public PointerCoords() {
2409 }
2410
2411 /**
2412 * Creates a pointer coords object as a copy of the
2413 * contents of another pointer coords object.
2414 *
2415 * @param other The pointer coords object to copy.
2416 */
2417 public PointerCoords(PointerCoords other) {
2418 copyFrom(other);
2419 }
2420
Jeff Brownc5ed5912010-07-14 18:48:53 -07002421 /**
Jeff Brown6f2fba42011-02-19 01:08:02 -08002422 * The X component of the pointer movement.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002423 *
2424 * @see MotionEvent#AXIS_X
Jeff Brownc5ed5912010-07-14 18:48:53 -07002425 */
2426 public float x;
2427
2428 /**
Jeff Brown6f2fba42011-02-19 01:08:02 -08002429 * The Y component of the pointer movement.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002430 *
2431 * @see MotionEvent#AXIS_Y
Jeff Brownc5ed5912010-07-14 18:48:53 -07002432 */
2433 public float y;
2434
2435 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08002436 * A normalized value that describes the pressure applied to the device
2437 * by a finger or other tool.
Jeff Brownc5ed5912010-07-14 18:48:53 -07002438 * The pressure generally ranges from 0 (no pressure at all) to 1 (normal pressure),
Jeff Brown91c69ab2011-02-14 17:03:18 -08002439 * although values higher than 1 may be generated depending on the calibration of
Jeff Brownc5ed5912010-07-14 18:48:53 -07002440 * the input device.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002441 *
2442 * @see MotionEvent#AXIS_PRESSURE
Jeff Brownc5ed5912010-07-14 18:48:53 -07002443 */
2444 public float pressure;
2445
2446 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08002447 * A normalized value that describes the approximate size of the pointer touch area
2448 * in relation to the maximum detectable size of the device.
2449 * It represents some approximation of the area of the screen being
Jeff Brownc5ed5912010-07-14 18:48:53 -07002450 * pressed; the actual value in pixels corresponding to the
2451 * touch is normalized with the device specific range of values
2452 * and scaled to a value between 0 and 1. The value of size can be used to
2453 * determine fat touch events.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002454 *
2455 * @see MotionEvent#AXIS_SIZE
Jeff Brownc5ed5912010-07-14 18:48:53 -07002456 */
2457 public float size;
2458
2459 /**
2460 * The length of the major axis of an ellipse that describes the touch area at
2461 * the point of contact.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002462 * If the device is a touch screen, the length is reported in pixels, otherwise it is
2463 * reported in device-specific units.
2464 *
2465 * @see MotionEvent#AXIS_TOUCH_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002466 */
2467 public float touchMajor;
2468
2469 /**
2470 * The length of the minor axis of an ellipse that describes the touch area at
2471 * the point of contact.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002472 * If the device is a touch screen, the length is reported in pixels, otherwise it is
2473 * reported in device-specific units.
2474 *
2475 * @see MotionEvent#AXIS_TOUCH_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002476 */
2477 public float touchMinor;
2478
2479 /**
2480 * The length of the major axis of an ellipse that describes the size of
2481 * the approaching tool.
2482 * The tool area represents the estimated size of the finger or pen that is
2483 * touching the device independent of its actual touch area at the point of contact.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002484 * If the device is a touch screen, the length is reported in pixels, otherwise it is
2485 * reported in device-specific units.
2486 *
2487 * @see MotionEvent#AXIS_TOOL_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002488 */
2489 public float toolMajor;
2490
2491 /**
2492 * The length of the minor axis of an ellipse that describes the size of
2493 * the approaching tool.
2494 * The tool area represents the estimated size of the finger or pen that is
2495 * touching the device independent of its actual touch area at the point of contact.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002496 * If the device is a touch screen, the length is reported in pixels, otherwise it is
2497 * reported in device-specific units.
2498 *
2499 * @see MotionEvent#AXIS_TOOL_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002500 */
2501 public float toolMinor;
2502
2503 /**
2504 * The orientation of the touch area and tool area in radians clockwise from vertical.
Jeff Brown6f2fba42011-02-19 01:08:02 -08002505 * An angle of 0 radians indicates that the major axis of contact is oriented
Jeff Brownc5ed5912010-07-14 18:48:53 -07002506 * upwards, is perfectly circular or is of unknown orientation. A positive angle
2507 * indicates that the major axis of contact is oriented to the right. A negative angle
2508 * indicates that the major axis of contact is oriented to the left.
Jeff Brown6d0fec22010-07-23 21:28:06 -07002509 * The full range is from -PI/2 radians (finger pointing fully left) to PI/2 radians
Jeff Brownc5ed5912010-07-14 18:48:53 -07002510 * (finger pointing fully right).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002511 *
2512 * @see MotionEvent#AXIS_ORIENTATION
Jeff Brownc5ed5912010-07-14 18:48:53 -07002513 */
2514 public float orientation;
Jeff Brown91c69ab2011-02-14 17:03:18 -08002515
2516 /**
2517 * Clears the contents of this object.
2518 * Resets all axes to zero.
2519 */
2520 public void clear() {
2521 mPackedAxisBits = 0;
2522
2523 x = 0;
2524 y = 0;
2525 pressure = 0;
2526 size = 0;
2527 touchMajor = 0;
2528 touchMinor = 0;
2529 toolMajor = 0;
2530 toolMinor = 0;
2531 orientation = 0;
Jeff Brownc5ed5912010-07-14 18:48:53 -07002532 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08002533
2534 /**
2535 * Copies the contents of another pointer coords object.
2536 *
2537 * @param other The pointer coords object to copy.
2538 */
2539 public void copyFrom(PointerCoords other) {
Jeff Brown6f2fba42011-02-19 01:08:02 -08002540 final long bits = other.mPackedAxisBits;
Jeff Brown91c69ab2011-02-14 17:03:18 -08002541 mPackedAxisBits = bits;
2542 if (bits != 0) {
2543 final float[] otherValues = other.mPackedAxisValues;
Jeff Brown6f2fba42011-02-19 01:08:02 -08002544 final int count = Long.bitCount(bits);
Jeff Brown91c69ab2011-02-14 17:03:18 -08002545 float[] values = mPackedAxisValues;
2546 if (values == null || count > values.length) {
2547 values = new float[otherValues.length];
2548 mPackedAxisValues = values;
2549 }
2550 System.arraycopy(otherValues, 0, values, 0, count);
2551 }
2552
2553 x = other.x;
2554 y = other.y;
2555 pressure = other.pressure;
2556 size = other.size;
2557 touchMajor = other.touchMajor;
2558 touchMinor = other.touchMinor;
2559 toolMajor = other.toolMajor;
2560 toolMinor = other.toolMinor;
2561 orientation = other.orientation;
Jeff Brownc5ed5912010-07-14 18:48:53 -07002562 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08002563
2564 /**
2565 * Gets the value associated with the specified axis.
2566 *
2567 * @param axis The axis identifier for the axis value to retrieve.
2568 * @return The value associated with the axis, or 0 if none.
2569 *
2570 * @see MotionEvent#AXIS_X
2571 * @see MotionEvent#AXIS_Y
2572 */
2573 public float getAxisValue(int axis) {
2574 switch (axis) {
2575 case AXIS_X:
2576 return x;
2577 case AXIS_Y:
2578 return y;
2579 case AXIS_PRESSURE:
2580 return pressure;
2581 case AXIS_SIZE:
2582 return size;
2583 case AXIS_TOUCH_MAJOR:
2584 return touchMajor;
2585 case AXIS_TOUCH_MINOR:
2586 return touchMinor;
2587 case AXIS_TOOL_MAJOR:
2588 return toolMajor;
2589 case AXIS_TOOL_MINOR:
2590 return toolMinor;
2591 case AXIS_ORIENTATION:
2592 return orientation;
2593 default: {
Jeff Brown6f2fba42011-02-19 01:08:02 -08002594 if (axis < 0 || axis > 63) {
2595 throw new IllegalArgumentException("Axis out of range.");
2596 }
2597 final long bits = mPackedAxisBits;
2598 final long axisBit = 1L << axis;
Jeff Brown91c69ab2011-02-14 17:03:18 -08002599 if ((bits & axisBit) == 0) {
2600 return 0;
2601 }
Jeff Brown6f2fba42011-02-19 01:08:02 -08002602 final int index = Long.bitCount(bits & (axisBit - 1L));
Jeff Brown91c69ab2011-02-14 17:03:18 -08002603 return mPackedAxisValues[index];
2604 }
2605 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002606 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08002607
2608 /**
2609 * Sets the value associated with the specified axis.
2610 *
2611 * @param axis The axis identifier for the axis value to assign.
2612 * @param value The value to set.
2613 *
2614 * @see MotionEvent#AXIS_X
2615 * @see MotionEvent#AXIS_Y
2616 */
2617 public void setAxisValue(int axis, float value) {
2618 switch (axis) {
2619 case AXIS_X:
2620 x = value;
2621 break;
2622 case AXIS_Y:
2623 y = value;
2624 break;
2625 case AXIS_PRESSURE:
2626 pressure = value;
2627 break;
2628 case AXIS_SIZE:
2629 size = value;
2630 break;
2631 case AXIS_TOUCH_MAJOR:
2632 touchMajor = value;
2633 break;
2634 case AXIS_TOUCH_MINOR:
2635 touchMinor = value;
2636 break;
2637 case AXIS_TOOL_MAJOR:
2638 toolMajor = value;
2639 break;
2640 case AXIS_TOOL_MINOR:
2641 toolMinor = value;
2642 break;
2643 case AXIS_ORIENTATION:
2644 orientation = value;
2645 break;
2646 default: {
Jeff Brown6f2fba42011-02-19 01:08:02 -08002647 if (axis < 0 || axis > 63) {
2648 throw new IllegalArgumentException("Axis out of range.");
2649 }
2650 final long bits = mPackedAxisBits;
2651 final long axisBit = 1L << axis;
2652 final int index = Long.bitCount(bits & (axisBit - 1L));
Jeff Brown91c69ab2011-02-14 17:03:18 -08002653 float[] values = mPackedAxisValues;
2654 if ((bits & axisBit) == 0) {
2655 if (values == null) {
2656 values = new float[INITIAL_PACKED_AXIS_VALUES];
2657 mPackedAxisValues = values;
2658 } else {
Jeff Brown6f2fba42011-02-19 01:08:02 -08002659 final int count = Long.bitCount(bits);
Jeff Brown91c69ab2011-02-14 17:03:18 -08002660 if (count < values.length) {
2661 if (index != count) {
2662 System.arraycopy(values, index, values, index + 1,
2663 count - index);
2664 }
2665 } else {
2666 float[] newValues = new float[count * 2];
2667 System.arraycopy(values, 0, newValues, 0, index);
2668 System.arraycopy(values, index, newValues, index + 1,
2669 count - index);
2670 values = newValues;
2671 mPackedAxisValues = values;
2672 }
2673 }
2674 mPackedAxisBits = bits | axisBit;
2675 }
2676 values[index] = value;
2677 }
2678 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002679 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002680 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002681}