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