blob: 19eff72ca814264c6777edc3915343a995e61a85 [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;
Artur Satayevad9254c2019-12-10 17:47:54 +000025import android.compat.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 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800490 * Flag indicating the motion event intersected the top edge of the screen.
491 */
492 public static final int EDGE_TOP = 0x00000001;
Romain Guycafdea62009-06-12 10:51:36 -0700493
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800494 /**
495 * Flag indicating the motion event intersected the bottom edge of the screen.
496 */
497 public static final int EDGE_BOTTOM = 0x00000002;
Romain Guycafdea62009-06-12 10:51:36 -0700498
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800499 /**
500 * Flag indicating the motion event intersected the left edge of the screen.
501 */
502 public static final int EDGE_LEFT = 0x00000004;
Romain Guycafdea62009-06-12 10:51:36 -0700503
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800504 /**
505 * Flag indicating the motion event intersected the right edge of the screen.
506 */
507 public static final int EDGE_RIGHT = 0x00000008;
Romain Guycafdea62009-06-12 10:51:36 -0700508
Jeff Brown91c69ab2011-02-14 17:03:18 -0800509 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700510 * Axis constant: X axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800511 * <p>
512 * <ul>
513 * <li>For a touch screen, reports the absolute X screen position of the center of
514 * the touch contact area. The units are display pixels.
515 * <li>For a touch pad, reports the absolute X surface position of the center of the touch
Jeff Browncc0c1592011-02-19 05:07:28 -0800516 * contact area. The units are device-dependent; use {@link InputDevice#getMotionRange(int)}
517 * to query the effective range of values.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800518 * <li>For a mouse, reports the absolute X screen position of the mouse pointer.
519 * The units are display pixels.
520 * <li>For a trackball, reports the relative horizontal displacement of the trackball.
521 * The value is normalized to a range from -1.0 (left) to 1.0 (right).
522 * <li>For a joystick, reports the absolute X position of the joystick.
523 * The value is normalized to a range from -1.0 (left) to 1.0 (right).
524 * </ul>
525 * </p>
Jeff Brown91c69ab2011-02-14 17:03:18 -0800526 *
527 * @see #getX(int)
528 * @see #getHistoricalX(int, int)
529 * @see MotionEvent.PointerCoords#x
530 * @see InputDevice#getMotionRange
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700531 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800532 public static final int AXIS_X = 0;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700533
Jeff Brown91c69ab2011-02-14 17:03:18 -0800534 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700535 * Axis constant: Y axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800536 * <p>
537 * <ul>
538 * <li>For a touch screen, reports the absolute Y screen position of the center of
539 * the touch contact area. The units are display pixels.
540 * <li>For a touch pad, reports the absolute Y surface position of the center of the touch
541 * contact area. The units are device-dependent; use {@link InputDevice#getMotionRange(int)}
542 * to query the effective range of values.
543 * <li>For a mouse, reports the absolute Y screen position of the mouse pointer.
544 * The units are display pixels.
545 * <li>For a trackball, reports the relative vertical displacement of the trackball.
546 * The value is normalized to a range from -1.0 (up) to 1.0 (down).
547 * <li>For a joystick, reports the absolute Y position of the joystick.
548 * The value is normalized to a range from -1.0 (up or far) to 1.0 (down or near).
549 * </ul>
550 * </p>
Jeff Brown91c69ab2011-02-14 17:03:18 -0800551 *
552 * @see #getY(int)
553 * @see #getHistoricalY(int, int)
554 * @see MotionEvent.PointerCoords#y
555 * @see InputDevice#getMotionRange
Jeff Brownc5ed5912010-07-14 18:48:53 -0700556 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800557 public static final int AXIS_Y = 1;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700558
Jeff Brown91c69ab2011-02-14 17:03:18 -0800559 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700560 * Axis constant: Pressure axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800561 * <p>
562 * <ul>
Jeff Browncc0c1592011-02-19 05:07:28 -0800563 * <li>For a touch screen or touch pad, reports the approximate pressure applied to the surface
Jeff Brown6f2fba42011-02-19 01:08:02 -0800564 * by a finger or other tool. The value is normalized to a range from
565 * 0 (no pressure at all) to 1 (normal pressure), although values higher than 1
566 * may be generated depending on the calibration of the input device.
567 * <li>For a trackball, the value is set to 1 if the trackball button is pressed
568 * or 0 otherwise.
569 * <li>For a mouse, the value is set to 1 if the primary mouse button is pressed
570 * or 0 otherwise.
571 * </ul>
572 * </p>
Jeff Brown91c69ab2011-02-14 17:03:18 -0800573 *
574 * @see #getPressure(int)
575 * @see #getHistoricalPressure(int, int)
576 * @see MotionEvent.PointerCoords#pressure
577 * @see InputDevice#getMotionRange
Jeff Brownc5ed5912010-07-14 18:48:53 -0700578 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800579 public static final int AXIS_PRESSURE = 2;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700580
Jeff Brown91c69ab2011-02-14 17:03:18 -0800581 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700582 * Axis constant: Size axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800583 * <p>
584 * <ul>
585 * <li>For a touch screen or touch pad, reports the approximate size of the contact area in
586 * relation to the maximum detectable size for the device. The value is normalized
587 * to a range from 0 (smallest detectable size) to 1 (largest detectable size),
Jeff Browncc0c1592011-02-19 05:07:28 -0800588 * although it is not a linear scale. This value is of limited use.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800589 * To obtain calibrated size information, use
590 * {@link #AXIS_TOUCH_MAJOR} or {@link #AXIS_TOOL_MAJOR}.
591 * </ul>
592 * </p>
Jeff Brown91c69ab2011-02-14 17:03:18 -0800593 *
594 * @see #getSize(int)
595 * @see #getHistoricalSize(int, int)
596 * @see MotionEvent.PointerCoords#size
597 * @see InputDevice#getMotionRange
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700598 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800599 public static final int AXIS_SIZE = 3;
600
601 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700602 * Axis constant: TouchMajor axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800603 * <p>
604 * <ul>
605 * <li>For a touch screen, reports the length of the major axis of an ellipse that
606 * represents the touch area at the point of contact.
607 * The units are display pixels.
608 * <li>For a touch pad, reports the length of the major axis of an ellipse that
609 * represents the touch area at the point of contact.
610 * The units are device-dependent; use {@link InputDevice#getMotionRange(int)}
611 * to query the effective range of values.
612 * </ul>
613 * </p>
Jeff Brown91c69ab2011-02-14 17:03:18 -0800614 *
615 * @see #getTouchMajor(int)
616 * @see #getHistoricalTouchMajor(int, int)
617 * @see MotionEvent.PointerCoords#touchMajor
618 * @see InputDevice#getMotionRange
Dianne Hackborn1e8dfc72009-08-06 12:43:01 -0700619 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800620 public static final int AXIS_TOUCH_MAJOR = 4;
621
622 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700623 * Axis constant: TouchMinor axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800624 * <p>
625 * <ul>
626 * <li>For a touch screen, reports the length of the minor axis of an ellipse that
627 * represents the touch area at the point of contact.
628 * The units are display pixels.
629 * <li>For a touch pad, reports the length of the minor axis of an ellipse that
630 * represents the touch area at the point of contact.
631 * The units are device-dependent; use {@link InputDevice#getMotionRange(int)}
632 * to query the effective range of values.
633 * </ul>
634 * </p><p>
635 * When the touch is circular, the major and minor axis lengths will be equal to one another.
636 * </p>
Jeff Brown91c69ab2011-02-14 17:03:18 -0800637 *
638 * @see #getTouchMinor(int)
639 * @see #getHistoricalTouchMinor(int, int)
640 * @see MotionEvent.PointerCoords#touchMinor
641 * @see InputDevice#getMotionRange
Jeff Brown9e2ad362010-07-30 19:20:11 -0700642 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800643 public static final int AXIS_TOUCH_MINOR = 5;
644
645 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700646 * Axis constant: ToolMajor axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800647 * <p>
648 * <ul>
649 * <li>For a touch screen, reports the length of the major axis of an ellipse that
650 * represents the size of the approaching finger or tool used to make contact.
651 * <li>For a touch pad, reports the length of the major axis of an ellipse that
652 * represents the size of the approaching finger or tool used to make contact.
653 * The units are device-dependent; use {@link InputDevice#getMotionRange(int)}
654 * to query the effective range of values.
655 * </ul>
656 * </p><p>
657 * When the touch is circular, the major and minor axis lengths will be equal to one another.
658 * </p><p>
659 * The tool size may be larger than the touch size since the tool may not be fully
660 * in contact with the touch sensor.
661 * </p>
Jeff Brown91c69ab2011-02-14 17:03:18 -0800662 *
663 * @see #getToolMajor(int)
664 * @see #getHistoricalToolMajor(int, int)
665 * @see MotionEvent.PointerCoords#toolMajor
666 * @see InputDevice#getMotionRange
667 */
668 public static final int AXIS_TOOL_MAJOR = 6;
669
670 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700671 * Axis constant: ToolMinor axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800672 * <p>
673 * <ul>
674 * <li>For a touch screen, reports the length of the minor axis of an ellipse that
675 * represents the size of the approaching finger or tool used to make contact.
676 * <li>For a touch pad, reports the length of the minor axis of an ellipse that
677 * represents the size of the approaching finger or tool used to make contact.
678 * The units are device-dependent; use {@link InputDevice#getMotionRange(int)}
679 * to query the effective range of values.
680 * </ul>
681 * </p><p>
682 * When the touch is circular, the major and minor axis lengths will be equal to one another.
683 * </p><p>
684 * The tool size may be larger than the touch size since the tool may not be fully
685 * in contact with the touch sensor.
686 * </p>
Jeff Brown91c69ab2011-02-14 17:03:18 -0800687 *
688 * @see #getToolMinor(int)
689 * @see #getHistoricalToolMinor(int, int)
690 * @see MotionEvent.PointerCoords#toolMinor
691 * @see InputDevice#getMotionRange
692 */
693 public static final int AXIS_TOOL_MINOR = 7;
694
695 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700696 * Axis constant: Orientation axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800697 * <p>
698 * <ul>
699 * <li>For a touch screen or touch pad, reports the orientation of the finger
700 * or tool in radians relative to the vertical plane of the device.
701 * An angle of 0 radians indicates that the major axis of contact is oriented
Jeff Brown91c69ab2011-02-14 17:03:18 -0800702 * upwards, is perfectly circular or is of unknown orientation. A positive angle
703 * indicates that the major axis of contact is oriented to the right. A negative angle
704 * indicates that the major axis of contact is oriented to the left.
705 * The full range is from -PI/2 radians (finger pointing fully left) to PI/2 radians
706 * (finger pointing fully right).
Jeff Brown65fd2512011-08-18 11:20:58 -0700707 * <li>For a stylus, the orientation indicates the direction in which the stylus
708 * is pointing in relation to the vertical axis of the current orientation of the screen.
709 * The range is from -PI radians to PI radians, where 0 is pointing up,
710 * -PI/2 radians is pointing left, -PI or PI radians is pointing down, and PI/2 radians
711 * is pointing right. See also {@link #AXIS_TILT}.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800712 * </ul>
713 * </p>
Jeff Brown91c69ab2011-02-14 17:03:18 -0800714 *
715 * @see #getOrientation(int)
716 * @see #getHistoricalOrientation(int, int)
717 * @see MotionEvent.PointerCoords#orientation
718 * @see InputDevice#getMotionRange
719 */
720 public static final int AXIS_ORIENTATION = 8;
721
Jeff Brown6f2fba42011-02-19 01:08:02 -0800722 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700723 * Axis constant: Vertical Scroll axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800724 * <p>
725 * <ul>
Jeff Browncc0c1592011-02-19 05:07:28 -0800726 * <li>For a mouse, reports the relative movement of the vertical scroll wheel.
Jeff Brown33bbfd22011-02-24 20:55:35 -0800727 * The value is normalized to a range from -1.0 (down) to 1.0 (up).
Jeff Brown6f2fba42011-02-19 01:08:02 -0800728 * </ul>
729 * </p><p>
730 * This axis should be used to scroll views vertically.
731 * </p>
732 *
733 * @see #getAxisValue(int, int)
734 * @see #getHistoricalAxisValue(int, int, int)
735 * @see MotionEvent.PointerCoords#getAxisValue(int)
736 * @see InputDevice#getMotionRange
737 */
738 public static final int AXIS_VSCROLL = 9;
739
740 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700741 * Axis constant: Horizontal Scroll axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800742 * <p>
743 * <ul>
Jeff Browncc0c1592011-02-19 05:07:28 -0800744 * <li>For a mouse, reports the relative movement of the horizontal scroll wheel.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800745 * The value is normalized to a range from -1.0 (left) to 1.0 (right).
746 * </ul>
747 * </p><p>
748 * This axis should be used to scroll views horizontally.
749 * </p>
750 *
751 * @see #getAxisValue(int, int)
752 * @see #getHistoricalAxisValue(int, int, int)
753 * @see MotionEvent.PointerCoords#getAxisValue(int)
754 * @see InputDevice#getMotionRange
755 */
756 public static final int AXIS_HSCROLL = 10;
757
758 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700759 * Axis constant: Z axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800760 * <p>
761 * <ul>
762 * <li>For a joystick, reports the absolute Z position of the joystick.
763 * The value is normalized to a range from -1.0 (high) to 1.0 (low).
764 * <em>On game pads with two analog joysticks, this axis is often reinterpreted
765 * to report the absolute X position of the second joystick instead.</em>
766 * </ul>
767 * </p>
768 *
769 * @see #getAxisValue(int, int)
770 * @see #getHistoricalAxisValue(int, int, int)
771 * @see MotionEvent.PointerCoords#getAxisValue(int)
772 * @see InputDevice#getMotionRange
773 */
774 public static final int AXIS_Z = 11;
775
776 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700777 * Axis constant: X Rotation axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800778 * <p>
779 * <ul>
780 * <li>For a joystick, reports the absolute rotation angle about the X axis.
781 * The value is normalized to a range from -1.0 (counter-clockwise) to 1.0 (clockwise).
782 * </ul>
783 * </p>
784 *
785 * @see #getAxisValue(int, int)
786 * @see #getHistoricalAxisValue(int, int, int)
787 * @see MotionEvent.PointerCoords#getAxisValue(int)
788 * @see InputDevice#getMotionRange
789 */
790 public static final int AXIS_RX = 12;
791
792 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700793 * Axis constant: Y Rotation axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800794 * <p>
795 * <ul>
796 * <li>For a joystick, reports the absolute rotation angle about the Y axis.
797 * The value is normalized to a range from -1.0 (counter-clockwise) to 1.0 (clockwise).
798 * </ul>
799 * </p>
800 *
801 * @see #getAxisValue(int, int)
802 * @see #getHistoricalAxisValue(int, int, int)
803 * @see MotionEvent.PointerCoords#getAxisValue(int)
804 * @see InputDevice#getMotionRange
805 */
806 public static final int AXIS_RY = 13;
807
808 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700809 * Axis constant: Z Rotation axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800810 * <p>
811 * <ul>
812 * <li>For a joystick, reports the absolute rotation angle about the Z axis.
813 * The value is normalized to a range from -1.0 (counter-clockwise) to 1.0 (clockwise).
814 * <em>On game pads with two analog joysticks, this axis is often reinterpreted
815 * to report the absolute Y position of the second joystick instead.</em>
816 * </ul>
817 * </p>
818 *
819 * @see #getAxisValue(int, int)
820 * @see #getHistoricalAxisValue(int, int, int)
821 * @see MotionEvent.PointerCoords#getAxisValue(int)
822 * @see InputDevice#getMotionRange
823 */
824 public static final int AXIS_RZ = 14;
825
826 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700827 * Axis constant: Hat X axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800828 * <p>
829 * <ul>
830 * <li>For a joystick, reports the absolute X position of the directional hat control.
831 * The value is normalized to a range from -1.0 (left) to 1.0 (right).
832 * </ul>
833 * </p>
834 *
835 * @see #getAxisValue(int, int)
836 * @see #getHistoricalAxisValue(int, int, int)
837 * @see MotionEvent.PointerCoords#getAxisValue(int)
838 * @see InputDevice#getMotionRange
839 */
840 public static final int AXIS_HAT_X = 15;
841
842 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700843 * Axis constant: Hat Y axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800844 * <p>
845 * <ul>
846 * <li>For a joystick, reports the absolute Y position of the directional hat control.
847 * The value is normalized to a range from -1.0 (up) to 1.0 (down).
848 * </ul>
849 * </p>
850 *
851 * @see #getAxisValue(int, int)
852 * @see #getHistoricalAxisValue(int, int, int)
853 * @see MotionEvent.PointerCoords#getAxisValue(int)
854 * @see InputDevice#getMotionRange
855 */
856 public static final int AXIS_HAT_Y = 16;
857
858 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700859 * Axis constant: Left Trigger axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800860 * <p>
861 * <ul>
862 * <li>For a joystick, reports the absolute position of the left trigger control.
863 * The value is normalized to a range from 0.0 (released) to 1.0 (fully pressed).
864 * </ul>
865 * </p>
866 *
867 * @see #getAxisValue(int, int)
868 * @see #getHistoricalAxisValue(int, int, int)
869 * @see MotionEvent.PointerCoords#getAxisValue(int)
870 * @see InputDevice#getMotionRange
871 */
872 public static final int AXIS_LTRIGGER = 17;
873
874 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700875 * Axis constant: Right Trigger axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800876 * <p>
877 * <ul>
878 * <li>For a joystick, reports the absolute position of the right trigger control.
879 * The value is normalized to a range from 0.0 (released) to 1.0 (fully pressed).
880 * </ul>
881 * </p>
882 *
883 * @see #getAxisValue(int, int)
884 * @see #getHistoricalAxisValue(int, int, int)
885 * @see MotionEvent.PointerCoords#getAxisValue(int)
886 * @see InputDevice#getMotionRange
887 */
888 public static final int AXIS_RTRIGGER = 18;
889
890 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700891 * Axis constant: Throttle axis of a motion event.
Jeff Brown3a22fa02011-03-04 13:07:49 -0800892 * <p>
893 * <ul>
894 * <li>For a joystick, reports the absolute position of the throttle control.
895 * The value is normalized to a range from 0.0 (fully open) to 1.0 (fully closed).
896 * </ul>
897 * </p>
898 *
899 * @see #getAxisValue(int, int)
900 * @see #getHistoricalAxisValue(int, int, int)
901 * @see MotionEvent.PointerCoords#getAxisValue(int)
902 * @see InputDevice#getMotionRange
903 */
904 public static final int AXIS_THROTTLE = 19;
905
906 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700907 * Axis constant: Rudder axis of a motion event.
Jeff Brown3a22fa02011-03-04 13:07:49 -0800908 * <p>
909 * <ul>
910 * <li>For a joystick, reports the absolute position of the rudder control.
911 * The value is normalized to a range from -1.0 (turn left) to 1.0 (turn right).
912 * </ul>
913 * </p>
914 *
915 * @see #getAxisValue(int, int)
916 * @see #getHistoricalAxisValue(int, int, int)
917 * @see MotionEvent.PointerCoords#getAxisValue(int)
918 * @see InputDevice#getMotionRange
919 */
920 public static final int AXIS_RUDDER = 20;
921
922 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700923 * Axis constant: Wheel axis of a motion event.
Jeff Brown3a22fa02011-03-04 13:07:49 -0800924 * <p>
925 * <ul>
926 * <li>For a joystick, reports the absolute position of the steering wheel control.
927 * The value is normalized to a range from -1.0 (turn left) to 1.0 (turn right).
928 * </ul>
929 * </p>
930 *
931 * @see #getAxisValue(int, int)
932 * @see #getHistoricalAxisValue(int, int, int)
933 * @see MotionEvent.PointerCoords#getAxisValue(int)
934 * @see InputDevice#getMotionRange
935 */
936 public static final int AXIS_WHEEL = 21;
937
938 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700939 * Axis constant: Gas axis of a motion event.
Jeff Brown3a22fa02011-03-04 13:07:49 -0800940 * <p>
941 * <ul>
942 * <li>For a joystick, reports the absolute position of the gas (accelerator) control.
943 * The value is normalized to a range from 0.0 (no acceleration)
944 * to 1.0 (maximum acceleration).
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_GAS = 22;
954
955 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700956 * Axis constant: Brake 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 brake control.
960 * The value is normalized to a range from 0.0 (no braking) to 1.0 (maximum braking).
961 * </ul>
962 * </p>
963 *
964 * @see #getAxisValue(int, int)
965 * @see #getHistoricalAxisValue(int, int, int)
966 * @see MotionEvent.PointerCoords#getAxisValue(int)
967 * @see InputDevice#getMotionRange
968 */
969 public static final int AXIS_BRAKE = 23;
970
971 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700972 * Axis constant: Distance axis of a motion event.
973 * <p>
974 * <ul>
975 * <li>For a stylus, reports the distance of the stylus from the screen.
Jeff Brown65fd2512011-08-18 11:20:58 -0700976 * A value of 0.0 indicates direct contact and larger values indicate increasing
977 * distance from the surface.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700978 * </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_DISTANCE = 24;
987
988 /**
Jeff Brown65fd2512011-08-18 11:20:58 -0700989 * Axis constant: Tilt axis of a motion event.
990 * <p>
991 * <ul>
992 * <li>For a stylus, reports the tilt angle of the stylus in radians where
993 * 0 radians indicates that the stylus is being held perpendicular to the
994 * surface, and PI/2 radians indicates that the stylus is being held flat
995 * against the surface.
996 * </ul>
997 * </p>
998 *
999 * @see #getAxisValue(int, int)
1000 * @see #getHistoricalAxisValue(int, int, int)
1001 * @see MotionEvent.PointerCoords#getAxisValue(int, int)
1002 * @see InputDevice#getMotionRange
1003 */
1004 public static final int AXIS_TILT = 25;
1005
1006 /**
Prashant Malani67322b12015-08-25 17:41:34 -07001007 * Axis constant: Generic scroll axis of a motion event.
1008 * <p>
1009 * <ul>
1010 * <li>Reports the relative movement of the generic scrolling device.
1011 * </ul>
1012 * </p><p>
1013 * This axis should be used for scroll events that are neither strictly vertical nor horizontal.
1014 * A good example would be the rotation of a rotary encoder input device.
1015 * </p>
1016 *
1017 * @see #getAxisValue(int, int)
Prashant Malani67322b12015-08-25 17:41:34 -07001018 */
1019 public static final int AXIS_SCROLL = 26;
1020
1021 /**
Jun Mukai347e5d42015-12-03 01:13:31 -08001022 * Axis constant: The movement of x position of a motion event.
1023 * <p>
1024 * <ul>
1025 * <li>For a mouse, reports a difference of x position between the previous position.
1026 * This is useful when pointer is captured, in that case the mouse pointer doesn't change
1027 * the location but this axis reports the difference which allows the app to see
1028 * how the mouse is moved.
1029 * </ul>
1030 * </p>
1031 *
1032 * @see #getAxisValue(int, int)
1033 * @see #getHistoricalAxisValue(int, int, int)
1034 * @see MotionEvent.PointerCoords#getAxisValue(int, int)
1035 * @see InputDevice#getMotionRange
1036 */
1037 public static final int AXIS_RELATIVE_X = 27;
1038
1039 /**
1040 * Axis constant: The movement of y position of a motion event.
1041 * <p>
1042 * This is similar to {@link #AXIS_RELATIVE_X} but for y-axis.
1043 * </p>
1044 *
1045 * @see #getAxisValue(int, int)
1046 * @see #getHistoricalAxisValue(int, int, int)
1047 * @see MotionEvent.PointerCoords#getAxisValue(int, int)
1048 * @see InputDevice#getMotionRange
1049 */
1050 public static final int AXIS_RELATIVE_Y = 28;
1051
1052 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001053 * Axis constant: Generic 1 axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -08001054 * The interpretation of a generic axis is device-specific.
1055 *
1056 * @see #getAxisValue(int, int)
1057 * @see #getHistoricalAxisValue(int, int, int)
1058 * @see MotionEvent.PointerCoords#getAxisValue(int)
1059 * @see InputDevice#getMotionRange
1060 */
1061 public static final int AXIS_GENERIC_1 = 32;
1062
1063 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001064 * Axis constant: Generic 2 axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -08001065 * The interpretation of a generic axis is device-specific.
1066 *
1067 * @see #getAxisValue(int, int)
1068 * @see #getHistoricalAxisValue(int, int, int)
1069 * @see MotionEvent.PointerCoords#getAxisValue(int)
1070 * @see InputDevice#getMotionRange
1071 */
1072 public static final int AXIS_GENERIC_2 = 33;
1073
1074 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001075 * Axis constant: Generic 3 axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -08001076 * The interpretation of a generic axis is device-specific.
1077 *
1078 * @see #getAxisValue(int, int)
1079 * @see #getHistoricalAxisValue(int, int, int)
1080 * @see MotionEvent.PointerCoords#getAxisValue(int)
1081 * @see InputDevice#getMotionRange
1082 */
1083 public static final int AXIS_GENERIC_3 = 34;
1084
1085 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001086 * Axis constant: Generic 4 axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -08001087 * The interpretation of a generic axis is device-specific.
1088 *
1089 * @see #getAxisValue(int, int)
1090 * @see #getHistoricalAxisValue(int, int, int)
1091 * @see MotionEvent.PointerCoords#getAxisValue(int)
1092 * @see InputDevice#getMotionRange
1093 */
1094 public static final int AXIS_GENERIC_4 = 35;
1095
1096 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001097 * Axis constant: Generic 5 axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -08001098 * The interpretation of a generic axis is device-specific.
1099 *
1100 * @see #getAxisValue(int, int)
1101 * @see #getHistoricalAxisValue(int, int, int)
1102 * @see MotionEvent.PointerCoords#getAxisValue(int)
1103 * @see InputDevice#getMotionRange
1104 */
1105 public static final int AXIS_GENERIC_5 = 36;
1106
1107 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001108 * Axis constant: Generic 6 axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -08001109 * The interpretation of a generic axis is device-specific.
1110 *
1111 * @see #getAxisValue(int, int)
1112 * @see #getHistoricalAxisValue(int, int, int)
1113 * @see MotionEvent.PointerCoords#getAxisValue(int)
1114 * @see InputDevice#getMotionRange
1115 */
1116 public static final int AXIS_GENERIC_6 = 37;
1117
1118 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001119 * Axis constant: Generic 7 axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -08001120 * The interpretation of a generic axis is device-specific.
1121 *
1122 * @see #getAxisValue(int, int)
1123 * @see #getHistoricalAxisValue(int, int, int)
1124 * @see MotionEvent.PointerCoords#getAxisValue(int)
1125 * @see InputDevice#getMotionRange
1126 */
1127 public static final int AXIS_GENERIC_7 = 38;
1128
1129 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001130 * Axis constant: Generic 8 axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -08001131 * The interpretation of a generic axis is device-specific.
1132 *
1133 * @see #getAxisValue(int, int)
1134 * @see #getHistoricalAxisValue(int, int, int)
1135 * @see MotionEvent.PointerCoords#getAxisValue(int)
1136 * @see InputDevice#getMotionRange
1137 */
1138 public static final int AXIS_GENERIC_8 = 39;
1139
1140 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001141 * Axis constant: Generic 9 axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -08001142 * The interpretation of a generic axis is device-specific.
1143 *
1144 * @see #getAxisValue(int, int)
1145 * @see #getHistoricalAxisValue(int, int, int)
1146 * @see MotionEvent.PointerCoords#getAxisValue(int)
1147 * @see InputDevice#getMotionRange
1148 */
1149 public static final int AXIS_GENERIC_9 = 40;
1150
1151 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001152 * Axis constant: Generic 10 axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -08001153 * The interpretation of a generic axis is device-specific.
1154 *
1155 * @see #getAxisValue(int, int)
1156 * @see #getHistoricalAxisValue(int, int, int)
1157 * @see MotionEvent.PointerCoords#getAxisValue(int)
1158 * @see InputDevice#getMotionRange
1159 */
1160 public static final int AXIS_GENERIC_10 = 41;
1161
1162 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001163 * Axis constant: Generic 11 axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -08001164 * The interpretation of a generic axis is device-specific.
1165 *
1166 * @see #getAxisValue(int, int)
1167 * @see #getHistoricalAxisValue(int, int, int)
1168 * @see MotionEvent.PointerCoords#getAxisValue(int)
1169 * @see InputDevice#getMotionRange
1170 */
1171 public static final int AXIS_GENERIC_11 = 42;
1172
1173 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001174 * Axis constant: Generic 12 axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -08001175 * The interpretation of a generic axis is device-specific.
1176 *
1177 * @see #getAxisValue(int, int)
1178 * @see #getHistoricalAxisValue(int, int, int)
1179 * @see MotionEvent.PointerCoords#getAxisValue(int)
1180 * @see InputDevice#getMotionRange
1181 */
1182 public static final int AXIS_GENERIC_12 = 43;
1183
1184 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001185 * Axis constant: Generic 13 axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -08001186 * The interpretation of a generic axis is device-specific.
1187 *
1188 * @see #getAxisValue(int, int)
1189 * @see #getHistoricalAxisValue(int, int, int)
1190 * @see MotionEvent.PointerCoords#getAxisValue(int)
1191 * @see InputDevice#getMotionRange
1192 */
1193 public static final int AXIS_GENERIC_13 = 44;
1194
1195 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001196 * Axis constant: Generic 14 axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -08001197 * The interpretation of a generic axis is device-specific.
1198 *
1199 * @see #getAxisValue(int, int)
1200 * @see #getHistoricalAxisValue(int, int, int)
1201 * @see MotionEvent.PointerCoords#getAxisValue(int)
1202 * @see InputDevice#getMotionRange
1203 */
1204 public static final int AXIS_GENERIC_14 = 45;
1205
1206 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001207 * Axis constant: Generic 15 axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -08001208 * The interpretation of a generic axis is device-specific.
1209 *
1210 * @see #getAxisValue(int, int)
1211 * @see #getHistoricalAxisValue(int, int, int)
1212 * @see MotionEvent.PointerCoords#getAxisValue(int)
1213 * @see InputDevice#getMotionRange
1214 */
1215 public static final int AXIS_GENERIC_15 = 46;
1216
1217 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001218 * Axis constant: Generic 16 axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -08001219 * The interpretation of a generic axis is device-specific.
1220 *
1221 * @see #getAxisValue(int, int)
1222 * @see #getHistoricalAxisValue(int, int, int)
1223 * @see MotionEvent.PointerCoords#getAxisValue(int)
1224 * @see InputDevice#getMotionRange
1225 */
1226 public static final int AXIS_GENERIC_16 = 47;
1227
1228 // NOTE: If you add a new axis here you must also add it to:
1229 // native/include/android/input.h
1230 // frameworks/base/include/ui/KeycodeLabels.h
1231
1232 // Symbolic names of all axes.
1233 private static final SparseArray<String> AXIS_SYMBOLIC_NAMES = new SparseArray<String>();
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001234 static {
Jeff Brown6f2fba42011-02-19 01:08:02 -08001235 SparseArray<String> names = AXIS_SYMBOLIC_NAMES;
1236 names.append(AXIS_X, "AXIS_X");
1237 names.append(AXIS_Y, "AXIS_Y");
1238 names.append(AXIS_PRESSURE, "AXIS_PRESSURE");
1239 names.append(AXIS_SIZE, "AXIS_SIZE");
1240 names.append(AXIS_TOUCH_MAJOR, "AXIS_TOUCH_MAJOR");
1241 names.append(AXIS_TOUCH_MINOR, "AXIS_TOUCH_MINOR");
1242 names.append(AXIS_TOOL_MAJOR, "AXIS_TOOL_MAJOR");
1243 names.append(AXIS_TOOL_MINOR, "AXIS_TOOL_MINOR");
1244 names.append(AXIS_ORIENTATION, "AXIS_ORIENTATION");
1245 names.append(AXIS_VSCROLL, "AXIS_VSCROLL");
1246 names.append(AXIS_HSCROLL, "AXIS_HSCROLL");
1247 names.append(AXIS_Z, "AXIS_Z");
1248 names.append(AXIS_RX, "AXIS_RX");
1249 names.append(AXIS_RY, "AXIS_RY");
1250 names.append(AXIS_RZ, "AXIS_RZ");
1251 names.append(AXIS_HAT_X, "AXIS_HAT_X");
1252 names.append(AXIS_HAT_Y, "AXIS_HAT_Y");
1253 names.append(AXIS_LTRIGGER, "AXIS_LTRIGGER");
1254 names.append(AXIS_RTRIGGER, "AXIS_RTRIGGER");
Jeff Brown3a22fa02011-03-04 13:07:49 -08001255 names.append(AXIS_THROTTLE, "AXIS_THROTTLE");
1256 names.append(AXIS_RUDDER, "AXIS_RUDDER");
1257 names.append(AXIS_WHEEL, "AXIS_WHEEL");
1258 names.append(AXIS_GAS, "AXIS_GAS");
1259 names.append(AXIS_BRAKE, "AXIS_BRAKE");
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001260 names.append(AXIS_DISTANCE, "AXIS_DISTANCE");
Jeff Brown65fd2512011-08-18 11:20:58 -07001261 names.append(AXIS_TILT, "AXIS_TILT");
Prashant Malani67322b12015-08-25 17:41:34 -07001262 names.append(AXIS_SCROLL, "AXIS_SCROLL");
Jun Mukai347e5d42015-12-03 01:13:31 -08001263 names.append(AXIS_RELATIVE_X, "AXIS_REALTIVE_X");
1264 names.append(AXIS_RELATIVE_Y, "AXIS_REALTIVE_Y");
Jeff Brown6f2fba42011-02-19 01:08:02 -08001265 names.append(AXIS_GENERIC_1, "AXIS_GENERIC_1");
1266 names.append(AXIS_GENERIC_2, "AXIS_GENERIC_2");
1267 names.append(AXIS_GENERIC_3, "AXIS_GENERIC_3");
1268 names.append(AXIS_GENERIC_4, "AXIS_GENERIC_4");
1269 names.append(AXIS_GENERIC_5, "AXIS_GENERIC_5");
1270 names.append(AXIS_GENERIC_6, "AXIS_GENERIC_6");
1271 names.append(AXIS_GENERIC_7, "AXIS_GENERIC_7");
1272 names.append(AXIS_GENERIC_8, "AXIS_GENERIC_8");
1273 names.append(AXIS_GENERIC_9, "AXIS_GENERIC_9");
1274 names.append(AXIS_GENERIC_10, "AXIS_GENERIC_10");
1275 names.append(AXIS_GENERIC_11, "AXIS_GENERIC_11");
1276 names.append(AXIS_GENERIC_12, "AXIS_GENERIC_12");
1277 names.append(AXIS_GENERIC_13, "AXIS_GENERIC_13");
1278 names.append(AXIS_GENERIC_14, "AXIS_GENERIC_14");
1279 names.append(AXIS_GENERIC_15, "AXIS_GENERIC_15");
1280 names.append(AXIS_GENERIC_16, "AXIS_GENERIC_16");
1281 }
1282
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001283 /**
Jeff Brown49754db2011-07-01 17:37:58 -07001284 * Button constant: Primary button (left mouse button).
1285 *
1286 * This button constant is not set in response to simple touches with a finger
1287 * or stylus tip. The user must actually push a button.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001288 *
1289 * @see #getButtonState
1290 */
1291 public static final int BUTTON_PRIMARY = 1 << 0;
1292
1293 /**
Michael Wright5bd69e62015-05-14 14:48:08 +01001294 * Button constant: Secondary button (right mouse button).
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001295 *
1296 * @see #getButtonState
1297 */
1298 public static final int BUTTON_SECONDARY = 1 << 1;
1299
1300 /**
Michael Wright5bd69e62015-05-14 14:48:08 +01001301 * Button constant: Tertiary button (middle mouse button).
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001302 *
1303 * @see #getButtonState
1304 */
1305 public static final int BUTTON_TERTIARY = 1 << 2;
1306
1307 /**
1308 * Button constant: Back button pressed (mouse back button).
1309 * <p>
1310 * The system may send a {@link KeyEvent#KEYCODE_BACK} key press to the application
1311 * when this button is pressed.
1312 * </p>
1313 *
1314 * @see #getButtonState
1315 */
1316 public static final int BUTTON_BACK = 1 << 3;
1317
1318 /**
1319 * Button constant: Forward button pressed (mouse forward button).
1320 * <p>
1321 * The system may send a {@link KeyEvent#KEYCODE_FORWARD} key press to the application
1322 * when this button is pressed.
1323 * </p>
1324 *
1325 * @see #getButtonState
1326 */
1327 public static final int BUTTON_FORWARD = 1 << 4;
1328
Michael Wright5bd69e62015-05-14 14:48:08 +01001329 /**
1330 * Button constant: Primary stylus button pressed.
1331 *
1332 * @see #getButtonState
1333 */
1334 public static final int BUTTON_STYLUS_PRIMARY = 1 << 5;
1335
1336 /**
1337 * Button constant: Secondary stylus button pressed.
1338 *
1339 * @see #getButtonState
1340 */
1341 public static final int BUTTON_STYLUS_SECONDARY = 1 << 6;
1342
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001343 // NOTE: If you add a new axis here you must also add it to:
1344 // native/include/android/input.h
1345
1346 // Symbolic names of all button states in bit order from least significant
1347 // to most significant.
1348 private static final String[] BUTTON_SYMBOLIC_NAMES = new String[] {
1349 "BUTTON_PRIMARY",
1350 "BUTTON_SECONDARY",
1351 "BUTTON_TERTIARY",
1352 "BUTTON_BACK",
1353 "BUTTON_FORWARD",
Michael Wright5bd69e62015-05-14 14:48:08 +01001354 "BUTTON_STYLUS_PRIMARY",
1355 "BUTTON_STYLUS_SECONDARY",
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001356 "0x00000080",
1357 "0x00000100",
1358 "0x00000200",
1359 "0x00000400",
1360 "0x00000800",
1361 "0x00001000",
1362 "0x00002000",
1363 "0x00004000",
1364 "0x00008000",
1365 "0x00010000",
1366 "0x00020000",
1367 "0x00040000",
1368 "0x00080000",
1369 "0x00100000",
1370 "0x00200000",
1371 "0x00400000",
1372 "0x00800000",
1373 "0x01000000",
1374 "0x02000000",
1375 "0x04000000",
1376 "0x08000000",
1377 "0x10000000",
1378 "0x20000000",
1379 "0x40000000",
1380 "0x80000000",
1381 };
1382
1383 /**
Siarhei Vishniakoub05b0b52018-12-28 17:50:24 -08001384 * Classification constant: None.
1385 *
1386 * No additional information is available about the current motion event stream.
1387 *
1388 * @see #getClassification
1389 */
1390 public static final int CLASSIFICATION_NONE = 0;
1391
1392 /**
1393 * Classification constant: Ambiguous gesture.
1394 *
1395 * The user's intent with respect to the current event stream is not yet determined.
1396 * Gestural actions, such as scrolling, should be inhibited until the classification resolves
1397 * to another value or the event stream ends.
1398 *
1399 * @see #getClassification
1400 */
1401 public static final int CLASSIFICATION_AMBIGUOUS_GESTURE = 1;
1402
1403 /**
1404 * Classification constant: Deep press.
1405 *
1406 * The current event stream represents the user intentionally pressing harder on the screen.
1407 * This classification type should be used to accelerate the long press behaviour.
1408 *
1409 * @see #getClassification
1410 */
1411 public static final int CLASSIFICATION_DEEP_PRESS = 2;
1412
1413 /** @hide */
1414 @Retention(SOURCE)
1415 @IntDef(prefix = { "CLASSIFICATION" }, value = {
1416 CLASSIFICATION_NONE, CLASSIFICATION_AMBIGUOUS_GESTURE, CLASSIFICATION_DEEP_PRESS})
1417 public @interface Classification {};
1418
1419 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001420 * Tool type constant: Unknown tool type.
1421 * This constant is used when the tool type is not known or is not relevant,
1422 * such as for a trackball or other non-pointing device.
1423 *
1424 * @see #getToolType
1425 */
1426 public static final int TOOL_TYPE_UNKNOWN = 0;
1427
1428 /**
Jeff Brown49754db2011-07-01 17:37:58 -07001429 * Tool type constant: The tool is a finger.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001430 *
1431 * @see #getToolType
1432 */
1433 public static final int TOOL_TYPE_FINGER = 1;
1434
1435 /**
Jeff Brown49754db2011-07-01 17:37:58 -07001436 * Tool type constant: The tool is a stylus.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001437 *
1438 * @see #getToolType
1439 */
1440 public static final int TOOL_TYPE_STYLUS = 2;
1441
1442 /**
Garfield Tanf2ef2a72019-11-26 09:52:53 -08001443 * Tool type constant: The tool is a mouse.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001444 *
1445 * @see #getToolType
1446 */
1447 public static final int TOOL_TYPE_MOUSE = 3;
1448
1449 /**
Jeff Brown49754db2011-07-01 17:37:58 -07001450 * Tool type constant: The tool is an eraser or a stylus being used in an inverted posture.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001451 *
1452 * @see #getToolType
1453 */
Jeff Brown49754db2011-07-01 17:37:58 -07001454 public static final int TOOL_TYPE_ERASER = 4;
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001455
1456 // NOTE: If you add a new tool type here you must also add it to:
1457 // native/include/android/input.h
1458
1459 // Symbolic names of all tool types.
1460 private static final SparseArray<String> TOOL_TYPE_SYMBOLIC_NAMES = new SparseArray<String>();
Jeff Brown6f2fba42011-02-19 01:08:02 -08001461 static {
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001462 SparseArray<String> names = TOOL_TYPE_SYMBOLIC_NAMES;
1463 names.append(TOOL_TYPE_UNKNOWN, "TOOL_TYPE_UNKNOWN");
1464 names.append(TOOL_TYPE_FINGER, "TOOL_TYPE_FINGER");
1465 names.append(TOOL_TYPE_STYLUS, "TOOL_TYPE_STYLUS");
1466 names.append(TOOL_TYPE_MOUSE, "TOOL_TYPE_MOUSE");
Jeff Brown49754db2011-07-01 17:37:58 -07001467 names.append(TOOL_TYPE_ERASER, "TOOL_TYPE_ERASER");
Jeff Brown6f2fba42011-02-19 01:08:02 -08001468 }
1469
Jeff Brown91c69ab2011-02-14 17:03:18 -08001470 // Private value for history pos that obtains the current sample.
Mathew Inwooda570dee2018-08-17 14:56:00 +01001471 @UnsupportedAppUsage
Jeff Brown91c69ab2011-02-14 17:03:18 -08001472 private static final int HISTORY_CURRENT = -0x80000000;
1473
Garfield Tan1da86282019-07-15 14:00:35 -07001474 // This is essentially the same as native AMOTION_EVENT_INVALID_CURSOR_POSITION as they're all
1475 // NaN and we use isnan() everywhere to check validity.
1476 private static final float INVALID_CURSOR_POSITION = Float.NaN;
1477
Jeff Brown1f245102010-11-18 20:53:46 -08001478 private static final int MAX_RECYCLED = 10;
1479 private static final Object gRecyclerLock = new Object();
1480 private static int gRecyclerUsed;
1481 private static MotionEvent gRecyclerTop;
Romain Guycafdea62009-06-12 10:51:36 -07001482
Jeff Brown91c69ab2011-02-14 17:03:18 -08001483 // Shared temporary objects used when translating coordinates supplied by
1484 // the caller into single element PointerCoords and pointer id arrays.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001485 private static final Object gSharedTempLock = new Object();
1486 private static PointerCoords[] gSharedTempPointerCoords;
1487 private static PointerProperties[] gSharedTempPointerProperties;
1488 private static int[] gSharedTempPointerIndexMap;
1489
1490 private static final void ensureSharedTempPointerCapacity(int desiredCapacity) {
1491 if (gSharedTempPointerCoords == null
1492 || gSharedTempPointerCoords.length < desiredCapacity) {
1493 int capacity = gSharedTempPointerCoords != null ? gSharedTempPointerCoords.length : 8;
1494 while (capacity < desiredCapacity) {
1495 capacity *= 2;
1496 }
1497 gSharedTempPointerCoords = PointerCoords.createArray(capacity);
1498 gSharedTempPointerProperties = PointerProperties.createArray(capacity);
1499 gSharedTempPointerIndexMap = new int[capacity];
1500 }
1501 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08001502
1503 // Pointer to the native MotionEvent object that contains the actual data.
George Mountbbc84a82019-02-08 09:58:45 -08001504 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
Ashok Bhat99a1ef22014-01-08 14:45:08 +00001505 private long mNativePtr;
Mitsuru Oshima8169dae2009-04-28 18:12:09 -07001506
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001507 private MotionEvent mNext;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001508
Ashok Bhat99a1ef22014-01-08 14:45:08 +00001509 private static native long nativeInitialize(long nativePtr,
Siarhei Vishniakou85ddfff2018-01-31 16:49:36 -08001510 int deviceId, int source, int displayId, int action, int flags, int edgeFlags,
Siarhei Vishniakoub05b0b52018-12-28 17:50:24 -08001511 int metaState, int buttonState, @Classification int classification,
Jeff Brown91c69ab2011-02-14 17:03:18 -08001512 float xOffset, float yOffset, float xPrecision, float yPrecision,
1513 long downTimeNanos, long eventTimeNanos,
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001514 int pointerCount, PointerProperties[] pointerIds, PointerCoords[] pointerCoords);
Ashok Bhat99a1ef22014-01-08 14:45:08 +00001515 private static native void nativeDispose(long nativePtr);
1516 private static native void nativeAddBatch(long nativePtr, long eventTimeNanos,
Jeff Brown91c69ab2011-02-14 17:03:18 -08001517 PointerCoords[] pointerCoords, int metaState);
Ashok Bhat99a1ef22014-01-08 14:45:08 +00001518 private static native void nativeGetPointerCoords(long nativePtr,
Jeff Brown91c69ab2011-02-14 17:03:18 -08001519 int pointerIndex, int historyPos, PointerCoords outPointerCoords);
Ashok Bhat99a1ef22014-01-08 14:45:08 +00001520 private static native void nativeGetPointerProperties(long nativePtr,
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001521 int pointerIndex, PointerProperties outPointerProperties);
Jeff Brown91c69ab2011-02-14 17:03:18 -08001522
Ashok Bhat99a1ef22014-01-08 14:45:08 +00001523 private static native long nativeReadFromParcel(long nativePtr, Parcel parcel);
1524 private static native void nativeWriteToParcel(long nativePtr, Parcel parcel);
Jeff Brown91c69ab2011-02-14 17:03:18 -08001525
Michael Wright337d9d22014-04-22 15:03:48 -07001526 private static native String nativeAxisToString(int axis);
1527 private static native int nativeAxisFromString(String label);
1528
John Reck09709972016-10-03 15:47:18 -07001529 // -------------- @FastNative -------------------------
1530
1531 @FastNative
1532 private static native int nativeGetPointerId(long nativePtr, int pointerIndex);
1533 @FastNative
1534 private static native int nativeGetToolType(long nativePtr, int pointerIndex);
1535 @FastNative
1536 private static native long nativeGetEventTimeNanos(long nativePtr, int historyPos);
1537 @FastNative
Mathew Inwooda570dee2018-08-17 14:56:00 +01001538 @UnsupportedAppUsage
John Reck09709972016-10-03 15:47:18 -07001539 private static native float nativeGetRawAxisValue(long nativePtr,
1540 int axis, int pointerIndex, int historyPos);
1541 @FastNative
1542 private static native float nativeGetAxisValue(long nativePtr,
1543 int axis, int pointerIndex, int historyPos);
Derek Sollenberger4dc0aae2019-12-27 15:15:18 -05001544 @FastNative
1545 private static native void nativeTransform(long nativePtr, Matrix matrix);
John Reck09709972016-10-03 15:47:18 -07001546
1547 // -------------- @CriticalNative ----------------------
1548
1549 @CriticalNative
1550 private static native long nativeCopy(long destNativePtr, long sourceNativePtr,
1551 boolean keepHistory);
1552 @CriticalNative
Garfield Tanc8362b22020-01-24 11:32:14 -08001553 private static native int nativeGetId(long nativePtr);
1554 @CriticalNative
John Reck09709972016-10-03 15:47:18 -07001555 private static native int nativeGetDeviceId(long nativePtr);
1556 @CriticalNative
1557 private static native int nativeGetSource(long nativePtr);
1558 @CriticalNative
Siarhei Vishniakou85ddfff2018-01-31 16:49:36 -08001559 private static native void nativeSetSource(long nativePtr, int source);
1560 @CriticalNative
1561 private static native int nativeGetDisplayId(long nativePtr);
1562 @CriticalNative
1563 private static native void nativeSetDisplayId(long nativePtr, int displayId);
John Reck09709972016-10-03 15:47:18 -07001564 @CriticalNative
1565 private static native int nativeGetAction(long nativePtr);
1566 @CriticalNative
1567 private static native void nativeSetAction(long nativePtr, int action);
1568 @CriticalNative
1569 private static native boolean nativeIsTouchEvent(long nativePtr);
1570 @CriticalNative
1571 private static native int nativeGetFlags(long nativePtr);
1572 @CriticalNative
1573 private static native void nativeSetFlags(long nativePtr, int flags);
1574 @CriticalNative
1575 private static native int nativeGetEdgeFlags(long nativePtr);
1576 @CriticalNative
1577 private static native void nativeSetEdgeFlags(long nativePtr, int action);
1578 @CriticalNative
1579 private static native int nativeGetMetaState(long nativePtr);
1580 @CriticalNative
1581 private static native int nativeGetButtonState(long nativePtr);
1582 @CriticalNative
1583 private static native void nativeSetButtonState(long nativePtr, int buttonState);
1584 @CriticalNative
Siarhei Vishniakoub05b0b52018-12-28 17:50:24 -08001585 private static native int nativeGetClassification(long nativePtr);
1586 @CriticalNative
John Reck09709972016-10-03 15:47:18 -07001587 private static native int nativeGetActionButton(long nativePtr);
1588 @CriticalNative
1589 private static native void nativeSetActionButton(long nativePtr, int actionButton);
1590 @CriticalNative
1591 private static native void nativeOffsetLocation(long nativePtr, float deltaX, float deltaY);
1592 @CriticalNative
1593 private static native float nativeGetXOffset(long nativePtr);
1594 @CriticalNative
1595 private static native float nativeGetYOffset(long nativePtr);
1596 @CriticalNative
1597 private static native float nativeGetXPrecision(long nativePtr);
1598 @CriticalNative
1599 private static native float nativeGetYPrecision(long nativePtr);
1600 @CriticalNative
Garfield Tan1da86282019-07-15 14:00:35 -07001601 private static native float nativeGetXCursorPosition(long nativePtr);
1602 @CriticalNative
1603 private static native float nativeGetYCursorPosition(long nativePtr);
1604 @CriticalNative
1605 private static native void nativeSetCursorPosition(long nativePtr, float x, float y);
1606 @CriticalNative
John Reck09709972016-10-03 15:47:18 -07001607 private static native long nativeGetDownTimeNanos(long nativePtr);
1608 @CriticalNative
1609 private static native void nativeSetDownTimeNanos(long nativePtr, long downTime);
1610
1611 @CriticalNative
1612 private static native int nativeGetPointerCount(long nativePtr);
1613 @CriticalNative
1614 private static native int nativeFindPointerIndex(long nativePtr, int pointerId);
1615
1616 @CriticalNative
1617 private static native int nativeGetHistorySize(long nativePtr);
1618
1619 @CriticalNative
1620 private static native void nativeScale(long nativePtr, float scale);
John Reck09709972016-10-03 15:47:18 -07001621
Jeff Brown91c69ab2011-02-14 17:03:18 -08001622 private MotionEvent() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001623 }
Romain Guycafdea62009-06-12 10:51:36 -07001624
Jeff Brown91c69ab2011-02-14 17:03:18 -08001625 @Override
1626 protected void finalize() throws Throwable {
1627 try {
1628 if (mNativePtr != 0) {
1629 nativeDispose(mNativePtr);
1630 mNativePtr = 0;
1631 }
1632 } finally {
1633 super.finalize();
1634 }
1635 }
1636
Mathew Inwooda570dee2018-08-17 14:56:00 +01001637 @UnsupportedAppUsage
Jeff Brown91c69ab2011-02-14 17:03:18 -08001638 static private MotionEvent obtain() {
Jeff Brown46b9ac02010-04-22 18:58:52 -07001639 final MotionEvent ev;
1640 synchronized (gRecyclerLock) {
Jeff Brown1f245102010-11-18 20:53:46 -08001641 ev = gRecyclerTop;
1642 if (ev == null) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001643 return new MotionEvent();
Jeff Brown46b9ac02010-04-22 18:58:52 -07001644 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07001645 gRecyclerTop = ev.mNext;
Jeff Brown5c225b12010-06-16 01:53:36 -07001646 gRecyclerUsed -= 1;
Jeff Brown46b9ac02010-04-22 18:58:52 -07001647 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07001648 ev.mNext = null;
Jeff Brown32cbc38552011-12-01 14:01:49 -08001649 ev.prepareForReuse();
Jeff Brown46b9ac02010-04-22 18:58:52 -07001650 return ev;
1651 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08001652
Michael Chan53071d62009-05-13 17:29:48 -07001653 /**
1654 * Create a new MotionEvent, filling in all of the basic values that
1655 * define the motion.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001656 *
Dennis Kempinac1b31d2016-11-02 17:02:25 -07001657 * @param downTime The time (in ms) when the user originally pressed down to start
Michael Chan53071d62009-05-13 17:29:48 -07001658 * a stream of position events. This must be obtained from {@link SystemClock#uptimeMillis()}.
Dennis Kempinac1b31d2016-11-02 17:02:25 -07001659 * @param eventTime The the time (in ms) when this specific event was generated. This
Michael Chan53071d62009-05-13 17:29:48 -07001660 * must be obtained from {@link SystemClock#uptimeMillis()}.
Jeff Browncc0c1592011-02-19 05:07:28 -08001661 * @param action The kind of action being performed, such as {@link #ACTION_DOWN}.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001662 * @param pointerCount The number of pointers that will be in this event.
1663 * @param pointerProperties An array of <em>pointerCount</em> values providing
1664 * a {@link PointerProperties} property object for each pointer, which must
1665 * include the pointer identifier.
1666 * @param pointerCoords An array of <em>pointerCount</em> values providing
1667 * a {@link PointerCoords} coordinate object for each pointer.
1668 * @param metaState The state of any meta / modifier keys that were in effect when
1669 * the event was generated.
1670 * @param buttonState The state of buttons that are pressed.
1671 * @param xPrecision The precision of the X coordinate being reported.
1672 * @param yPrecision The precision of the Y coordinate being reported.
1673 * @param deviceId The id for the device that this event came from. An id of
1674 * zero indicates that the event didn't come from a physical device; other
1675 * numbers are arbitrary and you shouldn't depend on the values.
1676 * @param edgeFlags A bitfield indicating which edges, if any, were touched by this
1677 * MotionEvent.
1678 * @param source The source of this event.
Siarhei Vishniakou85ddfff2018-01-31 16:49:36 -08001679 * @param displayId The display ID associated with this event.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001680 * @param flags The motion event flags.
Siarhei Vishniakou85ddfff2018-01-31 16:49:36 -08001681 * @hide
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001682 */
1683 static public MotionEvent obtain(long downTime, long eventTime,
1684 int action, int pointerCount, PointerProperties[] pointerProperties,
1685 PointerCoords[] pointerCoords, int metaState, int buttonState,
1686 float xPrecision, float yPrecision, int deviceId,
Siarhei Vishniakou85ddfff2018-01-31 16:49:36 -08001687 int edgeFlags, int source, int displayId, int flags) {
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001688 MotionEvent ev = obtain();
Garfield Tan1da86282019-07-15 14:00:35 -07001689 final boolean success = ev.initialize(deviceId, source, displayId, action, flags, edgeFlags,
1690 metaState, buttonState, CLASSIFICATION_NONE, 0, 0, xPrecision, yPrecision,
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001691 downTime * NS_PER_MS, eventTime * NS_PER_MS,
1692 pointerCount, pointerProperties, pointerCoords);
Garfield Tan1da86282019-07-15 14:00:35 -07001693 if (!success) {
Siarhei Vishniakou85ddfff2018-01-31 16:49:36 -08001694 Log.e(TAG, "Could not initialize MotionEvent");
1695 ev.recycle();
1696 return null;
1697 }
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001698 return ev;
1699 }
1700
1701 /**
1702 * Create a new MotionEvent, filling in all of the basic values that
1703 * define the motion.
Dennis Kempinac1b31d2016-11-02 17:02:25 -07001704 *
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001705 * @param downTime The time (in ms) when the user originally pressed down to start
1706 * a stream of position events. This must be obtained from {@link SystemClock#uptimeMillis()}.
1707 * @param eventTime The the time (in ms) when this specific event was generated. This
1708 * must be obtained from {@link SystemClock#uptimeMillis()}.
1709 * @param action The kind of action being performed, such as {@link #ACTION_DOWN}.
1710 * @param pointerCount The number of pointers that will be in this event.
Siarhei Vishniakou85ddfff2018-01-31 16:49:36 -08001711 * @param pointerProperties An array of <em>pointerCount</em> values providing
1712 * a {@link PointerProperties} property object for each pointer, which must
1713 * include the pointer identifier.
1714 * @param pointerCoords An array of <em>pointerCount</em> values providing
1715 * a {@link PointerCoords} coordinate object for each pointer.
1716 * @param metaState The state of any meta / modifier keys that were in effect when
1717 * the event was generated.
1718 * @param buttonState The state of buttons that are pressed.
1719 * @param xPrecision The precision of the X coordinate being reported.
1720 * @param yPrecision The precision of the Y coordinate being reported.
1721 * @param deviceId The id for the device that this event came from. An id of
1722 * zero indicates that the event didn't come from a physical device; other
1723 * numbers are arbitrary and you shouldn't depend on the values.
1724 * @param edgeFlags A bitfield indicating which edges, if any, were touched by this
1725 * MotionEvent.
1726 * @param source The source of this event.
1727 * @param flags The motion event flags.
1728 */
1729 public static MotionEvent obtain(long downTime, long eventTime,
1730 int action, int pointerCount, PointerProperties[] pointerProperties,
1731 PointerCoords[] pointerCoords, int metaState, int buttonState,
1732 float xPrecision, float yPrecision, int deviceId,
1733 int edgeFlags, int source, int flags) {
1734 return obtain(downTime, eventTime, action, pointerCount, pointerProperties, pointerCoords,
1735 metaState, buttonState, xPrecision, yPrecision, deviceId, edgeFlags, source,
1736 DEFAULT_DISPLAY, flags);
1737 }
1738
1739 /**
1740 * Create a new MotionEvent, filling in all of the basic values that
1741 * define the motion.
1742 *
1743 * @param downTime The time (in ms) when the user originally pressed down to start
1744 * a stream of position events. This must be obtained from {@link SystemClock#uptimeMillis()}.
1745 * @param eventTime The the time (in ms) when this specific event was generated. This
1746 * must be obtained from {@link SystemClock#uptimeMillis()}.
1747 * @param action The kind of action being performed, such as {@link #ACTION_DOWN}.
1748 * @param pointerCount The number of pointers that will be in this event.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001749 * @param pointerIds An array of <em>pointerCount</em> values providing
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001750 * an identifier for each pointer.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001751 * @param pointerCoords An array of <em>pointerCount</em> values providing
Jeff Brownc5ed5912010-07-14 18:48:53 -07001752 * a {@link PointerCoords} coordinate object for each pointer.
Michael Chan53071d62009-05-13 17:29:48 -07001753 * @param metaState The state of any meta / modifier keys that were in effect when
1754 * the event was generated.
1755 * @param xPrecision The precision of the X coordinate being reported.
1756 * @param yPrecision The precision of the Y coordinate being reported.
1757 * @param deviceId The id for the device that this event came from. An id of
1758 * zero indicates that the event didn't come from a physical device; other
1759 * numbers are arbitrary and you shouldn't depend on the values.
Jeff Brown85a31762010-09-01 17:01:00 -07001760 * @param edgeFlags A bitfield indicating which edges, if any, were touched by this
Michael Chan53071d62009-05-13 17:29:48 -07001761 * MotionEvent.
Jeff Brownc5ed5912010-07-14 18:48:53 -07001762 * @param source The source of this event.
Jeff Brown85a31762010-09-01 17:01:00 -07001763 * @param flags The motion event flags.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001764 *
1765 * @deprecated Use {@link #obtain(long, long, int, int, PointerProperties[], PointerCoords[], int, int, float, float, int, int, int, int)}
1766 * instead.
Michael Chan53071d62009-05-13 17:29:48 -07001767 */
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001768 @Deprecated
Jeff Brownc5ed5912010-07-14 18:48:53 -07001769 static public MotionEvent obtain(long downTime, long eventTime,
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001770 int action, int pointerCount, int[] pointerIds, PointerCoords[] pointerCoords,
Jeff Brownc5ed5912010-07-14 18:48:53 -07001771 int metaState, float xPrecision, float yPrecision, int deviceId,
Jeff Brown85a31762010-09-01 17:01:00 -07001772 int edgeFlags, int source, int flags) {
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001773 synchronized (gSharedTempLock) {
1774 ensureSharedTempPointerCapacity(pointerCount);
1775 final PointerProperties[] pp = gSharedTempPointerProperties;
1776 for (int i = 0; i < pointerCount; i++) {
1777 pp[i].clear();
1778 pp[i].id = pointerIds[i];
1779 }
1780 return obtain(downTime, eventTime, action, pointerCount, pp,
1781 pointerCoords, metaState, 0, xPrecision, yPrecision, deviceId,
1782 edgeFlags, source, flags);
1783 }
Michael Chan53071d62009-05-13 17:29:48 -07001784 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08001785
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001786 /**
1787 * Create a new MotionEvent, filling in all of the basic values that
1788 * define the motion.
Romain Guycafdea62009-06-12 10:51:36 -07001789 *
1790 * @param downTime The time (in ms) when the user originally pressed down to start
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001791 * a stream of position events. This must be obtained from {@link SystemClock#uptimeMillis()}.
Romain Guycafdea62009-06-12 10:51:36 -07001792 * @param eventTime The the time (in ms) when this specific event was generated. This
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001793 * must be obtained from {@link SystemClock#uptimeMillis()}.
Jeff Browncc0c1592011-02-19 05:07:28 -08001794 * @param action The kind of action being performed, such as {@link #ACTION_DOWN}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001795 * @param x The X coordinate of this event.
1796 * @param y The Y coordinate of this event.
Romain Guycafdea62009-06-12 10:51:36 -07001797 * @param pressure The current pressure of this event. The pressure generally
1798 * ranges from 0 (no pressure at all) to 1 (normal pressure), however
1799 * values higher than 1 may be generated depending on the calibration of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001800 * the input device.
1801 * @param size A scaled value of the approximate size of the area being pressed when
Romain Guycafdea62009-06-12 10:51:36 -07001802 * touched with the finger. The actual value in pixels corresponding to the finger
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001803 * touch is normalized with a device specific range of values
1804 * and scaled to a value between 0 and 1.
1805 * @param metaState The state of any meta / modifier keys that were in effect when
1806 * the event was generated.
1807 * @param xPrecision The precision of the X coordinate being reported.
1808 * @param yPrecision The precision of the Y coordinate being reported.
1809 * @param deviceId The id for the device that this event came from. An id of
1810 * zero indicates that the event didn't come from a physical device; other
1811 * numbers are arbitrary and you shouldn't depend on the values.
Jeff Brown85a31762010-09-01 17:01:00 -07001812 * @param edgeFlags A bitfield indicating which edges, if any, were touched by this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001813 * MotionEvent.
1814 */
1815 static public MotionEvent obtain(long downTime, long eventTime, int action,
1816 float x, float y, float pressure, float size, int metaState,
1817 float xPrecision, float yPrecision, int deviceId, int edgeFlags) {
Arthur Hung19b517a2018-09-14 18:24:31 +08001818 return obtain(downTime, eventTime, action, x, y, pressure, size, metaState,
1819 xPrecision, yPrecision, deviceId, edgeFlags, InputDevice.SOURCE_UNKNOWN,
1820 DEFAULT_DISPLAY);
1821 }
1822
1823 /**
1824 * Create a new MotionEvent, filling in all of the basic values that
1825 * define the motion.
1826 *
1827 * @param downTime The time (in ms) when the user originally pressed down to start
1828 * a stream of position events. This must be obtained from {@link SystemClock#uptimeMillis()}.
1829 * @param eventTime The the time (in ms) when this specific event was generated. This
1830 * must be obtained from {@link SystemClock#uptimeMillis()}.
1831 * @param action The kind of action being performed, such as {@link #ACTION_DOWN}.
1832 * @param x The X coordinate of this event.
1833 * @param y The Y coordinate of this event.
1834 * @param pressure The current pressure of this event. The pressure generally
1835 * ranges from 0 (no pressure at all) to 1 (normal pressure), however
1836 * values higher than 1 may be generated depending on the calibration of
1837 * the input device.
1838 * @param size A scaled value of the approximate size of the area being pressed when
1839 * touched with the finger. The actual value in pixels corresponding to the finger
1840 * touch is normalized with a device specific range of values
1841 * and scaled to a value between 0 and 1.
1842 * @param metaState The state of any meta / modifier keys that were in effect when
1843 * the event was generated.
1844 * @param xPrecision The precision of the X coordinate being reported.
1845 * @param yPrecision The precision of the Y coordinate being reported.
1846 * @param deviceId The id for the device that this event came from. An id of
1847 * zero indicates that the event didn't come from a physical device; other
1848 * numbers are arbitrary and you shouldn't depend on the values.
1849 * @param source The source of this event.
1850 * @param edgeFlags A bitfield indicating which edges, if any, were touched by this
1851 * MotionEvent.
1852 * @param displayId The display ID associated with this event.
1853 * @hide
1854 */
1855 public static MotionEvent obtain(long downTime, long eventTime, int action,
1856 float x, float y, float pressure, float size, int metaState,
1857 float xPrecision, float yPrecision, int deviceId, int edgeFlags, int source,
1858 int displayId) {
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001859 MotionEvent ev = obtain();
1860 synchronized (gSharedTempLock) {
1861 ensureSharedTempPointerCapacity(1);
1862 final PointerProperties[] pp = gSharedTempPointerProperties;
1863 pp[0].clear();
1864 pp[0].id = 0;
Jeff Brown91c69ab2011-02-14 17:03:18 -08001865
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001866 final PointerCoords pc[] = gSharedTempPointerCoords;
1867 pc[0].clear();
1868 pc[0].x = x;
1869 pc[0].y = y;
1870 pc[0].pressure = pressure;
1871 pc[0].size = size;
1872
Garfield Tan1da86282019-07-15 14:00:35 -07001873 ev.initialize(deviceId, source, displayId,
Siarhei Vishniakoub05b0b52018-12-28 17:50:24 -08001874 action, 0, edgeFlags, metaState, 0 /*buttonState*/, CLASSIFICATION_NONE,
Jeff Brown91c69ab2011-02-14 17:03:18 -08001875 0, 0, xPrecision, yPrecision,
1876 downTime * NS_PER_MS, eventTime * NS_PER_MS,
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001877 1, pp, pc);
Jeff Brown91c69ab2011-02-14 17:03:18 -08001878 return ev;
1879 }
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001880 }
1881
1882 /**
1883 * Create a new MotionEvent, filling in all of the basic values that
1884 * define the motion.
1885 *
1886 * @param downTime The time (in ms) when the user originally pressed down to start
1887 * a stream of position events. This must be obtained from {@link SystemClock#uptimeMillis()}.
1888 * @param eventTime The the time (in ms) when this specific event was generated. This
1889 * must be obtained from {@link SystemClock#uptimeMillis()}.
Jeff Browncc0c1592011-02-19 05:07:28 -08001890 * @param action The kind of action being performed, such as {@link #ACTION_DOWN}.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001891 * @param pointerCount The number of pointers that are active in this event.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001892 * @param x The X coordinate of this event.
1893 * @param y The Y coordinate of this event.
1894 * @param pressure The current pressure of this event. The pressure generally
1895 * ranges from 0 (no pressure at all) to 1 (normal pressure), however
1896 * values higher than 1 may be generated depending on the calibration of
1897 * the input device.
1898 * @param size A scaled value of the approximate size of the area being pressed when
1899 * touched with the finger. The actual value in pixels corresponding to the finger
1900 * touch is normalized with a device specific range of values
1901 * and scaled to a value between 0 and 1.
1902 * @param metaState The state of any meta / modifier keys that were in effect when
1903 * the event was generated.
1904 * @param xPrecision The precision of the X coordinate being reported.
1905 * @param yPrecision The precision of the Y coordinate being reported.
1906 * @param deviceId The id for the device that this event came from. An id of
1907 * zero indicates that the event didn't come from a physical device; other
1908 * numbers are arbitrary and you shouldn't depend on the values.
Jeff Brown85a31762010-09-01 17:01:00 -07001909 * @param edgeFlags A bitfield indicating which edges, if any, were touched by this
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001910 * MotionEvent.
Dennis Kempinac1b31d2016-11-02 17:02:25 -07001911 *
Jeff Brown5c225b12010-06-16 01:53:36 -07001912 * @deprecated Use {@link #obtain(long, long, int, float, float, float, float, int, float, float, int, int)}
1913 * instead.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001914 */
Jeff Brown5c225b12010-06-16 01:53:36 -07001915 @Deprecated
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001916 static public MotionEvent obtain(long downTime, long eventTime, int action,
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001917 int pointerCount, float x, float y, float pressure, float size, int metaState,
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001918 float xPrecision, float yPrecision, int deviceId, int edgeFlags) {
Jeff Brown5c225b12010-06-16 01:53:36 -07001919 return obtain(downTime, eventTime, action, x, y, pressure, size,
1920 metaState, xPrecision, yPrecision, deviceId, edgeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001921 }
Romain Guycafdea62009-06-12 10:51:36 -07001922
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001923 /**
1924 * Create a new MotionEvent, filling in a subset of the basic motion
1925 * values. Those not specified here are: device id (always 0), pressure
1926 * and size (always 1), x and y precision (always 1), and edgeFlags (always 0).
Romain Guycafdea62009-06-12 10:51:36 -07001927 *
1928 * @param downTime The time (in ms) when the user originally pressed down to start
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001929 * a stream of position events. This must be obtained from {@link SystemClock#uptimeMillis()}.
Romain Guycafdea62009-06-12 10:51:36 -07001930 * @param eventTime The the time (in ms) when this specific event was generated. This
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001931 * must be obtained from {@link SystemClock#uptimeMillis()}.
Jeff Browncc0c1592011-02-19 05:07:28 -08001932 * @param action The kind of action being performed, such as {@link #ACTION_DOWN}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001933 * @param x The X coordinate of this event.
1934 * @param y The Y coordinate of this event.
1935 * @param metaState The state of any meta / modifier keys that were in effect when
1936 * the event was generated.
1937 */
1938 static public MotionEvent obtain(long downTime, long eventTime, int action,
1939 float x, float y, int metaState) {
Jeff Brown5c225b12010-06-16 01:53:36 -07001940 return obtain(downTime, eventTime, action, x, y, 1.0f, 1.0f,
1941 metaState, 1.0f, 1.0f, 0, 0);
Mitsuru Oshima8169dae2009-04-28 18:12:09 -07001942 }
1943
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001944 /**
1945 * Create a new MotionEvent, copying from an existing one.
1946 */
Jeff Brown91c69ab2011-02-14 17:03:18 -08001947 static public MotionEvent obtain(MotionEvent other) {
1948 if (other == null) {
1949 throw new IllegalArgumentException("other motion event must not be null");
1950 }
1951
1952 MotionEvent ev = obtain();
1953 ev.mNativePtr = nativeCopy(ev.mNativePtr, other.mNativePtr, true /*keepHistory*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001954 return ev;
1955 }
Romain Guycafdea62009-06-12 10:51:36 -07001956
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001957 /**
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07001958 * Create a new MotionEvent, copying from an existing one, but not including
1959 * any historical point information.
1960 */
Jeff Brown91c69ab2011-02-14 17:03:18 -08001961 static public MotionEvent obtainNoHistory(MotionEvent other) {
1962 if (other == null) {
1963 throw new IllegalArgumentException("other motion event must not be null");
1964 }
1965
1966 MotionEvent ev = obtain();
1967 ev.mNativePtr = nativeCopy(ev.mNativePtr, other.mNativePtr, false /*keepHistory*/);
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07001968 return ev;
1969 }
1970
Garfield Tan1da86282019-07-15 14:00:35 -07001971 private boolean initialize(int deviceId, int source, int displayId, int action, int flags,
1972 int edgeFlags, int metaState, int buttonState, @Classification int classification,
1973 float xOffset, float yOffset, float xPrecision, float yPrecision,
1974 long downTimeNanos, long eventTimeNanos,
1975 int pointerCount, PointerProperties[] pointerIds, PointerCoords[] pointerCoords) {
1976 mNativePtr = nativeInitialize(mNativePtr, deviceId, source, displayId, action, flags,
1977 edgeFlags, metaState, buttonState, classification, xOffset, yOffset,
1978 xPrecision, yPrecision, downTimeNanos, eventTimeNanos, pointerCount, pointerIds,
1979 pointerCoords);
1980 if (mNativePtr == 0) {
1981 return false;
1982 }
1983 updateCursorPosition();
1984 return true;
1985 }
1986
Jeff Brown21bc5c92011-02-28 18:27:14 -08001987 /** @hide */
1988 @Override
Mathew Inwooda570dee2018-08-17 14:56:00 +01001989 @UnsupportedAppUsage
Jeff Brown21bc5c92011-02-28 18:27:14 -08001990 public MotionEvent copy() {
1991 return obtain(this);
1992 }
1993
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07001994 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001995 * Recycle the MotionEvent, to be re-used by a later caller. After calling
1996 * this function you must not ever touch the event again.
1997 */
Jeff Brown92cc2d82011-12-02 01:19:47 -08001998 @Override
Jeff Brown5c225b12010-06-16 01:53:36 -07001999 public final void recycle() {
Jeff Brown32cbc38552011-12-01 14:01:49 -08002000 super.recycle();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002001
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002002 synchronized (gRecyclerLock) {
2003 if (gRecyclerUsed < MAX_RECYCLED) {
2004 gRecyclerUsed++;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002005 mNext = gRecyclerTop;
2006 gRecyclerTop = this;
2007 }
2008 }
2009 }
Jeff Brown9ea77fc2012-03-21 19:49:27 -07002010
Jeff Brown5c225b12010-06-16 01:53:36 -07002011 /**
Jeff Brown9ea77fc2012-03-21 19:49:27 -07002012 * Applies a scale factor to all points within this event.
Jeff Brown5c225b12010-06-16 01:53:36 -07002013 *
Jeff Brown9ea77fc2012-03-21 19:49:27 -07002014 * This method is used to adjust touch events to simulate different density
2015 * displays for compatibility mode. The values returned by {@link #getRawX()},
2016 * {@link #getRawY()}, {@link #getXPrecision()} and {@link #getYPrecision()}
2017 * are also affected by the scale factor.
2018 *
2019 * @param scale The scale factor to apply.
Jeff Brown5c225b12010-06-16 01:53:36 -07002020 * @hide
2021 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01002022 @UnsupportedAppUsage
Jeff Brown5c225b12010-06-16 01:53:36 -07002023 public final void scale(float scale) {
Jeff Brown9ea77fc2012-03-21 19:49:27 -07002024 if (scale != 1.0f) {
2025 nativeScale(mNativePtr, scale);
2026 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08002027 }
2028
Garfield Tanc8362b22020-01-24 11:32:14 -08002029 /** @hide */
2030 @Override
2031 public int getId() {
2032 return nativeGetId(mNativePtr);
2033 }
2034
Jeff Brown91c69ab2011-02-14 17:03:18 -08002035 /** {@inheritDoc} */
2036 @Override
2037 public final int getDeviceId() {
2038 return nativeGetDeviceId(mNativePtr);
2039 }
2040
2041 /** {@inheritDoc} */
2042 @Override
2043 public final int getSource() {
2044 return nativeGetSource(mNativePtr);
2045 }
2046
2047 /** {@inheritDoc} */
2048 @Override
2049 public final void setSource(int source) {
Garfield Tan1da86282019-07-15 14:00:35 -07002050 if (source == getSource()) {
2051 return;
2052 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08002053 nativeSetSource(mNativePtr, source);
Garfield Tan1da86282019-07-15 14:00:35 -07002054 updateCursorPosition();
Jeff Brown5c225b12010-06-16 01:53:36 -07002055 }
Romain Guycafdea62009-06-12 10:51:36 -07002056
Siarhei Vishniakou85ddfff2018-01-31 16:49:36 -08002057 /** @hide */
Siarhei Vishniakou91fa08f2018-06-08 22:49:30 +01002058 @Override
Siarhei Vishniakou85ddfff2018-01-31 16:49:36 -08002059 public int getDisplayId() {
2060 return nativeGetDisplayId(mNativePtr);
2061 }
2062
2063 /** @hide */
lumark793e0562018-07-09 22:14:33 +08002064 @TestApi
Siarhei Vishniakou91fa08f2018-06-08 22:49:30 +01002065 @Override
Siarhei Vishniakou85ddfff2018-01-31 16:49:36 -08002066 public void setDisplayId(int displayId) {
2067 nativeSetDisplayId(mNativePtr, displayId);
2068 }
2069
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002070 /**
Jeff Browncc0c1592011-02-19 05:07:28 -08002071 * Return the kind of action being performed.
2072 * Consider using {@link #getActionMasked} and {@link #getActionIndex} to retrieve
2073 * the separate masked action and pointer index.
2074 * @return The action, such as {@link #ACTION_DOWN} or
2075 * the combination of {@link #ACTION_POINTER_DOWN} with a shifted pointer index.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002076 */
2077 public final int getAction() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002078 return nativeGetAction(mNativePtr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002079 }
2080
2081 /**
Jeff Browncc0c1592011-02-19 05:07:28 -08002082 * Return the masked action being performed, without pointer index information.
2083 * Use {@link #getActionIndex} to return the index associated with pointer actions.
2084 * @return The action, such as {@link #ACTION_DOWN} or {@link #ACTION_POINTER_DOWN}.
Dianne Hackbornb125dc52010-02-12 15:52:09 -08002085 */
2086 public final int getActionMasked() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002087 return nativeGetAction(mNativePtr) & ACTION_MASK;
Dianne Hackbornb125dc52010-02-12 15:52:09 -08002088 }
2089
2090 /**
2091 * For {@link #ACTION_POINTER_DOWN} or {@link #ACTION_POINTER_UP}
2092 * as returned by {@link #getActionMasked}, this returns the associated
Jeff Browncc0c1592011-02-19 05:07:28 -08002093 * pointer index.
2094 * The index may be used with {@link #getPointerId(int)},
Dianne Hackbornb125dc52010-02-12 15:52:09 -08002095 * {@link #getX(int)}, {@link #getY(int)}, {@link #getPressure(int)},
2096 * and {@link #getSize(int)} to get information about the pointer that has
2097 * gone down or up.
Jeff Browncc0c1592011-02-19 05:07:28 -08002098 * @return The index associated with the action.
Dianne Hackbornb125dc52010-02-12 15:52:09 -08002099 */
2100 public final int getActionIndex() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002101 return (nativeGetAction(mNativePtr) & ACTION_POINTER_INDEX_MASK)
2102 >> ACTION_POINTER_INDEX_SHIFT;
Dianne Hackbornb125dc52010-02-12 15:52:09 -08002103 }
2104
2105 /**
Jeff Brown33bbfd22011-02-24 20:55:35 -08002106 * Returns true if this motion event is a touch event.
2107 * <p>
Jeff Browna032cc02011-03-07 16:56:21 -08002108 * Specifically excludes pointer events with action {@link #ACTION_HOVER_MOVE},
2109 * {@link #ACTION_HOVER_ENTER}, {@link #ACTION_HOVER_EXIT}, or {@link #ACTION_SCROLL}
2110 * because they are not actually touch events (the pointer is not down).
Jeff Brown33bbfd22011-02-24 20:55:35 -08002111 * </p>
2112 * @return True if this motion event is a touch event.
2113 * @hide
2114 */
2115 public final boolean isTouchEvent() {
Jeff Brown56194eb2011-03-02 19:23:13 -08002116 return nativeIsTouchEvent(mNativePtr);
Jeff Brown33bbfd22011-02-24 20:55:35 -08002117 }
2118
2119 /**
Jeff Brown85a31762010-09-01 17:01:00 -07002120 * Gets the motion event flags.
2121 *
2122 * @see #FLAG_WINDOW_IS_OBSCURED
2123 */
2124 public final int getFlags() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002125 return nativeGetFlags(mNativePtr);
Jeff Brown85a31762010-09-01 17:01:00 -07002126 }
2127
Jeff Brown21bc5c92011-02-28 18:27:14 -08002128 /** @hide */
2129 @Override
2130 public final boolean isTainted() {
2131 final int flags = getFlags();
2132 return (flags & FLAG_TAINTED) != 0;
2133 }
2134
2135 /** @hide */
2136 @Override
2137 public final void setTainted(boolean tainted) {
2138 final int flags = getFlags();
2139 nativeSetFlags(mNativePtr, tainted ? flags | FLAG_TAINTED : flags & ~FLAG_TAINTED);
2140 }
2141
Svetoslavded133c2015-01-30 20:28:41 -08002142 /** @hide */
Vladislav Kaznacheev5a77c372016-10-10 16:11:15 -07002143 public final boolean isHoverExitPending() {
2144 final int flags = getFlags();
2145 return (flags & FLAG_HOVER_EXIT_PENDING) != 0;
2146 }
2147
2148 /** @hide */
2149 public void setHoverExitPending(boolean hoverExitPending) {
2150 final int flags = getFlags();
2151 nativeSetFlags(mNativePtr, hoverExitPending
2152 ? flags | FLAG_HOVER_EXIT_PENDING
2153 : flags & ~FLAG_HOVER_EXIT_PENDING);
2154 }
2155
Jeff Brown85a31762010-09-01 17:01:00 -07002156 /**
Romain Guycafdea62009-06-12 10:51:36 -07002157 * Returns the time (in ms) when the user originally pressed down to start
2158 * a stream of position events.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002159 */
2160 public final long getDownTime() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002161 return nativeGetDownTimeNanos(mNativePtr) / NS_PER_MS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002162 }
2163
2164 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07002165 * Sets the time (in ms) when the user originally pressed down to start
2166 * a stream of position events.
2167 *
2168 * @hide
2169 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01002170 @UnsupportedAppUsage
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07002171 public final void setDownTime(long downTime) {
2172 nativeSetDownTimeNanos(mNativePtr, downTime * NS_PER_MS);
2173 }
2174
2175 /**
Jeff Brownb11499d2012-04-20 19:54:22 -07002176 * Retrieve the time this event occurred,
2177 * in the {@link android.os.SystemClock#uptimeMillis} time base.
2178 *
2179 * @return Returns the time this event occurred,
2180 * in the {@link android.os.SystemClock#uptimeMillis} time base.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002181 */
Jeff Brownb11499d2012-04-20 19:54:22 -07002182 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002183 public final long getEventTime() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002184 return nativeGetEventTimeNanos(mNativePtr, HISTORY_CURRENT) / NS_PER_MS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002185 }
2186
2187 /**
Jeff Brownb11499d2012-04-20 19:54:22 -07002188 * Retrieve the time this event occurred,
2189 * in the {@link android.os.SystemClock#uptimeMillis} time base but with
2190 * nanosecond precision.
2191 * <p>
Michael Chan53071d62009-05-13 17:29:48 -07002192 * The value is in nanosecond precision but it may not have nanosecond accuracy.
Jeff Brownb11499d2012-04-20 19:54:22 -07002193 * </p>
2194 *
2195 * @return Returns the time this event occurred,
2196 * in the {@link android.os.SystemClock#uptimeMillis} time base but with
2197 * nanosecond precision.
Michael Chan53071d62009-05-13 17:29:48 -07002198 *
2199 * @hide
2200 */
Jeff Brownb11499d2012-04-20 19:54:22 -07002201 @Override
Mathew Inwooda570dee2018-08-17 14:56:00 +01002202 @UnsupportedAppUsage
Michael Chan53071d62009-05-13 17:29:48 -07002203 public final long getEventTimeNano() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002204 return nativeGetEventTimeNanos(mNativePtr, HISTORY_CURRENT);
Michael Chan53071d62009-05-13 17:29:48 -07002205 }
2206
2207 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002208 * {@link #getX(int)} for the first pointer index (may be an
2209 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002210 *
2211 * @see #AXIS_X
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002212 */
2213 public final float getX() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002214 return nativeGetAxisValue(mNativePtr, AXIS_X, 0, HISTORY_CURRENT);
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002215 }
2216
2217 /**
2218 * {@link #getY(int)} for the first pointer index (may be an
2219 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002220 *
2221 * @see #AXIS_Y
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002222 */
2223 public final float getY() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002224 return nativeGetAxisValue(mNativePtr, AXIS_Y, 0, HISTORY_CURRENT);
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002225 }
2226
2227 /**
2228 * {@link #getPressure(int)} for the first pointer index (may be an
2229 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002230 *
2231 * @see #AXIS_PRESSURE
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002232 */
2233 public final float getPressure() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002234 return nativeGetAxisValue(mNativePtr, AXIS_PRESSURE, 0, HISTORY_CURRENT);
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002235 }
2236
2237 /**
2238 * {@link #getSize(int)} for the first pointer index (may be an
2239 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002240 *
2241 * @see #AXIS_SIZE
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002242 */
2243 public final float getSize() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002244 return nativeGetAxisValue(mNativePtr, AXIS_SIZE, 0, HISTORY_CURRENT);
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002245 }
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002246
Jeff Brownc5ed5912010-07-14 18:48:53 -07002247 /**
2248 * {@link #getTouchMajor(int)} for the first pointer index (may be an
2249 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002250 *
2251 * @see #AXIS_TOUCH_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002252 */
2253 public final float getTouchMajor() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002254 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MAJOR, 0, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002255 }
2256
2257 /**
2258 * {@link #getTouchMinor(int)} for the first pointer index (may be an
2259 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002260 *
2261 * @see #AXIS_TOUCH_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002262 */
2263 public final float getTouchMinor() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002264 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MINOR, 0, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002265 }
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002266
Jeff Brownc5ed5912010-07-14 18:48:53 -07002267 /**
2268 * {@link #getToolMajor(int)} for the first pointer index (may be an
2269 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002270 *
2271 * @see #AXIS_TOOL_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002272 */
2273 public final float getToolMajor() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002274 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MAJOR, 0, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002275 }
2276
2277 /**
2278 * {@link #getToolMinor(int)} for the first pointer index (may be an
2279 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002280 *
2281 * @see #AXIS_TOOL_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002282 */
2283 public final float getToolMinor() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002284 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MINOR, 0, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002285 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08002286
Jeff Brownc5ed5912010-07-14 18:48:53 -07002287 /**
2288 * {@link #getOrientation(int)} for the first pointer index (may be an
2289 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002290 *
2291 * @see #AXIS_ORIENTATION
Jeff Brownc5ed5912010-07-14 18:48:53 -07002292 */
2293 public final float getOrientation() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002294 return nativeGetAxisValue(mNativePtr, AXIS_ORIENTATION, 0, HISTORY_CURRENT);
2295 }
2296
2297 /**
2298 * {@link #getAxisValue(int)} for the first pointer index (may be an
2299 * arbitrary pointer identifier).
2300 *
2301 * @param axis The axis identifier for the axis value to retrieve.
2302 *
2303 * @see #AXIS_X
2304 * @see #AXIS_Y
2305 */
2306 public final float getAxisValue(int axis) {
2307 return nativeGetAxisValue(mNativePtr, axis, 0, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002308 }
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002309
2310 /**
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002311 * The number of pointers of data contained in this event. Always
2312 * >= 1.
2313 */
2314 public final int getPointerCount() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002315 return nativeGetPointerCount(mNativePtr);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002316 }
John Reck09709972016-10-03 15:47:18 -07002317
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002318 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002319 * Return the pointer identifier associated with a particular pointer
Trevor Johns682c24e2016-04-12 10:13:47 -07002320 * data index in this event. The identifier tells you the actual pointer
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002321 * number associated with the data, accounting for individual pointers
2322 * going up and down since the start of the current gesture.
2323 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2324 * (the first pointer that is down) to {@link #getPointerCount()}-1.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002325 */
Dianne Hackbornd41ba662009-08-05 15:30:56 -07002326 public final int getPointerId(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002327 return nativeGetPointerId(mNativePtr, pointerIndex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002328 }
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07002329
2330 /**
2331 * Gets the tool type of a pointer for the given pointer index.
2332 * The tool type indicates the type of tool used to make contact such
2333 * as a finger or stylus, if known.
2334 *
2335 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2336 * (the first pointer that is down) to {@link #getPointerCount()}-1.
2337 * @return The tool type of the pointer.
2338 *
2339 * @see #TOOL_TYPE_UNKNOWN
2340 * @see #TOOL_TYPE_FINGER
2341 * @see #TOOL_TYPE_STYLUS
2342 * @see #TOOL_TYPE_MOUSE
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07002343 */
2344 public final int getToolType(int pointerIndex) {
2345 return nativeGetToolType(mNativePtr, pointerIndex);
2346 }
2347
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002348 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002349 * Given a pointer identifier, find the index of its data in the event.
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002350 *
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002351 * @param pointerId The identifier of the pointer to be found.
2352 * @return Returns either the index of the pointer (for use with
Gilles Debunneb0d6ba12010-08-17 20:01:42 -07002353 * {@link #getX(int)} et al.), or -1 if there is no data available for
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002354 * that pointer identifier.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002355 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002356 public final int findPointerIndex(int pointerId) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002357 return nativeFindPointerIndex(mNativePtr, pointerId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002358 }
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07002359
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002360 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002361 * Returns the X coordinate of this event for the given pointer
2362 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
2363 * identifier for this index).
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002364 * Whole numbers are pixels; the
2365 * value may have a fraction for input devices that are sub-pixel precise.
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002366 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2367 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002368 *
2369 * @see #AXIS_X
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002370 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002371 public final float getX(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002372 return nativeGetAxisValue(mNativePtr, AXIS_X, pointerIndex, HISTORY_CURRENT);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002373 }
2374
2375 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002376 * Returns the Y coordinate of this event for the given pointer
2377 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
2378 * identifier for this index).
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002379 * Whole numbers are pixels; the
2380 * value may have a fraction for input devices that are sub-pixel precise.
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002381 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2382 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002383 *
2384 * @see #AXIS_Y
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002385 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002386 public final float getY(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002387 return nativeGetAxisValue(mNativePtr, AXIS_Y, pointerIndex, HISTORY_CURRENT);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002388 }
2389
2390 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002391 * Returns the current pressure of this event for the given pointer
2392 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
2393 * identifier for this index).
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002394 * The pressure generally
Romain Guycafdea62009-06-12 10:51:36 -07002395 * ranges from 0 (no pressure at all) to 1 (normal pressure), however
2396 * values higher than 1 may be generated depending on the calibration of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002397 * the input device.
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002398 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2399 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002400 *
2401 * @see #AXIS_PRESSURE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002402 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002403 public final float getPressure(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002404 return nativeGetAxisValue(mNativePtr, AXIS_PRESSURE, pointerIndex, HISTORY_CURRENT);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002405 }
2406
2407 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002408 * Returns a scaled value of the approximate size for the given pointer
2409 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
2410 * identifier for this index).
2411 * This represents some approximation of the area of the screen being
2412 * pressed; the actual value in pixels corresponding to the
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002413 * touch is normalized with the device specific range of values
Romain Guycafdea62009-06-12 10:51:36 -07002414 * 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 -08002415 * determine fat touch events.
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002416 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2417 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002418 *
2419 * @see #AXIS_SIZE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002420 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002421 public final float getSize(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002422 return nativeGetAxisValue(mNativePtr, AXIS_SIZE, pointerIndex, HISTORY_CURRENT);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002423 }
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002424
Jeff Brownc5ed5912010-07-14 18:48:53 -07002425 /**
2426 * Returns the length of the major axis of an ellipse that describes the touch
2427 * area at the point of contact for the given pointer
2428 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
2429 * identifier for this index).
2430 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2431 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002432 *
2433 * @see #AXIS_TOUCH_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002434 */
2435 public final float getTouchMajor(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002436 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MAJOR, pointerIndex, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002437 }
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002438
Jeff Brownc5ed5912010-07-14 18:48:53 -07002439 /**
2440 * Returns the length of the minor axis of an ellipse that describes the touch
2441 * area at the point of contact for the given pointer
2442 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
2443 * identifier for this index).
2444 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2445 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002446 *
2447 * @see #AXIS_TOUCH_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002448 */
2449 public final float getTouchMinor(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002450 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MINOR, pointerIndex, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002451 }
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002452
Jeff Brownc5ed5912010-07-14 18:48:53 -07002453 /**
2454 * Returns the length of the major axis of an ellipse that describes the size of
2455 * the approaching tool for the given pointer
2456 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
2457 * identifier for this index).
2458 * The tool area represents the estimated size of the finger or pen that is
2459 * touching the device independent of its actual touch area at the point of contact.
2460 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2461 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002462 *
2463 * @see #AXIS_TOOL_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002464 */
2465 public final float getToolMajor(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002466 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MAJOR, pointerIndex, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002467 }
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002468
Jeff Brownc5ed5912010-07-14 18:48:53 -07002469 /**
2470 * Returns the length of the minor axis of an ellipse that describes the size of
2471 * the approaching tool for the given pointer
2472 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
2473 * identifier for this index).
2474 * The tool area represents the estimated size of the finger or pen that is
2475 * touching the device independent of its actual touch area at the point of contact.
2476 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2477 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002478 *
2479 * @see #AXIS_TOOL_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002480 */
2481 public final float getToolMinor(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002482 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MINOR, pointerIndex, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002483 }
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002484
Jeff Brownc5ed5912010-07-14 18:48:53 -07002485 /**
2486 * Returns the orientation of the touch area and tool area in radians clockwise from vertical
2487 * for the given pointer <em>index</em> (use {@link #getPointerId(int)} to find the pointer
2488 * identifier for this index).
Jeff Brown6f2fba42011-02-19 01:08:02 -08002489 * An angle of 0 radians indicates that the major axis of contact is oriented
Jeff Brownc5ed5912010-07-14 18:48:53 -07002490 * upwards, is perfectly circular or is of unknown orientation. A positive angle
2491 * indicates that the major axis of contact is oriented to the right. A negative angle
2492 * indicates that the major axis of contact is oriented to the left.
Jeff Brown6d0fec22010-07-23 21:28:06 -07002493 * The full range is from -PI/2 radians (finger pointing fully left) to PI/2 radians
Jeff Brownc5ed5912010-07-14 18:48:53 -07002494 * (finger pointing fully right).
2495 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2496 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002497 *
2498 * @see #AXIS_ORIENTATION
Jeff Brownc5ed5912010-07-14 18:48:53 -07002499 */
2500 public final float getOrientation(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002501 return nativeGetAxisValue(mNativePtr, AXIS_ORIENTATION, pointerIndex, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002502 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08002503
2504 /**
2505 * Returns the value of the requested axis for the given pointer <em>index</em>
2506 * (use {@link #getPointerId(int)} to find the pointer identifier for this index).
2507 *
2508 * @param axis The axis identifier for the axis value to retrieve.
2509 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2510 * (the first pointer that is down) to {@link #getPointerCount()}-1.
2511 * @return The value of the axis, or 0 if the axis is not available.
2512 *
2513 * @see #AXIS_X
2514 * @see #AXIS_Y
2515 */
2516 public final float getAxisValue(int axis, int pointerIndex) {
2517 return nativeGetAxisValue(mNativePtr, axis, pointerIndex, HISTORY_CURRENT);
2518 }
2519
Jeff Brownc5ed5912010-07-14 18:48:53 -07002520 /**
2521 * Populates a {@link PointerCoords} object with pointer coordinate data for
2522 * the specified pointer index.
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002523 *
Jeff Brownc5ed5912010-07-14 18:48:53 -07002524 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2525 * (the first pointer that is down) to {@link #getPointerCount()}-1.
2526 * @param outPointerCoords The pointer coordinate object to populate.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002527 *
2528 * @see PointerCoords
Jeff Brownc5ed5912010-07-14 18:48:53 -07002529 */
2530 public final void getPointerCoords(int pointerIndex, PointerCoords outPointerCoords) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002531 nativeGetPointerCoords(mNativePtr, pointerIndex, HISTORY_CURRENT, outPointerCoords);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002532 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002533
2534 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07002535 * Populates a {@link PointerProperties} object with pointer properties for
2536 * the specified pointer index.
2537 *
2538 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2539 * (the first pointer that is down) to {@link #getPointerCount()}-1.
2540 * @param outPointerProperties The pointer properties object to populate.
2541 *
2542 * @see PointerProperties
2543 */
2544 public final void getPointerProperties(int pointerIndex,
2545 PointerProperties outPointerProperties) {
2546 nativeGetPointerProperties(mNativePtr, pointerIndex, outPointerProperties);
2547 }
2548
2549 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002550 * Returns the state of any meta / modifier keys that were in effect when
2551 * the event was generated. This is the same values as those
2552 * returned by {@link KeyEvent#getMetaState() KeyEvent.getMetaState}.
2553 *
2554 * @return an integer in which each bit set to 1 represents a pressed
2555 * meta key
2556 *
2557 * @see KeyEvent#getMetaState()
2558 */
2559 public final int getMetaState() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002560 return nativeGetMetaState(mNativePtr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002561 }
2562
2563 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07002564 * Gets the state of all buttons that are pressed such as a mouse or stylus button.
2565 *
2566 * @return The button state.
2567 *
2568 * @see #BUTTON_PRIMARY
2569 * @see #BUTTON_SECONDARY
2570 * @see #BUTTON_TERTIARY
2571 * @see #BUTTON_FORWARD
2572 * @see #BUTTON_BACK
Michael Wright5bd69e62015-05-14 14:48:08 +01002573 * @see #BUTTON_STYLUS_PRIMARY
2574 * @see #BUTTON_STYLUS_SECONDARY
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07002575 */
2576 public final int getButtonState() {
2577 return nativeGetButtonState(mNativePtr);
2578 }
2579
2580 /**
Michael Wright5bd69e62015-05-14 14:48:08 +01002581 * Sets the bitfield indicating which buttons are pressed.
2582 *
2583 * @see #getButtonState()
2584 * @hide
2585 */
Kirill Grouchnikovb2a44f02016-09-14 16:24:44 -07002586 @TestApi
Michael Wright5bd69e62015-05-14 14:48:08 +01002587 public final void setButtonState(int buttonState) {
2588 nativeSetButtonState(mNativePtr, buttonState);
2589 }
2590
2591 /**
Siarhei Vishniakoub05b0b52018-12-28 17:50:24 -08002592 * Returns the classification for the current gesture.
2593 * The classification may change as more events become available for the same gesture.
2594 *
2595 * @see #CLASSIFICATION_NONE
2596 * @see #CLASSIFICATION_AMBIGUOUS_GESTURE
2597 * @see #CLASSIFICATION_DEEP_PRESS
2598 */
2599 public @Classification int getClassification() {
2600 return nativeGetClassification(mNativePtr);
2601 }
2602
2603 /**
Michael Wright5bd69e62015-05-14 14:48:08 +01002604 * Gets which button has been modified during a press or release action.
2605 *
2606 * For actions other than {@link #ACTION_BUTTON_PRESS} and {@link #ACTION_BUTTON_RELEASE}
2607 * the returned value is undefined.
2608 *
2609 * @see #getButtonState()
2610 */
2611 public final int getActionButton() {
2612 return nativeGetActionButton(mNativePtr);
2613 }
2614
2615 /**
Michael Wright6b819b42015-06-17 21:06:03 +01002616 * Sets the action button for the event.
2617 *
2618 * @see #getActionButton()
2619 * @hide
2620 */
Artur Satayevf0b7d0b2019-11-04 11:16:45 +00002621 @UnsupportedAppUsage
Kirill Grouchnikovc0b0ba52016-09-13 16:09:37 -07002622 @TestApi
Michael Wright6b819b42015-06-17 21:06:03 +01002623 public final void setActionButton(int button) {
2624 nativeSetActionButton(mNativePtr, button);
2625 }
2626
2627 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002628 * Returns the original raw X coordinate of this event. For touch
2629 * events on the screen, this is the original location of the event
2630 * on the screen, before it had been adjusted for the containing window
2631 * and views.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002632 *
Michael Wright072137c2013-04-24 20:41:20 -07002633 * @see #getX(int)
Jeff Brown91c69ab2011-02-14 17:03:18 -08002634 * @see #AXIS_X
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002635 */
2636 public final float getRawX() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002637 return nativeGetRawAxisValue(mNativePtr, AXIS_X, 0, HISTORY_CURRENT);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002638 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08002639
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002640 /**
2641 * Returns the original raw Y coordinate of this event. For touch
2642 * events on the screen, this is the original location of the event
2643 * on the screen, before it had been adjusted for the containing window
2644 * and views.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002645 *
Michael Wright072137c2013-04-24 20:41:20 -07002646 * @see #getY(int)
Jeff Brown91c69ab2011-02-14 17:03:18 -08002647 * @see #AXIS_Y
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002648 */
2649 public final float getRawY() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002650 return nativeGetRawAxisValue(mNativePtr, AXIS_Y, 0, HISTORY_CURRENT);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002651 }
2652
2653 /**
Vishnu Nair18999552018-12-13 09:28:11 -08002654 * Returns the original raw X coordinate of this event. For touch
2655 * events on the screen, this is the original location of the event
2656 * on the screen, before it had been adjusted for the containing window
2657 * and views.
2658 *
2659 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2660 * (the first pointer that is down) to {@link #getPointerCount()}-1.
2661 *
2662 * @see #getX(int)
2663 * @see #AXIS_X
2664 */
2665 public float getRawX(int pointerIndex) {
2666 return nativeGetRawAxisValue(mNativePtr, AXIS_X, pointerIndex, HISTORY_CURRENT);
2667 }
2668
2669 /**
2670 * Returns the original raw Y coordinate of this event. For touch
2671 * events on the screen, this is the original location of the event
2672 * on the screen, before it had been adjusted for the containing window
2673 * and views.
2674 *
2675 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2676 * (the first pointer that is down) to {@link #getPointerCount()}-1.
2677 *
2678 * @see #getY(int)
2679 * @see #AXIS_Y
2680 */
2681 public float getRawY(int pointerIndex) {
2682 return nativeGetRawAxisValue(mNativePtr, AXIS_Y, pointerIndex, HISTORY_CURRENT);
2683 }
2684
2685 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002686 * Return the precision of the X coordinates being reported. You can
Jeff Brown91c69ab2011-02-14 17:03:18 -08002687 * multiply this number with {@link #getX} to find the actual hardware
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002688 * value of the X coordinate.
2689 * @return Returns the precision of X coordinates being reported.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002690 *
2691 * @see #AXIS_X
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002692 */
2693 public final float getXPrecision() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002694 return nativeGetXPrecision(mNativePtr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002695 }
Romain Guycafdea62009-06-12 10:51:36 -07002696
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002697 /**
2698 * Return the precision of the Y coordinates being reported. You can
Jeff Brown91c69ab2011-02-14 17:03:18 -08002699 * multiply this number with {@link #getY} to find the actual hardware
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002700 * value of the Y coordinate.
2701 * @return Returns the precision of Y coordinates being reported.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002702 *
2703 * @see #AXIS_Y
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002704 */
2705 public final float getYPrecision() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002706 return nativeGetYPrecision(mNativePtr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002707 }
Romain Guycafdea62009-06-12 10:51:36 -07002708
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002709 /**
Garfield Tan1da86282019-07-15 14:00:35 -07002710 * Returns the x coordinate of mouse cursor position when this event is
2711 * reported. This value is only valid if {@link #getSource()} returns
2712 * {@link InputDevice#SOURCE_MOUSE}.
2713 *
2714 * @hide
2715 */
2716 public float getXCursorPosition() {
2717 return nativeGetXCursorPosition(mNativePtr);
2718 }
2719
2720 /**
2721 * Returns the y coordinate of mouse cursor position when this event is
2722 * reported. This value is only valid if {@link #getSource()} returns
2723 * {@link InputDevice#SOURCE_MOUSE}.
2724 *
2725 * @hide
2726 */
2727 public float getYCursorPosition() {
2728 return nativeGetYCursorPosition(mNativePtr);
2729 }
2730
2731 /**
2732 * Sets cursor position to given coordinates. The coordinate in parameters should be after
2733 * offsetting. In other words, the effect of this function is {@link #getXCursorPosition()} and
2734 * {@link #getYCursorPosition()} will return the same value passed in the parameters.
2735 *
2736 * @hide
2737 */
2738 private void setCursorPosition(float x, float y) {
2739 nativeSetCursorPosition(mNativePtr, x, y);
2740 }
2741
2742 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002743 * Returns the number of historical points in this event. These are
2744 * movements that have occurred between this event and the previous event.
2745 * This only applies to ACTION_MOVE events -- all other actions will have
2746 * a size of 0.
Romain Guycafdea62009-06-12 10:51:36 -07002747 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002748 * @return Returns the number of historical points in the event.
2749 */
2750 public final int getHistorySize() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002751 return nativeGetHistorySize(mNativePtr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002752 }
Romain Guycafdea62009-06-12 10:51:36 -07002753
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002754 /**
2755 * Returns the time that a historical movement occurred between this event
Jeff Brownb11499d2012-04-20 19:54:22 -07002756 * and the previous event, in the {@link android.os.SystemClock#uptimeMillis} time base.
2757 * <p>
2758 * This only applies to ACTION_MOVE events.
2759 * </p>
Romain Guycafdea62009-06-12 10:51:36 -07002760 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002761 * @param pos Which historical value to return; must be less than
2762 * {@link #getHistorySize}
Jeff Brownb11499d2012-04-20 19:54:22 -07002763 * @return Returns the time that a historical movement occurred between this
2764 * event and the previous event,
2765 * in the {@link android.os.SystemClock#uptimeMillis} time base.
Romain Guycafdea62009-06-12 10:51:36 -07002766 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002767 * @see #getHistorySize
2768 * @see #getEventTime
2769 */
2770 public final long getHistoricalEventTime(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002771 return nativeGetEventTimeNanos(mNativePtr, pos) / NS_PER_MS;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002772 }
2773
2774 /**
Jeff Brownb11499d2012-04-20 19:54:22 -07002775 * Returns the time that a historical movement occurred between this event
2776 * and the previous event, in the {@link android.os.SystemClock#uptimeMillis} time base
2777 * but with nanosecond (instead of millisecond) precision.
2778 * <p>
2779 * This only applies to ACTION_MOVE events.
2780 * </p><p>
2781 * The value is in nanosecond precision but it may not have nanosecond accuracy.
2782 * </p>
2783 *
2784 * @param pos Which historical value to return; must be less than
2785 * {@link #getHistorySize}
2786 * @return Returns the time that a historical movement occurred between this
2787 * event and the previous event,
2788 * in the {@link android.os.SystemClock#uptimeMillis} time base but with
2789 * nanosecond (instead of millisecond) precision.
2790 *
2791 * @see #getHistorySize
2792 * @see #getEventTime
2793 *
2794 * @hide
2795 */
2796 public final long getHistoricalEventTimeNano(int pos) {
2797 return nativeGetEventTimeNanos(mNativePtr, pos);
2798 }
2799
2800 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08002801 * {@link #getHistoricalX(int, int)} for the first pointer index (may be an
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002802 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002803 *
2804 * @param pos Which historical value to return; must be less than
2805 * {@link #getHistorySize}
2806 *
2807 * @see #getHistorySize
2808 * @see #getX()
2809 * @see #AXIS_X
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002810 */
2811 public final float getHistoricalX(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002812 return nativeGetAxisValue(mNativePtr, AXIS_X, 0, pos);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002813 }
2814
2815 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08002816 * {@link #getHistoricalY(int, int)} for the first pointer index (may be an
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002817 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002818 *
2819 * @param pos Which historical value to return; must be less than
2820 * {@link #getHistorySize}
2821 *
2822 * @see #getHistorySize
2823 * @see #getY()
2824 * @see #AXIS_Y
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002825 */
2826 public final float getHistoricalY(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002827 return nativeGetAxisValue(mNativePtr, AXIS_Y, 0, pos);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002828 }
2829
2830 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08002831 * {@link #getHistoricalPressure(int, int)} for the first pointer index (may be an
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002832 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002833 *
2834 * @param pos Which historical value to return; must be less than
2835 * {@link #getHistorySize}
2836 *
2837 * @see #getHistorySize
2838 * @see #getPressure()
2839 * @see #AXIS_PRESSURE
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002840 */
2841 public final float getHistoricalPressure(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002842 return nativeGetAxisValue(mNativePtr, AXIS_PRESSURE, 0, pos);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002843 }
2844
2845 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08002846 * {@link #getHistoricalSize(int, int)} for the first pointer index (may be an
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002847 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002848 *
2849 * @param pos Which historical value to return; must be less than
2850 * {@link #getHistorySize}
2851 *
2852 * @see #getHistorySize
2853 * @see #getSize()
2854 * @see #AXIS_SIZE
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002855 */
2856 public final float getHistoricalSize(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002857 return nativeGetAxisValue(mNativePtr, AXIS_SIZE, 0, pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002858 }
Romain Guycafdea62009-06-12 10:51:36 -07002859
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002860 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08002861 * {@link #getHistoricalTouchMajor(int, int)} for the first pointer index (may be an
Jeff Brownc5ed5912010-07-14 18:48:53 -07002862 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002863 *
2864 * @param pos Which historical value to return; must be less than
2865 * {@link #getHistorySize}
2866 *
2867 * @see #getHistorySize
2868 * @see #getTouchMajor()
2869 * @see #AXIS_TOUCH_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002870 */
2871 public final float getHistoricalTouchMajor(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002872 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MAJOR, 0, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002873 }
2874
2875 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08002876 * {@link #getHistoricalTouchMinor(int, int)} for the first pointer index (may be an
Jeff Brownc5ed5912010-07-14 18:48:53 -07002877 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002878 *
2879 * @param pos Which historical value to return; must be less than
2880 * {@link #getHistorySize}
2881 *
2882 * @see #getHistorySize
2883 * @see #getTouchMinor()
2884 * @see #AXIS_TOUCH_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002885 */
2886 public final float getHistoricalTouchMinor(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002887 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MINOR, 0, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002888 }
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002889
Jeff Brownc5ed5912010-07-14 18:48:53 -07002890 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08002891 * {@link #getHistoricalToolMajor(int, int)} for the first pointer index (may be an
Jeff Brownc5ed5912010-07-14 18:48:53 -07002892 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002893 *
2894 * @param pos Which historical value to return; must be less than
2895 * {@link #getHistorySize}
2896 *
2897 * @see #getHistorySize
2898 * @see #getToolMajor()
2899 * @see #AXIS_TOOL_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002900 */
2901 public final float getHistoricalToolMajor(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002902 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MAJOR, 0, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002903 }
2904
2905 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08002906 * {@link #getHistoricalToolMinor(int, int)} for the first pointer index (may be an
Jeff Brownc5ed5912010-07-14 18:48:53 -07002907 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002908 *
2909 * @param pos Which historical value to return; must be less than
2910 * {@link #getHistorySize}
2911 *
2912 * @see #getHistorySize
2913 * @see #getToolMinor()
2914 * @see #AXIS_TOOL_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002915 */
2916 public final float getHistoricalToolMinor(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002917 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MINOR, 0, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002918 }
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002919
Jeff Brownc5ed5912010-07-14 18:48:53 -07002920 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08002921 * {@link #getHistoricalOrientation(int, int)} for the first pointer index (may be an
Jeff Brownc5ed5912010-07-14 18:48:53 -07002922 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002923 *
2924 * @param pos Which historical value to return; must be less than
2925 * {@link #getHistorySize}
2926 *
2927 * @see #getHistorySize
2928 * @see #getOrientation()
2929 * @see #AXIS_ORIENTATION
Jeff Brownc5ed5912010-07-14 18:48:53 -07002930 */
2931 public final float getHistoricalOrientation(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002932 return nativeGetAxisValue(mNativePtr, AXIS_ORIENTATION, 0, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002933 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08002934
2935 /**
2936 * {@link #getHistoricalAxisValue(int, int, int)} for the first pointer index (may be an
2937 * arbitrary pointer identifier).
2938 *
2939 * @param axis The axis identifier for the axis value to retrieve.
2940 * @param pos Which historical value to return; must be less than
2941 * {@link #getHistorySize}
2942 *
2943 * @see #getHistorySize
2944 * @see #getAxisValue(int)
2945 * @see #AXIS_X
2946 * @see #AXIS_Y
2947 */
2948 public final float getHistoricalAxisValue(int axis, int pos) {
2949 return nativeGetAxisValue(mNativePtr, axis, 0, pos);
2950 }
2951
Jeff Brownc5ed5912010-07-14 18:48:53 -07002952 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002953 * Returns a historical X coordinate, as per {@link #getX(int)}, that
2954 * occurred between this event and the previous event for the given pointer.
2955 * Only applies to ACTION_MOVE events.
Romain Guycafdea62009-06-12 10:51:36 -07002956 *
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002957 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2958 * (the first pointer that is down) to {@link #getPointerCount()}-1.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002959 * @param pos Which historical value to return; must be less than
2960 * {@link #getHistorySize}
Romain Guycafdea62009-06-12 10:51:36 -07002961 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002962 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08002963 * @see #getX(int)
2964 * @see #AXIS_X
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002965 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002966 public final float getHistoricalX(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002967 return nativeGetAxisValue(mNativePtr, AXIS_X, pointerIndex, pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002968 }
Romain Guycafdea62009-06-12 10:51:36 -07002969
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002970 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002971 * Returns a historical Y coordinate, as per {@link #getY(int)}, that
2972 * occurred between this event and the previous event for the given pointer.
2973 * Only applies to ACTION_MOVE events.
Romain Guycafdea62009-06-12 10:51:36 -07002974 *
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002975 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2976 * (the first pointer that is down) to {@link #getPointerCount()}-1.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002977 * @param pos Which historical value to return; must be less than
2978 * {@link #getHistorySize}
Romain Guycafdea62009-06-12 10:51:36 -07002979 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002980 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08002981 * @see #getY(int)
2982 * @see #AXIS_Y
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002983 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002984 public final float getHistoricalY(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002985 return nativeGetAxisValue(mNativePtr, AXIS_Y, pointerIndex, pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002986 }
Romain Guycafdea62009-06-12 10:51:36 -07002987
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002988 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002989 * Returns a historical pressure coordinate, as per {@link #getPressure(int)},
2990 * that occurred between this event and the previous event for the given
2991 * pointer. Only applies to ACTION_MOVE events.
Romain Guycafdea62009-06-12 10:51:36 -07002992 *
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002993 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2994 * (the first pointer that is down) to {@link #getPointerCount()}-1.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002995 * @param pos Which historical value to return; must be less than
2996 * {@link #getHistorySize}
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002997 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002998 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08002999 * @see #getPressure(int)
3000 * @see #AXIS_PRESSURE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003001 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07003002 public final float getHistoricalPressure(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08003003 return nativeGetAxisValue(mNativePtr, AXIS_PRESSURE, pointerIndex, pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003004 }
Romain Guycafdea62009-06-12 10:51:36 -07003005
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003006 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07003007 * Returns a historical size coordinate, as per {@link #getSize(int)}, that
3008 * occurred between this event and the previous event for the given pointer.
3009 * Only applies to ACTION_MOVE events.
Romain Guycafdea62009-06-12 10:51:36 -07003010 *
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07003011 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
3012 * (the first pointer that is down) to {@link #getPointerCount()}-1.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003013 * @param pos Which historical value to return; must be less than
3014 * {@link #getHistorySize}
Dennis Kempinac1b31d2016-11-02 17:02:25 -07003015 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003016 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08003017 * @see #getSize(int)
3018 * @see #AXIS_SIZE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003019 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07003020 public final float getHistoricalSize(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08003021 return nativeGetAxisValue(mNativePtr, AXIS_SIZE, pointerIndex, pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003022 }
Dennis Kempinac1b31d2016-11-02 17:02:25 -07003023
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003024 /**
Jeff Brownc5ed5912010-07-14 18:48:53 -07003025 * Returns a historical touch major axis coordinate, as per {@link #getTouchMajor(int)}, that
3026 * occurred between this event and the previous event for the given pointer.
3027 * Only applies to ACTION_MOVE events.
3028 *
3029 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
3030 * (the first pointer that is down) to {@link #getPointerCount()}-1.
3031 * @param pos Which historical value to return; must be less than
3032 * {@link #getHistorySize}
Dennis Kempinac1b31d2016-11-02 17:02:25 -07003033 *
Jeff Brownc5ed5912010-07-14 18:48:53 -07003034 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08003035 * @see #getTouchMajor(int)
3036 * @see #AXIS_TOUCH_MAJOR
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003037 */
Jeff Brownc5ed5912010-07-14 18:48:53 -07003038 public final float getHistoricalTouchMajor(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08003039 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MAJOR, pointerIndex, pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003040 }
Romain Guycafdea62009-06-12 10:51:36 -07003041
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003042 /**
Jeff Brownc5ed5912010-07-14 18:48:53 -07003043 * Returns a historical touch minor axis coordinate, as per {@link #getTouchMinor(int)}, that
3044 * occurred between this event and the previous event for the given pointer.
3045 * Only applies to ACTION_MOVE events.
3046 *
3047 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
3048 * (the first pointer that is down) to {@link #getPointerCount()}-1.
3049 * @param pos Which historical value to return; must be less than
3050 * {@link #getHistorySize}
Dennis Kempinac1b31d2016-11-02 17:02:25 -07003051 *
Jeff Brownc5ed5912010-07-14 18:48:53 -07003052 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08003053 * @see #getTouchMinor(int)
3054 * @see #AXIS_TOUCH_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07003055 */
3056 public final float getHistoricalTouchMinor(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08003057 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MINOR, pointerIndex, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07003058 }
3059
3060 /**
3061 * Returns a historical tool major axis coordinate, as per {@link #getToolMajor(int)}, that
3062 * occurred between this event and the previous event for the given pointer.
3063 * Only applies to ACTION_MOVE events.
3064 *
3065 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
3066 * (the first pointer that is down) to {@link #getPointerCount()}-1.
3067 * @param pos Which historical value to return; must be less than
3068 * {@link #getHistorySize}
Dennis Kempinac1b31d2016-11-02 17:02:25 -07003069 *
Jeff Brownc5ed5912010-07-14 18:48:53 -07003070 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08003071 * @see #getToolMajor(int)
3072 * @see #AXIS_TOOL_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07003073 */
3074 public final float getHistoricalToolMajor(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08003075 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MAJOR, pointerIndex, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07003076 }
3077
3078 /**
3079 * Returns a historical tool minor axis coordinate, as per {@link #getToolMinor(int)}, that
3080 * occurred between this event and the previous event for the given pointer.
3081 * Only applies to ACTION_MOVE events.
3082 *
3083 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
3084 * (the first pointer that is down) to {@link #getPointerCount()}-1.
3085 * @param pos Which historical value to return; must be less than
3086 * {@link #getHistorySize}
Dennis Kempinac1b31d2016-11-02 17:02:25 -07003087 *
Jeff Brownc5ed5912010-07-14 18:48:53 -07003088 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08003089 * @see #getToolMinor(int)
3090 * @see #AXIS_TOOL_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07003091 */
3092 public final float getHistoricalToolMinor(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08003093 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MINOR, pointerIndex, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07003094 }
3095
3096 /**
3097 * Returns a historical orientation coordinate, as per {@link #getOrientation(int)}, that
3098 * occurred between this event and the previous event for the given pointer.
3099 * Only applies to ACTION_MOVE events.
3100 *
3101 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
3102 * (the first pointer that is down) to {@link #getPointerCount()}-1.
3103 * @param pos Which historical value to return; must be less than
3104 * {@link #getHistorySize}
Dennis Kempinac1b31d2016-11-02 17:02:25 -07003105 *
Jeff Brownc5ed5912010-07-14 18:48:53 -07003106 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08003107 * @see #getOrientation(int)
3108 * @see #AXIS_ORIENTATION
Jeff Brownc5ed5912010-07-14 18:48:53 -07003109 */
3110 public final float getHistoricalOrientation(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08003111 return nativeGetAxisValue(mNativePtr, AXIS_ORIENTATION, pointerIndex, pos);
3112 }
3113
3114 /**
3115 * Returns the historical value of the requested axis, as per {@link #getAxisValue(int, int)},
3116 * occurred between this event and the previous event for the given pointer.
3117 * Only applies to ACTION_MOVE events.
3118 *
3119 * @param axis The axis identifier for the axis value to retrieve.
3120 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
3121 * (the first pointer that is down) to {@link #getPointerCount()}-1.
3122 * @param pos Which historical value to return; must be less than
3123 * {@link #getHistorySize}
3124 * @return The value of the axis, or 0 if the axis is not available.
3125 *
3126 * @see #AXIS_X
3127 * @see #AXIS_Y
3128 */
3129 public final float getHistoricalAxisValue(int axis, int pointerIndex, int pos) {
3130 return nativeGetAxisValue(mNativePtr, axis, pointerIndex, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07003131 }
3132
3133 /**
3134 * Populates a {@link PointerCoords} object with historical pointer coordinate data,
3135 * as per {@link #getPointerCoords}, that occurred between this event and the previous
3136 * event for the given pointer.
3137 * Only applies to ACTION_MOVE events.
Dennis Kempinac1b31d2016-11-02 17:02:25 -07003138 *
Jeff Brownc5ed5912010-07-14 18:48:53 -07003139 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
3140 * (the first pointer that is down) to {@link #getPointerCount()}-1.
3141 * @param pos Which historical value to return; must be less than
3142 * {@link #getHistorySize}
3143 * @param outPointerCoords The pointer coordinate object to populate.
Dennis Kempinac1b31d2016-11-02 17:02:25 -07003144 *
Jeff Brownc5ed5912010-07-14 18:48:53 -07003145 * @see #getHistorySize
3146 * @see #getPointerCoords
Jeff Brown91c69ab2011-02-14 17:03:18 -08003147 * @see PointerCoords
Jeff Brownc5ed5912010-07-14 18:48:53 -07003148 */
3149 public final void getHistoricalPointerCoords(int pointerIndex, int pos,
3150 PointerCoords outPointerCoords) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08003151 nativeGetPointerCoords(mNativePtr, pointerIndex, pos, outPointerCoords);
Jeff Brownc5ed5912010-07-14 18:48:53 -07003152 }
Dennis Kempinac1b31d2016-11-02 17:02:25 -07003153
Jeff Brownc5ed5912010-07-14 18:48:53 -07003154 /**
Jeff Brown46b9ac02010-04-22 18:58:52 -07003155 * Returns a bitfield indicating which edges, if any, were touched by this
Romain Guycafdea62009-06-12 10:51:36 -07003156 * MotionEvent. For touch events, clients can use this to determine if the
3157 * user's finger was touching the edge of the display.
3158 *
Jeff Brownd41cff22011-03-03 02:09:54 -08003159 * This property is only set for {@link #ACTION_DOWN} events.
3160 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003161 * @see #EDGE_LEFT
3162 * @see #EDGE_TOP
3163 * @see #EDGE_RIGHT
3164 * @see #EDGE_BOTTOM
3165 */
3166 public final int getEdgeFlags() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08003167 return nativeGetEdgeFlags(mNativePtr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003168 }
Romain Guycafdea62009-06-12 10:51:36 -07003169
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003170 /**
Jeff Brown85a31762010-09-01 17:01:00 -07003171 * Sets the bitfield indicating which edges, if any, were touched by this
Romain Guycafdea62009-06-12 10:51:36 -07003172 * MotionEvent.
3173 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003174 * @see #getEdgeFlags()
3175 */
3176 public final void setEdgeFlags(int flags) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08003177 nativeSetEdgeFlags(mNativePtr, flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003178 }
3179
3180 /**
3181 * Sets this event's action.
3182 */
3183 public final void setAction(int action) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08003184 nativeSetAction(mNativePtr, action);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003185 }
3186
3187 /**
3188 * Adjust this event's location.
3189 * @param deltaX Amount to add to the current X coordinate of the event.
3190 * @param deltaY Amount to add to the current Y coordinate of the event.
3191 */
3192 public final void offsetLocation(float deltaX, float deltaY) {
Jeff Brown9ea77fc2012-03-21 19:49:27 -07003193 if (deltaX != 0.0f || deltaY != 0.0f) {
3194 nativeOffsetLocation(mNativePtr, deltaX, deltaY);
3195 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003196 }
Romain Guycafdea62009-06-12 10:51:36 -07003197
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003198 /**
3199 * Set this event's location. Applies {@link #offsetLocation} with a
3200 * delta from the current location to the given new location.
Romain Guycafdea62009-06-12 10:51:36 -07003201 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003202 * @param x New absolute X location.
3203 * @param y New absolute Y location.
3204 */
3205 public final void setLocation(float x, float y) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08003206 float oldX = getX();
3207 float oldY = getY();
Jeff Brown9ea77fc2012-03-21 19:49:27 -07003208 offsetLocation(x - oldX, y - oldY);
Jeff Brown5c225b12010-06-16 01:53:36 -07003209 }
Dennis Kempinac1b31d2016-11-02 17:02:25 -07003210
Jeff Brown20e987b2010-08-23 12:01:02 -07003211 /**
3212 * Applies a transformation matrix to all of the points in the event.
3213 *
3214 * @param matrix The transformation matrix to apply.
3215 */
3216 public final void transform(Matrix matrix) {
3217 if (matrix == null) {
3218 throw new IllegalArgumentException("matrix must not be null");
3219 }
3220
Derek Sollenberger4dc0aae2019-12-27 15:15:18 -05003221 nativeTransform(mNativePtr, matrix);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003222 }
Romain Guycafdea62009-06-12 10:51:36 -07003223
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003224 /**
3225 * Add a new movement to the batch of movements in this event. The event's
Jeff Brownc5ed5912010-07-14 18:48:53 -07003226 * current location, position and size is updated to the new values.
3227 * The current values in the event are added to a list of historical values.
Jeff Brown91c69ab2011-02-14 17:03:18 -08003228 *
Jeff Browncc0c1592011-02-19 05:07:28 -08003229 * Only applies to {@link #ACTION_MOVE} or {@link #ACTION_HOVER_MOVE} events.
Romain Guycafdea62009-06-12 10:51:36 -07003230 *
Jeff Brownc5ed5912010-07-14 18:48:53 -07003231 * @param eventTime The time stamp (in ms) for this data.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003232 * @param x The new X position.
3233 * @param y The new Y position.
3234 * @param pressure The new pressure.
3235 * @param size The new size.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07003236 * @param metaState Meta key state.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003237 */
3238 public final void addBatch(long eventTime, float x, float y,
3239 float pressure, float size, int metaState) {
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003240 synchronized (gSharedTempLock) {
3241 ensureSharedTempPointerCapacity(1);
3242 final PointerCoords[] pc = gSharedTempPointerCoords;
3243 pc[0].clear();
3244 pc[0].x = x;
3245 pc[0].y = y;
3246 pc[0].pressure = pressure;
3247 pc[0].size = size;
3248
3249 nativeAddBatch(mNativePtr, eventTime * NS_PER_MS, pc, metaState);
Jeff Brown91c69ab2011-02-14 17:03:18 -08003250 }
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07003251 }
Romain Guycafdea62009-06-12 10:51:36 -07003252
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07003253 /**
Jeff Brownc5ed5912010-07-14 18:48:53 -07003254 * Add a new movement to the batch of movements in this event. The event's
3255 * current location, position and size is updated to the new values.
3256 * The current values in the event are added to a list of historical values.
Jeff Brown91c69ab2011-02-14 17:03:18 -08003257 *
Jeff Browncc0c1592011-02-19 05:07:28 -08003258 * Only applies to {@link #ACTION_MOVE} or {@link #ACTION_HOVER_MOVE} events.
Jeff Brownc5ed5912010-07-14 18:48:53 -07003259 *
3260 * @param eventTime The time stamp (in ms) for this data.
3261 * @param pointerCoords The new pointer coordinates.
3262 * @param metaState Meta key state.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07003263 */
Jeff Brownc5ed5912010-07-14 18:48:53 -07003264 public final void addBatch(long eventTime, PointerCoords[] pointerCoords, int metaState) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08003265 nativeAddBatch(mNativePtr, eventTime * NS_PER_MS, pointerCoords, metaState);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003266 }
Romain Guycafdea62009-06-12 10:51:36 -07003267
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003268 /**
Jeff Brown9d3bdbd2012-03-21 11:50:06 -07003269 * Adds all of the movement samples of the specified event to this one if
3270 * it is compatible. To be compatible, the event must have the same device id,
Siarhei Vishniakoub05b0b52018-12-28 17:50:24 -08003271 * source, display id, action, flags, classification, pointer count, pointer properties.
Jeff Brown9d3bdbd2012-03-21 11:50:06 -07003272 *
3273 * Only applies to {@link #ACTION_MOVE} or {@link #ACTION_HOVER_MOVE} events.
3274 *
3275 * @param event The event whose movements samples should be added to this one
3276 * if possible.
3277 * @return True if batching was performed or false if batching was not possible.
3278 * @hide
3279 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01003280 @UnsupportedAppUsage
Jeff Brown9d3bdbd2012-03-21 11:50:06 -07003281 public final boolean addBatch(MotionEvent event) {
3282 final int action = nativeGetAction(mNativePtr);
3283 if (action != ACTION_MOVE && action != ACTION_HOVER_MOVE) {
3284 return false;
3285 }
3286 if (action != nativeGetAction(event.mNativePtr)) {
3287 return false;
3288 }
3289
3290 if (nativeGetDeviceId(mNativePtr) != nativeGetDeviceId(event.mNativePtr)
3291 || nativeGetSource(mNativePtr) != nativeGetSource(event.mNativePtr)
Siarhei Vishniakou85ddfff2018-01-31 16:49:36 -08003292 || nativeGetDisplayId(mNativePtr) != nativeGetDisplayId(event.mNativePtr)
Siarhei Vishniakoub05b0b52018-12-28 17:50:24 -08003293 || nativeGetFlags(mNativePtr) != nativeGetFlags(event.mNativePtr)
3294 || nativeGetClassification(mNativePtr)
3295 != nativeGetClassification(event.mNativePtr)) {
Jeff Brown9d3bdbd2012-03-21 11:50:06 -07003296 return false;
3297 }
3298
3299 final int pointerCount = nativeGetPointerCount(mNativePtr);
3300 if (pointerCount != nativeGetPointerCount(event.mNativePtr)) {
3301 return false;
3302 }
3303
3304 synchronized (gSharedTempLock) {
3305 ensureSharedTempPointerCapacity(Math.max(pointerCount, 2));
3306 final PointerProperties[] pp = gSharedTempPointerProperties;
3307 final PointerCoords[] pc = gSharedTempPointerCoords;
3308
3309 for (int i = 0; i < pointerCount; i++) {
3310 nativeGetPointerProperties(mNativePtr, i, pp[0]);
3311 nativeGetPointerProperties(event.mNativePtr, i, pp[1]);
3312 if (!pp[0].equals(pp[1])) {
3313 return false;
3314 }
3315 }
3316
3317 final int metaState = nativeGetMetaState(event.mNativePtr);
3318 final int historySize = nativeGetHistorySize(event.mNativePtr);
3319 for (int h = 0; h <= historySize; h++) {
3320 final int historyPos = (h == historySize ? HISTORY_CURRENT : h);
3321
3322 for (int i = 0; i < pointerCount; i++) {
3323 nativeGetPointerCoords(event.mNativePtr, i, historyPos, pc[i]);
3324 }
3325
3326 final long eventTimeNanos = nativeGetEventTimeNanos(event.mNativePtr, historyPos);
3327 nativeAddBatch(mNativePtr, eventTimeNanos, pc, metaState);
3328 }
3329 }
3330 return true;
3331 }
3332
3333 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003334 * Returns true if all points in the motion event are completely within the specified bounds.
3335 * @hide
3336 */
3337 public final boolean isWithinBoundsNoHistory(float left, float top,
3338 float right, float bottom) {
3339 final int pointerCount = nativeGetPointerCount(mNativePtr);
3340 for (int i = 0; i < pointerCount; i++) {
3341 final float x = nativeGetAxisValue(mNativePtr, AXIS_X, i, HISTORY_CURRENT);
3342 final float y = nativeGetAxisValue(mNativePtr, AXIS_Y, i, HISTORY_CURRENT);
3343 if (x < left || x > right || y < top || y > bottom) {
3344 return false;
3345 }
3346 }
3347 return true;
3348 }
3349
3350 private static final float clamp(float value, float low, float high) {
3351 if (value < low) {
3352 return low;
3353 } else if (value > high) {
3354 return high;
3355 }
3356 return value;
3357 }
3358
3359 /**
3360 * Returns a new motion events whose points have been clamped to the specified bounds.
3361 * @hide
3362 */
3363 public final MotionEvent clampNoHistory(float left, float top, float right, float bottom) {
3364 MotionEvent ev = obtain();
3365 synchronized (gSharedTempLock) {
3366 final int pointerCount = nativeGetPointerCount(mNativePtr);
3367
3368 ensureSharedTempPointerCapacity(pointerCount);
3369 final PointerProperties[] pp = gSharedTempPointerProperties;
3370 final PointerCoords[] pc = gSharedTempPointerCoords;
3371
3372 for (int i = 0; i < pointerCount; i++) {
3373 nativeGetPointerProperties(mNativePtr, i, pp[i]);
3374 nativeGetPointerCoords(mNativePtr, i, HISTORY_CURRENT, pc[i]);
3375 pc[i].x = clamp(pc[i].x, left, right);
3376 pc[i].y = clamp(pc[i].y, top, bottom);
3377 }
Garfield Tan1da86282019-07-15 14:00:35 -07003378 ev.initialize(nativeGetDeviceId(mNativePtr), nativeGetSource(mNativePtr),
Siarhei Vishniakou85ddfff2018-01-31 16:49:36 -08003379 nativeGetDisplayId(mNativePtr),
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003380 nativeGetAction(mNativePtr), nativeGetFlags(mNativePtr),
3381 nativeGetEdgeFlags(mNativePtr), nativeGetMetaState(mNativePtr),
Siarhei Vishniakoub05b0b52018-12-28 17:50:24 -08003382 nativeGetButtonState(mNativePtr), nativeGetClassification(mNativePtr),
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003383 nativeGetXOffset(mNativePtr), nativeGetYOffset(mNativePtr),
3384 nativeGetXPrecision(mNativePtr), nativeGetYPrecision(mNativePtr),
3385 nativeGetDownTimeNanos(mNativePtr),
3386 nativeGetEventTimeNanos(mNativePtr, HISTORY_CURRENT),
3387 pointerCount, pp, pc);
3388 return ev;
3389 }
3390 }
3391
3392 /**
3393 * Gets an integer where each pointer id present in the event is marked as a bit.
3394 * @hide
3395 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01003396 @UnsupportedAppUsage
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003397 public final int getPointerIdBits() {
3398 int idBits = 0;
3399 final int pointerCount = nativeGetPointerCount(mNativePtr);
3400 for (int i = 0; i < pointerCount; i++) {
3401 idBits |= 1 << nativeGetPointerId(mNativePtr, i);
3402 }
3403 return idBits;
3404 }
3405
3406 /**
3407 * Splits a motion event such that it includes only a subset of pointer ids.
3408 * @hide
3409 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01003410 @UnsupportedAppUsage
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003411 public final MotionEvent split(int idBits) {
3412 MotionEvent ev = obtain();
3413 synchronized (gSharedTempLock) {
3414 final int oldPointerCount = nativeGetPointerCount(mNativePtr);
3415 ensureSharedTempPointerCapacity(oldPointerCount);
3416 final PointerProperties[] pp = gSharedTempPointerProperties;
3417 final PointerCoords[] pc = gSharedTempPointerCoords;
3418 final int[] map = gSharedTempPointerIndexMap;
3419
3420 final int oldAction = nativeGetAction(mNativePtr);
3421 final int oldActionMasked = oldAction & ACTION_MASK;
3422 final int oldActionPointerIndex = (oldAction & ACTION_POINTER_INDEX_MASK)
3423 >> ACTION_POINTER_INDEX_SHIFT;
3424 int newActionPointerIndex = -1;
3425 int newPointerCount = 0;
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003426 for (int i = 0; i < oldPointerCount; i++) {
3427 nativeGetPointerProperties(mNativePtr, i, pp[newPointerCount]);
3428 final int idBit = 1 << pp[newPointerCount].id;
3429 if ((idBit & idBits) != 0) {
3430 if (i == oldActionPointerIndex) {
3431 newActionPointerIndex = newPointerCount;
3432 }
3433 map[newPointerCount] = i;
3434 newPointerCount += 1;
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003435 }
3436 }
3437
3438 if (newPointerCount == 0) {
3439 throw new IllegalArgumentException("idBits did not match any ids in the event");
3440 }
3441
3442 final int newAction;
3443 if (oldActionMasked == ACTION_POINTER_DOWN || oldActionMasked == ACTION_POINTER_UP) {
3444 if (newActionPointerIndex < 0) {
3445 // An unrelated pointer changed.
3446 newAction = ACTION_MOVE;
3447 } else if (newPointerCount == 1) {
3448 // The first/last pointer went down/up.
3449 newAction = oldActionMasked == ACTION_POINTER_DOWN
3450 ? ACTION_DOWN : ACTION_UP;
3451 } else {
3452 // A secondary pointer went down/up.
3453 newAction = oldActionMasked
3454 | (newActionPointerIndex << ACTION_POINTER_INDEX_SHIFT);
3455 }
3456 } else {
3457 // Simple up/down/cancel/move or other motion action.
3458 newAction = oldAction;
3459 }
3460
3461 final int historySize = nativeGetHistorySize(mNativePtr);
3462 for (int h = 0; h <= historySize; h++) {
3463 final int historyPos = h == historySize ? HISTORY_CURRENT : h;
3464
3465 for (int i = 0; i < newPointerCount; i++) {
3466 nativeGetPointerCoords(mNativePtr, map[i], historyPos, pc[i]);
3467 }
3468
3469 final long eventTimeNanos = nativeGetEventTimeNanos(mNativePtr, historyPos);
3470 if (h == 0) {
Garfield Tan1da86282019-07-15 14:00:35 -07003471 ev.initialize(nativeGetDeviceId(mNativePtr), nativeGetSource(mNativePtr),
Siarhei Vishniakou85ddfff2018-01-31 16:49:36 -08003472 nativeGetDisplayId(mNativePtr),
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003473 newAction, nativeGetFlags(mNativePtr),
3474 nativeGetEdgeFlags(mNativePtr), nativeGetMetaState(mNativePtr),
Siarhei Vishniakoub05b0b52018-12-28 17:50:24 -08003475 nativeGetButtonState(mNativePtr), nativeGetClassification(mNativePtr),
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003476 nativeGetXOffset(mNativePtr), nativeGetYOffset(mNativePtr),
3477 nativeGetXPrecision(mNativePtr), nativeGetYPrecision(mNativePtr),
3478 nativeGetDownTimeNanos(mNativePtr), eventTimeNanos,
3479 newPointerCount, pp, pc);
3480 } else {
3481 nativeAddBatch(ev.mNativePtr, eventTimeNanos, pc, 0);
3482 }
3483 }
3484 return ev;
3485 }
3486 }
3487
Garfield Tan1da86282019-07-15 14:00:35 -07003488 /**
3489 * Calculate new cursor position for events from mouse. This is used to split, clamp and inject
3490 * events.
3491 *
3492 * <p>If the source is mouse, it sets cursor position to the centroid of all pointers because
3493 * InputReader maps multiple fingers on a touchpad to locations around cursor position in screen
3494 * coordinates so that the mouse cursor is at the centroid of all pointers.
3495 *
3496 * <p>If the source is not mouse it sets cursor position to NaN.
3497 */
3498 private void updateCursorPosition() {
3499 if (getSource() != InputDevice.SOURCE_MOUSE) {
3500 setCursorPosition(INVALID_CURSOR_POSITION, INVALID_CURSOR_POSITION);
3501 return;
3502 }
3503
3504 float x = 0;
3505 float y = 0;
3506
3507 final int pointerCount = getPointerCount();
3508 for (int i = 0; i < pointerCount; ++i) {
3509 x += getX(i);
3510 y += getY(i);
3511 }
3512
3513 // If pointer count is 0, divisions below yield NaN, which is an acceptable result for this
3514 // corner case.
3515 x /= pointerCount;
3516 y /= pointerCount;
3517 setCursorPosition(x, y);
3518 }
3519
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003520 @Override
3521 public String toString() {
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003522 StringBuilder msg = new StringBuilder();
3523 msg.append("MotionEvent { action=").append(actionToString(getAction()));
Eugene Suslae6e55b52018-01-11 15:12:56 -08003524 appendUnless("0", msg, ", actionButton=", buttonStateToString(getActionButton()));
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003525
3526 final int pointerCount = getPointerCount();
3527 for (int i = 0; i < pointerCount; i++) {
Eugene Suslae6e55b52018-01-11 15:12:56 -08003528 appendUnless(i, msg, ", id[" + i + "]=", getPointerId(i));
3529 float x = getX(i);
3530 float y = getY(i);
3531 if (!DEBUG_CONCISE_TOSTRING || x != 0f || y != 0f) {
3532 msg.append(", x[").append(i).append("]=").append(x);
3533 msg.append(", y[").append(i).append("]=").append(y);
3534 }
3535 appendUnless(TOOL_TYPE_SYMBOLIC_NAMES.get(TOOL_TYPE_FINGER),
3536 msg, ", toolType[" + i + "]=", toolTypeToString(getToolType(i)));
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003537 }
3538
Eugene Suslae6e55b52018-01-11 15:12:56 -08003539 appendUnless("0", msg, ", buttonState=", MotionEvent.buttonStateToString(getButtonState()));
Siarhei Vishniakoub05b0b52018-12-28 17:50:24 -08003540 appendUnless(classificationToString(CLASSIFICATION_NONE), msg, ", classification=",
3541 classificationToString(getClassification()));
Eugene Suslae6e55b52018-01-11 15:12:56 -08003542 appendUnless("0", msg, ", metaState=", KeyEvent.metaStateToString(getMetaState()));
3543 appendUnless("0", msg, ", flags=0x", Integer.toHexString(getFlags()));
3544 appendUnless("0", msg, ", edgeFlags=0x", Integer.toHexString(getEdgeFlags()));
3545 appendUnless(1, msg, ", pointerCount=", pointerCount);
3546 appendUnless(0, msg, ", historySize=", getHistorySize());
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003547 msg.append(", eventTime=").append(getEventTime());
Eugene Suslae6e55b52018-01-11 15:12:56 -08003548 if (!DEBUG_CONCISE_TOSTRING) {
3549 msg.append(", downTime=").append(getDownTime());
3550 msg.append(", deviceId=").append(getDeviceId());
3551 msg.append(", source=0x").append(Integer.toHexString(getSource()));
Siarhei Vishniakou85ddfff2018-01-31 16:49:36 -08003552 msg.append(", displayId=").append(getDisplayId());
Eugene Suslae6e55b52018-01-11 15:12:56 -08003553 }
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003554 msg.append(" }");
3555 return msg.toString();
Jeff Brown497a92c2010-09-12 17:55:08 -07003556 }
3557
Eugene Suslae6e55b52018-01-11 15:12:56 -08003558 private static <T> void appendUnless(T defValue, StringBuilder sb, String key, T value) {
3559 if (DEBUG_CONCISE_TOSTRING && Objects.equals(defValue, value)) return;
3560 sb.append(key).append(value);
3561 }
3562
Jeff Brown497a92c2010-09-12 17:55:08 -07003563 /**
John Spurlock4dad6ca2013-06-05 13:17:05 -04003564 * Returns a string that represents the symbolic name of the specified unmasked action
Jeff Brown91c69ab2011-02-14 17:03:18 -08003565 * such as "ACTION_DOWN", "ACTION_POINTER_DOWN(3)" or an equivalent numeric constant
3566 * such as "35" if unknown.
Jeff Brown497a92c2010-09-12 17:55:08 -07003567 *
John Spurlock4dad6ca2013-06-05 13:17:05 -04003568 * @param action The unmasked action.
Jeff Brown497a92c2010-09-12 17:55:08 -07003569 * @return The symbolic name of the specified action.
John Spurlock4dad6ca2013-06-05 13:17:05 -04003570 * @see #getAction()
Jeff Brown497a92c2010-09-12 17:55:08 -07003571 */
3572 public static String actionToString(int action) {
3573 switch (action) {
3574 case ACTION_DOWN:
3575 return "ACTION_DOWN";
3576 case ACTION_UP:
3577 return "ACTION_UP";
3578 case ACTION_CANCEL:
3579 return "ACTION_CANCEL";
Jeff Brown33bbfd22011-02-24 20:55:35 -08003580 case ACTION_OUTSIDE:
3581 return "ACTION_OUTSIDE";
Jeff Brown497a92c2010-09-12 17:55:08 -07003582 case ACTION_MOVE:
3583 return "ACTION_MOVE";
Jeff Browncc0c1592011-02-19 05:07:28 -08003584 case ACTION_HOVER_MOVE:
3585 return "ACTION_HOVER_MOVE";
Jeff Brown33bbfd22011-02-24 20:55:35 -08003586 case ACTION_SCROLL:
3587 return "ACTION_SCROLL";
Jeff Browna032cc02011-03-07 16:56:21 -08003588 case ACTION_HOVER_ENTER:
3589 return "ACTION_HOVER_ENTER";
3590 case ACTION_HOVER_EXIT:
3591 return "ACTION_HOVER_EXIT";
Michael Wright5bd69e62015-05-14 14:48:08 +01003592 case ACTION_BUTTON_PRESS:
3593 return "ACTION_BUTTON_PRESS";
3594 case ACTION_BUTTON_RELEASE:
3595 return "ACTION_BUTTON_RELEASE";
Jeff Brown497a92c2010-09-12 17:55:08 -07003596 }
3597 int index = (action & ACTION_POINTER_INDEX_MASK) >> ACTION_POINTER_INDEX_SHIFT;
3598 switch (action & ACTION_MASK) {
3599 case ACTION_POINTER_DOWN:
3600 return "ACTION_POINTER_DOWN(" + index + ")";
3601 case ACTION_POINTER_UP:
3602 return "ACTION_POINTER_UP(" + index + ")";
3603 default:
3604 return Integer.toString(action);
3605 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003606 }
3607
Jeff Brown91c69ab2011-02-14 17:03:18 -08003608 /**
3609 * Returns a string that represents the symbolic name of the specified axis
Jeff Brown6f2fba42011-02-19 01:08:02 -08003610 * such as "AXIS_X" or an equivalent numeric constant such as "42" if unknown.
Jeff Brown91c69ab2011-02-14 17:03:18 -08003611 *
John Spurlock4dad6ca2013-06-05 13:17:05 -04003612 * @param axis The axis.
Jeff Brown91c69ab2011-02-14 17:03:18 -08003613 * @return The symbolic name of the specified axis.
Jeff Brown91c69ab2011-02-14 17:03:18 -08003614 */
3615 public static String axisToString(int axis) {
Michael Wright337d9d22014-04-22 15:03:48 -07003616 String symbolicName = nativeAxisToString(axis);
3617 return symbolicName != null ? LABEL_PREFIX + symbolicName : Integer.toString(axis);
Jeff Brown6f2fba42011-02-19 01:08:02 -08003618 }
3619
3620 /**
Jeff Browncc0c1592011-02-19 05:07:28 -08003621 * Gets an axis by its symbolic name such as "AXIS_X" or an
3622 * equivalent numeric constant such as "42".
Jeff Brown6f2fba42011-02-19 01:08:02 -08003623 *
3624 * @param symbolicName The symbolic name of the axis.
3625 * @return The axis or -1 if not found.
John Spurlock4dad6ca2013-06-05 13:17:05 -04003626 * @see KeyEvent#keyCodeToString(int)
Jeff Brown6f2fba42011-02-19 01:08:02 -08003627 */
3628 public static int axisFromString(String symbolicName) {
Michael Wright337d9d22014-04-22 15:03:48 -07003629 if (symbolicName.startsWith(LABEL_PREFIX)) {
3630 symbolicName = symbolicName.substring(LABEL_PREFIX.length());
Michael Wright973efa02014-05-13 15:38:56 -07003631 int axis = nativeAxisFromString(symbolicName);
3632 if (axis >= 0) {
3633 return axis;
3634 }
Jeff Brown6f2fba42011-02-19 01:08:02 -08003635 }
Jeff Brown6f2fba42011-02-19 01:08:02 -08003636 try {
3637 return Integer.parseInt(symbolicName, 10);
3638 } catch (NumberFormatException ex) {
3639 return -1;
Jeff Brown91c69ab2011-02-14 17:03:18 -08003640 }
3641 }
3642
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003643 /**
3644 * Returns a string that represents the symbolic name of the specified combined
3645 * button state flags such as "0", "BUTTON_PRIMARY",
3646 * "BUTTON_PRIMARY|BUTTON_SECONDARY" or an equivalent numeric constant such as "0x10000000"
3647 * if unknown.
3648 *
3649 * @param buttonState The button state.
3650 * @return The symbolic name of the specified combined button state flags.
3651 * @hide
3652 */
3653 public static String buttonStateToString(int buttonState) {
3654 if (buttonState == 0) {
3655 return "0";
3656 }
3657 StringBuilder result = null;
3658 int i = 0;
3659 while (buttonState != 0) {
3660 final boolean isSet = (buttonState & 1) != 0;
3661 buttonState >>>= 1; // unsigned shift!
3662 if (isSet) {
3663 final String name = BUTTON_SYMBOLIC_NAMES[i];
3664 if (result == null) {
3665 if (buttonState == 0) {
3666 return name;
3667 }
3668 result = new StringBuilder(name);
3669 } else {
3670 result.append('|');
3671 result.append(name);
3672 }
3673 }
3674 i += 1;
3675 }
3676 return result.toString();
3677 }
3678
3679 /**
Siarhei Vishniakoub05b0b52018-12-28 17:50:24 -08003680 * Returns a string that represents the symbolic name of the specified classification.
3681 *
3682 * @param classification The classification type.
3683 * @return The symbolic name of this classification.
3684 * @hide
3685 */
3686 public static String classificationToString(@Classification int classification) {
3687 switch (classification) {
3688 case CLASSIFICATION_NONE:
3689 return "NONE";
3690 case CLASSIFICATION_AMBIGUOUS_GESTURE:
3691 return "AMBIGUOUS_GESTURE";
3692 case CLASSIFICATION_DEEP_PRESS:
3693 return "DEEP_PRESS";
3694
3695 }
3696 return "NONE";
3697 }
3698
3699 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003700 * Returns a string that represents the symbolic name of the specified tool type
3701 * such as "TOOL_TYPE_FINGER" or an equivalent numeric constant such as "42" if unknown.
3702 *
3703 * @param toolType The tool type.
3704 * @return The symbolic name of the specified tool type.
3705 * @hide
3706 */
3707 public static String toolTypeToString(int toolType) {
3708 String symbolicName = TOOL_TYPE_SYMBOLIC_NAMES.get(toolType);
3709 return symbolicName != null ? symbolicName : Integer.toString(toolType);
3710 }
3711
Sujith Ramakrishnancc32bd82014-05-19 15:32:13 -07003712 /**
3713 * Checks if a mouse or stylus button (or combination of buttons) is pressed.
3714 * @param button Button (or combination of buttons).
3715 * @return True if specified buttons are pressed.
3716 *
3717 * @see #BUTTON_PRIMARY
3718 * @see #BUTTON_SECONDARY
3719 * @see #BUTTON_TERTIARY
3720 * @see #BUTTON_FORWARD
3721 * @see #BUTTON_BACK
Michael Wright5bd69e62015-05-14 14:48:08 +01003722 * @see #BUTTON_STYLUS_PRIMARY
3723 * @see #BUTTON_STYLUS_SECONDARY
Sujith Ramakrishnancc32bd82014-05-19 15:32:13 -07003724 */
3725 public final boolean isButtonPressed(int button) {
3726 if (button == 0) {
3727 return false;
3728 }
3729 return (getButtonState() & button) == button;
3730 }
3731
Jeff Sharkey9e8f83d2019-02-28 12:06:45 -07003732 public static final @android.annotation.NonNull Parcelable.Creator<MotionEvent> CREATOR
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003733 = new Parcelable.Creator<MotionEvent>() {
3734 public MotionEvent createFromParcel(Parcel in) {
Jeff Brown6ec402b2010-07-28 15:48:59 -07003735 in.readInt(); // skip token, we already know this is a MotionEvent
3736 return MotionEvent.createFromParcelBody(in);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003737 }
3738
3739 public MotionEvent[] newArray(int size) {
3740 return new MotionEvent[size];
3741 }
3742 };
3743
Jeff Brown6ec402b2010-07-28 15:48:59 -07003744 /** @hide */
3745 public static MotionEvent createFromParcelBody(Parcel in) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08003746 MotionEvent ev = obtain();
3747 ev.mNativePtr = nativeReadFromParcel(ev.mNativePtr, in);
Jeff Brown6ec402b2010-07-28 15:48:59 -07003748 return ev;
3749 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08003750
Wale Ogunwalec3672cd2014-11-05 15:17:35 -08003751 /** @hide */
3752 @Override
3753 public final void cancel() {
3754 setAction(ACTION_CANCEL);
3755 }
3756
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003757 public void writeToParcel(Parcel out, int flags) {
Jeff Brown6ec402b2010-07-28 15:48:59 -07003758 out.writeInt(PARCEL_TOKEN_MOTION_EVENT);
Jeff Brown91c69ab2011-02-14 17:03:18 -08003759 nativeWriteToParcel(mNativePtr, out);
Jeff Brown5c225b12010-06-16 01:53:36 -07003760 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08003761
Jeff Brownc5ed5912010-07-14 18:48:53 -07003762 /**
3763 * Transfer object for pointer coordinates.
Dennis Kempinac1b31d2016-11-02 17:02:25 -07003764 *
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003765 * Objects of this type can be used to specify the pointer coordinates when
3766 * creating new {@link MotionEvent} objects and to query pointer coordinates
3767 * in bulk.
Dennis Kempinac1b31d2016-11-02 17:02:25 -07003768 *
Jeff Brownc5ed5912010-07-14 18:48:53 -07003769 * Refer to {@link InputDevice} for information about how different kinds of
3770 * input devices and sources represent pointer coordinates.
3771 */
3772 public static final class PointerCoords {
Jeff Brown91c69ab2011-02-14 17:03:18 -08003773 private static final int INITIAL_PACKED_AXIS_VALUES = 8;
Mathew Inwooda570dee2018-08-17 14:56:00 +01003774 @UnsupportedAppUsage
Jeff Brown6f2fba42011-02-19 01:08:02 -08003775 private long mPackedAxisBits;
Mathew Inwooda570dee2018-08-17 14:56:00 +01003776 @UnsupportedAppUsage
Jeff Brown91c69ab2011-02-14 17:03:18 -08003777 private float[] mPackedAxisValues;
3778
3779 /**
3780 * Creates a pointer coords object with all axes initialized to zero.
3781 */
3782 public PointerCoords() {
3783 }
3784
3785 /**
3786 * Creates a pointer coords object as a copy of the
3787 * contents of another pointer coords object.
3788 *
3789 * @param other The pointer coords object to copy.
3790 */
3791 public PointerCoords(PointerCoords other) {
3792 copyFrom(other);
3793 }
3794
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003795 /** @hide */
Mathew Inwooda570dee2018-08-17 14:56:00 +01003796 @UnsupportedAppUsage
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003797 public static PointerCoords[] createArray(int size) {
3798 PointerCoords[] array = new PointerCoords[size];
3799 for (int i = 0; i < size; i++) {
3800 array[i] = new PointerCoords();
3801 }
3802 return array;
3803 }
3804
Jeff Brownc5ed5912010-07-14 18:48:53 -07003805 /**
Jeff Brown6f2fba42011-02-19 01:08:02 -08003806 * The X component of the pointer movement.
Jeff Brown91c69ab2011-02-14 17:03:18 -08003807 *
3808 * @see MotionEvent#AXIS_X
Jeff Brownc5ed5912010-07-14 18:48:53 -07003809 */
3810 public float x;
Dennis Kempinac1b31d2016-11-02 17:02:25 -07003811
Jeff Brownc5ed5912010-07-14 18:48:53 -07003812 /**
Jeff Brown6f2fba42011-02-19 01:08:02 -08003813 * The Y component of the pointer movement.
Jeff Brown91c69ab2011-02-14 17:03:18 -08003814 *
3815 * @see MotionEvent#AXIS_Y
Jeff Brownc5ed5912010-07-14 18:48:53 -07003816 */
3817 public float y;
Dennis Kempinac1b31d2016-11-02 17:02:25 -07003818
Jeff Brownc5ed5912010-07-14 18:48:53 -07003819 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08003820 * A normalized value that describes the pressure applied to the device
3821 * by a finger or other tool.
Jeff Brownc5ed5912010-07-14 18:48:53 -07003822 * The pressure generally ranges from 0 (no pressure at all) to 1 (normal pressure),
Jeff Brown91c69ab2011-02-14 17:03:18 -08003823 * although values higher than 1 may be generated depending on the calibration of
Jeff Brownc5ed5912010-07-14 18:48:53 -07003824 * the input device.
Jeff Brown91c69ab2011-02-14 17:03:18 -08003825 *
3826 * @see MotionEvent#AXIS_PRESSURE
Jeff Brownc5ed5912010-07-14 18:48:53 -07003827 */
3828 public float pressure;
Dennis Kempinac1b31d2016-11-02 17:02:25 -07003829
Jeff Brownc5ed5912010-07-14 18:48:53 -07003830 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08003831 * A normalized value that describes the approximate size of the pointer touch area
3832 * in relation to the maximum detectable size of the device.
3833 * It represents some approximation of the area of the screen being
Jeff Brownc5ed5912010-07-14 18:48:53 -07003834 * pressed; the actual value in pixels corresponding to the
3835 * touch is normalized with the device specific range of values
3836 * and scaled to a value between 0 and 1. The value of size can be used to
3837 * determine fat touch events.
Jeff Brown91c69ab2011-02-14 17:03:18 -08003838 *
3839 * @see MotionEvent#AXIS_SIZE
Jeff Brownc5ed5912010-07-14 18:48:53 -07003840 */
3841 public float size;
Dennis Kempinac1b31d2016-11-02 17:02:25 -07003842
Jeff Brownc5ed5912010-07-14 18:48:53 -07003843 /**
3844 * The length of the major axis of an ellipse that describes the touch area at
3845 * the point of contact.
Jeff Brown91c69ab2011-02-14 17:03:18 -08003846 * If the device is a touch screen, the length is reported in pixels, otherwise it is
3847 * reported in device-specific units.
3848 *
3849 * @see MotionEvent#AXIS_TOUCH_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07003850 */
3851 public float touchMajor;
Dennis Kempinac1b31d2016-11-02 17:02:25 -07003852
Jeff Brownc5ed5912010-07-14 18:48:53 -07003853 /**
3854 * The length of the minor axis of an ellipse that describes the touch area at
3855 * the point of contact.
Jeff Brown91c69ab2011-02-14 17:03:18 -08003856 * If the device is a touch screen, the length is reported in pixels, otherwise it is
3857 * reported in device-specific units.
3858 *
3859 * @see MotionEvent#AXIS_TOUCH_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07003860 */
3861 public float touchMinor;
Dennis Kempinac1b31d2016-11-02 17:02:25 -07003862
Jeff Brownc5ed5912010-07-14 18:48:53 -07003863 /**
3864 * The length of the major axis of an ellipse that describes the size of
3865 * the approaching tool.
3866 * The tool area represents the estimated size of the finger or pen that is
3867 * touching the device independent of its actual touch area at the point of contact.
Jeff Brown91c69ab2011-02-14 17:03:18 -08003868 * If the device is a touch screen, the length is reported in pixels, otherwise it is
3869 * reported in device-specific units.
3870 *
3871 * @see MotionEvent#AXIS_TOOL_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07003872 */
3873 public float toolMajor;
Dennis Kempinac1b31d2016-11-02 17:02:25 -07003874
Jeff Brownc5ed5912010-07-14 18:48:53 -07003875 /**
3876 * The length of the minor axis of an ellipse that describes the size of
3877 * the approaching tool.
3878 * The tool area represents the estimated size of the finger or pen that is
3879 * touching the device independent of its actual touch area at the point of contact.
Jeff Brown91c69ab2011-02-14 17:03:18 -08003880 * If the device is a touch screen, the length is reported in pixels, otherwise it is
3881 * reported in device-specific units.
3882 *
3883 * @see MotionEvent#AXIS_TOOL_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07003884 */
3885 public float toolMinor;
Dennis Kempinac1b31d2016-11-02 17:02:25 -07003886
Jeff Brownc5ed5912010-07-14 18:48:53 -07003887 /**
3888 * The orientation of the touch area and tool area in radians clockwise from vertical.
Jeff Brown6f2fba42011-02-19 01:08:02 -08003889 * An angle of 0 radians indicates that the major axis of contact is oriented
Jeff Brownc5ed5912010-07-14 18:48:53 -07003890 * upwards, is perfectly circular or is of unknown orientation. A positive angle
3891 * indicates that the major axis of contact is oriented to the right. A negative angle
3892 * indicates that the major axis of contact is oriented to the left.
Jeff Brown6d0fec22010-07-23 21:28:06 -07003893 * The full range is from -PI/2 radians (finger pointing fully left) to PI/2 radians
Jeff Brownc5ed5912010-07-14 18:48:53 -07003894 * (finger pointing fully right).
Jeff Brown91c69ab2011-02-14 17:03:18 -08003895 *
3896 * @see MotionEvent#AXIS_ORIENTATION
Jeff Brownc5ed5912010-07-14 18:48:53 -07003897 */
3898 public float orientation;
Jeff Brown91c69ab2011-02-14 17:03:18 -08003899
3900 /**
3901 * Clears the contents of this object.
3902 * Resets all axes to zero.
3903 */
3904 public void clear() {
3905 mPackedAxisBits = 0;
3906
3907 x = 0;
3908 y = 0;
3909 pressure = 0;
3910 size = 0;
3911 touchMajor = 0;
3912 touchMinor = 0;
3913 toolMajor = 0;
3914 toolMinor = 0;
3915 orientation = 0;
Jeff Brownc5ed5912010-07-14 18:48:53 -07003916 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08003917
3918 /**
3919 * Copies the contents of another pointer coords object.
3920 *
3921 * @param other The pointer coords object to copy.
3922 */
3923 public void copyFrom(PointerCoords other) {
Jeff Brown6f2fba42011-02-19 01:08:02 -08003924 final long bits = other.mPackedAxisBits;
Jeff Brown91c69ab2011-02-14 17:03:18 -08003925 mPackedAxisBits = bits;
3926 if (bits != 0) {
3927 final float[] otherValues = other.mPackedAxisValues;
Jeff Brown6f2fba42011-02-19 01:08:02 -08003928 final int count = Long.bitCount(bits);
Jeff Brown91c69ab2011-02-14 17:03:18 -08003929 float[] values = mPackedAxisValues;
3930 if (values == null || count > values.length) {
3931 values = new float[otherValues.length];
3932 mPackedAxisValues = values;
3933 }
3934 System.arraycopy(otherValues, 0, values, 0, count);
3935 }
3936
3937 x = other.x;
3938 y = other.y;
3939 pressure = other.pressure;
3940 size = other.size;
3941 touchMajor = other.touchMajor;
3942 touchMinor = other.touchMinor;
3943 toolMajor = other.toolMajor;
3944 toolMinor = other.toolMinor;
3945 orientation = other.orientation;
Jeff Brownc5ed5912010-07-14 18:48:53 -07003946 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08003947
3948 /**
3949 * Gets the value associated with the specified axis.
3950 *
3951 * @param axis The axis identifier for the axis value to retrieve.
3952 * @return The value associated with the axis, or 0 if none.
3953 *
3954 * @see MotionEvent#AXIS_X
3955 * @see MotionEvent#AXIS_Y
3956 */
3957 public float getAxisValue(int axis) {
3958 switch (axis) {
3959 case AXIS_X:
3960 return x;
3961 case AXIS_Y:
3962 return y;
3963 case AXIS_PRESSURE:
3964 return pressure;
3965 case AXIS_SIZE:
3966 return size;
3967 case AXIS_TOUCH_MAJOR:
3968 return touchMajor;
3969 case AXIS_TOUCH_MINOR:
3970 return touchMinor;
3971 case AXIS_TOOL_MAJOR:
3972 return toolMajor;
3973 case AXIS_TOOL_MINOR:
3974 return toolMinor;
3975 case AXIS_ORIENTATION:
3976 return orientation;
3977 default: {
Jeff Brown6f2fba42011-02-19 01:08:02 -08003978 if (axis < 0 || axis > 63) {
3979 throw new IllegalArgumentException("Axis out of range.");
3980 }
3981 final long bits = mPackedAxisBits;
Michael Wright9adca062014-03-19 11:51:26 -07003982 final long axisBit = 0x8000000000000000L >>> axis;
Jeff Brown91c69ab2011-02-14 17:03:18 -08003983 if ((bits & axisBit) == 0) {
3984 return 0;
3985 }
Michael Wright9adca062014-03-19 11:51:26 -07003986 final int index = Long.bitCount(bits & ~(0xFFFFFFFFFFFFFFFFL >>> axis));
Jeff Brown91c69ab2011-02-14 17:03:18 -08003987 return mPackedAxisValues[index];
3988 }
3989 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07003990 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08003991
3992 /**
3993 * Sets the value associated with the specified axis.
3994 *
3995 * @param axis The axis identifier for the axis value to assign.
3996 * @param value The value to set.
3997 *
3998 * @see MotionEvent#AXIS_X
3999 * @see MotionEvent#AXIS_Y
4000 */
4001 public void setAxisValue(int axis, float value) {
4002 switch (axis) {
4003 case AXIS_X:
4004 x = value;
4005 break;
4006 case AXIS_Y:
4007 y = value;
4008 break;
4009 case AXIS_PRESSURE:
4010 pressure = value;
4011 break;
4012 case AXIS_SIZE:
4013 size = value;
4014 break;
4015 case AXIS_TOUCH_MAJOR:
4016 touchMajor = value;
4017 break;
4018 case AXIS_TOUCH_MINOR:
4019 touchMinor = value;
4020 break;
4021 case AXIS_TOOL_MAJOR:
4022 toolMajor = value;
4023 break;
4024 case AXIS_TOOL_MINOR:
4025 toolMinor = value;
4026 break;
4027 case AXIS_ORIENTATION:
4028 orientation = value;
4029 break;
4030 default: {
Jeff Brown6f2fba42011-02-19 01:08:02 -08004031 if (axis < 0 || axis > 63) {
4032 throw new IllegalArgumentException("Axis out of range.");
4033 }
4034 final long bits = mPackedAxisBits;
Michael Wright9adca062014-03-19 11:51:26 -07004035 final long axisBit = 0x8000000000000000L >>> axis;
4036 final int index = Long.bitCount(bits & ~(0xFFFFFFFFFFFFFFFFL >>> axis));
Jeff Brown91c69ab2011-02-14 17:03:18 -08004037 float[] values = mPackedAxisValues;
4038 if ((bits & axisBit) == 0) {
4039 if (values == null) {
4040 values = new float[INITIAL_PACKED_AXIS_VALUES];
4041 mPackedAxisValues = values;
4042 } else {
Jeff Brown6f2fba42011-02-19 01:08:02 -08004043 final int count = Long.bitCount(bits);
Jeff Brown91c69ab2011-02-14 17:03:18 -08004044 if (count < values.length) {
4045 if (index != count) {
4046 System.arraycopy(values, index, values, index + 1,
4047 count - index);
4048 }
4049 } else {
4050 float[] newValues = new float[count * 2];
4051 System.arraycopy(values, 0, newValues, 0, index);
4052 System.arraycopy(values, index, newValues, index + 1,
4053 count - index);
4054 values = newValues;
4055 mPackedAxisValues = values;
4056 }
4057 }
4058 mPackedAxisBits = bits | axisBit;
4059 }
4060 values[index] = value;
4061 }
4062 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07004063 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07004064 }
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07004065
4066 /**
4067 * Transfer object for pointer properties.
4068 *
4069 * Objects of this type can be used to specify the pointer id and tool type
4070 * when creating new {@link MotionEvent} objects and to query pointer properties in bulk.
4071 */
4072 public static final class PointerProperties {
4073 /**
4074 * Creates a pointer properties object with an invalid pointer id.
4075 */
4076 public PointerProperties() {
4077 clear();
4078 }
4079
4080 /**
4081 * Creates a pointer properties object as a copy of the contents of
4082 * another pointer properties object.
4083 * @param other
4084 */
4085 public PointerProperties(PointerProperties other) {
4086 copyFrom(other);
4087 }
4088
4089 /** @hide */
Mathew Inwooda570dee2018-08-17 14:56:00 +01004090 @UnsupportedAppUsage
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07004091 public static PointerProperties[] createArray(int size) {
4092 PointerProperties[] array = new PointerProperties[size];
4093 for (int i = 0; i < size; i++) {
4094 array[i] = new PointerProperties();
4095 }
4096 return array;
4097 }
4098
4099 /**
4100 * The pointer id.
4101 * Initially set to {@link #INVALID_POINTER_ID} (-1).
4102 *
4103 * @see MotionEvent#getPointerId(int)
4104 */
4105 public int id;
4106
4107 /**
4108 * The pointer tool type.
4109 * Initially set to 0.
4110 *
4111 * @see MotionEvent#getToolType(int)
4112 */
4113 public int toolType;
4114
4115 /**
4116 * Resets the pointer properties to their initial values.
4117 */
4118 public void clear() {
4119 id = INVALID_POINTER_ID;
4120 toolType = TOOL_TYPE_UNKNOWN;
4121 }
4122
4123 /**
4124 * Copies the contents of another pointer properties object.
4125 *
4126 * @param other The pointer properties object to copy.
4127 */
4128 public void copyFrom(PointerProperties other) {
4129 id = other.id;
4130 toolType = other.toolType;
4131 }
Jeff Brown9d3bdbd2012-03-21 11:50:06 -07004132
4133 @Override
4134 public boolean equals(Object other) {
4135 if (other instanceof PointerProperties) {
4136 return equals((PointerProperties)other);
4137 }
4138 return false;
4139 }
4140
4141 private boolean equals(PointerProperties other) {
4142 return other != null && id == other.id && toolType == other.toolType;
4143 }
4144
4145 @Override
4146 public int hashCode() {
4147 return id | (toolType << 8);
4148 }
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07004149 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004150}