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