blob: 98fe73f891d441dd3496f8880de959a408ae9979 [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
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700180 /**
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700181 * Offset for the sample's X coordinate.
182 * @hide
183 */
Jeff Brown6d0fec22010-07-23 21:28:06 -0700184 static private final int SAMPLE_X = 0;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700185
186 /**
187 * Offset for the sample's Y coordinate.
188 * @hide
189 */
Jeff Brown6d0fec22010-07-23 21:28:06 -0700190 static private final int SAMPLE_Y = 1;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700191
192 /**
Jeff Brownc5ed5912010-07-14 18:48:53 -0700193 * Offset for the sample's pressure.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700194 * @hide
195 */
Jeff Brown6d0fec22010-07-23 21:28:06 -0700196 static private final int SAMPLE_PRESSURE = 2;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700197
198 /**
Jeff Brownc5ed5912010-07-14 18:48:53 -0700199 * Offset for the sample's size
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700200 * @hide
201 */
Jeff Brown6d0fec22010-07-23 21:28:06 -0700202 static private final int SAMPLE_SIZE = 3;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700203
204 /**
Jeff Brownc5ed5912010-07-14 18:48:53 -0700205 * Offset for the sample's touch major axis length.
206 * @hide
207 */
Jeff Brown6d0fec22010-07-23 21:28:06 -0700208 static private final int SAMPLE_TOUCH_MAJOR = 4;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700209
210 /**
211 * Offset for the sample's touch minor axis length.
212 * @hide
213 */
Jeff Brown6d0fec22010-07-23 21:28:06 -0700214 static private final int SAMPLE_TOUCH_MINOR = 5;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700215
216 /**
217 * Offset for the sample's tool major axis length.
218 * @hide
219 */
Jeff Brown6d0fec22010-07-23 21:28:06 -0700220 static private final int SAMPLE_TOOL_MAJOR = 6;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700221
222 /**
223 * Offset for the sample's tool minor axis length.
224 * @hide
225 */
Jeff Brown6d0fec22010-07-23 21:28:06 -0700226 static private final int SAMPLE_TOOL_MINOR = 7;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700227
228 /**
229 * Offset for the sample's orientation.
230 * @hide
231 */
Jeff Brown6d0fec22010-07-23 21:28:06 -0700232 static private final int SAMPLE_ORIENTATION = 8;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700233
234 /**
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700235 * Number of data items for each sample.
236 * @hide
237 */
Jeff Brown6d0fec22010-07-23 21:28:06 -0700238 static private final int NUM_SAMPLE_DATA = 9;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700239
Dianne Hackborn1e8dfc72009-08-06 12:43:01 -0700240 /**
241 * Number of possible pointers.
242 * @hide
243 */
244 static public final int BASE_AVAIL_POINTERS = 5;
245
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700246 static private final int BASE_AVAIL_SAMPLES = 8;
247
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800248 static private final int MAX_RECYCLED = 10;
249 static private Object gRecyclerLock = new Object();
250 static private int gRecyclerUsed = 0;
251 static private MotionEvent gRecyclerTop = null;
Romain Guycafdea62009-06-12 10:51:36 -0700252
Jeff Brown5c225b12010-06-16 01:53:36 -0700253 private long mDownTimeNano;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800254 private int mAction;
Jeff Brown5c225b12010-06-16 01:53:36 -0700255 private float mXOffset;
256 private float mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800257 private float mXPrecision;
258 private float mYPrecision;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800259 private int mEdgeFlags;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700260 private int mMetaState;
261
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700262 private int mNumPointers;
263 private int mNumSamples;
Jeff Brown5c225b12010-06-16 01:53:36 -0700264
265 private int mLastDataSampleIndex;
266 private int mLastEventTimeNanoSampleIndex;
267
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700268 // Array of mNumPointers size of identifiers for each pointer of data.
269 private int[] mPointerIdentifiers;
Jeff Brown5c225b12010-06-16 01:53:36 -0700270
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700271 // Array of (mNumSamples * mNumPointers * NUM_SAMPLE_DATA) size of event data.
Jeff Brown5c225b12010-06-16 01:53:36 -0700272 // Samples are ordered from oldest to newest.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700273 private float[] mDataSamples;
Jeff Brown5c225b12010-06-16 01:53:36 -0700274
275 // Array of mNumSamples size of event time stamps in nanoseconds.
276 // Samples are ordered from oldest to newest.
277 private long[] mEventTimeNanoSamples;
Mitsuru Oshima8169dae2009-04-28 18:12:09 -0700278
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800279 private MotionEvent mNext;
280 private RuntimeException mRecycledLocation;
281 private boolean mRecycled;
282
Jeff Brown46b9ac02010-04-22 18:58:52 -0700283 private MotionEvent(int pointerCount, int sampleCount) {
284 mPointerIdentifiers = new int[pointerCount];
285 mDataSamples = new float[pointerCount * sampleCount * NUM_SAMPLE_DATA];
Jeff Brown5c225b12010-06-16 01:53:36 -0700286 mEventTimeNanoSamples = new long[sampleCount];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800287 }
Romain Guycafdea62009-06-12 10:51:36 -0700288
Jeff Brown46b9ac02010-04-22 18:58:52 -0700289 static private MotionEvent obtain(int pointerCount, int sampleCount) {
290 final MotionEvent ev;
291 synchronized (gRecyclerLock) {
292 if (gRecyclerTop == null) {
293 if (pointerCount < BASE_AVAIL_POINTERS) {
294 pointerCount = BASE_AVAIL_POINTERS;
295 }
296 if (sampleCount < BASE_AVAIL_SAMPLES) {
297 sampleCount = BASE_AVAIL_SAMPLES;
298 }
299 return new MotionEvent(pointerCount, sampleCount);
300 }
301 ev = gRecyclerTop;
302 gRecyclerTop = ev.mNext;
Jeff Brown5c225b12010-06-16 01:53:36 -0700303 gRecyclerUsed -= 1;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700304 }
305 ev.mRecycledLocation = null;
306 ev.mRecycled = false;
307 ev.mNext = null;
308
309 if (ev.mPointerIdentifiers.length < pointerCount) {
310 ev.mPointerIdentifiers = new int[pointerCount];
311 }
312
Jeff Brown5c225b12010-06-16 01:53:36 -0700313 if (ev.mEventTimeNanoSamples.length < sampleCount) {
314 ev.mEventTimeNanoSamples = new long[sampleCount];
Jeff Brown46b9ac02010-04-22 18:58:52 -0700315 }
316
Jeff Brown46b9ac02010-04-22 18:58:52 -0700317 final int neededDataSamplesLength = pointerCount * sampleCount * NUM_SAMPLE_DATA;
Jeff Brown5c225b12010-06-16 01:53:36 -0700318 if (ev.mDataSamples.length < neededDataSamplesLength) {
Jeff Brown46b9ac02010-04-22 18:58:52 -0700319 ev.mDataSamples = new float[neededDataSamplesLength];
320 }
321
322 return ev;
323 }
Jeff Brown5c225b12010-06-16 01:53:36 -0700324
Michael Chan53071d62009-05-13 17:29:48 -0700325 /**
326 * Create a new MotionEvent, filling in all of the basic values that
327 * define the motion.
328 *
329 * @param downTime The time (in ms) when the user originally pressed down to start
330 * a stream of position events. This must be obtained from {@link SystemClock#uptimeMillis()}.
Jeff Brownc5ed5912010-07-14 18:48:53 -0700331 * @param eventTime The the time (in ms) when this specific event was generated. This
Michael Chan53071d62009-05-13 17:29:48 -0700332 * must be obtained from {@link SystemClock#uptimeMillis()}.
Michael Chan53071d62009-05-13 17:29:48 -0700333 * @param action The kind of action being performed -- one of either
334 * {@link #ACTION_DOWN}, {@link #ACTION_MOVE}, {@link #ACTION_UP}, or
335 * {@link #ACTION_CANCEL}.
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700336 * @param pointers The number of points that will be in this event.
Jeff Brownc5ed5912010-07-14 18:48:53 -0700337 * @param pointerIds An array of <em>pointers</em> values providing
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700338 * an identifier for each pointer.
Jeff Brownc5ed5912010-07-14 18:48:53 -0700339 * @param pointerCoords An array of <em>pointers</em> values providing
340 * a {@link PointerCoords} coordinate object for each pointer.
Michael Chan53071d62009-05-13 17:29:48 -0700341 * @param metaState The state of any meta / modifier keys that were in effect when
342 * the event was generated.
343 * @param xPrecision The precision of the X coordinate being reported.
344 * @param yPrecision The precision of the Y coordinate being reported.
345 * @param deviceId The id for the device that this event came from. An id of
346 * zero indicates that the event didn't come from a physical device; other
347 * numbers are arbitrary and you shouldn't depend on the values.
348 * @param edgeFlags A bitfield indicating which edges, if any, where touched by this
349 * MotionEvent.
Jeff Brownc5ed5912010-07-14 18:48:53 -0700350 * @param source The source of this event.
Michael Chan53071d62009-05-13 17:29:48 -0700351 */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700352 static public MotionEvent obtain(long downTime, long eventTime,
353 int action, int pointers, int[] pointerIds, PointerCoords[] pointerCoords,
354 int metaState, float xPrecision, float yPrecision, int deviceId,
355 int edgeFlags, int source) {
Jeff Brown5c225b12010-06-16 01:53:36 -0700356 MotionEvent ev = obtain(pointers, 1);
Michael Chan53071d62009-05-13 17:29:48 -0700357 ev.mDeviceId = deviceId;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700358 ev.mSource = source;
Michael Chan53071d62009-05-13 17:29:48 -0700359 ev.mEdgeFlags = edgeFlags;
Jeff Brown5c225b12010-06-16 01:53:36 -0700360 ev.mDownTimeNano = downTime * MS_PER_NS;
Michael Chan53071d62009-05-13 17:29:48 -0700361 ev.mAction = action;
Michael Chan53071d62009-05-13 17:29:48 -0700362 ev.mMetaState = metaState;
Jeff Brown5c225b12010-06-16 01:53:36 -0700363 ev.mXOffset = 0;
364 ev.mYOffset = 0;
Michael Chan53071d62009-05-13 17:29:48 -0700365 ev.mXPrecision = xPrecision;
366 ev.mYPrecision = yPrecision;
Jeff Brown5c225b12010-06-16 01:53:36 -0700367
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700368 ev.mNumPointers = pointers;
369 ev.mNumSamples = 1;
370
Jeff Brown5c225b12010-06-16 01:53:36 -0700371 ev.mLastDataSampleIndex = 0;
372 ev.mLastEventTimeNanoSampleIndex = 0;
Dianne Hackborn1e8dfc72009-08-06 12:43:01 -0700373
Jeff Brownc5ed5912010-07-14 18:48:53 -0700374 System.arraycopy(pointerIds, 0, ev.mPointerIdentifiers, 0, pointers);
Dianne Hackborn1e8dfc72009-08-06 12:43:01 -0700375
Jeff Brownc5ed5912010-07-14 18:48:53 -0700376 ev.mEventTimeNanoSamples[0] = eventTime * MS_PER_NS;
Jeff Brown5c225b12010-06-16 01:53:36 -0700377
Jeff Brownc5ed5912010-07-14 18:48:53 -0700378 ev.setPointerCoordsAtSampleIndex(0, pointerCoords);
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700379
Michael Chan53071d62009-05-13 17:29:48 -0700380 return ev;
381 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800382
383 /**
384 * Create a new MotionEvent, filling in all of the basic values that
385 * define the motion.
Romain Guycafdea62009-06-12 10:51:36 -0700386 *
387 * @param downTime The time (in ms) when the user originally pressed down to start
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800388 * a stream of position events. This must be obtained from {@link SystemClock#uptimeMillis()}.
Romain Guycafdea62009-06-12 10:51:36 -0700389 * @param eventTime The the time (in ms) when this specific event was generated. This
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800390 * must be obtained from {@link SystemClock#uptimeMillis()}.
391 * @param action The kind of action being performed -- one of either
392 * {@link #ACTION_DOWN}, {@link #ACTION_MOVE}, {@link #ACTION_UP}, or
393 * {@link #ACTION_CANCEL}.
394 * @param x The X coordinate of this event.
395 * @param y The Y coordinate of this event.
Romain Guycafdea62009-06-12 10:51:36 -0700396 * @param pressure The current pressure of this event. The pressure generally
397 * ranges from 0 (no pressure at all) to 1 (normal pressure), however
398 * values higher than 1 may be generated depending on the calibration of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800399 * the input device.
400 * @param size A scaled value of the approximate size of the area being pressed when
Romain Guycafdea62009-06-12 10:51:36 -0700401 * touched with the finger. The actual value in pixels corresponding to the finger
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800402 * touch is normalized with a device specific range of values
403 * and scaled to a value between 0 and 1.
404 * @param metaState The state of any meta / modifier keys that were in effect when
405 * the event was generated.
406 * @param xPrecision The precision of the X coordinate being reported.
407 * @param yPrecision The precision of the Y coordinate being reported.
408 * @param deviceId The id for the device that this event came from. An id of
409 * zero indicates that the event didn't come from a physical device; other
410 * numbers are arbitrary and you shouldn't depend on the values.
411 * @param edgeFlags A bitfield indicating which edges, if any, where touched by this
412 * MotionEvent.
413 */
414 static public MotionEvent obtain(long downTime, long eventTime, int action,
415 float x, float y, float pressure, float size, int metaState,
416 float xPrecision, float yPrecision, int deviceId, int edgeFlags) {
Jeff Brown5c225b12010-06-16 01:53:36 -0700417 MotionEvent ev = obtain(1, 1);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800418 ev.mDeviceId = deviceId;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700419 ev.mSource = InputDevice.SOURCE_UNKNOWN;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800420 ev.mEdgeFlags = edgeFlags;
Jeff Brown5c225b12010-06-16 01:53:36 -0700421 ev.mDownTimeNano = downTime * MS_PER_NS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800422 ev.mAction = action;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800423 ev.mMetaState = metaState;
Jeff Brown5c225b12010-06-16 01:53:36 -0700424 ev.mXOffset = 0;
425 ev.mYOffset = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800426 ev.mXPrecision = xPrecision;
427 ev.mYPrecision = yPrecision;
Jeff Brown5c225b12010-06-16 01:53:36 -0700428
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700429 ev.mNumPointers = 1;
430 ev.mNumSamples = 1;
Jeff Brown5c225b12010-06-16 01:53:36 -0700431
432 ev.mLastDataSampleIndex = 0;
433 ev.mLastEventTimeNanoSampleIndex = 0;
434
435 ev.mPointerIdentifiers[0] = 0;
436
437 ev.mEventTimeNanoSamples[0] = eventTime * MS_PER_NS;
438
Jeff Brownc5ed5912010-07-14 18:48:53 -0700439 ev.setPointerCoordsAtSampleIndex(0, x, y, pressure, size);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700440 return ev;
441 }
442
443 /**
444 * Create a new MotionEvent, filling in all of the basic values that
445 * define the motion.
446 *
447 * @param downTime The time (in ms) when the user originally pressed down to start
448 * a stream of position events. This must be obtained from {@link SystemClock#uptimeMillis()}.
449 * @param eventTime The the time (in ms) when this specific event was generated. This
450 * must be obtained from {@link SystemClock#uptimeMillis()}.
451 * @param action The kind of action being performed -- one of either
452 * {@link #ACTION_DOWN}, {@link #ACTION_MOVE}, {@link #ACTION_UP}, or
453 * {@link #ACTION_CANCEL}.
454 * @param pointers The number of pointers that are active in this event.
455 * @param x The X coordinate of this event.
456 * @param y The Y coordinate of this event.
457 * @param pressure The current pressure of this event. The pressure generally
458 * ranges from 0 (no pressure at all) to 1 (normal pressure), however
459 * values higher than 1 may be generated depending on the calibration of
460 * the input device.
461 * @param size A scaled value of the approximate size of the area being pressed when
462 * touched with the finger. The actual value in pixels corresponding to the finger
463 * touch is normalized with a device specific range of values
464 * and scaled to a value between 0 and 1.
465 * @param metaState The state of any meta / modifier keys that were in effect when
466 * the event was generated.
467 * @param xPrecision The precision of the X coordinate being reported.
468 * @param yPrecision The precision of the Y coordinate being reported.
469 * @param deviceId The id for the device that this event came from. An id of
470 * zero indicates that the event didn't come from a physical device; other
471 * numbers are arbitrary and you shouldn't depend on the values.
472 * @param edgeFlags A bitfield indicating which edges, if any, where touched by this
473 * MotionEvent.
Jeff Brown5c225b12010-06-16 01:53:36 -0700474 *
475 * @deprecated Use {@link #obtain(long, long, int, float, float, float, float, int, float, float, int, int)}
476 * instead.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700477 */
Jeff Brown5c225b12010-06-16 01:53:36 -0700478 @Deprecated
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700479 static public MotionEvent obtain(long downTime, long eventTime, int action,
480 int pointers, float x, float y, float pressure, float size, int metaState,
481 float xPrecision, float yPrecision, int deviceId, int edgeFlags) {
Jeff Brown5c225b12010-06-16 01:53:36 -0700482 return obtain(downTime, eventTime, action, x, y, pressure, size,
483 metaState, xPrecision, yPrecision, deviceId, edgeFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800484 }
Romain Guycafdea62009-06-12 10:51:36 -0700485
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800486 /**
487 * Create a new MotionEvent, filling in a subset of the basic motion
488 * values. Those not specified here are: device id (always 0), pressure
489 * and size (always 1), x and y precision (always 1), and edgeFlags (always 0).
Romain Guycafdea62009-06-12 10:51:36 -0700490 *
491 * @param downTime The time (in ms) when the user originally pressed down to start
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800492 * a stream of position events. This must be obtained from {@link SystemClock#uptimeMillis()}.
Romain Guycafdea62009-06-12 10:51:36 -0700493 * @param eventTime The the time (in ms) when this specific event was generated. This
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800494 * must be obtained from {@link SystemClock#uptimeMillis()}.
495 * @param action The kind of action being performed -- one of either
496 * {@link #ACTION_DOWN}, {@link #ACTION_MOVE}, {@link #ACTION_UP}, or
497 * {@link #ACTION_CANCEL}.
498 * @param x The X coordinate of this event.
499 * @param y The Y coordinate of this event.
500 * @param metaState The state of any meta / modifier keys that were in effect when
501 * the event was generated.
502 */
503 static public MotionEvent obtain(long downTime, long eventTime, int action,
504 float x, float y, int metaState) {
Jeff Brown5c225b12010-06-16 01:53:36 -0700505 return obtain(downTime, eventTime, action, x, y, 1.0f, 1.0f,
506 metaState, 1.0f, 1.0f, 0, 0);
Mitsuru Oshima8169dae2009-04-28 18:12:09 -0700507 }
508
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800509 /**
510 * Create a new MotionEvent, copying from an existing one.
511 */
512 static public MotionEvent obtain(MotionEvent o) {
Jeff Brown5c225b12010-06-16 01:53:36 -0700513 MotionEvent ev = obtain(o.mNumPointers, o.mNumSamples);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800514 ev.mDeviceId = o.mDeviceId;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700515 ev.mSource = o.mSource;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800516 ev.mEdgeFlags = o.mEdgeFlags;
Jeff Brown5c225b12010-06-16 01:53:36 -0700517 ev.mDownTimeNano = o.mDownTimeNano;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800518 ev.mAction = o.mAction;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800519 ev.mMetaState = o.mMetaState;
Jeff Brown5c225b12010-06-16 01:53:36 -0700520 ev.mXOffset = o.mXOffset;
521 ev.mYOffset = o.mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800522 ev.mXPrecision = o.mXPrecision;
523 ev.mYPrecision = o.mYPrecision;
Jeff Brown5c225b12010-06-16 01:53:36 -0700524 int numPointers = ev.mNumPointers = o.mNumPointers;
525 int numSamples = ev.mNumSamples = o.mNumSamples;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700526
Jeff Brown5c225b12010-06-16 01:53:36 -0700527 ev.mLastDataSampleIndex = o.mLastDataSampleIndex;
528 ev.mLastEventTimeNanoSampleIndex = o.mLastEventTimeNanoSampleIndex;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700529
Jeff Brown5c225b12010-06-16 01:53:36 -0700530 System.arraycopy(o.mPointerIdentifiers, 0, ev.mPointerIdentifiers, 0, numPointers);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700531
Jeff Brown5c225b12010-06-16 01:53:36 -0700532 System.arraycopy(o.mEventTimeNanoSamples, 0, ev.mEventTimeNanoSamples, 0, numSamples);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700533
Jeff Brown5c225b12010-06-16 01:53:36 -0700534 System.arraycopy(o.mDataSamples, 0, ev.mDataSamples, 0,
535 numPointers * numSamples * NUM_SAMPLE_DATA);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800536 return ev;
537 }
Romain Guycafdea62009-06-12 10:51:36 -0700538
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800539 /**
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -0700540 * Create a new MotionEvent, copying from an existing one, but not including
541 * any historical point information.
542 */
543 static public MotionEvent obtainNoHistory(MotionEvent o) {
Jeff Brown5c225b12010-06-16 01:53:36 -0700544 MotionEvent ev = obtain(o.mNumPointers, 1);
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -0700545 ev.mDeviceId = o.mDeviceId;
Jeff Brownc5ed5912010-07-14 18:48:53 -0700546 ev.mSource = o.mSource;
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -0700547 ev.mEdgeFlags = o.mEdgeFlags;
Jeff Brown5c225b12010-06-16 01:53:36 -0700548 ev.mDownTimeNano = o.mDownTimeNano;
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -0700549 ev.mAction = o.mAction;
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -0700550 ev.mMetaState = o.mMetaState;
Jeff Brown5c225b12010-06-16 01:53:36 -0700551 ev.mXOffset = o.mXOffset;
552 ev.mYOffset = o.mYOffset;
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -0700553 ev.mXPrecision = o.mXPrecision;
554 ev.mYPrecision = o.mYPrecision;
555
Jeff Brown5c225b12010-06-16 01:53:36 -0700556 int numPointers = ev.mNumPointers = o.mNumPointers;
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -0700557 ev.mNumSamples = 1;
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -0700558
Jeff Brown5c225b12010-06-16 01:53:36 -0700559 ev.mLastDataSampleIndex = 0;
560 ev.mLastEventTimeNanoSampleIndex = 0;
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -0700561
Jeff Brown5c225b12010-06-16 01:53:36 -0700562 System.arraycopy(o.mPointerIdentifiers, 0, ev.mPointerIdentifiers, 0, numPointers);
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -0700563
Jeff Brown5c225b12010-06-16 01:53:36 -0700564 ev.mEventTimeNanoSamples[0] = o.mEventTimeNanoSamples[o.mLastEventTimeNanoSampleIndex];
565
566 System.arraycopy(o.mDataSamples, o.mLastDataSampleIndex, ev.mDataSamples, 0,
567 numPointers * NUM_SAMPLE_DATA);
Dianne Hackborn8df8b2b2009-08-17 15:15:18 -0700568 return ev;
569 }
570
571 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800572 * Recycle the MotionEvent, to be re-used by a later caller. After calling
573 * this function you must not ever touch the event again.
574 */
Jeff Brown5c225b12010-06-16 01:53:36 -0700575 public final void recycle() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800576 // Ensure recycle is only called once!
577 if (TRACK_RECYCLED_LOCATION) {
578 if (mRecycledLocation != null) {
579 throw new RuntimeException(toString() + " recycled twice!", mRecycledLocation);
580 }
581 mRecycledLocation = new RuntimeException("Last recycled here");
Jeff Brownd28f4be2010-06-02 15:35:46 -0700582 //Log.w("MotionEvent", "Recycling event " + this, mRecycledLocation);
583 } else {
584 if (mRecycled) {
585 throw new RuntimeException(toString() + " recycled twice!");
586 }
587 mRecycled = true;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800588 }
589
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800590 synchronized (gRecyclerLock) {
591 if (gRecyclerUsed < MAX_RECYCLED) {
592 gRecyclerUsed++;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700593 mNumSamples = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800594 mNext = gRecyclerTop;
595 gRecyclerTop = this;
596 }
597 }
598 }
Jeff Brown5c225b12010-06-16 01:53:36 -0700599
600 /**
601 * Scales down the coordination of this event by the given scale.
602 *
603 * @hide
604 */
605 public final void scale(float scale) {
606 mXOffset *= scale;
607 mYOffset *= scale;
608 mXPrecision *= scale;
609 mYPrecision *= scale;
610
611 float[] history = mDataSamples;
612 final int length = mNumPointers * mNumSamples * NUM_SAMPLE_DATA;
613 for (int i = 0; i < length; i += NUM_SAMPLE_DATA) {
614 history[i + SAMPLE_X] *= scale;
615 history[i + SAMPLE_Y] *= scale;
616 // no need to scale pressure
617 history[i + SAMPLE_SIZE] *= scale; // TODO: square this?
Jeff Brownc5ed5912010-07-14 18:48:53 -0700618 history[i + SAMPLE_TOUCH_MAJOR] *= scale;
619 history[i + SAMPLE_TOUCH_MINOR] *= scale;
620 history[i + SAMPLE_TOOL_MAJOR] *= scale;
621 history[i + SAMPLE_TOOL_MINOR] *= scale;
Jeff Brown5c225b12010-06-16 01:53:36 -0700622 }
623 }
Romain Guycafdea62009-06-12 10:51:36 -0700624
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800625 /**
626 * Return the kind of action being performed -- one of either
627 * {@link #ACTION_DOWN}, {@link #ACTION_MOVE}, {@link #ACTION_UP}, or
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800628 * {@link #ACTION_CANCEL}. Consider using {@link #getActionMasked}
629 * and {@link #getActionIndex} to retrieve the separate masked action
630 * and pointer index.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800631 */
632 public final int getAction() {
633 return mAction;
634 }
635
636 /**
Dianne Hackbornb125dc52010-02-12 15:52:09 -0800637 * Return the masked action being performed, without pointer index
638 * information. May be any of the actions: {@link #ACTION_DOWN},
639 * {@link #ACTION_MOVE}, {@link #ACTION_UP}, {@link #ACTION_CANCEL},
640 * {@link #ACTION_POINTER_DOWN}, or {@link #ACTION_POINTER_UP}.
641 * Use {@link #getActionIndex} to return the index associated with
642 * pointer actions.
643 */
644 public final int getActionMasked() {
645 return mAction & ACTION_MASK;
646 }
647
648 /**
649 * For {@link #ACTION_POINTER_DOWN} or {@link #ACTION_POINTER_UP}
650 * as returned by {@link #getActionMasked}, this returns the associated
651 * pointer index. The index may be used with {@link #getPointerId(int)},
652 * {@link #getX(int)}, {@link #getY(int)}, {@link #getPressure(int)},
653 * and {@link #getSize(int)} to get information about the pointer that has
654 * gone down or up.
655 */
656 public final int getActionIndex() {
657 return (mAction & ACTION_POINTER_INDEX_MASK) >> ACTION_POINTER_INDEX_SHIFT;
658 }
659
660 /**
Romain Guycafdea62009-06-12 10:51:36 -0700661 * Returns the time (in ms) when the user originally pressed down to start
662 * a stream of position events.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800663 */
664 public final long getDownTime() {
Jeff Brown5c225b12010-06-16 01:53:36 -0700665 return mDownTimeNano / MS_PER_NS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800666 }
667
668 /**
669 * Returns the time (in ms) when this specific event was generated.
670 */
671 public final long getEventTime() {
Jeff Brown5c225b12010-06-16 01:53:36 -0700672 return mEventTimeNanoSamples[mLastEventTimeNanoSampleIndex] / MS_PER_NS;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800673 }
674
675 /**
Michael Chan53071d62009-05-13 17:29:48 -0700676 * Returns the time (in ns) when this specific event was generated.
677 * The value is in nanosecond precision but it may not have nanosecond accuracy.
678 *
679 * @hide
680 */
681 public final long getEventTimeNano() {
Jeff Brown5c225b12010-06-16 01:53:36 -0700682 return mEventTimeNanoSamples[mLastEventTimeNanoSampleIndex];
Michael Chan53071d62009-05-13 17:29:48 -0700683 }
684
685 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700686 * {@link #getX(int)} for the first pointer index (may be an
687 * arbitrary pointer identifier).
688 */
689 public final float getX() {
Jeff Brown5c225b12010-06-16 01:53:36 -0700690 return mDataSamples[mLastDataSampleIndex + SAMPLE_X] + mXOffset;
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700691 }
692
693 /**
694 * {@link #getY(int)} for the first pointer index (may be an
695 * arbitrary pointer identifier).
696 */
697 public final float getY() {
Jeff Brown5c225b12010-06-16 01:53:36 -0700698 return mDataSamples[mLastDataSampleIndex + SAMPLE_Y] + mYOffset;
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700699 }
700
701 /**
702 * {@link #getPressure(int)} for the first pointer index (may be an
703 * arbitrary pointer identifier).
704 */
705 public final float getPressure() {
Jeff Brown5c225b12010-06-16 01:53:36 -0700706 return mDataSamples[mLastDataSampleIndex + SAMPLE_PRESSURE];
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700707 }
708
709 /**
710 * {@link #getSize(int)} for the first pointer index (may be an
711 * arbitrary pointer identifier).
712 */
713 public final float getSize() {
Jeff Brown5c225b12010-06-16 01:53:36 -0700714 return mDataSamples[mLastDataSampleIndex + SAMPLE_SIZE];
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700715 }
Jeff Brownc5ed5912010-07-14 18:48:53 -0700716
717 /**
718 * {@link #getTouchMajor(int)} for the first pointer index (may be an
719 * arbitrary pointer identifier).
720 */
721 public final float getTouchMajor() {
722 return mDataSamples[mLastDataSampleIndex + SAMPLE_TOUCH_MAJOR];
723 }
724
725 /**
726 * {@link #getTouchMinor(int)} for the first pointer index (may be an
727 * arbitrary pointer identifier).
728 */
729 public final float getTouchMinor() {
730 return mDataSamples[mLastDataSampleIndex + SAMPLE_TOUCH_MINOR];
731 }
732
733 /**
734 * {@link #getToolMajor(int)} for the first pointer index (may be an
735 * arbitrary pointer identifier).
736 */
737 public final float getToolMajor() {
738 return mDataSamples[mLastDataSampleIndex + SAMPLE_TOOL_MAJOR];
739 }
740
741 /**
742 * {@link #getToolMinor(int)} for the first pointer index (may be an
743 * arbitrary pointer identifier).
744 */
745 public final float getToolMinor() {
746 return mDataSamples[mLastDataSampleIndex + SAMPLE_TOOL_MINOR];
747 }
748
749 /**
750 * {@link #getOrientation(int)} for the first pointer index (may be an
751 * arbitrary pointer identifier).
752 */
753 public final float getOrientation() {
754 return mDataSamples[mLastDataSampleIndex + SAMPLE_ORIENTATION];
755 }
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700756
757 /**
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700758 * The number of pointers of data contained in this event. Always
759 * >= 1.
760 */
761 public final int getPointerCount() {
762 return mNumPointers;
763 }
764
765 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700766 * Return the pointer identifier associated with a particular pointer
767 * data index is this event. The identifier tells you the actual pointer
768 * number associated with the data, accounting for individual pointers
769 * going up and down since the start of the current gesture.
770 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
771 * (the first pointer that is down) to {@link #getPointerCount()}-1.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800772 */
Dianne Hackbornd41ba662009-08-05 15:30:56 -0700773 public final int getPointerId(int pointerIndex) {
774 return mPointerIdentifiers[pointerIndex];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800775 }
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700776
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800777 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700778 * Given a pointer identifier, find the index of its data in the event.
779 *
780 * @param pointerId The identifier of the pointer to be found.
781 * @return Returns either the index of the pointer (for use with
782 * {@link #getX(int) et al.), or -1 if there is no data available for
783 * that pointer identifier.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800784 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700785 public final int findPointerIndex(int pointerId) {
786 int i = mNumPointers;
787 while (i > 0) {
788 i--;
789 if (mPointerIdentifiers[i] == pointerId) {
790 return i;
791 }
792 }
793 return -1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800794 }
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700795
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800796 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700797 * Returns the X coordinate of this event for the given pointer
798 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
799 * identifier for this index).
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700800 * Whole numbers are pixels; the
801 * value may have a fraction for input devices that are sub-pixel precise.
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700802 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
803 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700804 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700805 public final float getX(int pointerIndex) {
Jeff Brown5c225b12010-06-16 01:53:36 -0700806 return mDataSamples[mLastDataSampleIndex
807 + pointerIndex * NUM_SAMPLE_DATA + SAMPLE_X] + mXOffset;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700808 }
809
810 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700811 * Returns the Y coordinate of this event for the given pointer
812 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
813 * identifier for this index).
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700814 * Whole numbers are pixels; the
815 * value may have a fraction for input devices that are sub-pixel precise.
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700816 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
817 * (the first pointer that is down) to {@link #getPointerCount()}-1.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700818 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700819 public final float getY(int pointerIndex) {
Jeff Brown5c225b12010-06-16 01:53:36 -0700820 return mDataSamples[mLastDataSampleIndex
821 + pointerIndex * NUM_SAMPLE_DATA + SAMPLE_Y] + mYOffset;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700822 }
823
824 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700825 * Returns the current pressure of this event for the given pointer
826 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
827 * identifier for this index).
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700828 * The pressure generally
Romain Guycafdea62009-06-12 10:51:36 -0700829 * ranges from 0 (no pressure at all) to 1 (normal pressure), however
830 * values higher than 1 may be generated depending on the calibration of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800831 * the input device.
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700832 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
833 * (the first pointer that is down) to {@link #getPointerCount()}-1.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800834 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700835 public final float getPressure(int pointerIndex) {
Jeff Brown5c225b12010-06-16 01:53:36 -0700836 return mDataSamples[mLastDataSampleIndex
837 + pointerIndex * NUM_SAMPLE_DATA + SAMPLE_PRESSURE];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800838 }
839
840 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700841 * Returns a scaled value of the approximate size for the given pointer
842 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
843 * identifier for this index).
844 * This represents some approximation of the area of the screen being
845 * pressed; the actual value in pixels corresponding to the
Dianne Hackborn9822d2b2009-07-20 17:33:15 -0700846 * touch is normalized with the device specific range of values
Romain Guycafdea62009-06-12 10:51:36 -0700847 * 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 -0800848 * determine fat touch events.
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700849 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
850 * (the first pointer that is down) to {@link #getPointerCount()}-1.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800851 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -0700852 public final float getSize(int pointerIndex) {
Jeff Brown5c225b12010-06-16 01:53:36 -0700853 return mDataSamples[mLastDataSampleIndex
854 + pointerIndex * NUM_SAMPLE_DATA + SAMPLE_SIZE];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800855 }
Jeff Brownc5ed5912010-07-14 18:48:53 -0700856
857 /**
858 * Returns the length of the major axis of an ellipse that describes the touch
859 * area at the point of contact for the given pointer
860 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
861 * identifier for this index).
862 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
863 * (the first pointer that is down) to {@link #getPointerCount()}-1.
864 */
865 public final float getTouchMajor(int pointerIndex) {
866 return mDataSamples[mLastDataSampleIndex
867 + pointerIndex * NUM_SAMPLE_DATA + SAMPLE_TOUCH_MAJOR];
868 }
869
870 /**
871 * Returns the length of the minor axis of an ellipse that describes the touch
872 * area at the point of contact for the given pointer
873 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
874 * identifier for this index).
875 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
876 * (the first pointer that is down) to {@link #getPointerCount()}-1.
877 */
878 public final float getTouchMinor(int pointerIndex) {
879 return mDataSamples[mLastDataSampleIndex
880 + pointerIndex * NUM_SAMPLE_DATA + SAMPLE_TOUCH_MINOR];
881 }
882
883 /**
884 * Returns the length of the major axis of an ellipse that describes the size of
885 * the approaching tool for the given pointer
886 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
887 * identifier for this index).
888 * The tool area represents the estimated size of the finger or pen that is
889 * touching the device independent of its actual touch area at the point of contact.
890 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
891 * (the first pointer that is down) to {@link #getPointerCount()}-1.
892 */
893 public final float getToolMajor(int pointerIndex) {
894 return mDataSamples[mLastDataSampleIndex
895 + pointerIndex * NUM_SAMPLE_DATA + SAMPLE_TOOL_MAJOR];
896 }
897
898 /**
899 * Returns the length of the minor axis of an ellipse that describes the size of
900 * the approaching tool for the given pointer
901 * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
902 * identifier for this index).
903 * The tool area represents the estimated size of the finger or pen that is
904 * touching the device independent of its actual touch area at the point of contact.
905 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
906 * (the first pointer that is down) to {@link #getPointerCount()}-1.
907 */
908 public final float getToolMinor(int pointerIndex) {
909 return mDataSamples[mLastDataSampleIndex
910 + pointerIndex * NUM_SAMPLE_DATA + SAMPLE_TOOL_MINOR];
911 }
912
913 /**
914 * Returns the orientation of the touch area and tool area in radians clockwise from vertical
915 * for the given pointer <em>index</em> (use {@link #getPointerId(int)} to find the pointer
916 * identifier for this index).
917 * An angle of 0 degrees indicates that the major axis of contact is oriented
918 * upwards, is perfectly circular or is of unknown orientation. A positive angle
919 * indicates that the major axis of contact is oriented to the right. A negative angle
920 * indicates that the major axis of contact is oriented to the left.
Jeff Brown6d0fec22010-07-23 21:28:06 -0700921 * The full range is from -PI/2 radians (finger pointing fully left) to PI/2 radians
Jeff Brownc5ed5912010-07-14 18:48:53 -0700922 * (finger pointing fully right).
923 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
924 * (the first pointer that is down) to {@link #getPointerCount()}-1.
925 */
926 public final float getOrientation(int pointerIndex) {
927 return mDataSamples[mLastDataSampleIndex
928 + pointerIndex * NUM_SAMPLE_DATA + SAMPLE_ORIENTATION];
929 }
930
931 /**
932 * Populates a {@link PointerCoords} object with pointer coordinate data for
933 * the specified pointer index.
934 *
935 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
936 * (the first pointer that is down) to {@link #getPointerCount()}-1.
937 * @param outPointerCoords The pointer coordinate object to populate.
938 */
939 public final void getPointerCoords(int pointerIndex, PointerCoords outPointerCoords) {
940 final int sampleIndex = mLastDataSampleIndex + pointerIndex * NUM_SAMPLE_DATA;
941 getPointerCoordsAtSampleIndex(sampleIndex, outPointerCoords);
942 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800943
944 /**
945 * Returns the state of any meta / modifier keys that were in effect when
946 * the event was generated. This is the same values as those
947 * returned by {@link KeyEvent#getMetaState() KeyEvent.getMetaState}.
948 *
949 * @return an integer in which each bit set to 1 represents a pressed
950 * meta key
951 *
952 * @see KeyEvent#getMetaState()
953 */
954 public final int getMetaState() {
955 return mMetaState;
956 }
957
958 /**
959 * Returns the original raw X coordinate of this event. For touch
960 * events on the screen, this is the original location of the event
961 * on the screen, before it had been adjusted for the containing window
962 * and views.
963 */
964 public final float getRawX() {
Jeff Brown5c225b12010-06-16 01:53:36 -0700965 return mDataSamples[mLastDataSampleIndex + SAMPLE_X];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800966 }
Jeff Brownc5ed5912010-07-14 18:48:53 -0700967
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800968 /**
969 * Returns the original raw Y coordinate of this event. For touch
970 * events on the screen, this is the original location of the event
971 * on the screen, before it had been adjusted for the containing window
972 * and views.
973 */
974 public final float getRawY() {
Jeff Brown5c225b12010-06-16 01:53:36 -0700975 return mDataSamples[mLastDataSampleIndex + SAMPLE_Y];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800976 }
977
978 /**
979 * Return the precision of the X coordinates being reported. You can
980 * multiple this number with {@link #getX} to find the actual hardware
981 * value of the X coordinate.
982 * @return Returns the precision of X coordinates being reported.
983 */
984 public final float getXPrecision() {
985 return mXPrecision;
986 }
Romain Guycafdea62009-06-12 10:51:36 -0700987
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800988 /**
989 * Return the precision of the Y coordinates being reported. You can
990 * multiple this number with {@link #getY} to find the actual hardware
991 * value of the Y coordinate.
992 * @return Returns the precision of Y coordinates being reported.
993 */
994 public final float getYPrecision() {
995 return mYPrecision;
996 }
Romain Guycafdea62009-06-12 10:51:36 -0700997
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800998 /**
999 * Returns the number of historical points in this event. These are
1000 * movements that have occurred between this event and the previous event.
1001 * This only applies to ACTION_MOVE events -- all other actions will have
1002 * a size of 0.
Romain Guycafdea62009-06-12 10:51:36 -07001003 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001004 * @return Returns the number of historical points in the event.
1005 */
1006 public final int getHistorySize() {
Jeff Brown5c225b12010-06-16 01:53:36 -07001007 return mLastEventTimeNanoSampleIndex;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001008 }
Romain Guycafdea62009-06-12 10:51:36 -07001009
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001010 /**
1011 * Returns the time that a historical movement occurred between this event
1012 * and the previous event. Only applies to ACTION_MOVE events.
Romain Guycafdea62009-06-12 10:51:36 -07001013 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001014 * @param pos Which historical value to return; must be less than
1015 * {@link #getHistorySize}
Romain Guycafdea62009-06-12 10:51:36 -07001016 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001017 * @see #getHistorySize
1018 * @see #getEventTime
1019 */
1020 public final long getHistoricalEventTime(int pos) {
Jeff Brown5c225b12010-06-16 01:53:36 -07001021 return mEventTimeNanoSamples[pos] / MS_PER_NS;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001022 }
1023
1024 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001025 * {@link #getHistoricalX(int)} for the first pointer index (may be an
1026 * arbitrary pointer identifier).
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001027 */
1028 public final float getHistoricalX(int pos) {
Jeff Brown5c225b12010-06-16 01:53:36 -07001029 return mDataSamples[pos * mNumPointers * NUM_SAMPLE_DATA + SAMPLE_X] + mXOffset;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001030 }
1031
1032 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001033 * {@link #getHistoricalY(int)} for the first pointer index (may be an
1034 * arbitrary pointer identifier).
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001035 */
1036 public final float getHistoricalY(int pos) {
Jeff Brown5c225b12010-06-16 01:53:36 -07001037 return mDataSamples[pos * mNumPointers * NUM_SAMPLE_DATA + SAMPLE_Y] + mYOffset;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001038 }
1039
1040 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001041 * {@link #getHistoricalPressure(int)} for the first pointer index (may be an
1042 * arbitrary pointer identifier).
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001043 */
1044 public final float getHistoricalPressure(int pos) {
Jeff Brown5c225b12010-06-16 01:53:36 -07001045 return mDataSamples[pos * mNumPointers * NUM_SAMPLE_DATA + SAMPLE_PRESSURE];
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001046 }
1047
1048 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001049 * {@link #getHistoricalSize(int)} for the first pointer index (may be an
1050 * arbitrary pointer identifier).
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001051 */
1052 public final float getHistoricalSize(int pos) {
Jeff Brown5c225b12010-06-16 01:53:36 -07001053 return mDataSamples[pos * mNumPointers * NUM_SAMPLE_DATA + SAMPLE_SIZE];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001054 }
Romain Guycafdea62009-06-12 10:51:36 -07001055
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001056 /**
Jeff Brownc5ed5912010-07-14 18:48:53 -07001057 * {@link #getHistoricalTouchMajor(int)} for the first pointer index (may be an
1058 * arbitrary pointer identifier).
1059 */
1060 public final float getHistoricalTouchMajor(int pos) {
1061 return mDataSamples[pos * mNumPointers * NUM_SAMPLE_DATA + SAMPLE_TOUCH_MAJOR];
1062 }
1063
1064 /**
1065 * {@link #getHistoricalTouchMinor(int)} for the first pointer index (may be an
1066 * arbitrary pointer identifier).
1067 */
1068 public final float getHistoricalTouchMinor(int pos) {
1069 return mDataSamples[pos * mNumPointers * NUM_SAMPLE_DATA + SAMPLE_TOUCH_MINOR];
1070 }
1071
1072 /**
1073 * {@link #getHistoricalToolMajor(int)} for the first pointer index (may be an
1074 * arbitrary pointer identifier).
1075 */
1076 public final float getHistoricalToolMajor(int pos) {
1077 return mDataSamples[pos * mNumPointers * NUM_SAMPLE_DATA + SAMPLE_TOOL_MAJOR];
1078 }
1079
1080 /**
1081 * {@link #getHistoricalToolMinor(int)} for the first pointer index (may be an
1082 * arbitrary pointer identifier).
1083 */
1084 public final float getHistoricalToolMinor(int pos) {
1085 return mDataSamples[pos * mNumPointers * NUM_SAMPLE_DATA + SAMPLE_TOOL_MINOR];
1086 }
1087
1088 /**
1089 * {@link #getHistoricalOrientation(int)} for the first pointer index (may be an
1090 * arbitrary pointer identifier).
1091 */
1092 public final float getHistoricalOrientation(int pos) {
1093 return mDataSamples[pos * mNumPointers * NUM_SAMPLE_DATA + SAMPLE_ORIENTATION];
1094 }
1095
1096 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001097 * Returns a historical X coordinate, as per {@link #getX(int)}, that
1098 * occurred between this event and the previous event for the given pointer.
1099 * Only applies to ACTION_MOVE events.
Romain Guycafdea62009-06-12 10:51:36 -07001100 *
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001101 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1102 * (the first pointer that is down) to {@link #getPointerCount()}-1.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001103 * @param pos Which historical value to return; must be less than
1104 * {@link #getHistorySize}
Romain Guycafdea62009-06-12 10:51:36 -07001105 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001106 * @see #getHistorySize
1107 * @see #getX
1108 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001109 public final float getHistoricalX(int pointerIndex, int pos) {
Jeff Brown5c225b12010-06-16 01:53:36 -07001110 return mDataSamples[(pos * mNumPointers + pointerIndex)
1111 * NUM_SAMPLE_DATA + SAMPLE_X] + mXOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001112 }
Romain Guycafdea62009-06-12 10:51:36 -07001113
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001114 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001115 * Returns a historical Y coordinate, as per {@link #getY(int)}, that
1116 * occurred between this event and the previous event for the given pointer.
1117 * Only applies to ACTION_MOVE events.
Romain Guycafdea62009-06-12 10:51:36 -07001118 *
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001119 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1120 * (the first pointer that is down) to {@link #getPointerCount()}-1.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001121 * @param pos Which historical value to return; must be less than
1122 * {@link #getHistorySize}
Romain Guycafdea62009-06-12 10:51:36 -07001123 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001124 * @see #getHistorySize
1125 * @see #getY
1126 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001127 public final float getHistoricalY(int pointerIndex, int pos) {
Jeff Brown5c225b12010-06-16 01:53:36 -07001128 return mDataSamples[(pos * mNumPointers + pointerIndex)
1129 * NUM_SAMPLE_DATA + SAMPLE_Y] + mYOffset;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001130 }
Romain Guycafdea62009-06-12 10:51:36 -07001131
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001132 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001133 * Returns a historical pressure coordinate, as per {@link #getPressure(int)},
1134 * that occurred between this event and the previous event for the given
1135 * pointer. Only applies to ACTION_MOVE events.
Romain Guycafdea62009-06-12 10:51:36 -07001136 *
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001137 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1138 * (the first pointer that is down) to {@link #getPointerCount()}-1.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001139 * @param pos Which historical value to return; must be less than
1140 * {@link #getHistorySize}
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001141 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001142 * @see #getHistorySize
1143 * @see #getPressure
1144 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001145 public final float getHistoricalPressure(int pointerIndex, int pos) {
Jeff Brown5c225b12010-06-16 01:53:36 -07001146 return mDataSamples[(pos * mNumPointers + pointerIndex)
1147 * NUM_SAMPLE_DATA + SAMPLE_PRESSURE];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001148 }
Romain Guycafdea62009-06-12 10:51:36 -07001149
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001150 /**
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001151 * Returns a historical size coordinate, as per {@link #getSize(int)}, that
1152 * occurred between this event and the previous event for the given pointer.
1153 * Only applies to ACTION_MOVE events.
Romain Guycafdea62009-06-12 10:51:36 -07001154 *
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001155 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1156 * (the first pointer that is down) to {@link #getPointerCount()}-1.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001157 * @param pos Which historical value to return; must be less than
1158 * {@link #getHistorySize}
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001159 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001160 * @see #getHistorySize
1161 * @see #getSize
1162 */
Dianne Hackborn0dd7cb42009-08-04 05:49:43 -07001163 public final float getHistoricalSize(int pointerIndex, int pos) {
Jeff Brown5c225b12010-06-16 01:53:36 -07001164 return mDataSamples[(pos * mNumPointers + pointerIndex)
1165 * NUM_SAMPLE_DATA + SAMPLE_SIZE];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001166 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07001167
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001168 /**
Jeff Brownc5ed5912010-07-14 18:48:53 -07001169 * Returns a historical touch major axis coordinate, as per {@link #getTouchMajor(int)}, that
1170 * occurred between this event and the previous event for the given pointer.
1171 * Only applies to ACTION_MOVE events.
1172 *
1173 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1174 * (the first pointer that is down) to {@link #getPointerCount()}-1.
1175 * @param pos Which historical value to return; must be less than
1176 * {@link #getHistorySize}
1177 *
1178 * @see #getHistorySize
1179 * @see #getTouchMajor
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001180 */
Jeff Brownc5ed5912010-07-14 18:48:53 -07001181 public final float getHistoricalTouchMajor(int pointerIndex, int pos) {
1182 return mDataSamples[(pos * mNumPointers + pointerIndex)
1183 * NUM_SAMPLE_DATA + SAMPLE_TOUCH_MAJOR];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001184 }
Romain Guycafdea62009-06-12 10:51:36 -07001185
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001186 /**
Jeff Brownc5ed5912010-07-14 18:48:53 -07001187 * Returns a historical touch minor axis coordinate, as per {@link #getTouchMinor(int)}, that
1188 * occurred between this event and the previous event for the given pointer.
1189 * Only applies to ACTION_MOVE events.
1190 *
1191 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1192 * (the first pointer that is down) to {@link #getPointerCount()}-1.
1193 * @param pos Which historical value to return; must be less than
1194 * {@link #getHistorySize}
1195 *
1196 * @see #getHistorySize
1197 * @see #getTouchMinor
1198 */
1199 public final float getHistoricalTouchMinor(int pointerIndex, int pos) {
1200 return mDataSamples[(pos * mNumPointers + pointerIndex)
1201 * NUM_SAMPLE_DATA + SAMPLE_TOUCH_MINOR];
1202 }
1203
1204 /**
1205 * Returns a historical tool major axis coordinate, as per {@link #getToolMajor(int)}, that
1206 * occurred between this event and the previous event for the given pointer.
1207 * Only applies to ACTION_MOVE events.
1208 *
1209 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1210 * (the first pointer that is down) to {@link #getPointerCount()}-1.
1211 * @param pos Which historical value to return; must be less than
1212 * {@link #getHistorySize}
1213 *
1214 * @see #getHistorySize
1215 * @see #getToolMajor
1216 */
1217 public final float getHistoricalToolMajor(int pointerIndex, int pos) {
1218 return mDataSamples[(pos * mNumPointers + pointerIndex)
1219 * NUM_SAMPLE_DATA + SAMPLE_TOOL_MAJOR];
1220 }
1221
1222 /**
1223 * Returns a historical tool minor axis coordinate, as per {@link #getToolMinor(int)}, that
1224 * occurred between this event and the previous event for the given pointer.
1225 * Only applies to ACTION_MOVE events.
1226 *
1227 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1228 * (the first pointer that is down) to {@link #getPointerCount()}-1.
1229 * @param pos Which historical value to return; must be less than
1230 * {@link #getHistorySize}
1231 *
1232 * @see #getHistorySize
1233 * @see #getToolMinor
1234 */
1235 public final float getHistoricalToolMinor(int pointerIndex, int pos) {
1236 return mDataSamples[(pos * mNumPointers + pointerIndex)
1237 * NUM_SAMPLE_DATA + SAMPLE_TOOL_MINOR];
1238 }
1239
1240 /**
1241 * Returns a historical orientation coordinate, as per {@link #getOrientation(int)}, that
1242 * occurred between this event and the previous event for the given pointer.
1243 * Only applies to ACTION_MOVE events.
1244 *
1245 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1246 * (the first pointer that is down) to {@link #getPointerCount()}-1.
1247 * @param pos Which historical value to return; must be less than
1248 * {@link #getHistorySize}
1249 *
1250 * @see #getHistorySize
1251 * @see #getOrientation
1252 */
1253 public final float getHistoricalOrientation(int pointerIndex, int pos) {
1254 return mDataSamples[(pos * mNumPointers + pointerIndex)
1255 * NUM_SAMPLE_DATA + SAMPLE_ORIENTATION];
1256 }
1257
1258 /**
1259 * Populates a {@link PointerCoords} object with historical pointer coordinate data,
1260 * as per {@link #getPointerCoords}, that occurred between this event and the previous
1261 * event for the given pointer.
1262 * Only applies to ACTION_MOVE events.
1263 *
1264 * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0
1265 * (the first pointer that is down) to {@link #getPointerCount()}-1.
1266 * @param pos Which historical value to return; must be less than
1267 * {@link #getHistorySize}
1268 * @param outPointerCoords The pointer coordinate object to populate.
1269 *
1270 * @see #getHistorySize
1271 * @see #getPointerCoords
1272 */
1273 public final void getHistoricalPointerCoords(int pointerIndex, int pos,
1274 PointerCoords outPointerCoords) {
1275 final int sampleIndex = (pos * mNumPointers + pointerIndex) * NUM_SAMPLE_DATA;
1276 getPointerCoordsAtSampleIndex(sampleIndex, outPointerCoords);
1277 }
1278
1279 /**
Jeff Brown46b9ac02010-04-22 18:58:52 -07001280 * Returns a bitfield indicating which edges, if any, were touched by this
Romain Guycafdea62009-06-12 10:51:36 -07001281 * MotionEvent. For touch events, clients can use this to determine if the
1282 * user's finger was touching the edge of the display.
1283 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001284 * @see #EDGE_LEFT
1285 * @see #EDGE_TOP
1286 * @see #EDGE_RIGHT
1287 * @see #EDGE_BOTTOM
1288 */
1289 public final int getEdgeFlags() {
1290 return mEdgeFlags;
1291 }
Romain Guycafdea62009-06-12 10:51:36 -07001292
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001293
1294 /**
1295 * Sets the bitfield indicating which edges, if any, where touched by this
Romain Guycafdea62009-06-12 10:51:36 -07001296 * MotionEvent.
1297 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001298 * @see #getEdgeFlags()
1299 */
1300 public final void setEdgeFlags(int flags) {
1301 mEdgeFlags = flags;
1302 }
1303
1304 /**
1305 * Sets this event's action.
1306 */
1307 public final void setAction(int action) {
1308 mAction = action;
1309 }
1310
1311 /**
1312 * Adjust this event's location.
1313 * @param deltaX Amount to add to the current X coordinate of the event.
1314 * @param deltaY Amount to add to the current Y coordinate of the event.
1315 */
1316 public final void offsetLocation(float deltaX, float deltaY) {
Jeff Brown5c225b12010-06-16 01:53:36 -07001317 mXOffset += deltaX;
1318 mYOffset += deltaY;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001319 }
Romain Guycafdea62009-06-12 10:51:36 -07001320
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001321 /**
1322 * Set this event's location. Applies {@link #offsetLocation} with a
1323 * delta from the current location to the given new location.
Romain Guycafdea62009-06-12 10:51:36 -07001324 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001325 * @param x New absolute X location.
1326 * @param y New absolute Y location.
1327 */
1328 public final void setLocation(float x, float y) {
Jeff Brown5c225b12010-06-16 01:53:36 -07001329 mXOffset = x - mDataSamples[mLastDataSampleIndex + SAMPLE_X];
1330 mYOffset = y - mDataSamples[mLastDataSampleIndex + SAMPLE_Y];
1331 }
1332
Jeff Brownc5ed5912010-07-14 18:48:53 -07001333 private final void getPointerCoordsAtSampleIndex(int sampleIndex,
1334 PointerCoords outPointerCoords) {
1335 outPointerCoords.x = mDataSamples[sampleIndex + SAMPLE_X] + mXOffset;
1336 outPointerCoords.y = mDataSamples[sampleIndex + SAMPLE_Y] + mYOffset;
1337 outPointerCoords.pressure = mDataSamples[sampleIndex + SAMPLE_PRESSURE];
1338 outPointerCoords.size = mDataSamples[sampleIndex + SAMPLE_SIZE];
1339 outPointerCoords.touchMajor = mDataSamples[sampleIndex + SAMPLE_TOUCH_MAJOR];
1340 outPointerCoords.touchMinor = mDataSamples[sampleIndex + SAMPLE_TOUCH_MINOR];
1341 outPointerCoords.toolMajor = mDataSamples[sampleIndex + SAMPLE_TOOL_MAJOR];
1342 outPointerCoords.toolMinor = mDataSamples[sampleIndex + SAMPLE_TOOL_MINOR];
1343 outPointerCoords.orientation = mDataSamples[sampleIndex + SAMPLE_ORIENTATION];
1344 }
1345
1346 private final void setPointerCoordsAtSampleIndex(int sampleIndex,
1347 PointerCoords[] pointerCoords) {
1348 final int numPointers = mNumPointers;
1349 for (int i = 0; i < numPointers; i++) {
1350 setPointerCoordsAtSampleIndex(sampleIndex, pointerCoords[i]);
1351 sampleIndex += NUM_SAMPLE_DATA;
1352 }
1353 }
1354
1355 private final void setPointerCoordsAtSampleIndex(int sampleIndex,
1356 PointerCoords pointerCoords) {
1357 mDataSamples[sampleIndex + SAMPLE_X] = pointerCoords.x - mXOffset;
1358 mDataSamples[sampleIndex + SAMPLE_Y] = pointerCoords.y - mYOffset;
1359 mDataSamples[sampleIndex + SAMPLE_PRESSURE] = pointerCoords.pressure;
1360 mDataSamples[sampleIndex + SAMPLE_SIZE] = pointerCoords.size;
1361 mDataSamples[sampleIndex + SAMPLE_TOUCH_MAJOR] = pointerCoords.touchMajor;
1362 mDataSamples[sampleIndex + SAMPLE_TOUCH_MINOR] = pointerCoords.touchMinor;
1363 mDataSamples[sampleIndex + SAMPLE_TOOL_MAJOR] = pointerCoords.toolMajor;
1364 mDataSamples[sampleIndex + SAMPLE_TOOL_MINOR] = pointerCoords.toolMinor;
1365 mDataSamples[sampleIndex + SAMPLE_ORIENTATION] = pointerCoords.orientation;
1366 }
1367
1368 private final void setPointerCoordsAtSampleIndex(int sampleIndex,
1369 float x, float y, float pressure, float size) {
1370 mDataSamples[sampleIndex + SAMPLE_X] = x - mXOffset;
1371 mDataSamples[sampleIndex + SAMPLE_Y] = y - mYOffset;
1372 mDataSamples[sampleIndex + SAMPLE_PRESSURE] = pressure;
1373 mDataSamples[sampleIndex + SAMPLE_SIZE] = size;
1374 mDataSamples[sampleIndex + SAMPLE_TOUCH_MAJOR] = pressure;
1375 mDataSamples[sampleIndex + SAMPLE_TOUCH_MINOR] = pressure;
1376 mDataSamples[sampleIndex + SAMPLE_TOOL_MAJOR] = size;
1377 mDataSamples[sampleIndex + SAMPLE_TOOL_MINOR] = size;
1378 mDataSamples[sampleIndex + SAMPLE_ORIENTATION] = 0;
1379 }
1380
Jeff Brown5c225b12010-06-16 01:53:36 -07001381 private final void incrementNumSamplesAndReserveStorage(int dataSampleStride) {
1382 if (mNumSamples == mEventTimeNanoSamples.length) {
1383 long[] newEventTimeNanoSamples = new long[mNumSamples + BASE_AVAIL_SAMPLES];
1384 System.arraycopy(mEventTimeNanoSamples, 0, newEventTimeNanoSamples, 0, mNumSamples);
1385 mEventTimeNanoSamples = newEventTimeNanoSamples;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001386 }
Jeff Brown5c225b12010-06-16 01:53:36 -07001387
1388 int nextDataSampleIndex = mLastDataSampleIndex + dataSampleStride;
1389 if (nextDataSampleIndex + dataSampleStride > mDataSamples.length) {
1390 float[] newDataSamples = new float[nextDataSampleIndex
1391 + BASE_AVAIL_SAMPLES * dataSampleStride];
1392 System.arraycopy(mDataSamples, 0, newDataSamples, 0, nextDataSampleIndex);
1393 mDataSamples = newDataSamples;
1394 }
1395
1396 mLastEventTimeNanoSampleIndex = mNumSamples;
1397 mLastDataSampleIndex = nextDataSampleIndex;
1398 mNumSamples += 1;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001399 }
Romain Guycafdea62009-06-12 10:51:36 -07001400
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001401 /**
1402 * Add a new movement to the batch of movements in this event. The event's
Jeff Brownc5ed5912010-07-14 18:48:53 -07001403 * current location, position and size is updated to the new values.
1404 * The current values in the event are added to a list of historical values.
1405 *
Jeff Browne33348b2010-07-15 23:54:05 -07001406 * Only applies to {@link #ACTION_MOVE} events.
Romain Guycafdea62009-06-12 10:51:36 -07001407 *
Jeff Brownc5ed5912010-07-14 18:48:53 -07001408 * @param eventTime The time stamp (in ms) for this data.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001409 * @param x The new X position.
1410 * @param y The new Y position.
1411 * @param pressure The new pressure.
1412 * @param size The new size.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001413 * @param metaState Meta key state.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001414 */
1415 public final void addBatch(long eventTime, float x, float y,
1416 float pressure, float size, int metaState) {
Jeff Brown5c225b12010-06-16 01:53:36 -07001417 incrementNumSamplesAndReserveStorage(NUM_SAMPLE_DATA);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001418
Jeff Brown5c225b12010-06-16 01:53:36 -07001419 mEventTimeNanoSamples[mLastEventTimeNanoSampleIndex] = eventTime * MS_PER_NS;
Jeff Brownc5ed5912010-07-14 18:48:53 -07001420 setPointerCoordsAtSampleIndex(mLastDataSampleIndex, x, y, pressure, size);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001421
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001422 mMetaState |= metaState;
1423 }
Romain Guycafdea62009-06-12 10:51:36 -07001424
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001425 /**
Jeff Brownc5ed5912010-07-14 18:48:53 -07001426 * Add a new movement to the batch of movements in this event. The event's
1427 * current location, position and size is updated to the new values.
1428 * The current values in the event are added to a list of historical values.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001429 *
Jeff Browne33348b2010-07-15 23:54:05 -07001430 * Only applies to {@link #ACTION_MOVE} events.
Jeff Brownc5ed5912010-07-14 18:48:53 -07001431 *
1432 * @param eventTime The time stamp (in ms) for this data.
1433 * @param pointerCoords The new pointer coordinates.
1434 * @param metaState Meta key state.
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001435 */
Jeff Brownc5ed5912010-07-14 18:48:53 -07001436 public final void addBatch(long eventTime, PointerCoords[] pointerCoords, int metaState) {
1437 final int dataSampleStride = mNumPointers * NUM_SAMPLE_DATA;
Jeff Brown5c225b12010-06-16 01:53:36 -07001438 incrementNumSamplesAndReserveStorage(dataSampleStride);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001439
Jeff Brown5c225b12010-06-16 01:53:36 -07001440 mEventTimeNanoSamples[mLastEventTimeNanoSampleIndex] = eventTime * MS_PER_NS;
Jeff Brownc5ed5912010-07-14 18:48:53 -07001441 setPointerCoordsAtSampleIndex(mLastDataSampleIndex, pointerCoords);
Jeff Brown5c225b12010-06-16 01:53:36 -07001442
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001443 mMetaState |= metaState;
1444 }
Romain Guycafdea62009-06-12 10:51:36 -07001445
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001446 @Override
1447 public String toString() {
1448 return "MotionEvent{" + Integer.toHexString(System.identityHashCode(this))
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001449 + " action=" + mAction + " x=" + getX()
1450 + " y=" + getY() + " pressure=" + getPressure() + " size=" + getSize() + "}";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001451 }
1452
1453 public static final Parcelable.Creator<MotionEvent> CREATOR
1454 = new Parcelable.Creator<MotionEvent>() {
1455 public MotionEvent createFromParcel(Parcel in) {
Jeff Brown6ec402b2010-07-28 15:48:59 -07001456 in.readInt(); // skip token, we already know this is a MotionEvent
1457 return MotionEvent.createFromParcelBody(in);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001458 }
1459
1460 public MotionEvent[] newArray(int size) {
1461 return new MotionEvent[size];
1462 }
1463 };
1464
Jeff Brown6ec402b2010-07-28 15:48:59 -07001465 /** @hide */
1466 public static MotionEvent createFromParcelBody(Parcel in) {
1467 final int NP = in.readInt();
1468 final int NS = in.readInt();
1469 final int NI = NP * NS * NUM_SAMPLE_DATA;
1470
1471 MotionEvent ev = obtain(NP, NS);
1472 ev.mNumPointers = NP;
1473 ev.mNumSamples = NS;
1474
1475 ev.readBaseFromParcel(in);
1476
1477 ev.mDownTimeNano = in.readLong();
1478 ev.mAction = in.readInt();
1479 ev.mXOffset = in.readFloat();
1480 ev.mYOffset = in.readFloat();
1481 ev.mXPrecision = in.readFloat();
1482 ev.mYPrecision = in.readFloat();
1483 ev.mEdgeFlags = in.readInt();
1484 ev.mMetaState = in.readInt();
1485
1486 final int[] pointerIdentifiers = ev.mPointerIdentifiers;
1487 for (int i = 0; i < NP; i++) {
1488 pointerIdentifiers[i] = in.readInt();
1489 }
1490
1491 final long[] eventTimeNanoSamples = ev.mEventTimeNanoSamples;
1492 for (int i = 0; i < NS; i++) {
1493 eventTimeNanoSamples[i] = in.readLong();
1494 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001495
Jeff Brown6ec402b2010-07-28 15:48:59 -07001496 final float[] dataSamples = ev.mDataSamples;
1497 for (int i = 0; i < NI; i++) {
1498 dataSamples[i] = in.readFloat();
1499 }
1500
1501 ev.mLastEventTimeNanoSampleIndex = NS - 1;
1502 ev.mLastDataSampleIndex = (NS - 1) * NP * NUM_SAMPLE_DATA;
1503 return ev;
1504 }
1505
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001506 public void writeToParcel(Parcel out, int flags) {
Jeff Brown6ec402b2010-07-28 15:48:59 -07001507 out.writeInt(PARCEL_TOKEN_MOTION_EVENT);
1508
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001509 final int NP = mNumPointers;
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001510 final int NS = mNumSamples;
Jeff Brown5c225b12010-06-16 01:53:36 -07001511 final int NI = NP * NS * NUM_SAMPLE_DATA;
1512
1513 out.writeInt(NP);
Dianne Hackborn9822d2b2009-07-20 17:33:15 -07001514 out.writeInt(NS);
Jeff Brown5c225b12010-06-16 01:53:36 -07001515
Jeff Brown6ec402b2010-07-28 15:48:59 -07001516 writeBaseToParcel(out);
1517
Jeff Brown5c225b12010-06-16 01:53:36 -07001518 out.writeLong(mDownTimeNano);
1519 out.writeInt(mAction);
1520 out.writeFloat(mXOffset);
1521 out.writeFloat(mYOffset);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001522 out.writeFloat(mXPrecision);
1523 out.writeFloat(mYPrecision);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001524 out.writeInt(mEdgeFlags);
Jeff Brown5c225b12010-06-16 01:53:36 -07001525 out.writeInt(mMetaState);
1526
1527 final int[] pointerIdentifiers = mPointerIdentifiers;
1528 for (int i = 0; i < NP; i++) {
1529 out.writeInt(pointerIdentifiers[i]);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001530 }
Jeff Brown5c225b12010-06-16 01:53:36 -07001531
1532 final long[] eventTimeNanoSamples = mEventTimeNanoSamples;
1533 for (int i = 0; i < NS; i++) {
1534 out.writeLong(eventTimeNanoSamples[i]);
1535 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001536
Jeff Brown5c225b12010-06-16 01:53:36 -07001537 final float[] dataSamples = mDataSamples;
1538 for (int i = 0; i < NI; i++) {
1539 out.writeFloat(dataSamples[i]);
1540 }
1541 }
Jeff Brownc5ed5912010-07-14 18:48:53 -07001542
1543 /**
1544 * Transfer object for pointer coordinates.
1545 *
1546 * Objects of this type can be used to manufacture new {@link MotionEvent} objects
1547 * and to query pointer coordinate information in bulk.
1548 *
1549 * Refer to {@link InputDevice} for information about how different kinds of
1550 * input devices and sources represent pointer coordinates.
1551 */
1552 public static final class PointerCoords {
1553 /**
1554 * The X coordinate of the pointer movement.
1555 * The interpretation varies by input source and may represent the position of
1556 * the center of the contact area, a relative displacement in device-specific units
1557 * or something else.
1558 */
1559 public float x;
1560
1561 /**
1562 * The Y coordinate of the pointer movement.
1563 * The interpretation varies by input source and may represent the position of
1564 * the center of the contact area, a relative displacement in device-specific units
1565 * or something else.
1566 */
1567 public float y;
1568
1569 /**
1570 * A scaled value that describes the pressure applied to the pointer.
1571 * The pressure generally ranges from 0 (no pressure at all) to 1 (normal pressure),
1572 * however values higher than 1 may be generated depending on the calibration of
1573 * the input device.
1574 */
1575 public float pressure;
1576
1577 /**
1578 * A scaled value of the approximate size of the pointer touch area.
1579 * This represents some approximation of the area of the screen being
1580 * pressed; the actual value in pixels corresponding to the
1581 * touch is normalized with the device specific range of values
1582 * and scaled to a value between 0 and 1. The value of size can be used to
1583 * determine fat touch events.
1584 */
1585 public float size;
1586
1587 /**
1588 * The length of the major axis of an ellipse that describes the touch area at
1589 * the point of contact.
1590 */
1591 public float touchMajor;
1592
1593 /**
1594 * The length of the minor axis of an ellipse that describes the touch area at
1595 * the point of contact.
1596 */
1597 public float touchMinor;
1598
1599 /**
1600 * The length of the major axis of an ellipse that describes the size of
1601 * the approaching tool.
1602 * The tool area represents the estimated size of the finger or pen that is
1603 * touching the device independent of its actual touch area at the point of contact.
1604 */
1605 public float toolMajor;
1606
1607 /**
1608 * The length of the minor axis of an ellipse that describes the size of
1609 * the approaching tool.
1610 * The tool area represents the estimated size of the finger or pen that is
1611 * touching the device independent of its actual touch area at the point of contact.
1612 */
1613 public float toolMinor;
1614
1615 /**
1616 * The orientation of the touch area and tool area in radians clockwise from vertical.
1617 * An angle of 0 degrees indicates that the major axis of contact is oriented
1618 * upwards, is perfectly circular or is of unknown orientation. A positive angle
1619 * indicates that the major axis of contact is oriented to the right. A negative angle
1620 * indicates that the major axis of contact is oriented to the left.
Jeff Brown6d0fec22010-07-23 21:28:06 -07001621 * The full range is from -PI/2 radians (finger pointing fully left) to PI/2 radians
Jeff Brownc5ed5912010-07-14 18:48:53 -07001622 * (finger pointing fully right).
1623 */
1624 public float orientation;
1625
1626 /*
Jeff Brown6d0fec22010-07-23 21:28:06 -07001627 private static final float PI_4 = (float) (Math.PI / 4);
Jeff Brownc5ed5912010-07-14 18:48:53 -07001628
1629 public float getTouchWidth() {
Jeff Brown6d0fec22010-07-23 21:28:06 -07001630 return Math.abs(orientation) > PI_4 ? touchMajor : touchMinor;
Jeff Brownc5ed5912010-07-14 18:48:53 -07001631 }
1632
1633 public float getTouchHeight() {
Jeff Brown6d0fec22010-07-23 21:28:06 -07001634 return Math.abs(orientation) > PI_4 ? touchMinor : touchMajor;
Jeff Brownc5ed5912010-07-14 18:48:53 -07001635 }
1636
1637 public float getToolWidth() {
Jeff Brown6d0fec22010-07-23 21:28:06 -07001638 return Math.abs(orientation) > PI_4 ? toolMajor : toolMinor;
Jeff Brownc5ed5912010-07-14 18:48:53 -07001639 }
1640
1641 public float getToolHeight() {
Jeff Brown6d0fec22010-07-23 21:28:06 -07001642 return Math.abs(orientation) > PI_4 ? toolMinor : toolMajor;
Jeff Brownc5ed5912010-07-14 18:48:53 -07001643 }
1644 */
1645 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001646}