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