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