blob: 6673be2bbd3cb5af769d9a9e8b44bfe64040cba2 [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;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023
24/**
25 * Object used to report movement (mouse, pen, finger, trackball) events. This
26 * class may hold either absolute or relative movements, depending on what
27 * it is being used for.
Jeff Browndc1ab4b2010-09-14 18:03:38 -070028 * <p>
Jeff Browncb1404e2011-01-15 18:14:15 -080029 * On pointing devices with source class {@link InputDevice#SOURCE_CLASS_POINTER}
30 * such as touch screens, the pointer coordinates specify absolute
Jeff Browndc1ab4b2010-09-14 18:03:38 -070031 * positions such as view X/Y coordinates. Each complete gesture is represented
32 * by a sequence of motion events with actions that describe pointer state transitions
33 * and movements. A gesture starts with a motion event with {@link #ACTION_DOWN}
34 * that provides the location of the first pointer down. As each additional
35 * pointer that goes down or up, the framework will generate a motion event with
36 * {@link #ACTION_POINTER_DOWN} or {@link #ACTION_POINTER_UP} accordingly.
37 * Pointer movements are described by motion events with {@link #ACTION_MOVE}.
38 * Finally, a gesture end either when the final pointer goes up as represented
39 * by a motion event with {@link #ACTION_UP} or when gesture is canceled
40 * with {@link #ACTION_CANCEL}.
41 * </p><p>
Jeff Browncb1404e2011-01-15 18:14:15 -080042 * On trackball devices with source class {@link InputDevice#SOURCE_CLASS_TRACKBALL},
43 * the pointer coordinates specify relative movements as X/Y deltas.
Jeff Browndc1ab4b2010-09-14 18:03:38 -070044 * A trackball gesture consists of a sequence of movements described by motion
45 * events with {@link #ACTION_MOVE} interspersed with occasional {@link #ACTION_DOWN}
46 * or {@link #ACTION_UP} motion events when the trackball button is pressed or released.
47 * </p><p>
Jeff Browncb1404e2011-01-15 18:14:15 -080048 * On joystick devices with source class {@link InputDevice#SOURCE_CLASS_JOYSTICK},
49 * the pointer coordinates specify the absolute position of the joystick axes.
50 * The joystick axis values are normalized to a range of -1.0 to 1.0 where 0.0 corresponds
51 * to the center position. More information about the set of available axes and the
52 * range of motion can be obtained using {@link InputDevice#getMotionRange}.
53 * </p><p>
Jeff Browndc1ab4b2010-09-14 18:03:38 -070054 * Motion events always report movements for all pointers at once. The number
55 * of pointers only ever changes by one as individual pointers go up and down,
56 * except when the gesture is canceled.
57 * </p><p>
58 * The order in which individual pointers appear within a motion event can change
59 * from one event to the next. Use the {@link #getPointerId(int)} method to obtain a
60 * pointer id to track pointers across motion events in a gesture. Then for
61 * successive motion events, use the {@link #findPointerIndex(int)} method to obtain
62 * the pointer index for a given pointer id in that motion event.
63 * </p><p>
64 * For efficiency, motion events with {@link #ACTION_MOVE} may batch together
65 * multiple movement samples within a single object. The most current
66 * pointer coordinates are available using {@link #getX(int)} and {@link #getY(int)}.
67 * Earlier coordinates within the batch are accessed using {@link #getHistoricalX(int, int)}
68 * and {@link #getHistoricalY(int, int)}. The coordinates are "historical" only
69 * insofar as they are older than the current coordinates in the batch; however,
70 * they are still distinct from any other coordinates reported in prior motion events.
71 * To process all coordinates in the batch in time order, first consume the historical
72 * coordinates then consume the current coordinates.
73 * </p><p>
74 * Example: Consuming all samples for all pointers in a motion event in time order.
75 * </p><p><pre><code>
76 * void printSamples(MotionEvent ev) {
77 * final int historySize = ev.getHistorySize();
78 * final int pointerCount = ev.getPointerCount();
79 * for (int h = 0; h &lt; historySize; h++) {
80 * System.out.printf("At time %d:", ev.getHistoricalEventTime(h));
81 * for (int p = 0; p &lt; pointerCount; p++) {
82 * System.out.printf(" pointer %d: (%f,%f)",
83 * ev.getPointerId(p), ev.getHistoricalX(p, h), ev.getHistoricalY(p, h));
84 * }
85 * }
86 * System.out.printf("At time %d:", ev.getEventTime());
87 * for (int p = 0; p &lt; pointerCount; p++) {
88 * System.out.printf(" pointer %d: (%f,%f)",
89 * ev.getPointerId(p), ev.getX(p), ev.getY(p));
90 * }
91 * }
92 * </code></pre></p><p>
Jeff Brownb6997262010-10-08 22:31:17 -070093 * In general, the framework cannot guarantee that the motion events it delivers
94 * to a view always constitute a complete motion sequences since some events may be dropped
95 * or modified by containing views before they are delivered. The view implementation
96 * should be prepared to handle {@link #ACTION_CANCEL} and should tolerate anomalous
97 * situations such as receiving a new {@link #ACTION_DOWN} without first having
98 * received an {@link #ACTION_UP} for the prior gesture.
Jeff Browndc1ab4b2010-09-14 18:03:38 -070099 * </p><p>
100 * Refer to {@link InputDevice} for more information about how different kinds of
Jeff Brownc5ed5912010-07-14 18:48:53 -0700101 * input devices and sources represent pointer coordinates.
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700102 * </p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800103 */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700104public final class MotionEvent extends InputEvent implements Parcelable {
Jeff Brown91c69ab2011-02-14 17:03:18 -0800105 private static final long NS_PER_MS = 1000000;
Jeff Brown85a31762010-09-01 17:01:00 -0700106 private static final boolean TRACK_RECYCLED_LOCATION = false;
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700107
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800108 /**
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700109 * Bit mask of the parts of the action code that are the action itself.
110 */
111 public static final int ACTION_MASK = 0xff;
112
113 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800114 * Constant for {@link #getAction}: A pressed gesture has started, the
115 * motion contains the initial starting location.
116 */
117 public static final int ACTION_DOWN = 0;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700118
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800119 /**
120 * Constant for {@link #getAction}: A pressed gesture has finished, the
121 * motion contains the final release location as well as any intermediate
122 * points since the last down or move event.
123 */
124 public static final int ACTION_UP = 1;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700125
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800126 /**
127 * Constant for {@link #getAction}: A change has happened during a
128 * press gesture (between {@link #ACTION_DOWN} and {@link #ACTION_UP}).
129 * The motion contains the most recent point, as well as any intermediate
130 * points since the last down or move event.
131 */
132 public static final int ACTION_MOVE = 2;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700133
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800134 /**
135 * Constant for {@link #getAction}: The current gesture has been aborted.
136 * You will not receive any more points in it. You should treat this as
137 * an up event, but not perform any action that you normally would.
138 */
139 public static final int ACTION_CANCEL = 3;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700140
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800141 /**
142 * Constant for {@link #getAction}: A movement has happened outside of the
143 * normal bounds of the UI element. This does not provide a full gesture,
144 * but only the initial location of the movement/touch.
145 */
146 public static final int ACTION_OUTSIDE = 4;
147
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700148 /**
149 * A non-primary pointer has gone down. The bits in
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700150 * {@link #ACTION_POINTER_ID_MASK} indicate which pointer changed.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700151 */
152 public static final int ACTION_POINTER_DOWN = 5;
153
154 /**
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700155 * A non-primary pointer has gone up. The bits in
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700156 * {@link #ACTION_POINTER_ID_MASK} indicate which pointer changed.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700157 */
158 public static final int ACTION_POINTER_UP = 6;
159
160 /**
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800161 * Bits in the action code that represent a pointer index, used with
162 * {@link #ACTION_POINTER_DOWN} and {@link #ACTION_POINTER_UP}. Shifting
163 * down by {@link #ACTION_POINTER_INDEX_SHIFT} provides the actual pointer
164 * index where the data for the pointer going up or down can be found; you can
165 * get its identifier with {@link #getPointerId(int)} and the actual
166 * data with {@link #getX(int)} etc.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700167 */
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800168 public static final int ACTION_POINTER_INDEX_MASK = 0xff00;
169
170 /**
171 * Bit shift for the action bits holding the pointer index as
172 * defined by {@link #ACTION_POINTER_INDEX_MASK}.
173 */
174 public static final int ACTION_POINTER_INDEX_SHIFT = 8;
175
176 /**
177 * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the
178 * data index associated with {@link #ACTION_POINTER_DOWN}.
179 */
180 @Deprecated
181 public static final int ACTION_POINTER_1_DOWN = ACTION_POINTER_DOWN | 0x0000;
182
183 /**
184 * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the
185 * data index associated with {@link #ACTION_POINTER_DOWN}.
186 */
187 @Deprecated
188 public static final int ACTION_POINTER_2_DOWN = ACTION_POINTER_DOWN | 0x0100;
189
190 /**
191 * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the
192 * data index associated with {@link #ACTION_POINTER_DOWN}.
193 */
194 @Deprecated
195 public static final int ACTION_POINTER_3_DOWN = ACTION_POINTER_DOWN | 0x0200;
196
197 /**
198 * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the
199 * data index associated with {@link #ACTION_POINTER_UP}.
200 */
201 @Deprecated
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700202 public static final int ACTION_POINTER_1_UP = ACTION_POINTER_UP | 0x0000;
203
204 /**
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800205 * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the
206 * data index associated with {@link #ACTION_POINTER_UP}.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700207 */
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800208 @Deprecated
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700209 public static final int ACTION_POINTER_2_UP = ACTION_POINTER_UP | 0x0100;
210
211 /**
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800212 * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the
213 * data index associated with {@link #ACTION_POINTER_UP}.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700214 */
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800215 @Deprecated
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700216 public static final int ACTION_POINTER_3_UP = ACTION_POINTER_UP | 0x0200;
217
218 /**
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800219 * @deprecated Renamed to {@link #ACTION_POINTER_INDEX_MASK} to match
220 * the actual data contained in these bits.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700221 */
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800222 @Deprecated
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700223 public static final int ACTION_POINTER_ID_MASK = 0xff00;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700224
225 /**
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800226 * @deprecated Renamed to {@link #ACTION_POINTER_INDEX_SHIFT} to match
227 * the actual data contained in these bits.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700228 */
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800229 @Deprecated
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700230 public static final int ACTION_POINTER_ID_SHIFT = 8;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700231
Jeff Brown85a31762010-09-01 17:01:00 -0700232 /**
233 * This flag indicates that the window that received this motion event is partly
234 * or wholly obscured by another visible window above it. This flag is set to true
235 * even if the event did not directly pass through the obscured area.
236 * A security sensitive application can check this flag to identify situations in which
237 * a malicious application may have covered up part of its content for the purpose
238 * of misleading the user or hijacking touches. An appropriate response might be
239 * to drop the suspect touches or to take additional precautions to confirm the user's
240 * actual intent.
241 */
242 public static final int FLAG_WINDOW_IS_OBSCURED = 0x1;
Romain Guycafdea62009-06-12 10:51:36 -0700243
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800244 /**
245 * Flag indicating the motion event intersected the top edge of the screen.
246 */
247 public static final int EDGE_TOP = 0x00000001;
Romain Guycafdea62009-06-12 10:51:36 -0700248
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800249 /**
250 * Flag indicating the motion event intersected the bottom edge of the screen.
251 */
252 public static final int EDGE_BOTTOM = 0x00000002;
Romain Guycafdea62009-06-12 10:51:36 -0700253
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800254 /**
255 * Flag indicating the motion event intersected the left edge of the screen.
256 */
257 public static final int EDGE_LEFT = 0x00000004;
Romain Guycafdea62009-06-12 10:51:36 -0700258
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800259 /**
260 * Flag indicating the motion event intersected the right edge of the screen.
261 */
262 public static final int EDGE_RIGHT = 0x00000008;
Romain Guycafdea62009-06-12 10:51:36 -0700263
Jeff Brown91c69ab2011-02-14 17:03:18 -0800264 /**
265 * Constant used to identify the X axis of a motion event.
266 *
267 * The interpretation of the X axis varies by input source.
268 * It may represent the X position of the center of the touch contact area,
269 * a relative horizontal displacement of a trackball or joystick, or something else.
270 *
271 * @see #getX(int)
272 * @see #getHistoricalX(int, int)
273 * @see MotionEvent.PointerCoords#x
274 * @see InputDevice#getMotionRange
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700275 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800276 public static final int AXIS_X = 0;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700277
Jeff Brown91c69ab2011-02-14 17:03:18 -0800278 /**
279 * Constant used to identify the Y axis of a motion event.
280 *
281 * The interpretation of the Y axis varies by input source.
282 * It may represent the Y position of the center of the touch contact area,
283 * a relative vertical displacement of a trackball or joystick, or something else.
284 *
285 * @see #getY(int)
286 * @see #getHistoricalY(int, int)
287 * @see MotionEvent.PointerCoords#y
288 * @see InputDevice#getMotionRange
Jeff Brownc5ed5912010-07-14 18:48:53 -0700289 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800290 public static final int AXIS_Y = 1;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700291
Jeff Brown91c69ab2011-02-14 17:03:18 -0800292 /**
293 * Constant used to identify the Pressure axis of a motion event.
294 *
295 * The pressure axis specifies a normalized value that describes the approximate
296 * pressure applied to the device by a finger or other tool.
297 * The pressure generally ranges from 0 (no pressure at all) to 1 (normal pressure),
298 * although values higher than 1 may be generated depending on the calibration of
299 * the input device.
300 *
301 * @see #getPressure(int)
302 * @see #getHistoricalPressure(int, int)
303 * @see MotionEvent.PointerCoords#pressure
304 * @see InputDevice#getMotionRange
Jeff Brownc5ed5912010-07-14 18:48:53 -0700305 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800306 public static final int AXIS_PRESSURE = 2;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700307
Jeff Brown91c69ab2011-02-14 17:03:18 -0800308 /**
309 * Constant used to identify the Size axis of a motion event.
310 *
311 * The size axis specifies a normalized value that describes the approximate size
312 * of the pointer touch area in relation to the maximum detectable size for the device.
313 * It represents some approximation of the area of the screen being
314 * pressed; the actual value in pixels corresponding to the
315 * touch is normalized with the device specific range of values
316 * and scaled to a value between 0 and 1. The value of size can be used to
317 * determine fat touch events.
318 *
319 * To obtain calibrated size information in terms of pixels, use
320 * {@link #AXIS_TOUCH_MAJOR} or {@link #AXIS_TOOL_MAJOR} instead.
321 *
322 * @see #getSize(int)
323 * @see #getHistoricalSize(int, int)
324 * @see MotionEvent.PointerCoords#size
325 * @see InputDevice#getMotionRange
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700326 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800327 public static final int AXIS_SIZE = 3;
328
329 /**
330 * Constant used to identify the TouchMajor axis of a motion event.
331 *
332 * The touch major axis specifies the length of the major axis of an ellipse that
333 * describes the touch area at the point of contact.
334 * If the device is a touch screen, the length is reported in pixels, otherwise it is
335 * reported in device-specific units.
336 *
337 * @see #getTouchMajor(int)
338 * @see #getHistoricalTouchMajor(int, int)
339 * @see MotionEvent.PointerCoords#touchMajor
340 * @see InputDevice#getMotionRange
Dianne Hackborn1e8dfc72009-08-06 12:43:01 -0700341 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800342 public static final int AXIS_TOUCH_MAJOR = 4;
343
344 /**
345 * Constant used to identify the TouchMinor axis of a motion event.
346 *
347 * The touch major axis specifies the length of the minor axis of an ellipse that
348 * describes the touch area at the point of contact.
349 * If the device is a touch screen, the length is reported in pixels, otherwise it is
350 * reported in device-specific units.
351 *
352 * @see #getTouchMinor(int)
353 * @see #getHistoricalTouchMinor(int, int)
354 * @see MotionEvent.PointerCoords#touchMinor
355 * @see InputDevice#getMotionRange
Jeff Brown9e2ad362010-07-30 19:20:11 -0700356 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800357 public static final int AXIS_TOUCH_MINOR = 5;
358
359 /**
360 * Constant used to identify the ToolMajor axis of a motion event.
361 *
362 * The tool major axis specifies the length of the major axis of an ellipse that
363 * describes the size of the approaching tool.
364 * The tool area represents the estimated size of the finger or pen that is
365 * touching the device independent of its actual touch area at the point of contact.
366 * If the device is a touch screen, the length is reported in pixels, otherwise it is
367 * reported in device-specific units.
368 *
369 * @see #getToolMajor(int)
370 * @see #getHistoricalToolMajor(int, int)
371 * @see MotionEvent.PointerCoords#toolMajor
372 * @see InputDevice#getMotionRange
373 */
374 public static final int AXIS_TOOL_MAJOR = 6;
375
376 /**
377 * Constant used to identify the ToolMinor axis of a motion event.
378 *
379 * The tool minor axis specifies the length of the major axis of an ellipse that
380 * describes the size of the approaching tool.
381 * The tool area represents the estimated size of the finger or pen that is
382 * touching the device independent of its actual touch area at the point of contact.
383 * If the device is a touch screen, the length is reported in pixels, otherwise it is
384 * reported in device-specific units.
385 *
386 * @see #getToolMinor(int)
387 * @see #getHistoricalToolMinor(int, int)
388 * @see MotionEvent.PointerCoords#toolMinor
389 * @see InputDevice#getMotionRange
390 */
391 public static final int AXIS_TOOL_MINOR = 7;
392
393 /**
394 * Constant used to identify the Orientation axis of a motion event.
395 *
396 * The orientation axis specifies the orientation of the touch area and tool area in
397 * radians clockwise from vertical relative to the vertical plane of the device.
398 * An angle of 0 degrees indicates that the major axis of contact is oriented
399 * upwards, is perfectly circular or is of unknown orientation. A positive angle
400 * indicates that the major axis of contact is oriented to the right. A negative angle
401 * indicates that the major axis of contact is oriented to the left.
402 * The full range is from -PI/2 radians (finger pointing fully left) to PI/2 radians
403 * (finger pointing fully right).
404 *
405 * @see #getOrientation(int)
406 * @see #getHistoricalOrientation(int, int)
407 * @see MotionEvent.PointerCoords#orientation
408 * @see InputDevice#getMotionRange
409 */
410 public static final int AXIS_ORIENTATION = 8;
411
412 // Private value for history pos that obtains the current sample.
413 private static final int HISTORY_CURRENT = -0x80000000;
414
Jeff Brown1f245102010-11-18 20:53:46 -0800415 private static final int MAX_RECYCLED = 10;
416 private static final Object gRecyclerLock = new Object();
417 private static int gRecyclerUsed;
418 private static MotionEvent gRecyclerTop;
Romain Guycafdea62009-06-12 10:51:36 -0700419
Jeff Brown91c69ab2011-02-14 17:03:18 -0800420 // Shared temporary objects used when translating coordinates supplied by
421 // the caller into single element PointerCoords and pointer id arrays.
422 // Must lock gTmpPointerCoords prior to use.
423 private static final PointerCoords[] gTmpPointerCoords =
424 new PointerCoords[] { new PointerCoords() };
425 private static final int[] gTmpPointerIds = new int[] { 0 /*always 0*/ };
426
427 // Pointer to the native MotionEvent object that contains the actual data.
428 private int mNativePtr;
Mitsuru Oshima8169dae2009-04-28 18:12:09 -0700429
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800430 private MotionEvent mNext;
431 private RuntimeException mRecycledLocation;
432 private boolean mRecycled;
433
Jeff Brown91c69ab2011-02-14 17:03:18 -0800434 private static native int nativeInitialize(int nativePtr,
435 int deviceId, int source, int action, int flags, int edgeFlags, int metaState,
436 float xOffset, float yOffset, float xPrecision, float yPrecision,
437 long downTimeNanos, long eventTimeNanos,
438 int pointerCount, int[] pointerIds, PointerCoords[] pointerCoords);
439 private static native int nativeCopy(int destNativePtr, int sourceNativePtr,
440 boolean keepHistory);
441 private static native void nativeDispose(int nativePtr);
442 private static native void nativeAddBatch(int nativePtr, long eventTimeNanos,
443 PointerCoords[] pointerCoords, int metaState);
Jeff Brown20e987b2010-08-23 12:01:02 -0700444
Jeff Brown91c69ab2011-02-14 17:03:18 -0800445 private static native int nativeGetDeviceId(int nativePtr);
446 private static native int nativeGetSource(int nativePtr);
447 private static native int nativeSetSource(int nativePtr, int source);
448 private static native int nativeGetAction(int nativePtr);
449 private static native void nativeSetAction(int nativePtr, int action);
450 private static native int nativeGetFlags(int nativePtr);
451 private static native int nativeGetEdgeFlags(int nativePtr);
452 private static native void nativeSetEdgeFlags(int nativePtr, int action);
453 private static native int nativeGetMetaState(int nativePtr);
454 private static native void nativeOffsetLocation(int nativePtr, float deltaX, float deltaY);
455 private static native float nativeGetXPrecision(int nativePtr);
456 private static native float nativeGetYPrecision(int nativePtr);
457 private static native long nativeGetDownTimeNanos(int nativePtr);
458
459 private static native int nativeGetPointerCount(int nativePtr);
460 private static native int nativeGetPointerId(int nativePtr, int pointerIndex);
461 private static native int nativeFindPointerIndex(int nativePtr, int pointerId);
462
463 private static native int nativeGetHistorySize(int nativePtr);
464 private static native long nativeGetEventTimeNanos(int nativePtr, int historyPos);
465 private static native float nativeGetRawAxisValue(int nativePtr,
466 int axis, int pointerIndex, int historyPos);
467 private static native float nativeGetAxisValue(int nativePtr,
468 int axis, int pointerIndex, int historyPos);
469 private static native void nativeGetPointerCoords(int nativePtr,
470 int pointerIndex, int historyPos, PointerCoords outPointerCoords);
471
472 private static native void nativeScale(int nativePtr, float scale);
473 private static native void nativeTransform(int nativePtr, Matrix matrix);
474
475 private static native int nativeReadFromParcel(int nativePtr, Parcel parcel);
476 private static native void nativeWriteToParcel(int nativePtr, Parcel parcel);
477
478 private MotionEvent() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800479 }
Romain Guycafdea62009-06-12 10:51:36 -0700480
Jeff Brown91c69ab2011-02-14 17:03:18 -0800481 @Override
482 protected void finalize() throws Throwable {
483 try {
484 if (mNativePtr != 0) {
485 nativeDispose(mNativePtr);
486 mNativePtr = 0;
487 }
488 } finally {
489 super.finalize();
490 }
491 }
492
493 static private MotionEvent obtain() {
Jeff Brown46b9ac02010-04-22 18:58:52 -0700494 final MotionEvent ev;
495 synchronized (gRecyclerLock) {
Jeff Brown1f245102010-11-18 20:53:46 -0800496 ev = gRecyclerTop;
497 if (ev == null) {
Jeff Brown91c69ab2011-02-14 17:03:18 -0800498 return new MotionEvent();
Jeff Brown46b9ac02010-04-22 18:58:52 -0700499 }
Jeff Brown46b9ac02010-04-22 18:58:52 -0700500 gRecyclerTop = ev.mNext;
Jeff Brown5c225b12010-06-16 01:53:36 -0700501 gRecyclerUsed -= 1;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700502 }
503 ev.mRecycledLocation = null;
504 ev.mRecycled = false;
505 ev.mNext = null;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700506 return ev;
507 }
Jeff Brown91c69ab2011-02-14 17:03:18 -0800508
Michael Chan53071d62009-05-13 17:29:48 -0700509 /**
510 * Create a new MotionEvent, filling in all of the basic values that
511 * define the motion.
512 *
513 * @param downTime The time (in ms) when the user originally pressed down to start
514 * a stream of position events. This must be obtained from {@link SystemClock#uptimeMillis()}.
Jeff Brownc5ed5912010-07-14 18:48:53 -0700515 * @param eventTime The the time (in ms) when this specific event was generated. This
Michael Chan53071d62009-05-13 17:29:48 -0700516 * must be obtained from {@link SystemClock#uptimeMillis()}.
Michael Chan53071d62009-05-13 17:29:48 -0700517 * @param action The kind of action being performed -- one of either
518 * {@link #ACTION_DOWN}, {@link #ACTION_MOVE}, {@link #ACTION_UP}, or
519 * {@link #ACTION_CANCEL}.
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700520 * @param pointers The number of points that will be in this event.
Jeff Brownc5ed5912010-07-14 18:48:53 -0700521 * @param pointerIds An array of <em>pointers</em> values providing
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700522 * an identifier for each pointer.
Jeff Brownc5ed5912010-07-14 18:48:53 -0700523 * @param pointerCoords An array of <em>pointers</em> values providing
524 * a {@link PointerCoords} coordinate object for each pointer.
Michael Chan53071d62009-05-13 17:29:48 -0700525 * @param metaState The state of any meta / modifier keys that were in effect when
526 * the event was generated.
527 * @param xPrecision The precision of the X coordinate being reported.
528 * @param yPrecision The precision of the Y coordinate being reported.
529 * @param deviceId The id for the device that this event came from. An id of
530 * zero indicates that the event didn't come from a physical device; other
531 * numbers are arbitrary and you shouldn't depend on the values.
Jeff Brown85a31762010-09-01 17:01:00 -0700532 * @param edgeFlags A bitfield indicating which edges, if any, were touched by this
Michael Chan53071d62009-05-13 17:29:48 -0700533 * MotionEvent.
Jeff Brownc5ed5912010-07-14 18:48:53 -0700534 * @param source The source of this event.
Jeff Brown85a31762010-09-01 17:01:00 -0700535 * @param flags The motion event flags.
Michael Chan53071d62009-05-13 17:29:48 -0700536 */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700537 static public MotionEvent obtain(long downTime, long eventTime,
538 int action, int pointers, int[] pointerIds, PointerCoords[] pointerCoords,
539 int metaState, float xPrecision, float yPrecision, int deviceId,
Jeff Brown85a31762010-09-01 17:01:00 -0700540 int edgeFlags, int source, int flags) {
Jeff Brown91c69ab2011-02-14 17:03:18 -0800541 MotionEvent ev = obtain();
542 ev.mNativePtr = nativeInitialize(ev.mNativePtr,
543 deviceId, source, action, flags, edgeFlags, metaState,
544 0, 0, xPrecision, yPrecision,
545 downTime * NS_PER_MS, eventTime * NS_PER_MS,
546 pointers, pointerIds, pointerCoords);
Michael Chan53071d62009-05-13 17:29:48 -0700547 return ev;
548 }
Jeff Brown91c69ab2011-02-14 17:03:18 -0800549
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800550 /**
551 * Create a new MotionEvent, filling in all of the basic values that
552 * define the motion.
Romain Guycafdea62009-06-12 10:51:36 -0700553 *
554 * @param downTime The time (in ms) when the user originally pressed down to start
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800555 * a stream of position events. This must be obtained from {@link SystemClock#uptimeMillis()}.
Romain Guycafdea62009-06-12 10:51:36 -0700556 * @param eventTime The the time (in ms) when this specific event was generated. This
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800557 * must be obtained from {@link SystemClock#uptimeMillis()}.
558 * @param action The kind of action being performed -- one of either
559 * {@link #ACTION_DOWN}, {@link #ACTION_MOVE}, {@link #ACTION_UP}, or
560 * {@link #ACTION_CANCEL}.
561 * @param x The X coordinate of this event.
562 * @param y The Y coordinate of this event.
Romain Guycafdea62009-06-12 10:51:36 -0700563 * @param pressure The current pressure of this event. The pressure generally
564 * ranges from 0 (no pressure at all) to 1 (normal pressure), however
565 * values higher than 1 may be generated depending on the calibration of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800566 * the input device.
567 * @param size A scaled value of the approximate size of the area being pressed when
Romain Guycafdea62009-06-12 10:51:36 -0700568 * touched with the finger. The actual value in pixels corresponding to the finger
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800569 * touch is normalized with a device specific range of values
570 * and scaled to a value between 0 and 1.
571 * @param metaState The state of any meta / modifier keys that were in effect when
572 * the event was generated.
573 * @param xPrecision The precision of the X coordinate being reported.
574 * @param yPrecision The precision of the Y coordinate being reported.
575 * @param deviceId The id for the device that this event came from. An id of
576 * zero indicates that the event didn't come from a physical device; other
577 * numbers are arbitrary and you shouldn't depend on the values.
Jeff Brown85a31762010-09-01 17:01:00 -0700578 * @param edgeFlags A bitfield indicating which edges, if any, were touched by this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800579 * MotionEvent.
580 */
581 static public MotionEvent obtain(long downTime, long eventTime, int action,
582 float x, float y, float pressure, float size, int metaState,
583 float xPrecision, float yPrecision, int deviceId, int edgeFlags) {
Jeff Brown91c69ab2011-02-14 17:03:18 -0800584 synchronized (gTmpPointerCoords) {
585 final PointerCoords pc = gTmpPointerCoords[0];
586 pc.clear();
587 pc.x = x;
588 pc.y = y;
589 pc.pressure = pressure;
590 pc.size = size;
591
592 MotionEvent ev = obtain();
593 ev.mNativePtr = nativeInitialize(ev.mNativePtr,
594 deviceId, InputDevice.SOURCE_UNKNOWN, action, 0, edgeFlags, metaState,
595 0, 0, xPrecision, yPrecision,
596 downTime * NS_PER_MS, eventTime * NS_PER_MS,
597 1, gTmpPointerIds, gTmpPointerCoords);
598 return ev;
599 }
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700600 }
601
602 /**
603 * Create a new MotionEvent, filling in all of the basic values that
604 * define the motion.
605 *
606 * @param downTime The time (in ms) when the user originally pressed down to start
607 * a stream of position events. This must be obtained from {@link SystemClock#uptimeMillis()}.
608 * @param eventTime The the time (in ms) when this specific event was generated. This
609 * must be obtained from {@link SystemClock#uptimeMillis()}.
610 * @param action The kind of action being performed -- one of either
611 * {@link #ACTION_DOWN}, {@link #ACTION_MOVE}, {@link #ACTION_UP}, or
612 * {@link #ACTION_CANCEL}.
613 * @param pointers The number of pointers that are active in this event.
614 * @param x The X coordinate of this event.
615 * @param y The Y coordinate of this event.
616 * @param pressure The current pressure of this event. The pressure generally
617 * ranges from 0 (no pressure at all) to 1 (normal pressure), however
618 * values higher than 1 may be generated depending on the calibration of
619 * the input device.
620 * @param size A scaled value of the approximate size of the area being pressed when
621 * touched with the finger. The actual value in pixels corresponding to the finger
622 * touch is normalized with a device specific range of values
623 * and scaled to a value between 0 and 1.
624 * @param metaState The state of any meta / modifier keys that were in effect when
625 * the event was generated.
626 * @param xPrecision The precision of the X coordinate being reported.
627 * @param yPrecision The precision of the Y coordinate being reported.
628 * @param deviceId The id for the device that this event came from. An id of
629 * zero indicates that the event didn't come from a physical device; other
630 * numbers are arbitrary and you shouldn't depend on the values.
Jeff Brown85a31762010-09-01 17:01:00 -0700631 * @param edgeFlags A bitfield indicating which edges, if any, were touched by this
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700632 * MotionEvent.
Jeff Brown5c225b12010-06-16 01:53:36 -0700633 *
634 * @deprecated Use {@link #obtain(long, long, int, float, float, float, float, int, float, float, int, int)}
635 * instead.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700636 */
Jeff Brown5c225b12010-06-16 01:53:36 -0700637 @Deprecated
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700638 static public MotionEvent obtain(long downTime, long eventTime, int action,
639 int pointers, float x, float y, float pressure, float size, int metaState,
640 float xPrecision, float yPrecision, int deviceId, int edgeFlags) {
Jeff Brown5c225b12010-06-16 01:53:36 -0700641 return obtain(downTime, eventTime, action, x, y, pressure, size,
642 metaState, xPrecision, yPrecision, deviceId, edgeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800643 }
Romain Guycafdea62009-06-12 10:51:36 -0700644
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800645 /**
646 * Create a new MotionEvent, filling in a subset of the basic motion
647 * values. Those not specified here are: device id (always 0), pressure
648 * and size (always 1), x and y precision (always 1), and edgeFlags (always 0).
Romain Guycafdea62009-06-12 10:51:36 -0700649 *
650 * @param downTime The time (in ms) when the user originally pressed down to start
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800651 * a stream of position events. This must be obtained from {@link SystemClock#uptimeMillis()}.
Romain Guycafdea62009-06-12 10:51:36 -0700652 * @param eventTime The the time (in ms) when this specific event was generated. This
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800653 * must be obtained from {@link SystemClock#uptimeMillis()}.
654 * @param action The kind of action being performed -- one of either
655 * {@link #ACTION_DOWN}, {@link #ACTION_MOVE}, {@link #ACTION_UP}, or
656 * {@link #ACTION_CANCEL}.
657 * @param x The X coordinate of this event.
658 * @param y The Y coordinate of this event.
659 * @param metaState The state of any meta / modifier keys that were in effect when
660 * the event was generated.
661 */
662 static public MotionEvent obtain(long downTime, long eventTime, int action,
663 float x, float y, int metaState) {
Jeff Brown5c225b12010-06-16 01:53:36 -0700664 return obtain(downTime, eventTime, action, x, y, 1.0f, 1.0f,
665 metaState, 1.0f, 1.0f, 0, 0);
Mitsuru Oshima8169dae2009-04-28 18:12:09 -0700666 }
667
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800668 /**
669 * Create a new MotionEvent, copying from an existing one.
670 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800671 static public MotionEvent obtain(MotionEvent other) {
672 if (other == null) {
673 throw new IllegalArgumentException("other motion event must not be null");
674 }
675
676 MotionEvent ev = obtain();
677 ev.mNativePtr = nativeCopy(ev.mNativePtr, other.mNativePtr, true /*keepHistory*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800678 return ev;
679 }
Romain Guycafdea62009-06-12 10:51:36 -0700680
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800681 /**
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -0700682 * Create a new MotionEvent, copying from an existing one, but not including
683 * any historical point information.
684 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800685 static public MotionEvent obtainNoHistory(MotionEvent other) {
686 if (other == null) {
687 throw new IllegalArgumentException("other motion event must not be null");
688 }
689
690 MotionEvent ev = obtain();
691 ev.mNativePtr = nativeCopy(ev.mNativePtr, other.mNativePtr, false /*keepHistory*/);
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -0700692 return ev;
693 }
694
695 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800696 * Recycle the MotionEvent, to be re-used by a later caller. After calling
697 * this function you must not ever touch the event again.
698 */
Jeff Brown5c225b12010-06-16 01:53:36 -0700699 public final void recycle() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800700 // Ensure recycle is only called once!
701 if (TRACK_RECYCLED_LOCATION) {
702 if (mRecycledLocation != null) {
703 throw new RuntimeException(toString() + " recycled twice!", mRecycledLocation);
704 }
705 mRecycledLocation = new RuntimeException("Last recycled here");
Jeff Brownd28f4be2010-06-02 15:35:46 -0700706 //Log.w("MotionEvent", "Recycling event " + this, mRecycledLocation);
707 } else {
708 if (mRecycled) {
709 throw new RuntimeException(toString() + " recycled twice!");
710 }
711 mRecycled = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800712 }
713
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800714 synchronized (gRecyclerLock) {
715 if (gRecyclerUsed < MAX_RECYCLED) {
716 gRecyclerUsed++;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800717 mNext = gRecyclerTop;
718 gRecyclerTop = this;
719 }
720 }
721 }
Jeff Brown5c225b12010-06-16 01:53:36 -0700722
723 /**
724 * Scales down the coordination of this event by the given scale.
725 *
726 * @hide
727 */
728 public final void scale(float scale) {
Jeff Brown91c69ab2011-02-14 17:03:18 -0800729 nativeScale(mNativePtr, scale);
730 }
731
732 /** {@inheritDoc} */
733 @Override
734 public final int getDeviceId() {
735 return nativeGetDeviceId(mNativePtr);
736 }
737
738 /** {@inheritDoc} */
739 @Override
740 public final int getSource() {
741 return nativeGetSource(mNativePtr);
742 }
743
744 /** {@inheritDoc} */
745 @Override
746 public final void setSource(int source) {
747 nativeSetSource(mNativePtr, source);
Jeff Brown5c225b12010-06-16 01:53:36 -0700748 }
Romain Guycafdea62009-06-12 10:51:36 -0700749
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800750 /**
751 * Return the kind of action being performed -- one of either
752 * {@link #ACTION_DOWN}, {@link #ACTION_MOVE}, {@link #ACTION_UP}, or
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800753 * {@link #ACTION_CANCEL}. Consider using {@link #getActionMasked}
754 * and {@link #getActionIndex} to retrieve the separate masked action
755 * and pointer index.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800756 */
757 public final int getAction() {
Jeff Brown91c69ab2011-02-14 17:03:18 -0800758 return nativeGetAction(mNativePtr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800759 }
760
761 /**
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800762 * Return the masked action being performed, without pointer index
763 * information. May be any of the actions: {@link #ACTION_DOWN},
764 * {@link #ACTION_MOVE}, {@link #ACTION_UP}, {@link #ACTION_CANCEL},
765 * {@link #ACTION_POINTER_DOWN}, or {@link #ACTION_POINTER_UP}.
766 * Use {@link #getActionIndex} to return the index associated with
767 * pointer actions.
768 */
769 public final int getActionMasked() {
Jeff Brown91c69ab2011-02-14 17:03:18 -0800770 return nativeGetAction(mNativePtr) & ACTION_MASK;
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800771 }
772
773 /**
774 * For {@link #ACTION_POINTER_DOWN} or {@link #ACTION_POINTER_UP}
775 * as returned by {@link #getActionMasked}, this returns the associated
776 * pointer index. The index may be used with {@link #getPointerId(int)},
777 * {@link #getX(int)}, {@link #getY(int)}, {@link #getPressure(int)},
778 * and {@link #getSize(int)} to get information about the pointer that has
779 * gone down or up.
780 */
781 public final int getActionIndex() {
Jeff Brown91c69ab2011-02-14 17:03:18 -0800782 return (nativeGetAction(mNativePtr) & ACTION_POINTER_INDEX_MASK)
783 >> ACTION_POINTER_INDEX_SHIFT;
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800784 }
785
786 /**
Jeff Brown85a31762010-09-01 17:01:00 -0700787 * Gets the motion event flags.
788 *
789 * @see #FLAG_WINDOW_IS_OBSCURED
790 */
791 public final int getFlags() {
Jeff Brown91c69ab2011-02-14 17:03:18 -0800792 return nativeGetFlags(mNativePtr);
Jeff Brown85a31762010-09-01 17:01:00 -0700793 }
794
795 /**
Romain Guycafdea62009-06-12 10:51:36 -0700796 * Returns the time (in ms) when the user originally pressed down to start
797 * a stream of position events.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800798 */
799 public final long getDownTime() {
Jeff Brown91c69ab2011-02-14 17:03:18 -0800800 return nativeGetDownTimeNanos(mNativePtr) / NS_PER_MS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800801 }
802
803 /**
804 * Returns the time (in ms) when this specific event was generated.
805 */
806 public final long getEventTime() {
Jeff Brown91c69ab2011-02-14 17:03:18 -0800807 return nativeGetEventTimeNanos(mNativePtr, HISTORY_CURRENT) / NS_PER_MS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800808 }
809
810 /**
Michael Chan53071d62009-05-13 17:29:48 -0700811 * Returns the time (in ns) when this specific event was generated.
812 * The value is in nanosecond precision but it may not have nanosecond accuracy.
813 *
814 * @hide
815 */
816 public final long getEventTimeNano() {
Jeff Brown91c69ab2011-02-14 17:03:18 -0800817 return nativeGetEventTimeNanos(mNativePtr, HISTORY_CURRENT);
Michael Chan53071d62009-05-13 17:29:48 -0700818 }
819
820 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700821 * {@link #getX(int)} for the first pointer index (may be an
822 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -0800823 *
824 * @see #AXIS_X
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700825 */
826 public final float getX() {
Jeff Brown91c69ab2011-02-14 17:03:18 -0800827 return nativeGetAxisValue(mNativePtr, AXIS_X, 0, HISTORY_CURRENT);
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700828 }
829
830 /**
831 * {@link #getY(int)} for the first pointer index (may be an
832 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -0800833 *
834 * @see #AXIS_Y
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700835 */
836 public final float getY() {
Jeff Brown91c69ab2011-02-14 17:03:18 -0800837 return nativeGetAxisValue(mNativePtr, AXIS_Y, 0, HISTORY_CURRENT);
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700838 }
839
840 /**
841 * {@link #getPressure(int)} for the first pointer index (may be an
842 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -0800843 *
844 * @see #AXIS_PRESSURE
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700845 */
846 public final float getPressure() {
Jeff Brown91c69ab2011-02-14 17:03:18 -0800847 return nativeGetAxisValue(mNativePtr, AXIS_PRESSURE, 0, HISTORY_CURRENT);
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700848 }
849
850 /**
851 * {@link #getSize(int)} for the first pointer index (may be an
852 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -0800853 *
854 * @see #AXIS_SIZE
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700855 */
856 public final float getSize() {
Jeff Brown91c69ab2011-02-14 17:03:18 -0800857 return nativeGetAxisValue(mNativePtr, AXIS_SIZE, 0, HISTORY_CURRENT);
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700858 }
Jeff Brownc5ed5912010-07-14 18:48:53 -0700859
860 /**
861 * {@link #getTouchMajor(int)} for the first pointer index (may be an
862 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -0800863 *
864 * @see #AXIS_TOUCH_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -0700865 */
866 public final float getTouchMajor() {
Jeff Brown91c69ab2011-02-14 17:03:18 -0800867 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MAJOR, 0, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -0700868 }
869
870 /**
871 * {@link #getTouchMinor(int)} for the first pointer index (may be an
872 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -0800873 *
874 * @see #AXIS_TOUCH_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -0700875 */
876 public final float getTouchMinor() {
Jeff Brown91c69ab2011-02-14 17:03:18 -0800877 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MINOR, 0, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -0700878 }
879
880 /**
881 * {@link #getToolMajor(int)} for the first pointer index (may be an
882 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -0800883 *
884 * @see #AXIS_TOOL_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -0700885 */
886 public final float getToolMajor() {
Jeff Brown91c69ab2011-02-14 17:03:18 -0800887 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MAJOR, 0, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -0700888 }
889
890 /**
891 * {@link #getToolMinor(int)} for the first pointer index (may be an
892 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -0800893 *
894 * @see #AXIS_TOOL_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -0700895 */
896 public final float getToolMinor() {
Jeff Brown91c69ab2011-02-14 17:03:18 -0800897 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MINOR, 0, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -0700898 }
Jeff Brown91c69ab2011-02-14 17:03:18 -0800899
Jeff Brownc5ed5912010-07-14 18:48:53 -0700900 /**
901 * {@link #getOrientation(int)} for the first pointer index (may be an
902 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -0800903 *
904 * @see #AXIS_ORIENTATION
Jeff Brownc5ed5912010-07-14 18:48:53 -0700905 */
906 public final float getOrientation() {
Jeff Brown91c69ab2011-02-14 17:03:18 -0800907 return nativeGetAxisValue(mNativePtr, AXIS_ORIENTATION, 0, HISTORY_CURRENT);
908 }
909
910 /**
911 * {@link #getAxisValue(int)} for the first pointer index (may be an
912 * arbitrary pointer identifier).
913 *
914 * @param axis The axis identifier for the axis value to retrieve.
915 *
916 * @see #AXIS_X
917 * @see #AXIS_Y
918 */
919 public final float getAxisValue(int axis) {
920 return nativeGetAxisValue(mNativePtr, axis, 0, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -0700921 }
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700922
923 /**
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700924 * The number of pointers of data contained in this event. Always
925 * >= 1.
926 */
927 public final int getPointerCount() {
Jeff Brown91c69ab2011-02-14 17:03:18 -0800928 return nativeGetPointerCount(mNativePtr);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700929 }
930
931 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700932 * Return the pointer identifier associated with a particular pointer
933 * data index is this event. The identifier tells you the actual pointer
934 * number associated with the data, accounting for individual pointers
935 * going up and down since the start of the current gesture.
936 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
937 * (the first pointer that is down) to {@link #getPointerCount()}-1.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800938 */
Dianne Hackbornd41ba662009-08-05 15:30:56 -0700939 public final int getPointerId(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -0800940 return nativeGetPointerId(mNativePtr, pointerIndex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800941 }
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700942
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800943 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700944 * Given a pointer identifier, find the index of its data in the event.
945 *
946 * @param pointerId The identifier of the pointer to be found.
947 * @return Returns either the index of the pointer (for use with
Gilles Debunneb0d6ba12010-08-17 20:01:42 -0700948 * {@link #getX(int)} et al.), or -1 if there is no data available for
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700949 * that pointer identifier.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800950 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700951 public final int findPointerIndex(int pointerId) {
Jeff Brown91c69ab2011-02-14 17:03:18 -0800952 return nativeFindPointerIndex(mNativePtr, pointerId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800953 }
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700954
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800955 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700956 * Returns the X coordinate of this event for the given pointer
957 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
958 * identifier for this index).
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700959 * Whole numbers are pixels; the
960 * value may have a fraction for input devices that are sub-pixel precise.
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700961 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
962 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -0800963 *
964 * @see #AXIS_X
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700965 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700966 public final float getX(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -0800967 return nativeGetAxisValue(mNativePtr, AXIS_X, pointerIndex, HISTORY_CURRENT);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700968 }
969
970 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700971 * Returns the Y coordinate of this event for the given pointer
972 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
973 * identifier for this index).
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700974 * Whole numbers are pixels; the
975 * value may have a fraction for input devices that are sub-pixel precise.
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700976 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
977 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -0800978 *
979 * @see #AXIS_Y
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700980 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700981 public final float getY(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -0800982 return nativeGetAxisValue(mNativePtr, AXIS_Y, pointerIndex, HISTORY_CURRENT);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700983 }
984
985 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700986 * Returns the current pressure of this event for the given pointer
987 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
988 * identifier for this index).
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700989 * The pressure generally
Romain Guycafdea62009-06-12 10:51:36 -0700990 * ranges from 0 (no pressure at all) to 1 (normal pressure), however
991 * values higher than 1 may be generated depending on the calibration of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800992 * the input device.
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700993 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
994 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -0800995 *
996 * @see #AXIS_PRESSURE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800997 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700998 public final float getPressure(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -0800999 return nativeGetAxisValue(mNativePtr, AXIS_PRESSURE, pointerIndex, HISTORY_CURRENT);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001000 }
1001
1002 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001003 * Returns a scaled value of the approximate size for the given pointer
1004 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
1005 * identifier for this index).
1006 * This represents some approximation of the area of the screen being
1007 * pressed; the actual value in pixels corresponding to the
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001008 * touch is normalized with the device specific range of values
Romain Guycafdea62009-06-12 10:51:36 -07001009 * 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 -08001010 * determine fat touch events.
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001011 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1012 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08001013 *
1014 * @see #AXIS_SIZE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001015 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001016 public final float getSize(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001017 return nativeGetAxisValue(mNativePtr, AXIS_SIZE, pointerIndex, HISTORY_CURRENT);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001018 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07001019
1020 /**
1021 * Returns the length of the major axis of an ellipse that describes the touch
1022 * area at the point of contact for the given pointer
1023 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
1024 * identifier for this index).
1025 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1026 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08001027 *
1028 * @see #AXIS_TOUCH_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07001029 */
1030 public final float getTouchMajor(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001031 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MAJOR, pointerIndex, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001032 }
1033
1034 /**
1035 * Returns the length of the minor axis of an ellipse that describes the touch
1036 * area at the point of contact for the given pointer
1037 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
1038 * identifier for this index).
1039 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1040 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08001041 *
1042 * @see #AXIS_TOUCH_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07001043 */
1044 public final float getTouchMinor(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001045 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MINOR, pointerIndex, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001046 }
1047
1048 /**
1049 * Returns the length of the major axis of an ellipse that describes the size of
1050 * the approaching tool for the given pointer
1051 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
1052 * identifier for this index).
1053 * The tool area represents the estimated size of the finger or pen that is
1054 * touching the device independent of its actual touch area at the point of contact.
1055 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1056 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08001057 *
1058 * @see #AXIS_TOOL_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07001059 */
1060 public final float getToolMajor(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001061 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MAJOR, pointerIndex, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001062 }
1063
1064 /**
1065 * Returns the length of the minor axis of an ellipse that describes the size of
1066 * the approaching tool for the given pointer
1067 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
1068 * identifier for this index).
1069 * The tool area represents the estimated size of the finger or pen that is
1070 * touching the device independent of its actual touch area at the point of contact.
1071 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1072 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08001073 *
1074 * @see #AXIS_TOOL_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07001075 */
1076 public final float getToolMinor(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001077 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MINOR, pointerIndex, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001078 }
1079
1080 /**
1081 * Returns the orientation of the touch area and tool area in radians clockwise from vertical
1082 * for the given pointer <em>index</em> (use {@link #getPointerId(int)} to find the pointer
1083 * identifier for this index).
1084 * An angle of 0 degrees indicates that the major axis of contact is oriented
1085 * upwards, is perfectly circular or is of unknown orientation. A positive angle
1086 * indicates that the major axis of contact is oriented to the right. A negative angle
1087 * indicates that the major axis of contact is oriented to the left.
Jeff Brown6d0fec22010-07-23 21:28:06 -07001088 * The full range is from -PI/2 radians (finger pointing fully left) to PI/2 radians
Jeff Brownc5ed5912010-07-14 18:48:53 -07001089 * (finger pointing fully right).
1090 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1091 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08001092 *
1093 * @see #AXIS_ORIENTATION
Jeff Brownc5ed5912010-07-14 18:48:53 -07001094 */
1095 public final float getOrientation(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001096 return nativeGetAxisValue(mNativePtr, AXIS_ORIENTATION, pointerIndex, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001097 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08001098
1099 /**
1100 * Returns the value of the requested axis for the given pointer <em>index</em>
1101 * (use {@link #getPointerId(int)} to find the pointer identifier for this index).
1102 *
1103 * @param axis The axis identifier for the axis value to retrieve.
1104 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1105 * (the first pointer that is down) to {@link #getPointerCount()}-1.
1106 * @return The value of the axis, or 0 if the axis is not available.
1107 *
1108 * @see #AXIS_X
1109 * @see #AXIS_Y
1110 */
1111 public final float getAxisValue(int axis, int pointerIndex) {
1112 return nativeGetAxisValue(mNativePtr, axis, pointerIndex, HISTORY_CURRENT);
1113 }
1114
Jeff Brownc5ed5912010-07-14 18:48:53 -07001115 /**
1116 * Populates a {@link PointerCoords} object with pointer coordinate data for
1117 * the specified pointer index.
1118 *
1119 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1120 * (the first pointer that is down) to {@link #getPointerCount()}-1.
1121 * @param outPointerCoords The pointer coordinate object to populate.
Jeff Brown91c69ab2011-02-14 17:03:18 -08001122 *
1123 * @see PointerCoords
Jeff Brownc5ed5912010-07-14 18:48:53 -07001124 */
1125 public final void getPointerCoords(int pointerIndex, PointerCoords outPointerCoords) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001126 nativeGetPointerCoords(mNativePtr, pointerIndex, HISTORY_CURRENT, outPointerCoords);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001127 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001128
1129 /**
1130 * Returns the state of any meta / modifier keys that were in effect when
1131 * the event was generated. This is the same values as those
1132 * returned by {@link KeyEvent#getMetaState() KeyEvent.getMetaState}.
1133 *
1134 * @return an integer in which each bit set to 1 represents a pressed
1135 * meta key
1136 *
1137 * @see KeyEvent#getMetaState()
1138 */
1139 public final int getMetaState() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001140 return nativeGetMetaState(mNativePtr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001141 }
1142
1143 /**
1144 * Returns the original raw X coordinate of this event. For touch
1145 * events on the screen, this is the original location of the event
1146 * on the screen, before it had been adjusted for the containing window
1147 * and views.
Jeff Brown91c69ab2011-02-14 17:03:18 -08001148 *
1149 * @see getX()
1150 * @see #AXIS_X
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001151 */
1152 public final float getRawX() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001153 return nativeGetRawAxisValue(mNativePtr, AXIS_X, 0, HISTORY_CURRENT);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001154 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08001155
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001156 /**
1157 * Returns the original raw Y coordinate of this event. For touch
1158 * events on the screen, this is the original location of the event
1159 * on the screen, before it had been adjusted for the containing window
1160 * and views.
Jeff Brown91c69ab2011-02-14 17:03:18 -08001161 *
1162 * @see getY()
1163 * @see #AXIS_Y
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001164 */
1165 public final float getRawY() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001166 return nativeGetRawAxisValue(mNativePtr, AXIS_Y, 0, HISTORY_CURRENT);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001167 }
1168
1169 /**
1170 * Return the precision of the X coordinates being reported. You can
Jeff Brown91c69ab2011-02-14 17:03:18 -08001171 * multiply this number with {@link #getX} to find the actual hardware
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001172 * value of the X coordinate.
1173 * @return Returns the precision of X coordinates being reported.
Jeff Brown91c69ab2011-02-14 17:03:18 -08001174 *
1175 * @see #AXIS_X
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001176 */
1177 public final float getXPrecision() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001178 return nativeGetXPrecision(mNativePtr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001179 }
Romain Guycafdea62009-06-12 10:51:36 -07001180
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001181 /**
1182 * Return the precision of the Y coordinates being reported. You can
Jeff Brown91c69ab2011-02-14 17:03:18 -08001183 * multiply this number with {@link #getY} to find the actual hardware
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001184 * value of the Y coordinate.
1185 * @return Returns the precision of Y coordinates being reported.
Jeff Brown91c69ab2011-02-14 17:03:18 -08001186 *
1187 * @see #AXIS_Y
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001188 */
1189 public final float getYPrecision() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001190 return nativeGetYPrecision(mNativePtr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001191 }
Romain Guycafdea62009-06-12 10:51:36 -07001192
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001193 /**
1194 * Returns the number of historical points in this event. These are
1195 * movements that have occurred between this event and the previous event.
1196 * This only applies to ACTION_MOVE events -- all other actions will have
1197 * a size of 0.
Romain Guycafdea62009-06-12 10:51:36 -07001198 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001199 * @return Returns the number of historical points in the event.
1200 */
1201 public final int getHistorySize() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001202 return nativeGetHistorySize(mNativePtr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001203 }
Romain Guycafdea62009-06-12 10:51:36 -07001204
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001205 /**
1206 * Returns the time that a historical movement occurred between this event
1207 * and the previous event. Only applies to ACTION_MOVE events.
Romain Guycafdea62009-06-12 10:51:36 -07001208 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001209 * @param pos Which historical value to return; must be less than
1210 * {@link #getHistorySize}
Romain Guycafdea62009-06-12 10:51:36 -07001211 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001212 * @see #getHistorySize
1213 * @see #getEventTime
1214 */
1215 public final long getHistoricalEventTime(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001216 return nativeGetEventTimeNanos(mNativePtr, pos) / NS_PER_MS;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001217 }
1218
1219 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08001220 * {@link #getHistoricalX(int, int)} for the first pointer index (may be an
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001221 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001222 *
1223 * @param pos Which historical value to return; must be less than
1224 * {@link #getHistorySize}
1225 *
1226 * @see #getHistorySize
1227 * @see #getX()
1228 * @see #AXIS_X
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001229 */
1230 public final float getHistoricalX(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001231 return nativeGetAxisValue(mNativePtr, AXIS_X, 0, pos);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001232 }
1233
1234 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08001235 * {@link #getHistoricalY(int, int)} for the first pointer index (may be an
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001236 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001237 *
1238 * @param pos Which historical value to return; must be less than
1239 * {@link #getHistorySize}
1240 *
1241 * @see #getHistorySize
1242 * @see #getY()
1243 * @see #AXIS_Y
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001244 */
1245 public final float getHistoricalY(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001246 return nativeGetAxisValue(mNativePtr, AXIS_Y, 0, pos);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001247 }
1248
1249 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08001250 * {@link #getHistoricalPressure(int, int)} for the first pointer index (may be an
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001251 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001252 *
1253 * @param pos Which historical value to return; must be less than
1254 * {@link #getHistorySize}
1255 *
1256 * @see #getHistorySize
1257 * @see #getPressure()
1258 * @see #AXIS_PRESSURE
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001259 */
1260 public final float getHistoricalPressure(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001261 return nativeGetAxisValue(mNativePtr, AXIS_PRESSURE, 0, pos);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001262 }
1263
1264 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08001265 * {@link #getHistoricalSize(int, int)} for the first pointer index (may be an
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001266 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001267 *
1268 * @param pos Which historical value to return; must be less than
1269 * {@link #getHistorySize}
1270 *
1271 * @see #getHistorySize
1272 * @see #getSize()
1273 * @see #AXIS_SIZE
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001274 */
1275 public final float getHistoricalSize(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001276 return nativeGetAxisValue(mNativePtr, AXIS_SIZE, 0, pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001277 }
Romain Guycafdea62009-06-12 10:51:36 -07001278
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001279 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08001280 * {@link #getHistoricalTouchMajor(int, int)} for the first pointer index (may be an
Jeff Brownc5ed5912010-07-14 18:48:53 -07001281 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001282 *
1283 * @param pos Which historical value to return; must be less than
1284 * {@link #getHistorySize}
1285 *
1286 * @see #getHistorySize
1287 * @see #getTouchMajor()
1288 * @see #AXIS_TOUCH_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07001289 */
1290 public final float getHistoricalTouchMajor(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001291 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MAJOR, 0, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001292 }
1293
1294 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08001295 * {@link #getHistoricalTouchMinor(int, int)} for the first pointer index (may be an
Jeff Brownc5ed5912010-07-14 18:48:53 -07001296 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001297 *
1298 * @param pos Which historical value to return; must be less than
1299 * {@link #getHistorySize}
1300 *
1301 * @see #getHistorySize
1302 * @see #getTouchMinor()
1303 * @see #AXIS_TOUCH_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07001304 */
1305 public final float getHistoricalTouchMinor(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001306 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MINOR, 0, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001307 }
1308
1309 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08001310 * {@link #getHistoricalToolMajor(int, int)} for the first pointer index (may be an
Jeff Brownc5ed5912010-07-14 18:48:53 -07001311 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001312 *
1313 * @param pos Which historical value to return; must be less than
1314 * {@link #getHistorySize}
1315 *
1316 * @see #getHistorySize
1317 * @see #getToolMajor()
1318 * @see #AXIS_TOOL_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07001319 */
1320 public final float getHistoricalToolMajor(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001321 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MAJOR, 0, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001322 }
1323
1324 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08001325 * {@link #getHistoricalToolMinor(int, int)} for the first pointer index (may be an
Jeff Brownc5ed5912010-07-14 18:48:53 -07001326 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001327 *
1328 * @param pos Which historical value to return; must be less than
1329 * {@link #getHistorySize}
1330 *
1331 * @see #getHistorySize
1332 * @see #getToolMinor()
1333 * @see #AXIS_TOOL_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07001334 */
1335 public final float getHistoricalToolMinor(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001336 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MINOR, 0, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001337 }
1338
1339 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08001340 * {@link #getHistoricalOrientation(int, int)} for the first pointer index (may be an
Jeff Brownc5ed5912010-07-14 18:48:53 -07001341 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001342 *
1343 * @param pos Which historical value to return; must be less than
1344 * {@link #getHistorySize}
1345 *
1346 * @see #getHistorySize
1347 * @see #getOrientation()
1348 * @see #AXIS_ORIENTATION
Jeff Brownc5ed5912010-07-14 18:48:53 -07001349 */
1350 public final float getHistoricalOrientation(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001351 return nativeGetAxisValue(mNativePtr, AXIS_ORIENTATION, 0, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001352 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08001353
1354 /**
1355 * {@link #getHistoricalAxisValue(int, int, int)} for the first pointer index (may be an
1356 * arbitrary pointer identifier).
1357 *
1358 * @param axis The axis identifier for the axis value to retrieve.
1359 * @param pos Which historical value to return; must be less than
1360 * {@link #getHistorySize}
1361 *
1362 * @see #getHistorySize
1363 * @see #getAxisValue(int)
1364 * @see #AXIS_X
1365 * @see #AXIS_Y
1366 */
1367 public final float getHistoricalAxisValue(int axis, int pos) {
1368 return nativeGetAxisValue(mNativePtr, axis, 0, pos);
1369 }
1370
Jeff Brownc5ed5912010-07-14 18:48:53 -07001371 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001372 * Returns a historical X coordinate, as per {@link #getX(int)}, that
1373 * occurred between this event and the previous event for the given pointer.
1374 * Only applies to ACTION_MOVE events.
Romain Guycafdea62009-06-12 10:51:36 -07001375 *
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001376 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1377 * (the first pointer that is down) to {@link #getPointerCount()}-1.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001378 * @param pos Which historical value to return; must be less than
1379 * {@link #getHistorySize}
Romain Guycafdea62009-06-12 10:51:36 -07001380 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001381 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08001382 * @see #getX(int)
1383 * @see #AXIS_X
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001384 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001385 public final float getHistoricalX(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001386 return nativeGetAxisValue(mNativePtr, AXIS_X, pointerIndex, pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001387 }
Romain Guycafdea62009-06-12 10:51:36 -07001388
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001389 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001390 * Returns a historical Y coordinate, as per {@link #getY(int)}, that
1391 * occurred between this event and the previous event for the given pointer.
1392 * Only applies to ACTION_MOVE events.
Romain Guycafdea62009-06-12 10:51:36 -07001393 *
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001394 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1395 * (the first pointer that is down) to {@link #getPointerCount()}-1.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001396 * @param pos Which historical value to return; must be less than
1397 * {@link #getHistorySize}
Romain Guycafdea62009-06-12 10:51:36 -07001398 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001399 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08001400 * @see #getY(int)
1401 * @see #AXIS_Y
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001402 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001403 public final float getHistoricalY(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001404 return nativeGetAxisValue(mNativePtr, AXIS_Y, pointerIndex, pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001405 }
Romain Guycafdea62009-06-12 10:51:36 -07001406
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001407 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001408 * Returns a historical pressure coordinate, as per {@link #getPressure(int)},
1409 * that occurred between this event and the previous event for the given
1410 * pointer. Only applies to ACTION_MOVE events.
Romain Guycafdea62009-06-12 10:51:36 -07001411 *
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001412 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1413 * (the first pointer that is down) to {@link #getPointerCount()}-1.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001414 * @param pos Which historical value to return; must be less than
1415 * {@link #getHistorySize}
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001416 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001417 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08001418 * @see #getPressure(int)
1419 * @see #AXIS_PRESSURE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001420 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001421 public final float getHistoricalPressure(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001422 return nativeGetAxisValue(mNativePtr, AXIS_PRESSURE, pointerIndex, pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001423 }
Romain Guycafdea62009-06-12 10:51:36 -07001424
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001425 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001426 * Returns a historical size coordinate, as per {@link #getSize(int)}, that
1427 * occurred between this event and the previous event for the given pointer.
1428 * Only applies to ACTION_MOVE events.
Romain Guycafdea62009-06-12 10:51:36 -07001429 *
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001430 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1431 * (the first pointer that is down) to {@link #getPointerCount()}-1.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001432 * @param pos Which historical value to return; must be less than
1433 * {@link #getHistorySize}
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001434 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001435 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08001436 * @see #getSize(int)
1437 * @see #AXIS_SIZE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001438 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001439 public final float getHistoricalSize(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001440 return nativeGetAxisValue(mNativePtr, AXIS_SIZE, pointerIndex, pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001441 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07001442
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001443 /**
Jeff Brownc5ed5912010-07-14 18:48:53 -07001444 * Returns a historical touch major axis coordinate, as per {@link #getTouchMajor(int)}, that
1445 * occurred between this event and the previous event for the given pointer.
1446 * Only applies to ACTION_MOVE events.
1447 *
1448 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1449 * (the first pointer that is down) to {@link #getPointerCount()}-1.
1450 * @param pos Which historical value to return; must be less than
1451 * {@link #getHistorySize}
1452 *
1453 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08001454 * @see #getTouchMajor(int)
1455 * @see #AXIS_TOUCH_MAJOR
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001456 */
Jeff Brownc5ed5912010-07-14 18:48:53 -07001457 public final float getHistoricalTouchMajor(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001458 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MAJOR, pointerIndex, pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001459 }
Romain Guycafdea62009-06-12 10:51:36 -07001460
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001461 /**
Jeff Brownc5ed5912010-07-14 18:48:53 -07001462 * Returns a historical touch minor axis coordinate, as per {@link #getTouchMinor(int)}, that
1463 * occurred between this event and the previous event for the given pointer.
1464 * Only applies to ACTION_MOVE events.
1465 *
1466 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1467 * (the first pointer that is down) to {@link #getPointerCount()}-1.
1468 * @param pos Which historical value to return; must be less than
1469 * {@link #getHistorySize}
1470 *
1471 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08001472 * @see #getTouchMinor(int)
1473 * @see #AXIS_TOUCH_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07001474 */
1475 public final float getHistoricalTouchMinor(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001476 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MINOR, pointerIndex, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001477 }
1478
1479 /**
1480 * Returns a historical tool major axis coordinate, as per {@link #getToolMajor(int)}, that
1481 * occurred between this event and the previous event for the given pointer.
1482 * Only applies to ACTION_MOVE events.
1483 *
1484 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1485 * (the first pointer that is down) to {@link #getPointerCount()}-1.
1486 * @param pos Which historical value to return; must be less than
1487 * {@link #getHistorySize}
1488 *
1489 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08001490 * @see #getToolMajor(int)
1491 * @see #AXIS_TOOL_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07001492 */
1493 public final float getHistoricalToolMajor(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001494 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MAJOR, pointerIndex, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001495 }
1496
1497 /**
1498 * Returns a historical tool minor axis coordinate, as per {@link #getToolMinor(int)}, that
1499 * occurred between this event and the previous event for the given pointer.
1500 * Only applies to ACTION_MOVE events.
1501 *
1502 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1503 * (the first pointer that is down) to {@link #getPointerCount()}-1.
1504 * @param pos Which historical value to return; must be less than
1505 * {@link #getHistorySize}
1506 *
1507 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08001508 * @see #getToolMinor(int)
1509 * @see #AXIS_TOOL_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07001510 */
1511 public final float getHistoricalToolMinor(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001512 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MINOR, pointerIndex, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001513 }
1514
1515 /**
1516 * Returns a historical orientation coordinate, as per {@link #getOrientation(int)}, that
1517 * occurred between this event and the previous event for the given pointer.
1518 * Only applies to ACTION_MOVE events.
1519 *
1520 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1521 * (the first pointer that is down) to {@link #getPointerCount()}-1.
1522 * @param pos Which historical value to return; must be less than
1523 * {@link #getHistorySize}
1524 *
1525 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08001526 * @see #getOrientation(int)
1527 * @see #AXIS_ORIENTATION
Jeff Brownc5ed5912010-07-14 18:48:53 -07001528 */
1529 public final float getHistoricalOrientation(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001530 return nativeGetAxisValue(mNativePtr, AXIS_ORIENTATION, pointerIndex, pos);
1531 }
1532
1533 /**
1534 * Returns the historical value of the requested axis, as per {@link #getAxisValue(int, int)},
1535 * occurred between this event and the previous event for the given pointer.
1536 * Only applies to ACTION_MOVE events.
1537 *
1538 * @param axis The axis identifier for the axis value to retrieve.
1539 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1540 * (the first pointer that is down) to {@link #getPointerCount()}-1.
1541 * @param pos Which historical value to return; must be less than
1542 * {@link #getHistorySize}
1543 * @return The value of the axis, or 0 if the axis is not available.
1544 *
1545 * @see #AXIS_X
1546 * @see #AXIS_Y
1547 */
1548 public final float getHistoricalAxisValue(int axis, int pointerIndex, int pos) {
1549 return nativeGetAxisValue(mNativePtr, axis, pointerIndex, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001550 }
1551
1552 /**
1553 * Populates a {@link PointerCoords} object with historical pointer coordinate data,
1554 * as per {@link #getPointerCoords}, that occurred between this event and the previous
1555 * event for the given pointer.
1556 * Only applies to ACTION_MOVE events.
1557 *
1558 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1559 * (the first pointer that is down) to {@link #getPointerCount()}-1.
1560 * @param pos Which historical value to return; must be less than
1561 * {@link #getHistorySize}
1562 * @param outPointerCoords The pointer coordinate object to populate.
1563 *
1564 * @see #getHistorySize
1565 * @see #getPointerCoords
Jeff Brown91c69ab2011-02-14 17:03:18 -08001566 * @see PointerCoords
Jeff Brownc5ed5912010-07-14 18:48:53 -07001567 */
1568 public final void getHistoricalPointerCoords(int pointerIndex, int pos,
1569 PointerCoords outPointerCoords) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001570 nativeGetPointerCoords(mNativePtr, pointerIndex, pos, outPointerCoords);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001571 }
1572
1573 /**
Jeff Brown46b9ac02010-04-22 18:58:52 -07001574 * Returns a bitfield indicating which edges, if any, were touched by this
Romain Guycafdea62009-06-12 10:51:36 -07001575 * MotionEvent. For touch events, clients can use this to determine if the
1576 * user's finger was touching the edge of the display.
1577 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001578 * @see #EDGE_LEFT
1579 * @see #EDGE_TOP
1580 * @see #EDGE_RIGHT
1581 * @see #EDGE_BOTTOM
1582 */
1583 public final int getEdgeFlags() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001584 return nativeGetEdgeFlags(mNativePtr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001585 }
Romain Guycafdea62009-06-12 10:51:36 -07001586
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001587 /**
Jeff Brown85a31762010-09-01 17:01:00 -07001588 * Sets the bitfield indicating which edges, if any, were touched by this
Romain Guycafdea62009-06-12 10:51:36 -07001589 * MotionEvent.
1590 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001591 * @see #getEdgeFlags()
1592 */
1593 public final void setEdgeFlags(int flags) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001594 nativeSetEdgeFlags(mNativePtr, flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001595 }
1596
1597 /**
1598 * Sets this event's action.
1599 */
1600 public final void setAction(int action) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001601 nativeSetAction(mNativePtr, action);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001602 }
1603
1604 /**
1605 * Adjust this event's location.
1606 * @param deltaX Amount to add to the current X coordinate of the event.
1607 * @param deltaY Amount to add to the current Y coordinate of the event.
1608 */
1609 public final void offsetLocation(float deltaX, float deltaY) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001610 nativeOffsetLocation(mNativePtr, deltaX, deltaY);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001611 }
Romain Guycafdea62009-06-12 10:51:36 -07001612
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001613 /**
1614 * Set this event's location. Applies {@link #offsetLocation} with a
1615 * delta from the current location to the given new location.
Romain Guycafdea62009-06-12 10:51:36 -07001616 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001617 * @param x New absolute X location.
1618 * @param y New absolute Y location.
1619 */
1620 public final void setLocation(float x, float y) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001621 float oldX = getX();
1622 float oldY = getY();
1623 nativeOffsetLocation(mNativePtr, x - oldX, y - oldY);
Jeff Brown5c225b12010-06-16 01:53:36 -07001624 }
1625
Jeff Brown20e987b2010-08-23 12:01:02 -07001626 /**
1627 * Applies a transformation matrix to all of the points in the event.
1628 *
1629 * @param matrix The transformation matrix to apply.
1630 */
1631 public final void transform(Matrix matrix) {
1632 if (matrix == null) {
1633 throw new IllegalArgumentException("matrix must not be null");
1634 }
1635
Jeff Brown91c69ab2011-02-14 17:03:18 -08001636 nativeTransform(mNativePtr, matrix);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001637 }
Romain Guycafdea62009-06-12 10:51:36 -07001638
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001639 /**
1640 * Add a new movement to the batch of movements in this event. The event's
Jeff Brownc5ed5912010-07-14 18:48:53 -07001641 * current location, position and size is updated to the new values.
1642 * The current values in the event are added to a list of historical values.
Jeff Brown91c69ab2011-02-14 17:03:18 -08001643 *
Jeff Browne33348b2010-07-15 23:54:05 -07001644 * Only applies to {@link #ACTION_MOVE} events.
Romain Guycafdea62009-06-12 10:51:36 -07001645 *
Jeff Brownc5ed5912010-07-14 18:48:53 -07001646 * @param eventTime The time stamp (in ms) for this data.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001647 * @param x The new X position.
1648 * @param y The new Y position.
1649 * @param pressure The new pressure.
1650 * @param size The new size.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001651 * @param metaState Meta key state.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001652 */
1653 public final void addBatch(long eventTime, float x, float y,
1654 float pressure, float size, int metaState) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001655 synchronized (gTmpPointerCoords) {
1656 final PointerCoords pc = gTmpPointerCoords[0];
1657 pc.clear();
1658 pc.x = x;
1659 pc.y = y;
1660 pc.pressure = pressure;
1661 pc.size = size;
1662 nativeAddBatch(mNativePtr, eventTime * NS_PER_MS, gTmpPointerCoords, metaState);
1663 }
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001664 }
Romain Guycafdea62009-06-12 10:51:36 -07001665
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001666 /**
Jeff Brownc5ed5912010-07-14 18:48:53 -07001667 * Add a new movement to the batch of movements in this event. The event's
1668 * current location, position and size is updated to the new values.
1669 * The current values in the event are added to a list of historical values.
Jeff Brown91c69ab2011-02-14 17:03:18 -08001670 *
Jeff Browne33348b2010-07-15 23:54:05 -07001671 * Only applies to {@link #ACTION_MOVE} events.
Jeff Brownc5ed5912010-07-14 18:48:53 -07001672 *
1673 * @param eventTime The time stamp (in ms) for this data.
1674 * @param pointerCoords The new pointer coordinates.
1675 * @param metaState Meta key state.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001676 */
Jeff Brownc5ed5912010-07-14 18:48:53 -07001677 public final void addBatch(long eventTime, PointerCoords[] pointerCoords, int metaState) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001678 nativeAddBatch(mNativePtr, eventTime * NS_PER_MS, pointerCoords, metaState);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001679 }
Romain Guycafdea62009-06-12 10:51:36 -07001680
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001681 @Override
1682 public String toString() {
1683 return "MotionEvent{" + Integer.toHexString(System.identityHashCode(this))
Huahui Wue838a422011-01-13 16:03:43 -08001684 + " pointerId=" + getPointerId(0)
Jeff Brown91c69ab2011-02-14 17:03:18 -08001685 + " action=" + actionToString(getAction())
Jeff Brown497a92c2010-09-12 17:55:08 -07001686 + " x=" + getX()
1687 + " y=" + getY()
1688 + " pressure=" + getPressure()
1689 + " size=" + getSize()
1690 + " touchMajor=" + getTouchMajor()
1691 + " touchMinor=" + getTouchMinor()
1692 + " toolMajor=" + getToolMajor()
1693 + " toolMinor=" + getToolMinor()
1694 + " orientation=" + getOrientation()
Jeff Brown91c69ab2011-02-14 17:03:18 -08001695 + " meta=" + KeyEvent.metaStateToString(getMetaState())
Jeff Brown497a92c2010-09-12 17:55:08 -07001696 + " pointerCount=" + getPointerCount()
1697 + " historySize=" + getHistorySize()
Jeff Brown91c69ab2011-02-14 17:03:18 -08001698 + " flags=0x" + Integer.toHexString(getFlags())
1699 + " edgeFlags=0x" + Integer.toHexString(getEdgeFlags())
1700 + " device=" + getDeviceId()
1701 + " source=0x" + Integer.toHexString(getSource())
Huahui Wue838a422011-01-13 16:03:43 -08001702 + (getPointerCount() > 1 ?
Huahui Wuf9324692011-01-24 12:07:37 -08001703 " pointerId2=" + getPointerId(1) + " x2=" + getX(1) + " y2=" + getY(1) : "")
Jeff Brown497a92c2010-09-12 17:55:08 -07001704 + "}";
1705 }
1706
1707 /**
1708 * Returns a string that represents the symbolic name of the specified action
Jeff Brown91c69ab2011-02-14 17:03:18 -08001709 * such as "ACTION_DOWN", "ACTION_POINTER_DOWN(3)" or an equivalent numeric constant
1710 * such as "35" if unknown.
Jeff Brown497a92c2010-09-12 17:55:08 -07001711 *
1712 * @param action The action.
1713 * @return The symbolic name of the specified action.
1714 * @hide
1715 */
1716 public static String actionToString(int action) {
1717 switch (action) {
1718 case ACTION_DOWN:
1719 return "ACTION_DOWN";
1720 case ACTION_UP:
1721 return "ACTION_UP";
1722 case ACTION_CANCEL:
1723 return "ACTION_CANCEL";
1724 case ACTION_MOVE:
1725 return "ACTION_MOVE";
1726 }
1727 int index = (action & ACTION_POINTER_INDEX_MASK) >> ACTION_POINTER_INDEX_SHIFT;
1728 switch (action & ACTION_MASK) {
1729 case ACTION_POINTER_DOWN:
1730 return "ACTION_POINTER_DOWN(" + index + ")";
1731 case ACTION_POINTER_UP:
1732 return "ACTION_POINTER_UP(" + index + ")";
1733 default:
1734 return Integer.toString(action);
1735 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001736 }
1737
Jeff Brown91c69ab2011-02-14 17:03:18 -08001738 /**
1739 * Returns a string that represents the symbolic name of the specified axis
1740 * such as "AXIS_X" or an equivalent numeric constants such as "42" if unknown.
1741 *
1742 * @param axis The axis
1743 * @return The symbolic name of the specified axis.
1744 * @hide
1745 */
1746 public static String axisToString(int axis) {
1747 switch (axis) {
1748 case AXIS_X:
1749 return "AXIS_X";
1750 case AXIS_Y:
1751 return "AXIS_Y";
1752 case AXIS_PRESSURE:
1753 return "AXIS_PRESSURE";
1754 case AXIS_SIZE:
1755 return "AXIS_SIZE";
1756 case AXIS_TOUCH_MAJOR:
1757 return "AXIS_TOUCH_MAJOR";
1758 case AXIS_TOUCH_MINOR:
1759 return "AXIS_TOUCH_MINOR";
1760 case AXIS_TOOL_MAJOR:
1761 return "AXIS_TOOL_MAJOR";
1762 case AXIS_TOOL_MINOR:
1763 return "AXIS_TOOL_MINOR";
1764 case AXIS_ORIENTATION:
1765 return "AXIS_ORIENTATION";
1766 default:
1767 return Integer.toString(axis);
1768 }
1769 }
1770
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001771 public static final Parcelable.Creator<MotionEvent> CREATOR
1772 = new Parcelable.Creator<MotionEvent>() {
1773 public MotionEvent createFromParcel(Parcel in) {
Jeff Brown6ec402b2010-07-28 15:48:59 -07001774 in.readInt(); // skip token, we already know this is a MotionEvent
1775 return MotionEvent.createFromParcelBody(in);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001776 }
1777
1778 public MotionEvent[] newArray(int size) {
1779 return new MotionEvent[size];
1780 }
1781 };
1782
Jeff Brown6ec402b2010-07-28 15:48:59 -07001783 /** @hide */
1784 public static MotionEvent createFromParcelBody(Parcel in) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001785 MotionEvent ev = obtain();
1786 ev.mNativePtr = nativeReadFromParcel(ev.mNativePtr, in);
Jeff Brown6ec402b2010-07-28 15:48:59 -07001787 return ev;
1788 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08001789
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001790 public void writeToParcel(Parcel out, int flags) {
Jeff Brown6ec402b2010-07-28 15:48:59 -07001791 out.writeInt(PARCEL_TOKEN_MOTION_EVENT);
Jeff Brown91c69ab2011-02-14 17:03:18 -08001792 nativeWriteToParcel(mNativePtr, out);
Jeff Brown5c225b12010-06-16 01:53:36 -07001793 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08001794
Jeff Brownc5ed5912010-07-14 18:48:53 -07001795 /**
1796 * Transfer object for pointer coordinates.
1797 *
1798 * Objects of this type can be used to manufacture new {@link MotionEvent} objects
1799 * and to query pointer coordinate information in bulk.
1800 *
1801 * Refer to {@link InputDevice} for information about how different kinds of
1802 * input devices and sources represent pointer coordinates.
1803 */
1804 public static final class PointerCoords {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001805 private static final int INITIAL_PACKED_AXIS_VALUES = 8;
1806 private int mPackedAxisBits; // 32bits are enough for now, can raise to 64bit when needed
1807 private float[] mPackedAxisValues;
1808
1809 /**
1810 * Creates a pointer coords object with all axes initialized to zero.
1811 */
1812 public PointerCoords() {
1813 }
1814
1815 /**
1816 * Creates a pointer coords object as a copy of the
1817 * contents of another pointer coords object.
1818 *
1819 * @param other The pointer coords object to copy.
1820 */
1821 public PointerCoords(PointerCoords other) {
1822 copyFrom(other);
1823 }
1824
Jeff Brownc5ed5912010-07-14 18:48:53 -07001825 /**
1826 * The X coordinate of the pointer movement.
Jeff Brown91c69ab2011-02-14 17:03:18 -08001827 * The interpretation of the X axis varies by input source.
1828 * It may represent the X position of the center of the touch contact area,
1829 * a relative horizontal displacement of a trackball or joystick, or something else.
1830 *
1831 * @see MotionEvent#AXIS_X
Jeff Brownc5ed5912010-07-14 18:48:53 -07001832 */
1833 public float x;
1834
1835 /**
1836 * The Y coordinate of the pointer movement.
Jeff Brown91c69ab2011-02-14 17:03:18 -08001837 * The interpretation of the Y axis varies by input source.
1838 * It may represent the Y position of the center of the touch contact area,
1839 * a relative vertical displacement of a trackball or joystick, or something else.
1840 *
1841 * @see MotionEvent#AXIS_Y
Jeff Brownc5ed5912010-07-14 18:48:53 -07001842 */
1843 public float y;
1844
1845 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08001846 * A normalized value that describes the pressure applied to the device
1847 * by a finger or other tool.
Jeff Brownc5ed5912010-07-14 18:48:53 -07001848 * The pressure generally ranges from 0 (no pressure at all) to 1 (normal pressure),
Jeff Brown91c69ab2011-02-14 17:03:18 -08001849 * although values higher than 1 may be generated depending on the calibration of
Jeff Brownc5ed5912010-07-14 18:48:53 -07001850 * the input device.
Jeff Brown91c69ab2011-02-14 17:03:18 -08001851 *
1852 * @see MotionEvent#AXIS_PRESSURE
Jeff Brownc5ed5912010-07-14 18:48:53 -07001853 */
1854 public float pressure;
1855
1856 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08001857 * A normalized value that describes the approximate size of the pointer touch area
1858 * in relation to the maximum detectable size of the device.
1859 * It represents some approximation of the area of the screen being
Jeff Brownc5ed5912010-07-14 18:48:53 -07001860 * pressed; the actual value in pixels corresponding to the
1861 * touch is normalized with the device specific range of values
1862 * and scaled to a value between 0 and 1. The value of size can be used to
1863 * determine fat touch events.
Jeff Brown91c69ab2011-02-14 17:03:18 -08001864 *
1865 * @see MotionEvent#AXIS_SIZE
Jeff Brownc5ed5912010-07-14 18:48:53 -07001866 */
1867 public float size;
1868
1869 /**
1870 * The length of the major axis of an ellipse that describes the touch area at
1871 * the point of contact.
Jeff Brown91c69ab2011-02-14 17:03:18 -08001872 * If the device is a touch screen, the length is reported in pixels, otherwise it is
1873 * reported in device-specific units.
1874 *
1875 * @see MotionEvent#AXIS_TOUCH_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07001876 */
1877 public float touchMajor;
1878
1879 /**
1880 * The length of the minor axis of an ellipse that describes the touch area at
1881 * the point of contact.
Jeff Brown91c69ab2011-02-14 17:03:18 -08001882 * If the device is a touch screen, the length is reported in pixels, otherwise it is
1883 * reported in device-specific units.
1884 *
1885 * @see MotionEvent#AXIS_TOUCH_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07001886 */
1887 public float touchMinor;
1888
1889 /**
1890 * The length of the major axis of an ellipse that describes the size of
1891 * the approaching tool.
1892 * The tool area represents the estimated size of the finger or pen that is
1893 * touching the device independent of its actual touch area at the point of contact.
Jeff Brown91c69ab2011-02-14 17:03:18 -08001894 * If the device is a touch screen, the length is reported in pixels, otherwise it is
1895 * reported in device-specific units.
1896 *
1897 * @see MotionEvent#AXIS_TOOL_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07001898 */
1899 public float toolMajor;
1900
1901 /**
1902 * The length of the minor axis of an ellipse that describes the size of
1903 * the approaching tool.
1904 * The tool area represents the estimated size of the finger or pen that is
1905 * touching the device independent of its actual touch area at the point of contact.
Jeff Brown91c69ab2011-02-14 17:03:18 -08001906 * If the device is a touch screen, the length is reported in pixels, otherwise it is
1907 * reported in device-specific units.
1908 *
1909 * @see MotionEvent#AXIS_TOOL_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07001910 */
1911 public float toolMinor;
1912
1913 /**
1914 * The orientation of the touch area and tool area in radians clockwise from vertical.
1915 * An angle of 0 degrees indicates that the major axis of contact is oriented
1916 * upwards, is perfectly circular or is of unknown orientation. A positive angle
1917 * indicates that the major axis of contact is oriented to the right. A negative angle
1918 * indicates that the major axis of contact is oriented to the left.
Jeff Brown6d0fec22010-07-23 21:28:06 -07001919 * The full range is from -PI/2 radians (finger pointing fully left) to PI/2 radians
Jeff Brownc5ed5912010-07-14 18:48:53 -07001920 * (finger pointing fully right).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001921 *
1922 * @see MotionEvent#AXIS_ORIENTATION
Jeff Brownc5ed5912010-07-14 18:48:53 -07001923 */
1924 public float orientation;
Jeff Brown91c69ab2011-02-14 17:03:18 -08001925
1926 /**
1927 * Clears the contents of this object.
1928 * Resets all axes to zero.
1929 */
1930 public void clear() {
1931 mPackedAxisBits = 0;
1932
1933 x = 0;
1934 y = 0;
1935 pressure = 0;
1936 size = 0;
1937 touchMajor = 0;
1938 touchMinor = 0;
1939 toolMajor = 0;
1940 toolMinor = 0;
1941 orientation = 0;
Jeff Brownc5ed5912010-07-14 18:48:53 -07001942 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08001943
1944 /**
1945 * Copies the contents of another pointer coords object.
1946 *
1947 * @param other The pointer coords object to copy.
1948 */
1949 public void copyFrom(PointerCoords other) {
1950 final int bits = other.mPackedAxisBits;
1951 mPackedAxisBits = bits;
1952 if (bits != 0) {
1953 final float[] otherValues = other.mPackedAxisValues;
1954 final int count = Integer.bitCount(bits);
1955 float[] values = mPackedAxisValues;
1956 if (values == null || count > values.length) {
1957 values = new float[otherValues.length];
1958 mPackedAxisValues = values;
1959 }
1960 System.arraycopy(otherValues, 0, values, 0, count);
1961 }
1962
1963 x = other.x;
1964 y = other.y;
1965 pressure = other.pressure;
1966 size = other.size;
1967 touchMajor = other.touchMajor;
1968 touchMinor = other.touchMinor;
1969 toolMajor = other.toolMajor;
1970 toolMinor = other.toolMinor;
1971 orientation = other.orientation;
Jeff Brownc5ed5912010-07-14 18:48:53 -07001972 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08001973
1974 /**
1975 * Gets the value associated with the specified axis.
1976 *
1977 * @param axis The axis identifier for the axis value to retrieve.
1978 * @return The value associated with the axis, or 0 if none.
1979 *
1980 * @see MotionEvent#AXIS_X
1981 * @see MotionEvent#AXIS_Y
1982 */
1983 public float getAxisValue(int axis) {
1984 switch (axis) {
1985 case AXIS_X:
1986 return x;
1987 case AXIS_Y:
1988 return y;
1989 case AXIS_PRESSURE:
1990 return pressure;
1991 case AXIS_SIZE:
1992 return size;
1993 case AXIS_TOUCH_MAJOR:
1994 return touchMajor;
1995 case AXIS_TOUCH_MINOR:
1996 return touchMinor;
1997 case AXIS_TOOL_MAJOR:
1998 return toolMajor;
1999 case AXIS_TOOL_MINOR:
2000 return toolMinor;
2001 case AXIS_ORIENTATION:
2002 return orientation;
2003 default: {
2004 final int bits = mPackedAxisBits;
2005 final int axisBit = 1 << axis;
2006 if ((bits & axisBit) == 0) {
2007 return 0;
2008 }
2009 final int index = Integer.bitCount(bits & (axisBit - 1));
2010 return mPackedAxisValues[index];
2011 }
2012 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002013 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08002014
2015 /**
2016 * Sets the value associated with the specified axis.
2017 *
2018 * @param axis The axis identifier for the axis value to assign.
2019 * @param value The value to set.
2020 *
2021 * @see MotionEvent#AXIS_X
2022 * @see MotionEvent#AXIS_Y
2023 */
2024 public void setAxisValue(int axis, float value) {
2025 switch (axis) {
2026 case AXIS_X:
2027 x = value;
2028 break;
2029 case AXIS_Y:
2030 y = value;
2031 break;
2032 case AXIS_PRESSURE:
2033 pressure = value;
2034 break;
2035 case AXIS_SIZE:
2036 size = value;
2037 break;
2038 case AXIS_TOUCH_MAJOR:
2039 touchMajor = value;
2040 break;
2041 case AXIS_TOUCH_MINOR:
2042 touchMinor = value;
2043 break;
2044 case AXIS_TOOL_MAJOR:
2045 toolMajor = value;
2046 break;
2047 case AXIS_TOOL_MINOR:
2048 toolMinor = value;
2049 break;
2050 case AXIS_ORIENTATION:
2051 orientation = value;
2052 break;
2053 default: {
2054 final int bits = mPackedAxisBits;
2055 final int axisBit = 1 << axis;
2056 final int index = Integer.bitCount(bits & (axisBit - 1));
2057 float[] values = mPackedAxisValues;
2058 if ((bits & axisBit) == 0) {
2059 if (values == null) {
2060 values = new float[INITIAL_PACKED_AXIS_VALUES];
2061 mPackedAxisValues = values;
2062 } else {
2063 final int count = Integer.bitCount(bits);
2064 if (count < values.length) {
2065 if (index != count) {
2066 System.arraycopy(values, index, values, index + 1,
2067 count - index);
2068 }
2069 } else {
2070 float[] newValues = new float[count * 2];
2071 System.arraycopy(values, 0, newValues, 0, index);
2072 System.arraycopy(values, index, newValues, index + 1,
2073 count - index);
2074 values = newValues;
2075 mPackedAxisValues = values;
2076 }
2077 }
2078 mPackedAxisBits = bits | axisBit;
2079 }
2080 values[index] = value;
2081 }
2082 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002083 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002084 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002085}