blob: 47061c1710e93653968ff13e5c3994432a4da465 [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
19import android.os.Parcel;
20import android.os.Parcelable;
21import android.os.SystemClock;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080022
23/**
24 * Object used to report movement (mouse, pen, finger, trackball) events. This
25 * class may hold either absolute or relative movements, depending on what
26 * it is being used for.
Jeff Brownc5ed5912010-07-14 18:48:53 -070027 *
28 * Refer to {@link InputDevice} for information about how different kinds of
29 * input devices and sources represent pointer coordinates.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030 */
Jeff Brownc5ed5912010-07-14 18:48:53 -070031public final class MotionEvent extends InputEvent implements Parcelable {
Jeff Brown5c225b12010-06-16 01:53:36 -070032 private static final long MS_PER_NS = 1000000;
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -070033
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080034 /**
Dianne Hackborn9822d2b2009-07-20 17:33:15 -070035 * Bit mask of the parts of the action code that are the action itself.
36 */
37 public static final int ACTION_MASK = 0xff;
38
39 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040 * Constant for {@link #getAction}: A pressed gesture has started, the
41 * motion contains the initial starting location.
42 */
43 public static final int ACTION_DOWN = 0;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -070044
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080045 /**
46 * Constant for {@link #getAction}: A pressed gesture has finished, the
47 * motion contains the final release location as well as any intermediate
48 * points since the last down or move event.
49 */
50 public static final int ACTION_UP = 1;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -070051
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080052 /**
53 * Constant for {@link #getAction}: A change has happened during a
54 * press gesture (between {@link #ACTION_DOWN} and {@link #ACTION_UP}).
55 * The motion contains the most recent point, as well as any intermediate
56 * points since the last down or move event.
57 */
58 public static final int ACTION_MOVE = 2;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -070059
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060 /**
61 * Constant for {@link #getAction}: The current gesture has been aborted.
62 * You will not receive any more points in it. You should treat this as
63 * an up event, but not perform any action that you normally would.
64 */
65 public static final int ACTION_CANCEL = 3;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -070066
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067 /**
68 * Constant for {@link #getAction}: A movement has happened outside of the
69 * normal bounds of the UI element. This does not provide a full gesture,
70 * but only the initial location of the movement/touch.
71 */
72 public static final int ACTION_OUTSIDE = 4;
73
Dianne Hackborn9822d2b2009-07-20 17:33:15 -070074 /**
75 * A non-primary pointer has gone down. The bits in
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -070076 * {@link #ACTION_POINTER_ID_MASK} indicate which pointer changed.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -070077 */
78 public static final int ACTION_POINTER_DOWN = 5;
79
80 /**
Dianne Hackborn9822d2b2009-07-20 17:33:15 -070081 * A non-primary pointer has gone up. The bits in
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -070082 * {@link #ACTION_POINTER_ID_MASK} indicate which pointer changed.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -070083 */
84 public static final int ACTION_POINTER_UP = 6;
85
86 /**
Dianne Hackbornb125dc52010-02-12 15:52:09 -080087 * Bits in the action code that represent a pointer index, used with
88 * {@link #ACTION_POINTER_DOWN} and {@link #ACTION_POINTER_UP}. Shifting
89 * down by {@link #ACTION_POINTER_INDEX_SHIFT} provides the actual pointer
90 * index where the data for the pointer going up or down can be found; you can
91 * get its identifier with {@link #getPointerId(int)} and the actual
92 * data with {@link #getX(int)} etc.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -070093 */
Dianne Hackbornb125dc52010-02-12 15:52:09 -080094 public static final int ACTION_POINTER_INDEX_MASK = 0xff00;
95
96 /**
97 * Bit shift for the action bits holding the pointer index as
98 * defined by {@link #ACTION_POINTER_INDEX_MASK}.
99 */
100 public static final int ACTION_POINTER_INDEX_SHIFT = 8;
101
102 /**
103 * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the
104 * data index associated with {@link #ACTION_POINTER_DOWN}.
105 */
106 @Deprecated
107 public static final int ACTION_POINTER_1_DOWN = ACTION_POINTER_DOWN | 0x0000;
108
109 /**
110 * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the
111 * data index associated with {@link #ACTION_POINTER_DOWN}.
112 */
113 @Deprecated
114 public static final int ACTION_POINTER_2_DOWN = ACTION_POINTER_DOWN | 0x0100;
115
116 /**
117 * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the
118 * data index associated with {@link #ACTION_POINTER_DOWN}.
119 */
120 @Deprecated
121 public static final int ACTION_POINTER_3_DOWN = ACTION_POINTER_DOWN | 0x0200;
122
123 /**
124 * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the
125 * data index associated with {@link #ACTION_POINTER_UP}.
126 */
127 @Deprecated
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700128 public static final int ACTION_POINTER_1_UP = ACTION_POINTER_UP | 0x0000;
129
130 /**
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800131 * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the
132 * data index associated with {@link #ACTION_POINTER_UP}.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700133 */
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800134 @Deprecated
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700135 public static final int ACTION_POINTER_2_UP = ACTION_POINTER_UP | 0x0100;
136
137 /**
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800138 * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the
139 * data index associated with {@link #ACTION_POINTER_UP}.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700140 */
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800141 @Deprecated
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700142 public static final int ACTION_POINTER_3_UP = ACTION_POINTER_UP | 0x0200;
143
144 /**
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800145 * @deprecated Renamed to {@link #ACTION_POINTER_INDEX_MASK} to match
146 * the actual data contained in these bits.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700147 */
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800148 @Deprecated
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700149 public static final int ACTION_POINTER_ID_MASK = 0xff00;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700150
151 /**
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800152 * @deprecated Renamed to {@link #ACTION_POINTER_INDEX_SHIFT} to match
153 * the actual data contained in these bits.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700154 */
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800155 @Deprecated
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700156 public static final int ACTION_POINTER_ID_SHIFT = 8;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700157
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800158 private static final boolean TRACK_RECYCLED_LOCATION = false;
Romain Guycafdea62009-06-12 10:51:36 -0700159
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800160 /**
161 * Flag indicating the motion event intersected the top edge of the screen.
162 */
163 public static final int EDGE_TOP = 0x00000001;
Romain Guycafdea62009-06-12 10:51:36 -0700164
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800165 /**
166 * Flag indicating the motion event intersected the bottom edge of the screen.
167 */
168 public static final int EDGE_BOTTOM = 0x00000002;
Romain Guycafdea62009-06-12 10:51:36 -0700169
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800170 /**
171 * Flag indicating the motion event intersected the left edge of the screen.
172 */
173 public static final int EDGE_LEFT = 0x00000004;
Romain Guycafdea62009-06-12 10:51:36 -0700174
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800175 /**
176 * Flag indicating the motion event intersected the right edge of the screen.
177 */
178 public static final int EDGE_RIGHT = 0x00000008;
Romain Guycafdea62009-06-12 10:51:36 -0700179
Jeff Brown9e2ad362010-07-30 19:20:11 -0700180 /*
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700181 * Offset for the sample's X coordinate.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700182 */
Jeff Brown6d0fec22010-07-23 21:28:06 -0700183 static private final int SAMPLE_X = 0;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700184
Jeff Brown9e2ad362010-07-30 19:20:11 -0700185 /*
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700186 * Offset for the sample's Y coordinate.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700187 */
Jeff Brown6d0fec22010-07-23 21:28:06 -0700188 static private final int SAMPLE_Y = 1;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700189
Jeff Brown9e2ad362010-07-30 19:20:11 -0700190 /*
Jeff Brownc5ed5912010-07-14 18:48:53 -0700191 * Offset for the sample's pressure.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700192 */
Jeff Brown6d0fec22010-07-23 21:28:06 -0700193 static private final int SAMPLE_PRESSURE = 2;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700194
Jeff Brown9e2ad362010-07-30 19:20:11 -0700195 /*
Jeff Brownc5ed5912010-07-14 18:48:53 -0700196 * Offset for the sample's size
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700197 */
Jeff Brown6d0fec22010-07-23 21:28:06 -0700198 static private final int SAMPLE_SIZE = 3;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700199
Jeff Brown9e2ad362010-07-30 19:20:11 -0700200 /*
Jeff Brownc5ed5912010-07-14 18:48:53 -0700201 * Offset for the sample's touch major axis length.
Jeff Brownc5ed5912010-07-14 18:48:53 -0700202 */
Jeff Brown6d0fec22010-07-23 21:28:06 -0700203 static private final int SAMPLE_TOUCH_MAJOR = 4;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700204
Jeff Brown9e2ad362010-07-30 19:20:11 -0700205 /*
Jeff Brownc5ed5912010-07-14 18:48:53 -0700206 * Offset for the sample's touch minor axis length.
Jeff Brownc5ed5912010-07-14 18:48:53 -0700207 */
Jeff Brown6d0fec22010-07-23 21:28:06 -0700208 static private final int SAMPLE_TOUCH_MINOR = 5;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700209
Jeff Brown9e2ad362010-07-30 19:20:11 -0700210 /*
Jeff Brownc5ed5912010-07-14 18:48:53 -0700211 * Offset for the sample's tool major axis length.
Jeff Brownc5ed5912010-07-14 18:48:53 -0700212 */
Jeff Brown6d0fec22010-07-23 21:28:06 -0700213 static private final int SAMPLE_TOOL_MAJOR = 6;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700214
Jeff Brown9e2ad362010-07-30 19:20:11 -0700215 /*
Jeff Brownc5ed5912010-07-14 18:48:53 -0700216 * Offset for the sample's tool minor axis length.
Jeff Brownc5ed5912010-07-14 18:48:53 -0700217 */
Jeff Brown6d0fec22010-07-23 21:28:06 -0700218 static private final int SAMPLE_TOOL_MINOR = 7;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700219
Jeff Brown9e2ad362010-07-30 19:20:11 -0700220 /*
Jeff Brownc5ed5912010-07-14 18:48:53 -0700221 * Offset for the sample's orientation.
Jeff Brownc5ed5912010-07-14 18:48:53 -0700222 */
Jeff Brown6d0fec22010-07-23 21:28:06 -0700223 static private final int SAMPLE_ORIENTATION = 8;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700224
Jeff Brown9e2ad362010-07-30 19:20:11 -0700225 /*
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700226 * Number of data items for each sample.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700227 */
Jeff Brown6d0fec22010-07-23 21:28:06 -0700228 static private final int NUM_SAMPLE_DATA = 9;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700229
Jeff Brown9e2ad362010-07-30 19:20:11 -0700230 /*
231 * Minimum number of pointers for which to reserve space when allocating new
232 * motion events. This is explicitly not a bound on the maximum number of pointers.
Dianne Hackborn1e8dfc72009-08-06 12:43:01 -0700233 */
Jeff Brown9e2ad362010-07-30 19:20:11 -0700234 static private final int BASE_AVAIL_POINTERS = 5;
Dianne Hackborn1e8dfc72009-08-06 12:43:01 -0700235
Jeff Brown9e2ad362010-07-30 19:20:11 -0700236 /*
237 * Minimum number of samples for which to reserve space when allocating new motion events.
238 */
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700239 static private final int BASE_AVAIL_SAMPLES = 8;
240
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800241 static private final int MAX_RECYCLED = 10;
242 static private Object gRecyclerLock = new Object();
243 static private int gRecyclerUsed = 0;
244 static private MotionEvent gRecyclerTop = null;
Romain Guycafdea62009-06-12 10:51:36 -0700245
Jeff Brown5c225b12010-06-16 01:53:36 -0700246 private long mDownTimeNano;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800247 private int mAction;
Jeff Brown5c225b12010-06-16 01:53:36 -0700248 private float mXOffset;
249 private float mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800250 private float mXPrecision;
251 private float mYPrecision;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800252 private int mEdgeFlags;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700253 private int mMetaState;
254
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700255 private int mNumPointers;
256 private int mNumSamples;
Jeff Brown5c225b12010-06-16 01:53:36 -0700257
258 private int mLastDataSampleIndex;
259 private int mLastEventTimeNanoSampleIndex;
260
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700261 // Array of mNumPointers size of identifiers for each pointer of data.
262 private int[] mPointerIdentifiers;
Jeff Brown5c225b12010-06-16 01:53:36 -0700263
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700264 // Array of (mNumSamples * mNumPointers * NUM_SAMPLE_DATA) size of event data.
Jeff Brown5c225b12010-06-16 01:53:36 -0700265 // Samples are ordered from oldest to newest.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700266 private float[] mDataSamples;
Jeff Brown5c225b12010-06-16 01:53:36 -0700267
268 // Array of mNumSamples size of event time stamps in nanoseconds.
269 // Samples are ordered from oldest to newest.
270 private long[] mEventTimeNanoSamples;
Mitsuru Oshima8169dae2009-04-28 18:12:09 -0700271
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800272 private MotionEvent mNext;
273 private RuntimeException mRecycledLocation;
274 private boolean mRecycled;
275
Jeff Brown46b9ac02010-04-22 18:58:52 -0700276 private MotionEvent(int pointerCount, int sampleCount) {
277 mPointerIdentifiers = new int[pointerCount];
278 mDataSamples = new float[pointerCount * sampleCount * NUM_SAMPLE_DATA];
Jeff Brown5c225b12010-06-16 01:53:36 -0700279 mEventTimeNanoSamples = new long[sampleCount];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800280 }
Romain Guycafdea62009-06-12 10:51:36 -0700281
Jeff Brown46b9ac02010-04-22 18:58:52 -0700282 static private MotionEvent obtain(int pointerCount, int sampleCount) {
283 final MotionEvent ev;
284 synchronized (gRecyclerLock) {
285 if (gRecyclerTop == null) {
286 if (pointerCount < BASE_AVAIL_POINTERS) {
287 pointerCount = BASE_AVAIL_POINTERS;
288 }
289 if (sampleCount < BASE_AVAIL_SAMPLES) {
290 sampleCount = BASE_AVAIL_SAMPLES;
291 }
292 return new MotionEvent(pointerCount, sampleCount);
293 }
294 ev = gRecyclerTop;
295 gRecyclerTop = ev.mNext;
Jeff Brown5c225b12010-06-16 01:53:36 -0700296 gRecyclerUsed -= 1;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700297 }
298 ev.mRecycledLocation = null;
299 ev.mRecycled = false;
300 ev.mNext = null;
301
302 if (ev.mPointerIdentifiers.length < pointerCount) {
303 ev.mPointerIdentifiers = new int[pointerCount];
304 }
305
Jeff Brown5c225b12010-06-16 01:53:36 -0700306 if (ev.mEventTimeNanoSamples.length < sampleCount) {
307 ev.mEventTimeNanoSamples = new long[sampleCount];
Jeff Brown46b9ac02010-04-22 18:58:52 -0700308 }
309
Jeff Brown46b9ac02010-04-22 18:58:52 -0700310 final int neededDataSamplesLength = pointerCount * sampleCount * NUM_SAMPLE_DATA;
Jeff Brown5c225b12010-06-16 01:53:36 -0700311 if (ev.mDataSamples.length < neededDataSamplesLength) {
Jeff Brown46b9ac02010-04-22 18:58:52 -0700312 ev.mDataSamples = new float[neededDataSamplesLength];
313 }
314
315 return ev;
316 }
Jeff Brown5c225b12010-06-16 01:53:36 -0700317
Michael Chan53071d62009-05-13 17:29:48 -0700318 /**
319 * Create a new MotionEvent, filling in all of the basic values that
320 * define the motion.
321 *
322 * @param downTime The time (in ms) when the user originally pressed down to start
323 * a stream of position events. This must be obtained from {@link SystemClock#uptimeMillis()}.
Jeff Brownc5ed5912010-07-14 18:48:53 -0700324 * @param eventTime The the time (in ms) when this specific event was generated. This
Michael Chan53071d62009-05-13 17:29:48 -0700325 * must be obtained from {@link SystemClock#uptimeMillis()}.
Michael Chan53071d62009-05-13 17:29:48 -0700326 * @param action The kind of action being performed -- one of either
327 * {@link #ACTION_DOWN}, {@link #ACTION_MOVE}, {@link #ACTION_UP}, or
328 * {@link #ACTION_CANCEL}.
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700329 * @param pointers The number of points that will be in this event.
Jeff Brownc5ed5912010-07-14 18:48:53 -0700330 * @param pointerIds An array of <em>pointers</em> values providing
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700331 * an identifier for each pointer.
Jeff Brownc5ed5912010-07-14 18:48:53 -0700332 * @param pointerCoords An array of <em>pointers</em> values providing
333 * a {@link PointerCoords} coordinate object for each pointer.
Michael Chan53071d62009-05-13 17:29:48 -0700334 * @param metaState The state of any meta / modifier keys that were in effect when
335 * the event was generated.
336 * @param xPrecision The precision of the X coordinate being reported.
337 * @param yPrecision The precision of the Y coordinate being reported.
338 * @param deviceId The id for the device that this event came from. An id of
339 * zero indicates that the event didn't come from a physical device; other
340 * numbers are arbitrary and you shouldn't depend on the values.
341 * @param edgeFlags A bitfield indicating which edges, if any, where touched by this
342 * MotionEvent.
Jeff Brownc5ed5912010-07-14 18:48:53 -0700343 * @param source The source of this event.
Michael Chan53071d62009-05-13 17:29:48 -0700344 */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700345 static public MotionEvent obtain(long downTime, long eventTime,
346 int action, int pointers, int[] pointerIds, PointerCoords[] pointerCoords,
347 int metaState, float xPrecision, float yPrecision, int deviceId,
348 int edgeFlags, int source) {
Jeff Brown5c225b12010-06-16 01:53:36 -0700349 MotionEvent ev = obtain(pointers, 1);
Michael Chan53071d62009-05-13 17:29:48 -0700350 ev.mDeviceId = deviceId;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700351 ev.mSource = source;
Michael Chan53071d62009-05-13 17:29:48 -0700352 ev.mEdgeFlags = edgeFlags;
Jeff Brown5c225b12010-06-16 01:53:36 -0700353 ev.mDownTimeNano = downTime * MS_PER_NS;
Michael Chan53071d62009-05-13 17:29:48 -0700354 ev.mAction = action;
Michael Chan53071d62009-05-13 17:29:48 -0700355 ev.mMetaState = metaState;
Jeff Brown5c225b12010-06-16 01:53:36 -0700356 ev.mXOffset = 0;
357 ev.mYOffset = 0;
Michael Chan53071d62009-05-13 17:29:48 -0700358 ev.mXPrecision = xPrecision;
359 ev.mYPrecision = yPrecision;
Jeff Brown5c225b12010-06-16 01:53:36 -0700360
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700361 ev.mNumPointers = pointers;
362 ev.mNumSamples = 1;
363
Jeff Brown5c225b12010-06-16 01:53:36 -0700364 ev.mLastDataSampleIndex = 0;
365 ev.mLastEventTimeNanoSampleIndex = 0;
Dianne Hackborn1e8dfc72009-08-06 12:43:01 -0700366
Jeff Brownc5ed5912010-07-14 18:48:53 -0700367 System.arraycopy(pointerIds, 0, ev.mPointerIdentifiers, 0, pointers);
Dianne Hackborn1e8dfc72009-08-06 12:43:01 -0700368
Jeff Brownc5ed5912010-07-14 18:48:53 -0700369 ev.mEventTimeNanoSamples[0] = eventTime * MS_PER_NS;
Jeff Brown5c225b12010-06-16 01:53:36 -0700370
Jeff Brownc5ed5912010-07-14 18:48:53 -0700371 ev.setPointerCoordsAtSampleIndex(0, pointerCoords);
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700372
Michael Chan53071d62009-05-13 17:29:48 -0700373 return ev;
374 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800375
376 /**
377 * Create a new MotionEvent, filling in all of the basic values that
378 * define the motion.
Romain Guycafdea62009-06-12 10:51:36 -0700379 *
380 * @param downTime The time (in ms) when the user originally pressed down to start
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800381 * a stream of position events. This must be obtained from {@link SystemClock#uptimeMillis()}.
Romain Guycafdea62009-06-12 10:51:36 -0700382 * @param eventTime The the time (in ms) when this specific event was generated. This
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800383 * must be obtained from {@link SystemClock#uptimeMillis()}.
384 * @param action The kind of action being performed -- one of either
385 * {@link #ACTION_DOWN}, {@link #ACTION_MOVE}, {@link #ACTION_UP}, or
386 * {@link #ACTION_CANCEL}.
387 * @param x The X coordinate of this event.
388 * @param y The Y coordinate of this event.
Romain Guycafdea62009-06-12 10:51:36 -0700389 * @param pressure The current pressure of this event. The pressure generally
390 * ranges from 0 (no pressure at all) to 1 (normal pressure), however
391 * values higher than 1 may be generated depending on the calibration of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800392 * the input device.
393 * @param size A scaled value of the approximate size of the area being pressed when
Romain Guycafdea62009-06-12 10:51:36 -0700394 * touched with the finger. The actual value in pixels corresponding to the finger
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800395 * touch is normalized with a device specific range of values
396 * and scaled to a value between 0 and 1.
397 * @param metaState The state of any meta / modifier keys that were in effect when
398 * the event was generated.
399 * @param xPrecision The precision of the X coordinate being reported.
400 * @param yPrecision The precision of the Y coordinate being reported.
401 * @param deviceId The id for the device that this event came from. An id of
402 * zero indicates that the event didn't come from a physical device; other
403 * numbers are arbitrary and you shouldn't depend on the values.
404 * @param edgeFlags A bitfield indicating which edges, if any, where touched by this
405 * MotionEvent.
406 */
407 static public MotionEvent obtain(long downTime, long eventTime, int action,
408 float x, float y, float pressure, float size, int metaState,
409 float xPrecision, float yPrecision, int deviceId, int edgeFlags) {
Jeff Brown5c225b12010-06-16 01:53:36 -0700410 MotionEvent ev = obtain(1, 1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800411 ev.mDeviceId = deviceId;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700412 ev.mSource = InputDevice.SOURCE_UNKNOWN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800413 ev.mEdgeFlags = edgeFlags;
Jeff Brown5c225b12010-06-16 01:53:36 -0700414 ev.mDownTimeNano = downTime * MS_PER_NS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800415 ev.mAction = action;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800416 ev.mMetaState = metaState;
Jeff Brown5c225b12010-06-16 01:53:36 -0700417 ev.mXOffset = 0;
418 ev.mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800419 ev.mXPrecision = xPrecision;
420 ev.mYPrecision = yPrecision;
Jeff Brown5c225b12010-06-16 01:53:36 -0700421
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700422 ev.mNumPointers = 1;
423 ev.mNumSamples = 1;
Jeff Brown5c225b12010-06-16 01:53:36 -0700424
425 ev.mLastDataSampleIndex = 0;
426 ev.mLastEventTimeNanoSampleIndex = 0;
427
428 ev.mPointerIdentifiers[0] = 0;
429
430 ev.mEventTimeNanoSamples[0] = eventTime * MS_PER_NS;
431
Jeff Brownc5ed5912010-07-14 18:48:53 -0700432 ev.setPointerCoordsAtSampleIndex(0, x, y, pressure, size);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700433 return ev;
434 }
435
436 /**
437 * Create a new MotionEvent, filling in all of the basic values that
438 * define the motion.
439 *
440 * @param downTime The time (in ms) when the user originally pressed down to start
441 * a stream of position events. This must be obtained from {@link SystemClock#uptimeMillis()}.
442 * @param eventTime The the time (in ms) when this specific event was generated. This
443 * must be obtained from {@link SystemClock#uptimeMillis()}.
444 * @param action The kind of action being performed -- one of either
445 * {@link #ACTION_DOWN}, {@link #ACTION_MOVE}, {@link #ACTION_UP}, or
446 * {@link #ACTION_CANCEL}.
447 * @param pointers The number of pointers that are active in this event.
448 * @param x The X coordinate of this event.
449 * @param y The Y coordinate of this event.
450 * @param pressure The current pressure of this event. The pressure generally
451 * ranges from 0 (no pressure at all) to 1 (normal pressure), however
452 * values higher than 1 may be generated depending on the calibration of
453 * the input device.
454 * @param size A scaled value of the approximate size of the area being pressed when
455 * touched with the finger. The actual value in pixels corresponding to the finger
456 * touch is normalized with a device specific range of values
457 * and scaled to a value between 0 and 1.
458 * @param metaState The state of any meta / modifier keys that were in effect when
459 * the event was generated.
460 * @param xPrecision The precision of the X coordinate being reported.
461 * @param yPrecision The precision of the Y coordinate being reported.
462 * @param deviceId The id for the device that this event came from. An id of
463 * zero indicates that the event didn't come from a physical device; other
464 * numbers are arbitrary and you shouldn't depend on the values.
465 * @param edgeFlags A bitfield indicating which edges, if any, where touched by this
466 * MotionEvent.
Jeff Brown5c225b12010-06-16 01:53:36 -0700467 *
468 * @deprecated Use {@link #obtain(long, long, int, float, float, float, float, int, float, float, int, int)}
469 * instead.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700470 */
Jeff Brown5c225b12010-06-16 01:53:36 -0700471 @Deprecated
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700472 static public MotionEvent obtain(long downTime, long eventTime, int action,
473 int pointers, float x, float y, float pressure, float size, int metaState,
474 float xPrecision, float yPrecision, int deviceId, int edgeFlags) {
Jeff Brown5c225b12010-06-16 01:53:36 -0700475 return obtain(downTime, eventTime, action, x, y, pressure, size,
476 metaState, xPrecision, yPrecision, deviceId, edgeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800477 }
Romain Guycafdea62009-06-12 10:51:36 -0700478
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800479 /**
480 * Create a new MotionEvent, filling in a subset of the basic motion
481 * values. Those not specified here are: device id (always 0), pressure
482 * and size (always 1), x and y precision (always 1), and edgeFlags (always 0).
Romain Guycafdea62009-06-12 10:51:36 -0700483 *
484 * @param downTime The time (in ms) when the user originally pressed down to start
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800485 * a stream of position events. This must be obtained from {@link SystemClock#uptimeMillis()}.
Romain Guycafdea62009-06-12 10:51:36 -0700486 * @param eventTime The the time (in ms) when this specific event was generated. This
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800487 * must be obtained from {@link SystemClock#uptimeMillis()}.
488 * @param action The kind of action being performed -- one of either
489 * {@link #ACTION_DOWN}, {@link #ACTION_MOVE}, {@link #ACTION_UP}, or
490 * {@link #ACTION_CANCEL}.
491 * @param x The X coordinate of this event.
492 * @param y The Y coordinate of this event.
493 * @param metaState The state of any meta / modifier keys that were in effect when
494 * the event was generated.
495 */
496 static public MotionEvent obtain(long downTime, long eventTime, int action,
497 float x, float y, int metaState) {
Jeff Brown5c225b12010-06-16 01:53:36 -0700498 return obtain(downTime, eventTime, action, x, y, 1.0f, 1.0f,
499 metaState, 1.0f, 1.0f, 0, 0);
Mitsuru Oshima8169dae2009-04-28 18:12:09 -0700500 }
501
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800502 /**
503 * Create a new MotionEvent, copying from an existing one.
504 */
505 static public MotionEvent obtain(MotionEvent o) {
Jeff Brown5c225b12010-06-16 01:53:36 -0700506 MotionEvent ev = obtain(o.mNumPointers, o.mNumSamples);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800507 ev.mDeviceId = o.mDeviceId;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700508 ev.mSource = o.mSource;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800509 ev.mEdgeFlags = o.mEdgeFlags;
Jeff Brown5c225b12010-06-16 01:53:36 -0700510 ev.mDownTimeNano = o.mDownTimeNano;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800511 ev.mAction = o.mAction;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800512 ev.mMetaState = o.mMetaState;
Jeff Brown5c225b12010-06-16 01:53:36 -0700513 ev.mXOffset = o.mXOffset;
514 ev.mYOffset = o.mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800515 ev.mXPrecision = o.mXPrecision;
516 ev.mYPrecision = o.mYPrecision;
Jeff Brown5c225b12010-06-16 01:53:36 -0700517 int numPointers = ev.mNumPointers = o.mNumPointers;
518 int numSamples = ev.mNumSamples = o.mNumSamples;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700519
Jeff Brown5c225b12010-06-16 01:53:36 -0700520 ev.mLastDataSampleIndex = o.mLastDataSampleIndex;
521 ev.mLastEventTimeNanoSampleIndex = o.mLastEventTimeNanoSampleIndex;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700522
Jeff Brown5c225b12010-06-16 01:53:36 -0700523 System.arraycopy(o.mPointerIdentifiers, 0, ev.mPointerIdentifiers, 0, numPointers);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700524
Jeff Brown5c225b12010-06-16 01:53:36 -0700525 System.arraycopy(o.mEventTimeNanoSamples, 0, ev.mEventTimeNanoSamples, 0, numSamples);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700526
Jeff Brown5c225b12010-06-16 01:53:36 -0700527 System.arraycopy(o.mDataSamples, 0, ev.mDataSamples, 0,
528 numPointers * numSamples * NUM_SAMPLE_DATA);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800529 return ev;
530 }
Romain Guycafdea62009-06-12 10:51:36 -0700531
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800532 /**
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -0700533 * Create a new MotionEvent, copying from an existing one, but not including
534 * any historical point information.
535 */
536 static public MotionEvent obtainNoHistory(MotionEvent o) {
Jeff Brown5c225b12010-06-16 01:53:36 -0700537 MotionEvent ev = obtain(o.mNumPointers, 1);
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -0700538 ev.mDeviceId = o.mDeviceId;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700539 ev.mSource = o.mSource;
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -0700540 ev.mEdgeFlags = o.mEdgeFlags;
Jeff Brown5c225b12010-06-16 01:53:36 -0700541 ev.mDownTimeNano = o.mDownTimeNano;
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -0700542 ev.mAction = o.mAction;
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -0700543 ev.mMetaState = o.mMetaState;
Jeff Brown5c225b12010-06-16 01:53:36 -0700544 ev.mXOffset = o.mXOffset;
545 ev.mYOffset = o.mYOffset;
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -0700546 ev.mXPrecision = o.mXPrecision;
547 ev.mYPrecision = o.mYPrecision;
548
Jeff Brown5c225b12010-06-16 01:53:36 -0700549 int numPointers = ev.mNumPointers = o.mNumPointers;
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -0700550 ev.mNumSamples = 1;
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -0700551
Jeff Brown5c225b12010-06-16 01:53:36 -0700552 ev.mLastDataSampleIndex = 0;
553 ev.mLastEventTimeNanoSampleIndex = 0;
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -0700554
Jeff Brown5c225b12010-06-16 01:53:36 -0700555 System.arraycopy(o.mPointerIdentifiers, 0, ev.mPointerIdentifiers, 0, numPointers);
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -0700556
Jeff Brown5c225b12010-06-16 01:53:36 -0700557 ev.mEventTimeNanoSamples[0] = o.mEventTimeNanoSamples[o.mLastEventTimeNanoSampleIndex];
558
559 System.arraycopy(o.mDataSamples, o.mLastDataSampleIndex, ev.mDataSamples, 0,
560 numPointers * NUM_SAMPLE_DATA);
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -0700561 return ev;
562 }
563
564 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800565 * Recycle the MotionEvent, to be re-used by a later caller. After calling
566 * this function you must not ever touch the event again.
567 */
Jeff Brown5c225b12010-06-16 01:53:36 -0700568 public final void recycle() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800569 // Ensure recycle is only called once!
570 if (TRACK_RECYCLED_LOCATION) {
571 if (mRecycledLocation != null) {
572 throw new RuntimeException(toString() + " recycled twice!", mRecycledLocation);
573 }
574 mRecycledLocation = new RuntimeException("Last recycled here");
Jeff Brownd28f4be2010-06-02 15:35:46 -0700575 //Log.w("MotionEvent", "Recycling event " + this, mRecycledLocation);
576 } else {
577 if (mRecycled) {
578 throw new RuntimeException(toString() + " recycled twice!");
579 }
580 mRecycled = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800581 }
582
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800583 synchronized (gRecyclerLock) {
584 if (gRecyclerUsed < MAX_RECYCLED) {
585 gRecyclerUsed++;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700586 mNumSamples = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800587 mNext = gRecyclerTop;
588 gRecyclerTop = this;
589 }
590 }
591 }
Jeff Brown5c225b12010-06-16 01:53:36 -0700592
593 /**
594 * Scales down the coordination of this event by the given scale.
595 *
596 * @hide
597 */
598 public final void scale(float scale) {
599 mXOffset *= scale;
600 mYOffset *= scale;
601 mXPrecision *= scale;
602 mYPrecision *= scale;
603
604 float[] history = mDataSamples;
605 final int length = mNumPointers * mNumSamples * NUM_SAMPLE_DATA;
606 for (int i = 0; i < length; i += NUM_SAMPLE_DATA) {
607 history[i + SAMPLE_X] *= scale;
608 history[i + SAMPLE_Y] *= scale;
609 // no need to scale pressure
610 history[i + SAMPLE_SIZE] *= scale; // TODO: square this?
Jeff Brownc5ed5912010-07-14 18:48:53 -0700611 history[i + SAMPLE_TOUCH_MAJOR] *= scale;
612 history[i + SAMPLE_TOUCH_MINOR] *= scale;
613 history[i + SAMPLE_TOOL_MAJOR] *= scale;
614 history[i + SAMPLE_TOOL_MINOR] *= scale;
Jeff Brown5c225b12010-06-16 01:53:36 -0700615 }
616 }
Romain Guycafdea62009-06-12 10:51:36 -0700617
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800618 /**
619 * Return the kind of action being performed -- one of either
620 * {@link #ACTION_DOWN}, {@link #ACTION_MOVE}, {@link #ACTION_UP}, or
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800621 * {@link #ACTION_CANCEL}. Consider using {@link #getActionMasked}
622 * and {@link #getActionIndex} to retrieve the separate masked action
623 * and pointer index.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800624 */
625 public final int getAction() {
626 return mAction;
627 }
628
629 /**
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800630 * Return the masked action being performed, without pointer index
631 * information. May be any of the actions: {@link #ACTION_DOWN},
632 * {@link #ACTION_MOVE}, {@link #ACTION_UP}, {@link #ACTION_CANCEL},
633 * {@link #ACTION_POINTER_DOWN}, or {@link #ACTION_POINTER_UP}.
634 * Use {@link #getActionIndex} to return the index associated with
635 * pointer actions.
636 */
637 public final int getActionMasked() {
638 return mAction & ACTION_MASK;
639 }
640
641 /**
642 * For {@link #ACTION_POINTER_DOWN} or {@link #ACTION_POINTER_UP}
643 * as returned by {@link #getActionMasked}, this returns the associated
644 * pointer index. The index may be used with {@link #getPointerId(int)},
645 * {@link #getX(int)}, {@link #getY(int)}, {@link #getPressure(int)},
646 * and {@link #getSize(int)} to get information about the pointer that has
647 * gone down or up.
648 */
649 public final int getActionIndex() {
650 return (mAction & ACTION_POINTER_INDEX_MASK) >> ACTION_POINTER_INDEX_SHIFT;
651 }
652
653 /**
Romain Guycafdea62009-06-12 10:51:36 -0700654 * Returns the time (in ms) when the user originally pressed down to start
655 * a stream of position events.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800656 */
657 public final long getDownTime() {
Jeff Brown5c225b12010-06-16 01:53:36 -0700658 return mDownTimeNano / MS_PER_NS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800659 }
660
661 /**
662 * Returns the time (in ms) when this specific event was generated.
663 */
664 public final long getEventTime() {
Jeff Brown5c225b12010-06-16 01:53:36 -0700665 return mEventTimeNanoSamples[mLastEventTimeNanoSampleIndex] / MS_PER_NS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800666 }
667
668 /**
Michael Chan53071d62009-05-13 17:29:48 -0700669 * Returns the time (in ns) when this specific event was generated.
670 * The value is in nanosecond precision but it may not have nanosecond accuracy.
671 *
672 * @hide
673 */
674 public final long getEventTimeNano() {
Jeff Brown5c225b12010-06-16 01:53:36 -0700675 return mEventTimeNanoSamples[mLastEventTimeNanoSampleIndex];
Michael Chan53071d62009-05-13 17:29:48 -0700676 }
677
678 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700679 * {@link #getX(int)} for the first pointer index (may be an
680 * arbitrary pointer identifier).
681 */
682 public final float getX() {
Jeff Brown5c225b12010-06-16 01:53:36 -0700683 return mDataSamples[mLastDataSampleIndex + SAMPLE_X] + mXOffset;
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700684 }
685
686 /**
687 * {@link #getY(int)} for the first pointer index (may be an
688 * arbitrary pointer identifier).
689 */
690 public final float getY() {
Jeff Brown5c225b12010-06-16 01:53:36 -0700691 return mDataSamples[mLastDataSampleIndex + SAMPLE_Y] + mYOffset;
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700692 }
693
694 /**
695 * {@link #getPressure(int)} for the first pointer index (may be an
696 * arbitrary pointer identifier).
697 */
698 public final float getPressure() {
Jeff Brown5c225b12010-06-16 01:53:36 -0700699 return mDataSamples[mLastDataSampleIndex + SAMPLE_PRESSURE];
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700700 }
701
702 /**
703 * {@link #getSize(int)} for the first pointer index (may be an
704 * arbitrary pointer identifier).
705 */
706 public final float getSize() {
Jeff Brown5c225b12010-06-16 01:53:36 -0700707 return mDataSamples[mLastDataSampleIndex + SAMPLE_SIZE];
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700708 }
Jeff Brownc5ed5912010-07-14 18:48:53 -0700709
710 /**
711 * {@link #getTouchMajor(int)} for the first pointer index (may be an
712 * arbitrary pointer identifier).
713 */
714 public final float getTouchMajor() {
715 return mDataSamples[mLastDataSampleIndex + SAMPLE_TOUCH_MAJOR];
716 }
717
718 /**
719 * {@link #getTouchMinor(int)} for the first pointer index (may be an
720 * arbitrary pointer identifier).
721 */
722 public final float getTouchMinor() {
723 return mDataSamples[mLastDataSampleIndex + SAMPLE_TOUCH_MINOR];
724 }
725
726 /**
727 * {@link #getToolMajor(int)} for the first pointer index (may be an
728 * arbitrary pointer identifier).
729 */
730 public final float getToolMajor() {
731 return mDataSamples[mLastDataSampleIndex + SAMPLE_TOOL_MAJOR];
732 }
733
734 /**
735 * {@link #getToolMinor(int)} for the first pointer index (may be an
736 * arbitrary pointer identifier).
737 */
738 public final float getToolMinor() {
739 return mDataSamples[mLastDataSampleIndex + SAMPLE_TOOL_MINOR];
740 }
741
742 /**
743 * {@link #getOrientation(int)} for the first pointer index (may be an
744 * arbitrary pointer identifier).
745 */
746 public final float getOrientation() {
747 return mDataSamples[mLastDataSampleIndex + SAMPLE_ORIENTATION];
748 }
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700749
750 /**
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700751 * The number of pointers of data contained in this event. Always
752 * >= 1.
753 */
754 public final int getPointerCount() {
755 return mNumPointers;
756 }
757
758 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700759 * Return the pointer identifier associated with a particular pointer
760 * data index is this event. The identifier tells you the actual pointer
761 * number associated with the data, accounting for individual pointers
762 * going up and down since the start of the current gesture.
763 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
764 * (the first pointer that is down) to {@link #getPointerCount()}-1.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800765 */
Dianne Hackbornd41ba662009-08-05 15:30:56 -0700766 public final int getPointerId(int pointerIndex) {
767 return mPointerIdentifiers[pointerIndex];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800768 }
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700769
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800770 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700771 * Given a pointer identifier, find the index of its data in the event.
772 *
773 * @param pointerId The identifier of the pointer to be found.
774 * @return Returns either the index of the pointer (for use with
775 * {@link #getX(int) et al.), or -1 if there is no data available for
776 * that pointer identifier.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800777 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700778 public final int findPointerIndex(int pointerId) {
779 int i = mNumPointers;
780 while (i > 0) {
781 i--;
782 if (mPointerIdentifiers[i] == pointerId) {
783 return i;
784 }
785 }
786 return -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800787 }
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700788
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800789 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700790 * Returns the X coordinate of this event for the given pointer
791 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
792 * identifier for this index).
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700793 * Whole numbers are pixels; the
794 * value may have a fraction for input devices that are sub-pixel precise.
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700795 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
796 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700797 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700798 public final float getX(int pointerIndex) {
Jeff Brown5c225b12010-06-16 01:53:36 -0700799 return mDataSamples[mLastDataSampleIndex
800 + pointerIndex * NUM_SAMPLE_DATA + SAMPLE_X] + mXOffset;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700801 }
802
803 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700804 * Returns the Y coordinate of this event for the given pointer
805 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
806 * identifier for this index).
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700807 * Whole numbers are pixels; the
808 * value may have a fraction for input devices that are sub-pixel precise.
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700809 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
810 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700811 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700812 public final float getY(int pointerIndex) {
Jeff Brown5c225b12010-06-16 01:53:36 -0700813 return mDataSamples[mLastDataSampleIndex
814 + pointerIndex * NUM_SAMPLE_DATA + SAMPLE_Y] + mYOffset;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700815 }
816
817 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700818 * Returns the current pressure of this event for the given pointer
819 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
820 * identifier for this index).
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700821 * The pressure generally
Romain Guycafdea62009-06-12 10:51:36 -0700822 * ranges from 0 (no pressure at all) to 1 (normal pressure), however
823 * values higher than 1 may be generated depending on the calibration of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800824 * the input device.
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700825 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
826 * (the first pointer that is down) to {@link #getPointerCount()}-1.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800827 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700828 public final float getPressure(int pointerIndex) {
Jeff Brown5c225b12010-06-16 01:53:36 -0700829 return mDataSamples[mLastDataSampleIndex
830 + pointerIndex * NUM_SAMPLE_DATA + SAMPLE_PRESSURE];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800831 }
832
833 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700834 * Returns a scaled value of the approximate size for the given pointer
835 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
836 * identifier for this index).
837 * This represents some approximation of the area of the screen being
838 * pressed; the actual value in pixels corresponding to the
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700839 * touch is normalized with the device specific range of values
Romain Guycafdea62009-06-12 10:51:36 -0700840 * 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 -0800841 * determine fat touch events.
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700842 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
843 * (the first pointer that is down) to {@link #getPointerCount()}-1.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800844 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700845 public final float getSize(int pointerIndex) {
Jeff Brown5c225b12010-06-16 01:53:36 -0700846 return mDataSamples[mLastDataSampleIndex
847 + pointerIndex * NUM_SAMPLE_DATA + SAMPLE_SIZE];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800848 }
Jeff Brownc5ed5912010-07-14 18:48:53 -0700849
850 /**
851 * Returns the length of the major axis of an ellipse that describes the touch
852 * area at the point of contact for the given pointer
853 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
854 * identifier for this index).
855 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
856 * (the first pointer that is down) to {@link #getPointerCount()}-1.
857 */
858 public final float getTouchMajor(int pointerIndex) {
859 return mDataSamples[mLastDataSampleIndex
860 + pointerIndex * NUM_SAMPLE_DATA + SAMPLE_TOUCH_MAJOR];
861 }
862
863 /**
864 * Returns the length of the minor axis of an ellipse that describes the touch
865 * area at the point of contact for the given pointer
866 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
867 * identifier for this index).
868 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
869 * (the first pointer that is down) to {@link #getPointerCount()}-1.
870 */
871 public final float getTouchMinor(int pointerIndex) {
872 return mDataSamples[mLastDataSampleIndex
873 + pointerIndex * NUM_SAMPLE_DATA + SAMPLE_TOUCH_MINOR];
874 }
875
876 /**
877 * Returns the length of the major axis of an ellipse that describes the size of
878 * the approaching tool for the given pointer
879 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
880 * identifier for this index).
881 * The tool area represents the estimated size of the finger or pen that is
882 * touching the device independent of its actual touch area at the point of contact.
883 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
884 * (the first pointer that is down) to {@link #getPointerCount()}-1.
885 */
886 public final float getToolMajor(int pointerIndex) {
887 return mDataSamples[mLastDataSampleIndex
888 + pointerIndex * NUM_SAMPLE_DATA + SAMPLE_TOOL_MAJOR];
889 }
890
891 /**
892 * Returns the length of the minor axis of an ellipse that describes the size of
893 * the approaching tool for the given pointer
894 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
895 * identifier for this index).
896 * The tool area represents the estimated size of the finger or pen that is
897 * touching the device independent of its actual touch area at the point of contact.
898 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
899 * (the first pointer that is down) to {@link #getPointerCount()}-1.
900 */
901 public final float getToolMinor(int pointerIndex) {
902 return mDataSamples[mLastDataSampleIndex
903 + pointerIndex * NUM_SAMPLE_DATA + SAMPLE_TOOL_MINOR];
904 }
905
906 /**
907 * Returns the orientation of the touch area and tool area in radians clockwise from vertical
908 * for the given pointer <em>index</em> (use {@link #getPointerId(int)} to find the pointer
909 * identifier for this index).
910 * An angle of 0 degrees indicates that the major axis of contact is oriented
911 * upwards, is perfectly circular or is of unknown orientation. A positive angle
912 * indicates that the major axis of contact is oriented to the right. A negative angle
913 * indicates that the major axis of contact is oriented to the left.
Jeff Brown6d0fec22010-07-23 21:28:06 -0700914 * The full range is from -PI/2 radians (finger pointing fully left) to PI/2 radians
Jeff Brownc5ed5912010-07-14 18:48:53 -0700915 * (finger pointing fully right).
916 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
917 * (the first pointer that is down) to {@link #getPointerCount()}-1.
918 */
919 public final float getOrientation(int pointerIndex) {
920 return mDataSamples[mLastDataSampleIndex
921 + pointerIndex * NUM_SAMPLE_DATA + SAMPLE_ORIENTATION];
922 }
923
924 /**
925 * Populates a {@link PointerCoords} object with pointer coordinate data for
926 * the specified pointer index.
927 *
928 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
929 * (the first pointer that is down) to {@link #getPointerCount()}-1.
930 * @param outPointerCoords The pointer coordinate object to populate.
931 */
932 public final void getPointerCoords(int pointerIndex, PointerCoords outPointerCoords) {
933 final int sampleIndex = mLastDataSampleIndex + pointerIndex * NUM_SAMPLE_DATA;
934 getPointerCoordsAtSampleIndex(sampleIndex, outPointerCoords);
935 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800936
937 /**
938 * Returns the state of any meta / modifier keys that were in effect when
939 * the event was generated. This is the same values as those
940 * returned by {@link KeyEvent#getMetaState() KeyEvent.getMetaState}.
941 *
942 * @return an integer in which each bit set to 1 represents a pressed
943 * meta key
944 *
945 * @see KeyEvent#getMetaState()
946 */
947 public final int getMetaState() {
948 return mMetaState;
949 }
950
951 /**
952 * Returns the original raw X coordinate of this event. For touch
953 * events on the screen, this is the original location of the event
954 * on the screen, before it had been adjusted for the containing window
955 * and views.
956 */
957 public final float getRawX() {
Jeff Brown5c225b12010-06-16 01:53:36 -0700958 return mDataSamples[mLastDataSampleIndex + SAMPLE_X];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800959 }
Jeff Brownc5ed5912010-07-14 18:48:53 -0700960
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800961 /**
962 * Returns the original raw Y coordinate of this event. For touch
963 * events on the screen, this is the original location of the event
964 * on the screen, before it had been adjusted for the containing window
965 * and views.
966 */
967 public final float getRawY() {
Jeff Brown5c225b12010-06-16 01:53:36 -0700968 return mDataSamples[mLastDataSampleIndex + SAMPLE_Y];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800969 }
970
971 /**
972 * Return the precision of the X coordinates being reported. You can
973 * multiple this number with {@link #getX} to find the actual hardware
974 * value of the X coordinate.
975 * @return Returns the precision of X coordinates being reported.
976 */
977 public final float getXPrecision() {
978 return mXPrecision;
979 }
Romain Guycafdea62009-06-12 10:51:36 -0700980
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800981 /**
982 * Return the precision of the Y coordinates being reported. You can
983 * multiple this number with {@link #getY} to find the actual hardware
984 * value of the Y coordinate.
985 * @return Returns the precision of Y coordinates being reported.
986 */
987 public final float getYPrecision() {
988 return mYPrecision;
989 }
Romain Guycafdea62009-06-12 10:51:36 -0700990
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800991 /**
992 * Returns the number of historical points in this event. These are
993 * movements that have occurred between this event and the previous event.
994 * This only applies to ACTION_MOVE events -- all other actions will have
995 * a size of 0.
Romain Guycafdea62009-06-12 10:51:36 -0700996 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800997 * @return Returns the number of historical points in the event.
998 */
999 public final int getHistorySize() {
Jeff Brown5c225b12010-06-16 01:53:36 -07001000 return mLastEventTimeNanoSampleIndex;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001001 }
Romain Guycafdea62009-06-12 10:51:36 -07001002
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001003 /**
1004 * Returns the time that a historical movement occurred between this event
1005 * and the previous event. Only applies to ACTION_MOVE events.
Romain Guycafdea62009-06-12 10:51:36 -07001006 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001007 * @param pos Which historical value to return; must be less than
1008 * {@link #getHistorySize}
Romain Guycafdea62009-06-12 10:51:36 -07001009 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001010 * @see #getHistorySize
1011 * @see #getEventTime
1012 */
1013 public final long getHistoricalEventTime(int pos) {
Jeff Brown5c225b12010-06-16 01:53:36 -07001014 return mEventTimeNanoSamples[pos] / MS_PER_NS;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001015 }
1016
1017 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001018 * {@link #getHistoricalX(int)} for the first pointer index (may be an
1019 * arbitrary pointer identifier).
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001020 */
1021 public final float getHistoricalX(int pos) {
Jeff Brown5c225b12010-06-16 01:53:36 -07001022 return mDataSamples[pos * mNumPointers * NUM_SAMPLE_DATA + SAMPLE_X] + mXOffset;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001023 }
1024
1025 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001026 * {@link #getHistoricalY(int)} for the first pointer index (may be an
1027 * arbitrary pointer identifier).
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001028 */
1029 public final float getHistoricalY(int pos) {
Jeff Brown5c225b12010-06-16 01:53:36 -07001030 return mDataSamples[pos * mNumPointers * NUM_SAMPLE_DATA + SAMPLE_Y] + mYOffset;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001031 }
1032
1033 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001034 * {@link #getHistoricalPressure(int)} for the first pointer index (may be an
1035 * arbitrary pointer identifier).
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001036 */
1037 public final float getHistoricalPressure(int pos) {
Jeff Brown5c225b12010-06-16 01:53:36 -07001038 return mDataSamples[pos * mNumPointers * NUM_SAMPLE_DATA + SAMPLE_PRESSURE];
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001039 }
1040
1041 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001042 * {@link #getHistoricalSize(int)} for the first pointer index (may be an
1043 * arbitrary pointer identifier).
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001044 */
1045 public final float getHistoricalSize(int pos) {
Jeff Brown5c225b12010-06-16 01:53:36 -07001046 return mDataSamples[pos * mNumPointers * NUM_SAMPLE_DATA + SAMPLE_SIZE];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001047 }
Romain Guycafdea62009-06-12 10:51:36 -07001048
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001049 /**
Jeff Brownc5ed5912010-07-14 18:48:53 -07001050 * {@link #getHistoricalTouchMajor(int)} for the first pointer index (may be an
1051 * arbitrary pointer identifier).
1052 */
1053 public final float getHistoricalTouchMajor(int pos) {
1054 return mDataSamples[pos * mNumPointers * NUM_SAMPLE_DATA + SAMPLE_TOUCH_MAJOR];
1055 }
1056
1057 /**
1058 * {@link #getHistoricalTouchMinor(int)} for the first pointer index (may be an
1059 * arbitrary pointer identifier).
1060 */
1061 public final float getHistoricalTouchMinor(int pos) {
1062 return mDataSamples[pos * mNumPointers * NUM_SAMPLE_DATA + SAMPLE_TOUCH_MINOR];
1063 }
1064
1065 /**
1066 * {@link #getHistoricalToolMajor(int)} for the first pointer index (may be an
1067 * arbitrary pointer identifier).
1068 */
1069 public final float getHistoricalToolMajor(int pos) {
1070 return mDataSamples[pos * mNumPointers * NUM_SAMPLE_DATA + SAMPLE_TOOL_MAJOR];
1071 }
1072
1073 /**
1074 * {@link #getHistoricalToolMinor(int)} for the first pointer index (may be an
1075 * arbitrary pointer identifier).
1076 */
1077 public final float getHistoricalToolMinor(int pos) {
1078 return mDataSamples[pos * mNumPointers * NUM_SAMPLE_DATA + SAMPLE_TOOL_MINOR];
1079 }
1080
1081 /**
1082 * {@link #getHistoricalOrientation(int)} for the first pointer index (may be an
1083 * arbitrary pointer identifier).
1084 */
1085 public final float getHistoricalOrientation(int pos) {
1086 return mDataSamples[pos * mNumPointers * NUM_SAMPLE_DATA + SAMPLE_ORIENTATION];
1087 }
1088
1089 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001090 * Returns a historical X coordinate, as per {@link #getX(int)}, that
1091 * occurred between this event and the previous event for the given pointer.
1092 * Only applies to ACTION_MOVE events.
Romain Guycafdea62009-06-12 10:51:36 -07001093 *
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001094 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1095 * (the first pointer that is down) to {@link #getPointerCount()}-1.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001096 * @param pos Which historical value to return; must be less than
1097 * {@link #getHistorySize}
Romain Guycafdea62009-06-12 10:51:36 -07001098 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001099 * @see #getHistorySize
1100 * @see #getX
1101 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001102 public final float getHistoricalX(int pointerIndex, int pos) {
Jeff Brown5c225b12010-06-16 01:53:36 -07001103 return mDataSamples[(pos * mNumPointers + pointerIndex)
1104 * NUM_SAMPLE_DATA + SAMPLE_X] + mXOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001105 }
Romain Guycafdea62009-06-12 10:51:36 -07001106
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001107 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001108 * Returns a historical Y coordinate, as per {@link #getY(int)}, that
1109 * occurred between this event and the previous event for the given pointer.
1110 * Only applies to ACTION_MOVE events.
Romain Guycafdea62009-06-12 10:51:36 -07001111 *
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001112 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1113 * (the first pointer that is down) to {@link #getPointerCount()}-1.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001114 * @param pos Which historical value to return; must be less than
1115 * {@link #getHistorySize}
Romain Guycafdea62009-06-12 10:51:36 -07001116 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001117 * @see #getHistorySize
1118 * @see #getY
1119 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001120 public final float getHistoricalY(int pointerIndex, int pos) {
Jeff Brown5c225b12010-06-16 01:53:36 -07001121 return mDataSamples[(pos * mNumPointers + pointerIndex)
1122 * NUM_SAMPLE_DATA + SAMPLE_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001123 }
Romain Guycafdea62009-06-12 10:51:36 -07001124
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001125 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001126 * Returns a historical pressure coordinate, as per {@link #getPressure(int)},
1127 * that occurred between this event and the previous event for the given
1128 * pointer. Only applies to ACTION_MOVE events.
Romain Guycafdea62009-06-12 10:51:36 -07001129 *
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001130 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1131 * (the first pointer that is down) to {@link #getPointerCount()}-1.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001132 * @param pos Which historical value to return; must be less than
1133 * {@link #getHistorySize}
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001134 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001135 * @see #getHistorySize
1136 * @see #getPressure
1137 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001138 public final float getHistoricalPressure(int pointerIndex, int pos) {
Jeff Brown5c225b12010-06-16 01:53:36 -07001139 return mDataSamples[(pos * mNumPointers + pointerIndex)
1140 * NUM_SAMPLE_DATA + SAMPLE_PRESSURE];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001141 }
Romain Guycafdea62009-06-12 10:51:36 -07001142
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001143 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001144 * Returns a historical size coordinate, as per {@link #getSize(int)}, that
1145 * occurred between this event and the previous event for the given pointer.
1146 * Only applies to ACTION_MOVE events.
Romain Guycafdea62009-06-12 10:51:36 -07001147 *
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001148 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1149 * (the first pointer that is down) to {@link #getPointerCount()}-1.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001150 * @param pos Which historical value to return; must be less than
1151 * {@link #getHistorySize}
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001152 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001153 * @see #getHistorySize
1154 * @see #getSize
1155 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001156 public final float getHistoricalSize(int pointerIndex, int pos) {
Jeff Brown5c225b12010-06-16 01:53:36 -07001157 return mDataSamples[(pos * mNumPointers + pointerIndex)
1158 * NUM_SAMPLE_DATA + SAMPLE_SIZE];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001159 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07001160
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001161 /**
Jeff Brownc5ed5912010-07-14 18:48:53 -07001162 * Returns a historical touch major axis coordinate, as per {@link #getTouchMajor(int)}, that
1163 * occurred between this event and the previous event for the given pointer.
1164 * Only applies to ACTION_MOVE events.
1165 *
1166 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1167 * (the first pointer that is down) to {@link #getPointerCount()}-1.
1168 * @param pos Which historical value to return; must be less than
1169 * {@link #getHistorySize}
1170 *
1171 * @see #getHistorySize
1172 * @see #getTouchMajor
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001173 */
Jeff Brownc5ed5912010-07-14 18:48:53 -07001174 public final float getHistoricalTouchMajor(int pointerIndex, int pos) {
1175 return mDataSamples[(pos * mNumPointers + pointerIndex)
1176 * NUM_SAMPLE_DATA + SAMPLE_TOUCH_MAJOR];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001177 }
Romain Guycafdea62009-06-12 10:51:36 -07001178
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001179 /**
Jeff Brownc5ed5912010-07-14 18:48:53 -07001180 * Returns a historical touch minor axis coordinate, as per {@link #getTouchMinor(int)}, that
1181 * occurred between this event and the previous event for the given pointer.
1182 * Only applies to ACTION_MOVE events.
1183 *
1184 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1185 * (the first pointer that is down) to {@link #getPointerCount()}-1.
1186 * @param pos Which historical value to return; must be less than
1187 * {@link #getHistorySize}
1188 *
1189 * @see #getHistorySize
1190 * @see #getTouchMinor
1191 */
1192 public final float getHistoricalTouchMinor(int pointerIndex, int pos) {
1193 return mDataSamples[(pos * mNumPointers + pointerIndex)
1194 * NUM_SAMPLE_DATA + SAMPLE_TOUCH_MINOR];
1195 }
1196
1197 /**
1198 * Returns a historical tool major axis coordinate, as per {@link #getToolMajor(int)}, that
1199 * occurred between this event and the previous event for the given pointer.
1200 * Only applies to ACTION_MOVE events.
1201 *
1202 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1203 * (the first pointer that is down) to {@link #getPointerCount()}-1.
1204 * @param pos Which historical value to return; must be less than
1205 * {@link #getHistorySize}
1206 *
1207 * @see #getHistorySize
1208 * @see #getToolMajor
1209 */
1210 public final float getHistoricalToolMajor(int pointerIndex, int pos) {
1211 return mDataSamples[(pos * mNumPointers + pointerIndex)
1212 * NUM_SAMPLE_DATA + SAMPLE_TOOL_MAJOR];
1213 }
1214
1215 /**
1216 * Returns a historical tool minor axis coordinate, as per {@link #getToolMinor(int)}, that
1217 * occurred between this event and the previous event for the given pointer.
1218 * Only applies to ACTION_MOVE events.
1219 *
1220 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1221 * (the first pointer that is down) to {@link #getPointerCount()}-1.
1222 * @param pos Which historical value to return; must be less than
1223 * {@link #getHistorySize}
1224 *
1225 * @see #getHistorySize
1226 * @see #getToolMinor
1227 */
1228 public final float getHistoricalToolMinor(int pointerIndex, int pos) {
1229 return mDataSamples[(pos * mNumPointers + pointerIndex)
1230 * NUM_SAMPLE_DATA + SAMPLE_TOOL_MINOR];
1231 }
1232
1233 /**
1234 * Returns a historical orientation coordinate, as per {@link #getOrientation(int)}, that
1235 * occurred between this event and the previous event for the given pointer.
1236 * Only applies to ACTION_MOVE events.
1237 *
1238 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1239 * (the first pointer that is down) to {@link #getPointerCount()}-1.
1240 * @param pos Which historical value to return; must be less than
1241 * {@link #getHistorySize}
1242 *
1243 * @see #getHistorySize
1244 * @see #getOrientation
1245 */
1246 public final float getHistoricalOrientation(int pointerIndex, int pos) {
1247 return mDataSamples[(pos * mNumPointers + pointerIndex)
1248 * NUM_SAMPLE_DATA + SAMPLE_ORIENTATION];
1249 }
1250
1251 /**
1252 * Populates a {@link PointerCoords} object with historical pointer coordinate data,
1253 * as per {@link #getPointerCoords}, that occurred between this event and the previous
1254 * event for the given pointer.
1255 * Only applies to ACTION_MOVE events.
1256 *
1257 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1258 * (the first pointer that is down) to {@link #getPointerCount()}-1.
1259 * @param pos Which historical value to return; must be less than
1260 * {@link #getHistorySize}
1261 * @param outPointerCoords The pointer coordinate object to populate.
1262 *
1263 * @see #getHistorySize
1264 * @see #getPointerCoords
1265 */
1266 public final void getHistoricalPointerCoords(int pointerIndex, int pos,
1267 PointerCoords outPointerCoords) {
1268 final int sampleIndex = (pos * mNumPointers + pointerIndex) * NUM_SAMPLE_DATA;
1269 getPointerCoordsAtSampleIndex(sampleIndex, outPointerCoords);
1270 }
1271
1272 /**
Jeff Brown46b9ac02010-04-22 18:58:52 -07001273 * Returns a bitfield indicating which edges, if any, were touched by this
Romain Guycafdea62009-06-12 10:51:36 -07001274 * MotionEvent. For touch events, clients can use this to determine if the
1275 * user's finger was touching the edge of the display.
1276 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001277 * @see #EDGE_LEFT
1278 * @see #EDGE_TOP
1279 * @see #EDGE_RIGHT
1280 * @see #EDGE_BOTTOM
1281 */
1282 public final int getEdgeFlags() {
1283 return mEdgeFlags;
1284 }
Romain Guycafdea62009-06-12 10:51:36 -07001285
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001286
1287 /**
1288 * Sets the bitfield indicating which edges, if any, where touched by this
Romain Guycafdea62009-06-12 10:51:36 -07001289 * MotionEvent.
1290 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001291 * @see #getEdgeFlags()
1292 */
1293 public final void setEdgeFlags(int flags) {
1294 mEdgeFlags = flags;
1295 }
1296
1297 /**
1298 * Sets this event's action.
1299 */
1300 public final void setAction(int action) {
1301 mAction = action;
1302 }
1303
1304 /**
1305 * Adjust this event's location.
1306 * @param deltaX Amount to add to the current X coordinate of the event.
1307 * @param deltaY Amount to add to the current Y coordinate of the event.
1308 */
1309 public final void offsetLocation(float deltaX, float deltaY) {
Jeff Brown5c225b12010-06-16 01:53:36 -07001310 mXOffset += deltaX;
1311 mYOffset += deltaY;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001312 }
Romain Guycafdea62009-06-12 10:51:36 -07001313
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001314 /**
1315 * Set this event's location. Applies {@link #offsetLocation} with a
1316 * delta from the current location to the given new location.
Romain Guycafdea62009-06-12 10:51:36 -07001317 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001318 * @param x New absolute X location.
1319 * @param y New absolute Y location.
1320 */
1321 public final void setLocation(float x, float y) {
Jeff Brown5c225b12010-06-16 01:53:36 -07001322 mXOffset = x - mDataSamples[mLastDataSampleIndex + SAMPLE_X];
1323 mYOffset = y - mDataSamples[mLastDataSampleIndex + SAMPLE_Y];
1324 }
1325
Jeff Brownc5ed5912010-07-14 18:48:53 -07001326 private final void getPointerCoordsAtSampleIndex(int sampleIndex,
1327 PointerCoords outPointerCoords) {
1328 outPointerCoords.x = mDataSamples[sampleIndex + SAMPLE_X] + mXOffset;
1329 outPointerCoords.y = mDataSamples[sampleIndex + SAMPLE_Y] + mYOffset;
1330 outPointerCoords.pressure = mDataSamples[sampleIndex + SAMPLE_PRESSURE];
1331 outPointerCoords.size = mDataSamples[sampleIndex + SAMPLE_SIZE];
1332 outPointerCoords.touchMajor = mDataSamples[sampleIndex + SAMPLE_TOUCH_MAJOR];
1333 outPointerCoords.touchMinor = mDataSamples[sampleIndex + SAMPLE_TOUCH_MINOR];
1334 outPointerCoords.toolMajor = mDataSamples[sampleIndex + SAMPLE_TOOL_MAJOR];
1335 outPointerCoords.toolMinor = mDataSamples[sampleIndex + SAMPLE_TOOL_MINOR];
1336 outPointerCoords.orientation = mDataSamples[sampleIndex + SAMPLE_ORIENTATION];
1337 }
1338
1339 private final void setPointerCoordsAtSampleIndex(int sampleIndex,
1340 PointerCoords[] pointerCoords) {
1341 final int numPointers = mNumPointers;
1342 for (int i = 0; i < numPointers; i++) {
1343 setPointerCoordsAtSampleIndex(sampleIndex, pointerCoords[i]);
1344 sampleIndex += NUM_SAMPLE_DATA;
1345 }
1346 }
1347
1348 private final void setPointerCoordsAtSampleIndex(int sampleIndex,
1349 PointerCoords pointerCoords) {
1350 mDataSamples[sampleIndex + SAMPLE_X] = pointerCoords.x - mXOffset;
1351 mDataSamples[sampleIndex + SAMPLE_Y] = pointerCoords.y - mYOffset;
1352 mDataSamples[sampleIndex + SAMPLE_PRESSURE] = pointerCoords.pressure;
1353 mDataSamples[sampleIndex + SAMPLE_SIZE] = pointerCoords.size;
1354 mDataSamples[sampleIndex + SAMPLE_TOUCH_MAJOR] = pointerCoords.touchMajor;
1355 mDataSamples[sampleIndex + SAMPLE_TOUCH_MINOR] = pointerCoords.touchMinor;
1356 mDataSamples[sampleIndex + SAMPLE_TOOL_MAJOR] = pointerCoords.toolMajor;
1357 mDataSamples[sampleIndex + SAMPLE_TOOL_MINOR] = pointerCoords.toolMinor;
1358 mDataSamples[sampleIndex + SAMPLE_ORIENTATION] = pointerCoords.orientation;
1359 }
1360
1361 private final void setPointerCoordsAtSampleIndex(int sampleIndex,
1362 float x, float y, float pressure, float size) {
1363 mDataSamples[sampleIndex + SAMPLE_X] = x - mXOffset;
1364 mDataSamples[sampleIndex + SAMPLE_Y] = y - mYOffset;
1365 mDataSamples[sampleIndex + SAMPLE_PRESSURE] = pressure;
1366 mDataSamples[sampleIndex + SAMPLE_SIZE] = size;
1367 mDataSamples[sampleIndex + SAMPLE_TOUCH_MAJOR] = pressure;
1368 mDataSamples[sampleIndex + SAMPLE_TOUCH_MINOR] = pressure;
1369 mDataSamples[sampleIndex + SAMPLE_TOOL_MAJOR] = size;
1370 mDataSamples[sampleIndex + SAMPLE_TOOL_MINOR] = size;
1371 mDataSamples[sampleIndex + SAMPLE_ORIENTATION] = 0;
1372 }
1373
Jeff Brown5c225b12010-06-16 01:53:36 -07001374 private final void incrementNumSamplesAndReserveStorage(int dataSampleStride) {
1375 if (mNumSamples == mEventTimeNanoSamples.length) {
1376 long[] newEventTimeNanoSamples = new long[mNumSamples + BASE_AVAIL_SAMPLES];
1377 System.arraycopy(mEventTimeNanoSamples, 0, newEventTimeNanoSamples, 0, mNumSamples);
1378 mEventTimeNanoSamples = newEventTimeNanoSamples;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001379 }
Jeff Brown5c225b12010-06-16 01:53:36 -07001380
1381 int nextDataSampleIndex = mLastDataSampleIndex + dataSampleStride;
1382 if (nextDataSampleIndex + dataSampleStride > mDataSamples.length) {
1383 float[] newDataSamples = new float[nextDataSampleIndex
1384 + BASE_AVAIL_SAMPLES * dataSampleStride];
1385 System.arraycopy(mDataSamples, 0, newDataSamples, 0, nextDataSampleIndex);
1386 mDataSamples = newDataSamples;
1387 }
1388
1389 mLastEventTimeNanoSampleIndex = mNumSamples;
1390 mLastDataSampleIndex = nextDataSampleIndex;
1391 mNumSamples += 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001392 }
Romain Guycafdea62009-06-12 10:51:36 -07001393
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001394 /**
1395 * Add a new movement to the batch of movements in this event. The event's
Jeff Brownc5ed5912010-07-14 18:48:53 -07001396 * current location, position and size is updated to the new values.
1397 * The current values in the event are added to a list of historical values.
1398 *
Jeff Browne33348b2010-07-15 23:54:05 -07001399 * Only applies to {@link #ACTION_MOVE} events.
Romain Guycafdea62009-06-12 10:51:36 -07001400 *
Jeff Brownc5ed5912010-07-14 18:48:53 -07001401 * @param eventTime The time stamp (in ms) for this data.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001402 * @param x The new X position.
1403 * @param y The new Y position.
1404 * @param pressure The new pressure.
1405 * @param size The new size.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001406 * @param metaState Meta key state.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001407 */
1408 public final void addBatch(long eventTime, float x, float y,
1409 float pressure, float size, int metaState) {
Jeff Brown5c225b12010-06-16 01:53:36 -07001410 incrementNumSamplesAndReserveStorage(NUM_SAMPLE_DATA);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001411
Jeff Brown5c225b12010-06-16 01:53:36 -07001412 mEventTimeNanoSamples[mLastEventTimeNanoSampleIndex] = eventTime * MS_PER_NS;
Jeff Brownc5ed5912010-07-14 18:48:53 -07001413 setPointerCoordsAtSampleIndex(mLastDataSampleIndex, x, y, pressure, size);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001414
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001415 mMetaState |= metaState;
1416 }
Romain Guycafdea62009-06-12 10:51:36 -07001417
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001418 /**
Jeff Brownc5ed5912010-07-14 18:48:53 -07001419 * Add a new movement to the batch of movements in this event. The event's
1420 * current location, position and size is updated to the new values.
1421 * The current values in the event are added to a list of historical values.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001422 *
Jeff Browne33348b2010-07-15 23:54:05 -07001423 * Only applies to {@link #ACTION_MOVE} events.
Jeff Brownc5ed5912010-07-14 18:48:53 -07001424 *
1425 * @param eventTime The time stamp (in ms) for this data.
1426 * @param pointerCoords The new pointer coordinates.
1427 * @param metaState Meta key state.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001428 */
Jeff Brownc5ed5912010-07-14 18:48:53 -07001429 public final void addBatch(long eventTime, PointerCoords[] pointerCoords, int metaState) {
1430 final int dataSampleStride = mNumPointers * NUM_SAMPLE_DATA;
Jeff Brown5c225b12010-06-16 01:53:36 -07001431 incrementNumSamplesAndReserveStorage(dataSampleStride);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001432
Jeff Brown5c225b12010-06-16 01:53:36 -07001433 mEventTimeNanoSamples[mLastEventTimeNanoSampleIndex] = eventTime * MS_PER_NS;
Jeff Brownc5ed5912010-07-14 18:48:53 -07001434 setPointerCoordsAtSampleIndex(mLastDataSampleIndex, pointerCoords);
Jeff Brown5c225b12010-06-16 01:53:36 -07001435
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001436 mMetaState |= metaState;
1437 }
Romain Guycafdea62009-06-12 10:51:36 -07001438
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001439 @Override
1440 public String toString() {
1441 return "MotionEvent{" + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001442 + " action=" + mAction + " x=" + getX()
1443 + " y=" + getY() + " pressure=" + getPressure() + " size=" + getSize() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001444 }
1445
1446 public static final Parcelable.Creator<MotionEvent> CREATOR
1447 = new Parcelable.Creator<MotionEvent>() {
1448 public MotionEvent createFromParcel(Parcel in) {
Jeff Brown6ec402b2010-07-28 15:48:59 -07001449 in.readInt(); // skip token, we already know this is a MotionEvent
1450 return MotionEvent.createFromParcelBody(in);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001451 }
1452
1453 public MotionEvent[] newArray(int size) {
1454 return new MotionEvent[size];
1455 }
1456 };
1457
Jeff Brown6ec402b2010-07-28 15:48:59 -07001458 /** @hide */
1459 public static MotionEvent createFromParcelBody(Parcel in) {
1460 final int NP = in.readInt();
1461 final int NS = in.readInt();
1462 final int NI = NP * NS * NUM_SAMPLE_DATA;
1463
1464 MotionEvent ev = obtain(NP, NS);
1465 ev.mNumPointers = NP;
1466 ev.mNumSamples = NS;
1467
1468 ev.readBaseFromParcel(in);
1469
1470 ev.mDownTimeNano = in.readLong();
1471 ev.mAction = in.readInt();
1472 ev.mXOffset = in.readFloat();
1473 ev.mYOffset = in.readFloat();
1474 ev.mXPrecision = in.readFloat();
1475 ev.mYPrecision = in.readFloat();
1476 ev.mEdgeFlags = in.readInt();
1477 ev.mMetaState = in.readInt();
1478
1479 final int[] pointerIdentifiers = ev.mPointerIdentifiers;
1480 for (int i = 0; i < NP; i++) {
1481 pointerIdentifiers[i] = in.readInt();
1482 }
1483
1484 final long[] eventTimeNanoSamples = ev.mEventTimeNanoSamples;
1485 for (int i = 0; i < NS; i++) {
1486 eventTimeNanoSamples[i] = in.readLong();
1487 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001488
Jeff Brown6ec402b2010-07-28 15:48:59 -07001489 final float[] dataSamples = ev.mDataSamples;
1490 for (int i = 0; i < NI; i++) {
1491 dataSamples[i] = in.readFloat();
1492 }
1493
1494 ev.mLastEventTimeNanoSampleIndex = NS - 1;
1495 ev.mLastDataSampleIndex = (NS - 1) * NP * NUM_SAMPLE_DATA;
1496 return ev;
1497 }
1498
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001499 public void writeToParcel(Parcel out, int flags) {
Jeff Brown6ec402b2010-07-28 15:48:59 -07001500 out.writeInt(PARCEL_TOKEN_MOTION_EVENT);
1501
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001502 final int NP = mNumPointers;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001503 final int NS = mNumSamples;
Jeff Brown5c225b12010-06-16 01:53:36 -07001504 final int NI = NP * NS * NUM_SAMPLE_DATA;
1505
1506 out.writeInt(NP);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001507 out.writeInt(NS);
Jeff Brown5c225b12010-06-16 01:53:36 -07001508
Jeff Brown6ec402b2010-07-28 15:48:59 -07001509 writeBaseToParcel(out);
1510
Jeff Brown5c225b12010-06-16 01:53:36 -07001511 out.writeLong(mDownTimeNano);
1512 out.writeInt(mAction);
1513 out.writeFloat(mXOffset);
1514 out.writeFloat(mYOffset);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001515 out.writeFloat(mXPrecision);
1516 out.writeFloat(mYPrecision);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001517 out.writeInt(mEdgeFlags);
Jeff Brown5c225b12010-06-16 01:53:36 -07001518 out.writeInt(mMetaState);
1519
1520 final int[] pointerIdentifiers = mPointerIdentifiers;
1521 for (int i = 0; i < NP; i++) {
1522 out.writeInt(pointerIdentifiers[i]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001523 }
Jeff Brown5c225b12010-06-16 01:53:36 -07001524
1525 final long[] eventTimeNanoSamples = mEventTimeNanoSamples;
1526 for (int i = 0; i < NS; i++) {
1527 out.writeLong(eventTimeNanoSamples[i]);
1528 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001529
Jeff Brown5c225b12010-06-16 01:53:36 -07001530 final float[] dataSamples = mDataSamples;
1531 for (int i = 0; i < NI; i++) {
1532 out.writeFloat(dataSamples[i]);
1533 }
1534 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07001535
1536 /**
1537 * Transfer object for pointer coordinates.
1538 *
1539 * Objects of this type can be used to manufacture new {@link MotionEvent} objects
1540 * and to query pointer coordinate information in bulk.
1541 *
1542 * Refer to {@link InputDevice} for information about how different kinds of
1543 * input devices and sources represent pointer coordinates.
1544 */
1545 public static final class PointerCoords {
1546 /**
1547 * The X coordinate of the pointer movement.
1548 * The interpretation varies by input source and may represent the position of
1549 * the center of the contact area, a relative displacement in device-specific units
1550 * or something else.
1551 */
1552 public float x;
1553
1554 /**
1555 * The Y coordinate of the pointer movement.
1556 * The interpretation varies by input source and may represent the position of
1557 * the center of the contact area, a relative displacement in device-specific units
1558 * or something else.
1559 */
1560 public float y;
1561
1562 /**
1563 * A scaled value that describes the pressure applied to the pointer.
1564 * The pressure generally ranges from 0 (no pressure at all) to 1 (normal pressure),
1565 * however values higher than 1 may be generated depending on the calibration of
1566 * the input device.
1567 */
1568 public float pressure;
1569
1570 /**
1571 * A scaled value of the approximate size of the pointer touch area.
1572 * This represents some approximation of the area of the screen being
1573 * pressed; the actual value in pixels corresponding to the
1574 * touch is normalized with the device specific range of values
1575 * and scaled to a value between 0 and 1. The value of size can be used to
1576 * determine fat touch events.
1577 */
1578 public float size;
1579
1580 /**
1581 * The length of the major axis of an ellipse that describes the touch area at
1582 * the point of contact.
1583 */
1584 public float touchMajor;
1585
1586 /**
1587 * The length of the minor axis of an ellipse that describes the touch area at
1588 * the point of contact.
1589 */
1590 public float touchMinor;
1591
1592 /**
1593 * The length of the major axis of an ellipse that describes the size of
1594 * the approaching tool.
1595 * The tool area represents the estimated size of the finger or pen that is
1596 * touching the device independent of its actual touch area at the point of contact.
1597 */
1598 public float toolMajor;
1599
1600 /**
1601 * The length of the minor axis of an ellipse that describes the size of
1602 * the approaching tool.
1603 * The tool area represents the estimated size of the finger or pen that is
1604 * touching the device independent of its actual touch area at the point of contact.
1605 */
1606 public float toolMinor;
1607
1608 /**
1609 * The orientation of the touch area and tool area in radians clockwise from vertical.
1610 * An angle of 0 degrees indicates that the major axis of contact is oriented
1611 * upwards, is perfectly circular or is of unknown orientation. A positive angle
1612 * indicates that the major axis of contact is oriented to the right. A negative angle
1613 * indicates that the major axis of contact is oriented to the left.
Jeff Brown6d0fec22010-07-23 21:28:06 -07001614 * The full range is from -PI/2 radians (finger pointing fully left) to PI/2 radians
Jeff Brownc5ed5912010-07-14 18:48:53 -07001615 * (finger pointing fully right).
1616 */
1617 public float orientation;
1618
1619 /*
Jeff Brown6d0fec22010-07-23 21:28:06 -07001620 private static final float PI_4 = (float) (Math.PI / 4);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001621
1622 public float getTouchWidth() {
Jeff Brown6d0fec22010-07-23 21:28:06 -07001623 return Math.abs(orientation) > PI_4 ? touchMajor : touchMinor;
Jeff Brownc5ed5912010-07-14 18:48:53 -07001624 }
1625
1626 public float getTouchHeight() {
Jeff Brown6d0fec22010-07-23 21:28:06 -07001627 return Math.abs(orientation) > PI_4 ? touchMinor : touchMajor;
Jeff Brownc5ed5912010-07-14 18:48:53 -07001628 }
1629
1630 public float getToolWidth() {
Jeff Brown6d0fec22010-07-23 21:28:06 -07001631 return Math.abs(orientation) > PI_4 ? toolMajor : toolMinor;
Jeff Brownc5ed5912010-07-14 18:48:53 -07001632 }
1633
1634 public float getToolHeight() {
Jeff Brown6d0fec22010-07-23 21:28:06 -07001635 return Math.abs(orientation) > PI_4 ? toolMinor : toolMajor;
Jeff Brownc5ed5912010-07-14 18:48:53 -07001636 }
1637 */
1638 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001639}