blob: a0f51425ab1ede9cb8b6b14a891b46961712cd63 [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
Jeff Brown20e987b2010-08-23 12:01:02 -070019import android.graphics.Matrix;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080020import android.os.Parcel;
21import android.os.Parcelable;
22import android.os.SystemClock;
Jeff Brown6f2fba42011-02-19 01:08:02 -080023import android.util.SparseArray;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024
25/**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -070026 * Object used to report movement (mouse, pen, finger, trackball) events.
27 * Motion events may hold either absolute or relative movements and other data,
28 * depending on the type of device.
29 *
30 * <h3>Overview</h3>
Jeff Browndc1ab4b2010-09-14 18:03:38 -070031 * <p>
Jeff Brownfe9f8ab2011-05-06 18:20:01 -070032 * Motion events describe movements in terms of an action code and a set of axis values.
33 * The action code specifies the state change that occurred such as a pointer going
34 * down or up. The axis values describe the position and other movement properties.
35 * </p><p>
36 * For example, when the user first touches the screen, the system delivers a touch
37 * event to the appropriate {@link View} with the action code {@link #ACTION_DOWN}
38 * and a set of axis values that include the X and Y coordinates of the touch and
39 * information about the pressure, size and orientation of the contact area.
40 * </p><p>
41 * Some devices can report multiple movement traces at the same time. Multi-touch
42 * screens emit one movement trace for each finger. The individual fingers or
43 * other objects that generate movement traces are referred to as <em>pointers</em>.
44 * Motion events contain information about all of the pointers that are currently active
45 * even if some of them have not moved since the last event was delivered.
46 * </p><p>
47 * The number of pointers only ever changes by one as individual pointers go up and down,
48 * except when the gesture is canceled.
49 * </p><p>
50 * Each pointer has a unique id that is assigned when it first goes down
51 * (indicated by {@link #ACTION_DOWN} or {@link #ACTION_POINTER_DOWN}). A pointer id
52 * remains valid until the pointer eventually goes up (indicated by {@link #ACTION_UP}
53 * or {@link #ACTION_POINTER_UP}) or when the gesture is canceled (indicated by
54 * {@link #ACTION_CANCEL}).
55 * </p><p>
56 * The MotionEvent class provides many methods to query the position and other properties of
57 * pointers, such as {@link #getX(int)}, {@link #getY(int)}, {@link #getAxisValue},
58 * {@link #getPointerId(int)}, {@link #getToolType(int)}, and many others. Most of these
59 * methods accept the pointer index as a parameter rather than the pointer id.
60 * The pointer index of each pointer in the event ranges from 0 to one less than the value
61 * returned by {@link #getPointerCount()}.
62 * </p><p>
63 * The order in which individual pointers appear within a motion event is undefined.
64 * Thus the pointer index of a pointer can change from one event to the next but
65 * the pointer id of a pointer is guaranteed to remain constant as long as the pointer
66 * remains active. Use the {@link #getPointerId(int)} method to obtain the
67 * pointer id of a pointer to track it across all subsequent motion events in a gesture.
68 * Then for successive motion events, use the {@link #findPointerIndex(int)} method
69 * to obtain the pointer index for a given pointer id in that motion event.
70 * </p><p>
71 * Mouse and stylus buttons can be retrieved using {@link #getButtonState()}. It is a
72 * good idea to check the button state while handling {@link #ACTION_DOWN} as part
73 * of a touch event. The application may choose to perform some different action
74 * if the touch event starts due to a secondary button click, such as presenting a
75 * context menu.
76 * </p>
77 *
78 * <h3>Batching</h3>
79 * <p>
80 * For efficiency, motion events with {@link #ACTION_MOVE} may batch together
81 * multiple movement samples within a single object. The most current
82 * pointer coordinates are available using {@link #getX(int)} and {@link #getY(int)}.
83 * Earlier coordinates within the batch are accessed using {@link #getHistoricalX(int, int)}
84 * and {@link #getHistoricalY(int, int)}. The coordinates are "historical" only
85 * insofar as they are older than the current coordinates in the batch; however,
86 * they are still distinct from any other coordinates reported in prior motion events.
87 * To process all coordinates in the batch in time order, first consume the historical
88 * coordinates then consume the current coordinates.
89 * </p><p>
90 * Example: Consuming all samples for all pointers in a motion event in time order.
91 * </p><p><pre><code>
92 * void printSamples(MotionEvent ev) {
93 * final int historySize = ev.getHistorySize();
94 * final int pointerCount = ev.getPointerCount();
95 * for (int h = 0; h &lt; historySize; h++) {
96 * System.out.printf("At time %d:", ev.getHistoricalEventTime(h));
97 * for (int p = 0; p &lt; pointerCount; p++) {
98 * System.out.printf(" pointer %d: (%f,%f)",
99 * ev.getPointerId(p), ev.getHistoricalX(p, h), ev.getHistoricalY(p, h));
100 * }
101 * }
102 * System.out.printf("At time %d:", ev.getEventTime());
103 * for (int p = 0; p &lt; pointerCount; p++) {
104 * System.out.printf(" pointer %d: (%f,%f)",
105 * ev.getPointerId(p), ev.getX(p), ev.getY(p));
106 * }
107 * }
108 * </code></pre></p>
109 *
110 * <h3>Device Types</h3>
111 * <p>
112 * The interpretation of the contents of a MotionEvent varies significantly depending
113 * on the source class of the device.
114 * </p><p>
Jeff Browncb1404e2011-01-15 18:14:15 -0800115 * On pointing devices with source class {@link InputDevice#SOURCE_CLASS_POINTER}
116 * such as touch screens, the pointer coordinates specify absolute
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700117 * positions such as view X/Y coordinates. Each complete gesture is represented
118 * by a sequence of motion events with actions that describe pointer state transitions
119 * and movements. A gesture starts with a motion event with {@link #ACTION_DOWN}
120 * that provides the location of the first pointer down. As each additional
121 * pointer that goes down or up, the framework will generate a motion event with
122 * {@link #ACTION_POINTER_DOWN} or {@link #ACTION_POINTER_UP} accordingly.
123 * Pointer movements are described by motion events with {@link #ACTION_MOVE}.
124 * Finally, a gesture end either when the final pointer goes up as represented
125 * by a motion event with {@link #ACTION_UP} or when gesture is canceled
126 * with {@link #ACTION_CANCEL}.
127 * </p><p>
Jeff Brown33bbfd22011-02-24 20:55:35 -0800128 * Some pointing devices such as mice may support vertical and/or horizontal scrolling.
129 * A scroll event is reported as a generic motion event with {@link #ACTION_SCROLL} that
130 * includes the relative scroll offset in the {@link #AXIS_VSCROLL} and
131 * {@link #AXIS_HSCROLL} axes. See {@link #getAxisValue(int)} for information
132 * about retrieving these additional axes.
133 * </p><p>
Jeff Browncb1404e2011-01-15 18:14:15 -0800134 * On trackball devices with source class {@link InputDevice#SOURCE_CLASS_TRACKBALL},
135 * the pointer coordinates specify relative movements as X/Y deltas.
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700136 * A trackball gesture consists of a sequence of movements described by motion
137 * events with {@link #ACTION_MOVE} interspersed with occasional {@link #ACTION_DOWN}
138 * or {@link #ACTION_UP} motion events when the trackball button is pressed or released.
139 * </p><p>
Jeff Browncb1404e2011-01-15 18:14:15 -0800140 * On joystick devices with source class {@link InputDevice#SOURCE_CLASS_JOYSTICK},
141 * the pointer coordinates specify the absolute position of the joystick axes.
142 * The joystick axis values are normalized to a range of -1.0 to 1.0 where 0.0 corresponds
143 * to the center position. More information about the set of available axes and the
144 * range of motion can be obtained using {@link InputDevice#getMotionRange}.
Jeff Brown33bbfd22011-02-24 20:55:35 -0800145 * Some common joystick axes are {@link #AXIS_X}, {@link #AXIS_Y},
146 * {@link #AXIS_HAT_X}, {@link #AXIS_HAT_Y}, {@link #AXIS_Z} and {@link #AXIS_RZ}.
Jeff Browncb1404e2011-01-15 18:14:15 -0800147 * </p><p>
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700148 * Refer to {@link InputDevice} for more information about how different kinds of
Jeff Brownc5ed5912010-07-14 18:48:53 -0700149 * input devices and sources represent pointer coordinates.
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700150 * </p>
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700151 *
152 * <h3>Consistency Guarantees</h3>
153 * <p>
154 * Motion events are always delivered to views as a consistent stream of events.
155 * What constitutes a consistent stream varies depending on the type of device.
156 * For touch events, consistency implies that pointers go down one at a time,
157 * move around as a group and then go up one at a time or are canceled.
158 * </p><p>
159 * While the framework tries to deliver consistent streams of motion events to
160 * views, it cannot guarantee it. Some events may be dropped or modified by
161 * containing views in the application before they are delivered thereby making
162 * the stream of events inconsistent. Views should always be prepared to
163 * handle {@link #ACTION_CANCEL} and should tolerate anomalous
164 * situations such as receiving a new {@link #ACTION_DOWN} without first having
165 * received an {@link #ACTION_UP} for the prior gesture.
166 * </p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800167 */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700168public final class MotionEvent extends InputEvent implements Parcelable {
Jeff Brown91c69ab2011-02-14 17:03:18 -0800169 private static final long NS_PER_MS = 1000000;
Michael Wright337d9d22014-04-22 15:03:48 -0700170 private static final String LABEL_PREFIX = "AXIS_";
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700171
172 /**
173 * An invalid pointer id.
174 *
175 * This value (-1) can be used as a placeholder to indicate that a pointer id
176 * has not been assigned or is not available. It cannot appear as
177 * a pointer id inside a {@link MotionEvent}.
178 */
179 public static final int INVALID_POINTER_ID = -1;
180
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800181 /**
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700182 * Bit mask of the parts of the action code that are the action itself.
183 */
184 public static final int ACTION_MASK = 0xff;
185
186 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700187 * Constant for {@link #getActionMasked}: A pressed gesture has started, the
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800188 * motion contains the initial starting location.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700189 * <p>
190 * This is also a good time to check the button state to distinguish
191 * secondary and tertiary button clicks and handle them appropriately.
192 * Use {@link #getButtonState} to retrieve the button state.
193 * </p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800194 */
195 public static final int ACTION_DOWN = 0;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700196
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800197 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700198 * Constant for {@link #getActionMasked}: A pressed gesture has finished, the
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800199 * motion contains the final release location as well as any intermediate
200 * points since the last down or move event.
201 */
202 public static final int ACTION_UP = 1;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700203
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800204 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700205 * Constant for {@link #getActionMasked}: A change has happened during a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800206 * press gesture (between {@link #ACTION_DOWN} and {@link #ACTION_UP}).
207 * The motion contains the most recent point, as well as any intermediate
208 * points since the last down or move event.
209 */
210 public static final int ACTION_MOVE = 2;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700211
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800212 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700213 * Constant for {@link #getActionMasked}: The current gesture has been aborted.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800214 * You will not receive any more points in it. You should treat this as
215 * an up event, but not perform any action that you normally would.
216 */
217 public static final int ACTION_CANCEL = 3;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700218
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800219 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700220 * Constant for {@link #getActionMasked}: A movement has happened outside of the
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800221 * normal bounds of the UI element. This does not provide a full gesture,
222 * but only the initial location of the movement/touch.
223 */
224 public static final int ACTION_OUTSIDE = 4;
225
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700226 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700227 * Constant for {@link #getActionMasked}: A non-primary pointer has gone down.
228 * <p>
229 * Use {@link #getActionIndex} to retrieve the index of the pointer that changed.
230 * </p><p>
231 * The index is encoded in the {@link #ACTION_POINTER_INDEX_MASK} bits of the
232 * unmasked action returned by {@link #getAction}.
233 * </p>
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700234 */
235 public static final int ACTION_POINTER_DOWN = 5;
236
237 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700238 * Constant for {@link #getActionMasked}: A non-primary pointer has gone up.
239 * <p>
240 * Use {@link #getActionIndex} to retrieve the index of the pointer that changed.
241 * </p><p>
242 * The index is encoded in the {@link #ACTION_POINTER_INDEX_MASK} bits of the
243 * unmasked action returned by {@link #getAction}.
244 * </p>
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700245 */
246 public static final int ACTION_POINTER_UP = 6;
Jeff Browncc0c1592011-02-19 05:07:28 -0800247
248 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700249 * Constant for {@link #getActionMasked}: A change happened but the pointer
Jeff Browncc0c1592011-02-19 05:07:28 -0800250 * is not down (unlike {@link #ACTION_MOVE}). The motion contains the most
251 * recent point, as well as any intermediate points since the last
252 * hover move event.
Jeff Brown33bbfd22011-02-24 20:55:35 -0800253 * <p>
Jeff Browna032cc02011-03-07 16:56:21 -0800254 * This action is always delivered to the window or view under the pointer.
255 * </p><p>
Jeff Brown33bbfd22011-02-24 20:55:35 -0800256 * This action is not a touch event so it is delivered to
257 * {@link View#onGenericMotionEvent(MotionEvent)} rather than
258 * {@link View#onTouchEvent(MotionEvent)}.
259 * </p>
Jeff Browncc0c1592011-02-19 05:07:28 -0800260 */
261 public static final int ACTION_HOVER_MOVE = 7;
262
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700263 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700264 * Constant for {@link #getActionMasked}: The motion event contains relative
Jeff Brown33bbfd22011-02-24 20:55:35 -0800265 * vertical and/or horizontal scroll offsets. Use {@link #getAxisValue(int)}
266 * to retrieve the information from {@link #AXIS_VSCROLL} and {@link #AXIS_HSCROLL}.
267 * The pointer may or may not be down when this event is dispatched.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700268 * <p>
Jeff Browna032cc02011-03-07 16:56:21 -0800269 * This action is always delivered to the window or view under the pointer, which
270 * may not be the window or view currently touched.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700271 * </p><p>
Jeff Brown33bbfd22011-02-24 20:55:35 -0800272 * This action is not a touch event so it is delivered to
273 * {@link View#onGenericMotionEvent(MotionEvent)} rather than
274 * {@link View#onTouchEvent(MotionEvent)}.
275 * </p>
276 */
277 public static final int ACTION_SCROLL = 8;
278
279 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700280 * Constant for {@link #getActionMasked}: The pointer is not down but has entered the
Jeff Browna032cc02011-03-07 16:56:21 -0800281 * boundaries of a window or view.
282 * <p>
283 * This action is always delivered to the window or view under the pointer.
284 * </p><p>
285 * This action is not a touch event so it is delivered to
286 * {@link View#onGenericMotionEvent(MotionEvent)} rather than
287 * {@link View#onTouchEvent(MotionEvent)}.
288 * </p>
289 */
290 public static final int ACTION_HOVER_ENTER = 9;
291
292 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700293 * Constant for {@link #getActionMasked}: The pointer is not down but has exited the
Jeff Browna032cc02011-03-07 16:56:21 -0800294 * boundaries of a window or view.
295 * <p>
296 * This action is always delivered to the window or view that was previously under the pointer.
297 * </p><p>
298 * This action is not a touch event so it is delivered to
299 * {@link View#onGenericMotionEvent(MotionEvent)} rather than
300 * {@link View#onTouchEvent(MotionEvent)}.
301 * </p>
302 */
303 public static final int ACTION_HOVER_EXIT = 10;
304
305 /**
Michael Wright5bd69e62015-05-14 14:48:08 +0100306 * Constant for {@link #getActionMasked}: A button has been pressed.
307 *
308 * <p>
309 * Use {@link #getActionButton()} to get which button was pressed.
310 * </p><p>
311 * This action is not a touch event so it is delivered to
312 * {@link View#onGenericMotionEvent(MotionEvent)} rather than
313 * {@link View#onTouchEvent(MotionEvent)}.
314 * </p>
315 */
316 public static final int ACTION_BUTTON_PRESS = 11;
317
318 /**
319 * Constant for {@link #getActionMasked}: A button has been released.
320 *
321 * <p>
322 * Use {@link #getActionButton()} to get which button was released.
323 * </p><p>
324 * This action is not a touch event so it is delivered to
325 * {@link View#onGenericMotionEvent(MotionEvent)} rather than
326 * {@link View#onTouchEvent(MotionEvent)}.
327 * </p>
328 */
329 public static final int ACTION_BUTTON_RELEASE = 12;
330
331 /**
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800332 * Bits in the action code that represent a pointer index, used with
333 * {@link #ACTION_POINTER_DOWN} and {@link #ACTION_POINTER_UP}. Shifting
334 * down by {@link #ACTION_POINTER_INDEX_SHIFT} provides the actual pointer
335 * index where the data for the pointer going up or down can be found; you can
336 * get its identifier with {@link #getPointerId(int)} and the actual
337 * data with {@link #getX(int)} etc.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700338 *
339 * @see #getActionIndex
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700340 */
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800341 public static final int ACTION_POINTER_INDEX_MASK = 0xff00;
342
343 /**
344 * Bit shift for the action bits holding the pointer index as
345 * defined by {@link #ACTION_POINTER_INDEX_MASK}.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700346 *
347 * @see #getActionIndex
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800348 */
349 public static final int ACTION_POINTER_INDEX_SHIFT = 8;
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700350
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800351 /**
352 * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the
353 * data index associated with {@link #ACTION_POINTER_DOWN}.
354 */
355 @Deprecated
356 public static final int ACTION_POINTER_1_DOWN = ACTION_POINTER_DOWN | 0x0000;
357
358 /**
359 * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the
360 * data index associated with {@link #ACTION_POINTER_DOWN}.
361 */
362 @Deprecated
363 public static final int ACTION_POINTER_2_DOWN = ACTION_POINTER_DOWN | 0x0100;
364
365 /**
366 * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the
367 * data index associated with {@link #ACTION_POINTER_DOWN}.
368 */
369 @Deprecated
370 public static final int ACTION_POINTER_3_DOWN = ACTION_POINTER_DOWN | 0x0200;
371
372 /**
373 * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the
374 * data index associated with {@link #ACTION_POINTER_UP}.
375 */
376 @Deprecated
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700377 public static final int ACTION_POINTER_1_UP = ACTION_POINTER_UP | 0x0000;
378
379 /**
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800380 * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the
381 * data index associated with {@link #ACTION_POINTER_UP}.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700382 */
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800383 @Deprecated
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700384 public static final int ACTION_POINTER_2_UP = ACTION_POINTER_UP | 0x0100;
385
386 /**
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800387 * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the
388 * data index associated with {@link #ACTION_POINTER_UP}.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700389 */
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800390 @Deprecated
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700391 public static final int ACTION_POINTER_3_UP = ACTION_POINTER_UP | 0x0200;
392
393 /**
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800394 * @deprecated Renamed to {@link #ACTION_POINTER_INDEX_MASK} to match
395 * the actual data contained in these bits.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700396 */
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800397 @Deprecated
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700398 public static final int ACTION_POINTER_ID_MASK = 0xff00;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700399
400 /**
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800401 * @deprecated Renamed to {@link #ACTION_POINTER_INDEX_SHIFT} to match
402 * the actual data contained in these bits.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700403 */
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800404 @Deprecated
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700405 public static final int ACTION_POINTER_ID_SHIFT = 8;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700406
Jeff Brown85a31762010-09-01 17:01:00 -0700407 /**
408 * This flag indicates that the window that received this motion event is partly
409 * or wholly obscured by another visible window above it. This flag is set to true
410 * even if the event did not directly pass through the obscured area.
411 * A security sensitive application can check this flag to identify situations in which
412 * a malicious application may have covered up part of its content for the purpose
413 * of misleading the user or hijacking touches. An appropriate response might be
414 * to drop the suspect touches or to take additional precautions to confirm the user's
415 * actual intent.
416 */
417 public static final int FLAG_WINDOW_IS_OBSCURED = 0x1;
Romain Guycafdea62009-06-12 10:51:36 -0700418
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800419 /**
Jeff Brown21bc5c92011-02-28 18:27:14 -0800420 * Private flag that indicates when the system has detected that this motion event
421 * may be inconsistent with respect to the sequence of previously delivered motion events,
422 * such as when a pointer move event is sent but the pointer is not down.
423 *
424 * @hide
425 * @see #isTainted
426 * @see #setTainted
427 */
428 public static final int FLAG_TAINTED = 0x80000000;
429
430 /**
Svetoslavded133c2015-01-30 20:28:41 -0800431 * Private flag indicating that this event was synthesized by the system and
432 * should be delivered to the accessibility focused view first. When being
433 * dispatched such an event is not handled by predecessors of the accessibility
434 * focused view and after the event reaches that view the flag is cleared and
435 * normal event dispatch is performed. This ensures that the platform can click
436 * on any view that has accessibility focus which is semantically equivalent to
437 * asking the view to perform a click accessibility action but more generic as
438 * views not implementing click action correctly can still be activated.
439 *
440 * @hide
441 * @see #isTargetAccessibilityFocus()
442 * @see #setTargetAccessibilityFocus(boolean)
443 */
444 public static final int FLAG_TARGET_ACCESSIBILITY_FOCUS = 0x40000000;
445
446
447 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800448 * Flag indicating the motion event intersected the top edge of the screen.
449 */
450 public static final int EDGE_TOP = 0x00000001;
Romain Guycafdea62009-06-12 10:51:36 -0700451
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800452 /**
453 * Flag indicating the motion event intersected the bottom edge of the screen.
454 */
455 public static final int EDGE_BOTTOM = 0x00000002;
Romain Guycafdea62009-06-12 10:51:36 -0700456
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800457 /**
458 * Flag indicating the motion event intersected the left edge of the screen.
459 */
460 public static final int EDGE_LEFT = 0x00000004;
Romain Guycafdea62009-06-12 10:51:36 -0700461
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800462 /**
463 * Flag indicating the motion event intersected the right edge of the screen.
464 */
465 public static final int EDGE_RIGHT = 0x00000008;
Romain Guycafdea62009-06-12 10:51:36 -0700466
Jeff Brown91c69ab2011-02-14 17:03:18 -0800467 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700468 * Axis constant: X axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800469 * <p>
470 * <ul>
471 * <li>For a touch screen, reports the absolute X screen position of the center of
472 * the touch contact area. The units are display pixels.
473 * <li>For a touch pad, reports the absolute X surface position of the center of the touch
Jeff Browncc0c1592011-02-19 05:07:28 -0800474 * contact area. The units are device-dependent; use {@link InputDevice#getMotionRange(int)}
475 * to query the effective range of values.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800476 * <li>For a mouse, reports the absolute X screen position of the mouse pointer.
477 * The units are display pixels.
478 * <li>For a trackball, reports the relative horizontal displacement of the trackball.
479 * The value is normalized to a range from -1.0 (left) to 1.0 (right).
480 * <li>For a joystick, reports the absolute X position of the joystick.
481 * The value is normalized to a range from -1.0 (left) to 1.0 (right).
482 * </ul>
483 * </p>
Jeff Brown91c69ab2011-02-14 17:03:18 -0800484 *
485 * @see #getX(int)
486 * @see #getHistoricalX(int, int)
487 * @see MotionEvent.PointerCoords#x
488 * @see InputDevice#getMotionRange
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700489 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800490 public static final int AXIS_X = 0;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700491
Jeff Brown91c69ab2011-02-14 17:03:18 -0800492 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700493 * Axis constant: Y axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800494 * <p>
495 * <ul>
496 * <li>For a touch screen, reports the absolute Y screen position of the center of
497 * the touch contact area. The units are display pixels.
498 * <li>For a touch pad, reports the absolute Y surface position of the center of the touch
499 * contact area. The units are device-dependent; use {@link InputDevice#getMotionRange(int)}
500 * to query the effective range of values.
501 * <li>For a mouse, reports the absolute Y screen position of the mouse pointer.
502 * The units are display pixels.
503 * <li>For a trackball, reports the relative vertical displacement of the trackball.
504 * The value is normalized to a range from -1.0 (up) to 1.0 (down).
505 * <li>For a joystick, reports the absolute Y position of the joystick.
506 * The value is normalized to a range from -1.0 (up or far) to 1.0 (down or near).
507 * </ul>
508 * </p>
Jeff Brown91c69ab2011-02-14 17:03:18 -0800509 *
510 * @see #getY(int)
511 * @see #getHistoricalY(int, int)
512 * @see MotionEvent.PointerCoords#y
513 * @see InputDevice#getMotionRange
Jeff Brownc5ed5912010-07-14 18:48:53 -0700514 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800515 public static final int AXIS_Y = 1;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700516
Jeff Brown91c69ab2011-02-14 17:03:18 -0800517 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700518 * Axis constant: Pressure axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800519 * <p>
520 * <ul>
Jeff Browncc0c1592011-02-19 05:07:28 -0800521 * <li>For a touch screen or touch pad, reports the approximate pressure applied to the surface
Jeff Brown6f2fba42011-02-19 01:08:02 -0800522 * by a finger or other tool. The value is normalized to a range from
523 * 0 (no pressure at all) to 1 (normal pressure), although values higher than 1
524 * may be generated depending on the calibration of the input device.
525 * <li>For a trackball, the value is set to 1 if the trackball button is pressed
526 * or 0 otherwise.
527 * <li>For a mouse, the value is set to 1 if the primary mouse button is pressed
528 * or 0 otherwise.
529 * </ul>
530 * </p>
Jeff Brown91c69ab2011-02-14 17:03:18 -0800531 *
532 * @see #getPressure(int)
533 * @see #getHistoricalPressure(int, int)
534 * @see MotionEvent.PointerCoords#pressure
535 * @see InputDevice#getMotionRange
Jeff Brownc5ed5912010-07-14 18:48:53 -0700536 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800537 public static final int AXIS_PRESSURE = 2;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700538
Jeff Brown91c69ab2011-02-14 17:03:18 -0800539 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700540 * Axis constant: Size axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800541 * <p>
542 * <ul>
543 * <li>For a touch screen or touch pad, reports the approximate size of the contact area in
544 * relation to the maximum detectable size for the device. The value is normalized
545 * to a range from 0 (smallest detectable size) to 1 (largest detectable size),
Jeff Browncc0c1592011-02-19 05:07:28 -0800546 * although it is not a linear scale. This value is of limited use.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800547 * To obtain calibrated size information, use
548 * {@link #AXIS_TOUCH_MAJOR} or {@link #AXIS_TOOL_MAJOR}.
549 * </ul>
550 * </p>
Jeff Brown91c69ab2011-02-14 17:03:18 -0800551 *
552 * @see #getSize(int)
553 * @see #getHistoricalSize(int, int)
554 * @see MotionEvent.PointerCoords#size
555 * @see InputDevice#getMotionRange
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700556 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800557 public static final int AXIS_SIZE = 3;
558
559 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700560 * Axis constant: TouchMajor axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800561 * <p>
562 * <ul>
563 * <li>For a touch screen, reports the length of the major axis of an ellipse that
564 * represents the touch area at the point of contact.
565 * The units are display pixels.
566 * <li>For a touch pad, reports the length of the major axis of an ellipse that
567 * represents the touch area at the point of contact.
568 * The units are device-dependent; use {@link InputDevice#getMotionRange(int)}
569 * to query the effective range of values.
570 * </ul>
571 * </p>
Jeff Brown91c69ab2011-02-14 17:03:18 -0800572 *
573 * @see #getTouchMajor(int)
574 * @see #getHistoricalTouchMajor(int, int)
575 * @see MotionEvent.PointerCoords#touchMajor
576 * @see InputDevice#getMotionRange
Dianne Hackborn1e8dfc72009-08-06 12:43:01 -0700577 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800578 public static final int AXIS_TOUCH_MAJOR = 4;
579
580 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700581 * Axis constant: TouchMinor axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800582 * <p>
583 * <ul>
584 * <li>For a touch screen, reports the length of the minor axis of an ellipse that
585 * represents the touch area at the point of contact.
586 * The units are display pixels.
587 * <li>For a touch pad, reports the length of the minor axis of an ellipse that
588 * represents the touch area at the point of contact.
589 * The units are device-dependent; use {@link InputDevice#getMotionRange(int)}
590 * to query the effective range of values.
591 * </ul>
592 * </p><p>
593 * When the touch is circular, the major and minor axis lengths will be equal to one another.
594 * </p>
Jeff Brown91c69ab2011-02-14 17:03:18 -0800595 *
596 * @see #getTouchMinor(int)
597 * @see #getHistoricalTouchMinor(int, int)
598 * @see MotionEvent.PointerCoords#touchMinor
599 * @see InputDevice#getMotionRange
Jeff Brown9e2ad362010-07-30 19:20:11 -0700600 */
Jeff Brown91c69ab2011-02-14 17:03:18 -0800601 public static final int AXIS_TOUCH_MINOR = 5;
602
603 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700604 * Axis constant: ToolMajor axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800605 * <p>
606 * <ul>
607 * <li>For a touch screen, reports the length of the major axis of an ellipse that
608 * represents the size of the approaching finger or tool used to make contact.
609 * <li>For a touch pad, reports the length of the major axis of an ellipse that
610 * represents the size of the approaching finger or tool used to make contact.
611 * The units are device-dependent; use {@link InputDevice#getMotionRange(int)}
612 * to query the effective range of values.
613 * </ul>
614 * </p><p>
615 * When the touch is circular, the major and minor axis lengths will be equal to one another.
616 * </p><p>
617 * The tool size may be larger than the touch size since the tool may not be fully
618 * in contact with the touch sensor.
619 * </p>
Jeff Brown91c69ab2011-02-14 17:03:18 -0800620 *
621 * @see #getToolMajor(int)
622 * @see #getHistoricalToolMajor(int, int)
623 * @see MotionEvent.PointerCoords#toolMajor
624 * @see InputDevice#getMotionRange
625 */
626 public static final int AXIS_TOOL_MAJOR = 6;
627
628 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700629 * Axis constant: ToolMinor axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800630 * <p>
631 * <ul>
632 * <li>For a touch screen, reports the length of the minor axis of an ellipse that
633 * represents the size of the approaching finger or tool used to make contact.
634 * <li>For a touch pad, reports the length of the minor axis of an ellipse that
635 * represents the size of the approaching finger or tool used to make contact.
636 * The units are device-dependent; use {@link InputDevice#getMotionRange(int)}
637 * to query the effective range of values.
638 * </ul>
639 * </p><p>
640 * When the touch is circular, the major and minor axis lengths will be equal to one another.
641 * </p><p>
642 * The tool size may be larger than the touch size since the tool may not be fully
643 * in contact with the touch sensor.
644 * </p>
Jeff Brown91c69ab2011-02-14 17:03:18 -0800645 *
646 * @see #getToolMinor(int)
647 * @see #getHistoricalToolMinor(int, int)
648 * @see MotionEvent.PointerCoords#toolMinor
649 * @see InputDevice#getMotionRange
650 */
651 public static final int AXIS_TOOL_MINOR = 7;
652
653 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700654 * Axis constant: Orientation axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800655 * <p>
656 * <ul>
657 * <li>For a touch screen or touch pad, reports the orientation of the finger
658 * or tool in radians relative to the vertical plane of the device.
659 * An angle of 0 radians indicates that the major axis of contact is oriented
Jeff Brown91c69ab2011-02-14 17:03:18 -0800660 * upwards, is perfectly circular or is of unknown orientation. A positive angle
661 * indicates that the major axis of contact is oriented to the right. A negative angle
662 * indicates that the major axis of contact is oriented to the left.
663 * The full range is from -PI/2 radians (finger pointing fully left) to PI/2 radians
664 * (finger pointing fully right).
Jeff Brown65fd2512011-08-18 11:20:58 -0700665 * <li>For a stylus, the orientation indicates the direction in which the stylus
666 * is pointing in relation to the vertical axis of the current orientation of the screen.
667 * The range is from -PI radians to PI radians, where 0 is pointing up,
668 * -PI/2 radians is pointing left, -PI or PI radians is pointing down, and PI/2 radians
669 * is pointing right. See also {@link #AXIS_TILT}.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800670 * </ul>
671 * </p>
Jeff Brown91c69ab2011-02-14 17:03:18 -0800672 *
673 * @see #getOrientation(int)
674 * @see #getHistoricalOrientation(int, int)
675 * @see MotionEvent.PointerCoords#orientation
676 * @see InputDevice#getMotionRange
677 */
678 public static final int AXIS_ORIENTATION = 8;
679
Jeff Brown6f2fba42011-02-19 01:08:02 -0800680 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700681 * Axis constant: Vertical Scroll axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800682 * <p>
683 * <ul>
Jeff Browncc0c1592011-02-19 05:07:28 -0800684 * <li>For a mouse, reports the relative movement of the vertical scroll wheel.
Jeff Brown33bbfd22011-02-24 20:55:35 -0800685 * The value is normalized to a range from -1.0 (down) to 1.0 (up).
Jeff Brown6f2fba42011-02-19 01:08:02 -0800686 * </ul>
687 * </p><p>
688 * This axis should be used to scroll views vertically.
689 * </p>
690 *
691 * @see #getAxisValue(int, int)
692 * @see #getHistoricalAxisValue(int, int, int)
693 * @see MotionEvent.PointerCoords#getAxisValue(int)
694 * @see InputDevice#getMotionRange
695 */
696 public static final int AXIS_VSCROLL = 9;
697
698 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700699 * Axis constant: Horizontal Scroll axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800700 * <p>
701 * <ul>
Jeff Browncc0c1592011-02-19 05:07:28 -0800702 * <li>For a mouse, reports the relative movement of the horizontal scroll wheel.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800703 * The value is normalized to a range from -1.0 (left) to 1.0 (right).
704 * </ul>
705 * </p><p>
706 * This axis should be used to scroll views horizontally.
707 * </p>
708 *
709 * @see #getAxisValue(int, int)
710 * @see #getHistoricalAxisValue(int, int, int)
711 * @see MotionEvent.PointerCoords#getAxisValue(int)
712 * @see InputDevice#getMotionRange
713 */
714 public static final int AXIS_HSCROLL = 10;
715
716 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700717 * Axis constant: Z axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800718 * <p>
719 * <ul>
720 * <li>For a joystick, reports the absolute Z position of the joystick.
721 * The value is normalized to a range from -1.0 (high) to 1.0 (low).
722 * <em>On game pads with two analog joysticks, this axis is often reinterpreted
723 * to report the absolute X position of the second joystick instead.</em>
724 * </ul>
725 * </p>
726 *
727 * @see #getAxisValue(int, int)
728 * @see #getHistoricalAxisValue(int, int, int)
729 * @see MotionEvent.PointerCoords#getAxisValue(int)
730 * @see InputDevice#getMotionRange
731 */
732 public static final int AXIS_Z = 11;
733
734 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700735 * Axis constant: X Rotation axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800736 * <p>
737 * <ul>
738 * <li>For a joystick, reports the absolute rotation angle about the X axis.
739 * The value is normalized to a range from -1.0 (counter-clockwise) to 1.0 (clockwise).
740 * </ul>
741 * </p>
742 *
743 * @see #getAxisValue(int, int)
744 * @see #getHistoricalAxisValue(int, int, int)
745 * @see MotionEvent.PointerCoords#getAxisValue(int)
746 * @see InputDevice#getMotionRange
747 */
748 public static final int AXIS_RX = 12;
749
750 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700751 * Axis constant: Y Rotation axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800752 * <p>
753 * <ul>
754 * <li>For a joystick, reports the absolute rotation angle about the Y axis.
755 * The value is normalized to a range from -1.0 (counter-clockwise) to 1.0 (clockwise).
756 * </ul>
757 * </p>
758 *
759 * @see #getAxisValue(int, int)
760 * @see #getHistoricalAxisValue(int, int, int)
761 * @see MotionEvent.PointerCoords#getAxisValue(int)
762 * @see InputDevice#getMotionRange
763 */
764 public static final int AXIS_RY = 13;
765
766 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700767 * Axis constant: Z Rotation axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800768 * <p>
769 * <ul>
770 * <li>For a joystick, reports the absolute rotation angle about the Z axis.
771 * The value is normalized to a range from -1.0 (counter-clockwise) to 1.0 (clockwise).
772 * <em>On game pads with two analog joysticks, this axis is often reinterpreted
773 * to report the absolute Y position of the second joystick instead.</em>
774 * </ul>
775 * </p>
776 *
777 * @see #getAxisValue(int, int)
778 * @see #getHistoricalAxisValue(int, int, int)
779 * @see MotionEvent.PointerCoords#getAxisValue(int)
780 * @see InputDevice#getMotionRange
781 */
782 public static final int AXIS_RZ = 14;
783
784 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700785 * Axis constant: Hat X axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800786 * <p>
787 * <ul>
788 * <li>For a joystick, reports the absolute X position of the directional hat control.
789 * The value is normalized to a range from -1.0 (left) to 1.0 (right).
790 * </ul>
791 * </p>
792 *
793 * @see #getAxisValue(int, int)
794 * @see #getHistoricalAxisValue(int, int, int)
795 * @see MotionEvent.PointerCoords#getAxisValue(int)
796 * @see InputDevice#getMotionRange
797 */
798 public static final int AXIS_HAT_X = 15;
799
800 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700801 * Axis constant: Hat Y axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800802 * <p>
803 * <ul>
804 * <li>For a joystick, reports the absolute Y position of the directional hat control.
805 * The value is normalized to a range from -1.0 (up) to 1.0 (down).
806 * </ul>
807 * </p>
808 *
809 * @see #getAxisValue(int, int)
810 * @see #getHistoricalAxisValue(int, int, int)
811 * @see MotionEvent.PointerCoords#getAxisValue(int)
812 * @see InputDevice#getMotionRange
813 */
814 public static final int AXIS_HAT_Y = 16;
815
816 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700817 * Axis constant: Left Trigger axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800818 * <p>
819 * <ul>
820 * <li>For a joystick, reports the absolute position of the left trigger control.
821 * The value is normalized to a range from 0.0 (released) to 1.0 (fully pressed).
822 * </ul>
823 * </p>
824 *
825 * @see #getAxisValue(int, int)
826 * @see #getHistoricalAxisValue(int, int, int)
827 * @see MotionEvent.PointerCoords#getAxisValue(int)
828 * @see InputDevice#getMotionRange
829 */
830 public static final int AXIS_LTRIGGER = 17;
831
832 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700833 * Axis constant: Right Trigger axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -0800834 * <p>
835 * <ul>
836 * <li>For a joystick, reports the absolute position of the right trigger control.
837 * The value is normalized to a range from 0.0 (released) to 1.0 (fully pressed).
838 * </ul>
839 * </p>
840 *
841 * @see #getAxisValue(int, int)
842 * @see #getHistoricalAxisValue(int, int, int)
843 * @see MotionEvent.PointerCoords#getAxisValue(int)
844 * @see InputDevice#getMotionRange
845 */
846 public static final int AXIS_RTRIGGER = 18;
847
848 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700849 * Axis constant: Throttle axis of a motion event.
Jeff Brown3a22fa02011-03-04 13:07:49 -0800850 * <p>
851 * <ul>
852 * <li>For a joystick, reports the absolute position of the throttle control.
853 * The value is normalized to a range from 0.0 (fully open) to 1.0 (fully closed).
854 * </ul>
855 * </p>
856 *
857 * @see #getAxisValue(int, int)
858 * @see #getHistoricalAxisValue(int, int, int)
859 * @see MotionEvent.PointerCoords#getAxisValue(int)
860 * @see InputDevice#getMotionRange
861 */
862 public static final int AXIS_THROTTLE = 19;
863
864 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700865 * Axis constant: Rudder axis of a motion event.
Jeff Brown3a22fa02011-03-04 13:07:49 -0800866 * <p>
867 * <ul>
868 * <li>For a joystick, reports the absolute position of the rudder control.
869 * The value is normalized to a range from -1.0 (turn left) to 1.0 (turn right).
870 * </ul>
871 * </p>
872 *
873 * @see #getAxisValue(int, int)
874 * @see #getHistoricalAxisValue(int, int, int)
875 * @see MotionEvent.PointerCoords#getAxisValue(int)
876 * @see InputDevice#getMotionRange
877 */
878 public static final int AXIS_RUDDER = 20;
879
880 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700881 * Axis constant: Wheel axis of a motion event.
Jeff Brown3a22fa02011-03-04 13:07:49 -0800882 * <p>
883 * <ul>
884 * <li>For a joystick, reports the absolute position of the steering wheel control.
885 * The value is normalized to a range from -1.0 (turn left) to 1.0 (turn right).
886 * </ul>
887 * </p>
888 *
889 * @see #getAxisValue(int, int)
890 * @see #getHistoricalAxisValue(int, int, int)
891 * @see MotionEvent.PointerCoords#getAxisValue(int)
892 * @see InputDevice#getMotionRange
893 */
894 public static final int AXIS_WHEEL = 21;
895
896 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700897 * Axis constant: Gas axis of a motion event.
Jeff Brown3a22fa02011-03-04 13:07:49 -0800898 * <p>
899 * <ul>
900 * <li>For a joystick, reports the absolute position of the gas (accelerator) control.
901 * The value is normalized to a range from 0.0 (no acceleration)
902 * to 1.0 (maximum acceleration).
903 * </ul>
904 * </p>
905 *
906 * @see #getAxisValue(int, int)
907 * @see #getHistoricalAxisValue(int, int, int)
908 * @see MotionEvent.PointerCoords#getAxisValue(int)
909 * @see InputDevice#getMotionRange
910 */
911 public static final int AXIS_GAS = 22;
912
913 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700914 * Axis constant: Brake axis of a motion event.
Jeff Brown3a22fa02011-03-04 13:07:49 -0800915 * <p>
916 * <ul>
917 * <li>For a joystick, reports the absolute position of the brake control.
918 * The value is normalized to a range from 0.0 (no braking) to 1.0 (maximum braking).
919 * </ul>
920 * </p>
921 *
922 * @see #getAxisValue(int, int)
923 * @see #getHistoricalAxisValue(int, int, int)
924 * @see MotionEvent.PointerCoords#getAxisValue(int)
925 * @see InputDevice#getMotionRange
926 */
927 public static final int AXIS_BRAKE = 23;
928
929 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700930 * Axis constant: Distance axis of a motion event.
931 * <p>
932 * <ul>
933 * <li>For a stylus, reports the distance of the stylus from the screen.
Jeff Brown65fd2512011-08-18 11:20:58 -0700934 * A value of 0.0 indicates direct contact and larger values indicate increasing
935 * distance from the surface.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -0700936 * </ul>
937 * </p>
938 *
939 * @see #getAxisValue(int, int)
940 * @see #getHistoricalAxisValue(int, int, int)
941 * @see MotionEvent.PointerCoords#getAxisValue(int)
942 * @see InputDevice#getMotionRange
943 */
944 public static final int AXIS_DISTANCE = 24;
945
946 /**
Jeff Brown65fd2512011-08-18 11:20:58 -0700947 * Axis constant: Tilt axis of a motion event.
948 * <p>
949 * <ul>
950 * <li>For a stylus, reports the tilt angle of the stylus in radians where
951 * 0 radians indicates that the stylus is being held perpendicular to the
952 * surface, and PI/2 radians indicates that the stylus is being held flat
953 * against the surface.
954 * </ul>
955 * </p>
956 *
957 * @see #getAxisValue(int, int)
958 * @see #getHistoricalAxisValue(int, int, int)
959 * @see MotionEvent.PointerCoords#getAxisValue(int, int)
960 * @see InputDevice#getMotionRange
961 */
962 public static final int AXIS_TILT = 25;
963
964 /**
Prashant Malani67322b12015-08-25 17:41:34 -0700965 * Axis constant: Generic scroll axis of a motion event.
966 * <p>
967 * <ul>
968 * <li>Reports the relative movement of the generic scrolling device.
969 * </ul>
970 * </p><p>
971 * This axis should be used for scroll events that are neither strictly vertical nor horizontal.
972 * A good example would be the rotation of a rotary encoder input device.
973 * </p>
974 *
975 * @see #getAxisValue(int, int)
Prashant Malani81716582016-01-06 13:31:14 -0800976 * {@hide}
Prashant Malani67322b12015-08-25 17:41:34 -0700977 */
978 public static final int AXIS_SCROLL = 26;
979
980 /**
Jun Mukai347e5d42015-12-03 01:13:31 -0800981 * Axis constant: The movement of x position of a motion event.
982 * <p>
983 * <ul>
984 * <li>For a mouse, reports a difference of x position between the previous position.
985 * This is useful when pointer is captured, in that case the mouse pointer doesn't change
986 * the location but this axis reports the difference which allows the app to see
987 * how the mouse is moved.
988 * </ul>
989 * </p>
990 *
991 * @see #getAxisValue(int, int)
992 * @see #getHistoricalAxisValue(int, int, int)
993 * @see MotionEvent.PointerCoords#getAxisValue(int, int)
994 * @see InputDevice#getMotionRange
995 */
996 public static final int AXIS_RELATIVE_X = 27;
997
998 /**
999 * Axis constant: The movement of y position of a motion event.
1000 * <p>
1001 * This is similar to {@link #AXIS_RELATIVE_X} but for y-axis.
1002 * </p>
1003 *
1004 * @see #getAxisValue(int, int)
1005 * @see #getHistoricalAxisValue(int, int, int)
1006 * @see MotionEvent.PointerCoords#getAxisValue(int, int)
1007 * @see InputDevice#getMotionRange
1008 */
1009 public static final int AXIS_RELATIVE_Y = 28;
1010
1011 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001012 * Axis constant: Generic 1 axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -08001013 * The interpretation of a generic axis is device-specific.
1014 *
1015 * @see #getAxisValue(int, int)
1016 * @see #getHistoricalAxisValue(int, int, int)
1017 * @see MotionEvent.PointerCoords#getAxisValue(int)
1018 * @see InputDevice#getMotionRange
1019 */
1020 public static final int AXIS_GENERIC_1 = 32;
1021
1022 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001023 * Axis constant: Generic 2 axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -08001024 * The interpretation of a generic axis is device-specific.
1025 *
1026 * @see #getAxisValue(int, int)
1027 * @see #getHistoricalAxisValue(int, int, int)
1028 * @see MotionEvent.PointerCoords#getAxisValue(int)
1029 * @see InputDevice#getMotionRange
1030 */
1031 public static final int AXIS_GENERIC_2 = 33;
1032
1033 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001034 * Axis constant: Generic 3 axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -08001035 * The interpretation of a generic axis is device-specific.
1036 *
1037 * @see #getAxisValue(int, int)
1038 * @see #getHistoricalAxisValue(int, int, int)
1039 * @see MotionEvent.PointerCoords#getAxisValue(int)
1040 * @see InputDevice#getMotionRange
1041 */
1042 public static final int AXIS_GENERIC_3 = 34;
1043
1044 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001045 * Axis constant: Generic 4 axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -08001046 * The interpretation of a generic axis is device-specific.
1047 *
1048 * @see #getAxisValue(int, int)
1049 * @see #getHistoricalAxisValue(int, int, int)
1050 * @see MotionEvent.PointerCoords#getAxisValue(int)
1051 * @see InputDevice#getMotionRange
1052 */
1053 public static final int AXIS_GENERIC_4 = 35;
1054
1055 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001056 * Axis constant: Generic 5 axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -08001057 * The interpretation of a generic axis is device-specific.
1058 *
1059 * @see #getAxisValue(int, int)
1060 * @see #getHistoricalAxisValue(int, int, int)
1061 * @see MotionEvent.PointerCoords#getAxisValue(int)
1062 * @see InputDevice#getMotionRange
1063 */
1064 public static final int AXIS_GENERIC_5 = 36;
1065
1066 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001067 * Axis constant: Generic 6 axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -08001068 * The interpretation of a generic axis is device-specific.
1069 *
1070 * @see #getAxisValue(int, int)
1071 * @see #getHistoricalAxisValue(int, int, int)
1072 * @see MotionEvent.PointerCoords#getAxisValue(int)
1073 * @see InputDevice#getMotionRange
1074 */
1075 public static final int AXIS_GENERIC_6 = 37;
1076
1077 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001078 * Axis constant: Generic 7 axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -08001079 * The interpretation of a generic axis is device-specific.
1080 *
1081 * @see #getAxisValue(int, int)
1082 * @see #getHistoricalAxisValue(int, int, int)
1083 * @see MotionEvent.PointerCoords#getAxisValue(int)
1084 * @see InputDevice#getMotionRange
1085 */
1086 public static final int AXIS_GENERIC_7 = 38;
1087
1088 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001089 * Axis constant: Generic 8 axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -08001090 * The interpretation of a generic axis is device-specific.
1091 *
1092 * @see #getAxisValue(int, int)
1093 * @see #getHistoricalAxisValue(int, int, int)
1094 * @see MotionEvent.PointerCoords#getAxisValue(int)
1095 * @see InputDevice#getMotionRange
1096 */
1097 public static final int AXIS_GENERIC_8 = 39;
1098
1099 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001100 * Axis constant: Generic 9 axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -08001101 * The interpretation of a generic axis is device-specific.
1102 *
1103 * @see #getAxisValue(int, int)
1104 * @see #getHistoricalAxisValue(int, int, int)
1105 * @see MotionEvent.PointerCoords#getAxisValue(int)
1106 * @see InputDevice#getMotionRange
1107 */
1108 public static final int AXIS_GENERIC_9 = 40;
1109
1110 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001111 * Axis constant: Generic 10 axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -08001112 * The interpretation of a generic axis is device-specific.
1113 *
1114 * @see #getAxisValue(int, int)
1115 * @see #getHistoricalAxisValue(int, int, int)
1116 * @see MotionEvent.PointerCoords#getAxisValue(int)
1117 * @see InputDevice#getMotionRange
1118 */
1119 public static final int AXIS_GENERIC_10 = 41;
1120
1121 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001122 * Axis constant: Generic 11 axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -08001123 * The interpretation of a generic axis is device-specific.
1124 *
1125 * @see #getAxisValue(int, int)
1126 * @see #getHistoricalAxisValue(int, int, int)
1127 * @see MotionEvent.PointerCoords#getAxisValue(int)
1128 * @see InputDevice#getMotionRange
1129 */
1130 public static final int AXIS_GENERIC_11 = 42;
1131
1132 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001133 * Axis constant: Generic 12 axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -08001134 * The interpretation of a generic axis is device-specific.
1135 *
1136 * @see #getAxisValue(int, int)
1137 * @see #getHistoricalAxisValue(int, int, int)
1138 * @see MotionEvent.PointerCoords#getAxisValue(int)
1139 * @see InputDevice#getMotionRange
1140 */
1141 public static final int AXIS_GENERIC_12 = 43;
1142
1143 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001144 * Axis constant: Generic 13 axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -08001145 * The interpretation of a generic axis is device-specific.
1146 *
1147 * @see #getAxisValue(int, int)
1148 * @see #getHistoricalAxisValue(int, int, int)
1149 * @see MotionEvent.PointerCoords#getAxisValue(int)
1150 * @see InputDevice#getMotionRange
1151 */
1152 public static final int AXIS_GENERIC_13 = 44;
1153
1154 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001155 * Axis constant: Generic 14 axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -08001156 * The interpretation of a generic axis is device-specific.
1157 *
1158 * @see #getAxisValue(int, int)
1159 * @see #getHistoricalAxisValue(int, int, int)
1160 * @see MotionEvent.PointerCoords#getAxisValue(int)
1161 * @see InputDevice#getMotionRange
1162 */
1163 public static final int AXIS_GENERIC_14 = 45;
1164
1165 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001166 * Axis constant: Generic 15 axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -08001167 * The interpretation of a generic axis is device-specific.
1168 *
1169 * @see #getAxisValue(int, int)
1170 * @see #getHistoricalAxisValue(int, int, int)
1171 * @see MotionEvent.PointerCoords#getAxisValue(int)
1172 * @see InputDevice#getMotionRange
1173 */
1174 public static final int AXIS_GENERIC_15 = 46;
1175
1176 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001177 * Axis constant: Generic 16 axis of a motion event.
Jeff Brown6f2fba42011-02-19 01:08:02 -08001178 * The interpretation of a generic axis is device-specific.
1179 *
1180 * @see #getAxisValue(int, int)
1181 * @see #getHistoricalAxisValue(int, int, int)
1182 * @see MotionEvent.PointerCoords#getAxisValue(int)
1183 * @see InputDevice#getMotionRange
1184 */
1185 public static final int AXIS_GENERIC_16 = 47;
1186
1187 // NOTE: If you add a new axis here you must also add it to:
1188 // native/include/android/input.h
1189 // frameworks/base/include/ui/KeycodeLabels.h
1190
1191 // Symbolic names of all axes.
1192 private static final SparseArray<String> AXIS_SYMBOLIC_NAMES = new SparseArray<String>();
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001193 static {
Jeff Brown6f2fba42011-02-19 01:08:02 -08001194 SparseArray<String> names = AXIS_SYMBOLIC_NAMES;
1195 names.append(AXIS_X, "AXIS_X");
1196 names.append(AXIS_Y, "AXIS_Y");
1197 names.append(AXIS_PRESSURE, "AXIS_PRESSURE");
1198 names.append(AXIS_SIZE, "AXIS_SIZE");
1199 names.append(AXIS_TOUCH_MAJOR, "AXIS_TOUCH_MAJOR");
1200 names.append(AXIS_TOUCH_MINOR, "AXIS_TOUCH_MINOR");
1201 names.append(AXIS_TOOL_MAJOR, "AXIS_TOOL_MAJOR");
1202 names.append(AXIS_TOOL_MINOR, "AXIS_TOOL_MINOR");
1203 names.append(AXIS_ORIENTATION, "AXIS_ORIENTATION");
1204 names.append(AXIS_VSCROLL, "AXIS_VSCROLL");
1205 names.append(AXIS_HSCROLL, "AXIS_HSCROLL");
1206 names.append(AXIS_Z, "AXIS_Z");
1207 names.append(AXIS_RX, "AXIS_RX");
1208 names.append(AXIS_RY, "AXIS_RY");
1209 names.append(AXIS_RZ, "AXIS_RZ");
1210 names.append(AXIS_HAT_X, "AXIS_HAT_X");
1211 names.append(AXIS_HAT_Y, "AXIS_HAT_Y");
1212 names.append(AXIS_LTRIGGER, "AXIS_LTRIGGER");
1213 names.append(AXIS_RTRIGGER, "AXIS_RTRIGGER");
Jeff Brown3a22fa02011-03-04 13:07:49 -08001214 names.append(AXIS_THROTTLE, "AXIS_THROTTLE");
1215 names.append(AXIS_RUDDER, "AXIS_RUDDER");
1216 names.append(AXIS_WHEEL, "AXIS_WHEEL");
1217 names.append(AXIS_GAS, "AXIS_GAS");
1218 names.append(AXIS_BRAKE, "AXIS_BRAKE");
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001219 names.append(AXIS_DISTANCE, "AXIS_DISTANCE");
Jeff Brown65fd2512011-08-18 11:20:58 -07001220 names.append(AXIS_TILT, "AXIS_TILT");
Prashant Malani67322b12015-08-25 17:41:34 -07001221 names.append(AXIS_SCROLL, "AXIS_SCROLL");
Jun Mukai347e5d42015-12-03 01:13:31 -08001222 names.append(AXIS_RELATIVE_X, "AXIS_REALTIVE_X");
1223 names.append(AXIS_RELATIVE_Y, "AXIS_REALTIVE_Y");
Jeff Brown6f2fba42011-02-19 01:08:02 -08001224 names.append(AXIS_GENERIC_1, "AXIS_GENERIC_1");
1225 names.append(AXIS_GENERIC_2, "AXIS_GENERIC_2");
1226 names.append(AXIS_GENERIC_3, "AXIS_GENERIC_3");
1227 names.append(AXIS_GENERIC_4, "AXIS_GENERIC_4");
1228 names.append(AXIS_GENERIC_5, "AXIS_GENERIC_5");
1229 names.append(AXIS_GENERIC_6, "AXIS_GENERIC_6");
1230 names.append(AXIS_GENERIC_7, "AXIS_GENERIC_7");
1231 names.append(AXIS_GENERIC_8, "AXIS_GENERIC_8");
1232 names.append(AXIS_GENERIC_9, "AXIS_GENERIC_9");
1233 names.append(AXIS_GENERIC_10, "AXIS_GENERIC_10");
1234 names.append(AXIS_GENERIC_11, "AXIS_GENERIC_11");
1235 names.append(AXIS_GENERIC_12, "AXIS_GENERIC_12");
1236 names.append(AXIS_GENERIC_13, "AXIS_GENERIC_13");
1237 names.append(AXIS_GENERIC_14, "AXIS_GENERIC_14");
1238 names.append(AXIS_GENERIC_15, "AXIS_GENERIC_15");
1239 names.append(AXIS_GENERIC_16, "AXIS_GENERIC_16");
1240 }
1241
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001242 /**
Jeff Brown49754db2011-07-01 17:37:58 -07001243 * Button constant: Primary button (left mouse button).
1244 *
1245 * This button constant is not set in response to simple touches with a finger
1246 * or stylus tip. The user must actually push a button.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001247 *
1248 * @see #getButtonState
1249 */
1250 public static final int BUTTON_PRIMARY = 1 << 0;
1251
1252 /**
Michael Wright5bd69e62015-05-14 14:48:08 +01001253 * Button constant: Secondary button (right mouse button).
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001254 *
1255 * @see #getButtonState
1256 */
1257 public static final int BUTTON_SECONDARY = 1 << 1;
1258
1259 /**
Michael Wright5bd69e62015-05-14 14:48:08 +01001260 * Button constant: Tertiary button (middle mouse button).
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001261 *
1262 * @see #getButtonState
1263 */
1264 public static final int BUTTON_TERTIARY = 1 << 2;
1265
1266 /**
1267 * Button constant: Back button pressed (mouse back button).
1268 * <p>
1269 * The system may send a {@link KeyEvent#KEYCODE_BACK} key press to the application
1270 * when this button is pressed.
1271 * </p>
1272 *
1273 * @see #getButtonState
1274 */
1275 public static final int BUTTON_BACK = 1 << 3;
1276
1277 /**
1278 * Button constant: Forward button pressed (mouse forward button).
1279 * <p>
1280 * The system may send a {@link KeyEvent#KEYCODE_FORWARD} key press to the application
1281 * when this button is pressed.
1282 * </p>
1283 *
1284 * @see #getButtonState
1285 */
1286 public static final int BUTTON_FORWARD = 1 << 4;
1287
Michael Wright5bd69e62015-05-14 14:48:08 +01001288 /**
1289 * Button constant: Primary stylus button pressed.
1290 *
1291 * @see #getButtonState
1292 */
1293 public static final int BUTTON_STYLUS_PRIMARY = 1 << 5;
1294
1295 /**
1296 * Button constant: Secondary stylus button pressed.
1297 *
1298 * @see #getButtonState
1299 */
1300 public static final int BUTTON_STYLUS_SECONDARY = 1 << 6;
1301
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001302 // NOTE: If you add a new axis here you must also add it to:
1303 // native/include/android/input.h
1304
1305 // Symbolic names of all button states in bit order from least significant
1306 // to most significant.
1307 private static final String[] BUTTON_SYMBOLIC_NAMES = new String[] {
1308 "BUTTON_PRIMARY",
1309 "BUTTON_SECONDARY",
1310 "BUTTON_TERTIARY",
1311 "BUTTON_BACK",
1312 "BUTTON_FORWARD",
Michael Wright5bd69e62015-05-14 14:48:08 +01001313 "BUTTON_STYLUS_PRIMARY",
1314 "BUTTON_STYLUS_SECONDARY",
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001315 "0x00000080",
1316 "0x00000100",
1317 "0x00000200",
1318 "0x00000400",
1319 "0x00000800",
1320 "0x00001000",
1321 "0x00002000",
1322 "0x00004000",
1323 "0x00008000",
1324 "0x00010000",
1325 "0x00020000",
1326 "0x00040000",
1327 "0x00080000",
1328 "0x00100000",
1329 "0x00200000",
1330 "0x00400000",
1331 "0x00800000",
1332 "0x01000000",
1333 "0x02000000",
1334 "0x04000000",
1335 "0x08000000",
1336 "0x10000000",
1337 "0x20000000",
1338 "0x40000000",
1339 "0x80000000",
1340 };
1341
1342 /**
1343 * Tool type constant: Unknown tool type.
1344 * This constant is used when the tool type is not known or is not relevant,
1345 * such as for a trackball or other non-pointing device.
1346 *
1347 * @see #getToolType
1348 */
1349 public static final int TOOL_TYPE_UNKNOWN = 0;
1350
1351 /**
Jeff Brown49754db2011-07-01 17:37:58 -07001352 * Tool type constant: The tool is a finger.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001353 *
1354 * @see #getToolType
1355 */
1356 public static final int TOOL_TYPE_FINGER = 1;
1357
1358 /**
Jeff Brown49754db2011-07-01 17:37:58 -07001359 * Tool type constant: The tool is a stylus.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001360 *
1361 * @see #getToolType
1362 */
1363 public static final int TOOL_TYPE_STYLUS = 2;
1364
1365 /**
Jeff Brown49754db2011-07-01 17:37:58 -07001366 * Tool type constant: The tool is a mouse or trackpad.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001367 *
1368 * @see #getToolType
1369 */
1370 public static final int TOOL_TYPE_MOUSE = 3;
1371
1372 /**
Jeff Brown49754db2011-07-01 17:37:58 -07001373 * Tool type constant: The tool is an eraser or a stylus being used in an inverted posture.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001374 *
1375 * @see #getToolType
1376 */
Jeff Brown49754db2011-07-01 17:37:58 -07001377 public static final int TOOL_TYPE_ERASER = 4;
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001378
1379 // NOTE: If you add a new tool type here you must also add it to:
1380 // native/include/android/input.h
1381
1382 // Symbolic names of all tool types.
1383 private static final SparseArray<String> TOOL_TYPE_SYMBOLIC_NAMES = new SparseArray<String>();
Jeff Brown6f2fba42011-02-19 01:08:02 -08001384 static {
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001385 SparseArray<String> names = TOOL_TYPE_SYMBOLIC_NAMES;
1386 names.append(TOOL_TYPE_UNKNOWN, "TOOL_TYPE_UNKNOWN");
1387 names.append(TOOL_TYPE_FINGER, "TOOL_TYPE_FINGER");
1388 names.append(TOOL_TYPE_STYLUS, "TOOL_TYPE_STYLUS");
1389 names.append(TOOL_TYPE_MOUSE, "TOOL_TYPE_MOUSE");
Jeff Brown49754db2011-07-01 17:37:58 -07001390 names.append(TOOL_TYPE_ERASER, "TOOL_TYPE_ERASER");
Jeff Brown6f2fba42011-02-19 01:08:02 -08001391 }
1392
Jeff Brown91c69ab2011-02-14 17:03:18 -08001393 // Private value for history pos that obtains the current sample.
1394 private static final int HISTORY_CURRENT = -0x80000000;
1395
Jeff Brown1f245102010-11-18 20:53:46 -08001396 private static final int MAX_RECYCLED = 10;
1397 private static final Object gRecyclerLock = new Object();
1398 private static int gRecyclerUsed;
1399 private static MotionEvent gRecyclerTop;
Romain Guycafdea62009-06-12 10:51:36 -07001400
Jeff Brown91c69ab2011-02-14 17:03:18 -08001401 // Shared temporary objects used when translating coordinates supplied by
1402 // the caller into single element PointerCoords and pointer id arrays.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001403 private static final Object gSharedTempLock = new Object();
1404 private static PointerCoords[] gSharedTempPointerCoords;
1405 private static PointerProperties[] gSharedTempPointerProperties;
1406 private static int[] gSharedTempPointerIndexMap;
1407
1408 private static final void ensureSharedTempPointerCapacity(int desiredCapacity) {
1409 if (gSharedTempPointerCoords == null
1410 || gSharedTempPointerCoords.length < desiredCapacity) {
1411 int capacity = gSharedTempPointerCoords != null ? gSharedTempPointerCoords.length : 8;
1412 while (capacity < desiredCapacity) {
1413 capacity *= 2;
1414 }
1415 gSharedTempPointerCoords = PointerCoords.createArray(capacity);
1416 gSharedTempPointerProperties = PointerProperties.createArray(capacity);
1417 gSharedTempPointerIndexMap = new int[capacity];
1418 }
1419 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08001420
1421 // Pointer to the native MotionEvent object that contains the actual data.
Ashok Bhat99a1ef22014-01-08 14:45:08 +00001422 private long mNativePtr;
Mitsuru Oshima8169dae2009-04-28 18:12:09 -07001423
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001424 private MotionEvent mNext;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001425
Ashok Bhat99a1ef22014-01-08 14:45:08 +00001426 private static native long nativeInitialize(long nativePtr,
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001427 int deviceId, int source, int action, int flags, int edgeFlags,
1428 int metaState, int buttonState,
Jeff Brown91c69ab2011-02-14 17:03:18 -08001429 float xOffset, float yOffset, float xPrecision, float yPrecision,
1430 long downTimeNanos, long eventTimeNanos,
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001431 int pointerCount, PointerProperties[] pointerIds, PointerCoords[] pointerCoords);
Ashok Bhat99a1ef22014-01-08 14:45:08 +00001432 private static native long nativeCopy(long destNativePtr, long sourceNativePtr,
Jeff Brown91c69ab2011-02-14 17:03:18 -08001433 boolean keepHistory);
Ashok Bhat99a1ef22014-01-08 14:45:08 +00001434 private static native void nativeDispose(long nativePtr);
1435 private static native void nativeAddBatch(long nativePtr, long eventTimeNanos,
Jeff Brown91c69ab2011-02-14 17:03:18 -08001436 PointerCoords[] pointerCoords, int metaState);
Jeff Brown20e987b2010-08-23 12:01:02 -07001437
Ashok Bhat99a1ef22014-01-08 14:45:08 +00001438 private static native int nativeGetDeviceId(long nativePtr);
1439 private static native int nativeGetSource(long nativePtr);
1440 private static native int nativeSetSource(long nativePtr, int source);
1441 private static native int nativeGetAction(long nativePtr);
1442 private static native void nativeSetAction(long nativePtr, int action);
1443 private static native boolean nativeIsTouchEvent(long nativePtr);
1444 private static native int nativeGetFlags(long nativePtr);
1445 private static native void nativeSetFlags(long nativePtr, int flags);
1446 private static native int nativeGetEdgeFlags(long nativePtr);
1447 private static native void nativeSetEdgeFlags(long nativePtr, int action);
1448 private static native int nativeGetMetaState(long nativePtr);
1449 private static native int nativeGetButtonState(long nativePtr);
Michael Wright5bd69e62015-05-14 14:48:08 +01001450 private static native void nativeSetButtonState(long nativePtr, int buttonState);
1451 private static native int nativeGetActionButton(long nativePtr);
Michael Wright6b819b42015-06-17 21:06:03 +01001452 private static native void nativeSetActionButton(long nativePtr, int actionButton);
Ashok Bhat99a1ef22014-01-08 14:45:08 +00001453 private static native void nativeOffsetLocation(long nativePtr, float deltaX, float deltaY);
1454 private static native float nativeGetXOffset(long nativePtr);
1455 private static native float nativeGetYOffset(long nativePtr);
1456 private static native float nativeGetXPrecision(long nativePtr);
1457 private static native float nativeGetYPrecision(long nativePtr);
1458 private static native long nativeGetDownTimeNanos(long nativePtr);
1459 private static native void nativeSetDownTimeNanos(long nativePtr, long downTime);
Jeff Brown91c69ab2011-02-14 17:03:18 -08001460
Ashok Bhat99a1ef22014-01-08 14:45:08 +00001461 private static native int nativeGetPointerCount(long nativePtr);
1462 private static native int nativeGetPointerId(long nativePtr, int pointerIndex);
1463 private static native int nativeGetToolType(long nativePtr, int pointerIndex);
1464 private static native int nativeFindPointerIndex(long nativePtr, int pointerId);
Jeff Brown91c69ab2011-02-14 17:03:18 -08001465
Ashok Bhat99a1ef22014-01-08 14:45:08 +00001466 private static native int nativeGetHistorySize(long nativePtr);
1467 private static native long nativeGetEventTimeNanos(long nativePtr, int historyPos);
1468 private static native float nativeGetRawAxisValue(long nativePtr,
Jeff Brown91c69ab2011-02-14 17:03:18 -08001469 int axis, int pointerIndex, int historyPos);
Ashok Bhat99a1ef22014-01-08 14:45:08 +00001470 private static native float nativeGetAxisValue(long nativePtr,
Jeff Brown91c69ab2011-02-14 17:03:18 -08001471 int axis, int pointerIndex, int historyPos);
Ashok Bhat99a1ef22014-01-08 14:45:08 +00001472 private static native void nativeGetPointerCoords(long nativePtr,
Jeff Brown91c69ab2011-02-14 17:03:18 -08001473 int pointerIndex, int historyPos, PointerCoords outPointerCoords);
Ashok Bhat99a1ef22014-01-08 14:45:08 +00001474 private static native void nativeGetPointerProperties(long nativePtr,
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001475 int pointerIndex, PointerProperties outPointerProperties);
Jeff Brown91c69ab2011-02-14 17:03:18 -08001476
Ashok Bhat99a1ef22014-01-08 14:45:08 +00001477 private static native void nativeScale(long nativePtr, float scale);
1478 private static native void nativeTransform(long nativePtr, Matrix matrix);
Jeff Brown91c69ab2011-02-14 17:03:18 -08001479
Ashok Bhat99a1ef22014-01-08 14:45:08 +00001480 private static native long nativeReadFromParcel(long nativePtr, Parcel parcel);
1481 private static native void nativeWriteToParcel(long nativePtr, Parcel parcel);
Jeff Brown91c69ab2011-02-14 17:03:18 -08001482
Michael Wright337d9d22014-04-22 15:03:48 -07001483 private static native String nativeAxisToString(int axis);
1484 private static native int nativeAxisFromString(String label);
1485
Jeff Brown91c69ab2011-02-14 17:03:18 -08001486 private MotionEvent() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001487 }
Romain Guycafdea62009-06-12 10:51:36 -07001488
Jeff Brown91c69ab2011-02-14 17:03:18 -08001489 @Override
1490 protected void finalize() throws Throwable {
1491 try {
1492 if (mNativePtr != 0) {
1493 nativeDispose(mNativePtr);
1494 mNativePtr = 0;
1495 }
1496 } finally {
1497 super.finalize();
1498 }
1499 }
1500
1501 static private MotionEvent obtain() {
Jeff Brown46b9ac02010-04-22 18:58:52 -07001502 final MotionEvent ev;
1503 synchronized (gRecyclerLock) {
Jeff Brown1f245102010-11-18 20:53:46 -08001504 ev = gRecyclerTop;
1505 if (ev == null) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001506 return new MotionEvent();
Jeff Brown46b9ac02010-04-22 18:58:52 -07001507 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07001508 gRecyclerTop = ev.mNext;
Jeff Brown5c225b12010-06-16 01:53:36 -07001509 gRecyclerUsed -= 1;
Jeff Brown46b9ac02010-04-22 18:58:52 -07001510 }
Jeff Brown46b9ac02010-04-22 18:58:52 -07001511 ev.mNext = null;
Jeff Brown32cbc38552011-12-01 14:01:49 -08001512 ev.prepareForReuse();
Jeff Brown46b9ac02010-04-22 18:58:52 -07001513 return ev;
1514 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08001515
Michael Chan53071d62009-05-13 17:29:48 -07001516 /**
1517 * Create a new MotionEvent, filling in all of the basic values that
1518 * define the motion.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001519 *
Michael Chan53071d62009-05-13 17:29:48 -07001520 * @param downTime The time (in ms) when the user originally pressed down to start
1521 * a stream of position events. This must be obtained from {@link SystemClock#uptimeMillis()}.
Jeff Brownc5ed5912010-07-14 18:48:53 -07001522 * @param eventTime The the time (in ms) when this specific event was generated. This
Michael Chan53071d62009-05-13 17:29:48 -07001523 * must be obtained from {@link SystemClock#uptimeMillis()}.
Jeff Browncc0c1592011-02-19 05:07:28 -08001524 * @param action The kind of action being performed, such as {@link #ACTION_DOWN}.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001525 * @param pointerCount The number of pointers that will be in this event.
1526 * @param pointerProperties An array of <em>pointerCount</em> values providing
1527 * a {@link PointerProperties} property object for each pointer, which must
1528 * include the pointer identifier.
1529 * @param pointerCoords An array of <em>pointerCount</em> values providing
1530 * a {@link PointerCoords} coordinate object for each pointer.
1531 * @param metaState The state of any meta / modifier keys that were in effect when
1532 * the event was generated.
1533 * @param buttonState The state of buttons that are pressed.
1534 * @param xPrecision The precision of the X coordinate being reported.
1535 * @param yPrecision The precision of the Y coordinate being reported.
1536 * @param deviceId The id for the device that this event came from. An id of
1537 * zero indicates that the event didn't come from a physical device; other
1538 * numbers are arbitrary and you shouldn't depend on the values.
1539 * @param edgeFlags A bitfield indicating which edges, if any, were touched by this
1540 * MotionEvent.
1541 * @param source The source of this event.
1542 * @param flags The motion event flags.
1543 */
1544 static public MotionEvent obtain(long downTime, long eventTime,
1545 int action, int pointerCount, PointerProperties[] pointerProperties,
1546 PointerCoords[] pointerCoords, int metaState, int buttonState,
1547 float xPrecision, float yPrecision, int deviceId,
1548 int edgeFlags, int source, int flags) {
1549 MotionEvent ev = obtain();
1550 ev.mNativePtr = nativeInitialize(ev.mNativePtr,
1551 deviceId, source, action, flags, edgeFlags, metaState, buttonState,
1552 0, 0, xPrecision, yPrecision,
1553 downTime * NS_PER_MS, eventTime * NS_PER_MS,
1554 pointerCount, pointerProperties, pointerCoords);
1555 return ev;
1556 }
1557
1558 /**
1559 * Create a new MotionEvent, filling in all of the basic values that
1560 * define the motion.
1561 *
1562 * @param downTime The time (in ms) when the user originally pressed down to start
1563 * a stream of position events. This must be obtained from {@link SystemClock#uptimeMillis()}.
1564 * @param eventTime The the time (in ms) when this specific event was generated. This
1565 * must be obtained from {@link SystemClock#uptimeMillis()}.
1566 * @param action The kind of action being performed, such as {@link #ACTION_DOWN}.
1567 * @param pointerCount The number of pointers that will be in this event.
1568 * @param pointerIds An array of <em>pointerCount</em> values providing
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001569 * an identifier for each pointer.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001570 * @param pointerCoords An array of <em>pointerCount</em> values providing
Jeff Brownc5ed5912010-07-14 18:48:53 -07001571 * a {@link PointerCoords} coordinate object for each pointer.
Michael Chan53071d62009-05-13 17:29:48 -07001572 * @param metaState The state of any meta / modifier keys that were in effect when
1573 * the event was generated.
1574 * @param xPrecision The precision of the X coordinate being reported.
1575 * @param yPrecision The precision of the Y coordinate being reported.
1576 * @param deviceId The id for the device that this event came from. An id of
1577 * zero indicates that the event didn't come from a physical device; other
1578 * numbers are arbitrary and you shouldn't depend on the values.
Jeff Brown85a31762010-09-01 17:01:00 -07001579 * @param edgeFlags A bitfield indicating which edges, if any, were touched by this
Michael Chan53071d62009-05-13 17:29:48 -07001580 * MotionEvent.
Jeff Brownc5ed5912010-07-14 18:48:53 -07001581 * @param source The source of this event.
Jeff Brown85a31762010-09-01 17:01:00 -07001582 * @param flags The motion event flags.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001583 *
1584 * @deprecated Use {@link #obtain(long, long, int, int, PointerProperties[], PointerCoords[], int, int, float, float, int, int, int, int)}
1585 * instead.
Michael Chan53071d62009-05-13 17:29:48 -07001586 */
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001587 @Deprecated
Jeff Brownc5ed5912010-07-14 18:48:53 -07001588 static public MotionEvent obtain(long downTime, long eventTime,
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001589 int action, int pointerCount, int[] pointerIds, PointerCoords[] pointerCoords,
Jeff Brownc5ed5912010-07-14 18:48:53 -07001590 int metaState, float xPrecision, float yPrecision, int deviceId,
Jeff Brown85a31762010-09-01 17:01:00 -07001591 int edgeFlags, int source, int flags) {
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001592 synchronized (gSharedTempLock) {
1593 ensureSharedTempPointerCapacity(pointerCount);
1594 final PointerProperties[] pp = gSharedTempPointerProperties;
1595 for (int i = 0; i < pointerCount; i++) {
1596 pp[i].clear();
1597 pp[i].id = pointerIds[i];
1598 }
1599 return obtain(downTime, eventTime, action, pointerCount, pp,
1600 pointerCoords, metaState, 0, xPrecision, yPrecision, deviceId,
1601 edgeFlags, source, flags);
1602 }
Michael Chan53071d62009-05-13 17:29:48 -07001603 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08001604
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001605 /**
1606 * Create a new MotionEvent, filling in all of the basic values that
1607 * define the motion.
Romain Guycafdea62009-06-12 10:51:36 -07001608 *
1609 * @param downTime The time (in ms) when the user originally pressed down to start
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001610 * a stream of position events. This must be obtained from {@link SystemClock#uptimeMillis()}.
Romain Guycafdea62009-06-12 10:51:36 -07001611 * @param eventTime The the time (in ms) when this specific event was generated. This
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001612 * must be obtained from {@link SystemClock#uptimeMillis()}.
Jeff Browncc0c1592011-02-19 05:07:28 -08001613 * @param action The kind of action being performed, such as {@link #ACTION_DOWN}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001614 * @param x The X coordinate of this event.
1615 * @param y The Y coordinate of this event.
Romain Guycafdea62009-06-12 10:51:36 -07001616 * @param pressure The current pressure of this event. The pressure generally
1617 * ranges from 0 (no pressure at all) to 1 (normal pressure), however
1618 * values higher than 1 may be generated depending on the calibration of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001619 * the input device.
1620 * @param size A scaled value of the approximate size of the area being pressed when
Romain Guycafdea62009-06-12 10:51:36 -07001621 * touched with the finger. The actual value in pixels corresponding to the finger
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001622 * touch is normalized with a device specific range of values
1623 * and scaled to a value between 0 and 1.
1624 * @param metaState The state of any meta / modifier keys that were in effect when
1625 * the event was generated.
1626 * @param xPrecision The precision of the X coordinate being reported.
1627 * @param yPrecision The precision of the Y coordinate being reported.
1628 * @param deviceId The id for the device that this event came from. An id of
1629 * zero indicates that the event didn't come from a physical device; other
1630 * numbers are arbitrary and you shouldn't depend on the values.
Jeff Brown85a31762010-09-01 17:01:00 -07001631 * @param edgeFlags A bitfield indicating which edges, if any, were touched by this
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001632 * MotionEvent.
1633 */
1634 static public MotionEvent obtain(long downTime, long eventTime, int action,
1635 float x, float y, float pressure, float size, int metaState,
1636 float xPrecision, float yPrecision, int deviceId, int edgeFlags) {
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001637 MotionEvent ev = obtain();
1638 synchronized (gSharedTempLock) {
1639 ensureSharedTempPointerCapacity(1);
1640 final PointerProperties[] pp = gSharedTempPointerProperties;
1641 pp[0].clear();
1642 pp[0].id = 0;
Jeff Brown91c69ab2011-02-14 17:03:18 -08001643
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001644 final PointerCoords pc[] = gSharedTempPointerCoords;
1645 pc[0].clear();
1646 pc[0].x = x;
1647 pc[0].y = y;
1648 pc[0].pressure = pressure;
1649 pc[0].size = size;
1650
Jeff Brown91c69ab2011-02-14 17:03:18 -08001651 ev.mNativePtr = nativeInitialize(ev.mNativePtr,
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001652 deviceId, InputDevice.SOURCE_UNKNOWN, action, 0, edgeFlags, metaState, 0,
Jeff Brown91c69ab2011-02-14 17:03:18 -08001653 0, 0, xPrecision, yPrecision,
1654 downTime * NS_PER_MS, eventTime * NS_PER_MS,
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001655 1, pp, pc);
Jeff Brown91c69ab2011-02-14 17:03:18 -08001656 return ev;
1657 }
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001658 }
1659
1660 /**
1661 * Create a new MotionEvent, filling in all of the basic values that
1662 * define the motion.
1663 *
1664 * @param downTime The time (in ms) when the user originally pressed down to start
1665 * a stream of position events. This must be obtained from {@link SystemClock#uptimeMillis()}.
1666 * @param eventTime The the time (in ms) when this specific event was generated. This
1667 * must be obtained from {@link SystemClock#uptimeMillis()}.
Jeff Browncc0c1592011-02-19 05:07:28 -08001668 * @param action The kind of action being performed, such as {@link #ACTION_DOWN}.
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001669 * @param pointerCount The number of pointers that are active in this event.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001670 * @param x The X coordinate of this event.
1671 * @param y The Y coordinate of this event.
1672 * @param pressure The current pressure of this event. The pressure generally
1673 * ranges from 0 (no pressure at all) to 1 (normal pressure), however
1674 * values higher than 1 may be generated depending on the calibration of
1675 * the input device.
1676 * @param size A scaled value of the approximate size of the area being pressed when
1677 * touched with the finger. The actual value in pixels corresponding to the finger
1678 * touch is normalized with a device specific range of values
1679 * and scaled to a value between 0 and 1.
1680 * @param metaState The state of any meta / modifier keys that were in effect when
1681 * the event was generated.
1682 * @param xPrecision The precision of the X coordinate being reported.
1683 * @param yPrecision The precision of the Y coordinate being reported.
1684 * @param deviceId The id for the device that this event came from. An id of
1685 * zero indicates that the event didn't come from a physical device; other
1686 * numbers are arbitrary and you shouldn't depend on the values.
Jeff Brown85a31762010-09-01 17:01:00 -07001687 * @param edgeFlags A bitfield indicating which edges, if any, were touched by this
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001688 * MotionEvent.
Jeff Brown5c225b12010-06-16 01:53:36 -07001689 *
1690 * @deprecated Use {@link #obtain(long, long, int, float, float, float, float, int, float, float, int, int)}
1691 * instead.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001692 */
Jeff Brown5c225b12010-06-16 01:53:36 -07001693 @Deprecated
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001694 static public MotionEvent obtain(long downTime, long eventTime, int action,
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001695 int pointerCount, float x, float y, float pressure, float size, int metaState,
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001696 float xPrecision, float yPrecision, int deviceId, int edgeFlags) {
Jeff Brown5c225b12010-06-16 01:53:36 -07001697 return obtain(downTime, eventTime, action, x, y, pressure, size,
1698 metaState, xPrecision, yPrecision, deviceId, edgeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001699 }
Romain Guycafdea62009-06-12 10:51:36 -07001700
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001701 /**
1702 * Create a new MotionEvent, filling in a subset of the basic motion
1703 * values. Those not specified here are: device id (always 0), pressure
1704 * and size (always 1), x and y precision (always 1), and edgeFlags (always 0).
Romain Guycafdea62009-06-12 10:51:36 -07001705 *
1706 * @param downTime The time (in ms) when the user originally pressed down to start
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001707 * a stream of position events. This must be obtained from {@link SystemClock#uptimeMillis()}.
Romain Guycafdea62009-06-12 10:51:36 -07001708 * @param eventTime The the time (in ms) when this specific event was generated. This
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001709 * must be obtained from {@link SystemClock#uptimeMillis()}.
Jeff Browncc0c1592011-02-19 05:07:28 -08001710 * @param action The kind of action being performed, such as {@link #ACTION_DOWN}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001711 * @param x The X coordinate of this event.
1712 * @param y The Y coordinate of this event.
1713 * @param metaState The state of any meta / modifier keys that were in effect when
1714 * the event was generated.
1715 */
1716 static public MotionEvent obtain(long downTime, long eventTime, int action,
1717 float x, float y, int metaState) {
Jeff Brown5c225b12010-06-16 01:53:36 -07001718 return obtain(downTime, eventTime, action, x, y, 1.0f, 1.0f,
1719 metaState, 1.0f, 1.0f, 0, 0);
Mitsuru Oshima8169dae2009-04-28 18:12:09 -07001720 }
1721
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001722 /**
1723 * Create a new MotionEvent, copying from an existing one.
1724 */
Jeff Brown91c69ab2011-02-14 17:03:18 -08001725 static public MotionEvent obtain(MotionEvent other) {
1726 if (other == null) {
1727 throw new IllegalArgumentException("other motion event must not be null");
1728 }
1729
1730 MotionEvent ev = obtain();
1731 ev.mNativePtr = nativeCopy(ev.mNativePtr, other.mNativePtr, true /*keepHistory*/);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001732 return ev;
1733 }
Romain Guycafdea62009-06-12 10:51:36 -07001734
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001735 /**
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07001736 * Create a new MotionEvent, copying from an existing one, but not including
1737 * any historical point information.
1738 */
Jeff Brown91c69ab2011-02-14 17:03:18 -08001739 static public MotionEvent obtainNoHistory(MotionEvent other) {
1740 if (other == null) {
1741 throw new IllegalArgumentException("other motion event must not be null");
1742 }
1743
1744 MotionEvent ev = obtain();
1745 ev.mNativePtr = nativeCopy(ev.mNativePtr, other.mNativePtr, false /*keepHistory*/);
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07001746 return ev;
1747 }
1748
Jeff Brown21bc5c92011-02-28 18:27:14 -08001749 /** @hide */
1750 @Override
1751 public MotionEvent copy() {
1752 return obtain(this);
1753 }
1754
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -07001755 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001756 * Recycle the MotionEvent, to be re-used by a later caller. After calling
1757 * this function you must not ever touch the event again.
1758 */
Jeff Brown92cc2d82011-12-02 01:19:47 -08001759 @Override
Jeff Brown5c225b12010-06-16 01:53:36 -07001760 public final void recycle() {
Jeff Brown32cbc38552011-12-01 14:01:49 -08001761 super.recycle();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001762
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001763 synchronized (gRecyclerLock) {
1764 if (gRecyclerUsed < MAX_RECYCLED) {
1765 gRecyclerUsed++;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001766 mNext = gRecyclerTop;
1767 gRecyclerTop = this;
1768 }
1769 }
1770 }
Jeff Brown9ea77fc2012-03-21 19:49:27 -07001771
Jeff Brown5c225b12010-06-16 01:53:36 -07001772 /**
Jeff Brown9ea77fc2012-03-21 19:49:27 -07001773 * Applies a scale factor to all points within this event.
Jeff Brown5c225b12010-06-16 01:53:36 -07001774 *
Jeff Brown9ea77fc2012-03-21 19:49:27 -07001775 * This method is used to adjust touch events to simulate different density
1776 * displays for compatibility mode. The values returned by {@link #getRawX()},
1777 * {@link #getRawY()}, {@link #getXPrecision()} and {@link #getYPrecision()}
1778 * are also affected by the scale factor.
1779 *
1780 * @param scale The scale factor to apply.
Jeff Brown5c225b12010-06-16 01:53:36 -07001781 * @hide
1782 */
1783 public final void scale(float scale) {
Jeff Brown9ea77fc2012-03-21 19:49:27 -07001784 if (scale != 1.0f) {
1785 nativeScale(mNativePtr, scale);
1786 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08001787 }
1788
1789 /** {@inheritDoc} */
1790 @Override
1791 public final int getDeviceId() {
1792 return nativeGetDeviceId(mNativePtr);
1793 }
1794
1795 /** {@inheritDoc} */
1796 @Override
1797 public final int getSource() {
1798 return nativeGetSource(mNativePtr);
1799 }
1800
1801 /** {@inheritDoc} */
1802 @Override
1803 public final void setSource(int source) {
1804 nativeSetSource(mNativePtr, source);
Jeff Brown5c225b12010-06-16 01:53:36 -07001805 }
Romain Guycafdea62009-06-12 10:51:36 -07001806
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001807 /**
Jeff Browncc0c1592011-02-19 05:07:28 -08001808 * Return the kind of action being performed.
1809 * Consider using {@link #getActionMasked} and {@link #getActionIndex} to retrieve
1810 * the separate masked action and pointer index.
1811 * @return The action, such as {@link #ACTION_DOWN} or
1812 * the combination of {@link #ACTION_POINTER_DOWN} with a shifted pointer index.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001813 */
1814 public final int getAction() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001815 return nativeGetAction(mNativePtr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001816 }
1817
1818 /**
Jeff Browncc0c1592011-02-19 05:07:28 -08001819 * Return the masked action being performed, without pointer index information.
1820 * Use {@link #getActionIndex} to return the index associated with pointer actions.
1821 * @return The action, such as {@link #ACTION_DOWN} or {@link #ACTION_POINTER_DOWN}.
Dianne Hackbornb125dc52010-02-12 15:52:09 -08001822 */
1823 public final int getActionMasked() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001824 return nativeGetAction(mNativePtr) & ACTION_MASK;
Dianne Hackbornb125dc52010-02-12 15:52:09 -08001825 }
1826
1827 /**
1828 * For {@link #ACTION_POINTER_DOWN} or {@link #ACTION_POINTER_UP}
1829 * as returned by {@link #getActionMasked}, this returns the associated
Jeff Browncc0c1592011-02-19 05:07:28 -08001830 * pointer index.
1831 * The index may be used with {@link #getPointerId(int)},
Dianne Hackbornb125dc52010-02-12 15:52:09 -08001832 * {@link #getX(int)}, {@link #getY(int)}, {@link #getPressure(int)},
1833 * and {@link #getSize(int)} to get information about the pointer that has
1834 * gone down or up.
Jeff Browncc0c1592011-02-19 05:07:28 -08001835 * @return The index associated with the action.
Dianne Hackbornb125dc52010-02-12 15:52:09 -08001836 */
1837 public final int getActionIndex() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001838 return (nativeGetAction(mNativePtr) & ACTION_POINTER_INDEX_MASK)
1839 >> ACTION_POINTER_INDEX_SHIFT;
Dianne Hackbornb125dc52010-02-12 15:52:09 -08001840 }
1841
1842 /**
Jeff Brown33bbfd22011-02-24 20:55:35 -08001843 * Returns true if this motion event is a touch event.
1844 * <p>
Jeff Browna032cc02011-03-07 16:56:21 -08001845 * Specifically excludes pointer events with action {@link #ACTION_HOVER_MOVE},
1846 * {@link #ACTION_HOVER_ENTER}, {@link #ACTION_HOVER_EXIT}, or {@link #ACTION_SCROLL}
1847 * because they are not actually touch events (the pointer is not down).
Jeff Brown33bbfd22011-02-24 20:55:35 -08001848 * </p>
1849 * @return True if this motion event is a touch event.
1850 * @hide
1851 */
1852 public final boolean isTouchEvent() {
Jeff Brown56194eb2011-03-02 19:23:13 -08001853 return nativeIsTouchEvent(mNativePtr);
Jeff Brown33bbfd22011-02-24 20:55:35 -08001854 }
1855
1856 /**
Jeff Brown85a31762010-09-01 17:01:00 -07001857 * Gets the motion event flags.
1858 *
1859 * @see #FLAG_WINDOW_IS_OBSCURED
1860 */
1861 public final int getFlags() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001862 return nativeGetFlags(mNativePtr);
Jeff Brown85a31762010-09-01 17:01:00 -07001863 }
1864
Jeff Brown21bc5c92011-02-28 18:27:14 -08001865 /** @hide */
1866 @Override
1867 public final boolean isTainted() {
1868 final int flags = getFlags();
1869 return (flags & FLAG_TAINTED) != 0;
1870 }
1871
1872 /** @hide */
1873 @Override
1874 public final void setTainted(boolean tainted) {
1875 final int flags = getFlags();
1876 nativeSetFlags(mNativePtr, tainted ? flags | FLAG_TAINTED : flags & ~FLAG_TAINTED);
1877 }
1878
Svetoslavded133c2015-01-30 20:28:41 -08001879 /** @hide */
1880 public final boolean isTargetAccessibilityFocus() {
1881 final int flags = getFlags();
1882 return (flags & FLAG_TARGET_ACCESSIBILITY_FOCUS) != 0;
1883 }
1884
1885 /** @hide */
1886 public final void setTargetAccessibilityFocus(boolean targetsFocus) {
1887 final int flags = getFlags();
1888 nativeSetFlags(mNativePtr, targetsFocus
1889 ? flags | FLAG_TARGET_ACCESSIBILITY_FOCUS
1890 : flags & ~FLAG_TARGET_ACCESSIBILITY_FOCUS);
1891 }
1892
Jeff Brown85a31762010-09-01 17:01:00 -07001893 /**
Romain Guycafdea62009-06-12 10:51:36 -07001894 * Returns the time (in ms) when the user originally pressed down to start
1895 * a stream of position events.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001896 */
1897 public final long getDownTime() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001898 return nativeGetDownTimeNanos(mNativePtr) / NS_PER_MS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001899 }
1900
1901 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07001902 * Sets the time (in ms) when the user originally pressed down to start
1903 * a stream of position events.
1904 *
1905 * @hide
1906 */
1907 public final void setDownTime(long downTime) {
1908 nativeSetDownTimeNanos(mNativePtr, downTime * NS_PER_MS);
1909 }
1910
1911 /**
Jeff Brownb11499d2012-04-20 19:54:22 -07001912 * Retrieve the time this event occurred,
1913 * in the {@link android.os.SystemClock#uptimeMillis} time base.
1914 *
1915 * @return Returns the time this event occurred,
1916 * in the {@link android.os.SystemClock#uptimeMillis} time base.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001917 */
Jeff Brownb11499d2012-04-20 19:54:22 -07001918 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001919 public final long getEventTime() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001920 return nativeGetEventTimeNanos(mNativePtr, HISTORY_CURRENT) / NS_PER_MS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001921 }
1922
1923 /**
Jeff Brownb11499d2012-04-20 19:54:22 -07001924 * Retrieve the time this event occurred,
1925 * in the {@link android.os.SystemClock#uptimeMillis} time base but with
1926 * nanosecond precision.
1927 * <p>
Michael Chan53071d62009-05-13 17:29:48 -07001928 * The value is in nanosecond precision but it may not have nanosecond accuracy.
Jeff Brownb11499d2012-04-20 19:54:22 -07001929 * </p>
1930 *
1931 * @return Returns the time this event occurred,
1932 * in the {@link android.os.SystemClock#uptimeMillis} time base but with
1933 * nanosecond precision.
Michael Chan53071d62009-05-13 17:29:48 -07001934 *
1935 * @hide
1936 */
Jeff Brownb11499d2012-04-20 19:54:22 -07001937 @Override
Michael Chan53071d62009-05-13 17:29:48 -07001938 public final long getEventTimeNano() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001939 return nativeGetEventTimeNanos(mNativePtr, HISTORY_CURRENT);
Michael Chan53071d62009-05-13 17:29:48 -07001940 }
1941
1942 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001943 * {@link #getX(int)} for the first pointer index (may be an
1944 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001945 *
1946 * @see #AXIS_X
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001947 */
1948 public final float getX() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001949 return nativeGetAxisValue(mNativePtr, AXIS_X, 0, HISTORY_CURRENT);
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001950 }
1951
1952 /**
1953 * {@link #getY(int)} for the first pointer index (may be an
1954 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001955 *
1956 * @see #AXIS_Y
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001957 */
1958 public final float getY() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001959 return nativeGetAxisValue(mNativePtr, AXIS_Y, 0, HISTORY_CURRENT);
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001960 }
1961
1962 /**
1963 * {@link #getPressure(int)} for the first pointer index (may be an
1964 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001965 *
1966 * @see #AXIS_PRESSURE
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001967 */
1968 public final float getPressure() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001969 return nativeGetAxisValue(mNativePtr, AXIS_PRESSURE, 0, HISTORY_CURRENT);
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001970 }
1971
1972 /**
1973 * {@link #getSize(int)} for the first pointer index (may be an
1974 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001975 *
1976 * @see #AXIS_SIZE
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001977 */
1978 public final float getSize() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001979 return nativeGetAxisValue(mNativePtr, AXIS_SIZE, 0, HISTORY_CURRENT);
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001980 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07001981
1982 /**
1983 * {@link #getTouchMajor(int)} for the first pointer index (may be an
1984 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001985 *
1986 * @see #AXIS_TOUCH_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07001987 */
1988 public final float getTouchMajor() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001989 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MAJOR, 0, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001990 }
1991
1992 /**
1993 * {@link #getTouchMinor(int)} for the first pointer index (may be an
1994 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08001995 *
1996 * @see #AXIS_TOUCH_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07001997 */
1998 public final float getTouchMinor() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08001999 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MINOR, 0, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002000 }
2001
2002 /**
2003 * {@link #getToolMajor(int)} for the first pointer index (may be an
2004 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002005 *
2006 * @see #AXIS_TOOL_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002007 */
2008 public final float getToolMajor() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002009 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MAJOR, 0, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002010 }
2011
2012 /**
2013 * {@link #getToolMinor(int)} for the first pointer index (may be an
2014 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002015 *
2016 * @see #AXIS_TOOL_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002017 */
2018 public final float getToolMinor() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002019 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MINOR, 0, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002020 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08002021
Jeff Brownc5ed5912010-07-14 18:48:53 -07002022 /**
2023 * {@link #getOrientation(int)} for the first pointer index (may be an
2024 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002025 *
2026 * @see #AXIS_ORIENTATION
Jeff Brownc5ed5912010-07-14 18:48:53 -07002027 */
2028 public final float getOrientation() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002029 return nativeGetAxisValue(mNativePtr, AXIS_ORIENTATION, 0, HISTORY_CURRENT);
2030 }
2031
2032 /**
2033 * {@link #getAxisValue(int)} for the first pointer index (may be an
2034 * arbitrary pointer identifier).
2035 *
2036 * @param axis The axis identifier for the axis value to retrieve.
2037 *
2038 * @see #AXIS_X
2039 * @see #AXIS_Y
2040 */
2041 public final float getAxisValue(int axis) {
2042 return nativeGetAxisValue(mNativePtr, axis, 0, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002043 }
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002044
2045 /**
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002046 * The number of pointers of data contained in this event. Always
2047 * >= 1.
2048 */
2049 public final int getPointerCount() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002050 return nativeGetPointerCount(mNativePtr);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002051 }
2052
2053 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002054 * Return the pointer identifier associated with a particular pointer
2055 * data index is this event. The identifier tells you the actual pointer
2056 * number associated with the data, accounting for individual pointers
2057 * going up and down since the start of the current gesture.
2058 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2059 * (the first pointer that is down) to {@link #getPointerCount()}-1.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002060 */
Dianne Hackbornd41ba662009-08-05 15:30:56 -07002061 public final int getPointerId(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002062 return nativeGetPointerId(mNativePtr, pointerIndex);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002063 }
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07002064
2065 /**
2066 * Gets the tool type of a pointer for the given pointer index.
2067 * The tool type indicates the type of tool used to make contact such
2068 * as a finger or stylus, if known.
2069 *
2070 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2071 * (the first pointer that is down) to {@link #getPointerCount()}-1.
2072 * @return The tool type of the pointer.
2073 *
2074 * @see #TOOL_TYPE_UNKNOWN
2075 * @see #TOOL_TYPE_FINGER
2076 * @see #TOOL_TYPE_STYLUS
2077 * @see #TOOL_TYPE_MOUSE
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07002078 */
2079 public final int getToolType(int pointerIndex) {
2080 return nativeGetToolType(mNativePtr, pointerIndex);
2081 }
2082
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002083 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002084 * Given a pointer identifier, find the index of its data in the event.
2085 *
2086 * @param pointerId The identifier of the pointer to be found.
2087 * @return Returns either the index of the pointer (for use with
Gilles Debunneb0d6ba12010-08-17 20:01:42 -07002088 * {@link #getX(int)} et al.), or -1 if there is no data available for
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002089 * that pointer identifier.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002090 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002091 public final int findPointerIndex(int pointerId) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002092 return nativeFindPointerIndex(mNativePtr, pointerId);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002093 }
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07002094
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002095 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002096 * Returns the X coordinate of this event for the given pointer
2097 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
2098 * identifier for this index).
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002099 * Whole numbers are pixels; the
2100 * value may have a fraction for input devices that are sub-pixel precise.
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002101 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2102 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002103 *
2104 * @see #AXIS_X
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002105 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002106 public final float getX(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002107 return nativeGetAxisValue(mNativePtr, AXIS_X, pointerIndex, HISTORY_CURRENT);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002108 }
2109
2110 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002111 * Returns the Y coordinate of this event for the given pointer
2112 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
2113 * identifier for this index).
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002114 * Whole numbers are pixels; the
2115 * value may have a fraction for input devices that are sub-pixel precise.
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002116 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2117 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002118 *
2119 * @see #AXIS_Y
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002120 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002121 public final float getY(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002122 return nativeGetAxisValue(mNativePtr, AXIS_Y, pointerIndex, HISTORY_CURRENT);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002123 }
2124
2125 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002126 * Returns the current pressure of this event for the given pointer
2127 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
2128 * identifier for this index).
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002129 * The pressure generally
Romain Guycafdea62009-06-12 10:51:36 -07002130 * ranges from 0 (no pressure at all) to 1 (normal pressure), however
2131 * values higher than 1 may be generated depending on the calibration of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002132 * the input device.
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002133 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2134 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002135 *
2136 * @see #AXIS_PRESSURE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002137 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002138 public final float getPressure(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002139 return nativeGetAxisValue(mNativePtr, AXIS_PRESSURE, pointerIndex, HISTORY_CURRENT);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002140 }
2141
2142 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002143 * Returns a scaled value of the approximate size for the given pointer
2144 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
2145 * identifier for this index).
2146 * This represents some approximation of the area of the screen being
2147 * pressed; the actual value in pixels corresponding to the
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002148 * touch is normalized with the device specific range of values
Romain Guycafdea62009-06-12 10:51:36 -07002149 * 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 -08002150 * determine fat touch events.
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002151 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2152 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002153 *
2154 * @see #AXIS_SIZE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002155 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002156 public final float getSize(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002157 return nativeGetAxisValue(mNativePtr, AXIS_SIZE, pointerIndex, HISTORY_CURRENT);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002158 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002159
2160 /**
2161 * Returns the length of the major axis of an ellipse that describes the touch
2162 * area at the point of contact for the given pointer
2163 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
2164 * identifier for this index).
2165 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2166 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002167 *
2168 * @see #AXIS_TOUCH_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002169 */
2170 public final float getTouchMajor(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002171 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MAJOR, pointerIndex, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002172 }
2173
2174 /**
2175 * Returns the length of the minor axis of an ellipse that describes the touch
2176 * area at the point of contact for the given pointer
2177 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
2178 * identifier for this index).
2179 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2180 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002181 *
2182 * @see #AXIS_TOUCH_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002183 */
2184 public final float getTouchMinor(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002185 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MINOR, pointerIndex, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002186 }
2187
2188 /**
2189 * Returns the length of the major axis of an ellipse that describes the size of
2190 * the approaching tool for the given pointer
2191 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
2192 * identifier for this index).
2193 * The tool area represents the estimated size of the finger or pen that is
2194 * touching the device independent of its actual touch area at the point of contact.
2195 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2196 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002197 *
2198 * @see #AXIS_TOOL_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002199 */
2200 public final float getToolMajor(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002201 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MAJOR, pointerIndex, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002202 }
2203
2204 /**
2205 * Returns the length of the minor axis of an ellipse that describes the size of
2206 * the approaching tool for the given pointer
2207 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
2208 * identifier for this index).
2209 * The tool area represents the estimated size of the finger or pen that is
2210 * touching the device independent of its actual touch area at the point of contact.
2211 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2212 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002213 *
2214 * @see #AXIS_TOOL_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002215 */
2216 public final float getToolMinor(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002217 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MINOR, pointerIndex, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002218 }
2219
2220 /**
2221 * Returns the orientation of the touch area and tool area in radians clockwise from vertical
2222 * for the given pointer <em>index</em> (use {@link #getPointerId(int)} to find the pointer
2223 * identifier for this index).
Jeff Brown6f2fba42011-02-19 01:08:02 -08002224 * An angle of 0 radians indicates that the major axis of contact is oriented
Jeff Brownc5ed5912010-07-14 18:48:53 -07002225 * upwards, is perfectly circular or is of unknown orientation. A positive angle
2226 * indicates that the major axis of contact is oriented to the right. A negative angle
2227 * indicates that the major axis of contact is oriented to the left.
Jeff Brown6d0fec22010-07-23 21:28:06 -07002228 * The full range is from -PI/2 radians (finger pointing fully left) to PI/2 radians
Jeff Brownc5ed5912010-07-14 18:48:53 -07002229 * (finger pointing fully right).
2230 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2231 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002232 *
2233 * @see #AXIS_ORIENTATION
Jeff Brownc5ed5912010-07-14 18:48:53 -07002234 */
2235 public final float getOrientation(int pointerIndex) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002236 return nativeGetAxisValue(mNativePtr, AXIS_ORIENTATION, pointerIndex, HISTORY_CURRENT);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002237 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08002238
2239 /**
2240 * Returns the value of the requested axis for the given pointer <em>index</em>
2241 * (use {@link #getPointerId(int)} to find the pointer identifier for this index).
2242 *
2243 * @param axis The axis identifier for the axis value to retrieve.
2244 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2245 * (the first pointer that is down) to {@link #getPointerCount()}-1.
2246 * @return The value of the axis, or 0 if the axis is not available.
2247 *
2248 * @see #AXIS_X
2249 * @see #AXIS_Y
2250 */
2251 public final float getAxisValue(int axis, int pointerIndex) {
2252 return nativeGetAxisValue(mNativePtr, axis, pointerIndex, HISTORY_CURRENT);
2253 }
2254
Jeff Brownc5ed5912010-07-14 18:48:53 -07002255 /**
2256 * Populates a {@link PointerCoords} object with pointer coordinate data for
2257 * the specified pointer index.
2258 *
2259 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2260 * (the first pointer that is down) to {@link #getPointerCount()}-1.
2261 * @param outPointerCoords The pointer coordinate object to populate.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002262 *
2263 * @see PointerCoords
Jeff Brownc5ed5912010-07-14 18:48:53 -07002264 */
2265 public final void getPointerCoords(int pointerIndex, PointerCoords outPointerCoords) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002266 nativeGetPointerCoords(mNativePtr, pointerIndex, HISTORY_CURRENT, outPointerCoords);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002267 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002268
2269 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07002270 * Populates a {@link PointerProperties} object with pointer properties for
2271 * the specified pointer index.
2272 *
2273 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2274 * (the first pointer that is down) to {@link #getPointerCount()}-1.
2275 * @param outPointerProperties The pointer properties object to populate.
2276 *
2277 * @see PointerProperties
2278 */
2279 public final void getPointerProperties(int pointerIndex,
2280 PointerProperties outPointerProperties) {
2281 nativeGetPointerProperties(mNativePtr, pointerIndex, outPointerProperties);
2282 }
2283
2284 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002285 * Returns the state of any meta / modifier keys that were in effect when
2286 * the event was generated. This is the same values as those
2287 * returned by {@link KeyEvent#getMetaState() KeyEvent.getMetaState}.
2288 *
2289 * @return an integer in which each bit set to 1 represents a pressed
2290 * meta key
2291 *
2292 * @see KeyEvent#getMetaState()
2293 */
2294 public final int getMetaState() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002295 return nativeGetMetaState(mNativePtr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002296 }
2297
2298 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07002299 * Gets the state of all buttons that are pressed such as a mouse or stylus button.
2300 *
2301 * @return The button state.
2302 *
2303 * @see #BUTTON_PRIMARY
2304 * @see #BUTTON_SECONDARY
2305 * @see #BUTTON_TERTIARY
2306 * @see #BUTTON_FORWARD
2307 * @see #BUTTON_BACK
Michael Wright5bd69e62015-05-14 14:48:08 +01002308 * @see #BUTTON_STYLUS_PRIMARY
2309 * @see #BUTTON_STYLUS_SECONDARY
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07002310 */
2311 public final int getButtonState() {
2312 return nativeGetButtonState(mNativePtr);
2313 }
2314
2315 /**
Michael Wright5bd69e62015-05-14 14:48:08 +01002316 * Sets the bitfield indicating which buttons are pressed.
2317 *
2318 * @see #getButtonState()
2319 * @hide
2320 */
2321 public final void setButtonState(int buttonState) {
2322 nativeSetButtonState(mNativePtr, buttonState);
2323 }
2324
2325 /**
2326 * Gets which button has been modified during a press or release action.
2327 *
2328 * For actions other than {@link #ACTION_BUTTON_PRESS} and {@link #ACTION_BUTTON_RELEASE}
2329 * the returned value is undefined.
2330 *
2331 * @see #getButtonState()
2332 */
2333 public final int getActionButton() {
2334 return nativeGetActionButton(mNativePtr);
2335 }
2336
2337 /**
Michael Wright6b819b42015-06-17 21:06:03 +01002338 * Sets the action button for the event.
2339 *
2340 * @see #getActionButton()
2341 * @hide
2342 */
2343 public final void setActionButton(int button) {
2344 nativeSetActionButton(mNativePtr, button);
2345 }
2346
2347 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002348 * Returns the original raw X coordinate of this event. For touch
2349 * events on the screen, this is the original location of the event
2350 * on the screen, before it had been adjusted for the containing window
2351 * and views.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002352 *
Michael Wright072137c2013-04-24 20:41:20 -07002353 * @see #getX(int)
Jeff Brown91c69ab2011-02-14 17:03:18 -08002354 * @see #AXIS_X
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002355 */
2356 public final float getRawX() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002357 return nativeGetRawAxisValue(mNativePtr, AXIS_X, 0, HISTORY_CURRENT);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002358 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08002359
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002360 /**
2361 * Returns the original raw Y coordinate of this event. For touch
2362 * events on the screen, this is the original location of the event
2363 * on the screen, before it had been adjusted for the containing window
2364 * and views.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002365 *
Michael Wright072137c2013-04-24 20:41:20 -07002366 * @see #getY(int)
Jeff Brown91c69ab2011-02-14 17:03:18 -08002367 * @see #AXIS_Y
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002368 */
2369 public final float getRawY() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002370 return nativeGetRawAxisValue(mNativePtr, AXIS_Y, 0, HISTORY_CURRENT);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002371 }
2372
2373 /**
2374 * Return the precision of the X coordinates being reported. You can
Jeff Brown91c69ab2011-02-14 17:03:18 -08002375 * multiply this number with {@link #getX} to find the actual hardware
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002376 * value of the X coordinate.
2377 * @return Returns the precision of X coordinates being reported.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002378 *
2379 * @see #AXIS_X
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002380 */
2381 public final float getXPrecision() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002382 return nativeGetXPrecision(mNativePtr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002383 }
Romain Guycafdea62009-06-12 10:51:36 -07002384
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002385 /**
2386 * Return the precision of the Y coordinates being reported. You can
Jeff Brown91c69ab2011-02-14 17:03:18 -08002387 * multiply this number with {@link #getY} to find the actual hardware
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002388 * value of the Y coordinate.
2389 * @return Returns the precision of Y coordinates being reported.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002390 *
2391 * @see #AXIS_Y
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002392 */
2393 public final float getYPrecision() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002394 return nativeGetYPrecision(mNativePtr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002395 }
Romain Guycafdea62009-06-12 10:51:36 -07002396
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002397 /**
2398 * Returns the number of historical points in this event. These are
2399 * movements that have occurred between this event and the previous event.
2400 * This only applies to ACTION_MOVE events -- all other actions will have
2401 * a size of 0.
Romain Guycafdea62009-06-12 10:51:36 -07002402 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002403 * @return Returns the number of historical points in the event.
2404 */
2405 public final int getHistorySize() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002406 return nativeGetHistorySize(mNativePtr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002407 }
Romain Guycafdea62009-06-12 10:51:36 -07002408
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002409 /**
2410 * Returns the time that a historical movement occurred between this event
Jeff Brownb11499d2012-04-20 19:54:22 -07002411 * and the previous event, in the {@link android.os.SystemClock#uptimeMillis} time base.
2412 * <p>
2413 * This only applies to ACTION_MOVE events.
2414 * </p>
Romain Guycafdea62009-06-12 10:51:36 -07002415 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002416 * @param pos Which historical value to return; must be less than
2417 * {@link #getHistorySize}
Jeff Brownb11499d2012-04-20 19:54:22 -07002418 * @return Returns the time that a historical movement occurred between this
2419 * event and the previous event,
2420 * in the {@link android.os.SystemClock#uptimeMillis} time base.
Romain Guycafdea62009-06-12 10:51:36 -07002421 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002422 * @see #getHistorySize
2423 * @see #getEventTime
2424 */
2425 public final long getHistoricalEventTime(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002426 return nativeGetEventTimeNanos(mNativePtr, pos) / NS_PER_MS;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002427 }
2428
2429 /**
Jeff Brownb11499d2012-04-20 19:54:22 -07002430 * Returns the time that a historical movement occurred between this event
2431 * and the previous event, in the {@link android.os.SystemClock#uptimeMillis} time base
2432 * but with nanosecond (instead of millisecond) precision.
2433 * <p>
2434 * This only applies to ACTION_MOVE events.
2435 * </p><p>
2436 * The value is in nanosecond precision but it may not have nanosecond accuracy.
2437 * </p>
2438 *
2439 * @param pos Which historical value to return; must be less than
2440 * {@link #getHistorySize}
2441 * @return Returns the time that a historical movement occurred between this
2442 * event and the previous event,
2443 * in the {@link android.os.SystemClock#uptimeMillis} time base but with
2444 * nanosecond (instead of millisecond) precision.
2445 *
2446 * @see #getHistorySize
2447 * @see #getEventTime
2448 *
2449 * @hide
2450 */
2451 public final long getHistoricalEventTimeNano(int pos) {
2452 return nativeGetEventTimeNanos(mNativePtr, pos);
2453 }
2454
2455 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08002456 * {@link #getHistoricalX(int, int)} for the first pointer index (may be an
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002457 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002458 *
2459 * @param pos Which historical value to return; must be less than
2460 * {@link #getHistorySize}
2461 *
2462 * @see #getHistorySize
2463 * @see #getX()
2464 * @see #AXIS_X
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002465 */
2466 public final float getHistoricalX(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002467 return nativeGetAxisValue(mNativePtr, AXIS_X, 0, pos);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002468 }
2469
2470 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08002471 * {@link #getHistoricalY(int, int)} for the first pointer index (may be an
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002472 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002473 *
2474 * @param pos Which historical value to return; must be less than
2475 * {@link #getHistorySize}
2476 *
2477 * @see #getHistorySize
2478 * @see #getY()
2479 * @see #AXIS_Y
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002480 */
2481 public final float getHistoricalY(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002482 return nativeGetAxisValue(mNativePtr, AXIS_Y, 0, pos);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002483 }
2484
2485 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08002486 * {@link #getHistoricalPressure(int, int)} for the first pointer index (may be an
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002487 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002488 *
2489 * @param pos Which historical value to return; must be less than
2490 * {@link #getHistorySize}
2491 *
2492 * @see #getHistorySize
2493 * @see #getPressure()
2494 * @see #AXIS_PRESSURE
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002495 */
2496 public final float getHistoricalPressure(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002497 return nativeGetAxisValue(mNativePtr, AXIS_PRESSURE, 0, pos);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002498 }
2499
2500 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08002501 * {@link #getHistoricalSize(int, int)} for the first pointer index (may be an
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002502 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002503 *
2504 * @param pos Which historical value to return; must be less than
2505 * {@link #getHistorySize}
2506 *
2507 * @see #getHistorySize
2508 * @see #getSize()
2509 * @see #AXIS_SIZE
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002510 */
2511 public final float getHistoricalSize(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002512 return nativeGetAxisValue(mNativePtr, AXIS_SIZE, 0, pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002513 }
Romain Guycafdea62009-06-12 10:51:36 -07002514
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002515 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08002516 * {@link #getHistoricalTouchMajor(int, int)} for the first pointer index (may be an
Jeff Brownc5ed5912010-07-14 18:48:53 -07002517 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002518 *
2519 * @param pos Which historical value to return; must be less than
2520 * {@link #getHistorySize}
2521 *
2522 * @see #getHistorySize
2523 * @see #getTouchMajor()
2524 * @see #AXIS_TOUCH_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002525 */
2526 public final float getHistoricalTouchMajor(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002527 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MAJOR, 0, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002528 }
2529
2530 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08002531 * {@link #getHistoricalTouchMinor(int, int)} for the first pointer index (may be an
Jeff Brownc5ed5912010-07-14 18:48:53 -07002532 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002533 *
2534 * @param pos Which historical value to return; must be less than
2535 * {@link #getHistorySize}
2536 *
2537 * @see #getHistorySize
2538 * @see #getTouchMinor()
2539 * @see #AXIS_TOUCH_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002540 */
2541 public final float getHistoricalTouchMinor(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002542 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MINOR, 0, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002543 }
2544
2545 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08002546 * {@link #getHistoricalToolMajor(int, int)} for the first pointer index (may be an
Jeff Brownc5ed5912010-07-14 18:48:53 -07002547 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002548 *
2549 * @param pos Which historical value to return; must be less than
2550 * {@link #getHistorySize}
2551 *
2552 * @see #getHistorySize
2553 * @see #getToolMajor()
2554 * @see #AXIS_TOOL_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002555 */
2556 public final float getHistoricalToolMajor(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002557 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MAJOR, 0, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002558 }
2559
2560 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08002561 * {@link #getHistoricalToolMinor(int, int)} for the first pointer index (may be an
Jeff Brownc5ed5912010-07-14 18:48:53 -07002562 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002563 *
2564 * @param pos Which historical value to return; must be less than
2565 * {@link #getHistorySize}
2566 *
2567 * @see #getHistorySize
2568 * @see #getToolMinor()
2569 * @see #AXIS_TOOL_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002570 */
2571 public final float getHistoricalToolMinor(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002572 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MINOR, 0, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002573 }
2574
2575 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08002576 * {@link #getHistoricalOrientation(int, int)} for the first pointer index (may be an
Jeff Brownc5ed5912010-07-14 18:48:53 -07002577 * arbitrary pointer identifier).
Jeff Brown91c69ab2011-02-14 17:03:18 -08002578 *
2579 * @param pos Which historical value to return; must be less than
2580 * {@link #getHistorySize}
2581 *
2582 * @see #getHistorySize
2583 * @see #getOrientation()
2584 * @see #AXIS_ORIENTATION
Jeff Brownc5ed5912010-07-14 18:48:53 -07002585 */
2586 public final float getHistoricalOrientation(int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002587 return nativeGetAxisValue(mNativePtr, AXIS_ORIENTATION, 0, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002588 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08002589
2590 /**
2591 * {@link #getHistoricalAxisValue(int, int, int)} for the first pointer index (may be an
2592 * arbitrary pointer identifier).
2593 *
2594 * @param axis The axis identifier for the axis value to retrieve.
2595 * @param pos Which historical value to return; must be less than
2596 * {@link #getHistorySize}
2597 *
2598 * @see #getHistorySize
2599 * @see #getAxisValue(int)
2600 * @see #AXIS_X
2601 * @see #AXIS_Y
2602 */
2603 public final float getHistoricalAxisValue(int axis, int pos) {
2604 return nativeGetAxisValue(mNativePtr, axis, 0, pos);
2605 }
2606
Jeff Brownc5ed5912010-07-14 18:48:53 -07002607 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002608 * Returns a historical X coordinate, as per {@link #getX(int)}, that
2609 * occurred between this event and the previous event for the given pointer.
2610 * Only applies to ACTION_MOVE events.
Romain Guycafdea62009-06-12 10:51:36 -07002611 *
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002612 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2613 * (the first pointer that is down) to {@link #getPointerCount()}-1.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002614 * @param pos Which historical value to return; must be less than
2615 * {@link #getHistorySize}
Romain Guycafdea62009-06-12 10:51:36 -07002616 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002617 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08002618 * @see #getX(int)
2619 * @see #AXIS_X
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002620 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002621 public final float getHistoricalX(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002622 return nativeGetAxisValue(mNativePtr, AXIS_X, pointerIndex, pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002623 }
Romain Guycafdea62009-06-12 10:51:36 -07002624
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002625 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002626 * Returns a historical Y coordinate, as per {@link #getY(int)}, that
2627 * occurred between this event and the previous event for the given pointer.
2628 * Only applies to ACTION_MOVE events.
Romain Guycafdea62009-06-12 10:51:36 -07002629 *
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002630 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2631 * (the first pointer that is down) to {@link #getPointerCount()}-1.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002632 * @param pos Which historical value to return; must be less than
2633 * {@link #getHistorySize}
Romain Guycafdea62009-06-12 10:51:36 -07002634 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002635 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08002636 * @see #getY(int)
2637 * @see #AXIS_Y
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002638 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002639 public final float getHistoricalY(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002640 return nativeGetAxisValue(mNativePtr, AXIS_Y, pointerIndex, pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002641 }
Romain Guycafdea62009-06-12 10:51:36 -07002642
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002643 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002644 * Returns a historical pressure coordinate, as per {@link #getPressure(int)},
2645 * that occurred between this event and the previous event for the given
2646 * pointer. Only applies to ACTION_MOVE events.
Romain Guycafdea62009-06-12 10:51:36 -07002647 *
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002648 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2649 * (the first pointer that is down) to {@link #getPointerCount()}-1.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002650 * @param pos Which historical value to return; must be less than
2651 * {@link #getHistorySize}
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002652 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002653 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08002654 * @see #getPressure(int)
2655 * @see #AXIS_PRESSURE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002656 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002657 public final float getHistoricalPressure(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002658 return nativeGetAxisValue(mNativePtr, AXIS_PRESSURE, pointerIndex, pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002659 }
Romain Guycafdea62009-06-12 10:51:36 -07002660
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002661 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002662 * Returns a historical size coordinate, as per {@link #getSize(int)}, that
2663 * occurred between this event and the previous event for the given pointer.
2664 * Only applies to ACTION_MOVE events.
Romain Guycafdea62009-06-12 10:51:36 -07002665 *
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002666 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2667 * (the first pointer that is down) to {@link #getPointerCount()}-1.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002668 * @param pos Which historical value to return; must be less than
2669 * {@link #getHistorySize}
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002670 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002671 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08002672 * @see #getSize(int)
2673 * @see #AXIS_SIZE
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002674 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07002675 public final float getHistoricalSize(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002676 return nativeGetAxisValue(mNativePtr, AXIS_SIZE, pointerIndex, pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002677 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07002678
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002679 /**
Jeff Brownc5ed5912010-07-14 18:48:53 -07002680 * Returns a historical touch major axis coordinate, as per {@link #getTouchMajor(int)}, that
2681 * occurred between this event and the previous event for the given pointer.
2682 * Only applies to ACTION_MOVE events.
2683 *
2684 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2685 * (the first pointer that is down) to {@link #getPointerCount()}-1.
2686 * @param pos Which historical value to return; must be less than
2687 * {@link #getHistorySize}
2688 *
2689 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08002690 * @see #getTouchMajor(int)
2691 * @see #AXIS_TOUCH_MAJOR
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002692 */
Jeff Brownc5ed5912010-07-14 18:48:53 -07002693 public final float getHistoricalTouchMajor(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002694 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MAJOR, pointerIndex, pos);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002695 }
Romain Guycafdea62009-06-12 10:51:36 -07002696
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002697 /**
Jeff Brownc5ed5912010-07-14 18:48:53 -07002698 * Returns a historical touch minor axis coordinate, as per {@link #getTouchMinor(int)}, that
2699 * occurred between this event and the previous event for the given pointer.
2700 * Only applies to ACTION_MOVE events.
2701 *
2702 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2703 * (the first pointer that is down) to {@link #getPointerCount()}-1.
2704 * @param pos Which historical value to return; must be less than
2705 * {@link #getHistorySize}
2706 *
2707 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08002708 * @see #getTouchMinor(int)
2709 * @see #AXIS_TOUCH_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002710 */
2711 public final float getHistoricalTouchMinor(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002712 return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MINOR, pointerIndex, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002713 }
2714
2715 /**
2716 * Returns a historical tool major axis coordinate, as per {@link #getToolMajor(int)}, that
2717 * occurred between this event and the previous event for the given pointer.
2718 * Only applies to ACTION_MOVE events.
2719 *
2720 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2721 * (the first pointer that is down) to {@link #getPointerCount()}-1.
2722 * @param pos Which historical value to return; must be less than
2723 * {@link #getHistorySize}
2724 *
2725 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08002726 * @see #getToolMajor(int)
2727 * @see #AXIS_TOOL_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002728 */
2729 public final float getHistoricalToolMajor(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002730 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MAJOR, pointerIndex, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002731 }
2732
2733 /**
2734 * Returns a historical tool minor axis coordinate, as per {@link #getToolMinor(int)}, that
2735 * occurred between this event and the previous event for the given pointer.
2736 * Only applies to ACTION_MOVE events.
2737 *
2738 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2739 * (the first pointer that is down) to {@link #getPointerCount()}-1.
2740 * @param pos Which historical value to return; must be less than
2741 * {@link #getHistorySize}
2742 *
2743 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08002744 * @see #getToolMinor(int)
2745 * @see #AXIS_TOOL_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07002746 */
2747 public final float getHistoricalToolMinor(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002748 return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MINOR, pointerIndex, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002749 }
2750
2751 /**
2752 * Returns a historical orientation coordinate, as per {@link #getOrientation(int)}, that
2753 * occurred between this event and the previous event for the given pointer.
2754 * Only applies to ACTION_MOVE events.
2755 *
2756 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2757 * (the first pointer that is down) to {@link #getPointerCount()}-1.
2758 * @param pos Which historical value to return; must be less than
2759 * {@link #getHistorySize}
2760 *
2761 * @see #getHistorySize
Jeff Brown91c69ab2011-02-14 17:03:18 -08002762 * @see #getOrientation(int)
2763 * @see #AXIS_ORIENTATION
Jeff Brownc5ed5912010-07-14 18:48:53 -07002764 */
2765 public final float getHistoricalOrientation(int pointerIndex, int pos) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002766 return nativeGetAxisValue(mNativePtr, AXIS_ORIENTATION, pointerIndex, pos);
2767 }
2768
2769 /**
2770 * Returns the historical value of the requested axis, as per {@link #getAxisValue(int, int)},
2771 * occurred between this event and the previous event for the given pointer.
2772 * Only applies to ACTION_MOVE events.
2773 *
2774 * @param axis The axis identifier for the axis value to retrieve.
2775 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2776 * (the first pointer that is down) to {@link #getPointerCount()}-1.
2777 * @param pos Which historical value to return; must be less than
2778 * {@link #getHistorySize}
2779 * @return The value of the axis, or 0 if the axis is not available.
2780 *
2781 * @see #AXIS_X
2782 * @see #AXIS_Y
2783 */
2784 public final float getHistoricalAxisValue(int axis, int pointerIndex, int pos) {
2785 return nativeGetAxisValue(mNativePtr, axis, pointerIndex, pos);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002786 }
2787
2788 /**
2789 * Populates a {@link PointerCoords} object with historical pointer coordinate data,
2790 * as per {@link #getPointerCoords}, that occurred between this event and the previous
2791 * event for the given pointer.
2792 * Only applies to ACTION_MOVE events.
2793 *
2794 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
2795 * (the first pointer that is down) to {@link #getPointerCount()}-1.
2796 * @param pos Which historical value to return; must be less than
2797 * {@link #getHistorySize}
2798 * @param outPointerCoords The pointer coordinate object to populate.
2799 *
2800 * @see #getHistorySize
2801 * @see #getPointerCoords
Jeff Brown91c69ab2011-02-14 17:03:18 -08002802 * @see PointerCoords
Jeff Brownc5ed5912010-07-14 18:48:53 -07002803 */
2804 public final void getHistoricalPointerCoords(int pointerIndex, int pos,
2805 PointerCoords outPointerCoords) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002806 nativeGetPointerCoords(mNativePtr, pointerIndex, pos, outPointerCoords);
Jeff Brownc5ed5912010-07-14 18:48:53 -07002807 }
2808
2809 /**
Jeff Brown46b9ac02010-04-22 18:58:52 -07002810 * Returns a bitfield indicating which edges, if any, were touched by this
Romain Guycafdea62009-06-12 10:51:36 -07002811 * MotionEvent. For touch events, clients can use this to determine if the
2812 * user's finger was touching the edge of the display.
2813 *
Jeff Brownd41cff22011-03-03 02:09:54 -08002814 * This property is only set for {@link #ACTION_DOWN} events.
2815 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002816 * @see #EDGE_LEFT
2817 * @see #EDGE_TOP
2818 * @see #EDGE_RIGHT
2819 * @see #EDGE_BOTTOM
2820 */
2821 public final int getEdgeFlags() {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002822 return nativeGetEdgeFlags(mNativePtr);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002823 }
Romain Guycafdea62009-06-12 10:51:36 -07002824
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002825 /**
Jeff Brown85a31762010-09-01 17:01:00 -07002826 * Sets the bitfield indicating which edges, if any, were touched by this
Romain Guycafdea62009-06-12 10:51:36 -07002827 * MotionEvent.
2828 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002829 * @see #getEdgeFlags()
2830 */
2831 public final void setEdgeFlags(int flags) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002832 nativeSetEdgeFlags(mNativePtr, flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002833 }
2834
2835 /**
2836 * Sets this event's action.
2837 */
2838 public final void setAction(int action) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002839 nativeSetAction(mNativePtr, action);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002840 }
2841
2842 /**
2843 * Adjust this event's location.
2844 * @param deltaX Amount to add to the current X coordinate of the event.
2845 * @param deltaY Amount to add to the current Y coordinate of the event.
2846 */
2847 public final void offsetLocation(float deltaX, float deltaY) {
Jeff Brown9ea77fc2012-03-21 19:49:27 -07002848 if (deltaX != 0.0f || deltaY != 0.0f) {
2849 nativeOffsetLocation(mNativePtr, deltaX, deltaY);
2850 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002851 }
Romain Guycafdea62009-06-12 10:51:36 -07002852
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002853 /**
2854 * Set this event's location. Applies {@link #offsetLocation} with a
2855 * delta from the current location to the given new location.
Romain Guycafdea62009-06-12 10:51:36 -07002856 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002857 * @param x New absolute X location.
2858 * @param y New absolute Y location.
2859 */
2860 public final void setLocation(float x, float y) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002861 float oldX = getX();
2862 float oldY = getY();
Jeff Brown9ea77fc2012-03-21 19:49:27 -07002863 offsetLocation(x - oldX, y - oldY);
Jeff Brown5c225b12010-06-16 01:53:36 -07002864 }
2865
Jeff Brown20e987b2010-08-23 12:01:02 -07002866 /**
2867 * Applies a transformation matrix to all of the points in the event.
2868 *
2869 * @param matrix The transformation matrix to apply.
2870 */
2871 public final void transform(Matrix matrix) {
2872 if (matrix == null) {
2873 throw new IllegalArgumentException("matrix must not be null");
2874 }
2875
Jeff Brown91c69ab2011-02-14 17:03:18 -08002876 nativeTransform(mNativePtr, matrix);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002877 }
Romain Guycafdea62009-06-12 10:51:36 -07002878
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002879 /**
2880 * Add a new movement to the batch of movements in this event. The event's
Jeff Brownc5ed5912010-07-14 18:48:53 -07002881 * current location, position and size is updated to the new values.
2882 * The current values in the event are added to a list of historical values.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002883 *
Jeff Browncc0c1592011-02-19 05:07:28 -08002884 * Only applies to {@link #ACTION_MOVE} or {@link #ACTION_HOVER_MOVE} events.
Romain Guycafdea62009-06-12 10:51:36 -07002885 *
Jeff Brownc5ed5912010-07-14 18:48:53 -07002886 * @param eventTime The time stamp (in ms) for this data.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002887 * @param x The new X position.
2888 * @param y The new Y position.
2889 * @param pressure The new pressure.
2890 * @param size The new size.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002891 * @param metaState Meta key state.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002892 */
2893 public final void addBatch(long eventTime, float x, float y,
2894 float pressure, float size, int metaState) {
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07002895 synchronized (gSharedTempLock) {
2896 ensureSharedTempPointerCapacity(1);
2897 final PointerCoords[] pc = gSharedTempPointerCoords;
2898 pc[0].clear();
2899 pc[0].x = x;
2900 pc[0].y = y;
2901 pc[0].pressure = pressure;
2902 pc[0].size = size;
2903
2904 nativeAddBatch(mNativePtr, eventTime * NS_PER_MS, pc, metaState);
Jeff Brown91c69ab2011-02-14 17:03:18 -08002905 }
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002906 }
Romain Guycafdea62009-06-12 10:51:36 -07002907
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002908 /**
Jeff Brownc5ed5912010-07-14 18:48:53 -07002909 * Add a new movement to the batch of movements in this event. The event's
2910 * current location, position and size is updated to the new values.
2911 * The current values in the event are added to a list of historical values.
Jeff Brown91c69ab2011-02-14 17:03:18 -08002912 *
Jeff Browncc0c1592011-02-19 05:07:28 -08002913 * Only applies to {@link #ACTION_MOVE} or {@link #ACTION_HOVER_MOVE} events.
Jeff Brownc5ed5912010-07-14 18:48:53 -07002914 *
2915 * @param eventTime The time stamp (in ms) for this data.
2916 * @param pointerCoords The new pointer coordinates.
2917 * @param metaState Meta key state.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07002918 */
Jeff Brownc5ed5912010-07-14 18:48:53 -07002919 public final void addBatch(long eventTime, PointerCoords[] pointerCoords, int metaState) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08002920 nativeAddBatch(mNativePtr, eventTime * NS_PER_MS, pointerCoords, metaState);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002921 }
Romain Guycafdea62009-06-12 10:51:36 -07002922
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07002923 /**
Jeff Brown9d3bdbd2012-03-21 11:50:06 -07002924 * Adds all of the movement samples of the specified event to this one if
2925 * it is compatible. To be compatible, the event must have the same device id,
2926 * source, action, flags, pointer count, pointer properties.
2927 *
2928 * Only applies to {@link #ACTION_MOVE} or {@link #ACTION_HOVER_MOVE} events.
2929 *
2930 * @param event The event whose movements samples should be added to this one
2931 * if possible.
2932 * @return True if batching was performed or false if batching was not possible.
2933 * @hide
2934 */
2935 public final boolean addBatch(MotionEvent event) {
2936 final int action = nativeGetAction(mNativePtr);
2937 if (action != ACTION_MOVE && action != ACTION_HOVER_MOVE) {
2938 return false;
2939 }
2940 if (action != nativeGetAction(event.mNativePtr)) {
2941 return false;
2942 }
2943
2944 if (nativeGetDeviceId(mNativePtr) != nativeGetDeviceId(event.mNativePtr)
2945 || nativeGetSource(mNativePtr) != nativeGetSource(event.mNativePtr)
2946 || nativeGetFlags(mNativePtr) != nativeGetFlags(event.mNativePtr)) {
2947 return false;
2948 }
2949
2950 final int pointerCount = nativeGetPointerCount(mNativePtr);
2951 if (pointerCount != nativeGetPointerCount(event.mNativePtr)) {
2952 return false;
2953 }
2954
2955 synchronized (gSharedTempLock) {
2956 ensureSharedTempPointerCapacity(Math.max(pointerCount, 2));
2957 final PointerProperties[] pp = gSharedTempPointerProperties;
2958 final PointerCoords[] pc = gSharedTempPointerCoords;
2959
2960 for (int i = 0; i < pointerCount; i++) {
2961 nativeGetPointerProperties(mNativePtr, i, pp[0]);
2962 nativeGetPointerProperties(event.mNativePtr, i, pp[1]);
2963 if (!pp[0].equals(pp[1])) {
2964 return false;
2965 }
2966 }
2967
2968 final int metaState = nativeGetMetaState(event.mNativePtr);
2969 final int historySize = nativeGetHistorySize(event.mNativePtr);
2970 for (int h = 0; h <= historySize; h++) {
2971 final int historyPos = (h == historySize ? HISTORY_CURRENT : h);
2972
2973 for (int i = 0; i < pointerCount; i++) {
2974 nativeGetPointerCoords(event.mNativePtr, i, historyPos, pc[i]);
2975 }
2976
2977 final long eventTimeNanos = nativeGetEventTimeNanos(event.mNativePtr, historyPos);
2978 nativeAddBatch(mNativePtr, eventTimeNanos, pc, metaState);
2979 }
2980 }
2981 return true;
2982 }
2983
2984 /**
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07002985 * Returns true if all points in the motion event are completely within the specified bounds.
2986 * @hide
2987 */
2988 public final boolean isWithinBoundsNoHistory(float left, float top,
2989 float right, float bottom) {
2990 final int pointerCount = nativeGetPointerCount(mNativePtr);
2991 for (int i = 0; i < pointerCount; i++) {
2992 final float x = nativeGetAxisValue(mNativePtr, AXIS_X, i, HISTORY_CURRENT);
2993 final float y = nativeGetAxisValue(mNativePtr, AXIS_Y, i, HISTORY_CURRENT);
2994 if (x < left || x > right || y < top || y > bottom) {
2995 return false;
2996 }
2997 }
2998 return true;
2999 }
3000
3001 private static final float clamp(float value, float low, float high) {
3002 if (value < low) {
3003 return low;
3004 } else if (value > high) {
3005 return high;
3006 }
3007 return value;
3008 }
3009
3010 /**
3011 * Returns a new motion events whose points have been clamped to the specified bounds.
3012 * @hide
3013 */
3014 public final MotionEvent clampNoHistory(float left, float top, float right, float bottom) {
3015 MotionEvent ev = obtain();
3016 synchronized (gSharedTempLock) {
3017 final int pointerCount = nativeGetPointerCount(mNativePtr);
3018
3019 ensureSharedTempPointerCapacity(pointerCount);
3020 final PointerProperties[] pp = gSharedTempPointerProperties;
3021 final PointerCoords[] pc = gSharedTempPointerCoords;
3022
3023 for (int i = 0; i < pointerCount; i++) {
3024 nativeGetPointerProperties(mNativePtr, i, pp[i]);
3025 nativeGetPointerCoords(mNativePtr, i, HISTORY_CURRENT, pc[i]);
3026 pc[i].x = clamp(pc[i].x, left, right);
3027 pc[i].y = clamp(pc[i].y, top, bottom);
3028 }
3029 ev.mNativePtr = nativeInitialize(ev.mNativePtr,
3030 nativeGetDeviceId(mNativePtr), nativeGetSource(mNativePtr),
3031 nativeGetAction(mNativePtr), nativeGetFlags(mNativePtr),
3032 nativeGetEdgeFlags(mNativePtr), nativeGetMetaState(mNativePtr),
3033 nativeGetButtonState(mNativePtr),
3034 nativeGetXOffset(mNativePtr), nativeGetYOffset(mNativePtr),
3035 nativeGetXPrecision(mNativePtr), nativeGetYPrecision(mNativePtr),
3036 nativeGetDownTimeNanos(mNativePtr),
3037 nativeGetEventTimeNanos(mNativePtr, HISTORY_CURRENT),
3038 pointerCount, pp, pc);
3039 return ev;
3040 }
3041 }
3042
3043 /**
3044 * Gets an integer where each pointer id present in the event is marked as a bit.
3045 * @hide
3046 */
3047 public final int getPointerIdBits() {
3048 int idBits = 0;
3049 final int pointerCount = nativeGetPointerCount(mNativePtr);
3050 for (int i = 0; i < pointerCount; i++) {
3051 idBits |= 1 << nativeGetPointerId(mNativePtr, i);
3052 }
3053 return idBits;
3054 }
3055
3056 /**
3057 * Splits a motion event such that it includes only a subset of pointer ids.
3058 * @hide
3059 */
3060 public final MotionEvent split(int idBits) {
3061 MotionEvent ev = obtain();
3062 synchronized (gSharedTempLock) {
3063 final int oldPointerCount = nativeGetPointerCount(mNativePtr);
3064 ensureSharedTempPointerCapacity(oldPointerCount);
3065 final PointerProperties[] pp = gSharedTempPointerProperties;
3066 final PointerCoords[] pc = gSharedTempPointerCoords;
3067 final int[] map = gSharedTempPointerIndexMap;
3068
3069 final int oldAction = nativeGetAction(mNativePtr);
3070 final int oldActionMasked = oldAction & ACTION_MASK;
3071 final int oldActionPointerIndex = (oldAction & ACTION_POINTER_INDEX_MASK)
3072 >> ACTION_POINTER_INDEX_SHIFT;
3073 int newActionPointerIndex = -1;
3074 int newPointerCount = 0;
3075 int newIdBits = 0;
3076 for (int i = 0; i < oldPointerCount; i++) {
3077 nativeGetPointerProperties(mNativePtr, i, pp[newPointerCount]);
3078 final int idBit = 1 << pp[newPointerCount].id;
3079 if ((idBit & idBits) != 0) {
3080 if (i == oldActionPointerIndex) {
3081 newActionPointerIndex = newPointerCount;
3082 }
3083 map[newPointerCount] = i;
3084 newPointerCount += 1;
3085 newIdBits |= idBit;
3086 }
3087 }
3088
3089 if (newPointerCount == 0) {
3090 throw new IllegalArgumentException("idBits did not match any ids in the event");
3091 }
3092
3093 final int newAction;
3094 if (oldActionMasked == ACTION_POINTER_DOWN || oldActionMasked == ACTION_POINTER_UP) {
3095 if (newActionPointerIndex < 0) {
3096 // An unrelated pointer changed.
3097 newAction = ACTION_MOVE;
3098 } else if (newPointerCount == 1) {
3099 // The first/last pointer went down/up.
3100 newAction = oldActionMasked == ACTION_POINTER_DOWN
3101 ? ACTION_DOWN : ACTION_UP;
3102 } else {
3103 // A secondary pointer went down/up.
3104 newAction = oldActionMasked
3105 | (newActionPointerIndex << ACTION_POINTER_INDEX_SHIFT);
3106 }
3107 } else {
3108 // Simple up/down/cancel/move or other motion action.
3109 newAction = oldAction;
3110 }
3111
3112 final int historySize = nativeGetHistorySize(mNativePtr);
3113 for (int h = 0; h <= historySize; h++) {
3114 final int historyPos = h == historySize ? HISTORY_CURRENT : h;
3115
3116 for (int i = 0; i < newPointerCount; i++) {
3117 nativeGetPointerCoords(mNativePtr, map[i], historyPos, pc[i]);
3118 }
3119
3120 final long eventTimeNanos = nativeGetEventTimeNanos(mNativePtr, historyPos);
3121 if (h == 0) {
3122 ev.mNativePtr = nativeInitialize(ev.mNativePtr,
3123 nativeGetDeviceId(mNativePtr), nativeGetSource(mNativePtr),
3124 newAction, nativeGetFlags(mNativePtr),
3125 nativeGetEdgeFlags(mNativePtr), nativeGetMetaState(mNativePtr),
3126 nativeGetButtonState(mNativePtr),
3127 nativeGetXOffset(mNativePtr), nativeGetYOffset(mNativePtr),
3128 nativeGetXPrecision(mNativePtr), nativeGetYPrecision(mNativePtr),
3129 nativeGetDownTimeNanos(mNativePtr), eventTimeNanos,
3130 newPointerCount, pp, pc);
3131 } else {
3132 nativeAddBatch(ev.mNativePtr, eventTimeNanos, pc, 0);
3133 }
3134 }
3135 return ev;
3136 }
3137 }
3138
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003139 @Override
3140 public String toString() {
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003141 StringBuilder msg = new StringBuilder();
3142 msg.append("MotionEvent { action=").append(actionToString(getAction()));
Michael Wright5bd69e62015-05-14 14:48:08 +01003143 msg.append(", actionButton=").append(buttonStateToString(getActionButton()));
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003144
3145 final int pointerCount = getPointerCount();
3146 for (int i = 0; i < pointerCount; i++) {
3147 msg.append(", id[").append(i).append("]=").append(getPointerId(i));
3148 msg.append(", x[").append(i).append("]=").append(getX(i));
3149 msg.append(", y[").append(i).append("]=").append(getY(i));
3150 msg.append(", toolType[").append(i).append("]=").append(
3151 toolTypeToString(getToolType(i)));
3152 }
3153
Jeff Brown81346812011-06-28 20:08:48 -07003154 msg.append(", buttonState=").append(MotionEvent.buttonStateToString(getButtonState()));
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003155 msg.append(", metaState=").append(KeyEvent.metaStateToString(getMetaState()));
3156 msg.append(", flags=0x").append(Integer.toHexString(getFlags()));
3157 msg.append(", edgeFlags=0x").append(Integer.toHexString(getEdgeFlags()));
3158 msg.append(", pointerCount=").append(pointerCount);
3159 msg.append(", historySize=").append(getHistorySize());
3160 msg.append(", eventTime=").append(getEventTime());
3161 msg.append(", downTime=").append(getDownTime());
3162 msg.append(", deviceId=").append(getDeviceId());
3163 msg.append(", source=0x").append(Integer.toHexString(getSource()));
3164 msg.append(" }");
3165 return msg.toString();
Jeff Brown497a92c2010-09-12 17:55:08 -07003166 }
3167
3168 /**
John Spurlock4dad6ca2013-06-05 13:17:05 -04003169 * Returns a string that represents the symbolic name of the specified unmasked action
Jeff Brown91c69ab2011-02-14 17:03:18 -08003170 * such as "ACTION_DOWN", "ACTION_POINTER_DOWN(3)" or an equivalent numeric constant
3171 * such as "35" if unknown.
Jeff Brown497a92c2010-09-12 17:55:08 -07003172 *
John Spurlock4dad6ca2013-06-05 13:17:05 -04003173 * @param action The unmasked action.
Jeff Brown497a92c2010-09-12 17:55:08 -07003174 * @return The symbolic name of the specified action.
John Spurlock4dad6ca2013-06-05 13:17:05 -04003175 * @see #getAction()
Jeff Brown497a92c2010-09-12 17:55:08 -07003176 */
3177 public static String actionToString(int action) {
3178 switch (action) {
3179 case ACTION_DOWN:
3180 return "ACTION_DOWN";
3181 case ACTION_UP:
3182 return "ACTION_UP";
3183 case ACTION_CANCEL:
3184 return "ACTION_CANCEL";
Jeff Brown33bbfd22011-02-24 20:55:35 -08003185 case ACTION_OUTSIDE:
3186 return "ACTION_OUTSIDE";
Jeff Brown497a92c2010-09-12 17:55:08 -07003187 case ACTION_MOVE:
3188 return "ACTION_MOVE";
Jeff Browncc0c1592011-02-19 05:07:28 -08003189 case ACTION_HOVER_MOVE:
3190 return "ACTION_HOVER_MOVE";
Jeff Brown33bbfd22011-02-24 20:55:35 -08003191 case ACTION_SCROLL:
3192 return "ACTION_SCROLL";
Jeff Browna032cc02011-03-07 16:56:21 -08003193 case ACTION_HOVER_ENTER:
3194 return "ACTION_HOVER_ENTER";
3195 case ACTION_HOVER_EXIT:
3196 return "ACTION_HOVER_EXIT";
Michael Wright5bd69e62015-05-14 14:48:08 +01003197 case ACTION_BUTTON_PRESS:
3198 return "ACTION_BUTTON_PRESS";
3199 case ACTION_BUTTON_RELEASE:
3200 return "ACTION_BUTTON_RELEASE";
Jeff Brown497a92c2010-09-12 17:55:08 -07003201 }
3202 int index = (action & ACTION_POINTER_INDEX_MASK) >> ACTION_POINTER_INDEX_SHIFT;
3203 switch (action & ACTION_MASK) {
3204 case ACTION_POINTER_DOWN:
3205 return "ACTION_POINTER_DOWN(" + index + ")";
3206 case ACTION_POINTER_UP:
3207 return "ACTION_POINTER_UP(" + index + ")";
3208 default:
3209 return Integer.toString(action);
3210 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003211 }
3212
Jeff Brown91c69ab2011-02-14 17:03:18 -08003213 /**
3214 * Returns a string that represents the symbolic name of the specified axis
Jeff Brown6f2fba42011-02-19 01:08:02 -08003215 * such as "AXIS_X" or an equivalent numeric constant such as "42" if unknown.
Jeff Brown91c69ab2011-02-14 17:03:18 -08003216 *
John Spurlock4dad6ca2013-06-05 13:17:05 -04003217 * @param axis The axis.
Jeff Brown91c69ab2011-02-14 17:03:18 -08003218 * @return The symbolic name of the specified axis.
Jeff Brown91c69ab2011-02-14 17:03:18 -08003219 */
3220 public static String axisToString(int axis) {
Michael Wright337d9d22014-04-22 15:03:48 -07003221 String symbolicName = nativeAxisToString(axis);
3222 return symbolicName != null ? LABEL_PREFIX + symbolicName : Integer.toString(axis);
Jeff Brown6f2fba42011-02-19 01:08:02 -08003223 }
3224
3225 /**
Jeff Browncc0c1592011-02-19 05:07:28 -08003226 * Gets an axis by its symbolic name such as "AXIS_X" or an
3227 * equivalent numeric constant such as "42".
Jeff Brown6f2fba42011-02-19 01:08:02 -08003228 *
3229 * @param symbolicName The symbolic name of the axis.
3230 * @return The axis or -1 if not found.
John Spurlock4dad6ca2013-06-05 13:17:05 -04003231 * @see KeyEvent#keyCodeToString(int)
Jeff Brown6f2fba42011-02-19 01:08:02 -08003232 */
3233 public static int axisFromString(String symbolicName) {
Michael Wright337d9d22014-04-22 15:03:48 -07003234 if (symbolicName.startsWith(LABEL_PREFIX)) {
3235 symbolicName = symbolicName.substring(LABEL_PREFIX.length());
Michael Wright973efa02014-05-13 15:38:56 -07003236 int axis = nativeAxisFromString(symbolicName);
3237 if (axis >= 0) {
3238 return axis;
3239 }
Jeff Brown6f2fba42011-02-19 01:08:02 -08003240 }
Jeff Brown6f2fba42011-02-19 01:08:02 -08003241 try {
3242 return Integer.parseInt(symbolicName, 10);
3243 } catch (NumberFormatException ex) {
3244 return -1;
Jeff Brown91c69ab2011-02-14 17:03:18 -08003245 }
3246 }
3247
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003248 /**
3249 * Returns a string that represents the symbolic name of the specified combined
3250 * button state flags such as "0", "BUTTON_PRIMARY",
3251 * "BUTTON_PRIMARY|BUTTON_SECONDARY" or an equivalent numeric constant such as "0x10000000"
3252 * if unknown.
3253 *
3254 * @param buttonState The button state.
3255 * @return The symbolic name of the specified combined button state flags.
3256 * @hide
3257 */
3258 public static String buttonStateToString(int buttonState) {
3259 if (buttonState == 0) {
3260 return "0";
3261 }
3262 StringBuilder result = null;
3263 int i = 0;
3264 while (buttonState != 0) {
3265 final boolean isSet = (buttonState & 1) != 0;
3266 buttonState >>>= 1; // unsigned shift!
3267 if (isSet) {
3268 final String name = BUTTON_SYMBOLIC_NAMES[i];
3269 if (result == null) {
3270 if (buttonState == 0) {
3271 return name;
3272 }
3273 result = new StringBuilder(name);
3274 } else {
3275 result.append('|');
3276 result.append(name);
3277 }
3278 }
3279 i += 1;
3280 }
3281 return result.toString();
3282 }
3283
3284 /**
3285 * Returns a string that represents the symbolic name of the specified tool type
3286 * such as "TOOL_TYPE_FINGER" or an equivalent numeric constant such as "42" if unknown.
3287 *
3288 * @param toolType The tool type.
3289 * @return The symbolic name of the specified tool type.
3290 * @hide
3291 */
3292 public static String toolTypeToString(int toolType) {
3293 String symbolicName = TOOL_TYPE_SYMBOLIC_NAMES.get(toolType);
3294 return symbolicName != null ? symbolicName : Integer.toString(toolType);
3295 }
3296
Sujith Ramakrishnancc32bd82014-05-19 15:32:13 -07003297 /**
3298 * Checks if a mouse or stylus button (or combination of buttons) is pressed.
3299 * @param button Button (or combination of buttons).
3300 * @return True if specified buttons are pressed.
3301 *
3302 * @see #BUTTON_PRIMARY
3303 * @see #BUTTON_SECONDARY
3304 * @see #BUTTON_TERTIARY
3305 * @see #BUTTON_FORWARD
3306 * @see #BUTTON_BACK
Michael Wright5bd69e62015-05-14 14:48:08 +01003307 * @see #BUTTON_STYLUS_PRIMARY
3308 * @see #BUTTON_STYLUS_SECONDARY
Sujith Ramakrishnancc32bd82014-05-19 15:32:13 -07003309 */
3310 public final boolean isButtonPressed(int button) {
3311 if (button == 0) {
3312 return false;
3313 }
3314 return (getButtonState() & button) == button;
3315 }
3316
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003317 public static final Parcelable.Creator<MotionEvent> CREATOR
3318 = new Parcelable.Creator<MotionEvent>() {
3319 public MotionEvent createFromParcel(Parcel in) {
Jeff Brown6ec402b2010-07-28 15:48:59 -07003320 in.readInt(); // skip token, we already know this is a MotionEvent
3321 return MotionEvent.createFromParcelBody(in);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003322 }
3323
3324 public MotionEvent[] newArray(int size) {
3325 return new MotionEvent[size];
3326 }
3327 };
3328
Jeff Brown6ec402b2010-07-28 15:48:59 -07003329 /** @hide */
3330 public static MotionEvent createFromParcelBody(Parcel in) {
Jeff Brown91c69ab2011-02-14 17:03:18 -08003331 MotionEvent ev = obtain();
3332 ev.mNativePtr = nativeReadFromParcel(ev.mNativePtr, in);
Jeff Brown6ec402b2010-07-28 15:48:59 -07003333 return ev;
3334 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08003335
Wale Ogunwalec3672cd2014-11-05 15:17:35 -08003336 /** @hide */
3337 @Override
3338 public final void cancel() {
3339 setAction(ACTION_CANCEL);
3340 }
3341
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003342 public void writeToParcel(Parcel out, int flags) {
Jeff Brown6ec402b2010-07-28 15:48:59 -07003343 out.writeInt(PARCEL_TOKEN_MOTION_EVENT);
Jeff Brown91c69ab2011-02-14 17:03:18 -08003344 nativeWriteToParcel(mNativePtr, out);
Jeff Brown5c225b12010-06-16 01:53:36 -07003345 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08003346
Jeff Brownc5ed5912010-07-14 18:48:53 -07003347 /**
3348 * Transfer object for pointer coordinates.
3349 *
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003350 * Objects of this type can be used to specify the pointer coordinates when
3351 * creating new {@link MotionEvent} objects and to query pointer coordinates
3352 * in bulk.
Jeff Brownc5ed5912010-07-14 18:48:53 -07003353 *
3354 * Refer to {@link InputDevice} for information about how different kinds of
3355 * input devices and sources represent pointer coordinates.
3356 */
3357 public static final class PointerCoords {
Jeff Brown91c69ab2011-02-14 17:03:18 -08003358 private static final int INITIAL_PACKED_AXIS_VALUES = 8;
Jeff Brown6f2fba42011-02-19 01:08:02 -08003359 private long mPackedAxisBits;
Jeff Brown91c69ab2011-02-14 17:03:18 -08003360 private float[] mPackedAxisValues;
3361
3362 /**
3363 * Creates a pointer coords object with all axes initialized to zero.
3364 */
3365 public PointerCoords() {
3366 }
3367
3368 /**
3369 * Creates a pointer coords object as a copy of the
3370 * contents of another pointer coords object.
3371 *
3372 * @param other The pointer coords object to copy.
3373 */
3374 public PointerCoords(PointerCoords other) {
3375 copyFrom(other);
3376 }
3377
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003378 /** @hide */
3379 public static PointerCoords[] createArray(int size) {
3380 PointerCoords[] array = new PointerCoords[size];
3381 for (int i = 0; i < size; i++) {
3382 array[i] = new PointerCoords();
3383 }
3384 return array;
3385 }
3386
Jeff Brownc5ed5912010-07-14 18:48:53 -07003387 /**
Jeff Brown6f2fba42011-02-19 01:08:02 -08003388 * The X component of the pointer movement.
Jeff Brown91c69ab2011-02-14 17:03:18 -08003389 *
3390 * @see MotionEvent#AXIS_X
Jeff Brownc5ed5912010-07-14 18:48:53 -07003391 */
3392 public float x;
3393
3394 /**
Jeff Brown6f2fba42011-02-19 01:08:02 -08003395 * The Y component of the pointer movement.
Jeff Brown91c69ab2011-02-14 17:03:18 -08003396 *
3397 * @see MotionEvent#AXIS_Y
Jeff Brownc5ed5912010-07-14 18:48:53 -07003398 */
3399 public float y;
3400
3401 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08003402 * A normalized value that describes the pressure applied to the device
3403 * by a finger or other tool.
Jeff Brownc5ed5912010-07-14 18:48:53 -07003404 * The pressure generally ranges from 0 (no pressure at all) to 1 (normal pressure),
Jeff Brown91c69ab2011-02-14 17:03:18 -08003405 * although values higher than 1 may be generated depending on the calibration of
Jeff Brownc5ed5912010-07-14 18:48:53 -07003406 * the input device.
Jeff Brown91c69ab2011-02-14 17:03:18 -08003407 *
3408 * @see MotionEvent#AXIS_PRESSURE
Jeff Brownc5ed5912010-07-14 18:48:53 -07003409 */
3410 public float pressure;
3411
3412 /**
Jeff Brown91c69ab2011-02-14 17:03:18 -08003413 * A normalized value that describes the approximate size of the pointer touch area
3414 * in relation to the maximum detectable size of the device.
3415 * It represents some approximation of the area of the screen being
Jeff Brownc5ed5912010-07-14 18:48:53 -07003416 * pressed; the actual value in pixels corresponding to the
3417 * touch is normalized with the device specific range of values
3418 * and scaled to a value between 0 and 1. The value of size can be used to
3419 * determine fat touch events.
Jeff Brown91c69ab2011-02-14 17:03:18 -08003420 *
3421 * @see MotionEvent#AXIS_SIZE
Jeff Brownc5ed5912010-07-14 18:48:53 -07003422 */
3423 public float size;
3424
3425 /**
3426 * The length of the major axis of an ellipse that describes the touch area at
3427 * the point of contact.
Jeff Brown91c69ab2011-02-14 17:03:18 -08003428 * If the device is a touch screen, the length is reported in pixels, otherwise it is
3429 * reported in device-specific units.
3430 *
3431 * @see MotionEvent#AXIS_TOUCH_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07003432 */
3433 public float touchMajor;
3434
3435 /**
3436 * The length of the minor axis of an ellipse that describes the touch area at
3437 * the point of contact.
Jeff Brown91c69ab2011-02-14 17:03:18 -08003438 * If the device is a touch screen, the length is reported in pixels, otherwise it is
3439 * reported in device-specific units.
3440 *
3441 * @see MotionEvent#AXIS_TOUCH_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07003442 */
3443 public float touchMinor;
3444
3445 /**
3446 * The length of the major axis of an ellipse that describes the size of
3447 * the approaching tool.
3448 * The tool area represents the estimated size of the finger or pen that is
3449 * touching the device independent of its actual touch area at the point of contact.
Jeff Brown91c69ab2011-02-14 17:03:18 -08003450 * If the device is a touch screen, the length is reported in pixels, otherwise it is
3451 * reported in device-specific units.
3452 *
3453 * @see MotionEvent#AXIS_TOOL_MAJOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07003454 */
3455 public float toolMajor;
3456
3457 /**
3458 * The length of the minor axis of an ellipse that describes the size of
3459 * the approaching tool.
3460 * The tool area represents the estimated size of the finger or pen that is
3461 * touching the device independent of its actual touch area at the point of contact.
Jeff Brown91c69ab2011-02-14 17:03:18 -08003462 * If the device is a touch screen, the length is reported in pixels, otherwise it is
3463 * reported in device-specific units.
3464 *
3465 * @see MotionEvent#AXIS_TOOL_MINOR
Jeff Brownc5ed5912010-07-14 18:48:53 -07003466 */
3467 public float toolMinor;
3468
3469 /**
3470 * The orientation of the touch area and tool area in radians clockwise from vertical.
Jeff Brown6f2fba42011-02-19 01:08:02 -08003471 * An angle of 0 radians indicates that the major axis of contact is oriented
Jeff Brownc5ed5912010-07-14 18:48:53 -07003472 * upwards, is perfectly circular or is of unknown orientation. A positive angle
3473 * indicates that the major axis of contact is oriented to the right. A negative angle
3474 * indicates that the major axis of contact is oriented to the left.
Jeff Brown6d0fec22010-07-23 21:28:06 -07003475 * The full range is from -PI/2 radians (finger pointing fully left) to PI/2 radians
Jeff Brownc5ed5912010-07-14 18:48:53 -07003476 * (finger pointing fully right).
Jeff Brown91c69ab2011-02-14 17:03:18 -08003477 *
3478 * @see MotionEvent#AXIS_ORIENTATION
Jeff Brownc5ed5912010-07-14 18:48:53 -07003479 */
3480 public float orientation;
Jeff Brown91c69ab2011-02-14 17:03:18 -08003481
3482 /**
3483 * Clears the contents of this object.
3484 * Resets all axes to zero.
3485 */
3486 public void clear() {
3487 mPackedAxisBits = 0;
3488
3489 x = 0;
3490 y = 0;
3491 pressure = 0;
3492 size = 0;
3493 touchMajor = 0;
3494 touchMinor = 0;
3495 toolMajor = 0;
3496 toolMinor = 0;
3497 orientation = 0;
Jeff Brownc5ed5912010-07-14 18:48:53 -07003498 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08003499
3500 /**
3501 * Copies the contents of another pointer coords object.
3502 *
3503 * @param other The pointer coords object to copy.
3504 */
3505 public void copyFrom(PointerCoords other) {
Jeff Brown6f2fba42011-02-19 01:08:02 -08003506 final long bits = other.mPackedAxisBits;
Jeff Brown91c69ab2011-02-14 17:03:18 -08003507 mPackedAxisBits = bits;
3508 if (bits != 0) {
3509 final float[] otherValues = other.mPackedAxisValues;
Jeff Brown6f2fba42011-02-19 01:08:02 -08003510 final int count = Long.bitCount(bits);
Jeff Brown91c69ab2011-02-14 17:03:18 -08003511 float[] values = mPackedAxisValues;
3512 if (values == null || count > values.length) {
3513 values = new float[otherValues.length];
3514 mPackedAxisValues = values;
3515 }
3516 System.arraycopy(otherValues, 0, values, 0, count);
3517 }
3518
3519 x = other.x;
3520 y = other.y;
3521 pressure = other.pressure;
3522 size = other.size;
3523 touchMajor = other.touchMajor;
3524 touchMinor = other.touchMinor;
3525 toolMajor = other.toolMajor;
3526 toolMinor = other.toolMinor;
3527 orientation = other.orientation;
Jeff Brownc5ed5912010-07-14 18:48:53 -07003528 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08003529
3530 /**
3531 * Gets the value associated with the specified axis.
3532 *
3533 * @param axis The axis identifier for the axis value to retrieve.
3534 * @return The value associated with the axis, or 0 if none.
3535 *
3536 * @see MotionEvent#AXIS_X
3537 * @see MotionEvent#AXIS_Y
3538 */
3539 public float getAxisValue(int axis) {
3540 switch (axis) {
3541 case AXIS_X:
3542 return x;
3543 case AXIS_Y:
3544 return y;
3545 case AXIS_PRESSURE:
3546 return pressure;
3547 case AXIS_SIZE:
3548 return size;
3549 case AXIS_TOUCH_MAJOR:
3550 return touchMajor;
3551 case AXIS_TOUCH_MINOR:
3552 return touchMinor;
3553 case AXIS_TOOL_MAJOR:
3554 return toolMajor;
3555 case AXIS_TOOL_MINOR:
3556 return toolMinor;
3557 case AXIS_ORIENTATION:
3558 return orientation;
3559 default: {
Jeff Brown6f2fba42011-02-19 01:08:02 -08003560 if (axis < 0 || axis > 63) {
3561 throw new IllegalArgumentException("Axis out of range.");
3562 }
3563 final long bits = mPackedAxisBits;
Michael Wright9adca062014-03-19 11:51:26 -07003564 final long axisBit = 0x8000000000000000L >>> axis;
Jeff Brown91c69ab2011-02-14 17:03:18 -08003565 if ((bits & axisBit) == 0) {
3566 return 0;
3567 }
Michael Wright9adca062014-03-19 11:51:26 -07003568 final int index = Long.bitCount(bits & ~(0xFFFFFFFFFFFFFFFFL >>> axis));
Jeff Brown91c69ab2011-02-14 17:03:18 -08003569 return mPackedAxisValues[index];
3570 }
3571 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07003572 }
Jeff Brown91c69ab2011-02-14 17:03:18 -08003573
3574 /**
3575 * Sets the value associated with the specified axis.
3576 *
3577 * @param axis The axis identifier for the axis value to assign.
3578 * @param value The value to set.
3579 *
3580 * @see MotionEvent#AXIS_X
3581 * @see MotionEvent#AXIS_Y
3582 */
3583 public void setAxisValue(int axis, float value) {
3584 switch (axis) {
3585 case AXIS_X:
3586 x = value;
3587 break;
3588 case AXIS_Y:
3589 y = value;
3590 break;
3591 case AXIS_PRESSURE:
3592 pressure = value;
3593 break;
3594 case AXIS_SIZE:
3595 size = value;
3596 break;
3597 case AXIS_TOUCH_MAJOR:
3598 touchMajor = value;
3599 break;
3600 case AXIS_TOUCH_MINOR:
3601 touchMinor = value;
3602 break;
3603 case AXIS_TOOL_MAJOR:
3604 toolMajor = value;
3605 break;
3606 case AXIS_TOOL_MINOR:
3607 toolMinor = value;
3608 break;
3609 case AXIS_ORIENTATION:
3610 orientation = value;
3611 break;
3612 default: {
Jeff Brown6f2fba42011-02-19 01:08:02 -08003613 if (axis < 0 || axis > 63) {
3614 throw new IllegalArgumentException("Axis out of range.");
3615 }
3616 final long bits = mPackedAxisBits;
Michael Wright9adca062014-03-19 11:51:26 -07003617 final long axisBit = 0x8000000000000000L >>> axis;
3618 final int index = Long.bitCount(bits & ~(0xFFFFFFFFFFFFFFFFL >>> axis));
Jeff Brown91c69ab2011-02-14 17:03:18 -08003619 float[] values = mPackedAxisValues;
3620 if ((bits & axisBit) == 0) {
3621 if (values == null) {
3622 values = new float[INITIAL_PACKED_AXIS_VALUES];
3623 mPackedAxisValues = values;
3624 } else {
Jeff Brown6f2fba42011-02-19 01:08:02 -08003625 final int count = Long.bitCount(bits);
Jeff Brown91c69ab2011-02-14 17:03:18 -08003626 if (count < values.length) {
3627 if (index != count) {
3628 System.arraycopy(values, index, values, index + 1,
3629 count - index);
3630 }
3631 } else {
3632 float[] newValues = new float[count * 2];
3633 System.arraycopy(values, 0, newValues, 0, index);
3634 System.arraycopy(values, index, newValues, index + 1,
3635 count - index);
3636 values = newValues;
3637 mPackedAxisValues = values;
3638 }
3639 }
3640 mPackedAxisBits = bits | axisBit;
3641 }
3642 values[index] = value;
3643 }
3644 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07003645 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07003646 }
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003647
3648 /**
3649 * Transfer object for pointer properties.
3650 *
3651 * Objects of this type can be used to specify the pointer id and tool type
3652 * when creating new {@link MotionEvent} objects and to query pointer properties in bulk.
3653 */
3654 public static final class PointerProperties {
3655 /**
3656 * Creates a pointer properties object with an invalid pointer id.
3657 */
3658 public PointerProperties() {
3659 clear();
3660 }
3661
3662 /**
3663 * Creates a pointer properties object as a copy of the contents of
3664 * another pointer properties object.
3665 * @param other
3666 */
3667 public PointerProperties(PointerProperties other) {
3668 copyFrom(other);
3669 }
3670
3671 /** @hide */
3672 public static PointerProperties[] createArray(int size) {
3673 PointerProperties[] array = new PointerProperties[size];
3674 for (int i = 0; i < size; i++) {
3675 array[i] = new PointerProperties();
3676 }
3677 return array;
3678 }
3679
3680 /**
3681 * The pointer id.
3682 * Initially set to {@link #INVALID_POINTER_ID} (-1).
3683 *
3684 * @see MotionEvent#getPointerId(int)
3685 */
3686 public int id;
3687
3688 /**
3689 * The pointer tool type.
3690 * Initially set to 0.
3691 *
3692 * @see MotionEvent#getToolType(int)
3693 */
3694 public int toolType;
3695
3696 /**
3697 * Resets the pointer properties to their initial values.
3698 */
3699 public void clear() {
3700 id = INVALID_POINTER_ID;
3701 toolType = TOOL_TYPE_UNKNOWN;
3702 }
3703
3704 /**
3705 * Copies the contents of another pointer properties object.
3706 *
3707 * @param other The pointer properties object to copy.
3708 */
3709 public void copyFrom(PointerProperties other) {
3710 id = other.id;
3711 toolType = other.toolType;
3712 }
Jeff Brown9d3bdbd2012-03-21 11:50:06 -07003713
3714 @Override
3715 public boolean equals(Object other) {
3716 if (other instanceof PointerProperties) {
3717 return equals((PointerProperties)other);
3718 }
3719 return false;
3720 }
3721
3722 private boolean equals(PointerProperties other) {
3723 return other != null && id == other.id && toolType == other.toolType;
3724 }
3725
3726 @Override
3727 public int hashCode() {
3728 return id | (toolType << 8);
3729 }
Jeff Brownfe9f8ab2011-05-06 18:20:01 -07003730 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08003731}