Home | History | Annotate | Download | only in view
      1 /*
      2  * Copyright 2018 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 androidx.core.view;
     18 
     19 import android.view.MotionEvent;
     20 
     21 /**
     22  * Helper for accessing features in {@link MotionEvent}.
     23  */
     24 public final class MotionEventCompat {
     25     /**
     26      * Synonym for {@link MotionEvent#ACTION_MASK}.
     27      *
     28      * @deprecated Use {@link MotionEvent#ACTION_MASK} directly.
     29      */
     30     @Deprecated
     31     public static final int ACTION_MASK = 0xff;
     32 
     33     /**
     34      * Synonym for {@link MotionEvent#ACTION_POINTER_DOWN}.
     35      *
     36      * @deprecated Use {@link MotionEvent#ACTION_POINTER_DOWN} directly.
     37      */
     38     @Deprecated
     39     public static final int ACTION_POINTER_DOWN = 5;
     40 
     41     /**
     42      * Synonym for {@link MotionEvent#ACTION_POINTER_UP}.
     43      *
     44      * @deprecated Use {@link MotionEvent#ACTION_POINTER_UP} directly.
     45      */
     46     @Deprecated
     47     public static final int ACTION_POINTER_UP = 6;
     48 
     49     /**
     50      * Synonym for {@link MotionEvent#ACTION_HOVER_MOVE}.
     51      *
     52      * @deprecated Use {@link MotionEvent#ACTION_HOVER_MOVE} directly.
     53      */
     54     @Deprecated
     55     public static final int ACTION_HOVER_MOVE = 7;
     56 
     57     /**
     58      * Synonym for {@link MotionEvent#ACTION_SCROLL}.
     59      *
     60      * @deprecated Use {@link MotionEvent#ACTION_SCROLL} directly.
     61      */
     62     @Deprecated
     63     public static final int ACTION_SCROLL = 8;
     64 
     65     /**
     66      * Synonym for {@link MotionEvent#ACTION_POINTER_INDEX_MASK}.
     67      *
     68      * @deprecated Use {@link MotionEvent#ACTION_POINTER_INDEX_MASK} directly.
     69      */
     70     @Deprecated
     71     public static final int ACTION_POINTER_INDEX_MASK  = 0xff00;
     72 
     73     /**
     74      * Synonym for {@link MotionEvent#ACTION_POINTER_INDEX_SHIFT}.
     75      *
     76      * @deprecated Use {@link MotionEvent#ACTION_POINTER_INDEX_SHIFT} directly.
     77      */
     78     @Deprecated
     79     public static final int ACTION_POINTER_INDEX_SHIFT = 8;
     80 
     81     /**
     82      * Synonym for {@link MotionEvent#ACTION_HOVER_ENTER}.
     83      *
     84      * @deprecated Use {@link MotionEvent#ACTION_HOVER_ENTER} directly.
     85      */
     86     @Deprecated
     87     public static final int ACTION_HOVER_ENTER = 9;
     88 
     89     /**
     90      * Synonym for {@link MotionEvent#ACTION_HOVER_EXIT}.
     91      *
     92      * @deprecated Use {@link MotionEvent#ACTION_HOVER_EXIT} directly.
     93      */
     94     @Deprecated
     95     public static final int ACTION_HOVER_EXIT = 10;
     96 
     97     /**
     98      * Synonym for {@link MotionEvent#AXIS_X}.
     99      *
    100      * @deprecated Use {@link MotionEvent#AXIS_X} directly.
    101      */
    102     @Deprecated
    103     public static final int AXIS_X = 0;
    104 
    105     /**
    106      * Synonym for {@link MotionEvent#AXIS_Y}.
    107      *
    108      * @deprecated Use {@link MotionEvent#AXIS_Y} directly.
    109      */
    110     @Deprecated
    111     public static final int AXIS_Y = 1;
    112 
    113     /**
    114      * Synonym for {@link MotionEvent#AXIS_PRESSURE}.
    115      *
    116      * @deprecated Use {@link MotionEvent#AXIS_PRESSURE} directly.
    117      */
    118     @Deprecated
    119     public static final int AXIS_PRESSURE = 2;
    120 
    121     /**
    122      * Synonym for {@link MotionEvent#AXIS_SIZE}.
    123      *
    124      * @deprecated Use {@link MotionEvent#AXIS_SIZE} directly.
    125      */
    126     @Deprecated
    127     public static final int AXIS_SIZE = 3;
    128 
    129     /**
    130      * Synonym for {@link MotionEvent#AXIS_TOUCH_MAJOR}.
    131      *
    132      * @deprecated Use {@link MotionEvent#AXIS_TOUCH_MAJOR} directly.
    133      */
    134     @Deprecated
    135     public static final int AXIS_TOUCH_MAJOR = 4;
    136 
    137     /**
    138      * Synonym for {@link MotionEvent#AXIS_TOUCH_MINOR}.
    139      *
    140      * @deprecated Use {@link MotionEvent#AXIS_TOUCH_MINOR} directly.
    141      */
    142     @Deprecated
    143     public static final int AXIS_TOUCH_MINOR = 5;
    144 
    145     /**
    146      * Synonym for {@link MotionEvent#AXIS_TOOL_MAJOR}.
    147      *
    148      * @deprecated Use {@link MotionEvent#AXIS_TOOL_MAJOR} directly.
    149      */
    150     @Deprecated
    151     public static final int AXIS_TOOL_MAJOR = 6;
    152 
    153     /**
    154      * Synonym for {@link MotionEvent#AXIS_TOOL_MINOR}.
    155      *
    156      * @deprecated Use {@link MotionEvent#AXIS_TOOL_MINOR} directly.
    157      */
    158     @Deprecated
    159     public static final int AXIS_TOOL_MINOR = 7;
    160 
    161     /**
    162      * Synonym for {@link MotionEvent#AXIS_ORIENTATION}.
    163      *
    164      * @deprecated Use {@link MotionEvent#AXIS_ORIENTATION} directly.
    165      */
    166     @Deprecated
    167     public static final int AXIS_ORIENTATION = 8;
    168 
    169     /**
    170      * Synonym for {@link MotionEvent#AXIS_VSCROLL}.
    171      *
    172      * @deprecated Use {@link MotionEvent#AXIS_VSCROLL} directly.
    173      */
    174     @Deprecated
    175     public static final int AXIS_VSCROLL = 9;
    176 
    177     /**
    178      * Synonym for {@link MotionEvent#AXIS_HSCROLL}.
    179      *
    180      * @deprecated Use {@link MotionEvent#AXIS_HSCROLL} directly.
    181      */
    182     @Deprecated
    183     public static final int AXIS_HSCROLL = 10;
    184 
    185     /**
    186      * Synonym for {@link MotionEvent#AXIS_Z}.
    187      *
    188      * @deprecated Use {@link MotionEvent#AXIS_Z} directly.
    189      */
    190     @Deprecated
    191     public static final int AXIS_Z = 11;
    192 
    193     /**
    194      * Synonym for {@link MotionEvent#AXIS_RX}.
    195      *
    196      * @deprecated Use {@link MotionEvent#AXIS_RX} directly.
    197      */
    198     @Deprecated
    199     public static final int AXIS_RX = 12;
    200 
    201     /**
    202      * Synonym for {@link MotionEvent#AXIS_RY}.
    203      *
    204      * @deprecated Use {@link MotionEvent#AXIS_RY} directly.
    205      */
    206     @Deprecated
    207     public static final int AXIS_RY = 13;
    208 
    209     /**
    210      * Synonym for {@link MotionEvent#AXIS_RZ}.
    211      *
    212      * @deprecated Use {@link MotionEvent#AXIS_RZ} directly.
    213      */
    214     @Deprecated
    215     public static final int AXIS_RZ = 14;
    216 
    217     /**
    218      * Synonym for {@link MotionEvent#AXIS_HAT_X}.
    219      *
    220      * @deprecated Use {@link MotionEvent#AXIS_HAT_X} directly.
    221      */
    222     @Deprecated
    223     public static final int AXIS_HAT_X = 15;
    224 
    225     /**
    226      * Synonym for {@link MotionEvent#AXIS_HAT_Y}.
    227      *
    228      * @deprecated Use {@link MotionEvent#AXIS_HAT_Y} directly.
    229      */
    230     @Deprecated
    231     public static final int AXIS_HAT_Y = 16;
    232 
    233     /**
    234      * Synonym for {@link MotionEvent#AXIS_LTRIGGER}.
    235      *
    236      * @deprecated Use {@link MotionEvent#AXIS_LTRIGGER} directly.
    237      */
    238     @Deprecated
    239     public static final int AXIS_LTRIGGER = 17;
    240 
    241     /**
    242      * Synonym for {@link MotionEvent#AXIS_RTRIGGER}.
    243      *
    244      * @deprecated Use {@link MotionEvent#AXIS_RTRIGGER} directly.
    245      */
    246     @Deprecated
    247     public static final int AXIS_RTRIGGER = 18;
    248 
    249     /**
    250      * Synonym for {@link MotionEvent#AXIS_THROTTLE}.
    251      *
    252      * @deprecated Use {@link MotionEvent#AXIS_THROTTLE} directly.
    253      */
    254     @Deprecated
    255     public static final int AXIS_THROTTLE = 19;
    256 
    257     /**
    258      * Synonym for {@link MotionEvent#AXIS_RUDDER}.
    259      *
    260      * @deprecated Use {@link MotionEvent#AXIS_RUDDER} directly.
    261      */
    262     @Deprecated
    263     public static final int AXIS_RUDDER = 20;
    264 
    265     /**
    266      * Synonym for {@link MotionEvent#AXIS_WHEEL}.
    267      *
    268      * @deprecated Use {@link MotionEvent#AXIS_WHEEL} directly.
    269      */
    270     @Deprecated
    271     public static final int AXIS_WHEEL = 21;
    272 
    273     /**
    274      * Synonym for {@link MotionEvent#AXIS_GAS}.
    275      *
    276      * @deprecated Use {@link MotionEvent#AXIS_GAS} directly.
    277      */
    278     @Deprecated
    279     public static final int AXIS_GAS = 22;
    280 
    281     /**
    282      * Synonym for {@link MotionEvent#AXIS_BRAKE}.
    283      *
    284      * @deprecated Use {@link MotionEvent#AXIS_BRAKE} directly.
    285      */
    286     @Deprecated
    287     public static final int AXIS_BRAKE = 23;
    288 
    289     /**
    290      * Synonym for {@link MotionEvent#AXIS_DISTANCE}.
    291      *
    292      * @deprecated Use {@link MotionEvent#AXIS_DISTANCE} directly.
    293      */
    294     @Deprecated
    295     public static final int AXIS_DISTANCE = 24;
    296 
    297     /**
    298      * Synonym for {@link MotionEvent#AXIS_TILT}.
    299      *
    300      * @deprecated Use {@link MotionEvent#AXIS_TILT} directly.
    301      */
    302     @Deprecated
    303     public static final int AXIS_TILT = 25;
    304 
    305     /**
    306      * Synonym for {@link MotionEvent#AXIS_SCROLL}.
    307      */
    308     public static final int AXIS_SCROLL = 26;
    309 
    310     /**
    311      * Synonym for {@link MotionEvent#AXIS_RELATIVE_X}.
    312      */
    313     public static final int AXIS_RELATIVE_X = 27;
    314 
    315     /**
    316      * Synonym for {@link MotionEvent#AXIS_RELATIVE_Y}.
    317      */
    318     public static final int AXIS_RELATIVE_Y = 28;
    319 
    320     /**
    321      * Synonym for {@link MotionEvent#AXIS_GENERIC_1}.
    322      *
    323      * @deprecated Use {@link MotionEvent#AXIS_GENERIC_1} directly.
    324      */
    325     @Deprecated
    326     public static final int AXIS_GENERIC_1 = 32;
    327 
    328     /**
    329      * Synonym for {@link MotionEvent#AXIS_GENERIC_2}.
    330      *
    331      * @deprecated Use {@link MotionEvent#AXIS_GENERIC_2} directly.
    332      */
    333     @Deprecated
    334     public static final int AXIS_GENERIC_2 = 33;
    335 
    336     /**
    337      * Synonym for {@link MotionEvent#AXIS_GENERIC_3}.
    338      *
    339      * @deprecated Use {@link MotionEvent#AXIS_GENERIC_3} directly.
    340      */
    341     @Deprecated
    342     public static final int AXIS_GENERIC_3 = 34;
    343 
    344     /**
    345      * Synonym for {@link MotionEvent#AXIS_GENERIC_4}.
    346      *
    347      * @deprecated Use {@link MotionEvent#AXIS_GENERIC_4} directly.
    348      */
    349     @Deprecated
    350     public static final int AXIS_GENERIC_4 = 35;
    351 
    352     /**
    353      * Synonym for {@link MotionEvent#AXIS_GENERIC_5}.
    354      *
    355      * @deprecated Use {@link MotionEvent#AXIS_GENERIC_5} directly.
    356      */
    357     @Deprecated
    358     public static final int AXIS_GENERIC_5 = 36;
    359 
    360     /**
    361      * Synonym for {@link MotionEvent#AXIS_GENERIC_6}.
    362      *
    363      * @deprecated Use {@link MotionEvent#AXIS_GENERIC_6} directly.
    364      */
    365     @Deprecated
    366     public static final int AXIS_GENERIC_6 = 37;
    367 
    368     /**
    369      * Synonym for {@link MotionEvent#AXIS_GENERIC_7}.
    370      *
    371      * @deprecated Use {@link MotionEvent#AXIS_GENERIC_7} directly.
    372      */
    373     @Deprecated
    374     public static final int AXIS_GENERIC_7 = 38;
    375 
    376     /**
    377      * Synonym for {@link MotionEvent#AXIS_GENERIC_8}.
    378      *
    379      * @deprecated Use {@link MotionEvent#AXIS_GENERIC_8} directly.
    380      */
    381     @Deprecated
    382     public static final int AXIS_GENERIC_8 = 39;
    383 
    384     /**
    385      * Synonym for {@link MotionEvent#AXIS_GENERIC_9}.
    386      *
    387      * @deprecated Use {@link MotionEvent#AXIS_GENERIC_9} directly.
    388      */
    389     @Deprecated
    390     public static final int AXIS_GENERIC_9 = 40;
    391 
    392     /**
    393      * Synonym for {@link MotionEvent#AXIS_GENERIC_10}.
    394      *
    395      * @deprecated Use {@link MotionEvent#AXIS_GENERIC_10} directly.
    396      */
    397     @Deprecated
    398     public static final int AXIS_GENERIC_10 = 41;
    399 
    400     /**
    401      * Synonym for {@link MotionEvent#AXIS_GENERIC_11}.
    402      *
    403      * @deprecated Use {@link MotionEvent#AXIS_GENERIC_11} directly.
    404      */
    405     @Deprecated
    406     public static final int AXIS_GENERIC_11 = 42;
    407 
    408     /**
    409      * Synonym for {@link MotionEvent#AXIS_GENERIC_12}.
    410      *
    411      * @deprecated Use {@link MotionEvent#AXIS_GENERIC_12} directly.
    412      */
    413     @Deprecated
    414     public static final int AXIS_GENERIC_12 = 43;
    415 
    416     /**
    417      * Synonym for {@link MotionEvent#AXIS_GENERIC_13}.
    418      *
    419      * @deprecated Use {@link MotionEvent#AXIS_GENERIC_13} directly.
    420      */
    421     @Deprecated
    422     public static final int AXIS_GENERIC_13 = 44;
    423 
    424     /**
    425      * Synonym for {@link MotionEvent#AXIS_GENERIC_14}.
    426      *
    427      * @deprecated Use {@link MotionEvent#AXIS_GENERIC_14} directly.
    428      */
    429     @Deprecated
    430     public static final int AXIS_GENERIC_14 = 45;
    431 
    432     /**
    433      * Synonym for {@link MotionEvent#AXIS_GENERIC_15}.
    434      *
    435      * @deprecated Use {@link MotionEvent#AXIS_GENERIC_15} directly.
    436      */
    437     @Deprecated
    438     public static final int AXIS_GENERIC_15 = 46;
    439 
    440     /**
    441      * Synonym for {@link MotionEvent#AXIS_GENERIC_16}.
    442      *
    443      * @deprecated Use {@link MotionEvent#AXIS_GENERIC_16} directly.
    444      */
    445     @Deprecated
    446     public static final int AXIS_GENERIC_16 = 47;
    447 
    448     /**
    449      * Synonym for {@link MotionEvent#BUTTON_PRIMARY}.
    450      *
    451      * @deprecated Use {@link MotionEvent#BUTTON_PRIMARY} directly.
    452      */
    453     @Deprecated
    454     public static final int BUTTON_PRIMARY = 1;
    455 
    456     /**
    457      * Call {@link MotionEvent#getAction}, returning only the {@link #ACTION_MASK}
    458      * portion.
    459      *
    460      * @deprecated Call {@link MotionEvent#getAction()} directly. This method will be
    461      * removed in a future release.
    462      */
    463     @Deprecated
    464     public static int getActionMasked(MotionEvent event) {
    465         return event.getActionMasked();
    466     }
    467 
    468     /**
    469      * Call {@link MotionEvent#getAction}, returning only the pointer index
    470      * portion.
    471      *
    472      * @deprecated Call {@link MotionEvent#getActionIndex()} directly. This method will be
    473      * removed in a future release.
    474      */
    475     @Deprecated
    476     public static int getActionIndex(MotionEvent event) {
    477         return event.getActionIndex();
    478     }
    479 
    480     /**
    481      * Call {@link MotionEvent#findPointerIndex(int)}.
    482      *
    483      * @deprecated Call {@link MotionEvent#findPointerIndex(int)} directly. This method will be
    484      * removed in a future release.
    485      */
    486     @Deprecated
    487     public static int findPointerIndex(MotionEvent event, int pointerId) {
    488         return event.findPointerIndex(pointerId);
    489     }
    490 
    491     /**
    492      * Call {@link MotionEvent#getPointerId(int)}.
    493      *
    494      * @deprecated Call {@link MotionEvent#getPointerId(int)} directly. This method will be
    495      * removed in a future release.
    496      */
    497     @Deprecated
    498     public static int getPointerId(MotionEvent event, int pointerIndex) {
    499         return event.getPointerId(pointerIndex);
    500     }
    501 
    502     /**
    503      * Call {@link MotionEvent#getX(int)}.
    504      *
    505      * @deprecated Call {@link MotionEvent#getX()} directly. This method will be
    506      * removed in a future release.
    507      */
    508     @Deprecated
    509     public static float getX(MotionEvent event, int pointerIndex) {
    510         return event.getX(pointerIndex);
    511     }
    512 
    513     /**
    514      * Call {@link MotionEvent#getY(int)}.
    515      *
    516      * @deprecated Call {@link MotionEvent#getY()} directly. This method will be
    517      * removed in a future release.
    518      */
    519     @Deprecated
    520     public static float getY(MotionEvent event, int pointerIndex) {
    521         return event.getY(pointerIndex);
    522     }
    523 
    524     /**
    525      * The number of pointers of data contained in this event.  Always
    526      *
    527      * @deprecated Call {@link MotionEvent#getPointerCount()} directly. This method will be
    528      * removed in a future release.
    529      */
    530     @Deprecated
    531     public static int getPointerCount(MotionEvent event) {
    532         return event.getPointerCount();
    533     }
    534 
    535     /**
    536      * Gets the source of the event.
    537      *
    538      * @return The event source or {@link InputDeviceCompat#SOURCE_UNKNOWN} if unknown.
    539      * @deprecated Call {@link MotionEvent#getSource()} directly. This method will be
    540      * removed in a future release.
    541      */
    542     @Deprecated
    543     public static int getSource(MotionEvent event) {
    544         return event.getSource();
    545     }
    546 
    547     /**
    548      * Determines whether the event is from the given source.
    549      * @param source The input source to check against.
    550      * @return Whether the event is from the given source.
    551      */
    552     public static boolean isFromSource(MotionEvent event, int source) {
    553         return (event.getSource() & source) == source;
    554     }
    555 
    556     /**
    557      * Get axis value for the first pointer index (may be an
    558      * arbitrary pointer identifier).
    559      *
    560      * @param axis The axis identifier for the axis value to retrieve.
    561      *
    562      * @see #AXIS_X
    563      * @see #AXIS_Y
    564      *
    565      * @deprecated Call {@link MotionEvent#getAxisValue(int)} directly. This method will be
    566      * removed in a future release.
    567      */
    568     @Deprecated
    569     public static float getAxisValue(MotionEvent event, int axis) {
    570         return event.getAxisValue(axis);
    571     }
    572 
    573     /**
    574      * Returns the value of the requested axis for the given pointer <em>index</em>
    575      * (use {@link #getPointerId(MotionEvent, int)} to find the pointer identifier for this index).
    576      *
    577      * @param axis The axis identifier for the axis value to retrieve.
    578      * @param pointerIndex Raw index of pointer to retrieve.  Value may be from 0
    579      * (the first pointer that is down) to {@link #getPointerCount(MotionEvent)}-1.
    580      * @return The value of the axis, or 0 if the axis is not available.
    581      *
    582      * @see #AXIS_X
    583      * @see #AXIS_Y
    584      *
    585      * @deprecated Call {@link MotionEvent#getAxisValue(int, int)} directly. This method will be
    586      * removed in a future release.
    587      */
    588     @Deprecated
    589     public static float getAxisValue(MotionEvent event, int axis, int pointerIndex) {
    590         return event.getAxisValue(axis, pointerIndex);
    591     }
    592 
    593     /**
    594      * @deprecated Call {@link MotionEvent#getButtonState()} directly. This method will be
    595      * removed in a future release.
    596      */
    597     @Deprecated
    598     public static int getButtonState(MotionEvent event) {
    599         return event.getButtonState();
    600     }
    601 
    602     private MotionEventCompat() {}
    603 }
    604