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