MotionEvent.java revision 5a77c3748817eb120fc6c988ccfe2d31069f6325
1/*
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
19import android.annotation.TestApi;
20import android.graphics.Matrix;
21import android.os.Parcel;
22import android.os.Parcelable;
23import android.os.SystemClock;
24import android.util.SparseArray;
25
26import dalvik.annotation.optimization.CriticalNative;
27import dalvik.annotation.optimization.FastNative;
28
29/**
30 * Object used to report movement (mouse, pen, finger, trackball) events.
31 * Motion events may hold either absolute or relative movements and other data,
32 * depending on the type of device.
33 *
34 * <h3>Overview</h3>
35 * <p>
36 * Motion events describe movements in terms of an action code and a set of axis values.
37 * The action code specifies the state change that occurred such as a pointer going
38 * down or up.  The axis values describe the position and other movement properties.
39 * </p><p>
40 * For example, when the user first touches the screen, the system delivers a touch
41 * event to the appropriate {@link View} with the action code {@link #ACTION_DOWN}
42 * and a set of axis values that include the X and Y coordinates of the touch and
43 * information about the pressure, size and orientation of the contact area.
44 * </p><p>
45 * Some devices can report multiple movement traces at the same time.  Multi-touch
46 * screens emit one movement trace for each finger.  The individual fingers or
47 * other objects that generate movement traces are referred to as <em>pointers</em>.
48 * Motion events contain information about all of the pointers that are currently active
49 * even if some of them have not moved since the last event was delivered.
50 * </p><p>
51 * The number of pointers only ever changes by one as individual pointers go up and down,
52 * except when the gesture is canceled.
53 * </p><p>
54 * Each pointer has a unique id that is assigned when it first goes down
55 * (indicated by {@link #ACTION_DOWN} or {@link #ACTION_POINTER_DOWN}).  A pointer id
56 * remains valid until the pointer eventually goes up (indicated by {@link #ACTION_UP}
57 * or {@link #ACTION_POINTER_UP}) or when the gesture is canceled (indicated by
58 * {@link #ACTION_CANCEL}).
59 * </p><p>
60 * The MotionEvent class provides many methods to query the position and other properties of
61 * pointers, such as {@link #getX(int)}, {@link #getY(int)}, {@link #getAxisValue},
62 * {@link #getPointerId(int)}, {@link #getToolType(int)}, and many others.  Most of these
63 * methods accept the pointer index as a parameter rather than the pointer id.
64 * The pointer index of each pointer in the event ranges from 0 to one less than the value
65 * returned by {@link #getPointerCount()}.
66 * </p><p>
67 * The order in which individual pointers appear within a motion event is undefined.
68 * Thus the pointer index of a pointer can change from one event to the next but
69 * the pointer id of a pointer is guaranteed to remain constant as long as the pointer
70 * remains active.  Use the {@link #getPointerId(int)} method to obtain the
71 * pointer id of a pointer to track it across all subsequent motion events in a gesture.
72 * Then for successive motion events, use the {@link #findPointerIndex(int)} method
73 * to obtain the pointer index for a given pointer id in that motion event.
74 * </p><p>
75 * Mouse and stylus buttons can be retrieved using {@link #getButtonState()}.  It is a
76 * good idea to check the button state while handling {@link #ACTION_DOWN} as part
77 * of a touch event.  The application may choose to perform some different action
78 * if the touch event starts due to a secondary button click, such as presenting a
79 * context menu.
80 * </p>
81 *
82 * <h3>Batching</h3>
83 * <p>
84 * For efficiency, motion events with {@link #ACTION_MOVE} may batch together
85 * multiple movement samples within a single object.  The most current
86 * pointer coordinates are available using {@link #getX(int)} and {@link #getY(int)}.
87 * Earlier coordinates within the batch are accessed using {@link #getHistoricalX(int, int)}
88 * and {@link #getHistoricalY(int, int)}.  The coordinates are "historical" only
89 * insofar as they are older than the current coordinates in the batch; however,
90 * they are still distinct from any other coordinates reported in prior motion events.
91 * To process all coordinates in the batch in time order, first consume the historical
92 * coordinates then consume the current coordinates.
93 * </p><p>
94 * Example: Consuming all samples for all pointers in a motion event in time order.
95 * </p><p><pre><code>
96 * void printSamples(MotionEvent ev) {
97 *     final int historySize = ev.getHistorySize();
98 *     final int pointerCount = ev.getPointerCount();
99 *     for (int h = 0; h &lt; historySize; h++) {
100 *         System.out.printf("At time %d:", ev.getHistoricalEventTime(h));
101 *         for (int p = 0; p &lt; pointerCount; p++) {
102 *             System.out.printf("  pointer %d: (%f,%f)",
103 *                 ev.getPointerId(p), ev.getHistoricalX(p, h), ev.getHistoricalY(p, h));
104 *         }
105 *     }
106 *     System.out.printf("At time %d:", ev.getEventTime());
107 *     for (int p = 0; p &lt; pointerCount; p++) {
108 *         System.out.printf("  pointer %d: (%f,%f)",
109 *             ev.getPointerId(p), ev.getX(p), ev.getY(p));
110 *     }
111 * }
112 * </code></pre></p>
113 *
114 * <h3>Device Types</h3>
115 * <p>
116 * The interpretation of the contents of a MotionEvent varies significantly depending
117 * on the source class of the device.
118 * </p><p>
119 * On pointing devices with source class {@link InputDevice#SOURCE_CLASS_POINTER}
120 * such as touch screens, the pointer coordinates specify absolute
121 * positions such as view X/Y coordinates.  Each complete gesture is represented
122 * by a sequence of motion events with actions that describe pointer state transitions
123 * and movements.  A gesture starts with a motion event with {@link #ACTION_DOWN}
124 * that provides the location of the first pointer down.  As each additional
125 * pointer that goes down or up, the framework will generate a motion event with
126 * {@link #ACTION_POINTER_DOWN} or {@link #ACTION_POINTER_UP} accordingly.
127 * Pointer movements are described by motion events with {@link #ACTION_MOVE}.
128 * Finally, a gesture end either when the final pointer goes up as represented
129 * by a motion event with {@link #ACTION_UP} or when gesture is canceled
130 * with {@link #ACTION_CANCEL}.
131 * </p><p>
132 * Some pointing devices such as mice may support vertical and/or horizontal scrolling.
133 * A scroll event is reported as a generic motion event with {@link #ACTION_SCROLL} that
134 * includes the relative scroll offset in the {@link #AXIS_VSCROLL} and
135 * {@link #AXIS_HSCROLL} axes.  See {@link #getAxisValue(int)} for information
136 * about retrieving these additional axes.
137 * </p><p>
138 * On trackball devices with source class {@link InputDevice#SOURCE_CLASS_TRACKBALL},
139 * the pointer coordinates specify relative movements as X/Y deltas.
140 * A trackball gesture consists of a sequence of movements described by motion
141 * events with {@link #ACTION_MOVE} interspersed with occasional {@link #ACTION_DOWN}
142 * or {@link #ACTION_UP} motion events when the trackball button is pressed or released.
143 * </p><p>
144 * On joystick devices with source class {@link InputDevice#SOURCE_CLASS_JOYSTICK},
145 * the pointer coordinates specify the absolute position of the joystick axes.
146 * The joystick axis values are normalized to a range of -1.0 to 1.0 where 0.0 corresponds
147 * to the center position.  More information about the set of available axes and the
148 * range of motion can be obtained using {@link InputDevice#getMotionRange}.
149 * Some common joystick axes are {@link #AXIS_X}, {@link #AXIS_Y},
150 * {@link #AXIS_HAT_X}, {@link #AXIS_HAT_Y}, {@link #AXIS_Z} and {@link #AXIS_RZ}.
151 * </p><p>
152 * Refer to {@link InputDevice} for more information about how different kinds of
153 * input devices and sources represent pointer coordinates.
154 * </p>
155 *
156 * <h3>Consistency Guarantees</h3>
157 * <p>
158 * Motion events are always delivered to views as a consistent stream of events.
159 * What constitutes a consistent stream varies depending on the type of device.
160 * For touch events, consistency implies that pointers go down one at a time,
161 * move around as a group and then go up one at a time or are canceled.
162 * </p><p>
163 * While the framework tries to deliver consistent streams of motion events to
164 * views, it cannot guarantee it.  Some events may be dropped or modified by
165 * containing views in the application before they are delivered thereby making
166 * the stream of events inconsistent.  Views should always be prepared to
167 * handle {@link #ACTION_CANCEL} and should tolerate anomalous
168 * situations such as receiving a new {@link #ACTION_DOWN} without first having
169 * received an {@link #ACTION_UP} for the prior gesture.
170 * </p>
171 */
172public final class MotionEvent extends InputEvent implements Parcelable {
173    private static final long NS_PER_MS = 1000000;
174    private static final String LABEL_PREFIX = "AXIS_";
175
176    /**
177     * An invalid pointer id.
178     *
179     * This value (-1) can be used as a placeholder to indicate that a pointer id
180     * has not been assigned or is not available.  It cannot appear as
181     * a pointer id inside a {@link MotionEvent}.
182     */
183    public static final int INVALID_POINTER_ID = -1;
184
185    /**
186     * Bit mask of the parts of the action code that are the action itself.
187     */
188    public static final int ACTION_MASK             = 0xff;
189
190    /**
191     * Constant for {@link #getActionMasked}: A pressed gesture has started, the
192     * motion contains the initial starting location.
193     * <p>
194     * This is also a good time to check the button state to distinguish
195     * secondary and tertiary button clicks and handle them appropriately.
196     * Use {@link #getButtonState} to retrieve the button state.
197     * </p>
198     */
199    public static final int ACTION_DOWN             = 0;
200
201    /**
202     * Constant for {@link #getActionMasked}: A pressed gesture has finished, the
203     * motion contains the final release location as well as any intermediate
204     * points since the last down or move event.
205     */
206    public static final int ACTION_UP               = 1;
207
208    /**
209     * Constant for {@link #getActionMasked}: A change has happened during a
210     * press gesture (between {@link #ACTION_DOWN} and {@link #ACTION_UP}).
211     * The motion contains the most recent point, as well as any intermediate
212     * points since the last down or move event.
213     */
214    public static final int ACTION_MOVE             = 2;
215
216    /**
217     * Constant for {@link #getActionMasked}: The current gesture has been aborted.
218     * You will not receive any more points in it.  You should treat this as
219     * an up event, but not perform any action that you normally would.
220     */
221    public static final int ACTION_CANCEL           = 3;
222
223    /**
224     * Constant for {@link #getActionMasked}: A movement has happened outside of the
225     * normal bounds of the UI element.  This does not provide a full gesture,
226     * but only the initial location of the movement/touch.
227     */
228    public static final int ACTION_OUTSIDE          = 4;
229
230    /**
231     * Constant for {@link #getActionMasked}: A non-primary pointer has gone down.
232     * <p>
233     * Use {@link #getActionIndex} to retrieve the index of the pointer that changed.
234     * </p><p>
235     * The index is encoded in the {@link #ACTION_POINTER_INDEX_MASK} bits of the
236     * unmasked action returned by {@link #getAction}.
237     * </p>
238     */
239    public static final int ACTION_POINTER_DOWN     = 5;
240
241    /**
242     * Constant for {@link #getActionMasked}: A non-primary pointer has gone up.
243     * <p>
244     * Use {@link #getActionIndex} to retrieve the index of the pointer that changed.
245     * </p><p>
246     * The index is encoded in the {@link #ACTION_POINTER_INDEX_MASK} bits of the
247     * unmasked action returned by {@link #getAction}.
248     * </p>
249     */
250    public static final int ACTION_POINTER_UP       = 6;
251
252    /**
253     * Constant for {@link #getActionMasked}: A change happened but the pointer
254     * is not down (unlike {@link #ACTION_MOVE}).  The motion contains the most
255     * recent point, as well as any intermediate points since the last
256     * hover move event.
257     * <p>
258     * This action is always delivered to the window or view under the pointer.
259     * </p><p>
260     * This action is not a touch event so it is delivered to
261     * {@link View#onGenericMotionEvent(MotionEvent)} rather than
262     * {@link View#onTouchEvent(MotionEvent)}.
263     * </p>
264     */
265    public static final int ACTION_HOVER_MOVE       = 7;
266
267    /**
268     * Constant for {@link #getActionMasked}: The motion event contains relative
269     * vertical and/or horizontal scroll offsets.  Use {@link #getAxisValue(int)}
270     * to retrieve the information from {@link #AXIS_VSCROLL} and {@link #AXIS_HSCROLL}.
271     * The pointer may or may not be down when this event is dispatched.
272     * <p>
273     * This action is always delivered to the window or view under the pointer, which
274     * may not be the window or view currently touched.
275     * </p><p>
276     * This action is not a touch event so it is delivered to
277     * {@link View#onGenericMotionEvent(MotionEvent)} rather than
278     * {@link View#onTouchEvent(MotionEvent)}.
279     * </p>
280     */
281    public static final int ACTION_SCROLL           = 8;
282
283    /**
284     * Constant for {@link #getActionMasked}: The pointer is not down but has entered the
285     * boundaries of a window or view.
286     * <p>
287     * This action is always delivered to the window or view under the pointer.
288     * </p><p>
289     * This action is not a touch event so it is delivered to
290     * {@link View#onGenericMotionEvent(MotionEvent)} rather than
291     * {@link View#onTouchEvent(MotionEvent)}.
292     * </p>
293     */
294    public static final int ACTION_HOVER_ENTER      = 9;
295
296    /**
297     * Constant for {@link #getActionMasked}: The pointer is not down but has exited the
298     * boundaries of a window or view.
299     * <p>
300     * This action is always delivered to the window or view that was previously under the pointer.
301     * </p><p>
302     * This action is not a touch event so it is delivered to
303     * {@link View#onGenericMotionEvent(MotionEvent)} rather than
304     * {@link View#onTouchEvent(MotionEvent)}.
305     * </p>
306     */
307    public static final int ACTION_HOVER_EXIT       = 10;
308
309    /**
310     * Constant for {@link #getActionMasked}: A button has been pressed.
311     *
312     * <p>
313     * Use {@link #getActionButton()} to get which button was pressed.
314     * </p><p>
315     * This action is not a touch event so it is delivered to
316     * {@link View#onGenericMotionEvent(MotionEvent)} rather than
317     * {@link View#onTouchEvent(MotionEvent)}.
318     * </p>
319     */
320    public static final int ACTION_BUTTON_PRESS   = 11;
321
322    /**
323     * Constant for {@link #getActionMasked}: A button has been released.
324     *
325     * <p>
326     * Use {@link #getActionButton()} to get which button was released.
327     * </p><p>
328     * This action is not a touch event so it is delivered to
329     * {@link View#onGenericMotionEvent(MotionEvent)} rather than
330     * {@link View#onTouchEvent(MotionEvent)}.
331     * </p>
332     */
333    public static final int ACTION_BUTTON_RELEASE  = 12;
334
335    /**
336     * Bits in the action code that represent a pointer index, used with
337     * {@link #ACTION_POINTER_DOWN} and {@link #ACTION_POINTER_UP}.  Shifting
338     * down by {@link #ACTION_POINTER_INDEX_SHIFT} provides the actual pointer
339     * index where the data for the pointer going up or down can be found; you can
340     * get its identifier with {@link #getPointerId(int)} and the actual
341     * data with {@link #getX(int)} etc.
342     *
343     * @see #getActionIndex
344     */
345    public static final int ACTION_POINTER_INDEX_MASK  = 0xff00;
346
347    /**
348     * Bit shift for the action bits holding the pointer index as
349     * defined by {@link #ACTION_POINTER_INDEX_MASK}.
350     *
351     * @see #getActionIndex
352     */
353    public static final int ACTION_POINTER_INDEX_SHIFT = 8;
354
355    /**
356     * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the
357     * data index associated with {@link #ACTION_POINTER_DOWN}.
358     */
359    @Deprecated
360    public static final int ACTION_POINTER_1_DOWN   = ACTION_POINTER_DOWN | 0x0000;
361
362    /**
363     * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the
364     * data index associated with {@link #ACTION_POINTER_DOWN}.
365     */
366    @Deprecated
367    public static final int ACTION_POINTER_2_DOWN   = ACTION_POINTER_DOWN | 0x0100;
368
369    /**
370     * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the
371     * data index associated with {@link #ACTION_POINTER_DOWN}.
372     */
373    @Deprecated
374    public static final int ACTION_POINTER_3_DOWN   = ACTION_POINTER_DOWN | 0x0200;
375
376    /**
377     * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the
378     * data index associated with {@link #ACTION_POINTER_UP}.
379     */
380    @Deprecated
381    public static final int ACTION_POINTER_1_UP     = ACTION_POINTER_UP | 0x0000;
382
383    /**
384     * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the
385     * data index associated with {@link #ACTION_POINTER_UP}.
386     */
387    @Deprecated
388    public static final int ACTION_POINTER_2_UP     = ACTION_POINTER_UP | 0x0100;
389
390    /**
391     * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the
392     * data index associated with {@link #ACTION_POINTER_UP}.
393     */
394    @Deprecated
395    public static final int ACTION_POINTER_3_UP     = ACTION_POINTER_UP | 0x0200;
396
397    /**
398     * @deprecated Renamed to {@link #ACTION_POINTER_INDEX_MASK} to match
399     * the actual data contained in these bits.
400     */
401    @Deprecated
402    public static final int ACTION_POINTER_ID_MASK  = 0xff00;
403
404    /**
405     * @deprecated Renamed to {@link #ACTION_POINTER_INDEX_SHIFT} to match
406     * the actual data contained in these bits.
407     */
408    @Deprecated
409    public static final int ACTION_POINTER_ID_SHIFT = 8;
410
411    /**
412     * This flag indicates that the window that received this motion event is partly
413     * or wholly obscured by another visible window above it.  This flag is set to true
414     * even if the event did not directly pass through the obscured area.
415     * A security sensitive application can check this flag to identify situations in which
416     * a malicious application may have covered up part of its content for the purpose
417     * of misleading the user or hijacking touches.  An appropriate response might be
418     * to drop the suspect touches or to take additional precautions to confirm the user's
419     * actual intent.
420     */
421    public static final int FLAG_WINDOW_IS_OBSCURED = 0x1;
422
423    /**
424     * This flag indicates that the window that received this motion event is partly
425     * or wholly obscured by another visible window above it.  This flag is set to true
426     * even if the event did not directly pass through the obscured area.
427     * A security sensitive application can check this flag to identify situations in which
428     * a malicious application may have covered up part of its content for the purpose
429     * of misleading the user or hijacking touches.  An appropriate response might be
430     * to drop the suspect touches or to take additional precautions to confirm the user's
431     * actual intent.
432     *
433     * Unlike FLAG_WINDOW_IS_OBSCURED, this is actually true.
434     * @hide
435     */
436    public static final int FLAG_WINDOW_IS_PARTIALLY_OBSCURED = 0x2;
437
438    /**
439     * This private flag is only set on {@link #ACTION_HOVER_MOVE} events and indicates that
440     * this event will be immediately followed by a {@link #ACTION_HOVER_EXIT}. It is used to
441     * prevent generating redundant {@link #ACTION_HOVER_ENTER} events.
442     * @hide
443     */
444    public static final int FLAG_HOVER_EXIT_PENDING = 0x4;
445
446    /**
447     * Private flag that indicates when the system has detected that this motion event
448     * may be inconsistent with respect to the sequence of previously delivered motion events,
449     * such as when a pointer move event is sent but the pointer is not down.
450     *
451     * @hide
452     * @see #isTainted
453     * @see #setTainted
454     */
455    public static final int FLAG_TAINTED = 0x80000000;
456
457    /**
458     * Private flag indicating that this event was synthesized by the system and
459     * should be delivered to the accessibility focused view first. When being
460     * dispatched such an event is not handled by predecessors of the accessibility
461     * focused view and after the event reaches that view the flag is cleared and
462     * normal event dispatch is performed. This ensures that the platform can click
463     * on any view that has accessibility focus which is semantically equivalent to
464     * asking the view to perform a click accessibility action but more generic as
465     * views not implementing click action correctly can still be activated.
466     *
467     * @hide
468     * @see #isTargetAccessibilityFocus()
469     * @see #setTargetAccessibilityFocus(boolean)
470     */
471    public static final int FLAG_TARGET_ACCESSIBILITY_FOCUS = 0x40000000;
472
473
474    /**
475     * Flag indicating the motion event intersected the top edge of the screen.
476     */
477    public static final int EDGE_TOP = 0x00000001;
478
479    /**
480     * Flag indicating the motion event intersected the bottom edge of the screen.
481     */
482    public static final int EDGE_BOTTOM = 0x00000002;
483
484    /**
485     * Flag indicating the motion event intersected the left edge of the screen.
486     */
487    public static final int EDGE_LEFT = 0x00000004;
488
489    /**
490     * Flag indicating the motion event intersected the right edge of the screen.
491     */
492    public static final int EDGE_RIGHT = 0x00000008;
493
494    /**
495     * Axis constant: X axis of a motion event.
496     * <p>
497     * <ul>
498     * <li>For a touch screen, reports the absolute X screen position of the center of
499     * the touch contact area.  The units are display pixels.
500     * <li>For a touch pad, reports the absolute X surface position of the center of the touch
501     * contact area.  The units are device-dependent; use {@link InputDevice#getMotionRange(int)}
502     * to query the effective range of values.
503     * <li>For a mouse, reports the absolute X screen position of the mouse pointer.
504     * The units are display pixels.
505     * <li>For a trackball, reports the relative horizontal displacement of the trackball.
506     * The value is normalized to a range from -1.0 (left) to 1.0 (right).
507     * <li>For a joystick, reports the absolute X position of the joystick.
508     * The value is normalized to a range from -1.0 (left) to 1.0 (right).
509     * </ul>
510     * </p>
511     *
512     * @see #getX(int)
513     * @see #getHistoricalX(int, int)
514     * @see MotionEvent.PointerCoords#x
515     * @see InputDevice#getMotionRange
516     */
517    public static final int AXIS_X = 0;
518
519    /**
520     * Axis constant: Y axis of a motion event.
521     * <p>
522     * <ul>
523     * <li>For a touch screen, reports the absolute Y screen position of the center of
524     * the touch contact area.  The units are display pixels.
525     * <li>For a touch pad, reports the absolute Y surface position of the center of the touch
526     * contact area.  The units are device-dependent; use {@link InputDevice#getMotionRange(int)}
527     * to query the effective range of values.
528     * <li>For a mouse, reports the absolute Y screen position of the mouse pointer.
529     * The units are display pixels.
530     * <li>For a trackball, reports the relative vertical displacement of the trackball.
531     * The value is normalized to a range from -1.0 (up) to 1.0 (down).
532     * <li>For a joystick, reports the absolute Y position of the joystick.
533     * The value is normalized to a range from -1.0 (up or far) to 1.0 (down or near).
534     * </ul>
535     * </p>
536     *
537     * @see #getY(int)
538     * @see #getHistoricalY(int, int)
539     * @see MotionEvent.PointerCoords#y
540     * @see InputDevice#getMotionRange
541     */
542    public static final int AXIS_Y = 1;
543
544    /**
545     * Axis constant: Pressure axis of a motion event.
546     * <p>
547     * <ul>
548     * <li>For a touch screen or touch pad, reports the approximate pressure applied to the surface
549     * by a finger or other tool.  The value is normalized to a range from
550     * 0 (no pressure at all) to 1 (normal pressure), although values higher than 1
551     * may be generated depending on the calibration of the input device.
552     * <li>For a trackball, the value is set to 1 if the trackball button is pressed
553     * or 0 otherwise.
554     * <li>For a mouse, the value is set to 1 if the primary mouse button is pressed
555     * or 0 otherwise.
556     * </ul>
557     * </p>
558     *
559     * @see #getPressure(int)
560     * @see #getHistoricalPressure(int, int)
561     * @see MotionEvent.PointerCoords#pressure
562     * @see InputDevice#getMotionRange
563     */
564    public static final int AXIS_PRESSURE = 2;
565
566    /**
567     * Axis constant: Size axis of a motion event.
568     * <p>
569     * <ul>
570     * <li>For a touch screen or touch pad, reports the approximate size of the contact area in
571     * relation to the maximum detectable size for the device.  The value is normalized
572     * to a range from 0 (smallest detectable size) to 1 (largest detectable size),
573     * although it is not a linear scale.  This value is of limited use.
574     * To obtain calibrated size information, use
575     * {@link #AXIS_TOUCH_MAJOR} or {@link #AXIS_TOOL_MAJOR}.
576     * </ul>
577     * </p>
578     *
579     * @see #getSize(int)
580     * @see #getHistoricalSize(int, int)
581     * @see MotionEvent.PointerCoords#size
582     * @see InputDevice#getMotionRange
583     */
584    public static final int AXIS_SIZE = 3;
585
586    /**
587     * Axis constant: TouchMajor axis of a motion event.
588     * <p>
589     * <ul>
590     * <li>For a touch screen, reports the length of the major axis of an ellipse that
591     * represents the touch area at the point of contact.
592     * The units are display pixels.
593     * <li>For a touch pad, reports the length of the major axis of an ellipse that
594     * represents the touch area at the point of contact.
595     * The units are device-dependent; use {@link InputDevice#getMotionRange(int)}
596     * to query the effective range of values.
597     * </ul>
598     * </p>
599     *
600     * @see #getTouchMajor(int)
601     * @see #getHistoricalTouchMajor(int, int)
602     * @see MotionEvent.PointerCoords#touchMajor
603     * @see InputDevice#getMotionRange
604     */
605    public static final int AXIS_TOUCH_MAJOR = 4;
606
607    /**
608     * Axis constant: TouchMinor axis of a motion event.
609     * <p>
610     * <ul>
611     * <li>For a touch screen, reports the length of the minor axis of an ellipse that
612     * represents the touch area at the point of contact.
613     * The units are display pixels.
614     * <li>For a touch pad, reports the length of the minor axis of an ellipse that
615     * represents the touch area at the point of contact.
616     * The units are device-dependent; use {@link InputDevice#getMotionRange(int)}
617     * to query the effective range of values.
618     * </ul>
619     * </p><p>
620     * When the touch is circular, the major and minor axis lengths will be equal to one another.
621     * </p>
622     *
623     * @see #getTouchMinor(int)
624     * @see #getHistoricalTouchMinor(int, int)
625     * @see MotionEvent.PointerCoords#touchMinor
626     * @see InputDevice#getMotionRange
627     */
628    public static final int AXIS_TOUCH_MINOR = 5;
629
630    /**
631     * Axis constant: ToolMajor axis of a motion event.
632     * <p>
633     * <ul>
634     * <li>For a touch screen, reports the length of the major axis of an ellipse that
635     * represents the size of the approaching finger or tool used to make contact.
636     * <li>For a touch pad, reports the length of the major axis of an ellipse that
637     * represents the size of the approaching finger or tool used to make contact.
638     * The units are device-dependent; use {@link InputDevice#getMotionRange(int)}
639     * to query the effective range of values.
640     * </ul>
641     * </p><p>
642     * When the touch is circular, the major and minor axis lengths will be equal to one another.
643     * </p><p>
644     * The tool size may be larger than the touch size since the tool may not be fully
645     * in contact with the touch sensor.
646     * </p>
647     *
648     * @see #getToolMajor(int)
649     * @see #getHistoricalToolMajor(int, int)
650     * @see MotionEvent.PointerCoords#toolMajor
651     * @see InputDevice#getMotionRange
652     */
653    public static final int AXIS_TOOL_MAJOR = 6;
654
655    /**
656     * Axis constant: ToolMinor axis of a motion event.
657     * <p>
658     * <ul>
659     * <li>For a touch screen, reports the length of the minor axis of an ellipse that
660     * represents the size of the approaching finger or tool used to make contact.
661     * <li>For a touch pad, reports the length of the minor axis of an ellipse that
662     * represents the size of the approaching finger or tool used to make contact.
663     * The units are device-dependent; use {@link InputDevice#getMotionRange(int)}
664     * to query the effective range of values.
665     * </ul>
666     * </p><p>
667     * When the touch is circular, the major and minor axis lengths will be equal to one another.
668     * </p><p>
669     * The tool size may be larger than the touch size since the tool may not be fully
670     * in contact with the touch sensor.
671     * </p>
672     *
673     * @see #getToolMinor(int)
674     * @see #getHistoricalToolMinor(int, int)
675     * @see MotionEvent.PointerCoords#toolMinor
676     * @see InputDevice#getMotionRange
677     */
678    public static final int AXIS_TOOL_MINOR = 7;
679
680    /**
681     * Axis constant: Orientation axis of a motion event.
682     * <p>
683     * <ul>
684     * <li>For a touch screen or touch pad, reports the orientation of the finger
685     * or tool in radians relative to the vertical plane of the device.
686     * An angle of 0 radians indicates that the major axis of contact is oriented
687     * upwards, is perfectly circular or is of unknown orientation.  A positive angle
688     * indicates that the major axis of contact is oriented to the right.  A negative angle
689     * indicates that the major axis of contact is oriented to the left.
690     * The full range is from -PI/2 radians (finger pointing fully left) to PI/2 radians
691     * (finger pointing fully right).
692     * <li>For a stylus, the orientation indicates the direction in which the stylus
693     * is pointing in relation to the vertical axis of the current orientation of the screen.
694     * The range is from -PI radians to PI radians, where 0 is pointing up,
695     * -PI/2 radians is pointing left, -PI or PI radians is pointing down, and PI/2 radians
696     * is pointing right.  See also {@link #AXIS_TILT}.
697     * </ul>
698     * </p>
699     *
700     * @see #getOrientation(int)
701     * @see #getHistoricalOrientation(int, int)
702     * @see MotionEvent.PointerCoords#orientation
703     * @see InputDevice#getMotionRange
704     */
705    public static final int AXIS_ORIENTATION = 8;
706
707    /**
708     * Axis constant: Vertical Scroll axis of a motion event.
709     * <p>
710     * <ul>
711     * <li>For a mouse, reports the relative movement of the vertical scroll wheel.
712     * The value is normalized to a range from -1.0 (down) to 1.0 (up).
713     * </ul>
714     * </p><p>
715     * This axis should be used to scroll views vertically.
716     * </p>
717     *
718     * @see #getAxisValue(int, int)
719     * @see #getHistoricalAxisValue(int, int, int)
720     * @see MotionEvent.PointerCoords#getAxisValue(int)
721     * @see InputDevice#getMotionRange
722     */
723    public static final int AXIS_VSCROLL = 9;
724
725    /**
726     * Axis constant: Horizontal Scroll axis of a motion event.
727     * <p>
728     * <ul>
729     * <li>For a mouse, reports the relative movement of the horizontal scroll wheel.
730     * The value is normalized to a range from -1.0 (left) to 1.0 (right).
731     * </ul>
732     * </p><p>
733     * This axis should be used to scroll views horizontally.
734     * </p>
735     *
736     * @see #getAxisValue(int, int)
737     * @see #getHistoricalAxisValue(int, int, int)
738     * @see MotionEvent.PointerCoords#getAxisValue(int)
739     * @see InputDevice#getMotionRange
740     */
741    public static final int AXIS_HSCROLL = 10;
742
743    /**
744     * Axis constant: Z axis of a motion event.
745     * <p>
746     * <ul>
747     * <li>For a joystick, reports the absolute Z position of the joystick.
748     * The value is normalized to a range from -1.0 (high) to 1.0 (low).
749     * <em>On game pads with two analog joysticks, this axis is often reinterpreted
750     * to report the absolute X position of the second joystick instead.</em>
751     * </ul>
752     * </p>
753     *
754     * @see #getAxisValue(int, int)
755     * @see #getHistoricalAxisValue(int, int, int)
756     * @see MotionEvent.PointerCoords#getAxisValue(int)
757     * @see InputDevice#getMotionRange
758     */
759    public static final int AXIS_Z = 11;
760
761    /**
762     * Axis constant: X Rotation axis of a motion event.
763     * <p>
764     * <ul>
765     * <li>For a joystick, reports the absolute rotation angle about the X axis.
766     * The value is normalized to a range from -1.0 (counter-clockwise) to 1.0 (clockwise).
767     * </ul>
768     * </p>
769     *
770     * @see #getAxisValue(int, int)
771     * @see #getHistoricalAxisValue(int, int, int)
772     * @see MotionEvent.PointerCoords#getAxisValue(int)
773     * @see InputDevice#getMotionRange
774     */
775    public static final int AXIS_RX = 12;
776
777    /**
778     * Axis constant: Y Rotation axis of a motion event.
779     * <p>
780     * <ul>
781     * <li>For a joystick, reports the absolute rotation angle about the Y axis.
782     * The value is normalized to a range from -1.0 (counter-clockwise) to 1.0 (clockwise).
783     * </ul>
784     * </p>
785     *
786     * @see #getAxisValue(int, int)
787     * @see #getHistoricalAxisValue(int, int, int)
788     * @see MotionEvent.PointerCoords#getAxisValue(int)
789     * @see InputDevice#getMotionRange
790     */
791    public static final int AXIS_RY = 13;
792
793    /**
794     * Axis constant: Z Rotation axis of a motion event.
795     * <p>
796     * <ul>
797     * <li>For a joystick, reports the absolute rotation angle about the Z axis.
798     * The value is normalized to a range from -1.0 (counter-clockwise) to 1.0 (clockwise).
799     * <em>On game pads with two analog joysticks, this axis is often reinterpreted
800     * to report the absolute Y position of the second joystick instead.</em>
801     * </ul>
802     * </p>
803     *
804     * @see #getAxisValue(int, int)
805     * @see #getHistoricalAxisValue(int, int, int)
806     * @see MotionEvent.PointerCoords#getAxisValue(int)
807     * @see InputDevice#getMotionRange
808     */
809    public static final int AXIS_RZ = 14;
810
811    /**
812     * Axis constant: Hat X axis of a motion event.
813     * <p>
814     * <ul>
815     * <li>For a joystick, reports the absolute X position of the directional hat control.
816     * The value is normalized to a range from -1.0 (left) to 1.0 (right).
817     * </ul>
818     * </p>
819     *
820     * @see #getAxisValue(int, int)
821     * @see #getHistoricalAxisValue(int, int, int)
822     * @see MotionEvent.PointerCoords#getAxisValue(int)
823     * @see InputDevice#getMotionRange
824     */
825    public static final int AXIS_HAT_X = 15;
826
827    /**
828     * Axis constant: Hat Y axis of a motion event.
829     * <p>
830     * <ul>
831     * <li>For a joystick, reports the absolute Y position of the directional hat control.
832     * The value is normalized to a range from -1.0 (up) to 1.0 (down).
833     * </ul>
834     * </p>
835     *
836     * @see #getAxisValue(int, int)
837     * @see #getHistoricalAxisValue(int, int, int)
838     * @see MotionEvent.PointerCoords#getAxisValue(int)
839     * @see InputDevice#getMotionRange
840     */
841    public static final int AXIS_HAT_Y = 16;
842
843    /**
844     * Axis constant: Left Trigger axis of a motion event.
845     * <p>
846     * <ul>
847     * <li>For a joystick, reports the absolute position of the left trigger control.
848     * The value is normalized to a range from 0.0 (released) to 1.0 (fully pressed).
849     * </ul>
850     * </p>
851     *
852     * @see #getAxisValue(int, int)
853     * @see #getHistoricalAxisValue(int, int, int)
854     * @see MotionEvent.PointerCoords#getAxisValue(int)
855     * @see InputDevice#getMotionRange
856     */
857    public static final int AXIS_LTRIGGER = 17;
858
859    /**
860     * Axis constant: Right Trigger axis of a motion event.
861     * <p>
862     * <ul>
863     * <li>For a joystick, reports the absolute position of the right trigger control.
864     * The value is normalized to a range from 0.0 (released) to 1.0 (fully pressed).
865     * </ul>
866     * </p>
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_RTRIGGER = 18;
874
875    /**
876     * Axis constant: Throttle axis of a motion event.
877     * <p>
878     * <ul>
879     * <li>For a joystick, reports the absolute position of the throttle control.
880     * The value is normalized to a range from 0.0 (fully open) to 1.0 (fully closed).
881     * </ul>
882     * </p>
883     *
884     * @see #getAxisValue(int, int)
885     * @see #getHistoricalAxisValue(int, int, int)
886     * @see MotionEvent.PointerCoords#getAxisValue(int)
887     * @see InputDevice#getMotionRange
888     */
889    public static final int AXIS_THROTTLE = 19;
890
891    /**
892     * Axis constant: Rudder axis of a motion event.
893     * <p>
894     * <ul>
895     * <li>For a joystick, reports the absolute position of the rudder control.
896     * The value is normalized to a range from -1.0 (turn left) to 1.0 (turn right).
897     * </ul>
898     * </p>
899     *
900     * @see #getAxisValue(int, int)
901     * @see #getHistoricalAxisValue(int, int, int)
902     * @see MotionEvent.PointerCoords#getAxisValue(int)
903     * @see InputDevice#getMotionRange
904     */
905    public static final int AXIS_RUDDER = 20;
906
907    /**
908     * Axis constant: Wheel axis of a motion event.
909     * <p>
910     * <ul>
911     * <li>For a joystick, reports the absolute position of the steering wheel control.
912     * The value is normalized to a range from -1.0 (turn left) to 1.0 (turn right).
913     * </ul>
914     * </p>
915     *
916     * @see #getAxisValue(int, int)
917     * @see #getHistoricalAxisValue(int, int, int)
918     * @see MotionEvent.PointerCoords#getAxisValue(int)
919     * @see InputDevice#getMotionRange
920     */
921    public static final int AXIS_WHEEL = 21;
922
923    /**
924     * Axis constant: Gas axis of a motion event.
925     * <p>
926     * <ul>
927     * <li>For a joystick, reports the absolute position of the gas (accelerator) control.
928     * The value is normalized to a range from 0.0 (no acceleration)
929     * to 1.0 (maximum acceleration).
930     * </ul>
931     * </p>
932     *
933     * @see #getAxisValue(int, int)
934     * @see #getHistoricalAxisValue(int, int, int)
935     * @see MotionEvent.PointerCoords#getAxisValue(int)
936     * @see InputDevice#getMotionRange
937     */
938    public static final int AXIS_GAS = 22;
939
940    /**
941     * Axis constant: Brake axis of a motion event.
942     * <p>
943     * <ul>
944     * <li>For a joystick, reports the absolute position of the brake control.
945     * The value is normalized to a range from 0.0 (no braking) to 1.0 (maximum braking).
946     * </ul>
947     * </p>
948     *
949     * @see #getAxisValue(int, int)
950     * @see #getHistoricalAxisValue(int, int, int)
951     * @see MotionEvent.PointerCoords#getAxisValue(int)
952     * @see InputDevice#getMotionRange
953     */
954    public static final int AXIS_BRAKE = 23;
955
956    /**
957     * Axis constant: Distance axis of a motion event.
958     * <p>
959     * <ul>
960     * <li>For a stylus, reports the distance of the stylus from the screen.
961     * A value of 0.0 indicates direct contact and larger values indicate increasing
962     * distance from the surface.
963     * </ul>
964     * </p>
965     *
966     * @see #getAxisValue(int, int)
967     * @see #getHistoricalAxisValue(int, int, int)
968     * @see MotionEvent.PointerCoords#getAxisValue(int)
969     * @see InputDevice#getMotionRange
970     */
971    public static final int AXIS_DISTANCE = 24;
972
973    /**
974     * Axis constant: Tilt axis of a motion event.
975     * <p>
976     * <ul>
977     * <li>For a stylus, reports the tilt angle of the stylus in radians where
978     * 0 radians indicates that the stylus is being held perpendicular to the
979     * surface, and PI/2 radians indicates that the stylus is being held flat
980     * against the surface.
981     * </ul>
982     * </p>
983     *
984     * @see #getAxisValue(int, int)
985     * @see #getHistoricalAxisValue(int, int, int)
986     * @see MotionEvent.PointerCoords#getAxisValue(int, int)
987     * @see InputDevice#getMotionRange
988     */
989    public static final int AXIS_TILT = 25;
990
991    /**
992     * Axis constant: Generic scroll axis of a motion event.
993     * <p>
994     * <ul>
995     * <li>Reports the relative movement of the generic scrolling device.
996     * </ul>
997     * </p><p>
998     * This axis should be used for scroll events that are neither strictly vertical nor horizontal.
999     * A good example would be the rotation of a rotary encoder input device.
1000     * </p>
1001     *
1002     * @see #getAxisValue(int, int)
1003     * {@hide}
1004     */
1005    public static final int AXIS_SCROLL = 26;
1006
1007    /**
1008     * Axis constant: The movement of x position of a motion event.
1009     * <p>
1010     * <ul>
1011     * <li>For a mouse, reports a difference of x position between the previous position.
1012     * This is useful when pointer is captured, in that case the mouse pointer doesn't change
1013     * the location but this axis reports the difference which allows the app to see
1014     * how the mouse is moved.
1015     * </ul>
1016     * </p>
1017     *
1018     * @see #getAxisValue(int, int)
1019     * @see #getHistoricalAxisValue(int, int, int)
1020     * @see MotionEvent.PointerCoords#getAxisValue(int, int)
1021     * @see InputDevice#getMotionRange
1022     */
1023    public static final int AXIS_RELATIVE_X = 27;
1024
1025    /**
1026     * Axis constant: The movement of y position of a motion event.
1027     * <p>
1028     * This is similar to {@link #AXIS_RELATIVE_X} but for y-axis.
1029     * </p>
1030     *
1031     * @see #getAxisValue(int, int)
1032     * @see #getHistoricalAxisValue(int, int, int)
1033     * @see MotionEvent.PointerCoords#getAxisValue(int, int)
1034     * @see InputDevice#getMotionRange
1035     */
1036    public static final int AXIS_RELATIVE_Y = 28;
1037
1038    /**
1039     * Axis constant: Generic 1 axis of a motion event.
1040     * The interpretation of a generic axis is device-specific.
1041     *
1042     * @see #getAxisValue(int, int)
1043     * @see #getHistoricalAxisValue(int, int, int)
1044     * @see MotionEvent.PointerCoords#getAxisValue(int)
1045     * @see InputDevice#getMotionRange
1046     */
1047    public static final int AXIS_GENERIC_1 = 32;
1048
1049    /**
1050     * Axis constant: Generic 2 axis of a motion event.
1051     * The interpretation of a generic axis is device-specific.
1052     *
1053     * @see #getAxisValue(int, int)
1054     * @see #getHistoricalAxisValue(int, int, int)
1055     * @see MotionEvent.PointerCoords#getAxisValue(int)
1056     * @see InputDevice#getMotionRange
1057     */
1058    public static final int AXIS_GENERIC_2 = 33;
1059
1060    /**
1061     * Axis constant: Generic 3 axis of a motion event.
1062     * The interpretation of a generic axis is device-specific.
1063     *
1064     * @see #getAxisValue(int, int)
1065     * @see #getHistoricalAxisValue(int, int, int)
1066     * @see MotionEvent.PointerCoords#getAxisValue(int)
1067     * @see InputDevice#getMotionRange
1068     */
1069    public static final int AXIS_GENERIC_3 = 34;
1070
1071    /**
1072     * Axis constant: Generic 4 axis of a motion event.
1073     * The interpretation of a generic axis is device-specific.
1074     *
1075     * @see #getAxisValue(int, int)
1076     * @see #getHistoricalAxisValue(int, int, int)
1077     * @see MotionEvent.PointerCoords#getAxisValue(int)
1078     * @see InputDevice#getMotionRange
1079     */
1080    public static final int AXIS_GENERIC_4 = 35;
1081
1082    /**
1083     * Axis constant: Generic 5 axis of a motion event.
1084     * The interpretation of a generic axis is device-specific.
1085     *
1086     * @see #getAxisValue(int, int)
1087     * @see #getHistoricalAxisValue(int, int, int)
1088     * @see MotionEvent.PointerCoords#getAxisValue(int)
1089     * @see InputDevice#getMotionRange
1090     */
1091    public static final int AXIS_GENERIC_5 = 36;
1092
1093    /**
1094     * Axis constant: Generic 6 axis of a motion event.
1095     * The interpretation of a generic axis is device-specific.
1096     *
1097     * @see #getAxisValue(int, int)
1098     * @see #getHistoricalAxisValue(int, int, int)
1099     * @see MotionEvent.PointerCoords#getAxisValue(int)
1100     * @see InputDevice#getMotionRange
1101     */
1102    public static final int AXIS_GENERIC_6 = 37;
1103
1104    /**
1105     * Axis constant: Generic 7 axis of a motion event.
1106     * The interpretation of a generic axis is device-specific.
1107     *
1108     * @see #getAxisValue(int, int)
1109     * @see #getHistoricalAxisValue(int, int, int)
1110     * @see MotionEvent.PointerCoords#getAxisValue(int)
1111     * @see InputDevice#getMotionRange
1112     */
1113    public static final int AXIS_GENERIC_7 = 38;
1114
1115    /**
1116     * Axis constant: Generic 8 axis of a motion event.
1117     * The interpretation of a generic axis is device-specific.
1118     *
1119     * @see #getAxisValue(int, int)
1120     * @see #getHistoricalAxisValue(int, int, int)
1121     * @see MotionEvent.PointerCoords#getAxisValue(int)
1122     * @see InputDevice#getMotionRange
1123     */
1124    public static final int AXIS_GENERIC_8 = 39;
1125
1126    /**
1127     * Axis constant: Generic 9 axis of a motion event.
1128     * The interpretation of a generic axis is device-specific.
1129     *
1130     * @see #getAxisValue(int, int)
1131     * @see #getHistoricalAxisValue(int, int, int)
1132     * @see MotionEvent.PointerCoords#getAxisValue(int)
1133     * @see InputDevice#getMotionRange
1134     */
1135    public static final int AXIS_GENERIC_9 = 40;
1136
1137    /**
1138     * Axis constant: Generic 10 axis of a motion event.
1139     * The interpretation of a generic axis is device-specific.
1140     *
1141     * @see #getAxisValue(int, int)
1142     * @see #getHistoricalAxisValue(int, int, int)
1143     * @see MotionEvent.PointerCoords#getAxisValue(int)
1144     * @see InputDevice#getMotionRange
1145     */
1146    public static final int AXIS_GENERIC_10 = 41;
1147
1148    /**
1149     * Axis constant: Generic 11 axis of a motion event.
1150     * The interpretation of a generic axis is device-specific.
1151     *
1152     * @see #getAxisValue(int, int)
1153     * @see #getHistoricalAxisValue(int, int, int)
1154     * @see MotionEvent.PointerCoords#getAxisValue(int)
1155     * @see InputDevice#getMotionRange
1156     */
1157    public static final int AXIS_GENERIC_11 = 42;
1158
1159    /**
1160     * Axis constant: Generic 12 axis of a motion event.
1161     * The interpretation of a generic axis is device-specific.
1162     *
1163     * @see #getAxisValue(int, int)
1164     * @see #getHistoricalAxisValue(int, int, int)
1165     * @see MotionEvent.PointerCoords#getAxisValue(int)
1166     * @see InputDevice#getMotionRange
1167     */
1168    public static final int AXIS_GENERIC_12 = 43;
1169
1170    /**
1171     * Axis constant: Generic 13 axis of a motion event.
1172     * The interpretation of a generic axis is device-specific.
1173     *
1174     * @see #getAxisValue(int, int)
1175     * @see #getHistoricalAxisValue(int, int, int)
1176     * @see MotionEvent.PointerCoords#getAxisValue(int)
1177     * @see InputDevice#getMotionRange
1178     */
1179    public static final int AXIS_GENERIC_13 = 44;
1180
1181    /**
1182     * Axis constant: Generic 14 axis of a motion event.
1183     * The interpretation of a generic axis is device-specific.
1184     *
1185     * @see #getAxisValue(int, int)
1186     * @see #getHistoricalAxisValue(int, int, int)
1187     * @see MotionEvent.PointerCoords#getAxisValue(int)
1188     * @see InputDevice#getMotionRange
1189     */
1190    public static final int AXIS_GENERIC_14 = 45;
1191
1192    /**
1193     * Axis constant: Generic 15 axis of a motion event.
1194     * The interpretation of a generic axis is device-specific.
1195     *
1196     * @see #getAxisValue(int, int)
1197     * @see #getHistoricalAxisValue(int, int, int)
1198     * @see MotionEvent.PointerCoords#getAxisValue(int)
1199     * @see InputDevice#getMotionRange
1200     */
1201    public static final int AXIS_GENERIC_15 = 46;
1202
1203    /**
1204     * Axis constant: Generic 16 axis of a motion event.
1205     * The interpretation of a generic axis is device-specific.
1206     *
1207     * @see #getAxisValue(int, int)
1208     * @see #getHistoricalAxisValue(int, int, int)
1209     * @see MotionEvent.PointerCoords#getAxisValue(int)
1210     * @see InputDevice#getMotionRange
1211     */
1212    public static final int AXIS_GENERIC_16 = 47;
1213
1214    // NOTE: If you add a new axis here you must also add it to:
1215    //  native/include/android/input.h
1216    //  frameworks/base/include/ui/KeycodeLabels.h
1217
1218    // Symbolic names of all axes.
1219    private static final SparseArray<String> AXIS_SYMBOLIC_NAMES = new SparseArray<String>();
1220    static {
1221        SparseArray<String> names = AXIS_SYMBOLIC_NAMES;
1222        names.append(AXIS_X, "AXIS_X");
1223        names.append(AXIS_Y, "AXIS_Y");
1224        names.append(AXIS_PRESSURE, "AXIS_PRESSURE");
1225        names.append(AXIS_SIZE, "AXIS_SIZE");
1226        names.append(AXIS_TOUCH_MAJOR, "AXIS_TOUCH_MAJOR");
1227        names.append(AXIS_TOUCH_MINOR, "AXIS_TOUCH_MINOR");
1228        names.append(AXIS_TOOL_MAJOR, "AXIS_TOOL_MAJOR");
1229        names.append(AXIS_TOOL_MINOR, "AXIS_TOOL_MINOR");
1230        names.append(AXIS_ORIENTATION, "AXIS_ORIENTATION");
1231        names.append(AXIS_VSCROLL, "AXIS_VSCROLL");
1232        names.append(AXIS_HSCROLL, "AXIS_HSCROLL");
1233        names.append(AXIS_Z, "AXIS_Z");
1234        names.append(AXIS_RX, "AXIS_RX");
1235        names.append(AXIS_RY, "AXIS_RY");
1236        names.append(AXIS_RZ, "AXIS_RZ");
1237        names.append(AXIS_HAT_X, "AXIS_HAT_X");
1238        names.append(AXIS_HAT_Y, "AXIS_HAT_Y");
1239        names.append(AXIS_LTRIGGER, "AXIS_LTRIGGER");
1240        names.append(AXIS_RTRIGGER, "AXIS_RTRIGGER");
1241        names.append(AXIS_THROTTLE, "AXIS_THROTTLE");
1242        names.append(AXIS_RUDDER, "AXIS_RUDDER");
1243        names.append(AXIS_WHEEL, "AXIS_WHEEL");
1244        names.append(AXIS_GAS, "AXIS_GAS");
1245        names.append(AXIS_BRAKE, "AXIS_BRAKE");
1246        names.append(AXIS_DISTANCE, "AXIS_DISTANCE");
1247        names.append(AXIS_TILT, "AXIS_TILT");
1248        names.append(AXIS_SCROLL, "AXIS_SCROLL");
1249        names.append(AXIS_RELATIVE_X, "AXIS_REALTIVE_X");
1250        names.append(AXIS_RELATIVE_Y, "AXIS_REALTIVE_Y");
1251        names.append(AXIS_GENERIC_1, "AXIS_GENERIC_1");
1252        names.append(AXIS_GENERIC_2, "AXIS_GENERIC_2");
1253        names.append(AXIS_GENERIC_3, "AXIS_GENERIC_3");
1254        names.append(AXIS_GENERIC_4, "AXIS_GENERIC_4");
1255        names.append(AXIS_GENERIC_5, "AXIS_GENERIC_5");
1256        names.append(AXIS_GENERIC_6, "AXIS_GENERIC_6");
1257        names.append(AXIS_GENERIC_7, "AXIS_GENERIC_7");
1258        names.append(AXIS_GENERIC_8, "AXIS_GENERIC_8");
1259        names.append(AXIS_GENERIC_9, "AXIS_GENERIC_9");
1260        names.append(AXIS_GENERIC_10, "AXIS_GENERIC_10");
1261        names.append(AXIS_GENERIC_11, "AXIS_GENERIC_11");
1262        names.append(AXIS_GENERIC_12, "AXIS_GENERIC_12");
1263        names.append(AXIS_GENERIC_13, "AXIS_GENERIC_13");
1264        names.append(AXIS_GENERIC_14, "AXIS_GENERIC_14");
1265        names.append(AXIS_GENERIC_15, "AXIS_GENERIC_15");
1266        names.append(AXIS_GENERIC_16, "AXIS_GENERIC_16");
1267    }
1268
1269    /**
1270     * Button constant: Primary button (left mouse button).
1271     *
1272     * This button constant is not set in response to simple touches with a finger
1273     * or stylus tip.  The user must actually push a button.
1274     *
1275     * @see #getButtonState
1276     */
1277    public static final int BUTTON_PRIMARY = 1 << 0;
1278
1279    /**
1280     * Button constant: Secondary button (right mouse button).
1281     *
1282     * @see #getButtonState
1283     */
1284    public static final int BUTTON_SECONDARY = 1 << 1;
1285
1286    /**
1287     * Button constant: Tertiary button (middle mouse button).
1288     *
1289     * @see #getButtonState
1290     */
1291    public static final int BUTTON_TERTIARY = 1 << 2;
1292
1293    /**
1294     * Button constant: Back button pressed (mouse back button).
1295     * <p>
1296     * The system may send a {@link KeyEvent#KEYCODE_BACK} key press to the application
1297     * when this button is pressed.
1298     * </p>
1299     *
1300     * @see #getButtonState
1301     */
1302    public static final int BUTTON_BACK = 1 << 3;
1303
1304    /**
1305     * Button constant: Forward button pressed (mouse forward button).
1306     * <p>
1307     * The system may send a {@link KeyEvent#KEYCODE_FORWARD} key press to the application
1308     * when this button is pressed.
1309     * </p>
1310     *
1311     * @see #getButtonState
1312     */
1313    public static final int BUTTON_FORWARD = 1 << 4;
1314
1315    /**
1316     * Button constant: Primary stylus button pressed.
1317     *
1318     * @see #getButtonState
1319     */
1320    public static final int BUTTON_STYLUS_PRIMARY = 1 << 5;
1321
1322    /**
1323     * Button constant: Secondary stylus button pressed.
1324     *
1325     * @see #getButtonState
1326     */
1327    public static final int BUTTON_STYLUS_SECONDARY = 1 << 6;
1328
1329    // NOTE: If you add a new axis here you must also add it to:
1330    //  native/include/android/input.h
1331
1332    // Symbolic names of all button states in bit order from least significant
1333    // to most significant.
1334    private static final String[] BUTTON_SYMBOLIC_NAMES = new String[] {
1335        "BUTTON_PRIMARY",
1336        "BUTTON_SECONDARY",
1337        "BUTTON_TERTIARY",
1338        "BUTTON_BACK",
1339        "BUTTON_FORWARD",
1340        "BUTTON_STYLUS_PRIMARY",
1341        "BUTTON_STYLUS_SECONDARY",
1342        "0x00000080",
1343        "0x00000100",
1344        "0x00000200",
1345        "0x00000400",
1346        "0x00000800",
1347        "0x00001000",
1348        "0x00002000",
1349        "0x00004000",
1350        "0x00008000",
1351        "0x00010000",
1352        "0x00020000",
1353        "0x00040000",
1354        "0x00080000",
1355        "0x00100000",
1356        "0x00200000",
1357        "0x00400000",
1358        "0x00800000",
1359        "0x01000000",
1360        "0x02000000",
1361        "0x04000000",
1362        "0x08000000",
1363        "0x10000000",
1364        "0x20000000",
1365        "0x40000000",
1366        "0x80000000",
1367    };
1368
1369    /**
1370     * Tool type constant: Unknown tool type.
1371     * This constant is used when the tool type is not known or is not relevant,
1372     * such as for a trackball or other non-pointing device.
1373     *
1374     * @see #getToolType
1375     */
1376    public static final int TOOL_TYPE_UNKNOWN = 0;
1377
1378    /**
1379     * Tool type constant: The tool is a finger.
1380     *
1381     * @see #getToolType
1382     */
1383    public static final int TOOL_TYPE_FINGER = 1;
1384
1385    /**
1386     * Tool type constant: The tool is a stylus.
1387     *
1388     * @see #getToolType
1389     */
1390    public static final int TOOL_TYPE_STYLUS = 2;
1391
1392    /**
1393     * Tool type constant: The tool is a mouse or trackpad.
1394     *
1395     * @see #getToolType
1396     */
1397    public static final int TOOL_TYPE_MOUSE = 3;
1398
1399    /**
1400     * Tool type constant: The tool is an eraser or a stylus being used in an inverted posture.
1401     *
1402     * @see #getToolType
1403     */
1404    public static final int TOOL_TYPE_ERASER = 4;
1405
1406    // NOTE: If you add a new tool type here you must also add it to:
1407    //  native/include/android/input.h
1408
1409    // Symbolic names of all tool types.
1410    private static final SparseArray<String> TOOL_TYPE_SYMBOLIC_NAMES = new SparseArray<String>();
1411    static {
1412        SparseArray<String> names = TOOL_TYPE_SYMBOLIC_NAMES;
1413        names.append(TOOL_TYPE_UNKNOWN, "TOOL_TYPE_UNKNOWN");
1414        names.append(TOOL_TYPE_FINGER, "TOOL_TYPE_FINGER");
1415        names.append(TOOL_TYPE_STYLUS, "TOOL_TYPE_STYLUS");
1416        names.append(TOOL_TYPE_MOUSE, "TOOL_TYPE_MOUSE");
1417        names.append(TOOL_TYPE_ERASER, "TOOL_TYPE_ERASER");
1418    }
1419
1420    // Private value for history pos that obtains the current sample.
1421    private static final int HISTORY_CURRENT = -0x80000000;
1422
1423    private static final int MAX_RECYCLED = 10;
1424    private static final Object gRecyclerLock = new Object();
1425    private static int gRecyclerUsed;
1426    private static MotionEvent gRecyclerTop;
1427
1428    // Shared temporary objects used when translating coordinates supplied by
1429    // the caller into single element PointerCoords and pointer id arrays.
1430    private static final Object gSharedTempLock = new Object();
1431    private static PointerCoords[] gSharedTempPointerCoords;
1432    private static PointerProperties[] gSharedTempPointerProperties;
1433    private static int[] gSharedTempPointerIndexMap;
1434
1435    private static final void ensureSharedTempPointerCapacity(int desiredCapacity) {
1436        if (gSharedTempPointerCoords == null
1437                || gSharedTempPointerCoords.length < desiredCapacity) {
1438            int capacity = gSharedTempPointerCoords != null ? gSharedTempPointerCoords.length : 8;
1439            while (capacity < desiredCapacity) {
1440                capacity *= 2;
1441            }
1442            gSharedTempPointerCoords = PointerCoords.createArray(capacity);
1443            gSharedTempPointerProperties = PointerProperties.createArray(capacity);
1444            gSharedTempPointerIndexMap = new int[capacity];
1445        }
1446    }
1447
1448    // Pointer to the native MotionEvent object that contains the actual data.
1449    private long mNativePtr;
1450
1451    private MotionEvent mNext;
1452
1453    private static native long nativeInitialize(long nativePtr,
1454            int deviceId, int source, int action, int flags, int edgeFlags,
1455            int metaState, int buttonState,
1456            float xOffset, float yOffset, float xPrecision, float yPrecision,
1457            long downTimeNanos, long eventTimeNanos,
1458            int pointerCount, PointerProperties[] pointerIds, PointerCoords[] pointerCoords);
1459    private static native void nativeDispose(long nativePtr);
1460    private static native void nativeAddBatch(long nativePtr, long eventTimeNanos,
1461            PointerCoords[] pointerCoords, int metaState);
1462    private static native void nativeGetPointerCoords(long nativePtr,
1463            int pointerIndex, int historyPos, PointerCoords outPointerCoords);
1464    private static native void nativeGetPointerProperties(long nativePtr,
1465            int pointerIndex, PointerProperties outPointerProperties);
1466
1467    private static native long nativeReadFromParcel(long nativePtr, Parcel parcel);
1468    private static native void nativeWriteToParcel(long nativePtr, Parcel parcel);
1469
1470    private static native String nativeAxisToString(int axis);
1471    private static native int nativeAxisFromString(String label);
1472
1473    // -------------- @FastNative -------------------------
1474
1475    @FastNative
1476    private static native int nativeGetPointerId(long nativePtr, int pointerIndex);
1477    @FastNative
1478    private static native int nativeGetToolType(long nativePtr, int pointerIndex);
1479    @FastNative
1480    private static native long nativeGetEventTimeNanos(long nativePtr, int historyPos);
1481    @FastNative
1482    private static native float nativeGetRawAxisValue(long nativePtr,
1483            int axis, int pointerIndex, int historyPos);
1484    @FastNative
1485    private static native float nativeGetAxisValue(long nativePtr,
1486            int axis, int pointerIndex, int historyPos);
1487
1488    // -------------- @CriticalNative ----------------------
1489
1490    @CriticalNative
1491    private static native long nativeCopy(long destNativePtr, long sourceNativePtr,
1492            boolean keepHistory);
1493    @CriticalNative
1494    private static native int nativeGetDeviceId(long nativePtr);
1495    @CriticalNative
1496    private static native int nativeGetSource(long nativePtr);
1497    @CriticalNative
1498    private static native int nativeSetSource(long nativePtr, int source);
1499    @CriticalNative
1500    private static native int nativeGetAction(long nativePtr);
1501    @CriticalNative
1502    private static native void nativeSetAction(long nativePtr, int action);
1503    @CriticalNative
1504    private static native boolean nativeIsTouchEvent(long nativePtr);
1505    @CriticalNative
1506    private static native int nativeGetFlags(long nativePtr);
1507    @CriticalNative
1508    private static native void nativeSetFlags(long nativePtr, int flags);
1509    @CriticalNative
1510    private static native int nativeGetEdgeFlags(long nativePtr);
1511    @CriticalNative
1512    private static native void nativeSetEdgeFlags(long nativePtr, int action);
1513    @CriticalNative
1514    private static native int nativeGetMetaState(long nativePtr);
1515    @CriticalNative
1516    private static native int nativeGetButtonState(long nativePtr);
1517    @CriticalNative
1518    private static native void nativeSetButtonState(long nativePtr, int buttonState);
1519    @CriticalNative
1520    private static native int nativeGetActionButton(long nativePtr);
1521    @CriticalNative
1522    private static native void nativeSetActionButton(long nativePtr, int actionButton);
1523    @CriticalNative
1524    private static native void nativeOffsetLocation(long nativePtr, float deltaX, float deltaY);
1525    @CriticalNative
1526    private static native float nativeGetXOffset(long nativePtr);
1527    @CriticalNative
1528    private static native float nativeGetYOffset(long nativePtr);
1529    @CriticalNative
1530    private static native float nativeGetXPrecision(long nativePtr);
1531    @CriticalNative
1532    private static native float nativeGetYPrecision(long nativePtr);
1533    @CriticalNative
1534    private static native long nativeGetDownTimeNanos(long nativePtr);
1535    @CriticalNative
1536    private static native void nativeSetDownTimeNanos(long nativePtr, long downTime);
1537
1538    @CriticalNative
1539    private static native int nativeGetPointerCount(long nativePtr);
1540    @CriticalNative
1541    private static native int nativeFindPointerIndex(long nativePtr, int pointerId);
1542
1543    @CriticalNative
1544    private static native int nativeGetHistorySize(long nativePtr);
1545
1546    @CriticalNative
1547    private static native void nativeScale(long nativePtr, float scale);
1548    @CriticalNative
1549    private static native void nativeTransform(long nativePtr, long matrix);
1550
1551    private MotionEvent() {
1552    }
1553
1554    @Override
1555    protected void finalize() throws Throwable {
1556        try {
1557            if (mNativePtr != 0) {
1558                nativeDispose(mNativePtr);
1559                mNativePtr = 0;
1560            }
1561        } finally {
1562            super.finalize();
1563        }
1564    }
1565
1566    static private MotionEvent obtain() {
1567        final MotionEvent ev;
1568        synchronized (gRecyclerLock) {
1569            ev = gRecyclerTop;
1570            if (ev == null) {
1571                return new MotionEvent();
1572            }
1573            gRecyclerTop = ev.mNext;
1574            gRecyclerUsed -= 1;
1575        }
1576        ev.mNext = null;
1577        ev.prepareForReuse();
1578        return ev;
1579    }
1580
1581    /**
1582     * Create a new MotionEvent, filling in all of the basic values that
1583     * define the motion.
1584     *
1585     * @param downTime The time (in ms) when the user originally pressed down to start
1586     * a stream of position events.  This must be obtained from {@link SystemClock#uptimeMillis()}.
1587     * @param eventTime The the time (in ms) when this specific event was generated.  This
1588     * must be obtained from {@link SystemClock#uptimeMillis()}.
1589     * @param action The kind of action being performed, such as {@link #ACTION_DOWN}.
1590     * @param pointerCount The number of pointers that will be in this event.
1591     * @param pointerProperties An array of <em>pointerCount</em> values providing
1592     * a {@link PointerProperties} property object for each pointer, which must
1593     * include the pointer identifier.
1594     * @param pointerCoords An array of <em>pointerCount</em> values providing
1595     * a {@link PointerCoords} coordinate object for each pointer.
1596     * @param metaState The state of any meta / modifier keys that were in effect when
1597     * the event was generated.
1598     * @param buttonState The state of buttons that are pressed.
1599     * @param xPrecision The precision of the X coordinate being reported.
1600     * @param yPrecision The precision of the Y coordinate being reported.
1601     * @param deviceId The id for the device that this event came from.  An id of
1602     * zero indicates that the event didn't come from a physical device; other
1603     * numbers are arbitrary and you shouldn't depend on the values.
1604     * @param edgeFlags A bitfield indicating which edges, if any, were touched by this
1605     * MotionEvent.
1606     * @param source The source of this event.
1607     * @param flags The motion event flags.
1608     */
1609    static public MotionEvent obtain(long downTime, long eventTime,
1610            int action, int pointerCount, PointerProperties[] pointerProperties,
1611            PointerCoords[] pointerCoords, int metaState, int buttonState,
1612            float xPrecision, float yPrecision, int deviceId,
1613            int edgeFlags, int source, int flags) {
1614        MotionEvent ev = obtain();
1615        ev.mNativePtr = nativeInitialize(ev.mNativePtr,
1616                deviceId, source, action, flags, edgeFlags, metaState, buttonState,
1617                0, 0, xPrecision, yPrecision,
1618                downTime * NS_PER_MS, eventTime * NS_PER_MS,
1619                pointerCount, pointerProperties, pointerCoords);
1620        return ev;
1621    }
1622
1623    /**
1624     * Create a new MotionEvent, filling in all of the basic values that
1625     * define the motion.
1626     *
1627     * @param downTime The time (in ms) when the user originally pressed down to start
1628     * a stream of position events.  This must be obtained from {@link SystemClock#uptimeMillis()}.
1629     * @param eventTime The the time (in ms) when this specific event was generated.  This
1630     * must be obtained from {@link SystemClock#uptimeMillis()}.
1631     * @param action The kind of action being performed, such as {@link #ACTION_DOWN}.
1632     * @param pointerCount The number of pointers that will be in this event.
1633     * @param pointerIds An array of <em>pointerCount</em> values providing
1634     * an identifier for each pointer.
1635     * @param pointerCoords An array of <em>pointerCount</em> values providing
1636     * a {@link PointerCoords} coordinate object for each pointer.
1637     * @param metaState The state of any meta / modifier keys that were in effect when
1638     * the event was generated.
1639     * @param xPrecision The precision of the X coordinate being reported.
1640     * @param yPrecision The precision of the Y coordinate being reported.
1641     * @param deviceId The id for the device that this event came from.  An id of
1642     * zero indicates that the event didn't come from a physical device; other
1643     * numbers are arbitrary and you shouldn't depend on the values.
1644     * @param edgeFlags A bitfield indicating which edges, if any, were touched by this
1645     * MotionEvent.
1646     * @param source The source of this event.
1647     * @param flags The motion event flags.
1648     *
1649     * @deprecated Use {@link #obtain(long, long, int, int, PointerProperties[], PointerCoords[], int, int, float, float, int, int, int, int)}
1650     * instead.
1651     */
1652    @Deprecated
1653    static public MotionEvent obtain(long downTime, long eventTime,
1654            int action, int pointerCount, int[] pointerIds, PointerCoords[] pointerCoords,
1655            int metaState, float xPrecision, float yPrecision, int deviceId,
1656            int edgeFlags, int source, int flags) {
1657        synchronized (gSharedTempLock) {
1658            ensureSharedTempPointerCapacity(pointerCount);
1659            final PointerProperties[] pp = gSharedTempPointerProperties;
1660            for (int i = 0; i < pointerCount; i++) {
1661                pp[i].clear();
1662                pp[i].id = pointerIds[i];
1663            }
1664            return obtain(downTime, eventTime, action, pointerCount, pp,
1665                    pointerCoords, metaState, 0, xPrecision, yPrecision, deviceId,
1666                    edgeFlags, source, flags);
1667        }
1668    }
1669
1670    /**
1671     * Create a new MotionEvent, filling in all of the basic values that
1672     * define the motion.
1673     *
1674     * @param downTime The time (in ms) when the user originally pressed down to start
1675     * a stream of position events.  This must be obtained from {@link SystemClock#uptimeMillis()}.
1676     * @param eventTime  The the time (in ms) when this specific event was generated.  This
1677     * must be obtained from {@link SystemClock#uptimeMillis()}.
1678     * @param action The kind of action being performed, such as {@link #ACTION_DOWN}.
1679     * @param x The X coordinate of this event.
1680     * @param y The Y coordinate of this event.
1681     * @param pressure The current pressure of this event.  The pressure generally
1682     * ranges from 0 (no pressure at all) to 1 (normal pressure), however
1683     * values higher than 1 may be generated depending on the calibration of
1684     * the input device.
1685     * @param size A scaled value of the approximate size of the area being pressed when
1686     * touched with the finger. The actual value in pixels corresponding to the finger
1687     * touch is normalized with a device specific range of values
1688     * and scaled to a value between 0 and 1.
1689     * @param metaState The state of any meta / modifier keys that were in effect when
1690     * the event was generated.
1691     * @param xPrecision The precision of the X coordinate being reported.
1692     * @param yPrecision The precision of the Y coordinate being reported.
1693     * @param deviceId The id for the device that this event came from.  An id of
1694     * zero indicates that the event didn't come from a physical device; other
1695     * numbers are arbitrary and you shouldn't depend on the values.
1696     * @param edgeFlags A bitfield indicating which edges, if any, were touched by this
1697     * MotionEvent.
1698     */
1699    static public MotionEvent obtain(long downTime, long eventTime, int action,
1700            float x, float y, float pressure, float size, int metaState,
1701            float xPrecision, float yPrecision, int deviceId, int edgeFlags) {
1702        MotionEvent ev = obtain();
1703        synchronized (gSharedTempLock) {
1704            ensureSharedTempPointerCapacity(1);
1705            final PointerProperties[] pp = gSharedTempPointerProperties;
1706            pp[0].clear();
1707            pp[0].id = 0;
1708
1709            final PointerCoords pc[] = gSharedTempPointerCoords;
1710            pc[0].clear();
1711            pc[0].x = x;
1712            pc[0].y = y;
1713            pc[0].pressure = pressure;
1714            pc[0].size = size;
1715
1716            ev.mNativePtr = nativeInitialize(ev.mNativePtr,
1717                    deviceId, InputDevice.SOURCE_UNKNOWN, action, 0, edgeFlags, metaState, 0,
1718                    0, 0, xPrecision, yPrecision,
1719                    downTime * NS_PER_MS, eventTime * NS_PER_MS,
1720                    1, pp, pc);
1721            return ev;
1722        }
1723    }
1724
1725    /**
1726     * Create a new MotionEvent, filling in all of the basic values that
1727     * define the motion.
1728     *
1729     * @param downTime The time (in ms) when the user originally pressed down to start
1730     * a stream of position events.  This must be obtained from {@link SystemClock#uptimeMillis()}.
1731     * @param eventTime  The the time (in ms) when this specific event was generated.  This
1732     * must be obtained from {@link SystemClock#uptimeMillis()}.
1733     * @param action The kind of action being performed, such as {@link #ACTION_DOWN}.
1734     * @param pointerCount The number of pointers that are active in this event.
1735     * @param x The X coordinate of this event.
1736     * @param y The Y coordinate of this event.
1737     * @param pressure The current pressure of this event.  The pressure generally
1738     * ranges from 0 (no pressure at all) to 1 (normal pressure), however
1739     * values higher than 1 may be generated depending on the calibration of
1740     * the input device.
1741     * @param size A scaled value of the approximate size of the area being pressed when
1742     * touched with the finger. The actual value in pixels corresponding to the finger
1743     * touch is normalized with a device specific range of values
1744     * and scaled to a value between 0 and 1.
1745     * @param metaState The state of any meta / modifier keys that were in effect when
1746     * the event was generated.
1747     * @param xPrecision The precision of the X coordinate being reported.
1748     * @param yPrecision The precision of the Y coordinate being reported.
1749     * @param deviceId The id for the device that this event came from.  An id of
1750     * zero indicates that the event didn't come from a physical device; other
1751     * numbers are arbitrary and you shouldn't depend on the values.
1752     * @param edgeFlags A bitfield indicating which edges, if any, were touched by this
1753     * MotionEvent.
1754     *
1755     * @deprecated Use {@link #obtain(long, long, int, float, float, float, float, int, float, float, int, int)}
1756     * instead.
1757     */
1758    @Deprecated
1759    static public MotionEvent obtain(long downTime, long eventTime, int action,
1760            int pointerCount, float x, float y, float pressure, float size, int metaState,
1761            float xPrecision, float yPrecision, int deviceId, int edgeFlags) {
1762        return obtain(downTime, eventTime, action, x, y, pressure, size,
1763                metaState, xPrecision, yPrecision, deviceId, edgeFlags);
1764    }
1765
1766    /**
1767     * Create a new MotionEvent, filling in a subset of the basic motion
1768     * values.  Those not specified here are: device id (always 0), pressure
1769     * and size (always 1), x and y precision (always 1), and edgeFlags (always 0).
1770     *
1771     * @param downTime The time (in ms) when the user originally pressed down to start
1772     * a stream of position events.  This must be obtained from {@link SystemClock#uptimeMillis()}.
1773     * @param eventTime  The the time (in ms) when this specific event was generated.  This
1774     * must be obtained from {@link SystemClock#uptimeMillis()}.
1775     * @param action The kind of action being performed, such as {@link #ACTION_DOWN}.
1776     * @param x The X coordinate of this event.
1777     * @param y The Y coordinate of this event.
1778     * @param metaState The state of any meta / modifier keys that were in effect when
1779     * the event was generated.
1780     */
1781    static public MotionEvent obtain(long downTime, long eventTime, int action,
1782            float x, float y, int metaState) {
1783        return obtain(downTime, eventTime, action, x, y, 1.0f, 1.0f,
1784                metaState, 1.0f, 1.0f, 0, 0);
1785    }
1786
1787    /**
1788     * Create a new MotionEvent, copying from an existing one.
1789     */
1790    static public MotionEvent obtain(MotionEvent other) {
1791        if (other == null) {
1792            throw new IllegalArgumentException("other motion event must not be null");
1793        }
1794
1795        MotionEvent ev = obtain();
1796        ev.mNativePtr = nativeCopy(ev.mNativePtr, other.mNativePtr, true /*keepHistory*/);
1797        return ev;
1798    }
1799
1800    /**
1801     * Create a new MotionEvent, copying from an existing one, but not including
1802     * any historical point information.
1803     */
1804    static public MotionEvent obtainNoHistory(MotionEvent other) {
1805        if (other == null) {
1806            throw new IllegalArgumentException("other motion event must not be null");
1807        }
1808
1809        MotionEvent ev = obtain();
1810        ev.mNativePtr = nativeCopy(ev.mNativePtr, other.mNativePtr, false /*keepHistory*/);
1811        return ev;
1812    }
1813
1814    /** @hide */
1815    @Override
1816    public MotionEvent copy() {
1817        return obtain(this);
1818    }
1819
1820    /**
1821     * Recycle the MotionEvent, to be re-used by a later caller.  After calling
1822     * this function you must not ever touch the event again.
1823     */
1824    @Override
1825    public final void recycle() {
1826        super.recycle();
1827
1828        synchronized (gRecyclerLock) {
1829            if (gRecyclerUsed < MAX_RECYCLED) {
1830                gRecyclerUsed++;
1831                mNext = gRecyclerTop;
1832                gRecyclerTop = this;
1833            }
1834        }
1835    }
1836
1837    /**
1838     * Applies a scale factor to all points within this event.
1839     *
1840     * This method is used to adjust touch events to simulate different density
1841     * displays for compatibility mode.  The values returned by {@link #getRawX()},
1842     * {@link #getRawY()}, {@link #getXPrecision()} and {@link #getYPrecision()}
1843     * are also affected by the scale factor.
1844     *
1845     * @param scale The scale factor to apply.
1846     * @hide
1847     */
1848    public final void scale(float scale) {
1849        if (scale != 1.0f) {
1850            nativeScale(mNativePtr, scale);
1851        }
1852    }
1853
1854    /** {@inheritDoc} */
1855    @Override
1856    public final int getDeviceId() {
1857        return nativeGetDeviceId(mNativePtr);
1858    }
1859
1860    /** {@inheritDoc} */
1861    @Override
1862    public final int getSource() {
1863        return nativeGetSource(mNativePtr);
1864    }
1865
1866    /** {@inheritDoc} */
1867    @Override
1868    public final void setSource(int source) {
1869        nativeSetSource(mNativePtr, source);
1870    }
1871
1872    /**
1873     * Return the kind of action being performed.
1874     * Consider using {@link #getActionMasked} and {@link #getActionIndex} to retrieve
1875     * the separate masked action and pointer index.
1876     * @return The action, such as {@link #ACTION_DOWN} or
1877     * the combination of {@link #ACTION_POINTER_DOWN} with a shifted pointer index.
1878     */
1879    public final int getAction() {
1880        return nativeGetAction(mNativePtr);
1881    }
1882
1883    /**
1884     * Return the masked action being performed, without pointer index information.
1885     * Use {@link #getActionIndex} to return the index associated with pointer actions.
1886     * @return The action, such as {@link #ACTION_DOWN} or {@link #ACTION_POINTER_DOWN}.
1887     */
1888    public final int getActionMasked() {
1889        return nativeGetAction(mNativePtr) & ACTION_MASK;
1890    }
1891
1892    /**
1893     * For {@link #ACTION_POINTER_DOWN} or {@link #ACTION_POINTER_UP}
1894     * as returned by {@link #getActionMasked}, this returns the associated
1895     * pointer index.
1896     * The index may be used with {@link #getPointerId(int)},
1897     * {@link #getX(int)}, {@link #getY(int)}, {@link #getPressure(int)},
1898     * and {@link #getSize(int)} to get information about the pointer that has
1899     * gone down or up.
1900     * @return The index associated with the action.
1901     */
1902    public final int getActionIndex() {
1903        return (nativeGetAction(mNativePtr) & ACTION_POINTER_INDEX_MASK)
1904                >> ACTION_POINTER_INDEX_SHIFT;
1905    }
1906
1907    /**
1908     * Returns true if this motion event is a touch event.
1909     * <p>
1910     * Specifically excludes pointer events with action {@link #ACTION_HOVER_MOVE},
1911     * {@link #ACTION_HOVER_ENTER}, {@link #ACTION_HOVER_EXIT}, or {@link #ACTION_SCROLL}
1912     * because they are not actually touch events (the pointer is not down).
1913     * </p>
1914     * @return True if this motion event is a touch event.
1915     * @hide
1916     */
1917    public final boolean isTouchEvent() {
1918        return nativeIsTouchEvent(mNativePtr);
1919    }
1920
1921    /**
1922     * Gets the motion event flags.
1923     *
1924     * @see #FLAG_WINDOW_IS_OBSCURED
1925     */
1926    public final int getFlags() {
1927        return nativeGetFlags(mNativePtr);
1928    }
1929
1930    /** @hide */
1931    @Override
1932    public final boolean isTainted() {
1933        final int flags = getFlags();
1934        return (flags & FLAG_TAINTED) != 0;
1935    }
1936
1937    /** @hide */
1938    @Override
1939    public final void setTainted(boolean tainted) {
1940        final int flags = getFlags();
1941        nativeSetFlags(mNativePtr, tainted ? flags | FLAG_TAINTED : flags & ~FLAG_TAINTED);
1942    }
1943
1944    /** @hide */
1945    public final boolean isTargetAccessibilityFocus() {
1946        final int flags = getFlags();
1947        return (flags & FLAG_TARGET_ACCESSIBILITY_FOCUS) != 0;
1948    }
1949
1950    /** @hide */
1951    public final void setTargetAccessibilityFocus(boolean targetsFocus) {
1952        final int flags = getFlags();
1953        nativeSetFlags(mNativePtr, targetsFocus
1954                ? flags | FLAG_TARGET_ACCESSIBILITY_FOCUS
1955                : flags & ~FLAG_TARGET_ACCESSIBILITY_FOCUS);
1956    }
1957
1958    /** @hide */
1959    public final boolean isHoverExitPending() {
1960        final int flags = getFlags();
1961        return (flags & FLAG_HOVER_EXIT_PENDING) != 0;
1962    }
1963
1964    /** @hide */
1965    public void setHoverExitPending(boolean hoverExitPending) {
1966        final int flags = getFlags();
1967        nativeSetFlags(mNativePtr, hoverExitPending
1968                ? flags | FLAG_HOVER_EXIT_PENDING
1969                : flags & ~FLAG_HOVER_EXIT_PENDING);
1970    }
1971
1972    /**
1973     * Returns the time (in ms) when the user originally pressed down to start
1974     * a stream of position events.
1975     */
1976    public final long getDownTime() {
1977        return nativeGetDownTimeNanos(mNativePtr) / NS_PER_MS;
1978    }
1979
1980    /**
1981     * Sets the time (in ms) when the user originally pressed down to start
1982     * a stream of position events.
1983     *
1984     * @hide
1985     */
1986    public final void setDownTime(long downTime) {
1987        nativeSetDownTimeNanos(mNativePtr, downTime * NS_PER_MS);
1988    }
1989
1990    /**
1991     * Retrieve the time this event occurred,
1992     * in the {@link android.os.SystemClock#uptimeMillis} time base.
1993     *
1994     * @return Returns the time this event occurred,
1995     * in the {@link android.os.SystemClock#uptimeMillis} time base.
1996     */
1997    @Override
1998    public final long getEventTime() {
1999        return nativeGetEventTimeNanos(mNativePtr, HISTORY_CURRENT) / NS_PER_MS;
2000    }
2001
2002    /**
2003     * Retrieve the time this event occurred,
2004     * in the {@link android.os.SystemClock#uptimeMillis} time base but with
2005     * nanosecond precision.
2006     * <p>
2007     * The value is in nanosecond precision but it may not have nanosecond accuracy.
2008     * </p>
2009     *
2010     * @return Returns the time this event occurred,
2011     * in the {@link android.os.SystemClock#uptimeMillis} time base but with
2012     * nanosecond precision.
2013     *
2014     * @hide
2015     */
2016    @Override
2017    public final long getEventTimeNano() {
2018        return nativeGetEventTimeNanos(mNativePtr, HISTORY_CURRENT);
2019    }
2020
2021    /**
2022     * {@link #getX(int)} for the first pointer index (may be an
2023     * arbitrary pointer identifier).
2024     *
2025     * @see #AXIS_X
2026     */
2027    public final float getX() {
2028        return nativeGetAxisValue(mNativePtr, AXIS_X, 0, HISTORY_CURRENT);
2029    }
2030
2031    /**
2032     * {@link #getY(int)} for the first pointer index (may be an
2033     * arbitrary pointer identifier).
2034     *
2035     * @see #AXIS_Y
2036     */
2037    public final float getY() {
2038        return nativeGetAxisValue(mNativePtr, AXIS_Y, 0, HISTORY_CURRENT);
2039    }
2040
2041    /**
2042     * {@link #getPressure(int)} for the first pointer index (may be an
2043     * arbitrary pointer identifier).
2044     *
2045     * @see #AXIS_PRESSURE
2046     */
2047    public final float getPressure() {
2048        return nativeGetAxisValue(mNativePtr, AXIS_PRESSURE, 0, HISTORY_CURRENT);
2049    }
2050
2051    /**
2052     * {@link #getSize(int)} for the first pointer index (may be an
2053     * arbitrary pointer identifier).
2054     *
2055     * @see #AXIS_SIZE
2056     */
2057    public final float getSize() {
2058        return nativeGetAxisValue(mNativePtr, AXIS_SIZE, 0, HISTORY_CURRENT);
2059    }
2060
2061    /**
2062     * {@link #getTouchMajor(int)} for the first pointer index (may be an
2063     * arbitrary pointer identifier).
2064     *
2065     * @see #AXIS_TOUCH_MAJOR
2066     */
2067    public final float getTouchMajor() {
2068        return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MAJOR, 0, HISTORY_CURRENT);
2069    }
2070
2071    /**
2072     * {@link #getTouchMinor(int)} for the first pointer index (may be an
2073     * arbitrary pointer identifier).
2074     *
2075     * @see #AXIS_TOUCH_MINOR
2076     */
2077    public final float getTouchMinor() {
2078        return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MINOR, 0, HISTORY_CURRENT);
2079    }
2080
2081    /**
2082     * {@link #getToolMajor(int)} for the first pointer index (may be an
2083     * arbitrary pointer identifier).
2084     *
2085     * @see #AXIS_TOOL_MAJOR
2086     */
2087    public final float getToolMajor() {
2088        return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MAJOR, 0, HISTORY_CURRENT);
2089    }
2090
2091    /**
2092     * {@link #getToolMinor(int)} for the first pointer index (may be an
2093     * arbitrary pointer identifier).
2094     *
2095     * @see #AXIS_TOOL_MINOR
2096     */
2097    public final float getToolMinor() {
2098        return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MINOR, 0, HISTORY_CURRENT);
2099    }
2100
2101    /**
2102     * {@link #getOrientation(int)} for the first pointer index (may be an
2103     * arbitrary pointer identifier).
2104     *
2105     * @see #AXIS_ORIENTATION
2106     */
2107    public final float getOrientation() {
2108        return nativeGetAxisValue(mNativePtr, AXIS_ORIENTATION, 0, HISTORY_CURRENT);
2109    }
2110
2111    /**
2112     * {@link #getAxisValue(int)} for the first pointer index (may be an
2113     * arbitrary pointer identifier).
2114     *
2115     * @param axis The axis identifier for the axis value to retrieve.
2116     *
2117     * @see #AXIS_X
2118     * @see #AXIS_Y
2119     */
2120    public final float getAxisValue(int axis) {
2121        return nativeGetAxisValue(mNativePtr, axis, 0, HISTORY_CURRENT);
2122    }
2123
2124    /**
2125     * The number of pointers of data contained in this event.  Always
2126     * >= 1.
2127     */
2128    public final int getPointerCount() {
2129        return nativeGetPointerCount(mNativePtr);
2130    }
2131
2132    /**
2133     * Return the pointer identifier associated with a particular pointer
2134     * data index in this event.  The identifier tells you the actual pointer
2135     * number associated with the data, accounting for individual pointers
2136     * going up and down since the start of the current gesture.
2137     * @param pointerIndex Raw index of pointer to retrieve.  Value may be from 0
2138     * (the first pointer that is down) to {@link #getPointerCount()}-1.
2139     */
2140    public final int getPointerId(int pointerIndex) {
2141        return nativeGetPointerId(mNativePtr, pointerIndex);
2142    }
2143
2144    /**
2145     * Gets the tool type of a pointer for the given pointer index.
2146     * The tool type indicates the type of tool used to make contact such
2147     * as a finger or stylus, if known.
2148     *
2149     * @param pointerIndex Raw index of pointer to retrieve.  Value may be from 0
2150     * (the first pointer that is down) to {@link #getPointerCount()}-1.
2151     * @return The tool type of the pointer.
2152     *
2153     * @see #TOOL_TYPE_UNKNOWN
2154     * @see #TOOL_TYPE_FINGER
2155     * @see #TOOL_TYPE_STYLUS
2156     * @see #TOOL_TYPE_MOUSE
2157     */
2158    public final int getToolType(int pointerIndex) {
2159        return nativeGetToolType(mNativePtr, pointerIndex);
2160    }
2161
2162    /**
2163     * Given a pointer identifier, find the index of its data in the event.
2164     *
2165     * @param pointerId The identifier of the pointer to be found.
2166     * @return Returns either the index of the pointer (for use with
2167     * {@link #getX(int)} et al.), or -1 if there is no data available for
2168     * that pointer identifier.
2169     */
2170    public final int findPointerIndex(int pointerId) {
2171        return nativeFindPointerIndex(mNativePtr, pointerId);
2172    }
2173
2174    /**
2175     * Returns the X coordinate of this event for the given pointer
2176     * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
2177     * identifier for this index).
2178     * Whole numbers are pixels; the
2179     * value may have a fraction for input devices that are sub-pixel precise.
2180     * @param pointerIndex Raw index of pointer to retrieve.  Value may be from 0
2181     * (the first pointer that is down) to {@link #getPointerCount()}-1.
2182     *
2183     * @see #AXIS_X
2184     */
2185    public final float getX(int pointerIndex) {
2186        return nativeGetAxisValue(mNativePtr, AXIS_X, pointerIndex, HISTORY_CURRENT);
2187    }
2188
2189    /**
2190     * Returns the Y coordinate of this event for the given pointer
2191     * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
2192     * identifier for this index).
2193     * Whole numbers are pixels; the
2194     * value may have a fraction for input devices that are sub-pixel precise.
2195     * @param pointerIndex Raw index of pointer to retrieve.  Value may be from 0
2196     * (the first pointer that is down) to {@link #getPointerCount()}-1.
2197     *
2198     * @see #AXIS_Y
2199     */
2200    public final float getY(int pointerIndex) {
2201        return nativeGetAxisValue(mNativePtr, AXIS_Y, pointerIndex, HISTORY_CURRENT);
2202    }
2203
2204    /**
2205     * Returns the current pressure of this event for the given pointer
2206     * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
2207     * identifier for this index).
2208     * The pressure generally
2209     * ranges from 0 (no pressure at all) to 1 (normal pressure), however
2210     * values higher than 1 may be generated depending on the calibration of
2211     * the input device.
2212     * @param pointerIndex Raw index of pointer to retrieve.  Value may be from 0
2213     * (the first pointer that is down) to {@link #getPointerCount()}-1.
2214     *
2215     * @see #AXIS_PRESSURE
2216     */
2217    public final float getPressure(int pointerIndex) {
2218        return nativeGetAxisValue(mNativePtr, AXIS_PRESSURE, pointerIndex, HISTORY_CURRENT);
2219    }
2220
2221    /**
2222     * Returns a scaled value of the approximate size for the given pointer
2223     * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
2224     * identifier for this index).
2225     * This represents some approximation of the area of the screen being
2226     * pressed; the actual value in pixels corresponding to the
2227     * touch is normalized with the device specific range of values
2228     * and scaled to a value between 0 and 1. The value of size can be used to
2229     * determine fat touch events.
2230     * @param pointerIndex Raw index of pointer to retrieve.  Value may be from 0
2231     * (the first pointer that is down) to {@link #getPointerCount()}-1.
2232     *
2233     * @see #AXIS_SIZE
2234     */
2235    public final float getSize(int pointerIndex) {
2236        return nativeGetAxisValue(mNativePtr, AXIS_SIZE, pointerIndex, HISTORY_CURRENT);
2237    }
2238
2239    /**
2240     * Returns the length of the major axis of an ellipse that describes the touch
2241     * area at the point of contact for the given pointer
2242     * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
2243     * identifier for this index).
2244     * @param pointerIndex Raw index of pointer to retrieve.  Value may be from 0
2245     * (the first pointer that is down) to {@link #getPointerCount()}-1.
2246     *
2247     * @see #AXIS_TOUCH_MAJOR
2248     */
2249    public final float getTouchMajor(int pointerIndex) {
2250        return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MAJOR, pointerIndex, HISTORY_CURRENT);
2251    }
2252
2253    /**
2254     * Returns the length of the minor axis of an ellipse that describes the touch
2255     * area at the point of contact for the given pointer
2256     * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
2257     * identifier for this index).
2258     * @param pointerIndex Raw index of pointer to retrieve.  Value may be from 0
2259     * (the first pointer that is down) to {@link #getPointerCount()}-1.
2260     *
2261     * @see #AXIS_TOUCH_MINOR
2262     */
2263    public final float getTouchMinor(int pointerIndex) {
2264        return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MINOR, pointerIndex, HISTORY_CURRENT);
2265    }
2266
2267    /**
2268     * Returns the length of the major axis of an ellipse that describes the size of
2269     * the approaching tool for the given pointer
2270     * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
2271     * identifier for this index).
2272     * The tool area represents the estimated size of the finger or pen that is
2273     * touching the device independent of its actual touch area at the point of contact.
2274     * @param pointerIndex Raw index of pointer to retrieve.  Value may be from 0
2275     * (the first pointer that is down) to {@link #getPointerCount()}-1.
2276     *
2277     * @see #AXIS_TOOL_MAJOR
2278     */
2279    public final float getToolMajor(int pointerIndex) {
2280        return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MAJOR, pointerIndex, HISTORY_CURRENT);
2281    }
2282
2283    /**
2284     * Returns the length of the minor axis of an ellipse that describes the size of
2285     * the approaching tool for the given pointer
2286     * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
2287     * identifier for this index).
2288     * The tool area represents the estimated size of the finger or pen that is
2289     * touching the device independent of its actual touch area at the point of contact.
2290     * @param pointerIndex Raw index of pointer to retrieve.  Value may be from 0
2291     * (the first pointer that is down) to {@link #getPointerCount()}-1.
2292     *
2293     * @see #AXIS_TOOL_MINOR
2294     */
2295    public final float getToolMinor(int pointerIndex) {
2296        return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MINOR, pointerIndex, HISTORY_CURRENT);
2297    }
2298
2299    /**
2300     * Returns the orientation of the touch area and tool area in radians clockwise from vertical
2301     * for the given pointer <em>index</em> (use {@link #getPointerId(int)} to find the pointer
2302     * identifier for this index).
2303     * An angle of 0 radians indicates that the major axis of contact is oriented
2304     * upwards, is perfectly circular or is of unknown orientation.  A positive angle
2305     * indicates that the major axis of contact is oriented to the right.  A negative angle
2306     * indicates that the major axis of contact is oriented to the left.
2307     * The full range is from -PI/2 radians (finger pointing fully left) to PI/2 radians
2308     * (finger pointing fully right).
2309     * @param pointerIndex Raw index of pointer to retrieve.  Value may be from 0
2310     * (the first pointer that is down) to {@link #getPointerCount()}-1.
2311     *
2312     * @see #AXIS_ORIENTATION
2313     */
2314    public final float getOrientation(int pointerIndex) {
2315        return nativeGetAxisValue(mNativePtr, AXIS_ORIENTATION, pointerIndex, HISTORY_CURRENT);
2316    }
2317
2318    /**
2319     * Returns the value of the requested axis for the given pointer <em>index</em>
2320     * (use {@link #getPointerId(int)} to find the pointer identifier for this index).
2321     *
2322     * @param axis The axis identifier for the axis value to retrieve.
2323     * @param pointerIndex Raw index of pointer to retrieve.  Value may be from 0
2324     * (the first pointer that is down) to {@link #getPointerCount()}-1.
2325     * @return The value of the axis, or 0 if the axis is not available.
2326     *
2327     * @see #AXIS_X
2328     * @see #AXIS_Y
2329     */
2330    public final float getAxisValue(int axis, int pointerIndex) {
2331        return nativeGetAxisValue(mNativePtr, axis, pointerIndex, HISTORY_CURRENT);
2332    }
2333
2334    /**
2335     * Populates a {@link PointerCoords} object with pointer coordinate data for
2336     * the specified pointer index.
2337     *
2338     * @param pointerIndex Raw index of pointer to retrieve.  Value may be from 0
2339     * (the first pointer that is down) to {@link #getPointerCount()}-1.
2340     * @param outPointerCoords The pointer coordinate object to populate.
2341     *
2342     * @see PointerCoords
2343     */
2344    public final void getPointerCoords(int pointerIndex, PointerCoords outPointerCoords) {
2345        nativeGetPointerCoords(mNativePtr, pointerIndex, HISTORY_CURRENT, outPointerCoords);
2346    }
2347
2348    /**
2349     * Populates a {@link PointerProperties} object with pointer properties for
2350     * the specified pointer index.
2351     *
2352     * @param pointerIndex Raw index of pointer to retrieve.  Value may be from 0
2353     * (the first pointer that is down) to {@link #getPointerCount()}-1.
2354     * @param outPointerProperties The pointer properties object to populate.
2355     *
2356     * @see PointerProperties
2357     */
2358    public final void getPointerProperties(int pointerIndex,
2359            PointerProperties outPointerProperties) {
2360        nativeGetPointerProperties(mNativePtr, pointerIndex, outPointerProperties);
2361    }
2362
2363    /**
2364     * Returns the state of any meta / modifier keys that were in effect when
2365     * the event was generated.  This is the same values as those
2366     * returned by {@link KeyEvent#getMetaState() KeyEvent.getMetaState}.
2367     *
2368     * @return an integer in which each bit set to 1 represents a pressed
2369     *         meta key
2370     *
2371     * @see KeyEvent#getMetaState()
2372     */
2373    public final int getMetaState() {
2374        return nativeGetMetaState(mNativePtr);
2375    }
2376
2377    /**
2378     * Gets the state of all buttons that are pressed such as a mouse or stylus button.
2379     *
2380     * @return The button state.
2381     *
2382     * @see #BUTTON_PRIMARY
2383     * @see #BUTTON_SECONDARY
2384     * @see #BUTTON_TERTIARY
2385     * @see #BUTTON_FORWARD
2386     * @see #BUTTON_BACK
2387     * @see #BUTTON_STYLUS_PRIMARY
2388     * @see #BUTTON_STYLUS_SECONDARY
2389     */
2390    public final int getButtonState() {
2391        return nativeGetButtonState(mNativePtr);
2392    }
2393
2394    /**
2395     * Sets the bitfield indicating which buttons are pressed.
2396     *
2397     * @see #getButtonState()
2398     * @hide
2399     */
2400    @TestApi
2401    public final void setButtonState(int buttonState) {
2402        nativeSetButtonState(mNativePtr, buttonState);
2403    }
2404
2405    /**
2406     * Gets which button has been modified during a press or release action.
2407     *
2408     * For actions other than {@link #ACTION_BUTTON_PRESS} and {@link #ACTION_BUTTON_RELEASE}
2409     * the returned value is undefined.
2410     *
2411     * @see #getButtonState()
2412     */
2413    public final int getActionButton() {
2414        return nativeGetActionButton(mNativePtr);
2415    }
2416
2417    /**
2418     * Sets the action button for the event.
2419     *
2420     * @see #getActionButton()
2421     * @hide
2422     */
2423    @TestApi
2424    public final void setActionButton(int button) {
2425        nativeSetActionButton(mNativePtr, button);
2426    }
2427
2428    /**
2429     * Returns the original raw X coordinate of this event.  For touch
2430     * events on the screen, this is the original location of the event
2431     * on the screen, before it had been adjusted for the containing window
2432     * and views.
2433     *
2434     * @see #getX(int)
2435     * @see #AXIS_X
2436     */
2437    public final float getRawX() {
2438        return nativeGetRawAxisValue(mNativePtr, AXIS_X, 0, HISTORY_CURRENT);
2439    }
2440
2441    /**
2442     * Returns the original raw Y coordinate of this event.  For touch
2443     * events on the screen, this is the original location of the event
2444     * on the screen, before it had been adjusted for the containing window
2445     * and views.
2446     *
2447     * @see #getY(int)
2448     * @see #AXIS_Y
2449     */
2450    public final float getRawY() {
2451        return nativeGetRawAxisValue(mNativePtr, AXIS_Y, 0, HISTORY_CURRENT);
2452    }
2453
2454    /**
2455     * Return the precision of the X coordinates being reported.  You can
2456     * multiply this number with {@link #getX} to find the actual hardware
2457     * value of the X coordinate.
2458     * @return Returns the precision of X coordinates being reported.
2459     *
2460     * @see #AXIS_X
2461     */
2462    public final float getXPrecision() {
2463        return nativeGetXPrecision(mNativePtr);
2464    }
2465
2466    /**
2467     * Return the precision of the Y coordinates being reported.  You can
2468     * multiply this number with {@link #getY} to find the actual hardware
2469     * value of the Y coordinate.
2470     * @return Returns the precision of Y coordinates being reported.
2471     *
2472     * @see #AXIS_Y
2473     */
2474    public final float getYPrecision() {
2475        return nativeGetYPrecision(mNativePtr);
2476    }
2477
2478    /**
2479     * Returns the number of historical points in this event.  These are
2480     * movements that have occurred between this event and the previous event.
2481     * This only applies to ACTION_MOVE events -- all other actions will have
2482     * a size of 0.
2483     *
2484     * @return Returns the number of historical points in the event.
2485     */
2486    public final int getHistorySize() {
2487        return nativeGetHistorySize(mNativePtr);
2488    }
2489
2490    /**
2491     * Returns the time that a historical movement occurred between this event
2492     * and the previous event, in the {@link android.os.SystemClock#uptimeMillis} time base.
2493     * <p>
2494     * This only applies to ACTION_MOVE events.
2495     * </p>
2496     *
2497     * @param pos Which historical value to return; must be less than
2498     * {@link #getHistorySize}
2499     * @return Returns the time that a historical movement occurred between this
2500     * event and the previous event,
2501     * in the {@link android.os.SystemClock#uptimeMillis} time base.
2502     *
2503     * @see #getHistorySize
2504     * @see #getEventTime
2505     */
2506    public final long getHistoricalEventTime(int pos) {
2507        return nativeGetEventTimeNanos(mNativePtr, pos) / NS_PER_MS;
2508    }
2509
2510    /**
2511     * Returns the time that a historical movement occurred between this event
2512     * and the previous event, in the {@link android.os.SystemClock#uptimeMillis} time base
2513     * but with nanosecond (instead of millisecond) precision.
2514     * <p>
2515     * This only applies to ACTION_MOVE events.
2516     * </p><p>
2517     * The value is in nanosecond precision but it may not have nanosecond accuracy.
2518     * </p>
2519     *
2520     * @param pos Which historical value to return; must be less than
2521     * {@link #getHistorySize}
2522     * @return Returns the time that a historical movement occurred between this
2523     * event and the previous event,
2524     * in the {@link android.os.SystemClock#uptimeMillis} time base but with
2525     * nanosecond (instead of millisecond) precision.
2526     *
2527     * @see #getHistorySize
2528     * @see #getEventTime
2529     *
2530     * @hide
2531     */
2532    public final long getHistoricalEventTimeNano(int pos) {
2533        return nativeGetEventTimeNanos(mNativePtr, pos);
2534    }
2535
2536    /**
2537     * {@link #getHistoricalX(int, int)} for the first pointer index (may be an
2538     * arbitrary pointer identifier).
2539     *
2540     * @param pos Which historical value to return; must be less than
2541     * {@link #getHistorySize}
2542     *
2543     * @see #getHistorySize
2544     * @see #getX()
2545     * @see #AXIS_X
2546     */
2547    public final float getHistoricalX(int pos) {
2548        return nativeGetAxisValue(mNativePtr, AXIS_X, 0, pos);
2549    }
2550
2551    /**
2552     * {@link #getHistoricalY(int, int)} for the first pointer index (may be an
2553     * arbitrary pointer identifier).
2554     *
2555     * @param pos Which historical value to return; must be less than
2556     * {@link #getHistorySize}
2557     *
2558     * @see #getHistorySize
2559     * @see #getY()
2560     * @see #AXIS_Y
2561     */
2562    public final float getHistoricalY(int pos) {
2563        return nativeGetAxisValue(mNativePtr, AXIS_Y, 0, pos);
2564    }
2565
2566    /**
2567     * {@link #getHistoricalPressure(int, int)} for the first pointer index (may be an
2568     * arbitrary pointer identifier).
2569     *
2570     * @param pos Which historical value to return; must be less than
2571     * {@link #getHistorySize}
2572     *
2573     * @see #getHistorySize
2574     * @see #getPressure()
2575     * @see #AXIS_PRESSURE
2576     */
2577    public final float getHistoricalPressure(int pos) {
2578        return nativeGetAxisValue(mNativePtr, AXIS_PRESSURE, 0, pos);
2579    }
2580
2581    /**
2582     * {@link #getHistoricalSize(int, int)} for the first pointer index (may be an
2583     * arbitrary pointer identifier).
2584     *
2585     * @param pos Which historical value to return; must be less than
2586     * {@link #getHistorySize}
2587     *
2588     * @see #getHistorySize
2589     * @see #getSize()
2590     * @see #AXIS_SIZE
2591     */
2592    public final float getHistoricalSize(int pos) {
2593        return nativeGetAxisValue(mNativePtr, AXIS_SIZE, 0, pos);
2594    }
2595
2596    /**
2597     * {@link #getHistoricalTouchMajor(int, int)} for the first pointer index (may be an
2598     * arbitrary pointer identifier).
2599     *
2600     * @param pos Which historical value to return; must be less than
2601     * {@link #getHistorySize}
2602     *
2603     * @see #getHistorySize
2604     * @see #getTouchMajor()
2605     * @see #AXIS_TOUCH_MAJOR
2606     */
2607    public final float getHistoricalTouchMajor(int pos) {
2608        return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MAJOR, 0, pos);
2609    }
2610
2611    /**
2612     * {@link #getHistoricalTouchMinor(int, int)} for the first pointer index (may be an
2613     * arbitrary pointer identifier).
2614     *
2615     * @param pos Which historical value to return; must be less than
2616     * {@link #getHistorySize}
2617     *
2618     * @see #getHistorySize
2619     * @see #getTouchMinor()
2620     * @see #AXIS_TOUCH_MINOR
2621     */
2622    public final float getHistoricalTouchMinor(int pos) {
2623        return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MINOR, 0, pos);
2624    }
2625
2626    /**
2627     * {@link #getHistoricalToolMajor(int, int)} for the first pointer index (may be an
2628     * arbitrary pointer identifier).
2629     *
2630     * @param pos Which historical value to return; must be less than
2631     * {@link #getHistorySize}
2632     *
2633     * @see #getHistorySize
2634     * @see #getToolMajor()
2635     * @see #AXIS_TOOL_MAJOR
2636     */
2637    public final float getHistoricalToolMajor(int pos) {
2638        return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MAJOR, 0, pos);
2639    }
2640
2641    /**
2642     * {@link #getHistoricalToolMinor(int, int)} for the first pointer index (may be an
2643     * arbitrary pointer identifier).
2644     *
2645     * @param pos Which historical value to return; must be less than
2646     * {@link #getHistorySize}
2647     *
2648     * @see #getHistorySize
2649     * @see #getToolMinor()
2650     * @see #AXIS_TOOL_MINOR
2651     */
2652    public final float getHistoricalToolMinor(int pos) {
2653        return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MINOR, 0, pos);
2654    }
2655
2656    /**
2657     * {@link #getHistoricalOrientation(int, int)} for the first pointer index (may be an
2658     * arbitrary pointer identifier).
2659     *
2660     * @param pos Which historical value to return; must be less than
2661     * {@link #getHistorySize}
2662     *
2663     * @see #getHistorySize
2664     * @see #getOrientation()
2665     * @see #AXIS_ORIENTATION
2666     */
2667    public final float getHistoricalOrientation(int pos) {
2668        return nativeGetAxisValue(mNativePtr, AXIS_ORIENTATION, 0, pos);
2669    }
2670
2671    /**
2672     * {@link #getHistoricalAxisValue(int, int, int)} for the first pointer index (may be an
2673     * arbitrary pointer identifier).
2674     *
2675     * @param axis The axis identifier for the axis value to retrieve.
2676     * @param pos Which historical value to return; must be less than
2677     * {@link #getHistorySize}
2678     *
2679     * @see #getHistorySize
2680     * @see #getAxisValue(int)
2681     * @see #AXIS_X
2682     * @see #AXIS_Y
2683     */
2684    public final float getHistoricalAxisValue(int axis, int pos) {
2685        return nativeGetAxisValue(mNativePtr, axis, 0, pos);
2686    }
2687
2688    /**
2689     * Returns a historical X coordinate, as per {@link #getX(int)}, that
2690     * occurred between this event and the previous event for the given pointer.
2691     * Only applies to ACTION_MOVE events.
2692     *
2693     * @param pointerIndex Raw index of pointer to retrieve.  Value may be from 0
2694     * (the first pointer that is down) to {@link #getPointerCount()}-1.
2695     * @param pos Which historical value to return; must be less than
2696     * {@link #getHistorySize}
2697     *
2698     * @see #getHistorySize
2699     * @see #getX(int)
2700     * @see #AXIS_X
2701     */
2702    public final float getHistoricalX(int pointerIndex, int pos) {
2703        return nativeGetAxisValue(mNativePtr, AXIS_X, pointerIndex, pos);
2704    }
2705
2706    /**
2707     * Returns a historical Y coordinate, as per {@link #getY(int)}, that
2708     * occurred between this event and the previous event for the given pointer.
2709     * Only applies to ACTION_MOVE events.
2710     *
2711     * @param pointerIndex Raw index of pointer to retrieve.  Value may be from 0
2712     * (the first pointer that is down) to {@link #getPointerCount()}-1.
2713     * @param pos Which historical value to return; must be less than
2714     * {@link #getHistorySize}
2715     *
2716     * @see #getHistorySize
2717     * @see #getY(int)
2718     * @see #AXIS_Y
2719     */
2720    public final float getHistoricalY(int pointerIndex, int pos) {
2721        return nativeGetAxisValue(mNativePtr, AXIS_Y, pointerIndex, pos);
2722    }
2723
2724    /**
2725     * Returns a historical pressure coordinate, as per {@link #getPressure(int)},
2726     * that occurred between this event and the previous event for the given
2727     * pointer.  Only applies to ACTION_MOVE events.
2728     *
2729     * @param pointerIndex Raw index of pointer to retrieve.  Value may be from 0
2730     * (the first pointer that is down) to {@link #getPointerCount()}-1.
2731     * @param pos Which historical value to return; must be less than
2732     * {@link #getHistorySize}
2733     *
2734     * @see #getHistorySize
2735     * @see #getPressure(int)
2736     * @see #AXIS_PRESSURE
2737     */
2738    public final float getHistoricalPressure(int pointerIndex, int pos) {
2739        return nativeGetAxisValue(mNativePtr, AXIS_PRESSURE, pointerIndex, pos);
2740    }
2741
2742    /**
2743     * Returns a historical size coordinate, as per {@link #getSize(int)}, that
2744     * occurred between this event and the previous event for the given pointer.
2745     * Only applies to ACTION_MOVE events.
2746     *
2747     * @param pointerIndex Raw index of pointer to retrieve.  Value may be from 0
2748     * (the first pointer that is down) to {@link #getPointerCount()}-1.
2749     * @param pos Which historical value to return; must be less than
2750     * {@link #getHistorySize}
2751     *
2752     * @see #getHistorySize
2753     * @see #getSize(int)
2754     * @see #AXIS_SIZE
2755     */
2756    public final float getHistoricalSize(int pointerIndex, int pos) {
2757        return nativeGetAxisValue(mNativePtr, AXIS_SIZE, pointerIndex, pos);
2758    }
2759
2760    /**
2761     * Returns a historical touch major axis coordinate, as per {@link #getTouchMajor(int)}, that
2762     * occurred between this event and the previous event for the given pointer.
2763     * Only applies to ACTION_MOVE events.
2764     *
2765     * @param pointerIndex Raw index of pointer to retrieve.  Value may be from 0
2766     * (the first pointer that is down) to {@link #getPointerCount()}-1.
2767     * @param pos Which historical value to return; must be less than
2768     * {@link #getHistorySize}
2769     *
2770     * @see #getHistorySize
2771     * @see #getTouchMajor(int)
2772     * @see #AXIS_TOUCH_MAJOR
2773     */
2774    public final float getHistoricalTouchMajor(int pointerIndex, int pos) {
2775        return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MAJOR, pointerIndex, pos);
2776    }
2777
2778    /**
2779     * Returns a historical touch minor axis coordinate, as per {@link #getTouchMinor(int)}, that
2780     * occurred between this event and the previous event for the given pointer.
2781     * Only applies to ACTION_MOVE events.
2782     *
2783     * @param pointerIndex Raw index of pointer to retrieve.  Value may be from 0
2784     * (the first pointer that is down) to {@link #getPointerCount()}-1.
2785     * @param pos Which historical value to return; must be less than
2786     * {@link #getHistorySize}
2787     *
2788     * @see #getHistorySize
2789     * @see #getTouchMinor(int)
2790     * @see #AXIS_TOUCH_MINOR
2791     */
2792    public final float getHistoricalTouchMinor(int pointerIndex, int pos) {
2793        return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MINOR, pointerIndex, pos);
2794    }
2795
2796    /**
2797     * Returns a historical tool major axis coordinate, as per {@link #getToolMajor(int)}, that
2798     * occurred between this event and the previous event for the given pointer.
2799     * Only applies to ACTION_MOVE events.
2800     *
2801     * @param pointerIndex Raw index of pointer to retrieve.  Value may be from 0
2802     * (the first pointer that is down) to {@link #getPointerCount()}-1.
2803     * @param pos Which historical value to return; must be less than
2804     * {@link #getHistorySize}
2805     *
2806     * @see #getHistorySize
2807     * @see #getToolMajor(int)
2808     * @see #AXIS_TOOL_MAJOR
2809     */
2810    public final float getHistoricalToolMajor(int pointerIndex, int pos) {
2811        return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MAJOR, pointerIndex, pos);
2812    }
2813
2814    /**
2815     * Returns a historical tool minor axis coordinate, as per {@link #getToolMinor(int)}, that
2816     * occurred between this event and the previous event for the given pointer.
2817     * Only applies to ACTION_MOVE events.
2818     *
2819     * @param pointerIndex Raw index of pointer to retrieve.  Value may be from 0
2820     * (the first pointer that is down) to {@link #getPointerCount()}-1.
2821     * @param pos Which historical value to return; must be less than
2822     * {@link #getHistorySize}
2823     *
2824     * @see #getHistorySize
2825     * @see #getToolMinor(int)
2826     * @see #AXIS_TOOL_MINOR
2827     */
2828    public final float getHistoricalToolMinor(int pointerIndex, int pos) {
2829        return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MINOR, pointerIndex, pos);
2830    }
2831
2832    /**
2833     * Returns a historical orientation coordinate, as per {@link #getOrientation(int)}, that
2834     * occurred between this event and the previous event for the given pointer.
2835     * Only applies to ACTION_MOVE events.
2836     *
2837     * @param pointerIndex Raw index of pointer to retrieve.  Value may be from 0
2838     * (the first pointer that is down) to {@link #getPointerCount()}-1.
2839     * @param pos Which historical value to return; must be less than
2840     * {@link #getHistorySize}
2841     *
2842     * @see #getHistorySize
2843     * @see #getOrientation(int)
2844     * @see #AXIS_ORIENTATION
2845     */
2846    public final float getHistoricalOrientation(int pointerIndex, int pos) {
2847        return nativeGetAxisValue(mNativePtr, AXIS_ORIENTATION, pointerIndex, pos);
2848    }
2849
2850    /**
2851     * Returns the historical value of the requested axis, as per {@link #getAxisValue(int, int)},
2852     * occurred between this event and the previous event for the given pointer.
2853     * Only applies to ACTION_MOVE events.
2854     *
2855     * @param axis The axis identifier for the axis value to retrieve.
2856     * @param pointerIndex Raw index of pointer to retrieve.  Value may be from 0
2857     * (the first pointer that is down) to {@link #getPointerCount()}-1.
2858     * @param pos Which historical value to return; must be less than
2859     * {@link #getHistorySize}
2860     * @return The value of the axis, or 0 if the axis is not available.
2861     *
2862     * @see #AXIS_X
2863     * @see #AXIS_Y
2864     */
2865    public final float getHistoricalAxisValue(int axis, int pointerIndex, int pos) {
2866        return nativeGetAxisValue(mNativePtr, axis, pointerIndex, pos);
2867    }
2868
2869    /**
2870     * Populates a {@link PointerCoords} object with historical pointer coordinate data,
2871     * as per {@link #getPointerCoords}, that occurred between this event and the previous
2872     * event for the given pointer.
2873     * Only applies to ACTION_MOVE events.
2874     *
2875     * @param pointerIndex Raw index of pointer to retrieve.  Value may be from 0
2876     * (the first pointer that is down) to {@link #getPointerCount()}-1.
2877     * @param pos Which historical value to return; must be less than
2878     * {@link #getHistorySize}
2879     * @param outPointerCoords The pointer coordinate object to populate.
2880     *
2881     * @see #getHistorySize
2882     * @see #getPointerCoords
2883     * @see PointerCoords
2884     */
2885    public final void getHistoricalPointerCoords(int pointerIndex, int pos,
2886            PointerCoords outPointerCoords) {
2887        nativeGetPointerCoords(mNativePtr, pointerIndex, pos, outPointerCoords);
2888    }
2889
2890    /**
2891     * Returns a bitfield indicating which edges, if any, were touched by this
2892     * MotionEvent. For touch events, clients can use this to determine if the
2893     * user's finger was touching the edge of the display.
2894     *
2895     * This property is only set for {@link #ACTION_DOWN} events.
2896     *
2897     * @see #EDGE_LEFT
2898     * @see #EDGE_TOP
2899     * @see #EDGE_RIGHT
2900     * @see #EDGE_BOTTOM
2901     */
2902    public final int getEdgeFlags() {
2903        return nativeGetEdgeFlags(mNativePtr);
2904    }
2905
2906    /**
2907     * Sets the bitfield indicating which edges, if any, were touched by this
2908     * MotionEvent.
2909     *
2910     * @see #getEdgeFlags()
2911     */
2912    public final void setEdgeFlags(int flags) {
2913        nativeSetEdgeFlags(mNativePtr, flags);
2914    }
2915
2916    /**
2917     * Sets this event's action.
2918     */
2919    public final void setAction(int action) {
2920        nativeSetAction(mNativePtr, action);
2921    }
2922
2923    /**
2924     * Adjust this event's location.
2925     * @param deltaX Amount to add to the current X coordinate of the event.
2926     * @param deltaY Amount to add to the current Y coordinate of the event.
2927     */
2928    public final void offsetLocation(float deltaX, float deltaY) {
2929        if (deltaX != 0.0f || deltaY != 0.0f) {
2930            nativeOffsetLocation(mNativePtr, deltaX, deltaY);
2931        }
2932    }
2933
2934    /**
2935     * Set this event's location.  Applies {@link #offsetLocation} with a
2936     * delta from the current location to the given new location.
2937     *
2938     * @param x New absolute X location.
2939     * @param y New absolute Y location.
2940     */
2941    public final void setLocation(float x, float y) {
2942        float oldX = getX();
2943        float oldY = getY();
2944        offsetLocation(x - oldX, y - oldY);
2945    }
2946
2947    /**
2948     * Applies a transformation matrix to all of the points in the event.
2949     *
2950     * @param matrix The transformation matrix to apply.
2951     */
2952    public final void transform(Matrix matrix) {
2953        if (matrix == null) {
2954            throw new IllegalArgumentException("matrix must not be null");
2955        }
2956
2957        nativeTransform(mNativePtr, matrix.native_instance);
2958    }
2959
2960    /**
2961     * Add a new movement to the batch of movements in this event.  The event's
2962     * current location, position and size is updated to the new values.
2963     * The current values in the event are added to a list of historical values.
2964     *
2965     * Only applies to {@link #ACTION_MOVE} or {@link #ACTION_HOVER_MOVE} events.
2966     *
2967     * @param eventTime The time stamp (in ms) for this data.
2968     * @param x The new X position.
2969     * @param y The new Y position.
2970     * @param pressure The new pressure.
2971     * @param size The new size.
2972     * @param metaState Meta key state.
2973     */
2974    public final void addBatch(long eventTime, float x, float y,
2975            float pressure, float size, int metaState) {
2976        synchronized (gSharedTempLock) {
2977            ensureSharedTempPointerCapacity(1);
2978            final PointerCoords[] pc = gSharedTempPointerCoords;
2979            pc[0].clear();
2980            pc[0].x = x;
2981            pc[0].y = y;
2982            pc[0].pressure = pressure;
2983            pc[0].size = size;
2984
2985            nativeAddBatch(mNativePtr, eventTime * NS_PER_MS, pc, metaState);
2986        }
2987    }
2988
2989    /**
2990     * Add a new movement to the batch of movements in this event.  The event's
2991     * current location, position and size is updated to the new values.
2992     * The current values in the event are added to a list of historical values.
2993     *
2994     * Only applies to {@link #ACTION_MOVE} or {@link #ACTION_HOVER_MOVE} events.
2995     *
2996     * @param eventTime The time stamp (in ms) for this data.
2997     * @param pointerCoords The new pointer coordinates.
2998     * @param metaState Meta key state.
2999     */
3000    public final void addBatch(long eventTime, PointerCoords[] pointerCoords, int metaState) {
3001        nativeAddBatch(mNativePtr, eventTime * NS_PER_MS, pointerCoords, metaState);
3002    }
3003
3004    /**
3005     * Adds all of the movement samples of the specified event to this one if
3006     * it is compatible.  To be compatible, the event must have the same device id,
3007     * source, action, flags, pointer count, pointer properties.
3008     *
3009     * Only applies to {@link #ACTION_MOVE} or {@link #ACTION_HOVER_MOVE} events.
3010     *
3011     * @param event The event whose movements samples should be added to this one
3012     * if possible.
3013     * @return True if batching was performed or false if batching was not possible.
3014     * @hide
3015     */
3016    public final boolean addBatch(MotionEvent event) {
3017        final int action = nativeGetAction(mNativePtr);
3018        if (action != ACTION_MOVE && action != ACTION_HOVER_MOVE) {
3019            return false;
3020        }
3021        if (action != nativeGetAction(event.mNativePtr)) {
3022            return false;
3023        }
3024
3025        if (nativeGetDeviceId(mNativePtr) != nativeGetDeviceId(event.mNativePtr)
3026                || nativeGetSource(mNativePtr) != nativeGetSource(event.mNativePtr)
3027                || nativeGetFlags(mNativePtr) != nativeGetFlags(event.mNativePtr)) {
3028            return false;
3029        }
3030
3031        final int pointerCount = nativeGetPointerCount(mNativePtr);
3032        if (pointerCount != nativeGetPointerCount(event.mNativePtr)) {
3033            return false;
3034        }
3035
3036        synchronized (gSharedTempLock) {
3037            ensureSharedTempPointerCapacity(Math.max(pointerCount, 2));
3038            final PointerProperties[] pp = gSharedTempPointerProperties;
3039            final PointerCoords[] pc = gSharedTempPointerCoords;
3040
3041            for (int i = 0; i < pointerCount; i++) {
3042                nativeGetPointerProperties(mNativePtr, i, pp[0]);
3043                nativeGetPointerProperties(event.mNativePtr, i, pp[1]);
3044                if (!pp[0].equals(pp[1])) {
3045                    return false;
3046                }
3047            }
3048
3049            final int metaState = nativeGetMetaState(event.mNativePtr);
3050            final int historySize = nativeGetHistorySize(event.mNativePtr);
3051            for (int h = 0; h <= historySize; h++) {
3052                final int historyPos = (h == historySize ? HISTORY_CURRENT : h);
3053
3054                for (int i = 0; i < pointerCount; i++) {
3055                    nativeGetPointerCoords(event.mNativePtr, i, historyPos, pc[i]);
3056                }
3057
3058                final long eventTimeNanos = nativeGetEventTimeNanos(event.mNativePtr, historyPos);
3059                nativeAddBatch(mNativePtr, eventTimeNanos, pc, metaState);
3060            }
3061        }
3062        return true;
3063    }
3064
3065    /**
3066     * Returns true if all points in the motion event are completely within the specified bounds.
3067     * @hide
3068     */
3069    public final boolean isWithinBoundsNoHistory(float left, float top,
3070            float right, float bottom) {
3071        final int pointerCount = nativeGetPointerCount(mNativePtr);
3072        for (int i = 0; i < pointerCount; i++) {
3073            final float x = nativeGetAxisValue(mNativePtr, AXIS_X, i, HISTORY_CURRENT);
3074            final float y = nativeGetAxisValue(mNativePtr, AXIS_Y, i, HISTORY_CURRENT);
3075            if (x < left || x > right || y < top || y > bottom) {
3076                return false;
3077            }
3078        }
3079        return true;
3080    }
3081
3082    private static final float clamp(float value, float low, float high) {
3083        if (value < low) {
3084            return low;
3085        } else if (value > high) {
3086            return high;
3087        }
3088        return value;
3089    }
3090
3091    /**
3092     * Returns a new motion events whose points have been clamped to the specified bounds.
3093     * @hide
3094     */
3095    public final MotionEvent clampNoHistory(float left, float top, float right, float bottom) {
3096        MotionEvent ev = obtain();
3097        synchronized (gSharedTempLock) {
3098            final int pointerCount = nativeGetPointerCount(mNativePtr);
3099
3100            ensureSharedTempPointerCapacity(pointerCount);
3101            final PointerProperties[] pp = gSharedTempPointerProperties;
3102            final PointerCoords[] pc = gSharedTempPointerCoords;
3103
3104            for (int i = 0; i < pointerCount; i++) {
3105                nativeGetPointerProperties(mNativePtr, i, pp[i]);
3106                nativeGetPointerCoords(mNativePtr, i, HISTORY_CURRENT, pc[i]);
3107                pc[i].x = clamp(pc[i].x, left, right);
3108                pc[i].y = clamp(pc[i].y, top, bottom);
3109            }
3110            ev.mNativePtr = nativeInitialize(ev.mNativePtr,
3111                    nativeGetDeviceId(mNativePtr), nativeGetSource(mNativePtr),
3112                    nativeGetAction(mNativePtr), nativeGetFlags(mNativePtr),
3113                    nativeGetEdgeFlags(mNativePtr), nativeGetMetaState(mNativePtr),
3114                    nativeGetButtonState(mNativePtr),
3115                    nativeGetXOffset(mNativePtr), nativeGetYOffset(mNativePtr),
3116                    nativeGetXPrecision(mNativePtr), nativeGetYPrecision(mNativePtr),
3117                    nativeGetDownTimeNanos(mNativePtr),
3118                    nativeGetEventTimeNanos(mNativePtr, HISTORY_CURRENT),
3119                    pointerCount, pp, pc);
3120            return ev;
3121        }
3122    }
3123
3124    /**
3125     * Gets an integer where each pointer id present in the event is marked as a bit.
3126     * @hide
3127     */
3128    public final int getPointerIdBits() {
3129        int idBits = 0;
3130        final int pointerCount = nativeGetPointerCount(mNativePtr);
3131        for (int i = 0; i < pointerCount; i++) {
3132            idBits |= 1 << nativeGetPointerId(mNativePtr, i);
3133        }
3134        return idBits;
3135    }
3136
3137    /**
3138     * Splits a motion event such that it includes only a subset of pointer ids.
3139     * @hide
3140     */
3141    public final MotionEvent split(int idBits) {
3142        MotionEvent ev = obtain();
3143        synchronized (gSharedTempLock) {
3144            final int oldPointerCount = nativeGetPointerCount(mNativePtr);
3145            ensureSharedTempPointerCapacity(oldPointerCount);
3146            final PointerProperties[] pp = gSharedTempPointerProperties;
3147            final PointerCoords[] pc = gSharedTempPointerCoords;
3148            final int[] map = gSharedTempPointerIndexMap;
3149
3150            final int oldAction = nativeGetAction(mNativePtr);
3151            final int oldActionMasked = oldAction & ACTION_MASK;
3152            final int oldActionPointerIndex = (oldAction & ACTION_POINTER_INDEX_MASK)
3153                    >> ACTION_POINTER_INDEX_SHIFT;
3154            int newActionPointerIndex = -1;
3155            int newPointerCount = 0;
3156            int newIdBits = 0;
3157            for (int i = 0; i < oldPointerCount; i++) {
3158                nativeGetPointerProperties(mNativePtr, i, pp[newPointerCount]);
3159                final int idBit = 1 << pp[newPointerCount].id;
3160                if ((idBit & idBits) != 0) {
3161                    if (i == oldActionPointerIndex) {
3162                        newActionPointerIndex = newPointerCount;
3163                    }
3164                    map[newPointerCount] = i;
3165                    newPointerCount += 1;
3166                    newIdBits |= idBit;
3167                }
3168            }
3169
3170            if (newPointerCount == 0) {
3171                throw new IllegalArgumentException("idBits did not match any ids in the event");
3172            }
3173
3174            final int newAction;
3175            if (oldActionMasked == ACTION_POINTER_DOWN || oldActionMasked == ACTION_POINTER_UP) {
3176                if (newActionPointerIndex < 0) {
3177                    // An unrelated pointer changed.
3178                    newAction = ACTION_MOVE;
3179                } else if (newPointerCount == 1) {
3180                    // The first/last pointer went down/up.
3181                    newAction = oldActionMasked == ACTION_POINTER_DOWN
3182                            ? ACTION_DOWN : ACTION_UP;
3183                } else {
3184                    // A secondary pointer went down/up.
3185                    newAction = oldActionMasked
3186                            | (newActionPointerIndex << ACTION_POINTER_INDEX_SHIFT);
3187                }
3188            } else {
3189                // Simple up/down/cancel/move or other motion action.
3190                newAction = oldAction;
3191            }
3192
3193            final int historySize = nativeGetHistorySize(mNativePtr);
3194            for (int h = 0; h <= historySize; h++) {
3195                final int historyPos = h == historySize ? HISTORY_CURRENT : h;
3196
3197                for (int i = 0; i < newPointerCount; i++) {
3198                    nativeGetPointerCoords(mNativePtr, map[i], historyPos, pc[i]);
3199                }
3200
3201                final long eventTimeNanos = nativeGetEventTimeNanos(mNativePtr, historyPos);
3202                if (h == 0) {
3203                    ev.mNativePtr = nativeInitialize(ev.mNativePtr,
3204                            nativeGetDeviceId(mNativePtr), nativeGetSource(mNativePtr),
3205                            newAction, nativeGetFlags(mNativePtr),
3206                            nativeGetEdgeFlags(mNativePtr), nativeGetMetaState(mNativePtr),
3207                            nativeGetButtonState(mNativePtr),
3208                            nativeGetXOffset(mNativePtr), nativeGetYOffset(mNativePtr),
3209                            nativeGetXPrecision(mNativePtr), nativeGetYPrecision(mNativePtr),
3210                            nativeGetDownTimeNanos(mNativePtr), eventTimeNanos,
3211                            newPointerCount, pp, pc);
3212                } else {
3213                    nativeAddBatch(ev.mNativePtr, eventTimeNanos, pc, 0);
3214                }
3215            }
3216            return ev;
3217        }
3218    }
3219
3220    @Override
3221    public String toString() {
3222        StringBuilder msg = new StringBuilder();
3223        msg.append("MotionEvent { action=").append(actionToString(getAction()));
3224        msg.append(", actionButton=").append(buttonStateToString(getActionButton()));
3225
3226        final int pointerCount = getPointerCount();
3227        for (int i = 0; i < pointerCount; i++) {
3228            msg.append(", id[").append(i).append("]=").append(getPointerId(i));
3229            msg.append(", x[").append(i).append("]=").append(getX(i));
3230            msg.append(", y[").append(i).append("]=").append(getY(i));
3231            msg.append(", toolType[").append(i).append("]=").append(
3232                    toolTypeToString(getToolType(i)));
3233        }
3234
3235        msg.append(", buttonState=").append(MotionEvent.buttonStateToString(getButtonState()));
3236        msg.append(", metaState=").append(KeyEvent.metaStateToString(getMetaState()));
3237        msg.append(", flags=0x").append(Integer.toHexString(getFlags()));
3238        msg.append(", edgeFlags=0x").append(Integer.toHexString(getEdgeFlags()));
3239        msg.append(", pointerCount=").append(pointerCount);
3240        msg.append(", historySize=").append(getHistorySize());
3241        msg.append(", eventTime=").append(getEventTime());
3242        msg.append(", downTime=").append(getDownTime());
3243        msg.append(", deviceId=").append(getDeviceId());
3244        msg.append(", source=0x").append(Integer.toHexString(getSource()));
3245        msg.append(" }");
3246        return msg.toString();
3247    }
3248
3249    /**
3250     * Returns a string that represents the symbolic name of the specified unmasked action
3251     * such as "ACTION_DOWN", "ACTION_POINTER_DOWN(3)" or an equivalent numeric constant
3252     * such as "35" if unknown.
3253     *
3254     * @param action The unmasked action.
3255     * @return The symbolic name of the specified action.
3256     * @see #getAction()
3257     */
3258    public static String actionToString(int action) {
3259        switch (action) {
3260            case ACTION_DOWN:
3261                return "ACTION_DOWN";
3262            case ACTION_UP:
3263                return "ACTION_UP";
3264            case ACTION_CANCEL:
3265                return "ACTION_CANCEL";
3266            case ACTION_OUTSIDE:
3267                return "ACTION_OUTSIDE";
3268            case ACTION_MOVE:
3269                return "ACTION_MOVE";
3270            case ACTION_HOVER_MOVE:
3271                return "ACTION_HOVER_MOVE";
3272            case ACTION_SCROLL:
3273                return "ACTION_SCROLL";
3274            case ACTION_HOVER_ENTER:
3275                return "ACTION_HOVER_ENTER";
3276            case ACTION_HOVER_EXIT:
3277                return "ACTION_HOVER_EXIT";
3278            case ACTION_BUTTON_PRESS:
3279                return "ACTION_BUTTON_PRESS";
3280            case ACTION_BUTTON_RELEASE:
3281                return "ACTION_BUTTON_RELEASE";
3282        }
3283        int index = (action & ACTION_POINTER_INDEX_MASK) >> ACTION_POINTER_INDEX_SHIFT;
3284        switch (action & ACTION_MASK) {
3285            case ACTION_POINTER_DOWN:
3286                return "ACTION_POINTER_DOWN(" + index + ")";
3287            case ACTION_POINTER_UP:
3288                return "ACTION_POINTER_UP(" + index + ")";
3289            default:
3290                return Integer.toString(action);
3291        }
3292    }
3293
3294    /**
3295     * Returns a string that represents the symbolic name of the specified axis
3296     * such as "AXIS_X" or an equivalent numeric constant such as "42" if unknown.
3297     *
3298     * @param axis The axis.
3299     * @return The symbolic name of the specified axis.
3300     */
3301    public static String axisToString(int axis) {
3302        String symbolicName = nativeAxisToString(axis);
3303        return symbolicName != null ? LABEL_PREFIX + symbolicName : Integer.toString(axis);
3304    }
3305
3306    /**
3307     * Gets an axis by its symbolic name such as "AXIS_X" or an
3308     * equivalent numeric constant such as "42".
3309     *
3310     * @param symbolicName The symbolic name of the axis.
3311     * @return The axis or -1 if not found.
3312     * @see KeyEvent#keyCodeToString(int)
3313     */
3314    public static int axisFromString(String symbolicName) {
3315        if (symbolicName.startsWith(LABEL_PREFIX)) {
3316            symbolicName = symbolicName.substring(LABEL_PREFIX.length());
3317            int axis = nativeAxisFromString(symbolicName);
3318            if (axis >= 0) {
3319                return axis;
3320            }
3321        }
3322        try {
3323            return Integer.parseInt(symbolicName, 10);
3324        } catch (NumberFormatException ex) {
3325            return -1;
3326        }
3327    }
3328
3329    /**
3330     * Returns a string that represents the symbolic name of the specified combined
3331     * button state flags such as "0", "BUTTON_PRIMARY",
3332     * "BUTTON_PRIMARY|BUTTON_SECONDARY" or an equivalent numeric constant such as "0x10000000"
3333     * if unknown.
3334     *
3335     * @param buttonState The button state.
3336     * @return The symbolic name of the specified combined button state flags.
3337     * @hide
3338     */
3339    public static String buttonStateToString(int buttonState) {
3340        if (buttonState == 0) {
3341            return "0";
3342        }
3343        StringBuilder result = null;
3344        int i = 0;
3345        while (buttonState != 0) {
3346            final boolean isSet = (buttonState & 1) != 0;
3347            buttonState >>>= 1; // unsigned shift!
3348            if (isSet) {
3349                final String name = BUTTON_SYMBOLIC_NAMES[i];
3350                if (result == null) {
3351                    if (buttonState == 0) {
3352                        return name;
3353                    }
3354                    result = new StringBuilder(name);
3355                } else {
3356                    result.append('|');
3357                    result.append(name);
3358                }
3359            }
3360            i += 1;
3361        }
3362        return result.toString();
3363    }
3364
3365    /**
3366     * Returns a string that represents the symbolic name of the specified tool type
3367     * such as "TOOL_TYPE_FINGER" or an equivalent numeric constant such as "42" if unknown.
3368     *
3369     * @param toolType The tool type.
3370     * @return The symbolic name of the specified tool type.
3371     * @hide
3372     */
3373    public static String toolTypeToString(int toolType) {
3374        String symbolicName = TOOL_TYPE_SYMBOLIC_NAMES.get(toolType);
3375        return symbolicName != null ? symbolicName : Integer.toString(toolType);
3376    }
3377
3378    /**
3379     * Checks if a mouse or stylus button (or combination of buttons) is pressed.
3380     * @param button Button (or combination of buttons).
3381     * @return True if specified buttons are pressed.
3382     *
3383     * @see #BUTTON_PRIMARY
3384     * @see #BUTTON_SECONDARY
3385     * @see #BUTTON_TERTIARY
3386     * @see #BUTTON_FORWARD
3387     * @see #BUTTON_BACK
3388     * @see #BUTTON_STYLUS_PRIMARY
3389     * @see #BUTTON_STYLUS_SECONDARY
3390     */
3391    public final boolean isButtonPressed(int button) {
3392        if (button == 0) {
3393            return false;
3394        }
3395        return (getButtonState() & button) == button;
3396    }
3397
3398    public static final Parcelable.Creator<MotionEvent> CREATOR
3399            = new Parcelable.Creator<MotionEvent>() {
3400        public MotionEvent createFromParcel(Parcel in) {
3401            in.readInt(); // skip token, we already know this is a MotionEvent
3402            return MotionEvent.createFromParcelBody(in);
3403        }
3404
3405        public MotionEvent[] newArray(int size) {
3406            return new MotionEvent[size];
3407        }
3408    };
3409
3410    /** @hide */
3411    public static MotionEvent createFromParcelBody(Parcel in) {
3412        MotionEvent ev = obtain();
3413        ev.mNativePtr = nativeReadFromParcel(ev.mNativePtr, in);
3414        return ev;
3415    }
3416
3417    /** @hide */
3418    @Override
3419    public final void cancel() {
3420        setAction(ACTION_CANCEL);
3421    }
3422
3423    public void writeToParcel(Parcel out, int flags) {
3424        out.writeInt(PARCEL_TOKEN_MOTION_EVENT);
3425        nativeWriteToParcel(mNativePtr, out);
3426    }
3427
3428    /**
3429     * Transfer object for pointer coordinates.
3430     *
3431     * Objects of this type can be used to specify the pointer coordinates when
3432     * creating new {@link MotionEvent} objects and to query pointer coordinates
3433     * in bulk.
3434     *
3435     * Refer to {@link InputDevice} for information about how different kinds of
3436     * input devices and sources represent pointer coordinates.
3437     */
3438    public static final class PointerCoords {
3439        private static final int INITIAL_PACKED_AXIS_VALUES = 8;
3440        private long mPackedAxisBits;
3441        private float[] mPackedAxisValues;
3442
3443        /**
3444         * Creates a pointer coords object with all axes initialized to zero.
3445         */
3446        public PointerCoords() {
3447        }
3448
3449        /**
3450         * Creates a pointer coords object as a copy of the
3451         * contents of another pointer coords object.
3452         *
3453         * @param other The pointer coords object to copy.
3454         */
3455        public PointerCoords(PointerCoords other) {
3456            copyFrom(other);
3457        }
3458
3459        /** @hide */
3460        public static PointerCoords[] createArray(int size) {
3461            PointerCoords[] array = new PointerCoords[size];
3462            for (int i = 0; i < size; i++) {
3463                array[i] = new PointerCoords();
3464            }
3465            return array;
3466        }
3467
3468        /**
3469         * The X component of the pointer movement.
3470         *
3471         * @see MotionEvent#AXIS_X
3472         */
3473        public float x;
3474
3475        /**
3476         * The Y component of the pointer movement.
3477         *
3478         * @see MotionEvent#AXIS_Y
3479         */
3480        public float y;
3481
3482        /**
3483         * A normalized value that describes the pressure applied to the device
3484         * by a finger or other tool.
3485         * The pressure generally ranges from 0 (no pressure at all) to 1 (normal pressure),
3486         * although values higher than 1 may be generated depending on the calibration of
3487         * the input device.
3488         *
3489         * @see MotionEvent#AXIS_PRESSURE
3490         */
3491        public float pressure;
3492
3493        /**
3494         * A normalized value that describes the approximate size of the pointer touch area
3495         * in relation to the maximum detectable size of the device.
3496         * It represents some approximation of the area of the screen being
3497         * pressed; the actual value in pixels corresponding to the
3498         * touch is normalized with the device specific range of values
3499         * and scaled to a value between 0 and 1. The value of size can be used to
3500         * determine fat touch events.
3501         *
3502         * @see MotionEvent#AXIS_SIZE
3503         */
3504        public float size;
3505
3506        /**
3507         * The length of the major axis of an ellipse that describes the touch area at
3508         * the point of contact.
3509         * If the device is a touch screen, the length is reported in pixels, otherwise it is
3510         * reported in device-specific units.
3511         *
3512         * @see MotionEvent#AXIS_TOUCH_MAJOR
3513         */
3514        public float touchMajor;
3515
3516        /**
3517         * The length of the minor axis of an ellipse that describes the touch area at
3518         * the point of contact.
3519         * If the device is a touch screen, the length is reported in pixels, otherwise it is
3520         * reported in device-specific units.
3521         *
3522         * @see MotionEvent#AXIS_TOUCH_MINOR
3523         */
3524        public float touchMinor;
3525
3526        /**
3527         * The length of the major axis of an ellipse that describes the size of
3528         * the approaching tool.
3529         * The tool area represents the estimated size of the finger or pen that is
3530         * touching the device independent of its actual touch area at the point of contact.
3531         * If the device is a touch screen, the length is reported in pixels, otherwise it is
3532         * reported in device-specific units.
3533         *
3534         * @see MotionEvent#AXIS_TOOL_MAJOR
3535         */
3536        public float toolMajor;
3537
3538        /**
3539         * The length of the minor axis of an ellipse that describes the size of
3540         * the approaching tool.
3541         * The tool area represents the estimated size of the finger or pen that is
3542         * touching the device independent of its actual touch area at the point of contact.
3543         * If the device is a touch screen, the length is reported in pixels, otherwise it is
3544         * reported in device-specific units.
3545         *
3546         * @see MotionEvent#AXIS_TOOL_MINOR
3547         */
3548        public float toolMinor;
3549
3550        /**
3551         * The orientation of the touch area and tool area in radians clockwise from vertical.
3552         * An angle of 0 radians indicates that the major axis of contact is oriented
3553         * upwards, is perfectly circular or is of unknown orientation.  A positive angle
3554         * indicates that the major axis of contact is oriented to the right.  A negative angle
3555         * indicates that the major axis of contact is oriented to the left.
3556         * The full range is from -PI/2 radians (finger pointing fully left) to PI/2 radians
3557         * (finger pointing fully right).
3558         *
3559         * @see MotionEvent#AXIS_ORIENTATION
3560         */
3561        public float orientation;
3562
3563        /**
3564         * Clears the contents of this object.
3565         * Resets all axes to zero.
3566         */
3567        public void clear() {
3568            mPackedAxisBits = 0;
3569
3570            x = 0;
3571            y = 0;
3572            pressure = 0;
3573            size = 0;
3574            touchMajor = 0;
3575            touchMinor = 0;
3576            toolMajor = 0;
3577            toolMinor = 0;
3578            orientation = 0;
3579        }
3580
3581        /**
3582         * Copies the contents of another pointer coords object.
3583         *
3584         * @param other The pointer coords object to copy.
3585         */
3586        public void copyFrom(PointerCoords other) {
3587            final long bits = other.mPackedAxisBits;
3588            mPackedAxisBits = bits;
3589            if (bits != 0) {
3590                final float[] otherValues = other.mPackedAxisValues;
3591                final int count = Long.bitCount(bits);
3592                float[] values = mPackedAxisValues;
3593                if (values == null || count > values.length) {
3594                    values = new float[otherValues.length];
3595                    mPackedAxisValues = values;
3596                }
3597                System.arraycopy(otherValues, 0, values, 0, count);
3598            }
3599
3600            x = other.x;
3601            y = other.y;
3602            pressure = other.pressure;
3603            size = other.size;
3604            touchMajor = other.touchMajor;
3605            touchMinor = other.touchMinor;
3606            toolMajor = other.toolMajor;
3607            toolMinor = other.toolMinor;
3608            orientation = other.orientation;
3609        }
3610
3611        /**
3612         * Gets the value associated with the specified axis.
3613         *
3614         * @param axis The axis identifier for the axis value to retrieve.
3615         * @return The value associated with the axis, or 0 if none.
3616         *
3617         * @see MotionEvent#AXIS_X
3618         * @see MotionEvent#AXIS_Y
3619         */
3620        public float getAxisValue(int axis) {
3621            switch (axis) {
3622                case AXIS_X:
3623                    return x;
3624                case AXIS_Y:
3625                    return y;
3626                case AXIS_PRESSURE:
3627                    return pressure;
3628                case AXIS_SIZE:
3629                    return size;
3630                case AXIS_TOUCH_MAJOR:
3631                    return touchMajor;
3632                case AXIS_TOUCH_MINOR:
3633                    return touchMinor;
3634                case AXIS_TOOL_MAJOR:
3635                    return toolMajor;
3636                case AXIS_TOOL_MINOR:
3637                    return toolMinor;
3638                case AXIS_ORIENTATION:
3639                    return orientation;
3640                default: {
3641                    if (axis < 0 || axis > 63) {
3642                        throw new IllegalArgumentException("Axis out of range.");
3643                    }
3644                    final long bits = mPackedAxisBits;
3645                    final long axisBit = 0x8000000000000000L >>> axis;
3646                    if ((bits & axisBit) == 0) {
3647                        return 0;
3648                    }
3649                    final int index = Long.bitCount(bits & ~(0xFFFFFFFFFFFFFFFFL >>> axis));
3650                    return mPackedAxisValues[index];
3651                }
3652            }
3653        }
3654
3655        /**
3656         * Sets the value associated with the specified axis.
3657         *
3658         * @param axis The axis identifier for the axis value to assign.
3659         * @param value The value to set.
3660         *
3661         * @see MotionEvent#AXIS_X
3662         * @see MotionEvent#AXIS_Y
3663         */
3664        public void setAxisValue(int axis, float value) {
3665            switch (axis) {
3666                case AXIS_X:
3667                    x = value;
3668                    break;
3669                case AXIS_Y:
3670                    y = value;
3671                    break;
3672                case AXIS_PRESSURE:
3673                    pressure = value;
3674                    break;
3675                case AXIS_SIZE:
3676                    size = value;
3677                    break;
3678                case AXIS_TOUCH_MAJOR:
3679                    touchMajor = value;
3680                    break;
3681                case AXIS_TOUCH_MINOR:
3682                    touchMinor = value;
3683                    break;
3684                case AXIS_TOOL_MAJOR:
3685                    toolMajor = value;
3686                    break;
3687                case AXIS_TOOL_MINOR:
3688                    toolMinor = value;
3689                    break;
3690                case AXIS_ORIENTATION:
3691                    orientation = value;
3692                    break;
3693                default: {
3694                    if (axis < 0 || axis > 63) {
3695                        throw new IllegalArgumentException("Axis out of range.");
3696                    }
3697                    final long bits = mPackedAxisBits;
3698                    final long axisBit = 0x8000000000000000L >>> axis;
3699                    final int index = Long.bitCount(bits & ~(0xFFFFFFFFFFFFFFFFL >>> axis));
3700                    float[] values = mPackedAxisValues;
3701                    if ((bits & axisBit) == 0) {
3702                        if (values == null) {
3703                            values = new float[INITIAL_PACKED_AXIS_VALUES];
3704                            mPackedAxisValues = values;
3705                        } else {
3706                            final int count = Long.bitCount(bits);
3707                            if (count < values.length) {
3708                                if (index != count) {
3709                                    System.arraycopy(values, index, values, index + 1,
3710                                            count - index);
3711                                }
3712                            } else {
3713                                float[] newValues = new float[count * 2];
3714                                System.arraycopy(values, 0, newValues, 0, index);
3715                                System.arraycopy(values, index, newValues, index + 1,
3716                                        count - index);
3717                                values = newValues;
3718                                mPackedAxisValues = values;
3719                            }
3720                        }
3721                        mPackedAxisBits = bits | axisBit;
3722                    }
3723                    values[index] = value;
3724                }
3725            }
3726        }
3727    }
3728
3729    /**
3730     * Transfer object for pointer properties.
3731     *
3732     * Objects of this type can be used to specify the pointer id and tool type
3733     * when creating new {@link MotionEvent} objects and to query pointer properties in bulk.
3734     */
3735    public static final class PointerProperties {
3736        /**
3737         * Creates a pointer properties object with an invalid pointer id.
3738         */
3739        public PointerProperties() {
3740            clear();
3741        }
3742
3743        /**
3744         * Creates a pointer properties object as a copy of the contents of
3745         * another pointer properties object.
3746         * @param other
3747         */
3748        public PointerProperties(PointerProperties other) {
3749            copyFrom(other);
3750        }
3751
3752        /** @hide */
3753        public static PointerProperties[] createArray(int size) {
3754            PointerProperties[] array = new PointerProperties[size];
3755            for (int i = 0; i < size; i++) {
3756                array[i] = new PointerProperties();
3757            }
3758            return array;
3759        }
3760
3761        /**
3762         * The pointer id.
3763         * Initially set to {@link #INVALID_POINTER_ID} (-1).
3764         *
3765         * @see MotionEvent#getPointerId(int)
3766         */
3767        public int id;
3768
3769        /**
3770         * The pointer tool type.
3771         * Initially set to 0.
3772         *
3773         * @see MotionEvent#getToolType(int)
3774         */
3775        public int toolType;
3776
3777        /**
3778         * Resets the pointer properties to their initial values.
3779         */
3780        public void clear() {
3781            id = INVALID_POINTER_ID;
3782            toolType = TOOL_TYPE_UNKNOWN;
3783        }
3784
3785        /**
3786         * Copies the contents of another pointer properties object.
3787         *
3788         * @param other The pointer properties object to copy.
3789         */
3790        public void copyFrom(PointerProperties other) {
3791            id = other.id;
3792            toolType = other.toolType;
3793        }
3794
3795        @Override
3796        public boolean equals(Object other) {
3797            if (other instanceof PointerProperties) {
3798                return equals((PointerProperties)other);
3799            }
3800            return false;
3801        }
3802
3803        private boolean equals(PointerProperties other) {
3804            return other != null && id == other.id && toolType == other.toolType;
3805        }
3806
3807        @Override
3808        public int hashCode() {
3809            return id | (toolType << 8);
3810        }
3811    }
3812}
3813