blob: 076f71298490a0cdeb310ef6cafa9ee2b5f00bae [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 /**
678 * Constant used to identify the Generic 1 axis of a motion event.
679 * The interpretation of a generic axis is device-specific.
680 *
681 * @see #getAxisValue(int, int)
682 * @see #getHistoricalAxisValue(int, int, int)
683 * @see MotionEvent.PointerCoords#getAxisValue(int)
684 * @see InputDevice#getMotionRange
685 */
686 public static final int AXIS_GENERIC_1 = 32;
687
688 /**
689 * Constant used to identify the Generic 2 axis of a motion event.
690 * The interpretation of a generic axis is device-specific.
691 *
692 * @see #getAxisValue(int, int)
693 * @see #getHistoricalAxisValue(int, int, int)
694 * @see MotionEvent.PointerCoords#getAxisValue(int)
695 * @see InputDevice#getMotionRange
696 */
697 public static final int AXIS_GENERIC_2 = 33;
698
699 /**
700 * Constant used to identify the Generic 3 axis of a motion event.
701 * The interpretation of a generic axis is device-specific.
702 *
703 * @see #getAxisValue(int, int)
704 * @see #getHistoricalAxisValue(int, int, int)
705 * @see MotionEvent.PointerCoords#getAxisValue(int)
706 * @see InputDevice#getMotionRange
707 */
708 public static final int AXIS_GENERIC_3 = 34;
709
710 /**
711 * Constant used to identify the Generic 4 axis of a motion event.
712 * The interpretation of a generic axis is device-specific.
713 *
714 * @see #getAxisValue(int, int)
715 * @see #getHistoricalAxisValue(int, int, int)
716 * @see MotionEvent.PointerCoords#getAxisValue(int)
717 * @see InputDevice#getMotionRange
718 */
719 public static final int AXIS_GENERIC_4 = 35;
720
721 /**
722 * Constant used to identify the Generic 5 axis of a motion event.
723 * The interpretation of a generic axis is device-specific.
724 *
725 * @see #getAxisValue(int, int)
726 * @see #getHistoricalAxisValue(int, int, int)
727 * @see MotionEvent.PointerCoords#getAxisValue(int)
728 * @see InputDevice#getMotionRange
729 */
730 public static final int AXIS_GENERIC_5 = 36;
731
732 /**
733 * Constant used to identify the Generic 6 axis of a motion event.
734 * The interpretation of a generic axis is device-specific.
735 *
736 * @see #getAxisValue(int, int)
737 * @see #getHistoricalAxisValue(int, int, int)
738 * @see MotionEvent.PointerCoords#getAxisValue(int)
739 * @see InputDevice#getMotionRange
740 */
741 public static final int AXIS_GENERIC_6 = 37;
742
743 /**
744 * Constant used to identify the Generic 7 axis of a motion event.
745 * The interpretation of a generic axis is device-specific.
746 *
747 * @see #getAxisValue(int, int)
748 * @see #getHistoricalAxisValue(int, int, int)
749 * @see MotionEvent.PointerCoords#getAxisValue(int)
750 * @see InputDevice#getMotionRange
751 */
752 public static final int AXIS_GENERIC_7 = 38;
753
754 /**
755 * Constant used to identify the Generic 8 axis of a motion event.
756 * The interpretation of a generic axis is device-specific.
757 *
758 * @see #getAxisValue(int, int)
759 * @see #getHistoricalAxisValue(int, int, int)
760 * @see MotionEvent.PointerCoords#getAxisValue(int)
761 * @see InputDevice#getMotionRange
762 */
763 public static final int AXIS_GENERIC_8 = 39;
764
765 /**
766 * Constant used to identify the Generic 9 axis of a motion event.
767 * The interpretation of a generic axis is device-specific.
768 *
769 * @see #getAxisValue(int, int)
770 * @see #getHistoricalAxisValue(int, int, int)
771 * @see MotionEvent.PointerCoords#getAxisValue(int)
772 * @see InputDevice#getMotionRange
773 */
774 public static final int AXIS_GENERIC_9 = 40;
775
776 /**
777 * Constant used to identify the Generic 10 axis of a motion event.
778 * The interpretation of a generic axis is device-specific.
779 *
780 * @see #getAxisValue(int, int)
781 * @see #getHistoricalAxisValue(int, int, int)
782 * @see MotionEvent.PointerCoords#getAxisValue(int)
783 * @see InputDevice#getMotionRange
784 */
785 public static final int AXIS_GENERIC_10 = 41;
786
787 /**
788 * Constant used to identify the Generic 11 axis of a motion event.
789 * The interpretation of a generic axis is device-specific.
790 *
791 * @see #getAxisValue(int, int)
792 * @see #getHistoricalAxisValue(int, int, int)
793 * @see MotionEvent.PointerCoords#getAxisValue(int)
794 * @see InputDevice#getMotionRange
795 */
796 public static final int AXIS_GENERIC_11 = 42;
797
798 /**
799 * Constant used to identify the Generic 12 axis of a motion event.
800 * The interpretation of a generic axis is device-specific.
801 *
802 * @see #getAxisValue(int, int)
803 * @see #getHistoricalAxisValue(int, int, int)
804 * @see MotionEvent.PointerCoords#getAxisValue(int)
805 * @see InputDevice#getMotionRange
806 */
807 public static final int AXIS_GENERIC_12 = 43;
808
809 /**
810 * Constant used to identify the Generic 13 axis of a motion event.
811 * The interpretation of a generic axis is device-specific.
812 *
813 * @see #getAxisValue(int, int)
814 * @see #getHistoricalAxisValue(int, int, int)
815 * @see MotionEvent.PointerCoords#getAxisValue(int)
816 * @see InputDevice#getMotionRange
817 */
818 public static final int AXIS_GENERIC_13 = 44;
819
820 /**
821 * Constant used to identify the Generic 14 axis of a motion event.
822 * The interpretation of a generic axis is device-specific.
823 *
824 * @see #getAxisValue(int, int)
825 * @see #getHistoricalAxisValue(int, int, int)
826 * @see MotionEvent.PointerCoords#getAxisValue(int)
827 * @see InputDevice#getMotionRange
828 */
829 public static final int AXIS_GENERIC_14 = 45;
830
831 /**
832 * Constant used to identify the Generic 15 axis of a motion event.
833 * The interpretation of a generic axis is device-specific.
834 *
835 * @see #getAxisValue(int, int)
836 * @see #getHistoricalAxisValue(int, int, int)
837 * @see MotionEvent.PointerCoords#getAxisValue(int)
838 * @see InputDevice#getMotionRange
839 */
840 public static final int AXIS_GENERIC_15 = 46;
841
842 /**
843 * Constant used to identify the Generic 16 axis of a motion event.
844 * The interpretation of a generic axis is device-specific.
845 *
846 * @see #getAxisValue(int, int)
847 * @see #getHistoricalAxisValue(int, int, int)
848 * @see MotionEvent.PointerCoords#getAxisValue(int)
849 * @see InputDevice#getMotionRange
850 */
851 public static final int AXIS_GENERIC_16 = 47;
852
853 // NOTE: If you add a new axis here you must also add it to:
854 // native/include/android/input.h
855 // frameworks/base/include/ui/KeycodeLabels.h
856
857 // Symbolic names of all axes.
858 private static final SparseArray<String> AXIS_SYMBOLIC_NAMES = new SparseArray<String>();
859 private static void populateAxisSymbolicNames() {
860 SparseArray<String> names = AXIS_SYMBOLIC_NAMES;
861 names.append(AXIS_X, "AXIS_X");
862 names.append(AXIS_Y, "AXIS_Y");
863 names.append(AXIS_PRESSURE, "AXIS_PRESSURE");
864 names.append(AXIS_SIZE, "AXIS_SIZE");
865 names.append(AXIS_TOUCH_MAJOR, "AXIS_TOUCH_MAJOR");
866 names.append(AXIS_TOUCH_MINOR, "AXIS_TOUCH_MINOR");
867 names.append(AXIS_TOOL_MAJOR, "AXIS_TOOL_MAJOR");
868 names.append(AXIS_TOOL_MINOR, "AXIS_TOOL_MINOR");
869 names.append(AXIS_ORIENTATION, "AXIS_ORIENTATION");
870 names.append(AXIS_VSCROLL, "AXIS_VSCROLL");
871 names.append(AXIS_HSCROLL, "AXIS_HSCROLL");
872 names.append(AXIS_Z, "AXIS_Z");
873 names.append(AXIS_RX, "AXIS_RX");
874 names.append(AXIS_RY, "AXIS_RY");
875 names.append(AXIS_RZ, "AXIS_RZ");
876 names.append(AXIS_HAT_X, "AXIS_HAT_X");
877 names.append(AXIS_HAT_Y, "AXIS_HAT_Y");
878 names.append(AXIS_LTRIGGER, "AXIS_LTRIGGER");
879 names.append(AXIS_RTRIGGER, "AXIS_RTRIGGER");
880 names.append(AXIS_GENERIC_1, "AXIS_GENERIC_1");
881 names.append(AXIS_GENERIC_2, "AXIS_GENERIC_2");
882 names.append(AXIS_GENERIC_3, "AXIS_GENERIC_3");
883 names.append(AXIS_GENERIC_4, "AXIS_GENERIC_4");
884 names.append(AXIS_GENERIC_5, "AXIS_GENERIC_5");
885 names.append(AXIS_GENERIC_6, "AXIS_GENERIC_6");
886 names.append(AXIS_GENERIC_7, "AXIS_GENERIC_7");
887 names.append(AXIS_GENERIC_8, "AXIS_GENERIC_8");
888 names.append(AXIS_GENERIC_9, "AXIS_GENERIC_9");
889 names.append(AXIS_GENERIC_10, "AXIS_GENERIC_10");
890 names.append(AXIS_GENERIC_11, "AXIS_GENERIC_11");
891 names.append(AXIS_GENERIC_12, "AXIS_GENERIC_12");
892 names.append(AXIS_GENERIC_13, "AXIS_GENERIC_13");
893 names.append(AXIS_GENERIC_14, "AXIS_GENERIC_14");
894 names.append(AXIS_GENERIC_15, "AXIS_GENERIC_15");
895 names.append(AXIS_GENERIC_16, "AXIS_GENERIC_16");
896 }
897
898 static {
899 populateAxisSymbolicNames();
900 }
901
Jeff Brown91c69ab2011-02-14 17:03:18 -0800902 // Private value for history pos that obtains the current sample.
903 private static final int HISTORY_CURRENT = -0x80000000;
904
Jeff Brown1f245102010-11-18 20:53:46 -0800905 private static final int MAX_RECYCLED = 10;
906 private static final Object gRecyclerLock = new Object();
907 private static int gRecyclerUsed;
908 private static MotionEvent gRecyclerTop;
Romain Guycafdea62009-06-12 10:51:36 -0700909
Jeff Brown91c69ab2011-02-14 17:03:18 -0800910 // Shared temporary objects used when translating coordinates supplied by
911 // the caller into single element PointerCoords and pointer id arrays.
912 // Must lock gTmpPointerCoords prior to use.
913 private static final PointerCoords[] gTmpPointerCoords =
914 new PointerCoords[] { new PointerCoords() };
915 private static final int[] gTmpPointerIds = new int[] { 0 /*always 0*/ };
916
917 // Pointer to the native MotionEvent object that contains the actual data.
918 private int mNativePtr;
Mitsuru Oshima8169dae2009-04-28 18:12:09 -0700919
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800920 private MotionEvent mNext;
921 private RuntimeException mRecycledLocation;
922 private boolean mRecycled;
923
Jeff Brown91c69ab2011-02-14 17:03:18 -0800924 private static native int nativeInitialize(int nativePtr,
925 int deviceId, int source, int action, int flags, int edgeFlags, int metaState,
926 float xOffset, float yOffset, float xPrecision, float yPrecision,
927 long downTimeNanos, long eventTimeNanos,
928 int pointerCount, int[] pointerIds, PointerCoords[] pointerCoords);
929 private static native int nativeCopy(int destNativePtr, int sourceNativePtr,
930 boolean keepHistory);
931 private static native void nativeDispose(int nativePtr);
932 private static native void nativeAddBatch(int nativePtr, long eventTimeNanos,
933 PointerCoords[] pointerCoords, int metaState);
Jeff Brown20e987b2010-08-23 12:01:02 -0700934
Jeff Brown91c69ab2011-02-14 17:03:18 -0800935 private static native int nativeGetDeviceId(int nativePtr);
936 private static native int nativeGetSource(int nativePtr);
937 private static native int nativeSetSource(int nativePtr, int source);
938 private static native int nativeGetAction(int nativePtr);
939 private static native void nativeSetAction(int nativePtr, int action);
Jeff Brown56194eb2011-03-02 19:23:13 -0800940 private static native boolean nativeIsTouchEvent(int nativePtr);
Jeff Brown91c69ab2011-02-14 17:03:18 -0800941 private static native int nativeGetFlags(int nativePtr);
942 private static native int nativeGetEdgeFlags(int nativePtr);
943 private static native void nativeSetEdgeFlags(int nativePtr, int action);
944 private static native int nativeGetMetaState(int nativePtr);
945 private static native void nativeOffsetLocation(int nativePtr, float deltaX, float deltaY);
946 private static native float nativeGetXPrecision(int nativePtr);
947 private static native float nativeGetYPrecision(int nativePtr);
948 private static native long nativeGetDownTimeNanos(int nativePtr);
949
950 private static native int nativeGetPointerCount(int nativePtr);
951 private static native int nativeGetPointerId(int nativePtr, int pointerIndex);
952 private static native int nativeFindPointerIndex(int nativePtr, int pointerId);
953
954 private static native int nativeGetHistorySize(int nativePtr);
955 private static native long nativeGetEventTimeNanos(int nativePtr, int historyPos);
956 private static native float nativeGetRawAxisValue(int nativePtr,
957 int axis, int pointerIndex, int historyPos);
958 private static native float nativeGetAxisValue(int nativePtr,
959 int axis, int pointerIndex, int historyPos);
960 private static native void nativeGetPointerCoords(int nativePtr,
961 int pointerIndex, int historyPos, PointerCoords outPointerCoords);
962
963 private static native void nativeScale(int nativePtr, float scale);
964 private static native void nativeTransform(int nativePtr, Matrix matrix);
965
966 private static native int nativeReadFromParcel(int nativePtr, Parcel parcel);
967 private static native void nativeWriteToParcel(int nativePtr, Parcel parcel);
968
969 private MotionEvent() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800970 }
Romain Guycafdea62009-06-12 10:51:36 -0700971
Jeff Brown91c69ab2011-02-14 17:03:18 -0800972 @Override
973 protected void finalize() throws Throwable {
974 try {
975 if (mNativePtr != 0) {
976 nativeDispose(mNativePtr);
977 mNativePtr = 0;
978 }
979 } finally {
980 super.finalize();
981 }
982 }
983
984 static private MotionEvent obtain() {
Jeff Brown46b9ac02010-04-22 18:58:52 -0700985 final MotionEvent ev;
986 synchronized (gRecyclerLock) {
Jeff Brown1f245102010-11-18 20:53:46 -0800987 ev = gRecyclerTop;
988 if (ev == null) {
Jeff Brown91c69ab2011-02-14 17:03:18 -0800989 return new MotionEvent();
Jeff Brown46b9ac02010-04-22 18:58:52 -0700990 }
Jeff Brown46b9ac02010-04-22 18:58:52 -0700991 gRecyclerTop = ev.mNext;
Jeff Brown5c225b12010-06-16 01:53:36 -0700992 gRecyclerUsed -= 1;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700993 }
994 ev.mRecycledLocation = null;
995 ev.mRecycled = false;
996 ev.mNext = null;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700997 return ev;
998 }
Jeff Brown91c69ab2011-02-14 17:03:18 -0800999
Michael Chan53071d62009-05-13 17:29:48 -07001000 /**
1001 * Create a new MotionEvent, filling in all of the basic values that
1002 * define the motion.
1003 *
1004 * @param downTime The time (in ms) when the user originally pressed down to start
1005 * a stream of position events. This must be obtained from {@link SystemClock#uptimeMillis()}.
Jeff Brownc5ed5912010-07-14 18:48:53 -07001006 * @param eventTime The the time (in ms) when this specific event was generated. This
Michael Chan53071d62009-05-13 17:29:48 -07001007 * must be obtained from {@link SystemClock#uptimeMillis()}.
Jeff Browncc0c1592011-02-19 05:07:28 -08001008 * @param action The kind of action being performed, such as {@link #ACTION_DOWN}.
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001009 * @param pointers The number of points that will be in this event.
Jeff Brownc5ed5912010-07-14 18:48:53 -07001010 * @param pointerIds An array of <em>pointers</em> values providing
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001011 * an identifier for each pointer.
Jeff Brownc5ed5912010-07-14 18:48:53 -07001012 * @param pointerCoords An array of <em>pointers</em> values providing
1013 * a {@link PointerCoords} coordinate object for each pointer.
Michael Chan53071d62009-05-13 17:29:48 -07001014 * @param metaState The state of any meta / modifier keys that were in effect when
1015 * the event was generated.
1016 * @param xPrecision The precision of the X coordinate being reported.
1017 * @param yPrecision The precision of the Y coordinate being reported.
1018 * @param deviceId The id for the device that this event came from. An id of
1019 * zero indicates that the event didn't come from a physical device; other
1020 * numbers are arbitrary and you shouldn't depend on the values.
Jeff Brown85a31762010-09-01 17:01:00 -07001021 * @param edgeFlags A bitfield indicating which edges, if any, were touched by this
Michael Chan53071d62009-05-13 17:29:48 -07001022 * MotionEvent.
Jeff Brownc5ed5912010-07-14 18:48:53 -07001023 * @param source The source of this event.
Jeff Brown85a31762010-09-01 17:01:00 -07001024 * @param flags The motion event flags.
Michael Chan53071d62009-05-13 17:29:48 -07001025 */
Jeff Brownc5ed5912010-07-14 18:48:53 -07001026 static public MotionEvent obtain(long downTime, long eventTime,
1027 int action, int pointers, int[] pointerIds, PointerCoords[] pointerCoords,
1028 int metaState, float xPrecision, float yPrecision, int deviceId,
Jeff Brown85a31762010-09-01 17:01:00 -07001029 int edgeFlags, int source, int flags) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001030 MotionEvent ev = obtain();
1031 ev.mNativePtr = nativeInitialize(ev.mNativePtr,
1032 deviceId, source, action, flags, edgeFlags, metaState,
1033 0, 0, xPrecision, yPrecision,
1034 downTime * NS_PER_MS, eventTime * NS_PER_MS,
1035 pointers, pointerIds, pointerCoords);
Michael Chan53071d62009-05-13 17:29:48 -07001036 return ev;
1037 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08001038
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001039 /**
1040 * Create a new MotionEvent, filling in all of the basic values that
1041 * define the motion.
Romain Guycafdea62009-06-12 10:51:36 -07001042 *
1043 * @param downTime The time (in ms) when the user originally pressed down to start
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001044 * a stream of position events. This must be obtained from {@link SystemClock#uptimeMillis()}.
Romain Guycafdea62009-06-12 10:51:36 -07001045 * @param eventTime The the time (in ms) when this specific event was generated. This
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001046 * must be obtained from {@link SystemClock#uptimeMillis()}.
Jeff Browncc0c1592011-02-19 05:07:28 -08001047 * @param action The kind of action being performed, such as {@link #ACTION_DOWN}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001048 * @param x The X coordinate of this event.
1049 * @param y The Y coordinate of this event.
Romain Guycafdea62009-06-12 10:51:36 -07001050 * @param pressure The current pressure of this event. The pressure generally
1051 * ranges from 0 (no pressure at all) to 1 (normal pressure), however
1052 * values higher than 1 may be generated depending on the calibration of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001053 * the input device.
1054 * @param size A scaled value of the approximate size of the area being pressed when
Romain Guycafdea62009-06-12 10:51:36 -07001055 * touched with the finger. The actual value in pixels corresponding to the finger
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001056 * touch is normalized with a device specific range of values
1057 * and scaled to a value between 0 and 1.
1058 * @param metaState The state of any meta / modifier keys that were in effect when
1059 * the event was generated.
1060 * @param xPrecision The precision of the X coordinate being reported.
1061 * @param yPrecision The precision of the Y coordinate being reported.
1062 * @param deviceId The id for the device that this event came from. An id of
1063 * zero indicates that the event didn't come from a physical device; other
1064 * numbers are arbitrary and you shouldn't depend on the values.
Jeff Brown85a31762010-09-01 17:01:00 -07001065 * @param edgeFlags A bitfield indicating which edges, if any, were touched by this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001066 * MotionEvent.
1067 */
1068 static public MotionEvent obtain(long downTime, long eventTime, int action,
1069 float x, float y, float pressure, float size, int metaState,
1070 float xPrecision, float yPrecision, int deviceId, int edgeFlags) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001071 synchronized (gTmpPointerCoords) {
1072 final PointerCoords pc = gTmpPointerCoords[0];
1073 pc.clear();
1074 pc.x = x;
1075 pc.y = y;
1076 pc.pressure = pressure;
1077 pc.size = size;
1078
1079 MotionEvent ev = obtain();
1080 ev.mNativePtr = nativeInitialize(ev.mNativePtr,
1081 deviceId, InputDevice.SOURCE_UNKNOWN, action, 0, edgeFlags, metaState,
1082 0, 0, xPrecision, yPrecision,
1083 downTime * NS_PER_MS, eventTime * NS_PER_MS,
1084 1, gTmpPointerIds, gTmpPointerCoords);
1085 return ev;
1086 }
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001087 }
1088
1089 /**
1090 * Create a new MotionEvent, filling in all of the basic values that
1091 * define the motion.
1092 *
1093 * @param downTime The time (in ms) when the user originally pressed down to start
1094 * a stream of position events. This must be obtained from {@link SystemClock#uptimeMillis()}.
1095 * @param eventTime The the time (in ms) when this specific event was generated. This
1096 * must be obtained from {@link SystemClock#uptimeMillis()}.
Jeff Browncc0c1592011-02-19 05:07:28 -08001097 * @param action The kind of action being performed, such as {@link #ACTION_DOWN}.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001098 * @param pointers The number of pointers that are active in this event.
1099 * @param x The X coordinate of this event.
1100 * @param y The Y coordinate of this event.
1101 * @param pressure The current pressure of this event. The pressure generally
1102 * ranges from 0 (no pressure at all) to 1 (normal pressure), however
1103 * values higher than 1 may be generated depending on the calibration of
1104 * the input device.
1105 * @param size A scaled value of the approximate size of the area being pressed when
1106 * touched with the finger. The actual value in pixels corresponding to the finger
1107 * touch is normalized with a device specific range of values
1108 * and scaled to a value between 0 and 1.
1109 * @param metaState The state of any meta / modifier keys that were in effect when
1110 * the event was generated.
1111 * @param xPrecision The precision of the X coordinate being reported.
1112 * @param yPrecision The precision of the Y coordinate being reported.
1113 * @param deviceId The id for the device that this event came from. An id of
1114 * zero indicates that the event didn't come from a physical device; other
1115 * numbers are arbitrary and you shouldn't depend on the values.
Jeff Brown85a31762010-09-01 17:01:00 -07001116 * @param edgeFlags A bitfield indicating which edges, if any, were touched by this
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001117 * MotionEvent.
Jeff Brown5c225b12010-06-16 01:53:36 -07001118 *
1119 * @deprecated Use {@link #obtain(long, long, int, float, float, float, float, int, float, float, int, int)}
1120 * instead.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001121 */
Jeff Brown5c225b12010-06-16 01:53:36 -07001122 @Deprecated
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001123 static public MotionEvent obtain(long downTime, long eventTime, int action,
1124 int pointers, float x, float y, float pressure, float size, int metaState,
1125 float xPrecision, float yPrecision, int deviceId, int edgeFlags) {
Jeff Brown5c225b12010-06-16 01:53:36 -07001126 return obtain(downTime, eventTime, action, x, y, pressure, size,
1127 metaState, xPrecision, yPrecision, deviceId, edgeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001128 }
Romain Guycafdea62009-06-12 10:51:36 -07001129
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001130 /**
1131 * Create a new MotionEvent, filling in a subset of the basic motion
1132 * values. Those not specified here are: device id (always 0), pressure
1133 * and size (always 1), x and y precision (always 1), and edgeFlags (always 0).
Romain Guycafdea62009-06-12 10:51:36 -07001134 *
1135 * @param downTime The time (in ms) when the user originally pressed down to start
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001136 * a stream of position events. This must be obtained from {@link SystemClock#uptimeMillis()}.
Romain Guycafdea62009-06-12 10:51:36 -07001137 * @param eventTime The the time (in ms) when this specific event was generated. This
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001138 * must be obtained from {@link SystemClock#uptimeMillis()}.
Jeff Browncc0c1592011-02-19 05:07:28 -08001139 * @param action The kind of action being performed, such as {@link #ACTION_DOWN}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001140 * @param x The X coordinate of this event.
1141 * @param y The Y coordinate of this event.
1142 * @param metaState The state of any meta / modifier keys that were in effect when
1143 * the event was generated.
1144 */
1145 static public MotionEvent obtain(long downTime, long eventTime, int action,
1146 float x, float y, int metaState) {
Jeff Brown5c225b12010-06-16 01:53:36 -07001147 return obtain(downTime, eventTime, action, x, y, 1.0f, 1.0f,
1148 metaState, 1.0f, 1.0f, 0, 0);
Mitsuru Oshima8169dae2009-04-28 18:12:09 -07001149 }
1150
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001151 /**
1152 * Create a new MotionEvent, copying from an existing one.
1153 */
Jeff Brown91c69ab2011-02-14 17:03:18 -08001154 static public MotionEvent obtain(MotionEvent other) {
1155 if (other == null) {
1156 throw new IllegalArgumentException("other motion event must not be null");
1157 }
1158
1159 MotionEvent ev = obtain();
1160 ev.mNativePtr = nativeCopy(ev.mNativePtr, other.mNativePtr, true /*keepHistory*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001161 return ev;
1162 }
Romain Guycafdea62009-06-12 10:51:36 -07001163
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001164 /**
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07001165 * Create a new MotionEvent, copying from an existing one, but not including
1166 * any historical point information.
1167 */
Jeff Brown91c69ab2011-02-14 17:03:18 -08001168 static public MotionEvent obtainNoHistory(MotionEvent other) {
1169 if (other == null) {
1170 throw new IllegalArgumentException("other motion event must not be null");
1171 }
1172
1173 MotionEvent ev = obtain();
1174 ev.mNativePtr = nativeCopy(ev.mNativePtr, other.mNativePtr, false /*keepHistory*/);
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07001175 return ev;
1176 }
1177
1178 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001179 * Recycle the MotionEvent, to be re-used by a later caller. After calling
1180 * this function you must not ever touch the event again.
1181 */
Jeff Brown5c225b12010-06-16 01:53:36 -07001182 public final void recycle() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001183 // Ensure recycle is only called once!
1184 if (TRACK_RECYCLED_LOCATION) {
1185 if (mRecycledLocation != null) {
1186 throw new RuntimeException(toString() + " recycled twice!", mRecycledLocation);
1187 }
1188 mRecycledLocation = new RuntimeException("Last recycled here");
Jeff Brownd28f4be2010-06-02 15:35:46 -07001189 //Log.w("MotionEvent", "Recycling event " + this, mRecycledLocation);
1190 } else {
1191 if (mRecycled) {
1192 throw new RuntimeException(toString() + " recycled twice!");
1193 }
1194 mRecycled = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001195 }
1196
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001197 synchronized (gRecyclerLock) {
1198 if (gRecyclerUsed < MAX_RECYCLED) {
1199 gRecyclerUsed++;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001200 mNext = gRecyclerTop;
1201 gRecyclerTop = this;
1202 }
1203 }
1204 }
Jeff Brown5c225b12010-06-16 01:53:36 -07001205
1206 /**
1207 * Scales down the coordination of this event by the given scale.
1208 *
1209 * @hide
1210 */
1211 public final void scale(float scale) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001212 nativeScale(mNativePtr, scale);
1213 }
1214
1215 /** {@inheritDoc} */
1216 @Override
1217 public final int getDeviceId() {
1218 return nativeGetDeviceId(mNativePtr);
1219 }
1220
1221 /** {@inheritDoc} */
1222 @Override
1223 public final int getSource() {
1224 return nativeGetSource(mNativePtr);
1225 }
1226
1227 /** {@inheritDoc} */
1228 @Override
1229 public final void setSource(int source) {
1230 nativeSetSource(mNativePtr, source);
Jeff Brown5c225b12010-06-16 01:53:36 -07001231 }
Romain Guycafdea62009-06-12 10:51:36 -07001232
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001233 /**
Jeff Browncc0c1592011-02-19 05:07:28 -08001234 * Return the kind of action being performed.
1235 * Consider using {@link #getActionMasked} and {@link #getActionIndex} to retrieve
1236 * the separate masked action and pointer index.
1237 * @return The action, such as {@link #ACTION_DOWN} or
1238 * the combination of {@link #ACTION_POINTER_DOWN} with a shifted pointer index.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001239 */
1240 public final int getAction() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001241 return nativeGetAction(mNativePtr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001242 }
1243
1244 /**
Jeff Browncc0c1592011-02-19 05:07:28 -08001245 * Return the masked action being performed, without pointer index information.
1246 * Use {@link #getActionIndex} to return the index associated with pointer actions.
1247 * @return The action, such as {@link #ACTION_DOWN} or {@link #ACTION_POINTER_DOWN}.
Dianne Hackbornb125dc52010-02-12 15:52:09 -08001248 */
1249 public final int getActionMasked() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001250 return nativeGetAction(mNativePtr) & ACTION_MASK;
Dianne Hackbornb125dc52010-02-12 15:52:09 -08001251 }
1252
1253 /**
1254 * For {@link #ACTION_POINTER_DOWN} or {@link #ACTION_POINTER_UP}
1255 * as returned by {@link #getActionMasked}, this returns the associated
Jeff Browncc0c1592011-02-19 05:07:28 -08001256 * pointer index.
1257 * The index may be used with {@link #getPointerId(int)},
Dianne Hackbornb125dc52010-02-12 15:52:09 -08001258 * {@link #getX(int)}, {@link #getY(int)}, {@link #getPressure(int)},
1259 * and {@link #getSize(int)} to get information about the pointer that has
1260 * gone down or up.
Jeff Browncc0c1592011-02-19 05:07:28 -08001261 * @return The index associated with the action.
Dianne Hackbornb125dc52010-02-12 15:52:09 -08001262 */
1263 public final int getActionIndex() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001264 return (nativeGetAction(mNativePtr) & ACTION_POINTER_INDEX_MASK)
1265 >> ACTION_POINTER_INDEX_SHIFT;
Dianne Hackbornb125dc52010-02-12 15:52:09 -08001266 }
1267
1268 /**
Jeff Brown33bbfd22011-02-24 20:55:35 -08001269 * Returns true if this motion event is a touch event.
1270 * <p>
1271 * Specifically excludes pointer events with action {@link #ACTION_HOVER_MOVE}
1272 * or {@link #ACTION_SCROLL} because they are not actually touch events
1273 * (the pointer is not down).
1274 * </p>
1275 * @return True if this motion event is a touch event.
1276 * @hide
1277 */
1278 public final boolean isTouchEvent() {
Jeff Brown56194eb2011-03-02 19:23:13 -08001279 return nativeIsTouchEvent(mNativePtr);
Jeff Brown33bbfd22011-02-24 20:55:35 -08001280 }
1281
1282 /**
Jeff Brown85a31762010-09-01 17:01:00 -07001283 * Gets the motion event flags.
1284 *
1285 * @see #FLAG_WINDOW_IS_OBSCURED
1286 */
1287 public final int getFlags() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001288 return nativeGetFlags(mNativePtr);
Jeff Brown85a31762010-09-01 17:01:00 -07001289 }
1290
1291 /**
Romain Guycafdea62009-06-12 10:51:36 -07001292 * Returns the time (in ms) when the user originally pressed down to start
1293 * a stream of position events.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001294 */
1295 public final long getDownTime() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001296 return nativeGetDownTimeNanos(mNativePtr) / NS_PER_MS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001297 }
1298
1299 /**
1300 * Returns the time (in ms) when this specific event was generated.
1301 */
1302 public final long getEventTime() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001303 return nativeGetEventTimeNanos(mNativePtr, HISTORY_CURRENT) / NS_PER_MS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001304 }
1305
1306 /**
Michael Chan53071d62009-05-13 17:29:48 -07001307 * Returns the time (in ns) when this specific event was generated.
1308 * The value is in nanosecond precision but it may not have nanosecond accuracy.
1309 *
1310 * @hide
1311 */
1312 public final long getEventTimeNano() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001313 return nativeGetEventTimeNanos(mNativePtr, HISTORY_CURRENT);
Michael Chan53071d62009-05-13 17:29:48 -07001314 }
1315
1316 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001317 * {@link #getX(int)} for the first pointer index (may be an
1318 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001319 *
1320 * @see #AXIS_X
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001321 */
1322 public final float getX() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001323 return nativeGetAxisValue(mNativePtr, AXIS_X, 0, HISTORY_CURRENT);
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001324 }
1325
1326 /**
1327 * {@link #getY(int)} for the first pointer index (may be an
1328 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001329 *
1330 * @see #AXIS_Y
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001331 */
1332 public final float getY() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001333 return nativeGetAxisValue(mNativePtr, AXIS_Y, 0, HISTORY_CURRENT);
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001334 }
1335
1336 /**
1337 * {@link #getPressure(int)} for the first pointer index (may be an
1338 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001339 *
1340 * @see #AXIS_PRESSURE
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001341 */
1342 public final float getPressure() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001343 return nativeGetAxisValue(mNativePtr, AXIS_PRESSURE, 0, HISTORY_CURRENT);
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001344 }
1345
1346 /**
1347 * {@link #getSize(int)} for the first pointer index (may be an
1348 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001349 *
1350 * @see #AXIS_SIZE
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001351 */
1352 public final float getSize() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001353 return nativeGetAxisValue(mNativePtr, AXIS_SIZE, 0, HISTORY_CURRENT);
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001354 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07001355
1356 /**
1357 * {@link #getTouchMajor(int)} for the first pointer index (may be an
1358 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001359 *
1360 * @see #AXIS_TOUCH_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07001361 */
1362 public final float getTouchMajor() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001363 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MAJOR, 0, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001364 }
1365
1366 /**
1367 * {@link #getTouchMinor(int)} for the first pointer index (may be an
1368 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001369 *
1370 * @see #AXIS_TOUCH_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07001371 */
1372 public final float getTouchMinor() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001373 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MINOR, 0, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001374 }
1375
1376 /**
1377 * {@link #getToolMajor(int)} for the first pointer index (may be an
1378 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001379 *
1380 * @see #AXIS_TOOL_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07001381 */
1382 public final float getToolMajor() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001383 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MAJOR, 0, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001384 }
1385
1386 /**
1387 * {@link #getToolMinor(int)} for the first pointer index (may be an
1388 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001389 *
1390 * @see #AXIS_TOOL_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07001391 */
1392 public final float getToolMinor() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001393 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MINOR, 0, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001394 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08001395
Jeff Brownc5ed5912010-07-14 18:48:53 -07001396 /**
1397 * {@link #getOrientation(int)} for the first pointer index (may be an
1398 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001399 *
1400 * @see #AXIS_ORIENTATION
Jeff Brownc5ed5912010-07-14 18:48:53 -07001401 */
1402 public final float getOrientation() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001403 return nativeGetAxisValue(mNativePtr, AXIS_ORIENTATION, 0, HISTORY_CURRENT);
1404 }
1405
1406 /**
1407 * {@link #getAxisValue(int)} for the first pointer index (may be an
1408 * arbitrary pointer identifier).
1409 *
1410 * @param axis The axis identifier for the axis value to retrieve.
1411 *
1412 * @see #AXIS_X
1413 * @see #AXIS_Y
1414 */
1415 public final float getAxisValue(int axis) {
1416 return nativeGetAxisValue(mNativePtr, axis, 0, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001417 }
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001418
1419 /**
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001420 * The number of pointers of data contained in this event. Always
1421 * >= 1.
1422 */
1423 public final int getPointerCount() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001424 return nativeGetPointerCount(mNativePtr);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001425 }
1426
1427 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001428 * Return the pointer identifier associated with a particular pointer
1429 * data index is this event. The identifier tells you the actual pointer
1430 * number associated with the data, accounting for individual pointers
1431 * going up and down since the start of the current gesture.
1432 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1433 * (the first pointer that is down) to {@link #getPointerCount()}-1.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001434 */
Dianne Hackbornd41ba662009-08-05 15:30:56 -07001435 public final int getPointerId(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001436 return nativeGetPointerId(mNativePtr, pointerIndex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001437 }
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001438
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001439 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001440 * Given a pointer identifier, find the index of its data in the event.
1441 *
1442 * @param pointerId The identifier of the pointer to be found.
1443 * @return Returns either the index of the pointer (for use with
Gilles Debunneb0d6ba12010-08-17 20:01:42 -07001444 * {@link #getX(int)} et al.), or -1 if there is no data available for
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001445 * that pointer identifier.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001446 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001447 public final int findPointerIndex(int pointerId) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001448 return nativeFindPointerIndex(mNativePtr, pointerId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001449 }
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001450
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001451 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001452 * Returns the X coordinate of this event for the given pointer
1453 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
1454 * identifier for this index).
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001455 * Whole numbers are pixels; the
1456 * value may have a fraction for input devices that are sub-pixel precise.
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001457 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1458 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08001459 *
1460 * @see #AXIS_X
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001461 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001462 public final float getX(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001463 return nativeGetAxisValue(mNativePtr, AXIS_X, pointerIndex, HISTORY_CURRENT);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001464 }
1465
1466 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001467 * Returns the Y coordinate of this event for the given pointer
1468 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
1469 * identifier for this index).
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001470 * Whole numbers are pixels; the
1471 * value may have a fraction for input devices that are sub-pixel precise.
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001472 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1473 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08001474 *
1475 * @see #AXIS_Y
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001476 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001477 public final float getY(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001478 return nativeGetAxisValue(mNativePtr, AXIS_Y, pointerIndex, HISTORY_CURRENT);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001479 }
1480
1481 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001482 * Returns the current pressure of this event for the given pointer
1483 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
1484 * identifier for this index).
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001485 * The pressure generally
Romain Guycafdea62009-06-12 10:51:36 -07001486 * ranges from 0 (no pressure at all) to 1 (normal pressure), however
1487 * values higher than 1 may be generated depending on the calibration of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001488 * the input device.
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001489 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1490 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08001491 *
1492 * @see #AXIS_PRESSURE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001493 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001494 public final float getPressure(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001495 return nativeGetAxisValue(mNativePtr, AXIS_PRESSURE, pointerIndex, HISTORY_CURRENT);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001496 }
1497
1498 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001499 * Returns a scaled value of the approximate size for the given pointer
1500 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
1501 * identifier for this index).
1502 * This represents some approximation of the area of the screen being
1503 * pressed; the actual value in pixels corresponding to the
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001504 * touch is normalized with the device specific range of values
Romain Guycafdea62009-06-12 10:51:36 -07001505 * 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 -08001506 * determine fat touch events.
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001507 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1508 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08001509 *
1510 * @see #AXIS_SIZE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001511 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001512 public final float getSize(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001513 return nativeGetAxisValue(mNativePtr, AXIS_SIZE, pointerIndex, HISTORY_CURRENT);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001514 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07001515
1516 /**
1517 * Returns the length of the major axis of an ellipse that describes the touch
1518 * area at the point of contact for the given pointer
1519 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
1520 * identifier for this index).
1521 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1522 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08001523 *
1524 * @see #AXIS_TOUCH_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07001525 */
1526 public final float getTouchMajor(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001527 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MAJOR, pointerIndex, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001528 }
1529
1530 /**
1531 * Returns the length of the minor axis of an ellipse that describes the touch
1532 * area at the point of contact for the given pointer
1533 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
1534 * identifier for this index).
1535 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1536 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08001537 *
1538 * @see #AXIS_TOUCH_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07001539 */
1540 public final float getTouchMinor(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001541 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MINOR, pointerIndex, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001542 }
1543
1544 /**
1545 * Returns the length of the major axis of an ellipse that describes the size of
1546 * the approaching tool for the given pointer
1547 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
1548 * identifier for this index).
1549 * The tool area represents the estimated size of the finger or pen that is
1550 * touching the device independent of its actual touch area at the point of contact.
1551 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1552 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08001553 *
1554 * @see #AXIS_TOOL_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07001555 */
1556 public final float getToolMajor(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001557 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MAJOR, pointerIndex, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001558 }
1559
1560 /**
1561 * Returns the length of the minor axis of an ellipse that describes the size of
1562 * the approaching tool for the given pointer
1563 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
1564 * identifier for this index).
1565 * The tool area represents the estimated size of the finger or pen that is
1566 * touching the device independent of its actual touch area at the point of contact.
1567 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1568 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08001569 *
1570 * @see #AXIS_TOOL_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07001571 */
1572 public final float getToolMinor(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001573 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MINOR, pointerIndex, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001574 }
1575
1576 /**
1577 * Returns the orientation of the touch area and tool area in radians clockwise from vertical
1578 * for the given pointer <em>index</em> (use {@link #getPointerId(int)} to find the pointer
1579 * identifier for this index).
Jeff Brown6f2fba42011-02-19 01:08:02 -08001580 * An angle of 0 radians indicates that the major axis of contact is oriented
Jeff Brownc5ed5912010-07-14 18:48:53 -07001581 * upwards, is perfectly circular or is of unknown orientation. A positive angle
1582 * indicates that the major axis of contact is oriented to the right. A negative angle
1583 * indicates that the major axis of contact is oriented to the left.
Jeff Brown6d0fec22010-07-23 21:28:06 -07001584 * The full range is from -PI/2 radians (finger pointing fully left) to PI/2 radians
Jeff Brownc5ed5912010-07-14 18:48:53 -07001585 * (finger pointing fully right).
1586 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1587 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08001588 *
1589 * @see #AXIS_ORIENTATION
Jeff Brownc5ed5912010-07-14 18:48:53 -07001590 */
1591 public final float getOrientation(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001592 return nativeGetAxisValue(mNativePtr, AXIS_ORIENTATION, pointerIndex, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001593 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08001594
1595 /**
1596 * Returns the value of the requested axis for the given pointer <em>index</em>
1597 * (use {@link #getPointerId(int)} to find the pointer identifier for this index).
1598 *
1599 * @param axis The axis identifier for the axis value to retrieve.
1600 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1601 * (the first pointer that is down) to {@link #getPointerCount()}-1.
1602 * @return The value of the axis, or 0 if the axis is not available.
1603 *
1604 * @see #AXIS_X
1605 * @see #AXIS_Y
1606 */
1607 public final float getAxisValue(int axis, int pointerIndex) {
1608 return nativeGetAxisValue(mNativePtr, axis, pointerIndex, HISTORY_CURRENT);
1609 }
1610
Jeff Brownc5ed5912010-07-14 18:48:53 -07001611 /**
1612 * Populates a {@link PointerCoords} object with pointer coordinate data for
1613 * the specified pointer index.
1614 *
1615 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1616 * (the first pointer that is down) to {@link #getPointerCount()}-1.
1617 * @param outPointerCoords The pointer coordinate object to populate.
Jeff Brown91c69ab2011-02-14 17:03:18 -08001618 *
1619 * @see PointerCoords
Jeff Brownc5ed5912010-07-14 18:48:53 -07001620 */
1621 public final void getPointerCoords(int pointerIndex, PointerCoords outPointerCoords) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001622 nativeGetPointerCoords(mNativePtr, pointerIndex, HISTORY_CURRENT, outPointerCoords);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001623 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001624
1625 /**
1626 * Returns the state of any meta / modifier keys that were in effect when
1627 * the event was generated. This is the same values as those
1628 * returned by {@link KeyEvent#getMetaState() KeyEvent.getMetaState}.
1629 *
1630 * @return an integer in which each bit set to 1 represents a pressed
1631 * meta key
1632 *
1633 * @see KeyEvent#getMetaState()
1634 */
1635 public final int getMetaState() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001636 return nativeGetMetaState(mNativePtr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001637 }
1638
1639 /**
1640 * Returns the original raw X coordinate of this event. For touch
1641 * events on the screen, this is the original location of the event
1642 * on the screen, before it had been adjusted for the containing window
1643 * and views.
Jeff Brown91c69ab2011-02-14 17:03:18 -08001644 *
1645 * @see getX()
1646 * @see #AXIS_X
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001647 */
1648 public final float getRawX() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001649 return nativeGetRawAxisValue(mNativePtr, AXIS_X, 0, HISTORY_CURRENT);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001650 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08001651
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001652 /**
1653 * Returns the original raw Y coordinate of this event. For touch
1654 * events on the screen, this is the original location of the event
1655 * on the screen, before it had been adjusted for the containing window
1656 * and views.
Jeff Brown91c69ab2011-02-14 17:03:18 -08001657 *
1658 * @see getY()
1659 * @see #AXIS_Y
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001660 */
1661 public final float getRawY() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001662 return nativeGetRawAxisValue(mNativePtr, AXIS_Y, 0, HISTORY_CURRENT);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001663 }
1664
1665 /**
1666 * Return the precision of the X coordinates being reported. You can
Jeff Brown91c69ab2011-02-14 17:03:18 -08001667 * multiply this number with {@link #getX} to find the actual hardware
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001668 * value of the X coordinate.
1669 * @return Returns the precision of X coordinates being reported.
Jeff Brown91c69ab2011-02-14 17:03:18 -08001670 *
1671 * @see #AXIS_X
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001672 */
1673 public final float getXPrecision() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001674 return nativeGetXPrecision(mNativePtr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001675 }
Romain Guycafdea62009-06-12 10:51:36 -07001676
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001677 /**
1678 * Return the precision of the Y coordinates being reported. You can
Jeff Brown91c69ab2011-02-14 17:03:18 -08001679 * multiply this number with {@link #getY} to find the actual hardware
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001680 * value of the Y coordinate.
1681 * @return Returns the precision of Y coordinates being reported.
Jeff Brown91c69ab2011-02-14 17:03:18 -08001682 *
1683 * @see #AXIS_Y
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001684 */
1685 public final float getYPrecision() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001686 return nativeGetYPrecision(mNativePtr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001687 }
Romain Guycafdea62009-06-12 10:51:36 -07001688
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001689 /**
1690 * Returns the number of historical points in this event. These are
1691 * movements that have occurred between this event and the previous event.
1692 * This only applies to ACTION_MOVE events -- all other actions will have
1693 * a size of 0.
Romain Guycafdea62009-06-12 10:51:36 -07001694 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001695 * @return Returns the number of historical points in the event.
1696 */
1697 public final int getHistorySize() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001698 return nativeGetHistorySize(mNativePtr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001699 }
Romain Guycafdea62009-06-12 10:51:36 -07001700
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001701 /**
1702 * Returns the time that a historical movement occurred between this event
1703 * and the previous event. Only applies to ACTION_MOVE events.
Romain Guycafdea62009-06-12 10:51:36 -07001704 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001705 * @param pos Which historical value to return; must be less than
1706 * {@link #getHistorySize}
Romain Guycafdea62009-06-12 10:51:36 -07001707 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001708 * @see #getHistorySize
1709 * @see #getEventTime
1710 */
1711 public final long getHistoricalEventTime(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001712 return nativeGetEventTimeNanos(mNativePtr, pos) / NS_PER_MS;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001713 }
1714
1715 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08001716 * {@link #getHistoricalX(int, int)} for the first pointer index (may be an
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001717 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001718 *
1719 * @param pos Which historical value to return; must be less than
1720 * {@link #getHistorySize}
1721 *
1722 * @see #getHistorySize
1723 * @see #getX()
1724 * @see #AXIS_X
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001725 */
1726 public final float getHistoricalX(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001727 return nativeGetAxisValue(mNativePtr, AXIS_X, 0, pos);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001728 }
1729
1730 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08001731 * {@link #getHistoricalY(int, int)} for the first pointer index (may be an
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001732 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001733 *
1734 * @param pos Which historical value to return; must be less than
1735 * {@link #getHistorySize}
1736 *
1737 * @see #getHistorySize
1738 * @see #getY()
1739 * @see #AXIS_Y
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001740 */
1741 public final float getHistoricalY(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001742 return nativeGetAxisValue(mNativePtr, AXIS_Y, 0, pos);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001743 }
1744
1745 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08001746 * {@link #getHistoricalPressure(int, int)} for the first pointer index (may be an
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001747 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001748 *
1749 * @param pos Which historical value to return; must be less than
1750 * {@link #getHistorySize}
1751 *
1752 * @see #getHistorySize
1753 * @see #getPressure()
1754 * @see #AXIS_PRESSURE
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001755 */
1756 public final float getHistoricalPressure(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001757 return nativeGetAxisValue(mNativePtr, AXIS_PRESSURE, 0, pos);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001758 }
1759
1760 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08001761 * {@link #getHistoricalSize(int, int)} for the first pointer index (may be an
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001762 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001763 *
1764 * @param pos Which historical value to return; must be less than
1765 * {@link #getHistorySize}
1766 *
1767 * @see #getHistorySize
1768 * @see #getSize()
1769 * @see #AXIS_SIZE
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001770 */
1771 public final float getHistoricalSize(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001772 return nativeGetAxisValue(mNativePtr, AXIS_SIZE, 0, pos);
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 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08001776 * {@link #getHistoricalTouchMajor(int, int)} for the first pointer index (may be an
Jeff Brownc5ed5912010-07-14 18:48:53 -07001777 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001778 *
1779 * @param pos Which historical value to return; must be less than
1780 * {@link #getHistorySize}
1781 *
1782 * @see #getHistorySize
1783 * @see #getTouchMajor()
1784 * @see #AXIS_TOUCH_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07001785 */
1786 public final float getHistoricalTouchMajor(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001787 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MAJOR, 0, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001788 }
1789
1790 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08001791 * {@link #getHistoricalTouchMinor(int, int)} for the first pointer index (may be an
Jeff Brownc5ed5912010-07-14 18:48:53 -07001792 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001793 *
1794 * @param pos Which historical value to return; must be less than
1795 * {@link #getHistorySize}
1796 *
1797 * @see #getHistorySize
1798 * @see #getTouchMinor()
1799 * @see #AXIS_TOUCH_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07001800 */
1801 public final float getHistoricalTouchMinor(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001802 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MINOR, 0, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001803 }
1804
1805 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08001806 * {@link #getHistoricalToolMajor(int, int)} for the first pointer index (may be an
Jeff Brownc5ed5912010-07-14 18:48:53 -07001807 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001808 *
1809 * @param pos Which historical value to return; must be less than
1810 * {@link #getHistorySize}
1811 *
1812 * @see #getHistorySize
1813 * @see #getToolMajor()
1814 * @see #AXIS_TOOL_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07001815 */
1816 public final float getHistoricalToolMajor(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001817 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MAJOR, 0, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001818 }
1819
1820 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08001821 * {@link #getHistoricalToolMinor(int, int)} for the first pointer index (may be an
Jeff Brownc5ed5912010-07-14 18:48:53 -07001822 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001823 *
1824 * @param pos Which historical value to return; must be less than
1825 * {@link #getHistorySize}
1826 *
1827 * @see #getHistorySize
1828 * @see #getToolMinor()
1829 * @see #AXIS_TOOL_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07001830 */
1831 public final float getHistoricalToolMinor(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001832 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MINOR, 0, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001833 }
1834
1835 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08001836 * {@link #getHistoricalOrientation(int, int)} for the first pointer index (may be an
Jeff Brownc5ed5912010-07-14 18:48:53 -07001837 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001838 *
1839 * @param pos Which historical value to return; must be less than
1840 * {@link #getHistorySize}
1841 *
1842 * @see #getHistorySize
1843 * @see #getOrientation()
1844 * @see #AXIS_ORIENTATION
Jeff Brownc5ed5912010-07-14 18:48:53 -07001845 */
1846 public final float getHistoricalOrientation(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001847 return nativeGetAxisValue(mNativePtr, AXIS_ORIENTATION, 0, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001848 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08001849
1850 /**
1851 * {@link #getHistoricalAxisValue(int, int, int)} for the first pointer index (may be an
1852 * arbitrary pointer identifier).
1853 *
1854 * @param axis The axis identifier for the axis value to retrieve.
1855 * @param pos Which historical value to return; must be less than
1856 * {@link #getHistorySize}
1857 *
1858 * @see #getHistorySize
1859 * @see #getAxisValue(int)
1860 * @see #AXIS_X
1861 * @see #AXIS_Y
1862 */
1863 public final float getHistoricalAxisValue(int axis, int pos) {
1864 return nativeGetAxisValue(mNativePtr, axis, 0, pos);
1865 }
1866
Jeff Brownc5ed5912010-07-14 18:48:53 -07001867 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001868 * Returns a historical X coordinate, as per {@link #getX(int)}, that
1869 * occurred between this event and the previous event for the given pointer.
1870 * Only applies to ACTION_MOVE events.
Romain Guycafdea62009-06-12 10:51:36 -07001871 *
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001872 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1873 * (the first pointer that is down) to {@link #getPointerCount()}-1.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001874 * @param pos Which historical value to return; must be less than
1875 * {@link #getHistorySize}
Romain Guycafdea62009-06-12 10:51:36 -07001876 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001877 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08001878 * @see #getX(int)
1879 * @see #AXIS_X
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001880 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001881 public final float getHistoricalX(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001882 return nativeGetAxisValue(mNativePtr, AXIS_X, pointerIndex, pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001883 }
Romain Guycafdea62009-06-12 10:51:36 -07001884
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001885 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001886 * Returns a historical Y coordinate, as per {@link #getY(int)}, that
1887 * occurred between this event and the previous event for the given pointer.
1888 * Only applies to ACTION_MOVE events.
Romain Guycafdea62009-06-12 10:51:36 -07001889 *
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001890 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1891 * (the first pointer that is down) to {@link #getPointerCount()}-1.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001892 * @param pos Which historical value to return; must be less than
1893 * {@link #getHistorySize}
Romain Guycafdea62009-06-12 10:51:36 -07001894 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001895 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08001896 * @see #getY(int)
1897 * @see #AXIS_Y
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001898 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001899 public final float getHistoricalY(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001900 return nativeGetAxisValue(mNativePtr, AXIS_Y, pointerIndex, pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001901 }
Romain Guycafdea62009-06-12 10:51:36 -07001902
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001903 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001904 * Returns a historical pressure coordinate, as per {@link #getPressure(int)},
1905 * that occurred between this event and the previous event for the given
1906 * pointer. Only applies to ACTION_MOVE events.
Romain Guycafdea62009-06-12 10:51:36 -07001907 *
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001908 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1909 * (the first pointer that is down) to {@link #getPointerCount()}-1.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001910 * @param pos Which historical value to return; must be less than
1911 * {@link #getHistorySize}
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001912 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001913 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08001914 * @see #getPressure(int)
1915 * @see #AXIS_PRESSURE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001916 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001917 public final float getHistoricalPressure(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001918 return nativeGetAxisValue(mNativePtr, AXIS_PRESSURE, pointerIndex, pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001919 }
Romain Guycafdea62009-06-12 10:51:36 -07001920
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001921 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001922 * Returns a historical size coordinate, as per {@link #getSize(int)}, that
1923 * occurred between this event and the previous event for the given pointer.
1924 * Only applies to ACTION_MOVE events.
Romain Guycafdea62009-06-12 10:51:36 -07001925 *
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001926 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1927 * (the first pointer that is down) to {@link #getPointerCount()}-1.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001928 * @param pos Which historical value to return; must be less than
1929 * {@link #getHistorySize}
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001930 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001931 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08001932 * @see #getSize(int)
1933 * @see #AXIS_SIZE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001934 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001935 public final float getHistoricalSize(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001936 return nativeGetAxisValue(mNativePtr, AXIS_SIZE, pointerIndex, pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001937 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07001938
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001939 /**
Jeff Brownc5ed5912010-07-14 18:48:53 -07001940 * Returns a historical touch major axis coordinate, as per {@link #getTouchMajor(int)}, that
1941 * occurred between this event and the previous event for the given pointer.
1942 * Only applies to ACTION_MOVE events.
1943 *
1944 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1945 * (the first pointer that is down) to {@link #getPointerCount()}-1.
1946 * @param pos Which historical value to return; must be less than
1947 * {@link #getHistorySize}
1948 *
1949 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08001950 * @see #getTouchMajor(int)
1951 * @see #AXIS_TOUCH_MAJOR
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001952 */
Jeff Brownc5ed5912010-07-14 18:48:53 -07001953 public final float getHistoricalTouchMajor(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001954 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MAJOR, pointerIndex, pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001955 }
Romain Guycafdea62009-06-12 10:51:36 -07001956
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001957 /**
Jeff Brownc5ed5912010-07-14 18:48:53 -07001958 * Returns a historical touch minor axis coordinate, as per {@link #getTouchMinor(int)}, that
1959 * occurred between this event and the previous event for the given pointer.
1960 * Only applies to ACTION_MOVE events.
1961 *
1962 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1963 * (the first pointer that is down) to {@link #getPointerCount()}-1.
1964 * @param pos Which historical value to return; must be less than
1965 * {@link #getHistorySize}
1966 *
1967 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08001968 * @see #getTouchMinor(int)
1969 * @see #AXIS_TOUCH_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07001970 */
1971 public final float getHistoricalTouchMinor(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001972 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MINOR, pointerIndex, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001973 }
1974
1975 /**
1976 * Returns a historical tool major axis coordinate, as per {@link #getToolMajor(int)}, that
1977 * occurred between this event and the previous event for the given pointer.
1978 * Only applies to ACTION_MOVE events.
1979 *
1980 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1981 * (the first pointer that is down) to {@link #getPointerCount()}-1.
1982 * @param pos Which historical value to return; must be less than
1983 * {@link #getHistorySize}
1984 *
1985 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08001986 * @see #getToolMajor(int)
1987 * @see #AXIS_TOOL_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07001988 */
1989 public final float getHistoricalToolMajor(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001990 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MAJOR, pointerIndex, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001991 }
1992
1993 /**
1994 * Returns a historical tool minor axis coordinate, as per {@link #getToolMinor(int)}, that
1995 * occurred between this event and the previous event for the given pointer.
1996 * Only applies to ACTION_MOVE events.
1997 *
1998 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1999 * (the first pointer that is down) to {@link #getPointerCount()}-1.
2000 * @param pos Which historical value to return; must be less than
2001 * {@link #getHistorySize}
2002 *
2003 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08002004 * @see #getToolMinor(int)
2005 * @see #AXIS_TOOL_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002006 */
2007 public final float getHistoricalToolMinor(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002008 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MINOR, pointerIndex, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002009 }
2010
2011 /**
2012 * Returns a historical orientation coordinate, as per {@link #getOrientation(int)}, that
2013 * occurred between this event and the previous event for the given pointer.
2014 * Only applies to ACTION_MOVE events.
2015 *
2016 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2017 * (the first pointer that is down) to {@link #getPointerCount()}-1.
2018 * @param pos Which historical value to return; must be less than
2019 * {@link #getHistorySize}
2020 *
2021 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08002022 * @see #getOrientation(int)
2023 * @see #AXIS_ORIENTATION
Jeff Brownc5ed5912010-07-14 18:48:53 -07002024 */
2025 public final float getHistoricalOrientation(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002026 return nativeGetAxisValue(mNativePtr, AXIS_ORIENTATION, pointerIndex, pos);
2027 }
2028
2029 /**
2030 * Returns the historical value of the requested axis, as per {@link #getAxisValue(int, int)},
2031 * occurred between this event and the previous event for the given pointer.
2032 * Only applies to ACTION_MOVE events.
2033 *
2034 * @param axis The axis identifier for the axis value to retrieve.
2035 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2036 * (the first pointer that is down) to {@link #getPointerCount()}-1.
2037 * @param pos Which historical value to return; must be less than
2038 * {@link #getHistorySize}
2039 * @return The value of the axis, or 0 if the axis is not available.
2040 *
2041 * @see #AXIS_X
2042 * @see #AXIS_Y
2043 */
2044 public final float getHistoricalAxisValue(int axis, int pointerIndex, int pos) {
2045 return nativeGetAxisValue(mNativePtr, axis, pointerIndex, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002046 }
2047
2048 /**
2049 * Populates a {@link PointerCoords} object with historical pointer coordinate data,
2050 * as per {@link #getPointerCoords}, that occurred between this event and the previous
2051 * event for the given pointer.
2052 * Only applies to ACTION_MOVE events.
2053 *
2054 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2055 * (the first pointer that is down) to {@link #getPointerCount()}-1.
2056 * @param pos Which historical value to return; must be less than
2057 * {@link #getHistorySize}
2058 * @param outPointerCoords The pointer coordinate object to populate.
2059 *
2060 * @see #getHistorySize
2061 * @see #getPointerCoords
Jeff Brown91c69ab2011-02-14 17:03:18 -08002062 * @see PointerCoords
Jeff Brownc5ed5912010-07-14 18:48:53 -07002063 */
2064 public final void getHistoricalPointerCoords(int pointerIndex, int pos,
2065 PointerCoords outPointerCoords) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002066 nativeGetPointerCoords(mNativePtr, pointerIndex, pos, outPointerCoords);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002067 }
2068
2069 /**
Jeff Brown46b9ac02010-04-22 18:58:52 -07002070 * Returns a bitfield indicating which edges, if any, were touched by this
Romain Guycafdea62009-06-12 10:51:36 -07002071 * MotionEvent. For touch events, clients can use this to determine if the
2072 * user's finger was touching the edge of the display.
2073 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002074 * @see #EDGE_LEFT
2075 * @see #EDGE_TOP
2076 * @see #EDGE_RIGHT
2077 * @see #EDGE_BOTTOM
2078 */
2079 public final int getEdgeFlags() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002080 return nativeGetEdgeFlags(mNativePtr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002081 }
Romain Guycafdea62009-06-12 10:51:36 -07002082
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002083 /**
Jeff Brown85a31762010-09-01 17:01:00 -07002084 * Sets the bitfield indicating which edges, if any, were touched by this
Romain Guycafdea62009-06-12 10:51:36 -07002085 * MotionEvent.
2086 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002087 * @see #getEdgeFlags()
2088 */
2089 public final void setEdgeFlags(int flags) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002090 nativeSetEdgeFlags(mNativePtr, flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002091 }
2092
2093 /**
2094 * Sets this event's action.
2095 */
2096 public final void setAction(int action) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002097 nativeSetAction(mNativePtr, action);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002098 }
2099
2100 /**
2101 * Adjust this event's location.
2102 * @param deltaX Amount to add to the current X coordinate of the event.
2103 * @param deltaY Amount to add to the current Y coordinate of the event.
2104 */
2105 public final void offsetLocation(float deltaX, float deltaY) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002106 nativeOffsetLocation(mNativePtr, deltaX, deltaY);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002107 }
Romain Guycafdea62009-06-12 10:51:36 -07002108
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002109 /**
2110 * Set this event's location. Applies {@link #offsetLocation} with a
2111 * delta from the current location to the given new location.
Romain Guycafdea62009-06-12 10:51:36 -07002112 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002113 * @param x New absolute X location.
2114 * @param y New absolute Y location.
2115 */
2116 public final void setLocation(float x, float y) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002117 float oldX = getX();
2118 float oldY = getY();
2119 nativeOffsetLocation(mNativePtr, x - oldX, y - oldY);
Jeff Brown5c225b12010-06-16 01:53:36 -07002120 }
2121
Jeff Brown20e987b2010-08-23 12:01:02 -07002122 /**
2123 * Applies a transformation matrix to all of the points in the event.
2124 *
2125 * @param matrix The transformation matrix to apply.
2126 */
2127 public final void transform(Matrix matrix) {
2128 if (matrix == null) {
2129 throw new IllegalArgumentException("matrix must not be null");
2130 }
2131
Jeff Brown91c69ab2011-02-14 17:03:18 -08002132 nativeTransform(mNativePtr, matrix);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002133 }
Romain Guycafdea62009-06-12 10:51:36 -07002134
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002135 /**
2136 * Add a new movement to the batch of movements in this event. The event's
Jeff Brownc5ed5912010-07-14 18:48:53 -07002137 * current location, position and size is updated to the new values.
2138 * The current values in the event are added to a list of historical values.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002139 *
Jeff Browncc0c1592011-02-19 05:07:28 -08002140 * Only applies to {@link #ACTION_MOVE} or {@link #ACTION_HOVER_MOVE} events.
Romain Guycafdea62009-06-12 10:51:36 -07002141 *
Jeff Brownc5ed5912010-07-14 18:48:53 -07002142 * @param eventTime The time stamp (in ms) for this data.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002143 * @param x The new X position.
2144 * @param y The new Y position.
2145 * @param pressure The new pressure.
2146 * @param size The new size.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002147 * @param metaState Meta key state.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002148 */
2149 public final void addBatch(long eventTime, float x, float y,
2150 float pressure, float size, int metaState) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002151 synchronized (gTmpPointerCoords) {
2152 final PointerCoords pc = gTmpPointerCoords[0];
2153 pc.clear();
2154 pc.x = x;
2155 pc.y = y;
2156 pc.pressure = pressure;
2157 pc.size = size;
2158 nativeAddBatch(mNativePtr, eventTime * NS_PER_MS, gTmpPointerCoords, metaState);
2159 }
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002160 }
Romain Guycafdea62009-06-12 10:51:36 -07002161
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002162 /**
Jeff Brownc5ed5912010-07-14 18:48:53 -07002163 * Add a new movement to the batch of movements in this event. The event's
2164 * current location, position and size is updated to the new values.
2165 * The current values in the event are added to a list of historical values.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002166 *
Jeff Browncc0c1592011-02-19 05:07:28 -08002167 * Only applies to {@link #ACTION_MOVE} or {@link #ACTION_HOVER_MOVE} events.
Jeff Brownc5ed5912010-07-14 18:48:53 -07002168 *
2169 * @param eventTime The time stamp (in ms) for this data.
2170 * @param pointerCoords The new pointer coordinates.
2171 * @param metaState Meta key state.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002172 */
Jeff Brownc5ed5912010-07-14 18:48:53 -07002173 public final void addBatch(long eventTime, PointerCoords[] pointerCoords, int metaState) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002174 nativeAddBatch(mNativePtr, eventTime * NS_PER_MS, pointerCoords, metaState);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002175 }
Romain Guycafdea62009-06-12 10:51:36 -07002176
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002177 @Override
2178 public String toString() {
2179 return "MotionEvent{" + Integer.toHexString(System.identityHashCode(this))
Huahui Wue838a422011-01-13 16:03:43 -08002180 + " pointerId=" + getPointerId(0)
Jeff Brown91c69ab2011-02-14 17:03:18 -08002181 + " action=" + actionToString(getAction())
Jeff Brown497a92c2010-09-12 17:55:08 -07002182 + " x=" + getX()
2183 + " y=" + getY()
2184 + " pressure=" + getPressure()
2185 + " size=" + getSize()
2186 + " touchMajor=" + getTouchMajor()
2187 + " touchMinor=" + getTouchMinor()
2188 + " toolMajor=" + getToolMajor()
2189 + " toolMinor=" + getToolMinor()
2190 + " orientation=" + getOrientation()
Jeff Brown91c69ab2011-02-14 17:03:18 -08002191 + " meta=" + KeyEvent.metaStateToString(getMetaState())
Jeff Brown497a92c2010-09-12 17:55:08 -07002192 + " pointerCount=" + getPointerCount()
2193 + " historySize=" + getHistorySize()
Jeff Brown91c69ab2011-02-14 17:03:18 -08002194 + " flags=0x" + Integer.toHexString(getFlags())
2195 + " edgeFlags=0x" + Integer.toHexString(getEdgeFlags())
2196 + " device=" + getDeviceId()
2197 + " source=0x" + Integer.toHexString(getSource())
Huahui Wue838a422011-01-13 16:03:43 -08002198 + (getPointerCount() > 1 ?
Huahui Wuf9324692011-01-24 12:07:37 -08002199 " pointerId2=" + getPointerId(1) + " x2=" + getX(1) + " y2=" + getY(1) : "")
Jeff Brown497a92c2010-09-12 17:55:08 -07002200 + "}";
2201 }
2202
2203 /**
2204 * Returns a string that represents the symbolic name of the specified action
Jeff Brown91c69ab2011-02-14 17:03:18 -08002205 * such as "ACTION_DOWN", "ACTION_POINTER_DOWN(3)" or an equivalent numeric constant
2206 * such as "35" if unknown.
Jeff Brown497a92c2010-09-12 17:55:08 -07002207 *
2208 * @param action The action.
2209 * @return The symbolic name of the specified action.
2210 * @hide
2211 */
2212 public static String actionToString(int action) {
2213 switch (action) {
2214 case ACTION_DOWN:
2215 return "ACTION_DOWN";
2216 case ACTION_UP:
2217 return "ACTION_UP";
2218 case ACTION_CANCEL:
2219 return "ACTION_CANCEL";
Jeff Brown33bbfd22011-02-24 20:55:35 -08002220 case ACTION_OUTSIDE:
2221 return "ACTION_OUTSIDE";
Jeff Brown497a92c2010-09-12 17:55:08 -07002222 case ACTION_MOVE:
2223 return "ACTION_MOVE";
Jeff Browncc0c1592011-02-19 05:07:28 -08002224 case ACTION_HOVER_MOVE:
2225 return "ACTION_HOVER_MOVE";
Jeff Brown33bbfd22011-02-24 20:55:35 -08002226 case ACTION_SCROLL:
2227 return "ACTION_SCROLL";
Jeff Brown497a92c2010-09-12 17:55:08 -07002228 }
2229 int index = (action & ACTION_POINTER_INDEX_MASK) >> ACTION_POINTER_INDEX_SHIFT;
2230 switch (action & ACTION_MASK) {
2231 case ACTION_POINTER_DOWN:
2232 return "ACTION_POINTER_DOWN(" + index + ")";
2233 case ACTION_POINTER_UP:
2234 return "ACTION_POINTER_UP(" + index + ")";
2235 default:
2236 return Integer.toString(action);
2237 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002238 }
2239
Jeff Brown91c69ab2011-02-14 17:03:18 -08002240 /**
2241 * Returns a string that represents the symbolic name of the specified axis
Jeff Brown6f2fba42011-02-19 01:08:02 -08002242 * such as "AXIS_X" or an equivalent numeric constant such as "42" if unknown.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002243 *
2244 * @param axis The axis
2245 * @return The symbolic name of the specified axis.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002246 */
2247 public static String axisToString(int axis) {
Jeff Brown6f2fba42011-02-19 01:08:02 -08002248 String symbolicName = AXIS_SYMBOLIC_NAMES.get(axis);
2249 return symbolicName != null ? symbolicName : Integer.toString(axis);
2250 }
2251
2252 /**
Jeff Browncc0c1592011-02-19 05:07:28 -08002253 * Gets an axis by its symbolic name such as "AXIS_X" or an
2254 * equivalent numeric constant such as "42".
Jeff Brown6f2fba42011-02-19 01:08:02 -08002255 *
2256 * @param symbolicName The symbolic name of the axis.
2257 * @return The axis or -1 if not found.
2258 * @see #keycodeToString
2259 */
2260 public static int axisFromString(String symbolicName) {
2261 if (symbolicName == null) {
2262 throw new IllegalArgumentException("symbolicName must not be null");
2263 }
2264
2265 final int count = AXIS_SYMBOLIC_NAMES.size();
2266 for (int i = 0; i < count; i++) {
2267 if (symbolicName.equals(AXIS_SYMBOLIC_NAMES.valueAt(i))) {
2268 return i;
2269 }
2270 }
2271
2272 try {
2273 return Integer.parseInt(symbolicName, 10);
2274 } catch (NumberFormatException ex) {
2275 return -1;
Jeff Brown91c69ab2011-02-14 17:03:18 -08002276 }
2277 }
2278
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002279 public static final Parcelable.Creator<MotionEvent> CREATOR
2280 = new Parcelable.Creator<MotionEvent>() {
2281 public MotionEvent createFromParcel(Parcel in) {
Jeff Brown6ec402b2010-07-28 15:48:59 -07002282 in.readInt(); // skip token, we already know this is a MotionEvent
2283 return MotionEvent.createFromParcelBody(in);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002284 }
2285
2286 public MotionEvent[] newArray(int size) {
2287 return new MotionEvent[size];
2288 }
2289 };
2290
Jeff Brown6ec402b2010-07-28 15:48:59 -07002291 /** @hide */
2292 public static MotionEvent createFromParcelBody(Parcel in) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002293 MotionEvent ev = obtain();
2294 ev.mNativePtr = nativeReadFromParcel(ev.mNativePtr, in);
Jeff Brown6ec402b2010-07-28 15:48:59 -07002295 return ev;
2296 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08002297
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002298 public void writeToParcel(Parcel out, int flags) {
Jeff Brown6ec402b2010-07-28 15:48:59 -07002299 out.writeInt(PARCEL_TOKEN_MOTION_EVENT);
Jeff Brown91c69ab2011-02-14 17:03:18 -08002300 nativeWriteToParcel(mNativePtr, out);
Jeff Brown5c225b12010-06-16 01:53:36 -07002301 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08002302
Jeff Brownc5ed5912010-07-14 18:48:53 -07002303 /**
2304 * Transfer object for pointer coordinates.
2305 *
2306 * Objects of this type can be used to manufacture new {@link MotionEvent} objects
2307 * and to query pointer coordinate information in bulk.
2308 *
2309 * Refer to {@link InputDevice} for information about how different kinds of
2310 * input devices and sources represent pointer coordinates.
2311 */
2312 public static final class PointerCoords {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002313 private static final int INITIAL_PACKED_AXIS_VALUES = 8;
Jeff Brown6f2fba42011-02-19 01:08:02 -08002314 private long mPackedAxisBits;
Jeff Brown91c69ab2011-02-14 17:03:18 -08002315 private float[] mPackedAxisValues;
2316
2317 /**
2318 * Creates a pointer coords object with all axes initialized to zero.
2319 */
2320 public PointerCoords() {
2321 }
2322
2323 /**
2324 * Creates a pointer coords object as a copy of the
2325 * contents of another pointer coords object.
2326 *
2327 * @param other The pointer coords object to copy.
2328 */
2329 public PointerCoords(PointerCoords other) {
2330 copyFrom(other);
2331 }
2332
Jeff Brownc5ed5912010-07-14 18:48:53 -07002333 /**
Jeff Brown6f2fba42011-02-19 01:08:02 -08002334 * The X component of the pointer movement.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002335 *
2336 * @see MotionEvent#AXIS_X
Jeff Brownc5ed5912010-07-14 18:48:53 -07002337 */
2338 public float x;
2339
2340 /**
Jeff Brown6f2fba42011-02-19 01:08:02 -08002341 * The Y component of the pointer movement.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002342 *
2343 * @see MotionEvent#AXIS_Y
Jeff Brownc5ed5912010-07-14 18:48:53 -07002344 */
2345 public float y;
2346
2347 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08002348 * A normalized value that describes the pressure applied to the device
2349 * by a finger or other tool.
Jeff Brownc5ed5912010-07-14 18:48:53 -07002350 * The pressure generally ranges from 0 (no pressure at all) to 1 (normal pressure),
Jeff Brown91c69ab2011-02-14 17:03:18 -08002351 * although values higher than 1 may be generated depending on the calibration of
Jeff Brownc5ed5912010-07-14 18:48:53 -07002352 * the input device.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002353 *
2354 * @see MotionEvent#AXIS_PRESSURE
Jeff Brownc5ed5912010-07-14 18:48:53 -07002355 */
2356 public float pressure;
2357
2358 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08002359 * A normalized value that describes the approximate size of the pointer touch area
2360 * in relation to the maximum detectable size of the device.
2361 * It represents some approximation of the area of the screen being
Jeff Brownc5ed5912010-07-14 18:48:53 -07002362 * pressed; the actual value in pixels corresponding to the
2363 * touch is normalized with the device specific range of values
2364 * and scaled to a value between 0 and 1. The value of size can be used to
2365 * determine fat touch events.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002366 *
2367 * @see MotionEvent#AXIS_SIZE
Jeff Brownc5ed5912010-07-14 18:48:53 -07002368 */
2369 public float size;
2370
2371 /**
2372 * The length of the major axis of an ellipse that describes the touch area at
2373 * the point of contact.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002374 * If the device is a touch screen, the length is reported in pixels, otherwise it is
2375 * reported in device-specific units.
2376 *
2377 * @see MotionEvent#AXIS_TOUCH_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002378 */
2379 public float touchMajor;
2380
2381 /**
2382 * The length of the minor axis of an ellipse that describes the touch area at
2383 * the point of contact.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002384 * If the device is a touch screen, the length is reported in pixels, otherwise it is
2385 * reported in device-specific units.
2386 *
2387 * @see MotionEvent#AXIS_TOUCH_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002388 */
2389 public float touchMinor;
2390
2391 /**
2392 * The length of the major axis of an ellipse that describes the size of
2393 * the approaching tool.
2394 * The tool area represents the estimated size of the finger or pen that is
2395 * touching the device independent of its actual touch area at the point of contact.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002396 * If the device is a touch screen, the length is reported in pixels, otherwise it is
2397 * reported in device-specific units.
2398 *
2399 * @see MotionEvent#AXIS_TOOL_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002400 */
2401 public float toolMajor;
2402
2403 /**
2404 * The length of the minor axis of an ellipse that describes the size of
2405 * the approaching tool.
2406 * The tool area represents the estimated size of the finger or pen that is
2407 * touching the device independent of its actual touch area at the point of contact.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002408 * If the device is a touch screen, the length is reported in pixels, otherwise it is
2409 * reported in device-specific units.
2410 *
2411 * @see MotionEvent#AXIS_TOOL_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002412 */
2413 public float toolMinor;
2414
2415 /**
2416 * The orientation of the touch area and tool area in radians clockwise from vertical.
Jeff Brown6f2fba42011-02-19 01:08:02 -08002417 * An angle of 0 radians indicates that the major axis of contact is oriented
Jeff Brownc5ed5912010-07-14 18:48:53 -07002418 * upwards, is perfectly circular or is of unknown orientation. A positive angle
2419 * indicates that the major axis of contact is oriented to the right. A negative angle
2420 * indicates that the major axis of contact is oriented to the left.
Jeff Brown6d0fec22010-07-23 21:28:06 -07002421 * The full range is from -PI/2 radians (finger pointing fully left) to PI/2 radians
Jeff Brownc5ed5912010-07-14 18:48:53 -07002422 * (finger pointing fully right).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002423 *
2424 * @see MotionEvent#AXIS_ORIENTATION
Jeff Brownc5ed5912010-07-14 18:48:53 -07002425 */
2426 public float orientation;
Jeff Brown91c69ab2011-02-14 17:03:18 -08002427
2428 /**
2429 * Clears the contents of this object.
2430 * Resets all axes to zero.
2431 */
2432 public void clear() {
2433 mPackedAxisBits = 0;
2434
2435 x = 0;
2436 y = 0;
2437 pressure = 0;
2438 size = 0;
2439 touchMajor = 0;
2440 touchMinor = 0;
2441 toolMajor = 0;
2442 toolMinor = 0;
2443 orientation = 0;
Jeff Brownc5ed5912010-07-14 18:48:53 -07002444 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08002445
2446 /**
2447 * Copies the contents of another pointer coords object.
2448 *
2449 * @param other The pointer coords object to copy.
2450 */
2451 public void copyFrom(PointerCoords other) {
Jeff Brown6f2fba42011-02-19 01:08:02 -08002452 final long bits = other.mPackedAxisBits;
Jeff Brown91c69ab2011-02-14 17:03:18 -08002453 mPackedAxisBits = bits;
2454 if (bits != 0) {
2455 final float[] otherValues = other.mPackedAxisValues;
Jeff Brown6f2fba42011-02-19 01:08:02 -08002456 final int count = Long.bitCount(bits);
Jeff Brown91c69ab2011-02-14 17:03:18 -08002457 float[] values = mPackedAxisValues;
2458 if (values == null || count > values.length) {
2459 values = new float[otherValues.length];
2460 mPackedAxisValues = values;
2461 }
2462 System.arraycopy(otherValues, 0, values, 0, count);
2463 }
2464
2465 x = other.x;
2466 y = other.y;
2467 pressure = other.pressure;
2468 size = other.size;
2469 touchMajor = other.touchMajor;
2470 touchMinor = other.touchMinor;
2471 toolMajor = other.toolMajor;
2472 toolMinor = other.toolMinor;
2473 orientation = other.orientation;
Jeff Brownc5ed5912010-07-14 18:48:53 -07002474 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08002475
2476 /**
2477 * Gets the value associated with the specified axis.
2478 *
2479 * @param axis The axis identifier for the axis value to retrieve.
2480 * @return The value associated with the axis, or 0 if none.
2481 *
2482 * @see MotionEvent#AXIS_X
2483 * @see MotionEvent#AXIS_Y
2484 */
2485 public float getAxisValue(int axis) {
2486 switch (axis) {
2487 case AXIS_X:
2488 return x;
2489 case AXIS_Y:
2490 return y;
2491 case AXIS_PRESSURE:
2492 return pressure;
2493 case AXIS_SIZE:
2494 return size;
2495 case AXIS_TOUCH_MAJOR:
2496 return touchMajor;
2497 case AXIS_TOUCH_MINOR:
2498 return touchMinor;
2499 case AXIS_TOOL_MAJOR:
2500 return toolMajor;
2501 case AXIS_TOOL_MINOR:
2502 return toolMinor;
2503 case AXIS_ORIENTATION:
2504 return orientation;
2505 default: {
Jeff Brown6f2fba42011-02-19 01:08:02 -08002506 if (axis < 0 || axis > 63) {
2507 throw new IllegalArgumentException("Axis out of range.");
2508 }
2509 final long bits = mPackedAxisBits;
2510 final long axisBit = 1L << axis;
Jeff Brown91c69ab2011-02-14 17:03:18 -08002511 if ((bits & axisBit) == 0) {
2512 return 0;
2513 }
Jeff Brown6f2fba42011-02-19 01:08:02 -08002514 final int index = Long.bitCount(bits & (axisBit - 1L));
Jeff Brown91c69ab2011-02-14 17:03:18 -08002515 return mPackedAxisValues[index];
2516 }
2517 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002518 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08002519
2520 /**
2521 * Sets the value associated with the specified axis.
2522 *
2523 * @param axis The axis identifier for the axis value to assign.
2524 * @param value The value to set.
2525 *
2526 * @see MotionEvent#AXIS_X
2527 * @see MotionEvent#AXIS_Y
2528 */
2529 public void setAxisValue(int axis, float value) {
2530 switch (axis) {
2531 case AXIS_X:
2532 x = value;
2533 break;
2534 case AXIS_Y:
2535 y = value;
2536 break;
2537 case AXIS_PRESSURE:
2538 pressure = value;
2539 break;
2540 case AXIS_SIZE:
2541 size = value;
2542 break;
2543 case AXIS_TOUCH_MAJOR:
2544 touchMajor = value;
2545 break;
2546 case AXIS_TOUCH_MINOR:
2547 touchMinor = value;
2548 break;
2549 case AXIS_TOOL_MAJOR:
2550 toolMajor = value;
2551 break;
2552 case AXIS_TOOL_MINOR:
2553 toolMinor = value;
2554 break;
2555 case AXIS_ORIENTATION:
2556 orientation = value;
2557 break;
2558 default: {
Jeff Brown6f2fba42011-02-19 01:08:02 -08002559 if (axis < 0 || axis > 63) {
2560 throw new IllegalArgumentException("Axis out of range.");
2561 }
2562 final long bits = mPackedAxisBits;
2563 final long axisBit = 1L << axis;
2564 final int index = Long.bitCount(bits & (axisBit - 1L));
Jeff Brown91c69ab2011-02-14 17:03:18 -08002565 float[] values = mPackedAxisValues;
2566 if ((bits & axisBit) == 0) {
2567 if (values == null) {
2568 values = new float[INITIAL_PACKED_AXIS_VALUES];
2569 mPackedAxisValues = values;
2570 } else {
Jeff Brown6f2fba42011-02-19 01:08:02 -08002571 final int count = Long.bitCount(bits);
Jeff Brown91c69ab2011-02-14 17:03:18 -08002572 if (count < values.length) {
2573 if (index != count) {
2574 System.arraycopy(values, index, values, index + 1,
2575 count - index);
2576 }
2577 } else {
2578 float[] newValues = new float[count * 2];
2579 System.arraycopy(values, 0, newValues, 0, index);
2580 System.arraycopy(values, index, newValues, index + 1,
2581 count - index);
2582 values = newValues;
2583 mPackedAxisValues = values;
2584 }
2585 }
2586 mPackedAxisBits = bits | axisBit;
2587 }
2588 values[index] = value;
2589 }
2590 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002591 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002592 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002593}