MotionEvent.java revision f93246923f0a8c85fddb508533d63d59977f75eb
1/*
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.graphics.Matrix;
20import android.os.Parcel;
21import android.os.Parcelable;
22import android.os.SystemClock;
23
24/**
25 * Object used to report movement (mouse, pen, finger, trackball) events.  This
26 * class may hold either absolute or relative movements, depending on what
27 * it is being used for.
28 * <p>
29 * On pointing devices such as touch screens, pointer coordinates specify absolute
30 * positions such as view X/Y coordinates.  Each complete gesture is represented
31 * by a sequence of motion events with actions that describe pointer state transitions
32 * and movements.  A gesture starts with a motion event with {@link #ACTION_DOWN}
33 * that provides the location of the first pointer down.  As each additional
34 * pointer that goes down or up, the framework will generate a motion event with
35 * {@link #ACTION_POINTER_DOWN} or {@link #ACTION_POINTER_UP} accordingly.
36 * Pointer movements are described by motion events with {@link #ACTION_MOVE}.
37 * Finally, a gesture end either when the final pointer goes up as represented
38 * by a motion event with {@link #ACTION_UP} or when gesture is canceled
39 * with {@link #ACTION_CANCEL}.
40 * </p><p>
41 * On trackballs, the pointer coordinates specify relative movements as X/Y deltas.
42 * A trackball gesture consists of a sequence of movements described by motion
43 * events with {@link #ACTION_MOVE} interspersed with occasional {@link #ACTION_DOWN}
44 * or {@link #ACTION_UP} motion events when the trackball button is pressed or released.
45 * </p><p>
46 * Motion events always report movements for all pointers at once.  The number
47 * of pointers only ever changes by one as individual pointers go up and down,
48 * except when the gesture is canceled.
49 * </p><p>
50 * The order in which individual pointers appear within a motion event can change
51 * from one event to the next. Use the {@link #getPointerId(int)} method to obtain a
52 * pointer id to track pointers across motion events in a gesture.  Then for
53 * successive motion events, use the {@link #findPointerIndex(int)} method to obtain
54 * the pointer index for a given pointer id in that motion event.
55 * </p><p>
56 * For efficiency, motion events with {@link #ACTION_MOVE} may batch together
57 * multiple movement samples within a single object.  The most current
58 * pointer coordinates are available using {@link #getX(int)} and {@link #getY(int)}.
59 * Earlier coordinates within the batch are accessed using {@link #getHistoricalX(int, int)}
60 * and {@link #getHistoricalY(int, int)}.  The coordinates are "historical" only
61 * insofar as they are older than the current coordinates in the batch; however,
62 * they are still distinct from any other coordinates reported in prior motion events.
63 * To process all coordinates in the batch in time order, first consume the historical
64 * coordinates then consume the current coordinates.
65 * </p><p>
66 * Example: Consuming all samples for all pointers in a motion event in time order.
67 * </p><p><pre><code>
68 * void printSamples(MotionEvent ev) {
69 *     final int historySize = ev.getHistorySize();
70 *     final int pointerCount = ev.getPointerCount();
71 *     for (int h = 0; h &lt; historySize; h++) {
72 *         System.out.printf("At time %d:", ev.getHistoricalEventTime(h));
73 *         for (int p = 0; p &lt; pointerCount; p++) {
74 *             System.out.printf("  pointer %d: (%f,%f)",
75 *                 ev.getPointerId(p), ev.getHistoricalX(p, h), ev.getHistoricalY(p, h));
76 *         }
77 *     }
78 *     System.out.printf("At time %d:", ev.getEventTime());
79 *     for (int p = 0; p &lt; pointerCount; p++) {
80 *         System.out.printf("  pointer %d: (%f,%f)",
81 *             ev.getPointerId(p), ev.getX(p), ev.getY(p));
82 *     }
83 * }
84 * </code></pre></p><p>
85 * In general, the framework cannot guarantee that the motion events it delivers
86 * to a view always constitute a complete motion sequences since some events may be dropped
87 * or modified by containing views before they are delivered.  The view implementation
88 * should be prepared to handle {@link #ACTION_CANCEL} and should tolerate anomalous
89 * situations such as receiving a new {@link #ACTION_DOWN} without first having
90 * received an {@link #ACTION_UP} for the prior gesture.
91 * </p><p>
92 * Refer to {@link InputDevice} for more information about how different kinds of
93 * input devices and sources represent pointer coordinates.
94 * </p>
95 */
96public final class MotionEvent extends InputEvent implements Parcelable {
97    private static final long MS_PER_NS = 1000000;
98    private static final boolean TRACK_RECYCLED_LOCATION = false;
99
100    /**
101     * Bit mask of the parts of the action code that are the action itself.
102     */
103    public static final int ACTION_MASK             = 0xff;
104
105    /**
106     * Constant for {@link #getAction}: A pressed gesture has started, the
107     * motion contains the initial starting location.
108     */
109    public static final int ACTION_DOWN             = 0;
110
111    /**
112     * Constant for {@link #getAction}: A pressed gesture has finished, the
113     * motion contains the final release location as well as any intermediate
114     * points since the last down or move event.
115     */
116    public static final int ACTION_UP               = 1;
117
118    /**
119     * Constant for {@link #getAction}: A change has happened during a
120     * press gesture (between {@link #ACTION_DOWN} and {@link #ACTION_UP}).
121     * The motion contains the most recent point, as well as any intermediate
122     * points since the last down or move event.
123     */
124    public static final int ACTION_MOVE             = 2;
125
126    /**
127     * Constant for {@link #getAction}: The current gesture has been aborted.
128     * You will not receive any more points in it.  You should treat this as
129     * an up event, but not perform any action that you normally would.
130     */
131    public static final int ACTION_CANCEL           = 3;
132
133    /**
134     * Constant for {@link #getAction}: A movement has happened outside of the
135     * normal bounds of the UI element.  This does not provide a full gesture,
136     * but only the initial location of the movement/touch.
137     */
138    public static final int ACTION_OUTSIDE          = 4;
139
140    /**
141     * A non-primary pointer has gone down.  The bits in
142     * {@link #ACTION_POINTER_ID_MASK} indicate which pointer changed.
143     */
144    public static final int ACTION_POINTER_DOWN     = 5;
145
146    /**
147     * A non-primary pointer has gone up.  The bits in
148     * {@link #ACTION_POINTER_ID_MASK} indicate which pointer changed.
149     */
150    public static final int ACTION_POINTER_UP       = 6;
151
152    /**
153     * Bits in the action code that represent a pointer index, used with
154     * {@link #ACTION_POINTER_DOWN} and {@link #ACTION_POINTER_UP}.  Shifting
155     * down by {@link #ACTION_POINTER_INDEX_SHIFT} provides the actual pointer
156     * index where the data for the pointer going up or down can be found; you can
157     * get its identifier with {@link #getPointerId(int)} and the actual
158     * data with {@link #getX(int)} etc.
159     */
160    public static final int ACTION_POINTER_INDEX_MASK  = 0xff00;
161
162    /**
163     * Bit shift for the action bits holding the pointer index as
164     * defined by {@link #ACTION_POINTER_INDEX_MASK}.
165     */
166    public static final int ACTION_POINTER_INDEX_SHIFT = 8;
167
168    /**
169     * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the
170     * data index associated with {@link #ACTION_POINTER_DOWN}.
171     */
172    @Deprecated
173    public static final int ACTION_POINTER_1_DOWN   = ACTION_POINTER_DOWN | 0x0000;
174
175    /**
176     * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the
177     * data index associated with {@link #ACTION_POINTER_DOWN}.
178     */
179    @Deprecated
180    public static final int ACTION_POINTER_2_DOWN   = ACTION_POINTER_DOWN | 0x0100;
181
182    /**
183     * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the
184     * data index associated with {@link #ACTION_POINTER_DOWN}.
185     */
186    @Deprecated
187    public static final int ACTION_POINTER_3_DOWN   = ACTION_POINTER_DOWN | 0x0200;
188
189    /**
190     * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the
191     * data index associated with {@link #ACTION_POINTER_UP}.
192     */
193    @Deprecated
194    public static final int ACTION_POINTER_1_UP     = ACTION_POINTER_UP | 0x0000;
195
196    /**
197     * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the
198     * data index associated with {@link #ACTION_POINTER_UP}.
199     */
200    @Deprecated
201    public static final int ACTION_POINTER_2_UP     = ACTION_POINTER_UP | 0x0100;
202
203    /**
204     * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the
205     * data index associated with {@link #ACTION_POINTER_UP}.
206     */
207    @Deprecated
208    public static final int ACTION_POINTER_3_UP     = ACTION_POINTER_UP | 0x0200;
209
210    /**
211     * @deprecated Renamed to {@link #ACTION_POINTER_INDEX_MASK} to match
212     * the actual data contained in these bits.
213     */
214    @Deprecated
215    public static final int ACTION_POINTER_ID_MASK  = 0xff00;
216
217    /**
218     * @deprecated Renamed to {@link #ACTION_POINTER_INDEX_SHIFT} to match
219     * the actual data contained in these bits.
220     */
221    @Deprecated
222    public static final int ACTION_POINTER_ID_SHIFT = 8;
223
224    /**
225     * This flag indicates that the window that received this motion event is partly
226     * or wholly obscured by another visible window above it.  This flag is set to true
227     * even if the event did not directly pass through the obscured area.
228     * A security sensitive application can check this flag to identify situations in which
229     * a malicious application may have covered up part of its content for the purpose
230     * of misleading the user or hijacking touches.  An appropriate response might be
231     * to drop the suspect touches or to take additional precautions to confirm the user's
232     * actual intent.
233     */
234    public static final int FLAG_WINDOW_IS_OBSCURED = 0x1;
235
236    /**
237     * Flag indicating the motion event intersected the top edge of the screen.
238     */
239    public static final int EDGE_TOP = 0x00000001;
240
241    /**
242     * Flag indicating the motion event intersected the bottom edge of the screen.
243     */
244    public static final int EDGE_BOTTOM = 0x00000002;
245
246    /**
247     * Flag indicating the motion event intersected the left edge of the screen.
248     */
249    public static final int EDGE_LEFT = 0x00000004;
250
251    /**
252     * Flag indicating the motion event intersected the right edge of the screen.
253     */
254    public static final int EDGE_RIGHT = 0x00000008;
255
256    /*
257     * Offset for the sample's X coordinate.
258     */
259    static private final int SAMPLE_X = 0;
260
261    /*
262     * Offset for the sample's Y coordinate.
263     */
264    static private final int SAMPLE_Y = 1;
265
266    /*
267     * Offset for the sample's pressure.
268     */
269    static private final int SAMPLE_PRESSURE = 2;
270
271    /*
272     * Offset for the sample's size
273     */
274    static private final int SAMPLE_SIZE = 3;
275
276    /*
277     * Offset for the sample's touch major axis length.
278     */
279    static private final int SAMPLE_TOUCH_MAJOR = 4;
280
281    /*
282     * Offset for the sample's touch minor axis length.
283     */
284    static private final int SAMPLE_TOUCH_MINOR = 5;
285
286    /*
287     * Offset for the sample's tool major axis length.
288     */
289    static private final int SAMPLE_TOOL_MAJOR = 6;
290
291    /*
292     * Offset for the sample's tool minor axis length.
293     */
294    static private final int SAMPLE_TOOL_MINOR = 7;
295
296    /*
297     * Offset for the sample's orientation.
298     */
299    static private final int SAMPLE_ORIENTATION = 8;
300
301    /*
302     * Number of data items for each sample.
303     */
304    static private final int NUM_SAMPLE_DATA = 9;
305
306    /*
307     * Minimum number of pointers for which to reserve space when allocating new
308     * motion events.  This is explicitly not a bound on the maximum number of pointers.
309     */
310    static private final int BASE_AVAIL_POINTERS = 5;
311
312    /*
313     * Minimum number of samples for which to reserve space when allocating new motion events.
314     */
315    static private final int BASE_AVAIL_SAMPLES = 8;
316
317    private static final int MAX_RECYCLED = 10;
318    private static final Object gRecyclerLock = new Object();
319    private static int gRecyclerUsed;
320    private static MotionEvent gRecyclerTop;
321
322    private long mDownTimeNano;
323    private int mAction;
324    private float mXOffset;
325    private float mYOffset;
326    private float mXPrecision;
327    private float mYPrecision;
328    private int mEdgeFlags;
329    private int mMetaState;
330    private int mFlags;
331
332    private int mNumPointers;
333    private int mNumSamples;
334
335    private int mLastDataSampleIndex;
336    private int mLastEventTimeNanoSampleIndex;
337
338    // Array of mNumPointers size of identifiers for each pointer of data.
339    private int[] mPointerIdentifiers;
340
341    // Array of (mNumSamples * mNumPointers * NUM_SAMPLE_DATA) size of event data.
342    // Samples are ordered from oldest to newest.
343    private float[] mDataSamples;
344
345    // Array of mNumSamples size of event time stamps in nanoseconds.
346    // Samples are ordered from oldest to newest.
347    private long[] mEventTimeNanoSamples;
348
349    private MotionEvent mNext;
350    private RuntimeException mRecycledLocation;
351    private boolean mRecycled;
352
353    private native void nativeTransform(Matrix matrix);
354
355    private MotionEvent(int pointerCount, int sampleCount) {
356        mPointerIdentifiers = new int[pointerCount];
357        mDataSamples = new float[pointerCount * sampleCount * NUM_SAMPLE_DATA];
358        mEventTimeNanoSamples = new long[sampleCount];
359    }
360
361    static private MotionEvent obtain(int pointerCount, int sampleCount) {
362        final MotionEvent ev;
363        synchronized (gRecyclerLock) {
364            ev = gRecyclerTop;
365            if (ev == null) {
366                if (pointerCount < BASE_AVAIL_POINTERS) {
367                    pointerCount = BASE_AVAIL_POINTERS;
368                }
369                if (sampleCount < BASE_AVAIL_SAMPLES) {
370                    sampleCount = BASE_AVAIL_SAMPLES;
371                }
372                return new MotionEvent(pointerCount, sampleCount);
373            }
374            gRecyclerTop = ev.mNext;
375            gRecyclerUsed -= 1;
376        }
377        ev.mRecycledLocation = null;
378        ev.mRecycled = false;
379        ev.mNext = null;
380
381        if (ev.mPointerIdentifiers.length < pointerCount) {
382            ev.mPointerIdentifiers = new int[pointerCount];
383        }
384
385        if (ev.mEventTimeNanoSamples.length < sampleCount) {
386            ev.mEventTimeNanoSamples = new long[sampleCount];
387        }
388
389        final int neededDataSamplesLength = pointerCount * sampleCount * NUM_SAMPLE_DATA;
390        if (ev.mDataSamples.length < neededDataSamplesLength) {
391            ev.mDataSamples = new float[neededDataSamplesLength];
392        }
393
394        return ev;
395    }
396
397    /**
398     * Create a new MotionEvent, filling in all of the basic values that
399     * define the motion.
400     *
401     * @param downTime The time (in ms) when the user originally pressed down to start
402     * a stream of position events.  This must be obtained from {@link SystemClock#uptimeMillis()}.
403     * @param eventTime The the time (in ms) when this specific event was generated.  This
404     * must be obtained from {@link SystemClock#uptimeMillis()}.
405     * @param action The kind of action being performed -- one of either
406     * {@link #ACTION_DOWN}, {@link #ACTION_MOVE}, {@link #ACTION_UP}, or
407     * {@link #ACTION_CANCEL}.
408     * @param pointers The number of points that will be in this event.
409     * @param pointerIds An array of <em>pointers</em> values providing
410     * an identifier for each pointer.
411     * @param pointerCoords An array of <em>pointers</em> values providing
412     * a {@link PointerCoords} coordinate object for each pointer.
413     * @param metaState The state of any meta / modifier keys that were in effect when
414     * the event was generated.
415     * @param xPrecision The precision of the X coordinate being reported.
416     * @param yPrecision The precision of the Y coordinate being reported.
417     * @param deviceId The id for the device that this event came from.  An id of
418     * zero indicates that the event didn't come from a physical device; other
419     * numbers are arbitrary and you shouldn't depend on the values.
420     * @param edgeFlags A bitfield indicating which edges, if any, were touched by this
421     * MotionEvent.
422     * @param source The source of this event.
423     * @param flags The motion event flags.
424     */
425    static public MotionEvent obtain(long downTime, long eventTime,
426            int action, int pointers, int[] pointerIds, PointerCoords[] pointerCoords,
427            int metaState, float xPrecision, float yPrecision, int deviceId,
428            int edgeFlags, int source, int flags) {
429        MotionEvent ev = obtain(pointers, 1);
430        ev.mDeviceId = deviceId;
431        ev.mSource = source;
432        ev.mEdgeFlags = edgeFlags;
433        ev.mDownTimeNano = downTime * MS_PER_NS;
434        ev.mAction = action;
435        ev.mFlags = flags;
436        ev.mMetaState = metaState;
437        ev.mXOffset = 0;
438        ev.mYOffset = 0;
439        ev.mXPrecision = xPrecision;
440        ev.mYPrecision = yPrecision;
441
442        ev.mNumPointers = pointers;
443        ev.mNumSamples = 1;
444
445        ev.mLastDataSampleIndex = 0;
446        ev.mLastEventTimeNanoSampleIndex = 0;
447
448        System.arraycopy(pointerIds, 0, ev.mPointerIdentifiers, 0, pointers);
449
450        ev.mEventTimeNanoSamples[0] = eventTime * MS_PER_NS;
451
452        ev.setPointerCoordsAtSampleIndex(0, pointerCoords);
453
454        return ev;
455    }
456
457    /**
458     * Create a new MotionEvent, filling in all of the basic values that
459     * define the motion.
460     *
461     * @param downTime The time (in ms) when the user originally pressed down to start
462     * a stream of position events.  This must be obtained from {@link SystemClock#uptimeMillis()}.
463     * @param eventTime  The the time (in ms) when this specific event was generated.  This
464     * must be obtained from {@link SystemClock#uptimeMillis()}.
465     * @param action The kind of action being performed -- one of either
466     * {@link #ACTION_DOWN}, {@link #ACTION_MOVE}, {@link #ACTION_UP}, or
467     * {@link #ACTION_CANCEL}.
468     * @param x The X coordinate of this event.
469     * @param y The Y coordinate of this event.
470     * @param pressure The current pressure of this event.  The pressure generally
471     * ranges from 0 (no pressure at all) to 1 (normal pressure), however
472     * values higher than 1 may be generated depending on the calibration of
473     * the input device.
474     * @param size A scaled value of the approximate size of the area being pressed when
475     * touched with the finger. The actual value in pixels corresponding to the finger
476     * touch is normalized with a device specific range of values
477     * and scaled to a value between 0 and 1.
478     * @param metaState The state of any meta / modifier keys that were in effect when
479     * the event was generated.
480     * @param xPrecision The precision of the X coordinate being reported.
481     * @param yPrecision The precision of the Y coordinate being reported.
482     * @param deviceId The id for the device that this event came from.  An id of
483     * zero indicates that the event didn't come from a physical device; other
484     * numbers are arbitrary and you shouldn't depend on the values.
485     * @param edgeFlags A bitfield indicating which edges, if any, were touched by this
486     * MotionEvent.
487     */
488    static public MotionEvent obtain(long downTime, long eventTime, int action,
489            float x, float y, float pressure, float size, int metaState,
490            float xPrecision, float yPrecision, int deviceId, int edgeFlags) {
491        MotionEvent ev = obtain(1, 1);
492        ev.mDeviceId = deviceId;
493        ev.mSource = InputDevice.SOURCE_UNKNOWN;
494        ev.mEdgeFlags = edgeFlags;
495        ev.mDownTimeNano = downTime * MS_PER_NS;
496        ev.mAction = action;
497        ev.mFlags = 0;
498        ev.mMetaState = metaState;
499        ev.mXOffset = 0;
500        ev.mYOffset = 0;
501        ev.mXPrecision = xPrecision;
502        ev.mYPrecision = yPrecision;
503
504        ev.mNumPointers = 1;
505        ev.mNumSamples = 1;
506
507        ev.mLastDataSampleIndex = 0;
508        ev.mLastEventTimeNanoSampleIndex = 0;
509
510        ev.mPointerIdentifiers[0] = 0;
511
512        ev.mEventTimeNanoSamples[0] = eventTime * MS_PER_NS;
513
514        ev.setPointerCoordsAtSampleIndex(0, x, y, pressure, size);
515        return ev;
516    }
517
518    /**
519     * Create a new MotionEvent, filling in all of the basic values that
520     * define the motion.
521     *
522     * @param downTime The time (in ms) when the user originally pressed down to start
523     * a stream of position events.  This must be obtained from {@link SystemClock#uptimeMillis()}.
524     * @param eventTime  The the time (in ms) when this specific event was generated.  This
525     * must be obtained from {@link SystemClock#uptimeMillis()}.
526     * @param action The kind of action being performed -- one of either
527     * {@link #ACTION_DOWN}, {@link #ACTION_MOVE}, {@link #ACTION_UP}, or
528     * {@link #ACTION_CANCEL}.
529     * @param pointers The number of pointers that are active in this event.
530     * @param x The X coordinate of this event.
531     * @param y The Y coordinate of this event.
532     * @param pressure The current pressure of this event.  The pressure generally
533     * ranges from 0 (no pressure at all) to 1 (normal pressure), however
534     * values higher than 1 may be generated depending on the calibration of
535     * the input device.
536     * @param size A scaled value of the approximate size of the area being pressed when
537     * touched with the finger. The actual value in pixels corresponding to the finger
538     * touch is normalized with a device specific range of values
539     * and scaled to a value between 0 and 1.
540     * @param metaState The state of any meta / modifier keys that were in effect when
541     * the event was generated.
542     * @param xPrecision The precision of the X coordinate being reported.
543     * @param yPrecision The precision of the Y coordinate being reported.
544     * @param deviceId The id for the device that this event came from.  An id of
545     * zero indicates that the event didn't come from a physical device; other
546     * numbers are arbitrary and you shouldn't depend on the values.
547     * @param edgeFlags A bitfield indicating which edges, if any, were touched by this
548     * MotionEvent.
549     *
550     * @deprecated Use {@link #obtain(long, long, int, float, float, float, float, int, float, float, int, int)}
551     * instead.
552     */
553    @Deprecated
554    static public MotionEvent obtain(long downTime, long eventTime, int action,
555            int pointers, float x, float y, float pressure, float size, int metaState,
556            float xPrecision, float yPrecision, int deviceId, int edgeFlags) {
557        return obtain(downTime, eventTime, action, x, y, pressure, size,
558                metaState, xPrecision, yPrecision, deviceId, edgeFlags);
559    }
560
561    /**
562     * Create a new MotionEvent, filling in a subset of the basic motion
563     * values.  Those not specified here are: device id (always 0), pressure
564     * and size (always 1), x and y precision (always 1), and edgeFlags (always 0).
565     *
566     * @param downTime The time (in ms) when the user originally pressed down to start
567     * a stream of position events.  This must be obtained from {@link SystemClock#uptimeMillis()}.
568     * @param eventTime  The the time (in ms) when this specific event was generated.  This
569     * must be obtained from {@link SystemClock#uptimeMillis()}.
570     * @param action The kind of action being performed -- one of either
571     * {@link #ACTION_DOWN}, {@link #ACTION_MOVE}, {@link #ACTION_UP}, or
572     * {@link #ACTION_CANCEL}.
573     * @param x The X coordinate of this event.
574     * @param y The Y coordinate of this event.
575     * @param metaState The state of any meta / modifier keys that were in effect when
576     * the event was generated.
577     */
578    static public MotionEvent obtain(long downTime, long eventTime, int action,
579            float x, float y, int metaState) {
580        return obtain(downTime, eventTime, action, x, y, 1.0f, 1.0f,
581                metaState, 1.0f, 1.0f, 0, 0);
582    }
583
584    /**
585     * Create a new MotionEvent, copying from an existing one.
586     */
587    static public MotionEvent obtain(MotionEvent o) {
588        MotionEvent ev = obtain(o.mNumPointers, o.mNumSamples);
589        ev.mDeviceId = o.mDeviceId;
590        ev.mSource = o.mSource;
591        ev.mEdgeFlags = o.mEdgeFlags;
592        ev.mDownTimeNano = o.mDownTimeNano;
593        ev.mAction = o.mAction;
594        ev.mFlags = o.mFlags;
595        ev.mMetaState = o.mMetaState;
596        ev.mXOffset = o.mXOffset;
597        ev.mYOffset = o.mYOffset;
598        ev.mXPrecision = o.mXPrecision;
599        ev.mYPrecision = o.mYPrecision;
600        int numPointers = ev.mNumPointers = o.mNumPointers;
601        int numSamples = ev.mNumSamples = o.mNumSamples;
602
603        ev.mLastDataSampleIndex = o.mLastDataSampleIndex;
604        ev.mLastEventTimeNanoSampleIndex = o.mLastEventTimeNanoSampleIndex;
605
606        System.arraycopy(o.mPointerIdentifiers, 0, ev.mPointerIdentifiers, 0, numPointers);
607
608        System.arraycopy(o.mEventTimeNanoSamples, 0, ev.mEventTimeNanoSamples, 0, numSamples);
609
610        System.arraycopy(o.mDataSamples, 0, ev.mDataSamples, 0,
611                numPointers * numSamples * NUM_SAMPLE_DATA);
612        return ev;
613    }
614
615    /**
616     * Create a new MotionEvent, copying from an existing one, but not including
617     * any historical point information.
618     */
619    static public MotionEvent obtainNoHistory(MotionEvent o) {
620        MotionEvent ev = obtain(o.mNumPointers, 1);
621        ev.mDeviceId = o.mDeviceId;
622        ev.mSource = o.mSource;
623        ev.mEdgeFlags = o.mEdgeFlags;
624        ev.mDownTimeNano = o.mDownTimeNano;
625        ev.mAction = o.mAction;
626        o.mFlags = o.mFlags;
627        ev.mMetaState = o.mMetaState;
628        ev.mXOffset = o.mXOffset;
629        ev.mYOffset = o.mYOffset;
630        ev.mXPrecision = o.mXPrecision;
631        ev.mYPrecision = o.mYPrecision;
632
633        int numPointers = ev.mNumPointers = o.mNumPointers;
634        ev.mNumSamples = 1;
635
636        ev.mLastDataSampleIndex = 0;
637        ev.mLastEventTimeNanoSampleIndex = 0;
638
639        System.arraycopy(o.mPointerIdentifiers, 0, ev.mPointerIdentifiers, 0, numPointers);
640
641        ev.mEventTimeNanoSamples[0] = o.mEventTimeNanoSamples[o.mLastEventTimeNanoSampleIndex];
642
643        System.arraycopy(o.mDataSamples, o.mLastDataSampleIndex, ev.mDataSamples, 0,
644                numPointers * NUM_SAMPLE_DATA);
645        return ev;
646    }
647
648    /**
649     * Recycle the MotionEvent, to be re-used by a later caller.  After calling
650     * this function you must not ever touch the event again.
651     */
652    public final void recycle() {
653        // Ensure recycle is only called once!
654        if (TRACK_RECYCLED_LOCATION) {
655            if (mRecycledLocation != null) {
656                throw new RuntimeException(toString() + " recycled twice!", mRecycledLocation);
657            }
658            mRecycledLocation = new RuntimeException("Last recycled here");
659            //Log.w("MotionEvent", "Recycling event " + this, mRecycledLocation);
660        } else {
661            if (mRecycled) {
662                throw new RuntimeException(toString() + " recycled twice!");
663            }
664            mRecycled = true;
665        }
666
667        synchronized (gRecyclerLock) {
668            if (gRecyclerUsed < MAX_RECYCLED) {
669                gRecyclerUsed++;
670                mNumSamples = 0;
671                mNext = gRecyclerTop;
672                gRecyclerTop = this;
673            }
674        }
675    }
676
677    /**
678     * Scales down the coordination of this event by the given scale.
679     *
680     * @hide
681     */
682    public final void scale(float scale) {
683        mXOffset *= scale;
684        mYOffset *= scale;
685        mXPrecision *= scale;
686        mYPrecision *= scale;
687
688        float[] history = mDataSamples;
689        final int length = mNumPointers * mNumSamples * NUM_SAMPLE_DATA;
690        for (int i = 0; i < length; i += NUM_SAMPLE_DATA) {
691            history[i + SAMPLE_X] *= scale;
692            history[i + SAMPLE_Y] *= scale;
693            // no need to scale pressure
694            history[i + SAMPLE_SIZE] *= scale;    // TODO: square this?
695            history[i + SAMPLE_TOUCH_MAJOR] *= scale;
696            history[i + SAMPLE_TOUCH_MINOR] *= scale;
697            history[i + SAMPLE_TOOL_MAJOR] *= scale;
698            history[i + SAMPLE_TOOL_MINOR] *= scale;
699        }
700    }
701
702    /**
703     * Return the kind of action being performed -- one of either
704     * {@link #ACTION_DOWN}, {@link #ACTION_MOVE}, {@link #ACTION_UP}, or
705     * {@link #ACTION_CANCEL}.  Consider using {@link #getActionMasked}
706     * and {@link #getActionIndex} to retrieve the separate masked action
707     * and pointer index.
708     */
709    public final int getAction() {
710        return mAction;
711    }
712
713    /**
714     * Return the masked action being performed, without pointer index
715     * information.  May be any of the actions: {@link #ACTION_DOWN},
716     * {@link #ACTION_MOVE}, {@link #ACTION_UP}, {@link #ACTION_CANCEL},
717     * {@link #ACTION_POINTER_DOWN}, or {@link #ACTION_POINTER_UP}.
718     * Use {@link #getActionIndex} to return the index associated with
719     * pointer actions.
720     */
721    public final int getActionMasked() {
722        return mAction & ACTION_MASK;
723    }
724
725    /**
726     * For {@link #ACTION_POINTER_DOWN} or {@link #ACTION_POINTER_UP}
727     * as returned by {@link #getActionMasked}, this returns the associated
728     * pointer index.  The index may be used with {@link #getPointerId(int)},
729     * {@link #getX(int)}, {@link #getY(int)}, {@link #getPressure(int)},
730     * and {@link #getSize(int)} to get information about the pointer that has
731     * gone down or up.
732     */
733    public final int getActionIndex() {
734        return (mAction & ACTION_POINTER_INDEX_MASK) >> ACTION_POINTER_INDEX_SHIFT;
735    }
736
737    /**
738     * Gets the motion event flags.
739     *
740     * @see #FLAG_WINDOW_IS_OBSCURED
741     */
742    public final int getFlags() {
743        return mFlags;
744    }
745
746    /**
747     * Returns the time (in ms) when the user originally pressed down to start
748     * a stream of position events.
749     */
750    public final long getDownTime() {
751        return mDownTimeNano / MS_PER_NS;
752    }
753
754    /**
755     * Returns the time (in ms) when this specific event was generated.
756     */
757    public final long getEventTime() {
758        return mEventTimeNanoSamples[mLastEventTimeNanoSampleIndex] / MS_PER_NS;
759    }
760
761    /**
762     * Returns the time (in ns) when this specific event was generated.
763     * The value is in nanosecond precision but it may not have nanosecond accuracy.
764     *
765     * @hide
766     */
767    public final long getEventTimeNano() {
768        return mEventTimeNanoSamples[mLastEventTimeNanoSampleIndex];
769    }
770
771    /**
772     * {@link #getX(int)} for the first pointer index (may be an
773     * arbitrary pointer identifier).
774     */
775    public final float getX() {
776        return mDataSamples[mLastDataSampleIndex + SAMPLE_X] + mXOffset;
777    }
778
779    /**
780     * {@link #getY(int)} for the first pointer index (may be an
781     * arbitrary pointer identifier).
782     */
783    public final float getY() {
784        return mDataSamples[mLastDataSampleIndex + SAMPLE_Y] + mYOffset;
785    }
786
787    /**
788     * {@link #getPressure(int)} for the first pointer index (may be an
789     * arbitrary pointer identifier).
790     */
791    public final float getPressure() {
792        return mDataSamples[mLastDataSampleIndex + SAMPLE_PRESSURE];
793    }
794
795    /**
796     * {@link #getSize(int)} for the first pointer index (may be an
797     * arbitrary pointer identifier).
798     */
799    public final float getSize() {
800        return mDataSamples[mLastDataSampleIndex + SAMPLE_SIZE];
801    }
802
803    /**
804     * {@link #getTouchMajor(int)} for the first pointer index (may be an
805     * arbitrary pointer identifier).
806     */
807    public final float getTouchMajor() {
808        return mDataSamples[mLastDataSampleIndex + SAMPLE_TOUCH_MAJOR];
809    }
810
811    /**
812     * {@link #getTouchMinor(int)} for the first pointer index (may be an
813     * arbitrary pointer identifier).
814     */
815    public final float getTouchMinor() {
816        return mDataSamples[mLastDataSampleIndex + SAMPLE_TOUCH_MINOR];
817    }
818
819    /**
820     * {@link #getToolMajor(int)} for the first pointer index (may be an
821     * arbitrary pointer identifier).
822     */
823    public final float getToolMajor() {
824        return mDataSamples[mLastDataSampleIndex + SAMPLE_TOOL_MAJOR];
825    }
826
827    /**
828     * {@link #getToolMinor(int)} for the first pointer index (may be an
829     * arbitrary pointer identifier).
830     */
831    public final float getToolMinor() {
832        return mDataSamples[mLastDataSampleIndex + SAMPLE_TOOL_MINOR];
833    }
834
835    /**
836     * {@link #getOrientation(int)} for the first pointer index (may be an
837     * arbitrary pointer identifier).
838     */
839    public final float getOrientation() {
840        return mDataSamples[mLastDataSampleIndex + SAMPLE_ORIENTATION];
841    }
842
843    /**
844     * The number of pointers of data contained in this event.  Always
845     * >= 1.
846     */
847    public final int getPointerCount() {
848        return mNumPointers;
849    }
850
851    /**
852     * Return the pointer identifier associated with a particular pointer
853     * data index is this event.  The identifier tells you the actual pointer
854     * number associated with the data, accounting for individual pointers
855     * going up and down since the start of the current gesture.
856     * @param pointerIndex Raw index of pointer to retrieve.  Value may be from 0
857     * (the first pointer that is down) to {@link #getPointerCount()}-1.
858     */
859    public final int getPointerId(int pointerIndex) {
860        return mPointerIdentifiers[pointerIndex];
861    }
862
863    /**
864     * Given a pointer identifier, find the index of its data in the event.
865     *
866     * @param pointerId The identifier of the pointer to be found.
867     * @return Returns either the index of the pointer (for use with
868     * {@link #getX(int)} et al.), or -1 if there is no data available for
869     * that pointer identifier.
870     */
871    public final int findPointerIndex(int pointerId) {
872        int i = mNumPointers;
873        while (i > 0) {
874            i--;
875            if (mPointerIdentifiers[i] == pointerId) {
876                return i;
877            }
878        }
879        return -1;
880    }
881
882    /**
883     * Returns the X coordinate of this event for the given pointer
884     * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
885     * identifier for this index).
886     * Whole numbers are pixels; the
887     * value may have a fraction for input devices that are sub-pixel precise.
888     * @param pointerIndex Raw index of pointer to retrieve.  Value may be from 0
889     * (the first pointer that is down) to {@link #getPointerCount()}-1.
890     */
891    public final float getX(int pointerIndex) {
892        return mDataSamples[mLastDataSampleIndex
893                            + pointerIndex * NUM_SAMPLE_DATA + SAMPLE_X] + mXOffset;
894    }
895
896    /**
897     * Returns the Y coordinate of this event for the given pointer
898     * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
899     * identifier for this index).
900     * Whole numbers are pixels; the
901     * value may have a fraction for input devices that are sub-pixel precise.
902     * @param pointerIndex Raw index of pointer to retrieve.  Value may be from 0
903     * (the first pointer that is down) to {@link #getPointerCount()}-1.
904     */
905    public final float getY(int pointerIndex) {
906        return mDataSamples[mLastDataSampleIndex
907                            + pointerIndex * NUM_SAMPLE_DATA + SAMPLE_Y] + mYOffset;
908    }
909
910    /**
911     * Returns the current pressure of this event for the given pointer
912     * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
913     * identifier for this index).
914     * The pressure generally
915     * ranges from 0 (no pressure at all) to 1 (normal pressure), however
916     * values higher than 1 may be generated depending on the calibration of
917     * the input device.
918     * @param pointerIndex Raw index of pointer to retrieve.  Value may be from 0
919     * (the first pointer that is down) to {@link #getPointerCount()}-1.
920     */
921    public final float getPressure(int pointerIndex) {
922        return mDataSamples[mLastDataSampleIndex
923                            + pointerIndex * NUM_SAMPLE_DATA + SAMPLE_PRESSURE];
924    }
925
926    /**
927     * Returns a scaled value of the approximate size for the given pointer
928     * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
929     * identifier for this index).
930     * This represents some approximation of the area of the screen being
931     * pressed; the actual value in pixels corresponding to the
932     * touch is normalized with the device specific range of values
933     * and scaled to a value between 0 and 1. The value of size can be used to
934     * determine fat touch events.
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     */
938    public final float getSize(int pointerIndex) {
939        return mDataSamples[mLastDataSampleIndex
940                            + pointerIndex * NUM_SAMPLE_DATA + SAMPLE_SIZE];
941    }
942
943    /**
944     * Returns the length of the major axis of an ellipse that describes the touch
945     * area at the point of contact for the given pointer
946     * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
947     * identifier for this index).
948     * @param pointerIndex Raw index of pointer to retrieve.  Value may be from 0
949     * (the first pointer that is down) to {@link #getPointerCount()}-1.
950     */
951    public final float getTouchMajor(int pointerIndex) {
952        return mDataSamples[mLastDataSampleIndex
953                            + pointerIndex * NUM_SAMPLE_DATA + SAMPLE_TOUCH_MAJOR];
954    }
955
956    /**
957     * Returns the length of the minor axis of an ellipse that describes the touch
958     * area at the point of contact for the given pointer
959     * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
960     * identifier for this index).
961     * @param pointerIndex Raw index of pointer to retrieve.  Value may be from 0
962     * (the first pointer that is down) to {@link #getPointerCount()}-1.
963     */
964    public final float getTouchMinor(int pointerIndex) {
965        return mDataSamples[mLastDataSampleIndex
966                            + pointerIndex * NUM_SAMPLE_DATA + SAMPLE_TOUCH_MINOR];
967    }
968
969    /**
970     * Returns the length of the major axis of an ellipse that describes the size of
971     * the approaching tool for the given pointer
972     * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
973     * identifier for this index).
974     * The tool area represents the estimated size of the finger or pen that is
975     * touching the device independent of its actual touch area at the point of contact.
976     * @param pointerIndex Raw index of pointer to retrieve.  Value may be from 0
977     * (the first pointer that is down) to {@link #getPointerCount()}-1.
978     */
979    public final float getToolMajor(int pointerIndex) {
980        return mDataSamples[mLastDataSampleIndex
981                            + pointerIndex * NUM_SAMPLE_DATA + SAMPLE_TOOL_MAJOR];
982    }
983
984    /**
985     * Returns the length of the minor axis of an ellipse that describes the size of
986     * the approaching tool for the given pointer
987     * <em>index</em> (use {@link #getPointerId(int)} to find the pointer
988     * identifier for this index).
989     * The tool area represents the estimated size of the finger or pen that is
990     * touching the device independent of its actual touch area at the point of contact.
991     * @param pointerIndex Raw index of pointer to retrieve.  Value may be from 0
992     * (the first pointer that is down) to {@link #getPointerCount()}-1.
993     */
994    public final float getToolMinor(int pointerIndex) {
995        return mDataSamples[mLastDataSampleIndex
996                            + pointerIndex * NUM_SAMPLE_DATA + SAMPLE_TOOL_MINOR];
997    }
998
999    /**
1000     * Returns the orientation of the touch area and tool area in radians clockwise from vertical
1001     * for the given pointer <em>index</em> (use {@link #getPointerId(int)} to find the pointer
1002     * identifier for this index).
1003     * An angle of 0 degrees indicates that the major axis of contact is oriented
1004     * upwards, is perfectly circular or is of unknown orientation.  A positive angle
1005     * indicates that the major axis of contact is oriented to the right.  A negative angle
1006     * indicates that the major axis of contact is oriented to the left.
1007     * The full range is from -PI/2 radians (finger pointing fully left) to PI/2 radians
1008     * (finger pointing fully right).
1009     * @param pointerIndex Raw index of pointer to retrieve.  Value may be from 0
1010     * (the first pointer that is down) to {@link #getPointerCount()}-1.
1011     */
1012    public final float getOrientation(int pointerIndex) {
1013        return mDataSamples[mLastDataSampleIndex
1014                            + pointerIndex * NUM_SAMPLE_DATA + SAMPLE_ORIENTATION];
1015    }
1016
1017    /**
1018     * Populates a {@link PointerCoords} object with pointer coordinate data for
1019     * the specified pointer index.
1020     *
1021     * @param pointerIndex Raw index of pointer to retrieve.  Value may be from 0
1022     * (the first pointer that is down) to {@link #getPointerCount()}-1.
1023     * @param outPointerCoords The pointer coordinate object to populate.
1024     */
1025    public final void getPointerCoords(int pointerIndex, PointerCoords outPointerCoords) {
1026        final int sampleIndex = mLastDataSampleIndex + pointerIndex * NUM_SAMPLE_DATA;
1027        getPointerCoordsAtSampleIndex(sampleIndex, outPointerCoords);
1028    }
1029
1030    /**
1031     * Returns the state of any meta / modifier keys that were in effect when
1032     * the event was generated.  This is the same values as those
1033     * returned by {@link KeyEvent#getMetaState() KeyEvent.getMetaState}.
1034     *
1035     * @return an integer in which each bit set to 1 represents a pressed
1036     *         meta key
1037     *
1038     * @see KeyEvent#getMetaState()
1039     */
1040    public final int getMetaState() {
1041        return mMetaState;
1042    }
1043
1044    /**
1045     * Returns the original raw X coordinate of this event.  For touch
1046     * events on the screen, this is the original location of the event
1047     * on the screen, before it had been adjusted for the containing window
1048     * and views.
1049     */
1050    public final float getRawX() {
1051        return mDataSamples[mLastDataSampleIndex + SAMPLE_X];
1052    }
1053
1054    /**
1055     * Returns the original raw Y coordinate of this event.  For touch
1056     * events on the screen, this is the original location of the event
1057     * on the screen, before it had been adjusted for the containing window
1058     * and views.
1059     */
1060    public final float getRawY() {
1061        return mDataSamples[mLastDataSampleIndex + SAMPLE_Y];
1062    }
1063
1064    /**
1065     * Return the precision of the X coordinates being reported.  You can
1066     * multiple this number with {@link #getX} to find the actual hardware
1067     * value of the X coordinate.
1068     * @return Returns the precision of X coordinates being reported.
1069     */
1070    public final float getXPrecision() {
1071        return mXPrecision;
1072    }
1073
1074    /**
1075     * Return the precision of the Y coordinates being reported.  You can
1076     * multiple this number with {@link #getY} to find the actual hardware
1077     * value of the Y coordinate.
1078     * @return Returns the precision of Y coordinates being reported.
1079     */
1080    public final float getYPrecision() {
1081        return mYPrecision;
1082    }
1083
1084    /**
1085     * Returns the number of historical points in this event.  These are
1086     * movements that have occurred between this event and the previous event.
1087     * This only applies to ACTION_MOVE events -- all other actions will have
1088     * a size of 0.
1089     *
1090     * @return Returns the number of historical points in the event.
1091     */
1092    public final int getHistorySize() {
1093        return mLastEventTimeNanoSampleIndex;
1094    }
1095
1096    /**
1097     * Returns the time that a historical movement occurred between this event
1098     * and the previous event.  Only applies to ACTION_MOVE events.
1099     *
1100     * @param pos Which historical value to return; must be less than
1101     * {@link #getHistorySize}
1102     *
1103     * @see #getHistorySize
1104     * @see #getEventTime
1105     */
1106    public final long getHistoricalEventTime(int pos) {
1107        return mEventTimeNanoSamples[pos] / MS_PER_NS;
1108    }
1109
1110    /**
1111     * {@link #getHistoricalX(int)} for the first pointer index (may be an
1112     * arbitrary pointer identifier).
1113     */
1114    public final float getHistoricalX(int pos) {
1115        return mDataSamples[pos * mNumPointers * NUM_SAMPLE_DATA + SAMPLE_X] + mXOffset;
1116    }
1117
1118    /**
1119     * {@link #getHistoricalY(int)} for the first pointer index (may be an
1120     * arbitrary pointer identifier).
1121     */
1122    public final float getHistoricalY(int pos) {
1123        return mDataSamples[pos * mNumPointers * NUM_SAMPLE_DATA + SAMPLE_Y] + mYOffset;
1124    }
1125
1126    /**
1127     * {@link #getHistoricalPressure(int)} for the first pointer index (may be an
1128     * arbitrary pointer identifier).
1129     */
1130    public final float getHistoricalPressure(int pos) {
1131        return mDataSamples[pos * mNumPointers * NUM_SAMPLE_DATA + SAMPLE_PRESSURE];
1132    }
1133
1134    /**
1135     * {@link #getHistoricalSize(int)} for the first pointer index (may be an
1136     * arbitrary pointer identifier).
1137     */
1138    public final float getHistoricalSize(int pos) {
1139        return mDataSamples[pos * mNumPointers * NUM_SAMPLE_DATA + SAMPLE_SIZE];
1140    }
1141
1142    /**
1143     * {@link #getHistoricalTouchMajor(int)} for the first pointer index (may be an
1144     * arbitrary pointer identifier).
1145     */
1146    public final float getHistoricalTouchMajor(int pos) {
1147        return mDataSamples[pos * mNumPointers * NUM_SAMPLE_DATA + SAMPLE_TOUCH_MAJOR];
1148    }
1149
1150    /**
1151     * {@link #getHistoricalTouchMinor(int)} for the first pointer index (may be an
1152     * arbitrary pointer identifier).
1153     */
1154    public final float getHistoricalTouchMinor(int pos) {
1155        return mDataSamples[pos * mNumPointers * NUM_SAMPLE_DATA + SAMPLE_TOUCH_MINOR];
1156    }
1157
1158    /**
1159     * {@link #getHistoricalToolMajor(int)} for the first pointer index (may be an
1160     * arbitrary pointer identifier).
1161     */
1162    public final float getHistoricalToolMajor(int pos) {
1163        return mDataSamples[pos * mNumPointers * NUM_SAMPLE_DATA + SAMPLE_TOOL_MAJOR];
1164    }
1165
1166    /**
1167     * {@link #getHistoricalToolMinor(int)} for the first pointer index (may be an
1168     * arbitrary pointer identifier).
1169     */
1170    public final float getHistoricalToolMinor(int pos) {
1171        return mDataSamples[pos * mNumPointers * NUM_SAMPLE_DATA + SAMPLE_TOOL_MINOR];
1172    }
1173
1174    /**
1175     * {@link #getHistoricalOrientation(int)} for the first pointer index (may be an
1176     * arbitrary pointer identifier).
1177     */
1178    public final float getHistoricalOrientation(int pos) {
1179        return mDataSamples[pos * mNumPointers * NUM_SAMPLE_DATA + SAMPLE_ORIENTATION];
1180    }
1181
1182    /**
1183     * Returns a historical X coordinate, as per {@link #getX(int)}, that
1184     * occurred between this event and the previous event for the given pointer.
1185     * Only applies to ACTION_MOVE events.
1186     *
1187     * @param pointerIndex Raw index of pointer to retrieve.  Value may be from 0
1188     * (the first pointer that is down) to {@link #getPointerCount()}-1.
1189     * @param pos Which historical value to return; must be less than
1190     * {@link #getHistorySize}
1191     *
1192     * @see #getHistorySize
1193     * @see #getX
1194     */
1195    public final float getHistoricalX(int pointerIndex, int pos) {
1196        return mDataSamples[(pos * mNumPointers + pointerIndex)
1197                            * NUM_SAMPLE_DATA + SAMPLE_X] + mXOffset;
1198    }
1199
1200    /**
1201     * Returns a historical Y coordinate, as per {@link #getY(int)}, that
1202     * occurred between this event and the previous event for the given pointer.
1203     * Only applies to ACTION_MOVE events.
1204     *
1205     * @param pointerIndex Raw index of pointer to retrieve.  Value may be from 0
1206     * (the first pointer that is down) to {@link #getPointerCount()}-1.
1207     * @param pos Which historical value to return; must be less than
1208     * {@link #getHistorySize}
1209     *
1210     * @see #getHistorySize
1211     * @see #getY
1212     */
1213    public final float getHistoricalY(int pointerIndex, int pos) {
1214        return mDataSamples[(pos * mNumPointers + pointerIndex)
1215                            * NUM_SAMPLE_DATA + SAMPLE_Y] + mYOffset;
1216    }
1217
1218    /**
1219     * Returns a historical pressure coordinate, as per {@link #getPressure(int)},
1220     * that occurred between this event and the previous event for the given
1221     * pointer.  Only applies to ACTION_MOVE events.
1222     *
1223     * @param pointerIndex Raw index of pointer to retrieve.  Value may be from 0
1224     * (the first pointer that is down) to {@link #getPointerCount()}-1.
1225     * @param pos Which historical value to return; must be less than
1226     * {@link #getHistorySize}
1227     *
1228     * @see #getHistorySize
1229     * @see #getPressure
1230     */
1231    public final float getHistoricalPressure(int pointerIndex, int pos) {
1232        return mDataSamples[(pos * mNumPointers + pointerIndex)
1233                            * NUM_SAMPLE_DATA + SAMPLE_PRESSURE];
1234    }
1235
1236    /**
1237     * Returns a historical size coordinate, as per {@link #getSize(int)}, that
1238     * occurred between this event and the previous event for the given pointer.
1239     * Only applies to ACTION_MOVE events.
1240     *
1241     * @param pointerIndex Raw index of pointer to retrieve.  Value may be from 0
1242     * (the first pointer that is down) to {@link #getPointerCount()}-1.
1243     * @param pos Which historical value to return; must be less than
1244     * {@link #getHistorySize}
1245     *
1246     * @see #getHistorySize
1247     * @see #getSize
1248     */
1249    public final float getHistoricalSize(int pointerIndex, int pos) {
1250        return mDataSamples[(pos * mNumPointers + pointerIndex)
1251                            * NUM_SAMPLE_DATA + SAMPLE_SIZE];
1252    }
1253
1254    /**
1255     * Returns a historical touch major axis coordinate, as per {@link #getTouchMajor(int)}, that
1256     * occurred between this event and the previous event for the given pointer.
1257     * Only applies to ACTION_MOVE events.
1258     *
1259     * @param pointerIndex Raw index of pointer to retrieve.  Value may be from 0
1260     * (the first pointer that is down) to {@link #getPointerCount()}-1.
1261     * @param pos Which historical value to return; must be less than
1262     * {@link #getHistorySize}
1263     *
1264     * @see #getHistorySize
1265     * @see #getTouchMajor
1266     */
1267    public final float getHistoricalTouchMajor(int pointerIndex, int pos) {
1268        return mDataSamples[(pos * mNumPointers + pointerIndex)
1269                            * NUM_SAMPLE_DATA + SAMPLE_TOUCH_MAJOR];
1270    }
1271
1272    /**
1273     * Returns a historical touch minor axis coordinate, as per {@link #getTouchMinor(int)}, that
1274     * occurred between this event and the previous event for the given pointer.
1275     * Only applies to ACTION_MOVE events.
1276     *
1277     * @param pointerIndex Raw index of pointer to retrieve.  Value may be from 0
1278     * (the first pointer that is down) to {@link #getPointerCount()}-1.
1279     * @param pos Which historical value to return; must be less than
1280     * {@link #getHistorySize}
1281     *
1282     * @see #getHistorySize
1283     * @see #getTouchMinor
1284     */
1285    public final float getHistoricalTouchMinor(int pointerIndex, int pos) {
1286        return mDataSamples[(pos * mNumPointers + pointerIndex)
1287                            * NUM_SAMPLE_DATA + SAMPLE_TOUCH_MINOR];
1288    }
1289
1290    /**
1291     * Returns a historical tool major axis coordinate, as per {@link #getToolMajor(int)}, that
1292     * occurred between this event and the previous event for the given pointer.
1293     * Only applies to ACTION_MOVE events.
1294     *
1295     * @param pointerIndex Raw index of pointer to retrieve.  Value may be from 0
1296     * (the first pointer that is down) to {@link #getPointerCount()}-1.
1297     * @param pos Which historical value to return; must be less than
1298     * {@link #getHistorySize}
1299     *
1300     * @see #getHistorySize
1301     * @see #getToolMajor
1302     */
1303    public final float getHistoricalToolMajor(int pointerIndex, int pos) {
1304        return mDataSamples[(pos * mNumPointers + pointerIndex)
1305                            * NUM_SAMPLE_DATA + SAMPLE_TOOL_MAJOR];
1306    }
1307
1308    /**
1309     * Returns a historical tool minor axis coordinate, as per {@link #getToolMinor(int)}, that
1310     * occurred between this event and the previous event for the given pointer.
1311     * Only applies to ACTION_MOVE events.
1312     *
1313     * @param pointerIndex Raw index of pointer to retrieve.  Value may be from 0
1314     * (the first pointer that is down) to {@link #getPointerCount()}-1.
1315     * @param pos Which historical value to return; must be less than
1316     * {@link #getHistorySize}
1317     *
1318     * @see #getHistorySize
1319     * @see #getToolMinor
1320     */
1321    public final float getHistoricalToolMinor(int pointerIndex, int pos) {
1322        return mDataSamples[(pos * mNumPointers + pointerIndex)
1323                            * NUM_SAMPLE_DATA + SAMPLE_TOOL_MINOR];
1324    }
1325
1326    /**
1327     * Returns a historical orientation coordinate, as per {@link #getOrientation(int)}, that
1328     * occurred between this event and the previous event for the given pointer.
1329     * Only applies to ACTION_MOVE events.
1330     *
1331     * @param pointerIndex Raw index of pointer to retrieve.  Value may be from 0
1332     * (the first pointer that is down) to {@link #getPointerCount()}-1.
1333     * @param pos Which historical value to return; must be less than
1334     * {@link #getHistorySize}
1335     *
1336     * @see #getHistorySize
1337     * @see #getOrientation
1338     */
1339    public final float getHistoricalOrientation(int pointerIndex, int pos) {
1340        return mDataSamples[(pos * mNumPointers + pointerIndex)
1341                            * NUM_SAMPLE_DATA + SAMPLE_ORIENTATION];
1342    }
1343
1344    /**
1345     * Populates a {@link PointerCoords} object with historical pointer coordinate data,
1346     * as per {@link #getPointerCoords}, that occurred between this event and the previous
1347     * event for the given pointer.
1348     * Only applies to ACTION_MOVE events.
1349     *
1350     * @param pointerIndex Raw index of pointer to retrieve.  Value may be from 0
1351     * (the first pointer that is down) to {@link #getPointerCount()}-1.
1352     * @param pos Which historical value to return; must be less than
1353     * {@link #getHistorySize}
1354     * @param outPointerCoords The pointer coordinate object to populate.
1355     *
1356     * @see #getHistorySize
1357     * @see #getPointerCoords
1358     */
1359    public final void getHistoricalPointerCoords(int pointerIndex, int pos,
1360            PointerCoords outPointerCoords) {
1361        final int sampleIndex = (pos * mNumPointers + pointerIndex) * NUM_SAMPLE_DATA;
1362        getPointerCoordsAtSampleIndex(sampleIndex, outPointerCoords);
1363    }
1364
1365    /**
1366     * Returns a bitfield indicating which edges, if any, were touched by this
1367     * MotionEvent. For touch events, clients can use this to determine if the
1368     * user's finger was touching the edge of the display.
1369     *
1370     * @see #EDGE_LEFT
1371     * @see #EDGE_TOP
1372     * @see #EDGE_RIGHT
1373     * @see #EDGE_BOTTOM
1374     */
1375    public final int getEdgeFlags() {
1376        return mEdgeFlags;
1377    }
1378
1379
1380    /**
1381     * Sets the bitfield indicating which edges, if any, were touched by this
1382     * MotionEvent.
1383     *
1384     * @see #getEdgeFlags()
1385     */
1386    public final void setEdgeFlags(int flags) {
1387        mEdgeFlags = flags;
1388    }
1389
1390    /**
1391     * Sets this event's action.
1392     */
1393    public final void setAction(int action) {
1394        mAction = action;
1395    }
1396
1397    /**
1398     * Adjust this event's location.
1399     * @param deltaX Amount to add to the current X coordinate of the event.
1400     * @param deltaY Amount to add to the current Y coordinate of the event.
1401     */
1402    public final void offsetLocation(float deltaX, float deltaY) {
1403        mXOffset += deltaX;
1404        mYOffset += deltaY;
1405    }
1406
1407    /**
1408     * Set this event's location.  Applies {@link #offsetLocation} with a
1409     * delta from the current location to the given new location.
1410     *
1411     * @param x New absolute X location.
1412     * @param y New absolute Y location.
1413     */
1414    public final void setLocation(float x, float y) {
1415        final float[] dataSamples = mDataSamples;
1416        final int lastDataSampleIndex = mLastDataSampleIndex;
1417        mXOffset = x - dataSamples[lastDataSampleIndex + SAMPLE_X];
1418        mYOffset = y - dataSamples[lastDataSampleIndex + SAMPLE_Y];
1419    }
1420
1421    /**
1422     * Applies a transformation matrix to all of the points in the event.
1423     *
1424     * @param matrix The transformation matrix to apply.
1425     */
1426    public final void transform(Matrix matrix) {
1427        if (matrix == null) {
1428            throw new IllegalArgumentException("matrix must not be null");
1429        }
1430
1431        nativeTransform(matrix);
1432    }
1433
1434    private final void getPointerCoordsAtSampleIndex(int sampleIndex,
1435            PointerCoords outPointerCoords) {
1436        final float[] dataSamples = mDataSamples;
1437        outPointerCoords.x = dataSamples[sampleIndex + SAMPLE_X] + mXOffset;
1438        outPointerCoords.y = dataSamples[sampleIndex + SAMPLE_Y] + mYOffset;
1439        outPointerCoords.pressure = dataSamples[sampleIndex + SAMPLE_PRESSURE];
1440        outPointerCoords.size = dataSamples[sampleIndex + SAMPLE_SIZE];
1441        outPointerCoords.touchMajor = dataSamples[sampleIndex + SAMPLE_TOUCH_MAJOR];
1442        outPointerCoords.touchMinor = dataSamples[sampleIndex + SAMPLE_TOUCH_MINOR];
1443        outPointerCoords.toolMajor = dataSamples[sampleIndex + SAMPLE_TOOL_MAJOR];
1444        outPointerCoords.toolMinor = dataSamples[sampleIndex + SAMPLE_TOOL_MINOR];
1445        outPointerCoords.orientation = dataSamples[sampleIndex + SAMPLE_ORIENTATION];
1446    }
1447
1448    private final void setPointerCoordsAtSampleIndex(int sampleIndex,
1449            PointerCoords[] pointerCoords) {
1450        final int numPointers = mNumPointers;
1451        for (int i = 0; i < numPointers; i++) {
1452            setPointerCoordsAtSampleIndex(sampleIndex, pointerCoords[i]);
1453            sampleIndex += NUM_SAMPLE_DATA;
1454        }
1455    }
1456
1457    private final void setPointerCoordsAtSampleIndex(int sampleIndex,
1458            PointerCoords pointerCoords) {
1459        final float[] dataSamples = mDataSamples;
1460        dataSamples[sampleIndex + SAMPLE_X] = pointerCoords.x - mXOffset;
1461        dataSamples[sampleIndex + SAMPLE_Y] = pointerCoords.y - mYOffset;
1462        dataSamples[sampleIndex + SAMPLE_PRESSURE] = pointerCoords.pressure;
1463        dataSamples[sampleIndex + SAMPLE_SIZE] = pointerCoords.size;
1464        dataSamples[sampleIndex + SAMPLE_TOUCH_MAJOR] = pointerCoords.touchMajor;
1465        dataSamples[sampleIndex + SAMPLE_TOUCH_MINOR] = pointerCoords.touchMinor;
1466        dataSamples[sampleIndex + SAMPLE_TOOL_MAJOR] = pointerCoords.toolMajor;
1467        dataSamples[sampleIndex + SAMPLE_TOOL_MINOR] = pointerCoords.toolMinor;
1468        dataSamples[sampleIndex + SAMPLE_ORIENTATION] = pointerCoords.orientation;
1469    }
1470
1471    private final void setPointerCoordsAtSampleIndex(int sampleIndex,
1472            float x, float y, float pressure, float size) {
1473        final float[] dataSamples = mDataSamples;
1474        dataSamples[sampleIndex + SAMPLE_X] = x - mXOffset;
1475        dataSamples[sampleIndex + SAMPLE_Y] = y - mYOffset;
1476        dataSamples[sampleIndex + SAMPLE_PRESSURE] = pressure;
1477        dataSamples[sampleIndex + SAMPLE_SIZE] = size;
1478        dataSamples[sampleIndex + SAMPLE_TOUCH_MAJOR] = pressure;
1479        dataSamples[sampleIndex + SAMPLE_TOUCH_MINOR] = pressure;
1480        dataSamples[sampleIndex + SAMPLE_TOOL_MAJOR] = size;
1481        dataSamples[sampleIndex + SAMPLE_TOOL_MINOR] = size;
1482        dataSamples[sampleIndex + SAMPLE_ORIENTATION] = 0;
1483    }
1484
1485    private final void incrementNumSamplesAndReserveStorage(int dataSampleStride) {
1486        if (mNumSamples == mEventTimeNanoSamples.length) {
1487            long[] newEventTimeNanoSamples = new long[mNumSamples + BASE_AVAIL_SAMPLES];
1488            System.arraycopy(mEventTimeNanoSamples, 0, newEventTimeNanoSamples, 0, mNumSamples);
1489            mEventTimeNanoSamples = newEventTimeNanoSamples;
1490        }
1491
1492        int nextDataSampleIndex = mLastDataSampleIndex + dataSampleStride;
1493        if (nextDataSampleIndex + dataSampleStride > mDataSamples.length) {
1494            float[] newDataSamples = new float[nextDataSampleIndex
1495                                               + BASE_AVAIL_SAMPLES * dataSampleStride];
1496            System.arraycopy(mDataSamples, 0, newDataSamples, 0, nextDataSampleIndex);
1497            mDataSamples = newDataSamples;
1498        }
1499
1500        mLastEventTimeNanoSampleIndex = mNumSamples;
1501        mLastDataSampleIndex = nextDataSampleIndex;
1502        mNumSamples += 1;
1503    }
1504
1505    /**
1506     * Add a new movement to the batch of movements in this event.  The event's
1507     * current location, position and size is updated to the new values.
1508     * The current values in the event are added to a list of historical values.
1509     *
1510     * Only applies to {@link #ACTION_MOVE} events.
1511     *
1512     * @param eventTime The time stamp (in ms) for this data.
1513     * @param x The new X position.
1514     * @param y The new Y position.
1515     * @param pressure The new pressure.
1516     * @param size The new size.
1517     * @param metaState Meta key state.
1518     */
1519    public final void addBatch(long eventTime, float x, float y,
1520            float pressure, float size, int metaState) {
1521        incrementNumSamplesAndReserveStorage(NUM_SAMPLE_DATA);
1522
1523        mEventTimeNanoSamples[mLastEventTimeNanoSampleIndex] = eventTime * MS_PER_NS;
1524        setPointerCoordsAtSampleIndex(mLastDataSampleIndex, x, y, pressure, size);
1525
1526        mMetaState |= metaState;
1527    }
1528
1529    /**
1530     * Add a new movement to the batch of movements in this event.  The event's
1531     * current location, position and size is updated to the new values.
1532     * The current values in the event are added to a list of historical values.
1533     *
1534     * Only applies to {@link #ACTION_MOVE} events.
1535     *
1536     * @param eventTime The time stamp (in ms) for this data.
1537     * @param pointerCoords The new pointer coordinates.
1538     * @param metaState Meta key state.
1539     */
1540    public final void addBatch(long eventTime, PointerCoords[] pointerCoords, int metaState) {
1541        final int dataSampleStride = mNumPointers * NUM_SAMPLE_DATA;
1542        incrementNumSamplesAndReserveStorage(dataSampleStride);
1543
1544        mEventTimeNanoSamples[mLastEventTimeNanoSampleIndex] = eventTime * MS_PER_NS;
1545        setPointerCoordsAtSampleIndex(mLastDataSampleIndex, pointerCoords);
1546
1547        mMetaState |= metaState;
1548    }
1549
1550    @Override
1551    public String toString() {
1552        return "MotionEvent{" + Integer.toHexString(System.identityHashCode(this))
1553            + " pointerId=" + getPointerId(0)
1554            + " action=" + actionToString(mAction)
1555            + " x=" + getX()
1556            + " y=" + getY()
1557            + " pressure=" + getPressure()
1558            + " size=" + getSize()
1559            + " touchMajor=" + getTouchMajor()
1560            + " touchMinor=" + getTouchMinor()
1561            + " toolMajor=" + getToolMajor()
1562            + " toolMinor=" + getToolMinor()
1563            + " orientation=" + getOrientation()
1564            + " meta=" + KeyEvent.metaStateToString(mMetaState)
1565            + " pointerCount=" + getPointerCount()
1566            + " historySize=" + getHistorySize()
1567            + " flags=0x" + Integer.toHexString(mFlags)
1568            + " edgeFlags=0x" + Integer.toHexString(mEdgeFlags)
1569            + " device=" + mDeviceId
1570            + " source=0x" + Integer.toHexString(mSource)
1571            + (getPointerCount() > 1 ?
1572                " pointerId2=" + getPointerId(1) + " x2=" + getX(1) + " y2=" + getY(1) : "")
1573            + "}";
1574    }
1575
1576    /**
1577     * Returns a string that represents the symbolic name of the specified action
1578     * such as "ACTION_DOWN", "ACTION_POINTER_DOWN(3)" or "35" (if unknown).
1579     *
1580     * @param action The action.
1581     * @return The symbolic name of the specified action.
1582     * @hide
1583     */
1584    public static String actionToString(int action) {
1585        switch (action) {
1586            case ACTION_DOWN:
1587                return "ACTION_DOWN";
1588            case ACTION_UP:
1589                return "ACTION_UP";
1590            case ACTION_CANCEL:
1591                return "ACTION_CANCEL";
1592            case ACTION_MOVE:
1593                return "ACTION_MOVE";
1594        }
1595        int index = (action & ACTION_POINTER_INDEX_MASK) >> ACTION_POINTER_INDEX_SHIFT;
1596        switch (action & ACTION_MASK) {
1597            case ACTION_POINTER_DOWN:
1598                return "ACTION_POINTER_DOWN(" + index + ")";
1599            case ACTION_POINTER_UP:
1600                return "ACTION_POINTER_UP(" + index + ")";
1601            default:
1602                return Integer.toString(action);
1603        }
1604    }
1605
1606    public static final Parcelable.Creator<MotionEvent> CREATOR
1607            = new Parcelable.Creator<MotionEvent>() {
1608        public MotionEvent createFromParcel(Parcel in) {
1609            in.readInt(); // skip token, we already know this is a MotionEvent
1610            return MotionEvent.createFromParcelBody(in);
1611        }
1612
1613        public MotionEvent[] newArray(int size) {
1614            return new MotionEvent[size];
1615        }
1616    };
1617
1618    /** @hide */
1619    public static MotionEvent createFromParcelBody(Parcel in) {
1620        final int NP = in.readInt();
1621        final int NS = in.readInt();
1622        final int NI = NP * NS * NUM_SAMPLE_DATA;
1623
1624        MotionEvent ev = obtain(NP, NS);
1625        ev.mNumPointers = NP;
1626        ev.mNumSamples = NS;
1627
1628        ev.readBaseFromParcel(in);
1629
1630        ev.mDownTimeNano = in.readLong();
1631        ev.mAction = in.readInt();
1632        ev.mXOffset = in.readFloat();
1633        ev.mYOffset = in.readFloat();
1634        ev.mXPrecision = in.readFloat();
1635        ev.mYPrecision = in.readFloat();
1636        ev.mEdgeFlags = in.readInt();
1637        ev.mMetaState = in.readInt();
1638        ev.mFlags = in.readInt();
1639
1640        final int[] pointerIdentifiers = ev.mPointerIdentifiers;
1641        for (int i = 0; i < NP; i++) {
1642            pointerIdentifiers[i] = in.readInt();
1643        }
1644
1645        final long[] eventTimeNanoSamples = ev.mEventTimeNanoSamples;
1646        for (int i = 0; i < NS; i++) {
1647            eventTimeNanoSamples[i] = in.readLong();
1648        }
1649
1650        final float[] dataSamples = ev.mDataSamples;
1651        for (int i = 0; i < NI; i++) {
1652            dataSamples[i] = in.readFloat();
1653        }
1654
1655        ev.mLastEventTimeNanoSampleIndex = NS - 1;
1656        ev.mLastDataSampleIndex = (NS - 1) * NP * NUM_SAMPLE_DATA;
1657        return ev;
1658    }
1659
1660    public void writeToParcel(Parcel out, int flags) {
1661        out.writeInt(PARCEL_TOKEN_MOTION_EVENT);
1662
1663        final int NP = mNumPointers;
1664        final int NS = mNumSamples;
1665        final int NI = NP * NS * NUM_SAMPLE_DATA;
1666
1667        out.writeInt(NP);
1668        out.writeInt(NS);
1669
1670        writeBaseToParcel(out);
1671
1672        out.writeLong(mDownTimeNano);
1673        out.writeInt(mAction);
1674        out.writeFloat(mXOffset);
1675        out.writeFloat(mYOffset);
1676        out.writeFloat(mXPrecision);
1677        out.writeFloat(mYPrecision);
1678        out.writeInt(mEdgeFlags);
1679        out.writeInt(mMetaState);
1680        out.writeInt(mFlags);
1681
1682        final int[] pointerIdentifiers = mPointerIdentifiers;
1683        for (int i = 0; i < NP; i++) {
1684            out.writeInt(pointerIdentifiers[i]);
1685        }
1686
1687        final long[] eventTimeNanoSamples = mEventTimeNanoSamples;
1688        for (int i = 0; i < NS; i++) {
1689            out.writeLong(eventTimeNanoSamples[i]);
1690        }
1691
1692        final float[] dataSamples = mDataSamples;
1693        for (int i = 0; i < NI; i++) {
1694            out.writeFloat(dataSamples[i]);
1695        }
1696    }
1697
1698    /**
1699     * Transfer object for pointer coordinates.
1700     *
1701     * Objects of this type can be used to manufacture new {@link MotionEvent} objects
1702     * and to query pointer coordinate information in bulk.
1703     *
1704     * Refer to {@link InputDevice} for information about how different kinds of
1705     * input devices and sources represent pointer coordinates.
1706     */
1707    public static final class PointerCoords {
1708        /**
1709         * The X coordinate of the pointer movement.
1710         * The interpretation varies by input source and may represent the position of
1711         * the center of the contact area, a relative displacement in device-specific units
1712         * or something else.
1713         */
1714        public float x;
1715
1716        /**
1717         * The Y coordinate of the pointer movement.
1718         * The interpretation varies by input source and may represent the position of
1719         * the center of the contact area, a relative displacement in device-specific units
1720         * or something else.
1721         */
1722        public float y;
1723
1724        /**
1725         * A scaled value that describes the pressure applied to the pointer.
1726         * The pressure generally ranges from 0 (no pressure at all) to 1 (normal pressure),
1727         * however values higher than 1 may be generated depending on the calibration of
1728         * the input device.
1729         */
1730        public float pressure;
1731
1732        /**
1733         * A scaled value of the approximate size of the pointer touch area.
1734         * This represents some approximation of the area of the screen being
1735         * pressed; the actual value in pixels corresponding to the
1736         * touch is normalized with the device specific range of values
1737         * and scaled to a value between 0 and 1. The value of size can be used to
1738         * determine fat touch events.
1739         */
1740        public float size;
1741
1742        /**
1743         * The length of the major axis of an ellipse that describes the touch area at
1744         * the point of contact.
1745         */
1746        public float touchMajor;
1747
1748        /**
1749         * The length of the minor axis of an ellipse that describes the touch area at
1750         * the point of contact.
1751         */
1752        public float touchMinor;
1753
1754        /**
1755         * The length of the major axis of an ellipse that describes the size of
1756         * the approaching tool.
1757         * The tool area represents the estimated size of the finger or pen that is
1758         * touching the device independent of its actual touch area at the point of contact.
1759         */
1760        public float toolMajor;
1761
1762        /**
1763         * The length of the minor axis of an ellipse that describes the size of
1764         * the approaching tool.
1765         * The tool area represents the estimated size of the finger or pen that is
1766         * touching the device independent of its actual touch area at the point of contact.
1767         */
1768        public float toolMinor;
1769
1770        /**
1771         * The orientation of the touch area and tool area in radians clockwise from vertical.
1772         * An angle of 0 degrees indicates that the major axis of contact is oriented
1773         * upwards, is perfectly circular or is of unknown orientation.  A positive angle
1774         * indicates that the major axis of contact is oriented to the right.  A negative angle
1775         * indicates that the major axis of contact is oriented to the left.
1776         * The full range is from -PI/2 radians (finger pointing fully left) to PI/2 radians
1777         * (finger pointing fully right).
1778         */
1779        public float orientation;
1780
1781        /*
1782        private static final float PI_4 = (float) (Math.PI / 4);
1783
1784        public float getTouchWidth() {
1785            return Math.abs(orientation) > PI_4 ? touchMajor : touchMinor;
1786        }
1787
1788        public float getTouchHeight() {
1789            return Math.abs(orientation) > PI_4 ? touchMinor : touchMajor;
1790        }
1791
1792        public float getToolWidth() {
1793            return Math.abs(orientation) > PI_4 ? toolMajor : toolMinor;
1794        }
1795
1796        public float getToolHeight() {
1797            return Math.abs(orientation) > PI_4 ? toolMinor : toolMajor;
1798        }
1799        */
1800    }
1801}
1802