blob: 7611b084dd02a9ff5ea1d6f85a8c04874d637898 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.view;
18
Jeff Brown20e987b2010-08-23 12:01:02 -070019import android.graphics.Matrix;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080020import android.os.Parcel;
21import android.os.Parcelable;
22import android.os.SystemClock;
Jeff Brown6f2fba42011-02-19 01:08:02 -080023import android.util.SparseArray;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024
25/**
26 * Object used to report movement (mouse, pen, finger, trackball) events. This
27 * class may hold either absolute or relative movements, depending on what
28 * it is being used for.
Jeff Browndc1ab4b2010-09-14 18:03:38 -070029 * <p>
Jeff Browncb1404e2011-01-15 18:14:15 -080030 * On pointing devices with source class {@link InputDevice#SOURCE_CLASS_POINTER}
31 * such as touch screens, the pointer coordinates specify absolute
Jeff Browndc1ab4b2010-09-14 18:03:38 -070032 * positions such as view X/Y coordinates. Each complete gesture is represented
33 * by a sequence of motion events with actions that describe pointer state transitions
34 * and movements. A gesture starts with a motion event with {@link #ACTION_DOWN}
35 * that provides the location of the first pointer down. As each additional
36 * pointer that goes down or up, the framework will generate a motion event with
37 * {@link #ACTION_POINTER_DOWN} or {@link #ACTION_POINTER_UP} accordingly.
38 * Pointer movements are described by motion events with {@link #ACTION_MOVE}.
39 * Finally, a gesture end either when the final pointer goes up as represented
40 * by a motion event with {@link #ACTION_UP} or when gesture is canceled
41 * with {@link #ACTION_CANCEL}.
42 * </p><p>
Jeff Brown33bbfd22011-02-24 20:55:35 -080043 * Some pointing devices such as mice may support vertical and/or horizontal scrolling.
44 * A scroll event is reported as a generic motion event with {@link #ACTION_SCROLL} that
45 * includes the relative scroll offset in the {@link #AXIS_VSCROLL} and
46 * {@link #AXIS_HSCROLL} axes. See {@link #getAxisValue(int)} for information
47 * about retrieving these additional axes.
48 * </p><p>
Jeff Browncb1404e2011-01-15 18:14:15 -080049 * On trackball devices with source class {@link InputDevice#SOURCE_CLASS_TRACKBALL},
50 * the pointer coordinates specify relative movements as X/Y deltas.
Jeff Browndc1ab4b2010-09-14 18:03:38 -070051 * A trackball gesture consists of a sequence of movements described by motion
52 * events with {@link #ACTION_MOVE} interspersed with occasional {@link #ACTION_DOWN}
53 * or {@link #ACTION_UP} motion events when the trackball button is pressed or released.
54 * </p><p>
Jeff Browncb1404e2011-01-15 18:14:15 -080055 * On joystick devices with source class {@link InputDevice#SOURCE_CLASS_JOYSTICK},
56 * the pointer coordinates specify the absolute position of the joystick axes.
57 * The joystick axis values are normalized to a range of -1.0 to 1.0 where 0.0 corresponds
58 * to the center position. More information about the set of available axes and the
59 * range of motion can be obtained using {@link InputDevice#getMotionRange}.
Jeff Brown33bbfd22011-02-24 20:55:35 -080060 * Some common joystick axes are {@link #AXIS_X}, {@link #AXIS_Y},
61 * {@link #AXIS_HAT_X}, {@link #AXIS_HAT_Y}, {@link #AXIS_Z} and {@link #AXIS_RZ}.
Jeff Browncb1404e2011-01-15 18:14:15 -080062 * </p><p>
Jeff Browndc1ab4b2010-09-14 18:03:38 -070063 * Motion events always report movements for all pointers at once. The number
64 * of pointers only ever changes by one as individual pointers go up and down,
65 * except when the gesture is canceled.
66 * </p><p>
67 * The order in which individual pointers appear within a motion event can change
68 * from one event to the next. Use the {@link #getPointerId(int)} method to obtain a
69 * pointer id to track pointers across motion events in a gesture. Then for
70 * successive motion events, use the {@link #findPointerIndex(int)} method to obtain
71 * the pointer index for a given pointer id in that motion event.
72 * </p><p>
73 * For efficiency, motion events with {@link #ACTION_MOVE} may batch together
74 * multiple movement samples within a single object. The most current
75 * pointer coordinates are available using {@link #getX(int)} and {@link #getY(int)}.
76 * Earlier coordinates within the batch are accessed using {@link #getHistoricalX(int, int)}
77 * and {@link #getHistoricalY(int, int)}. The coordinates are "historical" only
78 * insofar as they are older than the current coordinates in the batch; however,
79 * they are still distinct from any other coordinates reported in prior motion events.
80 * To process all coordinates in the batch in time order, first consume the historical
81 * coordinates then consume the current coordinates.
82 * </p><p>
83 * Example: Consuming all samples for all pointers in a motion event in time order.
84 * </p><p><pre><code>
85 * void printSamples(MotionEvent ev) {
86 * final int historySize = ev.getHistorySize();
87 * final int pointerCount = ev.getPointerCount();
88 * for (int h = 0; h &lt; historySize; h++) {
89 * System.out.printf("At time %d:", ev.getHistoricalEventTime(h));
90 * for (int p = 0; p &lt; pointerCount; p++) {
91 * System.out.printf(" pointer %d: (%f,%f)",
92 * ev.getPointerId(p), ev.getHistoricalX(p, h), ev.getHistoricalY(p, h));
93 * }
94 * }
95 * System.out.printf("At time %d:", ev.getEventTime());
96 * for (int p = 0; p &lt; pointerCount; p++) {
97 * System.out.printf(" pointer %d: (%f,%f)",
98 * ev.getPointerId(p), ev.getX(p), ev.getY(p));
99 * }
100 * }
101 * </code></pre></p><p>
Jeff Brownb6997262010-10-08 22:31:17 -0700102 * In general, the framework cannot guarantee that the motion events it delivers
103 * to a view always constitute a complete motion sequences since some events may be dropped
104 * or modified by containing views before they are delivered. The view implementation
105 * should be prepared to handle {@link #ACTION_CANCEL} and should tolerate anomalous
106 * situations such as receiving a new {@link #ACTION_DOWN} without first having
107 * received an {@link #ACTION_UP} for the prior gesture.
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700108 * </p><p>
109 * Refer to {@link InputDevice} for more information about how different kinds of
Jeff Brownc5ed5912010-07-14 18:48:53 -0700110 * input devices and sources represent pointer coordinates.
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700111 * </p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800112 */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700113public final class MotionEvent extends InputEvent implements Parcelable {
Jeff Brown91c69ab2011-02-14 17:03:18 -0800114 private static final long NS_PER_MS = 1000000;
Jeff Brown85a31762010-09-01 17:01:00 -0700115 private static final boolean TRACK_RECYCLED_LOCATION = false;
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700116
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800117 /**
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700118 * Bit mask of the parts of the action code that are the action itself.
119 */
120 public static final int ACTION_MASK = 0xff;
121
122 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800123 * Constant for {@link #getAction}: A pressed gesture has started, the
124 * motion contains the initial starting location.
125 */
126 public static final int ACTION_DOWN = 0;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700127
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800128 /**
129 * Constant for {@link #getAction}: A pressed gesture has finished, the
130 * motion contains the final release location as well as any intermediate
131 * points since the last down or move event.
132 */
133 public static final int ACTION_UP = 1;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700134
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800135 /**
136 * Constant for {@link #getAction}: A change has happened during a
137 * press gesture (between {@link #ACTION_DOWN} and {@link #ACTION_UP}).
138 * The motion contains the most recent point, as well as any intermediate
139 * points since the last down or move event.
140 */
141 public static final int ACTION_MOVE = 2;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700142
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800143 /**
144 * Constant for {@link #getAction}: The current gesture has been aborted.
145 * You will not receive any more points in it. You should treat this as
146 * an up event, but not perform any action that you normally would.
147 */
148 public static final int ACTION_CANCEL = 3;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700149
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800150 /**
151 * Constant for {@link #getAction}: A movement has happened outside of the
152 * normal bounds of the UI element. This does not provide a full gesture,
153 * but only the initial location of the movement/touch.
154 */
155 public static final int ACTION_OUTSIDE = 4;
156
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700157 /**
158 * A non-primary pointer has gone down. The bits in
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700159 * {@link #ACTION_POINTER_ID_MASK} indicate which pointer changed.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700160 */
161 public static final int ACTION_POINTER_DOWN = 5;
162
163 /**
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700164 * A non-primary pointer has gone up. The bits in
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700165 * {@link #ACTION_POINTER_ID_MASK} indicate which pointer changed.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700166 */
167 public static final int ACTION_POINTER_UP = 6;
Jeff Browncc0c1592011-02-19 05:07:28 -0800168
169 /**
170 * Constant for {@link #getAction}: A change happened but the pointer
171 * is not down (unlike {@link #ACTION_MOVE}). The motion contains the most
172 * recent point, as well as any intermediate points since the last
173 * hover move event.
Jeff Brown33bbfd22011-02-24 20:55:35 -0800174 * <p>
Jeff Browna032cc02011-03-07 16:56:21 -0800175 * This action is always delivered to the window or view under the pointer.
176 * </p><p>
Jeff Brown33bbfd22011-02-24 20:55:35 -0800177 * This action is not a touch event so it is delivered to
178 * {@link View#onGenericMotionEvent(MotionEvent)} rather than
179 * {@link View#onTouchEvent(MotionEvent)}.
180 * </p>
Jeff Browncc0c1592011-02-19 05:07:28 -0800181 */
182 public static final int ACTION_HOVER_MOVE = 7;
183
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700184 /**
Jeff Brown33bbfd22011-02-24 20:55:35 -0800185 * Constant for {@link #getAction}: The motion event contains relative
186 * vertical and/or horizontal scroll offsets. Use {@link #getAxisValue(int)}
187 * to retrieve the information from {@link #AXIS_VSCROLL} and {@link #AXIS_HSCROLL}.
188 * The pointer may or may not be down when this event is dispatched.
Jeff Browna032cc02011-03-07 16:56:21 -0800189 * <p></p>
190 * This action is always delivered to the window or view under the pointer, which
191 * may not be the window or view currently touched.
Jeff Brown33bbfd22011-02-24 20:55:35 -0800192 * <p>
193 * This action is not a touch event so it is delivered to
194 * {@link View#onGenericMotionEvent(MotionEvent)} rather than
195 * {@link View#onTouchEvent(MotionEvent)}.
196 * </p>
197 */
198 public static final int ACTION_SCROLL = 8;
199
200 /**
Jeff Browna032cc02011-03-07 16:56:21 -0800201 * Constant for {@link #getAction}: The pointer is not down but has entered the
202 * boundaries of a window or view.
203 * <p>
204 * This action is always delivered to the window or view under the pointer.
205 * </p><p>
206 * This action is not a touch event so it is delivered to
207 * {@link View#onGenericMotionEvent(MotionEvent)} rather than
208 * {@link View#onTouchEvent(MotionEvent)}.
209 * </p>
210 */
211 public static final int ACTION_HOVER_ENTER = 9;
212
213 /**
214 * Constant for {@link #getAction}: The pointer is not down but has exited the
215 * boundaries of a window or view.
216 * <p>
217 * This action is always delivered to the window or view that was previously under the pointer.
218 * </p><p>
219 * This action is not a touch event so it is delivered to
220 * {@link View#onGenericMotionEvent(MotionEvent)} rather than
221 * {@link View#onTouchEvent(MotionEvent)}.
222 * </p>
223 */
224 public static final int ACTION_HOVER_EXIT = 10;
225
226 /**
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800227 * Bits in the action code that represent a pointer index, used with
228 * {@link #ACTION_POINTER_DOWN} and {@link #ACTION_POINTER_UP}. Shifting
229 * down by {@link #ACTION_POINTER_INDEX_SHIFT} provides the actual pointer
230 * index where the data for the pointer going up or down can be found; you can
231 * get its identifier with {@link #getPointerId(int)} and the actual
232 * data with {@link #getX(int)} etc.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700233 */
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800234 public static final int ACTION_POINTER_INDEX_MASK = 0xff00;
235
236 /**
237 * Bit shift for the action bits holding the pointer index as
238 * defined by {@link #ACTION_POINTER_INDEX_MASK}.
239 */
240 public static final int ACTION_POINTER_INDEX_SHIFT = 8;
241
242 /**
243 * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the
244 * data index associated with {@link #ACTION_POINTER_DOWN}.
245 */
246 @Deprecated
247 public static final int ACTION_POINTER_1_DOWN = ACTION_POINTER_DOWN | 0x0000;
248
249 /**
250 * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the
251 * data index associated with {@link #ACTION_POINTER_DOWN}.
252 */
253 @Deprecated
254 public static final int ACTION_POINTER_2_DOWN = ACTION_POINTER_DOWN | 0x0100;
255
256 /**
257 * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the
258 * data index associated with {@link #ACTION_POINTER_DOWN}.
259 */
260 @Deprecated
261 public static final int ACTION_POINTER_3_DOWN = ACTION_POINTER_DOWN | 0x0200;
262
263 /**
264 * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the
265 * data index associated with {@link #ACTION_POINTER_UP}.
266 */
267 @Deprecated
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700268 public static final int ACTION_POINTER_1_UP = ACTION_POINTER_UP | 0x0000;
269
270 /**
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800271 * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the
272 * data index associated with {@link #ACTION_POINTER_UP}.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700273 */
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800274 @Deprecated
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700275 public static final int ACTION_POINTER_2_UP = ACTION_POINTER_UP | 0x0100;
276
277 /**
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800278 * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the
279 * data index associated with {@link #ACTION_POINTER_UP}.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700280 */
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800281 @Deprecated
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700282 public static final int ACTION_POINTER_3_UP = ACTION_POINTER_UP | 0x0200;
283
284 /**
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800285 * @deprecated Renamed to {@link #ACTION_POINTER_INDEX_MASK} to match
286 * the actual data contained in these bits.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700287 */
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800288 @Deprecated
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700289 public static final int ACTION_POINTER_ID_MASK = 0xff00;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700290
291 /**
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800292 * @deprecated Renamed to {@link #ACTION_POINTER_INDEX_SHIFT} to match
293 * the actual data contained in these bits.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700294 */
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800295 @Deprecated
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700296 public static final int ACTION_POINTER_ID_SHIFT = 8;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700297
Jeff Brown85a31762010-09-01 17:01:00 -0700298 /**
299 * This flag indicates that the window that received this motion event is partly
300 * or wholly obscured by another visible window above it. This flag is set to true
301 * even if the event did not directly pass through the obscured area.
302 * A security sensitive application can check this flag to identify situations in which
303 * a malicious application may have covered up part of its content for the purpose
304 * of misleading the user or hijacking touches. An appropriate response might be
305 * to drop the suspect touches or to take additional precautions to confirm the user's
306 * actual intent.
307 */
308 public static final int FLAG_WINDOW_IS_OBSCURED = 0x1;
Romain Guycafdea62009-06-12 10:51:36 -0700309
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800310 /**
Jeff Brown21bc5c92011-02-28 18:27:14 -0800311 * Private flag that indicates when the system has detected that this motion event
312 * may be inconsistent with respect to the sequence of previously delivered motion events,
313 * such as when a pointer move event is sent but the pointer is not down.
314 *
315 * @hide
316 * @see #isTainted
317 * @see #setTainted
318 */
319 public static final int FLAG_TAINTED = 0x80000000;
320
321 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800322 * Flag indicating the motion event intersected the top edge of the screen.
323 */
324 public static final int EDGE_TOP = 0x00000001;
Romain Guycafdea62009-06-12 10:51:36 -0700325
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800326 /**
327 * Flag indicating the motion event intersected the bottom edge of the screen.
328 */
329 public static final int EDGE_BOTTOM = 0x00000002;
Romain Guycafdea62009-06-12 10:51:36 -0700330
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800331 /**
332 * Flag indicating the motion event intersected the left edge of the screen.
333 */
334 public static final int EDGE_LEFT = 0x00000004;
Romain Guycafdea62009-06-12 10:51:36 -0700335
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800336 /**
337 * Flag indicating the motion event intersected the right edge of the screen.
338 */
339 public static final int EDGE_RIGHT = 0x00000008;
Romain Guycafdea62009-06-12 10:51:36 -0700340
Jeff Brown91c69ab2011-02-14 17:03:18 -0800341 /**
342 * Constant used to identify the X axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800343 * <p>
344 * <ul>
345 * <li>For a touch screen, reports the absolute X screen position of the center of
346 * the touch contact area. The units are display pixels.
347 * <li>For a touch pad, reports the absolute X surface position of the center of the touch
Jeff Browncc0c1592011-02-19 05:07:28 -0800348 * contact area. The units are device-dependent; use {@link InputDevice#getMotionRange(int)}
349 * to query the effective range of values.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800350 * <li>For a mouse, reports the absolute X screen position of the mouse pointer.
351 * The units are display pixels.
352 * <li>For a trackball, reports the relative horizontal displacement of the trackball.
353 * The value is normalized to a range from -1.0 (left) to 1.0 (right).
354 * <li>For a joystick, reports the absolute X position of the joystick.
355 * The value is normalized to a range from -1.0 (left) to 1.0 (right).
356 * </ul>
357 * </p>
Jeff Brown91c69ab2011-02-14 17:03:18 -0800358 *
359 * @see #getX(int)
360 * @see #getHistoricalX(int, int)
361 * @see MotionEvent.PointerCoords#x
362 * @see InputDevice#getMotionRange
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700363 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800364 public static final int AXIS_X = 0;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700365
Jeff Brown91c69ab2011-02-14 17:03:18 -0800366 /**
367 * Constant used to identify the Y axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800368 * <p>
369 * <ul>
370 * <li>For a touch screen, reports the absolute Y screen position of the center of
371 * the touch contact area. The units are display pixels.
372 * <li>For a touch pad, reports the absolute Y surface position of the center of the touch
373 * contact area. The units are device-dependent; use {@link InputDevice#getMotionRange(int)}
374 * to query the effective range of values.
375 * <li>For a mouse, reports the absolute Y screen position of the mouse pointer.
376 * The units are display pixels.
377 * <li>For a trackball, reports the relative vertical displacement of the trackball.
378 * The value is normalized to a range from -1.0 (up) to 1.0 (down).
379 * <li>For a joystick, reports the absolute Y position of the joystick.
380 * The value is normalized to a range from -1.0 (up or far) to 1.0 (down or near).
381 * </ul>
382 * </p>
Jeff Brown91c69ab2011-02-14 17:03:18 -0800383 *
384 * @see #getY(int)
385 * @see #getHistoricalY(int, int)
386 * @see MotionEvent.PointerCoords#y
387 * @see InputDevice#getMotionRange
Jeff Brownc5ed5912010-07-14 18:48:53 -0700388 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800389 public static final int AXIS_Y = 1;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700390
Jeff Brown91c69ab2011-02-14 17:03:18 -0800391 /**
392 * Constant used to identify the Pressure axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800393 * <p>
394 * <ul>
Jeff Browncc0c1592011-02-19 05:07:28 -0800395 * <li>For a touch screen or touch pad, reports the approximate pressure applied to the surface
Jeff Brown6f2fba42011-02-19 01:08:02 -0800396 * by a finger or other tool. The value is normalized to a range from
397 * 0 (no pressure at all) to 1 (normal pressure), although values higher than 1
398 * may be generated depending on the calibration of the input device.
399 * <li>For a trackball, the value is set to 1 if the trackball button is pressed
400 * or 0 otherwise.
401 * <li>For a mouse, the value is set to 1 if the primary mouse button is pressed
402 * or 0 otherwise.
403 * </ul>
404 * </p>
Jeff Brown91c69ab2011-02-14 17:03:18 -0800405 *
406 * @see #getPressure(int)
407 * @see #getHistoricalPressure(int, int)
408 * @see MotionEvent.PointerCoords#pressure
409 * @see InputDevice#getMotionRange
Jeff Brownc5ed5912010-07-14 18:48:53 -0700410 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800411 public static final int AXIS_PRESSURE = 2;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700412
Jeff Brown91c69ab2011-02-14 17:03:18 -0800413 /**
414 * Constant used to identify the Size axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800415 * <p>
416 * <ul>
417 * <li>For a touch screen or touch pad, reports the approximate size of the contact area in
418 * relation to the maximum detectable size for the device. The value is normalized
419 * to a range from 0 (smallest detectable size) to 1 (largest detectable size),
Jeff Browncc0c1592011-02-19 05:07:28 -0800420 * although it is not a linear scale. This value is of limited use.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800421 * To obtain calibrated size information, use
422 * {@link #AXIS_TOUCH_MAJOR} or {@link #AXIS_TOOL_MAJOR}.
423 * </ul>
424 * </p>
Jeff Brown91c69ab2011-02-14 17:03:18 -0800425 *
426 * @see #getSize(int)
427 * @see #getHistoricalSize(int, int)
428 * @see MotionEvent.PointerCoords#size
429 * @see InputDevice#getMotionRange
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700430 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800431 public static final int AXIS_SIZE = 3;
432
433 /**
434 * Constant used to identify the TouchMajor axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800435 * <p>
436 * <ul>
437 * <li>For a touch screen, reports the length of the major axis of an ellipse that
438 * represents the touch area at the point of contact.
439 * The units are display pixels.
440 * <li>For a touch pad, reports the length of the major axis of an ellipse that
441 * represents the touch area at the point of contact.
442 * The units are device-dependent; use {@link InputDevice#getMotionRange(int)}
443 * to query the effective range of values.
444 * </ul>
445 * </p>
Jeff Brown91c69ab2011-02-14 17:03:18 -0800446 *
447 * @see #getTouchMajor(int)
448 * @see #getHistoricalTouchMajor(int, int)
449 * @see MotionEvent.PointerCoords#touchMajor
450 * @see InputDevice#getMotionRange
Dianne Hackborn1e8dfc72009-08-06 12:43:01 -0700451 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800452 public static final int AXIS_TOUCH_MAJOR = 4;
453
454 /**
455 * Constant used to identify the TouchMinor axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800456 * <p>
457 * <ul>
458 * <li>For a touch screen, reports the length of the minor axis of an ellipse that
459 * represents the touch area at the point of contact.
460 * The units are display pixels.
461 * <li>For a touch pad, reports the length of the minor axis of an ellipse that
462 * represents the touch area at the point of contact.
463 * The units are device-dependent; use {@link InputDevice#getMotionRange(int)}
464 * to query the effective range of values.
465 * </ul>
466 * </p><p>
467 * When the touch is circular, the major and minor axis lengths will be equal to one another.
468 * </p>
Jeff Brown91c69ab2011-02-14 17:03:18 -0800469 *
470 * @see #getTouchMinor(int)
471 * @see #getHistoricalTouchMinor(int, int)
472 * @see MotionEvent.PointerCoords#touchMinor
473 * @see InputDevice#getMotionRange
Jeff Brown9e2ad362010-07-30 19:20:11 -0700474 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800475 public static final int AXIS_TOUCH_MINOR = 5;
476
477 /**
478 * Constant used to identify the ToolMajor axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800479 * <p>
480 * <ul>
481 * <li>For a touch screen, reports the length of the major axis of an ellipse that
482 * represents the size of the approaching finger or tool used to make contact.
483 * <li>For a touch pad, reports the length of the major axis of an ellipse that
484 * represents the size of the approaching finger or tool used to make contact.
485 * The units are device-dependent; use {@link InputDevice#getMotionRange(int)}
486 * to query the effective range of values.
487 * </ul>
488 * </p><p>
489 * When the touch is circular, the major and minor axis lengths will be equal to one another.
490 * </p><p>
491 * The tool size may be larger than the touch size since the tool may not be fully
492 * in contact with the touch sensor.
493 * </p>
Jeff Brown91c69ab2011-02-14 17:03:18 -0800494 *
495 * @see #getToolMajor(int)
496 * @see #getHistoricalToolMajor(int, int)
497 * @see MotionEvent.PointerCoords#toolMajor
498 * @see InputDevice#getMotionRange
499 */
500 public static final int AXIS_TOOL_MAJOR = 6;
501
502 /**
503 * Constant used to identify the ToolMinor axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800504 * <p>
505 * <ul>
506 * <li>For a touch screen, reports the length of the minor axis of an ellipse that
507 * represents the size of the approaching finger or tool used to make contact.
508 * <li>For a touch pad, reports the length of the minor axis of an ellipse that
509 * represents the size of the approaching finger or tool used to make contact.
510 * The units are device-dependent; use {@link InputDevice#getMotionRange(int)}
511 * to query the effective range of values.
512 * </ul>
513 * </p><p>
514 * When the touch is circular, the major and minor axis lengths will be equal to one another.
515 * </p><p>
516 * The tool size may be larger than the touch size since the tool may not be fully
517 * in contact with the touch sensor.
518 * </p>
Jeff Brown91c69ab2011-02-14 17:03:18 -0800519 *
520 * @see #getToolMinor(int)
521 * @see #getHistoricalToolMinor(int, int)
522 * @see MotionEvent.PointerCoords#toolMinor
523 * @see InputDevice#getMotionRange
524 */
525 public static final int AXIS_TOOL_MINOR = 7;
526
527 /**
528 * Constant used to identify the Orientation axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800529 * <p>
530 * <ul>
531 * <li>For a touch screen or touch pad, reports the orientation of the finger
532 * or tool in radians relative to the vertical plane of the device.
533 * An angle of 0 radians indicates that the major axis of contact is oriented
Jeff Brown91c69ab2011-02-14 17:03:18 -0800534 * upwards, is perfectly circular or is of unknown orientation. A positive angle
535 * indicates that the major axis of contact is oriented to the right. A negative angle
536 * indicates that the major axis of contact is oriented to the left.
537 * The full range is from -PI/2 radians (finger pointing fully left) to PI/2 radians
538 * (finger pointing fully right).
Jeff Brown6f2fba42011-02-19 01:08:02 -0800539 * </ul>
540 * </p>
Jeff Brown91c69ab2011-02-14 17:03:18 -0800541 *
542 * @see #getOrientation(int)
543 * @see #getHistoricalOrientation(int, int)
544 * @see MotionEvent.PointerCoords#orientation
545 * @see InputDevice#getMotionRange
546 */
547 public static final int AXIS_ORIENTATION = 8;
548
Jeff Brown6f2fba42011-02-19 01:08:02 -0800549 /**
550 * Constant used to identify the Vertical Scroll axis of a motion event.
551 * <p>
552 * <ul>
Jeff Browncc0c1592011-02-19 05:07:28 -0800553 * <li>For a mouse, reports the relative movement of the vertical scroll wheel.
Jeff Brown33bbfd22011-02-24 20:55:35 -0800554 * The value is normalized to a range from -1.0 (down) to 1.0 (up).
Jeff Brown6f2fba42011-02-19 01:08:02 -0800555 * </ul>
556 * </p><p>
557 * This axis should be used to scroll views vertically.
558 * </p>
559 *
560 * @see #getAxisValue(int, int)
561 * @see #getHistoricalAxisValue(int, int, int)
562 * @see MotionEvent.PointerCoords#getAxisValue(int)
563 * @see InputDevice#getMotionRange
564 */
565 public static final int AXIS_VSCROLL = 9;
566
567 /**
568 * Constant used to identify the Horizontal Scroll axis of a motion event.
569 * <p>
570 * <ul>
Jeff Browncc0c1592011-02-19 05:07:28 -0800571 * <li>For a mouse, reports the relative movement of the horizontal scroll wheel.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800572 * The value is normalized to a range from -1.0 (left) to 1.0 (right).
573 * </ul>
574 * </p><p>
575 * This axis should be used to scroll views horizontally.
576 * </p>
577 *
578 * @see #getAxisValue(int, int)
579 * @see #getHistoricalAxisValue(int, int, int)
580 * @see MotionEvent.PointerCoords#getAxisValue(int)
581 * @see InputDevice#getMotionRange
582 */
583 public static final int AXIS_HSCROLL = 10;
584
585 /**
586 * Constant used to identify the Z axis of a motion event.
587 * <p>
588 * <ul>
589 * <li>For a joystick, reports the absolute Z position of the joystick.
590 * The value is normalized to a range from -1.0 (high) to 1.0 (low).
591 * <em>On game pads with two analog joysticks, this axis is often reinterpreted
592 * to report the absolute X position of the second joystick instead.</em>
593 * </ul>
594 * </p>
595 *
596 * @see #getAxisValue(int, int)
597 * @see #getHistoricalAxisValue(int, int, int)
598 * @see MotionEvent.PointerCoords#getAxisValue(int)
599 * @see InputDevice#getMotionRange
600 */
601 public static final int AXIS_Z = 11;
602
603 /**
604 * Constant used to identify the X Rotation axis of a motion event.
605 * <p>
606 * <ul>
607 * <li>For a joystick, reports the absolute rotation angle about the X axis.
608 * The value is normalized to a range from -1.0 (counter-clockwise) to 1.0 (clockwise).
609 * </ul>
610 * </p>
611 *
612 * @see #getAxisValue(int, int)
613 * @see #getHistoricalAxisValue(int, int, int)
614 * @see MotionEvent.PointerCoords#getAxisValue(int)
615 * @see InputDevice#getMotionRange
616 */
617 public static final int AXIS_RX = 12;
618
619 /**
620 * Constant used to identify the Y Rotation axis of a motion event.
621 * <p>
622 * <ul>
623 * <li>For a joystick, reports the absolute rotation angle about the Y axis.
624 * The value is normalized to a range from -1.0 (counter-clockwise) to 1.0 (clockwise).
625 * </ul>
626 * </p>
627 *
628 * @see #getAxisValue(int, int)
629 * @see #getHistoricalAxisValue(int, int, int)
630 * @see MotionEvent.PointerCoords#getAxisValue(int)
631 * @see InputDevice#getMotionRange
632 */
633 public static final int AXIS_RY = 13;
634
635 /**
636 * Constant used to identify the Z Rotation axis of a motion event.
637 * <p>
638 * <ul>
639 * <li>For a joystick, reports the absolute rotation angle about the Z axis.
640 * The value is normalized to a range from -1.0 (counter-clockwise) to 1.0 (clockwise).
641 * <em>On game pads with two analog joysticks, this axis is often reinterpreted
642 * to report the absolute Y position of the second joystick instead.</em>
643 * </ul>
644 * </p>
645 *
646 * @see #getAxisValue(int, int)
647 * @see #getHistoricalAxisValue(int, int, int)
648 * @see MotionEvent.PointerCoords#getAxisValue(int)
649 * @see InputDevice#getMotionRange
650 */
651 public static final int AXIS_RZ = 14;
652
653 /**
654 * Constant used to identify the Hat X axis of a motion event.
655 * <p>
656 * <ul>
657 * <li>For a joystick, reports the absolute X position of the directional hat control.
658 * The value is normalized to a range from -1.0 (left) to 1.0 (right).
659 * </ul>
660 * </p>
661 *
662 * @see #getAxisValue(int, int)
663 * @see #getHistoricalAxisValue(int, int, int)
664 * @see MotionEvent.PointerCoords#getAxisValue(int)
665 * @see InputDevice#getMotionRange
666 */
667 public static final int AXIS_HAT_X = 15;
668
669 /**
670 * Constant used to identify the Hat Y axis of a motion event.
671 * <p>
672 * <ul>
673 * <li>For a joystick, reports the absolute Y position of the directional hat control.
674 * The value is normalized to a range from -1.0 (up) to 1.0 (down).
675 * </ul>
676 * </p>
677 *
678 * @see #getAxisValue(int, int)
679 * @see #getHistoricalAxisValue(int, int, int)
680 * @see MotionEvent.PointerCoords#getAxisValue(int)
681 * @see InputDevice#getMotionRange
682 */
683 public static final int AXIS_HAT_Y = 16;
684
685 /**
686 * Constant used to identify the Left Trigger axis of a motion event.
687 * <p>
688 * <ul>
689 * <li>For a joystick, reports the absolute position of the left trigger control.
690 * The value is normalized to a range from 0.0 (released) to 1.0 (fully pressed).
691 * </ul>
692 * </p>
693 *
694 * @see #getAxisValue(int, int)
695 * @see #getHistoricalAxisValue(int, int, int)
696 * @see MotionEvent.PointerCoords#getAxisValue(int)
697 * @see InputDevice#getMotionRange
698 */
699 public static final int AXIS_LTRIGGER = 17;
700
701 /**
702 * Constant used to identify the Right Trigger axis of a motion event.
703 * <p>
704 * <ul>
705 * <li>For a joystick, reports the absolute position of the right trigger control.
706 * The value is normalized to a range from 0.0 (released) to 1.0 (fully pressed).
707 * </ul>
708 * </p>
709 *
710 * @see #getAxisValue(int, int)
711 * @see #getHistoricalAxisValue(int, int, int)
712 * @see MotionEvent.PointerCoords#getAxisValue(int)
713 * @see InputDevice#getMotionRange
714 */
715 public static final int AXIS_RTRIGGER = 18;
716
717 /**
Jeff Brown3a22fa02011-03-04 13:07:49 -0800718 * Constant used to identify the Throttle axis of a motion event.
719 * <p>
720 * <ul>
721 * <li>For a joystick, reports the absolute position of the throttle control.
722 * The value is normalized to a range from 0.0 (fully open) to 1.0 (fully closed).
723 * </ul>
724 * </p>
725 *
726 * @see #getAxisValue(int, int)
727 * @see #getHistoricalAxisValue(int, int, int)
728 * @see MotionEvent.PointerCoords#getAxisValue(int)
729 * @see InputDevice#getMotionRange
730 */
731 public static final int AXIS_THROTTLE = 19;
732
733 /**
734 * Constant used to identify the Rudder axis of a motion event.
735 * <p>
736 * <ul>
737 * <li>For a joystick, reports the absolute position of the rudder control.
738 * The value is normalized to a range from -1.0 (turn left) to 1.0 (turn right).
739 * </ul>
740 * </p>
741 *
742 * @see #getAxisValue(int, int)
743 * @see #getHistoricalAxisValue(int, int, int)
744 * @see MotionEvent.PointerCoords#getAxisValue(int)
745 * @see InputDevice#getMotionRange
746 */
747 public static final int AXIS_RUDDER = 20;
748
749 /**
750 * Constant used to identify the Wheel axis of a motion event.
751 * <p>
752 * <ul>
753 * <li>For a joystick, reports the absolute position of the steering wheel control.
754 * The value is normalized to a range from -1.0 (turn left) to 1.0 (turn right).
755 * </ul>
756 * </p>
757 *
758 * @see #getAxisValue(int, int)
759 * @see #getHistoricalAxisValue(int, int, int)
760 * @see MotionEvent.PointerCoords#getAxisValue(int)
761 * @see InputDevice#getMotionRange
762 */
763 public static final int AXIS_WHEEL = 21;
764
765 /**
766 * Constant used to identify the Gas axis of a motion event.
767 * <p>
768 * <ul>
769 * <li>For a joystick, reports the absolute position of the gas (accelerator) control.
770 * The value is normalized to a range from 0.0 (no acceleration)
771 * to 1.0 (maximum acceleration).
772 * </ul>
773 * </p>
774 *
775 * @see #getAxisValue(int, int)
776 * @see #getHistoricalAxisValue(int, int, int)
777 * @see MotionEvent.PointerCoords#getAxisValue(int)
778 * @see InputDevice#getMotionRange
779 */
780 public static final int AXIS_GAS = 22;
781
782 /**
783 * Constant used to identify the Brake axis of a motion event.
784 * <p>
785 * <ul>
786 * <li>For a joystick, reports the absolute position of the brake control.
787 * The value is normalized to a range from 0.0 (no braking) to 1.0 (maximum braking).
788 * </ul>
789 * </p>
790 *
791 * @see #getAxisValue(int, int)
792 * @see #getHistoricalAxisValue(int, int, int)
793 * @see MotionEvent.PointerCoords#getAxisValue(int)
794 * @see InputDevice#getMotionRange
795 */
796 public static final int AXIS_BRAKE = 23;
797
798 /**
Jeff Brown6f2fba42011-02-19 01:08:02 -0800799 * Constant used to identify the Generic 1 axis of a motion event.
800 * The interpretation of a generic axis is device-specific.
801 *
802 * @see #getAxisValue(int, int)
803 * @see #getHistoricalAxisValue(int, int, int)
804 * @see MotionEvent.PointerCoords#getAxisValue(int)
805 * @see InputDevice#getMotionRange
806 */
807 public static final int AXIS_GENERIC_1 = 32;
808
809 /**
810 * Constant used to identify the Generic 2 axis of a motion event.
811 * The interpretation of a generic axis is device-specific.
812 *
813 * @see #getAxisValue(int, int)
814 * @see #getHistoricalAxisValue(int, int, int)
815 * @see MotionEvent.PointerCoords#getAxisValue(int)
816 * @see InputDevice#getMotionRange
817 */
818 public static final int AXIS_GENERIC_2 = 33;
819
820 /**
821 * Constant used to identify the Generic 3 axis of a motion event.
822 * The interpretation of a generic axis is device-specific.
823 *
824 * @see #getAxisValue(int, int)
825 * @see #getHistoricalAxisValue(int, int, int)
826 * @see MotionEvent.PointerCoords#getAxisValue(int)
827 * @see InputDevice#getMotionRange
828 */
829 public static final int AXIS_GENERIC_3 = 34;
830
831 /**
832 * Constant used to identify the Generic 4 axis of a motion event.
833 * The interpretation of a generic axis is device-specific.
834 *
835 * @see #getAxisValue(int, int)
836 * @see #getHistoricalAxisValue(int, int, int)
837 * @see MotionEvent.PointerCoords#getAxisValue(int)
838 * @see InputDevice#getMotionRange
839 */
840 public static final int AXIS_GENERIC_4 = 35;
841
842 /**
843 * Constant used to identify the Generic 5 axis of a motion event.
844 * The interpretation of a generic axis is device-specific.
845 *
846 * @see #getAxisValue(int, int)
847 * @see #getHistoricalAxisValue(int, int, int)
848 * @see MotionEvent.PointerCoords#getAxisValue(int)
849 * @see InputDevice#getMotionRange
850 */
851 public static final int AXIS_GENERIC_5 = 36;
852
853 /**
854 * Constant used to identify the Generic 6 axis of a motion event.
855 * The interpretation of a generic axis is device-specific.
856 *
857 * @see #getAxisValue(int, int)
858 * @see #getHistoricalAxisValue(int, int, int)
859 * @see MotionEvent.PointerCoords#getAxisValue(int)
860 * @see InputDevice#getMotionRange
861 */
862 public static final int AXIS_GENERIC_6 = 37;
863
864 /**
865 * Constant used to identify the Generic 7 axis of a motion event.
866 * The interpretation of a generic axis is device-specific.
867 *
868 * @see #getAxisValue(int, int)
869 * @see #getHistoricalAxisValue(int, int, int)
870 * @see MotionEvent.PointerCoords#getAxisValue(int)
871 * @see InputDevice#getMotionRange
872 */
873 public static final int AXIS_GENERIC_7 = 38;
874
875 /**
876 * Constant used to identify the Generic 8 axis of a motion event.
877 * The interpretation of a generic axis is device-specific.
878 *
879 * @see #getAxisValue(int, int)
880 * @see #getHistoricalAxisValue(int, int, int)
881 * @see MotionEvent.PointerCoords#getAxisValue(int)
882 * @see InputDevice#getMotionRange
883 */
884 public static final int AXIS_GENERIC_8 = 39;
885
886 /**
887 * Constant used to identify the Generic 9 axis of a motion event.
888 * The interpretation of a generic axis is device-specific.
889 *
890 * @see #getAxisValue(int, int)
891 * @see #getHistoricalAxisValue(int, int, int)
892 * @see MotionEvent.PointerCoords#getAxisValue(int)
893 * @see InputDevice#getMotionRange
894 */
895 public static final int AXIS_GENERIC_9 = 40;
896
897 /**
898 * Constant used to identify the Generic 10 axis of a motion event.
899 * The interpretation of a generic axis is device-specific.
900 *
901 * @see #getAxisValue(int, int)
902 * @see #getHistoricalAxisValue(int, int, int)
903 * @see MotionEvent.PointerCoords#getAxisValue(int)
904 * @see InputDevice#getMotionRange
905 */
906 public static final int AXIS_GENERIC_10 = 41;
907
908 /**
909 * Constant used to identify the Generic 11 axis of a motion event.
910 * The interpretation of a generic axis is device-specific.
911 *
912 * @see #getAxisValue(int, int)
913 * @see #getHistoricalAxisValue(int, int, int)
914 * @see MotionEvent.PointerCoords#getAxisValue(int)
915 * @see InputDevice#getMotionRange
916 */
917 public static final int AXIS_GENERIC_11 = 42;
918
919 /**
920 * Constant used to identify the Generic 12 axis of a motion event.
921 * The interpretation of a generic axis is device-specific.
922 *
923 * @see #getAxisValue(int, int)
924 * @see #getHistoricalAxisValue(int, int, int)
925 * @see MotionEvent.PointerCoords#getAxisValue(int)
926 * @see InputDevice#getMotionRange
927 */
928 public static final int AXIS_GENERIC_12 = 43;
929
930 /**
931 * Constant used to identify the Generic 13 axis of a motion event.
932 * The interpretation of a generic axis is device-specific.
933 *
934 * @see #getAxisValue(int, int)
935 * @see #getHistoricalAxisValue(int, int, int)
936 * @see MotionEvent.PointerCoords#getAxisValue(int)
937 * @see InputDevice#getMotionRange
938 */
939 public static final int AXIS_GENERIC_13 = 44;
940
941 /**
942 * Constant used to identify the Generic 14 axis of a motion event.
943 * The interpretation of a generic axis is device-specific.
944 *
945 * @see #getAxisValue(int, int)
946 * @see #getHistoricalAxisValue(int, int, int)
947 * @see MotionEvent.PointerCoords#getAxisValue(int)
948 * @see InputDevice#getMotionRange
949 */
950 public static final int AXIS_GENERIC_14 = 45;
951
952 /**
953 * Constant used to identify the Generic 15 axis of a motion event.
954 * The interpretation of a generic axis is device-specific.
955 *
956 * @see #getAxisValue(int, int)
957 * @see #getHistoricalAxisValue(int, int, int)
958 * @see MotionEvent.PointerCoords#getAxisValue(int)
959 * @see InputDevice#getMotionRange
960 */
961 public static final int AXIS_GENERIC_15 = 46;
962
963 /**
964 * Constant used to identify the Generic 16 axis of a motion event.
965 * The interpretation of a generic axis is device-specific.
966 *
967 * @see #getAxisValue(int, int)
968 * @see #getHistoricalAxisValue(int, int, int)
969 * @see MotionEvent.PointerCoords#getAxisValue(int)
970 * @see InputDevice#getMotionRange
971 */
972 public static final int AXIS_GENERIC_16 = 47;
973
974 // NOTE: If you add a new axis here you must also add it to:
975 // native/include/android/input.h
976 // frameworks/base/include/ui/KeycodeLabels.h
977
978 // Symbolic names of all axes.
979 private static final SparseArray<String> AXIS_SYMBOLIC_NAMES = new SparseArray<String>();
980 private static void populateAxisSymbolicNames() {
981 SparseArray<String> names = AXIS_SYMBOLIC_NAMES;
982 names.append(AXIS_X, "AXIS_X");
983 names.append(AXIS_Y, "AXIS_Y");
984 names.append(AXIS_PRESSURE, "AXIS_PRESSURE");
985 names.append(AXIS_SIZE, "AXIS_SIZE");
986 names.append(AXIS_TOUCH_MAJOR, "AXIS_TOUCH_MAJOR");
987 names.append(AXIS_TOUCH_MINOR, "AXIS_TOUCH_MINOR");
988 names.append(AXIS_TOOL_MAJOR, "AXIS_TOOL_MAJOR");
989 names.append(AXIS_TOOL_MINOR, "AXIS_TOOL_MINOR");
990 names.append(AXIS_ORIENTATION, "AXIS_ORIENTATION");
991 names.append(AXIS_VSCROLL, "AXIS_VSCROLL");
992 names.append(AXIS_HSCROLL, "AXIS_HSCROLL");
993 names.append(AXIS_Z, "AXIS_Z");
994 names.append(AXIS_RX, "AXIS_RX");
995 names.append(AXIS_RY, "AXIS_RY");
996 names.append(AXIS_RZ, "AXIS_RZ");
997 names.append(AXIS_HAT_X, "AXIS_HAT_X");
998 names.append(AXIS_HAT_Y, "AXIS_HAT_Y");
999 names.append(AXIS_LTRIGGER, "AXIS_LTRIGGER");
1000 names.append(AXIS_RTRIGGER, "AXIS_RTRIGGER");
Jeff Brown3a22fa02011-03-04 13:07:49 -08001001 names.append(AXIS_THROTTLE, "AXIS_THROTTLE");
1002 names.append(AXIS_RUDDER, "AXIS_RUDDER");
1003 names.append(AXIS_WHEEL, "AXIS_WHEEL");
1004 names.append(AXIS_GAS, "AXIS_GAS");
1005 names.append(AXIS_BRAKE, "AXIS_BRAKE");
Jeff Brown6f2fba42011-02-19 01:08:02 -08001006 names.append(AXIS_GENERIC_1, "AXIS_GENERIC_1");
1007 names.append(AXIS_GENERIC_2, "AXIS_GENERIC_2");
1008 names.append(AXIS_GENERIC_3, "AXIS_GENERIC_3");
1009 names.append(AXIS_GENERIC_4, "AXIS_GENERIC_4");
1010 names.append(AXIS_GENERIC_5, "AXIS_GENERIC_5");
1011 names.append(AXIS_GENERIC_6, "AXIS_GENERIC_6");
1012 names.append(AXIS_GENERIC_7, "AXIS_GENERIC_7");
1013 names.append(AXIS_GENERIC_8, "AXIS_GENERIC_8");
1014 names.append(AXIS_GENERIC_9, "AXIS_GENERIC_9");
1015 names.append(AXIS_GENERIC_10, "AXIS_GENERIC_10");
1016 names.append(AXIS_GENERIC_11, "AXIS_GENERIC_11");
1017 names.append(AXIS_GENERIC_12, "AXIS_GENERIC_12");
1018 names.append(AXIS_GENERIC_13, "AXIS_GENERIC_13");
1019 names.append(AXIS_GENERIC_14, "AXIS_GENERIC_14");
1020 names.append(AXIS_GENERIC_15, "AXIS_GENERIC_15");
1021 names.append(AXIS_GENERIC_16, "AXIS_GENERIC_16");
1022 }
1023
1024 static {
1025 populateAxisSymbolicNames();
1026 }
1027
Jeff Brown91c69ab2011-02-14 17:03:18 -08001028 // Private value for history pos that obtains the current sample.
1029 private static final int HISTORY_CURRENT = -0x80000000;
1030
Jeff Brown1f245102010-11-18 20:53:46 -08001031 private static final int MAX_RECYCLED = 10;
1032 private static final Object gRecyclerLock = new Object();
1033 private static int gRecyclerUsed;
1034 private static MotionEvent gRecyclerTop;
Romain Guycafdea62009-06-12 10:51:36 -07001035
Jeff Brown91c69ab2011-02-14 17:03:18 -08001036 // Shared temporary objects used when translating coordinates supplied by
1037 // the caller into single element PointerCoords and pointer id arrays.
1038 // Must lock gTmpPointerCoords prior to use.
1039 private static final PointerCoords[] gTmpPointerCoords =
1040 new PointerCoords[] { new PointerCoords() };
1041 private static final int[] gTmpPointerIds = new int[] { 0 /*always 0*/ };
1042
1043 // Pointer to the native MotionEvent object that contains the actual data.
1044 private int mNativePtr;
Mitsuru Oshima8169dae2009-04-28 18:12:09 -07001045
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001046 private MotionEvent mNext;
1047 private RuntimeException mRecycledLocation;
1048 private boolean mRecycled;
1049
Jeff Brown91c69ab2011-02-14 17:03:18 -08001050 private static native int nativeInitialize(int nativePtr,
1051 int deviceId, int source, int action, int flags, int edgeFlags, int metaState,
1052 float xOffset, float yOffset, float xPrecision, float yPrecision,
1053 long downTimeNanos, long eventTimeNanos,
1054 int pointerCount, int[] pointerIds, PointerCoords[] pointerCoords);
1055 private static native int nativeCopy(int destNativePtr, int sourceNativePtr,
1056 boolean keepHistory);
1057 private static native void nativeDispose(int nativePtr);
1058 private static native void nativeAddBatch(int nativePtr, long eventTimeNanos,
1059 PointerCoords[] pointerCoords, int metaState);
Jeff Brown20e987b2010-08-23 12:01:02 -07001060
Jeff Brown91c69ab2011-02-14 17:03:18 -08001061 private static native int nativeGetDeviceId(int nativePtr);
1062 private static native int nativeGetSource(int nativePtr);
1063 private static native int nativeSetSource(int nativePtr, int source);
1064 private static native int nativeGetAction(int nativePtr);
1065 private static native void nativeSetAction(int nativePtr, int action);
Jeff Brown56194eb2011-03-02 19:23:13 -08001066 private static native boolean nativeIsTouchEvent(int nativePtr);
Jeff Brown91c69ab2011-02-14 17:03:18 -08001067 private static native int nativeGetFlags(int nativePtr);
Jeff Brown21bc5c92011-02-28 18:27:14 -08001068 private static native void nativeSetFlags(int nativePtr, int flags);
Jeff Brown91c69ab2011-02-14 17:03:18 -08001069 private static native int nativeGetEdgeFlags(int nativePtr);
1070 private static native void nativeSetEdgeFlags(int nativePtr, int action);
1071 private static native int nativeGetMetaState(int nativePtr);
1072 private static native void nativeOffsetLocation(int nativePtr, float deltaX, float deltaY);
1073 private static native float nativeGetXPrecision(int nativePtr);
1074 private static native float nativeGetYPrecision(int nativePtr);
1075 private static native long nativeGetDownTimeNanos(int nativePtr);
1076
1077 private static native int nativeGetPointerCount(int nativePtr);
1078 private static native int nativeGetPointerId(int nativePtr, int pointerIndex);
1079 private static native int nativeFindPointerIndex(int nativePtr, int pointerId);
1080
1081 private static native int nativeGetHistorySize(int nativePtr);
1082 private static native long nativeGetEventTimeNanos(int nativePtr, int historyPos);
1083 private static native float nativeGetRawAxisValue(int nativePtr,
1084 int axis, int pointerIndex, int historyPos);
1085 private static native float nativeGetAxisValue(int nativePtr,
1086 int axis, int pointerIndex, int historyPos);
1087 private static native void nativeGetPointerCoords(int nativePtr,
1088 int pointerIndex, int historyPos, PointerCoords outPointerCoords);
1089
1090 private static native void nativeScale(int nativePtr, float scale);
1091 private static native void nativeTransform(int nativePtr, Matrix matrix);
1092
1093 private static native int nativeReadFromParcel(int nativePtr, Parcel parcel);
1094 private static native void nativeWriteToParcel(int nativePtr, Parcel parcel);
1095
1096 private MotionEvent() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001097 }
Romain Guycafdea62009-06-12 10:51:36 -07001098
Jeff Brown91c69ab2011-02-14 17:03:18 -08001099 @Override
1100 protected void finalize() throws Throwable {
1101 try {
1102 if (mNativePtr != 0) {
1103 nativeDispose(mNativePtr);
1104 mNativePtr = 0;
1105 }
1106 } finally {
1107 super.finalize();
1108 }
1109 }
1110
1111 static private MotionEvent obtain() {
Jeff Brown46b9ac02010-04-22 18:58:52 -07001112 final MotionEvent ev;
1113 synchronized (gRecyclerLock) {
Jeff Brown1f245102010-11-18 20:53:46 -08001114 ev = gRecyclerTop;
1115 if (ev == null) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001116 return new MotionEvent();
Jeff Brown46b9ac02010-04-22 18:58:52 -07001117 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07001118 gRecyclerTop = ev.mNext;
Jeff Brown5c225b12010-06-16 01:53:36 -07001119 gRecyclerUsed -= 1;
Jeff Brown46b9ac02010-04-22 18:58:52 -07001120 }
1121 ev.mRecycledLocation = null;
1122 ev.mRecycled = false;
1123 ev.mNext = null;
Jeff Brown46b9ac02010-04-22 18:58:52 -07001124 return ev;
1125 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08001126
Michael Chan53071d62009-05-13 17:29:48 -07001127 /**
1128 * Create a new MotionEvent, filling in all of the basic values that
1129 * define the motion.
1130 *
1131 * @param downTime The time (in ms) when the user originally pressed down to start
1132 * a stream of position events. This must be obtained from {@link SystemClock#uptimeMillis()}.
Jeff Brownc5ed5912010-07-14 18:48:53 -07001133 * @param eventTime The the time (in ms) when this specific event was generated. This
Michael Chan53071d62009-05-13 17:29:48 -07001134 * must be obtained from {@link SystemClock#uptimeMillis()}.
Jeff Browncc0c1592011-02-19 05:07:28 -08001135 * @param action The kind of action being performed, such as {@link #ACTION_DOWN}.
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001136 * @param pointers The number of points that will be in this event.
Jeff Brownc5ed5912010-07-14 18:48:53 -07001137 * @param pointerIds An array of <em>pointers</em> values providing
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001138 * an identifier for each pointer.
Jeff Brownc5ed5912010-07-14 18:48:53 -07001139 * @param pointerCoords An array of <em>pointers</em> values providing
1140 * a {@link PointerCoords} coordinate object for each pointer.
Michael Chan53071d62009-05-13 17:29:48 -07001141 * @param metaState The state of any meta / modifier keys that were in effect when
1142 * the event was generated.
1143 * @param xPrecision The precision of the X coordinate being reported.
1144 * @param yPrecision The precision of the Y coordinate being reported.
1145 * @param deviceId The id for the device that this event came from. An id of
1146 * zero indicates that the event didn't come from a physical device; other
1147 * numbers are arbitrary and you shouldn't depend on the values.
Jeff Brown85a31762010-09-01 17:01:00 -07001148 * @param edgeFlags A bitfield indicating which edges, if any, were touched by this
Michael Chan53071d62009-05-13 17:29:48 -07001149 * MotionEvent.
Jeff Brownc5ed5912010-07-14 18:48:53 -07001150 * @param source The source of this event.
Jeff Brown85a31762010-09-01 17:01:00 -07001151 * @param flags The motion event flags.
Michael Chan53071d62009-05-13 17:29:48 -07001152 */
Jeff Brownc5ed5912010-07-14 18:48:53 -07001153 static public MotionEvent obtain(long downTime, long eventTime,
1154 int action, int pointers, int[] pointerIds, PointerCoords[] pointerCoords,
1155 int metaState, float xPrecision, float yPrecision, int deviceId,
Jeff Brown85a31762010-09-01 17:01:00 -07001156 int edgeFlags, int source, int flags) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001157 MotionEvent ev = obtain();
1158 ev.mNativePtr = nativeInitialize(ev.mNativePtr,
1159 deviceId, source, action, flags, edgeFlags, metaState,
1160 0, 0, xPrecision, yPrecision,
1161 downTime * NS_PER_MS, eventTime * NS_PER_MS,
1162 pointers, pointerIds, pointerCoords);
Michael Chan53071d62009-05-13 17:29:48 -07001163 return ev;
1164 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08001165
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001166 /**
1167 * Create a new MotionEvent, filling in all of the basic values that
1168 * define the motion.
Romain Guycafdea62009-06-12 10:51:36 -07001169 *
1170 * @param downTime The time (in ms) when the user originally pressed down to start
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001171 * a stream of position events. This must be obtained from {@link SystemClock#uptimeMillis()}.
Romain Guycafdea62009-06-12 10:51:36 -07001172 * @param eventTime The the time (in ms) when this specific event was generated. This
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001173 * must be obtained from {@link SystemClock#uptimeMillis()}.
Jeff Browncc0c1592011-02-19 05:07:28 -08001174 * @param action The kind of action being performed, such as {@link #ACTION_DOWN}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001175 * @param x The X coordinate of this event.
1176 * @param y The Y coordinate of this event.
Romain Guycafdea62009-06-12 10:51:36 -07001177 * @param pressure The current pressure of this event. The pressure generally
1178 * ranges from 0 (no pressure at all) to 1 (normal pressure), however
1179 * values higher than 1 may be generated depending on the calibration of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001180 * the input device.
1181 * @param size A scaled value of the approximate size of the area being pressed when
Romain Guycafdea62009-06-12 10:51:36 -07001182 * touched with the finger. The actual value in pixels corresponding to the finger
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001183 * touch is normalized with a device specific range of values
1184 * and scaled to a value between 0 and 1.
1185 * @param metaState The state of any meta / modifier keys that were in effect when
1186 * the event was generated.
1187 * @param xPrecision The precision of the X coordinate being reported.
1188 * @param yPrecision The precision of the Y coordinate being reported.
1189 * @param deviceId The id for the device that this event came from. An id of
1190 * zero indicates that the event didn't come from a physical device; other
1191 * numbers are arbitrary and you shouldn't depend on the values.
Jeff Brown85a31762010-09-01 17:01:00 -07001192 * @param edgeFlags A bitfield indicating which edges, if any, were touched by this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001193 * MotionEvent.
1194 */
1195 static public MotionEvent obtain(long downTime, long eventTime, int action,
1196 float x, float y, float pressure, float size, int metaState,
1197 float xPrecision, float yPrecision, int deviceId, int edgeFlags) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001198 synchronized (gTmpPointerCoords) {
1199 final PointerCoords pc = gTmpPointerCoords[0];
1200 pc.clear();
1201 pc.x = x;
1202 pc.y = y;
1203 pc.pressure = pressure;
1204 pc.size = size;
1205
1206 MotionEvent ev = obtain();
1207 ev.mNativePtr = nativeInitialize(ev.mNativePtr,
1208 deviceId, InputDevice.SOURCE_UNKNOWN, action, 0, edgeFlags, metaState,
1209 0, 0, xPrecision, yPrecision,
1210 downTime * NS_PER_MS, eventTime * NS_PER_MS,
1211 1, gTmpPointerIds, gTmpPointerCoords);
1212 return ev;
1213 }
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001214 }
1215
1216 /**
1217 * Create a new MotionEvent, filling in all of the basic values that
1218 * define the motion.
1219 *
1220 * @param downTime The time (in ms) when the user originally pressed down to start
1221 * a stream of position events. This must be obtained from {@link SystemClock#uptimeMillis()}.
1222 * @param eventTime The the time (in ms) when this specific event was generated. This
1223 * must be obtained from {@link SystemClock#uptimeMillis()}.
Jeff Browncc0c1592011-02-19 05:07:28 -08001224 * @param action The kind of action being performed, such as {@link #ACTION_DOWN}.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001225 * @param pointers The number of pointers that are active in this event.
1226 * @param x The X coordinate of this event.
1227 * @param y The Y coordinate of this event.
1228 * @param pressure The current pressure of this event. The pressure generally
1229 * ranges from 0 (no pressure at all) to 1 (normal pressure), however
1230 * values higher than 1 may be generated depending on the calibration of
1231 * the input device.
1232 * @param size A scaled value of the approximate size of the area being pressed when
1233 * touched with the finger. The actual value in pixels corresponding to the finger
1234 * touch is normalized with a device specific range of values
1235 * and scaled to a value between 0 and 1.
1236 * @param metaState The state of any meta / modifier keys that were in effect when
1237 * the event was generated.
1238 * @param xPrecision The precision of the X coordinate being reported.
1239 * @param yPrecision The precision of the Y coordinate being reported.
1240 * @param deviceId The id for the device that this event came from. An id of
1241 * zero indicates that the event didn't come from a physical device; other
1242 * numbers are arbitrary and you shouldn't depend on the values.
Jeff Brown85a31762010-09-01 17:01:00 -07001243 * @param edgeFlags A bitfield indicating which edges, if any, were touched by this
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001244 * MotionEvent.
Jeff Brown5c225b12010-06-16 01:53:36 -07001245 *
1246 * @deprecated Use {@link #obtain(long, long, int, float, float, float, float, int, float, float, int, int)}
1247 * instead.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001248 */
Jeff Brown5c225b12010-06-16 01:53:36 -07001249 @Deprecated
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001250 static public MotionEvent obtain(long downTime, long eventTime, int action,
1251 int pointers, float x, float y, float pressure, float size, int metaState,
1252 float xPrecision, float yPrecision, int deviceId, int edgeFlags) {
Jeff Brown5c225b12010-06-16 01:53:36 -07001253 return obtain(downTime, eventTime, action, x, y, pressure, size,
1254 metaState, xPrecision, yPrecision, deviceId, edgeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001255 }
Romain Guycafdea62009-06-12 10:51:36 -07001256
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001257 /**
1258 * Create a new MotionEvent, filling in a subset of the basic motion
1259 * values. Those not specified here are: device id (always 0), pressure
1260 * and size (always 1), x and y precision (always 1), and edgeFlags (always 0).
Romain Guycafdea62009-06-12 10:51:36 -07001261 *
1262 * @param downTime The time (in ms) when the user originally pressed down to start
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001263 * a stream of position events. This must be obtained from {@link SystemClock#uptimeMillis()}.
Romain Guycafdea62009-06-12 10:51:36 -07001264 * @param eventTime The the time (in ms) when this specific event was generated. This
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001265 * must be obtained from {@link SystemClock#uptimeMillis()}.
Jeff Browncc0c1592011-02-19 05:07:28 -08001266 * @param action The kind of action being performed, such as {@link #ACTION_DOWN}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001267 * @param x The X coordinate of this event.
1268 * @param y The Y coordinate of this event.
1269 * @param metaState The state of any meta / modifier keys that were in effect when
1270 * the event was generated.
1271 */
1272 static public MotionEvent obtain(long downTime, long eventTime, int action,
1273 float x, float y, int metaState) {
Jeff Brown5c225b12010-06-16 01:53:36 -07001274 return obtain(downTime, eventTime, action, x, y, 1.0f, 1.0f,
1275 metaState, 1.0f, 1.0f, 0, 0);
Mitsuru Oshima8169dae2009-04-28 18:12:09 -07001276 }
1277
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001278 /**
1279 * Create a new MotionEvent, copying from an existing one.
1280 */
Jeff Brown91c69ab2011-02-14 17:03:18 -08001281 static public MotionEvent obtain(MotionEvent other) {
1282 if (other == null) {
1283 throw new IllegalArgumentException("other motion event must not be null");
1284 }
1285
1286 MotionEvent ev = obtain();
1287 ev.mNativePtr = nativeCopy(ev.mNativePtr, other.mNativePtr, true /*keepHistory*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001288 return ev;
1289 }
Romain Guycafdea62009-06-12 10:51:36 -07001290
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001291 /**
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07001292 * Create a new MotionEvent, copying from an existing one, but not including
1293 * any historical point information.
1294 */
Jeff Brown91c69ab2011-02-14 17:03:18 -08001295 static public MotionEvent obtainNoHistory(MotionEvent other) {
1296 if (other == null) {
1297 throw new IllegalArgumentException("other motion event must not be null");
1298 }
1299
1300 MotionEvent ev = obtain();
1301 ev.mNativePtr = nativeCopy(ev.mNativePtr, other.mNativePtr, false /*keepHistory*/);
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07001302 return ev;
1303 }
1304
Jeff Brown21bc5c92011-02-28 18:27:14 -08001305 /** @hide */
1306 @Override
1307 public MotionEvent copy() {
1308 return obtain(this);
1309 }
1310
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07001311 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001312 * Recycle the MotionEvent, to be re-used by a later caller. After calling
1313 * this function you must not ever touch the event again.
1314 */
Jeff Brown5c225b12010-06-16 01:53:36 -07001315 public final void recycle() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001316 // Ensure recycle is only called once!
1317 if (TRACK_RECYCLED_LOCATION) {
1318 if (mRecycledLocation != null) {
1319 throw new RuntimeException(toString() + " recycled twice!", mRecycledLocation);
1320 }
1321 mRecycledLocation = new RuntimeException("Last recycled here");
Jeff Brownd28f4be2010-06-02 15:35:46 -07001322 //Log.w("MotionEvent", "Recycling event " + this, mRecycledLocation);
1323 } else {
1324 if (mRecycled) {
1325 throw new RuntimeException(toString() + " recycled twice!");
1326 }
1327 mRecycled = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001328 }
1329
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001330 synchronized (gRecyclerLock) {
1331 if (gRecyclerUsed < MAX_RECYCLED) {
1332 gRecyclerUsed++;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001333 mNext = gRecyclerTop;
1334 gRecyclerTop = this;
1335 }
1336 }
1337 }
Jeff Brown5c225b12010-06-16 01:53:36 -07001338
1339 /**
1340 * Scales down the coordination of this event by the given scale.
1341 *
1342 * @hide
1343 */
1344 public final void scale(float scale) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001345 nativeScale(mNativePtr, scale);
1346 }
1347
1348 /** {@inheritDoc} */
1349 @Override
1350 public final int getDeviceId() {
1351 return nativeGetDeviceId(mNativePtr);
1352 }
1353
1354 /** {@inheritDoc} */
1355 @Override
1356 public final int getSource() {
1357 return nativeGetSource(mNativePtr);
1358 }
1359
1360 /** {@inheritDoc} */
1361 @Override
1362 public final void setSource(int source) {
1363 nativeSetSource(mNativePtr, source);
Jeff Brown5c225b12010-06-16 01:53:36 -07001364 }
Romain Guycafdea62009-06-12 10:51:36 -07001365
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001366 /**
Jeff Browncc0c1592011-02-19 05:07:28 -08001367 * Return the kind of action being performed.
1368 * Consider using {@link #getActionMasked} and {@link #getActionIndex} to retrieve
1369 * the separate masked action and pointer index.
1370 * @return The action, such as {@link #ACTION_DOWN} or
1371 * the combination of {@link #ACTION_POINTER_DOWN} with a shifted pointer index.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001372 */
1373 public final int getAction() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001374 return nativeGetAction(mNativePtr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001375 }
1376
1377 /**
Jeff Browncc0c1592011-02-19 05:07:28 -08001378 * Return the masked action being performed, without pointer index information.
1379 * Use {@link #getActionIndex} to return the index associated with pointer actions.
1380 * @return The action, such as {@link #ACTION_DOWN} or {@link #ACTION_POINTER_DOWN}.
Dianne Hackbornb125dc52010-02-12 15:52:09 -08001381 */
1382 public final int getActionMasked() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001383 return nativeGetAction(mNativePtr) & ACTION_MASK;
Dianne Hackbornb125dc52010-02-12 15:52:09 -08001384 }
1385
1386 /**
1387 * For {@link #ACTION_POINTER_DOWN} or {@link #ACTION_POINTER_UP}
1388 * as returned by {@link #getActionMasked}, this returns the associated
Jeff Browncc0c1592011-02-19 05:07:28 -08001389 * pointer index.
1390 * The index may be used with {@link #getPointerId(int)},
Dianne Hackbornb125dc52010-02-12 15:52:09 -08001391 * {@link #getX(int)}, {@link #getY(int)}, {@link #getPressure(int)},
1392 * and {@link #getSize(int)} to get information about the pointer that has
1393 * gone down or up.
Jeff Browncc0c1592011-02-19 05:07:28 -08001394 * @return The index associated with the action.
Dianne Hackbornb125dc52010-02-12 15:52:09 -08001395 */
1396 public final int getActionIndex() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001397 return (nativeGetAction(mNativePtr) & ACTION_POINTER_INDEX_MASK)
1398 >> ACTION_POINTER_INDEX_SHIFT;
Dianne Hackbornb125dc52010-02-12 15:52:09 -08001399 }
1400
1401 /**
Jeff Brown33bbfd22011-02-24 20:55:35 -08001402 * Returns true if this motion event is a touch event.
1403 * <p>
Jeff Browna032cc02011-03-07 16:56:21 -08001404 * Specifically excludes pointer events with action {@link #ACTION_HOVER_MOVE},
1405 * {@link #ACTION_HOVER_ENTER}, {@link #ACTION_HOVER_EXIT}, or {@link #ACTION_SCROLL}
1406 * because they are not actually touch events (the pointer is not down).
Jeff Brown33bbfd22011-02-24 20:55:35 -08001407 * </p>
1408 * @return True if this motion event is a touch event.
1409 * @hide
1410 */
1411 public final boolean isTouchEvent() {
Jeff Brown56194eb2011-03-02 19:23:13 -08001412 return nativeIsTouchEvent(mNativePtr);
Jeff Brown33bbfd22011-02-24 20:55:35 -08001413 }
1414
1415 /**
Jeff Brown85a31762010-09-01 17:01:00 -07001416 * Gets the motion event flags.
1417 *
1418 * @see #FLAG_WINDOW_IS_OBSCURED
1419 */
1420 public final int getFlags() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001421 return nativeGetFlags(mNativePtr);
Jeff Brown85a31762010-09-01 17:01:00 -07001422 }
1423
Jeff Brown21bc5c92011-02-28 18:27:14 -08001424 /** @hide */
1425 @Override
1426 public final boolean isTainted() {
1427 final int flags = getFlags();
1428 return (flags & FLAG_TAINTED) != 0;
1429 }
1430
1431 /** @hide */
1432 @Override
1433 public final void setTainted(boolean tainted) {
1434 final int flags = getFlags();
1435 nativeSetFlags(mNativePtr, tainted ? flags | FLAG_TAINTED : flags & ~FLAG_TAINTED);
1436 }
1437
Jeff Brown85a31762010-09-01 17:01:00 -07001438 /**
Romain Guycafdea62009-06-12 10:51:36 -07001439 * Returns the time (in ms) when the user originally pressed down to start
1440 * a stream of position events.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001441 */
1442 public final long getDownTime() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001443 return nativeGetDownTimeNanos(mNativePtr) / NS_PER_MS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001444 }
1445
1446 /**
1447 * Returns the time (in ms) when this specific event was generated.
1448 */
1449 public final long getEventTime() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001450 return nativeGetEventTimeNanos(mNativePtr, HISTORY_CURRENT) / NS_PER_MS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001451 }
1452
1453 /**
Michael Chan53071d62009-05-13 17:29:48 -07001454 * Returns the time (in ns) when this specific event was generated.
1455 * The value is in nanosecond precision but it may not have nanosecond accuracy.
1456 *
1457 * @hide
1458 */
1459 public final long getEventTimeNano() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001460 return nativeGetEventTimeNanos(mNativePtr, HISTORY_CURRENT);
Michael Chan53071d62009-05-13 17:29:48 -07001461 }
1462
1463 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001464 * {@link #getX(int)} for the first pointer index (may be an
1465 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001466 *
1467 * @see #AXIS_X
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001468 */
1469 public final float getX() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001470 return nativeGetAxisValue(mNativePtr, AXIS_X, 0, HISTORY_CURRENT);
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001471 }
1472
1473 /**
1474 * {@link #getY(int)} for the first pointer index (may be an
1475 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001476 *
1477 * @see #AXIS_Y
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001478 */
1479 public final float getY() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001480 return nativeGetAxisValue(mNativePtr, AXIS_Y, 0, HISTORY_CURRENT);
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001481 }
1482
1483 /**
1484 * {@link #getPressure(int)} for the first pointer index (may be an
1485 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001486 *
1487 * @see #AXIS_PRESSURE
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001488 */
1489 public final float getPressure() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001490 return nativeGetAxisValue(mNativePtr, AXIS_PRESSURE, 0, HISTORY_CURRENT);
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001491 }
1492
1493 /**
1494 * {@link #getSize(int)} for the first pointer index (may be an
1495 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001496 *
1497 * @see #AXIS_SIZE
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001498 */
1499 public final float getSize() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001500 return nativeGetAxisValue(mNativePtr, AXIS_SIZE, 0, HISTORY_CURRENT);
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001501 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07001502
1503 /**
1504 * {@link #getTouchMajor(int)} for the first pointer index (may be an
1505 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001506 *
1507 * @see #AXIS_TOUCH_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07001508 */
1509 public final float getTouchMajor() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001510 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MAJOR, 0, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001511 }
1512
1513 /**
1514 * {@link #getTouchMinor(int)} for the first pointer index (may be an
1515 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001516 *
1517 * @see #AXIS_TOUCH_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07001518 */
1519 public final float getTouchMinor() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001520 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MINOR, 0, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001521 }
1522
1523 /**
1524 * {@link #getToolMajor(int)} for the first pointer index (may be an
1525 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001526 *
1527 * @see #AXIS_TOOL_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07001528 */
1529 public final float getToolMajor() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001530 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MAJOR, 0, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001531 }
1532
1533 /**
1534 * {@link #getToolMinor(int)} for the first pointer index (may be an
1535 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001536 *
1537 * @see #AXIS_TOOL_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07001538 */
1539 public final float getToolMinor() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001540 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MINOR, 0, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001541 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08001542
Jeff Brownc5ed5912010-07-14 18:48:53 -07001543 /**
1544 * {@link #getOrientation(int)} for the first pointer index (may be an
1545 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001546 *
1547 * @see #AXIS_ORIENTATION
Jeff Brownc5ed5912010-07-14 18:48:53 -07001548 */
1549 public final float getOrientation() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001550 return nativeGetAxisValue(mNativePtr, AXIS_ORIENTATION, 0, HISTORY_CURRENT);
1551 }
1552
1553 /**
1554 * {@link #getAxisValue(int)} for the first pointer index (may be an
1555 * arbitrary pointer identifier).
1556 *
1557 * @param axis The axis identifier for the axis value to retrieve.
1558 *
1559 * @see #AXIS_X
1560 * @see #AXIS_Y
1561 */
1562 public final float getAxisValue(int axis) {
1563 return nativeGetAxisValue(mNativePtr, axis, 0, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001564 }
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001565
1566 /**
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001567 * The number of pointers of data contained in this event. Always
1568 * >= 1.
1569 */
1570 public final int getPointerCount() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001571 return nativeGetPointerCount(mNativePtr);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001572 }
1573
1574 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001575 * Return the pointer identifier associated with a particular pointer
1576 * data index is this event. The identifier tells you the actual pointer
1577 * number associated with the data, accounting for individual pointers
1578 * going up and down since the start of the current gesture.
1579 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1580 * (the first pointer that is down) to {@link #getPointerCount()}-1.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001581 */
Dianne Hackbornd41ba662009-08-05 15:30:56 -07001582 public final int getPointerId(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001583 return nativeGetPointerId(mNativePtr, pointerIndex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001584 }
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001585
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001586 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001587 * Given a pointer identifier, find the index of its data in the event.
1588 *
1589 * @param pointerId The identifier of the pointer to be found.
1590 * @return Returns either the index of the pointer (for use with
Gilles Debunneb0d6ba12010-08-17 20:01:42 -07001591 * {@link #getX(int)} et al.), or -1 if there is no data available for
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001592 * that pointer identifier.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001593 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001594 public final int findPointerIndex(int pointerId) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001595 return nativeFindPointerIndex(mNativePtr, pointerId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001596 }
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001597
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001598 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001599 * Returns the X coordinate of this event for the given pointer
1600 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
1601 * identifier for this index).
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001602 * Whole numbers are pixels; the
1603 * value may have a fraction for input devices that are sub-pixel precise.
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001604 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1605 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08001606 *
1607 * @see #AXIS_X
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001608 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001609 public final float getX(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001610 return nativeGetAxisValue(mNativePtr, AXIS_X, pointerIndex, HISTORY_CURRENT);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001611 }
1612
1613 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001614 * Returns the Y coordinate of this event for the given pointer
1615 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
1616 * identifier for this index).
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001617 * Whole numbers are pixels; the
1618 * value may have a fraction for input devices that are sub-pixel precise.
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001619 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1620 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08001621 *
1622 * @see #AXIS_Y
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001623 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001624 public final float getY(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001625 return nativeGetAxisValue(mNativePtr, AXIS_Y, pointerIndex, HISTORY_CURRENT);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001626 }
1627
1628 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001629 * Returns the current pressure of this event for the given pointer
1630 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
1631 * identifier for this index).
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001632 * The pressure generally
Romain Guycafdea62009-06-12 10:51:36 -07001633 * ranges from 0 (no pressure at all) to 1 (normal pressure), however
1634 * values higher than 1 may be generated depending on the calibration of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001635 * the input device.
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001636 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1637 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08001638 *
1639 * @see #AXIS_PRESSURE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001640 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001641 public final float getPressure(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001642 return nativeGetAxisValue(mNativePtr, AXIS_PRESSURE, pointerIndex, HISTORY_CURRENT);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001643 }
1644
1645 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001646 * Returns a scaled value of the approximate size for the given pointer
1647 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
1648 * identifier for this index).
1649 * This represents some approximation of the area of the screen being
1650 * pressed; the actual value in pixels corresponding to the
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001651 * touch is normalized with the device specific range of values
Romain Guycafdea62009-06-12 10:51:36 -07001652 * 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 -08001653 * determine fat touch events.
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001654 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1655 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08001656 *
1657 * @see #AXIS_SIZE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001658 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001659 public final float getSize(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001660 return nativeGetAxisValue(mNativePtr, AXIS_SIZE, pointerIndex, HISTORY_CURRENT);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001661 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07001662
1663 /**
1664 * Returns the length of the major axis of an ellipse that describes the touch
1665 * area at the point of contact for the given pointer
1666 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
1667 * identifier for this index).
1668 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1669 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08001670 *
1671 * @see #AXIS_TOUCH_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07001672 */
1673 public final float getTouchMajor(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001674 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MAJOR, pointerIndex, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001675 }
1676
1677 /**
1678 * Returns the length of the minor axis of an ellipse that describes the touch
1679 * area at the point of contact for the given pointer
1680 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
1681 * identifier for this index).
1682 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1683 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08001684 *
1685 * @see #AXIS_TOUCH_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07001686 */
1687 public final float getTouchMinor(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001688 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MINOR, pointerIndex, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001689 }
1690
1691 /**
1692 * Returns the length of the major axis of an ellipse that describes the size of
1693 * the approaching tool for the given pointer
1694 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
1695 * identifier for this index).
1696 * The tool area represents the estimated size of the finger or pen that is
1697 * touching the device independent of its actual touch area at the point of contact.
1698 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1699 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08001700 *
1701 * @see #AXIS_TOOL_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07001702 */
1703 public final float getToolMajor(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001704 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MAJOR, pointerIndex, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001705 }
1706
1707 /**
1708 * Returns the length of the minor axis of an ellipse that describes the size of
1709 * the approaching tool for the given pointer
1710 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
1711 * identifier for this index).
1712 * The tool area represents the estimated size of the finger or pen that is
1713 * touching the device independent of its actual touch area at the point of contact.
1714 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1715 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08001716 *
1717 * @see #AXIS_TOOL_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07001718 */
1719 public final float getToolMinor(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001720 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MINOR, pointerIndex, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001721 }
1722
1723 /**
1724 * Returns the orientation of the touch area and tool area in radians clockwise from vertical
1725 * for the given pointer <em>index</em> (use {@link #getPointerId(int)} to find the pointer
1726 * identifier for this index).
Jeff Brown6f2fba42011-02-19 01:08:02 -08001727 * An angle of 0 radians indicates that the major axis of contact is oriented
Jeff Brownc5ed5912010-07-14 18:48:53 -07001728 * upwards, is perfectly circular or is of unknown orientation. A positive angle
1729 * indicates that the major axis of contact is oriented to the right. A negative angle
1730 * indicates that the major axis of contact is oriented to the left.
Jeff Brown6d0fec22010-07-23 21:28:06 -07001731 * The full range is from -PI/2 radians (finger pointing fully left) to PI/2 radians
Jeff Brownc5ed5912010-07-14 18:48:53 -07001732 * (finger pointing fully right).
1733 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1734 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08001735 *
1736 * @see #AXIS_ORIENTATION
Jeff Brownc5ed5912010-07-14 18:48:53 -07001737 */
1738 public final float getOrientation(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001739 return nativeGetAxisValue(mNativePtr, AXIS_ORIENTATION, pointerIndex, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001740 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08001741
1742 /**
1743 * Returns the value of the requested axis for the given pointer <em>index</em>
1744 * (use {@link #getPointerId(int)} to find the pointer identifier for this index).
1745 *
1746 * @param axis The axis identifier for the axis value to retrieve.
1747 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1748 * (the first pointer that is down) to {@link #getPointerCount()}-1.
1749 * @return The value of the axis, or 0 if the axis is not available.
1750 *
1751 * @see #AXIS_X
1752 * @see #AXIS_Y
1753 */
1754 public final float getAxisValue(int axis, int pointerIndex) {
1755 return nativeGetAxisValue(mNativePtr, axis, pointerIndex, HISTORY_CURRENT);
1756 }
1757
Jeff Brownc5ed5912010-07-14 18:48:53 -07001758 /**
1759 * Populates a {@link PointerCoords} object with pointer coordinate data for
1760 * the specified pointer index.
1761 *
1762 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1763 * (the first pointer that is down) to {@link #getPointerCount()}-1.
1764 * @param outPointerCoords The pointer coordinate object to populate.
Jeff Brown91c69ab2011-02-14 17:03:18 -08001765 *
1766 * @see PointerCoords
Jeff Brownc5ed5912010-07-14 18:48:53 -07001767 */
1768 public final void getPointerCoords(int pointerIndex, PointerCoords outPointerCoords) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001769 nativeGetPointerCoords(mNativePtr, pointerIndex, HISTORY_CURRENT, outPointerCoords);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001770 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001771
1772 /**
1773 * Returns the state of any meta / modifier keys that were in effect when
1774 * the event was generated. This is the same values as those
1775 * returned by {@link KeyEvent#getMetaState() KeyEvent.getMetaState}.
1776 *
1777 * @return an integer in which each bit set to 1 represents a pressed
1778 * meta key
1779 *
1780 * @see KeyEvent#getMetaState()
1781 */
1782 public final int getMetaState() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001783 return nativeGetMetaState(mNativePtr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001784 }
1785
1786 /**
1787 * Returns the original raw X coordinate of this event. For touch
1788 * events on the screen, this is the original location of the event
1789 * on the screen, before it had been adjusted for the containing window
1790 * and views.
Jeff Brown91c69ab2011-02-14 17:03:18 -08001791 *
1792 * @see getX()
1793 * @see #AXIS_X
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001794 */
1795 public final float getRawX() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001796 return nativeGetRawAxisValue(mNativePtr, AXIS_X, 0, HISTORY_CURRENT);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001797 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08001798
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001799 /**
1800 * Returns the original raw Y coordinate of this event. For touch
1801 * events on the screen, this is the original location of the event
1802 * on the screen, before it had been adjusted for the containing window
1803 * and views.
Jeff Brown91c69ab2011-02-14 17:03:18 -08001804 *
1805 * @see getY()
1806 * @see #AXIS_Y
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001807 */
1808 public final float getRawY() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001809 return nativeGetRawAxisValue(mNativePtr, AXIS_Y, 0, HISTORY_CURRENT);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001810 }
1811
1812 /**
1813 * Return the precision of the X coordinates being reported. You can
Jeff Brown91c69ab2011-02-14 17:03:18 -08001814 * multiply this number with {@link #getX} to find the actual hardware
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001815 * value of the X coordinate.
1816 * @return Returns the precision of X coordinates being reported.
Jeff Brown91c69ab2011-02-14 17:03:18 -08001817 *
1818 * @see #AXIS_X
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001819 */
1820 public final float getXPrecision() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001821 return nativeGetXPrecision(mNativePtr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001822 }
Romain Guycafdea62009-06-12 10:51:36 -07001823
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001824 /**
1825 * Return the precision of the Y coordinates being reported. You can
Jeff Brown91c69ab2011-02-14 17:03:18 -08001826 * multiply this number with {@link #getY} to find the actual hardware
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001827 * value of the Y coordinate.
1828 * @return Returns the precision of Y coordinates being reported.
Jeff Brown91c69ab2011-02-14 17:03:18 -08001829 *
1830 * @see #AXIS_Y
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001831 */
1832 public final float getYPrecision() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001833 return nativeGetYPrecision(mNativePtr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001834 }
Romain Guycafdea62009-06-12 10:51:36 -07001835
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001836 /**
1837 * Returns the number of historical points in this event. These are
1838 * movements that have occurred between this event and the previous event.
1839 * This only applies to ACTION_MOVE events -- all other actions will have
1840 * a size of 0.
Romain Guycafdea62009-06-12 10:51:36 -07001841 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001842 * @return Returns the number of historical points in the event.
1843 */
1844 public final int getHistorySize() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001845 return nativeGetHistorySize(mNativePtr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001846 }
Romain Guycafdea62009-06-12 10:51:36 -07001847
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001848 /**
1849 * Returns the time that a historical movement occurred between this event
1850 * and the previous event. Only applies to ACTION_MOVE events.
Romain Guycafdea62009-06-12 10:51:36 -07001851 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001852 * @param pos Which historical value to return; must be less than
1853 * {@link #getHistorySize}
Romain Guycafdea62009-06-12 10:51:36 -07001854 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001855 * @see #getHistorySize
1856 * @see #getEventTime
1857 */
1858 public final long getHistoricalEventTime(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001859 return nativeGetEventTimeNanos(mNativePtr, pos) / NS_PER_MS;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001860 }
1861
1862 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08001863 * {@link #getHistoricalX(int, int)} for the first pointer index (may be an
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001864 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001865 *
1866 * @param pos Which historical value to return; must be less than
1867 * {@link #getHistorySize}
1868 *
1869 * @see #getHistorySize
1870 * @see #getX()
1871 * @see #AXIS_X
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001872 */
1873 public final float getHistoricalX(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001874 return nativeGetAxisValue(mNativePtr, AXIS_X, 0, pos);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001875 }
1876
1877 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08001878 * {@link #getHistoricalY(int, int)} for the first pointer index (may be an
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001879 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001880 *
1881 * @param pos Which historical value to return; must be less than
1882 * {@link #getHistorySize}
1883 *
1884 * @see #getHistorySize
1885 * @see #getY()
1886 * @see #AXIS_Y
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001887 */
1888 public final float getHistoricalY(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001889 return nativeGetAxisValue(mNativePtr, AXIS_Y, 0, pos);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001890 }
1891
1892 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08001893 * {@link #getHistoricalPressure(int, int)} for the first pointer index (may be an
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001894 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001895 *
1896 * @param pos Which historical value to return; must be less than
1897 * {@link #getHistorySize}
1898 *
1899 * @see #getHistorySize
1900 * @see #getPressure()
1901 * @see #AXIS_PRESSURE
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001902 */
1903 public final float getHistoricalPressure(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001904 return nativeGetAxisValue(mNativePtr, AXIS_PRESSURE, 0, pos);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001905 }
1906
1907 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08001908 * {@link #getHistoricalSize(int, int)} for the first pointer index (may be an
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001909 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001910 *
1911 * @param pos Which historical value to return; must be less than
1912 * {@link #getHistorySize}
1913 *
1914 * @see #getHistorySize
1915 * @see #getSize()
1916 * @see #AXIS_SIZE
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001917 */
1918 public final float getHistoricalSize(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001919 return nativeGetAxisValue(mNativePtr, AXIS_SIZE, 0, pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001920 }
Romain Guycafdea62009-06-12 10:51:36 -07001921
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001922 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08001923 * {@link #getHistoricalTouchMajor(int, int)} for the first pointer index (may be an
Jeff Brownc5ed5912010-07-14 18:48:53 -07001924 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001925 *
1926 * @param pos Which historical value to return; must be less than
1927 * {@link #getHistorySize}
1928 *
1929 * @see #getHistorySize
1930 * @see #getTouchMajor()
1931 * @see #AXIS_TOUCH_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07001932 */
1933 public final float getHistoricalTouchMajor(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001934 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MAJOR, 0, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001935 }
1936
1937 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08001938 * {@link #getHistoricalTouchMinor(int, int)} for the first pointer index (may be an
Jeff Brownc5ed5912010-07-14 18:48:53 -07001939 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001940 *
1941 * @param pos Which historical value to return; must be less than
1942 * {@link #getHistorySize}
1943 *
1944 * @see #getHistorySize
1945 * @see #getTouchMinor()
1946 * @see #AXIS_TOUCH_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07001947 */
1948 public final float getHistoricalTouchMinor(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001949 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MINOR, 0, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001950 }
1951
1952 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08001953 * {@link #getHistoricalToolMajor(int, int)} for the first pointer index (may be an
Jeff Brownc5ed5912010-07-14 18:48:53 -07001954 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001955 *
1956 * @param pos Which historical value to return; must be less than
1957 * {@link #getHistorySize}
1958 *
1959 * @see #getHistorySize
1960 * @see #getToolMajor()
1961 * @see #AXIS_TOOL_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07001962 */
1963 public final float getHistoricalToolMajor(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001964 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MAJOR, 0, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001965 }
1966
1967 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08001968 * {@link #getHistoricalToolMinor(int, int)} for the first pointer index (may be an
Jeff Brownc5ed5912010-07-14 18:48:53 -07001969 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001970 *
1971 * @param pos Which historical value to return; must be less than
1972 * {@link #getHistorySize}
1973 *
1974 * @see #getHistorySize
1975 * @see #getToolMinor()
1976 * @see #AXIS_TOOL_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07001977 */
1978 public final float getHistoricalToolMinor(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001979 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MINOR, 0, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001980 }
1981
1982 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08001983 * {@link #getHistoricalOrientation(int, int)} for the first pointer index (may be an
Jeff Brownc5ed5912010-07-14 18:48:53 -07001984 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001985 *
1986 * @param pos Which historical value to return; must be less than
1987 * {@link #getHistorySize}
1988 *
1989 * @see #getHistorySize
1990 * @see #getOrientation()
1991 * @see #AXIS_ORIENTATION
Jeff Brownc5ed5912010-07-14 18:48:53 -07001992 */
1993 public final float getHistoricalOrientation(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001994 return nativeGetAxisValue(mNativePtr, AXIS_ORIENTATION, 0, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001995 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08001996
1997 /**
1998 * {@link #getHistoricalAxisValue(int, int, int)} for the first pointer index (may be an
1999 * arbitrary pointer identifier).
2000 *
2001 * @param axis The axis identifier for the axis value to retrieve.
2002 * @param pos Which historical value to return; must be less than
2003 * {@link #getHistorySize}
2004 *
2005 * @see #getHistorySize
2006 * @see #getAxisValue(int)
2007 * @see #AXIS_X
2008 * @see #AXIS_Y
2009 */
2010 public final float getHistoricalAxisValue(int axis, int pos) {
2011 return nativeGetAxisValue(mNativePtr, axis, 0, pos);
2012 }
2013
Jeff Brownc5ed5912010-07-14 18:48:53 -07002014 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002015 * Returns a historical X coordinate, as per {@link #getX(int)}, that
2016 * occurred between this event and the previous event for the given pointer.
2017 * Only applies to ACTION_MOVE events.
Romain Guycafdea62009-06-12 10:51:36 -07002018 *
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002019 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2020 * (the first pointer that is down) to {@link #getPointerCount()}-1.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002021 * @param pos Which historical value to return; must be less than
2022 * {@link #getHistorySize}
Romain Guycafdea62009-06-12 10:51:36 -07002023 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002024 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08002025 * @see #getX(int)
2026 * @see #AXIS_X
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002027 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002028 public final float getHistoricalX(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002029 return nativeGetAxisValue(mNativePtr, AXIS_X, pointerIndex, pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002030 }
Romain Guycafdea62009-06-12 10:51:36 -07002031
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002032 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002033 * Returns a historical Y coordinate, as per {@link #getY(int)}, that
2034 * occurred between this event and the previous event for the given pointer.
2035 * Only applies to ACTION_MOVE events.
Romain Guycafdea62009-06-12 10:51:36 -07002036 *
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002037 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2038 * (the first pointer that is down) to {@link #getPointerCount()}-1.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002039 * @param pos Which historical value to return; must be less than
2040 * {@link #getHistorySize}
Romain Guycafdea62009-06-12 10:51:36 -07002041 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002042 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08002043 * @see #getY(int)
2044 * @see #AXIS_Y
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002045 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002046 public final float getHistoricalY(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002047 return nativeGetAxisValue(mNativePtr, AXIS_Y, pointerIndex, pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002048 }
Romain Guycafdea62009-06-12 10:51:36 -07002049
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002050 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002051 * Returns a historical pressure coordinate, as per {@link #getPressure(int)},
2052 * that occurred between this event and the previous event for the given
2053 * pointer. Only applies to ACTION_MOVE events.
Romain Guycafdea62009-06-12 10:51:36 -07002054 *
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002055 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2056 * (the first pointer that is down) to {@link #getPointerCount()}-1.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002057 * @param pos Which historical value to return; must be less than
2058 * {@link #getHistorySize}
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002059 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002060 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08002061 * @see #getPressure(int)
2062 * @see #AXIS_PRESSURE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002063 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002064 public final float getHistoricalPressure(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002065 return nativeGetAxisValue(mNativePtr, AXIS_PRESSURE, pointerIndex, pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002066 }
Romain Guycafdea62009-06-12 10:51:36 -07002067
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002068 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002069 * Returns a historical size coordinate, as per {@link #getSize(int)}, that
2070 * occurred between this event and the previous event for the given pointer.
2071 * Only applies to ACTION_MOVE events.
Romain Guycafdea62009-06-12 10:51:36 -07002072 *
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002073 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2074 * (the first pointer that is down) to {@link #getPointerCount()}-1.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002075 * @param pos Which historical value to return; must be less than
2076 * {@link #getHistorySize}
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002077 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002078 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08002079 * @see #getSize(int)
2080 * @see #AXIS_SIZE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002081 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002082 public final float getHistoricalSize(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002083 return nativeGetAxisValue(mNativePtr, AXIS_SIZE, pointerIndex, pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002084 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002085
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002086 /**
Jeff Brownc5ed5912010-07-14 18:48:53 -07002087 * Returns a historical touch major axis coordinate, as per {@link #getTouchMajor(int)}, that
2088 * occurred between this event and the previous event for the given pointer.
2089 * Only applies to ACTION_MOVE events.
2090 *
2091 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2092 * (the first pointer that is down) to {@link #getPointerCount()}-1.
2093 * @param pos Which historical value to return; must be less than
2094 * {@link #getHistorySize}
2095 *
2096 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08002097 * @see #getTouchMajor(int)
2098 * @see #AXIS_TOUCH_MAJOR
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002099 */
Jeff Brownc5ed5912010-07-14 18:48:53 -07002100 public final float getHistoricalTouchMajor(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002101 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MAJOR, pointerIndex, pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002102 }
Romain Guycafdea62009-06-12 10:51:36 -07002103
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002104 /**
Jeff Brownc5ed5912010-07-14 18:48:53 -07002105 * Returns a historical touch minor axis coordinate, as per {@link #getTouchMinor(int)}, that
2106 * occurred between this event and the previous event for the given pointer.
2107 * Only applies to ACTION_MOVE events.
2108 *
2109 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2110 * (the first pointer that is down) to {@link #getPointerCount()}-1.
2111 * @param pos Which historical value to return; must be less than
2112 * {@link #getHistorySize}
2113 *
2114 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08002115 * @see #getTouchMinor(int)
2116 * @see #AXIS_TOUCH_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002117 */
2118 public final float getHistoricalTouchMinor(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002119 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MINOR, pointerIndex, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002120 }
2121
2122 /**
2123 * Returns a historical tool major axis coordinate, as per {@link #getToolMajor(int)}, that
2124 * occurred between this event and the previous event for the given pointer.
2125 * Only applies to ACTION_MOVE events.
2126 *
2127 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2128 * (the first pointer that is down) to {@link #getPointerCount()}-1.
2129 * @param pos Which historical value to return; must be less than
2130 * {@link #getHistorySize}
2131 *
2132 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08002133 * @see #getToolMajor(int)
2134 * @see #AXIS_TOOL_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002135 */
2136 public final float getHistoricalToolMajor(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002137 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MAJOR, pointerIndex, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002138 }
2139
2140 /**
2141 * Returns a historical tool minor axis coordinate, as per {@link #getToolMinor(int)}, that
2142 * occurred between this event and the previous event for the given pointer.
2143 * Only applies to ACTION_MOVE events.
2144 *
2145 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2146 * (the first pointer that is down) to {@link #getPointerCount()}-1.
2147 * @param pos Which historical value to return; must be less than
2148 * {@link #getHistorySize}
2149 *
2150 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08002151 * @see #getToolMinor(int)
2152 * @see #AXIS_TOOL_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002153 */
2154 public final float getHistoricalToolMinor(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002155 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MINOR, pointerIndex, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002156 }
2157
2158 /**
2159 * Returns a historical orientation coordinate, as per {@link #getOrientation(int)}, that
2160 * occurred between this event and the previous event for the given pointer.
2161 * Only applies to ACTION_MOVE events.
2162 *
2163 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2164 * (the first pointer that is down) to {@link #getPointerCount()}-1.
2165 * @param pos Which historical value to return; must be less than
2166 * {@link #getHistorySize}
2167 *
2168 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08002169 * @see #getOrientation(int)
2170 * @see #AXIS_ORIENTATION
Jeff Brownc5ed5912010-07-14 18:48:53 -07002171 */
2172 public final float getHistoricalOrientation(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002173 return nativeGetAxisValue(mNativePtr, AXIS_ORIENTATION, pointerIndex, pos);
2174 }
2175
2176 /**
2177 * Returns the historical value of the requested axis, as per {@link #getAxisValue(int, int)},
2178 * occurred between this event and the previous event for the given pointer.
2179 * Only applies to ACTION_MOVE events.
2180 *
2181 * @param axis The axis identifier for the axis value to retrieve.
2182 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2183 * (the first pointer that is down) to {@link #getPointerCount()}-1.
2184 * @param pos Which historical value to return; must be less than
2185 * {@link #getHistorySize}
2186 * @return The value of the axis, or 0 if the axis is not available.
2187 *
2188 * @see #AXIS_X
2189 * @see #AXIS_Y
2190 */
2191 public final float getHistoricalAxisValue(int axis, int pointerIndex, int pos) {
2192 return nativeGetAxisValue(mNativePtr, axis, pointerIndex, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002193 }
2194
2195 /**
2196 * Populates a {@link PointerCoords} object with historical pointer coordinate data,
2197 * as per {@link #getPointerCoords}, that occurred between this event and the previous
2198 * event for the given pointer.
2199 * Only applies to ACTION_MOVE events.
2200 *
2201 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2202 * (the first pointer that is down) to {@link #getPointerCount()}-1.
2203 * @param pos Which historical value to return; must be less than
2204 * {@link #getHistorySize}
2205 * @param outPointerCoords The pointer coordinate object to populate.
2206 *
2207 * @see #getHistorySize
2208 * @see #getPointerCoords
Jeff Brown91c69ab2011-02-14 17:03:18 -08002209 * @see PointerCoords
Jeff Brownc5ed5912010-07-14 18:48:53 -07002210 */
2211 public final void getHistoricalPointerCoords(int pointerIndex, int pos,
2212 PointerCoords outPointerCoords) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002213 nativeGetPointerCoords(mNativePtr, pointerIndex, pos, outPointerCoords);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002214 }
2215
2216 /**
Jeff Brown46b9ac02010-04-22 18:58:52 -07002217 * Returns a bitfield indicating which edges, if any, were touched by this
Romain Guycafdea62009-06-12 10:51:36 -07002218 * MotionEvent. For touch events, clients can use this to determine if the
2219 * user's finger was touching the edge of the display.
2220 *
Jeff Brownd41cff22011-03-03 02:09:54 -08002221 * This property is only set for {@link #ACTION_DOWN} events.
2222 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002223 * @see #EDGE_LEFT
2224 * @see #EDGE_TOP
2225 * @see #EDGE_RIGHT
2226 * @see #EDGE_BOTTOM
2227 */
2228 public final int getEdgeFlags() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002229 return nativeGetEdgeFlags(mNativePtr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002230 }
Romain Guycafdea62009-06-12 10:51:36 -07002231
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002232 /**
Jeff Brown85a31762010-09-01 17:01:00 -07002233 * Sets the bitfield indicating which edges, if any, were touched by this
Romain Guycafdea62009-06-12 10:51:36 -07002234 * MotionEvent.
2235 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002236 * @see #getEdgeFlags()
2237 */
2238 public final void setEdgeFlags(int flags) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002239 nativeSetEdgeFlags(mNativePtr, flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002240 }
2241
2242 /**
2243 * Sets this event's action.
2244 */
2245 public final void setAction(int action) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002246 nativeSetAction(mNativePtr, action);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002247 }
2248
2249 /**
2250 * Adjust this event's location.
2251 * @param deltaX Amount to add to the current X coordinate of the event.
2252 * @param deltaY Amount to add to the current Y coordinate of the event.
2253 */
2254 public final void offsetLocation(float deltaX, float deltaY) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002255 nativeOffsetLocation(mNativePtr, deltaX, deltaY);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002256 }
Romain Guycafdea62009-06-12 10:51:36 -07002257
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002258 /**
2259 * Set this event's location. Applies {@link #offsetLocation} with a
2260 * delta from the current location to the given new location.
Romain Guycafdea62009-06-12 10:51:36 -07002261 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002262 * @param x New absolute X location.
2263 * @param y New absolute Y location.
2264 */
2265 public final void setLocation(float x, float y) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002266 float oldX = getX();
2267 float oldY = getY();
2268 nativeOffsetLocation(mNativePtr, x - oldX, y - oldY);
Jeff Brown5c225b12010-06-16 01:53:36 -07002269 }
2270
Jeff Brown20e987b2010-08-23 12:01:02 -07002271 /**
2272 * Applies a transformation matrix to all of the points in the event.
2273 *
2274 * @param matrix The transformation matrix to apply.
2275 */
2276 public final void transform(Matrix matrix) {
2277 if (matrix == null) {
2278 throw new IllegalArgumentException("matrix must not be null");
2279 }
2280
Jeff Brown91c69ab2011-02-14 17:03:18 -08002281 nativeTransform(mNativePtr, matrix);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002282 }
Romain Guycafdea62009-06-12 10:51:36 -07002283
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002284 /**
2285 * Add a new movement to the batch of movements in this event. The event's
Jeff Brownc5ed5912010-07-14 18:48:53 -07002286 * current location, position and size is updated to the new values.
2287 * The current values in the event are added to a list of historical values.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002288 *
Jeff Browncc0c1592011-02-19 05:07:28 -08002289 * Only applies to {@link #ACTION_MOVE} or {@link #ACTION_HOVER_MOVE} events.
Romain Guycafdea62009-06-12 10:51:36 -07002290 *
Jeff Brownc5ed5912010-07-14 18:48:53 -07002291 * @param eventTime The time stamp (in ms) for this data.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002292 * @param x The new X position.
2293 * @param y The new Y position.
2294 * @param pressure The new pressure.
2295 * @param size The new size.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002296 * @param metaState Meta key state.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002297 */
2298 public final void addBatch(long eventTime, float x, float y,
2299 float pressure, float size, int metaState) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002300 synchronized (gTmpPointerCoords) {
2301 final PointerCoords pc = gTmpPointerCoords[0];
2302 pc.clear();
2303 pc.x = x;
2304 pc.y = y;
2305 pc.pressure = pressure;
2306 pc.size = size;
2307 nativeAddBatch(mNativePtr, eventTime * NS_PER_MS, gTmpPointerCoords, metaState);
2308 }
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002309 }
Romain Guycafdea62009-06-12 10:51:36 -07002310
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002311 /**
Jeff Brownc5ed5912010-07-14 18:48:53 -07002312 * Add a new movement to the batch of movements in this event. The event's
2313 * current location, position and size is updated to the new values.
2314 * The current values in the event are added to a list of historical values.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002315 *
Jeff Browncc0c1592011-02-19 05:07:28 -08002316 * Only applies to {@link #ACTION_MOVE} or {@link #ACTION_HOVER_MOVE} events.
Jeff Brownc5ed5912010-07-14 18:48:53 -07002317 *
2318 * @param eventTime The time stamp (in ms) for this data.
2319 * @param pointerCoords The new pointer coordinates.
2320 * @param metaState Meta key state.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002321 */
Jeff Brownc5ed5912010-07-14 18:48:53 -07002322 public final void addBatch(long eventTime, PointerCoords[] pointerCoords, int metaState) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002323 nativeAddBatch(mNativePtr, eventTime * NS_PER_MS, pointerCoords, metaState);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002324 }
Romain Guycafdea62009-06-12 10:51:36 -07002325
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002326 @Override
2327 public String toString() {
2328 return "MotionEvent{" + Integer.toHexString(System.identityHashCode(this))
Huahui Wue838a422011-01-13 16:03:43 -08002329 + " pointerId=" + getPointerId(0)
Jeff Brown91c69ab2011-02-14 17:03:18 -08002330 + " action=" + actionToString(getAction())
Jeff Brown497a92c2010-09-12 17:55:08 -07002331 + " x=" + getX()
2332 + " y=" + getY()
2333 + " pressure=" + getPressure()
2334 + " size=" + getSize()
2335 + " touchMajor=" + getTouchMajor()
2336 + " touchMinor=" + getTouchMinor()
2337 + " toolMajor=" + getToolMajor()
2338 + " toolMinor=" + getToolMinor()
2339 + " orientation=" + getOrientation()
Jeff Brown91c69ab2011-02-14 17:03:18 -08002340 + " meta=" + KeyEvent.metaStateToString(getMetaState())
Jeff Brown497a92c2010-09-12 17:55:08 -07002341 + " pointerCount=" + getPointerCount()
2342 + " historySize=" + getHistorySize()
Jeff Brown91c69ab2011-02-14 17:03:18 -08002343 + " flags=0x" + Integer.toHexString(getFlags())
2344 + " edgeFlags=0x" + Integer.toHexString(getEdgeFlags())
2345 + " device=" + getDeviceId()
2346 + " source=0x" + Integer.toHexString(getSource())
Huahui Wue838a422011-01-13 16:03:43 -08002347 + (getPointerCount() > 1 ?
Huahui Wuf9324692011-01-24 12:07:37 -08002348 " pointerId2=" + getPointerId(1) + " x2=" + getX(1) + " y2=" + getY(1) : "")
Jeff Brown497a92c2010-09-12 17:55:08 -07002349 + "}";
2350 }
2351
2352 /**
2353 * Returns a string that represents the symbolic name of the specified action
Jeff Brown91c69ab2011-02-14 17:03:18 -08002354 * such as "ACTION_DOWN", "ACTION_POINTER_DOWN(3)" or an equivalent numeric constant
2355 * such as "35" if unknown.
Jeff Brown497a92c2010-09-12 17:55:08 -07002356 *
2357 * @param action The action.
2358 * @return The symbolic name of the specified action.
2359 * @hide
2360 */
2361 public static String actionToString(int action) {
2362 switch (action) {
2363 case ACTION_DOWN:
2364 return "ACTION_DOWN";
2365 case ACTION_UP:
2366 return "ACTION_UP";
2367 case ACTION_CANCEL:
2368 return "ACTION_CANCEL";
Jeff Brown33bbfd22011-02-24 20:55:35 -08002369 case ACTION_OUTSIDE:
2370 return "ACTION_OUTSIDE";
Jeff Brown497a92c2010-09-12 17:55:08 -07002371 case ACTION_MOVE:
2372 return "ACTION_MOVE";
Jeff Browncc0c1592011-02-19 05:07:28 -08002373 case ACTION_HOVER_MOVE:
2374 return "ACTION_HOVER_MOVE";
Jeff Brown33bbfd22011-02-24 20:55:35 -08002375 case ACTION_SCROLL:
2376 return "ACTION_SCROLL";
Jeff Browna032cc02011-03-07 16:56:21 -08002377 case ACTION_HOVER_ENTER:
2378 return "ACTION_HOVER_ENTER";
2379 case ACTION_HOVER_EXIT:
2380 return "ACTION_HOVER_EXIT";
Jeff Brown497a92c2010-09-12 17:55:08 -07002381 }
2382 int index = (action & ACTION_POINTER_INDEX_MASK) >> ACTION_POINTER_INDEX_SHIFT;
2383 switch (action & ACTION_MASK) {
2384 case ACTION_POINTER_DOWN:
2385 return "ACTION_POINTER_DOWN(" + index + ")";
2386 case ACTION_POINTER_UP:
2387 return "ACTION_POINTER_UP(" + index + ")";
2388 default:
2389 return Integer.toString(action);
2390 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002391 }
2392
Jeff Brown91c69ab2011-02-14 17:03:18 -08002393 /**
2394 * Returns a string that represents the symbolic name of the specified axis
Jeff Brown6f2fba42011-02-19 01:08:02 -08002395 * such as "AXIS_X" or an equivalent numeric constant such as "42" if unknown.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002396 *
2397 * @param axis The axis
2398 * @return The symbolic name of the specified axis.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002399 */
2400 public static String axisToString(int axis) {
Jeff Brown6f2fba42011-02-19 01:08:02 -08002401 String symbolicName = AXIS_SYMBOLIC_NAMES.get(axis);
2402 return symbolicName != null ? symbolicName : Integer.toString(axis);
2403 }
2404
2405 /**
Jeff Browncc0c1592011-02-19 05:07:28 -08002406 * Gets an axis by its symbolic name such as "AXIS_X" or an
2407 * equivalent numeric constant such as "42".
Jeff Brown6f2fba42011-02-19 01:08:02 -08002408 *
2409 * @param symbolicName The symbolic name of the axis.
2410 * @return The axis or -1 if not found.
2411 * @see #keycodeToString
2412 */
2413 public static int axisFromString(String symbolicName) {
2414 if (symbolicName == null) {
2415 throw new IllegalArgumentException("symbolicName must not be null");
2416 }
2417
2418 final int count = AXIS_SYMBOLIC_NAMES.size();
2419 for (int i = 0; i < count; i++) {
2420 if (symbolicName.equals(AXIS_SYMBOLIC_NAMES.valueAt(i))) {
2421 return i;
2422 }
2423 }
2424
2425 try {
2426 return Integer.parseInt(symbolicName, 10);
2427 } catch (NumberFormatException ex) {
2428 return -1;
Jeff Brown91c69ab2011-02-14 17:03:18 -08002429 }
2430 }
2431
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002432 public static final Parcelable.Creator<MotionEvent> CREATOR
2433 = new Parcelable.Creator<MotionEvent>() {
2434 public MotionEvent createFromParcel(Parcel in) {
Jeff Brown6ec402b2010-07-28 15:48:59 -07002435 in.readInt(); // skip token, we already know this is a MotionEvent
2436 return MotionEvent.createFromParcelBody(in);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002437 }
2438
2439 public MotionEvent[] newArray(int size) {
2440 return new MotionEvent[size];
2441 }
2442 };
2443
Jeff Brown6ec402b2010-07-28 15:48:59 -07002444 /** @hide */
2445 public static MotionEvent createFromParcelBody(Parcel in) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002446 MotionEvent ev = obtain();
2447 ev.mNativePtr = nativeReadFromParcel(ev.mNativePtr, in);
Jeff Brown6ec402b2010-07-28 15:48:59 -07002448 return ev;
2449 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08002450
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002451 public void writeToParcel(Parcel out, int flags) {
Jeff Brown6ec402b2010-07-28 15:48:59 -07002452 out.writeInt(PARCEL_TOKEN_MOTION_EVENT);
Jeff Brown91c69ab2011-02-14 17:03:18 -08002453 nativeWriteToParcel(mNativePtr, out);
Jeff Brown5c225b12010-06-16 01:53:36 -07002454 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08002455
Jeff Brownc5ed5912010-07-14 18:48:53 -07002456 /**
2457 * Transfer object for pointer coordinates.
2458 *
2459 * Objects of this type can be used to manufacture new {@link MotionEvent} objects
2460 * and to query pointer coordinate information in bulk.
2461 *
2462 * Refer to {@link InputDevice} for information about how different kinds of
2463 * input devices and sources represent pointer coordinates.
2464 */
2465 public static final class PointerCoords {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002466 private static final int INITIAL_PACKED_AXIS_VALUES = 8;
Jeff Brown6f2fba42011-02-19 01:08:02 -08002467 private long mPackedAxisBits;
Jeff Brown91c69ab2011-02-14 17:03:18 -08002468 private float[] mPackedAxisValues;
2469
2470 /**
2471 * Creates a pointer coords object with all axes initialized to zero.
2472 */
2473 public PointerCoords() {
2474 }
2475
2476 /**
2477 * Creates a pointer coords object as a copy of the
2478 * contents of another pointer coords object.
2479 *
2480 * @param other The pointer coords object to copy.
2481 */
2482 public PointerCoords(PointerCoords other) {
2483 copyFrom(other);
2484 }
2485
Jeff Brownc5ed5912010-07-14 18:48:53 -07002486 /**
Jeff Brown6f2fba42011-02-19 01:08:02 -08002487 * The X component of the pointer movement.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002488 *
2489 * @see MotionEvent#AXIS_X
Jeff Brownc5ed5912010-07-14 18:48:53 -07002490 */
2491 public float x;
2492
2493 /**
Jeff Brown6f2fba42011-02-19 01:08:02 -08002494 * The Y component of the pointer movement.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002495 *
2496 * @see MotionEvent#AXIS_Y
Jeff Brownc5ed5912010-07-14 18:48:53 -07002497 */
2498 public float y;
2499
2500 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08002501 * A normalized value that describes the pressure applied to the device
2502 * by a finger or other tool.
Jeff Brownc5ed5912010-07-14 18:48:53 -07002503 * The pressure generally ranges from 0 (no pressure at all) to 1 (normal pressure),
Jeff Brown91c69ab2011-02-14 17:03:18 -08002504 * although values higher than 1 may be generated depending on the calibration of
Jeff Brownc5ed5912010-07-14 18:48:53 -07002505 * the input device.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002506 *
2507 * @see MotionEvent#AXIS_PRESSURE
Jeff Brownc5ed5912010-07-14 18:48:53 -07002508 */
2509 public float pressure;
2510
2511 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08002512 * A normalized value that describes the approximate size of the pointer touch area
2513 * in relation to the maximum detectable size of the device.
2514 * It represents some approximation of the area of the screen being
Jeff Brownc5ed5912010-07-14 18:48:53 -07002515 * pressed; the actual value in pixels corresponding to the
2516 * touch is normalized with the device specific range of values
2517 * and scaled to a value between 0 and 1. The value of size can be used to
2518 * determine fat touch events.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002519 *
2520 * @see MotionEvent#AXIS_SIZE
Jeff Brownc5ed5912010-07-14 18:48:53 -07002521 */
2522 public float size;
2523
2524 /**
2525 * The length of the major axis of an ellipse that describes the touch area at
2526 * the point of contact.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002527 * If the device is a touch screen, the length is reported in pixels, otherwise it is
2528 * reported in device-specific units.
2529 *
2530 * @see MotionEvent#AXIS_TOUCH_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002531 */
2532 public float touchMajor;
2533
2534 /**
2535 * The length of the minor axis of an ellipse that describes the touch area at
2536 * the point of contact.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002537 * If the device is a touch screen, the length is reported in pixels, otherwise it is
2538 * reported in device-specific units.
2539 *
2540 * @see MotionEvent#AXIS_TOUCH_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002541 */
2542 public float touchMinor;
2543
2544 /**
2545 * The length of the major axis of an ellipse that describes the size of
2546 * the approaching tool.
2547 * The tool area represents the estimated size of the finger or pen that is
2548 * touching the device independent of its actual touch area at the point of contact.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002549 * If the device is a touch screen, the length is reported in pixels, otherwise it is
2550 * reported in device-specific units.
2551 *
2552 * @see MotionEvent#AXIS_TOOL_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002553 */
2554 public float toolMajor;
2555
2556 /**
2557 * The length of the minor axis of an ellipse that describes the size of
2558 * the approaching tool.
2559 * The tool area represents the estimated size of the finger or pen that is
2560 * touching the device independent of its actual touch area at the point of contact.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002561 * If the device is a touch screen, the length is reported in pixels, otherwise it is
2562 * reported in device-specific units.
2563 *
2564 * @see MotionEvent#AXIS_TOOL_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002565 */
2566 public float toolMinor;
2567
2568 /**
2569 * The orientation of the touch area and tool area in radians clockwise from vertical.
Jeff Brown6f2fba42011-02-19 01:08:02 -08002570 * An angle of 0 radians indicates that the major axis of contact is oriented
Jeff Brownc5ed5912010-07-14 18:48:53 -07002571 * upwards, is perfectly circular or is of unknown orientation. A positive angle
2572 * indicates that the major axis of contact is oriented to the right. A negative angle
2573 * indicates that the major axis of contact is oriented to the left.
Jeff Brown6d0fec22010-07-23 21:28:06 -07002574 * The full range is from -PI/2 radians (finger pointing fully left) to PI/2 radians
Jeff Brownc5ed5912010-07-14 18:48:53 -07002575 * (finger pointing fully right).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002576 *
2577 * @see MotionEvent#AXIS_ORIENTATION
Jeff Brownc5ed5912010-07-14 18:48:53 -07002578 */
2579 public float orientation;
Jeff Brown91c69ab2011-02-14 17:03:18 -08002580
2581 /**
2582 * Clears the contents of this object.
2583 * Resets all axes to zero.
2584 */
2585 public void clear() {
2586 mPackedAxisBits = 0;
2587
2588 x = 0;
2589 y = 0;
2590 pressure = 0;
2591 size = 0;
2592 touchMajor = 0;
2593 touchMinor = 0;
2594 toolMajor = 0;
2595 toolMinor = 0;
2596 orientation = 0;
Jeff Brownc5ed5912010-07-14 18:48:53 -07002597 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08002598
2599 /**
2600 * Copies the contents of another pointer coords object.
2601 *
2602 * @param other The pointer coords object to copy.
2603 */
2604 public void copyFrom(PointerCoords other) {
Jeff Brown6f2fba42011-02-19 01:08:02 -08002605 final long bits = other.mPackedAxisBits;
Jeff Brown91c69ab2011-02-14 17:03:18 -08002606 mPackedAxisBits = bits;
2607 if (bits != 0) {
2608 final float[] otherValues = other.mPackedAxisValues;
Jeff Brown6f2fba42011-02-19 01:08:02 -08002609 final int count = Long.bitCount(bits);
Jeff Brown91c69ab2011-02-14 17:03:18 -08002610 float[] values = mPackedAxisValues;
2611 if (values == null || count > values.length) {
2612 values = new float[otherValues.length];
2613 mPackedAxisValues = values;
2614 }
2615 System.arraycopy(otherValues, 0, values, 0, count);
2616 }
2617
2618 x = other.x;
2619 y = other.y;
2620 pressure = other.pressure;
2621 size = other.size;
2622 touchMajor = other.touchMajor;
2623 touchMinor = other.touchMinor;
2624 toolMajor = other.toolMajor;
2625 toolMinor = other.toolMinor;
2626 orientation = other.orientation;
Jeff Brownc5ed5912010-07-14 18:48:53 -07002627 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08002628
2629 /**
2630 * Gets the value associated with the specified axis.
2631 *
2632 * @param axis The axis identifier for the axis value to retrieve.
2633 * @return The value associated with the axis, or 0 if none.
2634 *
2635 * @see MotionEvent#AXIS_X
2636 * @see MotionEvent#AXIS_Y
2637 */
2638 public float getAxisValue(int axis) {
2639 switch (axis) {
2640 case AXIS_X:
2641 return x;
2642 case AXIS_Y:
2643 return y;
2644 case AXIS_PRESSURE:
2645 return pressure;
2646 case AXIS_SIZE:
2647 return size;
2648 case AXIS_TOUCH_MAJOR:
2649 return touchMajor;
2650 case AXIS_TOUCH_MINOR:
2651 return touchMinor;
2652 case AXIS_TOOL_MAJOR:
2653 return toolMajor;
2654 case AXIS_TOOL_MINOR:
2655 return toolMinor;
2656 case AXIS_ORIENTATION:
2657 return orientation;
2658 default: {
Jeff Brown6f2fba42011-02-19 01:08:02 -08002659 if (axis < 0 || axis > 63) {
2660 throw new IllegalArgumentException("Axis out of range.");
2661 }
2662 final long bits = mPackedAxisBits;
2663 final long axisBit = 1L << axis;
Jeff Brown91c69ab2011-02-14 17:03:18 -08002664 if ((bits & axisBit) == 0) {
2665 return 0;
2666 }
Jeff Brown6f2fba42011-02-19 01:08:02 -08002667 final int index = Long.bitCount(bits & (axisBit - 1L));
Jeff Brown91c69ab2011-02-14 17:03:18 -08002668 return mPackedAxisValues[index];
2669 }
2670 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002671 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08002672
2673 /**
2674 * Sets the value associated with the specified axis.
2675 *
2676 * @param axis The axis identifier for the axis value to assign.
2677 * @param value The value to set.
2678 *
2679 * @see MotionEvent#AXIS_X
2680 * @see MotionEvent#AXIS_Y
2681 */
2682 public void setAxisValue(int axis, float value) {
2683 switch (axis) {
2684 case AXIS_X:
2685 x = value;
2686 break;
2687 case AXIS_Y:
2688 y = value;
2689 break;
2690 case AXIS_PRESSURE:
2691 pressure = value;
2692 break;
2693 case AXIS_SIZE:
2694 size = value;
2695 break;
2696 case AXIS_TOUCH_MAJOR:
2697 touchMajor = value;
2698 break;
2699 case AXIS_TOUCH_MINOR:
2700 touchMinor = value;
2701 break;
2702 case AXIS_TOOL_MAJOR:
2703 toolMajor = value;
2704 break;
2705 case AXIS_TOOL_MINOR:
2706 toolMinor = value;
2707 break;
2708 case AXIS_ORIENTATION:
2709 orientation = value;
2710 break;
2711 default: {
Jeff Brown6f2fba42011-02-19 01:08:02 -08002712 if (axis < 0 || axis > 63) {
2713 throw new IllegalArgumentException("Axis out of range.");
2714 }
2715 final long bits = mPackedAxisBits;
2716 final long axisBit = 1L << axis;
2717 final int index = Long.bitCount(bits & (axisBit - 1L));
Jeff Brown91c69ab2011-02-14 17:03:18 -08002718 float[] values = mPackedAxisValues;
2719 if ((bits & axisBit) == 0) {
2720 if (values == null) {
2721 values = new float[INITIAL_PACKED_AXIS_VALUES];
2722 mPackedAxisValues = values;
2723 } else {
Jeff Brown6f2fba42011-02-19 01:08:02 -08002724 final int count = Long.bitCount(bits);
Jeff Brown91c69ab2011-02-14 17:03:18 -08002725 if (count < values.length) {
2726 if (index != count) {
2727 System.arraycopy(values, index, values, index + 1,
2728 count - index);
2729 }
2730 } else {
2731 float[] newValues = new float[count * 2];
2732 System.arraycopy(values, 0, newValues, 0, index);
2733 System.arraycopy(values, index, newValues, index + 1,
2734 count - index);
2735 values = newValues;
2736 mPackedAxisValues = values;
2737 }
2738 }
2739 mPackedAxisBits = bits | axisBit;
2740 }
2741 values[index] = value;
2742 }
2743 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002744 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002745 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002746}