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