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