The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | |
| 17 | package android.view; |
| 18 | |
| 19 | import android.os.Parcel; |
| 20 | import android.os.Parcelable; |
| 21 | import android.os.SystemClock; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 22 | |
| 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 Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 27 | * |
| 28 | * Refer to {@link InputDevice} for information about how different kinds of |
| 29 | * input devices and sources represent pointer coordinates. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | */ |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 31 | public final class MotionEvent extends InputEvent implements Parcelable { |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 32 | private static final long MS_PER_NS = 1000000; |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 33 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | /** |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 35 | * 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | * 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 Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 44 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 45 | /** |
| 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 Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 51 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | /** |
| 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 Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 59 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 60 | /** |
| 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 Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 66 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | /** |
| 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 Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 74 | /** |
| 75 | * A non-primary pointer has gone down. The bits in |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 76 | * {@link #ACTION_POINTER_ID_MASK} indicate which pointer changed. |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 77 | */ |
| 78 | public static final int ACTION_POINTER_DOWN = 5; |
| 79 | |
| 80 | /** |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 81 | * A non-primary pointer has gone up. The bits in |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 82 | * {@link #ACTION_POINTER_ID_MASK} indicate which pointer changed. |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 83 | */ |
| 84 | public static final int ACTION_POINTER_UP = 6; |
| 85 | |
| 86 | /** |
Dianne Hackborn | b125dc5 | 2010-02-12 15:52:09 -0800 | [diff] [blame] | 87 | * 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 Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 93 | */ |
Dianne Hackborn | b125dc5 | 2010-02-12 15:52:09 -0800 | [diff] [blame] | 94 | 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 Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 128 | public static final int ACTION_POINTER_1_UP = ACTION_POINTER_UP | 0x0000; |
| 129 | |
| 130 | /** |
Dianne Hackborn | b125dc5 | 2010-02-12 15:52:09 -0800 | [diff] [blame] | 131 | * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the |
| 132 | * data index associated with {@link #ACTION_POINTER_UP}. |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 133 | */ |
Dianne Hackborn | b125dc5 | 2010-02-12 15:52:09 -0800 | [diff] [blame] | 134 | @Deprecated |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 135 | public static final int ACTION_POINTER_2_UP = ACTION_POINTER_UP | 0x0100; |
| 136 | |
| 137 | /** |
Dianne Hackborn | b125dc5 | 2010-02-12 15:52:09 -0800 | [diff] [blame] | 138 | * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the |
| 139 | * data index associated with {@link #ACTION_POINTER_UP}. |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 140 | */ |
Dianne Hackborn | b125dc5 | 2010-02-12 15:52:09 -0800 | [diff] [blame] | 141 | @Deprecated |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 142 | public static final int ACTION_POINTER_3_UP = ACTION_POINTER_UP | 0x0200; |
| 143 | |
| 144 | /** |
Dianne Hackborn | b125dc5 | 2010-02-12 15:52:09 -0800 | [diff] [blame] | 145 | * @deprecated Renamed to {@link #ACTION_POINTER_INDEX_MASK} to match |
| 146 | * the actual data contained in these bits. |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 147 | */ |
Dianne Hackborn | b125dc5 | 2010-02-12 15:52:09 -0800 | [diff] [blame] | 148 | @Deprecated |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 149 | public static final int ACTION_POINTER_ID_MASK = 0xff00; |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 150 | |
| 151 | /** |
Dianne Hackborn | b125dc5 | 2010-02-12 15:52:09 -0800 | [diff] [blame] | 152 | * @deprecated Renamed to {@link #ACTION_POINTER_INDEX_SHIFT} to match |
| 153 | * the actual data contained in these bits. |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 154 | */ |
Dianne Hackborn | b125dc5 | 2010-02-12 15:52:09 -0800 | [diff] [blame] | 155 | @Deprecated |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 156 | public static final int ACTION_POINTER_ID_SHIFT = 8; |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 157 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 158 | private static final boolean TRACK_RECYCLED_LOCATION = false; |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 159 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 160 | /** |
| 161 | * Flag indicating the motion event intersected the top edge of the screen. |
| 162 | */ |
| 163 | public static final int EDGE_TOP = 0x00000001; |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 164 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 165 | /** |
| 166 | * Flag indicating the motion event intersected the bottom edge of the screen. |
| 167 | */ |
| 168 | public static final int EDGE_BOTTOM = 0x00000002; |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 169 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 170 | /** |
| 171 | * Flag indicating the motion event intersected the left edge of the screen. |
| 172 | */ |
| 173 | public static final int EDGE_LEFT = 0x00000004; |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 174 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 175 | /** |
| 176 | * Flag indicating the motion event intersected the right edge of the screen. |
| 177 | */ |
| 178 | public static final int EDGE_RIGHT = 0x00000008; |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 179 | |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 180 | /** |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 181 | * Offset for the sample's X coordinate. |
| 182 | * @hide |
| 183 | */ |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 184 | static private final int SAMPLE_X = 0; |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 185 | |
| 186 | /** |
| 187 | * Offset for the sample's Y coordinate. |
| 188 | * @hide |
| 189 | */ |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 190 | static private final int SAMPLE_Y = 1; |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 191 | |
| 192 | /** |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 193 | * Offset for the sample's pressure. |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 194 | * @hide |
| 195 | */ |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 196 | static private final int SAMPLE_PRESSURE = 2; |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 197 | |
| 198 | /** |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 199 | * Offset for the sample's size |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 200 | * @hide |
| 201 | */ |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 202 | static private final int SAMPLE_SIZE = 3; |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 203 | |
| 204 | /** |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 205 | * Offset for the sample's touch major axis length. |
| 206 | * @hide |
| 207 | */ |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 208 | static private final int SAMPLE_TOUCH_MAJOR = 4; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 209 | |
| 210 | /** |
| 211 | * Offset for the sample's touch minor axis length. |
| 212 | * @hide |
| 213 | */ |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 214 | static private final int SAMPLE_TOUCH_MINOR = 5; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 215 | |
| 216 | /** |
| 217 | * Offset for the sample's tool major axis length. |
| 218 | * @hide |
| 219 | */ |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 220 | static private final int SAMPLE_TOOL_MAJOR = 6; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 221 | |
| 222 | /** |
| 223 | * Offset for the sample's tool minor axis length. |
| 224 | * @hide |
| 225 | */ |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 226 | static private final int SAMPLE_TOOL_MINOR = 7; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 227 | |
| 228 | /** |
| 229 | * Offset for the sample's orientation. |
| 230 | * @hide |
| 231 | */ |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 232 | static private final int SAMPLE_ORIENTATION = 8; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 233 | |
| 234 | /** |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 235 | * Number of data items for each sample. |
| 236 | * @hide |
| 237 | */ |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 238 | static private final int NUM_SAMPLE_DATA = 9; |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 239 | |
Dianne Hackborn | 1e8dfc7 | 2009-08-06 12:43:01 -0700 | [diff] [blame] | 240 | /** |
| 241 | * Number of possible pointers. |
| 242 | * @hide |
| 243 | */ |
| 244 | static public final int BASE_AVAIL_POINTERS = 5; |
| 245 | |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 246 | static private final int BASE_AVAIL_SAMPLES = 8; |
| 247 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 248 | 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 Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 252 | |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 253 | private long mDownTimeNano; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 254 | private int mAction; |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 255 | private float mXOffset; |
| 256 | private float mYOffset; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 257 | private float mXPrecision; |
| 258 | private float mYPrecision; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 259 | private int mEdgeFlags; |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 260 | private int mMetaState; |
| 261 | |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 262 | private int mNumPointers; |
| 263 | private int mNumSamples; |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 264 | |
| 265 | private int mLastDataSampleIndex; |
| 266 | private int mLastEventTimeNanoSampleIndex; |
| 267 | |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 268 | // Array of mNumPointers size of identifiers for each pointer of data. |
| 269 | private int[] mPointerIdentifiers; |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 270 | |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 271 | // Array of (mNumSamples * mNumPointers * NUM_SAMPLE_DATA) size of event data. |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 272 | // Samples are ordered from oldest to newest. |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 273 | private float[] mDataSamples; |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 274 | |
| 275 | // Array of mNumSamples size of event time stamps in nanoseconds. |
| 276 | // Samples are ordered from oldest to newest. |
| 277 | private long[] mEventTimeNanoSamples; |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 278 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 279 | private MotionEvent mNext; |
| 280 | private RuntimeException mRecycledLocation; |
| 281 | private boolean mRecycled; |
| 282 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 283 | private MotionEvent(int pointerCount, int sampleCount) { |
| 284 | mPointerIdentifiers = new int[pointerCount]; |
| 285 | mDataSamples = new float[pointerCount * sampleCount * NUM_SAMPLE_DATA]; |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 286 | mEventTimeNanoSamples = new long[sampleCount]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 287 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 288 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 289 | 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 Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 303 | gRecyclerUsed -= 1; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 304 | } |
| 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 Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 313 | if (ev.mEventTimeNanoSamples.length < sampleCount) { |
| 314 | ev.mEventTimeNanoSamples = new long[sampleCount]; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 315 | } |
| 316 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 317 | final int neededDataSamplesLength = pointerCount * sampleCount * NUM_SAMPLE_DATA; |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 318 | if (ev.mDataSamples.length < neededDataSamplesLength) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 319 | ev.mDataSamples = new float[neededDataSamplesLength]; |
| 320 | } |
| 321 | |
| 322 | return ev; |
| 323 | } |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 324 | |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 325 | /** |
| 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 Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 331 | * @param eventTime The the time (in ms) when this specific event was generated. This |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 332 | * must be obtained from {@link SystemClock#uptimeMillis()}. |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 333 | * @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 Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 336 | * @param pointers The number of points that will be in this event. |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 337 | * @param pointerIds An array of <em>pointers</em> values providing |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 338 | * an identifier for each pointer. |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 339 | * @param pointerCoords An array of <em>pointers</em> values providing |
| 340 | * a {@link PointerCoords} coordinate object for each pointer. |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 341 | * @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 Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 350 | * @param source The source of this event. |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 351 | */ |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 352 | 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 Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 356 | MotionEvent ev = obtain(pointers, 1); |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 357 | ev.mDeviceId = deviceId; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 358 | ev.mSource = source; |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 359 | ev.mEdgeFlags = edgeFlags; |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 360 | ev.mDownTimeNano = downTime * MS_PER_NS; |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 361 | ev.mAction = action; |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 362 | ev.mMetaState = metaState; |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 363 | ev.mXOffset = 0; |
| 364 | ev.mYOffset = 0; |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 365 | ev.mXPrecision = xPrecision; |
| 366 | ev.mYPrecision = yPrecision; |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 367 | |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 368 | ev.mNumPointers = pointers; |
| 369 | ev.mNumSamples = 1; |
| 370 | |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 371 | ev.mLastDataSampleIndex = 0; |
| 372 | ev.mLastEventTimeNanoSampleIndex = 0; |
Dianne Hackborn | 1e8dfc7 | 2009-08-06 12:43:01 -0700 | [diff] [blame] | 373 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 374 | System.arraycopy(pointerIds, 0, ev.mPointerIdentifiers, 0, pointers); |
Dianne Hackborn | 1e8dfc7 | 2009-08-06 12:43:01 -0700 | [diff] [blame] | 375 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 376 | ev.mEventTimeNanoSamples[0] = eventTime * MS_PER_NS; |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 377 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 378 | ev.setPointerCoordsAtSampleIndex(0, pointerCoords); |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 379 | |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 380 | return ev; |
| 381 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 382 | |
| 383 | /** |
| 384 | * Create a new MotionEvent, filling in all of the basic values that |
| 385 | * define the motion. |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 386 | * |
| 387 | * @param downTime The time (in ms) when the user originally pressed down to start |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 388 | * a stream of position events. This must be obtained from {@link SystemClock#uptimeMillis()}. |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 389 | * @param eventTime The the time (in ms) when this specific event was generated. This |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 390 | * 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 Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 396 | * @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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 399 | * the input device. |
| 400 | * @param size A scaled value of the approximate size of the area being pressed when |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 401 | * touched with the finger. The actual value in pixels corresponding to the finger |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 402 | * 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 Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 417 | MotionEvent ev = obtain(1, 1); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 418 | ev.mDeviceId = deviceId; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 419 | ev.mSource = InputDevice.SOURCE_UNKNOWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 420 | ev.mEdgeFlags = edgeFlags; |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 421 | ev.mDownTimeNano = downTime * MS_PER_NS; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 422 | ev.mAction = action; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 423 | ev.mMetaState = metaState; |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 424 | ev.mXOffset = 0; |
| 425 | ev.mYOffset = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 426 | ev.mXPrecision = xPrecision; |
| 427 | ev.mYPrecision = yPrecision; |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 428 | |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 429 | ev.mNumPointers = 1; |
| 430 | ev.mNumSamples = 1; |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 431 | |
| 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 Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 439 | ev.setPointerCoordsAtSampleIndex(0, x, y, pressure, size); |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 440 | 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 Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 474 | * |
| 475 | * @deprecated Use {@link #obtain(long, long, int, float, float, float, float, int, float, float, int, int)} |
| 476 | * instead. |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 477 | */ |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 478 | @Deprecated |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 479 | 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 Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 482 | return obtain(downTime, eventTime, action, x, y, pressure, size, |
| 483 | metaState, xPrecision, yPrecision, deviceId, edgeFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 484 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 485 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 486 | /** |
| 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 Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 490 | * |
| 491 | * @param downTime The time (in ms) when the user originally pressed down to start |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 492 | * a stream of position events. This must be obtained from {@link SystemClock#uptimeMillis()}. |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 493 | * @param eventTime The the time (in ms) when this specific event was generated. This |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 494 | * 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 Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 505 | return obtain(downTime, eventTime, action, x, y, 1.0f, 1.0f, |
| 506 | metaState, 1.0f, 1.0f, 0, 0); |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 507 | } |
| 508 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 509 | /** |
| 510 | * Create a new MotionEvent, copying from an existing one. |
| 511 | */ |
| 512 | static public MotionEvent obtain(MotionEvent o) { |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 513 | MotionEvent ev = obtain(o.mNumPointers, o.mNumSamples); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 514 | ev.mDeviceId = o.mDeviceId; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 515 | ev.mSource = o.mSource; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 516 | ev.mEdgeFlags = o.mEdgeFlags; |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 517 | ev.mDownTimeNano = o.mDownTimeNano; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 518 | ev.mAction = o.mAction; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 519 | ev.mMetaState = o.mMetaState; |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 520 | ev.mXOffset = o.mXOffset; |
| 521 | ev.mYOffset = o.mYOffset; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 522 | ev.mXPrecision = o.mXPrecision; |
| 523 | ev.mYPrecision = o.mYPrecision; |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 524 | int numPointers = ev.mNumPointers = o.mNumPointers; |
| 525 | int numSamples = ev.mNumSamples = o.mNumSamples; |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 526 | |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 527 | ev.mLastDataSampleIndex = o.mLastDataSampleIndex; |
| 528 | ev.mLastEventTimeNanoSampleIndex = o.mLastEventTimeNanoSampleIndex; |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 529 | |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 530 | System.arraycopy(o.mPointerIdentifiers, 0, ev.mPointerIdentifiers, 0, numPointers); |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 531 | |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 532 | System.arraycopy(o.mEventTimeNanoSamples, 0, ev.mEventTimeNanoSamples, 0, numSamples); |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 533 | |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 534 | System.arraycopy(o.mDataSamples, 0, ev.mDataSamples, 0, |
| 535 | numPointers * numSamples * NUM_SAMPLE_DATA); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 536 | return ev; |
| 537 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 538 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 539 | /** |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 540 | * 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 Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 544 | MotionEvent ev = obtain(o.mNumPointers, 1); |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 545 | ev.mDeviceId = o.mDeviceId; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 546 | ev.mSource = o.mSource; |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 547 | ev.mEdgeFlags = o.mEdgeFlags; |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 548 | ev.mDownTimeNano = o.mDownTimeNano; |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 549 | ev.mAction = o.mAction; |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 550 | ev.mMetaState = o.mMetaState; |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 551 | ev.mXOffset = o.mXOffset; |
| 552 | ev.mYOffset = o.mYOffset; |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 553 | ev.mXPrecision = o.mXPrecision; |
| 554 | ev.mYPrecision = o.mYPrecision; |
| 555 | |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 556 | int numPointers = ev.mNumPointers = o.mNumPointers; |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 557 | ev.mNumSamples = 1; |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 558 | |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 559 | ev.mLastDataSampleIndex = 0; |
| 560 | ev.mLastEventTimeNanoSampleIndex = 0; |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 561 | |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 562 | System.arraycopy(o.mPointerIdentifiers, 0, ev.mPointerIdentifiers, 0, numPointers); |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 563 | |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 564 | ev.mEventTimeNanoSamples[0] = o.mEventTimeNanoSamples[o.mLastEventTimeNanoSampleIndex]; |
| 565 | |
| 566 | System.arraycopy(o.mDataSamples, o.mLastDataSampleIndex, ev.mDataSamples, 0, |
| 567 | numPointers * NUM_SAMPLE_DATA); |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 568 | return ev; |
| 569 | } |
| 570 | |
| 571 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 572 | * 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 Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 575 | public final void recycle() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 576 | // 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 Brown | d28f4be | 2010-06-02 15:35:46 -0700 | [diff] [blame] | 582 | //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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 588 | } |
| 589 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 590 | synchronized (gRecyclerLock) { |
| 591 | if (gRecyclerUsed < MAX_RECYCLED) { |
| 592 | gRecyclerUsed++; |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 593 | mNumSamples = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 594 | mNext = gRecyclerTop; |
| 595 | gRecyclerTop = this; |
| 596 | } |
| 597 | } |
| 598 | } |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 599 | |
| 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 Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 618 | 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 Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 622 | } |
| 623 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 624 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 625 | /** |
| 626 | * Return the kind of action being performed -- one of either |
| 627 | * {@link #ACTION_DOWN}, {@link #ACTION_MOVE}, {@link #ACTION_UP}, or |
Dianne Hackborn | b125dc5 | 2010-02-12 15:52:09 -0800 | [diff] [blame] | 628 | * {@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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 631 | */ |
| 632 | public final int getAction() { |
| 633 | return mAction; |
| 634 | } |
| 635 | |
| 636 | /** |
Dianne Hackborn | b125dc5 | 2010-02-12 15:52:09 -0800 | [diff] [blame] | 637 | * 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 Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 661 | * Returns the time (in ms) when the user originally pressed down to start |
| 662 | * a stream of position events. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 663 | */ |
| 664 | public final long getDownTime() { |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 665 | return mDownTimeNano / MS_PER_NS; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | /** |
| 669 | * Returns the time (in ms) when this specific event was generated. |
| 670 | */ |
| 671 | public final long getEventTime() { |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 672 | return mEventTimeNanoSamples[mLastEventTimeNanoSampleIndex] / MS_PER_NS; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 673 | } |
| 674 | |
| 675 | /** |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 676 | * 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 Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 682 | return mEventTimeNanoSamples[mLastEventTimeNanoSampleIndex]; |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 683 | } |
| 684 | |
| 685 | /** |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 686 | * {@link #getX(int)} for the first pointer index (may be an |
| 687 | * arbitrary pointer identifier). |
| 688 | */ |
| 689 | public final float getX() { |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 690 | return mDataSamples[mLastDataSampleIndex + SAMPLE_X] + mXOffset; |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 691 | } |
| 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 Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 698 | return mDataSamples[mLastDataSampleIndex + SAMPLE_Y] + mYOffset; |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 699 | } |
| 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 Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 706 | return mDataSamples[mLastDataSampleIndex + SAMPLE_PRESSURE]; |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 707 | } |
| 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 Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 714 | return mDataSamples[mLastDataSampleIndex + SAMPLE_SIZE]; |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 715 | } |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 716 | |
| 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 Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 756 | |
| 757 | /** |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 758 | * 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 Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 766 | * 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 772 | */ |
Dianne Hackborn | d41ba66 | 2009-08-05 15:30:56 -0700 | [diff] [blame] | 773 | public final int getPointerId(int pointerIndex) { |
| 774 | return mPointerIdentifiers[pointerIndex]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 775 | } |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 776 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 777 | /** |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 778 | * 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 784 | */ |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 785 | 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 794 | } |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 795 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 796 | /** |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 797 | * 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 Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 800 | * Whole numbers are pixels; the |
| 801 | * value may have a fraction for input devices that are sub-pixel precise. |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 802 | * @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 Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 804 | */ |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 805 | public final float getX(int pointerIndex) { |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 806 | return mDataSamples[mLastDataSampleIndex |
| 807 | + pointerIndex * NUM_SAMPLE_DATA + SAMPLE_X] + mXOffset; |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 808 | } |
| 809 | |
| 810 | /** |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 811 | * 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 Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 814 | * Whole numbers are pixels; the |
| 815 | * value may have a fraction for input devices that are sub-pixel precise. |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 816 | * @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 Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 818 | */ |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 819 | public final float getY(int pointerIndex) { |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 820 | return mDataSamples[mLastDataSampleIndex |
| 821 | + pointerIndex * NUM_SAMPLE_DATA + SAMPLE_Y] + mYOffset; |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 822 | } |
| 823 | |
| 824 | /** |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 825 | * 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 Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 828 | * The pressure generally |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 829 | * 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 831 | * the input device. |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 832 | * @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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 834 | */ |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 835 | public final float getPressure(int pointerIndex) { |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 836 | return mDataSamples[mLastDataSampleIndex |
| 837 | + pointerIndex * NUM_SAMPLE_DATA + SAMPLE_PRESSURE]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 838 | } |
| 839 | |
| 840 | /** |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 841 | * 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 Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 846 | * touch is normalized with the device specific range of values |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 847 | * and scaled to a value between 0 and 1. The value of size can be used to |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 848 | * determine fat touch events. |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 849 | * @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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 851 | */ |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 852 | public final float getSize(int pointerIndex) { |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 853 | return mDataSamples[mLastDataSampleIndex |
| 854 | + pointerIndex * NUM_SAMPLE_DATA + SAMPLE_SIZE]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 855 | } |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 856 | |
| 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 Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 921 | * The full range is from -PI/2 radians (finger pointing fully left) to PI/2 radians |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 922 | * (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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 943 | |
| 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 Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 965 | return mDataSamples[mLastDataSampleIndex + SAMPLE_X]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 966 | } |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 967 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 968 | /** |
| 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 Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 975 | return mDataSamples[mLastDataSampleIndex + SAMPLE_Y]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 976 | } |
| 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 Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 987 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 988 | /** |
| 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 Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 997 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 998 | /** |
| 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 Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1003 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1004 | * @return Returns the number of historical points in the event. |
| 1005 | */ |
| 1006 | public final int getHistorySize() { |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1007 | return mLastEventTimeNanoSampleIndex; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1008 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1009 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1010 | /** |
| 1011 | * Returns the time that a historical movement occurred between this event |
| 1012 | * and the previous event. Only applies to ACTION_MOVE events. |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1013 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1014 | * @param pos Which historical value to return; must be less than |
| 1015 | * {@link #getHistorySize} |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1016 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1017 | * @see #getHistorySize |
| 1018 | * @see #getEventTime |
| 1019 | */ |
| 1020 | public final long getHistoricalEventTime(int pos) { |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1021 | return mEventTimeNanoSamples[pos] / MS_PER_NS; |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1022 | } |
| 1023 | |
| 1024 | /** |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1025 | * {@link #getHistoricalX(int)} for the first pointer index (may be an |
| 1026 | * arbitrary pointer identifier). |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1027 | */ |
| 1028 | public final float getHistoricalX(int pos) { |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1029 | return mDataSamples[pos * mNumPointers * NUM_SAMPLE_DATA + SAMPLE_X] + mXOffset; |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1030 | } |
| 1031 | |
| 1032 | /** |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1033 | * {@link #getHistoricalY(int)} for the first pointer index (may be an |
| 1034 | * arbitrary pointer identifier). |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1035 | */ |
| 1036 | public final float getHistoricalY(int pos) { |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1037 | return mDataSamples[pos * mNumPointers * NUM_SAMPLE_DATA + SAMPLE_Y] + mYOffset; |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1038 | } |
| 1039 | |
| 1040 | /** |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1041 | * {@link #getHistoricalPressure(int)} for the first pointer index (may be an |
| 1042 | * arbitrary pointer identifier). |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1043 | */ |
| 1044 | public final float getHistoricalPressure(int pos) { |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1045 | return mDataSamples[pos * mNumPointers * NUM_SAMPLE_DATA + SAMPLE_PRESSURE]; |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1046 | } |
| 1047 | |
| 1048 | /** |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1049 | * {@link #getHistoricalSize(int)} for the first pointer index (may be an |
| 1050 | * arbitrary pointer identifier). |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1051 | */ |
| 1052 | public final float getHistoricalSize(int pos) { |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1053 | return mDataSamples[pos * mNumPointers * NUM_SAMPLE_DATA + SAMPLE_SIZE]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1054 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1055 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1056 | /** |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1057 | * {@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 Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1097 | * 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 Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1100 | * |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1101 | * @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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1103 | * @param pos Which historical value to return; must be less than |
| 1104 | * {@link #getHistorySize} |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1105 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1106 | * @see #getHistorySize |
| 1107 | * @see #getX |
| 1108 | */ |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1109 | public final float getHistoricalX(int pointerIndex, int pos) { |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1110 | return mDataSamples[(pos * mNumPointers + pointerIndex) |
| 1111 | * NUM_SAMPLE_DATA + SAMPLE_X] + mXOffset; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1112 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1113 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1114 | /** |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1115 | * 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 Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1118 | * |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1119 | * @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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1121 | * @param pos Which historical value to return; must be less than |
| 1122 | * {@link #getHistorySize} |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1123 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1124 | * @see #getHistorySize |
| 1125 | * @see #getY |
| 1126 | */ |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1127 | public final float getHistoricalY(int pointerIndex, int pos) { |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1128 | return mDataSamples[(pos * mNumPointers + pointerIndex) |
| 1129 | * NUM_SAMPLE_DATA + SAMPLE_Y] + mYOffset; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1130 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1131 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1132 | /** |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1133 | * 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 Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1136 | * |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1137 | * @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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1139 | * @param pos Which historical value to return; must be less than |
| 1140 | * {@link #getHistorySize} |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1141 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1142 | * @see #getHistorySize |
| 1143 | * @see #getPressure |
| 1144 | */ |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1145 | public final float getHistoricalPressure(int pointerIndex, int pos) { |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1146 | return mDataSamples[(pos * mNumPointers + pointerIndex) |
| 1147 | * NUM_SAMPLE_DATA + SAMPLE_PRESSURE]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1148 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1149 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1150 | /** |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1151 | * 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 Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1154 | * |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1155 | * @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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1157 | * @param pos Which historical value to return; must be less than |
| 1158 | * {@link #getHistorySize} |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1159 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1160 | * @see #getHistorySize |
| 1161 | * @see #getSize |
| 1162 | */ |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1163 | public final float getHistoricalSize(int pointerIndex, int pos) { |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1164 | return mDataSamples[(pos * mNumPointers + pointerIndex) |
| 1165 | * NUM_SAMPLE_DATA + SAMPLE_SIZE]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1166 | } |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1167 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1168 | /** |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1169 | * 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1180 | */ |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1181 | 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1184 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1185 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1186 | /** |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1187 | * 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 Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1280 | * Returns a bitfield indicating which edges, if any, were touched by this |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1281 | * 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1284 | * @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 Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1292 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1293 | |
| 1294 | /** |
| 1295 | * Sets the bitfield indicating which edges, if any, where touched by this |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1296 | * MotionEvent. |
| 1297 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1298 | * @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 Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1317 | mXOffset += deltaX; |
| 1318 | mYOffset += deltaY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1319 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1320 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1321 | /** |
| 1322 | * Set this event's location. Applies {@link #offsetLocation} with a |
| 1323 | * delta from the current location to the given new location. |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1324 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1325 | * @param x New absolute X location. |
| 1326 | * @param y New absolute Y location. |
| 1327 | */ |
| 1328 | public final void setLocation(float x, float y) { |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1329 | mXOffset = x - mDataSamples[mLastDataSampleIndex + SAMPLE_X]; |
| 1330 | mYOffset = y - mDataSamples[mLastDataSampleIndex + SAMPLE_Y]; |
| 1331 | } |
| 1332 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1333 | 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 Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1381 | 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1386 | } |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1387 | |
| 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1399 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1400 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1401 | /** |
| 1402 | * Add a new movement to the batch of movements in this event. The event's |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1403 | * 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 Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1406 | * Only applies to {@link #ACTION_MOVE} events. |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1407 | * |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1408 | * @param eventTime The time stamp (in ms) for this data. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1409 | * @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 Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1413 | * @param metaState Meta key state. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1414 | */ |
| 1415 | public final void addBatch(long eventTime, float x, float y, |
| 1416 | float pressure, float size, int metaState) { |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1417 | incrementNumSamplesAndReserveStorage(NUM_SAMPLE_DATA); |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1418 | |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1419 | mEventTimeNanoSamples[mLastEventTimeNanoSampleIndex] = eventTime * MS_PER_NS; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1420 | setPointerCoordsAtSampleIndex(mLastDataSampleIndex, x, y, pressure, size); |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1421 | |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1422 | mMetaState |= metaState; |
| 1423 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1424 | |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1425 | /** |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1426 | * 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 Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1429 | * |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1430 | * Only applies to {@link #ACTION_MOVE} events. |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1431 | * |
| 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 Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1435 | */ |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1436 | public final void addBatch(long eventTime, PointerCoords[] pointerCoords, int metaState) { |
| 1437 | final int dataSampleStride = mNumPointers * NUM_SAMPLE_DATA; |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1438 | incrementNumSamplesAndReserveStorage(dataSampleStride); |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1439 | |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1440 | mEventTimeNanoSamples[mLastEventTimeNanoSampleIndex] = eventTime * MS_PER_NS; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1441 | setPointerCoordsAtSampleIndex(mLastDataSampleIndex, pointerCoords); |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1442 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1443 | mMetaState |= metaState; |
| 1444 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1445 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1446 | @Override |
| 1447 | public String toString() { |
| 1448 | return "MotionEvent{" + Integer.toHexString(System.identityHashCode(this)) |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1449 | + " action=" + mAction + " x=" + getX() |
| 1450 | + " y=" + getY() + " pressure=" + getPressure() + " size=" + getSize() + "}"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1451 | } |
| 1452 | |
| 1453 | public static final Parcelable.Creator<MotionEvent> CREATOR |
| 1454 | = new Parcelable.Creator<MotionEvent>() { |
| 1455 | public MotionEvent createFromParcel(Parcel in) { |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame^] | 1456 | in.readInt(); // skip token, we already know this is a MotionEvent |
| 1457 | return MotionEvent.createFromParcelBody(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1458 | } |
| 1459 | |
| 1460 | public MotionEvent[] newArray(int size) { |
| 1461 | return new MotionEvent[size]; |
| 1462 | } |
| 1463 | }; |
| 1464 | |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame^] | 1465 | /** @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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1495 | |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame^] | 1496 | 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1506 | public void writeToParcel(Parcel out, int flags) { |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame^] | 1507 | out.writeInt(PARCEL_TOKEN_MOTION_EVENT); |
| 1508 | |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1509 | final int NP = mNumPointers; |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1510 | final int NS = mNumSamples; |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1511 | final int NI = NP * NS * NUM_SAMPLE_DATA; |
| 1512 | |
| 1513 | out.writeInt(NP); |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1514 | out.writeInt(NS); |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1515 | |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame^] | 1516 | writeBaseToParcel(out); |
| 1517 | |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1518 | out.writeLong(mDownTimeNano); |
| 1519 | out.writeInt(mAction); |
| 1520 | out.writeFloat(mXOffset); |
| 1521 | out.writeFloat(mYOffset); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1522 | out.writeFloat(mXPrecision); |
| 1523 | out.writeFloat(mYPrecision); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1524 | out.writeInt(mEdgeFlags); |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1525 | 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1530 | } |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1531 | |
| 1532 | final long[] eventTimeNanoSamples = mEventTimeNanoSamples; |
| 1533 | for (int i = 0; i < NS; i++) { |
| 1534 | out.writeLong(eventTimeNanoSamples[i]); |
| 1535 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1536 | |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1537 | final float[] dataSamples = mDataSamples; |
| 1538 | for (int i = 0; i < NI; i++) { |
| 1539 | out.writeFloat(dataSamples[i]); |
| 1540 | } |
| 1541 | } |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1542 | |
| 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 Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1621 | * The full range is from -PI/2 radians (finger pointing fully left) to PI/2 radians |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1622 | * (finger pointing fully right). |
| 1623 | */ |
| 1624 | public float orientation; |
| 1625 | |
| 1626 | /* |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1627 | private static final float PI_4 = (float) (Math.PI / 4); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1628 | |
| 1629 | public float getTouchWidth() { |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1630 | return Math.abs(orientation) > PI_4 ? touchMajor : touchMinor; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1631 | } |
| 1632 | |
| 1633 | public float getTouchHeight() { |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1634 | return Math.abs(orientation) > PI_4 ? touchMinor : touchMajor; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1635 | } |
| 1636 | |
| 1637 | public float getToolWidth() { |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1638 | return Math.abs(orientation) > PI_4 ? toolMajor : toolMinor; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1639 | } |
| 1640 | |
| 1641 | public float getToolHeight() { |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1642 | return Math.abs(orientation) > PI_4 ? toolMinor : toolMajor; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1643 | } |
| 1644 | */ |
| 1645 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1646 | } |