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