blob: b6a4a095066f895cd7375267eff97cf96711e965 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.view;
18
Siarhei Vishniakou85ddfff2018-01-31 16:49:36 -080019import static android.view.Display.DEFAULT_DISPLAY;
20
Siarhei Vishniakoub05b0b52018-12-28 17:50:24 -080021import static java.lang.annotation.RetentionPolicy.SOURCE;
22
23import android.annotation.IntDef;
Kirill Grouchnikovc0b0ba52016-09-13 16:09:37 -070024import android.annotation.TestApi;
Mathew Inwooda570dee2018-08-17 14:56:00 +010025import android.annotation.UnsupportedAppUsage;
Jeff Brown20e987b2010-08-23 12:01:02 -070026import android.graphics.Matrix;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027import android.os.Parcel;
28import android.os.Parcelable;
29import android.os.SystemClock;
Siarhei Vishniakou85ddfff2018-01-31 16:49:36 -080030import android.util.Log;
Jeff Brown6f2fba42011-02-19 01:08:02 -080031import android.util.SparseArray;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032
John Reck09709972016-10-03 15:47:18 -070033import dalvik.annotation.optimization.CriticalNative;
34import dalvik.annotation.optimization.FastNative;
35
Siarhei Vishniakoub05b0b52018-12-28 17:50:24 -080036import java.lang.annotation.Retention;
Eugene Suslae6e55b52018-01-11 15:12:56 -080037import java.util.Objects;
38
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039/**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -070040 * Object used to report movement (mouse, pen, finger, trackball) events.
41 * Motion events may hold either absolute or relative movements and other data,
42 * depending on the type of device.
43 *
44 * <h3>Overview</h3>
Jeff Browndc1ab4b2010-09-14 18:03:38 -070045 * <p>
Jeff Brownfe9f8ab2011-05-06 18:20:01 -070046 * Motion events describe movements in terms of an action code and a set of axis values.
47 * The action code specifies the state change that occurred such as a pointer going
48 * down or up. The axis values describe the position and other movement properties.
49 * </p><p>
50 * For example, when the user first touches the screen, the system delivers a touch
51 * event to the appropriate {@link View} with the action code {@link #ACTION_DOWN}
52 * and a set of axis values that include the X and Y coordinates of the touch and
53 * information about the pressure, size and orientation of the contact area.
54 * </p><p>
55 * Some devices can report multiple movement traces at the same time. Multi-touch
56 * screens emit one movement trace for each finger. The individual fingers or
57 * other objects that generate movement traces are referred to as <em>pointers</em>.
58 * Motion events contain information about all of the pointers that are currently active
59 * even if some of them have not moved since the last event was delivered.
60 * </p><p>
61 * The number of pointers only ever changes by one as individual pointers go up and down,
62 * except when the gesture is canceled.
63 * </p><p>
64 * Each pointer has a unique id that is assigned when it first goes down
65 * (indicated by {@link #ACTION_DOWN} or {@link #ACTION_POINTER_DOWN}). A pointer id
66 * remains valid until the pointer eventually goes up (indicated by {@link #ACTION_UP}
67 * or {@link #ACTION_POINTER_UP}) or when the gesture is canceled (indicated by
68 * {@link #ACTION_CANCEL}).
69 * </p><p>
70 * The MotionEvent class provides many methods to query the position and other properties of
71 * pointers, such as {@link #getX(int)}, {@link #getY(int)}, {@link #getAxisValue},
72 * {@link #getPointerId(int)}, {@link #getToolType(int)}, and many others. Most of these
73 * methods accept the pointer index as a parameter rather than the pointer id.
74 * The pointer index of each pointer in the event ranges from 0 to one less than the value
75 * returned by {@link #getPointerCount()}.
76 * </p><p>
77 * The order in which individual pointers appear within a motion event is undefined.
78 * Thus the pointer index of a pointer can change from one event to the next but
79 * the pointer id of a pointer is guaranteed to remain constant as long as the pointer
80 * remains active. Use the {@link #getPointerId(int)} method to obtain the
81 * pointer id of a pointer to track it across all subsequent motion events in a gesture.
82 * Then for successive motion events, use the {@link #findPointerIndex(int)} method
83 * to obtain the pointer index for a given pointer id in that motion event.
84 * </p><p>
85 * Mouse and stylus buttons can be retrieved using {@link #getButtonState()}. It is a
86 * good idea to check the button state while handling {@link #ACTION_DOWN} as part
87 * of a touch event. The application may choose to perform some different action
88 * if the touch event starts due to a secondary button click, such as presenting a
89 * context menu.
90 * </p>
91 *
92 * <h3>Batching</h3>
93 * <p>
94 * For efficiency, motion events with {@link #ACTION_MOVE} may batch together
95 * multiple movement samples within a single object. The most current
96 * pointer coordinates are available using {@link #getX(int)} and {@link #getY(int)}.
97 * Earlier coordinates within the batch are accessed using {@link #getHistoricalX(int, int)}
98 * and {@link #getHistoricalY(int, int)}. The coordinates are "historical" only
99 * insofar as they are older than the current coordinates in the batch; however,
100 * they are still distinct from any other coordinates reported in prior motion events.
101 * To process all coordinates in the batch in time order, first consume the historical
102 * coordinates then consume the current coordinates.
103 * </p><p>
104 * Example: Consuming all samples for all pointers in a motion event in time order.
105 * </p><p><pre><code>
106 * void printSamples(MotionEvent ev) {
107 * final int historySize = ev.getHistorySize();
108 * final int pointerCount = ev.getPointerCount();
109 * for (int h = 0; h &lt; historySize; h++) {
110 * System.out.printf("At time %d:", ev.getHistoricalEventTime(h));
111 * for (int p = 0; p &lt; pointerCount; p++) {
112 * System.out.printf(" pointer %d: (%f,%f)",
113 * ev.getPointerId(p), ev.getHistoricalX(p, h), ev.getHistoricalY(p, h));
114 * }
115 * }
116 * System.out.printf("At time %d:", ev.getEventTime());
117 * for (int p = 0; p &lt; pointerCount; p++) {
118 * System.out.printf(" pointer %d: (%f,%f)",
119 * ev.getPointerId(p), ev.getX(p), ev.getY(p));
120 * }
121 * }
122 * </code></pre></p>
123 *
124 * <h3>Device Types</h3>
125 * <p>
126 * The interpretation of the contents of a MotionEvent varies significantly depending
127 * on the source class of the device.
128 * </p><p>
Jeff Browncb1404e2011-01-15 18:14:15 -0800129 * On pointing devices with source class {@link InputDevice#SOURCE_CLASS_POINTER}
130 * such as touch screens, the pointer coordinates specify absolute
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700131 * positions such as view X/Y coordinates. Each complete gesture is represented
132 * by a sequence of motion events with actions that describe pointer state transitions
133 * and movements. A gesture starts with a motion event with {@link #ACTION_DOWN}
134 * that provides the location of the first pointer down. As each additional
135 * pointer that goes down or up, the framework will generate a motion event with
136 * {@link #ACTION_POINTER_DOWN} or {@link #ACTION_POINTER_UP} accordingly.
137 * Pointer movements are described by motion events with {@link #ACTION_MOVE}.
138 * Finally, a gesture end either when the final pointer goes up as represented
139 * by a motion event with {@link #ACTION_UP} or when gesture is canceled
140 * with {@link #ACTION_CANCEL}.
141 * </p><p>
Jeff Brown33bbfd22011-02-24 20:55:35 -0800142 * Some pointing devices such as mice may support vertical and/or horizontal scrolling.
143 * A scroll event is reported as a generic motion event with {@link #ACTION_SCROLL} that
144 * includes the relative scroll offset in the {@link #AXIS_VSCROLL} and
145 * {@link #AXIS_HSCROLL} axes. See {@link #getAxisValue(int)} for information
146 * about retrieving these additional axes.
147 * </p><p>
Jeff Browncb1404e2011-01-15 18:14:15 -0800148 * On trackball devices with source class {@link InputDevice#SOURCE_CLASS_TRACKBALL},
149 * the pointer coordinates specify relative movements as X/Y deltas.
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700150 * A trackball gesture consists of a sequence of movements described by motion
151 * events with {@link #ACTION_MOVE} interspersed with occasional {@link #ACTION_DOWN}
152 * or {@link #ACTION_UP} motion events when the trackball button is pressed or released.
153 * </p><p>
Jeff Browncb1404e2011-01-15 18:14:15 -0800154 * On joystick devices with source class {@link InputDevice#SOURCE_CLASS_JOYSTICK},
155 * the pointer coordinates specify the absolute position of the joystick axes.
156 * The joystick axis values are normalized to a range of -1.0 to 1.0 where 0.0 corresponds
157 * to the center position. More information about the set of available axes and the
158 * range of motion can be obtained using {@link InputDevice#getMotionRange}.
Jeff Brown33bbfd22011-02-24 20:55:35 -0800159 * Some common joystick axes are {@link #AXIS_X}, {@link #AXIS_Y},
160 * {@link #AXIS_HAT_X}, {@link #AXIS_HAT_Y}, {@link #AXIS_Z} and {@link #AXIS_RZ}.
Jeff Browncb1404e2011-01-15 18:14:15 -0800161 * </p><p>
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700162 * Refer to {@link InputDevice} for more information about how different kinds of
Jeff Brownc5ed5912010-07-14 18:48:53 -0700163 * input devices and sources represent pointer coordinates.
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700164 * </p>
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700165 *
166 * <h3>Consistency Guarantees</h3>
167 * <p>
168 * Motion events are always delivered to views as a consistent stream of events.
169 * What constitutes a consistent stream varies depending on the type of device.
170 * For touch events, consistency implies that pointers go down one at a time,
171 * move around as a group and then go up one at a time or are canceled.
172 * </p><p>
173 * While the framework tries to deliver consistent streams of motion events to
174 * views, it cannot guarantee it. Some events may be dropped or modified by
175 * containing views in the application before they are delivered thereby making
176 * the stream of events inconsistent. Views should always be prepared to
177 * handle {@link #ACTION_CANCEL} and should tolerate anomalous
178 * situations such as receiving a new {@link #ACTION_DOWN} without first having
179 * received an {@link #ACTION_UP} for the prior gesture.
180 * </p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800181 */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700182public final class MotionEvent extends InputEvent implements Parcelable {
Siarhei Vishniakou85ddfff2018-01-31 16:49:36 -0800183 private static final String TAG = "MotionEvent";
Jeff Brown91c69ab2011-02-14 17:03:18 -0800184 private static final long NS_PER_MS = 1000000;
Michael Wright337d9d22014-04-22 15:03:48 -0700185 private static final String LABEL_PREFIX = "AXIS_";
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700186
Eugene Suslae6e55b52018-01-11 15:12:56 -0800187 private static final boolean DEBUG_CONCISE_TOSTRING = false;
188
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700189 /**
190 * An invalid pointer id.
191 *
192 * This value (-1) can be used as a placeholder to indicate that a pointer id
193 * has not been assigned or is not available. It cannot appear as
194 * a pointer id inside a {@link MotionEvent}.
195 */
196 public static final int INVALID_POINTER_ID = -1;
197
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800198 /**
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700199 * Bit mask of the parts of the action code that are the action itself.
200 */
201 public static final int ACTION_MASK = 0xff;
Dennis Kempinac1b31d2016-11-02 17:02:25 -0700202
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700203 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700204 * Constant for {@link #getActionMasked}: A pressed gesture has started, the
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800205 * motion contains the initial starting location.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700206 * <p>
207 * This is also a good time to check the button state to distinguish
208 * secondary and tertiary button clicks and handle them appropriately.
209 * Use {@link #getButtonState} to retrieve the button state.
210 * </p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800211 */
212 public static final int ACTION_DOWN = 0;
Dennis Kempinac1b31d2016-11-02 17:02:25 -0700213
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800214 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700215 * Constant for {@link #getActionMasked}: A pressed gesture has finished, the
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800216 * motion contains the final release location as well as any intermediate
217 * points since the last down or move event.
218 */
219 public static final int ACTION_UP = 1;
Dennis Kempinac1b31d2016-11-02 17:02:25 -0700220
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800221 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700222 * Constant for {@link #getActionMasked}: A change has happened during a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800223 * press gesture (between {@link #ACTION_DOWN} and {@link #ACTION_UP}).
224 * The motion contains the most recent point, as well as any intermediate
225 * points since the last down or move event.
226 */
227 public static final int ACTION_MOVE = 2;
Dennis Kempinac1b31d2016-11-02 17:02:25 -0700228
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800229 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700230 * Constant for {@link #getActionMasked}: The current gesture has been aborted.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800231 * You will not receive any more points in it. You should treat this as
232 * an up event, but not perform any action that you normally would.
233 */
234 public static final int ACTION_CANCEL = 3;
Dennis Kempinac1b31d2016-11-02 17:02:25 -0700235
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800236 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700237 * Constant for {@link #getActionMasked}: A movement has happened outside of the
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800238 * normal bounds of the UI element. This does not provide a full gesture,
239 * but only the initial location of the movement/touch.
Siarhei Vishniakou6ad0e392017-06-02 17:20:34 -0700240 * <p>
241 * Note: Because the location of any event will be outside the
242 * bounds of the view hierarchy, it will not get dispatched to
243 * any children of a ViewGroup by default. Therefore,
244 * movements with ACTION_OUTSIDE should be handled in either the
245 * root {@link View} or in the appropriate {@link Window.Callback}
246 * (e.g. {@link android.app.Activity} or {@link android.app.Dialog}).
247 * </p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800248 */
249 public static final int ACTION_OUTSIDE = 4;
250
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700251 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700252 * Constant for {@link #getActionMasked}: A non-primary pointer has gone down.
253 * <p>
254 * Use {@link #getActionIndex} to retrieve the index of the pointer that changed.
255 * </p><p>
256 * The index is encoded in the {@link #ACTION_POINTER_INDEX_MASK} bits of the
257 * unmasked action returned by {@link #getAction}.
258 * </p>
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700259 */
260 public static final int ACTION_POINTER_DOWN = 5;
Dennis Kempinac1b31d2016-11-02 17:02:25 -0700261
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700262 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700263 * Constant for {@link #getActionMasked}: A non-primary pointer has gone up.
264 * <p>
265 * Use {@link #getActionIndex} to retrieve the index of the pointer that changed.
266 * </p><p>
267 * The index is encoded in the {@link #ACTION_POINTER_INDEX_MASK} bits of the
268 * unmasked action returned by {@link #getAction}.
269 * </p>
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700270 */
271 public static final int ACTION_POINTER_UP = 6;
Jeff Browncc0c1592011-02-19 05:07:28 -0800272
273 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700274 * Constant for {@link #getActionMasked}: A change happened but the pointer
Jeff Browncc0c1592011-02-19 05:07:28 -0800275 * is not down (unlike {@link #ACTION_MOVE}). The motion contains the most
276 * recent point, as well as any intermediate points since the last
277 * hover move event.
Jeff Brown33bbfd22011-02-24 20:55:35 -0800278 * <p>
Jeff Browna032cc02011-03-07 16:56:21 -0800279 * This action is always delivered to the window or view under the pointer.
280 * </p><p>
Jeff Brown33bbfd22011-02-24 20:55:35 -0800281 * This action is not a touch event so it is delivered to
282 * {@link View#onGenericMotionEvent(MotionEvent)} rather than
283 * {@link View#onTouchEvent(MotionEvent)}.
284 * </p>
Jeff Browncc0c1592011-02-19 05:07:28 -0800285 */
286 public static final int ACTION_HOVER_MOVE = 7;
287
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700288 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700289 * Constant for {@link #getActionMasked}: The motion event contains relative
Jeff Brown33bbfd22011-02-24 20:55:35 -0800290 * vertical and/or horizontal scroll offsets. Use {@link #getAxisValue(int)}
291 * to retrieve the information from {@link #AXIS_VSCROLL} and {@link #AXIS_HSCROLL}.
292 * The pointer may or may not be down when this event is dispatched.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700293 * <p>
Jeff Browna032cc02011-03-07 16:56:21 -0800294 * This action is always delivered to the window or view under the pointer, which
295 * may not be the window or view currently touched.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700296 * </p><p>
Jeff Brown33bbfd22011-02-24 20:55:35 -0800297 * This action is not a touch event so it is delivered to
298 * {@link View#onGenericMotionEvent(MotionEvent)} rather than
299 * {@link View#onTouchEvent(MotionEvent)}.
300 * </p>
301 */
302 public static final int ACTION_SCROLL = 8;
303
304 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700305 * Constant for {@link #getActionMasked}: The pointer is not down but has entered the
Jeff Browna032cc02011-03-07 16:56:21 -0800306 * boundaries of a window or view.
307 * <p>
308 * This action is always delivered to the window or view under the pointer.
309 * </p><p>
310 * This action is not a touch event so it is delivered to
311 * {@link View#onGenericMotionEvent(MotionEvent)} rather than
312 * {@link View#onTouchEvent(MotionEvent)}.
313 * </p>
314 */
315 public static final int ACTION_HOVER_ENTER = 9;
316
317 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700318 * Constant for {@link #getActionMasked}: The pointer is not down but has exited the
Jeff Browna032cc02011-03-07 16:56:21 -0800319 * boundaries of a window or view.
320 * <p>
321 * This action is always delivered to the window or view that was previously under the pointer.
322 * </p><p>
323 * This action is not a touch event so it is delivered to
324 * {@link View#onGenericMotionEvent(MotionEvent)} rather than
325 * {@link View#onTouchEvent(MotionEvent)}.
326 * </p>
327 */
328 public static final int ACTION_HOVER_EXIT = 10;
329
330 /**
Michael Wright5bd69e62015-05-14 14:48:08 +0100331 * Constant for {@link #getActionMasked}: A button has been pressed.
332 *
333 * <p>
334 * Use {@link #getActionButton()} to get which button was pressed.
335 * </p><p>
336 * This action is not a touch event so it is delivered to
337 * {@link View#onGenericMotionEvent(MotionEvent)} rather than
338 * {@link View#onTouchEvent(MotionEvent)}.
339 * </p>
340 */
341 public static final int ACTION_BUTTON_PRESS = 11;
342
343 /**
344 * Constant for {@link #getActionMasked}: A button has been released.
345 *
346 * <p>
347 * Use {@link #getActionButton()} to get which button was released.
348 * </p><p>
349 * This action is not a touch event so it is delivered to
350 * {@link View#onGenericMotionEvent(MotionEvent)} rather than
351 * {@link View#onTouchEvent(MotionEvent)}.
352 * </p>
353 */
354 public static final int ACTION_BUTTON_RELEASE = 12;
355
356 /**
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800357 * Bits in the action code that represent a pointer index, used with
358 * {@link #ACTION_POINTER_DOWN} and {@link #ACTION_POINTER_UP}. Shifting
359 * down by {@link #ACTION_POINTER_INDEX_SHIFT} provides the actual pointer
360 * index where the data for the pointer going up or down can be found; you can
361 * get its identifier with {@link #getPointerId(int)} and the actual
362 * data with {@link #getX(int)} etc.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700363 *
364 * @see #getActionIndex
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700365 */
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800366 public static final int ACTION_POINTER_INDEX_MASK = 0xff00;
Dennis Kempinac1b31d2016-11-02 17:02:25 -0700367
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800368 /**
369 * Bit shift for the action bits holding the pointer index as
370 * defined by {@link #ACTION_POINTER_INDEX_MASK}.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700371 *
372 * @see #getActionIndex
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800373 */
374 public static final int ACTION_POINTER_INDEX_SHIFT = 8;
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700375
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800376 /**
377 * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the
378 * data index associated with {@link #ACTION_POINTER_DOWN}.
379 */
380 @Deprecated
381 public static final int ACTION_POINTER_1_DOWN = ACTION_POINTER_DOWN | 0x0000;
Dennis Kempinac1b31d2016-11-02 17:02:25 -0700382
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800383 /**
384 * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the
385 * data index associated with {@link #ACTION_POINTER_DOWN}.
386 */
387 @Deprecated
388 public static final int ACTION_POINTER_2_DOWN = ACTION_POINTER_DOWN | 0x0100;
Dennis Kempinac1b31d2016-11-02 17:02:25 -0700389
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800390 /**
391 * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the
392 * data index associated with {@link #ACTION_POINTER_DOWN}.
393 */
394 @Deprecated
395 public static final int ACTION_POINTER_3_DOWN = ACTION_POINTER_DOWN | 0x0200;
Dennis Kempinac1b31d2016-11-02 17:02:25 -0700396
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800397 /**
398 * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the
399 * data index associated with {@link #ACTION_POINTER_UP}.
400 */
401 @Deprecated
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700402 public static final int ACTION_POINTER_1_UP = ACTION_POINTER_UP | 0x0000;
Dennis Kempinac1b31d2016-11-02 17:02:25 -0700403
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700404 /**
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800405 * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the
406 * data index associated with {@link #ACTION_POINTER_UP}.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700407 */
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800408 @Deprecated
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700409 public static final int ACTION_POINTER_2_UP = ACTION_POINTER_UP | 0x0100;
Dennis Kempinac1b31d2016-11-02 17:02:25 -0700410
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700411 /**
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800412 * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the
413 * data index associated with {@link #ACTION_POINTER_UP}.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700414 */
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800415 @Deprecated
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700416 public static final int ACTION_POINTER_3_UP = ACTION_POINTER_UP | 0x0200;
Dennis Kempinac1b31d2016-11-02 17:02:25 -0700417
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700418 /**
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800419 * @deprecated Renamed to {@link #ACTION_POINTER_INDEX_MASK} to match
420 * the actual data contained in these bits.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700421 */
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800422 @Deprecated
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700423 public static final int ACTION_POINTER_ID_MASK = 0xff00;
Dennis Kempinac1b31d2016-11-02 17:02:25 -0700424
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700425 /**
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800426 * @deprecated Renamed to {@link #ACTION_POINTER_INDEX_SHIFT} to match
427 * the actual data contained in these bits.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700428 */
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800429 @Deprecated
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700430 public static final int ACTION_POINTER_ID_SHIFT = 8;
Dennis Kempinac1b31d2016-11-02 17:02:25 -0700431
Jeff Brown85a31762010-09-01 17:01:00 -0700432 /**
433 * This flag indicates that the window that received this motion event is partly
Siarhei Vishniakou3a6a4112019-01-30 10:15:12 -0800434 * or wholly obscured by another visible window above it. This flag is set to true
435 * if the event directly passed through the obscured area.
436 *
Jeff Brown85a31762010-09-01 17:01:00 -0700437 * A security sensitive application can check this flag to identify situations in which
438 * a malicious application may have covered up part of its content for the purpose
439 * of misleading the user or hijacking touches. An appropriate response might be
440 * to drop the suspect touches or to take additional precautions to confirm the user's
441 * actual intent.
442 */
443 public static final int FLAG_WINDOW_IS_OBSCURED = 0x1;
Romain Guycafdea62009-06-12 10:51:36 -0700444
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800445 /**
Michael Wright0625e112016-03-30 17:31:48 -0700446 * This flag indicates that the window that received this motion event is partly
Siarhei Vishniakou3a6a4112019-01-30 10:15:12 -0800447 * or wholly obscured by another visible window above it. This flag is set to true
Michael Wright0625e112016-03-30 17:31:48 -0700448 * even if the event did not directly pass through the obscured area.
Siarhei Vishniakou3a6a4112019-01-30 10:15:12 -0800449 *
Michael Wright0625e112016-03-30 17:31:48 -0700450 * A security sensitive application can check this flag to identify situations in which
451 * a malicious application may have covered up part of its content for the purpose
452 * of misleading the user or hijacking touches. An appropriate response might be
453 * to drop the suspect touches or to take additional precautions to confirm the user's
454 * actual intent.
455 *
Siarhei Vishniakou3a6a4112019-01-30 10:15:12 -0800456 * Unlike FLAG_WINDOW_IS_OBSCURED, this is true even if the window that received this event is
457 * obstructed in areas other than the touched location.
Michael Wright0625e112016-03-30 17:31:48 -0700458 */
459 public static final int FLAG_WINDOW_IS_PARTIALLY_OBSCURED = 0x2;
460
461 /**
Vladislav Kaznacheev5a77c372016-10-10 16:11:15 -0700462 * This private flag is only set on {@link #ACTION_HOVER_MOVE} events and indicates that
463 * this event will be immediately followed by a {@link #ACTION_HOVER_EXIT}. It is used to
464 * prevent generating redundant {@link #ACTION_HOVER_ENTER} events.
465 * @hide
466 */
467 public static final int FLAG_HOVER_EXIT_PENDING = 0x4;
468
469 /**
Dennis Kempinac1b31d2016-11-02 17:02:25 -0700470 * This flag indicates that the event has been generated by a gesture generator. It
Siarhei Vishniakoub05b0b52018-12-28 17:50:24 -0800471 * provides a hint to the GestureDetector to not apply any touch slop.
Dennis Kempinac1b31d2016-11-02 17:02:25 -0700472 *
473 * @hide
474 */
475 public static final int FLAG_IS_GENERATED_GESTURE = 0x8;
476
477 /**
Jeff Brown21bc5c92011-02-28 18:27:14 -0800478 * Private flag that indicates when the system has detected that this motion event
479 * may be inconsistent with respect to the sequence of previously delivered motion events,
480 * such as when a pointer move event is sent but the pointer is not down.
481 *
482 * @hide
483 * @see #isTainted
484 * @see #setTainted
485 */
486 public static final int FLAG_TAINTED = 0x80000000;
487
488 /**
Svetoslavded133c2015-01-30 20:28:41 -0800489 * Private flag indicating that this event was synthesized by the system and
490 * should be delivered to the accessibility focused view first. When being
491 * dispatched such an event is not handled by predecessors of the accessibility
492 * focused view and after the event reaches that view the flag is cleared and
493 * normal event dispatch is performed. This ensures that the platform can click
494 * on any view that has accessibility focus which is semantically equivalent to
495 * asking the view to perform a click accessibility action but more generic as
496 * views not implementing click action correctly can still be activated.
497 *
498 * @hide
499 * @see #isTargetAccessibilityFocus()
500 * @see #setTargetAccessibilityFocus(boolean)
501 */
502 public static final int FLAG_TARGET_ACCESSIBILITY_FOCUS = 0x40000000;
503
504
505 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800506 * Flag indicating the motion event intersected the top edge of the screen.
507 */
508 public static final int EDGE_TOP = 0x00000001;
Romain Guycafdea62009-06-12 10:51:36 -0700509
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800510 /**
511 * Flag indicating the motion event intersected the bottom edge of the screen.
512 */
513 public static final int EDGE_BOTTOM = 0x00000002;
Romain Guycafdea62009-06-12 10:51:36 -0700514
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800515 /**
516 * Flag indicating the motion event intersected the left edge of the screen.
517 */
518 public static final int EDGE_LEFT = 0x00000004;
Romain Guycafdea62009-06-12 10:51:36 -0700519
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800520 /**
521 * Flag indicating the motion event intersected the right edge of the screen.
522 */
523 public static final int EDGE_RIGHT = 0x00000008;
Romain Guycafdea62009-06-12 10:51:36 -0700524
Jeff Brown91c69ab2011-02-14 17:03:18 -0800525 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700526 * Axis constant: X axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800527 * <p>
528 * <ul>
529 * <li>For a touch screen, reports the absolute X screen position of the center of
530 * the touch contact area. The units are display pixels.
531 * <li>For a touch pad, reports the absolute X surface position of the center of the touch
Jeff Browncc0c1592011-02-19 05:07:28 -0800532 * contact area. The units are device-dependent; use {@link InputDevice#getMotionRange(int)}
533 * to query the effective range of values.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800534 * <li>For a mouse, reports the absolute X screen position of the mouse pointer.
535 * The units are display pixels.
536 * <li>For a trackball, reports the relative horizontal displacement of the trackball.
537 * The value is normalized to a range from -1.0 (left) to 1.0 (right).
538 * <li>For a joystick, reports the absolute X position of the joystick.
539 * The value is normalized to a range from -1.0 (left) to 1.0 (right).
540 * </ul>
541 * </p>
Jeff Brown91c69ab2011-02-14 17:03:18 -0800542 *
543 * @see #getX(int)
544 * @see #getHistoricalX(int, int)
545 * @see MotionEvent.PointerCoords#x
546 * @see InputDevice#getMotionRange
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700547 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800548 public static final int AXIS_X = 0;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700549
Jeff Brown91c69ab2011-02-14 17:03:18 -0800550 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700551 * Axis constant: Y axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800552 * <p>
553 * <ul>
554 * <li>For a touch screen, reports the absolute Y screen position of the center of
555 * the touch contact area. The units are display pixels.
556 * <li>For a touch pad, reports the absolute Y surface position of the center of the touch
557 * contact area. The units are device-dependent; use {@link InputDevice#getMotionRange(int)}
558 * to query the effective range of values.
559 * <li>For a mouse, reports the absolute Y screen position of the mouse pointer.
560 * The units are display pixels.
561 * <li>For a trackball, reports the relative vertical displacement of the trackball.
562 * The value is normalized to a range from -1.0 (up) to 1.0 (down).
563 * <li>For a joystick, reports the absolute Y position of the joystick.
564 * The value is normalized to a range from -1.0 (up or far) to 1.0 (down or near).
565 * </ul>
566 * </p>
Jeff Brown91c69ab2011-02-14 17:03:18 -0800567 *
568 * @see #getY(int)
569 * @see #getHistoricalY(int, int)
570 * @see MotionEvent.PointerCoords#y
571 * @see InputDevice#getMotionRange
Jeff Brownc5ed5912010-07-14 18:48:53 -0700572 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800573 public static final int AXIS_Y = 1;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700574
Jeff Brown91c69ab2011-02-14 17:03:18 -0800575 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700576 * Axis constant: Pressure axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800577 * <p>
578 * <ul>
Jeff Browncc0c1592011-02-19 05:07:28 -0800579 * <li>For a touch screen or touch pad, reports the approximate pressure applied to the surface
Jeff Brown6f2fba42011-02-19 01:08:02 -0800580 * by a finger or other tool. The value is normalized to a range from
581 * 0 (no pressure at all) to 1 (normal pressure), although values higher than 1
582 * may be generated depending on the calibration of the input device.
583 * <li>For a trackball, the value is set to 1 if the trackball button is pressed
584 * or 0 otherwise.
585 * <li>For a mouse, the value is set to 1 if the primary mouse button is pressed
586 * or 0 otherwise.
587 * </ul>
588 * </p>
Jeff Brown91c69ab2011-02-14 17:03:18 -0800589 *
590 * @see #getPressure(int)
591 * @see #getHistoricalPressure(int, int)
592 * @see MotionEvent.PointerCoords#pressure
593 * @see InputDevice#getMotionRange
Jeff Brownc5ed5912010-07-14 18:48:53 -0700594 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800595 public static final int AXIS_PRESSURE = 2;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700596
Jeff Brown91c69ab2011-02-14 17:03:18 -0800597 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700598 * Axis constant: Size axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800599 * <p>
600 * <ul>
601 * <li>For a touch screen or touch pad, reports the approximate size of the contact area in
602 * relation to the maximum detectable size for the device. The value is normalized
603 * to a range from 0 (smallest detectable size) to 1 (largest detectable size),
Jeff Browncc0c1592011-02-19 05:07:28 -0800604 * although it is not a linear scale. This value is of limited use.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800605 * To obtain calibrated size information, use
606 * {@link #AXIS_TOUCH_MAJOR} or {@link #AXIS_TOOL_MAJOR}.
607 * </ul>
608 * </p>
Jeff Brown91c69ab2011-02-14 17:03:18 -0800609 *
610 * @see #getSize(int)
611 * @see #getHistoricalSize(int, int)
612 * @see MotionEvent.PointerCoords#size
613 * @see InputDevice#getMotionRange
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700614 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800615 public static final int AXIS_SIZE = 3;
616
617 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700618 * Axis constant: TouchMajor axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800619 * <p>
620 * <ul>
621 * <li>For a touch screen, reports the length of the major axis of an ellipse that
622 * represents the touch area at the point of contact.
623 * The units are display pixels.
624 * <li>For a touch pad, reports the length of the major axis of an ellipse that
625 * represents the touch area at the point of contact.
626 * The units are device-dependent; use {@link InputDevice#getMotionRange(int)}
627 * to query the effective range of values.
628 * </ul>
629 * </p>
Jeff Brown91c69ab2011-02-14 17:03:18 -0800630 *
631 * @see #getTouchMajor(int)
632 * @see #getHistoricalTouchMajor(int, int)
633 * @see MotionEvent.PointerCoords#touchMajor
634 * @see InputDevice#getMotionRange
Dianne Hackborn1e8dfc72009-08-06 12:43:01 -0700635 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800636 public static final int AXIS_TOUCH_MAJOR = 4;
637
638 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700639 * Axis constant: TouchMinor axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800640 * <p>
641 * <ul>
642 * <li>For a touch screen, reports the length of the minor axis of an ellipse that
643 * represents the touch area at the point of contact.
644 * The units are display pixels.
645 * <li>For a touch pad, reports the length of the minor axis of an ellipse that
646 * represents the touch area at the point of contact.
647 * The units are device-dependent; use {@link InputDevice#getMotionRange(int)}
648 * to query the effective range of values.
649 * </ul>
650 * </p><p>
651 * When the touch is circular, the major and minor axis lengths will be equal to one another.
652 * </p>
Jeff Brown91c69ab2011-02-14 17:03:18 -0800653 *
654 * @see #getTouchMinor(int)
655 * @see #getHistoricalTouchMinor(int, int)
656 * @see MotionEvent.PointerCoords#touchMinor
657 * @see InputDevice#getMotionRange
Jeff Brown9e2ad362010-07-30 19:20:11 -0700658 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800659 public static final int AXIS_TOUCH_MINOR = 5;
660
661 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700662 * Axis constant: ToolMajor axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800663 * <p>
664 * <ul>
665 * <li>For a touch screen, reports the length of the major axis of an ellipse that
666 * represents the size of the approaching finger or tool used to make contact.
667 * <li>For a touch pad, reports the length of the major axis of an ellipse that
668 * represents the size of the approaching finger or tool used to make contact.
669 * The units are device-dependent; use {@link InputDevice#getMotionRange(int)}
670 * to query the effective range of values.
671 * </ul>
672 * </p><p>
673 * When the touch is circular, the major and minor axis lengths will be equal to one another.
674 * </p><p>
675 * The tool size may be larger than the touch size since the tool may not be fully
676 * in contact with the touch sensor.
677 * </p>
Jeff Brown91c69ab2011-02-14 17:03:18 -0800678 *
679 * @see #getToolMajor(int)
680 * @see #getHistoricalToolMajor(int, int)
681 * @see MotionEvent.PointerCoords#toolMajor
682 * @see InputDevice#getMotionRange
683 */
684 public static final int AXIS_TOOL_MAJOR = 6;
685
686 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700687 * Axis constant: ToolMinor axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800688 * <p>
689 * <ul>
690 * <li>For a touch screen, reports the length of the minor axis of an ellipse that
691 * represents the size of the approaching finger or tool used to make contact.
692 * <li>For a touch pad, reports the length of the minor axis of an ellipse that
693 * represents the size of the approaching finger or tool used to make contact.
694 * The units are device-dependent; use {@link InputDevice#getMotionRange(int)}
695 * to query the effective range of values.
696 * </ul>
697 * </p><p>
698 * When the touch is circular, the major and minor axis lengths will be equal to one another.
699 * </p><p>
700 * The tool size may be larger than the touch size since the tool may not be fully
701 * in contact with the touch sensor.
702 * </p>
Jeff Brown91c69ab2011-02-14 17:03:18 -0800703 *
704 * @see #getToolMinor(int)
705 * @see #getHistoricalToolMinor(int, int)
706 * @see MotionEvent.PointerCoords#toolMinor
707 * @see InputDevice#getMotionRange
708 */
709 public static final int AXIS_TOOL_MINOR = 7;
710
711 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700712 * Axis constant: Orientation axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800713 * <p>
714 * <ul>
715 * <li>For a touch screen or touch pad, reports the orientation of the finger
716 * or tool in radians relative to the vertical plane of the device.
717 * An angle of 0 radians indicates that the major axis of contact is oriented
Jeff Brown91c69ab2011-02-14 17:03:18 -0800718 * upwards, is perfectly circular or is of unknown orientation. A positive angle
719 * indicates that the major axis of contact is oriented to the right. A negative angle
720 * indicates that the major axis of contact is oriented to the left.
721 * The full range is from -PI/2 radians (finger pointing fully left) to PI/2 radians
722 * (finger pointing fully right).
Jeff Brown65fd2512011-08-18 11:20:58 -0700723 * <li>For a stylus, the orientation indicates the direction in which the stylus
724 * is pointing in relation to the vertical axis of the current orientation of the screen.
725 * The range is from -PI radians to PI radians, where 0 is pointing up,
726 * -PI/2 radians is pointing left, -PI or PI radians is pointing down, and PI/2 radians
727 * is pointing right. See also {@link #AXIS_TILT}.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800728 * </ul>
729 * </p>
Jeff Brown91c69ab2011-02-14 17:03:18 -0800730 *
731 * @see #getOrientation(int)
732 * @see #getHistoricalOrientation(int, int)
733 * @see MotionEvent.PointerCoords#orientation
734 * @see InputDevice#getMotionRange
735 */
736 public static final int AXIS_ORIENTATION = 8;
737
Jeff Brown6f2fba42011-02-19 01:08:02 -0800738 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700739 * Axis constant: Vertical Scroll axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800740 * <p>
741 * <ul>
Jeff Browncc0c1592011-02-19 05:07:28 -0800742 * <li>For a mouse, reports the relative movement of the vertical scroll wheel.
Jeff Brown33bbfd22011-02-24 20:55:35 -0800743 * The value is normalized to a range from -1.0 (down) to 1.0 (up).
Jeff Brown6f2fba42011-02-19 01:08:02 -0800744 * </ul>
745 * </p><p>
746 * This axis should be used to scroll views vertically.
747 * </p>
748 *
749 * @see #getAxisValue(int, int)
750 * @see #getHistoricalAxisValue(int, int, int)
751 * @see MotionEvent.PointerCoords#getAxisValue(int)
752 * @see InputDevice#getMotionRange
753 */
754 public static final int AXIS_VSCROLL = 9;
755
756 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700757 * Axis constant: Horizontal Scroll axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800758 * <p>
759 * <ul>
Jeff Browncc0c1592011-02-19 05:07:28 -0800760 * <li>For a mouse, reports the relative movement of the horizontal scroll wheel.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800761 * The value is normalized to a range from -1.0 (left) to 1.0 (right).
762 * </ul>
763 * </p><p>
764 * This axis should be used to scroll views horizontally.
765 * </p>
766 *
767 * @see #getAxisValue(int, int)
768 * @see #getHistoricalAxisValue(int, int, int)
769 * @see MotionEvent.PointerCoords#getAxisValue(int)
770 * @see InputDevice#getMotionRange
771 */
772 public static final int AXIS_HSCROLL = 10;
773
774 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700775 * Axis constant: Z axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800776 * <p>
777 * <ul>
778 * <li>For a joystick, reports the absolute Z position of the joystick.
779 * The value is normalized to a range from -1.0 (high) to 1.0 (low).
780 * <em>On game pads with two analog joysticks, this axis is often reinterpreted
781 * to report the absolute X position of the second joystick instead.</em>
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_Z = 11;
791
792 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700793 * Axis constant: X 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 X 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_RX = 12;
807
808 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700809 * Axis constant: Y 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 Y axis.
813 * The value is normalized to a range from -1.0 (counter-clockwise) to 1.0 (clockwise).
814 * </ul>
815 * </p>
816 *
817 * @see #getAxisValue(int, int)
818 * @see #getHistoricalAxisValue(int, int, int)
819 * @see MotionEvent.PointerCoords#getAxisValue(int)
820 * @see InputDevice#getMotionRange
821 */
822 public static final int AXIS_RY = 13;
823
824 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700825 * Axis constant: Z Rotation axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800826 * <p>
827 * <ul>
828 * <li>For a joystick, reports the absolute rotation angle about the Z axis.
829 * The value is normalized to a range from -1.0 (counter-clockwise) to 1.0 (clockwise).
830 * <em>On game pads with two analog joysticks, this axis is often reinterpreted
831 * to report the absolute Y position of the second joystick instead.</em>
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_RZ = 14;
841
842 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700843 * Axis constant: Hat X axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800844 * <p>
845 * <ul>
846 * <li>For a joystick, reports the absolute X position of the directional hat control.
847 * The value is normalized to a range from -1.0 (left) to 1.0 (right).
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_X = 15;
857
858 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700859 * Axis constant: Hat Y axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800860 * <p>
861 * <ul>
862 * <li>For a joystick, reports the absolute Y position of the directional hat control.
863 * The value is normalized to a range from -1.0 (up) to 1.0 (down).
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_HAT_Y = 16;
873
874 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700875 * Axis constant: Left 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 left 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_LTRIGGER = 17;
889
890 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700891 * Axis constant: Right Trigger axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800892 * <p>
893 * <ul>
894 * <li>For a joystick, reports the absolute position of the right trigger control.
895 * The value is normalized to a range from 0.0 (released) to 1.0 (fully pressed).
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_RTRIGGER = 18;
905
906 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700907 * Axis constant: Throttle 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 throttle control.
911 * The value is normalized to a range from 0.0 (fully open) to 1.0 (fully closed).
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_THROTTLE = 19;
921
922 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700923 * Axis constant: Rudder 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 rudder 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_RUDDER = 20;
937
938 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700939 * Axis constant: Wheel 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 steering wheel control.
943 * The value is normalized to a range from -1.0 (turn left) to 1.0 (turn right).
944 * </ul>
945 * </p>
946 *
947 * @see #getAxisValue(int, int)
948 * @see #getHistoricalAxisValue(int, int, int)
949 * @see MotionEvent.PointerCoords#getAxisValue(int)
950 * @see InputDevice#getMotionRange
951 */
952 public static final int AXIS_WHEEL = 21;
953
954 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700955 * Axis constant: Gas axis of a motion event.
Jeff Brown3a22fa02011-03-04 13:07:49 -0800956 * <p>
957 * <ul>
958 * <li>For a joystick, reports the absolute position of the gas (accelerator) control.
959 * The value is normalized to a range from 0.0 (no acceleration)
960 * to 1.0 (maximum acceleration).
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_GAS = 22;
970
971 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700972 * Axis constant: Brake axis of a motion event.
Jeff Brown3a22fa02011-03-04 13:07:49 -0800973 * <p>
974 * <ul>
975 * <li>For a joystick, reports the absolute position of the brake control.
976 * The value is normalized to a range from 0.0 (no braking) to 1.0 (maximum braking).
977 * </ul>
978 * </p>
979 *
980 * @see #getAxisValue(int, int)
981 * @see #getHistoricalAxisValue(int, int, int)
982 * @see MotionEvent.PointerCoords#getAxisValue(int)
983 * @see InputDevice#getMotionRange
984 */
985 public static final int AXIS_BRAKE = 23;
986
987 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700988 * Axis constant: Distance axis of a motion event.
989 * <p>
990 * <ul>
991 * <li>For a stylus, reports the distance of the stylus from the screen.
Jeff Brown65fd2512011-08-18 11:20:58 -0700992 * A value of 0.0 indicates direct contact and larger values indicate increasing
993 * distance from the surface.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700994 * </ul>
995 * </p>
996 *
997 * @see #getAxisValue(int, int)
998 * @see #getHistoricalAxisValue(int, int, int)
999 * @see MotionEvent.PointerCoords#getAxisValue(int)
1000 * @see InputDevice#getMotionRange
1001 */
1002 public static final int AXIS_DISTANCE = 24;
1003
1004 /**
Jeff Brown65fd2512011-08-18 11:20:58 -07001005 * Axis constant: Tilt axis of a motion event.
1006 * <p>
1007 * <ul>
1008 * <li>For a stylus, reports the tilt angle of the stylus in radians where
1009 * 0 radians indicates that the stylus is being held perpendicular to the
1010 * surface, and PI/2 radians indicates that the stylus is being held flat
1011 * against the surface.
1012 * </ul>
1013 * </p>
1014 *
1015 * @see #getAxisValue(int, int)
1016 * @see #getHistoricalAxisValue(int, int, int)
1017 * @see MotionEvent.PointerCoords#getAxisValue(int, int)
1018 * @see InputDevice#getMotionRange
1019 */
1020 public static final int AXIS_TILT = 25;
1021
1022 /**
Prashant Malani67322b12015-08-25 17:41:34 -07001023 * Axis constant: Generic scroll axis of a motion event.
1024 * <p>
1025 * <ul>
1026 * <li>Reports the relative movement of the generic scrolling device.
1027 * </ul>
1028 * </p><p>
1029 * This axis should be used for scroll events that are neither strictly vertical nor horizontal.
1030 * A good example would be the rotation of a rotary encoder input device.
1031 * </p>
1032 *
1033 * @see #getAxisValue(int, int)
Prashant Malani67322b12015-08-25 17:41:34 -07001034 */
1035 public static final int AXIS_SCROLL = 26;
1036
1037 /**
Jun Mukai347e5d42015-12-03 01:13:31 -08001038 * Axis constant: The movement of x position of a motion event.
1039 * <p>
1040 * <ul>
1041 * <li>For a mouse, reports a difference of x position between the previous position.
1042 * This is useful when pointer is captured, in that case the mouse pointer doesn't change
1043 * the location but this axis reports the difference which allows the app to see
1044 * how the mouse is moved.
1045 * </ul>
1046 * </p>
1047 *
1048 * @see #getAxisValue(int, int)
1049 * @see #getHistoricalAxisValue(int, int, int)
1050 * @see MotionEvent.PointerCoords#getAxisValue(int, int)
1051 * @see InputDevice#getMotionRange
1052 */
1053 public static final int AXIS_RELATIVE_X = 27;
1054
1055 /**
1056 * Axis constant: The movement of y position of a motion event.
1057 * <p>
1058 * This is similar to {@link #AXIS_RELATIVE_X} but for y-axis.
1059 * </p>
1060 *
1061 * @see #getAxisValue(int, int)
1062 * @see #getHistoricalAxisValue(int, int, int)
1063 * @see MotionEvent.PointerCoords#getAxisValue(int, int)
1064 * @see InputDevice#getMotionRange
1065 */
1066 public static final int AXIS_RELATIVE_Y = 28;
1067
1068 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001069 * Axis constant: Generic 1 axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -08001070 * The interpretation of a generic axis is device-specific.
1071 *
1072 * @see #getAxisValue(int, int)
1073 * @see #getHistoricalAxisValue(int, int, int)
1074 * @see MotionEvent.PointerCoords#getAxisValue(int)
1075 * @see InputDevice#getMotionRange
1076 */
1077 public static final int AXIS_GENERIC_1 = 32;
1078
1079 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001080 * Axis constant: Generic 2 axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -08001081 * The interpretation of a generic axis is device-specific.
1082 *
1083 * @see #getAxisValue(int, int)
1084 * @see #getHistoricalAxisValue(int, int, int)
1085 * @see MotionEvent.PointerCoords#getAxisValue(int)
1086 * @see InputDevice#getMotionRange
1087 */
1088 public static final int AXIS_GENERIC_2 = 33;
1089
1090 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001091 * Axis constant: Generic 3 axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -08001092 * The interpretation of a generic axis is device-specific.
1093 *
1094 * @see #getAxisValue(int, int)
1095 * @see #getHistoricalAxisValue(int, int, int)
1096 * @see MotionEvent.PointerCoords#getAxisValue(int)
1097 * @see InputDevice#getMotionRange
1098 */
1099 public static final int AXIS_GENERIC_3 = 34;
1100
1101 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001102 * Axis constant: Generic 4 axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -08001103 * The interpretation of a generic axis is device-specific.
1104 *
1105 * @see #getAxisValue(int, int)
1106 * @see #getHistoricalAxisValue(int, int, int)
1107 * @see MotionEvent.PointerCoords#getAxisValue(int)
1108 * @see InputDevice#getMotionRange
1109 */
1110 public static final int AXIS_GENERIC_4 = 35;
1111
1112 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001113 * Axis constant: Generic 5 axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -08001114 * The interpretation of a generic axis is device-specific.
1115 *
1116 * @see #getAxisValue(int, int)
1117 * @see #getHistoricalAxisValue(int, int, int)
1118 * @see MotionEvent.PointerCoords#getAxisValue(int)
1119 * @see InputDevice#getMotionRange
1120 */
1121 public static final int AXIS_GENERIC_5 = 36;
1122
1123 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001124 * Axis constant: Generic 6 axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -08001125 * The interpretation of a generic axis is device-specific.
1126 *
1127 * @see #getAxisValue(int, int)
1128 * @see #getHistoricalAxisValue(int, int, int)
1129 * @see MotionEvent.PointerCoords#getAxisValue(int)
1130 * @see InputDevice#getMotionRange
1131 */
1132 public static final int AXIS_GENERIC_6 = 37;
1133
1134 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001135 * Axis constant: Generic 7 axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -08001136 * The interpretation of a generic axis is device-specific.
1137 *
1138 * @see #getAxisValue(int, int)
1139 * @see #getHistoricalAxisValue(int, int, int)
1140 * @see MotionEvent.PointerCoords#getAxisValue(int)
1141 * @see InputDevice#getMotionRange
1142 */
1143 public static final int AXIS_GENERIC_7 = 38;
1144
1145 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001146 * Axis constant: Generic 8 axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -08001147 * The interpretation of a generic axis is device-specific.
1148 *
1149 * @see #getAxisValue(int, int)
1150 * @see #getHistoricalAxisValue(int, int, int)
1151 * @see MotionEvent.PointerCoords#getAxisValue(int)
1152 * @see InputDevice#getMotionRange
1153 */
1154 public static final int AXIS_GENERIC_8 = 39;
1155
1156 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001157 * Axis constant: Generic 9 axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -08001158 * The interpretation of a generic axis is device-specific.
1159 *
1160 * @see #getAxisValue(int, int)
1161 * @see #getHistoricalAxisValue(int, int, int)
1162 * @see MotionEvent.PointerCoords#getAxisValue(int)
1163 * @see InputDevice#getMotionRange
1164 */
1165 public static final int AXIS_GENERIC_9 = 40;
1166
1167 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001168 * Axis constant: Generic 10 axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -08001169 * The interpretation of a generic axis is device-specific.
1170 *
1171 * @see #getAxisValue(int, int)
1172 * @see #getHistoricalAxisValue(int, int, int)
1173 * @see MotionEvent.PointerCoords#getAxisValue(int)
1174 * @see InputDevice#getMotionRange
1175 */
1176 public static final int AXIS_GENERIC_10 = 41;
1177
1178 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001179 * Axis constant: Generic 11 axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -08001180 * The interpretation of a generic axis is device-specific.
1181 *
1182 * @see #getAxisValue(int, int)
1183 * @see #getHistoricalAxisValue(int, int, int)
1184 * @see MotionEvent.PointerCoords#getAxisValue(int)
1185 * @see InputDevice#getMotionRange
1186 */
1187 public static final int AXIS_GENERIC_11 = 42;
1188
1189 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001190 * Axis constant: Generic 12 axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -08001191 * The interpretation of a generic axis is device-specific.
1192 *
1193 * @see #getAxisValue(int, int)
1194 * @see #getHistoricalAxisValue(int, int, int)
1195 * @see MotionEvent.PointerCoords#getAxisValue(int)
1196 * @see InputDevice#getMotionRange
1197 */
1198 public static final int AXIS_GENERIC_12 = 43;
1199
1200 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001201 * Axis constant: Generic 13 axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -08001202 * The interpretation of a generic axis is device-specific.
1203 *
1204 * @see #getAxisValue(int, int)
1205 * @see #getHistoricalAxisValue(int, int, int)
1206 * @see MotionEvent.PointerCoords#getAxisValue(int)
1207 * @see InputDevice#getMotionRange
1208 */
1209 public static final int AXIS_GENERIC_13 = 44;
1210
1211 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001212 * Axis constant: Generic 14 axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -08001213 * The interpretation of a generic axis is device-specific.
1214 *
1215 * @see #getAxisValue(int, int)
1216 * @see #getHistoricalAxisValue(int, int, int)
1217 * @see MotionEvent.PointerCoords#getAxisValue(int)
1218 * @see InputDevice#getMotionRange
1219 */
1220 public static final int AXIS_GENERIC_14 = 45;
1221
1222 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001223 * Axis constant: Generic 15 axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -08001224 * The interpretation of a generic axis is device-specific.
1225 *
1226 * @see #getAxisValue(int, int)
1227 * @see #getHistoricalAxisValue(int, int, int)
1228 * @see MotionEvent.PointerCoords#getAxisValue(int)
1229 * @see InputDevice#getMotionRange
1230 */
1231 public static final int AXIS_GENERIC_15 = 46;
1232
1233 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001234 * Axis constant: Generic 16 axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -08001235 * The interpretation of a generic axis is device-specific.
1236 *
1237 * @see #getAxisValue(int, int)
1238 * @see #getHistoricalAxisValue(int, int, int)
1239 * @see MotionEvent.PointerCoords#getAxisValue(int)
1240 * @see InputDevice#getMotionRange
1241 */
1242 public static final int AXIS_GENERIC_16 = 47;
1243
1244 // NOTE: If you add a new axis here you must also add it to:
1245 // native/include/android/input.h
1246 // frameworks/base/include/ui/KeycodeLabels.h
1247
1248 // Symbolic names of all axes.
1249 private static final SparseArray<String> AXIS_SYMBOLIC_NAMES = new SparseArray<String>();
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001250 static {
Jeff Brown6f2fba42011-02-19 01:08:02 -08001251 SparseArray<String> names = AXIS_SYMBOLIC_NAMES;
1252 names.append(AXIS_X, "AXIS_X");
1253 names.append(AXIS_Y, "AXIS_Y");
1254 names.append(AXIS_PRESSURE, "AXIS_PRESSURE");
1255 names.append(AXIS_SIZE, "AXIS_SIZE");
1256 names.append(AXIS_TOUCH_MAJOR, "AXIS_TOUCH_MAJOR");
1257 names.append(AXIS_TOUCH_MINOR, "AXIS_TOUCH_MINOR");
1258 names.append(AXIS_TOOL_MAJOR, "AXIS_TOOL_MAJOR");
1259 names.append(AXIS_TOOL_MINOR, "AXIS_TOOL_MINOR");
1260 names.append(AXIS_ORIENTATION, "AXIS_ORIENTATION");
1261 names.append(AXIS_VSCROLL, "AXIS_VSCROLL");
1262 names.append(AXIS_HSCROLL, "AXIS_HSCROLL");
1263 names.append(AXIS_Z, "AXIS_Z");
1264 names.append(AXIS_RX, "AXIS_RX");
1265 names.append(AXIS_RY, "AXIS_RY");
1266 names.append(AXIS_RZ, "AXIS_RZ");
1267 names.append(AXIS_HAT_X, "AXIS_HAT_X");
1268 names.append(AXIS_HAT_Y, "AXIS_HAT_Y");
1269 names.append(AXIS_LTRIGGER, "AXIS_LTRIGGER");
1270 names.append(AXIS_RTRIGGER, "AXIS_RTRIGGER");
Jeff Brown3a22fa02011-03-04 13:07:49 -08001271 names.append(AXIS_THROTTLE, "AXIS_THROTTLE");
1272 names.append(AXIS_RUDDER, "AXIS_RUDDER");
1273 names.append(AXIS_WHEEL, "AXIS_WHEEL");
1274 names.append(AXIS_GAS, "AXIS_GAS");
1275 names.append(AXIS_BRAKE, "AXIS_BRAKE");
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001276 names.append(AXIS_DISTANCE, "AXIS_DISTANCE");
Jeff Brown65fd2512011-08-18 11:20:58 -07001277 names.append(AXIS_TILT, "AXIS_TILT");
Prashant Malani67322b12015-08-25 17:41:34 -07001278 names.append(AXIS_SCROLL, "AXIS_SCROLL");
Jun Mukai347e5d42015-12-03 01:13:31 -08001279 names.append(AXIS_RELATIVE_X, "AXIS_REALTIVE_X");
1280 names.append(AXIS_RELATIVE_Y, "AXIS_REALTIVE_Y");
Jeff Brown6f2fba42011-02-19 01:08:02 -08001281 names.append(AXIS_GENERIC_1, "AXIS_GENERIC_1");
1282 names.append(AXIS_GENERIC_2, "AXIS_GENERIC_2");
1283 names.append(AXIS_GENERIC_3, "AXIS_GENERIC_3");
1284 names.append(AXIS_GENERIC_4, "AXIS_GENERIC_4");
1285 names.append(AXIS_GENERIC_5, "AXIS_GENERIC_5");
1286 names.append(AXIS_GENERIC_6, "AXIS_GENERIC_6");
1287 names.append(AXIS_GENERIC_7, "AXIS_GENERIC_7");
1288 names.append(AXIS_GENERIC_8, "AXIS_GENERIC_8");
1289 names.append(AXIS_GENERIC_9, "AXIS_GENERIC_9");
1290 names.append(AXIS_GENERIC_10, "AXIS_GENERIC_10");
1291 names.append(AXIS_GENERIC_11, "AXIS_GENERIC_11");
1292 names.append(AXIS_GENERIC_12, "AXIS_GENERIC_12");
1293 names.append(AXIS_GENERIC_13, "AXIS_GENERIC_13");
1294 names.append(AXIS_GENERIC_14, "AXIS_GENERIC_14");
1295 names.append(AXIS_GENERIC_15, "AXIS_GENERIC_15");
1296 names.append(AXIS_GENERIC_16, "AXIS_GENERIC_16");
1297 }
1298
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001299 /**
Jeff Brown49754db2011-07-01 17:37:58 -07001300 * Button constant: Primary button (left mouse button).
1301 *
1302 * This button constant is not set in response to simple touches with a finger
1303 * or stylus tip. The user must actually push a button.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001304 *
1305 * @see #getButtonState
1306 */
1307 public static final int BUTTON_PRIMARY = 1 << 0;
1308
1309 /**
Michael Wright5bd69e62015-05-14 14:48:08 +01001310 * Button constant: Secondary button (right mouse button).
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001311 *
1312 * @see #getButtonState
1313 */
1314 public static final int BUTTON_SECONDARY = 1 << 1;
1315
1316 /**
Michael Wright5bd69e62015-05-14 14:48:08 +01001317 * Button constant: Tertiary button (middle mouse button).
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001318 *
1319 * @see #getButtonState
1320 */
1321 public static final int BUTTON_TERTIARY = 1 << 2;
1322
1323 /**
1324 * Button constant: Back button pressed (mouse back button).
1325 * <p>
1326 * The system may send a {@link KeyEvent#KEYCODE_BACK} key press to the application
1327 * when this button is pressed.
1328 * </p>
1329 *
1330 * @see #getButtonState
1331 */
1332 public static final int BUTTON_BACK = 1 << 3;
1333
1334 /**
1335 * Button constant: Forward button pressed (mouse forward button).
1336 * <p>
1337 * The system may send a {@link KeyEvent#KEYCODE_FORWARD} key press to the application
1338 * when this button is pressed.
1339 * </p>
1340 *
1341 * @see #getButtonState
1342 */
1343 public static final int BUTTON_FORWARD = 1 << 4;
1344
Michael Wright5bd69e62015-05-14 14:48:08 +01001345 /**
1346 * Button constant: Primary stylus button pressed.
1347 *
1348 * @see #getButtonState
1349 */
1350 public static final int BUTTON_STYLUS_PRIMARY = 1 << 5;
1351
1352 /**
1353 * Button constant: Secondary stylus button pressed.
1354 *
1355 * @see #getButtonState
1356 */
1357 public static final int BUTTON_STYLUS_SECONDARY = 1 << 6;
1358
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001359 // NOTE: If you add a new axis here you must also add it to:
1360 // native/include/android/input.h
1361
1362 // Symbolic names of all button states in bit order from least significant
1363 // to most significant.
1364 private static final String[] BUTTON_SYMBOLIC_NAMES = new String[] {
1365 "BUTTON_PRIMARY",
1366 "BUTTON_SECONDARY",
1367 "BUTTON_TERTIARY",
1368 "BUTTON_BACK",
1369 "BUTTON_FORWARD",
Michael Wright5bd69e62015-05-14 14:48:08 +01001370 "BUTTON_STYLUS_PRIMARY",
1371 "BUTTON_STYLUS_SECONDARY",
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001372 "0x00000080",
1373 "0x00000100",
1374 "0x00000200",
1375 "0x00000400",
1376 "0x00000800",
1377 "0x00001000",
1378 "0x00002000",
1379 "0x00004000",
1380 "0x00008000",
1381 "0x00010000",
1382 "0x00020000",
1383 "0x00040000",
1384 "0x00080000",
1385 "0x00100000",
1386 "0x00200000",
1387 "0x00400000",
1388 "0x00800000",
1389 "0x01000000",
1390 "0x02000000",
1391 "0x04000000",
1392 "0x08000000",
1393 "0x10000000",
1394 "0x20000000",
1395 "0x40000000",
1396 "0x80000000",
1397 };
1398
1399 /**
Siarhei Vishniakoub05b0b52018-12-28 17:50:24 -08001400 * Classification constant: None.
1401 *
1402 * No additional information is available about the current motion event stream.
1403 *
1404 * @see #getClassification
1405 */
1406 public static final int CLASSIFICATION_NONE = 0;
1407
1408 /**
1409 * Classification constant: Ambiguous gesture.
1410 *
1411 * The user's intent with respect to the current event stream is not yet determined.
1412 * Gestural actions, such as scrolling, should be inhibited until the classification resolves
1413 * to another value or the event stream ends.
1414 *
1415 * @see #getClassification
1416 */
1417 public static final int CLASSIFICATION_AMBIGUOUS_GESTURE = 1;
1418
1419 /**
1420 * Classification constant: Deep press.
1421 *
1422 * The current event stream represents the user intentionally pressing harder on the screen.
1423 * This classification type should be used to accelerate the long press behaviour.
1424 *
1425 * @see #getClassification
1426 */
1427 public static final int CLASSIFICATION_DEEP_PRESS = 2;
1428
1429 /** @hide */
1430 @Retention(SOURCE)
1431 @IntDef(prefix = { "CLASSIFICATION" }, value = {
1432 CLASSIFICATION_NONE, CLASSIFICATION_AMBIGUOUS_GESTURE, CLASSIFICATION_DEEP_PRESS})
1433 public @interface Classification {};
1434
1435 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001436 * Tool type constant: Unknown tool type.
1437 * This constant is used when the tool type is not known or is not relevant,
1438 * such as for a trackball or other non-pointing device.
1439 *
1440 * @see #getToolType
1441 */
1442 public static final int TOOL_TYPE_UNKNOWN = 0;
1443
1444 /**
Jeff Brown49754db2011-07-01 17:37:58 -07001445 * Tool type constant: The tool is a finger.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001446 *
1447 * @see #getToolType
1448 */
1449 public static final int TOOL_TYPE_FINGER = 1;
1450
1451 /**
Jeff Brown49754db2011-07-01 17:37:58 -07001452 * Tool type constant: The tool is a stylus.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001453 *
1454 * @see #getToolType
1455 */
1456 public static final int TOOL_TYPE_STYLUS = 2;
1457
1458 /**
Jeff Brown49754db2011-07-01 17:37:58 -07001459 * Tool type constant: The tool is a mouse or trackpad.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001460 *
1461 * @see #getToolType
1462 */
1463 public static final int TOOL_TYPE_MOUSE = 3;
1464
1465 /**
Jeff Brown49754db2011-07-01 17:37:58 -07001466 * Tool type constant: The tool is an eraser or a stylus being used in an inverted posture.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001467 *
1468 * @see #getToolType
1469 */
Jeff Brown49754db2011-07-01 17:37:58 -07001470 public static final int TOOL_TYPE_ERASER = 4;
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001471
1472 // NOTE: If you add a new tool type here you must also add it to:
1473 // native/include/android/input.h
1474
1475 // Symbolic names of all tool types.
1476 private static final SparseArray<String> TOOL_TYPE_SYMBOLIC_NAMES = new SparseArray<String>();
Jeff Brown6f2fba42011-02-19 01:08:02 -08001477 static {
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001478 SparseArray<String> names = TOOL_TYPE_SYMBOLIC_NAMES;
1479 names.append(TOOL_TYPE_UNKNOWN, "TOOL_TYPE_UNKNOWN");
1480 names.append(TOOL_TYPE_FINGER, "TOOL_TYPE_FINGER");
1481 names.append(TOOL_TYPE_STYLUS, "TOOL_TYPE_STYLUS");
1482 names.append(TOOL_TYPE_MOUSE, "TOOL_TYPE_MOUSE");
Jeff Brown49754db2011-07-01 17:37:58 -07001483 names.append(TOOL_TYPE_ERASER, "TOOL_TYPE_ERASER");
Jeff Brown6f2fba42011-02-19 01:08:02 -08001484 }
1485
Jeff Brown91c69ab2011-02-14 17:03:18 -08001486 // Private value for history pos that obtains the current sample.
Mathew Inwooda570dee2018-08-17 14:56:00 +01001487 @UnsupportedAppUsage
Jeff Brown91c69ab2011-02-14 17:03:18 -08001488 private static final int HISTORY_CURRENT = -0x80000000;
1489
Jeff Brown1f245102010-11-18 20:53:46 -08001490 private static final int MAX_RECYCLED = 10;
1491 private static final Object gRecyclerLock = new Object();
1492 private static int gRecyclerUsed;
1493 private static MotionEvent gRecyclerTop;
Romain Guycafdea62009-06-12 10:51:36 -07001494
Jeff Brown91c69ab2011-02-14 17:03:18 -08001495 // Shared temporary objects used when translating coordinates supplied by
1496 // the caller into single element PointerCoords and pointer id arrays.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001497 private static final Object gSharedTempLock = new Object();
1498 private static PointerCoords[] gSharedTempPointerCoords;
1499 private static PointerProperties[] gSharedTempPointerProperties;
1500 private static int[] gSharedTempPointerIndexMap;
1501
1502 private static final void ensureSharedTempPointerCapacity(int desiredCapacity) {
1503 if (gSharedTempPointerCoords == null
1504 || gSharedTempPointerCoords.length < desiredCapacity) {
1505 int capacity = gSharedTempPointerCoords != null ? gSharedTempPointerCoords.length : 8;
1506 while (capacity < desiredCapacity) {
1507 capacity *= 2;
1508 }
1509 gSharedTempPointerCoords = PointerCoords.createArray(capacity);
1510 gSharedTempPointerProperties = PointerProperties.createArray(capacity);
1511 gSharedTempPointerIndexMap = new int[capacity];
1512 }
1513 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08001514
1515 // Pointer to the native MotionEvent object that contains the actual data.
Mathew Inwooda570dee2018-08-17 14:56:00 +01001516 @UnsupportedAppUsage
Ashok Bhat99a1ef22014-01-08 14:45:08 +00001517 private long mNativePtr;
Mitsuru Oshima8169dae2009-04-28 18:12:09 -07001518
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001519 private MotionEvent mNext;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001520
Ashok Bhat99a1ef22014-01-08 14:45:08 +00001521 private static native long nativeInitialize(long nativePtr,
Siarhei Vishniakou85ddfff2018-01-31 16:49:36 -08001522 int deviceId, int source, int displayId, int action, int flags, int edgeFlags,
Siarhei Vishniakoub05b0b52018-12-28 17:50:24 -08001523 int metaState, int buttonState, @Classification int classification,
Jeff Brown91c69ab2011-02-14 17:03:18 -08001524 float xOffset, float yOffset, float xPrecision, float yPrecision,
1525 long downTimeNanos, long eventTimeNanos,
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001526 int pointerCount, PointerProperties[] pointerIds, PointerCoords[] pointerCoords);
Ashok Bhat99a1ef22014-01-08 14:45:08 +00001527 private static native void nativeDispose(long nativePtr);
1528 private static native void nativeAddBatch(long nativePtr, long eventTimeNanos,
Jeff Brown91c69ab2011-02-14 17:03:18 -08001529 PointerCoords[] pointerCoords, int metaState);
Ashok Bhat99a1ef22014-01-08 14:45:08 +00001530 private static native void nativeGetPointerCoords(long nativePtr,
Jeff Brown91c69ab2011-02-14 17:03:18 -08001531 int pointerIndex, int historyPos, PointerCoords outPointerCoords);
Ashok Bhat99a1ef22014-01-08 14:45:08 +00001532 private static native void nativeGetPointerProperties(long nativePtr,
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001533 int pointerIndex, PointerProperties outPointerProperties);
Jeff Brown91c69ab2011-02-14 17:03:18 -08001534
Ashok Bhat99a1ef22014-01-08 14:45:08 +00001535 private static native long nativeReadFromParcel(long nativePtr, Parcel parcel);
1536 private static native void nativeWriteToParcel(long nativePtr, Parcel parcel);
Jeff Brown91c69ab2011-02-14 17:03:18 -08001537
Michael Wright337d9d22014-04-22 15:03:48 -07001538 private static native String nativeAxisToString(int axis);
1539 private static native int nativeAxisFromString(String label);
1540
John Reck09709972016-10-03 15:47:18 -07001541 // -------------- @FastNative -------------------------
1542
1543 @FastNative
1544 private static native int nativeGetPointerId(long nativePtr, int pointerIndex);
1545 @FastNative
1546 private static native int nativeGetToolType(long nativePtr, int pointerIndex);
1547 @FastNative
1548 private static native long nativeGetEventTimeNanos(long nativePtr, int historyPos);
1549 @FastNative
Mathew Inwooda570dee2018-08-17 14:56:00 +01001550 @UnsupportedAppUsage
John Reck09709972016-10-03 15:47:18 -07001551 private static native float nativeGetRawAxisValue(long nativePtr,
1552 int axis, int pointerIndex, int historyPos);
1553 @FastNative
1554 private static native float nativeGetAxisValue(long nativePtr,
1555 int axis, int pointerIndex, int historyPos);
1556
1557 // -------------- @CriticalNative ----------------------
1558
1559 @CriticalNative
1560 private static native long nativeCopy(long destNativePtr, long sourceNativePtr,
1561 boolean keepHistory);
1562 @CriticalNative
1563 private static native int nativeGetDeviceId(long nativePtr);
1564 @CriticalNative
1565 private static native int nativeGetSource(long nativePtr);
1566 @CriticalNative
Siarhei Vishniakou85ddfff2018-01-31 16:49:36 -08001567 private static native void nativeSetSource(long nativePtr, int source);
1568 @CriticalNative
1569 private static native int nativeGetDisplayId(long nativePtr);
1570 @CriticalNative
1571 private static native void nativeSetDisplayId(long nativePtr, int displayId);
John Reck09709972016-10-03 15:47:18 -07001572 @CriticalNative
1573 private static native int nativeGetAction(long nativePtr);
1574 @CriticalNative
1575 private static native void nativeSetAction(long nativePtr, int action);
1576 @CriticalNative
1577 private static native boolean nativeIsTouchEvent(long nativePtr);
1578 @CriticalNative
1579 private static native int nativeGetFlags(long nativePtr);
1580 @CriticalNative
1581 private static native void nativeSetFlags(long nativePtr, int flags);
1582 @CriticalNative
1583 private static native int nativeGetEdgeFlags(long nativePtr);
1584 @CriticalNative
1585 private static native void nativeSetEdgeFlags(long nativePtr, int action);
1586 @CriticalNative
1587 private static native int nativeGetMetaState(long nativePtr);
1588 @CriticalNative
1589 private static native int nativeGetButtonState(long nativePtr);
1590 @CriticalNative
1591 private static native void nativeSetButtonState(long nativePtr, int buttonState);
1592 @CriticalNative
Siarhei Vishniakoub05b0b52018-12-28 17:50:24 -08001593 private static native int nativeGetClassification(long nativePtr);
1594 @CriticalNative
John Reck09709972016-10-03 15:47:18 -07001595 private static native int nativeGetActionButton(long nativePtr);
1596 @CriticalNative
1597 private static native void nativeSetActionButton(long nativePtr, int actionButton);
1598 @CriticalNative
1599 private static native void nativeOffsetLocation(long nativePtr, float deltaX, float deltaY);
1600 @CriticalNative
1601 private static native float nativeGetXOffset(long nativePtr);
1602 @CriticalNative
1603 private static native float nativeGetYOffset(long nativePtr);
1604 @CriticalNative
1605 private static native float nativeGetXPrecision(long nativePtr);
1606 @CriticalNative
1607 private static native float nativeGetYPrecision(long nativePtr);
1608 @CriticalNative
1609 private static native long nativeGetDownTimeNanos(long nativePtr);
1610 @CriticalNative
1611 private static native void nativeSetDownTimeNanos(long nativePtr, long downTime);
1612
1613 @CriticalNative
1614 private static native int nativeGetPointerCount(long nativePtr);
1615 @CriticalNative
1616 private static native int nativeFindPointerIndex(long nativePtr, int pointerId);
1617
1618 @CriticalNative
1619 private static native int nativeGetHistorySize(long nativePtr);
1620
1621 @CriticalNative
1622 private static native void nativeScale(long nativePtr, float scale);
1623 @CriticalNative
1624 private static native void nativeTransform(long nativePtr, long matrix);
1625
Jeff Brown91c69ab2011-02-14 17:03:18 -08001626 private MotionEvent() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001627 }
Romain Guycafdea62009-06-12 10:51:36 -07001628
Jeff Brown91c69ab2011-02-14 17:03:18 -08001629 @Override
1630 protected void finalize() throws Throwable {
1631 try {
1632 if (mNativePtr != 0) {
1633 nativeDispose(mNativePtr);
1634 mNativePtr = 0;
1635 }
1636 } finally {
1637 super.finalize();
1638 }
1639 }
1640
Mathew Inwooda570dee2018-08-17 14:56:00 +01001641 @UnsupportedAppUsage
Jeff Brown91c69ab2011-02-14 17:03:18 -08001642 static private MotionEvent obtain() {
Jeff Brown46b9ac02010-04-22 18:58:52 -07001643 final MotionEvent ev;
1644 synchronized (gRecyclerLock) {
Jeff Brown1f245102010-11-18 20:53:46 -08001645 ev = gRecyclerTop;
1646 if (ev == null) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001647 return new MotionEvent();
Jeff Brown46b9ac02010-04-22 18:58:52 -07001648 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07001649 gRecyclerTop = ev.mNext;
Jeff Brown5c225b12010-06-16 01:53:36 -07001650 gRecyclerUsed -= 1;
Jeff Brown46b9ac02010-04-22 18:58:52 -07001651 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07001652 ev.mNext = null;
Jeff Brown32cbc38552011-12-01 14:01:49 -08001653 ev.prepareForReuse();
Jeff Brown46b9ac02010-04-22 18:58:52 -07001654 return ev;
1655 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08001656
Michael Chan53071d62009-05-13 17:29:48 -07001657 /**
1658 * Create a new MotionEvent, filling in all of the basic values that
1659 * define the motion.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001660 *
Dennis Kempinac1b31d2016-11-02 17:02:25 -07001661 * @param downTime The time (in ms) when the user originally pressed down to start
Michael Chan53071d62009-05-13 17:29:48 -07001662 * a stream of position events. This must be obtained from {@link SystemClock#uptimeMillis()}.
Dennis Kempinac1b31d2016-11-02 17:02:25 -07001663 * @param eventTime The the time (in ms) when this specific event was generated. This
Michael Chan53071d62009-05-13 17:29:48 -07001664 * must be obtained from {@link SystemClock#uptimeMillis()}.
Jeff Browncc0c1592011-02-19 05:07:28 -08001665 * @param action The kind of action being performed, such as {@link #ACTION_DOWN}.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001666 * @param pointerCount The number of pointers that will be in this event.
1667 * @param pointerProperties An array of <em>pointerCount</em> values providing
1668 * a {@link PointerProperties} property object for each pointer, which must
1669 * include the pointer identifier.
1670 * @param pointerCoords An array of <em>pointerCount</em> values providing
1671 * a {@link PointerCoords} coordinate object for each pointer.
1672 * @param metaState The state of any meta / modifier keys that were in effect when
1673 * the event was generated.
1674 * @param buttonState The state of buttons that are pressed.
1675 * @param xPrecision The precision of the X coordinate being reported.
1676 * @param yPrecision The precision of the Y coordinate being reported.
1677 * @param deviceId The id for the device that this event came from. An id of
1678 * zero indicates that the event didn't come from a physical device; other
1679 * numbers are arbitrary and you shouldn't depend on the values.
1680 * @param edgeFlags A bitfield indicating which edges, if any, were touched by this
1681 * MotionEvent.
1682 * @param source The source of this event.
Siarhei Vishniakou85ddfff2018-01-31 16:49:36 -08001683 * @param displayId The display ID associated with this event.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001684 * @param flags The motion event flags.
Siarhei Vishniakou85ddfff2018-01-31 16:49:36 -08001685 * @hide
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001686 */
1687 static public MotionEvent obtain(long downTime, long eventTime,
1688 int action, int pointerCount, PointerProperties[] pointerProperties,
1689 PointerCoords[] pointerCoords, int metaState, int buttonState,
1690 float xPrecision, float yPrecision, int deviceId,
Siarhei Vishniakou85ddfff2018-01-31 16:49:36 -08001691 int edgeFlags, int source, int displayId, int flags) {
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001692 MotionEvent ev = obtain();
1693 ev.mNativePtr = nativeInitialize(ev.mNativePtr,
Siarhei Vishniakou85ddfff2018-01-31 16:49:36 -08001694 deviceId, source, displayId, action, flags, edgeFlags, metaState, buttonState,
Siarhei Vishniakoub05b0b52018-12-28 17:50:24 -08001695 CLASSIFICATION_NONE, 0, 0, xPrecision, yPrecision,
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001696 downTime * NS_PER_MS, eventTime * NS_PER_MS,
1697 pointerCount, pointerProperties, pointerCoords);
Siarhei Vishniakou85ddfff2018-01-31 16:49:36 -08001698 if (ev.mNativePtr == 0) {
1699 Log.e(TAG, "Could not initialize MotionEvent");
1700 ev.recycle();
1701 return null;
1702 }
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001703 return ev;
1704 }
1705
1706 /**
1707 * Create a new MotionEvent, filling in all of the basic values that
1708 * define the motion.
Dennis Kempinac1b31d2016-11-02 17:02:25 -07001709 *
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001710 * @param downTime The time (in ms) when the user originally pressed down to start
1711 * a stream of position events. This must be obtained from {@link SystemClock#uptimeMillis()}.
1712 * @param eventTime The the time (in ms) when this specific event was generated. This
1713 * must be obtained from {@link SystemClock#uptimeMillis()}.
1714 * @param action The kind of action being performed, such as {@link #ACTION_DOWN}.
1715 * @param pointerCount The number of pointers that will be in this event.
Siarhei Vishniakou85ddfff2018-01-31 16:49:36 -08001716 * @param pointerProperties An array of <em>pointerCount</em> values providing
1717 * a {@link PointerProperties} property object for each pointer, which must
1718 * include the pointer identifier.
1719 * @param pointerCoords An array of <em>pointerCount</em> values providing
1720 * a {@link PointerCoords} coordinate object for each pointer.
1721 * @param metaState The state of any meta / modifier keys that were in effect when
1722 * the event was generated.
1723 * @param buttonState The state of buttons that are pressed.
1724 * @param xPrecision The precision of the X coordinate being reported.
1725 * @param yPrecision The precision of the Y coordinate being reported.
1726 * @param deviceId The id for the device that this event came from. An id of
1727 * zero indicates that the event didn't come from a physical device; other
1728 * numbers are arbitrary and you shouldn't depend on the values.
1729 * @param edgeFlags A bitfield indicating which edges, if any, were touched by this
1730 * MotionEvent.
1731 * @param source The source of this event.
1732 * @param flags The motion event flags.
1733 */
1734 public static MotionEvent obtain(long downTime, long eventTime,
1735 int action, int pointerCount, PointerProperties[] pointerProperties,
1736 PointerCoords[] pointerCoords, int metaState, int buttonState,
1737 float xPrecision, float yPrecision, int deviceId,
1738 int edgeFlags, int source, int flags) {
1739 return obtain(downTime, eventTime, action, pointerCount, pointerProperties, pointerCoords,
1740 metaState, buttonState, xPrecision, yPrecision, deviceId, edgeFlags, source,
1741 DEFAULT_DISPLAY, flags);
1742 }
1743
1744 /**
1745 * Create a new MotionEvent, filling in all of the basic values that
1746 * define the motion.
1747 *
1748 * @param downTime The time (in ms) when the user originally pressed down to start
1749 * a stream of position events. This must be obtained from {@link SystemClock#uptimeMillis()}.
1750 * @param eventTime The the time (in ms) when this specific event was generated. This
1751 * must be obtained from {@link SystemClock#uptimeMillis()}.
1752 * @param action The kind of action being performed, such as {@link #ACTION_DOWN}.
1753 * @param pointerCount The number of pointers that will be in this event.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001754 * @param pointerIds An array of <em>pointerCount</em> values providing
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001755 * an identifier for each pointer.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001756 * @param pointerCoords An array of <em>pointerCount</em> values providing
Jeff Brownc5ed5912010-07-14 18:48:53 -07001757 * a {@link PointerCoords} coordinate object for each pointer.
Michael Chan53071d62009-05-13 17:29:48 -07001758 * @param metaState The state of any meta / modifier keys that were in effect when
1759 * the event was generated.
1760 * @param xPrecision The precision of the X coordinate being reported.
1761 * @param yPrecision The precision of the Y coordinate being reported.
1762 * @param deviceId The id for the device that this event came from. An id of
1763 * zero indicates that the event didn't come from a physical device; other
1764 * numbers are arbitrary and you shouldn't depend on the values.
Jeff Brown85a31762010-09-01 17:01:00 -07001765 * @param edgeFlags A bitfield indicating which edges, if any, were touched by this
Michael Chan53071d62009-05-13 17:29:48 -07001766 * MotionEvent.
Jeff Brownc5ed5912010-07-14 18:48:53 -07001767 * @param source The source of this event.
Jeff Brown85a31762010-09-01 17:01:00 -07001768 * @param flags The motion event flags.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001769 *
1770 * @deprecated Use {@link #obtain(long, long, int, int, PointerProperties[], PointerCoords[], int, int, float, float, int, int, int, int)}
1771 * instead.
Michael Chan53071d62009-05-13 17:29:48 -07001772 */
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001773 @Deprecated
Jeff Brownc5ed5912010-07-14 18:48:53 -07001774 static public MotionEvent obtain(long downTime, long eventTime,
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001775 int action, int pointerCount, int[] pointerIds, PointerCoords[] pointerCoords,
Jeff Brownc5ed5912010-07-14 18:48:53 -07001776 int metaState, float xPrecision, float yPrecision, int deviceId,
Jeff Brown85a31762010-09-01 17:01:00 -07001777 int edgeFlags, int source, int flags) {
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001778 synchronized (gSharedTempLock) {
1779 ensureSharedTempPointerCapacity(pointerCount);
1780 final PointerProperties[] pp = gSharedTempPointerProperties;
1781 for (int i = 0; i < pointerCount; i++) {
1782 pp[i].clear();
1783 pp[i].id = pointerIds[i];
1784 }
1785 return obtain(downTime, eventTime, action, pointerCount, pp,
1786 pointerCoords, metaState, 0, xPrecision, yPrecision, deviceId,
1787 edgeFlags, source, flags);
1788 }
Michael Chan53071d62009-05-13 17:29:48 -07001789 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08001790
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001791 /**
1792 * Create a new MotionEvent, filling in all of the basic values that
1793 * define the motion.
Romain Guycafdea62009-06-12 10:51:36 -07001794 *
1795 * @param downTime The time (in ms) when the user originally pressed down to start
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001796 * a stream of position events. This must be obtained from {@link SystemClock#uptimeMillis()}.
Romain Guycafdea62009-06-12 10:51:36 -07001797 * @param eventTime The the time (in ms) when this specific event was generated. This
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001798 * must be obtained from {@link SystemClock#uptimeMillis()}.
Jeff Browncc0c1592011-02-19 05:07:28 -08001799 * @param action The kind of action being performed, such as {@link #ACTION_DOWN}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001800 * @param x The X coordinate of this event.
1801 * @param y The Y coordinate of this event.
Romain Guycafdea62009-06-12 10:51:36 -07001802 * @param pressure The current pressure of this event. The pressure generally
1803 * ranges from 0 (no pressure at all) to 1 (normal pressure), however
1804 * values higher than 1 may be generated depending on the calibration of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001805 * the input device.
1806 * @param size A scaled value of the approximate size of the area being pressed when
Romain Guycafdea62009-06-12 10:51:36 -07001807 * touched with the finger. The actual value in pixels corresponding to the finger
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001808 * touch is normalized with a device specific range of values
1809 * and scaled to a value between 0 and 1.
1810 * @param metaState The state of any meta / modifier keys that were in effect when
1811 * the event was generated.
1812 * @param xPrecision The precision of the X coordinate being reported.
1813 * @param yPrecision The precision of the Y coordinate being reported.
1814 * @param deviceId The id for the device that this event came from. An id of
1815 * zero indicates that the event didn't come from a physical device; other
1816 * numbers are arbitrary and you shouldn't depend on the values.
Jeff Brown85a31762010-09-01 17:01:00 -07001817 * @param edgeFlags A bitfield indicating which edges, if any, were touched by this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001818 * MotionEvent.
1819 */
1820 static public MotionEvent obtain(long downTime, long eventTime, int action,
1821 float x, float y, float pressure, float size, int metaState,
1822 float xPrecision, float yPrecision, int deviceId, int edgeFlags) {
Arthur Hung19b517a2018-09-14 18:24:31 +08001823 return obtain(downTime, eventTime, action, x, y, pressure, size, metaState,
1824 xPrecision, yPrecision, deviceId, edgeFlags, InputDevice.SOURCE_UNKNOWN,
1825 DEFAULT_DISPLAY);
1826 }
1827
1828 /**
1829 * Create a new MotionEvent, filling in all of the basic values that
1830 * define the motion.
1831 *
1832 * @param downTime The time (in ms) when the user originally pressed down to start
1833 * a stream of position events. This must be obtained from {@link SystemClock#uptimeMillis()}.
1834 * @param eventTime The the time (in ms) when this specific event was generated. This
1835 * must be obtained from {@link SystemClock#uptimeMillis()}.
1836 * @param action The kind of action being performed, such as {@link #ACTION_DOWN}.
1837 * @param x The X coordinate of this event.
1838 * @param y The Y coordinate of this event.
1839 * @param pressure The current pressure of this event. The pressure generally
1840 * ranges from 0 (no pressure at all) to 1 (normal pressure), however
1841 * values higher than 1 may be generated depending on the calibration of
1842 * the input device.
1843 * @param size A scaled value of the approximate size of the area being pressed when
1844 * touched with the finger. The actual value in pixels corresponding to the finger
1845 * touch is normalized with a device specific range of values
1846 * and scaled to a value between 0 and 1.
1847 * @param metaState The state of any meta / modifier keys that were in effect when
1848 * the event was generated.
1849 * @param xPrecision The precision of the X coordinate being reported.
1850 * @param yPrecision The precision of the Y coordinate being reported.
1851 * @param deviceId The id for the device that this event came from. An id of
1852 * zero indicates that the event didn't come from a physical device; other
1853 * numbers are arbitrary and you shouldn't depend on the values.
1854 * @param source The source of this event.
1855 * @param edgeFlags A bitfield indicating which edges, if any, were touched by this
1856 * MotionEvent.
1857 * @param displayId The display ID associated with this event.
1858 * @hide
1859 */
1860 public static MotionEvent obtain(long downTime, long eventTime, int action,
1861 float x, float y, float pressure, float size, int metaState,
1862 float xPrecision, float yPrecision, int deviceId, int edgeFlags, int source,
1863 int displayId) {
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001864 MotionEvent ev = obtain();
1865 synchronized (gSharedTempLock) {
1866 ensureSharedTempPointerCapacity(1);
1867 final PointerProperties[] pp = gSharedTempPointerProperties;
1868 pp[0].clear();
1869 pp[0].id = 0;
Jeff Brown91c69ab2011-02-14 17:03:18 -08001870
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001871 final PointerCoords pc[] = gSharedTempPointerCoords;
1872 pc[0].clear();
1873 pc[0].x = x;
1874 pc[0].y = y;
1875 pc[0].pressure = pressure;
1876 pc[0].size = size;
1877
Jeff Brown91c69ab2011-02-14 17:03:18 -08001878 ev.mNativePtr = nativeInitialize(ev.mNativePtr,
Arthur Hung19b517a2018-09-14 18:24:31 +08001879 deviceId, source, displayId,
Siarhei Vishniakoub05b0b52018-12-28 17:50:24 -08001880 action, 0, edgeFlags, metaState, 0 /*buttonState*/, CLASSIFICATION_NONE,
Jeff Brown91c69ab2011-02-14 17:03:18 -08001881 0, 0, xPrecision, yPrecision,
1882 downTime * NS_PER_MS, eventTime * NS_PER_MS,
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001883 1, pp, pc);
Jeff Brown91c69ab2011-02-14 17:03:18 -08001884 return ev;
1885 }
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001886 }
1887
1888 /**
1889 * Create a new MotionEvent, filling in all of the basic values that
1890 * define the motion.
1891 *
1892 * @param downTime The time (in ms) when the user originally pressed down to start
1893 * a stream of position events. This must be obtained from {@link SystemClock#uptimeMillis()}.
1894 * @param eventTime The the time (in ms) when this specific event was generated. This
1895 * must be obtained from {@link SystemClock#uptimeMillis()}.
Jeff Browncc0c1592011-02-19 05:07:28 -08001896 * @param action The kind of action being performed, such as {@link #ACTION_DOWN}.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001897 * @param pointerCount The number of pointers that are active in this event.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001898 * @param x The X coordinate of this event.
1899 * @param y The Y coordinate of this event.
1900 * @param pressure The current pressure of this event. The pressure generally
1901 * ranges from 0 (no pressure at all) to 1 (normal pressure), however
1902 * values higher than 1 may be generated depending on the calibration of
1903 * the input device.
1904 * @param size A scaled value of the approximate size of the area being pressed when
1905 * touched with the finger. The actual value in pixels corresponding to the finger
1906 * touch is normalized with a device specific range of values
1907 * and scaled to a value between 0 and 1.
1908 * @param metaState The state of any meta / modifier keys that were in effect when
1909 * the event was generated.
1910 * @param xPrecision The precision of the X coordinate being reported.
1911 * @param yPrecision The precision of the Y coordinate being reported.
1912 * @param deviceId The id for the device that this event came from. An id of
1913 * zero indicates that the event didn't come from a physical device; other
1914 * numbers are arbitrary and you shouldn't depend on the values.
Jeff Brown85a31762010-09-01 17:01:00 -07001915 * @param edgeFlags A bitfield indicating which edges, if any, were touched by this
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001916 * MotionEvent.
Dennis Kempinac1b31d2016-11-02 17:02:25 -07001917 *
Jeff Brown5c225b12010-06-16 01:53:36 -07001918 * @deprecated Use {@link #obtain(long, long, int, float, float, float, float, int, float, float, int, int)}
1919 * instead.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001920 */
Jeff Brown5c225b12010-06-16 01:53:36 -07001921 @Deprecated
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001922 static public MotionEvent obtain(long downTime, long eventTime, int action,
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001923 int pointerCount, float x, float y, float pressure, float size, int metaState,
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001924 float xPrecision, float yPrecision, int deviceId, int edgeFlags) {
Jeff Brown5c225b12010-06-16 01:53:36 -07001925 return obtain(downTime, eventTime, action, x, y, pressure, size,
1926 metaState, xPrecision, yPrecision, deviceId, edgeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001927 }
Romain Guycafdea62009-06-12 10:51:36 -07001928
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001929 /**
1930 * Create a new MotionEvent, filling in a subset of the basic motion
1931 * values. Those not specified here are: device id (always 0), pressure
1932 * and size (always 1), x and y precision (always 1), and edgeFlags (always 0).
Romain Guycafdea62009-06-12 10:51:36 -07001933 *
1934 * @param downTime The time (in ms) when the user originally pressed down to start
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001935 * a stream of position events. This must be obtained from {@link SystemClock#uptimeMillis()}.
Romain Guycafdea62009-06-12 10:51:36 -07001936 * @param eventTime The the time (in ms) when this specific event was generated. This
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001937 * must be obtained from {@link SystemClock#uptimeMillis()}.
Jeff Browncc0c1592011-02-19 05:07:28 -08001938 * @param action The kind of action being performed, such as {@link #ACTION_DOWN}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001939 * @param x The X coordinate of this event.
1940 * @param y The Y coordinate of this event.
1941 * @param metaState The state of any meta / modifier keys that were in effect when
1942 * the event was generated.
1943 */
1944 static public MotionEvent obtain(long downTime, long eventTime, int action,
1945 float x, float y, int metaState) {
Jeff Brown5c225b12010-06-16 01:53:36 -07001946 return obtain(downTime, eventTime, action, x, y, 1.0f, 1.0f,
1947 metaState, 1.0f, 1.0f, 0, 0);
Mitsuru Oshima8169dae2009-04-28 18:12:09 -07001948 }
1949
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001950 /**
1951 * Create a new MotionEvent, copying from an existing one.
1952 */
Jeff Brown91c69ab2011-02-14 17:03:18 -08001953 static public MotionEvent obtain(MotionEvent other) {
1954 if (other == null) {
1955 throw new IllegalArgumentException("other motion event must not be null");
1956 }
1957
1958 MotionEvent ev = obtain();
1959 ev.mNativePtr = nativeCopy(ev.mNativePtr, other.mNativePtr, true /*keepHistory*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001960 return ev;
1961 }
Romain Guycafdea62009-06-12 10:51:36 -07001962
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001963 /**
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07001964 * Create a new MotionEvent, copying from an existing one, but not including
1965 * any historical point information.
1966 */
Jeff Brown91c69ab2011-02-14 17:03:18 -08001967 static public MotionEvent obtainNoHistory(MotionEvent other) {
1968 if (other == null) {
1969 throw new IllegalArgumentException("other motion event must not be null");
1970 }
1971
1972 MotionEvent ev = obtain();
1973 ev.mNativePtr = nativeCopy(ev.mNativePtr, other.mNativePtr, false /*keepHistory*/);
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07001974 return ev;
1975 }
1976
Jeff Brown21bc5c92011-02-28 18:27:14 -08001977 /** @hide */
1978 @Override
Mathew Inwooda570dee2018-08-17 14:56:00 +01001979 @UnsupportedAppUsage
Jeff Brown21bc5c92011-02-28 18:27:14 -08001980 public MotionEvent copy() {
1981 return obtain(this);
1982 }
1983
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07001984 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001985 * Recycle the MotionEvent, to be re-used by a later caller. After calling
1986 * this function you must not ever touch the event again.
1987 */
Jeff Brown92cc2d82011-12-02 01:19:47 -08001988 @Override
Jeff Brown5c225b12010-06-16 01:53:36 -07001989 public final void recycle() {
Jeff Brown32cbc38552011-12-01 14:01:49 -08001990 super.recycle();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001991
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001992 synchronized (gRecyclerLock) {
1993 if (gRecyclerUsed < MAX_RECYCLED) {
1994 gRecyclerUsed++;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001995 mNext = gRecyclerTop;
1996 gRecyclerTop = this;
1997 }
1998 }
1999 }
Jeff Brown9ea77fc2012-03-21 19:49:27 -07002000
Jeff Brown5c225b12010-06-16 01:53:36 -07002001 /**
Jeff Brown9ea77fc2012-03-21 19:49:27 -07002002 * Applies a scale factor to all points within this event.
Jeff Brown5c225b12010-06-16 01:53:36 -07002003 *
Jeff Brown9ea77fc2012-03-21 19:49:27 -07002004 * This method is used to adjust touch events to simulate different density
2005 * displays for compatibility mode. The values returned by {@link #getRawX()},
2006 * {@link #getRawY()}, {@link #getXPrecision()} and {@link #getYPrecision()}
2007 * are also affected by the scale factor.
2008 *
2009 * @param scale The scale factor to apply.
Jeff Brown5c225b12010-06-16 01:53:36 -07002010 * @hide
2011 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01002012 @UnsupportedAppUsage
Jeff Brown5c225b12010-06-16 01:53:36 -07002013 public final void scale(float scale) {
Jeff Brown9ea77fc2012-03-21 19:49:27 -07002014 if (scale != 1.0f) {
2015 nativeScale(mNativePtr, scale);
2016 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08002017 }
2018
2019 /** {@inheritDoc} */
2020 @Override
2021 public final int getDeviceId() {
2022 return nativeGetDeviceId(mNativePtr);
2023 }
2024
2025 /** {@inheritDoc} */
2026 @Override
2027 public final int getSource() {
2028 return nativeGetSource(mNativePtr);
2029 }
2030
2031 /** {@inheritDoc} */
2032 @Override
2033 public final void setSource(int source) {
2034 nativeSetSource(mNativePtr, source);
Jeff Brown5c225b12010-06-16 01:53:36 -07002035 }
Romain Guycafdea62009-06-12 10:51:36 -07002036
Siarhei Vishniakou85ddfff2018-01-31 16:49:36 -08002037 /** @hide */
Siarhei Vishniakou91fa08f2018-06-08 22:49:30 +01002038 @Override
Siarhei Vishniakou85ddfff2018-01-31 16:49:36 -08002039 public int getDisplayId() {
2040 return nativeGetDisplayId(mNativePtr);
2041 }
2042
2043 /** @hide */
lumark793e0562018-07-09 22:14:33 +08002044 @TestApi
Siarhei Vishniakou91fa08f2018-06-08 22:49:30 +01002045 @Override
Siarhei Vishniakou85ddfff2018-01-31 16:49:36 -08002046 public void setDisplayId(int displayId) {
2047 nativeSetDisplayId(mNativePtr, displayId);
2048 }
2049
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002050 /**
Jeff Browncc0c1592011-02-19 05:07:28 -08002051 * Return the kind of action being performed.
2052 * Consider using {@link #getActionMasked} and {@link #getActionIndex} to retrieve
2053 * the separate masked action and pointer index.
2054 * @return The action, such as {@link #ACTION_DOWN} or
2055 * the combination of {@link #ACTION_POINTER_DOWN} with a shifted pointer index.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002056 */
2057 public final int getAction() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002058 return nativeGetAction(mNativePtr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002059 }
2060
2061 /**
Jeff Browncc0c1592011-02-19 05:07:28 -08002062 * Return the masked action being performed, without pointer index information.
2063 * Use {@link #getActionIndex} to return the index associated with pointer actions.
2064 * @return The action, such as {@link #ACTION_DOWN} or {@link #ACTION_POINTER_DOWN}.
Dianne Hackbornb125dc52010-02-12 15:52:09 -08002065 */
2066 public final int getActionMasked() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002067 return nativeGetAction(mNativePtr) & ACTION_MASK;
Dianne Hackbornb125dc52010-02-12 15:52:09 -08002068 }
2069
2070 /**
2071 * For {@link #ACTION_POINTER_DOWN} or {@link #ACTION_POINTER_UP}
2072 * as returned by {@link #getActionMasked}, this returns the associated
Jeff Browncc0c1592011-02-19 05:07:28 -08002073 * pointer index.
2074 * The index may be used with {@link #getPointerId(int)},
Dianne Hackbornb125dc52010-02-12 15:52:09 -08002075 * {@link #getX(int)}, {@link #getY(int)}, {@link #getPressure(int)},
2076 * and {@link #getSize(int)} to get information about the pointer that has
2077 * gone down or up.
Jeff Browncc0c1592011-02-19 05:07:28 -08002078 * @return The index associated with the action.
Dianne Hackbornb125dc52010-02-12 15:52:09 -08002079 */
2080 public final int getActionIndex() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002081 return (nativeGetAction(mNativePtr) & ACTION_POINTER_INDEX_MASK)
2082 >> ACTION_POINTER_INDEX_SHIFT;
Dianne Hackbornb125dc52010-02-12 15:52:09 -08002083 }
2084
2085 /**
Jeff Brown33bbfd22011-02-24 20:55:35 -08002086 * Returns true if this motion event is a touch event.
2087 * <p>
Jeff Browna032cc02011-03-07 16:56:21 -08002088 * Specifically excludes pointer events with action {@link #ACTION_HOVER_MOVE},
2089 * {@link #ACTION_HOVER_ENTER}, {@link #ACTION_HOVER_EXIT}, or {@link #ACTION_SCROLL}
2090 * because they are not actually touch events (the pointer is not down).
Jeff Brown33bbfd22011-02-24 20:55:35 -08002091 * </p>
2092 * @return True if this motion event is a touch event.
2093 * @hide
2094 */
2095 public final boolean isTouchEvent() {
Jeff Brown56194eb2011-03-02 19:23:13 -08002096 return nativeIsTouchEvent(mNativePtr);
Jeff Brown33bbfd22011-02-24 20:55:35 -08002097 }
2098
2099 /**
Jeff Brown85a31762010-09-01 17:01:00 -07002100 * Gets the motion event flags.
2101 *
2102 * @see #FLAG_WINDOW_IS_OBSCURED
2103 */
2104 public final int getFlags() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002105 return nativeGetFlags(mNativePtr);
Jeff Brown85a31762010-09-01 17:01:00 -07002106 }
2107
Jeff Brown21bc5c92011-02-28 18:27:14 -08002108 /** @hide */
2109 @Override
2110 public final boolean isTainted() {
2111 final int flags = getFlags();
2112 return (flags & FLAG_TAINTED) != 0;
2113 }
2114
2115 /** @hide */
2116 @Override
2117 public final void setTainted(boolean tainted) {
2118 final int flags = getFlags();
2119 nativeSetFlags(mNativePtr, tainted ? flags | FLAG_TAINTED : flags & ~FLAG_TAINTED);
2120 }
2121
Svetoslavded133c2015-01-30 20:28:41 -08002122 /** @hide */
2123 public final boolean isTargetAccessibilityFocus() {
2124 final int flags = getFlags();
2125 return (flags & FLAG_TARGET_ACCESSIBILITY_FOCUS) != 0;
2126 }
2127
2128 /** @hide */
2129 public final void setTargetAccessibilityFocus(boolean targetsFocus) {
2130 final int flags = getFlags();
2131 nativeSetFlags(mNativePtr, targetsFocus
2132 ? flags | FLAG_TARGET_ACCESSIBILITY_FOCUS
2133 : flags & ~FLAG_TARGET_ACCESSIBILITY_FOCUS);
2134 }
2135
Vladislav Kaznacheev5a77c372016-10-10 16:11:15 -07002136 /** @hide */
2137 public final boolean isHoverExitPending() {
2138 final int flags = getFlags();
2139 return (flags & FLAG_HOVER_EXIT_PENDING) != 0;
2140 }
2141
2142 /** @hide */
2143 public void setHoverExitPending(boolean hoverExitPending) {
2144 final int flags = getFlags();
2145 nativeSetFlags(mNativePtr, hoverExitPending
2146 ? flags | FLAG_HOVER_EXIT_PENDING
2147 : flags & ~FLAG_HOVER_EXIT_PENDING);
2148 }
2149
Jeff Brown85a31762010-09-01 17:01:00 -07002150 /**
Romain Guycafdea62009-06-12 10:51:36 -07002151 * Returns the time (in ms) when the user originally pressed down to start
2152 * a stream of position events.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002153 */
2154 public final long getDownTime() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002155 return nativeGetDownTimeNanos(mNativePtr) / NS_PER_MS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002156 }
2157
2158 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07002159 * Sets the time (in ms) when the user originally pressed down to start
2160 * a stream of position events.
2161 *
2162 * @hide
2163 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01002164 @UnsupportedAppUsage
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07002165 public final void setDownTime(long downTime) {
2166 nativeSetDownTimeNanos(mNativePtr, downTime * NS_PER_MS);
2167 }
2168
2169 /**
Jeff Brownb11499d2012-04-20 19:54:22 -07002170 * Retrieve the time this event occurred,
2171 * in the {@link android.os.SystemClock#uptimeMillis} time base.
2172 *
2173 * @return Returns the time this event occurred,
2174 * in the {@link android.os.SystemClock#uptimeMillis} time base.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002175 */
Jeff Brownb11499d2012-04-20 19:54:22 -07002176 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002177 public final long getEventTime() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002178 return nativeGetEventTimeNanos(mNativePtr, HISTORY_CURRENT) / NS_PER_MS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002179 }
2180
2181 /**
Jeff Brownb11499d2012-04-20 19:54:22 -07002182 * Retrieve the time this event occurred,
2183 * in the {@link android.os.SystemClock#uptimeMillis} time base but with
2184 * nanosecond precision.
2185 * <p>
Michael Chan53071d62009-05-13 17:29:48 -07002186 * The value is in nanosecond precision but it may not have nanosecond accuracy.
Jeff Brownb11499d2012-04-20 19:54:22 -07002187 * </p>
2188 *
2189 * @return Returns the time this event occurred,
2190 * in the {@link android.os.SystemClock#uptimeMillis} time base but with
2191 * nanosecond precision.
Michael Chan53071d62009-05-13 17:29:48 -07002192 *
2193 * @hide
2194 */
Jeff Brownb11499d2012-04-20 19:54:22 -07002195 @Override
Mathew Inwooda570dee2018-08-17 14:56:00 +01002196 @UnsupportedAppUsage
Michael Chan53071d62009-05-13 17:29:48 -07002197 public final long getEventTimeNano() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002198 return nativeGetEventTimeNanos(mNativePtr, HISTORY_CURRENT);
Michael Chan53071d62009-05-13 17:29:48 -07002199 }
2200
2201 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002202 * {@link #getX(int)} for the first pointer index (may be an
2203 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002204 *
2205 * @see #AXIS_X
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002206 */
2207 public final float getX() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002208 return nativeGetAxisValue(mNativePtr, AXIS_X, 0, HISTORY_CURRENT);
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002209 }
2210
2211 /**
2212 * {@link #getY(int)} for the first pointer index (may be an
2213 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002214 *
2215 * @see #AXIS_Y
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002216 */
2217 public final float getY() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002218 return nativeGetAxisValue(mNativePtr, AXIS_Y, 0, HISTORY_CURRENT);
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002219 }
2220
2221 /**
2222 * {@link #getPressure(int)} for the first pointer index (may be an
2223 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002224 *
2225 * @see #AXIS_PRESSURE
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002226 */
2227 public final float getPressure() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002228 return nativeGetAxisValue(mNativePtr, AXIS_PRESSURE, 0, HISTORY_CURRENT);
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002229 }
2230
2231 /**
2232 * {@link #getSize(int)} for the first pointer index (may be an
2233 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002234 *
2235 * @see #AXIS_SIZE
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002236 */
2237 public final float getSize() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002238 return nativeGetAxisValue(mNativePtr, AXIS_SIZE, 0, HISTORY_CURRENT);
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002239 }
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002240
Jeff Brownc5ed5912010-07-14 18:48:53 -07002241 /**
2242 * {@link #getTouchMajor(int)} for the first pointer index (may be an
2243 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002244 *
2245 * @see #AXIS_TOUCH_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002246 */
2247 public final float getTouchMajor() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002248 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MAJOR, 0, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002249 }
2250
2251 /**
2252 * {@link #getTouchMinor(int)} for the first pointer index (may be an
2253 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002254 *
2255 * @see #AXIS_TOUCH_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002256 */
2257 public final float getTouchMinor() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002258 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MINOR, 0, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002259 }
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002260
Jeff Brownc5ed5912010-07-14 18:48:53 -07002261 /**
2262 * {@link #getToolMajor(int)} for the first pointer index (may be an
2263 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002264 *
2265 * @see #AXIS_TOOL_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002266 */
2267 public final float getToolMajor() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002268 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MAJOR, 0, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002269 }
2270
2271 /**
2272 * {@link #getToolMinor(int)} for the first pointer index (may be an
2273 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002274 *
2275 * @see #AXIS_TOOL_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002276 */
2277 public final float getToolMinor() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002278 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MINOR, 0, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002279 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08002280
Jeff Brownc5ed5912010-07-14 18:48:53 -07002281 /**
2282 * {@link #getOrientation(int)} for the first pointer index (may be an
2283 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002284 *
2285 * @see #AXIS_ORIENTATION
Jeff Brownc5ed5912010-07-14 18:48:53 -07002286 */
2287 public final float getOrientation() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002288 return nativeGetAxisValue(mNativePtr, AXIS_ORIENTATION, 0, HISTORY_CURRENT);
2289 }
2290
2291 /**
2292 * {@link #getAxisValue(int)} for the first pointer index (may be an
2293 * arbitrary pointer identifier).
2294 *
2295 * @param axis The axis identifier for the axis value to retrieve.
2296 *
2297 * @see #AXIS_X
2298 * @see #AXIS_Y
2299 */
2300 public final float getAxisValue(int axis) {
2301 return nativeGetAxisValue(mNativePtr, axis, 0, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002302 }
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002303
2304 /**
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002305 * The number of pointers of data contained in this event. Always
2306 * >= 1.
2307 */
2308 public final int getPointerCount() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002309 return nativeGetPointerCount(mNativePtr);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002310 }
John Reck09709972016-10-03 15:47:18 -07002311
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002312 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002313 * Return the pointer identifier associated with a particular pointer
Trevor Johns682c24e2016-04-12 10:13:47 -07002314 * data index in this event. The identifier tells you the actual pointer
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002315 * number associated with the data, accounting for individual pointers
2316 * going up and down since the start of the current gesture.
2317 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2318 * (the first pointer that is down) to {@link #getPointerCount()}-1.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002319 */
Dianne Hackbornd41ba662009-08-05 15:30:56 -07002320 public final int getPointerId(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002321 return nativeGetPointerId(mNativePtr, pointerIndex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002322 }
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07002323
2324 /**
2325 * Gets the tool type of a pointer for the given pointer index.
2326 * The tool type indicates the type of tool used to make contact such
2327 * as a finger or stylus, if known.
2328 *
2329 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2330 * (the first pointer that is down) to {@link #getPointerCount()}-1.
2331 * @return The tool type of the pointer.
2332 *
2333 * @see #TOOL_TYPE_UNKNOWN
2334 * @see #TOOL_TYPE_FINGER
2335 * @see #TOOL_TYPE_STYLUS
2336 * @see #TOOL_TYPE_MOUSE
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07002337 */
2338 public final int getToolType(int pointerIndex) {
2339 return nativeGetToolType(mNativePtr, pointerIndex);
2340 }
2341
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002342 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002343 * Given a pointer identifier, find the index of its data in the event.
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002344 *
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002345 * @param pointerId The identifier of the pointer to be found.
2346 * @return Returns either the index of the pointer (for use with
Gilles Debunneb0d6ba12010-08-17 20:01:42 -07002347 * {@link #getX(int)} et al.), or -1 if there is no data available for
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002348 * that pointer identifier.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002349 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002350 public final int findPointerIndex(int pointerId) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002351 return nativeFindPointerIndex(mNativePtr, pointerId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002352 }
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07002353
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002354 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002355 * Returns the X coordinate of this event for the given pointer
2356 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
2357 * identifier for this index).
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002358 * Whole numbers are pixels; the
2359 * value may have a fraction for input devices that are sub-pixel precise.
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002360 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2361 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002362 *
2363 * @see #AXIS_X
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002364 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002365 public final float getX(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002366 return nativeGetAxisValue(mNativePtr, AXIS_X, pointerIndex, HISTORY_CURRENT);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002367 }
2368
2369 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002370 * Returns the Y coordinate of this event for the given pointer
2371 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
2372 * identifier for this index).
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002373 * Whole numbers are pixels; the
2374 * value may have a fraction for input devices that are sub-pixel precise.
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002375 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2376 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002377 *
2378 * @see #AXIS_Y
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002379 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002380 public final float getY(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002381 return nativeGetAxisValue(mNativePtr, AXIS_Y, pointerIndex, HISTORY_CURRENT);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002382 }
2383
2384 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002385 * Returns the current pressure of this event for the given pointer
2386 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
2387 * identifier for this index).
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002388 * The pressure generally
Romain Guycafdea62009-06-12 10:51:36 -07002389 * ranges from 0 (no pressure at all) to 1 (normal pressure), however
2390 * values higher than 1 may be generated depending on the calibration of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002391 * the input device.
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002392 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2393 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002394 *
2395 * @see #AXIS_PRESSURE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002396 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002397 public final float getPressure(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002398 return nativeGetAxisValue(mNativePtr, AXIS_PRESSURE, pointerIndex, HISTORY_CURRENT);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002399 }
2400
2401 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002402 * Returns a scaled value of the approximate size for the given pointer
2403 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
2404 * identifier for this index).
2405 * This represents some approximation of the area of the screen being
2406 * pressed; the actual value in pixels corresponding to the
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002407 * touch is normalized with the device specific range of values
Romain Guycafdea62009-06-12 10:51:36 -07002408 * 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 -08002409 * determine fat touch events.
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002410 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2411 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002412 *
2413 * @see #AXIS_SIZE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002414 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002415 public final float getSize(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002416 return nativeGetAxisValue(mNativePtr, AXIS_SIZE, pointerIndex, HISTORY_CURRENT);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002417 }
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002418
Jeff Brownc5ed5912010-07-14 18:48:53 -07002419 /**
2420 * Returns the length of the major axis of an ellipse that describes the touch
2421 * area at the point of contact for the given pointer
2422 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
2423 * identifier for this index).
2424 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2425 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002426 *
2427 * @see #AXIS_TOUCH_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002428 */
2429 public final float getTouchMajor(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002430 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MAJOR, pointerIndex, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002431 }
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002432
Jeff Brownc5ed5912010-07-14 18:48:53 -07002433 /**
2434 * Returns the length of the minor axis of an ellipse that describes the touch
2435 * area at the point of contact for the given pointer
2436 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
2437 * identifier for this index).
2438 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2439 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002440 *
2441 * @see #AXIS_TOUCH_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002442 */
2443 public final float getTouchMinor(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002444 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MINOR, pointerIndex, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002445 }
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002446
Jeff Brownc5ed5912010-07-14 18:48:53 -07002447 /**
2448 * Returns the length of the major axis of an ellipse that describes the size of
2449 * the approaching tool for the given pointer
2450 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
2451 * identifier for this index).
2452 * The tool area represents the estimated size of the finger or pen that is
2453 * touching the device independent of its actual touch area at the point of contact.
2454 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2455 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002456 *
2457 * @see #AXIS_TOOL_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002458 */
2459 public final float getToolMajor(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002460 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MAJOR, pointerIndex, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002461 }
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002462
Jeff Brownc5ed5912010-07-14 18:48:53 -07002463 /**
2464 * Returns the length of the minor axis of an ellipse that describes the size of
2465 * the approaching tool for the given pointer
2466 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
2467 * identifier for this index).
2468 * The tool area represents the estimated size of the finger or pen that is
2469 * touching the device independent of its actual touch area at the point of contact.
2470 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2471 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002472 *
2473 * @see #AXIS_TOOL_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002474 */
2475 public final float getToolMinor(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002476 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MINOR, pointerIndex, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002477 }
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002478
Jeff Brownc5ed5912010-07-14 18:48:53 -07002479 /**
2480 * Returns the orientation of the touch area and tool area in radians clockwise from vertical
2481 * for the given pointer <em>index</em> (use {@link #getPointerId(int)} to find the pointer
2482 * identifier for this index).
Jeff Brown6f2fba42011-02-19 01:08:02 -08002483 * An angle of 0 radians indicates that the major axis of contact is oriented
Jeff Brownc5ed5912010-07-14 18:48:53 -07002484 * upwards, is perfectly circular or is of unknown orientation. A positive angle
2485 * indicates that the major axis of contact is oriented to the right. A negative angle
2486 * indicates that the major axis of contact is oriented to the left.
Jeff Brown6d0fec22010-07-23 21:28:06 -07002487 * The full range is from -PI/2 radians (finger pointing fully left) to PI/2 radians
Jeff Brownc5ed5912010-07-14 18:48:53 -07002488 * (finger pointing fully right).
2489 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2490 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002491 *
2492 * @see #AXIS_ORIENTATION
Jeff Brownc5ed5912010-07-14 18:48:53 -07002493 */
2494 public final float getOrientation(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002495 return nativeGetAxisValue(mNativePtr, AXIS_ORIENTATION, pointerIndex, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002496 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08002497
2498 /**
2499 * Returns the value of the requested axis for the given pointer <em>index</em>
2500 * (use {@link #getPointerId(int)} to find the pointer identifier for this index).
2501 *
2502 * @param axis The axis identifier for the axis value to retrieve.
2503 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2504 * (the first pointer that is down) to {@link #getPointerCount()}-1.
2505 * @return The value of the axis, or 0 if the axis is not available.
2506 *
2507 * @see #AXIS_X
2508 * @see #AXIS_Y
2509 */
2510 public final float getAxisValue(int axis, int pointerIndex) {
2511 return nativeGetAxisValue(mNativePtr, axis, pointerIndex, HISTORY_CURRENT);
2512 }
2513
Jeff Brownc5ed5912010-07-14 18:48:53 -07002514 /**
2515 * Populates a {@link PointerCoords} object with pointer coordinate data for
2516 * the specified pointer index.
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002517 *
Jeff Brownc5ed5912010-07-14 18:48:53 -07002518 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2519 * (the first pointer that is down) to {@link #getPointerCount()}-1.
2520 * @param outPointerCoords The pointer coordinate object to populate.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002521 *
2522 * @see PointerCoords
Jeff Brownc5ed5912010-07-14 18:48:53 -07002523 */
2524 public final void getPointerCoords(int pointerIndex, PointerCoords outPointerCoords) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002525 nativeGetPointerCoords(mNativePtr, pointerIndex, HISTORY_CURRENT, outPointerCoords);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002526 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002527
2528 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07002529 * Populates a {@link PointerProperties} object with pointer properties for
2530 * the specified pointer index.
2531 *
2532 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2533 * (the first pointer that is down) to {@link #getPointerCount()}-1.
2534 * @param outPointerProperties The pointer properties object to populate.
2535 *
2536 * @see PointerProperties
2537 */
2538 public final void getPointerProperties(int pointerIndex,
2539 PointerProperties outPointerProperties) {
2540 nativeGetPointerProperties(mNativePtr, pointerIndex, outPointerProperties);
2541 }
2542
2543 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002544 * Returns the state of any meta / modifier keys that were in effect when
2545 * the event was generated. This is the same values as those
2546 * returned by {@link KeyEvent#getMetaState() KeyEvent.getMetaState}.
2547 *
2548 * @return an integer in which each bit set to 1 represents a pressed
2549 * meta key
2550 *
2551 * @see KeyEvent#getMetaState()
2552 */
2553 public final int getMetaState() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002554 return nativeGetMetaState(mNativePtr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002555 }
2556
2557 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07002558 * Gets the state of all buttons that are pressed such as a mouse or stylus button.
2559 *
2560 * @return The button state.
2561 *
2562 * @see #BUTTON_PRIMARY
2563 * @see #BUTTON_SECONDARY
2564 * @see #BUTTON_TERTIARY
2565 * @see #BUTTON_FORWARD
2566 * @see #BUTTON_BACK
Michael Wright5bd69e62015-05-14 14:48:08 +01002567 * @see #BUTTON_STYLUS_PRIMARY
2568 * @see #BUTTON_STYLUS_SECONDARY
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07002569 */
2570 public final int getButtonState() {
2571 return nativeGetButtonState(mNativePtr);
2572 }
2573
2574 /**
Michael Wright5bd69e62015-05-14 14:48:08 +01002575 * Sets the bitfield indicating which buttons are pressed.
2576 *
2577 * @see #getButtonState()
2578 * @hide
2579 */
Kirill Grouchnikovb2a44f02016-09-14 16:24:44 -07002580 @TestApi
Michael Wright5bd69e62015-05-14 14:48:08 +01002581 public final void setButtonState(int buttonState) {
2582 nativeSetButtonState(mNativePtr, buttonState);
2583 }
2584
2585 /**
Siarhei Vishniakoub05b0b52018-12-28 17:50:24 -08002586 * Returns the classification for the current gesture.
2587 * The classification may change as more events become available for the same gesture.
2588 *
2589 * @see #CLASSIFICATION_NONE
2590 * @see #CLASSIFICATION_AMBIGUOUS_GESTURE
2591 * @see #CLASSIFICATION_DEEP_PRESS
2592 */
2593 public @Classification int getClassification() {
2594 return nativeGetClassification(mNativePtr);
2595 }
2596
2597 /**
Michael Wright5bd69e62015-05-14 14:48:08 +01002598 * Gets which button has been modified during a press or release action.
2599 *
2600 * For actions other than {@link #ACTION_BUTTON_PRESS} and {@link #ACTION_BUTTON_RELEASE}
2601 * the returned value is undefined.
2602 *
2603 * @see #getButtonState()
2604 */
2605 public final int getActionButton() {
2606 return nativeGetActionButton(mNativePtr);
2607 }
2608
2609 /**
Michael Wright6b819b42015-06-17 21:06:03 +01002610 * Sets the action button for the event.
2611 *
2612 * @see #getActionButton()
2613 * @hide
2614 */
Kirill Grouchnikovc0b0ba52016-09-13 16:09:37 -07002615 @TestApi
Michael Wright6b819b42015-06-17 21:06:03 +01002616 public final void setActionButton(int button) {
2617 nativeSetActionButton(mNativePtr, button);
2618 }
2619
2620 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002621 * Returns the original raw X coordinate of this event. For touch
2622 * events on the screen, this is the original location of the event
2623 * on the screen, before it had been adjusted for the containing window
2624 * and views.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002625 *
Michael Wright072137c2013-04-24 20:41:20 -07002626 * @see #getX(int)
Jeff Brown91c69ab2011-02-14 17:03:18 -08002627 * @see #AXIS_X
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002628 */
2629 public final float getRawX() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002630 return nativeGetRawAxisValue(mNativePtr, AXIS_X, 0, HISTORY_CURRENT);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002631 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08002632
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002633 /**
2634 * Returns the original raw Y coordinate of this event. For touch
2635 * events on the screen, this is the original location of the event
2636 * on the screen, before it had been adjusted for the containing window
2637 * and views.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002638 *
Michael Wright072137c2013-04-24 20:41:20 -07002639 * @see #getY(int)
Jeff Brown91c69ab2011-02-14 17:03:18 -08002640 * @see #AXIS_Y
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002641 */
2642 public final float getRawY() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002643 return nativeGetRawAxisValue(mNativePtr, AXIS_Y, 0, HISTORY_CURRENT);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002644 }
2645
2646 /**
Vishnu Nair18999552018-12-13 09:28:11 -08002647 * Returns the original raw X coordinate of this event. For touch
2648 * events on the screen, this is the original location of the event
2649 * on the screen, before it had been adjusted for the containing window
2650 * and views.
2651 *
2652 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2653 * (the first pointer that is down) to {@link #getPointerCount()}-1.
2654 *
2655 * @see #getX(int)
2656 * @see #AXIS_X
2657 */
2658 public float getRawX(int pointerIndex) {
2659 return nativeGetRawAxisValue(mNativePtr, AXIS_X, pointerIndex, HISTORY_CURRENT);
2660 }
2661
2662 /**
2663 * Returns the original raw Y coordinate of this event. For touch
2664 * events on the screen, this is the original location of the event
2665 * on the screen, before it had been adjusted for the containing window
2666 * and views.
2667 *
2668 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2669 * (the first pointer that is down) to {@link #getPointerCount()}-1.
2670 *
2671 * @see #getY(int)
2672 * @see #AXIS_Y
2673 */
2674 public float getRawY(int pointerIndex) {
2675 return nativeGetRawAxisValue(mNativePtr, AXIS_Y, pointerIndex, HISTORY_CURRENT);
2676 }
2677
2678 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002679 * Return the precision of the X coordinates being reported. You can
Jeff Brown91c69ab2011-02-14 17:03:18 -08002680 * multiply this number with {@link #getX} to find the actual hardware
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002681 * value of the X coordinate.
2682 * @return Returns the precision of X coordinates being reported.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002683 *
2684 * @see #AXIS_X
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002685 */
2686 public final float getXPrecision() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002687 return nativeGetXPrecision(mNativePtr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002688 }
Romain Guycafdea62009-06-12 10:51:36 -07002689
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002690 /**
2691 * Return the precision of the Y coordinates being reported. You can
Jeff Brown91c69ab2011-02-14 17:03:18 -08002692 * multiply this number with {@link #getY} to find the actual hardware
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002693 * value of the Y coordinate.
2694 * @return Returns the precision of Y coordinates being reported.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002695 *
2696 * @see #AXIS_Y
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002697 */
2698 public final float getYPrecision() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002699 return nativeGetYPrecision(mNativePtr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002700 }
Romain Guycafdea62009-06-12 10:51:36 -07002701
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002702 /**
2703 * Returns the number of historical points in this event. These are
2704 * movements that have occurred between this event and the previous event.
2705 * This only applies to ACTION_MOVE events -- all other actions will have
2706 * a size of 0.
Romain Guycafdea62009-06-12 10:51:36 -07002707 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002708 * @return Returns the number of historical points in the event.
2709 */
2710 public final int getHistorySize() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002711 return nativeGetHistorySize(mNativePtr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002712 }
Romain Guycafdea62009-06-12 10:51:36 -07002713
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002714 /**
2715 * Returns the time that a historical movement occurred between this event
Jeff Brownb11499d2012-04-20 19:54:22 -07002716 * and the previous event, in the {@link android.os.SystemClock#uptimeMillis} time base.
2717 * <p>
2718 * This only applies to ACTION_MOVE events.
2719 * </p>
Romain Guycafdea62009-06-12 10:51:36 -07002720 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002721 * @param pos Which historical value to return; must be less than
2722 * {@link #getHistorySize}
Jeff Brownb11499d2012-04-20 19:54:22 -07002723 * @return Returns the time that a historical movement occurred between this
2724 * event and the previous event,
2725 * in the {@link android.os.SystemClock#uptimeMillis} time base.
Romain Guycafdea62009-06-12 10:51:36 -07002726 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002727 * @see #getHistorySize
2728 * @see #getEventTime
2729 */
2730 public final long getHistoricalEventTime(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002731 return nativeGetEventTimeNanos(mNativePtr, pos) / NS_PER_MS;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002732 }
2733
2734 /**
Jeff Brownb11499d2012-04-20 19:54:22 -07002735 * Returns the time that a historical movement occurred between this event
2736 * and the previous event, in the {@link android.os.SystemClock#uptimeMillis} time base
2737 * but with nanosecond (instead of millisecond) precision.
2738 * <p>
2739 * This only applies to ACTION_MOVE events.
2740 * </p><p>
2741 * The value is in nanosecond precision but it may not have nanosecond accuracy.
2742 * </p>
2743 *
2744 * @param pos Which historical value to return; must be less than
2745 * {@link #getHistorySize}
2746 * @return Returns the time that a historical movement occurred between this
2747 * event and the previous event,
2748 * in the {@link android.os.SystemClock#uptimeMillis} time base but with
2749 * nanosecond (instead of millisecond) precision.
2750 *
2751 * @see #getHistorySize
2752 * @see #getEventTime
2753 *
2754 * @hide
2755 */
2756 public final long getHistoricalEventTimeNano(int pos) {
2757 return nativeGetEventTimeNanos(mNativePtr, pos);
2758 }
2759
2760 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08002761 * {@link #getHistoricalX(int, int)} for the first pointer index (may be an
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002762 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002763 *
2764 * @param pos Which historical value to return; must be less than
2765 * {@link #getHistorySize}
2766 *
2767 * @see #getHistorySize
2768 * @see #getX()
2769 * @see #AXIS_X
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002770 */
2771 public final float getHistoricalX(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002772 return nativeGetAxisValue(mNativePtr, AXIS_X, 0, pos);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002773 }
2774
2775 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08002776 * {@link #getHistoricalY(int, int)} for the first pointer index (may be an
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002777 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002778 *
2779 * @param pos Which historical value to return; must be less than
2780 * {@link #getHistorySize}
2781 *
2782 * @see #getHistorySize
2783 * @see #getY()
2784 * @see #AXIS_Y
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002785 */
2786 public final float getHistoricalY(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002787 return nativeGetAxisValue(mNativePtr, AXIS_Y, 0, pos);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002788 }
2789
2790 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08002791 * {@link #getHistoricalPressure(int, int)} for the first pointer index (may be an
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002792 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002793 *
2794 * @param pos Which historical value to return; must be less than
2795 * {@link #getHistorySize}
2796 *
2797 * @see #getHistorySize
2798 * @see #getPressure()
2799 * @see #AXIS_PRESSURE
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002800 */
2801 public final float getHistoricalPressure(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002802 return nativeGetAxisValue(mNativePtr, AXIS_PRESSURE, 0, pos);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002803 }
2804
2805 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08002806 * {@link #getHistoricalSize(int, int)} for the first pointer index (may be an
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002807 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002808 *
2809 * @param pos Which historical value to return; must be less than
2810 * {@link #getHistorySize}
2811 *
2812 * @see #getHistorySize
2813 * @see #getSize()
2814 * @see #AXIS_SIZE
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002815 */
2816 public final float getHistoricalSize(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002817 return nativeGetAxisValue(mNativePtr, AXIS_SIZE, 0, pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002818 }
Romain Guycafdea62009-06-12 10:51:36 -07002819
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002820 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08002821 * {@link #getHistoricalTouchMajor(int, int)} for the first pointer index (may be an
Jeff Brownc5ed5912010-07-14 18:48:53 -07002822 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002823 *
2824 * @param pos Which historical value to return; must be less than
2825 * {@link #getHistorySize}
2826 *
2827 * @see #getHistorySize
2828 * @see #getTouchMajor()
2829 * @see #AXIS_TOUCH_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002830 */
2831 public final float getHistoricalTouchMajor(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002832 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MAJOR, 0, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002833 }
2834
2835 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08002836 * {@link #getHistoricalTouchMinor(int, int)} for the first pointer index (may be an
Jeff Brownc5ed5912010-07-14 18:48:53 -07002837 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002838 *
2839 * @param pos Which historical value to return; must be less than
2840 * {@link #getHistorySize}
2841 *
2842 * @see #getHistorySize
2843 * @see #getTouchMinor()
2844 * @see #AXIS_TOUCH_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002845 */
2846 public final float getHistoricalTouchMinor(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002847 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MINOR, 0, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002848 }
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002849
Jeff Brownc5ed5912010-07-14 18:48:53 -07002850 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08002851 * {@link #getHistoricalToolMajor(int, int)} for the first pointer index (may be an
Jeff Brownc5ed5912010-07-14 18:48:53 -07002852 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002853 *
2854 * @param pos Which historical value to return; must be less than
2855 * {@link #getHistorySize}
2856 *
2857 * @see #getHistorySize
2858 * @see #getToolMajor()
2859 * @see #AXIS_TOOL_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002860 */
2861 public final float getHistoricalToolMajor(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002862 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MAJOR, 0, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002863 }
2864
2865 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08002866 * {@link #getHistoricalToolMinor(int, int)} for the first pointer index (may be an
Jeff Brownc5ed5912010-07-14 18:48:53 -07002867 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002868 *
2869 * @param pos Which historical value to return; must be less than
2870 * {@link #getHistorySize}
2871 *
2872 * @see #getHistorySize
2873 * @see #getToolMinor()
2874 * @see #AXIS_TOOL_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002875 */
2876 public final float getHistoricalToolMinor(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002877 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MINOR, 0, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002878 }
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002879
Jeff Brownc5ed5912010-07-14 18:48:53 -07002880 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08002881 * {@link #getHistoricalOrientation(int, int)} for the first pointer index (may be an
Jeff Brownc5ed5912010-07-14 18:48:53 -07002882 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002883 *
2884 * @param pos Which historical value to return; must be less than
2885 * {@link #getHistorySize}
2886 *
2887 * @see #getHistorySize
2888 * @see #getOrientation()
2889 * @see #AXIS_ORIENTATION
Jeff Brownc5ed5912010-07-14 18:48:53 -07002890 */
2891 public final float getHistoricalOrientation(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002892 return nativeGetAxisValue(mNativePtr, AXIS_ORIENTATION, 0, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002893 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08002894
2895 /**
2896 * {@link #getHistoricalAxisValue(int, int, int)} for the first pointer index (may be an
2897 * arbitrary pointer identifier).
2898 *
2899 * @param axis The axis identifier for the axis value to retrieve.
2900 * @param pos Which historical value to return; must be less than
2901 * {@link #getHistorySize}
2902 *
2903 * @see #getHistorySize
2904 * @see #getAxisValue(int)
2905 * @see #AXIS_X
2906 * @see #AXIS_Y
2907 */
2908 public final float getHistoricalAxisValue(int axis, int pos) {
2909 return nativeGetAxisValue(mNativePtr, axis, 0, pos);
2910 }
2911
Jeff Brownc5ed5912010-07-14 18:48:53 -07002912 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002913 * Returns a historical X coordinate, as per {@link #getX(int)}, that
2914 * occurred between this event and the previous event for the given pointer.
2915 * Only applies to ACTION_MOVE events.
Romain Guycafdea62009-06-12 10:51:36 -07002916 *
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002917 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2918 * (the first pointer that is down) to {@link #getPointerCount()}-1.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002919 * @param pos Which historical value to return; must be less than
2920 * {@link #getHistorySize}
Romain Guycafdea62009-06-12 10:51:36 -07002921 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002922 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08002923 * @see #getX(int)
2924 * @see #AXIS_X
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002925 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002926 public final float getHistoricalX(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002927 return nativeGetAxisValue(mNativePtr, AXIS_X, pointerIndex, pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002928 }
Romain Guycafdea62009-06-12 10:51:36 -07002929
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002930 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002931 * Returns a historical Y coordinate, as per {@link #getY(int)}, that
2932 * occurred between this event and the previous event for the given pointer.
2933 * Only applies to ACTION_MOVE events.
Romain Guycafdea62009-06-12 10:51:36 -07002934 *
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002935 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2936 * (the first pointer that is down) to {@link #getPointerCount()}-1.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002937 * @param pos Which historical value to return; must be less than
2938 * {@link #getHistorySize}
Romain Guycafdea62009-06-12 10:51:36 -07002939 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002940 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08002941 * @see #getY(int)
2942 * @see #AXIS_Y
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002943 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002944 public final float getHistoricalY(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002945 return nativeGetAxisValue(mNativePtr, AXIS_Y, pointerIndex, pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002946 }
Romain Guycafdea62009-06-12 10:51:36 -07002947
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002948 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002949 * Returns a historical pressure coordinate, as per {@link #getPressure(int)},
2950 * that occurred between this event and the previous event for the given
2951 * pointer. Only applies to ACTION_MOVE events.
Romain Guycafdea62009-06-12 10:51:36 -07002952 *
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002953 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2954 * (the first pointer that is down) to {@link #getPointerCount()}-1.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002955 * @param pos Which historical value to return; must be less than
2956 * {@link #getHistorySize}
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002957 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002958 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08002959 * @see #getPressure(int)
2960 * @see #AXIS_PRESSURE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002961 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002962 public final float getHistoricalPressure(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002963 return nativeGetAxisValue(mNativePtr, AXIS_PRESSURE, pointerIndex, pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002964 }
Romain Guycafdea62009-06-12 10:51:36 -07002965
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002966 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002967 * Returns a historical size coordinate, as per {@link #getSize(int)}, that
2968 * occurred between this event and the previous event for the given pointer.
2969 * Only applies to ACTION_MOVE events.
Romain Guycafdea62009-06-12 10:51:36 -07002970 *
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002971 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2972 * (the first pointer that is down) to {@link #getPointerCount()}-1.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002973 * @param pos Which historical value to return; must be less than
2974 * {@link #getHistorySize}
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002975 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002976 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08002977 * @see #getSize(int)
2978 * @see #AXIS_SIZE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002979 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002980 public final float getHistoricalSize(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002981 return nativeGetAxisValue(mNativePtr, AXIS_SIZE, pointerIndex, pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002982 }
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002983
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002984 /**
Jeff Brownc5ed5912010-07-14 18:48:53 -07002985 * Returns a historical touch major axis coordinate, as per {@link #getTouchMajor(int)}, that
2986 * occurred between this event and the previous event for the given pointer.
2987 * Only applies to ACTION_MOVE events.
2988 *
2989 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2990 * (the first pointer that is down) to {@link #getPointerCount()}-1.
2991 * @param pos Which historical value to return; must be less than
2992 * {@link #getHistorySize}
Dennis Kempinac1b31d2016-11-02 17:02:25 -07002993 *
Jeff Brownc5ed5912010-07-14 18:48:53 -07002994 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08002995 * @see #getTouchMajor(int)
2996 * @see #AXIS_TOUCH_MAJOR
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002997 */
Jeff Brownc5ed5912010-07-14 18:48:53 -07002998 public final float getHistoricalTouchMajor(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002999 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MAJOR, pointerIndex, pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003000 }
Romain Guycafdea62009-06-12 10:51:36 -07003001
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003002 /**
Jeff Brownc5ed5912010-07-14 18:48:53 -07003003 * Returns a historical touch minor axis coordinate, as per {@link #getTouchMinor(int)}, that
3004 * occurred between this event and the previous event for the given pointer.
3005 * Only applies to ACTION_MOVE events.
3006 *
3007 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
3008 * (the first pointer that is down) to {@link #getPointerCount()}-1.
3009 * @param pos Which historical value to return; must be less than
3010 * {@link #getHistorySize}
Dennis Kempinac1b31d2016-11-02 17:02:25 -07003011 *
Jeff Brownc5ed5912010-07-14 18:48:53 -07003012 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08003013 * @see #getTouchMinor(int)
3014 * @see #AXIS_TOUCH_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07003015 */
3016 public final float getHistoricalTouchMinor(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08003017 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MINOR, pointerIndex, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07003018 }
3019
3020 /**
3021 * Returns a historical tool major axis coordinate, as per {@link #getToolMajor(int)}, that
3022 * occurred between this event and the previous event for the given pointer.
3023 * Only applies to ACTION_MOVE events.
3024 *
3025 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
3026 * (the first pointer that is down) to {@link #getPointerCount()}-1.
3027 * @param pos Which historical value to return; must be less than
3028 * {@link #getHistorySize}
Dennis Kempinac1b31d2016-11-02 17:02:25 -07003029 *
Jeff Brownc5ed5912010-07-14 18:48:53 -07003030 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08003031 * @see #getToolMajor(int)
3032 * @see #AXIS_TOOL_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07003033 */
3034 public final float getHistoricalToolMajor(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08003035 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MAJOR, pointerIndex, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07003036 }
3037
3038 /**
3039 * Returns a historical tool minor axis coordinate, as per {@link #getToolMinor(int)}, that
3040 * occurred between this event and the previous event for the given pointer.
3041 * Only applies to ACTION_MOVE events.
3042 *
3043 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
3044 * (the first pointer that is down) to {@link #getPointerCount()}-1.
3045 * @param pos Which historical value to return; must be less than
3046 * {@link #getHistorySize}
Dennis Kempinac1b31d2016-11-02 17:02:25 -07003047 *
Jeff Brownc5ed5912010-07-14 18:48:53 -07003048 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08003049 * @see #getToolMinor(int)
3050 * @see #AXIS_TOOL_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07003051 */
3052 public final float getHistoricalToolMinor(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08003053 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MINOR, pointerIndex, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07003054 }
3055
3056 /**
3057 * Returns a historical orientation coordinate, as per {@link #getOrientation(int)}, that
3058 * occurred between this event and the previous event for the given pointer.
3059 * Only applies to ACTION_MOVE events.
3060 *
3061 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
3062 * (the first pointer that is down) to {@link #getPointerCount()}-1.
3063 * @param pos Which historical value to return; must be less than
3064 * {@link #getHistorySize}
Dennis Kempinac1b31d2016-11-02 17:02:25 -07003065 *
Jeff Brownc5ed5912010-07-14 18:48:53 -07003066 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08003067 * @see #getOrientation(int)
3068 * @see #AXIS_ORIENTATION
Jeff Brownc5ed5912010-07-14 18:48:53 -07003069 */
3070 public final float getHistoricalOrientation(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08003071 return nativeGetAxisValue(mNativePtr, AXIS_ORIENTATION, pointerIndex, pos);
3072 }
3073
3074 /**
3075 * Returns the historical value of the requested axis, as per {@link #getAxisValue(int, int)},
3076 * occurred between this event and the previous event for the given pointer.
3077 * Only applies to ACTION_MOVE events.
3078 *
3079 * @param axis The axis identifier for the axis value to retrieve.
3080 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
3081 * (the first pointer that is down) to {@link #getPointerCount()}-1.
3082 * @param pos Which historical value to return; must be less than
3083 * {@link #getHistorySize}
3084 * @return The value of the axis, or 0 if the axis is not available.
3085 *
3086 * @see #AXIS_X
3087 * @see #AXIS_Y
3088 */
3089 public final float getHistoricalAxisValue(int axis, int pointerIndex, int pos) {
3090 return nativeGetAxisValue(mNativePtr, axis, pointerIndex, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07003091 }
3092
3093 /**
3094 * Populates a {@link PointerCoords} object with historical pointer coordinate data,
3095 * as per {@link #getPointerCoords}, that occurred between this event and the previous
3096 * event for the given pointer.
3097 * Only applies to ACTION_MOVE events.
Dennis Kempinac1b31d2016-11-02 17:02:25 -07003098 *
Jeff Brownc5ed5912010-07-14 18:48:53 -07003099 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
3100 * (the first pointer that is down) to {@link #getPointerCount()}-1.
3101 * @param pos Which historical value to return; must be less than
3102 * {@link #getHistorySize}
3103 * @param outPointerCoords The pointer coordinate object to populate.
Dennis Kempinac1b31d2016-11-02 17:02:25 -07003104 *
Jeff Brownc5ed5912010-07-14 18:48:53 -07003105 * @see #getHistorySize
3106 * @see #getPointerCoords
Jeff Brown91c69ab2011-02-14 17:03:18 -08003107 * @see PointerCoords
Jeff Brownc5ed5912010-07-14 18:48:53 -07003108 */
3109 public final void getHistoricalPointerCoords(int pointerIndex, int pos,
3110 PointerCoords outPointerCoords) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08003111 nativeGetPointerCoords(mNativePtr, pointerIndex, pos, outPointerCoords);
Jeff Brownc5ed5912010-07-14 18:48:53 -07003112 }
Dennis Kempinac1b31d2016-11-02 17:02:25 -07003113
Jeff Brownc5ed5912010-07-14 18:48:53 -07003114 /**
Jeff Brown46b9ac02010-04-22 18:58:52 -07003115 * Returns a bitfield indicating which edges, if any, were touched by this
Romain Guycafdea62009-06-12 10:51:36 -07003116 * MotionEvent. For touch events, clients can use this to determine if the
3117 * user's finger was touching the edge of the display.
3118 *
Jeff Brownd41cff22011-03-03 02:09:54 -08003119 * This property is only set for {@link #ACTION_DOWN} events.
3120 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003121 * @see #EDGE_LEFT
3122 * @see #EDGE_TOP
3123 * @see #EDGE_RIGHT
3124 * @see #EDGE_BOTTOM
3125 */
3126 public final int getEdgeFlags() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08003127 return nativeGetEdgeFlags(mNativePtr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003128 }
Romain Guycafdea62009-06-12 10:51:36 -07003129
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003130 /**
Jeff Brown85a31762010-09-01 17:01:00 -07003131 * Sets the bitfield indicating which edges, if any, were touched by this
Romain Guycafdea62009-06-12 10:51:36 -07003132 * MotionEvent.
3133 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003134 * @see #getEdgeFlags()
3135 */
3136 public final void setEdgeFlags(int flags) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08003137 nativeSetEdgeFlags(mNativePtr, flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003138 }
3139
3140 /**
3141 * Sets this event's action.
3142 */
3143 public final void setAction(int action) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08003144 nativeSetAction(mNativePtr, action);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003145 }
3146
3147 /**
3148 * Adjust this event's location.
3149 * @param deltaX Amount to add to the current X coordinate of the event.
3150 * @param deltaY Amount to add to the current Y coordinate of the event.
3151 */
3152 public final void offsetLocation(float deltaX, float deltaY) {
Jeff Brown9ea77fc2012-03-21 19:49:27 -07003153 if (deltaX != 0.0f || deltaY != 0.0f) {
3154 nativeOffsetLocation(mNativePtr, deltaX, deltaY);
3155 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003156 }
Romain Guycafdea62009-06-12 10:51:36 -07003157
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003158 /**
3159 * Set this event's location. Applies {@link #offsetLocation} with a
3160 * delta from the current location to the given new location.
Romain Guycafdea62009-06-12 10:51:36 -07003161 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003162 * @param x New absolute X location.
3163 * @param y New absolute Y location.
3164 */
3165 public final void setLocation(float x, float y) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08003166 float oldX = getX();
3167 float oldY = getY();
Jeff Brown9ea77fc2012-03-21 19:49:27 -07003168 offsetLocation(x - oldX, y - oldY);
Jeff Brown5c225b12010-06-16 01:53:36 -07003169 }
Dennis Kempinac1b31d2016-11-02 17:02:25 -07003170
Jeff Brown20e987b2010-08-23 12:01:02 -07003171 /**
3172 * Applies a transformation matrix to all of the points in the event.
3173 *
3174 * @param matrix The transformation matrix to apply.
3175 */
3176 public final void transform(Matrix matrix) {
3177 if (matrix == null) {
3178 throw new IllegalArgumentException("matrix must not be null");
3179 }
3180
John Reck09709972016-10-03 15:47:18 -07003181 nativeTransform(mNativePtr, matrix.native_instance);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003182 }
Romain Guycafdea62009-06-12 10:51:36 -07003183
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003184 /**
3185 * Add a new movement to the batch of movements in this event. The event's
Jeff Brownc5ed5912010-07-14 18:48:53 -07003186 * current location, position and size is updated to the new values.
3187 * The current values in the event are added to a list of historical values.
Jeff Brown91c69ab2011-02-14 17:03:18 -08003188 *
Jeff Browncc0c1592011-02-19 05:07:28 -08003189 * Only applies to {@link #ACTION_MOVE} or {@link #ACTION_HOVER_MOVE} events.
Romain Guycafdea62009-06-12 10:51:36 -07003190 *
Jeff Brownc5ed5912010-07-14 18:48:53 -07003191 * @param eventTime The time stamp (in ms) for this data.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003192 * @param x The new X position.
3193 * @param y The new Y position.
3194 * @param pressure The new pressure.
3195 * @param size The new size.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07003196 * @param metaState Meta key state.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003197 */
3198 public final void addBatch(long eventTime, float x, float y,
3199 float pressure, float size, int metaState) {
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003200 synchronized (gSharedTempLock) {
3201 ensureSharedTempPointerCapacity(1);
3202 final PointerCoords[] pc = gSharedTempPointerCoords;
3203 pc[0].clear();
3204 pc[0].x = x;
3205 pc[0].y = y;
3206 pc[0].pressure = pressure;
3207 pc[0].size = size;
3208
3209 nativeAddBatch(mNativePtr, eventTime * NS_PER_MS, pc, metaState);
Jeff Brown91c69ab2011-02-14 17:03:18 -08003210 }
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07003211 }
Romain Guycafdea62009-06-12 10:51:36 -07003212
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07003213 /**
Jeff Brownc5ed5912010-07-14 18:48:53 -07003214 * Add a new movement to the batch of movements in this event. The event's
3215 * current location, position and size is updated to the new values.
3216 * The current values in the event are added to a list of historical values.
Jeff Brown91c69ab2011-02-14 17:03:18 -08003217 *
Jeff Browncc0c1592011-02-19 05:07:28 -08003218 * Only applies to {@link #ACTION_MOVE} or {@link #ACTION_HOVER_MOVE} events.
Jeff Brownc5ed5912010-07-14 18:48:53 -07003219 *
3220 * @param eventTime The time stamp (in ms) for this data.
3221 * @param pointerCoords The new pointer coordinates.
3222 * @param metaState Meta key state.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07003223 */
Jeff Brownc5ed5912010-07-14 18:48:53 -07003224 public final void addBatch(long eventTime, PointerCoords[] pointerCoords, int metaState) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08003225 nativeAddBatch(mNativePtr, eventTime * NS_PER_MS, pointerCoords, metaState);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003226 }
Romain Guycafdea62009-06-12 10:51:36 -07003227
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003228 /**
Jeff Brown9d3bdbd2012-03-21 11:50:06 -07003229 * Adds all of the movement samples of the specified event to this one if
3230 * it is compatible. To be compatible, the event must have the same device id,
Siarhei Vishniakoub05b0b52018-12-28 17:50:24 -08003231 * source, display id, action, flags, classification, pointer count, pointer properties.
Jeff Brown9d3bdbd2012-03-21 11:50:06 -07003232 *
3233 * Only applies to {@link #ACTION_MOVE} or {@link #ACTION_HOVER_MOVE} events.
3234 *
3235 * @param event The event whose movements samples should be added to this one
3236 * if possible.
3237 * @return True if batching was performed or false if batching was not possible.
3238 * @hide
3239 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01003240 @UnsupportedAppUsage
Jeff Brown9d3bdbd2012-03-21 11:50:06 -07003241 public final boolean addBatch(MotionEvent event) {
3242 final int action = nativeGetAction(mNativePtr);
3243 if (action != ACTION_MOVE && action != ACTION_HOVER_MOVE) {
3244 return false;
3245 }
3246 if (action != nativeGetAction(event.mNativePtr)) {
3247 return false;
3248 }
3249
3250 if (nativeGetDeviceId(mNativePtr) != nativeGetDeviceId(event.mNativePtr)
3251 || nativeGetSource(mNativePtr) != nativeGetSource(event.mNativePtr)
Siarhei Vishniakou85ddfff2018-01-31 16:49:36 -08003252 || nativeGetDisplayId(mNativePtr) != nativeGetDisplayId(event.mNativePtr)
Siarhei Vishniakoub05b0b52018-12-28 17:50:24 -08003253 || nativeGetFlags(mNativePtr) != nativeGetFlags(event.mNativePtr)
3254 || nativeGetClassification(mNativePtr)
3255 != nativeGetClassification(event.mNativePtr)) {
Jeff Brown9d3bdbd2012-03-21 11:50:06 -07003256 return false;
3257 }
3258
3259 final int pointerCount = nativeGetPointerCount(mNativePtr);
3260 if (pointerCount != nativeGetPointerCount(event.mNativePtr)) {
3261 return false;
3262 }
3263
3264 synchronized (gSharedTempLock) {
3265 ensureSharedTempPointerCapacity(Math.max(pointerCount, 2));
3266 final PointerProperties[] pp = gSharedTempPointerProperties;
3267 final PointerCoords[] pc = gSharedTempPointerCoords;
3268
3269 for (int i = 0; i < pointerCount; i++) {
3270 nativeGetPointerProperties(mNativePtr, i, pp[0]);
3271 nativeGetPointerProperties(event.mNativePtr, i, pp[1]);
3272 if (!pp[0].equals(pp[1])) {
3273 return false;
3274 }
3275 }
3276
3277 final int metaState = nativeGetMetaState(event.mNativePtr);
3278 final int historySize = nativeGetHistorySize(event.mNativePtr);
3279 for (int h = 0; h <= historySize; h++) {
3280 final int historyPos = (h == historySize ? HISTORY_CURRENT : h);
3281
3282 for (int i = 0; i < pointerCount; i++) {
3283 nativeGetPointerCoords(event.mNativePtr, i, historyPos, pc[i]);
3284 }
3285
3286 final long eventTimeNanos = nativeGetEventTimeNanos(event.mNativePtr, historyPos);
3287 nativeAddBatch(mNativePtr, eventTimeNanos, pc, metaState);
3288 }
3289 }
3290 return true;
3291 }
3292
3293 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003294 * Returns true if all points in the motion event are completely within the specified bounds.
3295 * @hide
3296 */
3297 public final boolean isWithinBoundsNoHistory(float left, float top,
3298 float right, float bottom) {
3299 final int pointerCount = nativeGetPointerCount(mNativePtr);
3300 for (int i = 0; i < pointerCount; i++) {
3301 final float x = nativeGetAxisValue(mNativePtr, AXIS_X, i, HISTORY_CURRENT);
3302 final float y = nativeGetAxisValue(mNativePtr, AXIS_Y, i, HISTORY_CURRENT);
3303 if (x < left || x > right || y < top || y > bottom) {
3304 return false;
3305 }
3306 }
3307 return true;
3308 }
3309
3310 private static final float clamp(float value, float low, float high) {
3311 if (value < low) {
3312 return low;
3313 } else if (value > high) {
3314 return high;
3315 }
3316 return value;
3317 }
3318
3319 /**
3320 * Returns a new motion events whose points have been clamped to the specified bounds.
3321 * @hide
3322 */
3323 public final MotionEvent clampNoHistory(float left, float top, float right, float bottom) {
3324 MotionEvent ev = obtain();
3325 synchronized (gSharedTempLock) {
3326 final int pointerCount = nativeGetPointerCount(mNativePtr);
3327
3328 ensureSharedTempPointerCapacity(pointerCount);
3329 final PointerProperties[] pp = gSharedTempPointerProperties;
3330 final PointerCoords[] pc = gSharedTempPointerCoords;
3331
3332 for (int i = 0; i < pointerCount; i++) {
3333 nativeGetPointerProperties(mNativePtr, i, pp[i]);
3334 nativeGetPointerCoords(mNativePtr, i, HISTORY_CURRENT, pc[i]);
3335 pc[i].x = clamp(pc[i].x, left, right);
3336 pc[i].y = clamp(pc[i].y, top, bottom);
3337 }
3338 ev.mNativePtr = nativeInitialize(ev.mNativePtr,
3339 nativeGetDeviceId(mNativePtr), nativeGetSource(mNativePtr),
Siarhei Vishniakou85ddfff2018-01-31 16:49:36 -08003340 nativeGetDisplayId(mNativePtr),
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003341 nativeGetAction(mNativePtr), nativeGetFlags(mNativePtr),
3342 nativeGetEdgeFlags(mNativePtr), nativeGetMetaState(mNativePtr),
Siarhei Vishniakoub05b0b52018-12-28 17:50:24 -08003343 nativeGetButtonState(mNativePtr), nativeGetClassification(mNativePtr),
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003344 nativeGetXOffset(mNativePtr), nativeGetYOffset(mNativePtr),
3345 nativeGetXPrecision(mNativePtr), nativeGetYPrecision(mNativePtr),
3346 nativeGetDownTimeNanos(mNativePtr),
3347 nativeGetEventTimeNanos(mNativePtr, HISTORY_CURRENT),
3348 pointerCount, pp, pc);
3349 return ev;
3350 }
3351 }
3352
3353 /**
3354 * Gets an integer where each pointer id present in the event is marked as a bit.
3355 * @hide
3356 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01003357 @UnsupportedAppUsage
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003358 public final int getPointerIdBits() {
3359 int idBits = 0;
3360 final int pointerCount = nativeGetPointerCount(mNativePtr);
3361 for (int i = 0; i < pointerCount; i++) {
3362 idBits |= 1 << nativeGetPointerId(mNativePtr, i);
3363 }
3364 return idBits;
3365 }
3366
3367 /**
3368 * Splits a motion event such that it includes only a subset of pointer ids.
3369 * @hide
3370 */
Mathew Inwooda570dee2018-08-17 14:56:00 +01003371 @UnsupportedAppUsage
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003372 public final MotionEvent split(int idBits) {
3373 MotionEvent ev = obtain();
3374 synchronized (gSharedTempLock) {
3375 final int oldPointerCount = nativeGetPointerCount(mNativePtr);
3376 ensureSharedTempPointerCapacity(oldPointerCount);
3377 final PointerProperties[] pp = gSharedTempPointerProperties;
3378 final PointerCoords[] pc = gSharedTempPointerCoords;
3379 final int[] map = gSharedTempPointerIndexMap;
3380
3381 final int oldAction = nativeGetAction(mNativePtr);
3382 final int oldActionMasked = oldAction & ACTION_MASK;
3383 final int oldActionPointerIndex = (oldAction & ACTION_POINTER_INDEX_MASK)
3384 >> ACTION_POINTER_INDEX_SHIFT;
3385 int newActionPointerIndex = -1;
3386 int newPointerCount = 0;
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003387 for (int i = 0; i < oldPointerCount; i++) {
3388 nativeGetPointerProperties(mNativePtr, i, pp[newPointerCount]);
3389 final int idBit = 1 << pp[newPointerCount].id;
3390 if ((idBit & idBits) != 0) {
3391 if (i == oldActionPointerIndex) {
3392 newActionPointerIndex = newPointerCount;
3393 }
3394 map[newPointerCount] = i;
3395 newPointerCount += 1;
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003396 }
3397 }
3398
3399 if (newPointerCount == 0) {
3400 throw new IllegalArgumentException("idBits did not match any ids in the event");
3401 }
3402
3403 final int newAction;
3404 if (oldActionMasked == ACTION_POINTER_DOWN || oldActionMasked == ACTION_POINTER_UP) {
3405 if (newActionPointerIndex < 0) {
3406 // An unrelated pointer changed.
3407 newAction = ACTION_MOVE;
3408 } else if (newPointerCount == 1) {
3409 // The first/last pointer went down/up.
3410 newAction = oldActionMasked == ACTION_POINTER_DOWN
3411 ? ACTION_DOWN : ACTION_UP;
3412 } else {
3413 // A secondary pointer went down/up.
3414 newAction = oldActionMasked
3415 | (newActionPointerIndex << ACTION_POINTER_INDEX_SHIFT);
3416 }
3417 } else {
3418 // Simple up/down/cancel/move or other motion action.
3419 newAction = oldAction;
3420 }
3421
3422 final int historySize = nativeGetHistorySize(mNativePtr);
3423 for (int h = 0; h <= historySize; h++) {
3424 final int historyPos = h == historySize ? HISTORY_CURRENT : h;
3425
3426 for (int i = 0; i < newPointerCount; i++) {
3427 nativeGetPointerCoords(mNativePtr, map[i], historyPos, pc[i]);
3428 }
3429
3430 final long eventTimeNanos = nativeGetEventTimeNanos(mNativePtr, historyPos);
3431 if (h == 0) {
3432 ev.mNativePtr = nativeInitialize(ev.mNativePtr,
3433 nativeGetDeviceId(mNativePtr), nativeGetSource(mNativePtr),
Siarhei Vishniakou85ddfff2018-01-31 16:49:36 -08003434 nativeGetDisplayId(mNativePtr),
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003435 newAction, nativeGetFlags(mNativePtr),
3436 nativeGetEdgeFlags(mNativePtr), nativeGetMetaState(mNativePtr),
Siarhei Vishniakoub05b0b52018-12-28 17:50:24 -08003437 nativeGetButtonState(mNativePtr), nativeGetClassification(mNativePtr),
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003438 nativeGetXOffset(mNativePtr), nativeGetYOffset(mNativePtr),
3439 nativeGetXPrecision(mNativePtr), nativeGetYPrecision(mNativePtr),
3440 nativeGetDownTimeNanos(mNativePtr), eventTimeNanos,
3441 newPointerCount, pp, pc);
3442 } else {
3443 nativeAddBatch(ev.mNativePtr, eventTimeNanos, pc, 0);
3444 }
3445 }
3446 return ev;
3447 }
3448 }
3449
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003450 @Override
3451 public String toString() {
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003452 StringBuilder msg = new StringBuilder();
3453 msg.append("MotionEvent { action=").append(actionToString(getAction()));
Eugene Suslae6e55b52018-01-11 15:12:56 -08003454 appendUnless("0", msg, ", actionButton=", buttonStateToString(getActionButton()));
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003455
3456 final int pointerCount = getPointerCount();
3457 for (int i = 0; i < pointerCount; i++) {
Eugene Suslae6e55b52018-01-11 15:12:56 -08003458 appendUnless(i, msg, ", id[" + i + "]=", getPointerId(i));
3459 float x = getX(i);
3460 float y = getY(i);
3461 if (!DEBUG_CONCISE_TOSTRING || x != 0f || y != 0f) {
3462 msg.append(", x[").append(i).append("]=").append(x);
3463 msg.append(", y[").append(i).append("]=").append(y);
3464 }
3465 appendUnless(TOOL_TYPE_SYMBOLIC_NAMES.get(TOOL_TYPE_FINGER),
3466 msg, ", toolType[" + i + "]=", toolTypeToString(getToolType(i)));
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003467 }
3468
Eugene Suslae6e55b52018-01-11 15:12:56 -08003469 appendUnless("0", msg, ", buttonState=", MotionEvent.buttonStateToString(getButtonState()));
Siarhei Vishniakoub05b0b52018-12-28 17:50:24 -08003470 appendUnless(classificationToString(CLASSIFICATION_NONE), msg, ", classification=",
3471 classificationToString(getClassification()));
Eugene Suslae6e55b52018-01-11 15:12:56 -08003472 appendUnless("0", msg, ", metaState=", KeyEvent.metaStateToString(getMetaState()));
3473 appendUnless("0", msg, ", flags=0x", Integer.toHexString(getFlags()));
3474 appendUnless("0", msg, ", edgeFlags=0x", Integer.toHexString(getEdgeFlags()));
3475 appendUnless(1, msg, ", pointerCount=", pointerCount);
3476 appendUnless(0, msg, ", historySize=", getHistorySize());
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003477 msg.append(", eventTime=").append(getEventTime());
Eugene Suslae6e55b52018-01-11 15:12:56 -08003478 if (!DEBUG_CONCISE_TOSTRING) {
3479 msg.append(", downTime=").append(getDownTime());
3480 msg.append(", deviceId=").append(getDeviceId());
3481 msg.append(", source=0x").append(Integer.toHexString(getSource()));
Siarhei Vishniakou85ddfff2018-01-31 16:49:36 -08003482 msg.append(", displayId=").append(getDisplayId());
Eugene Suslae6e55b52018-01-11 15:12:56 -08003483 }
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003484 msg.append(" }");
3485 return msg.toString();
Jeff Brown497a92c2010-09-12 17:55:08 -07003486 }
3487
Eugene Suslae6e55b52018-01-11 15:12:56 -08003488 private static <T> void appendUnless(T defValue, StringBuilder sb, String key, T value) {
3489 if (DEBUG_CONCISE_TOSTRING && Objects.equals(defValue, value)) return;
3490 sb.append(key).append(value);
3491 }
3492
Jeff Brown497a92c2010-09-12 17:55:08 -07003493 /**
John Spurlock4dad6ca2013-06-05 13:17:05 -04003494 * Returns a string that represents the symbolic name of the specified unmasked action
Jeff Brown91c69ab2011-02-14 17:03:18 -08003495 * such as "ACTION_DOWN", "ACTION_POINTER_DOWN(3)" or an equivalent numeric constant
3496 * such as "35" if unknown.
Jeff Brown497a92c2010-09-12 17:55:08 -07003497 *
John Spurlock4dad6ca2013-06-05 13:17:05 -04003498 * @param action The unmasked action.
Jeff Brown497a92c2010-09-12 17:55:08 -07003499 * @return The symbolic name of the specified action.
John Spurlock4dad6ca2013-06-05 13:17:05 -04003500 * @see #getAction()
Jeff Brown497a92c2010-09-12 17:55:08 -07003501 */
3502 public static String actionToString(int action) {
3503 switch (action) {
3504 case ACTION_DOWN:
3505 return "ACTION_DOWN";
3506 case ACTION_UP:
3507 return "ACTION_UP";
3508 case ACTION_CANCEL:
3509 return "ACTION_CANCEL";
Jeff Brown33bbfd22011-02-24 20:55:35 -08003510 case ACTION_OUTSIDE:
3511 return "ACTION_OUTSIDE";
Jeff Brown497a92c2010-09-12 17:55:08 -07003512 case ACTION_MOVE:
3513 return "ACTION_MOVE";
Jeff Browncc0c1592011-02-19 05:07:28 -08003514 case ACTION_HOVER_MOVE:
3515 return "ACTION_HOVER_MOVE";
Jeff Brown33bbfd22011-02-24 20:55:35 -08003516 case ACTION_SCROLL:
3517 return "ACTION_SCROLL";
Jeff Browna032cc02011-03-07 16:56:21 -08003518 case ACTION_HOVER_ENTER:
3519 return "ACTION_HOVER_ENTER";
3520 case ACTION_HOVER_EXIT:
3521 return "ACTION_HOVER_EXIT";
Michael Wright5bd69e62015-05-14 14:48:08 +01003522 case ACTION_BUTTON_PRESS:
3523 return "ACTION_BUTTON_PRESS";
3524 case ACTION_BUTTON_RELEASE:
3525 return "ACTION_BUTTON_RELEASE";
Jeff Brown497a92c2010-09-12 17:55:08 -07003526 }
3527 int index = (action & ACTION_POINTER_INDEX_MASK) >> ACTION_POINTER_INDEX_SHIFT;
3528 switch (action & ACTION_MASK) {
3529 case ACTION_POINTER_DOWN:
3530 return "ACTION_POINTER_DOWN(" + index + ")";
3531 case ACTION_POINTER_UP:
3532 return "ACTION_POINTER_UP(" + index + ")";
3533 default:
3534 return Integer.toString(action);
3535 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003536 }
3537
Jeff Brown91c69ab2011-02-14 17:03:18 -08003538 /**
3539 * Returns a string that represents the symbolic name of the specified axis
Jeff Brown6f2fba42011-02-19 01:08:02 -08003540 * such as "AXIS_X" or an equivalent numeric constant such as "42" if unknown.
Jeff Brown91c69ab2011-02-14 17:03:18 -08003541 *
John Spurlock4dad6ca2013-06-05 13:17:05 -04003542 * @param axis The axis.
Jeff Brown91c69ab2011-02-14 17:03:18 -08003543 * @return The symbolic name of the specified axis.
Jeff Brown91c69ab2011-02-14 17:03:18 -08003544 */
3545 public static String axisToString(int axis) {
Michael Wright337d9d22014-04-22 15:03:48 -07003546 String symbolicName = nativeAxisToString(axis);
3547 return symbolicName != null ? LABEL_PREFIX + symbolicName : Integer.toString(axis);
Jeff Brown6f2fba42011-02-19 01:08:02 -08003548 }
3549
3550 /**
Jeff Browncc0c1592011-02-19 05:07:28 -08003551 * Gets an axis by its symbolic name such as "AXIS_X" or an
3552 * equivalent numeric constant such as "42".
Jeff Brown6f2fba42011-02-19 01:08:02 -08003553 *
3554 * @param symbolicName The symbolic name of the axis.
3555 * @return The axis or -1 if not found.
John Spurlock4dad6ca2013-06-05 13:17:05 -04003556 * @see KeyEvent#keyCodeToString(int)
Jeff Brown6f2fba42011-02-19 01:08:02 -08003557 */
3558 public static int axisFromString(String symbolicName) {
Michael Wright337d9d22014-04-22 15:03:48 -07003559 if (symbolicName.startsWith(LABEL_PREFIX)) {
3560 symbolicName = symbolicName.substring(LABEL_PREFIX.length());
Michael Wright973efa02014-05-13 15:38:56 -07003561 int axis = nativeAxisFromString(symbolicName);
3562 if (axis >= 0) {
3563 return axis;
3564 }
Jeff Brown6f2fba42011-02-19 01:08:02 -08003565 }
Jeff Brown6f2fba42011-02-19 01:08:02 -08003566 try {
3567 return Integer.parseInt(symbolicName, 10);
3568 } catch (NumberFormatException ex) {
3569 return -1;
Jeff Brown91c69ab2011-02-14 17:03:18 -08003570 }
3571 }
3572
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003573 /**
3574 * Returns a string that represents the symbolic name of the specified combined
3575 * button state flags such as "0", "BUTTON_PRIMARY",
3576 * "BUTTON_PRIMARY|BUTTON_SECONDARY" or an equivalent numeric constant such as "0x10000000"
3577 * if unknown.
3578 *
3579 * @param buttonState The button state.
3580 * @return The symbolic name of the specified combined button state flags.
3581 * @hide
3582 */
3583 public static String buttonStateToString(int buttonState) {
3584 if (buttonState == 0) {
3585 return "0";
3586 }
3587 StringBuilder result = null;
3588 int i = 0;
3589 while (buttonState != 0) {
3590 final boolean isSet = (buttonState & 1) != 0;
3591 buttonState >>>= 1; // unsigned shift!
3592 if (isSet) {
3593 final String name = BUTTON_SYMBOLIC_NAMES[i];
3594 if (result == null) {
3595 if (buttonState == 0) {
3596 return name;
3597 }
3598 result = new StringBuilder(name);
3599 } else {
3600 result.append('|');
3601 result.append(name);
3602 }
3603 }
3604 i += 1;
3605 }
3606 return result.toString();
3607 }
3608
3609 /**
Siarhei Vishniakoub05b0b52018-12-28 17:50:24 -08003610 * Returns a string that represents the symbolic name of the specified classification.
3611 *
3612 * @param classification The classification type.
3613 * @return The symbolic name of this classification.
3614 * @hide
3615 */
3616 public static String classificationToString(@Classification int classification) {
3617 switch (classification) {
3618 case CLASSIFICATION_NONE:
3619 return "NONE";
3620 case CLASSIFICATION_AMBIGUOUS_GESTURE:
3621 return "AMBIGUOUS_GESTURE";
3622 case CLASSIFICATION_DEEP_PRESS:
3623 return "DEEP_PRESS";
3624
3625 }
3626 return "NONE";
3627 }
3628
3629 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003630 * Returns a string that represents the symbolic name of the specified tool type
3631 * such as "TOOL_TYPE_FINGER" or an equivalent numeric constant such as "42" if unknown.
3632 *
3633 * @param toolType The tool type.
3634 * @return The symbolic name of the specified tool type.
3635 * @hide
3636 */
3637 public static String toolTypeToString(int toolType) {
3638 String symbolicName = TOOL_TYPE_SYMBOLIC_NAMES.get(toolType);
3639 return symbolicName != null ? symbolicName : Integer.toString(toolType);
3640 }
3641
Sujith Ramakrishnancc32bd82014-05-19 15:32:13 -07003642 /**
3643 * Checks if a mouse or stylus button (or combination of buttons) is pressed.
3644 * @param button Button (or combination of buttons).
3645 * @return True if specified buttons are pressed.
3646 *
3647 * @see #BUTTON_PRIMARY
3648 * @see #BUTTON_SECONDARY
3649 * @see #BUTTON_TERTIARY
3650 * @see #BUTTON_FORWARD
3651 * @see #BUTTON_BACK
Michael Wright5bd69e62015-05-14 14:48:08 +01003652 * @see #BUTTON_STYLUS_PRIMARY
3653 * @see #BUTTON_STYLUS_SECONDARY
Sujith Ramakrishnancc32bd82014-05-19 15:32:13 -07003654 */
3655 public final boolean isButtonPressed(int button) {
3656 if (button == 0) {
3657 return false;
3658 }
3659 return (getButtonState() & button) == button;
3660 }
3661
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003662 public static final Parcelable.Creator<MotionEvent> CREATOR
3663 = new Parcelable.Creator<MotionEvent>() {
3664 public MotionEvent createFromParcel(Parcel in) {
Jeff Brown6ec402b2010-07-28 15:48:59 -07003665 in.readInt(); // skip token, we already know this is a MotionEvent
3666 return MotionEvent.createFromParcelBody(in);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003667 }
3668
3669 public MotionEvent[] newArray(int size) {
3670 return new MotionEvent[size];
3671 }
3672 };
3673
Jeff Brown6ec402b2010-07-28 15:48:59 -07003674 /** @hide */
3675 public static MotionEvent createFromParcelBody(Parcel in) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08003676 MotionEvent ev = obtain();
3677 ev.mNativePtr = nativeReadFromParcel(ev.mNativePtr, in);
Jeff Brown6ec402b2010-07-28 15:48:59 -07003678 return ev;
3679 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08003680
Wale Ogunwalec3672cd2014-11-05 15:17:35 -08003681 /** @hide */
3682 @Override
3683 public final void cancel() {
3684 setAction(ACTION_CANCEL);
3685 }
3686
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003687 public void writeToParcel(Parcel out, int flags) {
Jeff Brown6ec402b2010-07-28 15:48:59 -07003688 out.writeInt(PARCEL_TOKEN_MOTION_EVENT);
Jeff Brown91c69ab2011-02-14 17:03:18 -08003689 nativeWriteToParcel(mNativePtr, out);
Jeff Brown5c225b12010-06-16 01:53:36 -07003690 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08003691
Jeff Brownc5ed5912010-07-14 18:48:53 -07003692 /**
3693 * Transfer object for pointer coordinates.
Dennis Kempinac1b31d2016-11-02 17:02:25 -07003694 *
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003695 * Objects of this type can be used to specify the pointer coordinates when
3696 * creating new {@link MotionEvent} objects and to query pointer coordinates
3697 * in bulk.
Dennis Kempinac1b31d2016-11-02 17:02:25 -07003698 *
Jeff Brownc5ed5912010-07-14 18:48:53 -07003699 * Refer to {@link InputDevice} for information about how different kinds of
3700 * input devices and sources represent pointer coordinates.
3701 */
3702 public static final class PointerCoords {
Jeff Brown91c69ab2011-02-14 17:03:18 -08003703 private static final int INITIAL_PACKED_AXIS_VALUES = 8;
Mathew Inwooda570dee2018-08-17 14:56:00 +01003704 @UnsupportedAppUsage
Jeff Brown6f2fba42011-02-19 01:08:02 -08003705 private long mPackedAxisBits;
Mathew Inwooda570dee2018-08-17 14:56:00 +01003706 @UnsupportedAppUsage
Jeff Brown91c69ab2011-02-14 17:03:18 -08003707 private float[] mPackedAxisValues;
3708
3709 /**
3710 * Creates a pointer coords object with all axes initialized to zero.
3711 */
3712 public PointerCoords() {
3713 }
3714
3715 /**
3716 * Creates a pointer coords object as a copy of the
3717 * contents of another pointer coords object.
3718 *
3719 * @param other The pointer coords object to copy.
3720 */
3721 public PointerCoords(PointerCoords other) {
3722 copyFrom(other);
3723 }
3724
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003725 /** @hide */
Mathew Inwooda570dee2018-08-17 14:56:00 +01003726 @UnsupportedAppUsage
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003727 public static PointerCoords[] createArray(int size) {
3728 PointerCoords[] array = new PointerCoords[size];
3729 for (int i = 0; i < size; i++) {
3730 array[i] = new PointerCoords();
3731 }
3732 return array;
3733 }
3734
Jeff Brownc5ed5912010-07-14 18:48:53 -07003735 /**
Jeff Brown6f2fba42011-02-19 01:08:02 -08003736 * The X component of the pointer movement.
Jeff Brown91c69ab2011-02-14 17:03:18 -08003737 *
3738 * @see MotionEvent#AXIS_X
Jeff Brownc5ed5912010-07-14 18:48:53 -07003739 */
3740 public float x;
Dennis Kempinac1b31d2016-11-02 17:02:25 -07003741
Jeff Brownc5ed5912010-07-14 18:48:53 -07003742 /**
Jeff Brown6f2fba42011-02-19 01:08:02 -08003743 * The Y component of the pointer movement.
Jeff Brown91c69ab2011-02-14 17:03:18 -08003744 *
3745 * @see MotionEvent#AXIS_Y
Jeff Brownc5ed5912010-07-14 18:48:53 -07003746 */
3747 public float y;
Dennis Kempinac1b31d2016-11-02 17:02:25 -07003748
Jeff Brownc5ed5912010-07-14 18:48:53 -07003749 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08003750 * A normalized value that describes the pressure applied to the device
3751 * by a finger or other tool.
Jeff Brownc5ed5912010-07-14 18:48:53 -07003752 * The pressure generally ranges from 0 (no pressure at all) to 1 (normal pressure),
Jeff Brown91c69ab2011-02-14 17:03:18 -08003753 * although values higher than 1 may be generated depending on the calibration of
Jeff Brownc5ed5912010-07-14 18:48:53 -07003754 * the input device.
Jeff Brown91c69ab2011-02-14 17:03:18 -08003755 *
3756 * @see MotionEvent#AXIS_PRESSURE
Jeff Brownc5ed5912010-07-14 18:48:53 -07003757 */
3758 public float pressure;
Dennis Kempinac1b31d2016-11-02 17:02:25 -07003759
Jeff Brownc5ed5912010-07-14 18:48:53 -07003760 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08003761 * A normalized value that describes the approximate size of the pointer touch area
3762 * in relation to the maximum detectable size of the device.
3763 * It represents some approximation of the area of the screen being
Jeff Brownc5ed5912010-07-14 18:48:53 -07003764 * pressed; the actual value in pixels corresponding to the
3765 * touch is normalized with the device specific range of values
3766 * and scaled to a value between 0 and 1. The value of size can be used to
3767 * determine fat touch events.
Jeff Brown91c69ab2011-02-14 17:03:18 -08003768 *
3769 * @see MotionEvent#AXIS_SIZE
Jeff Brownc5ed5912010-07-14 18:48:53 -07003770 */
3771 public float size;
Dennis Kempinac1b31d2016-11-02 17:02:25 -07003772
Jeff Brownc5ed5912010-07-14 18:48:53 -07003773 /**
3774 * The length of the major axis of an ellipse that describes the touch area at
3775 * the point of contact.
Jeff Brown91c69ab2011-02-14 17:03:18 -08003776 * If the device is a touch screen, the length is reported in pixels, otherwise it is
3777 * reported in device-specific units.
3778 *
3779 * @see MotionEvent#AXIS_TOUCH_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07003780 */
3781 public float touchMajor;
Dennis Kempinac1b31d2016-11-02 17:02:25 -07003782
Jeff Brownc5ed5912010-07-14 18:48:53 -07003783 /**
3784 * The length of the minor axis of an ellipse that describes the touch area at
3785 * the point of contact.
Jeff Brown91c69ab2011-02-14 17:03:18 -08003786 * If the device is a touch screen, the length is reported in pixels, otherwise it is
3787 * reported in device-specific units.
3788 *
3789 * @see MotionEvent#AXIS_TOUCH_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07003790 */
3791 public float touchMinor;
Dennis Kempinac1b31d2016-11-02 17:02:25 -07003792
Jeff Brownc5ed5912010-07-14 18:48:53 -07003793 /**
3794 * The length of the major axis of an ellipse that describes the size of
3795 * the approaching tool.
3796 * The tool area represents the estimated size of the finger or pen that is
3797 * touching the device independent of its actual touch area at the point of contact.
Jeff Brown91c69ab2011-02-14 17:03:18 -08003798 * If the device is a touch screen, the length is reported in pixels, otherwise it is
3799 * reported in device-specific units.
3800 *
3801 * @see MotionEvent#AXIS_TOOL_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07003802 */
3803 public float toolMajor;
Dennis Kempinac1b31d2016-11-02 17:02:25 -07003804
Jeff Brownc5ed5912010-07-14 18:48:53 -07003805 /**
3806 * The length of the minor axis of an ellipse that describes the size of
3807 * the approaching tool.
3808 * The tool area represents the estimated size of the finger or pen that is
3809 * touching the device independent of its actual touch area at the point of contact.
Jeff Brown91c69ab2011-02-14 17:03:18 -08003810 * If the device is a touch screen, the length is reported in pixels, otherwise it is
3811 * reported in device-specific units.
3812 *
3813 * @see MotionEvent#AXIS_TOOL_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07003814 */
3815 public float toolMinor;
Dennis Kempinac1b31d2016-11-02 17:02:25 -07003816
Jeff Brownc5ed5912010-07-14 18:48:53 -07003817 /**
3818 * The orientation of the touch area and tool area in radians clockwise from vertical.
Jeff Brown6f2fba42011-02-19 01:08:02 -08003819 * An angle of 0 radians indicates that the major axis of contact is oriented
Jeff Brownc5ed5912010-07-14 18:48:53 -07003820 * upwards, is perfectly circular or is of unknown orientation. A positive angle
3821 * indicates that the major axis of contact is oriented to the right. A negative angle
3822 * indicates that the major axis of contact is oriented to the left.
Jeff Brown6d0fec22010-07-23 21:28:06 -07003823 * The full range is from -PI/2 radians (finger pointing fully left) to PI/2 radians
Jeff Brownc5ed5912010-07-14 18:48:53 -07003824 * (finger pointing fully right).
Jeff Brown91c69ab2011-02-14 17:03:18 -08003825 *
3826 * @see MotionEvent#AXIS_ORIENTATION
Jeff Brownc5ed5912010-07-14 18:48:53 -07003827 */
3828 public float orientation;
Jeff Brown91c69ab2011-02-14 17:03:18 -08003829
3830 /**
3831 * Clears the contents of this object.
3832 * Resets all axes to zero.
3833 */
3834 public void clear() {
3835 mPackedAxisBits = 0;
3836
3837 x = 0;
3838 y = 0;
3839 pressure = 0;
3840 size = 0;
3841 touchMajor = 0;
3842 touchMinor = 0;
3843 toolMajor = 0;
3844 toolMinor = 0;
3845 orientation = 0;
Jeff Brownc5ed5912010-07-14 18:48:53 -07003846 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08003847
3848 /**
3849 * Copies the contents of another pointer coords object.
3850 *
3851 * @param other The pointer coords object to copy.
3852 */
3853 public void copyFrom(PointerCoords other) {
Jeff Brown6f2fba42011-02-19 01:08:02 -08003854 final long bits = other.mPackedAxisBits;
Jeff Brown91c69ab2011-02-14 17:03:18 -08003855 mPackedAxisBits = bits;
3856 if (bits != 0) {
3857 final float[] otherValues = other.mPackedAxisValues;
Jeff Brown6f2fba42011-02-19 01:08:02 -08003858 final int count = Long.bitCount(bits);
Jeff Brown91c69ab2011-02-14 17:03:18 -08003859 float[] values = mPackedAxisValues;
3860 if (values == null || count > values.length) {
3861 values = new float[otherValues.length];
3862 mPackedAxisValues = values;
3863 }
3864 System.arraycopy(otherValues, 0, values, 0, count);
3865 }
3866
3867 x = other.x;
3868 y = other.y;
3869 pressure = other.pressure;
3870 size = other.size;
3871 touchMajor = other.touchMajor;
3872 touchMinor = other.touchMinor;
3873 toolMajor = other.toolMajor;
3874 toolMinor = other.toolMinor;
3875 orientation = other.orientation;
Jeff Brownc5ed5912010-07-14 18:48:53 -07003876 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08003877
3878 /**
3879 * Gets the value associated with the specified axis.
3880 *
3881 * @param axis The axis identifier for the axis value to retrieve.
3882 * @return The value associated with the axis, or 0 if none.
3883 *
3884 * @see MotionEvent#AXIS_X
3885 * @see MotionEvent#AXIS_Y
3886 */
3887 public float getAxisValue(int axis) {
3888 switch (axis) {
3889 case AXIS_X:
3890 return x;
3891 case AXIS_Y:
3892 return y;
3893 case AXIS_PRESSURE:
3894 return pressure;
3895 case AXIS_SIZE:
3896 return size;
3897 case AXIS_TOUCH_MAJOR:
3898 return touchMajor;
3899 case AXIS_TOUCH_MINOR:
3900 return touchMinor;
3901 case AXIS_TOOL_MAJOR:
3902 return toolMajor;
3903 case AXIS_TOOL_MINOR:
3904 return toolMinor;
3905 case AXIS_ORIENTATION:
3906 return orientation;
3907 default: {
Jeff Brown6f2fba42011-02-19 01:08:02 -08003908 if (axis < 0 || axis > 63) {
3909 throw new IllegalArgumentException("Axis out of range.");
3910 }
3911 final long bits = mPackedAxisBits;
Michael Wright9adca062014-03-19 11:51:26 -07003912 final long axisBit = 0x8000000000000000L >>> axis;
Jeff Brown91c69ab2011-02-14 17:03:18 -08003913 if ((bits & axisBit) == 0) {
3914 return 0;
3915 }
Michael Wright9adca062014-03-19 11:51:26 -07003916 final int index = Long.bitCount(bits & ~(0xFFFFFFFFFFFFFFFFL >>> axis));
Jeff Brown91c69ab2011-02-14 17:03:18 -08003917 return mPackedAxisValues[index];
3918 }
3919 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07003920 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08003921
3922 /**
3923 * Sets the value associated with the specified axis.
3924 *
3925 * @param axis The axis identifier for the axis value to assign.
3926 * @param value The value to set.
3927 *
3928 * @see MotionEvent#AXIS_X
3929 * @see MotionEvent#AXIS_Y
3930 */
3931 public void setAxisValue(int axis, float value) {
3932 switch (axis) {
3933 case AXIS_X:
3934 x = value;
3935 break;
3936 case AXIS_Y:
3937 y = value;
3938 break;
3939 case AXIS_PRESSURE:
3940 pressure = value;
3941 break;
3942 case AXIS_SIZE:
3943 size = value;
3944 break;
3945 case AXIS_TOUCH_MAJOR:
3946 touchMajor = value;
3947 break;
3948 case AXIS_TOUCH_MINOR:
3949 touchMinor = value;
3950 break;
3951 case AXIS_TOOL_MAJOR:
3952 toolMajor = value;
3953 break;
3954 case AXIS_TOOL_MINOR:
3955 toolMinor = value;
3956 break;
3957 case AXIS_ORIENTATION:
3958 orientation = value;
3959 break;
3960 default: {
Jeff Brown6f2fba42011-02-19 01:08:02 -08003961 if (axis < 0 || axis > 63) {
3962 throw new IllegalArgumentException("Axis out of range.");
3963 }
3964 final long bits = mPackedAxisBits;
Michael Wright9adca062014-03-19 11:51:26 -07003965 final long axisBit = 0x8000000000000000L >>> axis;
3966 final int index = Long.bitCount(bits & ~(0xFFFFFFFFFFFFFFFFL >>> axis));
Jeff Brown91c69ab2011-02-14 17:03:18 -08003967 float[] values = mPackedAxisValues;
3968 if ((bits & axisBit) == 0) {
3969 if (values == null) {
3970 values = new float[INITIAL_PACKED_AXIS_VALUES];
3971 mPackedAxisValues = values;
3972 } else {
Jeff Brown6f2fba42011-02-19 01:08:02 -08003973 final int count = Long.bitCount(bits);
Jeff Brown91c69ab2011-02-14 17:03:18 -08003974 if (count < values.length) {
3975 if (index != count) {
3976 System.arraycopy(values, index, values, index + 1,
3977 count - index);
3978 }
3979 } else {
3980 float[] newValues = new float[count * 2];
3981 System.arraycopy(values, 0, newValues, 0, index);
3982 System.arraycopy(values, index, newValues, index + 1,
3983 count - index);
3984 values = newValues;
3985 mPackedAxisValues = values;
3986 }
3987 }
3988 mPackedAxisBits = bits | axisBit;
3989 }
3990 values[index] = value;
3991 }
3992 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07003993 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07003994 }
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003995
3996 /**
3997 * Transfer object for pointer properties.
3998 *
3999 * Objects of this type can be used to specify the pointer id and tool type
4000 * when creating new {@link MotionEvent} objects and to query pointer properties in bulk.
4001 */
4002 public static final class PointerProperties {
4003 /**
4004 * Creates a pointer properties object with an invalid pointer id.
4005 */
4006 public PointerProperties() {
4007 clear();
4008 }
4009
4010 /**
4011 * Creates a pointer properties object as a copy of the contents of
4012 * another pointer properties object.
4013 * @param other
4014 */
4015 public PointerProperties(PointerProperties other) {
4016 copyFrom(other);
4017 }
4018
4019 /** @hide */
Mathew Inwooda570dee2018-08-17 14:56:00 +01004020 @UnsupportedAppUsage
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07004021 public static PointerProperties[] createArray(int size) {
4022 PointerProperties[] array = new PointerProperties[size];
4023 for (int i = 0; i < size; i++) {
4024 array[i] = new PointerProperties();
4025 }
4026 return array;
4027 }
4028
4029 /**
4030 * The pointer id.
4031 * Initially set to {@link #INVALID_POINTER_ID} (-1).
4032 *
4033 * @see MotionEvent#getPointerId(int)
4034 */
4035 public int id;
4036
4037 /**
4038 * The pointer tool type.
4039 * Initially set to 0.
4040 *
4041 * @see MotionEvent#getToolType(int)
4042 */
4043 public int toolType;
4044
4045 /**
4046 * Resets the pointer properties to their initial values.
4047 */
4048 public void clear() {
4049 id = INVALID_POINTER_ID;
4050 toolType = TOOL_TYPE_UNKNOWN;
4051 }
4052
4053 /**
4054 * Copies the contents of another pointer properties object.
4055 *
4056 * @param other The pointer properties object to copy.
4057 */
4058 public void copyFrom(PointerProperties other) {
4059 id = other.id;
4060 toolType = other.toolType;
4061 }
Jeff Brown9d3bdbd2012-03-21 11:50:06 -07004062
4063 @Override
4064 public boolean equals(Object other) {
4065 if (other instanceof PointerProperties) {
4066 return equals((PointerProperties)other);
4067 }
4068 return false;
4069 }
4070
4071 private boolean equals(PointerProperties other) {
4072 return other != null && id == other.id && toolType == other.toolType;
4073 }
4074
4075 @Override
4076 public int hashCode() {
4077 return id | (toolType << 8);
4078 }
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07004079 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08004080}