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