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