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