blob: b6c4cbbbe54de113b38e177bdb13fbd99e696893 [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
Siarhei Vishniakou85ddfff2018-01-31 16:49:36 -080019import static android.view.Display.DEFAULT_DISPLAY;
20
Siarhei Vishniakoub05b0b52018-12-28 17:50:24 -080021import static java.lang.annotation.RetentionPolicy.SOURCE;
22
23import android.annotation.IntDef;
Kirill Grouchnikovc0b0ba52016-09-13 16:09:37 -070024import android.annotation.TestApi;
Mathew Inwooda570dee2018-08-17 14:56:00 +010025import android.annotation.UnsupportedAppUsage;
Jeff Brown20e987b2010-08-23 12:01:02 -070026import android.graphics.Matrix;
George Mountbbc84a82019-02-08 09:58:45 -080027import android.os.Build;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028import android.os.Parcel;
29import android.os.Parcelable;
30import android.os.SystemClock;
Siarhei Vishniakou85ddfff2018-01-31 16:49:36 -080031import android.util.Log;
Jeff Brown6f2fba42011-02-19 01:08:02 -080032import android.util.SparseArray;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033
John Reck09709972016-10-03 15:47:18 -070034import dalvik.annotation.optimization.CriticalNative;
35import dalvik.annotation.optimization.FastNative;
36
Siarhei Vishniakoub05b0b52018-12-28 17:50:24 -080037import java.lang.annotation.Retention;
Eugene Suslae6e55b52018-01-11 15:12:56 -080038import java.util.Objects;
39
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040/**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -070041 * Object used to report movement (mouse, pen, finger, trackball) events.
42 * Motion events may hold either absolute or relative movements and other data,
43 * depending on the type of device.
44 *
45 * <h3>Overview</h3>
Jeff Browndc1ab4b2010-09-14 18:03:38 -070046 * <p>
Jeff Brownfe9f8ab2011-05-06 18:20:01 -070047 * Motion events describe movements in terms of an action code and a set of axis values.
48 * The action code specifies the state change that occurred such as a pointer going
49 * down or up. The axis values describe the position and other movement properties.
50 * </p><p>
51 * For example, when the user first touches the screen, the system delivers a touch
52 * event to the appropriate {@link View} with the action code {@link #ACTION_DOWN}
53 * and a set of axis values that include the X and Y coordinates of the touch and
54 * information about the pressure, size and orientation of the contact area.
55 * </p><p>
56 * Some devices can report multiple movement traces at the same time. Multi-touch
57 * screens emit one movement trace for each finger. The individual fingers or
58 * other objects that generate movement traces are referred to as <em>pointers</em>.
59 * Motion events contain information about all of the pointers that are currently active
60 * even if some of them have not moved since the last event was delivered.
61 * </p><p>
62 * The number of pointers only ever changes by one as individual pointers go up and down,
63 * except when the gesture is canceled.
64 * </p><p>
65 * Each pointer has a unique id that is assigned when it first goes down
66 * (indicated by {@link #ACTION_DOWN} or {@link #ACTION_POINTER_DOWN}). A pointer id
67 * remains valid until the pointer eventually goes up (indicated by {@link #ACTION_UP}
68 * or {@link #ACTION_POINTER_UP}) or when the gesture is canceled (indicated by
69 * {@link #ACTION_CANCEL}).
70 * </p><p>
71 * The MotionEvent class provides many methods to query the position and other properties of
72 * pointers, such as {@link #getX(int)}, {@link #getY(int)}, {@link #getAxisValue},
73 * {@link #getPointerId(int)}, {@link #getToolType(int)}, and many others. Most of these
74 * methods accept the pointer index as a parameter rather than the pointer id.
75 * The pointer index of each pointer in the event ranges from 0 to one less than the value
76 * returned by {@link #getPointerCount()}.
77 * </p><p>
78 * The order in which individual pointers appear within a motion event is undefined.
79 * Thus the pointer index of a pointer can change from one event to the next but
80 * the pointer id of a pointer is guaranteed to remain constant as long as the pointer
81 * remains active. Use the {@link #getPointerId(int)} method to obtain the
82 * pointer id of a pointer to track it across all subsequent motion events in a gesture.
83 * Then for successive motion events, use the {@link #findPointerIndex(int)} method
84 * to obtain the pointer index for a given pointer id in that motion event.
85 * </p><p>
86 * Mouse and stylus buttons can be retrieved using {@link #getButtonState()}. It is a
87 * good idea to check the button state while handling {@link #ACTION_DOWN} as part
88 * of a touch event. The application may choose to perform some different action
89 * if the touch event starts due to a secondary button click, such as presenting a
90 * context menu.
91 * </p>
92 *
93 * <h3>Batching</h3>
94 * <p>
95 * For efficiency, motion events with {@link #ACTION_MOVE} may batch together
96 * multiple movement samples within a single object. The most current
97 * pointer coordinates are available using {@link #getX(int)} and {@link #getY(int)}.
98 * Earlier coordinates within the batch are accessed using {@link #getHistoricalX(int, int)}
99 * and {@link #getHistoricalY(int, int)}. The coordinates are "historical" only
100 * insofar as they are older than the current coordinates in the batch; however,
101 * they are still distinct from any other coordinates reported in prior motion events.
102 * To process all coordinates in the batch in time order, first consume the historical
103 * coordinates then consume the current coordinates.
104 * </p><p>
105 * Example: Consuming all samples for all pointers in a motion event in time order.
106 * </p><p><pre><code>
107 * void printSamples(MotionEvent ev) {
108 * final int historySize = ev.getHistorySize();
109 * final int pointerCount = ev.getPointerCount();
110 * for (int h = 0; h &lt; historySize; h++) {
111 * System.out.printf("At time %d:", ev.getHistoricalEventTime(h));
112 * for (int p = 0; p &lt; pointerCount; p++) {
113 * System.out.printf(" pointer %d: (%f,%f)",
114 * ev.getPointerId(p), ev.getHistoricalX(p, h), ev.getHistoricalY(p, h));
115 * }
116 * }
117 * System.out.printf("At time %d:", ev.getEventTime());
118 * for (int p = 0; p &lt; pointerCount; p++) {
119 * System.out.printf(" pointer %d: (%f,%f)",
120 * ev.getPointerId(p), ev.getX(p), ev.getY(p));
121 * }
122 * }
123 * </code></pre></p>
124 *
125 * <h3>Device Types</h3>
126 * <p>
127 * The interpretation of the contents of a MotionEvent varies significantly depending
128 * on the source class of the device.
129 * </p><p>
Jeff Browncb1404e2011-01-15 18:14:15 -0800130 * On pointing devices with source class {@link InputDevice#SOURCE_CLASS_POINTER}
131 * such as touch screens, the pointer coordinates specify absolute
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700132 * positions such as view X/Y coordinates. Each complete gesture is represented
133 * by a sequence of motion events with actions that describe pointer state transitions
134 * and movements. A gesture starts with a motion event with {@link #ACTION_DOWN}
135 * that provides the location of the first pointer down. As each additional
136 * pointer that goes down or up, the framework will generate a motion event with
137 * {@link #ACTION_POINTER_DOWN} or {@link #ACTION_POINTER_UP} accordingly.
138 * Pointer movements are described by motion events with {@link #ACTION_MOVE}.
139 * Finally, a gesture end either when the final pointer goes up as represented
140 * by a motion event with {@link #ACTION_UP} or when gesture is canceled
141 * with {@link #ACTION_CANCEL}.
142 * </p><p>
Jeff Brown33bbfd22011-02-24 20:55:35 -0800143 * Some pointing devices such as mice may support vertical and/or horizontal scrolling.
144 * A scroll event is reported as a generic motion event with {@link #ACTION_SCROLL} that
145 * includes the relative scroll offset in the {@link #AXIS_VSCROLL} and
146 * {@link #AXIS_HSCROLL} axes. See {@link #getAxisValue(int)} for information
147 * about retrieving these additional axes.
148 * </p><p>
Jeff Browncb1404e2011-01-15 18:14:15 -0800149 * On trackball devices with source class {@link InputDevice#SOURCE_CLASS_TRACKBALL},
150 * the pointer coordinates specify relative movements as X/Y deltas.
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700151 * A trackball gesture consists of a sequence of movements described by motion
152 * events with {@link #ACTION_MOVE} interspersed with occasional {@link #ACTION_DOWN}
153 * or {@link #ACTION_UP} motion events when the trackball button is pressed or released.
154 * </p><p>
Jeff Browncb1404e2011-01-15 18:14:15 -0800155 * On joystick devices with source class {@link InputDevice#SOURCE_CLASS_JOYSTICK},
156 * the pointer coordinates specify the absolute position of the joystick axes.
157 * The joystick axis values are normalized to a range of -1.0 to 1.0 where 0.0 corresponds
158 * to the center position. More information about the set of available axes and the
159 * range of motion can be obtained using {@link InputDevice#getMotionRange}.
Jeff Brown33bbfd22011-02-24 20:55:35 -0800160 * Some common joystick axes are {@link #AXIS_X}, {@link #AXIS_Y},
161 * {@link #AXIS_HAT_X}, {@link #AXIS_HAT_Y}, {@link #AXIS_Z} and {@link #AXIS_RZ}.
Jeff Browncb1404e2011-01-15 18:14:15 -0800162 * </p><p>
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700163 * Refer to {@link InputDevice} for more information about how different kinds of
Jeff Brownc5ed5912010-07-14 18:48:53 -0700164 * input devices and sources represent pointer coordinates.
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700165 * </p>
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700166 *
167 * <h3>Consistency Guarantees</h3>
168 * <p>
169 * Motion events are always delivered to views as a consistent stream of events.
170 * What constitutes a consistent stream varies depending on the type of device.
171 * For touch events, consistency implies that pointers go down one at a time,
172 * move around as a group and then go up one at a time or are canceled.
173 * </p><p>
174 * While the framework tries to deliver consistent streams of motion events to
175 * views, it cannot guarantee it. Some events may be dropped or modified by
176 * containing views in the application before they are delivered thereby making
177 * the stream of events inconsistent. Views should always be prepared to
178 * handle {@link #ACTION_CANCEL} and should tolerate anomalous
179 * situations such as receiving a new {@link #ACTION_DOWN} without first having
180 * received an {@link #ACTION_UP} for the prior gesture.
181 * </p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800182 */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700183public final class MotionEvent extends InputEvent implements Parcelable {
Siarhei Vishniakou85ddfff2018-01-31 16:49:36 -0800184 private static final String TAG = "MotionEvent";
Jeff Brown91c69ab2011-02-14 17:03:18 -0800185 private static final long NS_PER_MS = 1000000;
Michael Wright337d9d22014-04-22 15:03:48 -0700186 private static final String LABEL_PREFIX = "AXIS_";
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700187
Eugene Suslae6e55b52018-01-11 15:12:56 -0800188 private static final boolean DEBUG_CONCISE_TOSTRING = false;
189
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700190 /**
191 * An invalid pointer id.
192 *
193 * This value (-1) can be used as a placeholder to indicate that a pointer id
194 * has not been assigned or is not available. It cannot appear as
195 * a pointer id inside a {@link MotionEvent}.
196 */
197 public static final int INVALID_POINTER_ID = -1;
198
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800199 /**
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700200 * Bit mask of the parts of the action code that are the action itself.
201 */
202 public static final int ACTION_MASK = 0xff;
Dennis Kempinac1b31d2016-11-02 17:02:25 -0700203
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700204 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700205 * Constant for {@link #getActionMasked}: A pressed gesture has started, the
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800206 * motion contains the initial starting location.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700207 * <p>
208 * This is also a good time to check the button state to distinguish
209 * secondary and tertiary button clicks and handle them appropriately.
210 * Use {@link #getButtonState} to retrieve the button state.
211 * </p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800212 */
213 public static final int ACTION_DOWN = 0;
Dennis Kempinac1b31d2016-11-02 17:02:25 -0700214
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800215 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700216 * Constant for {@link #getActionMasked}: A pressed gesture has finished, the
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800217 * motion contains the final release location as well as any intermediate
218 * points since the last down or move event.
219 */
220 public static final int ACTION_UP = 1;
Dennis Kempinac1b31d2016-11-02 17:02:25 -0700221
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800222 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700223 * Constant for {@link #getActionMasked}: A change has happened during a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800224 * press gesture (between {@link #ACTION_DOWN} and {@link #ACTION_UP}).
225 * The motion contains the most recent point, as well as any intermediate
226 * points since the last down or move event.
227 */
228 public static final int ACTION_MOVE = 2;
Dennis Kempinac1b31d2016-11-02 17:02:25 -0700229
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800230 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700231 * Constant for {@link #getActionMasked}: The current gesture has been aborted.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800232 * You will not receive any more points in it. You should treat this as
233 * an up event, but not perform any action that you normally would.
234 */
235 public static final int ACTION_CANCEL = 3;
Dennis Kempinac1b31d2016-11-02 17:02:25 -0700236
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800237 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700238 * Constant for {@link #getActionMasked}: A movement has happened outside of the
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800239 * normal bounds of the UI element. This does not provide a full gesture,
240 * but only the initial location of the movement/touch.
Siarhei Vishniakou6ad0e392017-06-02 17:20:34 -0700241 * <p>
242 * Note: Because the location of any event will be outside the
243 * bounds of the view hierarchy, it will not get dispatched to
244 * any children of a ViewGroup by default. Therefore,
245 * movements with ACTION_OUTSIDE should be handled in either the
246 * root {@link View} or in the appropriate {@link Window.Callback}
247 * (e.g. {@link android.app.Activity} or {@link android.app.Dialog}).
248 * </p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800249 */
250 public static final int ACTION_OUTSIDE = 4;
251
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700252 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700253 * Constant for {@link #getActionMasked}: A non-primary pointer has gone down.
254 * <p>
255 * Use {@link #getActionIndex} to retrieve the index of the pointer that changed.
256 * </p><p>
257 * The index is encoded in the {@link #ACTION_POINTER_INDEX_MASK} bits of the
258 * unmasked action returned by {@link #getAction}.
259 * </p>
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700260 */
261 public static final int ACTION_POINTER_DOWN = 5;
Dennis Kempinac1b31d2016-11-02 17:02:25 -0700262
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700263 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700264 * Constant for {@link #getActionMasked}: A non-primary pointer has gone up.
265 * <p>
266 * Use {@link #getActionIndex} to retrieve the index of the pointer that changed.
267 * </p><p>
268 * The index is encoded in the {@link #ACTION_POINTER_INDEX_MASK} bits of the
269 * unmasked action returned by {@link #getAction}.
270 * </p>
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700271 */
272 public static final int ACTION_POINTER_UP = 6;
Jeff Browncc0c1592011-02-19 05:07:28 -0800273
274 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700275 * Constant for {@link #getActionMasked}: A change happened but the pointer
Jeff Browncc0c1592011-02-19 05:07:28 -0800276 * is not down (unlike {@link #ACTION_MOVE}). The motion contains the most
277 * recent point, as well as any intermediate points since the last
278 * hover move event.
Jeff Brown33bbfd22011-02-24 20:55:35 -0800279 * <p>
Jeff Browna032cc02011-03-07 16:56:21 -0800280 * This action is always delivered to the window or view under the pointer.
281 * </p><p>
Jeff Brown33bbfd22011-02-24 20:55:35 -0800282 * This action is not a touch event so it is delivered to
283 * {@link View#onGenericMotionEvent(MotionEvent)} rather than
284 * {@link View#onTouchEvent(MotionEvent)}.
285 * </p>
Jeff Browncc0c1592011-02-19 05:07:28 -0800286 */
287 public static final int ACTION_HOVER_MOVE = 7;
288
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700289 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700290 * Constant for {@link #getActionMasked}: The motion event contains relative
Jeff Brown33bbfd22011-02-24 20:55:35 -0800291 * vertical and/or horizontal scroll offsets. Use {@link #getAxisValue(int)}
292 * to retrieve the information from {@link #AXIS_VSCROLL} and {@link #AXIS_HSCROLL}.
293 * The pointer may or may not be down when this event is dispatched.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700294 * <p>
Jeff Browna032cc02011-03-07 16:56:21 -0800295 * This action is always delivered to the window or view under the pointer, which
296 * may not be the window or view currently touched.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700297 * </p><p>
Jeff Brown33bbfd22011-02-24 20:55:35 -0800298 * This action is not a touch event so it is delivered to
299 * {@link View#onGenericMotionEvent(MotionEvent)} rather than
300 * {@link View#onTouchEvent(MotionEvent)}.
301 * </p>
302 */
303 public static final int ACTION_SCROLL = 8;
304
305 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700306 * Constant for {@link #getActionMasked}: The pointer is not down but has entered the
Jeff Browna032cc02011-03-07 16:56:21 -0800307 * boundaries of a window or view.
308 * <p>
309 * This action is always delivered to the window or view under the pointer.
310 * </p><p>
311 * This action is not a touch event so it is delivered to
312 * {@link View#onGenericMotionEvent(MotionEvent)} rather than
313 * {@link View#onTouchEvent(MotionEvent)}.
314 * </p>
315 */
316 public static final int ACTION_HOVER_ENTER = 9;
317
318 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700319 * Constant for {@link #getActionMasked}: The pointer is not down but has exited the
Jeff Browna032cc02011-03-07 16:56:21 -0800320 * boundaries of a window or view.
321 * <p>
322 * This action is always delivered to the window or view that was previously under the pointer.
323 * </p><p>
324 * This action is not a touch event so it is delivered to
325 * {@link View#onGenericMotionEvent(MotionEvent)} rather than
326 * {@link View#onTouchEvent(MotionEvent)}.
327 * </p>
328 */
329 public static final int ACTION_HOVER_EXIT = 10;
330
331 /**
Michael Wright5bd69e62015-05-14 14:48:08 +0100332 * Constant for {@link #getActionMasked}: A button has been pressed.
333 *
334 * <p>
335 * Use {@link #getActionButton()} to get which button was pressed.
336 * </p><p>
337 * This action is not a touch event so it is delivered to
338 * {@link View#onGenericMotionEvent(MotionEvent)} rather than
339 * {@link View#onTouchEvent(MotionEvent)}.
340 * </p>
341 */
342 public static final int ACTION_BUTTON_PRESS = 11;
343
344 /**
345 * Constant for {@link #getActionMasked}: A button has been released.
346 *
347 * <p>
348 * Use {@link #getActionButton()} to get which button was released.
349 * </p><p>
350 * This action is not a touch event so it is delivered to
351 * {@link View#onGenericMotionEvent(MotionEvent)} rather than
352 * {@link View#onTouchEvent(MotionEvent)}.
353 * </p>
354 */
355 public static final int ACTION_BUTTON_RELEASE = 12;
356
357 /**
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800358 * Bits in the action code that represent a pointer index, used with
359 * {@link #ACTION_POINTER_DOWN} and {@link #ACTION_POINTER_UP}. Shifting
360 * down by {@link #ACTION_POINTER_INDEX_SHIFT} provides the actual pointer
361 * index where the data for the pointer going up or down can be found; you can
362 * get its identifier with {@link #getPointerId(int)} and the actual
363 * data with {@link #getX(int)} etc.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700364 *
365 * @see #getActionIndex
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700366 */
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800367 public static final int ACTION_POINTER_INDEX_MASK = 0xff00;
Dennis Kempinac1b31d2016-11-02 17:02:25 -0700368
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800369 /**
370 * Bit shift for the action bits holding the pointer index as
371 * defined by {@link #ACTION_POINTER_INDEX_MASK}.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700372 *
373 * @see #getActionIndex
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800374 */
375 public static final int ACTION_POINTER_INDEX_SHIFT = 8;
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700376
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800377 /**
378 * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the
379 * data index associated with {@link #ACTION_POINTER_DOWN}.
380 */
381 @Deprecated
382 public static final int ACTION_POINTER_1_DOWN = ACTION_POINTER_DOWN | 0x0000;
Dennis Kempinac1b31d2016-11-02 17:02:25 -0700383
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800384 /**
385 * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the
386 * data index associated with {@link #ACTION_POINTER_DOWN}.
387 */
388 @Deprecated
389 public static final int ACTION_POINTER_2_DOWN = ACTION_POINTER_DOWN | 0x0100;
Dennis Kempinac1b31d2016-11-02 17:02:25 -0700390
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800391 /**
392 * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the
393 * data index associated with {@link #ACTION_POINTER_DOWN}.
394 */
395 @Deprecated
396 public static final int ACTION_POINTER_3_DOWN = ACTION_POINTER_DOWN | 0x0200;
Dennis Kempinac1b31d2016-11-02 17:02:25 -0700397
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800398 /**
399 * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the
400 * data index associated with {@link #ACTION_POINTER_UP}.
401 */
402 @Deprecated
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700403 public static final int ACTION_POINTER_1_UP = ACTION_POINTER_UP | 0x0000;
Dennis Kempinac1b31d2016-11-02 17:02:25 -0700404
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700405 /**
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800406 * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the
407 * data index associated with {@link #ACTION_POINTER_UP}.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700408 */
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800409 @Deprecated
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700410 public static final int ACTION_POINTER_2_UP = ACTION_POINTER_UP | 0x0100;
Dennis Kempinac1b31d2016-11-02 17:02:25 -0700411
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700412 /**
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800413 * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the
414 * data index associated with {@link #ACTION_POINTER_UP}.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700415 */
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800416 @Deprecated
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700417 public static final int ACTION_POINTER_3_UP = ACTION_POINTER_UP | 0x0200;
Dennis Kempinac1b31d2016-11-02 17:02:25 -0700418
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700419 /**
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800420 * @deprecated Renamed to {@link #ACTION_POINTER_INDEX_MASK} to match
421 * the actual data contained in these bits.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700422 */
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800423 @Deprecated
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700424 public static final int ACTION_POINTER_ID_MASK = 0xff00;
Dennis Kempinac1b31d2016-11-02 17:02:25 -0700425
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700426 /**
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800427 * @deprecated Renamed to {@link #ACTION_POINTER_INDEX_SHIFT} to match
428 * the actual data contained in these bits.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700429 */
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800430 @Deprecated
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700431 public static final int ACTION_POINTER_ID_SHIFT = 8;
Dennis Kempinac1b31d2016-11-02 17:02:25 -0700432
Jeff Brown85a31762010-09-01 17:01:00 -0700433 /**
434 * This flag indicates that the window that received this motion event is partly
Siarhei Vishniakou3a6a4112019-01-30 10:15:12 -0800435 * or wholly obscured by another visible window above it. This flag is set to true
436 * if the event directly passed through the obscured area.
437 *
Jeff Brown85a31762010-09-01 17:01:00 -0700438 * A security sensitive application can check this flag to identify situations in which
439 * a malicious application may have covered up part of its content for the purpose
440 * of misleading the user or hijacking touches. An appropriate response might be
441 * to drop the suspect touches or to take additional precautions to confirm the user's
442 * actual intent.
443 */
444 public static final int FLAG_WINDOW_IS_OBSCURED = 0x1;
Romain Guycafdea62009-06-12 10:51:36 -0700445
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800446 /**
Michael Wright0625e112016-03-30 17:31:48 -0700447 * This flag indicates that the window that received this motion event is partly
Siarhei Vishniakou3a6a4112019-01-30 10:15:12 -0800448 * or wholly obscured by another visible window above it. This flag is set to true
Michael Wright0625e112016-03-30 17:31:48 -0700449 * even if the event did not directly pass through the obscured area.
Siarhei Vishniakou3a6a4112019-01-30 10:15:12 -0800450 *
Michael Wright0625e112016-03-30 17:31:48 -0700451 * A security sensitive application can check this flag to identify situations in which
452 * a malicious application may have covered up part of its content for the purpose
453 * of misleading the user or hijacking touches. An appropriate response might be
454 * to drop the suspect touches or to take additional precautions to confirm the user's
455 * actual intent.
456 *
Siarhei Vishniakou3a6a4112019-01-30 10:15:12 -0800457 * Unlike FLAG_WINDOW_IS_OBSCURED, this is true even if the window that received this event is
458 * obstructed in areas other than the touched location.
Michael Wright0625e112016-03-30 17:31:48 -0700459 */
460 public static final int FLAG_WINDOW_IS_PARTIALLY_OBSCURED = 0x2;
461
462 /**
Vladislav Kaznacheev5a77c372016-10-10 16:11:15 -0700463 * This private flag is only set on {@link #ACTION_HOVER_MOVE} events and indicates that
464 * this event will be immediately followed by a {@link #ACTION_HOVER_EXIT}. It is used to
465 * prevent generating redundant {@link #ACTION_HOVER_ENTER} events.
466 * @hide
467 */
468 public static final int FLAG_HOVER_EXIT_PENDING = 0x4;
469
470 /**
Dennis Kempinac1b31d2016-11-02 17:02:25 -0700471 * This flag indicates that the event has been generated by a gesture generator. It
Siarhei Vishniakoub05b0b52018-12-28 17:50:24 -0800472 * provides a hint to the GestureDetector to not apply any touch slop.
Dennis Kempinac1b31d2016-11-02 17:02:25 -0700473 *
474 * @hide
475 */
476 public static final int FLAG_IS_GENERATED_GESTURE = 0x8;
477
478 /**
Jeff Brown21bc5c92011-02-28 18:27:14 -0800479 * Private flag that indicates when the system has detected that this motion event
480 * may be inconsistent with respect to the sequence of previously delivered motion events,
481 * such as when a pointer move event is sent but the pointer is not down.
482 *
483 * @hide
484 * @see #isTainted
485 * @see #setTainted
486 */
487 public static final int FLAG_TAINTED = 0x80000000;
488
489 /**
Svetoslavded133c2015-01-30 20:28:41 -0800490 * Private flag indicating that this event was synthesized by the system and
491 * should be delivered to the accessibility focused view first. When being
492 * dispatched such an event is not handled by predecessors of the accessibility
493 * focused view and after the event reaches that view the flag is cleared and
494 * normal event dispatch is performed. This ensures that the platform can click
495 * on any view that has accessibility focus which is semantically equivalent to
496 * asking the view to perform a click accessibility action but more generic as
497 * views not implementing click action correctly can still be activated.
498 *
499 * @hide
500 * @see #isTargetAccessibilityFocus()
501 * @see #setTargetAccessibilityFocus(boolean)
502 */
503 public static final int FLAG_TARGET_ACCESSIBILITY_FOCUS = 0x40000000;
504
505
506 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800507 * Flag indicating the motion event intersected the top edge of the screen.
508 */
509 public static final int EDGE_TOP = 0x00000001;
Romain Guycafdea62009-06-12 10:51:36 -0700510
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800511 /**
512 * Flag indicating the motion event intersected the bottom edge of the screen.
513 */
514 public static final int EDGE_BOTTOM = 0x00000002;
Romain Guycafdea62009-06-12 10:51:36 -0700515
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800516 /**
517 * Flag indicating the motion event intersected the left edge of the screen.
518 */
519 public static final int EDGE_LEFT = 0x00000004;
Romain Guycafdea62009-06-12 10:51:36 -0700520
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800521 /**
522 * Flag indicating the motion event intersected the right edge of the screen.
523 */
524 public static final int EDGE_RIGHT = 0x00000008;
Romain Guycafdea62009-06-12 10:51:36 -0700525
Jeff Brown91c69ab2011-02-14 17:03:18 -0800526 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700527 * Axis constant: X axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800528 * <p>
529 * <ul>
530 * <li>For a touch screen, reports the absolute X screen position of the center of
531 * the touch contact area. The units are display pixels.
532 * <li>For a touch pad, reports the absolute X surface position of the center of the touch
Jeff Browncc0c1592011-02-19 05:07:28 -0800533 * contact area. The units are device-dependent; use {@link InputDevice#getMotionRange(int)}
534 * to query the effective range of values.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800535 * <li>For a mouse, reports the absolute X screen position of the mouse pointer.
536 * The units are display pixels.
537 * <li>For a trackball, reports the relative horizontal displacement of the trackball.
538 * The value is normalized to a range from -1.0 (left) to 1.0 (right).
539 * <li>For a joystick, reports the absolute X position of the joystick.
540 * The value is normalized to a range from -1.0 (left) to 1.0 (right).
541 * </ul>
542 * </p>
Jeff Brown91c69ab2011-02-14 17:03:18 -0800543 *
544 * @see #getX(int)
545 * @see #getHistoricalX(int, int)
546 * @see MotionEvent.PointerCoords#x
547 * @see InputDevice#getMotionRange
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700548 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800549 public static final int AXIS_X = 0;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700550
Jeff Brown91c69ab2011-02-14 17:03:18 -0800551 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700552 * Axis constant: Y axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800553 * <p>
554 * <ul>
555 * <li>For a touch screen, reports the absolute Y screen position of the center of
556 * the touch contact area. The units are display pixels.
557 * <li>For a touch pad, reports the absolute Y surface position of the center of the touch
558 * contact area. The units are device-dependent; use {@link InputDevice#getMotionRange(int)}
559 * to query the effective range of values.
560 * <li>For a mouse, reports the absolute Y screen position of the mouse pointer.
561 * The units are display pixels.
562 * <li>For a trackball, reports the relative vertical displacement of the trackball.
563 * The value is normalized to a range from -1.0 (up) to 1.0 (down).
564 * <li>For a joystick, reports the absolute Y position of the joystick.
565 * The value is normalized to a range from -1.0 (up or far) to 1.0 (down or near).
566 * </ul>
567 * </p>
Jeff Brown91c69ab2011-02-14 17:03:18 -0800568 *
569 * @see #getY(int)
570 * @see #getHistoricalY(int, int)
571 * @see MotionEvent.PointerCoords#y
572 * @see InputDevice#getMotionRange
Jeff Brownc5ed5912010-07-14 18:48:53 -0700573 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800574 public static final int AXIS_Y = 1;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700575
Jeff Brown91c69ab2011-02-14 17:03:18 -0800576 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700577 * Axis constant: Pressure axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800578 * <p>
579 * <ul>
Jeff Browncc0c1592011-02-19 05:07:28 -0800580 * <li>For a touch screen or touch pad, reports the approximate pressure applied to the surface
Jeff Brown6f2fba42011-02-19 01:08:02 -0800581 * by a finger or other tool. The value is normalized to a range from
582 * 0 (no pressure at all) to 1 (normal pressure), although values higher than 1
583 * may be generated depending on the calibration of the input device.
584 * <li>For a trackball, the value is set to 1 if the trackball button is pressed
585 * or 0 otherwise.
586 * <li>For a mouse, the value is set to 1 if the primary mouse button is pressed
587 * or 0 otherwise.
588 * </ul>
589 * </p>
Jeff Brown91c69ab2011-02-14 17:03:18 -0800590 *
591 * @see #getPressure(int)
592 * @see #getHistoricalPressure(int, int)
593 * @see MotionEvent.PointerCoords#pressure
594 * @see InputDevice#getMotionRange
Jeff Brownc5ed5912010-07-14 18:48:53 -0700595 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800596 public static final int AXIS_PRESSURE = 2;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700597
Jeff Brown91c69ab2011-02-14 17:03:18 -0800598 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700599 * Axis constant: Size axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800600 * <p>
601 * <ul>
602 * <li>For a touch screen or touch pad, reports the approximate size of the contact area in
603 * relation to the maximum detectable size for the device. The value is normalized
604 * to a range from 0 (smallest detectable size) to 1 (largest detectable size),
Jeff Browncc0c1592011-02-19 05:07:28 -0800605 * although it is not a linear scale. This value is of limited use.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800606 * To obtain calibrated size information, use
607 * {@link #AXIS_TOUCH_MAJOR} or {@link #AXIS_TOOL_MAJOR}.
608 * </ul>
609 * </p>
Jeff Brown91c69ab2011-02-14 17:03:18 -0800610 *
611 * @see #getSize(int)
612 * @see #getHistoricalSize(int, int)
613 * @see MotionEvent.PointerCoords#size
614 * @see InputDevice#getMotionRange
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700615 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800616 public static final int AXIS_SIZE = 3;
617
618 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700619 * Axis constant: TouchMajor axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800620 * <p>
621 * <ul>
622 * <li>For a touch screen, reports the length of the major axis of an ellipse that
623 * represents the touch area at the point of contact.
624 * The units are display pixels.
625 * <li>For a touch pad, reports the length of the major axis of an ellipse that
626 * represents the touch area at the point of contact.
627 * The units are device-dependent; use {@link InputDevice#getMotionRange(int)}
628 * to query the effective range of values.
629 * </ul>
630 * </p>
Jeff Brown91c69ab2011-02-14 17:03:18 -0800631 *
632 * @see #getTouchMajor(int)
633 * @see #getHistoricalTouchMajor(int, int)
634 * @see MotionEvent.PointerCoords#touchMajor
635 * @see InputDevice#getMotionRange
Dianne Hackborn1e8dfc72009-08-06 12:43:01 -0700636 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800637 public static final int AXIS_TOUCH_MAJOR = 4;
638
639 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700640 * Axis constant: TouchMinor axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800641 * <p>
642 * <ul>
643 * <li>For a touch screen, reports the length of the minor axis of an ellipse that
644 * represents the touch area at the point of contact.
645 * The units are display pixels.
646 * <li>For a touch pad, reports the length of the minor axis of an ellipse that
647 * represents the touch area at the point of contact.
648 * The units are device-dependent; use {@link InputDevice#getMotionRange(int)}
649 * to query the effective range of values.
650 * </ul>
651 * </p><p>
652 * When the touch is circular, the major and minor axis lengths will be equal to one another.
653 * </p>
Jeff Brown91c69ab2011-02-14 17:03:18 -0800654 *
655 * @see #getTouchMinor(int)
656 * @see #getHistoricalTouchMinor(int, int)
657 * @see MotionEvent.PointerCoords#touchMinor
658 * @see InputDevice#getMotionRange
Jeff Brown9e2ad362010-07-30 19:20:11 -0700659 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800660 public static final int AXIS_TOUCH_MINOR = 5;
661
662 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700663 * Axis constant: ToolMajor axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800664 * <p>
665 * <ul>
666 * <li>For a touch screen, reports the length of the major axis of an ellipse that
667 * represents the size of the approaching finger or tool used to make contact.
668 * <li>For a touch pad, reports the length of the major axis of an ellipse that
669 * represents the size of the approaching finger or tool used to make contact.
670 * The units are device-dependent; use {@link InputDevice#getMotionRange(int)}
671 * to query the effective range of values.
672 * </ul>
673 * </p><p>
674 * When the touch is circular, the major and minor axis lengths will be equal to one another.
675 * </p><p>
676 * The tool size may be larger than the touch size since the tool may not be fully
677 * in contact with the touch sensor.
678 * </p>
Jeff Brown91c69ab2011-02-14 17:03:18 -0800679 *
680 * @see #getToolMajor(int)
681 * @see #getHistoricalToolMajor(int, int)
682 * @see MotionEvent.PointerCoords#toolMajor
683 * @see InputDevice#getMotionRange
684 */
685 public static final int AXIS_TOOL_MAJOR = 6;
686
687 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700688 * Axis constant: ToolMinor axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800689 * <p>
690 * <ul>
691 * <li>For a touch screen, reports the length of the minor axis of an ellipse that
692 * represents the size of the approaching finger or tool used to make contact.
693 * <li>For a touch pad, reports the length of the minor axis of an ellipse that
694 * represents the size of the approaching finger or tool used to make contact.
695 * The units are device-dependent; use {@link InputDevice#getMotionRange(int)}
696 * to query the effective range of values.
697 * </ul>
698 * </p><p>
699 * When the touch is circular, the major and minor axis lengths will be equal to one another.
700 * </p><p>
701 * The tool size may be larger than the touch size since the tool may not be fully
702 * in contact with the touch sensor.
703 * </p>
Jeff Brown91c69ab2011-02-14 17:03:18 -0800704 *
705 * @see #getToolMinor(int)
706 * @see #getHistoricalToolMinor(int, int)
707 * @see MotionEvent.PointerCoords#toolMinor
708 * @see InputDevice#getMotionRange
709 */
710 public static final int AXIS_TOOL_MINOR = 7;
711
712 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700713 * Axis constant: Orientation axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800714 * <p>
715 * <ul>
716 * <li>For a touch screen or touch pad, reports the orientation of the finger
717 * or tool in radians relative to the vertical plane of the device.
718 * An angle of 0 radians indicates that the major axis of contact is oriented
Jeff Brown91c69ab2011-02-14 17:03:18 -0800719 * upwards, is perfectly circular or is of unknown orientation. A positive angle
720 * indicates that the major axis of contact is oriented to the right. A negative angle
721 * indicates that the major axis of contact is oriented to the left.
722 * The full range is from -PI/2 radians (finger pointing fully left) to PI/2 radians
723 * (finger pointing fully right).
Jeff Brown65fd2512011-08-18 11:20:58 -0700724 * <li>For a stylus, the orientation indicates the direction in which the stylus
725 * is pointing in relation to the vertical axis of the current orientation of the screen.
726 * The range is from -PI radians to PI radians, where 0 is pointing up,
727 * -PI/2 radians is pointing left, -PI or PI radians is pointing down, and PI/2 radians
728 * is pointing right. See also {@link #AXIS_TILT}.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800729 * </ul>
730 * </p>
Jeff Brown91c69ab2011-02-14 17:03:18 -0800731 *
732 * @see #getOrientation(int)
733 * @see #getHistoricalOrientation(int, int)
734 * @see MotionEvent.PointerCoords#orientation
735 * @see InputDevice#getMotionRange
736 */
737 public static final int AXIS_ORIENTATION = 8;
738
Jeff Brown6f2fba42011-02-19 01:08:02 -0800739 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700740 * Axis constant: Vertical Scroll axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800741 * <p>
742 * <ul>
Jeff Browncc0c1592011-02-19 05:07:28 -0800743 * <li>For a mouse, reports the relative movement of the vertical scroll wheel.
Jeff Brown33bbfd22011-02-24 20:55:35 -0800744 * The value is normalized to a range from -1.0 (down) to 1.0 (up).
Jeff Brown6f2fba42011-02-19 01:08:02 -0800745 * </ul>
746 * </p><p>
747 * This axis should be used to scroll views vertically.
748 * </p>
749 *
750 * @see #getAxisValue(int, int)
751 * @see #getHistoricalAxisValue(int, int, int)
752 * @see MotionEvent.PointerCoords#getAxisValue(int)
753 * @see InputDevice#getMotionRange
754 */
755 public static final int AXIS_VSCROLL = 9;
756
757 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700758 * Axis constant: Horizontal Scroll axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800759 * <p>
760 * <ul>
Jeff Browncc0c1592011-02-19 05:07:28 -0800761 * <li>For a mouse, reports the relative movement of the horizontal scroll wheel.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800762 * The value is normalized to a range from -1.0 (left) to 1.0 (right).
763 * </ul>
764 * </p><p>
765 * This axis should be used to scroll views horizontally.
766 * </p>
767 *
768 * @see #getAxisValue(int, int)
769 * @see #getHistoricalAxisValue(int, int, int)
770 * @see MotionEvent.PointerCoords#getAxisValue(int)
771 * @see InputDevice#getMotionRange
772 */
773 public static final int AXIS_HSCROLL = 10;
774
775 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700776 * Axis constant: Z axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800777 * <p>
778 * <ul>
779 * <li>For a joystick, reports the absolute Z position of the joystick.
780 * The value is normalized to a range from -1.0 (high) to 1.0 (low).
781 * <em>On game pads with two analog joysticks, this axis is often reinterpreted
782 * to report the absolute X position of the second joystick instead.</em>
783 * </ul>
784 * </p>
785 *
786 * @see #getAxisValue(int, int)
787 * @see #getHistoricalAxisValue(int, int, int)
788 * @see MotionEvent.PointerCoords#getAxisValue(int)
789 * @see InputDevice#getMotionRange
790 */
791 public static final int AXIS_Z = 11;
792
793 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700794 * Axis constant: X Rotation axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800795 * <p>
796 * <ul>
797 * <li>For a joystick, reports the absolute rotation angle about the X axis.
798 * The value is normalized to a range from -1.0 (counter-clockwise) to 1.0 (clockwise).
799 * </ul>
800 * </p>
801 *
802 * @see #getAxisValue(int, int)
803 * @see #getHistoricalAxisValue(int, int, int)
804 * @see MotionEvent.PointerCoords#getAxisValue(int)
805 * @see InputDevice#getMotionRange
806 */
807 public static final int AXIS_RX = 12;
808
809 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700810 * Axis constant: Y Rotation axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800811 * <p>
812 * <ul>
813 * <li>For a joystick, reports the absolute rotation angle about the Y axis.
814 * The value is normalized to a range from -1.0 (counter-clockwise) to 1.0 (clockwise).
815 * </ul>
816 * </p>
817 *
818 * @see #getAxisValue(int, int)
819 * @see #getHistoricalAxisValue(int, int, int)
820 * @see MotionEvent.PointerCoords#getAxisValue(int)
821 * @see InputDevice#getMotionRange
822 */
823 public static final int AXIS_RY = 13;
824
825 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700826 * Axis constant: Z Rotation axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800827 * <p>
828 * <ul>
829 * <li>For a joystick, reports the absolute rotation angle about the Z axis.
830 * The value is normalized to a range from -1.0 (counter-clockwise) to 1.0 (clockwise).
831 * <em>On game pads with two analog joysticks, this axis is often reinterpreted
832 * to report the absolute Y position of the second joystick instead.</em>
833 * </ul>
834 * </p>
835 *
836 * @see #getAxisValue(int, int)
837 * @see #getHistoricalAxisValue(int, int, int)
838 * @see MotionEvent.PointerCoords#getAxisValue(int)
839 * @see InputDevice#getMotionRange
840 */
841 public static final int AXIS_RZ = 14;
842
843 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700844 * Axis constant: Hat X axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800845 * <p>
846 * <ul>
847 * <li>For a joystick, reports the absolute X position of the directional hat control.
848 * The value is normalized to a range from -1.0 (left) to 1.0 (right).
849 * </ul>
850 * </p>
851 *
852 * @see #getAxisValue(int, int)
853 * @see #getHistoricalAxisValue(int, int, int)
854 * @see MotionEvent.PointerCoords#getAxisValue(int)
855 * @see InputDevice#getMotionRange
856 */
857 public static final int AXIS_HAT_X = 15;
858
859 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700860 * Axis constant: Hat Y axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800861 * <p>
862 * <ul>
863 * <li>For a joystick, reports the absolute Y position of the directional hat control.
864 * The value is normalized to a range from -1.0 (up) to 1.0 (down).
865 * </ul>
866 * </p>
867 *
868 * @see #getAxisValue(int, int)
869 * @see #getHistoricalAxisValue(int, int, int)
870 * @see MotionEvent.PointerCoords#getAxisValue(int)
871 * @see InputDevice#getMotionRange
872 */
873 public static final int AXIS_HAT_Y = 16;
874
875 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700876 * Axis constant: Left Trigger axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800877 * <p>
878 * <ul>
879 * <li>For a joystick, reports the absolute position of the left trigger control.
880 * The value is normalized to a range from 0.0 (released) to 1.0 (fully pressed).
881 * </ul>
882 * </p>
883 *
884 * @see #getAxisValue(int, int)
885 * @see #getHistoricalAxisValue(int, int, int)
886 * @see MotionEvent.PointerCoords#getAxisValue(int)
887 * @see InputDevice#getMotionRange
888 */
889 public static final int AXIS_LTRIGGER = 17;
890
891 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700892 * Axis constant: Right Trigger axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800893 * <p>
894 * <ul>
895 * <li>For a joystick, reports the absolute position of the right trigger control.
896 * The value is normalized to a range from 0.0 (released) to 1.0 (fully pressed).
897 * </ul>
898 * </p>
899 *
900 * @see #getAxisValue(int, int)
901 * @see #getHistoricalAxisValue(int, int, int)
902 * @see MotionEvent.PointerCoords#getAxisValue(int)
903 * @see InputDevice#getMotionRange
904 */
905 public static final int AXIS_RTRIGGER = 18;
906
907 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700908 * Axis constant: Throttle axis of a motion event.
Jeff Brown3a22fa02011-03-04 13:07:49 -0800909 * <p>
910 * <ul>
911 * <li>For a joystick, reports the absolute position of the throttle control.
912 * The value is normalized to a range from 0.0 (fully open) to 1.0 (fully closed).
913 * </ul>
914 * </p>
915 *
916 * @see #getAxisValue(int, int)
917 * @see #getHistoricalAxisValue(int, int, int)
918 * @see MotionEvent.PointerCoords#getAxisValue(int)
919 * @see InputDevice#getMotionRange
920 */
921 public static final int AXIS_THROTTLE = 19;
922
923 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700924 * Axis constant: Rudder axis of a motion event.
Jeff Brown3a22fa02011-03-04 13:07:49 -0800925 * <p>
926 * <ul>
927 * <li>For a joystick, reports the absolute position of the rudder control.
928 * The value is normalized to a range from -1.0 (turn left) to 1.0 (turn right).
929 * </ul>
930 * </p>
931 *
932 * @see #getAxisValue(int, int)
933 * @see #getHistoricalAxisValue(int, int, int)
934 * @see MotionEvent.PointerCoords#getAxisValue(int)
935 * @see InputDevice#getMotionRange
936 */
937 public static final int AXIS_RUDDER = 20;
938
939 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700940 * Axis constant: Wheel axis of a motion event.
Jeff Brown3a22fa02011-03-04 13:07:49 -0800941 * <p>
942 * <ul>
943 * <li>For a joystick, reports the absolute position of the steering wheel control.
944 * The value is normalized to a range from -1.0 (turn left) to 1.0 (turn right).
945 * </ul>
946 * </p>
947 *
948 * @see #getAxisValue(int, int)
949 * @see #getHistoricalAxisValue(int, int, int)
950 * @see MotionEvent.PointerCoords#getAxisValue(int)
951 * @see InputDevice#getMotionRange
952 */
953 public static final int AXIS_WHEEL = 21;
954
955 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700956 * Axis constant: Gas axis of a motion event.
Jeff Brown3a22fa02011-03-04 13:07:49 -0800957 * <p>
958 * <ul>
959 * <li>For a joystick, reports the absolute position of the gas (accelerator) control.
960 * The value is normalized to a range from 0.0 (no acceleration)
961 * to 1.0 (maximum acceleration).
962 * </ul>
963 * </p>
964 *
965 * @see #getAxisValue(int, int)
966 * @see #getHistoricalAxisValue(int, int, int)
967 * @see MotionEvent.PointerCoords#getAxisValue(int)
968 * @see InputDevice#getMotionRange
969 */
970 public static final int AXIS_GAS = 22;
971
972 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700973 * Axis constant: Brake axis of a motion event.
Jeff Brown3a22fa02011-03-04 13:07:49 -0800974 * <p>
975 * <ul>
976 * <li>For a joystick, reports the absolute position of the brake control.
977 * The value is normalized to a range from 0.0 (no braking) to 1.0 (maximum braking).
978 * </ul>
979 * </p>
980 *
981 * @see #getAxisValue(int, int)
982 * @see #getHistoricalAxisValue(int, int, int)
983 * @see MotionEvent.PointerCoords#getAxisValue(int)
984 * @see InputDevice#getMotionRange
985 */
986 public static final int AXIS_BRAKE = 23;
987
988 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700989 * Axis constant: Distance axis of a motion event.
990 * <p>
991 * <ul>
992 * <li>For a stylus, reports the distance of the stylus from the screen.
Jeff Brown65fd2512011-08-18 11:20:58 -0700993 * A value of 0.0 indicates direct contact and larger values indicate increasing
994 * distance from the surface.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700995 * </ul>
996 * </p>
997 *
998 * @see #getAxisValue(int, int)
999 * @see #getHistoricalAxisValue(int, int, int)
1000 * @see MotionEvent.PointerCoords#getAxisValue(int)
1001 * @see InputDevice#getMotionRange
1002 */
1003 public static final int AXIS_DISTANCE = 24;
1004
1005 /**
Jeff Brown65fd2512011-08-18 11:20:58 -07001006 * Axis constant: Tilt axis of a motion event.
1007 * <p>
1008 * <ul>
1009 * <li>For a stylus, reports the tilt angle of the stylus in radians where
1010 * 0 radians indicates that the stylus is being held perpendicular to the
1011 * surface, and PI/2 radians indicates that the stylus is being held flat
1012 * against the surface.
1013 * </ul>
1014 * </p>
1015 *
1016 * @see #getAxisValue(int, int)
1017 * @see #getHistoricalAxisValue(int, int, int)
1018 * @see MotionEvent.PointerCoords#getAxisValue(int, int)
1019 * @see InputDevice#getMotionRange
1020 */
1021 public static final int AXIS_TILT = 25;
1022
1023 /**
Prashant Malani67322b12015-08-25 17:41:34 -07001024 * Axis constant: Generic scroll axis of a motion event.
1025 * <p>
1026 * <ul>
1027 * <li>Reports the relative movement of the generic scrolling device.
1028 * </ul>
1029 * </p><p>
1030 * This axis should be used for scroll events that are neither strictly vertical nor horizontal.
1031 * A good example would be the rotation of a rotary encoder input device.
1032 * </p>
1033 *
1034 * @see #getAxisValue(int, int)
Prashant Malani67322b12015-08-25 17:41:34 -07001035 */
1036 public static final int AXIS_SCROLL = 26;
1037
1038 /**
Jun Mukai347e5d42015-12-03 01:13:31 -08001039 * Axis constant: The movement of x position of a motion event.
1040 * <p>
1041 * <ul>
1042 * <li>For a mouse, reports a difference of x position between the previous position.
1043 * This is useful when pointer is captured, in that case the mouse pointer doesn't change
1044 * the location but this axis reports the difference which allows the app to see
1045 * how the mouse is moved.
1046 * </ul>
1047 * </p>
1048 *
1049 * @see #getAxisValue(int, int)
1050 * @see #getHistoricalAxisValue(int, int, int)
1051 * @see MotionEvent.PointerCoords#getAxisValue(int, int)
1052 * @see InputDevice#getMotionRange
1053 */
1054 public static final int AXIS_RELATIVE_X = 27;
1055
1056 /**
1057 * Axis constant: The movement of y position of a motion event.
1058 * <p>
1059 * This is similar to {@link #AXIS_RELATIVE_X} but for y-axis.
1060 * </p>
1061 *
1062 * @see #getAxisValue(int, int)
1063 * @see #getHistoricalAxisValue(int, int, int)
1064 * @see MotionEvent.PointerCoords#getAxisValue(int, int)
1065 * @see InputDevice#getMotionRange
1066 */
1067 public static final int AXIS_RELATIVE_Y = 28;
1068
1069 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001070 * Axis constant: Generic 1 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_1 = 32;
1079
1080 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001081 * Axis constant: Generic 2 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_2 = 33;
1090
1091 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001092 * Axis constant: Generic 3 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_3 = 34;
1101
1102 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001103 * Axis constant: Generic 4 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_4 = 35;
1112
1113 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001114 * Axis constant: Generic 5 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_5 = 36;
1123
1124 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001125 * Axis constant: Generic 6 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_6 = 37;
1134
1135 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001136 * Axis constant: Generic 7 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_7 = 38;
1145
1146 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001147 * Axis constant: Generic 8 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_8 = 39;
1156
1157 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001158 * Axis constant: Generic 9 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_9 = 40;
1167
1168 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001169 * Axis constant: Generic 10 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_10 = 41;
1178
1179 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001180 * Axis constant: Generic 11 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_11 = 42;
1189
1190 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001191 * Axis constant: Generic 12 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_12 = 43;
1200
1201 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001202 * Axis constant: Generic 13 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_13 = 44;
1211
1212 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001213 * Axis constant: Generic 14 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_14 = 45;
1222
1223 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001224 * Axis constant: Generic 15 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_15 = 46;
1233
1234 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001235 * Axis constant: Generic 16 axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -08001236 * The interpretation of a generic axis is device-specific.
1237 *
1238 * @see #getAxisValue(int, int)
1239 * @see #getHistoricalAxisValue(int, int, int)
1240 * @see MotionEvent.PointerCoords#getAxisValue(int)
1241 * @see InputDevice#getMotionRange
1242 */
1243 public static final int AXIS_GENERIC_16 = 47;
1244
1245 // NOTE: If you add a new axis here you must also add it to:
1246 // native/include/android/input.h
1247 // frameworks/base/include/ui/KeycodeLabels.h
1248
1249 // Symbolic names of all axes.
1250 private static final SparseArray<String> AXIS_SYMBOLIC_NAMES = new SparseArray<String>();
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001251 static {
Jeff Brown6f2fba42011-02-19 01:08:02 -08001252 SparseArray<String> names = AXIS_SYMBOLIC_NAMES;
1253 names.append(AXIS_X, "AXIS_X");
1254 names.append(AXIS_Y, "AXIS_Y");
1255 names.append(AXIS_PRESSURE, "AXIS_PRESSURE");
1256 names.append(AXIS_SIZE, "AXIS_SIZE");
1257 names.append(AXIS_TOUCH_MAJOR, "AXIS_TOUCH_MAJOR");
1258 names.append(AXIS_TOUCH_MINOR, "AXIS_TOUCH_MINOR");
1259 names.append(AXIS_TOOL_MAJOR, "AXIS_TOOL_MAJOR");
1260 names.append(AXIS_TOOL_MINOR, "AXIS_TOOL_MINOR");
1261 names.append(AXIS_ORIENTATION, "AXIS_ORIENTATION");
1262 names.append(AXIS_VSCROLL, "AXIS_VSCROLL");
1263 names.append(AXIS_HSCROLL, "AXIS_HSCROLL");
1264 names.append(AXIS_Z, "AXIS_Z");
1265 names.append(AXIS_RX, "AXIS_RX");
1266 names.append(AXIS_RY, "AXIS_RY");
1267 names.append(AXIS_RZ, "AXIS_RZ");
1268 names.append(AXIS_HAT_X, "AXIS_HAT_X");
1269 names.append(AXIS_HAT_Y, "AXIS_HAT_Y");
1270 names.append(AXIS_LTRIGGER, "AXIS_LTRIGGER");
1271 names.append(AXIS_RTRIGGER, "AXIS_RTRIGGER");
Jeff Brown3a22fa02011-03-04 13:07:49 -08001272 names.append(AXIS_THROTTLE, "AXIS_THROTTLE");
1273 names.append(AXIS_RUDDER, "AXIS_RUDDER");
1274 names.append(AXIS_WHEEL, "AXIS_WHEEL");
1275 names.append(AXIS_GAS, "AXIS_GAS");
1276 names.append(AXIS_BRAKE, "AXIS_BRAKE");
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001277 names.append(AXIS_DISTANCE, "AXIS_DISTANCE");
Jeff Brown65fd2512011-08-18 11:20:58 -07001278 names.append(AXIS_TILT, "AXIS_TILT");
Prashant Malani67322b12015-08-25 17:41:34 -07001279 names.append(AXIS_SCROLL, "AXIS_SCROLL");
Jun Mukai347e5d42015-12-03 01:13:31 -08001280 names.append(AXIS_RELATIVE_X, "AXIS_REALTIVE_X");
1281 names.append(AXIS_RELATIVE_Y, "AXIS_REALTIVE_Y");
Jeff Brown6f2fba42011-02-19 01:08:02 -08001282 names.append(AXIS_GENERIC_1, "AXIS_GENERIC_1");
1283 names.append(AXIS_GENERIC_2, "AXIS_GENERIC_2");
1284 names.append(AXIS_GENERIC_3, "AXIS_GENERIC_3");
1285 names.append(AXIS_GENERIC_4, "AXIS_GENERIC_4");
1286 names.append(AXIS_GENERIC_5, "AXIS_GENERIC_5");
1287 names.append(AXIS_GENERIC_6, "AXIS_GENERIC_6");
1288 names.append(AXIS_GENERIC_7, "AXIS_GENERIC_7");
1289 names.append(AXIS_GENERIC_8, "AXIS_GENERIC_8");
1290 names.append(AXIS_GENERIC_9, "AXIS_GENERIC_9");
1291 names.append(AXIS_GENERIC_10, "AXIS_GENERIC_10");
1292 names.append(AXIS_GENERIC_11, "AXIS_GENERIC_11");
1293 names.append(AXIS_GENERIC_12, "AXIS_GENERIC_12");
1294 names.append(AXIS_GENERIC_13, "AXIS_GENERIC_13");
1295 names.append(AXIS_GENERIC_14, "AXIS_GENERIC_14");
1296 names.append(AXIS_GENERIC_15, "AXIS_GENERIC_15");
1297 names.append(AXIS_GENERIC_16, "AXIS_GENERIC_16");
1298 }
1299
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001300 /**
Jeff Brown49754db2011-07-01 17:37:58 -07001301 * Button constant: Primary button (left mouse button).
1302 *
1303 * This button constant is not set in response to simple touches with a finger
1304 * or stylus tip. The user must actually push a button.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001305 *
1306 * @see #getButtonState
1307 */
1308 public static final int BUTTON_PRIMARY = 1 << 0;
1309
1310 /**
Michael Wright5bd69e62015-05-14 14:48:08 +01001311 * Button constant: Secondary button (right mouse button).
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001312 *
1313 * @see #getButtonState
1314 */
1315 public static final int BUTTON_SECONDARY = 1 << 1;
1316
1317 /**
Michael Wright5bd69e62015-05-14 14:48:08 +01001318 * Button constant: Tertiary button (middle mouse button).
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001319 *
1320 * @see #getButtonState
1321 */
1322 public static final int BUTTON_TERTIARY = 1 << 2;
1323
1324 /**
1325 * Button constant: Back button pressed (mouse back button).
1326 * <p>
1327 * The system may send a {@link KeyEvent#KEYCODE_BACK} key press to the application
1328 * when this button is pressed.
1329 * </p>
1330 *
1331 * @see #getButtonState
1332 */
1333 public static final int BUTTON_BACK = 1 << 3;
1334
1335 /**
1336 * Button constant: Forward button pressed (mouse forward button).
1337 * <p>
1338 * The system may send a {@link KeyEvent#KEYCODE_FORWARD} key press to the application
1339 * when this button is pressed.
1340 * </p>
1341 *
1342 * @see #getButtonState
1343 */
1344 public static final int BUTTON_FORWARD = 1 << 4;
1345
Michael Wright5bd69e62015-05-14 14:48:08 +01001346 /**
1347 * Button constant: Primary stylus button pressed.
1348 *
1349 * @see #getButtonState
1350 */
1351 public static final int BUTTON_STYLUS_PRIMARY = 1 << 5;
1352
1353 /**
1354 * Button constant: Secondary stylus button pressed.
1355 *
1356 * @see #getButtonState
1357 */
1358 public static final int BUTTON_STYLUS_SECONDARY = 1 << 6;
1359
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001360 // NOTE: If you add a new axis here you must also add it to:
1361 // native/include/android/input.h
1362
1363 // Symbolic names of all button states in bit order from least significant
1364 // to most significant.
1365 private static final String[] BUTTON_SYMBOLIC_NAMES = new String[] {
1366 "BUTTON_PRIMARY",
1367 "BUTTON_SECONDARY",
1368 "BUTTON_TERTIARY",
1369 "BUTTON_BACK",
1370 "BUTTON_FORWARD",
Michael Wright5bd69e62015-05-14 14:48:08 +01001371 "BUTTON_STYLUS_PRIMARY",
1372 "BUTTON_STYLUS_SECONDARY",
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001373 "0x00000080",
1374 "0x00000100",
1375 "0x00000200",
1376 "0x00000400",
1377 "0x00000800",
1378 "0x00001000",
1379 "0x00002000",
1380 "0x00004000",
1381 "0x00008000",
1382 "0x00010000",
1383 "0x00020000",
1384 "0x00040000",
1385 "0x00080000",
1386 "0x00100000",
1387 "0x00200000",
1388 "0x00400000",
1389 "0x00800000",
1390 "0x01000000",
1391 "0x02000000",
1392 "0x04000000",
1393 "0x08000000",
1394 "0x10000000",
1395 "0x20000000",
1396 "0x40000000",
1397 "0x80000000",
1398 };
1399
1400 /**
Siarhei Vishniakoub05b0b52018-12-28 17:50:24 -08001401 * Classification constant: None.
1402 *
1403 * No additional information is available about the current motion event stream.
1404 *
1405 * @see #getClassification
1406 */
1407 public static final int CLASSIFICATION_NONE = 0;
1408
1409 /**
1410 * Classification constant: Ambiguous gesture.
1411 *
1412 * The user's intent with respect to the current event stream is not yet determined.
1413 * Gestural actions, such as scrolling, should be inhibited until the classification resolves
1414 * to another value or the event stream ends.
1415 *
1416 * @see #getClassification
1417 */
1418 public static final int CLASSIFICATION_AMBIGUOUS_GESTURE = 1;
1419
1420 /**
1421 * Classification constant: Deep press.
1422 *
1423 * The current event stream represents the user intentionally pressing harder on the screen.
1424 * This classification type should be used to accelerate the long press behaviour.
1425 *
1426 * @see #getClassification
1427 */
1428 public static final int CLASSIFICATION_DEEP_PRESS = 2;
1429
1430 /** @hide */
1431 @Retention(SOURCE)
1432 @IntDef(prefix = { "CLASSIFICATION" }, value = {
1433 CLASSIFICATION_NONE, CLASSIFICATION_AMBIGUOUS_GESTURE, CLASSIFICATION_DEEP_PRESS})
1434 public @interface Classification {};
1435
1436 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001437 * Tool type constant: Unknown tool type.
1438 * This constant is used when the tool type is not known or is not relevant,
1439 * such as for a trackball or other non-pointing device.
1440 *
1441 * @see #getToolType
1442 */
1443 public static final int TOOL_TYPE_UNKNOWN = 0;
1444
1445 /**
Jeff Brown49754db2011-07-01 17:37:58 -07001446 * Tool type constant: The tool is a finger.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001447 *
1448 * @see #getToolType
1449 */
1450 public static final int TOOL_TYPE_FINGER = 1;
1451
1452 /**
Jeff Brown49754db2011-07-01 17:37:58 -07001453 * Tool type constant: The tool is a stylus.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001454 *
1455 * @see #getToolType
1456 */
1457 public static final int TOOL_TYPE_STYLUS = 2;
1458
1459 /**
Jeff Brown49754db2011-07-01 17:37:58 -07001460 * Tool type constant: The tool is a mouse or trackpad.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001461 *
1462 * @see #getToolType
1463 */
1464 public static final int TOOL_TYPE_MOUSE = 3;
1465
1466 /**
Jeff Brown49754db2011-07-01 17:37:58 -07001467 * Tool type constant: The tool is an eraser or a stylus being used in an inverted posture.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001468 *
1469 * @see #getToolType
1470 */
Jeff Brown49754db2011-07-01 17:37:58 -07001471 public static final int TOOL_TYPE_ERASER = 4;
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001472
1473 // NOTE: If you add a new tool type here you must also add it to:
1474 // native/include/android/input.h
1475
1476 // Symbolic names of all tool types.
1477 private static final SparseArray<String> TOOL_TYPE_SYMBOLIC_NAMES = new SparseArray<String>();
Jeff Brown6f2fba42011-02-19 01:08:02 -08001478 static {
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001479 SparseArray<String> names = TOOL_TYPE_SYMBOLIC_NAMES;
1480 names.append(TOOL_TYPE_UNKNOWN, "TOOL_TYPE_UNKNOWN");
1481 names.append(TOOL_TYPE_FINGER, "TOOL_TYPE_FINGER");
1482 names.append(TOOL_TYPE_STYLUS, "TOOL_TYPE_STYLUS");
1483 names.append(TOOL_TYPE_MOUSE, "TOOL_TYPE_MOUSE");
Jeff Brown49754db2011-07-01 17:37:58 -07001484 names.append(TOOL_TYPE_ERASER, "TOOL_TYPE_ERASER");
Jeff Brown6f2fba42011-02-19 01:08:02 -08001485 }
1486
Jeff Brown91c69ab2011-02-14 17:03:18 -08001487 // Private value for history pos that obtains the current sample.
Mathew Inwooda570dee2018-08-17 14:56:00 +01001488 @UnsupportedAppUsage
Jeff Brown91c69ab2011-02-14 17:03:18 -08001489 private static final int HISTORY_CURRENT = -0x80000000;
1490
Jeff Brown1f245102010-11-18 20:53:46 -08001491 private static final int MAX_RECYCLED = 10;
1492 private static final Object gRecyclerLock = new Object();
1493 private static int gRecyclerUsed;
1494 private static MotionEvent gRecyclerTop;
Romain Guycafdea62009-06-12 10:51:36 -07001495
Jeff Brown91c69ab2011-02-14 17:03:18 -08001496 // Shared temporary objects used when translating coordinates supplied by
1497 // the caller into single element PointerCoords and pointer id arrays.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001498 private static final Object gSharedTempLock = new Object();
1499 private static PointerCoords[] gSharedTempPointerCoords;
1500 private static PointerProperties[] gSharedTempPointerProperties;
1501 private static int[] gSharedTempPointerIndexMap;
1502
1503 private static final void ensureSharedTempPointerCapacity(int desiredCapacity) {
1504 if (gSharedTempPointerCoords == null
1505 || gSharedTempPointerCoords.length < desiredCapacity) {
1506 int capacity = gSharedTempPointerCoords != null ? gSharedTempPointerCoords.length : 8;
1507 while (capacity < desiredCapacity) {
1508 capacity *= 2;
1509 }
1510 gSharedTempPointerCoords = PointerCoords.createArray(capacity);
1511 gSharedTempPointerProperties = PointerProperties.createArray(capacity);
1512 gSharedTempPointerIndexMap = new int[capacity];
1513 }
1514 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08001515
1516 // Pointer to the native MotionEvent object that contains the actual data.
George Mountbbc84a82019-02-08 09:58:45 -08001517 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
Ashok Bhat99a1ef22014-01-08 14:45:08 +00001518 private long mNativePtr;
Mitsuru Oshima8169dae2009-04-28 18:12:09 -07001519
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001520 private MotionEvent mNext;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001521
Ashok Bhat99a1ef22014-01-08 14:45:08 +00001522 private static native long nativeInitialize(long nativePtr,
Siarhei Vishniakou85ddfff2018-01-31 16:49:36 -08001523 int deviceId, int source, int displayId, int action, int flags, int edgeFlags,
Siarhei Vishniakoub05b0b52018-12-28 17:50:24 -08001524 int metaState, int buttonState, @Classification int classification,
Jeff Brown91c69ab2011-02-14 17:03:18 -08001525 float xOffset, float yOffset, float xPrecision, float yPrecision,
1526 long downTimeNanos, long eventTimeNanos,
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001527 int pointerCount, PointerProperties[] pointerIds, PointerCoords[] pointerCoords);
Ashok Bhat99a1ef22014-01-08 14:45:08 +00001528 private static native void nativeDispose(long nativePtr);
1529 private static native void nativeAddBatch(long nativePtr, long eventTimeNanos,
Jeff Brown91c69ab2011-02-14 17:03:18 -08001530 PointerCoords[] pointerCoords, int metaState);
Ashok Bhat99a1ef22014-01-08 14:45:08 +00001531 private static native void nativeGetPointerCoords(long nativePtr,
Jeff Brown91c69ab2011-02-14 17:03:18 -08001532 int pointerIndex, int historyPos, PointerCoords outPointerCoords);
Ashok Bhat99a1ef22014-01-08 14:45:08 +00001533 private static native void nativeGetPointerProperties(long nativePtr,
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001534 int pointerIndex, PointerProperties outPointerProperties);
Jeff Brown91c69ab2011-02-14 17:03:18 -08001535
Ashok Bhat99a1ef22014-01-08 14:45:08 +00001536 private static native long nativeReadFromParcel(long nativePtr, Parcel parcel);
1537 private static native void nativeWriteToParcel(long nativePtr, Parcel parcel);
Jeff Brown91c69ab2011-02-14 17:03:18 -08001538
Michael Wright337d9d22014-04-22 15:03:48 -07001539 private static native String nativeAxisToString(int axis);
1540 private static native int nativeAxisFromString(String label);
1541
John Reck09709972016-10-03 15:47:18 -07001542 // -------------- @FastNative -------------------------
1543
1544 @FastNative
1545 private static native int nativeGetPointerId(long nativePtr, int pointerIndex);
1546 @FastNative
1547 private static native int nativeGetToolType(long nativePtr, int pointerIndex);
1548 @FastNative
1549 private static native long nativeGetEventTimeNanos(long nativePtr, int historyPos);
1550 @FastNative
Mathew Inwooda570dee2018-08-17 14:56:00 +01001551 @UnsupportedAppUsage
John Reck09709972016-10-03 15:47:18 -07001552 private static native float nativeGetRawAxisValue(long nativePtr,
1553 int axis, int pointerIndex, int historyPos);
1554 @FastNative
1555 private static native float nativeGetAxisValue(long nativePtr,
1556 int axis, int pointerIndex, int historyPos);
1557
1558 // -------------- @CriticalNative ----------------------
1559
1560 @CriticalNative
1561 private static native long nativeCopy(long destNativePtr, long sourceNativePtr,
1562 boolean keepHistory);
1563 @CriticalNative
1564 private static native int nativeGetDeviceId(long nativePtr);
1565 @CriticalNative
1566 private static native int nativeGetSource(long nativePtr);
1567 @CriticalNative
Siarhei Vishniakou85ddfff2018-01-31 16:49:36 -08001568 private static native void nativeSetSource(long nativePtr, int source);
1569 @CriticalNative
1570 private static native int nativeGetDisplayId(long nativePtr);
1571 @CriticalNative
1572 private static native void nativeSetDisplayId(long nativePtr, int displayId);
John Reck09709972016-10-03 15:47:18 -07001573 @CriticalNative
1574 private static native int nativeGetAction(long nativePtr);
1575 @CriticalNative
1576 private static native void nativeSetAction(long nativePtr, int action);
1577 @CriticalNative
1578 private static native boolean nativeIsTouchEvent(long nativePtr);
1579 @CriticalNative
1580 private static native int nativeGetFlags(long nativePtr);
1581 @CriticalNative
1582 private static native void nativeSetFlags(long nativePtr, int flags);
1583 @CriticalNative
1584 private static native int nativeGetEdgeFlags(long nativePtr);
1585 @CriticalNative
1586 private static native void nativeSetEdgeFlags(long nativePtr, int action);
1587 @CriticalNative
1588 private static native int nativeGetMetaState(long nativePtr);
1589 @CriticalNative
1590 private static native int nativeGetButtonState(long nativePtr);
1591 @CriticalNative
1592 private static native void nativeSetButtonState(long nativePtr, int buttonState);
1593 @CriticalNative
Siarhei Vishniakoub05b0b52018-12-28 17:50:24 -08001594 private static native int nativeGetClassification(long nativePtr);
1595 @CriticalNative
John Reck09709972016-10-03 15:47:18 -07001596 private static native int nativeGetActionButton(long nativePtr);
1597 @CriticalNative
1598 private static native void nativeSetActionButton(long nativePtr, int actionButton);
1599 @CriticalNative
1600 private static native void nativeOffsetLocation(long nativePtr, float deltaX, float deltaY);
1601 @CriticalNative
1602 private static native float nativeGetXOffset(long nativePtr);
1603 @CriticalNative
1604 private static native float nativeGetYOffset(long nativePtr);
1605 @CriticalNative
1606 private static native float nativeGetXPrecision(long nativePtr);
1607 @CriticalNative
1608 private static native float nativeGetYPrecision(long nativePtr);
1609 @CriticalNative
1610 private static native long nativeGetDownTimeNanos(long nativePtr);
1611 @CriticalNative
1612 private static native void nativeSetDownTimeNanos(long nativePtr, long downTime);
1613
1614 @CriticalNative
1615 private static native int nativeGetPointerCount(long nativePtr);
1616 @CriticalNative
1617 private static native int nativeFindPointerIndex(long nativePtr, int pointerId);
1618
1619 @CriticalNative
1620 private static native int nativeGetHistorySize(long nativePtr);
1621
1622 @CriticalNative
1623 private static native void nativeScale(long nativePtr, float scale);
1624 @CriticalNative
1625 private static native void nativeTransform(long nativePtr, long matrix);
1626
Jeff Brown91c69ab2011-02-14 17:03:18 -08001627 private MotionEvent() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001628 }
Romain Guycafdea62009-06-12 10:51:36 -07001629
Jeff Brown91c69ab2011-02-14 17:03:18 -08001630 @Override
1631 protected void finalize() throws Throwable {
1632 try {
1633 if (mNativePtr != 0) {
1634 nativeDispose(mNativePtr);
1635 mNativePtr = 0;
1636 }
1637 } finally {
1638 super.finalize();
1639 }
1640 }
1641
Mathew Inwooda570dee2018-08-17 14:56:00 +01001642 @UnsupportedAppUsage
Jeff Brown91c69ab2011-02-14 17:03:18 -08001643 static private MotionEvent obtain() {
Jeff Brown46b9ac02010-04-22 18:58:52 -07001644 final MotionEvent ev;
1645 synchronized (gRecyclerLock) {
Jeff Brown1f245102010-11-18 20:53:46 -08001646 ev = gRecyclerTop;
1647 if (ev == null) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001648 return new MotionEvent();
Jeff Brown46b9ac02010-04-22 18:58:52 -07001649 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07001650 gRecyclerTop = ev.mNext;
Jeff Brown5c225b12010-06-16 01:53:36 -07001651 gRecyclerUsed -= 1;
Jeff Brown46b9ac02010-04-22 18:58:52 -07001652 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07001653 ev.mNext = null;
Jeff Brown32cbc38552011-12-01 14:01:49 -08001654 ev.prepareForReuse();
Jeff Brown46b9ac02010-04-22 18:58:52 -07001655 return ev;
1656 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08001657
Michael Chan53071d62009-05-13 17:29:48 -07001658 /**
1659 * Create a new MotionEvent, filling in all of the basic values that
1660 * define the motion.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001661 *
Dennis Kempinac1b31d2016-11-02 17:02:25 -07001662 * @param downTime The time (in ms) when the user originally pressed down to start
Michael Chan53071d62009-05-13 17:29:48 -07001663 * a stream of position events. This must be obtained from {@link SystemClock#uptimeMillis()}.
Dennis Kempinac1b31d2016-11-02 17:02:25 -07001664 * @param eventTime The the time (in ms) when this specific event was generated. This
Michael Chan53071d62009-05-13 17:29:48 -07001665 * must be obtained from {@link SystemClock#uptimeMillis()}.
Jeff Browncc0c1592011-02-19 05:07:28 -08001666 * @param action The kind of action being performed, such as {@link #ACTION_DOWN}.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001667 * @param pointerCount The number of pointers that will be in this event.
1668 * @param pointerProperties An array of <em>pointerCount</em> values providing
1669 * a {@link PointerProperties} property object for each pointer, which must
1670 * include the pointer identifier.
1671 * @param pointerCoords An array of <em>pointerCount</em> values providing
1672 * a {@link PointerCoords} coordinate object for each pointer.
1673 * @param metaState The state of any meta / modifier keys that were in effect when
1674 * the event was generated.
1675 * @param buttonState The state of buttons that are pressed.
1676 * @param xPrecision The precision of the X coordinate being reported.
1677 * @param yPrecision The precision of the Y coordinate being reported.
1678 * @param deviceId The id for the device that this event came from. An id of
1679 * zero indicates that the event didn't come from a physical device; other
1680 * numbers are arbitrary and you shouldn't depend on the values.
1681 * @param edgeFlags A bitfield indicating which edges, if any, were touched by this
1682 * MotionEvent.
1683 * @param source The source of this event.
Siarhei Vishniakou85ddfff2018-01-31 16:49:36 -08001684 * @param displayId The display ID associated with this event.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001685 * @param flags The motion event flags.
Siarhei Vishniakou85ddfff2018-01-31 16:49:36 -08001686 * @hide
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001687 */
1688 static public MotionEvent obtain(long downTime, long eventTime,
1689 int action, int pointerCount, PointerProperties[] pointerProperties,
1690 PointerCoords[] pointerCoords, int metaState, int buttonState,
1691 float xPrecision, float yPrecision, int deviceId,
Siarhei Vishniakou85ddfff2018-01-31 16:49:36 -08001692 int edgeFlags, int source, int displayId, int flags) {
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001693 MotionEvent ev = obtain();
1694 ev.mNativePtr = nativeInitialize(ev.mNativePtr,
Siarhei Vishniakou85ddfff2018-01-31 16:49:36 -08001695 deviceId, source, displayId, action, flags, edgeFlags, metaState, buttonState,
Siarhei Vishniakoub05b0b52018-12-28 17:50:24 -08001696 CLASSIFICATION_NONE, 0, 0, xPrecision, yPrecision,
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001697 downTime * NS_PER_MS, eventTime * NS_PER_MS,
1698 pointerCount, pointerProperties, pointerCoords);
Siarhei Vishniakou85ddfff2018-01-31 16:49:36 -08001699 if (ev.mNativePtr == 0) {
1700 Log.e(TAG, "Could not initialize MotionEvent");
1701 ev.recycle();
1702 return null;
1703 }
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001704 return ev;
1705 }
1706
1707 /**
1708 * Create a new MotionEvent, filling in all of the basic values that
1709 * define the motion.
Dennis Kempinac1b31d2016-11-02 17:02:25 -07001710 *
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001711 * @param downTime The time (in ms) when the user originally pressed down to start
1712 * a stream of position events. This must be obtained from {@link SystemClock#uptimeMillis()}.
1713 * @param eventTime The the time (in ms) when this specific event was generated. This
1714 * must be obtained from {@link SystemClock#uptimeMillis()}.
1715 * @param action The kind of action being performed, such as {@link #ACTION_DOWN}.
1716 * @param pointerCount The number of pointers that will be in this event.
Siarhei Vishniakou85ddfff2018-01-31 16:49:36 -08001717 * @param pointerProperties An array of <em>pointerCount</em> values providing
1718 * a {@link PointerProperties} property object for each pointer, which must
1719 * include the pointer identifier.
1720 * @param pointerCoords An array of <em>pointerCount</em> values providing
1721 * a {@link PointerCoords} coordinate object for each pointer.
1722 * @param metaState The state of any meta / modifier keys that were in effect when
1723 * the event was generated.
1724 * @param buttonState The state of buttons that are pressed.
1725 * @param xPrecision The precision of the X coordinate being reported.
1726 * @param yPrecision The precision of the Y coordinate being reported.
1727 * @param deviceId The id for the device that this event came from. An id of
1728 * zero indicates that the event didn't come from a physical device; other
1729 * numbers are arbitrary and you shouldn't depend on the values.
1730 * @param edgeFlags A bitfield indicating which edges, if any, were touched by this
1731 * MotionEvent.
1732 * @param source The source of this event.
1733 * @param flags The motion event flags.
1734 */
1735 public static MotionEvent obtain(long downTime, long eventTime,
1736 int action, int pointerCount, PointerProperties[] pointerProperties,
1737 PointerCoords[] pointerCoords, int metaState, int buttonState,
1738 float xPrecision, float yPrecision, int deviceId,
1739 int edgeFlags, int source, int flags) {
1740 return obtain(downTime, eventTime, action, pointerCount, pointerProperties, pointerCoords,
1741 metaState, buttonState, xPrecision, yPrecision, deviceId, edgeFlags, source,
1742 DEFAULT_DISPLAY, flags);
1743 }
1744
1745 /**
1746 * Create a new MotionEvent, filling in all of the basic values that
1747 * define the motion.
1748 *
1749 * @param downTime The time (in ms) when the user originally pressed down to start
1750 * a stream of position events. This must be obtained from {@link SystemClock#uptimeMillis()}.
1751 * @param eventTime The the time (in ms) when this specific event was generated. This
1752 * must be obtained from {@link SystemClock#uptimeMillis()}.
1753 * @param action The kind of action being performed, such as {@link #ACTION_DOWN}.
1754 * @param pointerCount The number of pointers that will be in this event.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001755 * @param pointerIds An array of <em>pointerCount</em> values providing
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001756 * an identifier for each pointer.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001757 * @param pointerCoords An array of <em>pointerCount</em> values providing
Jeff Brownc5ed5912010-07-14 18:48:53 -07001758 * a {@link PointerCoords} coordinate object for each pointer.
Michael Chan53071d62009-05-13 17:29:48 -07001759 * @param metaState The state of any meta / modifier keys that were in effect when
1760 * the event was generated.
1761 * @param xPrecision The precision of the X coordinate being reported.
1762 * @param yPrecision The precision of the Y coordinate being reported.
1763 * @param deviceId The id for the device that this event came from. An id of
1764 * zero indicates that the event didn't come from a physical device; other
1765 * numbers are arbitrary and you shouldn't depend on the values.
Jeff Brown85a31762010-09-01 17:01:00 -07001766 * @param edgeFlags A bitfield indicating which edges, if any, were touched by this
Michael Chan53071d62009-05-13 17:29:48 -07001767 * MotionEvent.
Jeff Brownc5ed5912010-07-14 18:48:53 -07001768 * @param source The source of this event.
Jeff Brown85a31762010-09-01 17:01:00 -07001769 * @param flags The motion event flags.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001770 *
1771 * @deprecated Use {@link #obtain(long, long, int, int, PointerProperties[], PointerCoords[], int, int, float, float, int, int, int, int)}
1772 * instead.
Michael Chan53071d62009-05-13 17:29:48 -07001773 */
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001774 @Deprecated
Jeff Brownc5ed5912010-07-14 18:48:53 -07001775 static public MotionEvent obtain(long downTime, long eventTime,
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001776 int action, int pointerCount, int[] pointerIds, PointerCoords[] pointerCoords,
Jeff Brownc5ed5912010-07-14 18:48:53 -07001777 int metaState, float xPrecision, float yPrecision, int deviceId,
Jeff Brown85a31762010-09-01 17:01:00 -07001778 int edgeFlags, int source, int flags) {
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001779 synchronized (gSharedTempLock) {
1780 ensureSharedTempPointerCapacity(pointerCount);
1781 final PointerProperties[] pp = gSharedTempPointerProperties;
1782 for (int i = 0; i < pointerCount; i++) {
1783 pp[i].clear();
1784 pp[i].id = pointerIds[i];
1785 }
1786 return obtain(downTime, eventTime, action, pointerCount, pp,
1787 pointerCoords, metaState, 0, xPrecision, yPrecision, deviceId,
1788 edgeFlags, source, flags);
1789 }
Michael Chan53071d62009-05-13 17:29:48 -07001790 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08001791
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001792 /**
1793 * Create a new MotionEvent, filling in all of the basic values that
1794 * define the motion.
Romain Guycafdea62009-06-12 10:51:36 -07001795 *
1796 * @param downTime The time (in ms) when the user originally pressed down to start
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001797 * a stream of position events. This must be obtained from {@link SystemClock#uptimeMillis()}.
Romain Guycafdea62009-06-12 10:51:36 -07001798 * @param eventTime The the time (in ms) when this specific event was generated. This
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001799 * must be obtained from {@link SystemClock#uptimeMillis()}.
Jeff Browncc0c1592011-02-19 05:07:28 -08001800 * @param action The kind of action being performed, such as {@link #ACTION_DOWN}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001801 * @param x The X coordinate of this event.
1802 * @param y The Y coordinate of this event.
Romain Guycafdea62009-06-12 10:51:36 -07001803 * @param pressure The current pressure of this event. The pressure generally
1804 * ranges from 0 (no pressure at all) to 1 (normal pressure), however
1805 * values higher than 1 may be generated depending on the calibration of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001806 * the input device.
1807 * @param size A scaled value of the approximate size of the area being pressed when
Romain Guycafdea62009-06-12 10:51:36 -07001808 * touched with the finger. The actual value in pixels corresponding to the finger
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001809 * touch is normalized with a device specific range of values
1810 * and scaled to a value between 0 and 1.
1811 * @param metaState The state of any meta / modifier keys that were in effect when
1812 * the event was generated.
1813 * @param xPrecision The precision of the X coordinate being reported.
1814 * @param yPrecision The precision of the Y coordinate being reported.
1815 * @param deviceId The id for the device that this event came from. An id of
1816 * zero indicates that the event didn't come from a physical device; other
1817 * numbers are arbitrary and you shouldn't depend on the values.
Jeff Brown85a31762010-09-01 17:01:00 -07001818 * @param edgeFlags A bitfield indicating which edges, if any, were touched by this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001819 * MotionEvent.
1820 */
1821 static public MotionEvent obtain(long downTime, long eventTime, int action,
1822 float x, float y, float pressure, float size, int metaState,
1823 float xPrecision, float yPrecision, int deviceId, int edgeFlags) {
Arthur Hung19b517a2018-09-14 18:24:31 +08001824 return obtain(downTime, eventTime, action, x, y, pressure, size, metaState,
1825 xPrecision, yPrecision, deviceId, edgeFlags, InputDevice.SOURCE_UNKNOWN,
1826 DEFAULT_DISPLAY);
1827 }
1828
1829 /**
1830 * Create a new MotionEvent, filling in all of the basic values that
1831 * define the motion.
1832 *
1833 * @param downTime The time (in ms) when the user originally pressed down to start
1834 * a stream of position events. This must be obtained from {@link SystemClock#uptimeMillis()}.
1835 * @param eventTime The the time (in ms) when this specific event was generated. This
1836 * must be obtained from {@link SystemClock#uptimeMillis()}.
1837 * @param action The kind of action being performed, such as {@link #ACTION_DOWN}.
1838 * @param x The X coordinate of this event.
1839 * @param y The Y coordinate of this event.
1840 * @param pressure The current pressure of this event. The pressure generally
1841 * ranges from 0 (no pressure at all) to 1 (normal pressure), however
1842 * values higher than 1 may be generated depending on the calibration of
1843 * the input device.
1844 * @param size A scaled value of the approximate size of the area being pressed when
1845 * touched with the finger. The actual value in pixels corresponding to the finger
1846 * touch is normalized with a device specific range of values
1847 * and scaled to a value between 0 and 1.
1848 * @param metaState The state of any meta / modifier keys that were in effect when
1849 * the event was generated.
1850 * @param xPrecision The precision of the X coordinate being reported.
1851 * @param yPrecision The precision of the Y coordinate being reported.
1852 * @param deviceId The id for the device that this event came from. An id of
1853 * zero indicates that the event didn't come from a physical device; other
1854 * numbers are arbitrary and you shouldn't depend on the values.
1855 * @param source The source of this event.
1856 * @param edgeFlags A bitfield indicating which edges, if any, were touched by this
1857 * MotionEvent.
1858 * @param displayId The display ID associated with this event.
1859 * @hide
1860 */
1861 public static MotionEvent obtain(long downTime, long eventTime, int action,
1862 float x, float y, float pressure, float size, int metaState,
1863 float xPrecision, float yPrecision, int deviceId, int edgeFlags, int source,
1864 int displayId) {
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001865 MotionEvent ev = obtain();
1866 synchronized (gSharedTempLock) {
1867 ensureSharedTempPointerCapacity(1);
1868 final PointerProperties[] pp = gSharedTempPointerProperties;
1869 pp[0].clear();
1870 pp[0].id = 0;
Jeff Brown91c69ab2011-02-14 17:03:18 -08001871
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001872 final PointerCoords pc[] = gSharedTempPointerCoords;
1873 pc[0].clear();
1874 pc[0].x = x;
1875 pc[0].y = y;
1876 pc[0].pressure = pressure;
1877 pc[0].size = size;
1878
Jeff Brown91c69ab2011-02-14 17:03:18 -08001879 ev.mNativePtr = nativeInitialize(ev.mNativePtr,
Arthur Hung19b517a2018-09-14 18:24:31 +08001880 deviceId, source, displayId,
Siarhei Vishniakoub05b0b52018-12-28 17:50:24 -08001881 action, 0, edgeFlags, metaState, 0 /*buttonState*/, CLASSIFICATION_NONE,
Jeff Brown91c69ab2011-02-14 17:03:18 -08001882 0, 0, xPrecision, yPrecision,
1883 downTime * NS_PER_MS, eventTime * NS_PER_MS,
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001884 1, pp, pc);
Jeff Brown91c69ab2011-02-14 17:03:18 -08001885 return ev;
1886 }
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001887 }
1888
1889 /**
1890 * Create a new MotionEvent, filling in all of the basic values that
1891 * define the motion.
1892 *
1893 * @param downTime The time (in ms) when the user originally pressed down to start
1894 * a stream of position events. This must be obtained from {@link SystemClock#uptimeMillis()}.
1895 * @param eventTime The the time (in ms) when this specific event was generated. This
1896 * must be obtained from {@link SystemClock#uptimeMillis()}.
Jeff Browncc0c1592011-02-19 05:07:28 -08001897 * @param action The kind of action being performed, such as {@link #ACTION_DOWN}.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001898 * @param pointerCount The number of pointers that are active in this event.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001899 * @param x The X coordinate of this event.
1900 * @param y The Y coordinate of this event.
1901 * @param pressure The current pressure of this event. The pressure generally
1902 * ranges from 0 (no pressure at all) to 1 (normal pressure), however
1903 * values higher than 1 may be generated depending on the calibration of
1904 * the input device.
1905 * @param size A scaled value of the approximate size of the area being pressed when
1906 * touched with the finger. The actual value in pixels corresponding to the finger
1907 * touch is normalized with a device specific range of values
1908 * and scaled to a value between 0 and 1.
1909 * @param metaState The state of any meta / modifier keys that were in effect when
1910 * the event was generated.
1911 * @param xPrecision The precision of the X coordinate being reported.
1912 * @param yPrecision The precision of the Y coordinate being reported.
1913 * @param deviceId The id for the device that this event came from. An id of
1914 * zero indicates that the event didn't come from a physical device; other
1915 * numbers are arbitrary and you shouldn't depend on the values.
Jeff Brown85a31762010-09-01 17:01:00 -07001916 * @param edgeFlags A bitfield indicating which edges, if any, were touched by this
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001917 * MotionEvent.
Dennis Kempinac1b31d2016-11-02 17:02:25 -07001918 *
Jeff Brown5c225b12010-06-16 01:53:36 -07001919 * @deprecated Use {@link #obtain(long, long, int, float, float, float, float, int, float, float, int, int)}
1920 * instead.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001921 */
Jeff Brown5c225b12010-06-16 01:53:36 -07001922 @Deprecated
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001923 static public MotionEvent obtain(long downTime, long eventTime, int action,
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001924 int pointerCount, float x, float y, float pressure, float size, int metaState,
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001925 float xPrecision, float yPrecision, int deviceId, int edgeFlags) {
Jeff Brown5c225b12010-06-16 01:53:36 -07001926 return obtain(downTime, eventTime, action, x, y, pressure, size,
1927 metaState, xPrecision, yPrecision, deviceId, edgeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001928 }
Romain Guycafdea62009-06-12 10:51:36 -07001929
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001930 /**
1931 * Create a new MotionEvent, filling in a subset of the basic motion
1932 * values. Those not specified here are: device id (always 0), pressure
1933 * and size (always 1), x and y precision (always 1), and edgeFlags (always 0).
Romain Guycafdea62009-06-12 10:51:36 -07001934 *
1935 * @param downTime The time (in ms) when the user originally pressed down to start
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001936 * a stream of position events. This must be obtained from {@link SystemClock#uptimeMillis()}.
Romain Guycafdea62009-06-12 10:51:36 -07001937 * @param eventTime The the time (in ms) when this specific event was generated. This
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001938 * must be obtained from {@link SystemClock#uptimeMillis()}.
Jeff Browncc0c1592011-02-19 05:07:28 -08001939 * @param action The kind of action being performed, such as {@link #ACTION_DOWN}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001940 * @param x The X coordinate of this event.
1941 * @param y The Y coordinate of this event.
1942 * @param metaState The state of any meta / modifier keys that were in effect when
1943 * the event was generated.
1944 */
1945 static public MotionEvent obtain(long downTime, long eventTime, int action,
1946 float x, float y, int metaState) {
Jeff Brown5c225b12010-06-16 01:53:36 -07001947 return obtain(downTime, eventTime, action, x, y, 1.0f, 1.0f,
1948 metaState, 1.0f, 1.0f, 0, 0);
Mitsuru Oshima8169dae2009-04-28 18:12:09 -07001949 }
1950
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001951 /**
1952 * Create a new MotionEvent, copying from an existing one.
1953 */
Jeff Brown91c69ab2011-02-14 17:03:18 -08001954 static public MotionEvent obtain(MotionEvent other) {
1955 if (other == null) {
1956 throw new IllegalArgumentException("other motion event must not be null");
1957 }
1958
1959 MotionEvent ev = obtain();
1960 ev.mNativePtr = nativeCopy(ev.mNativePtr, other.mNativePtr, true /*keepHistory*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001961 return ev;
1962 }
Romain Guycafdea62009-06-12 10:51:36 -07001963
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001964 /**
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07001965 * Create a new MotionEvent, copying from an existing one, but not including
1966 * any historical point information.
1967 */
Jeff Brown91c69ab2011-02-14 17:03:18 -08001968 static public MotionEvent obtainNoHistory(MotionEvent other) {
1969 if (other == null) {
1970 throw new IllegalArgumentException("other motion event must not be null");
1971 }
1972
1973 MotionEvent ev = obtain();
1974 ev.mNativePtr = nativeCopy(ev.mNativePtr, other.mNativePtr, false /*keepHistory*/);
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07001975 return ev;
1976 }
1977
Jeff Brown21bc5c92011-02-28 18:27:14 -08001978 /** @hide */
1979 @Override
Mathew Inwooda570dee2018-08-17 14:56:00 +01001980 @UnsupportedAppUsage
Jeff Brown21bc5c92011-02-28 18:27:14 -08001981 public MotionEvent copy() {
1982 return obtain(this);
1983 }
1984
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07001985 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001986 * Recycle the MotionEvent, to be re-used by a later caller. After calling
1987 * this function you must not ever touch the event again.
1988 */
Jeff Brown92cc2d82011-12-02 01:19:47 -08001989 @Override
Jeff Brown5c225b12010-06-16 01:53:36 -07001990 public final void recycle() {
Jeff Brown32cbc38552011-12-01 14:01:49 -08001991 super.recycle();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001992
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001993 synchronized (gRecyclerLock) {
1994 if (gRecyclerUsed < MAX_RECYCLED) {
1995 gRecyclerUsed++;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001996 mNext = gRecyclerTop;
1997 gRecyclerTop = this;
1998 }
1999 }
2000 }
Jeff Brown9ea77fc2012-03-21 19:49:27 -07002001
Jeff Brown5c225b12010-06-16 01:53:36 -07002002 /**
Jeff Brown9ea77fc2012-03-21 19:49:27 -07002003 * Applies a scale factor to all points within this event.
Jeff Brown5c225b12010-06-16 01:53:36 -07002004 *
Jeff Brown9ea77fc2012-03-21 19:49:27 -07002005 * This method is used to adjust touch events to simulate different density
2006 * displays for compatibility mode. The values returned by {@link #getRawX()},
2007 * {@link #getRawY()}, {@link #getXPrecision()} and {@link #getYPrecision()}
2008 * are also affected by the scale factor.
2009 *
2010 * @param scale The scale factor to apply.
Jeff Brown5c225b12010-06-16 01:53:36 -07002011 * @hide
2012 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01002013 @UnsupportedAppUsage
Jeff Brown5c225b12010-06-16 01:53:36 -07002014 public final void scale(float scale) {
Jeff Brown9ea77fc2012-03-21 19:49:27 -07002015 if (scale != 1.0f) {
2016 nativeScale(mNativePtr, scale);
2017 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08002018 }
2019
2020 /** {@inheritDoc} */
2021 @Override
2022 public final int getDeviceId() {
2023 return nativeGetDeviceId(mNativePtr);
2024 }
2025
2026 /** {@inheritDoc} */
2027 @Override
2028 public final int getSource() {
2029 return nativeGetSource(mNativePtr);
2030 }
2031
2032 /** {@inheritDoc} */
2033 @Override
2034 public final void setSource(int source) {
2035 nativeSetSource(mNativePtr, source);
Jeff Brown5c225b12010-06-16 01:53:36 -07002036 }
Romain Guycafdea62009-06-12 10:51:36 -07002037
Siarhei Vishniakou85ddfff2018-01-31 16:49:36 -08002038 /** @hide */
Siarhei Vishniakou91fa08f2018-06-08 22:49:30 +01002039 @Override
Siarhei Vishniakou85ddfff2018-01-31 16:49:36 -08002040 public int getDisplayId() {
2041 return nativeGetDisplayId(mNativePtr);
2042 }
2043
2044 /** @hide */
lumark793e0562018-07-09 22:14:33 +08002045 @TestApi
Siarhei Vishniakou91fa08f2018-06-08 22:49:30 +01002046 @Override
Siarhei Vishniakou85ddfff2018-01-31 16:49:36 -08002047 public void setDisplayId(int displayId) {
2048 nativeSetDisplayId(mNativePtr, displayId);
2049 }
2050
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002051 /**
Jeff Browncc0c1592011-02-19 05:07:28 -08002052 * Return the kind of action being performed.
2053 * Consider using {@link #getActionMasked} and {@link #getActionIndex} to retrieve
2054 * the separate masked action and pointer index.
2055 * @return The action, such as {@link #ACTION_DOWN} or
2056 * the combination of {@link #ACTION_POINTER_DOWN} with a shifted pointer index.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002057 */
2058 public final int getAction() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002059 return nativeGetAction(mNativePtr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002060 }
2061
2062 /**
Jeff Browncc0c1592011-02-19 05:07:28 -08002063 * Return the masked action being performed, without pointer index information.
2064 * Use {@link #getActionIndex} to return the index associated with pointer actions.
2065 * @return The action, such as {@link #ACTION_DOWN} or {@link #ACTION_POINTER_DOWN}.
Dianne Hackbornb125dc52010-02-12 15:52:09 -08002066 */
2067 public final int getActionMasked() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002068 return nativeGetAction(mNativePtr) & ACTION_MASK;
Dianne Hackbornb125dc52010-02-12 15:52:09 -08002069 }
2070
2071 /**
2072 * For {@link #ACTION_POINTER_DOWN} or {@link #ACTION_POINTER_UP}
2073 * as returned by {@link #getActionMasked}, this returns the associated
Jeff Browncc0c1592011-02-19 05:07:28 -08002074 * pointer index.
2075 * The index may be used with {@link #getPointerId(int)},
Dianne Hackbornb125dc52010-02-12 15:52:09 -08002076 * {@link #getX(int)}, {@link #getY(int)}, {@link #getPressure(int)},
2077 * and {@link #getSize(int)} to get information about the pointer that has
2078 * gone down or up.
Jeff Browncc0c1592011-02-19 05:07:28 -08002079 * @return The index associated with the action.
Dianne Hackbornb125dc52010-02-12 15:52:09 -08002080 */
2081 public final int getActionIndex() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002082 return (nativeGetAction(mNativePtr) & ACTION_POINTER_INDEX_MASK)
2083 >> ACTION_POINTER_INDEX_SHIFT;
Dianne Hackbornb125dc52010-02-12 15:52:09 -08002084 }
2085
2086 /**
Jeff Brown33bbfd22011-02-24 20:55:35 -08002087 * Returns true if this motion event is a touch event.
2088 * <p>
Jeff Browna032cc02011-03-07 16:56:21 -08002089 * Specifically excludes pointer events with action {@link #ACTION_HOVER_MOVE},
2090 * {@link #ACTION_HOVER_ENTER}, {@link #ACTION_HOVER_EXIT}, or {@link #ACTION_SCROLL}
2091 * because they are not actually touch events (the pointer is not down).
Jeff Brown33bbfd22011-02-24 20:55:35 -08002092 * </p>
2093 * @return True if this motion event is a touch event.
2094 * @hide
2095 */
2096 public final boolean isTouchEvent() {
Jeff Brown56194eb2011-03-02 19:23:13 -08002097 return nativeIsTouchEvent(mNativePtr);
Jeff Brown33bbfd22011-02-24 20:55:35 -08002098 }
2099
2100 /**
Jeff Brown85a31762010-09-01 17:01:00 -07002101 * Gets the motion event flags.
2102 *
2103 * @see #FLAG_WINDOW_IS_OBSCURED
2104 */
2105 public final int getFlags() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002106 return nativeGetFlags(mNativePtr);
Jeff Brown85a31762010-09-01 17:01:00 -07002107 }
2108
Jeff Brown21bc5c92011-02-28 18:27:14 -08002109 /** @hide */
2110 @Override
2111 public final boolean isTainted() {
2112 final int flags = getFlags();
2113 return (flags & FLAG_TAINTED) != 0;
2114 }
2115
2116 /** @hide */
2117 @Override
2118 public final void setTainted(boolean tainted) {
2119 final int flags = getFlags();
2120 nativeSetFlags(mNativePtr, tainted ? flags | FLAG_TAINTED : flags & ~FLAG_TAINTED);
2121 }
2122
Svetoslavded133c2015-01-30 20:28:41 -08002123 /** @hide */
2124 public final boolean isTargetAccessibilityFocus() {
2125 final int flags = getFlags();
2126 return (flags & FLAG_TARGET_ACCESSIBILITY_FOCUS) != 0;
2127 }
2128
2129 /** @hide */
2130 public final void setTargetAccessibilityFocus(boolean targetsFocus) {
2131 final int flags = getFlags();
2132 nativeSetFlags(mNativePtr, targetsFocus
2133 ? flags | FLAG_TARGET_ACCESSIBILITY_FOCUS
2134 : flags & ~FLAG_TARGET_ACCESSIBILITY_FOCUS);
2135 }
2136
Vladislav Kaznacheev5a77c372016-10-10 16:11:15 -07002137 /** @hide */
2138 public final boolean isHoverExitPending() {
2139 final int flags = getFlags();
2140 return (flags & FLAG_HOVER_EXIT_PENDING) != 0;
2141 }
2142
2143 /** @hide */
2144 public void setHoverExitPending(boolean hoverExitPending) {
2145 final int flags = getFlags();
2146 nativeSetFlags(mNativePtr, hoverExitPending
2147 ? flags | FLAG_HOVER_EXIT_PENDING
2148 : flags & ~FLAG_HOVER_EXIT_PENDING);
2149 }
2150
Jeff Brown85a31762010-09-01 17:01:00 -07002151 /**
Romain Guycafdea62009-06-12 10:51:36 -07002152 * Returns the time (in ms) when the user originally pressed down to start
2153 * a stream of position events.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002154 */
2155 public final long getDownTime() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002156 return nativeGetDownTimeNanos(mNativePtr) / NS_PER_MS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002157 }
2158
2159 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07002160 * Sets the time (in ms) when the user originally pressed down to start
2161 * a stream of position events.
2162 *
2163 * @hide
2164 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01002165 @UnsupportedAppUsage
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07002166 public final void setDownTime(long downTime) {
2167 nativeSetDownTimeNanos(mNativePtr, downTime * NS_PER_MS);
2168 }
2169
2170 /**
Jeff Brownb11499d2012-04-20 19:54:22 -07002171 * Retrieve the time this event occurred,
2172 * in the {@link android.os.SystemClock#uptimeMillis} time base.
2173 *
2174 * @return Returns the time this event occurred,
2175 * in the {@link android.os.SystemClock#uptimeMillis} time base.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002176 */
Jeff Brownb11499d2012-04-20 19:54:22 -07002177 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002178 public final long getEventTime() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002179 return nativeGetEventTimeNanos(mNativePtr, HISTORY_CURRENT) / NS_PER_MS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002180 }
2181
2182 /**
Jeff Brownb11499d2012-04-20 19:54:22 -07002183 * Retrieve the time this event occurred,
2184 * in the {@link android.os.SystemClock#uptimeMillis} time base but with
2185 * nanosecond precision.
2186 * <p>
Michael Chan53071d62009-05-13 17:29:48 -07002187 * The value is in nanosecond precision but it may not have nanosecond accuracy.
Jeff Brownb11499d2012-04-20 19:54:22 -07002188 * </p>
2189 *
2190 * @return Returns the time this event occurred,
2191 * in the {@link android.os.SystemClock#uptimeMillis} time base but with
2192 * nanosecond precision.
Michael Chan53071d62009-05-13 17:29:48 -07002193 *
2194 * @hide
2195 */
Jeff Brownb11499d2012-04-20 19:54:22 -07002196 @Override
Mathew Inwooda570dee2018-08-17 14:56:00 +01002197 @UnsupportedAppUsage
Michael Chan53071d62009-05-13 17:29:48 -07002198 public final long getEventTimeNano() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002199 return nativeGetEventTimeNanos(mNativePtr, HISTORY_CURRENT);
Michael Chan53071d62009-05-13 17:29:48 -07002200 }
2201
2202 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002203 * {@link #getX(int)} for the first pointer index (may be an
2204 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002205 *
2206 * @see #AXIS_X
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002207 */
2208 public final float getX() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002209 return nativeGetAxisValue(mNativePtr, AXIS_X, 0, HISTORY_CURRENT);
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002210 }
2211
2212 /**
2213 * {@link #getY(int)} for the first pointer index (may be an
2214 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002215 *
2216 * @see #AXIS_Y
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002217 */
2218 public final float getY() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002219 return nativeGetAxisValue(mNativePtr, AXIS_Y, 0, HISTORY_CURRENT);
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002220 }
2221
2222 /**
2223 * {@link #getPressure(int)} for the first pointer index (may be an
2224 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002225 *
2226 * @see #AXIS_PRESSURE
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002227 */
2228 public final float getPressure() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002229 return nativeGetAxisValue(mNativePtr, AXIS_PRESSURE, 0, HISTORY_CURRENT);
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002230 }
2231
2232 /**
2233 * {@link #getSize(int)} for the first pointer index (may be an
2234 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002235 *
2236 * @see #AXIS_SIZE
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002237 */
2238 public final float getSize() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002239 return nativeGetAxisValue(mNativePtr, AXIS_SIZE, 0, HISTORY_CURRENT);
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002240 }
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002241
Jeff Brownc5ed5912010-07-14 18:48:53 -07002242 /**
2243 * {@link #getTouchMajor(int)} for the first pointer index (may be an
2244 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002245 *
2246 * @see #AXIS_TOUCH_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002247 */
2248 public final float getTouchMajor() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002249 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MAJOR, 0, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002250 }
2251
2252 /**
2253 * {@link #getTouchMinor(int)} for the first pointer index (may be an
2254 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002255 *
2256 * @see #AXIS_TOUCH_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002257 */
2258 public final float getTouchMinor() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002259 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MINOR, 0, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002260 }
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002261
Jeff Brownc5ed5912010-07-14 18:48:53 -07002262 /**
2263 * {@link #getToolMajor(int)} for the first pointer index (may be an
2264 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002265 *
2266 * @see #AXIS_TOOL_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002267 */
2268 public final float getToolMajor() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002269 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MAJOR, 0, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002270 }
2271
2272 /**
2273 * {@link #getToolMinor(int)} for the first pointer index (may be an
2274 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002275 *
2276 * @see #AXIS_TOOL_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002277 */
2278 public final float getToolMinor() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002279 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MINOR, 0, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002280 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08002281
Jeff Brownc5ed5912010-07-14 18:48:53 -07002282 /**
2283 * {@link #getOrientation(int)} for the first pointer index (may be an
2284 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002285 *
2286 * @see #AXIS_ORIENTATION
Jeff Brownc5ed5912010-07-14 18:48:53 -07002287 */
2288 public final float getOrientation() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002289 return nativeGetAxisValue(mNativePtr, AXIS_ORIENTATION, 0, HISTORY_CURRENT);
2290 }
2291
2292 /**
2293 * {@link #getAxisValue(int)} for the first pointer index (may be an
2294 * arbitrary pointer identifier).
2295 *
2296 * @param axis The axis identifier for the axis value to retrieve.
2297 *
2298 * @see #AXIS_X
2299 * @see #AXIS_Y
2300 */
2301 public final float getAxisValue(int axis) {
2302 return nativeGetAxisValue(mNativePtr, axis, 0, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002303 }
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002304
2305 /**
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002306 * The number of pointers of data contained in this event. Always
2307 * >= 1.
2308 */
2309 public final int getPointerCount() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002310 return nativeGetPointerCount(mNativePtr);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002311 }
John Reck09709972016-10-03 15:47:18 -07002312
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002313 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002314 * Return the pointer identifier associated with a particular pointer
Trevor Johns682c24e2016-04-12 10:13:47 -07002315 * data index in this event. The identifier tells you the actual pointer
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002316 * number associated with the data, accounting for individual pointers
2317 * going up and down since the start of the current gesture.
2318 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2319 * (the first pointer that is down) to {@link #getPointerCount()}-1.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002320 */
Dianne Hackbornd41ba662009-08-05 15:30:56 -07002321 public final int getPointerId(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002322 return nativeGetPointerId(mNativePtr, pointerIndex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002323 }
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07002324
2325 /**
2326 * Gets the tool type of a pointer for the given pointer index.
2327 * The tool type indicates the type of tool used to make contact such
2328 * as a finger or stylus, if known.
2329 *
2330 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2331 * (the first pointer that is down) to {@link #getPointerCount()}-1.
2332 * @return The tool type of the pointer.
2333 *
2334 * @see #TOOL_TYPE_UNKNOWN
2335 * @see #TOOL_TYPE_FINGER
2336 * @see #TOOL_TYPE_STYLUS
2337 * @see #TOOL_TYPE_MOUSE
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07002338 */
2339 public final int getToolType(int pointerIndex) {
2340 return nativeGetToolType(mNativePtr, pointerIndex);
2341 }
2342
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002343 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002344 * Given a pointer identifier, find the index of its data in the event.
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002345 *
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002346 * @param pointerId The identifier of the pointer to be found.
2347 * @return Returns either the index of the pointer (for use with
Gilles Debunneb0d6ba12010-08-17 20:01:42 -07002348 * {@link #getX(int)} et al.), or -1 if there is no data available for
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002349 * that pointer identifier.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002350 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002351 public final int findPointerIndex(int pointerId) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002352 return nativeFindPointerIndex(mNativePtr, pointerId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002353 }
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07002354
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002355 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002356 * Returns the X coordinate of this event for the given pointer
2357 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
2358 * identifier for this index).
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002359 * Whole numbers are pixels; the
2360 * value may have a fraction for input devices that are sub-pixel precise.
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002361 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2362 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002363 *
2364 * @see #AXIS_X
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002365 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002366 public final float getX(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002367 return nativeGetAxisValue(mNativePtr, AXIS_X, pointerIndex, HISTORY_CURRENT);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002368 }
2369
2370 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002371 * Returns the Y coordinate of this event for the given pointer
2372 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
2373 * identifier for this index).
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002374 * Whole numbers are pixels; the
2375 * value may have a fraction for input devices that are sub-pixel precise.
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002376 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2377 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002378 *
2379 * @see #AXIS_Y
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002380 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002381 public final float getY(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002382 return nativeGetAxisValue(mNativePtr, AXIS_Y, pointerIndex, HISTORY_CURRENT);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002383 }
2384
2385 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002386 * Returns the current pressure of this event for the given pointer
2387 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
2388 * identifier for this index).
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002389 * The pressure generally
Romain Guycafdea62009-06-12 10:51:36 -07002390 * ranges from 0 (no pressure at all) to 1 (normal pressure), however
2391 * values higher than 1 may be generated depending on the calibration of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002392 * the input device.
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002393 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2394 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002395 *
2396 * @see #AXIS_PRESSURE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002397 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002398 public final float getPressure(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002399 return nativeGetAxisValue(mNativePtr, AXIS_PRESSURE, pointerIndex, HISTORY_CURRENT);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002400 }
2401
2402 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002403 * Returns a scaled value of the approximate size for the given pointer
2404 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
2405 * identifier for this index).
2406 * This represents some approximation of the area of the screen being
2407 * pressed; the actual value in pixels corresponding to the
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002408 * touch is normalized with the device specific range of values
Romain Guycafdea62009-06-12 10:51:36 -07002409 * 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 -08002410 * determine fat touch events.
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002411 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2412 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002413 *
2414 * @see #AXIS_SIZE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002415 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002416 public final float getSize(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002417 return nativeGetAxisValue(mNativePtr, AXIS_SIZE, pointerIndex, HISTORY_CURRENT);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002418 }
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002419
Jeff Brownc5ed5912010-07-14 18:48:53 -07002420 /**
2421 * Returns the length of the major axis of an ellipse that describes the touch
2422 * area at the point of contact for the given pointer
2423 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
2424 * identifier for this index).
2425 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2426 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002427 *
2428 * @see #AXIS_TOUCH_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002429 */
2430 public final float getTouchMajor(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002431 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MAJOR, pointerIndex, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002432 }
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002433
Jeff Brownc5ed5912010-07-14 18:48:53 -07002434 /**
2435 * Returns the length of the minor axis of an ellipse that describes the touch
2436 * area at the point of contact for the given pointer
2437 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
2438 * identifier for this index).
2439 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2440 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002441 *
2442 * @see #AXIS_TOUCH_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002443 */
2444 public final float getTouchMinor(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002445 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MINOR, pointerIndex, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002446 }
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002447
Jeff Brownc5ed5912010-07-14 18:48:53 -07002448 /**
2449 * Returns the length of the major axis of an ellipse that describes the size of
2450 * the approaching tool for the given pointer
2451 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
2452 * identifier for this index).
2453 * The tool area represents the estimated size of the finger or pen that is
2454 * touching the device independent of its actual touch area at the point of contact.
2455 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2456 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002457 *
2458 * @see #AXIS_TOOL_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002459 */
2460 public final float getToolMajor(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002461 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MAJOR, pointerIndex, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002462 }
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002463
Jeff Brownc5ed5912010-07-14 18:48:53 -07002464 /**
2465 * Returns the length of the minor axis of an ellipse that describes the size of
2466 * the approaching tool for the given pointer
2467 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
2468 * identifier for this index).
2469 * The tool area represents the estimated size of the finger or pen that is
2470 * touching the device independent of its actual touch area at the point of contact.
2471 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2472 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002473 *
2474 * @see #AXIS_TOOL_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002475 */
2476 public final float getToolMinor(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002477 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MINOR, pointerIndex, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002478 }
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002479
Jeff Brownc5ed5912010-07-14 18:48:53 -07002480 /**
2481 * Returns the orientation of the touch area and tool area in radians clockwise from vertical
2482 * for the given pointer <em>index</em> (use {@link #getPointerId(int)} to find the pointer
2483 * identifier for this index).
Jeff Brown6f2fba42011-02-19 01:08:02 -08002484 * An angle of 0 radians indicates that the major axis of contact is oriented
Jeff Brownc5ed5912010-07-14 18:48:53 -07002485 * upwards, is perfectly circular or is of unknown orientation. A positive angle
2486 * indicates that the major axis of contact is oriented to the right. A negative angle
2487 * indicates that the major axis of contact is oriented to the left.
Jeff Brown6d0fec22010-07-23 21:28:06 -07002488 * The full range is from -PI/2 radians (finger pointing fully left) to PI/2 radians
Jeff Brownc5ed5912010-07-14 18:48:53 -07002489 * (finger pointing fully right).
2490 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2491 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002492 *
2493 * @see #AXIS_ORIENTATION
Jeff Brownc5ed5912010-07-14 18:48:53 -07002494 */
2495 public final float getOrientation(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002496 return nativeGetAxisValue(mNativePtr, AXIS_ORIENTATION, pointerIndex, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002497 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08002498
2499 /**
2500 * Returns the value of the requested axis for the given pointer <em>index</em>
2501 * (use {@link #getPointerId(int)} to find the pointer identifier for this index).
2502 *
2503 * @param axis The axis identifier for the axis value to retrieve.
2504 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2505 * (the first pointer that is down) to {@link #getPointerCount()}-1.
2506 * @return The value of the axis, or 0 if the axis is not available.
2507 *
2508 * @see #AXIS_X
2509 * @see #AXIS_Y
2510 */
2511 public final float getAxisValue(int axis, int pointerIndex) {
2512 return nativeGetAxisValue(mNativePtr, axis, pointerIndex, HISTORY_CURRENT);
2513 }
2514
Jeff Brownc5ed5912010-07-14 18:48:53 -07002515 /**
2516 * Populates a {@link PointerCoords} object with pointer coordinate data for
2517 * the specified pointer index.
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002518 *
Jeff Brownc5ed5912010-07-14 18:48:53 -07002519 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2520 * (the first pointer that is down) to {@link #getPointerCount()}-1.
2521 * @param outPointerCoords The pointer coordinate object to populate.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002522 *
2523 * @see PointerCoords
Jeff Brownc5ed5912010-07-14 18:48:53 -07002524 */
2525 public final void getPointerCoords(int pointerIndex, PointerCoords outPointerCoords) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002526 nativeGetPointerCoords(mNativePtr, pointerIndex, HISTORY_CURRENT, outPointerCoords);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002527 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002528
2529 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07002530 * Populates a {@link PointerProperties} object with pointer properties for
2531 * the specified pointer index.
2532 *
2533 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2534 * (the first pointer that is down) to {@link #getPointerCount()}-1.
2535 * @param outPointerProperties The pointer properties object to populate.
2536 *
2537 * @see PointerProperties
2538 */
2539 public final void getPointerProperties(int pointerIndex,
2540 PointerProperties outPointerProperties) {
2541 nativeGetPointerProperties(mNativePtr, pointerIndex, outPointerProperties);
2542 }
2543
2544 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002545 * Returns the state of any meta / modifier keys that were in effect when
2546 * the event was generated. This is the same values as those
2547 * returned by {@link KeyEvent#getMetaState() KeyEvent.getMetaState}.
2548 *
2549 * @return an integer in which each bit set to 1 represents a pressed
2550 * meta key
2551 *
2552 * @see KeyEvent#getMetaState()
2553 */
2554 public final int getMetaState() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002555 return nativeGetMetaState(mNativePtr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002556 }
2557
2558 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07002559 * Gets the state of all buttons that are pressed such as a mouse or stylus button.
2560 *
2561 * @return The button state.
2562 *
2563 * @see #BUTTON_PRIMARY
2564 * @see #BUTTON_SECONDARY
2565 * @see #BUTTON_TERTIARY
2566 * @see #BUTTON_FORWARD
2567 * @see #BUTTON_BACK
Michael Wright5bd69e62015-05-14 14:48:08 +01002568 * @see #BUTTON_STYLUS_PRIMARY
2569 * @see #BUTTON_STYLUS_SECONDARY
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07002570 */
2571 public final int getButtonState() {
2572 return nativeGetButtonState(mNativePtr);
2573 }
2574
2575 /**
Michael Wright5bd69e62015-05-14 14:48:08 +01002576 * Sets the bitfield indicating which buttons are pressed.
2577 *
2578 * @see #getButtonState()
2579 * @hide
2580 */
Kirill Grouchnikovb2a44f02016-09-14 16:24:44 -07002581 @TestApi
Michael Wright5bd69e62015-05-14 14:48:08 +01002582 public final void setButtonState(int buttonState) {
2583 nativeSetButtonState(mNativePtr, buttonState);
2584 }
2585
2586 /**
Siarhei Vishniakoub05b0b52018-12-28 17:50:24 -08002587 * Returns the classification for the current gesture.
2588 * The classification may change as more events become available for the same gesture.
2589 *
2590 * @see #CLASSIFICATION_NONE
2591 * @see #CLASSIFICATION_AMBIGUOUS_GESTURE
2592 * @see #CLASSIFICATION_DEEP_PRESS
2593 */
2594 public @Classification int getClassification() {
2595 return nativeGetClassification(mNativePtr);
2596 }
2597
2598 /**
Michael Wright5bd69e62015-05-14 14:48:08 +01002599 * Gets which button has been modified during a press or release action.
2600 *
2601 * For actions other than {@link #ACTION_BUTTON_PRESS} and {@link #ACTION_BUTTON_RELEASE}
2602 * the returned value is undefined.
2603 *
2604 * @see #getButtonState()
2605 */
2606 public final int getActionButton() {
2607 return nativeGetActionButton(mNativePtr);
2608 }
2609
2610 /**
Michael Wright6b819b42015-06-17 21:06:03 +01002611 * Sets the action button for the event.
2612 *
2613 * @see #getActionButton()
2614 * @hide
2615 */
Kirill Grouchnikovc0b0ba52016-09-13 16:09:37 -07002616 @TestApi
Michael Wright6b819b42015-06-17 21:06:03 +01002617 public final void setActionButton(int button) {
2618 nativeSetActionButton(mNativePtr, button);
2619 }
2620
2621 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002622 * Returns the original raw X coordinate of this event. For touch
2623 * events on the screen, this is the original location of the event
2624 * on the screen, before it had been adjusted for the containing window
2625 * and views.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002626 *
Michael Wright072137c2013-04-24 20:41:20 -07002627 * @see #getX(int)
Jeff Brown91c69ab2011-02-14 17:03:18 -08002628 * @see #AXIS_X
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002629 */
2630 public final float getRawX() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002631 return nativeGetRawAxisValue(mNativePtr, AXIS_X, 0, HISTORY_CURRENT);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002632 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08002633
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002634 /**
2635 * Returns the original raw Y coordinate of this event. For touch
2636 * events on the screen, this is the original location of the event
2637 * on the screen, before it had been adjusted for the containing window
2638 * and views.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002639 *
Michael Wright072137c2013-04-24 20:41:20 -07002640 * @see #getY(int)
Jeff Brown91c69ab2011-02-14 17:03:18 -08002641 * @see #AXIS_Y
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002642 */
2643 public final float getRawY() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002644 return nativeGetRawAxisValue(mNativePtr, AXIS_Y, 0, HISTORY_CURRENT);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002645 }
2646
2647 /**
Vishnu Nair18999552018-12-13 09:28:11 -08002648 * Returns the original raw X coordinate of this event. For touch
2649 * events on the screen, this is the original location of the event
2650 * on the screen, before it had been adjusted for the containing window
2651 * and views.
2652 *
2653 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2654 * (the first pointer that is down) to {@link #getPointerCount()}-1.
2655 *
2656 * @see #getX(int)
2657 * @see #AXIS_X
2658 */
2659 public float getRawX(int pointerIndex) {
2660 return nativeGetRawAxisValue(mNativePtr, AXIS_X, pointerIndex, HISTORY_CURRENT);
2661 }
2662
2663 /**
2664 * Returns the original raw Y coordinate of this event. For touch
2665 * events on the screen, this is the original location of the event
2666 * on the screen, before it had been adjusted for the containing window
2667 * and views.
2668 *
2669 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2670 * (the first pointer that is down) to {@link #getPointerCount()}-1.
2671 *
2672 * @see #getY(int)
2673 * @see #AXIS_Y
2674 */
2675 public float getRawY(int pointerIndex) {
2676 return nativeGetRawAxisValue(mNativePtr, AXIS_Y, pointerIndex, HISTORY_CURRENT);
2677 }
2678
2679 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002680 * Return the precision of the X coordinates being reported. You can
Jeff Brown91c69ab2011-02-14 17:03:18 -08002681 * multiply this number with {@link #getX} to find the actual hardware
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002682 * value of the X coordinate.
2683 * @return Returns the precision of X coordinates being reported.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002684 *
2685 * @see #AXIS_X
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002686 */
2687 public final float getXPrecision() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002688 return nativeGetXPrecision(mNativePtr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002689 }
Romain Guycafdea62009-06-12 10:51:36 -07002690
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002691 /**
2692 * Return the precision of the Y coordinates being reported. You can
Jeff Brown91c69ab2011-02-14 17:03:18 -08002693 * multiply this number with {@link #getY} to find the actual hardware
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002694 * value of the Y coordinate.
2695 * @return Returns the precision of Y coordinates being reported.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002696 *
2697 * @see #AXIS_Y
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002698 */
2699 public final float getYPrecision() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002700 return nativeGetYPrecision(mNativePtr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002701 }
Romain Guycafdea62009-06-12 10:51:36 -07002702
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002703 /**
2704 * Returns the number of historical points in this event. These are
2705 * movements that have occurred between this event and the previous event.
2706 * This only applies to ACTION_MOVE events -- all other actions will have
2707 * a size of 0.
Romain Guycafdea62009-06-12 10:51:36 -07002708 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002709 * @return Returns the number of historical points in the event.
2710 */
2711 public final int getHistorySize() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002712 return nativeGetHistorySize(mNativePtr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002713 }
Romain Guycafdea62009-06-12 10:51:36 -07002714
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002715 /**
2716 * Returns the time that a historical movement occurred between this event
Jeff Brownb11499d2012-04-20 19:54:22 -07002717 * and the previous event, in the {@link android.os.SystemClock#uptimeMillis} time base.
2718 * <p>
2719 * This only applies to ACTION_MOVE events.
2720 * </p>
Romain Guycafdea62009-06-12 10:51:36 -07002721 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002722 * @param pos Which historical value to return; must be less than
2723 * {@link #getHistorySize}
Jeff Brownb11499d2012-04-20 19:54:22 -07002724 * @return Returns the time that a historical movement occurred between this
2725 * event and the previous event,
2726 * in the {@link android.os.SystemClock#uptimeMillis} time base.
Romain Guycafdea62009-06-12 10:51:36 -07002727 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002728 * @see #getHistorySize
2729 * @see #getEventTime
2730 */
2731 public final long getHistoricalEventTime(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002732 return nativeGetEventTimeNanos(mNativePtr, pos) / NS_PER_MS;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002733 }
2734
2735 /**
Jeff Brownb11499d2012-04-20 19:54:22 -07002736 * Returns the time that a historical movement occurred between this event
2737 * and the previous event, in the {@link android.os.SystemClock#uptimeMillis} time base
2738 * but with nanosecond (instead of millisecond) precision.
2739 * <p>
2740 * This only applies to ACTION_MOVE events.
2741 * </p><p>
2742 * The value is in nanosecond precision but it may not have nanosecond accuracy.
2743 * </p>
2744 *
2745 * @param pos Which historical value to return; must be less than
2746 * {@link #getHistorySize}
2747 * @return Returns the time that a historical movement occurred between this
2748 * event and the previous event,
2749 * in the {@link android.os.SystemClock#uptimeMillis} time base but with
2750 * nanosecond (instead of millisecond) precision.
2751 *
2752 * @see #getHistorySize
2753 * @see #getEventTime
2754 *
2755 * @hide
2756 */
2757 public final long getHistoricalEventTimeNano(int pos) {
2758 return nativeGetEventTimeNanos(mNativePtr, pos);
2759 }
2760
2761 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08002762 * {@link #getHistoricalX(int, int)} for the first pointer index (may be an
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002763 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002764 *
2765 * @param pos Which historical value to return; must be less than
2766 * {@link #getHistorySize}
2767 *
2768 * @see #getHistorySize
2769 * @see #getX()
2770 * @see #AXIS_X
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002771 */
2772 public final float getHistoricalX(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002773 return nativeGetAxisValue(mNativePtr, AXIS_X, 0, pos);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002774 }
2775
2776 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08002777 * {@link #getHistoricalY(int, int)} for the first pointer index (may be an
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002778 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002779 *
2780 * @param pos Which historical value to return; must be less than
2781 * {@link #getHistorySize}
2782 *
2783 * @see #getHistorySize
2784 * @see #getY()
2785 * @see #AXIS_Y
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002786 */
2787 public final float getHistoricalY(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002788 return nativeGetAxisValue(mNativePtr, AXIS_Y, 0, pos);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002789 }
2790
2791 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08002792 * {@link #getHistoricalPressure(int, int)} for the first pointer index (may be an
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002793 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002794 *
2795 * @param pos Which historical value to return; must be less than
2796 * {@link #getHistorySize}
2797 *
2798 * @see #getHistorySize
2799 * @see #getPressure()
2800 * @see #AXIS_PRESSURE
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002801 */
2802 public final float getHistoricalPressure(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002803 return nativeGetAxisValue(mNativePtr, AXIS_PRESSURE, 0, pos);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002804 }
2805
2806 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08002807 * {@link #getHistoricalSize(int, int)} for the first pointer index (may be an
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002808 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002809 *
2810 * @param pos Which historical value to return; must be less than
2811 * {@link #getHistorySize}
2812 *
2813 * @see #getHistorySize
2814 * @see #getSize()
2815 * @see #AXIS_SIZE
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002816 */
2817 public final float getHistoricalSize(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002818 return nativeGetAxisValue(mNativePtr, AXIS_SIZE, 0, pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002819 }
Romain Guycafdea62009-06-12 10:51:36 -07002820
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002821 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08002822 * {@link #getHistoricalTouchMajor(int, int)} for the first pointer index (may be an
Jeff Brownc5ed5912010-07-14 18:48:53 -07002823 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002824 *
2825 * @param pos Which historical value to return; must be less than
2826 * {@link #getHistorySize}
2827 *
2828 * @see #getHistorySize
2829 * @see #getTouchMajor()
2830 * @see #AXIS_TOUCH_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002831 */
2832 public final float getHistoricalTouchMajor(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002833 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MAJOR, 0, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002834 }
2835
2836 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08002837 * {@link #getHistoricalTouchMinor(int, int)} for the first pointer index (may be an
Jeff Brownc5ed5912010-07-14 18:48:53 -07002838 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002839 *
2840 * @param pos Which historical value to return; must be less than
2841 * {@link #getHistorySize}
2842 *
2843 * @see #getHistorySize
2844 * @see #getTouchMinor()
2845 * @see #AXIS_TOUCH_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002846 */
2847 public final float getHistoricalTouchMinor(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002848 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MINOR, 0, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002849 }
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002850
Jeff Brownc5ed5912010-07-14 18:48:53 -07002851 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08002852 * {@link #getHistoricalToolMajor(int, int)} for the first pointer index (may be an
Jeff Brownc5ed5912010-07-14 18:48:53 -07002853 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002854 *
2855 * @param pos Which historical value to return; must be less than
2856 * {@link #getHistorySize}
2857 *
2858 * @see #getHistorySize
2859 * @see #getToolMajor()
2860 * @see #AXIS_TOOL_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002861 */
2862 public final float getHistoricalToolMajor(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002863 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MAJOR, 0, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002864 }
2865
2866 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08002867 * {@link #getHistoricalToolMinor(int, int)} for the first pointer index (may be an
Jeff Brownc5ed5912010-07-14 18:48:53 -07002868 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002869 *
2870 * @param pos Which historical value to return; must be less than
2871 * {@link #getHistorySize}
2872 *
2873 * @see #getHistorySize
2874 * @see #getToolMinor()
2875 * @see #AXIS_TOOL_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002876 */
2877 public final float getHistoricalToolMinor(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002878 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MINOR, 0, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002879 }
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002880
Jeff Brownc5ed5912010-07-14 18:48:53 -07002881 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08002882 * {@link #getHistoricalOrientation(int, int)} for the first pointer index (may be an
Jeff Brownc5ed5912010-07-14 18:48:53 -07002883 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002884 *
2885 * @param pos Which historical value to return; must be less than
2886 * {@link #getHistorySize}
2887 *
2888 * @see #getHistorySize
2889 * @see #getOrientation()
2890 * @see #AXIS_ORIENTATION
Jeff Brownc5ed5912010-07-14 18:48:53 -07002891 */
2892 public final float getHistoricalOrientation(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002893 return nativeGetAxisValue(mNativePtr, AXIS_ORIENTATION, 0, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002894 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08002895
2896 /**
2897 * {@link #getHistoricalAxisValue(int, int, int)} for the first pointer index (may be an
2898 * arbitrary pointer identifier).
2899 *
2900 * @param axis The axis identifier for the axis value to retrieve.
2901 * @param pos Which historical value to return; must be less than
2902 * {@link #getHistorySize}
2903 *
2904 * @see #getHistorySize
2905 * @see #getAxisValue(int)
2906 * @see #AXIS_X
2907 * @see #AXIS_Y
2908 */
2909 public final float getHistoricalAxisValue(int axis, int pos) {
2910 return nativeGetAxisValue(mNativePtr, axis, 0, pos);
2911 }
2912
Jeff Brownc5ed5912010-07-14 18:48:53 -07002913 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002914 * Returns a historical X coordinate, as per {@link #getX(int)}, that
2915 * occurred between this event and the previous event for the given pointer.
2916 * Only applies to ACTION_MOVE events.
Romain Guycafdea62009-06-12 10:51:36 -07002917 *
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002918 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2919 * (the first pointer that is down) to {@link #getPointerCount()}-1.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002920 * @param pos Which historical value to return; must be less than
2921 * {@link #getHistorySize}
Romain Guycafdea62009-06-12 10:51:36 -07002922 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002923 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08002924 * @see #getX(int)
2925 * @see #AXIS_X
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002926 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002927 public final float getHistoricalX(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002928 return nativeGetAxisValue(mNativePtr, AXIS_X, pointerIndex, pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002929 }
Romain Guycafdea62009-06-12 10:51:36 -07002930
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002931 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002932 * Returns a historical Y coordinate, as per {@link #getY(int)}, that
2933 * occurred between this event and the previous event for the given pointer.
2934 * Only applies to ACTION_MOVE events.
Romain Guycafdea62009-06-12 10:51:36 -07002935 *
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002936 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2937 * (the first pointer that is down) to {@link #getPointerCount()}-1.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002938 * @param pos Which historical value to return; must be less than
2939 * {@link #getHistorySize}
Romain Guycafdea62009-06-12 10:51:36 -07002940 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002941 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08002942 * @see #getY(int)
2943 * @see #AXIS_Y
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002944 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002945 public final float getHistoricalY(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002946 return nativeGetAxisValue(mNativePtr, AXIS_Y, pointerIndex, pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002947 }
Romain Guycafdea62009-06-12 10:51:36 -07002948
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002949 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002950 * Returns a historical pressure coordinate, as per {@link #getPressure(int)},
2951 * that occurred between this event and the previous event for the given
2952 * pointer. Only applies to ACTION_MOVE events.
Romain Guycafdea62009-06-12 10:51:36 -07002953 *
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002954 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2955 * (the first pointer that is down) to {@link #getPointerCount()}-1.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002956 * @param pos Which historical value to return; must be less than
2957 * {@link #getHistorySize}
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002958 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002959 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08002960 * @see #getPressure(int)
2961 * @see #AXIS_PRESSURE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002962 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002963 public final float getHistoricalPressure(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002964 return nativeGetAxisValue(mNativePtr, AXIS_PRESSURE, pointerIndex, pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002965 }
Romain Guycafdea62009-06-12 10:51:36 -07002966
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002967 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002968 * Returns a historical size coordinate, as per {@link #getSize(int)}, that
2969 * occurred between this event and the previous event for the given pointer.
2970 * Only applies to ACTION_MOVE events.
Romain Guycafdea62009-06-12 10:51:36 -07002971 *
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002972 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2973 * (the first pointer that is down) to {@link #getPointerCount()}-1.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002974 * @param pos Which historical value to return; must be less than
2975 * {@link #getHistorySize}
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002976 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002977 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08002978 * @see #getSize(int)
2979 * @see #AXIS_SIZE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002980 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002981 public final float getHistoricalSize(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002982 return nativeGetAxisValue(mNativePtr, AXIS_SIZE, pointerIndex, pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002983 }
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002984
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002985 /**
Jeff Brownc5ed5912010-07-14 18:48:53 -07002986 * Returns a historical touch major axis coordinate, as per {@link #getTouchMajor(int)}, that
2987 * occurred between this event and the previous event for the given pointer.
2988 * Only applies to ACTION_MOVE events.
2989 *
2990 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2991 * (the first pointer that is down) to {@link #getPointerCount()}-1.
2992 * @param pos Which historical value to return; must be less than
2993 * {@link #getHistorySize}
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002994 *
Jeff Brownc5ed5912010-07-14 18:48:53 -07002995 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08002996 * @see #getTouchMajor(int)
2997 * @see #AXIS_TOUCH_MAJOR
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002998 */
Jeff Brownc5ed5912010-07-14 18:48:53 -07002999 public final float getHistoricalTouchMajor(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08003000 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MAJOR, pointerIndex, pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003001 }
Romain Guycafdea62009-06-12 10:51:36 -07003002
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003003 /**
Jeff Brownc5ed5912010-07-14 18:48:53 -07003004 * Returns a historical touch minor axis coordinate, as per {@link #getTouchMinor(int)}, that
3005 * occurred between this event and the previous event for the given pointer.
3006 * Only applies to ACTION_MOVE events.
3007 *
3008 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
3009 * (the first pointer that is down) to {@link #getPointerCount()}-1.
3010 * @param pos Which historical value to return; must be less than
3011 * {@link #getHistorySize}
Dennis Kempinac1b31d2016-11-02 17:02:25 -07003012 *
Jeff Brownc5ed5912010-07-14 18:48:53 -07003013 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08003014 * @see #getTouchMinor(int)
3015 * @see #AXIS_TOUCH_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07003016 */
3017 public final float getHistoricalTouchMinor(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08003018 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MINOR, pointerIndex, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07003019 }
3020
3021 /**
3022 * Returns a historical tool major axis coordinate, as per {@link #getToolMajor(int)}, that
3023 * occurred between this event and the previous event for the given pointer.
3024 * Only applies to ACTION_MOVE events.
3025 *
3026 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
3027 * (the first pointer that is down) to {@link #getPointerCount()}-1.
3028 * @param pos Which historical value to return; must be less than
3029 * {@link #getHistorySize}
Dennis Kempinac1b31d2016-11-02 17:02:25 -07003030 *
Jeff Brownc5ed5912010-07-14 18:48:53 -07003031 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08003032 * @see #getToolMajor(int)
3033 * @see #AXIS_TOOL_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07003034 */
3035 public final float getHistoricalToolMajor(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08003036 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MAJOR, pointerIndex, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07003037 }
3038
3039 /**
3040 * Returns a historical tool minor axis coordinate, as per {@link #getToolMinor(int)}, that
3041 * occurred between this event and the previous event for the given pointer.
3042 * Only applies to ACTION_MOVE events.
3043 *
3044 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
3045 * (the first pointer that is down) to {@link #getPointerCount()}-1.
3046 * @param pos Which historical value to return; must be less than
3047 * {@link #getHistorySize}
Dennis Kempinac1b31d2016-11-02 17:02:25 -07003048 *
Jeff Brownc5ed5912010-07-14 18:48:53 -07003049 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08003050 * @see #getToolMinor(int)
3051 * @see #AXIS_TOOL_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07003052 */
3053 public final float getHistoricalToolMinor(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08003054 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MINOR, pointerIndex, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07003055 }
3056
3057 /**
3058 * Returns a historical orientation coordinate, as per {@link #getOrientation(int)}, that
3059 * occurred between this event and the previous event for the given pointer.
3060 * Only applies to ACTION_MOVE events.
3061 *
3062 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
3063 * (the first pointer that is down) to {@link #getPointerCount()}-1.
3064 * @param pos Which historical value to return; must be less than
3065 * {@link #getHistorySize}
Dennis Kempinac1b31d2016-11-02 17:02:25 -07003066 *
Jeff Brownc5ed5912010-07-14 18:48:53 -07003067 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08003068 * @see #getOrientation(int)
3069 * @see #AXIS_ORIENTATION
Jeff Brownc5ed5912010-07-14 18:48:53 -07003070 */
3071 public final float getHistoricalOrientation(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08003072 return nativeGetAxisValue(mNativePtr, AXIS_ORIENTATION, pointerIndex, pos);
3073 }
3074
3075 /**
3076 * Returns the historical value of the requested axis, as per {@link #getAxisValue(int, int)},
3077 * occurred between this event and the previous event for the given pointer.
3078 * Only applies to ACTION_MOVE events.
3079 *
3080 * @param axis The axis identifier for the axis value to retrieve.
3081 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
3082 * (the first pointer that is down) to {@link #getPointerCount()}-1.
3083 * @param pos Which historical value to return; must be less than
3084 * {@link #getHistorySize}
3085 * @return The value of the axis, or 0 if the axis is not available.
3086 *
3087 * @see #AXIS_X
3088 * @see #AXIS_Y
3089 */
3090 public final float getHistoricalAxisValue(int axis, int pointerIndex, int pos) {
3091 return nativeGetAxisValue(mNativePtr, axis, pointerIndex, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07003092 }
3093
3094 /**
3095 * Populates a {@link PointerCoords} object with historical pointer coordinate data,
3096 * as per {@link #getPointerCoords}, that occurred between this event and the previous
3097 * event for the given pointer.
3098 * Only applies to ACTION_MOVE events.
Dennis Kempinac1b31d2016-11-02 17:02:25 -07003099 *
Jeff Brownc5ed5912010-07-14 18:48:53 -07003100 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
3101 * (the first pointer that is down) to {@link #getPointerCount()}-1.
3102 * @param pos Which historical value to return; must be less than
3103 * {@link #getHistorySize}
3104 * @param outPointerCoords The pointer coordinate object to populate.
Dennis Kempinac1b31d2016-11-02 17:02:25 -07003105 *
Jeff Brownc5ed5912010-07-14 18:48:53 -07003106 * @see #getHistorySize
3107 * @see #getPointerCoords
Jeff Brown91c69ab2011-02-14 17:03:18 -08003108 * @see PointerCoords
Jeff Brownc5ed5912010-07-14 18:48:53 -07003109 */
3110 public final void getHistoricalPointerCoords(int pointerIndex, int pos,
3111 PointerCoords outPointerCoords) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08003112 nativeGetPointerCoords(mNativePtr, pointerIndex, pos, outPointerCoords);
Jeff Brownc5ed5912010-07-14 18:48:53 -07003113 }
Dennis Kempinac1b31d2016-11-02 17:02:25 -07003114
Jeff Brownc5ed5912010-07-14 18:48:53 -07003115 /**
Jeff Brown46b9ac02010-04-22 18:58:52 -07003116 * Returns a bitfield indicating which edges, if any, were touched by this
Romain Guycafdea62009-06-12 10:51:36 -07003117 * MotionEvent. For touch events, clients can use this to determine if the
3118 * user's finger was touching the edge of the display.
3119 *
Jeff Brownd41cff22011-03-03 02:09:54 -08003120 * This property is only set for {@link #ACTION_DOWN} events.
3121 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003122 * @see #EDGE_LEFT
3123 * @see #EDGE_TOP
3124 * @see #EDGE_RIGHT
3125 * @see #EDGE_BOTTOM
3126 */
3127 public final int getEdgeFlags() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08003128 return nativeGetEdgeFlags(mNativePtr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003129 }
Romain Guycafdea62009-06-12 10:51:36 -07003130
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003131 /**
Jeff Brown85a31762010-09-01 17:01:00 -07003132 * Sets the bitfield indicating which edges, if any, were touched by this
Romain Guycafdea62009-06-12 10:51:36 -07003133 * MotionEvent.
3134 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003135 * @see #getEdgeFlags()
3136 */
3137 public final void setEdgeFlags(int flags) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08003138 nativeSetEdgeFlags(mNativePtr, flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003139 }
3140
3141 /**
3142 * Sets this event's action.
3143 */
3144 public final void setAction(int action) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08003145 nativeSetAction(mNativePtr, action);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003146 }
3147
3148 /**
3149 * Adjust this event's location.
3150 * @param deltaX Amount to add to the current X coordinate of the event.
3151 * @param deltaY Amount to add to the current Y coordinate of the event.
3152 */
3153 public final void offsetLocation(float deltaX, float deltaY) {
Jeff Brown9ea77fc2012-03-21 19:49:27 -07003154 if (deltaX != 0.0f || deltaY != 0.0f) {
3155 nativeOffsetLocation(mNativePtr, deltaX, deltaY);
3156 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003157 }
Romain Guycafdea62009-06-12 10:51:36 -07003158
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003159 /**
3160 * Set this event's location. Applies {@link #offsetLocation} with a
3161 * delta from the current location to the given new location.
Romain Guycafdea62009-06-12 10:51:36 -07003162 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003163 * @param x New absolute X location.
3164 * @param y New absolute Y location.
3165 */
3166 public final void setLocation(float x, float y) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08003167 float oldX = getX();
3168 float oldY = getY();
Jeff Brown9ea77fc2012-03-21 19:49:27 -07003169 offsetLocation(x - oldX, y - oldY);
Jeff Brown5c225b12010-06-16 01:53:36 -07003170 }
Dennis Kempinac1b31d2016-11-02 17:02:25 -07003171
Jeff Brown20e987b2010-08-23 12:01:02 -07003172 /**
3173 * Applies a transformation matrix to all of the points in the event.
3174 *
3175 * @param matrix The transformation matrix to apply.
3176 */
3177 public final void transform(Matrix matrix) {
3178 if (matrix == null) {
3179 throw new IllegalArgumentException("matrix must not be null");
3180 }
3181
John Reck09709972016-10-03 15:47:18 -07003182 nativeTransform(mNativePtr, matrix.native_instance);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003183 }
Romain Guycafdea62009-06-12 10:51:36 -07003184
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003185 /**
3186 * Add a new movement to the batch of movements in this event. The event's
Jeff Brownc5ed5912010-07-14 18:48:53 -07003187 * current location, position and size is updated to the new values.
3188 * The current values in the event are added to a list of historical values.
Jeff Brown91c69ab2011-02-14 17:03:18 -08003189 *
Jeff Browncc0c1592011-02-19 05:07:28 -08003190 * Only applies to {@link #ACTION_MOVE} or {@link #ACTION_HOVER_MOVE} events.
Romain Guycafdea62009-06-12 10:51:36 -07003191 *
Jeff Brownc5ed5912010-07-14 18:48:53 -07003192 * @param eventTime The time stamp (in ms) for this data.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003193 * @param x The new X position.
3194 * @param y The new Y position.
3195 * @param pressure The new pressure.
3196 * @param size The new size.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07003197 * @param metaState Meta key state.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003198 */
3199 public final void addBatch(long eventTime, float x, float y,
3200 float pressure, float size, int metaState) {
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003201 synchronized (gSharedTempLock) {
3202 ensureSharedTempPointerCapacity(1);
3203 final PointerCoords[] pc = gSharedTempPointerCoords;
3204 pc[0].clear();
3205 pc[0].x = x;
3206 pc[0].y = y;
3207 pc[0].pressure = pressure;
3208 pc[0].size = size;
3209
3210 nativeAddBatch(mNativePtr, eventTime * NS_PER_MS, pc, metaState);
Jeff Brown91c69ab2011-02-14 17:03:18 -08003211 }
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07003212 }
Romain Guycafdea62009-06-12 10:51:36 -07003213
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07003214 /**
Jeff Brownc5ed5912010-07-14 18:48:53 -07003215 * Add a new movement to the batch of movements in this event. The event's
3216 * current location, position and size is updated to the new values.
3217 * The current values in the event are added to a list of historical values.
Jeff Brown91c69ab2011-02-14 17:03:18 -08003218 *
Jeff Browncc0c1592011-02-19 05:07:28 -08003219 * Only applies to {@link #ACTION_MOVE} or {@link #ACTION_HOVER_MOVE} events.
Jeff Brownc5ed5912010-07-14 18:48:53 -07003220 *
3221 * @param eventTime The time stamp (in ms) for this data.
3222 * @param pointerCoords The new pointer coordinates.
3223 * @param metaState Meta key state.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07003224 */
Jeff Brownc5ed5912010-07-14 18:48:53 -07003225 public final void addBatch(long eventTime, PointerCoords[] pointerCoords, int metaState) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08003226 nativeAddBatch(mNativePtr, eventTime * NS_PER_MS, pointerCoords, metaState);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003227 }
Romain Guycafdea62009-06-12 10:51:36 -07003228
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003229 /**
Jeff Brown9d3bdbd2012-03-21 11:50:06 -07003230 * Adds all of the movement samples of the specified event to this one if
3231 * it is compatible. To be compatible, the event must have the same device id,
Siarhei Vishniakoub05b0b52018-12-28 17:50:24 -08003232 * source, display id, action, flags, classification, pointer count, pointer properties.
Jeff Brown9d3bdbd2012-03-21 11:50:06 -07003233 *
3234 * Only applies to {@link #ACTION_MOVE} or {@link #ACTION_HOVER_MOVE} events.
3235 *
3236 * @param event The event whose movements samples should be added to this one
3237 * if possible.
3238 * @return True if batching was performed or false if batching was not possible.
3239 * @hide
3240 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01003241 @UnsupportedAppUsage
Jeff Brown9d3bdbd2012-03-21 11:50:06 -07003242 public final boolean addBatch(MotionEvent event) {
3243 final int action = nativeGetAction(mNativePtr);
3244 if (action != ACTION_MOVE && action != ACTION_HOVER_MOVE) {
3245 return false;
3246 }
3247 if (action != nativeGetAction(event.mNativePtr)) {
3248 return false;
3249 }
3250
3251 if (nativeGetDeviceId(mNativePtr) != nativeGetDeviceId(event.mNativePtr)
3252 || nativeGetSource(mNativePtr) != nativeGetSource(event.mNativePtr)
Siarhei Vishniakou85ddfff2018-01-31 16:49:36 -08003253 || nativeGetDisplayId(mNativePtr) != nativeGetDisplayId(event.mNativePtr)
Siarhei Vishniakoub05b0b52018-12-28 17:50:24 -08003254 || nativeGetFlags(mNativePtr) != nativeGetFlags(event.mNativePtr)
3255 || nativeGetClassification(mNativePtr)
3256 != nativeGetClassification(event.mNativePtr)) {
Jeff Brown9d3bdbd2012-03-21 11:50:06 -07003257 return false;
3258 }
3259
3260 final int pointerCount = nativeGetPointerCount(mNativePtr);
3261 if (pointerCount != nativeGetPointerCount(event.mNativePtr)) {
3262 return false;
3263 }
3264
3265 synchronized (gSharedTempLock) {
3266 ensureSharedTempPointerCapacity(Math.max(pointerCount, 2));
3267 final PointerProperties[] pp = gSharedTempPointerProperties;
3268 final PointerCoords[] pc = gSharedTempPointerCoords;
3269
3270 for (int i = 0; i < pointerCount; i++) {
3271 nativeGetPointerProperties(mNativePtr, i, pp[0]);
3272 nativeGetPointerProperties(event.mNativePtr, i, pp[1]);
3273 if (!pp[0].equals(pp[1])) {
3274 return false;
3275 }
3276 }
3277
3278 final int metaState = nativeGetMetaState(event.mNativePtr);
3279 final int historySize = nativeGetHistorySize(event.mNativePtr);
3280 for (int h = 0; h <= historySize; h++) {
3281 final int historyPos = (h == historySize ? HISTORY_CURRENT : h);
3282
3283 for (int i = 0; i < pointerCount; i++) {
3284 nativeGetPointerCoords(event.mNativePtr, i, historyPos, pc[i]);
3285 }
3286
3287 final long eventTimeNanos = nativeGetEventTimeNanos(event.mNativePtr, historyPos);
3288 nativeAddBatch(mNativePtr, eventTimeNanos, pc, metaState);
3289 }
3290 }
3291 return true;
3292 }
3293
3294 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003295 * Returns true if all points in the motion event are completely within the specified bounds.
3296 * @hide
3297 */
3298 public final boolean isWithinBoundsNoHistory(float left, float top,
3299 float right, float bottom) {
3300 final int pointerCount = nativeGetPointerCount(mNativePtr);
3301 for (int i = 0; i < pointerCount; i++) {
3302 final float x = nativeGetAxisValue(mNativePtr, AXIS_X, i, HISTORY_CURRENT);
3303 final float y = nativeGetAxisValue(mNativePtr, AXIS_Y, i, HISTORY_CURRENT);
3304 if (x < left || x > right || y < top || y > bottom) {
3305 return false;
3306 }
3307 }
3308 return true;
3309 }
3310
3311 private static final float clamp(float value, float low, float high) {
3312 if (value < low) {
3313 return low;
3314 } else if (value > high) {
3315 return high;
3316 }
3317 return value;
3318 }
3319
3320 /**
3321 * Returns a new motion events whose points have been clamped to the specified bounds.
3322 * @hide
3323 */
3324 public final MotionEvent clampNoHistory(float left, float top, float right, float bottom) {
3325 MotionEvent ev = obtain();
3326 synchronized (gSharedTempLock) {
3327 final int pointerCount = nativeGetPointerCount(mNativePtr);
3328
3329 ensureSharedTempPointerCapacity(pointerCount);
3330 final PointerProperties[] pp = gSharedTempPointerProperties;
3331 final PointerCoords[] pc = gSharedTempPointerCoords;
3332
3333 for (int i = 0; i < pointerCount; i++) {
3334 nativeGetPointerProperties(mNativePtr, i, pp[i]);
3335 nativeGetPointerCoords(mNativePtr, i, HISTORY_CURRENT, pc[i]);
3336 pc[i].x = clamp(pc[i].x, left, right);
3337 pc[i].y = clamp(pc[i].y, top, bottom);
3338 }
3339 ev.mNativePtr = nativeInitialize(ev.mNativePtr,
3340 nativeGetDeviceId(mNativePtr), nativeGetSource(mNativePtr),
Siarhei Vishniakou85ddfff2018-01-31 16:49:36 -08003341 nativeGetDisplayId(mNativePtr),
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003342 nativeGetAction(mNativePtr), nativeGetFlags(mNativePtr),
3343 nativeGetEdgeFlags(mNativePtr), nativeGetMetaState(mNativePtr),
Siarhei Vishniakoub05b0b52018-12-28 17:50:24 -08003344 nativeGetButtonState(mNativePtr), nativeGetClassification(mNativePtr),
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003345 nativeGetXOffset(mNativePtr), nativeGetYOffset(mNativePtr),
3346 nativeGetXPrecision(mNativePtr), nativeGetYPrecision(mNativePtr),
3347 nativeGetDownTimeNanos(mNativePtr),
3348 nativeGetEventTimeNanos(mNativePtr, HISTORY_CURRENT),
3349 pointerCount, pp, pc);
3350 return ev;
3351 }
3352 }
3353
3354 /**
3355 * Gets an integer where each pointer id present in the event is marked as a bit.
3356 * @hide
3357 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01003358 @UnsupportedAppUsage
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003359 public final int getPointerIdBits() {
3360 int idBits = 0;
3361 final int pointerCount = nativeGetPointerCount(mNativePtr);
3362 for (int i = 0; i < pointerCount; i++) {
3363 idBits |= 1 << nativeGetPointerId(mNativePtr, i);
3364 }
3365 return idBits;
3366 }
3367
3368 /**
3369 * Splits a motion event such that it includes only a subset of pointer ids.
3370 * @hide
3371 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01003372 @UnsupportedAppUsage
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003373 public final MotionEvent split(int idBits) {
3374 MotionEvent ev = obtain();
3375 synchronized (gSharedTempLock) {
3376 final int oldPointerCount = nativeGetPointerCount(mNativePtr);
3377 ensureSharedTempPointerCapacity(oldPointerCount);
3378 final PointerProperties[] pp = gSharedTempPointerProperties;
3379 final PointerCoords[] pc = gSharedTempPointerCoords;
3380 final int[] map = gSharedTempPointerIndexMap;
3381
3382 final int oldAction = nativeGetAction(mNativePtr);
3383 final int oldActionMasked = oldAction & ACTION_MASK;
3384 final int oldActionPointerIndex = (oldAction & ACTION_POINTER_INDEX_MASK)
3385 >> ACTION_POINTER_INDEX_SHIFT;
3386 int newActionPointerIndex = -1;
3387 int newPointerCount = 0;
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003388 for (int i = 0; i < oldPointerCount; i++) {
3389 nativeGetPointerProperties(mNativePtr, i, pp[newPointerCount]);
3390 final int idBit = 1 << pp[newPointerCount].id;
3391 if ((idBit & idBits) != 0) {
3392 if (i == oldActionPointerIndex) {
3393 newActionPointerIndex = newPointerCount;
3394 }
3395 map[newPointerCount] = i;
3396 newPointerCount += 1;
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003397 }
3398 }
3399
3400 if (newPointerCount == 0) {
3401 throw new IllegalArgumentException("idBits did not match any ids in the event");
3402 }
3403
3404 final int newAction;
3405 if (oldActionMasked == ACTION_POINTER_DOWN || oldActionMasked == ACTION_POINTER_UP) {
3406 if (newActionPointerIndex < 0) {
3407 // An unrelated pointer changed.
3408 newAction = ACTION_MOVE;
3409 } else if (newPointerCount == 1) {
3410 // The first/last pointer went down/up.
3411 newAction = oldActionMasked == ACTION_POINTER_DOWN
3412 ? ACTION_DOWN : ACTION_UP;
3413 } else {
3414 // A secondary pointer went down/up.
3415 newAction = oldActionMasked
3416 | (newActionPointerIndex << ACTION_POINTER_INDEX_SHIFT);
3417 }
3418 } else {
3419 // Simple up/down/cancel/move or other motion action.
3420 newAction = oldAction;
3421 }
3422
3423 final int historySize = nativeGetHistorySize(mNativePtr);
3424 for (int h = 0; h <= historySize; h++) {
3425 final int historyPos = h == historySize ? HISTORY_CURRENT : h;
3426
3427 for (int i = 0; i < newPointerCount; i++) {
3428 nativeGetPointerCoords(mNativePtr, map[i], historyPos, pc[i]);
3429 }
3430
3431 final long eventTimeNanos = nativeGetEventTimeNanos(mNativePtr, historyPos);
3432 if (h == 0) {
3433 ev.mNativePtr = nativeInitialize(ev.mNativePtr,
3434 nativeGetDeviceId(mNativePtr), nativeGetSource(mNativePtr),
Siarhei Vishniakou85ddfff2018-01-31 16:49:36 -08003435 nativeGetDisplayId(mNativePtr),
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003436 newAction, nativeGetFlags(mNativePtr),
3437 nativeGetEdgeFlags(mNativePtr), nativeGetMetaState(mNativePtr),
Siarhei Vishniakoub05b0b52018-12-28 17:50:24 -08003438 nativeGetButtonState(mNativePtr), nativeGetClassification(mNativePtr),
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003439 nativeGetXOffset(mNativePtr), nativeGetYOffset(mNativePtr),
3440 nativeGetXPrecision(mNativePtr), nativeGetYPrecision(mNativePtr),
3441 nativeGetDownTimeNanos(mNativePtr), eventTimeNanos,
3442 newPointerCount, pp, pc);
3443 } else {
3444 nativeAddBatch(ev.mNativePtr, eventTimeNanos, pc, 0);
3445 }
3446 }
3447 return ev;
3448 }
3449 }
3450
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003451 @Override
3452 public String toString() {
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003453 StringBuilder msg = new StringBuilder();
3454 msg.append("MotionEvent { action=").append(actionToString(getAction()));
Eugene Suslae6e55b52018-01-11 15:12:56 -08003455 appendUnless("0", msg, ", actionButton=", buttonStateToString(getActionButton()));
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003456
3457 final int pointerCount = getPointerCount();
3458 for (int i = 0; i < pointerCount; i++) {
Eugene Suslae6e55b52018-01-11 15:12:56 -08003459 appendUnless(i, msg, ", id[" + i + "]=", getPointerId(i));
3460 float x = getX(i);
3461 float y = getY(i);
3462 if (!DEBUG_CONCISE_TOSTRING || x != 0f || y != 0f) {
3463 msg.append(", x[").append(i).append("]=").append(x);
3464 msg.append(", y[").append(i).append("]=").append(y);
3465 }
3466 appendUnless(TOOL_TYPE_SYMBOLIC_NAMES.get(TOOL_TYPE_FINGER),
3467 msg, ", toolType[" + i + "]=", toolTypeToString(getToolType(i)));
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003468 }
3469
Eugene Suslae6e55b52018-01-11 15:12:56 -08003470 appendUnless("0", msg, ", buttonState=", MotionEvent.buttonStateToString(getButtonState()));
Siarhei Vishniakoub05b0b52018-12-28 17:50:24 -08003471 appendUnless(classificationToString(CLASSIFICATION_NONE), msg, ", classification=",
3472 classificationToString(getClassification()));
Eugene Suslae6e55b52018-01-11 15:12:56 -08003473 appendUnless("0", msg, ", metaState=", KeyEvent.metaStateToString(getMetaState()));
3474 appendUnless("0", msg, ", flags=0x", Integer.toHexString(getFlags()));
3475 appendUnless("0", msg, ", edgeFlags=0x", Integer.toHexString(getEdgeFlags()));
3476 appendUnless(1, msg, ", pointerCount=", pointerCount);
3477 appendUnless(0, msg, ", historySize=", getHistorySize());
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003478 msg.append(", eventTime=").append(getEventTime());
Eugene Suslae6e55b52018-01-11 15:12:56 -08003479 if (!DEBUG_CONCISE_TOSTRING) {
3480 msg.append(", downTime=").append(getDownTime());
3481 msg.append(", deviceId=").append(getDeviceId());
3482 msg.append(", source=0x").append(Integer.toHexString(getSource()));
Siarhei Vishniakou85ddfff2018-01-31 16:49:36 -08003483 msg.append(", displayId=").append(getDisplayId());
Eugene Suslae6e55b52018-01-11 15:12:56 -08003484 }
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003485 msg.append(" }");
3486 return msg.toString();
Jeff Brown497a92c2010-09-12 17:55:08 -07003487 }
3488
Eugene Suslae6e55b52018-01-11 15:12:56 -08003489 private static <T> void appendUnless(T defValue, StringBuilder sb, String key, T value) {
3490 if (DEBUG_CONCISE_TOSTRING && Objects.equals(defValue, value)) return;
3491 sb.append(key).append(value);
3492 }
3493
Jeff Brown497a92c2010-09-12 17:55:08 -07003494 /**
John Spurlock4dad6ca2013-06-05 13:17:05 -04003495 * Returns a string that represents the symbolic name of the specified unmasked action
Jeff Brown91c69ab2011-02-14 17:03:18 -08003496 * such as "ACTION_DOWN", "ACTION_POINTER_DOWN(3)" or an equivalent numeric constant
3497 * such as "35" if unknown.
Jeff Brown497a92c2010-09-12 17:55:08 -07003498 *
John Spurlock4dad6ca2013-06-05 13:17:05 -04003499 * @param action The unmasked action.
Jeff Brown497a92c2010-09-12 17:55:08 -07003500 * @return The symbolic name of the specified action.
John Spurlock4dad6ca2013-06-05 13:17:05 -04003501 * @see #getAction()
Jeff Brown497a92c2010-09-12 17:55:08 -07003502 */
3503 public static String actionToString(int action) {
3504 switch (action) {
3505 case ACTION_DOWN:
3506 return "ACTION_DOWN";
3507 case ACTION_UP:
3508 return "ACTION_UP";
3509 case ACTION_CANCEL:
3510 return "ACTION_CANCEL";
Jeff Brown33bbfd22011-02-24 20:55:35 -08003511 case ACTION_OUTSIDE:
3512 return "ACTION_OUTSIDE";
Jeff Brown497a92c2010-09-12 17:55:08 -07003513 case ACTION_MOVE:
3514 return "ACTION_MOVE";
Jeff Browncc0c1592011-02-19 05:07:28 -08003515 case ACTION_HOVER_MOVE:
3516 return "ACTION_HOVER_MOVE";
Jeff Brown33bbfd22011-02-24 20:55:35 -08003517 case ACTION_SCROLL:
3518 return "ACTION_SCROLL";
Jeff Browna032cc02011-03-07 16:56:21 -08003519 case ACTION_HOVER_ENTER:
3520 return "ACTION_HOVER_ENTER";
3521 case ACTION_HOVER_EXIT:
3522 return "ACTION_HOVER_EXIT";
Michael Wright5bd69e62015-05-14 14:48:08 +01003523 case ACTION_BUTTON_PRESS:
3524 return "ACTION_BUTTON_PRESS";
3525 case ACTION_BUTTON_RELEASE:
3526 return "ACTION_BUTTON_RELEASE";
Jeff Brown497a92c2010-09-12 17:55:08 -07003527 }
3528 int index = (action & ACTION_POINTER_INDEX_MASK) >> ACTION_POINTER_INDEX_SHIFT;
3529 switch (action & ACTION_MASK) {
3530 case ACTION_POINTER_DOWN:
3531 return "ACTION_POINTER_DOWN(" + index + ")";
3532 case ACTION_POINTER_UP:
3533 return "ACTION_POINTER_UP(" + index + ")";
3534 default:
3535 return Integer.toString(action);
3536 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003537 }
3538
Jeff Brown91c69ab2011-02-14 17:03:18 -08003539 /**
3540 * Returns a string that represents the symbolic name of the specified axis
Jeff Brown6f2fba42011-02-19 01:08:02 -08003541 * such as "AXIS_X" or an equivalent numeric constant such as "42" if unknown.
Jeff Brown91c69ab2011-02-14 17:03:18 -08003542 *
John Spurlock4dad6ca2013-06-05 13:17:05 -04003543 * @param axis The axis.
Jeff Brown91c69ab2011-02-14 17:03:18 -08003544 * @return The symbolic name of the specified axis.
Jeff Brown91c69ab2011-02-14 17:03:18 -08003545 */
3546 public static String axisToString(int axis) {
Michael Wright337d9d22014-04-22 15:03:48 -07003547 String symbolicName = nativeAxisToString(axis);
3548 return symbolicName != null ? LABEL_PREFIX + symbolicName : Integer.toString(axis);
Jeff Brown6f2fba42011-02-19 01:08:02 -08003549 }
3550
3551 /**
Jeff Browncc0c1592011-02-19 05:07:28 -08003552 * Gets an axis by its symbolic name such as "AXIS_X" or an
3553 * equivalent numeric constant such as "42".
Jeff Brown6f2fba42011-02-19 01:08:02 -08003554 *
3555 * @param symbolicName The symbolic name of the axis.
3556 * @return The axis or -1 if not found.
John Spurlock4dad6ca2013-06-05 13:17:05 -04003557 * @see KeyEvent#keyCodeToString(int)
Jeff Brown6f2fba42011-02-19 01:08:02 -08003558 */
3559 public static int axisFromString(String symbolicName) {
Michael Wright337d9d22014-04-22 15:03:48 -07003560 if (symbolicName.startsWith(LABEL_PREFIX)) {
3561 symbolicName = symbolicName.substring(LABEL_PREFIX.length());
Michael Wright973efa02014-05-13 15:38:56 -07003562 int axis = nativeAxisFromString(symbolicName);
3563 if (axis >= 0) {
3564 return axis;
3565 }
Jeff Brown6f2fba42011-02-19 01:08:02 -08003566 }
Jeff Brown6f2fba42011-02-19 01:08:02 -08003567 try {
3568 return Integer.parseInt(symbolicName, 10);
3569 } catch (NumberFormatException ex) {
3570 return -1;
Jeff Brown91c69ab2011-02-14 17:03:18 -08003571 }
3572 }
3573
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003574 /**
3575 * Returns a string that represents the symbolic name of the specified combined
3576 * button state flags such as "0", "BUTTON_PRIMARY",
3577 * "BUTTON_PRIMARY|BUTTON_SECONDARY" or an equivalent numeric constant such as "0x10000000"
3578 * if unknown.
3579 *
3580 * @param buttonState The button state.
3581 * @return The symbolic name of the specified combined button state flags.
3582 * @hide
3583 */
3584 public static String buttonStateToString(int buttonState) {
3585 if (buttonState == 0) {
3586 return "0";
3587 }
3588 StringBuilder result = null;
3589 int i = 0;
3590 while (buttonState != 0) {
3591 final boolean isSet = (buttonState & 1) != 0;
3592 buttonState >>>= 1; // unsigned shift!
3593 if (isSet) {
3594 final String name = BUTTON_SYMBOLIC_NAMES[i];
3595 if (result == null) {
3596 if (buttonState == 0) {
3597 return name;
3598 }
3599 result = new StringBuilder(name);
3600 } else {
3601 result.append('|');
3602 result.append(name);
3603 }
3604 }
3605 i += 1;
3606 }
3607 return result.toString();
3608 }
3609
3610 /**
Siarhei Vishniakoub05b0b52018-12-28 17:50:24 -08003611 * Returns a string that represents the symbolic name of the specified classification.
3612 *
3613 * @param classification The classification type.
3614 * @return The symbolic name of this classification.
3615 * @hide
3616 */
3617 public static String classificationToString(@Classification int classification) {
3618 switch (classification) {
3619 case CLASSIFICATION_NONE:
3620 return "NONE";
3621 case CLASSIFICATION_AMBIGUOUS_GESTURE:
3622 return "AMBIGUOUS_GESTURE";
3623 case CLASSIFICATION_DEEP_PRESS:
3624 return "DEEP_PRESS";
3625
3626 }
3627 return "NONE";
3628 }
3629
3630 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003631 * Returns a string that represents the symbolic name of the specified tool type
3632 * such as "TOOL_TYPE_FINGER" or an equivalent numeric constant such as "42" if unknown.
3633 *
3634 * @param toolType The tool type.
3635 * @return The symbolic name of the specified tool type.
3636 * @hide
3637 */
3638 public static String toolTypeToString(int toolType) {
3639 String symbolicName = TOOL_TYPE_SYMBOLIC_NAMES.get(toolType);
3640 return symbolicName != null ? symbolicName : Integer.toString(toolType);
3641 }
3642
Sujith Ramakrishnancc32bd82014-05-19 15:32:13 -07003643 /**
3644 * Checks if a mouse or stylus button (or combination of buttons) is pressed.
3645 * @param button Button (or combination of buttons).
3646 * @return True if specified buttons are pressed.
3647 *
3648 * @see #BUTTON_PRIMARY
3649 * @see #BUTTON_SECONDARY
3650 * @see #BUTTON_TERTIARY
3651 * @see #BUTTON_FORWARD
3652 * @see #BUTTON_BACK
Michael Wright5bd69e62015-05-14 14:48:08 +01003653 * @see #BUTTON_STYLUS_PRIMARY
3654 * @see #BUTTON_STYLUS_SECONDARY
Sujith Ramakrishnancc32bd82014-05-19 15:32:13 -07003655 */
3656 public final boolean isButtonPressed(int button) {
3657 if (button == 0) {
3658 return false;
3659 }
3660 return (getButtonState() & button) == button;
3661 }
3662
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003663 public static final Parcelable.Creator<MotionEvent> CREATOR
3664 = new Parcelable.Creator<MotionEvent>() {
3665 public MotionEvent createFromParcel(Parcel in) {
Jeff Brown6ec402b2010-07-28 15:48:59 -07003666 in.readInt(); // skip token, we already know this is a MotionEvent
3667 return MotionEvent.createFromParcelBody(in);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003668 }
3669
3670 public MotionEvent[] newArray(int size) {
3671 return new MotionEvent[size];
3672 }
3673 };
3674
Jeff Brown6ec402b2010-07-28 15:48:59 -07003675 /** @hide */
3676 public static MotionEvent createFromParcelBody(Parcel in) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08003677 MotionEvent ev = obtain();
3678 ev.mNativePtr = nativeReadFromParcel(ev.mNativePtr, in);
Jeff Brown6ec402b2010-07-28 15:48:59 -07003679 return ev;
3680 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08003681
Wale Ogunwalec3672cd2014-11-05 15:17:35 -08003682 /** @hide */
3683 @Override
3684 public final void cancel() {
3685 setAction(ACTION_CANCEL);
3686 }
3687
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003688 public void writeToParcel(Parcel out, int flags) {
Jeff Brown6ec402b2010-07-28 15:48:59 -07003689 out.writeInt(PARCEL_TOKEN_MOTION_EVENT);
Jeff Brown91c69ab2011-02-14 17:03:18 -08003690 nativeWriteToParcel(mNativePtr, out);
Jeff Brown5c225b12010-06-16 01:53:36 -07003691 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08003692
Jeff Brownc5ed5912010-07-14 18:48:53 -07003693 /**
3694 * Transfer object for pointer coordinates.
Dennis Kempinac1b31d2016-11-02 17:02:25 -07003695 *
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003696 * Objects of this type can be used to specify the pointer coordinates when
3697 * creating new {@link MotionEvent} objects and to query pointer coordinates
3698 * in bulk.
Dennis Kempinac1b31d2016-11-02 17:02:25 -07003699 *
Jeff Brownc5ed5912010-07-14 18:48:53 -07003700 * Refer to {@link InputDevice} for information about how different kinds of
3701 * input devices and sources represent pointer coordinates.
3702 */
3703 public static final class PointerCoords {
Jeff Brown91c69ab2011-02-14 17:03:18 -08003704 private static final int INITIAL_PACKED_AXIS_VALUES = 8;
Mathew Inwooda570dee2018-08-17 14:56:00 +01003705 @UnsupportedAppUsage
Jeff Brown6f2fba42011-02-19 01:08:02 -08003706 private long mPackedAxisBits;
Mathew Inwooda570dee2018-08-17 14:56:00 +01003707 @UnsupportedAppUsage
Jeff Brown91c69ab2011-02-14 17:03:18 -08003708 private float[] mPackedAxisValues;
3709
3710 /**
3711 * Creates a pointer coords object with all axes initialized to zero.
3712 */
3713 public PointerCoords() {
3714 }
3715
3716 /**
3717 * Creates a pointer coords object as a copy of the
3718 * contents of another pointer coords object.
3719 *
3720 * @param other The pointer coords object to copy.
3721 */
3722 public PointerCoords(PointerCoords other) {
3723 copyFrom(other);
3724 }
3725
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003726 /** @hide */
Mathew Inwooda570dee2018-08-17 14:56:00 +01003727 @UnsupportedAppUsage
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003728 public static PointerCoords[] createArray(int size) {
3729 PointerCoords[] array = new PointerCoords[size];
3730 for (int i = 0; i < size; i++) {
3731 array[i] = new PointerCoords();
3732 }
3733 return array;
3734 }
3735
Jeff Brownc5ed5912010-07-14 18:48:53 -07003736 /**
Jeff Brown6f2fba42011-02-19 01:08:02 -08003737 * The X component of the pointer movement.
Jeff Brown91c69ab2011-02-14 17:03:18 -08003738 *
3739 * @see MotionEvent#AXIS_X
Jeff Brownc5ed5912010-07-14 18:48:53 -07003740 */
3741 public float x;
Dennis Kempinac1b31d2016-11-02 17:02:25 -07003742
Jeff Brownc5ed5912010-07-14 18:48:53 -07003743 /**
Jeff Brown6f2fba42011-02-19 01:08:02 -08003744 * The Y component of the pointer movement.
Jeff Brown91c69ab2011-02-14 17:03:18 -08003745 *
3746 * @see MotionEvent#AXIS_Y
Jeff Brownc5ed5912010-07-14 18:48:53 -07003747 */
3748 public float y;
Dennis Kempinac1b31d2016-11-02 17:02:25 -07003749
Jeff Brownc5ed5912010-07-14 18:48:53 -07003750 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08003751 * A normalized value that describes the pressure applied to the device
3752 * by a finger or other tool.
Jeff Brownc5ed5912010-07-14 18:48:53 -07003753 * The pressure generally ranges from 0 (no pressure at all) to 1 (normal pressure),
Jeff Brown91c69ab2011-02-14 17:03:18 -08003754 * although values higher than 1 may be generated depending on the calibration of
Jeff Brownc5ed5912010-07-14 18:48:53 -07003755 * the input device.
Jeff Brown91c69ab2011-02-14 17:03:18 -08003756 *
3757 * @see MotionEvent#AXIS_PRESSURE
Jeff Brownc5ed5912010-07-14 18:48:53 -07003758 */
3759 public float pressure;
Dennis Kempinac1b31d2016-11-02 17:02:25 -07003760
Jeff Brownc5ed5912010-07-14 18:48:53 -07003761 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08003762 * A normalized value that describes the approximate size of the pointer touch area
3763 * in relation to the maximum detectable size of the device.
3764 * It represents some approximation of the area of the screen being
Jeff Brownc5ed5912010-07-14 18:48:53 -07003765 * pressed; the actual value in pixels corresponding to the
3766 * touch is normalized with the device specific range of values
3767 * and scaled to a value between 0 and 1. The value of size can be used to
3768 * determine fat touch events.
Jeff Brown91c69ab2011-02-14 17:03:18 -08003769 *
3770 * @see MotionEvent#AXIS_SIZE
Jeff Brownc5ed5912010-07-14 18:48:53 -07003771 */
3772 public float size;
Dennis Kempinac1b31d2016-11-02 17:02:25 -07003773
Jeff Brownc5ed5912010-07-14 18:48:53 -07003774 /**
3775 * The length of the major axis of an ellipse that describes the touch area at
3776 * the point of contact.
Jeff Brown91c69ab2011-02-14 17:03:18 -08003777 * If the device is a touch screen, the length is reported in pixels, otherwise it is
3778 * reported in device-specific units.
3779 *
3780 * @see MotionEvent#AXIS_TOUCH_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07003781 */
3782 public float touchMajor;
Dennis Kempinac1b31d2016-11-02 17:02:25 -07003783
Jeff Brownc5ed5912010-07-14 18:48:53 -07003784 /**
3785 * The length of the minor axis of an ellipse that describes the touch area at
3786 * the point of contact.
Jeff Brown91c69ab2011-02-14 17:03:18 -08003787 * If the device is a touch screen, the length is reported in pixels, otherwise it is
3788 * reported in device-specific units.
3789 *
3790 * @see MotionEvent#AXIS_TOUCH_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07003791 */
3792 public float touchMinor;
Dennis Kempinac1b31d2016-11-02 17:02:25 -07003793
Jeff Brownc5ed5912010-07-14 18:48:53 -07003794 /**
3795 * The length of the major axis of an ellipse that describes the size of
3796 * the approaching tool.
3797 * The tool area represents the estimated size of the finger or pen that is
3798 * touching the device independent of its actual touch area at the point of contact.
Jeff Brown91c69ab2011-02-14 17:03:18 -08003799 * If the device is a touch screen, the length is reported in pixels, otherwise it is
3800 * reported in device-specific units.
3801 *
3802 * @see MotionEvent#AXIS_TOOL_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07003803 */
3804 public float toolMajor;
Dennis Kempinac1b31d2016-11-02 17:02:25 -07003805
Jeff Brownc5ed5912010-07-14 18:48:53 -07003806 /**
3807 * The length of the minor axis of an ellipse that describes the size of
3808 * the approaching tool.
3809 * The tool area represents the estimated size of the finger or pen that is
3810 * touching the device independent of its actual touch area at the point of contact.
Jeff Brown91c69ab2011-02-14 17:03:18 -08003811 * If the device is a touch screen, the length is reported in pixels, otherwise it is
3812 * reported in device-specific units.
3813 *
3814 * @see MotionEvent#AXIS_TOOL_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07003815 */
3816 public float toolMinor;
Dennis Kempinac1b31d2016-11-02 17:02:25 -07003817
Jeff Brownc5ed5912010-07-14 18:48:53 -07003818 /**
3819 * The orientation of the touch area and tool area in radians clockwise from vertical.
Jeff Brown6f2fba42011-02-19 01:08:02 -08003820 * An angle of 0 radians indicates that the major axis of contact is oriented
Jeff Brownc5ed5912010-07-14 18:48:53 -07003821 * upwards, is perfectly circular or is of unknown orientation. A positive angle
3822 * indicates that the major axis of contact is oriented to the right. A negative angle
3823 * indicates that the major axis of contact is oriented to the left.
Jeff Brown6d0fec22010-07-23 21:28:06 -07003824 * The full range is from -PI/2 radians (finger pointing fully left) to PI/2 radians
Jeff Brownc5ed5912010-07-14 18:48:53 -07003825 * (finger pointing fully right).
Jeff Brown91c69ab2011-02-14 17:03:18 -08003826 *
3827 * @see MotionEvent#AXIS_ORIENTATION
Jeff Brownc5ed5912010-07-14 18:48:53 -07003828 */
3829 public float orientation;
Jeff Brown91c69ab2011-02-14 17:03:18 -08003830
3831 /**
3832 * Clears the contents of this object.
3833 * Resets all axes to zero.
3834 */
3835 public void clear() {
3836 mPackedAxisBits = 0;
3837
3838 x = 0;
3839 y = 0;
3840 pressure = 0;
3841 size = 0;
3842 touchMajor = 0;
3843 touchMinor = 0;
3844 toolMajor = 0;
3845 toolMinor = 0;
3846 orientation = 0;
Jeff Brownc5ed5912010-07-14 18:48:53 -07003847 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08003848
3849 /**
3850 * Copies the contents of another pointer coords object.
3851 *
3852 * @param other The pointer coords object to copy.
3853 */
3854 public void copyFrom(PointerCoords other) {
Jeff Brown6f2fba42011-02-19 01:08:02 -08003855 final long bits = other.mPackedAxisBits;
Jeff Brown91c69ab2011-02-14 17:03:18 -08003856 mPackedAxisBits = bits;
3857 if (bits != 0) {
3858 final float[] otherValues = other.mPackedAxisValues;
Jeff Brown6f2fba42011-02-19 01:08:02 -08003859 final int count = Long.bitCount(bits);
Jeff Brown91c69ab2011-02-14 17:03:18 -08003860 float[] values = mPackedAxisValues;
3861 if (values == null || count > values.length) {
3862 values = new float[otherValues.length];
3863 mPackedAxisValues = values;
3864 }
3865 System.arraycopy(otherValues, 0, values, 0, count);
3866 }
3867
3868 x = other.x;
3869 y = other.y;
3870 pressure = other.pressure;
3871 size = other.size;
3872 touchMajor = other.touchMajor;
3873 touchMinor = other.touchMinor;
3874 toolMajor = other.toolMajor;
3875 toolMinor = other.toolMinor;
3876 orientation = other.orientation;
Jeff Brownc5ed5912010-07-14 18:48:53 -07003877 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08003878
3879 /**
3880 * Gets the value associated with the specified axis.
3881 *
3882 * @param axis The axis identifier for the axis value to retrieve.
3883 * @return The value associated with the axis, or 0 if none.
3884 *
3885 * @see MotionEvent#AXIS_X
3886 * @see MotionEvent#AXIS_Y
3887 */
3888 public float getAxisValue(int axis) {
3889 switch (axis) {
3890 case AXIS_X:
3891 return x;
3892 case AXIS_Y:
3893 return y;
3894 case AXIS_PRESSURE:
3895 return pressure;
3896 case AXIS_SIZE:
3897 return size;
3898 case AXIS_TOUCH_MAJOR:
3899 return touchMajor;
3900 case AXIS_TOUCH_MINOR:
3901 return touchMinor;
3902 case AXIS_TOOL_MAJOR:
3903 return toolMajor;
3904 case AXIS_TOOL_MINOR:
3905 return toolMinor;
3906 case AXIS_ORIENTATION:
3907 return orientation;
3908 default: {
Jeff Brown6f2fba42011-02-19 01:08:02 -08003909 if (axis < 0 || axis > 63) {
3910 throw new IllegalArgumentException("Axis out of range.");
3911 }
3912 final long bits = mPackedAxisBits;
Michael Wright9adca062014-03-19 11:51:26 -07003913 final long axisBit = 0x8000000000000000L >>> axis;
Jeff Brown91c69ab2011-02-14 17:03:18 -08003914 if ((bits & axisBit) == 0) {
3915 return 0;
3916 }
Michael Wright9adca062014-03-19 11:51:26 -07003917 final int index = Long.bitCount(bits & ~(0xFFFFFFFFFFFFFFFFL >>> axis));
Jeff Brown91c69ab2011-02-14 17:03:18 -08003918 return mPackedAxisValues[index];
3919 }
3920 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07003921 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08003922
3923 /**
3924 * Sets the value associated with the specified axis.
3925 *
3926 * @param axis The axis identifier for the axis value to assign.
3927 * @param value The value to set.
3928 *
3929 * @see MotionEvent#AXIS_X
3930 * @see MotionEvent#AXIS_Y
3931 */
3932 public void setAxisValue(int axis, float value) {
3933 switch (axis) {
3934 case AXIS_X:
3935 x = value;
3936 break;
3937 case AXIS_Y:
3938 y = value;
3939 break;
3940 case AXIS_PRESSURE:
3941 pressure = value;
3942 break;
3943 case AXIS_SIZE:
3944 size = value;
3945 break;
3946 case AXIS_TOUCH_MAJOR:
3947 touchMajor = value;
3948 break;
3949 case AXIS_TOUCH_MINOR:
3950 touchMinor = value;
3951 break;
3952 case AXIS_TOOL_MAJOR:
3953 toolMajor = value;
3954 break;
3955 case AXIS_TOOL_MINOR:
3956 toolMinor = value;
3957 break;
3958 case AXIS_ORIENTATION:
3959 orientation = value;
3960 break;
3961 default: {
Jeff Brown6f2fba42011-02-19 01:08:02 -08003962 if (axis < 0 || axis > 63) {
3963 throw new IllegalArgumentException("Axis out of range.");
3964 }
3965 final long bits = mPackedAxisBits;
Michael Wright9adca062014-03-19 11:51:26 -07003966 final long axisBit = 0x8000000000000000L >>> axis;
3967 final int index = Long.bitCount(bits & ~(0xFFFFFFFFFFFFFFFFL >>> axis));
Jeff Brown91c69ab2011-02-14 17:03:18 -08003968 float[] values = mPackedAxisValues;
3969 if ((bits & axisBit) == 0) {
3970 if (values == null) {
3971 values = new float[INITIAL_PACKED_AXIS_VALUES];
3972 mPackedAxisValues = values;
3973 } else {
Jeff Brown6f2fba42011-02-19 01:08:02 -08003974 final int count = Long.bitCount(bits);
Jeff Brown91c69ab2011-02-14 17:03:18 -08003975 if (count < values.length) {
3976 if (index != count) {
3977 System.arraycopy(values, index, values, index + 1,
3978 count - index);
3979 }
3980 } else {
3981 float[] newValues = new float[count * 2];
3982 System.arraycopy(values, 0, newValues, 0, index);
3983 System.arraycopy(values, index, newValues, index + 1,
3984 count - index);
3985 values = newValues;
3986 mPackedAxisValues = values;
3987 }
3988 }
3989 mPackedAxisBits = bits | axisBit;
3990 }
3991 values[index] = value;
3992 }
3993 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07003994 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07003995 }
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003996
3997 /**
3998 * Transfer object for pointer properties.
3999 *
4000 * Objects of this type can be used to specify the pointer id and tool type
4001 * when creating new {@link MotionEvent} objects and to query pointer properties in bulk.
4002 */
4003 public static final class PointerProperties {
4004 /**
4005 * Creates a pointer properties object with an invalid pointer id.
4006 */
4007 public PointerProperties() {
4008 clear();
4009 }
4010
4011 /**
4012 * Creates a pointer properties object as a copy of the contents of
4013 * another pointer properties object.
4014 * @param other
4015 */
4016 public PointerProperties(PointerProperties other) {
4017 copyFrom(other);
4018 }
4019
4020 /** @hide */
Mathew Inwooda570dee2018-08-17 14:56:00 +01004021 @UnsupportedAppUsage
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07004022 public static PointerProperties[] createArray(int size) {
4023 PointerProperties[] array = new PointerProperties[size];
4024 for (int i = 0; i < size; i++) {
4025 array[i] = new PointerProperties();
4026 }
4027 return array;
4028 }
4029
4030 /**
4031 * The pointer id.
4032 * Initially set to {@link #INVALID_POINTER_ID} (-1).
4033 *
4034 * @see MotionEvent#getPointerId(int)
4035 */
4036 public int id;
4037
4038 /**
4039 * The pointer tool type.
4040 * Initially set to 0.
4041 *
4042 * @see MotionEvent#getToolType(int)
4043 */
4044 public int toolType;
4045
4046 /**
4047 * Resets the pointer properties to their initial values.
4048 */
4049 public void clear() {
4050 id = INVALID_POINTER_ID;
4051 toolType = TOOL_TYPE_UNKNOWN;
4052 }
4053
4054 /**
4055 * Copies the contents of another pointer properties object.
4056 *
4057 * @param other The pointer properties object to copy.
4058 */
4059 public void copyFrom(PointerProperties other) {
4060 id = other.id;
4061 toolType = other.toolType;
4062 }
Jeff Brown9d3bdbd2012-03-21 11:50:06 -07004063
4064 @Override
4065 public boolean equals(Object other) {
4066 if (other instanceof PointerProperties) {
4067 return equals((PointerProperties)other);
4068 }
4069 return false;
4070 }
4071
4072 private boolean equals(PointerProperties other) {
4073 return other != null && id == other.id && toolType == other.toolType;
4074 }
4075
4076 @Override
4077 public int hashCode() {
4078 return id | (toolType << 8);
4079 }
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07004080 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004081}