blob: d173ec5733303580496aa400df1b5a14e15fecea [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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
Kirill Grouchnikovc0b0ba52016-09-13 16:09:37 -070019import android.annotation.TestApi;
Mathew Inwoode5ad5982018-08-17 15:07:52 +010020import android.annotation.UnsupportedAppUsage;
Jeff Brown20e987b2010-08-23 12:01:02 -070021import android.graphics.Matrix;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080022import android.os.Parcel;
23import android.os.Parcelable;
24import android.os.SystemClock;
Jeff Brown6f2fba42011-02-19 01:08:02 -080025import android.util.SparseArray;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026
John Reck09709972016-10-03 15:47:18 -070027import dalvik.annotation.optimization.CriticalNative;
28import dalvik.annotation.optimization.FastNative;
29
Eugene Suslae6e55b52018-01-11 15:12:56 -080030import java.util.Objects;
31
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032/**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -070033 * Object used to report movement (mouse, pen, finger, trackball) events.
34 * Motion events may hold either absolute or relative movements and other data,
35 * depending on the type of device.
36 *
37 * <h3>Overview</h3>
Jeff Browndc1ab4b2010-09-14 18:03:38 -070038 * <p>
Jeff Brownfe9f8ab2011-05-06 18:20:01 -070039 * Motion events describe movements in terms of an action code and a set of axis values.
40 * The action code specifies the state change that occurred such as a pointer going
41 * down or up. The axis values describe the position and other movement properties.
42 * </p><p>
43 * For example, when the user first touches the screen, the system delivers a touch
44 * event to the appropriate {@link View} with the action code {@link #ACTION_DOWN}
45 * and a set of axis values that include the X and Y coordinates of the touch and
46 * information about the pressure, size and orientation of the contact area.
47 * </p><p>
48 * Some devices can report multiple movement traces at the same time. Multi-touch
49 * screens emit one movement trace for each finger. The individual fingers or
50 * other objects that generate movement traces are referred to as <em>pointers</em>.
51 * Motion events contain information about all of the pointers that are currently active
52 * even if some of them have not moved since the last event was delivered.
53 * </p><p>
54 * The number of pointers only ever changes by one as individual pointers go up and down,
55 * except when the gesture is canceled.
56 * </p><p>
57 * Each pointer has a unique id that is assigned when it first goes down
58 * (indicated by {@link #ACTION_DOWN} or {@link #ACTION_POINTER_DOWN}). A pointer id
59 * remains valid until the pointer eventually goes up (indicated by {@link #ACTION_UP}
60 * or {@link #ACTION_POINTER_UP}) or when the gesture is canceled (indicated by
61 * {@link #ACTION_CANCEL}).
62 * </p><p>
63 * The MotionEvent class provides many methods to query the position and other properties of
64 * pointers, such as {@link #getX(int)}, {@link #getY(int)}, {@link #getAxisValue},
65 * {@link #getPointerId(int)}, {@link #getToolType(int)}, and many others. Most of these
66 * methods accept the pointer index as a parameter rather than the pointer id.
67 * The pointer index of each pointer in the event ranges from 0 to one less than the value
68 * returned by {@link #getPointerCount()}.
69 * </p><p>
70 * The order in which individual pointers appear within a motion event is undefined.
71 * Thus the pointer index of a pointer can change from one event to the next but
72 * the pointer id of a pointer is guaranteed to remain constant as long as the pointer
73 * remains active. Use the {@link #getPointerId(int)} method to obtain the
74 * pointer id of a pointer to track it across all subsequent motion events in a gesture.
75 * Then for successive motion events, use the {@link #findPointerIndex(int)} method
76 * to obtain the pointer index for a given pointer id in that motion event.
77 * </p><p>
78 * Mouse and stylus buttons can be retrieved using {@link #getButtonState()}. It is a
79 * good idea to check the button state while handling {@link #ACTION_DOWN} as part
80 * of a touch event. The application may choose to perform some different action
81 * if the touch event starts due to a secondary button click, such as presenting a
82 * context menu.
83 * </p>
84 *
85 * <h3>Batching</h3>
86 * <p>
87 * For efficiency, motion events with {@link #ACTION_MOVE} may batch together
88 * multiple movement samples within a single object. The most current
89 * pointer coordinates are available using {@link #getX(int)} and {@link #getY(int)}.
90 * Earlier coordinates within the batch are accessed using {@link #getHistoricalX(int, int)}
91 * and {@link #getHistoricalY(int, int)}. The coordinates are "historical" only
92 * insofar as they are older than the current coordinates in the batch; however,
93 * they are still distinct from any other coordinates reported in prior motion events.
94 * To process all coordinates in the batch in time order, first consume the historical
95 * coordinates then consume the current coordinates.
96 * </p><p>
97 * Example: Consuming all samples for all pointers in a motion event in time order.
98 * </p><p><pre><code>
99 * void printSamples(MotionEvent ev) {
100 * final int historySize = ev.getHistorySize();
101 * final int pointerCount = ev.getPointerCount();
102 * for (int h = 0; h &lt; historySize; h++) {
103 * System.out.printf("At time %d:", ev.getHistoricalEventTime(h));
104 * for (int p = 0; p &lt; pointerCount; p++) {
105 * System.out.printf(" pointer %d: (%f,%f)",
106 * ev.getPointerId(p), ev.getHistoricalX(p, h), ev.getHistoricalY(p, h));
107 * }
108 * }
109 * System.out.printf("At time %d:", ev.getEventTime());
110 * for (int p = 0; p &lt; pointerCount; p++) {
111 * System.out.printf(" pointer %d: (%f,%f)",
112 * ev.getPointerId(p), ev.getX(p), ev.getY(p));
113 * }
114 * }
115 * </code></pre></p>
116 *
117 * <h3>Device Types</h3>
118 * <p>
119 * The interpretation of the contents of a MotionEvent varies significantly depending
120 * on the source class of the device.
121 * </p><p>
Jeff Browncb1404e2011-01-15 18:14:15 -0800122 * On pointing devices with source class {@link InputDevice#SOURCE_CLASS_POINTER}
123 * such as touch screens, the pointer coordinates specify absolute
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700124 * positions such as view X/Y coordinates. Each complete gesture is represented
125 * by a sequence of motion events with actions that describe pointer state transitions
126 * and movements. A gesture starts with a motion event with {@link #ACTION_DOWN}
127 * that provides the location of the first pointer down. As each additional
128 * pointer that goes down or up, the framework will generate a motion event with
129 * {@link #ACTION_POINTER_DOWN} or {@link #ACTION_POINTER_UP} accordingly.
130 * Pointer movements are described by motion events with {@link #ACTION_MOVE}.
131 * Finally, a gesture end either when the final pointer goes up as represented
132 * by a motion event with {@link #ACTION_UP} or when gesture is canceled
133 * with {@link #ACTION_CANCEL}.
134 * </p><p>
Jeff Brown33bbfd22011-02-24 20:55:35 -0800135 * Some pointing devices such as mice may support vertical and/or horizontal scrolling.
136 * A scroll event is reported as a generic motion event with {@link #ACTION_SCROLL} that
137 * includes the relative scroll offset in the {@link #AXIS_VSCROLL} and
138 * {@link #AXIS_HSCROLL} axes. See {@link #getAxisValue(int)} for information
139 * about retrieving these additional axes.
140 * </p><p>
Jeff Browncb1404e2011-01-15 18:14:15 -0800141 * On trackball devices with source class {@link InputDevice#SOURCE_CLASS_TRACKBALL},
142 * the pointer coordinates specify relative movements as X/Y deltas.
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700143 * A trackball gesture consists of a sequence of movements described by motion
144 * events with {@link #ACTION_MOVE} interspersed with occasional {@link #ACTION_DOWN}
145 * or {@link #ACTION_UP} motion events when the trackball button is pressed or released.
146 * </p><p>
Jeff Browncb1404e2011-01-15 18:14:15 -0800147 * On joystick devices with source class {@link InputDevice#SOURCE_CLASS_JOYSTICK},
148 * the pointer coordinates specify the absolute position of the joystick axes.
149 * The joystick axis values are normalized to a range of -1.0 to 1.0 where 0.0 corresponds
150 * to the center position. More information about the set of available axes and the
151 * range of motion can be obtained using {@link InputDevice#getMotionRange}.
Jeff Brown33bbfd22011-02-24 20:55:35 -0800152 * Some common joystick axes are {@link #AXIS_X}, {@link #AXIS_Y},
153 * {@link #AXIS_HAT_X}, {@link #AXIS_HAT_Y}, {@link #AXIS_Z} and {@link #AXIS_RZ}.
Jeff Browncb1404e2011-01-15 18:14:15 -0800154 * </p><p>
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700155 * Refer to {@link InputDevice} for more information about how different kinds of
Jeff Brownc5ed5912010-07-14 18:48:53 -0700156 * input devices and sources represent pointer coordinates.
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700157 * </p>
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700158 *
159 * <h3>Consistency Guarantees</h3>
160 * <p>
161 * Motion events are always delivered to views as a consistent stream of events.
162 * What constitutes a consistent stream varies depending on the type of device.
163 * For touch events, consistency implies that pointers go down one at a time,
164 * move around as a group and then go up one at a time or are canceled.
165 * </p><p>
166 * While the framework tries to deliver consistent streams of motion events to
167 * views, it cannot guarantee it. Some events may be dropped or modified by
168 * containing views in the application before they are delivered thereby making
169 * the stream of events inconsistent. Views should always be prepared to
170 * handle {@link #ACTION_CANCEL} and should tolerate anomalous
171 * situations such as receiving a new {@link #ACTION_DOWN} without first having
172 * received an {@link #ACTION_UP} for the prior gesture.
173 * </p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800174 */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700175public final class MotionEvent extends InputEvent implements Parcelable {
Jeff Brown91c69ab2011-02-14 17:03:18 -0800176 private static final long NS_PER_MS = 1000000;
Michael Wright337d9d22014-04-22 15:03:48 -0700177 private static final String LABEL_PREFIX = "AXIS_";
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700178
Eugene Suslae6e55b52018-01-11 15:12:56 -0800179 private static final boolean DEBUG_CONCISE_TOSTRING = false;
180
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700181 /**
182 * An invalid pointer id.
183 *
184 * This value (-1) can be used as a placeholder to indicate that a pointer id
185 * has not been assigned or is not available. It cannot appear as
186 * a pointer id inside a {@link MotionEvent}.
187 */
188 public static final int INVALID_POINTER_ID = -1;
189
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800190 /**
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700191 * Bit mask of the parts of the action code that are the action itself.
192 */
193 public static final int ACTION_MASK = 0xff;
Dennis Kempinac1b31d2016-11-02 17:02:25 -0700194
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700195 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700196 * Constant for {@link #getActionMasked}: A pressed gesture has started, the
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800197 * motion contains the initial starting location.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700198 * <p>
199 * This is also a good time to check the button state to distinguish
200 * secondary and tertiary button clicks and handle them appropriately.
201 * Use {@link #getButtonState} to retrieve the button state.
202 * </p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800203 */
204 public static final int ACTION_DOWN = 0;
Dennis Kempinac1b31d2016-11-02 17:02:25 -0700205
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800206 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700207 * Constant for {@link #getActionMasked}: A pressed gesture has finished, the
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800208 * motion contains the final release location as well as any intermediate
209 * points since the last down or move event.
210 */
211 public static final int ACTION_UP = 1;
Dennis Kempinac1b31d2016-11-02 17:02:25 -0700212
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800213 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700214 * Constant for {@link #getActionMasked}: A change has happened during a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800215 * press gesture (between {@link #ACTION_DOWN} and {@link #ACTION_UP}).
216 * The motion contains the most recent point, as well as any intermediate
217 * points since the last down or move event.
218 */
219 public static final int ACTION_MOVE = 2;
Dennis Kempinac1b31d2016-11-02 17:02:25 -0700220
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800221 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700222 * Constant for {@link #getActionMasked}: The current gesture has been aborted.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800223 * You will not receive any more points in it. You should treat this as
224 * an up event, but not perform any action that you normally would.
225 */
226 public static final int ACTION_CANCEL = 3;
Dennis Kempinac1b31d2016-11-02 17:02:25 -0700227
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800228 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700229 * Constant for {@link #getActionMasked}: A movement has happened outside of the
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800230 * normal bounds of the UI element. This does not provide a full gesture,
231 * but only the initial location of the movement/touch.
Siarhei Vishniakou6ad0e392017-06-02 17:20:34 -0700232 * <p>
233 * Note: Because the location of any event will be outside the
234 * bounds of the view hierarchy, it will not get dispatched to
235 * any children of a ViewGroup by default. Therefore,
236 * movements with ACTION_OUTSIDE should be handled in either the
237 * root {@link View} or in the appropriate {@link Window.Callback}
238 * (e.g. {@link android.app.Activity} or {@link android.app.Dialog}).
239 * </p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800240 */
241 public static final int ACTION_OUTSIDE = 4;
242
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700243 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700244 * Constant for {@link #getActionMasked}: A non-primary pointer has gone down.
245 * <p>
246 * Use {@link #getActionIndex} to retrieve the index of the pointer that changed.
247 * </p><p>
248 * The index is encoded in the {@link #ACTION_POINTER_INDEX_MASK} bits of the
249 * unmasked action returned by {@link #getAction}.
250 * </p>
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700251 */
252 public static final int ACTION_POINTER_DOWN = 5;
Dennis Kempinac1b31d2016-11-02 17:02:25 -0700253
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700254 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700255 * Constant for {@link #getActionMasked}: A non-primary pointer has gone up.
256 * <p>
257 * Use {@link #getActionIndex} to retrieve the index of the pointer that changed.
258 * </p><p>
259 * The index is encoded in the {@link #ACTION_POINTER_INDEX_MASK} bits of the
260 * unmasked action returned by {@link #getAction}.
261 * </p>
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700262 */
263 public static final int ACTION_POINTER_UP = 6;
Jeff Browncc0c1592011-02-19 05:07:28 -0800264
265 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700266 * Constant for {@link #getActionMasked}: A change happened but the pointer
Jeff Browncc0c1592011-02-19 05:07:28 -0800267 * is not down (unlike {@link #ACTION_MOVE}). The motion contains the most
268 * recent point, as well as any intermediate points since the last
269 * hover move event.
Jeff Brown33bbfd22011-02-24 20:55:35 -0800270 * <p>
Jeff Browna032cc02011-03-07 16:56:21 -0800271 * This action is always delivered to the window or view under the pointer.
272 * </p><p>
Jeff Brown33bbfd22011-02-24 20:55:35 -0800273 * This action is not a touch event so it is delivered to
274 * {@link View#onGenericMotionEvent(MotionEvent)} rather than
275 * {@link View#onTouchEvent(MotionEvent)}.
276 * </p>
Jeff Browncc0c1592011-02-19 05:07:28 -0800277 */
278 public static final int ACTION_HOVER_MOVE = 7;
279
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700280 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700281 * Constant for {@link #getActionMasked}: The motion event contains relative
Jeff Brown33bbfd22011-02-24 20:55:35 -0800282 * vertical and/or horizontal scroll offsets. Use {@link #getAxisValue(int)}
283 * to retrieve the information from {@link #AXIS_VSCROLL} and {@link #AXIS_HSCROLL}.
284 * The pointer may or may not be down when this event is dispatched.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700285 * <p>
Jeff Browna032cc02011-03-07 16:56:21 -0800286 * This action is always delivered to the window or view under the pointer, which
287 * may not be the window or view currently touched.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700288 * </p><p>
Jeff Brown33bbfd22011-02-24 20:55:35 -0800289 * 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_SCROLL = 8;
295
296 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700297 * Constant for {@link #getActionMasked}: The pointer is not down but has entered the
Jeff Browna032cc02011-03-07 16:56:21 -0800298 * boundaries of a window or view.
299 * <p>
300 * This action is always delivered to the window or view 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_ENTER = 9;
308
309 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700310 * Constant for {@link #getActionMasked}: The pointer is not down but has exited the
Jeff Browna032cc02011-03-07 16:56:21 -0800311 * boundaries of a window or view.
312 * <p>
313 * This action is always delivered to the window or view that was previously under the pointer.
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_HOVER_EXIT = 10;
321
322 /**
Michael Wright5bd69e62015-05-14 14:48:08 +0100323 * Constant for {@link #getActionMasked}: A button has been pressed.
324 *
325 * <p>
326 * Use {@link #getActionButton()} to get which button was pressed.
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_PRESS = 11;
334
335 /**
336 * Constant for {@link #getActionMasked}: A button has been released.
337 *
338 * <p>
339 * Use {@link #getActionButton()} to get which button was released.
340 * </p><p>
341 * This action is not a touch event so it is delivered to
342 * {@link View#onGenericMotionEvent(MotionEvent)} rather than
343 * {@link View#onTouchEvent(MotionEvent)}.
344 * </p>
345 */
346 public static final int ACTION_BUTTON_RELEASE = 12;
347
348 /**
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800349 * Bits in the action code that represent a pointer index, used with
350 * {@link #ACTION_POINTER_DOWN} and {@link #ACTION_POINTER_UP}. Shifting
351 * down by {@link #ACTION_POINTER_INDEX_SHIFT} provides the actual pointer
352 * index where the data for the pointer going up or down can be found; you can
353 * get its identifier with {@link #getPointerId(int)} and the actual
354 * data with {@link #getX(int)} etc.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700355 *
356 * @see #getActionIndex
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700357 */
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800358 public static final int ACTION_POINTER_INDEX_MASK = 0xff00;
Dennis Kempinac1b31d2016-11-02 17:02:25 -0700359
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800360 /**
361 * Bit shift for the action bits holding the pointer index as
362 * defined by {@link #ACTION_POINTER_INDEX_MASK}.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700363 *
364 * @see #getActionIndex
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800365 */
366 public static final int ACTION_POINTER_INDEX_SHIFT = 8;
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700367
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800368 /**
369 * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the
370 * data index associated with {@link #ACTION_POINTER_DOWN}.
371 */
372 @Deprecated
373 public static final int ACTION_POINTER_1_DOWN = ACTION_POINTER_DOWN | 0x0000;
Dennis Kempinac1b31d2016-11-02 17:02:25 -0700374
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800375 /**
376 * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the
377 * data index associated with {@link #ACTION_POINTER_DOWN}.
378 */
379 @Deprecated
380 public static final int ACTION_POINTER_2_DOWN = ACTION_POINTER_DOWN | 0x0100;
Dennis Kempinac1b31d2016-11-02 17:02:25 -0700381
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800382 /**
383 * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the
384 * data index associated with {@link #ACTION_POINTER_DOWN}.
385 */
386 @Deprecated
387 public static final int ACTION_POINTER_3_DOWN = ACTION_POINTER_DOWN | 0x0200;
Dennis Kempinac1b31d2016-11-02 17:02:25 -0700388
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800389 /**
390 * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the
391 * data index associated with {@link #ACTION_POINTER_UP}.
392 */
393 @Deprecated
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700394 public static final int ACTION_POINTER_1_UP = ACTION_POINTER_UP | 0x0000;
Dennis Kempinac1b31d2016-11-02 17:02:25 -0700395
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700396 /**
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800397 * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the
398 * data index associated with {@link #ACTION_POINTER_UP}.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700399 */
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800400 @Deprecated
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700401 public static final int ACTION_POINTER_2_UP = ACTION_POINTER_UP | 0x0100;
Dennis Kempinac1b31d2016-11-02 17:02:25 -0700402
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700403 /**
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800404 * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the
405 * data index associated with {@link #ACTION_POINTER_UP}.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700406 */
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800407 @Deprecated
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700408 public static final int ACTION_POINTER_3_UP = ACTION_POINTER_UP | 0x0200;
Dennis Kempinac1b31d2016-11-02 17:02:25 -0700409
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700410 /**
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800411 * @deprecated Renamed to {@link #ACTION_POINTER_INDEX_MASK} to match
412 * the actual data contained in these bits.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700413 */
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800414 @Deprecated
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700415 public static final int ACTION_POINTER_ID_MASK = 0xff00;
Dennis Kempinac1b31d2016-11-02 17:02:25 -0700416
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700417 /**
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800418 * @deprecated Renamed to {@link #ACTION_POINTER_INDEX_SHIFT} to match
419 * the actual data contained in these bits.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700420 */
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800421 @Deprecated
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700422 public static final int ACTION_POINTER_ID_SHIFT = 8;
Dennis Kempinac1b31d2016-11-02 17:02:25 -0700423
Jeff Brown85a31762010-09-01 17:01:00 -0700424 /**
425 * This flag indicates that the window that received this motion event is partly
426 * or wholly obscured by another visible window above it. This flag is set to true
427 * even if the event did not directly pass through the obscured area.
428 * A security sensitive application can check this flag to identify situations in which
429 * a malicious application may have covered up part of its content for the purpose
430 * of misleading the user or hijacking touches. An appropriate response might be
431 * to drop the suspect touches or to take additional precautions to confirm the user's
432 * actual intent.
433 */
434 public static final int FLAG_WINDOW_IS_OBSCURED = 0x1;
Romain Guycafdea62009-06-12 10:51:36 -0700435
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800436 /**
Michael Wright0625e112016-03-30 17:31:48 -0700437 * This flag indicates that the window that received this motion event is partly
438 * or wholly obscured by another visible window above it. This flag is set to true
439 * even if the event did not directly pass through the obscured area.
440 * A security sensitive application can check this flag to identify situations in which
441 * a malicious application may have covered up part of its content for the purpose
442 * of misleading the user or hijacking touches. An appropriate response might be
443 * to drop the suspect touches or to take additional precautions to confirm the user's
444 * actual intent.
445 *
446 * Unlike FLAG_WINDOW_IS_OBSCURED, this is actually true.
447 * @hide
448 */
449 public static final int FLAG_WINDOW_IS_PARTIALLY_OBSCURED = 0x2;
450
451 /**
Vladislav Kaznacheev5a77c372016-10-10 16:11:15 -0700452 * This private flag is only set on {@link #ACTION_HOVER_MOVE} events and indicates that
453 * this event will be immediately followed by a {@link #ACTION_HOVER_EXIT}. It is used to
454 * prevent generating redundant {@link #ACTION_HOVER_ENTER} events.
455 * @hide
456 */
457 public static final int FLAG_HOVER_EXIT_PENDING = 0x4;
458
459 /**
Dennis Kempinac1b31d2016-11-02 17:02:25 -0700460 * This flag indicates that the event has been generated by a gesture generator. It
461 * provides a hint to the GestureDector to not apply any touch slop.
462 *
463 * @hide
464 */
465 public static final int FLAG_IS_GENERATED_GESTURE = 0x8;
466
467 /**
Jeff Brown21bc5c92011-02-28 18:27:14 -0800468 * Private flag that indicates when the system has detected that this motion event
469 * may be inconsistent with respect to the sequence of previously delivered motion events,
470 * such as when a pointer move event is sent but the pointer is not down.
471 *
472 * @hide
473 * @see #isTainted
474 * @see #setTainted
475 */
476 public static final int FLAG_TAINTED = 0x80000000;
477
478 /**
Svetoslavded133c2015-01-30 20:28:41 -0800479 * Private flag indicating that this event was synthesized by the system and
480 * should be delivered to the accessibility focused view first. When being
481 * dispatched such an event is not handled by predecessors of the accessibility
482 * focused view and after the event reaches that view the flag is cleared and
483 * normal event dispatch is performed. This ensures that the platform can click
484 * on any view that has accessibility focus which is semantically equivalent to
485 * asking the view to perform a click accessibility action but more generic as
486 * views not implementing click action correctly can still be activated.
487 *
488 * @hide
489 * @see #isTargetAccessibilityFocus()
490 * @see #setTargetAccessibilityFocus(boolean)
491 */
492 public static final int FLAG_TARGET_ACCESSIBILITY_FOCUS = 0x40000000;
493
494
495 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800496 * Flag indicating the motion event intersected the top edge of the screen.
497 */
498 public static final int EDGE_TOP = 0x00000001;
Romain Guycafdea62009-06-12 10:51:36 -0700499
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800500 /**
501 * Flag indicating the motion event intersected the bottom edge of the screen.
502 */
503 public static final int EDGE_BOTTOM = 0x00000002;
Romain Guycafdea62009-06-12 10:51:36 -0700504
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800505 /**
506 * Flag indicating the motion event intersected the left edge of the screen.
507 */
508 public static final int EDGE_LEFT = 0x00000004;
Romain Guycafdea62009-06-12 10:51:36 -0700509
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800510 /**
511 * Flag indicating the motion event intersected the right edge of the screen.
512 */
513 public static final int EDGE_RIGHT = 0x00000008;
Romain Guycafdea62009-06-12 10:51:36 -0700514
Jeff Brown91c69ab2011-02-14 17:03:18 -0800515 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700516 * Axis constant: X axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800517 * <p>
518 * <ul>
519 * <li>For a touch screen, reports the absolute X screen position of the center of
520 * the touch contact area. The units are display pixels.
521 * <li>For a touch pad, reports the absolute X surface position of the center of the touch
Jeff Browncc0c1592011-02-19 05:07:28 -0800522 * contact area. The units are device-dependent; use {@link InputDevice#getMotionRange(int)}
523 * to query the effective range of values.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800524 * <li>For a mouse, reports the absolute X screen position of the mouse pointer.
525 * The units are display pixels.
526 * <li>For a trackball, reports the relative horizontal displacement of the trackball.
527 * The value is normalized to a range from -1.0 (left) to 1.0 (right).
528 * <li>For a joystick, reports the absolute X position of the joystick.
529 * The value is normalized to a range from -1.0 (left) to 1.0 (right).
530 * </ul>
531 * </p>
Jeff Brown91c69ab2011-02-14 17:03:18 -0800532 *
533 * @see #getX(int)
534 * @see #getHistoricalX(int, int)
535 * @see MotionEvent.PointerCoords#x
536 * @see InputDevice#getMotionRange
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700537 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800538 public static final int AXIS_X = 0;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700539
Jeff Brown91c69ab2011-02-14 17:03:18 -0800540 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700541 * Axis constant: Y axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800542 * <p>
543 * <ul>
544 * <li>For a touch screen, reports the absolute Y screen position of the center of
545 * the touch contact area. The units are display pixels.
546 * <li>For a touch pad, reports the absolute Y surface position of the center of the touch
547 * contact area. The units are device-dependent; use {@link InputDevice#getMotionRange(int)}
548 * to query the effective range of values.
549 * <li>For a mouse, reports the absolute Y screen position of the mouse pointer.
550 * The units are display pixels.
551 * <li>For a trackball, reports the relative vertical displacement of the trackball.
552 * The value is normalized to a range from -1.0 (up) to 1.0 (down).
553 * <li>For a joystick, reports the absolute Y position of the joystick.
554 * The value is normalized to a range from -1.0 (up or far) to 1.0 (down or near).
555 * </ul>
556 * </p>
Jeff Brown91c69ab2011-02-14 17:03:18 -0800557 *
558 * @see #getY(int)
559 * @see #getHistoricalY(int, int)
560 * @see MotionEvent.PointerCoords#y
561 * @see InputDevice#getMotionRange
Jeff Brownc5ed5912010-07-14 18:48:53 -0700562 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800563 public static final int AXIS_Y = 1;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700564
Jeff Brown91c69ab2011-02-14 17:03:18 -0800565 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700566 * Axis constant: Pressure axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800567 * <p>
568 * <ul>
Jeff Browncc0c1592011-02-19 05:07:28 -0800569 * <li>For a touch screen or touch pad, reports the approximate pressure applied to the surface
Jeff Brown6f2fba42011-02-19 01:08:02 -0800570 * by a finger or other tool. The value is normalized to a range from
571 * 0 (no pressure at all) to 1 (normal pressure), although values higher than 1
572 * may be generated depending on the calibration of the input device.
573 * <li>For a trackball, the value is set to 1 if the trackball button is pressed
574 * or 0 otherwise.
575 * <li>For a mouse, the value is set to 1 if the primary mouse button is pressed
576 * or 0 otherwise.
577 * </ul>
578 * </p>
Jeff Brown91c69ab2011-02-14 17:03:18 -0800579 *
580 * @see #getPressure(int)
581 * @see #getHistoricalPressure(int, int)
582 * @see MotionEvent.PointerCoords#pressure
583 * @see InputDevice#getMotionRange
Jeff Brownc5ed5912010-07-14 18:48:53 -0700584 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800585 public static final int AXIS_PRESSURE = 2;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700586
Jeff Brown91c69ab2011-02-14 17:03:18 -0800587 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700588 * Axis constant: Size axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800589 * <p>
590 * <ul>
591 * <li>For a touch screen or touch pad, reports the approximate size of the contact area in
592 * relation to the maximum detectable size for the device. The value is normalized
593 * to a range from 0 (smallest detectable size) to 1 (largest detectable size),
Jeff Browncc0c1592011-02-19 05:07:28 -0800594 * although it is not a linear scale. This value is of limited use.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800595 * To obtain calibrated size information, use
596 * {@link #AXIS_TOUCH_MAJOR} or {@link #AXIS_TOOL_MAJOR}.
597 * </ul>
598 * </p>
Jeff Brown91c69ab2011-02-14 17:03:18 -0800599 *
600 * @see #getSize(int)
601 * @see #getHistoricalSize(int, int)
602 * @see MotionEvent.PointerCoords#size
603 * @see InputDevice#getMotionRange
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700604 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800605 public static final int AXIS_SIZE = 3;
606
607 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700608 * Axis constant: TouchMajor axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800609 * <p>
610 * <ul>
611 * <li>For a touch screen, reports the length of the major axis of an ellipse that
612 * represents the touch area at the point of contact.
613 * The units are display pixels.
614 * <li>For a touch pad, reports the length of the major axis of an ellipse that
615 * represents the touch area at the point of contact.
616 * The units are device-dependent; use {@link InputDevice#getMotionRange(int)}
617 * to query the effective range of values.
618 * </ul>
619 * </p>
Jeff Brown91c69ab2011-02-14 17:03:18 -0800620 *
621 * @see #getTouchMajor(int)
622 * @see #getHistoricalTouchMajor(int, int)
623 * @see MotionEvent.PointerCoords#touchMajor
624 * @see InputDevice#getMotionRange
Dianne Hackborn1e8dfc72009-08-06 12:43:01 -0700625 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800626 public static final int AXIS_TOUCH_MAJOR = 4;
627
628 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700629 * Axis constant: TouchMinor axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800630 * <p>
631 * <ul>
632 * <li>For a touch screen, reports the length of the minor axis of an ellipse that
633 * represents the touch area at the point of contact.
634 * The units are display pixels.
635 * <li>For a touch pad, reports the length of the minor axis of an ellipse that
636 * represents the touch area at the point of contact.
637 * The units are device-dependent; use {@link InputDevice#getMotionRange(int)}
638 * to query the effective range of values.
639 * </ul>
640 * </p><p>
641 * When the touch is circular, the major and minor axis lengths will be equal to one another.
642 * </p>
Jeff Brown91c69ab2011-02-14 17:03:18 -0800643 *
644 * @see #getTouchMinor(int)
645 * @see #getHistoricalTouchMinor(int, int)
646 * @see MotionEvent.PointerCoords#touchMinor
647 * @see InputDevice#getMotionRange
Jeff Brown9e2ad362010-07-30 19:20:11 -0700648 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800649 public static final int AXIS_TOUCH_MINOR = 5;
650
651 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700652 * Axis constant: ToolMajor axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800653 * <p>
654 * <ul>
655 * <li>For a touch screen, reports the length of the major axis of an ellipse that
656 * represents the size of the approaching finger or tool used to make contact.
657 * <li>For a touch pad, reports the length of the major axis of an ellipse that
658 * represents the size of the approaching finger or tool used to make contact.
659 * The units are device-dependent; use {@link InputDevice#getMotionRange(int)}
660 * to query the effective range of values.
661 * </ul>
662 * </p><p>
663 * When the touch is circular, the major and minor axis lengths will be equal to one another.
664 * </p><p>
665 * The tool size may be larger than the touch size since the tool may not be fully
666 * in contact with the touch sensor.
667 * </p>
Jeff Brown91c69ab2011-02-14 17:03:18 -0800668 *
669 * @see #getToolMajor(int)
670 * @see #getHistoricalToolMajor(int, int)
671 * @see MotionEvent.PointerCoords#toolMajor
672 * @see InputDevice#getMotionRange
673 */
674 public static final int AXIS_TOOL_MAJOR = 6;
675
676 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700677 * Axis constant: ToolMinor axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800678 * <p>
679 * <ul>
680 * <li>For a touch screen, reports the length of the minor axis of an ellipse that
681 * represents the size of the approaching finger or tool used to make contact.
682 * <li>For a touch pad, reports the length of the minor axis of an ellipse that
683 * represents the size of the approaching finger or tool used to make contact.
684 * The units are device-dependent; use {@link InputDevice#getMotionRange(int)}
685 * to query the effective range of values.
686 * </ul>
687 * </p><p>
688 * When the touch is circular, the major and minor axis lengths will be equal to one another.
689 * </p><p>
690 * The tool size may be larger than the touch size since the tool may not be fully
691 * in contact with the touch sensor.
692 * </p>
Jeff Brown91c69ab2011-02-14 17:03:18 -0800693 *
694 * @see #getToolMinor(int)
695 * @see #getHistoricalToolMinor(int, int)
696 * @see MotionEvent.PointerCoords#toolMinor
697 * @see InputDevice#getMotionRange
698 */
699 public static final int AXIS_TOOL_MINOR = 7;
700
701 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700702 * Axis constant: Orientation axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800703 * <p>
704 * <ul>
705 * <li>For a touch screen or touch pad, reports the orientation of the finger
706 * or tool in radians relative to the vertical plane of the device.
707 * An angle of 0 radians indicates that the major axis of contact is oriented
Jeff Brown91c69ab2011-02-14 17:03:18 -0800708 * upwards, is perfectly circular or is of unknown orientation. A positive angle
709 * indicates that the major axis of contact is oriented to the right. A negative angle
710 * indicates that the major axis of contact is oriented to the left.
711 * The full range is from -PI/2 radians (finger pointing fully left) to PI/2 radians
712 * (finger pointing fully right).
Jeff Brown65fd2512011-08-18 11:20:58 -0700713 * <li>For a stylus, the orientation indicates the direction in which the stylus
714 * is pointing in relation to the vertical axis of the current orientation of the screen.
715 * The range is from -PI radians to PI radians, where 0 is pointing up,
716 * -PI/2 radians is pointing left, -PI or PI radians is pointing down, and PI/2 radians
717 * is pointing right. See also {@link #AXIS_TILT}.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800718 * </ul>
719 * </p>
Jeff Brown91c69ab2011-02-14 17:03:18 -0800720 *
721 * @see #getOrientation(int)
722 * @see #getHistoricalOrientation(int, int)
723 * @see MotionEvent.PointerCoords#orientation
724 * @see InputDevice#getMotionRange
725 */
726 public static final int AXIS_ORIENTATION = 8;
727
Jeff Brown6f2fba42011-02-19 01:08:02 -0800728 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700729 * Axis constant: Vertical Scroll axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800730 * <p>
731 * <ul>
Jeff Browncc0c1592011-02-19 05:07:28 -0800732 * <li>For a mouse, reports the relative movement of the vertical scroll wheel.
Jeff Brown33bbfd22011-02-24 20:55:35 -0800733 * The value is normalized to a range from -1.0 (down) to 1.0 (up).
Jeff Brown6f2fba42011-02-19 01:08:02 -0800734 * </ul>
735 * </p><p>
736 * This axis should be used to scroll views vertically.
737 * </p>
738 *
739 * @see #getAxisValue(int, int)
740 * @see #getHistoricalAxisValue(int, int, int)
741 * @see MotionEvent.PointerCoords#getAxisValue(int)
742 * @see InputDevice#getMotionRange
743 */
744 public static final int AXIS_VSCROLL = 9;
745
746 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700747 * Axis constant: Horizontal Scroll axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800748 * <p>
749 * <ul>
Jeff Browncc0c1592011-02-19 05:07:28 -0800750 * <li>For a mouse, reports the relative movement of the horizontal scroll wheel.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800751 * The value is normalized to a range from -1.0 (left) to 1.0 (right).
752 * </ul>
753 * </p><p>
754 * This axis should be used to scroll views horizontally.
755 * </p>
756 *
757 * @see #getAxisValue(int, int)
758 * @see #getHistoricalAxisValue(int, int, int)
759 * @see MotionEvent.PointerCoords#getAxisValue(int)
760 * @see InputDevice#getMotionRange
761 */
762 public static final int AXIS_HSCROLL = 10;
763
764 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700765 * Axis constant: Z axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800766 * <p>
767 * <ul>
768 * <li>For a joystick, reports the absolute Z position of the joystick.
769 * The value is normalized to a range from -1.0 (high) to 1.0 (low).
770 * <em>On game pads with two analog joysticks, this axis is often reinterpreted
771 * to report the absolute X position of the second joystick instead.</em>
772 * </ul>
773 * </p>
774 *
775 * @see #getAxisValue(int, int)
776 * @see #getHistoricalAxisValue(int, int, int)
777 * @see MotionEvent.PointerCoords#getAxisValue(int)
778 * @see InputDevice#getMotionRange
779 */
780 public static final int AXIS_Z = 11;
781
782 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700783 * Axis constant: X Rotation axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800784 * <p>
785 * <ul>
786 * <li>For a joystick, reports the absolute rotation angle about the X axis.
787 * The value is normalized to a range from -1.0 (counter-clockwise) to 1.0 (clockwise).
788 * </ul>
789 * </p>
790 *
791 * @see #getAxisValue(int, int)
792 * @see #getHistoricalAxisValue(int, int, int)
793 * @see MotionEvent.PointerCoords#getAxisValue(int)
794 * @see InputDevice#getMotionRange
795 */
796 public static final int AXIS_RX = 12;
797
798 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700799 * Axis constant: Y Rotation axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800800 * <p>
801 * <ul>
802 * <li>For a joystick, reports the absolute rotation angle about the Y axis.
803 * The value is normalized to a range from -1.0 (counter-clockwise) to 1.0 (clockwise).
804 * </ul>
805 * </p>
806 *
807 * @see #getAxisValue(int, int)
808 * @see #getHistoricalAxisValue(int, int, int)
809 * @see MotionEvent.PointerCoords#getAxisValue(int)
810 * @see InputDevice#getMotionRange
811 */
812 public static final int AXIS_RY = 13;
813
814 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700815 * Axis constant: Z Rotation axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800816 * <p>
817 * <ul>
818 * <li>For a joystick, reports the absolute rotation angle about the Z axis.
819 * The value is normalized to a range from -1.0 (counter-clockwise) to 1.0 (clockwise).
820 * <em>On game pads with two analog joysticks, this axis is often reinterpreted
821 * to report the absolute Y position of the second joystick instead.</em>
822 * </ul>
823 * </p>
824 *
825 * @see #getAxisValue(int, int)
826 * @see #getHistoricalAxisValue(int, int, int)
827 * @see MotionEvent.PointerCoords#getAxisValue(int)
828 * @see InputDevice#getMotionRange
829 */
830 public static final int AXIS_RZ = 14;
831
832 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700833 * Axis constant: Hat X axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800834 * <p>
835 * <ul>
836 * <li>For a joystick, reports the absolute X position of the directional hat control.
837 * The value is normalized to a range from -1.0 (left) to 1.0 (right).
838 * </ul>
839 * </p>
840 *
841 * @see #getAxisValue(int, int)
842 * @see #getHistoricalAxisValue(int, int, int)
843 * @see MotionEvent.PointerCoords#getAxisValue(int)
844 * @see InputDevice#getMotionRange
845 */
846 public static final int AXIS_HAT_X = 15;
847
848 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700849 * Axis constant: Hat Y axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800850 * <p>
851 * <ul>
852 * <li>For a joystick, reports the absolute Y position of the directional hat control.
853 * The value is normalized to a range from -1.0 (up) to 1.0 (down).
854 * </ul>
855 * </p>
856 *
857 * @see #getAxisValue(int, int)
858 * @see #getHistoricalAxisValue(int, int, int)
859 * @see MotionEvent.PointerCoords#getAxisValue(int)
860 * @see InputDevice#getMotionRange
861 */
862 public static final int AXIS_HAT_Y = 16;
863
864 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700865 * Axis constant: Left Trigger axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800866 * <p>
867 * <ul>
868 * <li>For a joystick, reports the absolute position of the left trigger control.
869 * The value is normalized to a range from 0.0 (released) to 1.0 (fully pressed).
870 * </ul>
871 * </p>
872 *
873 * @see #getAxisValue(int, int)
874 * @see #getHistoricalAxisValue(int, int, int)
875 * @see MotionEvent.PointerCoords#getAxisValue(int)
876 * @see InputDevice#getMotionRange
877 */
878 public static final int AXIS_LTRIGGER = 17;
879
880 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700881 * Axis constant: Right Trigger axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800882 * <p>
883 * <ul>
884 * <li>For a joystick, reports the absolute position of the right trigger control.
885 * The value is normalized to a range from 0.0 (released) to 1.0 (fully pressed).
886 * </ul>
887 * </p>
888 *
889 * @see #getAxisValue(int, int)
890 * @see #getHistoricalAxisValue(int, int, int)
891 * @see MotionEvent.PointerCoords#getAxisValue(int)
892 * @see InputDevice#getMotionRange
893 */
894 public static final int AXIS_RTRIGGER = 18;
895
896 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700897 * Axis constant: Throttle axis of a motion event.
Jeff Brown3a22fa02011-03-04 13:07:49 -0800898 * <p>
899 * <ul>
900 * <li>For a joystick, reports the absolute position of the throttle control.
901 * The value is normalized to a range from 0.0 (fully open) to 1.0 (fully closed).
902 * </ul>
903 * </p>
904 *
905 * @see #getAxisValue(int, int)
906 * @see #getHistoricalAxisValue(int, int, int)
907 * @see MotionEvent.PointerCoords#getAxisValue(int)
908 * @see InputDevice#getMotionRange
909 */
910 public static final int AXIS_THROTTLE = 19;
911
912 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700913 * Axis constant: Rudder axis of a motion event.
Jeff Brown3a22fa02011-03-04 13:07:49 -0800914 * <p>
915 * <ul>
916 * <li>For a joystick, reports the absolute position of the rudder control.
917 * The value is normalized to a range from -1.0 (turn left) to 1.0 (turn right).
918 * </ul>
919 * </p>
920 *
921 * @see #getAxisValue(int, int)
922 * @see #getHistoricalAxisValue(int, int, int)
923 * @see MotionEvent.PointerCoords#getAxisValue(int)
924 * @see InputDevice#getMotionRange
925 */
926 public static final int AXIS_RUDDER = 20;
927
928 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700929 * Axis constant: Wheel axis of a motion event.
Jeff Brown3a22fa02011-03-04 13:07:49 -0800930 * <p>
931 * <ul>
932 * <li>For a joystick, reports the absolute position of the steering wheel control.
933 * The value is normalized to a range from -1.0 (turn left) to 1.0 (turn right).
934 * </ul>
935 * </p>
936 *
937 * @see #getAxisValue(int, int)
938 * @see #getHistoricalAxisValue(int, int, int)
939 * @see MotionEvent.PointerCoords#getAxisValue(int)
940 * @see InputDevice#getMotionRange
941 */
942 public static final int AXIS_WHEEL = 21;
943
944 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700945 * Axis constant: Gas axis of a motion event.
Jeff Brown3a22fa02011-03-04 13:07:49 -0800946 * <p>
947 * <ul>
948 * <li>For a joystick, reports the absolute position of the gas (accelerator) control.
949 * The value is normalized to a range from 0.0 (no acceleration)
950 * to 1.0 (maximum acceleration).
951 * </ul>
952 * </p>
953 *
954 * @see #getAxisValue(int, int)
955 * @see #getHistoricalAxisValue(int, int, int)
956 * @see MotionEvent.PointerCoords#getAxisValue(int)
957 * @see InputDevice#getMotionRange
958 */
959 public static final int AXIS_GAS = 22;
960
961 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700962 * Axis constant: Brake axis of a motion event.
Jeff Brown3a22fa02011-03-04 13:07:49 -0800963 * <p>
964 * <ul>
965 * <li>For a joystick, reports the absolute position of the brake control.
966 * The value is normalized to a range from 0.0 (no braking) to 1.0 (maximum braking).
967 * </ul>
968 * </p>
969 *
970 * @see #getAxisValue(int, int)
971 * @see #getHistoricalAxisValue(int, int, int)
972 * @see MotionEvent.PointerCoords#getAxisValue(int)
973 * @see InputDevice#getMotionRange
974 */
975 public static final int AXIS_BRAKE = 23;
976
977 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700978 * Axis constant: Distance axis of a motion event.
979 * <p>
980 * <ul>
981 * <li>For a stylus, reports the distance of the stylus from the screen.
Jeff Brown65fd2512011-08-18 11:20:58 -0700982 * A value of 0.0 indicates direct contact and larger values indicate increasing
983 * distance from the surface.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700984 * </ul>
985 * </p>
986 *
987 * @see #getAxisValue(int, int)
988 * @see #getHistoricalAxisValue(int, int, int)
989 * @see MotionEvent.PointerCoords#getAxisValue(int)
990 * @see InputDevice#getMotionRange
991 */
992 public static final int AXIS_DISTANCE = 24;
993
994 /**
Jeff Brown65fd2512011-08-18 11:20:58 -0700995 * Axis constant: Tilt axis of a motion event.
996 * <p>
997 * <ul>
998 * <li>For a stylus, reports the tilt angle of the stylus in radians where
999 * 0 radians indicates that the stylus is being held perpendicular to the
1000 * surface, and PI/2 radians indicates that the stylus is being held flat
1001 * against the surface.
1002 * </ul>
1003 * </p>
1004 *
1005 * @see #getAxisValue(int, int)
1006 * @see #getHistoricalAxisValue(int, int, int)
1007 * @see MotionEvent.PointerCoords#getAxisValue(int, int)
1008 * @see InputDevice#getMotionRange
1009 */
1010 public static final int AXIS_TILT = 25;
1011
1012 /**
Prashant Malani67322b12015-08-25 17:41:34 -07001013 * Axis constant: Generic scroll axis of a motion event.
1014 * <p>
1015 * <ul>
1016 * <li>Reports the relative movement of the generic scrolling device.
1017 * </ul>
1018 * </p><p>
1019 * This axis should be used for scroll events that are neither strictly vertical nor horizontal.
1020 * A good example would be the rotation of a rotary encoder input device.
1021 * </p>
1022 *
1023 * @see #getAxisValue(int, int)
Prashant Malani67322b12015-08-25 17:41:34 -07001024 */
1025 public static final int AXIS_SCROLL = 26;
1026
1027 /**
Jun Mukai347e5d42015-12-03 01:13:31 -08001028 * Axis constant: The movement of x position of a motion event.
1029 * <p>
1030 * <ul>
1031 * <li>For a mouse, reports a difference of x position between the previous position.
1032 * This is useful when pointer is captured, in that case the mouse pointer doesn't change
1033 * the location but this axis reports the difference which allows the app to see
1034 * how the mouse is moved.
1035 * </ul>
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_X = 27;
1044
1045 /**
1046 * Axis constant: The movement of y position of a motion event.
1047 * <p>
1048 * This is similar to {@link #AXIS_RELATIVE_X} but for y-axis.
1049 * </p>
1050 *
1051 * @see #getAxisValue(int, int)
1052 * @see #getHistoricalAxisValue(int, int, int)
1053 * @see MotionEvent.PointerCoords#getAxisValue(int, int)
1054 * @see InputDevice#getMotionRange
1055 */
1056 public static final int AXIS_RELATIVE_Y = 28;
1057
1058 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001059 * Axis constant: Generic 1 axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -08001060 * The interpretation of a generic axis is device-specific.
1061 *
1062 * @see #getAxisValue(int, int)
1063 * @see #getHistoricalAxisValue(int, int, int)
1064 * @see MotionEvent.PointerCoords#getAxisValue(int)
1065 * @see InputDevice#getMotionRange
1066 */
1067 public static final int AXIS_GENERIC_1 = 32;
1068
1069 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001070 * Axis constant: Generic 2 axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -08001071 * The interpretation of a generic axis is device-specific.
1072 *
1073 * @see #getAxisValue(int, int)
1074 * @see #getHistoricalAxisValue(int, int, int)
1075 * @see MotionEvent.PointerCoords#getAxisValue(int)
1076 * @see InputDevice#getMotionRange
1077 */
1078 public static final int AXIS_GENERIC_2 = 33;
1079
1080 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001081 * Axis constant: Generic 3 axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -08001082 * The interpretation of a generic axis is device-specific.
1083 *
1084 * @see #getAxisValue(int, int)
1085 * @see #getHistoricalAxisValue(int, int, int)
1086 * @see MotionEvent.PointerCoords#getAxisValue(int)
1087 * @see InputDevice#getMotionRange
1088 */
1089 public static final int AXIS_GENERIC_3 = 34;
1090
1091 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001092 * Axis constant: Generic 4 axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -08001093 * The interpretation of a generic axis is device-specific.
1094 *
1095 * @see #getAxisValue(int, int)
1096 * @see #getHistoricalAxisValue(int, int, int)
1097 * @see MotionEvent.PointerCoords#getAxisValue(int)
1098 * @see InputDevice#getMotionRange
1099 */
1100 public static final int AXIS_GENERIC_4 = 35;
1101
1102 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001103 * Axis constant: Generic 5 axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -08001104 * The interpretation of a generic axis is device-specific.
1105 *
1106 * @see #getAxisValue(int, int)
1107 * @see #getHistoricalAxisValue(int, int, int)
1108 * @see MotionEvent.PointerCoords#getAxisValue(int)
1109 * @see InputDevice#getMotionRange
1110 */
1111 public static final int AXIS_GENERIC_5 = 36;
1112
1113 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001114 * Axis constant: Generic 6 axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -08001115 * The interpretation of a generic axis is device-specific.
1116 *
1117 * @see #getAxisValue(int, int)
1118 * @see #getHistoricalAxisValue(int, int, int)
1119 * @see MotionEvent.PointerCoords#getAxisValue(int)
1120 * @see InputDevice#getMotionRange
1121 */
1122 public static final int AXIS_GENERIC_6 = 37;
1123
1124 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001125 * Axis constant: Generic 7 axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -08001126 * The interpretation of a generic axis is device-specific.
1127 *
1128 * @see #getAxisValue(int, int)
1129 * @see #getHistoricalAxisValue(int, int, int)
1130 * @see MotionEvent.PointerCoords#getAxisValue(int)
1131 * @see InputDevice#getMotionRange
1132 */
1133 public static final int AXIS_GENERIC_7 = 38;
1134
1135 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001136 * Axis constant: Generic 8 axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -08001137 * The interpretation of a generic axis is device-specific.
1138 *
1139 * @see #getAxisValue(int, int)
1140 * @see #getHistoricalAxisValue(int, int, int)
1141 * @see MotionEvent.PointerCoords#getAxisValue(int)
1142 * @see InputDevice#getMotionRange
1143 */
1144 public static final int AXIS_GENERIC_8 = 39;
1145
1146 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001147 * Axis constant: Generic 9 axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -08001148 * The interpretation of a generic axis is device-specific.
1149 *
1150 * @see #getAxisValue(int, int)
1151 * @see #getHistoricalAxisValue(int, int, int)
1152 * @see MotionEvent.PointerCoords#getAxisValue(int)
1153 * @see InputDevice#getMotionRange
1154 */
1155 public static final int AXIS_GENERIC_9 = 40;
1156
1157 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001158 * Axis constant: Generic 10 axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -08001159 * The interpretation of a generic axis is device-specific.
1160 *
1161 * @see #getAxisValue(int, int)
1162 * @see #getHistoricalAxisValue(int, int, int)
1163 * @see MotionEvent.PointerCoords#getAxisValue(int)
1164 * @see InputDevice#getMotionRange
1165 */
1166 public static final int AXIS_GENERIC_10 = 41;
1167
1168 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001169 * Axis constant: Generic 11 axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -08001170 * The interpretation of a generic axis is device-specific.
1171 *
1172 * @see #getAxisValue(int, int)
1173 * @see #getHistoricalAxisValue(int, int, int)
1174 * @see MotionEvent.PointerCoords#getAxisValue(int)
1175 * @see InputDevice#getMotionRange
1176 */
1177 public static final int AXIS_GENERIC_11 = 42;
1178
1179 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001180 * Axis constant: Generic 12 axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -08001181 * The interpretation of a generic axis is device-specific.
1182 *
1183 * @see #getAxisValue(int, int)
1184 * @see #getHistoricalAxisValue(int, int, int)
1185 * @see MotionEvent.PointerCoords#getAxisValue(int)
1186 * @see InputDevice#getMotionRange
1187 */
1188 public static final int AXIS_GENERIC_12 = 43;
1189
1190 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001191 * Axis constant: Generic 13 axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -08001192 * The interpretation of a generic axis is device-specific.
1193 *
1194 * @see #getAxisValue(int, int)
1195 * @see #getHistoricalAxisValue(int, int, int)
1196 * @see MotionEvent.PointerCoords#getAxisValue(int)
1197 * @see InputDevice#getMotionRange
1198 */
1199 public static final int AXIS_GENERIC_13 = 44;
1200
1201 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001202 * Axis constant: Generic 14 axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -08001203 * The interpretation of a generic axis is device-specific.
1204 *
1205 * @see #getAxisValue(int, int)
1206 * @see #getHistoricalAxisValue(int, int, int)
1207 * @see MotionEvent.PointerCoords#getAxisValue(int)
1208 * @see InputDevice#getMotionRange
1209 */
1210 public static final int AXIS_GENERIC_14 = 45;
1211
1212 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001213 * Axis constant: Generic 15 axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -08001214 * The interpretation of a generic axis is device-specific.
1215 *
1216 * @see #getAxisValue(int, int)
1217 * @see #getHistoricalAxisValue(int, int, int)
1218 * @see MotionEvent.PointerCoords#getAxisValue(int)
1219 * @see InputDevice#getMotionRange
1220 */
1221 public static final int AXIS_GENERIC_15 = 46;
1222
1223 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001224 * Axis constant: Generic 16 axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -08001225 * The interpretation of a generic axis is device-specific.
1226 *
1227 * @see #getAxisValue(int, int)
1228 * @see #getHistoricalAxisValue(int, int, int)
1229 * @see MotionEvent.PointerCoords#getAxisValue(int)
1230 * @see InputDevice#getMotionRange
1231 */
1232 public static final int AXIS_GENERIC_16 = 47;
1233
1234 // NOTE: If you add a new axis here you must also add it to:
1235 // native/include/android/input.h
1236 // frameworks/base/include/ui/KeycodeLabels.h
1237
1238 // Symbolic names of all axes.
1239 private static final SparseArray<String> AXIS_SYMBOLIC_NAMES = new SparseArray<String>();
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001240 static {
Jeff Brown6f2fba42011-02-19 01:08:02 -08001241 SparseArray<String> names = AXIS_SYMBOLIC_NAMES;
1242 names.append(AXIS_X, "AXIS_X");
1243 names.append(AXIS_Y, "AXIS_Y");
1244 names.append(AXIS_PRESSURE, "AXIS_PRESSURE");
1245 names.append(AXIS_SIZE, "AXIS_SIZE");
1246 names.append(AXIS_TOUCH_MAJOR, "AXIS_TOUCH_MAJOR");
1247 names.append(AXIS_TOUCH_MINOR, "AXIS_TOUCH_MINOR");
1248 names.append(AXIS_TOOL_MAJOR, "AXIS_TOOL_MAJOR");
1249 names.append(AXIS_TOOL_MINOR, "AXIS_TOOL_MINOR");
1250 names.append(AXIS_ORIENTATION, "AXIS_ORIENTATION");
1251 names.append(AXIS_VSCROLL, "AXIS_VSCROLL");
1252 names.append(AXIS_HSCROLL, "AXIS_HSCROLL");
1253 names.append(AXIS_Z, "AXIS_Z");
1254 names.append(AXIS_RX, "AXIS_RX");
1255 names.append(AXIS_RY, "AXIS_RY");
1256 names.append(AXIS_RZ, "AXIS_RZ");
1257 names.append(AXIS_HAT_X, "AXIS_HAT_X");
1258 names.append(AXIS_HAT_Y, "AXIS_HAT_Y");
1259 names.append(AXIS_LTRIGGER, "AXIS_LTRIGGER");
1260 names.append(AXIS_RTRIGGER, "AXIS_RTRIGGER");
Jeff Brown3a22fa02011-03-04 13:07:49 -08001261 names.append(AXIS_THROTTLE, "AXIS_THROTTLE");
1262 names.append(AXIS_RUDDER, "AXIS_RUDDER");
1263 names.append(AXIS_WHEEL, "AXIS_WHEEL");
1264 names.append(AXIS_GAS, "AXIS_GAS");
1265 names.append(AXIS_BRAKE, "AXIS_BRAKE");
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001266 names.append(AXIS_DISTANCE, "AXIS_DISTANCE");
Jeff Brown65fd2512011-08-18 11:20:58 -07001267 names.append(AXIS_TILT, "AXIS_TILT");
Prashant Malani67322b12015-08-25 17:41:34 -07001268 names.append(AXIS_SCROLL, "AXIS_SCROLL");
Jun Mukai347e5d42015-12-03 01:13:31 -08001269 names.append(AXIS_RELATIVE_X, "AXIS_REALTIVE_X");
1270 names.append(AXIS_RELATIVE_Y, "AXIS_REALTIVE_Y");
Jeff Brown6f2fba42011-02-19 01:08:02 -08001271 names.append(AXIS_GENERIC_1, "AXIS_GENERIC_1");
1272 names.append(AXIS_GENERIC_2, "AXIS_GENERIC_2");
1273 names.append(AXIS_GENERIC_3, "AXIS_GENERIC_3");
1274 names.append(AXIS_GENERIC_4, "AXIS_GENERIC_4");
1275 names.append(AXIS_GENERIC_5, "AXIS_GENERIC_5");
1276 names.append(AXIS_GENERIC_6, "AXIS_GENERIC_6");
1277 names.append(AXIS_GENERIC_7, "AXIS_GENERIC_7");
1278 names.append(AXIS_GENERIC_8, "AXIS_GENERIC_8");
1279 names.append(AXIS_GENERIC_9, "AXIS_GENERIC_9");
1280 names.append(AXIS_GENERIC_10, "AXIS_GENERIC_10");
1281 names.append(AXIS_GENERIC_11, "AXIS_GENERIC_11");
1282 names.append(AXIS_GENERIC_12, "AXIS_GENERIC_12");
1283 names.append(AXIS_GENERIC_13, "AXIS_GENERIC_13");
1284 names.append(AXIS_GENERIC_14, "AXIS_GENERIC_14");
1285 names.append(AXIS_GENERIC_15, "AXIS_GENERIC_15");
1286 names.append(AXIS_GENERIC_16, "AXIS_GENERIC_16");
1287 }
1288
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001289 /**
Jeff Brown49754db2011-07-01 17:37:58 -07001290 * Button constant: Primary button (left mouse button).
1291 *
1292 * This button constant is not set in response to simple touches with a finger
1293 * or stylus tip. The user must actually push a button.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001294 *
1295 * @see #getButtonState
1296 */
1297 public static final int BUTTON_PRIMARY = 1 << 0;
1298
1299 /**
Michael Wright5bd69e62015-05-14 14:48:08 +01001300 * Button constant: Secondary button (right mouse button).
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001301 *
1302 * @see #getButtonState
1303 */
1304 public static final int BUTTON_SECONDARY = 1 << 1;
1305
1306 /**
Michael Wright5bd69e62015-05-14 14:48:08 +01001307 * Button constant: Tertiary button (middle mouse button).
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001308 *
1309 * @see #getButtonState
1310 */
1311 public static final int BUTTON_TERTIARY = 1 << 2;
1312
1313 /**
1314 * Button constant: Back button pressed (mouse back button).
1315 * <p>
1316 * The system may send a {@link KeyEvent#KEYCODE_BACK} key press to the application
1317 * when this button is pressed.
1318 * </p>
1319 *
1320 * @see #getButtonState
1321 */
1322 public static final int BUTTON_BACK = 1 << 3;
1323
1324 /**
1325 * Button constant: Forward button pressed (mouse forward button).
1326 * <p>
1327 * The system may send a {@link KeyEvent#KEYCODE_FORWARD} key press to the application
1328 * when this button is pressed.
1329 * </p>
1330 *
1331 * @see #getButtonState
1332 */
1333 public static final int BUTTON_FORWARD = 1 << 4;
1334
Michael Wright5bd69e62015-05-14 14:48:08 +01001335 /**
1336 * Button constant: Primary stylus button pressed.
1337 *
1338 * @see #getButtonState
1339 */
1340 public static final int BUTTON_STYLUS_PRIMARY = 1 << 5;
1341
1342 /**
1343 * Button constant: Secondary stylus button pressed.
1344 *
1345 * @see #getButtonState
1346 */
1347 public static final int BUTTON_STYLUS_SECONDARY = 1 << 6;
1348
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001349 // NOTE: If you add a new axis here you must also add it to:
1350 // native/include/android/input.h
1351
1352 // Symbolic names of all button states in bit order from least significant
1353 // to most significant.
1354 private static final String[] BUTTON_SYMBOLIC_NAMES = new String[] {
1355 "BUTTON_PRIMARY",
1356 "BUTTON_SECONDARY",
1357 "BUTTON_TERTIARY",
1358 "BUTTON_BACK",
1359 "BUTTON_FORWARD",
Michael Wright5bd69e62015-05-14 14:48:08 +01001360 "BUTTON_STYLUS_PRIMARY",
1361 "BUTTON_STYLUS_SECONDARY",
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001362 "0x00000080",
1363 "0x00000100",
1364 "0x00000200",
1365 "0x00000400",
1366 "0x00000800",
1367 "0x00001000",
1368 "0x00002000",
1369 "0x00004000",
1370 "0x00008000",
1371 "0x00010000",
1372 "0x00020000",
1373 "0x00040000",
1374 "0x00080000",
1375 "0x00100000",
1376 "0x00200000",
1377 "0x00400000",
1378 "0x00800000",
1379 "0x01000000",
1380 "0x02000000",
1381 "0x04000000",
1382 "0x08000000",
1383 "0x10000000",
1384 "0x20000000",
1385 "0x40000000",
1386 "0x80000000",
1387 };
1388
1389 /**
1390 * Tool type constant: Unknown tool type.
1391 * This constant is used when the tool type is not known or is not relevant,
1392 * such as for a trackball or other non-pointing device.
1393 *
1394 * @see #getToolType
1395 */
1396 public static final int TOOL_TYPE_UNKNOWN = 0;
1397
1398 /**
Jeff Brown49754db2011-07-01 17:37:58 -07001399 * Tool type constant: The tool is a finger.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001400 *
1401 * @see #getToolType
1402 */
1403 public static final int TOOL_TYPE_FINGER = 1;
1404
1405 /**
Jeff Brown49754db2011-07-01 17:37:58 -07001406 * Tool type constant: The tool is a stylus.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001407 *
1408 * @see #getToolType
1409 */
1410 public static final int TOOL_TYPE_STYLUS = 2;
1411
1412 /**
Jeff Brown49754db2011-07-01 17:37:58 -07001413 * Tool type constant: The tool is a mouse or trackpad.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001414 *
1415 * @see #getToolType
1416 */
1417 public static final int TOOL_TYPE_MOUSE = 3;
1418
1419 /**
Jeff Brown49754db2011-07-01 17:37:58 -07001420 * Tool type constant: The tool is an eraser or a stylus being used in an inverted posture.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001421 *
1422 * @see #getToolType
1423 */
Jeff Brown49754db2011-07-01 17:37:58 -07001424 public static final int TOOL_TYPE_ERASER = 4;
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001425
1426 // NOTE: If you add a new tool type here you must also add it to:
1427 // native/include/android/input.h
1428
1429 // Symbolic names of all tool types.
1430 private static final SparseArray<String> TOOL_TYPE_SYMBOLIC_NAMES = new SparseArray<String>();
Jeff Brown6f2fba42011-02-19 01:08:02 -08001431 static {
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001432 SparseArray<String> names = TOOL_TYPE_SYMBOLIC_NAMES;
1433 names.append(TOOL_TYPE_UNKNOWN, "TOOL_TYPE_UNKNOWN");
1434 names.append(TOOL_TYPE_FINGER, "TOOL_TYPE_FINGER");
1435 names.append(TOOL_TYPE_STYLUS, "TOOL_TYPE_STYLUS");
1436 names.append(TOOL_TYPE_MOUSE, "TOOL_TYPE_MOUSE");
Jeff Brown49754db2011-07-01 17:37:58 -07001437 names.append(TOOL_TYPE_ERASER, "TOOL_TYPE_ERASER");
Jeff Brown6f2fba42011-02-19 01:08:02 -08001438 }
1439
Jeff Brown91c69ab2011-02-14 17:03:18 -08001440 // Private value for history pos that obtains the current sample.
Mathew Inwoode5ad5982018-08-17 15:07:52 +01001441 @UnsupportedAppUsage
Jeff Brown91c69ab2011-02-14 17:03:18 -08001442 private static final int HISTORY_CURRENT = -0x80000000;
1443
Jeff Brown1f245102010-11-18 20:53:46 -08001444 private static final int MAX_RECYCLED = 10;
1445 private static final Object gRecyclerLock = new Object();
1446 private static int gRecyclerUsed;
1447 private static MotionEvent gRecyclerTop;
Romain Guycafdea62009-06-12 10:51:36 -07001448
Jeff Brown91c69ab2011-02-14 17:03:18 -08001449 // Shared temporary objects used when translating coordinates supplied by
1450 // the caller into single element PointerCoords and pointer id arrays.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001451 private static final Object gSharedTempLock = new Object();
1452 private static PointerCoords[] gSharedTempPointerCoords;
1453 private static PointerProperties[] gSharedTempPointerProperties;
1454 private static int[] gSharedTempPointerIndexMap;
1455
1456 private static final void ensureSharedTempPointerCapacity(int desiredCapacity) {
1457 if (gSharedTempPointerCoords == null
1458 || gSharedTempPointerCoords.length < desiredCapacity) {
1459 int capacity = gSharedTempPointerCoords != null ? gSharedTempPointerCoords.length : 8;
1460 while (capacity < desiredCapacity) {
1461 capacity *= 2;
1462 }
1463 gSharedTempPointerCoords = PointerCoords.createArray(capacity);
1464 gSharedTempPointerProperties = PointerProperties.createArray(capacity);
1465 gSharedTempPointerIndexMap = new int[capacity];
1466 }
1467 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08001468
1469 // Pointer to the native MotionEvent object that contains the actual data.
Mathew Inwoode5ad5982018-08-17 15:07:52 +01001470 @UnsupportedAppUsage
Ashok Bhat99a1ef22014-01-08 14:45:08 +00001471 private long mNativePtr;
Mitsuru Oshima8169dae2009-04-28 18:12:09 -07001472
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001473 private MotionEvent mNext;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001474
Ashok Bhat99a1ef22014-01-08 14:45:08 +00001475 private static native long nativeInitialize(long nativePtr,
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001476 int deviceId, int source, int action, int flags, int edgeFlags,
1477 int metaState, int buttonState,
Jeff Brown91c69ab2011-02-14 17:03:18 -08001478 float xOffset, float yOffset, float xPrecision, float yPrecision,
1479 long downTimeNanos, long eventTimeNanos,
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001480 int pointerCount, PointerProperties[] pointerIds, PointerCoords[] pointerCoords);
Ashok Bhat99a1ef22014-01-08 14:45:08 +00001481 private static native void nativeDispose(long nativePtr);
1482 private static native void nativeAddBatch(long nativePtr, long eventTimeNanos,
Jeff Brown91c69ab2011-02-14 17:03:18 -08001483 PointerCoords[] pointerCoords, int metaState);
Ashok Bhat99a1ef22014-01-08 14:45:08 +00001484 private static native void nativeGetPointerCoords(long nativePtr,
Jeff Brown91c69ab2011-02-14 17:03:18 -08001485 int pointerIndex, int historyPos, PointerCoords outPointerCoords);
Ashok Bhat99a1ef22014-01-08 14:45:08 +00001486 private static native void nativeGetPointerProperties(long nativePtr,
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001487 int pointerIndex, PointerProperties outPointerProperties);
Jeff Brown91c69ab2011-02-14 17:03:18 -08001488
Ashok Bhat99a1ef22014-01-08 14:45:08 +00001489 private static native long nativeReadFromParcel(long nativePtr, Parcel parcel);
1490 private static native void nativeWriteToParcel(long nativePtr, Parcel parcel);
Jeff Brown91c69ab2011-02-14 17:03:18 -08001491
Michael Wright337d9d22014-04-22 15:03:48 -07001492 private static native String nativeAxisToString(int axis);
1493 private static native int nativeAxisFromString(String label);
1494
John Reck09709972016-10-03 15:47:18 -07001495 // -------------- @FastNative -------------------------
1496
1497 @FastNative
1498 private static native int nativeGetPointerId(long nativePtr, int pointerIndex);
1499 @FastNative
1500 private static native int nativeGetToolType(long nativePtr, int pointerIndex);
1501 @FastNative
1502 private static native long nativeGetEventTimeNanos(long nativePtr, int historyPos);
1503 @FastNative
Mathew Inwoode5ad5982018-08-17 15:07:52 +01001504 @UnsupportedAppUsage
John Reck09709972016-10-03 15:47:18 -07001505 private static native float nativeGetRawAxisValue(long nativePtr,
1506 int axis, int pointerIndex, int historyPos);
1507 @FastNative
1508 private static native float nativeGetAxisValue(long nativePtr,
1509 int axis, int pointerIndex, int historyPos);
1510
1511 // -------------- @CriticalNative ----------------------
1512
1513 @CriticalNative
1514 private static native long nativeCopy(long destNativePtr, long sourceNativePtr,
1515 boolean keepHistory);
1516 @CriticalNative
1517 private static native int nativeGetDeviceId(long nativePtr);
1518 @CriticalNative
1519 private static native int nativeGetSource(long nativePtr);
1520 @CriticalNative
1521 private static native int nativeSetSource(long nativePtr, int source);
1522 @CriticalNative
1523 private static native int nativeGetAction(long nativePtr);
1524 @CriticalNative
1525 private static native void nativeSetAction(long nativePtr, int action);
1526 @CriticalNative
1527 private static native boolean nativeIsTouchEvent(long nativePtr);
1528 @CriticalNative
1529 private static native int nativeGetFlags(long nativePtr);
1530 @CriticalNative
1531 private static native void nativeSetFlags(long nativePtr, int flags);
1532 @CriticalNative
1533 private static native int nativeGetEdgeFlags(long nativePtr);
1534 @CriticalNative
1535 private static native void nativeSetEdgeFlags(long nativePtr, int action);
1536 @CriticalNative
1537 private static native int nativeGetMetaState(long nativePtr);
1538 @CriticalNative
1539 private static native int nativeGetButtonState(long nativePtr);
1540 @CriticalNative
1541 private static native void nativeSetButtonState(long nativePtr, int buttonState);
1542 @CriticalNative
1543 private static native int nativeGetActionButton(long nativePtr);
1544 @CriticalNative
1545 private static native void nativeSetActionButton(long nativePtr, int actionButton);
1546 @CriticalNative
1547 private static native void nativeOffsetLocation(long nativePtr, float deltaX, float deltaY);
1548 @CriticalNative
1549 private static native float nativeGetXOffset(long nativePtr);
1550 @CriticalNative
1551 private static native float nativeGetYOffset(long nativePtr);
1552 @CriticalNative
1553 private static native float nativeGetXPrecision(long nativePtr);
1554 @CriticalNative
1555 private static native float nativeGetYPrecision(long nativePtr);
1556 @CriticalNative
1557 private static native long nativeGetDownTimeNanos(long nativePtr);
1558 @CriticalNative
1559 private static native void nativeSetDownTimeNanos(long nativePtr, long downTime);
1560
1561 @CriticalNative
1562 private static native int nativeGetPointerCount(long nativePtr);
1563 @CriticalNative
1564 private static native int nativeFindPointerIndex(long nativePtr, int pointerId);
1565
1566 @CriticalNative
1567 private static native int nativeGetHistorySize(long nativePtr);
1568
1569 @CriticalNative
1570 private static native void nativeScale(long nativePtr, float scale);
1571 @CriticalNative
1572 private static native void nativeTransform(long nativePtr, long matrix);
1573
Jeff Brown91c69ab2011-02-14 17:03:18 -08001574 private MotionEvent() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001575 }
Romain Guycafdea62009-06-12 10:51:36 -07001576
Jeff Brown91c69ab2011-02-14 17:03:18 -08001577 @Override
1578 protected void finalize() throws Throwable {
1579 try {
1580 if (mNativePtr != 0) {
1581 nativeDispose(mNativePtr);
1582 mNativePtr = 0;
1583 }
1584 } finally {
1585 super.finalize();
1586 }
1587 }
1588
Mathew Inwoode5ad5982018-08-17 15:07:52 +01001589 @UnsupportedAppUsage
Jeff Brown91c69ab2011-02-14 17:03:18 -08001590 static private MotionEvent obtain() {
Jeff Brown46b9ac02010-04-22 18:58:52 -07001591 final MotionEvent ev;
1592 synchronized (gRecyclerLock) {
Jeff Brown1f245102010-11-18 20:53:46 -08001593 ev = gRecyclerTop;
1594 if (ev == null) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001595 return new MotionEvent();
Jeff Brown46b9ac02010-04-22 18:58:52 -07001596 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07001597 gRecyclerTop = ev.mNext;
Jeff Brown5c225b12010-06-16 01:53:36 -07001598 gRecyclerUsed -= 1;
Jeff Brown46b9ac02010-04-22 18:58:52 -07001599 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07001600 ev.mNext = null;
Jeff Brown32cbc38552011-12-01 14:01:49 -08001601 ev.prepareForReuse();
Jeff Brown46b9ac02010-04-22 18:58:52 -07001602 return ev;
1603 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08001604
Michael Chan53071d62009-05-13 17:29:48 -07001605 /**
1606 * Create a new MotionEvent, filling in all of the basic values that
1607 * define the motion.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001608 *
Dennis Kempinac1b31d2016-11-02 17:02:25 -07001609 * @param downTime The time (in ms) when the user originally pressed down to start
Michael Chan53071d62009-05-13 17:29:48 -07001610 * a stream of position events. This must be obtained from {@link SystemClock#uptimeMillis()}.
Dennis Kempinac1b31d2016-11-02 17:02:25 -07001611 * @param eventTime The the time (in ms) when this specific event was generated. This
Michael Chan53071d62009-05-13 17:29:48 -07001612 * must be obtained from {@link SystemClock#uptimeMillis()}.
Jeff Browncc0c1592011-02-19 05:07:28 -08001613 * @param action The kind of action being performed, such as {@link #ACTION_DOWN}.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001614 * @param pointerCount The number of pointers that will be in this event.
1615 * @param pointerProperties An array of <em>pointerCount</em> values providing
1616 * a {@link PointerProperties} property object for each pointer, which must
1617 * include the pointer identifier.
1618 * @param pointerCoords An array of <em>pointerCount</em> values providing
1619 * a {@link PointerCoords} coordinate object for each pointer.
1620 * @param metaState The state of any meta / modifier keys that were in effect when
1621 * the event was generated.
1622 * @param buttonState The state of buttons that are pressed.
1623 * @param xPrecision The precision of the X coordinate being reported.
1624 * @param yPrecision The precision of the Y coordinate being reported.
1625 * @param deviceId The id for the device that this event came from. An id of
1626 * zero indicates that the event didn't come from a physical device; other
1627 * numbers are arbitrary and you shouldn't depend on the values.
1628 * @param edgeFlags A bitfield indicating which edges, if any, were touched by this
1629 * MotionEvent.
1630 * @param source The source of this event.
1631 * @param flags The motion event flags.
1632 */
1633 static public MotionEvent obtain(long downTime, long eventTime,
1634 int action, int pointerCount, PointerProperties[] pointerProperties,
1635 PointerCoords[] pointerCoords, int metaState, int buttonState,
1636 float xPrecision, float yPrecision, int deviceId,
1637 int edgeFlags, int source, int flags) {
1638 MotionEvent ev = obtain();
1639 ev.mNativePtr = nativeInitialize(ev.mNativePtr,
1640 deviceId, source, action, flags, edgeFlags, metaState, buttonState,
1641 0, 0, xPrecision, yPrecision,
1642 downTime * NS_PER_MS, eventTime * NS_PER_MS,
1643 pointerCount, pointerProperties, pointerCoords);
1644 return ev;
1645 }
1646
1647 /**
1648 * Create a new MotionEvent, filling in all of the basic values that
1649 * define the motion.
Dennis Kempinac1b31d2016-11-02 17:02:25 -07001650 *
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001651 * @param downTime The time (in ms) when the user originally pressed down to start
1652 * a stream of position events. This must be obtained from {@link SystemClock#uptimeMillis()}.
1653 * @param eventTime The the time (in ms) when this specific event was generated. This
1654 * must be obtained from {@link SystemClock#uptimeMillis()}.
1655 * @param action The kind of action being performed, such as {@link #ACTION_DOWN}.
1656 * @param pointerCount The number of pointers that will be in this event.
1657 * @param pointerIds An array of <em>pointerCount</em> values providing
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001658 * an identifier for each pointer.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001659 * @param pointerCoords An array of <em>pointerCount</em> values providing
Jeff Brownc5ed5912010-07-14 18:48:53 -07001660 * a {@link PointerCoords} coordinate object for each pointer.
Michael Chan53071d62009-05-13 17:29:48 -07001661 * @param metaState The state of any meta / modifier keys that were in effect when
1662 * the event was generated.
1663 * @param xPrecision The precision of the X coordinate being reported.
1664 * @param yPrecision The precision of the Y coordinate being reported.
1665 * @param deviceId The id for the device that this event came from. An id of
1666 * zero indicates that the event didn't come from a physical device; other
1667 * numbers are arbitrary and you shouldn't depend on the values.
Jeff Brown85a31762010-09-01 17:01:00 -07001668 * @param edgeFlags A bitfield indicating which edges, if any, were touched by this
Michael Chan53071d62009-05-13 17:29:48 -07001669 * MotionEvent.
Jeff Brownc5ed5912010-07-14 18:48:53 -07001670 * @param source The source of this event.
Jeff Brown85a31762010-09-01 17:01:00 -07001671 * @param flags The motion event flags.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001672 *
1673 * @deprecated Use {@link #obtain(long, long, int, int, PointerProperties[], PointerCoords[], int, int, float, float, int, int, int, int)}
1674 * instead.
Michael Chan53071d62009-05-13 17:29:48 -07001675 */
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001676 @Deprecated
Jeff Brownc5ed5912010-07-14 18:48:53 -07001677 static public MotionEvent obtain(long downTime, long eventTime,
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001678 int action, int pointerCount, int[] pointerIds, PointerCoords[] pointerCoords,
Jeff Brownc5ed5912010-07-14 18:48:53 -07001679 int metaState, float xPrecision, float yPrecision, int deviceId,
Jeff Brown85a31762010-09-01 17:01:00 -07001680 int edgeFlags, int source, int flags) {
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001681 synchronized (gSharedTempLock) {
1682 ensureSharedTempPointerCapacity(pointerCount);
1683 final PointerProperties[] pp = gSharedTempPointerProperties;
1684 for (int i = 0; i < pointerCount; i++) {
1685 pp[i].clear();
1686 pp[i].id = pointerIds[i];
1687 }
1688 return obtain(downTime, eventTime, action, pointerCount, pp,
1689 pointerCoords, metaState, 0, xPrecision, yPrecision, deviceId,
1690 edgeFlags, source, flags);
1691 }
Michael Chan53071d62009-05-13 17:29:48 -07001692 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08001693
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001694 /**
1695 * Create a new MotionEvent, filling in all of the basic values that
1696 * define the motion.
Romain Guycafdea62009-06-12 10:51:36 -07001697 *
1698 * @param downTime The time (in ms) when the user originally pressed down to start
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001699 * a stream of position events. This must be obtained from {@link SystemClock#uptimeMillis()}.
Romain Guycafdea62009-06-12 10:51:36 -07001700 * @param eventTime The the time (in ms) when this specific event was generated. This
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001701 * must be obtained from {@link SystemClock#uptimeMillis()}.
Jeff Browncc0c1592011-02-19 05:07:28 -08001702 * @param action The kind of action being performed, such as {@link #ACTION_DOWN}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001703 * @param x The X coordinate of this event.
1704 * @param y The Y coordinate of this event.
Romain Guycafdea62009-06-12 10:51:36 -07001705 * @param pressure The current pressure of this event. The pressure generally
1706 * ranges from 0 (no pressure at all) to 1 (normal pressure), however
1707 * values higher than 1 may be generated depending on the calibration of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001708 * the input device.
1709 * @param size A scaled value of the approximate size of the area being pressed when
Romain Guycafdea62009-06-12 10:51:36 -07001710 * touched with the finger. The actual value in pixels corresponding to the finger
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001711 * touch is normalized with a device specific range of values
1712 * and scaled to a value between 0 and 1.
1713 * @param metaState The state of any meta / modifier keys that were in effect when
1714 * the event was generated.
1715 * @param xPrecision The precision of the X coordinate being reported.
1716 * @param yPrecision The precision of the Y coordinate being reported.
1717 * @param deviceId The id for the device that this event came from. An id of
1718 * zero indicates that the event didn't come from a physical device; other
1719 * numbers are arbitrary and you shouldn't depend on the values.
Jeff Brown85a31762010-09-01 17:01:00 -07001720 * @param edgeFlags A bitfield indicating which edges, if any, were touched by this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001721 * MotionEvent.
1722 */
1723 static public MotionEvent obtain(long downTime, long eventTime, int action,
1724 float x, float y, float pressure, float size, int metaState,
1725 float xPrecision, float yPrecision, int deviceId, int edgeFlags) {
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001726 MotionEvent ev = obtain();
1727 synchronized (gSharedTempLock) {
1728 ensureSharedTempPointerCapacity(1);
1729 final PointerProperties[] pp = gSharedTempPointerProperties;
1730 pp[0].clear();
1731 pp[0].id = 0;
Jeff Brown91c69ab2011-02-14 17:03:18 -08001732
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001733 final PointerCoords pc[] = gSharedTempPointerCoords;
1734 pc[0].clear();
1735 pc[0].x = x;
1736 pc[0].y = y;
1737 pc[0].pressure = pressure;
1738 pc[0].size = size;
1739
Jeff Brown91c69ab2011-02-14 17:03:18 -08001740 ev.mNativePtr = nativeInitialize(ev.mNativePtr,
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001741 deviceId, InputDevice.SOURCE_UNKNOWN, action, 0, edgeFlags, metaState, 0,
Jeff Brown91c69ab2011-02-14 17:03:18 -08001742 0, 0, xPrecision, yPrecision,
1743 downTime * NS_PER_MS, eventTime * NS_PER_MS,
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001744 1, pp, pc);
Jeff Brown91c69ab2011-02-14 17:03:18 -08001745 return ev;
1746 }
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001747 }
1748
1749 /**
1750 * Create a new MotionEvent, filling in all of the basic values that
1751 * define the motion.
1752 *
1753 * @param downTime The time (in ms) when the user originally pressed down to start
1754 * a stream of position events. This must be obtained from {@link SystemClock#uptimeMillis()}.
1755 * @param eventTime The the time (in ms) when this specific event was generated. This
1756 * must be obtained from {@link SystemClock#uptimeMillis()}.
Jeff Browncc0c1592011-02-19 05:07:28 -08001757 * @param action The kind of action being performed, such as {@link #ACTION_DOWN}.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001758 * @param pointerCount The number of pointers that are active in this event.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001759 * @param x The X coordinate of this event.
1760 * @param y The Y coordinate of this event.
1761 * @param pressure The current pressure of this event. The pressure generally
1762 * ranges from 0 (no pressure at all) to 1 (normal pressure), however
1763 * values higher than 1 may be generated depending on the calibration of
1764 * the input device.
1765 * @param size A scaled value of the approximate size of the area being pressed when
1766 * touched with the finger. The actual value in pixels corresponding to the finger
1767 * touch is normalized with a device specific range of values
1768 * and scaled to a value between 0 and 1.
1769 * @param metaState The state of any meta / modifier keys that were in effect when
1770 * the event was generated.
1771 * @param xPrecision The precision of the X coordinate being reported.
1772 * @param yPrecision The precision of the Y coordinate being reported.
1773 * @param deviceId The id for the device that this event came from. An id of
1774 * zero indicates that the event didn't come from a physical device; other
1775 * numbers are arbitrary and you shouldn't depend on the values.
Jeff Brown85a31762010-09-01 17:01:00 -07001776 * @param edgeFlags A bitfield indicating which edges, if any, were touched by this
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001777 * MotionEvent.
Dennis Kempinac1b31d2016-11-02 17:02:25 -07001778 *
Jeff Brown5c225b12010-06-16 01:53:36 -07001779 * @deprecated Use {@link #obtain(long, long, int, float, float, float, float, int, float, float, int, int)}
1780 * instead.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001781 */
Jeff Brown5c225b12010-06-16 01:53:36 -07001782 @Deprecated
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001783 static public MotionEvent obtain(long downTime, long eventTime, int action,
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001784 int pointerCount, float x, float y, float pressure, float size, int metaState,
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001785 float xPrecision, float yPrecision, int deviceId, int edgeFlags) {
Jeff Brown5c225b12010-06-16 01:53:36 -07001786 return obtain(downTime, eventTime, action, x, y, pressure, size,
1787 metaState, xPrecision, yPrecision, deviceId, edgeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001788 }
Romain Guycafdea62009-06-12 10:51:36 -07001789
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001790 /**
1791 * Create a new MotionEvent, filling in a subset of the basic motion
1792 * values. Those not specified here are: device id (always 0), pressure
1793 * and size (always 1), x and y precision (always 1), and edgeFlags (always 0).
Romain Guycafdea62009-06-12 10:51:36 -07001794 *
1795 * @param downTime The time (in ms) when the user originally pressed down to start
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001796 * a stream of position events. This must be obtained from {@link SystemClock#uptimeMillis()}.
Romain Guycafdea62009-06-12 10:51:36 -07001797 * @param eventTime The the time (in ms) when this specific event was generated. This
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001798 * must be obtained from {@link SystemClock#uptimeMillis()}.
Jeff Browncc0c1592011-02-19 05:07:28 -08001799 * @param action The kind of action being performed, such as {@link #ACTION_DOWN}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001800 * @param x The X coordinate of this event.
1801 * @param y The Y coordinate of this event.
1802 * @param metaState The state of any meta / modifier keys that were in effect when
1803 * the event was generated.
1804 */
1805 static public MotionEvent obtain(long downTime, long eventTime, int action,
1806 float x, float y, int metaState) {
Jeff Brown5c225b12010-06-16 01:53:36 -07001807 return obtain(downTime, eventTime, action, x, y, 1.0f, 1.0f,
1808 metaState, 1.0f, 1.0f, 0, 0);
Mitsuru Oshima8169dae2009-04-28 18:12:09 -07001809 }
1810
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001811 /**
1812 * Create a new MotionEvent, copying from an existing one.
1813 */
Jeff Brown91c69ab2011-02-14 17:03:18 -08001814 static public MotionEvent obtain(MotionEvent other) {
1815 if (other == null) {
1816 throw new IllegalArgumentException("other motion event must not be null");
1817 }
1818
1819 MotionEvent ev = obtain();
1820 ev.mNativePtr = nativeCopy(ev.mNativePtr, other.mNativePtr, true /*keepHistory*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001821 return ev;
1822 }
Romain Guycafdea62009-06-12 10:51:36 -07001823
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001824 /**
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07001825 * Create a new MotionEvent, copying from an existing one, but not including
1826 * any historical point information.
1827 */
Jeff Brown91c69ab2011-02-14 17:03:18 -08001828 static public MotionEvent obtainNoHistory(MotionEvent other) {
1829 if (other == null) {
1830 throw new IllegalArgumentException("other motion event must not be null");
1831 }
1832
1833 MotionEvent ev = obtain();
1834 ev.mNativePtr = nativeCopy(ev.mNativePtr, other.mNativePtr, false /*keepHistory*/);
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07001835 return ev;
1836 }
1837
Jeff Brown21bc5c92011-02-28 18:27:14 -08001838 /** @hide */
1839 @Override
Mathew Inwoode5ad5982018-08-17 15:07:52 +01001840 @UnsupportedAppUsage
Jeff Brown21bc5c92011-02-28 18:27:14 -08001841 public MotionEvent copy() {
1842 return obtain(this);
1843 }
1844
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07001845 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001846 * Recycle the MotionEvent, to be re-used by a later caller. After calling
1847 * this function you must not ever touch the event again.
1848 */
Jeff Brown92cc2d82011-12-02 01:19:47 -08001849 @Override
Jeff Brown5c225b12010-06-16 01:53:36 -07001850 public final void recycle() {
Jeff Brown32cbc38552011-12-01 14:01:49 -08001851 super.recycle();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001852
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001853 synchronized (gRecyclerLock) {
1854 if (gRecyclerUsed < MAX_RECYCLED) {
1855 gRecyclerUsed++;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001856 mNext = gRecyclerTop;
1857 gRecyclerTop = this;
1858 }
1859 }
1860 }
Jeff Brown9ea77fc2012-03-21 19:49:27 -07001861
Jeff Brown5c225b12010-06-16 01:53:36 -07001862 /**
Jeff Brown9ea77fc2012-03-21 19:49:27 -07001863 * Applies a scale factor to all points within this event.
Jeff Brown5c225b12010-06-16 01:53:36 -07001864 *
Jeff Brown9ea77fc2012-03-21 19:49:27 -07001865 * This method is used to adjust touch events to simulate different density
1866 * displays for compatibility mode. The values returned by {@link #getRawX()},
1867 * {@link #getRawY()}, {@link #getXPrecision()} and {@link #getYPrecision()}
1868 * are also affected by the scale factor.
1869 *
1870 * @param scale The scale factor to apply.
Jeff Brown5c225b12010-06-16 01:53:36 -07001871 * @hide
1872 */
Mathew Inwoode5ad5982018-08-17 15:07:52 +01001873 @UnsupportedAppUsage
Jeff Brown5c225b12010-06-16 01:53:36 -07001874 public final void scale(float scale) {
Jeff Brown9ea77fc2012-03-21 19:49:27 -07001875 if (scale != 1.0f) {
1876 nativeScale(mNativePtr, scale);
1877 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08001878 }
1879
1880 /** {@inheritDoc} */
1881 @Override
1882 public final int getDeviceId() {
1883 return nativeGetDeviceId(mNativePtr);
1884 }
1885
1886 /** {@inheritDoc} */
1887 @Override
1888 public final int getSource() {
1889 return nativeGetSource(mNativePtr);
1890 }
1891
1892 /** {@inheritDoc} */
1893 @Override
1894 public final void setSource(int source) {
1895 nativeSetSource(mNativePtr, source);
Jeff Brown5c225b12010-06-16 01:53:36 -07001896 }
Romain Guycafdea62009-06-12 10:51:36 -07001897
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001898 /**
Jeff Browncc0c1592011-02-19 05:07:28 -08001899 * Return the kind of action being performed.
1900 * Consider using {@link #getActionMasked} and {@link #getActionIndex} to retrieve
1901 * the separate masked action and pointer index.
1902 * @return The action, such as {@link #ACTION_DOWN} or
1903 * the combination of {@link #ACTION_POINTER_DOWN} with a shifted pointer index.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001904 */
1905 public final int getAction() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001906 return nativeGetAction(mNativePtr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001907 }
1908
1909 /**
Jeff Browncc0c1592011-02-19 05:07:28 -08001910 * Return the masked action being performed, without pointer index information.
1911 * Use {@link #getActionIndex} to return the index associated with pointer actions.
1912 * @return The action, such as {@link #ACTION_DOWN} or {@link #ACTION_POINTER_DOWN}.
Dianne Hackbornb125dc52010-02-12 15:52:09 -08001913 */
1914 public final int getActionMasked() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001915 return nativeGetAction(mNativePtr) & ACTION_MASK;
Dianne Hackbornb125dc52010-02-12 15:52:09 -08001916 }
1917
1918 /**
1919 * For {@link #ACTION_POINTER_DOWN} or {@link #ACTION_POINTER_UP}
1920 * as returned by {@link #getActionMasked}, this returns the associated
Jeff Browncc0c1592011-02-19 05:07:28 -08001921 * pointer index.
1922 * The index may be used with {@link #getPointerId(int)},
Dianne Hackbornb125dc52010-02-12 15:52:09 -08001923 * {@link #getX(int)}, {@link #getY(int)}, {@link #getPressure(int)},
1924 * and {@link #getSize(int)} to get information about the pointer that has
1925 * gone down or up.
Jeff Browncc0c1592011-02-19 05:07:28 -08001926 * @return The index associated with the action.
Dianne Hackbornb125dc52010-02-12 15:52:09 -08001927 */
1928 public final int getActionIndex() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001929 return (nativeGetAction(mNativePtr) & ACTION_POINTER_INDEX_MASK)
1930 >> ACTION_POINTER_INDEX_SHIFT;
Dianne Hackbornb125dc52010-02-12 15:52:09 -08001931 }
1932
1933 /**
Jeff Brown33bbfd22011-02-24 20:55:35 -08001934 * Returns true if this motion event is a touch event.
1935 * <p>
Jeff Browna032cc02011-03-07 16:56:21 -08001936 * Specifically excludes pointer events with action {@link #ACTION_HOVER_MOVE},
1937 * {@link #ACTION_HOVER_ENTER}, {@link #ACTION_HOVER_EXIT}, or {@link #ACTION_SCROLL}
1938 * because they are not actually touch events (the pointer is not down).
Jeff Brown33bbfd22011-02-24 20:55:35 -08001939 * </p>
1940 * @return True if this motion event is a touch event.
1941 * @hide
1942 */
1943 public final boolean isTouchEvent() {
Jeff Brown56194eb2011-03-02 19:23:13 -08001944 return nativeIsTouchEvent(mNativePtr);
Jeff Brown33bbfd22011-02-24 20:55:35 -08001945 }
1946
1947 /**
Jeff Brown85a31762010-09-01 17:01:00 -07001948 * Gets the motion event flags.
1949 *
1950 * @see #FLAG_WINDOW_IS_OBSCURED
1951 */
1952 public final int getFlags() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001953 return nativeGetFlags(mNativePtr);
Jeff Brown85a31762010-09-01 17:01:00 -07001954 }
1955
Jeff Brown21bc5c92011-02-28 18:27:14 -08001956 /** @hide */
1957 @Override
1958 public final boolean isTainted() {
1959 final int flags = getFlags();
1960 return (flags & FLAG_TAINTED) != 0;
1961 }
1962
1963 /** @hide */
1964 @Override
1965 public final void setTainted(boolean tainted) {
1966 final int flags = getFlags();
1967 nativeSetFlags(mNativePtr, tainted ? flags | FLAG_TAINTED : flags & ~FLAG_TAINTED);
1968 }
1969
Svetoslavded133c2015-01-30 20:28:41 -08001970 /** @hide */
1971 public final boolean isTargetAccessibilityFocus() {
1972 final int flags = getFlags();
1973 return (flags & FLAG_TARGET_ACCESSIBILITY_FOCUS) != 0;
1974 }
1975
1976 /** @hide */
1977 public final void setTargetAccessibilityFocus(boolean targetsFocus) {
1978 final int flags = getFlags();
1979 nativeSetFlags(mNativePtr, targetsFocus
1980 ? flags | FLAG_TARGET_ACCESSIBILITY_FOCUS
1981 : flags & ~FLAG_TARGET_ACCESSIBILITY_FOCUS);
1982 }
1983
Vladislav Kaznacheev5a77c372016-10-10 16:11:15 -07001984 /** @hide */
1985 public final boolean isHoverExitPending() {
1986 final int flags = getFlags();
1987 return (flags & FLAG_HOVER_EXIT_PENDING) != 0;
1988 }
1989
1990 /** @hide */
1991 public void setHoverExitPending(boolean hoverExitPending) {
1992 final int flags = getFlags();
1993 nativeSetFlags(mNativePtr, hoverExitPending
1994 ? flags | FLAG_HOVER_EXIT_PENDING
1995 : flags & ~FLAG_HOVER_EXIT_PENDING);
1996 }
1997
Jeff Brown85a31762010-09-01 17:01:00 -07001998 /**
Romain Guycafdea62009-06-12 10:51:36 -07001999 * Returns the time (in ms) when the user originally pressed down to start
2000 * a stream of position events.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002001 */
2002 public final long getDownTime() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002003 return nativeGetDownTimeNanos(mNativePtr) / NS_PER_MS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002004 }
2005
2006 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07002007 * Sets the time (in ms) when the user originally pressed down to start
2008 * a stream of position events.
2009 *
2010 * @hide
2011 */
Mathew Inwoode5ad5982018-08-17 15:07:52 +01002012 @UnsupportedAppUsage
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07002013 public final void setDownTime(long downTime) {
2014 nativeSetDownTimeNanos(mNativePtr, downTime * NS_PER_MS);
2015 }
2016
2017 /**
Jeff Brownb11499d2012-04-20 19:54:22 -07002018 * Retrieve the time this event occurred,
2019 * in the {@link android.os.SystemClock#uptimeMillis} time base.
2020 *
2021 * @return Returns the time this event occurred,
2022 * in the {@link android.os.SystemClock#uptimeMillis} time base.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002023 */
Jeff Brownb11499d2012-04-20 19:54:22 -07002024 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002025 public final long getEventTime() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002026 return nativeGetEventTimeNanos(mNativePtr, HISTORY_CURRENT) / NS_PER_MS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002027 }
2028
2029 /**
Jeff Brownb11499d2012-04-20 19:54:22 -07002030 * Retrieve the time this event occurred,
2031 * in the {@link android.os.SystemClock#uptimeMillis} time base but with
2032 * nanosecond precision.
2033 * <p>
Michael Chan53071d62009-05-13 17:29:48 -07002034 * The value is in nanosecond precision but it may not have nanosecond accuracy.
Jeff Brownb11499d2012-04-20 19:54:22 -07002035 * </p>
2036 *
2037 * @return Returns the time this event occurred,
2038 * in the {@link android.os.SystemClock#uptimeMillis} time base but with
2039 * nanosecond precision.
Michael Chan53071d62009-05-13 17:29:48 -07002040 *
2041 * @hide
2042 */
Jeff Brownb11499d2012-04-20 19:54:22 -07002043 @Override
Mathew Inwoode5ad5982018-08-17 15:07:52 +01002044 @UnsupportedAppUsage
Michael Chan53071d62009-05-13 17:29:48 -07002045 public final long getEventTimeNano() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002046 return nativeGetEventTimeNanos(mNativePtr, HISTORY_CURRENT);
Michael Chan53071d62009-05-13 17:29:48 -07002047 }
2048
2049 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002050 * {@link #getX(int)} for the first pointer index (may be an
2051 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002052 *
2053 * @see #AXIS_X
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002054 */
2055 public final float getX() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002056 return nativeGetAxisValue(mNativePtr, AXIS_X, 0, HISTORY_CURRENT);
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002057 }
2058
2059 /**
2060 * {@link #getY(int)} for the first pointer index (may be an
2061 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002062 *
2063 * @see #AXIS_Y
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002064 */
2065 public final float getY() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002066 return nativeGetAxisValue(mNativePtr, AXIS_Y, 0, HISTORY_CURRENT);
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002067 }
2068
2069 /**
2070 * {@link #getPressure(int)} for the first pointer index (may be an
2071 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002072 *
2073 * @see #AXIS_PRESSURE
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002074 */
2075 public final float getPressure() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002076 return nativeGetAxisValue(mNativePtr, AXIS_PRESSURE, 0, HISTORY_CURRENT);
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002077 }
2078
2079 /**
2080 * {@link #getSize(int)} for the first pointer index (may be an
2081 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002082 *
2083 * @see #AXIS_SIZE
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002084 */
2085 public final float getSize() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002086 return nativeGetAxisValue(mNativePtr, AXIS_SIZE, 0, HISTORY_CURRENT);
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002087 }
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002088
Jeff Brownc5ed5912010-07-14 18:48:53 -07002089 /**
2090 * {@link #getTouchMajor(int)} for the first pointer index (may be an
2091 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002092 *
2093 * @see #AXIS_TOUCH_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002094 */
2095 public final float getTouchMajor() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002096 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MAJOR, 0, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002097 }
2098
2099 /**
2100 * {@link #getTouchMinor(int)} for the first pointer index (may be an
2101 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002102 *
2103 * @see #AXIS_TOUCH_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002104 */
2105 public final float getTouchMinor() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002106 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MINOR, 0, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002107 }
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002108
Jeff Brownc5ed5912010-07-14 18:48:53 -07002109 /**
2110 * {@link #getToolMajor(int)} for the first pointer index (may be an
2111 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002112 *
2113 * @see #AXIS_TOOL_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002114 */
2115 public final float getToolMajor() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002116 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MAJOR, 0, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002117 }
2118
2119 /**
2120 * {@link #getToolMinor(int)} for the first pointer index (may be an
2121 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002122 *
2123 * @see #AXIS_TOOL_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002124 */
2125 public final float getToolMinor() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002126 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MINOR, 0, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002127 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08002128
Jeff Brownc5ed5912010-07-14 18:48:53 -07002129 /**
2130 * {@link #getOrientation(int)} for the first pointer index (may be an
2131 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002132 *
2133 * @see #AXIS_ORIENTATION
Jeff Brownc5ed5912010-07-14 18:48:53 -07002134 */
2135 public final float getOrientation() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002136 return nativeGetAxisValue(mNativePtr, AXIS_ORIENTATION, 0, HISTORY_CURRENT);
2137 }
2138
2139 /**
2140 * {@link #getAxisValue(int)} for the first pointer index (may be an
2141 * arbitrary pointer identifier).
2142 *
2143 * @param axis The axis identifier for the axis value to retrieve.
2144 *
2145 * @see #AXIS_X
2146 * @see #AXIS_Y
2147 */
2148 public final float getAxisValue(int axis) {
2149 return nativeGetAxisValue(mNativePtr, axis, 0, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002150 }
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002151
2152 /**
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002153 * The number of pointers of data contained in this event. Always
2154 * >= 1.
2155 */
2156 public final int getPointerCount() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002157 return nativeGetPointerCount(mNativePtr);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002158 }
John Reck09709972016-10-03 15:47:18 -07002159
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002160 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002161 * Return the pointer identifier associated with a particular pointer
Trevor Johns682c24e2016-04-12 10:13:47 -07002162 * data index in this event. The identifier tells you the actual pointer
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002163 * number associated with the data, accounting for individual pointers
2164 * going up and down since the start of the current gesture.
2165 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2166 * (the first pointer that is down) to {@link #getPointerCount()}-1.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002167 */
Dianne Hackbornd41ba662009-08-05 15:30:56 -07002168 public final int getPointerId(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002169 return nativeGetPointerId(mNativePtr, pointerIndex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002170 }
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07002171
2172 /**
2173 * Gets the tool type of a pointer for the given pointer index.
2174 * The tool type indicates the type of tool used to make contact such
2175 * as a finger or stylus, if known.
2176 *
2177 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2178 * (the first pointer that is down) to {@link #getPointerCount()}-1.
2179 * @return The tool type of the pointer.
2180 *
2181 * @see #TOOL_TYPE_UNKNOWN
2182 * @see #TOOL_TYPE_FINGER
2183 * @see #TOOL_TYPE_STYLUS
2184 * @see #TOOL_TYPE_MOUSE
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07002185 */
2186 public final int getToolType(int pointerIndex) {
2187 return nativeGetToolType(mNativePtr, pointerIndex);
2188 }
2189
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002190 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002191 * Given a pointer identifier, find the index of its data in the event.
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002192 *
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002193 * @param pointerId The identifier of the pointer to be found.
2194 * @return Returns either the index of the pointer (for use with
Gilles Debunneb0d6ba12010-08-17 20:01:42 -07002195 * {@link #getX(int)} et al.), or -1 if there is no data available for
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002196 * that pointer identifier.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002197 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002198 public final int findPointerIndex(int pointerId) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002199 return nativeFindPointerIndex(mNativePtr, pointerId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002200 }
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07002201
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002202 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002203 * Returns the X coordinate of this event for the given pointer
2204 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
2205 * identifier for this index).
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002206 * Whole numbers are pixels; the
2207 * value may have a fraction for input devices that are sub-pixel precise.
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002208 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2209 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002210 *
2211 * @see #AXIS_X
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002212 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002213 public final float getX(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002214 return nativeGetAxisValue(mNativePtr, AXIS_X, pointerIndex, HISTORY_CURRENT);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002215 }
2216
2217 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002218 * Returns the Y coordinate of this event for the given pointer
2219 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
2220 * identifier for this index).
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002221 * Whole numbers are pixels; the
2222 * value may have a fraction for input devices that are sub-pixel precise.
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002223 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2224 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002225 *
2226 * @see #AXIS_Y
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002227 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002228 public final float getY(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002229 return nativeGetAxisValue(mNativePtr, AXIS_Y, pointerIndex, HISTORY_CURRENT);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002230 }
2231
2232 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002233 * Returns the current pressure of this event for the given pointer
2234 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
2235 * identifier for this index).
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002236 * The pressure generally
Romain Guycafdea62009-06-12 10:51:36 -07002237 * ranges from 0 (no pressure at all) to 1 (normal pressure), however
2238 * values higher than 1 may be generated depending on the calibration of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002239 * the input device.
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002240 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2241 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002242 *
2243 * @see #AXIS_PRESSURE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002244 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002245 public final float getPressure(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002246 return nativeGetAxisValue(mNativePtr, AXIS_PRESSURE, pointerIndex, HISTORY_CURRENT);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002247 }
2248
2249 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002250 * Returns a scaled value of the approximate size for the given pointer
2251 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
2252 * identifier for this index).
2253 * This represents some approximation of the area of the screen being
2254 * pressed; the actual value in pixels corresponding to the
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002255 * touch is normalized with the device specific range of values
Romain Guycafdea62009-06-12 10:51:36 -07002256 * and scaled to a value between 0 and 1. The value of size can be used to
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002257 * determine fat touch events.
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002258 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2259 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002260 *
2261 * @see #AXIS_SIZE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002262 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002263 public final float getSize(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002264 return nativeGetAxisValue(mNativePtr, AXIS_SIZE, pointerIndex, HISTORY_CURRENT);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002265 }
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002266
Jeff Brownc5ed5912010-07-14 18:48:53 -07002267 /**
2268 * Returns the length of the major axis of an ellipse that describes the touch
2269 * area at the point of contact for the given pointer
2270 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
2271 * identifier for this index).
2272 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2273 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002274 *
2275 * @see #AXIS_TOUCH_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002276 */
2277 public final float getTouchMajor(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002278 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MAJOR, pointerIndex, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002279 }
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002280
Jeff Brownc5ed5912010-07-14 18:48:53 -07002281 /**
2282 * Returns the length of the minor axis of an ellipse that describes the touch
2283 * area at the point of contact for the given pointer
2284 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
2285 * identifier for this index).
2286 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2287 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002288 *
2289 * @see #AXIS_TOUCH_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002290 */
2291 public final float getTouchMinor(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002292 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MINOR, pointerIndex, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002293 }
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002294
Jeff Brownc5ed5912010-07-14 18:48:53 -07002295 /**
2296 * Returns the length of the major axis of an ellipse that describes the size of
2297 * the approaching tool for the given pointer
2298 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
2299 * identifier for this index).
2300 * The tool area represents the estimated size of the finger or pen that is
2301 * touching the device independent of its actual touch area at the point of contact.
2302 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2303 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002304 *
2305 * @see #AXIS_TOOL_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002306 */
2307 public final float getToolMajor(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002308 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MAJOR, pointerIndex, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002309 }
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002310
Jeff Brownc5ed5912010-07-14 18:48:53 -07002311 /**
2312 * Returns the length of the minor axis of an ellipse that describes the size of
2313 * the approaching tool for the given pointer
2314 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
2315 * identifier for this index).
2316 * The tool area represents the estimated size of the finger or pen that is
2317 * touching the device independent of its actual touch area at the point of contact.
2318 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2319 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002320 *
2321 * @see #AXIS_TOOL_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002322 */
2323 public final float getToolMinor(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002324 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MINOR, pointerIndex, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002325 }
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002326
Jeff Brownc5ed5912010-07-14 18:48:53 -07002327 /**
2328 * Returns the orientation of the touch area and tool area in radians clockwise from vertical
2329 * for the given pointer <em>index</em> (use {@link #getPointerId(int)} to find the pointer
2330 * identifier for this index).
Jeff Brown6f2fba42011-02-19 01:08:02 -08002331 * An angle of 0 radians indicates that the major axis of contact is oriented
Jeff Brownc5ed5912010-07-14 18:48:53 -07002332 * upwards, is perfectly circular or is of unknown orientation. A positive angle
2333 * indicates that the major axis of contact is oriented to the right. A negative angle
2334 * indicates that the major axis of contact is oriented to the left.
Jeff Brown6d0fec22010-07-23 21:28:06 -07002335 * The full range is from -PI/2 radians (finger pointing fully left) to PI/2 radians
Jeff Brownc5ed5912010-07-14 18:48:53 -07002336 * (finger pointing fully right).
2337 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2338 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002339 *
2340 * @see #AXIS_ORIENTATION
Jeff Brownc5ed5912010-07-14 18:48:53 -07002341 */
2342 public final float getOrientation(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002343 return nativeGetAxisValue(mNativePtr, AXIS_ORIENTATION, pointerIndex, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002344 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08002345
2346 /**
2347 * Returns the value of the requested axis for the given pointer <em>index</em>
2348 * (use {@link #getPointerId(int)} to find the pointer identifier for this index).
2349 *
2350 * @param axis The axis identifier for the axis value to retrieve.
2351 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2352 * (the first pointer that is down) to {@link #getPointerCount()}-1.
2353 * @return The value of the axis, or 0 if the axis is not available.
2354 *
2355 * @see #AXIS_X
2356 * @see #AXIS_Y
2357 */
2358 public final float getAxisValue(int axis, int pointerIndex) {
2359 return nativeGetAxisValue(mNativePtr, axis, pointerIndex, HISTORY_CURRENT);
2360 }
2361
Jeff Brownc5ed5912010-07-14 18:48:53 -07002362 /**
2363 * Populates a {@link PointerCoords} object with pointer coordinate data for
2364 * the specified pointer index.
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002365 *
Jeff Brownc5ed5912010-07-14 18:48:53 -07002366 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2367 * (the first pointer that is down) to {@link #getPointerCount()}-1.
2368 * @param outPointerCoords The pointer coordinate object to populate.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002369 *
2370 * @see PointerCoords
Jeff Brownc5ed5912010-07-14 18:48:53 -07002371 */
2372 public final void getPointerCoords(int pointerIndex, PointerCoords outPointerCoords) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002373 nativeGetPointerCoords(mNativePtr, pointerIndex, HISTORY_CURRENT, outPointerCoords);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002374 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002375
2376 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07002377 * Populates a {@link PointerProperties} object with pointer properties for
2378 * the specified pointer index.
2379 *
2380 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2381 * (the first pointer that is down) to {@link #getPointerCount()}-1.
2382 * @param outPointerProperties The pointer properties object to populate.
2383 *
2384 * @see PointerProperties
2385 */
2386 public final void getPointerProperties(int pointerIndex,
2387 PointerProperties outPointerProperties) {
2388 nativeGetPointerProperties(mNativePtr, pointerIndex, outPointerProperties);
2389 }
2390
2391 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002392 * Returns the state of any meta / modifier keys that were in effect when
2393 * the event was generated. This is the same values as those
2394 * returned by {@link KeyEvent#getMetaState() KeyEvent.getMetaState}.
2395 *
2396 * @return an integer in which each bit set to 1 represents a pressed
2397 * meta key
2398 *
2399 * @see KeyEvent#getMetaState()
2400 */
2401 public final int getMetaState() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002402 return nativeGetMetaState(mNativePtr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002403 }
2404
2405 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07002406 * Gets the state of all buttons that are pressed such as a mouse or stylus button.
2407 *
2408 * @return The button state.
2409 *
2410 * @see #BUTTON_PRIMARY
2411 * @see #BUTTON_SECONDARY
2412 * @see #BUTTON_TERTIARY
2413 * @see #BUTTON_FORWARD
2414 * @see #BUTTON_BACK
Michael Wright5bd69e62015-05-14 14:48:08 +01002415 * @see #BUTTON_STYLUS_PRIMARY
2416 * @see #BUTTON_STYLUS_SECONDARY
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07002417 */
2418 public final int getButtonState() {
2419 return nativeGetButtonState(mNativePtr);
2420 }
2421
2422 /**
Michael Wright5bd69e62015-05-14 14:48:08 +01002423 * Sets the bitfield indicating which buttons are pressed.
2424 *
2425 * @see #getButtonState()
2426 * @hide
2427 */
Kirill Grouchnikovb2a44f02016-09-14 16:24:44 -07002428 @TestApi
Michael Wright5bd69e62015-05-14 14:48:08 +01002429 public final void setButtonState(int buttonState) {
2430 nativeSetButtonState(mNativePtr, buttonState);
2431 }
2432
2433 /**
2434 * Gets which button has been modified during a press or release action.
2435 *
2436 * For actions other than {@link #ACTION_BUTTON_PRESS} and {@link #ACTION_BUTTON_RELEASE}
2437 * the returned value is undefined.
2438 *
2439 * @see #getButtonState()
2440 */
2441 public final int getActionButton() {
2442 return nativeGetActionButton(mNativePtr);
2443 }
2444
2445 /**
Michael Wright6b819b42015-06-17 21:06:03 +01002446 * Sets the action button for the event.
2447 *
2448 * @see #getActionButton()
2449 * @hide
2450 */
Kirill Grouchnikovc0b0ba52016-09-13 16:09:37 -07002451 @TestApi
Michael Wright6b819b42015-06-17 21:06:03 +01002452 public final void setActionButton(int button) {
2453 nativeSetActionButton(mNativePtr, button);
2454 }
2455
2456 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002457 * Returns the original raw X coordinate of this event. For touch
2458 * events on the screen, this is the original location of the event
2459 * on the screen, before it had been adjusted for the containing window
2460 * and views.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002461 *
Michael Wright072137c2013-04-24 20:41:20 -07002462 * @see #getX(int)
Jeff Brown91c69ab2011-02-14 17:03:18 -08002463 * @see #AXIS_X
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002464 */
2465 public final float getRawX() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002466 return nativeGetRawAxisValue(mNativePtr, AXIS_X, 0, HISTORY_CURRENT);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002467 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08002468
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002469 /**
2470 * Returns the original raw Y coordinate of this event. For touch
2471 * events on the screen, this is the original location of the event
2472 * on the screen, before it had been adjusted for the containing window
2473 * and views.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002474 *
Michael Wright072137c2013-04-24 20:41:20 -07002475 * @see #getY(int)
Jeff Brown91c69ab2011-02-14 17:03:18 -08002476 * @see #AXIS_Y
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002477 */
2478 public final float getRawY() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002479 return nativeGetRawAxisValue(mNativePtr, AXIS_Y, 0, HISTORY_CURRENT);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002480 }
2481
2482 /**
2483 * Return the precision of the X coordinates being reported. You can
Jeff Brown91c69ab2011-02-14 17:03:18 -08002484 * multiply this number with {@link #getX} to find the actual hardware
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002485 * value of the X coordinate.
2486 * @return Returns the precision of X coordinates being reported.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002487 *
2488 * @see #AXIS_X
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002489 */
2490 public final float getXPrecision() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002491 return nativeGetXPrecision(mNativePtr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002492 }
Romain Guycafdea62009-06-12 10:51:36 -07002493
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002494 /**
2495 * Return the precision of the Y coordinates being reported. You can
Jeff Brown91c69ab2011-02-14 17:03:18 -08002496 * multiply this number with {@link #getY} to find the actual hardware
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002497 * value of the Y coordinate.
2498 * @return Returns the precision of Y coordinates being reported.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002499 *
2500 * @see #AXIS_Y
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002501 */
2502 public final float getYPrecision() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002503 return nativeGetYPrecision(mNativePtr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002504 }
Romain Guycafdea62009-06-12 10:51:36 -07002505
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002506 /**
2507 * Returns the number of historical points in this event. These are
2508 * movements that have occurred between this event and the previous event.
2509 * This only applies to ACTION_MOVE events -- all other actions will have
2510 * a size of 0.
Romain Guycafdea62009-06-12 10:51:36 -07002511 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002512 * @return Returns the number of historical points in the event.
2513 */
2514 public final int getHistorySize() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002515 return nativeGetHistorySize(mNativePtr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002516 }
Romain Guycafdea62009-06-12 10:51:36 -07002517
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002518 /**
2519 * Returns the time that a historical movement occurred between this event
Jeff Brownb11499d2012-04-20 19:54:22 -07002520 * and the previous event, in the {@link android.os.SystemClock#uptimeMillis} time base.
2521 * <p>
2522 * This only applies to ACTION_MOVE events.
2523 * </p>
Romain Guycafdea62009-06-12 10:51:36 -07002524 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002525 * @param pos Which historical value to return; must be less than
2526 * {@link #getHistorySize}
Jeff Brownb11499d2012-04-20 19:54:22 -07002527 * @return Returns the time that a historical movement occurred between this
2528 * event and the previous event,
2529 * in the {@link android.os.SystemClock#uptimeMillis} time base.
Romain Guycafdea62009-06-12 10:51:36 -07002530 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002531 * @see #getHistorySize
2532 * @see #getEventTime
2533 */
2534 public final long getHistoricalEventTime(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002535 return nativeGetEventTimeNanos(mNativePtr, pos) / NS_PER_MS;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002536 }
2537
2538 /**
Jeff Brownb11499d2012-04-20 19:54:22 -07002539 * Returns the time that a historical movement occurred between this event
2540 * and the previous event, in the {@link android.os.SystemClock#uptimeMillis} time base
2541 * but with nanosecond (instead of millisecond) precision.
2542 * <p>
2543 * This only applies to ACTION_MOVE events.
2544 * </p><p>
2545 * The value is in nanosecond precision but it may not have nanosecond accuracy.
2546 * </p>
2547 *
2548 * @param pos Which historical value to return; must be less than
2549 * {@link #getHistorySize}
2550 * @return Returns the time that a historical movement occurred between this
2551 * event and the previous event,
2552 * in the {@link android.os.SystemClock#uptimeMillis} time base but with
2553 * nanosecond (instead of millisecond) precision.
2554 *
2555 * @see #getHistorySize
2556 * @see #getEventTime
2557 *
2558 * @hide
2559 */
2560 public final long getHistoricalEventTimeNano(int pos) {
2561 return nativeGetEventTimeNanos(mNativePtr, pos);
2562 }
2563
2564 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08002565 * {@link #getHistoricalX(int, int)} for the first pointer index (may be an
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002566 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002567 *
2568 * @param pos Which historical value to return; must be less than
2569 * {@link #getHistorySize}
2570 *
2571 * @see #getHistorySize
2572 * @see #getX()
2573 * @see #AXIS_X
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002574 */
2575 public final float getHistoricalX(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002576 return nativeGetAxisValue(mNativePtr, AXIS_X, 0, pos);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002577 }
2578
2579 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08002580 * {@link #getHistoricalY(int, int)} for the first pointer index (may be an
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002581 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002582 *
2583 * @param pos Which historical value to return; must be less than
2584 * {@link #getHistorySize}
2585 *
2586 * @see #getHistorySize
2587 * @see #getY()
2588 * @see #AXIS_Y
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002589 */
2590 public final float getHistoricalY(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002591 return nativeGetAxisValue(mNativePtr, AXIS_Y, 0, pos);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002592 }
2593
2594 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08002595 * {@link #getHistoricalPressure(int, int)} for the first pointer index (may be an
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002596 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002597 *
2598 * @param pos Which historical value to return; must be less than
2599 * {@link #getHistorySize}
2600 *
2601 * @see #getHistorySize
2602 * @see #getPressure()
2603 * @see #AXIS_PRESSURE
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002604 */
2605 public final float getHistoricalPressure(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002606 return nativeGetAxisValue(mNativePtr, AXIS_PRESSURE, 0, pos);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002607 }
2608
2609 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08002610 * {@link #getHistoricalSize(int, int)} for the first pointer index (may be an
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002611 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002612 *
2613 * @param pos Which historical value to return; must be less than
2614 * {@link #getHistorySize}
2615 *
2616 * @see #getHistorySize
2617 * @see #getSize()
2618 * @see #AXIS_SIZE
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002619 */
2620 public final float getHistoricalSize(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002621 return nativeGetAxisValue(mNativePtr, AXIS_SIZE, 0, pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002622 }
Romain Guycafdea62009-06-12 10:51:36 -07002623
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002624 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08002625 * {@link #getHistoricalTouchMajor(int, int)} for the first pointer index (may be an
Jeff Brownc5ed5912010-07-14 18:48:53 -07002626 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002627 *
2628 * @param pos Which historical value to return; must be less than
2629 * {@link #getHistorySize}
2630 *
2631 * @see #getHistorySize
2632 * @see #getTouchMajor()
2633 * @see #AXIS_TOUCH_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002634 */
2635 public final float getHistoricalTouchMajor(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002636 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MAJOR, 0, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002637 }
2638
2639 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08002640 * {@link #getHistoricalTouchMinor(int, int)} for the first pointer index (may be an
Jeff Brownc5ed5912010-07-14 18:48:53 -07002641 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002642 *
2643 * @param pos Which historical value to return; must be less than
2644 * {@link #getHistorySize}
2645 *
2646 * @see #getHistorySize
2647 * @see #getTouchMinor()
2648 * @see #AXIS_TOUCH_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002649 */
2650 public final float getHistoricalTouchMinor(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002651 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MINOR, 0, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002652 }
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002653
Jeff Brownc5ed5912010-07-14 18:48:53 -07002654 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08002655 * {@link #getHistoricalToolMajor(int, int)} for the first pointer index (may be an
Jeff Brownc5ed5912010-07-14 18:48:53 -07002656 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002657 *
2658 * @param pos Which historical value to return; must be less than
2659 * {@link #getHistorySize}
2660 *
2661 * @see #getHistorySize
2662 * @see #getToolMajor()
2663 * @see #AXIS_TOOL_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002664 */
2665 public final float getHistoricalToolMajor(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002666 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MAJOR, 0, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002667 }
2668
2669 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08002670 * {@link #getHistoricalToolMinor(int, int)} for the first pointer index (may be an
Jeff Brownc5ed5912010-07-14 18:48:53 -07002671 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002672 *
2673 * @param pos Which historical value to return; must be less than
2674 * {@link #getHistorySize}
2675 *
2676 * @see #getHistorySize
2677 * @see #getToolMinor()
2678 * @see #AXIS_TOOL_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002679 */
2680 public final float getHistoricalToolMinor(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002681 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MINOR, 0, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002682 }
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002683
Jeff Brownc5ed5912010-07-14 18:48:53 -07002684 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08002685 * {@link #getHistoricalOrientation(int, int)} for the first pointer index (may be an
Jeff Brownc5ed5912010-07-14 18:48:53 -07002686 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002687 *
2688 * @param pos Which historical value to return; must be less than
2689 * {@link #getHistorySize}
2690 *
2691 * @see #getHistorySize
2692 * @see #getOrientation()
2693 * @see #AXIS_ORIENTATION
Jeff Brownc5ed5912010-07-14 18:48:53 -07002694 */
2695 public final float getHistoricalOrientation(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002696 return nativeGetAxisValue(mNativePtr, AXIS_ORIENTATION, 0, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002697 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08002698
2699 /**
2700 * {@link #getHistoricalAxisValue(int, int, int)} for the first pointer index (may be an
2701 * arbitrary pointer identifier).
2702 *
2703 * @param axis The axis identifier for the axis value to retrieve.
2704 * @param pos Which historical value to return; must be less than
2705 * {@link #getHistorySize}
2706 *
2707 * @see #getHistorySize
2708 * @see #getAxisValue(int)
2709 * @see #AXIS_X
2710 * @see #AXIS_Y
2711 */
2712 public final float getHistoricalAxisValue(int axis, int pos) {
2713 return nativeGetAxisValue(mNativePtr, axis, 0, pos);
2714 }
2715
Jeff Brownc5ed5912010-07-14 18:48:53 -07002716 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002717 * Returns a historical X coordinate, as per {@link #getX(int)}, that
2718 * occurred between this event and the previous event for the given pointer.
2719 * Only applies to ACTION_MOVE events.
Romain Guycafdea62009-06-12 10:51:36 -07002720 *
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002721 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2722 * (the first pointer that is down) to {@link #getPointerCount()}-1.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002723 * @param pos Which historical value to return; must be less than
2724 * {@link #getHistorySize}
Romain Guycafdea62009-06-12 10:51:36 -07002725 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002726 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08002727 * @see #getX(int)
2728 * @see #AXIS_X
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002729 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002730 public final float getHistoricalX(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002731 return nativeGetAxisValue(mNativePtr, AXIS_X, pointerIndex, pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002732 }
Romain Guycafdea62009-06-12 10:51:36 -07002733
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002734 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002735 * Returns a historical Y coordinate, as per {@link #getY(int)}, that
2736 * occurred between this event and the previous event for the given pointer.
2737 * Only applies to ACTION_MOVE events.
Romain Guycafdea62009-06-12 10:51:36 -07002738 *
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002739 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2740 * (the first pointer that is down) to {@link #getPointerCount()}-1.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002741 * @param pos Which historical value to return; must be less than
2742 * {@link #getHistorySize}
Romain Guycafdea62009-06-12 10:51:36 -07002743 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002744 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08002745 * @see #getY(int)
2746 * @see #AXIS_Y
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002747 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002748 public final float getHistoricalY(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002749 return nativeGetAxisValue(mNativePtr, AXIS_Y, pointerIndex, pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002750 }
Romain Guycafdea62009-06-12 10:51:36 -07002751
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002752 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002753 * Returns a historical pressure coordinate, as per {@link #getPressure(int)},
2754 * that occurred between this event and the previous event for the given
2755 * pointer. Only applies to ACTION_MOVE events.
Romain Guycafdea62009-06-12 10:51:36 -07002756 *
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002757 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2758 * (the first pointer that is down) to {@link #getPointerCount()}-1.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002759 * @param pos Which historical value to return; must be less than
2760 * {@link #getHistorySize}
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002761 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002762 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08002763 * @see #getPressure(int)
2764 * @see #AXIS_PRESSURE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002765 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002766 public final float getHistoricalPressure(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002767 return nativeGetAxisValue(mNativePtr, AXIS_PRESSURE, pointerIndex, pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002768 }
Romain Guycafdea62009-06-12 10:51:36 -07002769
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002770 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002771 * Returns a historical size coordinate, as per {@link #getSize(int)}, that
2772 * occurred between this event and the previous event for the given pointer.
2773 * Only applies to ACTION_MOVE events.
Romain Guycafdea62009-06-12 10:51:36 -07002774 *
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002775 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2776 * (the first pointer that is down) to {@link #getPointerCount()}-1.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002777 * @param pos Which historical value to return; must be less than
2778 * {@link #getHistorySize}
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002779 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002780 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08002781 * @see #getSize(int)
2782 * @see #AXIS_SIZE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002783 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002784 public final float getHistoricalSize(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002785 return nativeGetAxisValue(mNativePtr, AXIS_SIZE, pointerIndex, pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002786 }
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002787
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002788 /**
Jeff Brownc5ed5912010-07-14 18:48:53 -07002789 * Returns a historical touch major axis coordinate, as per {@link #getTouchMajor(int)}, that
2790 * occurred between this event and the previous event for the given pointer.
2791 * Only applies to ACTION_MOVE events.
2792 *
2793 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2794 * (the first pointer that is down) to {@link #getPointerCount()}-1.
2795 * @param pos Which historical value to return; must be less than
2796 * {@link #getHistorySize}
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002797 *
Jeff Brownc5ed5912010-07-14 18:48:53 -07002798 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08002799 * @see #getTouchMajor(int)
2800 * @see #AXIS_TOUCH_MAJOR
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002801 */
Jeff Brownc5ed5912010-07-14 18:48:53 -07002802 public final float getHistoricalTouchMajor(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002803 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MAJOR, pointerIndex, pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002804 }
Romain Guycafdea62009-06-12 10:51:36 -07002805
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002806 /**
Jeff Brownc5ed5912010-07-14 18:48:53 -07002807 * Returns a historical touch minor axis coordinate, as per {@link #getTouchMinor(int)}, that
2808 * occurred between this event and the previous event for the given pointer.
2809 * Only applies to ACTION_MOVE events.
2810 *
2811 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2812 * (the first pointer that is down) to {@link #getPointerCount()}-1.
2813 * @param pos Which historical value to return; must be less than
2814 * {@link #getHistorySize}
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002815 *
Jeff Brownc5ed5912010-07-14 18:48:53 -07002816 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08002817 * @see #getTouchMinor(int)
2818 * @see #AXIS_TOUCH_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002819 */
2820 public final float getHistoricalTouchMinor(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002821 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MINOR, pointerIndex, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002822 }
2823
2824 /**
2825 * Returns a historical tool major axis coordinate, as per {@link #getToolMajor(int)}, that
2826 * occurred between this event and the previous event for the given pointer.
2827 * Only applies to ACTION_MOVE events.
2828 *
2829 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2830 * (the first pointer that is down) to {@link #getPointerCount()}-1.
2831 * @param pos Which historical value to return; must be less than
2832 * {@link #getHistorySize}
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002833 *
Jeff Brownc5ed5912010-07-14 18:48:53 -07002834 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08002835 * @see #getToolMajor(int)
2836 * @see #AXIS_TOOL_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002837 */
2838 public final float getHistoricalToolMajor(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002839 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MAJOR, pointerIndex, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002840 }
2841
2842 /**
2843 * Returns a historical tool minor axis coordinate, as per {@link #getToolMinor(int)}, that
2844 * occurred between this event and the previous event for the given pointer.
2845 * Only applies to ACTION_MOVE events.
2846 *
2847 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2848 * (the first pointer that is down) to {@link #getPointerCount()}-1.
2849 * @param pos Which historical value to return; must be less than
2850 * {@link #getHistorySize}
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002851 *
Jeff Brownc5ed5912010-07-14 18:48:53 -07002852 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08002853 * @see #getToolMinor(int)
2854 * @see #AXIS_TOOL_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002855 */
2856 public final float getHistoricalToolMinor(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002857 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MINOR, pointerIndex, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002858 }
2859
2860 /**
2861 * Returns a historical orientation coordinate, as per {@link #getOrientation(int)}, that
2862 * occurred between this event and the previous event for the given pointer.
2863 * Only applies to ACTION_MOVE events.
2864 *
2865 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2866 * (the first pointer that is down) to {@link #getPointerCount()}-1.
2867 * @param pos Which historical value to return; must be less than
2868 * {@link #getHistorySize}
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002869 *
Jeff Brownc5ed5912010-07-14 18:48:53 -07002870 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08002871 * @see #getOrientation(int)
2872 * @see #AXIS_ORIENTATION
Jeff Brownc5ed5912010-07-14 18:48:53 -07002873 */
2874 public final float getHistoricalOrientation(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002875 return nativeGetAxisValue(mNativePtr, AXIS_ORIENTATION, pointerIndex, pos);
2876 }
2877
2878 /**
2879 * Returns the historical value of the requested axis, as per {@link #getAxisValue(int, int)},
2880 * occurred between this event and the previous event for the given pointer.
2881 * Only applies to ACTION_MOVE events.
2882 *
2883 * @param axis The axis identifier for the axis value to retrieve.
2884 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2885 * (the first pointer that is down) to {@link #getPointerCount()}-1.
2886 * @param pos Which historical value to return; must be less than
2887 * {@link #getHistorySize}
2888 * @return The value of the axis, or 0 if the axis is not available.
2889 *
2890 * @see #AXIS_X
2891 * @see #AXIS_Y
2892 */
2893 public final float getHistoricalAxisValue(int axis, int pointerIndex, int pos) {
2894 return nativeGetAxisValue(mNativePtr, axis, pointerIndex, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002895 }
2896
2897 /**
2898 * Populates a {@link PointerCoords} object with historical pointer coordinate data,
2899 * as per {@link #getPointerCoords}, that occurred between this event and the previous
2900 * event for the given pointer.
2901 * Only applies to ACTION_MOVE events.
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002902 *
Jeff Brownc5ed5912010-07-14 18:48:53 -07002903 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2904 * (the first pointer that is down) to {@link #getPointerCount()}-1.
2905 * @param pos Which historical value to return; must be less than
2906 * {@link #getHistorySize}
2907 * @param outPointerCoords The pointer coordinate object to populate.
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002908 *
Jeff Brownc5ed5912010-07-14 18:48:53 -07002909 * @see #getHistorySize
2910 * @see #getPointerCoords
Jeff Brown91c69ab2011-02-14 17:03:18 -08002911 * @see PointerCoords
Jeff Brownc5ed5912010-07-14 18:48:53 -07002912 */
2913 public final void getHistoricalPointerCoords(int pointerIndex, int pos,
2914 PointerCoords outPointerCoords) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002915 nativeGetPointerCoords(mNativePtr, pointerIndex, pos, outPointerCoords);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002916 }
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002917
Jeff Brownc5ed5912010-07-14 18:48:53 -07002918 /**
Jeff Brown46b9ac02010-04-22 18:58:52 -07002919 * Returns a bitfield indicating which edges, if any, were touched by this
Romain Guycafdea62009-06-12 10:51:36 -07002920 * MotionEvent. For touch events, clients can use this to determine if the
2921 * user's finger was touching the edge of the display.
2922 *
Jeff Brownd41cff22011-03-03 02:09:54 -08002923 * This property is only set for {@link #ACTION_DOWN} events.
2924 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002925 * @see #EDGE_LEFT
2926 * @see #EDGE_TOP
2927 * @see #EDGE_RIGHT
2928 * @see #EDGE_BOTTOM
2929 */
2930 public final int getEdgeFlags() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002931 return nativeGetEdgeFlags(mNativePtr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002932 }
Romain Guycafdea62009-06-12 10:51:36 -07002933
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002934 /**
Jeff Brown85a31762010-09-01 17:01:00 -07002935 * Sets the bitfield indicating which edges, if any, were touched by this
Romain Guycafdea62009-06-12 10:51:36 -07002936 * MotionEvent.
2937 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002938 * @see #getEdgeFlags()
2939 */
2940 public final void setEdgeFlags(int flags) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002941 nativeSetEdgeFlags(mNativePtr, flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002942 }
2943
2944 /**
2945 * Sets this event's action.
2946 */
2947 public final void setAction(int action) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002948 nativeSetAction(mNativePtr, action);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002949 }
2950
2951 /**
2952 * Adjust this event's location.
2953 * @param deltaX Amount to add to the current X coordinate of the event.
2954 * @param deltaY Amount to add to the current Y coordinate of the event.
2955 */
2956 public final void offsetLocation(float deltaX, float deltaY) {
Jeff Brown9ea77fc2012-03-21 19:49:27 -07002957 if (deltaX != 0.0f || deltaY != 0.0f) {
2958 nativeOffsetLocation(mNativePtr, deltaX, deltaY);
2959 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002960 }
Romain Guycafdea62009-06-12 10:51:36 -07002961
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002962 /**
2963 * Set this event's location. Applies {@link #offsetLocation} with a
2964 * delta from the current location to the given new location.
Romain Guycafdea62009-06-12 10:51:36 -07002965 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002966 * @param x New absolute X location.
2967 * @param y New absolute Y location.
2968 */
2969 public final void setLocation(float x, float y) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002970 float oldX = getX();
2971 float oldY = getY();
Jeff Brown9ea77fc2012-03-21 19:49:27 -07002972 offsetLocation(x - oldX, y - oldY);
Jeff Brown5c225b12010-06-16 01:53:36 -07002973 }
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002974
Jeff Brown20e987b2010-08-23 12:01:02 -07002975 /**
2976 * Applies a transformation matrix to all of the points in the event.
2977 *
2978 * @param matrix The transformation matrix to apply.
2979 */
2980 public final void transform(Matrix matrix) {
2981 if (matrix == null) {
2982 throw new IllegalArgumentException("matrix must not be null");
2983 }
2984
John Reck09709972016-10-03 15:47:18 -07002985 nativeTransform(mNativePtr, matrix.native_instance);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002986 }
Romain Guycafdea62009-06-12 10:51:36 -07002987
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002988 /**
2989 * Add a new movement to the batch of movements in this event. The event's
Jeff Brownc5ed5912010-07-14 18:48:53 -07002990 * current location, position and size is updated to the new values.
2991 * The current values in the event are added to a list of historical values.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002992 *
Jeff Browncc0c1592011-02-19 05:07:28 -08002993 * Only applies to {@link #ACTION_MOVE} or {@link #ACTION_HOVER_MOVE} events.
Romain Guycafdea62009-06-12 10:51:36 -07002994 *
Jeff Brownc5ed5912010-07-14 18:48:53 -07002995 * @param eventTime The time stamp (in ms) for this data.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002996 * @param x The new X position.
2997 * @param y The new Y position.
2998 * @param pressure The new pressure.
2999 * @param size The new size.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07003000 * @param metaState Meta key state.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003001 */
3002 public final void addBatch(long eventTime, float x, float y,
3003 float pressure, float size, int metaState) {
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003004 synchronized (gSharedTempLock) {
3005 ensureSharedTempPointerCapacity(1);
3006 final PointerCoords[] pc = gSharedTempPointerCoords;
3007 pc[0].clear();
3008 pc[0].x = x;
3009 pc[0].y = y;
3010 pc[0].pressure = pressure;
3011 pc[0].size = size;
3012
3013 nativeAddBatch(mNativePtr, eventTime * NS_PER_MS, pc, metaState);
Jeff Brown91c69ab2011-02-14 17:03:18 -08003014 }
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07003015 }
Romain Guycafdea62009-06-12 10:51:36 -07003016
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07003017 /**
Jeff Brownc5ed5912010-07-14 18:48:53 -07003018 * Add a new movement to the batch of movements in this event. The event's
3019 * current location, position and size is updated to the new values.
3020 * The current values in the event are added to a list of historical values.
Jeff Brown91c69ab2011-02-14 17:03:18 -08003021 *
Jeff Browncc0c1592011-02-19 05:07:28 -08003022 * Only applies to {@link #ACTION_MOVE} or {@link #ACTION_HOVER_MOVE} events.
Jeff Brownc5ed5912010-07-14 18:48:53 -07003023 *
3024 * @param eventTime The time stamp (in ms) for this data.
3025 * @param pointerCoords The new pointer coordinates.
3026 * @param metaState Meta key state.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07003027 */
Jeff Brownc5ed5912010-07-14 18:48:53 -07003028 public final void addBatch(long eventTime, PointerCoords[] pointerCoords, int metaState) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08003029 nativeAddBatch(mNativePtr, eventTime * NS_PER_MS, pointerCoords, metaState);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003030 }
Romain Guycafdea62009-06-12 10:51:36 -07003031
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003032 /**
Jeff Brown9d3bdbd2012-03-21 11:50:06 -07003033 * Adds all of the movement samples of the specified event to this one if
3034 * it is compatible. To be compatible, the event must have the same device id,
3035 * source, action, flags, pointer count, pointer properties.
3036 *
3037 * Only applies to {@link #ACTION_MOVE} or {@link #ACTION_HOVER_MOVE} events.
3038 *
3039 * @param event The event whose movements samples should be added to this one
3040 * if possible.
3041 * @return True if batching was performed or false if batching was not possible.
3042 * @hide
3043 */
Mathew Inwoode5ad5982018-08-17 15:07:52 +01003044 @UnsupportedAppUsage
Jeff Brown9d3bdbd2012-03-21 11:50:06 -07003045 public final boolean addBatch(MotionEvent event) {
3046 final int action = nativeGetAction(mNativePtr);
3047 if (action != ACTION_MOVE && action != ACTION_HOVER_MOVE) {
3048 return false;
3049 }
3050 if (action != nativeGetAction(event.mNativePtr)) {
3051 return false;
3052 }
3053
3054 if (nativeGetDeviceId(mNativePtr) != nativeGetDeviceId(event.mNativePtr)
3055 || nativeGetSource(mNativePtr) != nativeGetSource(event.mNativePtr)
3056 || nativeGetFlags(mNativePtr) != nativeGetFlags(event.mNativePtr)) {
3057 return false;
3058 }
3059
3060 final int pointerCount = nativeGetPointerCount(mNativePtr);
3061 if (pointerCount != nativeGetPointerCount(event.mNativePtr)) {
3062 return false;
3063 }
3064
3065 synchronized (gSharedTempLock) {
3066 ensureSharedTempPointerCapacity(Math.max(pointerCount, 2));
3067 final PointerProperties[] pp = gSharedTempPointerProperties;
3068 final PointerCoords[] pc = gSharedTempPointerCoords;
3069
3070 for (int i = 0; i < pointerCount; i++) {
3071 nativeGetPointerProperties(mNativePtr, i, pp[0]);
3072 nativeGetPointerProperties(event.mNativePtr, i, pp[1]);
3073 if (!pp[0].equals(pp[1])) {
3074 return false;
3075 }
3076 }
3077
3078 final int metaState = nativeGetMetaState(event.mNativePtr);
3079 final int historySize = nativeGetHistorySize(event.mNativePtr);
3080 for (int h = 0; h <= historySize; h++) {
3081 final int historyPos = (h == historySize ? HISTORY_CURRENT : h);
3082
3083 for (int i = 0; i < pointerCount; i++) {
3084 nativeGetPointerCoords(event.mNativePtr, i, historyPos, pc[i]);
3085 }
3086
3087 final long eventTimeNanos = nativeGetEventTimeNanos(event.mNativePtr, historyPos);
3088 nativeAddBatch(mNativePtr, eventTimeNanos, pc, metaState);
3089 }
3090 }
3091 return true;
3092 }
3093
3094 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003095 * Returns true if all points in the motion event are completely within the specified bounds.
3096 * @hide
3097 */
3098 public final boolean isWithinBoundsNoHistory(float left, float top,
3099 float right, float bottom) {
3100 final int pointerCount = nativeGetPointerCount(mNativePtr);
3101 for (int i = 0; i < pointerCount; i++) {
3102 final float x = nativeGetAxisValue(mNativePtr, AXIS_X, i, HISTORY_CURRENT);
3103 final float y = nativeGetAxisValue(mNativePtr, AXIS_Y, i, HISTORY_CURRENT);
3104 if (x < left || x > right || y < top || y > bottom) {
3105 return false;
3106 }
3107 }
3108 return true;
3109 }
3110
3111 private static final float clamp(float value, float low, float high) {
3112 if (value < low) {
3113 return low;
3114 } else if (value > high) {
3115 return high;
3116 }
3117 return value;
3118 }
3119
3120 /**
3121 * Returns a new motion events whose points have been clamped to the specified bounds.
3122 * @hide
3123 */
3124 public final MotionEvent clampNoHistory(float left, float top, float right, float bottom) {
3125 MotionEvent ev = obtain();
3126 synchronized (gSharedTempLock) {
3127 final int pointerCount = nativeGetPointerCount(mNativePtr);
3128
3129 ensureSharedTempPointerCapacity(pointerCount);
3130 final PointerProperties[] pp = gSharedTempPointerProperties;
3131 final PointerCoords[] pc = gSharedTempPointerCoords;
3132
3133 for (int i = 0; i < pointerCount; i++) {
3134 nativeGetPointerProperties(mNativePtr, i, pp[i]);
3135 nativeGetPointerCoords(mNativePtr, i, HISTORY_CURRENT, pc[i]);
3136 pc[i].x = clamp(pc[i].x, left, right);
3137 pc[i].y = clamp(pc[i].y, top, bottom);
3138 }
3139 ev.mNativePtr = nativeInitialize(ev.mNativePtr,
3140 nativeGetDeviceId(mNativePtr), nativeGetSource(mNativePtr),
3141 nativeGetAction(mNativePtr), nativeGetFlags(mNativePtr),
3142 nativeGetEdgeFlags(mNativePtr), nativeGetMetaState(mNativePtr),
3143 nativeGetButtonState(mNativePtr),
3144 nativeGetXOffset(mNativePtr), nativeGetYOffset(mNativePtr),
3145 nativeGetXPrecision(mNativePtr), nativeGetYPrecision(mNativePtr),
3146 nativeGetDownTimeNanos(mNativePtr),
3147 nativeGetEventTimeNanos(mNativePtr, HISTORY_CURRENT),
3148 pointerCount, pp, pc);
3149 return ev;
3150 }
3151 }
3152
3153 /**
3154 * Gets an integer where each pointer id present in the event is marked as a bit.
3155 * @hide
3156 */
Mathew Inwoode5ad5982018-08-17 15:07:52 +01003157 @UnsupportedAppUsage
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003158 public final int getPointerIdBits() {
3159 int idBits = 0;
3160 final int pointerCount = nativeGetPointerCount(mNativePtr);
3161 for (int i = 0; i < pointerCount; i++) {
3162 idBits |= 1 << nativeGetPointerId(mNativePtr, i);
3163 }
3164 return idBits;
3165 }
3166
3167 /**
3168 * Splits a motion event such that it includes only a subset of pointer ids.
3169 * @hide
3170 */
Mathew Inwoode5ad5982018-08-17 15:07:52 +01003171 @UnsupportedAppUsage
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003172 public final MotionEvent split(int idBits) {
3173 MotionEvent ev = obtain();
3174 synchronized (gSharedTempLock) {
3175 final int oldPointerCount = nativeGetPointerCount(mNativePtr);
3176 ensureSharedTempPointerCapacity(oldPointerCount);
3177 final PointerProperties[] pp = gSharedTempPointerProperties;
3178 final PointerCoords[] pc = gSharedTempPointerCoords;
3179 final int[] map = gSharedTempPointerIndexMap;
3180
3181 final int oldAction = nativeGetAction(mNativePtr);
3182 final int oldActionMasked = oldAction & ACTION_MASK;
3183 final int oldActionPointerIndex = (oldAction & ACTION_POINTER_INDEX_MASK)
3184 >> ACTION_POINTER_INDEX_SHIFT;
3185 int newActionPointerIndex = -1;
3186 int newPointerCount = 0;
3187 int newIdBits = 0;
3188 for (int i = 0; i < oldPointerCount; i++) {
3189 nativeGetPointerProperties(mNativePtr, i, pp[newPointerCount]);
3190 final int idBit = 1 << pp[newPointerCount].id;
3191 if ((idBit & idBits) != 0) {
3192 if (i == oldActionPointerIndex) {
3193 newActionPointerIndex = newPointerCount;
3194 }
3195 map[newPointerCount] = i;
3196 newPointerCount += 1;
3197 newIdBits |= idBit;
3198 }
3199 }
3200
3201 if (newPointerCount == 0) {
3202 throw new IllegalArgumentException("idBits did not match any ids in the event");
3203 }
3204
3205 final int newAction;
3206 if (oldActionMasked == ACTION_POINTER_DOWN || oldActionMasked == ACTION_POINTER_UP) {
3207 if (newActionPointerIndex < 0) {
3208 // An unrelated pointer changed.
3209 newAction = ACTION_MOVE;
3210 } else if (newPointerCount == 1) {
3211 // The first/last pointer went down/up.
3212 newAction = oldActionMasked == ACTION_POINTER_DOWN
3213 ? ACTION_DOWN : ACTION_UP;
3214 } else {
3215 // A secondary pointer went down/up.
3216 newAction = oldActionMasked
3217 | (newActionPointerIndex << ACTION_POINTER_INDEX_SHIFT);
3218 }
3219 } else {
3220 // Simple up/down/cancel/move or other motion action.
3221 newAction = oldAction;
3222 }
3223
3224 final int historySize = nativeGetHistorySize(mNativePtr);
3225 for (int h = 0; h <= historySize; h++) {
3226 final int historyPos = h == historySize ? HISTORY_CURRENT : h;
3227
3228 for (int i = 0; i < newPointerCount; i++) {
3229 nativeGetPointerCoords(mNativePtr, map[i], historyPos, pc[i]);
3230 }
3231
3232 final long eventTimeNanos = nativeGetEventTimeNanos(mNativePtr, historyPos);
3233 if (h == 0) {
3234 ev.mNativePtr = nativeInitialize(ev.mNativePtr,
3235 nativeGetDeviceId(mNativePtr), nativeGetSource(mNativePtr),
3236 newAction, nativeGetFlags(mNativePtr),
3237 nativeGetEdgeFlags(mNativePtr), nativeGetMetaState(mNativePtr),
3238 nativeGetButtonState(mNativePtr),
3239 nativeGetXOffset(mNativePtr), nativeGetYOffset(mNativePtr),
3240 nativeGetXPrecision(mNativePtr), nativeGetYPrecision(mNativePtr),
3241 nativeGetDownTimeNanos(mNativePtr), eventTimeNanos,
3242 newPointerCount, pp, pc);
3243 } else {
3244 nativeAddBatch(ev.mNativePtr, eventTimeNanos, pc, 0);
3245 }
3246 }
3247 return ev;
3248 }
3249 }
3250
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003251 @Override
3252 public String toString() {
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003253 StringBuilder msg = new StringBuilder();
3254 msg.append("MotionEvent { action=").append(actionToString(getAction()));
Eugene Suslae6e55b52018-01-11 15:12:56 -08003255 appendUnless("0", msg, ", actionButton=", buttonStateToString(getActionButton()));
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003256
3257 final int pointerCount = getPointerCount();
3258 for (int i = 0; i < pointerCount; i++) {
Eugene Suslae6e55b52018-01-11 15:12:56 -08003259 appendUnless(i, msg, ", id[" + i + "]=", getPointerId(i));
3260 float x = getX(i);
3261 float y = getY(i);
3262 if (!DEBUG_CONCISE_TOSTRING || x != 0f || y != 0f) {
3263 msg.append(", x[").append(i).append("]=").append(x);
3264 msg.append(", y[").append(i).append("]=").append(y);
3265 }
3266 appendUnless(TOOL_TYPE_SYMBOLIC_NAMES.get(TOOL_TYPE_FINGER),
3267 msg, ", toolType[" + i + "]=", toolTypeToString(getToolType(i)));
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003268 }
3269
Eugene Suslae6e55b52018-01-11 15:12:56 -08003270 appendUnless("0", msg, ", buttonState=", MotionEvent.buttonStateToString(getButtonState()));
3271 appendUnless("0", msg, ", metaState=", KeyEvent.metaStateToString(getMetaState()));
3272 appendUnless("0", msg, ", flags=0x", Integer.toHexString(getFlags()));
3273 appendUnless("0", msg, ", edgeFlags=0x", Integer.toHexString(getEdgeFlags()));
3274 appendUnless(1, msg, ", pointerCount=", pointerCount);
3275 appendUnless(0, msg, ", historySize=", getHistorySize());
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003276 msg.append(", eventTime=").append(getEventTime());
Eugene Suslae6e55b52018-01-11 15:12:56 -08003277 if (!DEBUG_CONCISE_TOSTRING) {
3278 msg.append(", downTime=").append(getDownTime());
3279 msg.append(", deviceId=").append(getDeviceId());
3280 msg.append(", source=0x").append(Integer.toHexString(getSource()));
3281 }
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003282 msg.append(" }");
3283 return msg.toString();
Jeff Brown497a92c2010-09-12 17:55:08 -07003284 }
3285
Eugene Suslae6e55b52018-01-11 15:12:56 -08003286 private static <T> void appendUnless(T defValue, StringBuilder sb, String key, T value) {
3287 if (DEBUG_CONCISE_TOSTRING && Objects.equals(defValue, value)) return;
3288 sb.append(key).append(value);
3289 }
3290
Jeff Brown497a92c2010-09-12 17:55:08 -07003291 /**
John Spurlock4dad6ca2013-06-05 13:17:05 -04003292 * Returns a string that represents the symbolic name of the specified unmasked action
Jeff Brown91c69ab2011-02-14 17:03:18 -08003293 * such as "ACTION_DOWN", "ACTION_POINTER_DOWN(3)" or an equivalent numeric constant
3294 * such as "35" if unknown.
Jeff Brown497a92c2010-09-12 17:55:08 -07003295 *
John Spurlock4dad6ca2013-06-05 13:17:05 -04003296 * @param action The unmasked action.
Jeff Brown497a92c2010-09-12 17:55:08 -07003297 * @return The symbolic name of the specified action.
John Spurlock4dad6ca2013-06-05 13:17:05 -04003298 * @see #getAction()
Jeff Brown497a92c2010-09-12 17:55:08 -07003299 */
3300 public static String actionToString(int action) {
3301 switch (action) {
3302 case ACTION_DOWN:
3303 return "ACTION_DOWN";
3304 case ACTION_UP:
3305 return "ACTION_UP";
3306 case ACTION_CANCEL:
3307 return "ACTION_CANCEL";
Jeff Brown33bbfd22011-02-24 20:55:35 -08003308 case ACTION_OUTSIDE:
3309 return "ACTION_OUTSIDE";
Jeff Brown497a92c2010-09-12 17:55:08 -07003310 case ACTION_MOVE:
3311 return "ACTION_MOVE";
Jeff Browncc0c1592011-02-19 05:07:28 -08003312 case ACTION_HOVER_MOVE:
3313 return "ACTION_HOVER_MOVE";
Jeff Brown33bbfd22011-02-24 20:55:35 -08003314 case ACTION_SCROLL:
3315 return "ACTION_SCROLL";
Jeff Browna032cc02011-03-07 16:56:21 -08003316 case ACTION_HOVER_ENTER:
3317 return "ACTION_HOVER_ENTER";
3318 case ACTION_HOVER_EXIT:
3319 return "ACTION_HOVER_EXIT";
Michael Wright5bd69e62015-05-14 14:48:08 +01003320 case ACTION_BUTTON_PRESS:
3321 return "ACTION_BUTTON_PRESS";
3322 case ACTION_BUTTON_RELEASE:
3323 return "ACTION_BUTTON_RELEASE";
Jeff Brown497a92c2010-09-12 17:55:08 -07003324 }
3325 int index = (action & ACTION_POINTER_INDEX_MASK) >> ACTION_POINTER_INDEX_SHIFT;
3326 switch (action & ACTION_MASK) {
3327 case ACTION_POINTER_DOWN:
3328 return "ACTION_POINTER_DOWN(" + index + ")";
3329 case ACTION_POINTER_UP:
3330 return "ACTION_POINTER_UP(" + index + ")";
3331 default:
3332 return Integer.toString(action);
3333 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003334 }
3335
Jeff Brown91c69ab2011-02-14 17:03:18 -08003336 /**
3337 * Returns a string that represents the symbolic name of the specified axis
Jeff Brown6f2fba42011-02-19 01:08:02 -08003338 * such as "AXIS_X" or an equivalent numeric constant such as "42" if unknown.
Jeff Brown91c69ab2011-02-14 17:03:18 -08003339 *
John Spurlock4dad6ca2013-06-05 13:17:05 -04003340 * @param axis The axis.
Jeff Brown91c69ab2011-02-14 17:03:18 -08003341 * @return The symbolic name of the specified axis.
Jeff Brown91c69ab2011-02-14 17:03:18 -08003342 */
3343 public static String axisToString(int axis) {
Michael Wright337d9d22014-04-22 15:03:48 -07003344 String symbolicName = nativeAxisToString(axis);
3345 return symbolicName != null ? LABEL_PREFIX + symbolicName : Integer.toString(axis);
Jeff Brown6f2fba42011-02-19 01:08:02 -08003346 }
3347
3348 /**
Jeff Browncc0c1592011-02-19 05:07:28 -08003349 * Gets an axis by its symbolic name such as "AXIS_X" or an
3350 * equivalent numeric constant such as "42".
Jeff Brown6f2fba42011-02-19 01:08:02 -08003351 *
3352 * @param symbolicName The symbolic name of the axis.
3353 * @return The axis or -1 if not found.
John Spurlock4dad6ca2013-06-05 13:17:05 -04003354 * @see KeyEvent#keyCodeToString(int)
Jeff Brown6f2fba42011-02-19 01:08:02 -08003355 */
3356 public static int axisFromString(String symbolicName) {
Michael Wright337d9d22014-04-22 15:03:48 -07003357 if (symbolicName.startsWith(LABEL_PREFIX)) {
3358 symbolicName = symbolicName.substring(LABEL_PREFIX.length());
Michael Wright973efa02014-05-13 15:38:56 -07003359 int axis = nativeAxisFromString(symbolicName);
3360 if (axis >= 0) {
3361 return axis;
3362 }
Jeff Brown6f2fba42011-02-19 01:08:02 -08003363 }
Jeff Brown6f2fba42011-02-19 01:08:02 -08003364 try {
3365 return Integer.parseInt(symbolicName, 10);
3366 } catch (NumberFormatException ex) {
3367 return -1;
Jeff Brown91c69ab2011-02-14 17:03:18 -08003368 }
3369 }
3370
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003371 /**
3372 * Returns a string that represents the symbolic name of the specified combined
3373 * button state flags such as "0", "BUTTON_PRIMARY",
3374 * "BUTTON_PRIMARY|BUTTON_SECONDARY" or an equivalent numeric constant such as "0x10000000"
3375 * if unknown.
3376 *
3377 * @param buttonState The button state.
3378 * @return The symbolic name of the specified combined button state flags.
3379 * @hide
3380 */
3381 public static String buttonStateToString(int buttonState) {
3382 if (buttonState == 0) {
3383 return "0";
3384 }
3385 StringBuilder result = null;
3386 int i = 0;
3387 while (buttonState != 0) {
3388 final boolean isSet = (buttonState & 1) != 0;
3389 buttonState >>>= 1; // unsigned shift!
3390 if (isSet) {
3391 final String name = BUTTON_SYMBOLIC_NAMES[i];
3392 if (result == null) {
3393 if (buttonState == 0) {
3394 return name;
3395 }
3396 result = new StringBuilder(name);
3397 } else {
3398 result.append('|');
3399 result.append(name);
3400 }
3401 }
3402 i += 1;
3403 }
3404 return result.toString();
3405 }
3406
3407 /**
3408 * Returns a string that represents the symbolic name of the specified tool type
3409 * such as "TOOL_TYPE_FINGER" or an equivalent numeric constant such as "42" if unknown.
3410 *
3411 * @param toolType The tool type.
3412 * @return The symbolic name of the specified tool type.
3413 * @hide
3414 */
3415 public static String toolTypeToString(int toolType) {
3416 String symbolicName = TOOL_TYPE_SYMBOLIC_NAMES.get(toolType);
3417 return symbolicName != null ? symbolicName : Integer.toString(toolType);
3418 }
3419
Sujith Ramakrishnancc32bd82014-05-19 15:32:13 -07003420 /**
3421 * Checks if a mouse or stylus button (or combination of buttons) is pressed.
3422 * @param button Button (or combination of buttons).
3423 * @return True if specified buttons are pressed.
3424 *
3425 * @see #BUTTON_PRIMARY
3426 * @see #BUTTON_SECONDARY
3427 * @see #BUTTON_TERTIARY
3428 * @see #BUTTON_FORWARD
3429 * @see #BUTTON_BACK
Michael Wright5bd69e62015-05-14 14:48:08 +01003430 * @see #BUTTON_STYLUS_PRIMARY
3431 * @see #BUTTON_STYLUS_SECONDARY
Sujith Ramakrishnancc32bd82014-05-19 15:32:13 -07003432 */
3433 public final boolean isButtonPressed(int button) {
3434 if (button == 0) {
3435 return false;
3436 }
3437 return (getButtonState() & button) == button;
3438 }
3439
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003440 public static final Parcelable.Creator<MotionEvent> CREATOR
3441 = new Parcelable.Creator<MotionEvent>() {
3442 public MotionEvent createFromParcel(Parcel in) {
Jeff Brown6ec402b2010-07-28 15:48:59 -07003443 in.readInt(); // skip token, we already know this is a MotionEvent
3444 return MotionEvent.createFromParcelBody(in);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003445 }
3446
3447 public MotionEvent[] newArray(int size) {
3448 return new MotionEvent[size];
3449 }
3450 };
3451
Jeff Brown6ec402b2010-07-28 15:48:59 -07003452 /** @hide */
3453 public static MotionEvent createFromParcelBody(Parcel in) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08003454 MotionEvent ev = obtain();
3455 ev.mNativePtr = nativeReadFromParcel(ev.mNativePtr, in);
Jeff Brown6ec402b2010-07-28 15:48:59 -07003456 return ev;
3457 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08003458
Wale Ogunwalec3672cd2014-11-05 15:17:35 -08003459 /** @hide */
3460 @Override
3461 public final void cancel() {
3462 setAction(ACTION_CANCEL);
3463 }
3464
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003465 public void writeToParcel(Parcel out, int flags) {
Jeff Brown6ec402b2010-07-28 15:48:59 -07003466 out.writeInt(PARCEL_TOKEN_MOTION_EVENT);
Jeff Brown91c69ab2011-02-14 17:03:18 -08003467 nativeWriteToParcel(mNativePtr, out);
Jeff Brown5c225b12010-06-16 01:53:36 -07003468 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08003469
Jeff Brownc5ed5912010-07-14 18:48:53 -07003470 /**
3471 * Transfer object for pointer coordinates.
Dennis Kempinac1b31d2016-11-02 17:02:25 -07003472 *
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003473 * Objects of this type can be used to specify the pointer coordinates when
3474 * creating new {@link MotionEvent} objects and to query pointer coordinates
3475 * in bulk.
Dennis Kempinac1b31d2016-11-02 17:02:25 -07003476 *
Jeff Brownc5ed5912010-07-14 18:48:53 -07003477 * Refer to {@link InputDevice} for information about how different kinds of
3478 * input devices and sources represent pointer coordinates.
3479 */
3480 public static final class PointerCoords {
Jeff Brown91c69ab2011-02-14 17:03:18 -08003481 private static final int INITIAL_PACKED_AXIS_VALUES = 8;
Mathew Inwoode5ad5982018-08-17 15:07:52 +01003482 @UnsupportedAppUsage
Jeff Brown6f2fba42011-02-19 01:08:02 -08003483 private long mPackedAxisBits;
Mathew Inwoode5ad5982018-08-17 15:07:52 +01003484 @UnsupportedAppUsage
Jeff Brown91c69ab2011-02-14 17:03:18 -08003485 private float[] mPackedAxisValues;
3486
3487 /**
3488 * Creates a pointer coords object with all axes initialized to zero.
3489 */
3490 public PointerCoords() {
3491 }
3492
3493 /**
3494 * Creates a pointer coords object as a copy of the
3495 * contents of another pointer coords object.
3496 *
3497 * @param other The pointer coords object to copy.
3498 */
3499 public PointerCoords(PointerCoords other) {
3500 copyFrom(other);
3501 }
3502
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003503 /** @hide */
Mathew Inwoode5ad5982018-08-17 15:07:52 +01003504 @UnsupportedAppUsage
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003505 public static PointerCoords[] createArray(int size) {
3506 PointerCoords[] array = new PointerCoords[size];
3507 for (int i = 0; i < size; i++) {
3508 array[i] = new PointerCoords();
3509 }
3510 return array;
3511 }
3512
Jeff Brownc5ed5912010-07-14 18:48:53 -07003513 /**
Jeff Brown6f2fba42011-02-19 01:08:02 -08003514 * The X component of the pointer movement.
Jeff Brown91c69ab2011-02-14 17:03:18 -08003515 *
3516 * @see MotionEvent#AXIS_X
Jeff Brownc5ed5912010-07-14 18:48:53 -07003517 */
3518 public float x;
Dennis Kempinac1b31d2016-11-02 17:02:25 -07003519
Jeff Brownc5ed5912010-07-14 18:48:53 -07003520 /**
Jeff Brown6f2fba42011-02-19 01:08:02 -08003521 * The Y component of the pointer movement.
Jeff Brown91c69ab2011-02-14 17:03:18 -08003522 *
3523 * @see MotionEvent#AXIS_Y
Jeff Brownc5ed5912010-07-14 18:48:53 -07003524 */
3525 public float y;
Dennis Kempinac1b31d2016-11-02 17:02:25 -07003526
Jeff Brownc5ed5912010-07-14 18:48:53 -07003527 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08003528 * A normalized value that describes the pressure applied to the device
3529 * by a finger or other tool.
Jeff Brownc5ed5912010-07-14 18:48:53 -07003530 * The pressure generally ranges from 0 (no pressure at all) to 1 (normal pressure),
Jeff Brown91c69ab2011-02-14 17:03:18 -08003531 * although values higher than 1 may be generated depending on the calibration of
Jeff Brownc5ed5912010-07-14 18:48:53 -07003532 * the input device.
Jeff Brown91c69ab2011-02-14 17:03:18 -08003533 *
3534 * @see MotionEvent#AXIS_PRESSURE
Jeff Brownc5ed5912010-07-14 18:48:53 -07003535 */
3536 public float pressure;
Dennis Kempinac1b31d2016-11-02 17:02:25 -07003537
Jeff Brownc5ed5912010-07-14 18:48:53 -07003538 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08003539 * A normalized value that describes the approximate size of the pointer touch area
3540 * in relation to the maximum detectable size of the device.
3541 * It represents some approximation of the area of the screen being
Jeff Brownc5ed5912010-07-14 18:48:53 -07003542 * pressed; the actual value in pixels corresponding to the
3543 * touch is normalized with the device specific range of values
3544 * and scaled to a value between 0 and 1. The value of size can be used to
3545 * determine fat touch events.
Jeff Brown91c69ab2011-02-14 17:03:18 -08003546 *
3547 * @see MotionEvent#AXIS_SIZE
Jeff Brownc5ed5912010-07-14 18:48:53 -07003548 */
3549 public float size;
Dennis Kempinac1b31d2016-11-02 17:02:25 -07003550
Jeff Brownc5ed5912010-07-14 18:48:53 -07003551 /**
3552 * The length of the major axis of an ellipse that describes the touch area at
3553 * the point of contact.
Jeff Brown91c69ab2011-02-14 17:03:18 -08003554 * If the device is a touch screen, the length is reported in pixels, otherwise it is
3555 * reported in device-specific units.
3556 *
3557 * @see MotionEvent#AXIS_TOUCH_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07003558 */
3559 public float touchMajor;
Dennis Kempinac1b31d2016-11-02 17:02:25 -07003560
Jeff Brownc5ed5912010-07-14 18:48:53 -07003561 /**
3562 * The length of the minor axis of an ellipse that describes the touch area at
3563 * the point of contact.
Jeff Brown91c69ab2011-02-14 17:03:18 -08003564 * If the device is a touch screen, the length is reported in pixels, otherwise it is
3565 * reported in device-specific units.
3566 *
3567 * @see MotionEvent#AXIS_TOUCH_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07003568 */
3569 public float touchMinor;
Dennis Kempinac1b31d2016-11-02 17:02:25 -07003570
Jeff Brownc5ed5912010-07-14 18:48:53 -07003571 /**
3572 * The length of the major axis of an ellipse that describes the size of
3573 * the approaching tool.
3574 * The tool area represents the estimated size of the finger or pen that is
3575 * touching the device independent of its actual touch area at the point of contact.
Jeff Brown91c69ab2011-02-14 17:03:18 -08003576 * If the device is a touch screen, the length is reported in pixels, otherwise it is
3577 * reported in device-specific units.
3578 *
3579 * @see MotionEvent#AXIS_TOOL_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07003580 */
3581 public float toolMajor;
Dennis Kempinac1b31d2016-11-02 17:02:25 -07003582
Jeff Brownc5ed5912010-07-14 18:48:53 -07003583 /**
3584 * The length of the minor axis of an ellipse that describes the size of
3585 * the approaching tool.
3586 * The tool area represents the estimated size of the finger or pen that is
3587 * touching the device independent of its actual touch area at the point of contact.
Jeff Brown91c69ab2011-02-14 17:03:18 -08003588 * If the device is a touch screen, the length is reported in pixels, otherwise it is
3589 * reported in device-specific units.
3590 *
3591 * @see MotionEvent#AXIS_TOOL_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07003592 */
3593 public float toolMinor;
Dennis Kempinac1b31d2016-11-02 17:02:25 -07003594
Jeff Brownc5ed5912010-07-14 18:48:53 -07003595 /**
3596 * The orientation of the touch area and tool area in radians clockwise from vertical.
Jeff Brown6f2fba42011-02-19 01:08:02 -08003597 * An angle of 0 radians indicates that the major axis of contact is oriented
Jeff Brownc5ed5912010-07-14 18:48:53 -07003598 * upwards, is perfectly circular or is of unknown orientation. A positive angle
3599 * indicates that the major axis of contact is oriented to the right. A negative angle
3600 * indicates that the major axis of contact is oriented to the left.
Jeff Brown6d0fec22010-07-23 21:28:06 -07003601 * The full range is from -PI/2 radians (finger pointing fully left) to PI/2 radians
Jeff Brownc5ed5912010-07-14 18:48:53 -07003602 * (finger pointing fully right).
Jeff Brown91c69ab2011-02-14 17:03:18 -08003603 *
3604 * @see MotionEvent#AXIS_ORIENTATION
Jeff Brownc5ed5912010-07-14 18:48:53 -07003605 */
3606 public float orientation;
Jeff Brown91c69ab2011-02-14 17:03:18 -08003607
3608 /**
3609 * Clears the contents of this object.
3610 * Resets all axes to zero.
3611 */
3612 public void clear() {
3613 mPackedAxisBits = 0;
3614
3615 x = 0;
3616 y = 0;
3617 pressure = 0;
3618 size = 0;
3619 touchMajor = 0;
3620 touchMinor = 0;
3621 toolMajor = 0;
3622 toolMinor = 0;
3623 orientation = 0;
Jeff Brownc5ed5912010-07-14 18:48:53 -07003624 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08003625
3626 /**
3627 * Copies the contents of another pointer coords object.
3628 *
3629 * @param other The pointer coords object to copy.
3630 */
3631 public void copyFrom(PointerCoords other) {
Jeff Brown6f2fba42011-02-19 01:08:02 -08003632 final long bits = other.mPackedAxisBits;
Jeff Brown91c69ab2011-02-14 17:03:18 -08003633 mPackedAxisBits = bits;
3634 if (bits != 0) {
3635 final float[] otherValues = other.mPackedAxisValues;
Jeff Brown6f2fba42011-02-19 01:08:02 -08003636 final int count = Long.bitCount(bits);
Jeff Brown91c69ab2011-02-14 17:03:18 -08003637 float[] values = mPackedAxisValues;
3638 if (values == null || count > values.length) {
3639 values = new float[otherValues.length];
3640 mPackedAxisValues = values;
3641 }
3642 System.arraycopy(otherValues, 0, values, 0, count);
3643 }
3644
3645 x = other.x;
3646 y = other.y;
3647 pressure = other.pressure;
3648 size = other.size;
3649 touchMajor = other.touchMajor;
3650 touchMinor = other.touchMinor;
3651 toolMajor = other.toolMajor;
3652 toolMinor = other.toolMinor;
3653 orientation = other.orientation;
Jeff Brownc5ed5912010-07-14 18:48:53 -07003654 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08003655
3656 /**
3657 * Gets the value associated with the specified axis.
3658 *
3659 * @param axis The axis identifier for the axis value to retrieve.
3660 * @return The value associated with the axis, or 0 if none.
3661 *
3662 * @see MotionEvent#AXIS_X
3663 * @see MotionEvent#AXIS_Y
3664 */
3665 public float getAxisValue(int axis) {
3666 switch (axis) {
3667 case AXIS_X:
3668 return x;
3669 case AXIS_Y:
3670 return y;
3671 case AXIS_PRESSURE:
3672 return pressure;
3673 case AXIS_SIZE:
3674 return size;
3675 case AXIS_TOUCH_MAJOR:
3676 return touchMajor;
3677 case AXIS_TOUCH_MINOR:
3678 return touchMinor;
3679 case AXIS_TOOL_MAJOR:
3680 return toolMajor;
3681 case AXIS_TOOL_MINOR:
3682 return toolMinor;
3683 case AXIS_ORIENTATION:
3684 return orientation;
3685 default: {
Jeff Brown6f2fba42011-02-19 01:08:02 -08003686 if (axis < 0 || axis > 63) {
3687 throw new IllegalArgumentException("Axis out of range.");
3688 }
3689 final long bits = mPackedAxisBits;
Michael Wright9adca062014-03-19 11:51:26 -07003690 final long axisBit = 0x8000000000000000L >>> axis;
Jeff Brown91c69ab2011-02-14 17:03:18 -08003691 if ((bits & axisBit) == 0) {
3692 return 0;
3693 }
Michael Wright9adca062014-03-19 11:51:26 -07003694 final int index = Long.bitCount(bits & ~(0xFFFFFFFFFFFFFFFFL >>> axis));
Jeff Brown91c69ab2011-02-14 17:03:18 -08003695 return mPackedAxisValues[index];
3696 }
3697 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07003698 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08003699
3700 /**
3701 * Sets the value associated with the specified axis.
3702 *
3703 * @param axis The axis identifier for the axis value to assign.
3704 * @param value The value to set.
3705 *
3706 * @see MotionEvent#AXIS_X
3707 * @see MotionEvent#AXIS_Y
3708 */
3709 public void setAxisValue(int axis, float value) {
3710 switch (axis) {
3711 case AXIS_X:
3712 x = value;
3713 break;
3714 case AXIS_Y:
3715 y = value;
3716 break;
3717 case AXIS_PRESSURE:
3718 pressure = value;
3719 break;
3720 case AXIS_SIZE:
3721 size = value;
3722 break;
3723 case AXIS_TOUCH_MAJOR:
3724 touchMajor = value;
3725 break;
3726 case AXIS_TOUCH_MINOR:
3727 touchMinor = value;
3728 break;
3729 case AXIS_TOOL_MAJOR:
3730 toolMajor = value;
3731 break;
3732 case AXIS_TOOL_MINOR:
3733 toolMinor = value;
3734 break;
3735 case AXIS_ORIENTATION:
3736 orientation = value;
3737 break;
3738 default: {
Jeff Brown6f2fba42011-02-19 01:08:02 -08003739 if (axis < 0 || axis > 63) {
3740 throw new IllegalArgumentException("Axis out of range.");
3741 }
3742 final long bits = mPackedAxisBits;
Michael Wright9adca062014-03-19 11:51:26 -07003743 final long axisBit = 0x8000000000000000L >>> axis;
3744 final int index = Long.bitCount(bits & ~(0xFFFFFFFFFFFFFFFFL >>> axis));
Jeff Brown91c69ab2011-02-14 17:03:18 -08003745 float[] values = mPackedAxisValues;
3746 if ((bits & axisBit) == 0) {
3747 if (values == null) {
3748 values = new float[INITIAL_PACKED_AXIS_VALUES];
3749 mPackedAxisValues = values;
3750 } else {
Jeff Brown6f2fba42011-02-19 01:08:02 -08003751 final int count = Long.bitCount(bits);
Jeff Brown91c69ab2011-02-14 17:03:18 -08003752 if (count < values.length) {
3753 if (index != count) {
3754 System.arraycopy(values, index, values, index + 1,
3755 count - index);
3756 }
3757 } else {
3758 float[] newValues = new float[count * 2];
3759 System.arraycopy(values, 0, newValues, 0, index);
3760 System.arraycopy(values, index, newValues, index + 1,
3761 count - index);
3762 values = newValues;
3763 mPackedAxisValues = values;
3764 }
3765 }
3766 mPackedAxisBits = bits | axisBit;
3767 }
3768 values[index] = value;
3769 }
3770 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07003771 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07003772 }
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003773
3774 /**
3775 * Transfer object for pointer properties.
3776 *
3777 * Objects of this type can be used to specify the pointer id and tool type
3778 * when creating new {@link MotionEvent} objects and to query pointer properties in bulk.
3779 */
3780 public static final class PointerProperties {
3781 /**
3782 * Creates a pointer properties object with an invalid pointer id.
3783 */
3784 public PointerProperties() {
3785 clear();
3786 }
3787
3788 /**
3789 * Creates a pointer properties object as a copy of the contents of
3790 * another pointer properties object.
3791 * @param other
3792 */
3793 public PointerProperties(PointerProperties other) {
3794 copyFrom(other);
3795 }
3796
3797 /** @hide */
Mathew Inwoode5ad5982018-08-17 15:07:52 +01003798 @UnsupportedAppUsage
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003799 public static PointerProperties[] createArray(int size) {
3800 PointerProperties[] array = new PointerProperties[size];
3801 for (int i = 0; i < size; i++) {
3802 array[i] = new PointerProperties();
3803 }
3804 return array;
3805 }
3806
3807 /**
3808 * The pointer id.
3809 * Initially set to {@link #INVALID_POINTER_ID} (-1).
3810 *
3811 * @see MotionEvent#getPointerId(int)
3812 */
3813 public int id;
3814
3815 /**
3816 * The pointer tool type.
3817 * Initially set to 0.
3818 *
3819 * @see MotionEvent#getToolType(int)
3820 */
3821 public int toolType;
3822
3823 /**
3824 * Resets the pointer properties to their initial values.
3825 */
3826 public void clear() {
3827 id = INVALID_POINTER_ID;
3828 toolType = TOOL_TYPE_UNKNOWN;
3829 }
3830
3831 /**
3832 * Copies the contents of another pointer properties object.
3833 *
3834 * @param other The pointer properties object to copy.
3835 */
3836 public void copyFrom(PointerProperties other) {
3837 id = other.id;
3838 toolType = other.toolType;
3839 }
Jeff Brown9d3bdbd2012-03-21 11:50:06 -07003840
3841 @Override
3842 public boolean equals(Object other) {
3843 if (other instanceof PointerProperties) {
3844 return equals((PointerProperties)other);
3845 }
3846 return false;
3847 }
3848
3849 private boolean equals(PointerProperties other) {
3850 return other != null && id == other.id && toolType == other.toolType;
3851 }
3852
3853 @Override
3854 public int hashCode() {
3855 return id | (toolType << 8);
3856 }
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003857 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003858}