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; |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 23 | import android.util.SparseArray; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | |
| 25 | /** |
| 26 | * Object used to report movement (mouse, pen, finger, trackball) events. This |
| 27 | * class may hold either absolute or relative movements, depending on what |
| 28 | * it is being used for. |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 29 | * <p> |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 30 | * On pointing devices with source class {@link InputDevice#SOURCE_CLASS_POINTER} |
| 31 | * such as touch screens, the pointer coordinates specify absolute |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 32 | * positions such as view X/Y coordinates. Each complete gesture is represented |
| 33 | * by a sequence of motion events with actions that describe pointer state transitions |
| 34 | * and movements. A gesture starts with a motion event with {@link #ACTION_DOWN} |
| 35 | * that provides the location of the first pointer down. As each additional |
| 36 | * pointer that goes down or up, the framework will generate a motion event with |
| 37 | * {@link #ACTION_POINTER_DOWN} or {@link #ACTION_POINTER_UP} accordingly. |
| 38 | * Pointer movements are described by motion events with {@link #ACTION_MOVE}. |
| 39 | * Finally, a gesture end either when the final pointer goes up as represented |
| 40 | * by a motion event with {@link #ACTION_UP} or when gesture is canceled |
| 41 | * with {@link #ACTION_CANCEL}. |
| 42 | * </p><p> |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 43 | * Some pointing devices such as mice may support vertical and/or horizontal scrolling. |
| 44 | * A scroll event is reported as a generic motion event with {@link #ACTION_SCROLL} that |
| 45 | * includes the relative scroll offset in the {@link #AXIS_VSCROLL} and |
| 46 | * {@link #AXIS_HSCROLL} axes. See {@link #getAxisValue(int)} for information |
| 47 | * about retrieving these additional axes. |
| 48 | * </p><p> |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 49 | * On trackball devices with source class {@link InputDevice#SOURCE_CLASS_TRACKBALL}, |
| 50 | * the pointer coordinates specify relative movements as X/Y deltas. |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 51 | * A trackball gesture consists of a sequence of movements described by motion |
| 52 | * events with {@link #ACTION_MOVE} interspersed with occasional {@link #ACTION_DOWN} |
| 53 | * or {@link #ACTION_UP} motion events when the trackball button is pressed or released. |
| 54 | * </p><p> |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 55 | * On joystick devices with source class {@link InputDevice#SOURCE_CLASS_JOYSTICK}, |
| 56 | * the pointer coordinates specify the absolute position of the joystick axes. |
| 57 | * The joystick axis values are normalized to a range of -1.0 to 1.0 where 0.0 corresponds |
| 58 | * to the center position. More information about the set of available axes and the |
| 59 | * range of motion can be obtained using {@link InputDevice#getMotionRange}. |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 60 | * Some common joystick axes are {@link #AXIS_X}, {@link #AXIS_Y}, |
| 61 | * {@link #AXIS_HAT_X}, {@link #AXIS_HAT_Y}, {@link #AXIS_Z} and {@link #AXIS_RZ}. |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 62 | * </p><p> |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 63 | * Motion events always report movements for all pointers at once. The number |
| 64 | * of pointers only ever changes by one as individual pointers go up and down, |
| 65 | * except when the gesture is canceled. |
| 66 | * </p><p> |
| 67 | * The order in which individual pointers appear within a motion event can change |
| 68 | * from one event to the next. Use the {@link #getPointerId(int)} method to obtain a |
| 69 | * pointer id to track pointers across motion events in a gesture. Then for |
| 70 | * successive motion events, use the {@link #findPointerIndex(int)} method to obtain |
| 71 | * the pointer index for a given pointer id in that motion event. |
| 72 | * </p><p> |
| 73 | * For efficiency, motion events with {@link #ACTION_MOVE} may batch together |
| 74 | * multiple movement samples within a single object. The most current |
| 75 | * pointer coordinates are available using {@link #getX(int)} and {@link #getY(int)}. |
| 76 | * Earlier coordinates within the batch are accessed using {@link #getHistoricalX(int, int)} |
| 77 | * and {@link #getHistoricalY(int, int)}. The coordinates are "historical" only |
| 78 | * insofar as they are older than the current coordinates in the batch; however, |
| 79 | * they are still distinct from any other coordinates reported in prior motion events. |
| 80 | * To process all coordinates in the batch in time order, first consume the historical |
| 81 | * coordinates then consume the current coordinates. |
| 82 | * </p><p> |
| 83 | * Example: Consuming all samples for all pointers in a motion event in time order. |
| 84 | * </p><p><pre><code> |
| 85 | * void printSamples(MotionEvent ev) { |
| 86 | * final int historySize = ev.getHistorySize(); |
| 87 | * final int pointerCount = ev.getPointerCount(); |
| 88 | * for (int h = 0; h < historySize; h++) { |
| 89 | * System.out.printf("At time %d:", ev.getHistoricalEventTime(h)); |
| 90 | * for (int p = 0; p < pointerCount; p++) { |
| 91 | * System.out.printf(" pointer %d: (%f,%f)", |
| 92 | * ev.getPointerId(p), ev.getHistoricalX(p, h), ev.getHistoricalY(p, h)); |
| 93 | * } |
| 94 | * } |
| 95 | * System.out.printf("At time %d:", ev.getEventTime()); |
| 96 | * for (int p = 0; p < pointerCount; p++) { |
| 97 | * System.out.printf(" pointer %d: (%f,%f)", |
| 98 | * ev.getPointerId(p), ev.getX(p), ev.getY(p)); |
| 99 | * } |
| 100 | * } |
| 101 | * </code></pre></p><p> |
Jeff Brown | b699726 | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 102 | * In general, the framework cannot guarantee that the motion events it delivers |
| 103 | * to a view always constitute a complete motion sequences since some events may be dropped |
| 104 | * or modified by containing views before they are delivered. The view implementation |
| 105 | * should be prepared to handle {@link #ACTION_CANCEL} and should tolerate anomalous |
| 106 | * situations such as receiving a new {@link #ACTION_DOWN} without first having |
| 107 | * received an {@link #ACTION_UP} for the prior gesture. |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 108 | * </p><p> |
| 109 | * Refer to {@link InputDevice} for more information about how different kinds of |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 110 | * input devices and sources represent pointer coordinates. |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 111 | * </p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 112 | */ |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 113 | public final class MotionEvent extends InputEvent implements Parcelable { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 114 | private static final long NS_PER_MS = 1000000; |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 115 | private static final boolean TRACK_RECYCLED_LOCATION = false; |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 116 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 117 | /** |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 118 | * Bit mask of the parts of the action code that are the action itself. |
| 119 | */ |
| 120 | public static final int ACTION_MASK = 0xff; |
| 121 | |
| 122 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 123 | * Constant for {@link #getAction}: A pressed gesture has started, the |
| 124 | * motion contains the initial starting location. |
| 125 | */ |
| 126 | public static final int ACTION_DOWN = 0; |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 127 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 128 | /** |
| 129 | * Constant for {@link #getAction}: A pressed gesture has finished, the |
| 130 | * motion contains the final release location as well as any intermediate |
| 131 | * points since the last down or move event. |
| 132 | */ |
| 133 | public static final int ACTION_UP = 1; |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 134 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 135 | /** |
| 136 | * Constant for {@link #getAction}: A change has happened during a |
| 137 | * press gesture (between {@link #ACTION_DOWN} and {@link #ACTION_UP}). |
| 138 | * The motion contains the most recent point, as well as any intermediate |
| 139 | * points since the last down or move event. |
| 140 | */ |
| 141 | public static final int ACTION_MOVE = 2; |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 142 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 143 | /** |
| 144 | * Constant for {@link #getAction}: The current gesture has been aborted. |
| 145 | * You will not receive any more points in it. You should treat this as |
| 146 | * an up event, but not perform any action that you normally would. |
| 147 | */ |
| 148 | public static final int ACTION_CANCEL = 3; |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 149 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 150 | /** |
| 151 | * Constant for {@link #getAction}: A movement has happened outside of the |
| 152 | * normal bounds of the UI element. This does not provide a full gesture, |
| 153 | * but only the initial location of the movement/touch. |
| 154 | */ |
| 155 | public static final int ACTION_OUTSIDE = 4; |
| 156 | |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 157 | /** |
| 158 | * A non-primary pointer has gone down. The bits in |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 159 | * {@link #ACTION_POINTER_ID_MASK} indicate which pointer changed. |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 160 | */ |
| 161 | public static final int ACTION_POINTER_DOWN = 5; |
| 162 | |
| 163 | /** |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 164 | * A non-primary pointer has gone up. The bits in |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 165 | * {@link #ACTION_POINTER_ID_MASK} indicate which pointer changed. |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 166 | */ |
| 167 | public static final int ACTION_POINTER_UP = 6; |
Jeff Brown | cc0c159 | 2011-02-19 05:07:28 -0800 | [diff] [blame] | 168 | |
| 169 | /** |
| 170 | * Constant for {@link #getAction}: A change happened but the pointer |
| 171 | * is not down (unlike {@link #ACTION_MOVE}). The motion contains the most |
| 172 | * recent point, as well as any intermediate points since the last |
| 173 | * hover move event. |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 174 | * <p> |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 175 | * This action is always delivered to the window or view under the pointer. |
| 176 | * </p><p> |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 177 | * This action is not a touch event so it is delivered to |
| 178 | * {@link View#onGenericMotionEvent(MotionEvent)} rather than |
| 179 | * {@link View#onTouchEvent(MotionEvent)}. |
| 180 | * </p> |
Jeff Brown | cc0c159 | 2011-02-19 05:07:28 -0800 | [diff] [blame] | 181 | */ |
| 182 | public static final int ACTION_HOVER_MOVE = 7; |
| 183 | |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 184 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 185 | * Constant for {@link #getAction}: The motion event contains relative |
| 186 | * vertical and/or horizontal scroll offsets. Use {@link #getAxisValue(int)} |
| 187 | * to retrieve the information from {@link #AXIS_VSCROLL} and {@link #AXIS_HSCROLL}. |
| 188 | * The pointer may or may not be down when this event is dispatched. |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 189 | * <p></p> |
| 190 | * This action is always delivered to the window or view under the pointer, which |
| 191 | * may not be the window or view currently touched. |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 192 | * <p> |
| 193 | * This action is not a touch event so it is delivered to |
| 194 | * {@link View#onGenericMotionEvent(MotionEvent)} rather than |
| 195 | * {@link View#onTouchEvent(MotionEvent)}. |
| 196 | * </p> |
| 197 | */ |
| 198 | public static final int ACTION_SCROLL = 8; |
| 199 | |
| 200 | /** |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 201 | * Constant for {@link #getAction}: The pointer is not down but has entered the |
| 202 | * boundaries of a window or view. |
| 203 | * <p> |
| 204 | * This action is always delivered to the window or view under the pointer. |
| 205 | * </p><p> |
| 206 | * This action is not a touch event so it is delivered to |
| 207 | * {@link View#onGenericMotionEvent(MotionEvent)} rather than |
| 208 | * {@link View#onTouchEvent(MotionEvent)}. |
| 209 | * </p> |
| 210 | */ |
| 211 | public static final int ACTION_HOVER_ENTER = 9; |
| 212 | |
| 213 | /** |
| 214 | * Constant for {@link #getAction}: The pointer is not down but has exited the |
| 215 | * boundaries of a window or view. |
| 216 | * <p> |
| 217 | * This action is always delivered to the window or view that was previously under the pointer. |
| 218 | * </p><p> |
| 219 | * This action is not a touch event so it is delivered to |
| 220 | * {@link View#onGenericMotionEvent(MotionEvent)} rather than |
| 221 | * {@link View#onTouchEvent(MotionEvent)}. |
| 222 | * </p> |
| 223 | */ |
| 224 | public static final int ACTION_HOVER_EXIT = 10; |
| 225 | |
| 226 | /** |
Dianne Hackborn | b125dc5 | 2010-02-12 15:52:09 -0800 | [diff] [blame] | 227 | * Bits in the action code that represent a pointer index, used with |
| 228 | * {@link #ACTION_POINTER_DOWN} and {@link #ACTION_POINTER_UP}. Shifting |
| 229 | * down by {@link #ACTION_POINTER_INDEX_SHIFT} provides the actual pointer |
| 230 | * index where the data for the pointer going up or down can be found; you can |
| 231 | * get its identifier with {@link #getPointerId(int)} and the actual |
| 232 | * data with {@link #getX(int)} etc. |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 233 | */ |
Dianne Hackborn | b125dc5 | 2010-02-12 15:52:09 -0800 | [diff] [blame] | 234 | public static final int ACTION_POINTER_INDEX_MASK = 0xff00; |
| 235 | |
| 236 | /** |
| 237 | * Bit shift for the action bits holding the pointer index as |
| 238 | * defined by {@link #ACTION_POINTER_INDEX_MASK}. |
| 239 | */ |
| 240 | public static final int ACTION_POINTER_INDEX_SHIFT = 8; |
| 241 | |
| 242 | /** |
| 243 | * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the |
| 244 | * data index associated with {@link #ACTION_POINTER_DOWN}. |
| 245 | */ |
| 246 | @Deprecated |
| 247 | public static final int ACTION_POINTER_1_DOWN = ACTION_POINTER_DOWN | 0x0000; |
| 248 | |
| 249 | /** |
| 250 | * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the |
| 251 | * data index associated with {@link #ACTION_POINTER_DOWN}. |
| 252 | */ |
| 253 | @Deprecated |
| 254 | public static final int ACTION_POINTER_2_DOWN = ACTION_POINTER_DOWN | 0x0100; |
| 255 | |
| 256 | /** |
| 257 | * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the |
| 258 | * data index associated with {@link #ACTION_POINTER_DOWN}. |
| 259 | */ |
| 260 | @Deprecated |
| 261 | public static final int ACTION_POINTER_3_DOWN = ACTION_POINTER_DOWN | 0x0200; |
| 262 | |
| 263 | /** |
| 264 | * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the |
| 265 | * data index associated with {@link #ACTION_POINTER_UP}. |
| 266 | */ |
| 267 | @Deprecated |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 268 | public static final int ACTION_POINTER_1_UP = ACTION_POINTER_UP | 0x0000; |
| 269 | |
| 270 | /** |
Dianne Hackborn | b125dc5 | 2010-02-12 15:52:09 -0800 | [diff] [blame] | 271 | * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the |
| 272 | * data index associated with {@link #ACTION_POINTER_UP}. |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 273 | */ |
Dianne Hackborn | b125dc5 | 2010-02-12 15:52:09 -0800 | [diff] [blame] | 274 | @Deprecated |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 275 | public static final int ACTION_POINTER_2_UP = ACTION_POINTER_UP | 0x0100; |
| 276 | |
| 277 | /** |
Dianne Hackborn | b125dc5 | 2010-02-12 15:52:09 -0800 | [diff] [blame] | 278 | * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the |
| 279 | * data index associated with {@link #ACTION_POINTER_UP}. |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 280 | */ |
Dianne Hackborn | b125dc5 | 2010-02-12 15:52:09 -0800 | [diff] [blame] | 281 | @Deprecated |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 282 | public static final int ACTION_POINTER_3_UP = ACTION_POINTER_UP | 0x0200; |
| 283 | |
| 284 | /** |
Dianne Hackborn | b125dc5 | 2010-02-12 15:52:09 -0800 | [diff] [blame] | 285 | * @deprecated Renamed to {@link #ACTION_POINTER_INDEX_MASK} to match |
| 286 | * the actual data contained in these bits. |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 287 | */ |
Dianne Hackborn | b125dc5 | 2010-02-12 15:52:09 -0800 | [diff] [blame] | 288 | @Deprecated |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 289 | public static final int ACTION_POINTER_ID_MASK = 0xff00; |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 290 | |
| 291 | /** |
Dianne Hackborn | b125dc5 | 2010-02-12 15:52:09 -0800 | [diff] [blame] | 292 | * @deprecated Renamed to {@link #ACTION_POINTER_INDEX_SHIFT} to match |
| 293 | * the actual data contained in these bits. |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 294 | */ |
Dianne Hackborn | b125dc5 | 2010-02-12 15:52:09 -0800 | [diff] [blame] | 295 | @Deprecated |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 296 | public static final int ACTION_POINTER_ID_SHIFT = 8; |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 297 | |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 298 | /** |
| 299 | * This flag indicates that the window that received this motion event is partly |
| 300 | * or wholly obscured by another visible window above it. This flag is set to true |
| 301 | * even if the event did not directly pass through the obscured area. |
| 302 | * A security sensitive application can check this flag to identify situations in which |
| 303 | * a malicious application may have covered up part of its content for the purpose |
| 304 | * of misleading the user or hijacking touches. An appropriate response might be |
| 305 | * to drop the suspect touches or to take additional precautions to confirm the user's |
| 306 | * actual intent. |
| 307 | */ |
| 308 | public static final int FLAG_WINDOW_IS_OBSCURED = 0x1; |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 309 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 310 | /** |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 311 | * Private flag that indicates when the system has detected that this motion event |
| 312 | * may be inconsistent with respect to the sequence of previously delivered motion events, |
| 313 | * such as when a pointer move event is sent but the pointer is not down. |
| 314 | * |
| 315 | * @hide |
| 316 | * @see #isTainted |
| 317 | * @see #setTainted |
| 318 | */ |
| 319 | public static final int FLAG_TAINTED = 0x80000000; |
| 320 | |
| 321 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 322 | * Flag indicating the motion event intersected the top edge of the screen. |
| 323 | */ |
| 324 | public static final int EDGE_TOP = 0x00000001; |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 325 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 326 | /** |
| 327 | * Flag indicating the motion event intersected the bottom edge of the screen. |
| 328 | */ |
| 329 | public static final int EDGE_BOTTOM = 0x00000002; |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 330 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 331 | /** |
| 332 | * Flag indicating the motion event intersected the left edge of the screen. |
| 333 | */ |
| 334 | public static final int EDGE_LEFT = 0x00000004; |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 335 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 336 | /** |
| 337 | * Flag indicating the motion event intersected the right edge of the screen. |
| 338 | */ |
| 339 | public static final int EDGE_RIGHT = 0x00000008; |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 340 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 341 | /** |
| 342 | * Constant used to identify the X axis of a motion event. |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 343 | * <p> |
| 344 | * <ul> |
| 345 | * <li>For a touch screen, reports the absolute X screen position of the center of |
| 346 | * the touch contact area. The units are display pixels. |
| 347 | * <li>For a touch pad, reports the absolute X surface position of the center of the touch |
Jeff Brown | cc0c159 | 2011-02-19 05:07:28 -0800 | [diff] [blame] | 348 | * contact area. The units are device-dependent; use {@link InputDevice#getMotionRange(int)} |
| 349 | * to query the effective range of values. |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 350 | * <li>For a mouse, reports the absolute X screen position of the mouse pointer. |
| 351 | * The units are display pixels. |
| 352 | * <li>For a trackball, reports the relative horizontal displacement of the trackball. |
| 353 | * The value is normalized to a range from -1.0 (left) to 1.0 (right). |
| 354 | * <li>For a joystick, reports the absolute X position of the joystick. |
| 355 | * The value is normalized to a range from -1.0 (left) to 1.0 (right). |
| 356 | * </ul> |
| 357 | * </p> |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 358 | * |
| 359 | * @see #getX(int) |
| 360 | * @see #getHistoricalX(int, int) |
| 361 | * @see MotionEvent.PointerCoords#x |
| 362 | * @see InputDevice#getMotionRange |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 363 | */ |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 364 | public static final int AXIS_X = 0; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 365 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 366 | /** |
| 367 | * Constant used to identify the Y axis of a motion event. |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 368 | * <p> |
| 369 | * <ul> |
| 370 | * <li>For a touch screen, reports the absolute Y screen position of the center of |
| 371 | * the touch contact area. The units are display pixels. |
| 372 | * <li>For a touch pad, reports the absolute Y surface position of the center of the touch |
| 373 | * contact area. The units are device-dependent; use {@link InputDevice#getMotionRange(int)} |
| 374 | * to query the effective range of values. |
| 375 | * <li>For a mouse, reports the absolute Y screen position of the mouse pointer. |
| 376 | * The units are display pixels. |
| 377 | * <li>For a trackball, reports the relative vertical displacement of the trackball. |
| 378 | * The value is normalized to a range from -1.0 (up) to 1.0 (down). |
| 379 | * <li>For a joystick, reports the absolute Y position of the joystick. |
| 380 | * The value is normalized to a range from -1.0 (up or far) to 1.0 (down or near). |
| 381 | * </ul> |
| 382 | * </p> |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 383 | * |
| 384 | * @see #getY(int) |
| 385 | * @see #getHistoricalY(int, int) |
| 386 | * @see MotionEvent.PointerCoords#y |
| 387 | * @see InputDevice#getMotionRange |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 388 | */ |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 389 | public static final int AXIS_Y = 1; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 390 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 391 | /** |
| 392 | * Constant used to identify the Pressure axis of a motion event. |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 393 | * <p> |
| 394 | * <ul> |
Jeff Brown | cc0c159 | 2011-02-19 05:07:28 -0800 | [diff] [blame] | 395 | * <li>For a touch screen or touch pad, reports the approximate pressure applied to the surface |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 396 | * by a finger or other tool. The value is normalized to a range from |
| 397 | * 0 (no pressure at all) to 1 (normal pressure), although values higher than 1 |
| 398 | * may be generated depending on the calibration of the input device. |
| 399 | * <li>For a trackball, the value is set to 1 if the trackball button is pressed |
| 400 | * or 0 otherwise. |
| 401 | * <li>For a mouse, the value is set to 1 if the primary mouse button is pressed |
| 402 | * or 0 otherwise. |
| 403 | * </ul> |
| 404 | * </p> |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 405 | * |
| 406 | * @see #getPressure(int) |
| 407 | * @see #getHistoricalPressure(int, int) |
| 408 | * @see MotionEvent.PointerCoords#pressure |
| 409 | * @see InputDevice#getMotionRange |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 410 | */ |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 411 | public static final int AXIS_PRESSURE = 2; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 412 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 413 | /** |
| 414 | * Constant used to identify the Size axis of a motion event. |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 415 | * <p> |
| 416 | * <ul> |
| 417 | * <li>For a touch screen or touch pad, reports the approximate size of the contact area in |
| 418 | * relation to the maximum detectable size for the device. The value is normalized |
| 419 | * to a range from 0 (smallest detectable size) to 1 (largest detectable size), |
Jeff Brown | cc0c159 | 2011-02-19 05:07:28 -0800 | [diff] [blame] | 420 | * although it is not a linear scale. This value is of limited use. |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 421 | * To obtain calibrated size information, use |
| 422 | * {@link #AXIS_TOUCH_MAJOR} or {@link #AXIS_TOOL_MAJOR}. |
| 423 | * </ul> |
| 424 | * </p> |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 425 | * |
| 426 | * @see #getSize(int) |
| 427 | * @see #getHistoricalSize(int, int) |
| 428 | * @see MotionEvent.PointerCoords#size |
| 429 | * @see InputDevice#getMotionRange |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 430 | */ |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 431 | public static final int AXIS_SIZE = 3; |
| 432 | |
| 433 | /** |
| 434 | * Constant used to identify the TouchMajor axis of a motion event. |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 435 | * <p> |
| 436 | * <ul> |
| 437 | * <li>For a touch screen, reports the length of the major axis of an ellipse that |
| 438 | * represents the touch area at the point of contact. |
| 439 | * The units are display pixels. |
| 440 | * <li>For a touch pad, reports the length of the major axis of an ellipse that |
| 441 | * represents the touch area at the point of contact. |
| 442 | * The units are device-dependent; use {@link InputDevice#getMotionRange(int)} |
| 443 | * to query the effective range of values. |
| 444 | * </ul> |
| 445 | * </p> |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 446 | * |
| 447 | * @see #getTouchMajor(int) |
| 448 | * @see #getHistoricalTouchMajor(int, int) |
| 449 | * @see MotionEvent.PointerCoords#touchMajor |
| 450 | * @see InputDevice#getMotionRange |
Dianne Hackborn | 1e8dfc7 | 2009-08-06 12:43:01 -0700 | [diff] [blame] | 451 | */ |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 452 | public static final int AXIS_TOUCH_MAJOR = 4; |
| 453 | |
| 454 | /** |
| 455 | * Constant used to identify the TouchMinor axis of a motion event. |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 456 | * <p> |
| 457 | * <ul> |
| 458 | * <li>For a touch screen, reports the length of the minor axis of an ellipse that |
| 459 | * represents the touch area at the point of contact. |
| 460 | * The units are display pixels. |
| 461 | * <li>For a touch pad, reports the length of the minor axis of an ellipse that |
| 462 | * represents the touch area at the point of contact. |
| 463 | * The units are device-dependent; use {@link InputDevice#getMotionRange(int)} |
| 464 | * to query the effective range of values. |
| 465 | * </ul> |
| 466 | * </p><p> |
| 467 | * When the touch is circular, the major and minor axis lengths will be equal to one another. |
| 468 | * </p> |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 469 | * |
| 470 | * @see #getTouchMinor(int) |
| 471 | * @see #getHistoricalTouchMinor(int, int) |
| 472 | * @see MotionEvent.PointerCoords#touchMinor |
| 473 | * @see InputDevice#getMotionRange |
Jeff Brown | 9e2ad36 | 2010-07-30 19:20:11 -0700 | [diff] [blame] | 474 | */ |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 475 | public static final int AXIS_TOUCH_MINOR = 5; |
| 476 | |
| 477 | /** |
| 478 | * Constant used to identify the ToolMajor axis of a motion event. |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 479 | * <p> |
| 480 | * <ul> |
| 481 | * <li>For a touch screen, reports the length of the major axis of an ellipse that |
| 482 | * represents the size of the approaching finger or tool used to make contact. |
| 483 | * <li>For a touch pad, reports the length of the major axis of an ellipse that |
| 484 | * represents the size of the approaching finger or tool used to make contact. |
| 485 | * The units are device-dependent; use {@link InputDevice#getMotionRange(int)} |
| 486 | * to query the effective range of values. |
| 487 | * </ul> |
| 488 | * </p><p> |
| 489 | * When the touch is circular, the major and minor axis lengths will be equal to one another. |
| 490 | * </p><p> |
| 491 | * The tool size may be larger than the touch size since the tool may not be fully |
| 492 | * in contact with the touch sensor. |
| 493 | * </p> |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 494 | * |
| 495 | * @see #getToolMajor(int) |
| 496 | * @see #getHistoricalToolMajor(int, int) |
| 497 | * @see MotionEvent.PointerCoords#toolMajor |
| 498 | * @see InputDevice#getMotionRange |
| 499 | */ |
| 500 | public static final int AXIS_TOOL_MAJOR = 6; |
| 501 | |
| 502 | /** |
| 503 | * Constant used to identify the ToolMinor axis of a motion event. |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 504 | * <p> |
| 505 | * <ul> |
| 506 | * <li>For a touch screen, reports the length of the minor axis of an ellipse that |
| 507 | * represents the size of the approaching finger or tool used to make contact. |
| 508 | * <li>For a touch pad, reports the length of the minor axis of an ellipse that |
| 509 | * represents the size of the approaching finger or tool used to make contact. |
| 510 | * The units are device-dependent; use {@link InputDevice#getMotionRange(int)} |
| 511 | * to query the effective range of values. |
| 512 | * </ul> |
| 513 | * </p><p> |
| 514 | * When the touch is circular, the major and minor axis lengths will be equal to one another. |
| 515 | * </p><p> |
| 516 | * The tool size may be larger than the touch size since the tool may not be fully |
| 517 | * in contact with the touch sensor. |
| 518 | * </p> |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 519 | * |
| 520 | * @see #getToolMinor(int) |
| 521 | * @see #getHistoricalToolMinor(int, int) |
| 522 | * @see MotionEvent.PointerCoords#toolMinor |
| 523 | * @see InputDevice#getMotionRange |
| 524 | */ |
| 525 | public static final int AXIS_TOOL_MINOR = 7; |
| 526 | |
| 527 | /** |
| 528 | * Constant used to identify the Orientation axis of a motion event. |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 529 | * <p> |
| 530 | * <ul> |
| 531 | * <li>For a touch screen or touch pad, reports the orientation of the finger |
| 532 | * or tool in radians relative to the vertical plane of the device. |
| 533 | * An angle of 0 radians indicates that the major axis of contact is oriented |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 534 | * upwards, is perfectly circular or is of unknown orientation. A positive angle |
| 535 | * indicates that the major axis of contact is oriented to the right. A negative angle |
| 536 | * indicates that the major axis of contact is oriented to the left. |
| 537 | * The full range is from -PI/2 radians (finger pointing fully left) to PI/2 radians |
| 538 | * (finger pointing fully right). |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 539 | * </ul> |
| 540 | * </p> |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 541 | * |
| 542 | * @see #getOrientation(int) |
| 543 | * @see #getHistoricalOrientation(int, int) |
| 544 | * @see MotionEvent.PointerCoords#orientation |
| 545 | * @see InputDevice#getMotionRange |
| 546 | */ |
| 547 | public static final int AXIS_ORIENTATION = 8; |
| 548 | |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 549 | /** |
| 550 | * Constant used to identify the Vertical Scroll axis of a motion event. |
| 551 | * <p> |
| 552 | * <ul> |
Jeff Brown | cc0c159 | 2011-02-19 05:07:28 -0800 | [diff] [blame] | 553 | * <li>For a mouse, reports the relative movement of the vertical scroll wheel. |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 554 | * The value is normalized to a range from -1.0 (down) to 1.0 (up). |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 555 | * </ul> |
| 556 | * </p><p> |
| 557 | * This axis should be used to scroll views vertically. |
| 558 | * </p> |
| 559 | * |
| 560 | * @see #getAxisValue(int, int) |
| 561 | * @see #getHistoricalAxisValue(int, int, int) |
| 562 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 563 | * @see InputDevice#getMotionRange |
| 564 | */ |
| 565 | public static final int AXIS_VSCROLL = 9; |
| 566 | |
| 567 | /** |
| 568 | * Constant used to identify the Horizontal Scroll axis of a motion event. |
| 569 | * <p> |
| 570 | * <ul> |
Jeff Brown | cc0c159 | 2011-02-19 05:07:28 -0800 | [diff] [blame] | 571 | * <li>For a mouse, reports the relative movement of the horizontal scroll wheel. |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 572 | * The value is normalized to a range from -1.0 (left) to 1.0 (right). |
| 573 | * </ul> |
| 574 | * </p><p> |
| 575 | * This axis should be used to scroll views horizontally. |
| 576 | * </p> |
| 577 | * |
| 578 | * @see #getAxisValue(int, int) |
| 579 | * @see #getHistoricalAxisValue(int, int, int) |
| 580 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 581 | * @see InputDevice#getMotionRange |
| 582 | */ |
| 583 | public static final int AXIS_HSCROLL = 10; |
| 584 | |
| 585 | /** |
| 586 | * Constant used to identify the Z axis of a motion event. |
| 587 | * <p> |
| 588 | * <ul> |
| 589 | * <li>For a joystick, reports the absolute Z position of the joystick. |
| 590 | * The value is normalized to a range from -1.0 (high) to 1.0 (low). |
| 591 | * <em>On game pads with two analog joysticks, this axis is often reinterpreted |
| 592 | * to report the absolute X position of the second joystick instead.</em> |
| 593 | * </ul> |
| 594 | * </p> |
| 595 | * |
| 596 | * @see #getAxisValue(int, int) |
| 597 | * @see #getHistoricalAxisValue(int, int, int) |
| 598 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 599 | * @see InputDevice#getMotionRange |
| 600 | */ |
| 601 | public static final int AXIS_Z = 11; |
| 602 | |
| 603 | /** |
| 604 | * Constant used to identify the X Rotation axis of a motion event. |
| 605 | * <p> |
| 606 | * <ul> |
| 607 | * <li>For a joystick, reports the absolute rotation angle about the X axis. |
| 608 | * The value is normalized to a range from -1.0 (counter-clockwise) to 1.0 (clockwise). |
| 609 | * </ul> |
| 610 | * </p> |
| 611 | * |
| 612 | * @see #getAxisValue(int, int) |
| 613 | * @see #getHistoricalAxisValue(int, int, int) |
| 614 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 615 | * @see InputDevice#getMotionRange |
| 616 | */ |
| 617 | public static final int AXIS_RX = 12; |
| 618 | |
| 619 | /** |
| 620 | * Constant used to identify the Y Rotation axis of a motion event. |
| 621 | * <p> |
| 622 | * <ul> |
| 623 | * <li>For a joystick, reports the absolute rotation angle about the Y axis. |
| 624 | * The value is normalized to a range from -1.0 (counter-clockwise) to 1.0 (clockwise). |
| 625 | * </ul> |
| 626 | * </p> |
| 627 | * |
| 628 | * @see #getAxisValue(int, int) |
| 629 | * @see #getHistoricalAxisValue(int, int, int) |
| 630 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 631 | * @see InputDevice#getMotionRange |
| 632 | */ |
| 633 | public static final int AXIS_RY = 13; |
| 634 | |
| 635 | /** |
| 636 | * Constant used to identify the Z Rotation axis of a motion event. |
| 637 | * <p> |
| 638 | * <ul> |
| 639 | * <li>For a joystick, reports the absolute rotation angle about the Z axis. |
| 640 | * The value is normalized to a range from -1.0 (counter-clockwise) to 1.0 (clockwise). |
| 641 | * <em>On game pads with two analog joysticks, this axis is often reinterpreted |
| 642 | * to report the absolute Y position of the second joystick instead.</em> |
| 643 | * </ul> |
| 644 | * </p> |
| 645 | * |
| 646 | * @see #getAxisValue(int, int) |
| 647 | * @see #getHistoricalAxisValue(int, int, int) |
| 648 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 649 | * @see InputDevice#getMotionRange |
| 650 | */ |
| 651 | public static final int AXIS_RZ = 14; |
| 652 | |
| 653 | /** |
| 654 | * Constant used to identify the Hat X axis of a motion event. |
| 655 | * <p> |
| 656 | * <ul> |
| 657 | * <li>For a joystick, reports the absolute X position of the directional hat control. |
| 658 | * The value is normalized to a range from -1.0 (left) to 1.0 (right). |
| 659 | * </ul> |
| 660 | * </p> |
| 661 | * |
| 662 | * @see #getAxisValue(int, int) |
| 663 | * @see #getHistoricalAxisValue(int, int, int) |
| 664 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 665 | * @see InputDevice#getMotionRange |
| 666 | */ |
| 667 | public static final int AXIS_HAT_X = 15; |
| 668 | |
| 669 | /** |
| 670 | * Constant used to identify the Hat Y axis of a motion event. |
| 671 | * <p> |
| 672 | * <ul> |
| 673 | * <li>For a joystick, reports the absolute Y position of the directional hat control. |
| 674 | * The value is normalized to a range from -1.0 (up) to 1.0 (down). |
| 675 | * </ul> |
| 676 | * </p> |
| 677 | * |
| 678 | * @see #getAxisValue(int, int) |
| 679 | * @see #getHistoricalAxisValue(int, int, int) |
| 680 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 681 | * @see InputDevice#getMotionRange |
| 682 | */ |
| 683 | public static final int AXIS_HAT_Y = 16; |
| 684 | |
| 685 | /** |
| 686 | * Constant used to identify the Left Trigger axis of a motion event. |
| 687 | * <p> |
| 688 | * <ul> |
| 689 | * <li>For a joystick, reports the absolute position of the left trigger control. |
| 690 | * The value is normalized to a range from 0.0 (released) to 1.0 (fully pressed). |
| 691 | * </ul> |
| 692 | * </p> |
| 693 | * |
| 694 | * @see #getAxisValue(int, int) |
| 695 | * @see #getHistoricalAxisValue(int, int, int) |
| 696 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 697 | * @see InputDevice#getMotionRange |
| 698 | */ |
| 699 | public static final int AXIS_LTRIGGER = 17; |
| 700 | |
| 701 | /** |
| 702 | * Constant used to identify the Right Trigger axis of a motion event. |
| 703 | * <p> |
| 704 | * <ul> |
| 705 | * <li>For a joystick, reports the absolute position of the right trigger control. |
| 706 | * The value is normalized to a range from 0.0 (released) to 1.0 (fully pressed). |
| 707 | * </ul> |
| 708 | * </p> |
| 709 | * |
| 710 | * @see #getAxisValue(int, int) |
| 711 | * @see #getHistoricalAxisValue(int, int, int) |
| 712 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 713 | * @see InputDevice#getMotionRange |
| 714 | */ |
| 715 | public static final int AXIS_RTRIGGER = 18; |
| 716 | |
| 717 | /** |
Jeff Brown | 3a22fa0 | 2011-03-04 13:07:49 -0800 | [diff] [blame] | 718 | * Constant used to identify the Throttle axis of a motion event. |
| 719 | * <p> |
| 720 | * <ul> |
| 721 | * <li>For a joystick, reports the absolute position of the throttle control. |
| 722 | * The value is normalized to a range from 0.0 (fully open) to 1.0 (fully closed). |
| 723 | * </ul> |
| 724 | * </p> |
| 725 | * |
| 726 | * @see #getAxisValue(int, int) |
| 727 | * @see #getHistoricalAxisValue(int, int, int) |
| 728 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 729 | * @see InputDevice#getMotionRange |
| 730 | */ |
| 731 | public static final int AXIS_THROTTLE = 19; |
| 732 | |
| 733 | /** |
| 734 | * Constant used to identify the Rudder axis of a motion event. |
| 735 | * <p> |
| 736 | * <ul> |
| 737 | * <li>For a joystick, reports the absolute position of the rudder control. |
| 738 | * The value is normalized to a range from -1.0 (turn left) to 1.0 (turn right). |
| 739 | * </ul> |
| 740 | * </p> |
| 741 | * |
| 742 | * @see #getAxisValue(int, int) |
| 743 | * @see #getHistoricalAxisValue(int, int, int) |
| 744 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 745 | * @see InputDevice#getMotionRange |
| 746 | */ |
| 747 | public static final int AXIS_RUDDER = 20; |
| 748 | |
| 749 | /** |
| 750 | * Constant used to identify the Wheel axis of a motion event. |
| 751 | * <p> |
| 752 | * <ul> |
| 753 | * <li>For a joystick, reports the absolute position of the steering wheel control. |
| 754 | * The value is normalized to a range from -1.0 (turn left) to 1.0 (turn right). |
| 755 | * </ul> |
| 756 | * </p> |
| 757 | * |
| 758 | * @see #getAxisValue(int, int) |
| 759 | * @see #getHistoricalAxisValue(int, int, int) |
| 760 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 761 | * @see InputDevice#getMotionRange |
| 762 | */ |
| 763 | public static final int AXIS_WHEEL = 21; |
| 764 | |
| 765 | /** |
| 766 | * Constant used to identify the Gas axis of a motion event. |
| 767 | * <p> |
| 768 | * <ul> |
| 769 | * <li>For a joystick, reports the absolute position of the gas (accelerator) control. |
| 770 | * The value is normalized to a range from 0.0 (no acceleration) |
| 771 | * to 1.0 (maximum acceleration). |
| 772 | * </ul> |
| 773 | * </p> |
| 774 | * |
| 775 | * @see #getAxisValue(int, int) |
| 776 | * @see #getHistoricalAxisValue(int, int, int) |
| 777 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 778 | * @see InputDevice#getMotionRange |
| 779 | */ |
| 780 | public static final int AXIS_GAS = 22; |
| 781 | |
| 782 | /** |
| 783 | * Constant used to identify the Brake axis of a motion event. |
| 784 | * <p> |
| 785 | * <ul> |
| 786 | * <li>For a joystick, reports the absolute position of the brake control. |
| 787 | * The value is normalized to a range from 0.0 (no braking) to 1.0 (maximum braking). |
| 788 | * </ul> |
| 789 | * </p> |
| 790 | * |
| 791 | * @see #getAxisValue(int, int) |
| 792 | * @see #getHistoricalAxisValue(int, int, int) |
| 793 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 794 | * @see InputDevice#getMotionRange |
| 795 | */ |
| 796 | public static final int AXIS_BRAKE = 23; |
| 797 | |
| 798 | /** |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 799 | * Constant used to identify the Generic 1 axis of a motion event. |
| 800 | * The interpretation of a generic axis is device-specific. |
| 801 | * |
| 802 | * @see #getAxisValue(int, int) |
| 803 | * @see #getHistoricalAxisValue(int, int, int) |
| 804 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 805 | * @see InputDevice#getMotionRange |
| 806 | */ |
| 807 | public static final int AXIS_GENERIC_1 = 32; |
| 808 | |
| 809 | /** |
| 810 | * Constant used to identify the Generic 2 axis of a motion event. |
| 811 | * The interpretation of a generic axis is device-specific. |
| 812 | * |
| 813 | * @see #getAxisValue(int, int) |
| 814 | * @see #getHistoricalAxisValue(int, int, int) |
| 815 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 816 | * @see InputDevice#getMotionRange |
| 817 | */ |
| 818 | public static final int AXIS_GENERIC_2 = 33; |
| 819 | |
| 820 | /** |
| 821 | * Constant used to identify the Generic 3 axis of a motion event. |
| 822 | * The interpretation of a generic axis is device-specific. |
| 823 | * |
| 824 | * @see #getAxisValue(int, int) |
| 825 | * @see #getHistoricalAxisValue(int, int, int) |
| 826 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 827 | * @see InputDevice#getMotionRange |
| 828 | */ |
| 829 | public static final int AXIS_GENERIC_3 = 34; |
| 830 | |
| 831 | /** |
| 832 | * Constant used to identify the Generic 4 axis of a motion event. |
| 833 | * The interpretation of a generic axis is device-specific. |
| 834 | * |
| 835 | * @see #getAxisValue(int, int) |
| 836 | * @see #getHistoricalAxisValue(int, int, int) |
| 837 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 838 | * @see InputDevice#getMotionRange |
| 839 | */ |
| 840 | public static final int AXIS_GENERIC_4 = 35; |
| 841 | |
| 842 | /** |
| 843 | * Constant used to identify the Generic 5 axis of a motion event. |
| 844 | * The interpretation of a generic axis is device-specific. |
| 845 | * |
| 846 | * @see #getAxisValue(int, int) |
| 847 | * @see #getHistoricalAxisValue(int, int, int) |
| 848 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 849 | * @see InputDevice#getMotionRange |
| 850 | */ |
| 851 | public static final int AXIS_GENERIC_5 = 36; |
| 852 | |
| 853 | /** |
| 854 | * Constant used to identify the Generic 6 axis of a motion event. |
| 855 | * The interpretation of a generic axis is device-specific. |
| 856 | * |
| 857 | * @see #getAxisValue(int, int) |
| 858 | * @see #getHistoricalAxisValue(int, int, int) |
| 859 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 860 | * @see InputDevice#getMotionRange |
| 861 | */ |
| 862 | public static final int AXIS_GENERIC_6 = 37; |
| 863 | |
| 864 | /** |
| 865 | * Constant used to identify the Generic 7 axis of a motion event. |
| 866 | * The interpretation of a generic axis is device-specific. |
| 867 | * |
| 868 | * @see #getAxisValue(int, int) |
| 869 | * @see #getHistoricalAxisValue(int, int, int) |
| 870 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 871 | * @see InputDevice#getMotionRange |
| 872 | */ |
| 873 | public static final int AXIS_GENERIC_7 = 38; |
| 874 | |
| 875 | /** |
| 876 | * Constant used to identify the Generic 8 axis of a motion event. |
| 877 | * The interpretation of a generic axis is device-specific. |
| 878 | * |
| 879 | * @see #getAxisValue(int, int) |
| 880 | * @see #getHistoricalAxisValue(int, int, int) |
| 881 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 882 | * @see InputDevice#getMotionRange |
| 883 | */ |
| 884 | public static final int AXIS_GENERIC_8 = 39; |
| 885 | |
| 886 | /** |
| 887 | * Constant used to identify the Generic 9 axis of a motion event. |
| 888 | * The interpretation of a generic axis is device-specific. |
| 889 | * |
| 890 | * @see #getAxisValue(int, int) |
| 891 | * @see #getHistoricalAxisValue(int, int, int) |
| 892 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 893 | * @see InputDevice#getMotionRange |
| 894 | */ |
| 895 | public static final int AXIS_GENERIC_9 = 40; |
| 896 | |
| 897 | /** |
| 898 | * Constant used to identify the Generic 10 axis of a motion event. |
| 899 | * The interpretation of a generic axis is device-specific. |
| 900 | * |
| 901 | * @see #getAxisValue(int, int) |
| 902 | * @see #getHistoricalAxisValue(int, int, int) |
| 903 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 904 | * @see InputDevice#getMotionRange |
| 905 | */ |
| 906 | public static final int AXIS_GENERIC_10 = 41; |
| 907 | |
| 908 | /** |
| 909 | * Constant used to identify the Generic 11 axis of a motion event. |
| 910 | * The interpretation of a generic axis is device-specific. |
| 911 | * |
| 912 | * @see #getAxisValue(int, int) |
| 913 | * @see #getHistoricalAxisValue(int, int, int) |
| 914 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 915 | * @see InputDevice#getMotionRange |
| 916 | */ |
| 917 | public static final int AXIS_GENERIC_11 = 42; |
| 918 | |
| 919 | /** |
| 920 | * Constant used to identify the Generic 12 axis of a motion event. |
| 921 | * The interpretation of a generic axis is device-specific. |
| 922 | * |
| 923 | * @see #getAxisValue(int, int) |
| 924 | * @see #getHistoricalAxisValue(int, int, int) |
| 925 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 926 | * @see InputDevice#getMotionRange |
| 927 | */ |
| 928 | public static final int AXIS_GENERIC_12 = 43; |
| 929 | |
| 930 | /** |
| 931 | * Constant used to identify the Generic 13 axis of a motion event. |
| 932 | * The interpretation of a generic axis is device-specific. |
| 933 | * |
| 934 | * @see #getAxisValue(int, int) |
| 935 | * @see #getHistoricalAxisValue(int, int, int) |
| 936 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 937 | * @see InputDevice#getMotionRange |
| 938 | */ |
| 939 | public static final int AXIS_GENERIC_13 = 44; |
| 940 | |
| 941 | /** |
| 942 | * Constant used to identify the Generic 14 axis of a motion event. |
| 943 | * The interpretation of a generic axis is device-specific. |
| 944 | * |
| 945 | * @see #getAxisValue(int, int) |
| 946 | * @see #getHistoricalAxisValue(int, int, int) |
| 947 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 948 | * @see InputDevice#getMotionRange |
| 949 | */ |
| 950 | public static final int AXIS_GENERIC_14 = 45; |
| 951 | |
| 952 | /** |
| 953 | * Constant used to identify the Generic 15 axis of a motion event. |
| 954 | * The interpretation of a generic axis is device-specific. |
| 955 | * |
| 956 | * @see #getAxisValue(int, int) |
| 957 | * @see #getHistoricalAxisValue(int, int, int) |
| 958 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 959 | * @see InputDevice#getMotionRange |
| 960 | */ |
| 961 | public static final int AXIS_GENERIC_15 = 46; |
| 962 | |
| 963 | /** |
| 964 | * Constant used to identify the Generic 16 axis of a motion event. |
| 965 | * The interpretation of a generic axis is device-specific. |
| 966 | * |
| 967 | * @see #getAxisValue(int, int) |
| 968 | * @see #getHistoricalAxisValue(int, int, int) |
| 969 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 970 | * @see InputDevice#getMotionRange |
| 971 | */ |
| 972 | public static final int AXIS_GENERIC_16 = 47; |
| 973 | |
| 974 | // NOTE: If you add a new axis here you must also add it to: |
| 975 | // native/include/android/input.h |
| 976 | // frameworks/base/include/ui/KeycodeLabels.h |
| 977 | |
| 978 | // Symbolic names of all axes. |
| 979 | private static final SparseArray<String> AXIS_SYMBOLIC_NAMES = new SparseArray<String>(); |
| 980 | private static void populateAxisSymbolicNames() { |
| 981 | SparseArray<String> names = AXIS_SYMBOLIC_NAMES; |
| 982 | names.append(AXIS_X, "AXIS_X"); |
| 983 | names.append(AXIS_Y, "AXIS_Y"); |
| 984 | names.append(AXIS_PRESSURE, "AXIS_PRESSURE"); |
| 985 | names.append(AXIS_SIZE, "AXIS_SIZE"); |
| 986 | names.append(AXIS_TOUCH_MAJOR, "AXIS_TOUCH_MAJOR"); |
| 987 | names.append(AXIS_TOUCH_MINOR, "AXIS_TOUCH_MINOR"); |
| 988 | names.append(AXIS_TOOL_MAJOR, "AXIS_TOOL_MAJOR"); |
| 989 | names.append(AXIS_TOOL_MINOR, "AXIS_TOOL_MINOR"); |
| 990 | names.append(AXIS_ORIENTATION, "AXIS_ORIENTATION"); |
| 991 | names.append(AXIS_VSCROLL, "AXIS_VSCROLL"); |
| 992 | names.append(AXIS_HSCROLL, "AXIS_HSCROLL"); |
| 993 | names.append(AXIS_Z, "AXIS_Z"); |
| 994 | names.append(AXIS_RX, "AXIS_RX"); |
| 995 | names.append(AXIS_RY, "AXIS_RY"); |
| 996 | names.append(AXIS_RZ, "AXIS_RZ"); |
| 997 | names.append(AXIS_HAT_X, "AXIS_HAT_X"); |
| 998 | names.append(AXIS_HAT_Y, "AXIS_HAT_Y"); |
| 999 | names.append(AXIS_LTRIGGER, "AXIS_LTRIGGER"); |
| 1000 | names.append(AXIS_RTRIGGER, "AXIS_RTRIGGER"); |
Jeff Brown | 3a22fa0 | 2011-03-04 13:07:49 -0800 | [diff] [blame] | 1001 | names.append(AXIS_THROTTLE, "AXIS_THROTTLE"); |
| 1002 | names.append(AXIS_RUDDER, "AXIS_RUDDER"); |
| 1003 | names.append(AXIS_WHEEL, "AXIS_WHEEL"); |
| 1004 | names.append(AXIS_GAS, "AXIS_GAS"); |
| 1005 | names.append(AXIS_BRAKE, "AXIS_BRAKE"); |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 1006 | names.append(AXIS_GENERIC_1, "AXIS_GENERIC_1"); |
| 1007 | names.append(AXIS_GENERIC_2, "AXIS_GENERIC_2"); |
| 1008 | names.append(AXIS_GENERIC_3, "AXIS_GENERIC_3"); |
| 1009 | names.append(AXIS_GENERIC_4, "AXIS_GENERIC_4"); |
| 1010 | names.append(AXIS_GENERIC_5, "AXIS_GENERIC_5"); |
| 1011 | names.append(AXIS_GENERIC_6, "AXIS_GENERIC_6"); |
| 1012 | names.append(AXIS_GENERIC_7, "AXIS_GENERIC_7"); |
| 1013 | names.append(AXIS_GENERIC_8, "AXIS_GENERIC_8"); |
| 1014 | names.append(AXIS_GENERIC_9, "AXIS_GENERIC_9"); |
| 1015 | names.append(AXIS_GENERIC_10, "AXIS_GENERIC_10"); |
| 1016 | names.append(AXIS_GENERIC_11, "AXIS_GENERIC_11"); |
| 1017 | names.append(AXIS_GENERIC_12, "AXIS_GENERIC_12"); |
| 1018 | names.append(AXIS_GENERIC_13, "AXIS_GENERIC_13"); |
| 1019 | names.append(AXIS_GENERIC_14, "AXIS_GENERIC_14"); |
| 1020 | names.append(AXIS_GENERIC_15, "AXIS_GENERIC_15"); |
| 1021 | names.append(AXIS_GENERIC_16, "AXIS_GENERIC_16"); |
| 1022 | } |
| 1023 | |
| 1024 | static { |
| 1025 | populateAxisSymbolicNames(); |
| 1026 | } |
| 1027 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1028 | // Private value for history pos that obtains the current sample. |
| 1029 | private static final int HISTORY_CURRENT = -0x80000000; |
| 1030 | |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 1031 | private static final int MAX_RECYCLED = 10; |
| 1032 | private static final Object gRecyclerLock = new Object(); |
| 1033 | private static int gRecyclerUsed; |
| 1034 | private static MotionEvent gRecyclerTop; |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1035 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1036 | // Shared temporary objects used when translating coordinates supplied by |
| 1037 | // the caller into single element PointerCoords and pointer id arrays. |
| 1038 | // Must lock gTmpPointerCoords prior to use. |
| 1039 | private static final PointerCoords[] gTmpPointerCoords = |
| 1040 | new PointerCoords[] { new PointerCoords() }; |
| 1041 | private static final int[] gTmpPointerIds = new int[] { 0 /*always 0*/ }; |
| 1042 | |
| 1043 | // Pointer to the native MotionEvent object that contains the actual data. |
| 1044 | private int mNativePtr; |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 1045 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1046 | private MotionEvent mNext; |
| 1047 | private RuntimeException mRecycledLocation; |
| 1048 | private boolean mRecycled; |
| 1049 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1050 | private static native int nativeInitialize(int nativePtr, |
| 1051 | int deviceId, int source, int action, int flags, int edgeFlags, int metaState, |
| 1052 | float xOffset, float yOffset, float xPrecision, float yPrecision, |
| 1053 | long downTimeNanos, long eventTimeNanos, |
| 1054 | int pointerCount, int[] pointerIds, PointerCoords[] pointerCoords); |
| 1055 | private static native int nativeCopy(int destNativePtr, int sourceNativePtr, |
| 1056 | boolean keepHistory); |
| 1057 | private static native void nativeDispose(int nativePtr); |
| 1058 | private static native void nativeAddBatch(int nativePtr, long eventTimeNanos, |
| 1059 | PointerCoords[] pointerCoords, int metaState); |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 1060 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1061 | private static native int nativeGetDeviceId(int nativePtr); |
| 1062 | private static native int nativeGetSource(int nativePtr); |
| 1063 | private static native int nativeSetSource(int nativePtr, int source); |
| 1064 | private static native int nativeGetAction(int nativePtr); |
| 1065 | private static native void nativeSetAction(int nativePtr, int action); |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 1066 | private static native boolean nativeIsTouchEvent(int nativePtr); |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1067 | private static native int nativeGetFlags(int nativePtr); |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 1068 | private static native void nativeSetFlags(int nativePtr, int flags); |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1069 | private static native int nativeGetEdgeFlags(int nativePtr); |
| 1070 | private static native void nativeSetEdgeFlags(int nativePtr, int action); |
| 1071 | private static native int nativeGetMetaState(int nativePtr); |
| 1072 | private static native void nativeOffsetLocation(int nativePtr, float deltaX, float deltaY); |
| 1073 | private static native float nativeGetXPrecision(int nativePtr); |
| 1074 | private static native float nativeGetYPrecision(int nativePtr); |
| 1075 | private static native long nativeGetDownTimeNanos(int nativePtr); |
| 1076 | |
| 1077 | private static native int nativeGetPointerCount(int nativePtr); |
| 1078 | private static native int nativeGetPointerId(int nativePtr, int pointerIndex); |
| 1079 | private static native int nativeFindPointerIndex(int nativePtr, int pointerId); |
| 1080 | |
| 1081 | private static native int nativeGetHistorySize(int nativePtr); |
| 1082 | private static native long nativeGetEventTimeNanos(int nativePtr, int historyPos); |
| 1083 | private static native float nativeGetRawAxisValue(int nativePtr, |
| 1084 | int axis, int pointerIndex, int historyPos); |
| 1085 | private static native float nativeGetAxisValue(int nativePtr, |
| 1086 | int axis, int pointerIndex, int historyPos); |
| 1087 | private static native void nativeGetPointerCoords(int nativePtr, |
| 1088 | int pointerIndex, int historyPos, PointerCoords outPointerCoords); |
| 1089 | |
| 1090 | private static native void nativeScale(int nativePtr, float scale); |
| 1091 | private static native void nativeTransform(int nativePtr, Matrix matrix); |
| 1092 | |
| 1093 | private static native int nativeReadFromParcel(int nativePtr, Parcel parcel); |
| 1094 | private static native void nativeWriteToParcel(int nativePtr, Parcel parcel); |
| 1095 | |
| 1096 | private MotionEvent() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1097 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1098 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1099 | @Override |
| 1100 | protected void finalize() throws Throwable { |
| 1101 | try { |
| 1102 | if (mNativePtr != 0) { |
| 1103 | nativeDispose(mNativePtr); |
| 1104 | mNativePtr = 0; |
| 1105 | } |
| 1106 | } finally { |
| 1107 | super.finalize(); |
| 1108 | } |
| 1109 | } |
| 1110 | |
| 1111 | static private MotionEvent obtain() { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1112 | final MotionEvent ev; |
| 1113 | synchronized (gRecyclerLock) { |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 1114 | ev = gRecyclerTop; |
| 1115 | if (ev == null) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1116 | return new MotionEvent(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1117 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1118 | gRecyclerTop = ev.mNext; |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1119 | gRecyclerUsed -= 1; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1120 | } |
| 1121 | ev.mRecycledLocation = null; |
| 1122 | ev.mRecycled = false; |
| 1123 | ev.mNext = null; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1124 | return ev; |
| 1125 | } |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1126 | |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 1127 | /** |
| 1128 | * Create a new MotionEvent, filling in all of the basic values that |
| 1129 | * define the motion. |
| 1130 | * |
| 1131 | * @param downTime The time (in ms) when the user originally pressed down to start |
| 1132 | * 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] | 1133 | * @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] | 1134 | * must be obtained from {@link SystemClock#uptimeMillis()}. |
Jeff Brown | cc0c159 | 2011-02-19 05:07:28 -0800 | [diff] [blame] | 1135 | * @param action The kind of action being performed, such as {@link #ACTION_DOWN}. |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1136 | * @param pointers The number of points that will be in this event. |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1137 | * @param pointerIds An array of <em>pointers</em> values providing |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1138 | * an identifier for each pointer. |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1139 | * @param pointerCoords An array of <em>pointers</em> values providing |
| 1140 | * a {@link PointerCoords} coordinate object for each pointer. |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 1141 | * @param metaState The state of any meta / modifier keys that were in effect when |
| 1142 | * the event was generated. |
| 1143 | * @param xPrecision The precision of the X coordinate being reported. |
| 1144 | * @param yPrecision The precision of the Y coordinate being reported. |
| 1145 | * @param deviceId The id for the device that this event came from. An id of |
| 1146 | * zero indicates that the event didn't come from a physical device; other |
| 1147 | * numbers are arbitrary and you shouldn't depend on the values. |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 1148 | * @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] | 1149 | * MotionEvent. |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1150 | * @param source The source of this event. |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 1151 | * @param flags The motion event flags. |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 1152 | */ |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1153 | static public MotionEvent obtain(long downTime, long eventTime, |
| 1154 | int action, int pointers, int[] pointerIds, PointerCoords[] pointerCoords, |
| 1155 | int metaState, float xPrecision, float yPrecision, int deviceId, |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 1156 | int edgeFlags, int source, int flags) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1157 | MotionEvent ev = obtain(); |
| 1158 | ev.mNativePtr = nativeInitialize(ev.mNativePtr, |
| 1159 | deviceId, source, action, flags, edgeFlags, metaState, |
| 1160 | 0, 0, xPrecision, yPrecision, |
| 1161 | downTime * NS_PER_MS, eventTime * NS_PER_MS, |
| 1162 | pointers, pointerIds, pointerCoords); |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 1163 | return ev; |
| 1164 | } |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1165 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1166 | /** |
| 1167 | * Create a new MotionEvent, filling in all of the basic values that |
| 1168 | * define the motion. |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1169 | * |
| 1170 | * @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] | 1171 | * 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] | 1172 | * @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] | 1173 | * must be obtained from {@link SystemClock#uptimeMillis()}. |
Jeff Brown | cc0c159 | 2011-02-19 05:07:28 -0800 | [diff] [blame] | 1174 | * @param action The kind of action being performed, such as {@link #ACTION_DOWN}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1175 | * @param x The X coordinate of this event. |
| 1176 | * @param y The Y coordinate of this event. |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1177 | * @param pressure The current pressure of this event. The pressure generally |
| 1178 | * ranges from 0 (no pressure at all) to 1 (normal pressure), however |
| 1179 | * 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] | 1180 | * the input device. |
| 1181 | * @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] | 1182 | * 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] | 1183 | * touch is normalized with a device specific range of values |
| 1184 | * and scaled to a value between 0 and 1. |
| 1185 | * @param metaState The state of any meta / modifier keys that were in effect when |
| 1186 | * the event was generated. |
| 1187 | * @param xPrecision The precision of the X coordinate being reported. |
| 1188 | * @param yPrecision The precision of the Y coordinate being reported. |
| 1189 | * @param deviceId The id for the device that this event came from. An id of |
| 1190 | * zero indicates that the event didn't come from a physical device; other |
| 1191 | * numbers are arbitrary and you shouldn't depend on the values. |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 1192 | * @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] | 1193 | * MotionEvent. |
| 1194 | */ |
| 1195 | static public MotionEvent obtain(long downTime, long eventTime, int action, |
| 1196 | float x, float y, float pressure, float size, int metaState, |
| 1197 | float xPrecision, float yPrecision, int deviceId, int edgeFlags) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1198 | synchronized (gTmpPointerCoords) { |
| 1199 | final PointerCoords pc = gTmpPointerCoords[0]; |
| 1200 | pc.clear(); |
| 1201 | pc.x = x; |
| 1202 | pc.y = y; |
| 1203 | pc.pressure = pressure; |
| 1204 | pc.size = size; |
| 1205 | |
| 1206 | MotionEvent ev = obtain(); |
| 1207 | ev.mNativePtr = nativeInitialize(ev.mNativePtr, |
| 1208 | deviceId, InputDevice.SOURCE_UNKNOWN, action, 0, edgeFlags, metaState, |
| 1209 | 0, 0, xPrecision, yPrecision, |
| 1210 | downTime * NS_PER_MS, eventTime * NS_PER_MS, |
| 1211 | 1, gTmpPointerIds, gTmpPointerCoords); |
| 1212 | return ev; |
| 1213 | } |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1214 | } |
| 1215 | |
| 1216 | /** |
| 1217 | * Create a new MotionEvent, filling in all of the basic values that |
| 1218 | * define the motion. |
| 1219 | * |
| 1220 | * @param downTime The time (in ms) when the user originally pressed down to start |
| 1221 | * a stream of position events. This must be obtained from {@link SystemClock#uptimeMillis()}. |
| 1222 | * @param eventTime The the time (in ms) when this specific event was generated. This |
| 1223 | * must be obtained from {@link SystemClock#uptimeMillis()}. |
Jeff Brown | cc0c159 | 2011-02-19 05:07:28 -0800 | [diff] [blame] | 1224 | * @param action The kind of action being performed, such as {@link #ACTION_DOWN}. |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1225 | * @param pointers The number of pointers that are active in this event. |
| 1226 | * @param x The X coordinate of this event. |
| 1227 | * @param y The Y coordinate of this event. |
| 1228 | * @param pressure The current pressure of this event. The pressure generally |
| 1229 | * ranges from 0 (no pressure at all) to 1 (normal pressure), however |
| 1230 | * values higher than 1 may be generated depending on the calibration of |
| 1231 | * the input device. |
| 1232 | * @param size A scaled value of the approximate size of the area being pressed when |
| 1233 | * touched with the finger. The actual value in pixels corresponding to the finger |
| 1234 | * touch is normalized with a device specific range of values |
| 1235 | * and scaled to a value between 0 and 1. |
| 1236 | * @param metaState The state of any meta / modifier keys that were in effect when |
| 1237 | * the event was generated. |
| 1238 | * @param xPrecision The precision of the X coordinate being reported. |
| 1239 | * @param yPrecision The precision of the Y coordinate being reported. |
| 1240 | * @param deviceId The id for the device that this event came from. An id of |
| 1241 | * zero indicates that the event didn't come from a physical device; other |
| 1242 | * numbers are arbitrary and you shouldn't depend on the values. |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 1243 | * @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] | 1244 | * MotionEvent. |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1245 | * |
| 1246 | * @deprecated Use {@link #obtain(long, long, int, float, float, float, float, int, float, float, int, int)} |
| 1247 | * instead. |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1248 | */ |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1249 | @Deprecated |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1250 | static public MotionEvent obtain(long downTime, long eventTime, int action, |
| 1251 | int pointers, float x, float y, float pressure, float size, int metaState, |
| 1252 | float xPrecision, float yPrecision, int deviceId, int edgeFlags) { |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1253 | return obtain(downTime, eventTime, action, x, y, pressure, size, |
| 1254 | metaState, xPrecision, yPrecision, deviceId, edgeFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1255 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1256 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1257 | /** |
| 1258 | * Create a new MotionEvent, filling in a subset of the basic motion |
| 1259 | * values. Those not specified here are: device id (always 0), pressure |
| 1260 | * 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] | 1261 | * |
| 1262 | * @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] | 1263 | * 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] | 1264 | * @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] | 1265 | * must be obtained from {@link SystemClock#uptimeMillis()}. |
Jeff Brown | cc0c159 | 2011-02-19 05:07:28 -0800 | [diff] [blame] | 1266 | * @param action The kind of action being performed, such as {@link #ACTION_DOWN}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1267 | * @param x The X coordinate of this event. |
| 1268 | * @param y The Y coordinate of this event. |
| 1269 | * @param metaState The state of any meta / modifier keys that were in effect when |
| 1270 | * the event was generated. |
| 1271 | */ |
| 1272 | static public MotionEvent obtain(long downTime, long eventTime, int action, |
| 1273 | float x, float y, int metaState) { |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1274 | return obtain(downTime, eventTime, action, x, y, 1.0f, 1.0f, |
| 1275 | metaState, 1.0f, 1.0f, 0, 0); |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 1276 | } |
| 1277 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1278 | /** |
| 1279 | * Create a new MotionEvent, copying from an existing one. |
| 1280 | */ |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1281 | static public MotionEvent obtain(MotionEvent other) { |
| 1282 | if (other == null) { |
| 1283 | throw new IllegalArgumentException("other motion event must not be null"); |
| 1284 | } |
| 1285 | |
| 1286 | MotionEvent ev = obtain(); |
| 1287 | ev.mNativePtr = nativeCopy(ev.mNativePtr, other.mNativePtr, true /*keepHistory*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1288 | return ev; |
| 1289 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1290 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1291 | /** |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 1292 | * Create a new MotionEvent, copying from an existing one, but not including |
| 1293 | * any historical point information. |
| 1294 | */ |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1295 | static public MotionEvent obtainNoHistory(MotionEvent other) { |
| 1296 | if (other == null) { |
| 1297 | throw new IllegalArgumentException("other motion event must not be null"); |
| 1298 | } |
| 1299 | |
| 1300 | MotionEvent ev = obtain(); |
| 1301 | ev.mNativePtr = nativeCopy(ev.mNativePtr, other.mNativePtr, false /*keepHistory*/); |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 1302 | return ev; |
| 1303 | } |
| 1304 | |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 1305 | /** @hide */ |
| 1306 | @Override |
| 1307 | public MotionEvent copy() { |
| 1308 | return obtain(this); |
| 1309 | } |
| 1310 | |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 1311 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1312 | * Recycle the MotionEvent, to be re-used by a later caller. After calling |
| 1313 | * this function you must not ever touch the event again. |
| 1314 | */ |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1315 | public final void recycle() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1316 | // Ensure recycle is only called once! |
| 1317 | if (TRACK_RECYCLED_LOCATION) { |
| 1318 | if (mRecycledLocation != null) { |
| 1319 | throw new RuntimeException(toString() + " recycled twice!", mRecycledLocation); |
| 1320 | } |
| 1321 | mRecycledLocation = new RuntimeException("Last recycled here"); |
Jeff Brown | d28f4be | 2010-06-02 15:35:46 -0700 | [diff] [blame] | 1322 | //Log.w("MotionEvent", "Recycling event " + this, mRecycledLocation); |
| 1323 | } else { |
| 1324 | if (mRecycled) { |
| 1325 | throw new RuntimeException(toString() + " recycled twice!"); |
| 1326 | } |
| 1327 | mRecycled = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1328 | } |
| 1329 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1330 | synchronized (gRecyclerLock) { |
| 1331 | if (gRecyclerUsed < MAX_RECYCLED) { |
| 1332 | gRecyclerUsed++; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1333 | mNext = gRecyclerTop; |
| 1334 | gRecyclerTop = this; |
| 1335 | } |
| 1336 | } |
| 1337 | } |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1338 | |
| 1339 | /** |
| 1340 | * Scales down the coordination of this event by the given scale. |
| 1341 | * |
| 1342 | * @hide |
| 1343 | */ |
| 1344 | public final void scale(float scale) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1345 | nativeScale(mNativePtr, scale); |
| 1346 | } |
| 1347 | |
| 1348 | /** {@inheritDoc} */ |
| 1349 | @Override |
| 1350 | public final int getDeviceId() { |
| 1351 | return nativeGetDeviceId(mNativePtr); |
| 1352 | } |
| 1353 | |
| 1354 | /** {@inheritDoc} */ |
| 1355 | @Override |
| 1356 | public final int getSource() { |
| 1357 | return nativeGetSource(mNativePtr); |
| 1358 | } |
| 1359 | |
| 1360 | /** {@inheritDoc} */ |
| 1361 | @Override |
| 1362 | public final void setSource(int source) { |
| 1363 | nativeSetSource(mNativePtr, source); |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1364 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1365 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1366 | /** |
Jeff Brown | cc0c159 | 2011-02-19 05:07:28 -0800 | [diff] [blame] | 1367 | * Return the kind of action being performed. |
| 1368 | * Consider using {@link #getActionMasked} and {@link #getActionIndex} to retrieve |
| 1369 | * the separate masked action and pointer index. |
| 1370 | * @return The action, such as {@link #ACTION_DOWN} or |
| 1371 | * the combination of {@link #ACTION_POINTER_DOWN} with a shifted pointer index. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1372 | */ |
| 1373 | public final int getAction() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1374 | return nativeGetAction(mNativePtr); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1375 | } |
| 1376 | |
| 1377 | /** |
Jeff Brown | cc0c159 | 2011-02-19 05:07:28 -0800 | [diff] [blame] | 1378 | * Return the masked action being performed, without pointer index information. |
| 1379 | * Use {@link #getActionIndex} to return the index associated with pointer actions. |
| 1380 | * @return The action, such as {@link #ACTION_DOWN} or {@link #ACTION_POINTER_DOWN}. |
Dianne Hackborn | b125dc5 | 2010-02-12 15:52:09 -0800 | [diff] [blame] | 1381 | */ |
| 1382 | public final int getActionMasked() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1383 | return nativeGetAction(mNativePtr) & ACTION_MASK; |
Dianne Hackborn | b125dc5 | 2010-02-12 15:52:09 -0800 | [diff] [blame] | 1384 | } |
| 1385 | |
| 1386 | /** |
| 1387 | * For {@link #ACTION_POINTER_DOWN} or {@link #ACTION_POINTER_UP} |
| 1388 | * as returned by {@link #getActionMasked}, this returns the associated |
Jeff Brown | cc0c159 | 2011-02-19 05:07:28 -0800 | [diff] [blame] | 1389 | * pointer index. |
| 1390 | * The index may be used with {@link #getPointerId(int)}, |
Dianne Hackborn | b125dc5 | 2010-02-12 15:52:09 -0800 | [diff] [blame] | 1391 | * {@link #getX(int)}, {@link #getY(int)}, {@link #getPressure(int)}, |
| 1392 | * and {@link #getSize(int)} to get information about the pointer that has |
| 1393 | * gone down or up. |
Jeff Brown | cc0c159 | 2011-02-19 05:07:28 -0800 | [diff] [blame] | 1394 | * @return The index associated with the action. |
Dianne Hackborn | b125dc5 | 2010-02-12 15:52:09 -0800 | [diff] [blame] | 1395 | */ |
| 1396 | public final int getActionIndex() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1397 | return (nativeGetAction(mNativePtr) & ACTION_POINTER_INDEX_MASK) |
| 1398 | >> ACTION_POINTER_INDEX_SHIFT; |
Dianne Hackborn | b125dc5 | 2010-02-12 15:52:09 -0800 | [diff] [blame] | 1399 | } |
| 1400 | |
| 1401 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 1402 | * Returns true if this motion event is a touch event. |
| 1403 | * <p> |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 1404 | * Specifically excludes pointer events with action {@link #ACTION_HOVER_MOVE}, |
| 1405 | * {@link #ACTION_HOVER_ENTER}, {@link #ACTION_HOVER_EXIT}, or {@link #ACTION_SCROLL} |
| 1406 | * because they are not actually touch events (the pointer is not down). |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 1407 | * </p> |
| 1408 | * @return True if this motion event is a touch event. |
| 1409 | * @hide |
| 1410 | */ |
| 1411 | public final boolean isTouchEvent() { |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 1412 | return nativeIsTouchEvent(mNativePtr); |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 1413 | } |
| 1414 | |
| 1415 | /** |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 1416 | * Gets the motion event flags. |
| 1417 | * |
| 1418 | * @see #FLAG_WINDOW_IS_OBSCURED |
| 1419 | */ |
| 1420 | public final int getFlags() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1421 | return nativeGetFlags(mNativePtr); |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 1422 | } |
| 1423 | |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 1424 | /** @hide */ |
| 1425 | @Override |
| 1426 | public final boolean isTainted() { |
| 1427 | final int flags = getFlags(); |
| 1428 | return (flags & FLAG_TAINTED) != 0; |
| 1429 | } |
| 1430 | |
| 1431 | /** @hide */ |
| 1432 | @Override |
| 1433 | public final void setTainted(boolean tainted) { |
| 1434 | final int flags = getFlags(); |
| 1435 | nativeSetFlags(mNativePtr, tainted ? flags | FLAG_TAINTED : flags & ~FLAG_TAINTED); |
| 1436 | } |
| 1437 | |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 1438 | /** |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1439 | * Returns the time (in ms) when the user originally pressed down to start |
| 1440 | * a stream of position events. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1441 | */ |
| 1442 | public final long getDownTime() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1443 | return nativeGetDownTimeNanos(mNativePtr) / NS_PER_MS; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1444 | } |
| 1445 | |
| 1446 | /** |
| 1447 | * Returns the time (in ms) when this specific event was generated. |
| 1448 | */ |
| 1449 | public final long getEventTime() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1450 | return nativeGetEventTimeNanos(mNativePtr, HISTORY_CURRENT) / NS_PER_MS; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1451 | } |
| 1452 | |
| 1453 | /** |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 1454 | * Returns the time (in ns) when this specific event was generated. |
| 1455 | * The value is in nanosecond precision but it may not have nanosecond accuracy. |
| 1456 | * |
| 1457 | * @hide |
| 1458 | */ |
| 1459 | public final long getEventTimeNano() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1460 | return nativeGetEventTimeNanos(mNativePtr, HISTORY_CURRENT); |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 1461 | } |
| 1462 | |
| 1463 | /** |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1464 | * {@link #getX(int)} for the first pointer index (may be an |
| 1465 | * arbitrary pointer identifier). |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1466 | * |
| 1467 | * @see #AXIS_X |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1468 | */ |
| 1469 | public final float getX() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1470 | return nativeGetAxisValue(mNativePtr, AXIS_X, 0, HISTORY_CURRENT); |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1471 | } |
| 1472 | |
| 1473 | /** |
| 1474 | * {@link #getY(int)} for the first pointer index (may be an |
| 1475 | * arbitrary pointer identifier). |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1476 | * |
| 1477 | * @see #AXIS_Y |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1478 | */ |
| 1479 | public final float getY() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1480 | return nativeGetAxisValue(mNativePtr, AXIS_Y, 0, HISTORY_CURRENT); |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1481 | } |
| 1482 | |
| 1483 | /** |
| 1484 | * {@link #getPressure(int)} for the first pointer index (may be an |
| 1485 | * arbitrary pointer identifier). |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1486 | * |
| 1487 | * @see #AXIS_PRESSURE |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1488 | */ |
| 1489 | public final float getPressure() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1490 | return nativeGetAxisValue(mNativePtr, AXIS_PRESSURE, 0, HISTORY_CURRENT); |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1491 | } |
| 1492 | |
| 1493 | /** |
| 1494 | * {@link #getSize(int)} for the first pointer index (may be an |
| 1495 | * arbitrary pointer identifier). |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1496 | * |
| 1497 | * @see #AXIS_SIZE |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1498 | */ |
| 1499 | public final float getSize() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1500 | return nativeGetAxisValue(mNativePtr, AXIS_SIZE, 0, HISTORY_CURRENT); |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1501 | } |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1502 | |
| 1503 | /** |
| 1504 | * {@link #getTouchMajor(int)} for the first pointer index (may be an |
| 1505 | * arbitrary pointer identifier). |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1506 | * |
| 1507 | * @see #AXIS_TOUCH_MAJOR |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1508 | */ |
| 1509 | public final float getTouchMajor() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1510 | return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MAJOR, 0, HISTORY_CURRENT); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1511 | } |
| 1512 | |
| 1513 | /** |
| 1514 | * {@link #getTouchMinor(int)} for the first pointer index (may be an |
| 1515 | * arbitrary pointer identifier). |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1516 | * |
| 1517 | * @see #AXIS_TOUCH_MINOR |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1518 | */ |
| 1519 | public final float getTouchMinor() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1520 | return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MINOR, 0, HISTORY_CURRENT); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1521 | } |
| 1522 | |
| 1523 | /** |
| 1524 | * {@link #getToolMajor(int)} for the first pointer index (may be an |
| 1525 | * arbitrary pointer identifier). |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1526 | * |
| 1527 | * @see #AXIS_TOOL_MAJOR |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1528 | */ |
| 1529 | public final float getToolMajor() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1530 | return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MAJOR, 0, HISTORY_CURRENT); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1531 | } |
| 1532 | |
| 1533 | /** |
| 1534 | * {@link #getToolMinor(int)} for the first pointer index (may be an |
| 1535 | * arbitrary pointer identifier). |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1536 | * |
| 1537 | * @see #AXIS_TOOL_MINOR |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1538 | */ |
| 1539 | public final float getToolMinor() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1540 | return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MINOR, 0, HISTORY_CURRENT); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1541 | } |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1542 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1543 | /** |
| 1544 | * {@link #getOrientation(int)} for the first pointer index (may be an |
| 1545 | * arbitrary pointer identifier). |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1546 | * |
| 1547 | * @see #AXIS_ORIENTATION |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1548 | */ |
| 1549 | public final float getOrientation() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1550 | return nativeGetAxisValue(mNativePtr, AXIS_ORIENTATION, 0, HISTORY_CURRENT); |
| 1551 | } |
| 1552 | |
| 1553 | /** |
| 1554 | * {@link #getAxisValue(int)} for the first pointer index (may be an |
| 1555 | * arbitrary pointer identifier). |
| 1556 | * |
| 1557 | * @param axis The axis identifier for the axis value to retrieve. |
| 1558 | * |
| 1559 | * @see #AXIS_X |
| 1560 | * @see #AXIS_Y |
| 1561 | */ |
| 1562 | public final float getAxisValue(int axis) { |
| 1563 | return nativeGetAxisValue(mNativePtr, axis, 0, HISTORY_CURRENT); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1564 | } |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1565 | |
| 1566 | /** |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1567 | * The number of pointers of data contained in this event. Always |
| 1568 | * >= 1. |
| 1569 | */ |
| 1570 | public final int getPointerCount() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1571 | return nativeGetPointerCount(mNativePtr); |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1572 | } |
| 1573 | |
| 1574 | /** |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1575 | * Return the pointer identifier associated with a particular pointer |
| 1576 | * data index is this event. The identifier tells you the actual pointer |
| 1577 | * number associated with the data, accounting for individual pointers |
| 1578 | * going up and down since the start of the current gesture. |
| 1579 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 1580 | * (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] | 1581 | */ |
Dianne Hackborn | d41ba66 | 2009-08-05 15:30:56 -0700 | [diff] [blame] | 1582 | public final int getPointerId(int pointerIndex) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1583 | return nativeGetPointerId(mNativePtr, pointerIndex); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1584 | } |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1585 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1586 | /** |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1587 | * Given a pointer identifier, find the index of its data in the event. |
| 1588 | * |
| 1589 | * @param pointerId The identifier of the pointer to be found. |
| 1590 | * @return Returns either the index of the pointer (for use with |
Gilles Debunne | b0d6ba1 | 2010-08-17 20:01:42 -0700 | [diff] [blame] | 1591 | * {@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] | 1592 | * that pointer identifier. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1593 | */ |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1594 | public final int findPointerIndex(int pointerId) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1595 | return nativeFindPointerIndex(mNativePtr, pointerId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1596 | } |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1597 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1598 | /** |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1599 | * Returns the X coordinate of this event for the given pointer |
| 1600 | * <em>index</em> (use {@link #getPointerId(int)} to find the pointer |
| 1601 | * identifier for this index). |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1602 | * Whole numbers are pixels; the |
| 1603 | * 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] | 1604 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 1605 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1606 | * |
| 1607 | * @see #AXIS_X |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1608 | */ |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1609 | public final float getX(int pointerIndex) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1610 | return nativeGetAxisValue(mNativePtr, AXIS_X, pointerIndex, HISTORY_CURRENT); |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1611 | } |
| 1612 | |
| 1613 | /** |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1614 | * Returns the Y coordinate of this event for the given pointer |
| 1615 | * <em>index</em> (use {@link #getPointerId(int)} to find the pointer |
| 1616 | * identifier for this index). |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1617 | * Whole numbers are pixels; the |
| 1618 | * 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] | 1619 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 1620 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1621 | * |
| 1622 | * @see #AXIS_Y |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1623 | */ |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1624 | public final float getY(int pointerIndex) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1625 | return nativeGetAxisValue(mNativePtr, AXIS_Y, pointerIndex, HISTORY_CURRENT); |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1626 | } |
| 1627 | |
| 1628 | /** |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1629 | * Returns the current pressure of this event for the given pointer |
| 1630 | * <em>index</em> (use {@link #getPointerId(int)} to find the pointer |
| 1631 | * identifier for this index). |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1632 | * The pressure generally |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1633 | * ranges from 0 (no pressure at all) to 1 (normal pressure), however |
| 1634 | * 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] | 1635 | * the input device. |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1636 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 1637 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1638 | * |
| 1639 | * @see #AXIS_PRESSURE |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1640 | */ |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1641 | public final float getPressure(int pointerIndex) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1642 | return nativeGetAxisValue(mNativePtr, AXIS_PRESSURE, pointerIndex, HISTORY_CURRENT); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1643 | } |
| 1644 | |
| 1645 | /** |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1646 | * Returns a scaled value of the approximate size for the given pointer |
| 1647 | * <em>index</em> (use {@link #getPointerId(int)} to find the pointer |
| 1648 | * identifier for this index). |
| 1649 | * This represents some approximation of the area of the screen being |
| 1650 | * pressed; the actual value in pixels corresponding to the |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1651 | * touch is normalized with the device specific range of values |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1652 | * 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] | 1653 | * determine fat touch events. |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1654 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 1655 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1656 | * |
| 1657 | * @see #AXIS_SIZE |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1658 | */ |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1659 | public final float getSize(int pointerIndex) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1660 | return nativeGetAxisValue(mNativePtr, AXIS_SIZE, pointerIndex, HISTORY_CURRENT); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1661 | } |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1662 | |
| 1663 | /** |
| 1664 | * Returns the length of the major axis of an ellipse that describes the touch |
| 1665 | * area at the point of contact for the given pointer |
| 1666 | * <em>index</em> (use {@link #getPointerId(int)} to find the pointer |
| 1667 | * identifier for this index). |
| 1668 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 1669 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1670 | * |
| 1671 | * @see #AXIS_TOUCH_MAJOR |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1672 | */ |
| 1673 | public final float getTouchMajor(int pointerIndex) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1674 | return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MAJOR, pointerIndex, HISTORY_CURRENT); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1675 | } |
| 1676 | |
| 1677 | /** |
| 1678 | * Returns the length of the minor axis of an ellipse that describes the touch |
| 1679 | * area at the point of contact for the given pointer |
| 1680 | * <em>index</em> (use {@link #getPointerId(int)} to find the pointer |
| 1681 | * identifier for this index). |
| 1682 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 1683 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1684 | * |
| 1685 | * @see #AXIS_TOUCH_MINOR |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1686 | */ |
| 1687 | public final float getTouchMinor(int pointerIndex) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1688 | return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MINOR, pointerIndex, HISTORY_CURRENT); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1689 | } |
| 1690 | |
| 1691 | /** |
| 1692 | * Returns the length of the major axis of an ellipse that describes the size of |
| 1693 | * the approaching tool for the given pointer |
| 1694 | * <em>index</em> (use {@link #getPointerId(int)} to find the pointer |
| 1695 | * identifier for this index). |
| 1696 | * The tool area represents the estimated size of the finger or pen that is |
| 1697 | * touching the device independent of its actual touch area at the point of contact. |
| 1698 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 1699 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1700 | * |
| 1701 | * @see #AXIS_TOOL_MAJOR |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1702 | */ |
| 1703 | public final float getToolMajor(int pointerIndex) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1704 | return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MAJOR, pointerIndex, HISTORY_CURRENT); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1705 | } |
| 1706 | |
| 1707 | /** |
| 1708 | * Returns the length of the minor axis of an ellipse that describes the size of |
| 1709 | * the approaching tool for the given pointer |
| 1710 | * <em>index</em> (use {@link #getPointerId(int)} to find the pointer |
| 1711 | * identifier for this index). |
| 1712 | * The tool area represents the estimated size of the finger or pen that is |
| 1713 | * touching the device independent of its actual touch area at the point of contact. |
| 1714 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 1715 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1716 | * |
| 1717 | * @see #AXIS_TOOL_MINOR |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1718 | */ |
| 1719 | public final float getToolMinor(int pointerIndex) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1720 | return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MINOR, pointerIndex, HISTORY_CURRENT); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1721 | } |
| 1722 | |
| 1723 | /** |
| 1724 | * Returns the orientation of the touch area and tool area in radians clockwise from vertical |
| 1725 | * for the given pointer <em>index</em> (use {@link #getPointerId(int)} to find the pointer |
| 1726 | * identifier for this index). |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 1727 | * An angle of 0 radians indicates that the major axis of contact is oriented |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1728 | * upwards, is perfectly circular or is of unknown orientation. A positive angle |
| 1729 | * indicates that the major axis of contact is oriented to the right. A negative angle |
| 1730 | * indicates that the major axis of contact is oriented to the left. |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1731 | * 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] | 1732 | * (finger pointing fully right). |
| 1733 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 1734 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1735 | * |
| 1736 | * @see #AXIS_ORIENTATION |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1737 | */ |
| 1738 | public final float getOrientation(int pointerIndex) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1739 | return nativeGetAxisValue(mNativePtr, AXIS_ORIENTATION, pointerIndex, HISTORY_CURRENT); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1740 | } |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1741 | |
| 1742 | /** |
| 1743 | * Returns the value of the requested axis for the given pointer <em>index</em> |
| 1744 | * (use {@link #getPointerId(int)} to find the pointer identifier for this index). |
| 1745 | * |
| 1746 | * @param axis The axis identifier for the axis value to retrieve. |
| 1747 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 1748 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
| 1749 | * @return The value of the axis, or 0 if the axis is not available. |
| 1750 | * |
| 1751 | * @see #AXIS_X |
| 1752 | * @see #AXIS_Y |
| 1753 | */ |
| 1754 | public final float getAxisValue(int axis, int pointerIndex) { |
| 1755 | return nativeGetAxisValue(mNativePtr, axis, pointerIndex, HISTORY_CURRENT); |
| 1756 | } |
| 1757 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1758 | /** |
| 1759 | * Populates a {@link PointerCoords} object with pointer coordinate data for |
| 1760 | * the specified pointer index. |
| 1761 | * |
| 1762 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 1763 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
| 1764 | * @param outPointerCoords The pointer coordinate object to populate. |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1765 | * |
| 1766 | * @see PointerCoords |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1767 | */ |
| 1768 | public final void getPointerCoords(int pointerIndex, PointerCoords outPointerCoords) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1769 | nativeGetPointerCoords(mNativePtr, pointerIndex, HISTORY_CURRENT, outPointerCoords); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1770 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1771 | |
| 1772 | /** |
| 1773 | * Returns the state of any meta / modifier keys that were in effect when |
| 1774 | * the event was generated. This is the same values as those |
| 1775 | * returned by {@link KeyEvent#getMetaState() KeyEvent.getMetaState}. |
| 1776 | * |
| 1777 | * @return an integer in which each bit set to 1 represents a pressed |
| 1778 | * meta key |
| 1779 | * |
| 1780 | * @see KeyEvent#getMetaState() |
| 1781 | */ |
| 1782 | public final int getMetaState() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1783 | return nativeGetMetaState(mNativePtr); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1784 | } |
| 1785 | |
| 1786 | /** |
| 1787 | * Returns the original raw X coordinate of this event. For touch |
| 1788 | * events on the screen, this is the original location of the event |
| 1789 | * on the screen, before it had been adjusted for the containing window |
| 1790 | * and views. |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1791 | * |
| 1792 | * @see getX() |
| 1793 | * @see #AXIS_X |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1794 | */ |
| 1795 | public final float getRawX() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1796 | return nativeGetRawAxisValue(mNativePtr, AXIS_X, 0, HISTORY_CURRENT); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1797 | } |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1798 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1799 | /** |
| 1800 | * Returns the original raw Y coordinate of this event. For touch |
| 1801 | * events on the screen, this is the original location of the event |
| 1802 | * on the screen, before it had been adjusted for the containing window |
| 1803 | * and views. |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1804 | * |
| 1805 | * @see getY() |
| 1806 | * @see #AXIS_Y |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1807 | */ |
| 1808 | public final float getRawY() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1809 | return nativeGetRawAxisValue(mNativePtr, AXIS_Y, 0, HISTORY_CURRENT); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1810 | } |
| 1811 | |
| 1812 | /** |
| 1813 | * Return the precision of the X coordinates being reported. You can |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1814 | * 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] | 1815 | * value of the X coordinate. |
| 1816 | * @return Returns the precision of X coordinates being reported. |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1817 | * |
| 1818 | * @see #AXIS_X |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1819 | */ |
| 1820 | public final float getXPrecision() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1821 | return nativeGetXPrecision(mNativePtr); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1822 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1823 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1824 | /** |
| 1825 | * Return the precision of the Y coordinates being reported. You can |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1826 | * 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] | 1827 | * value of the Y coordinate. |
| 1828 | * @return Returns the precision of Y coordinates being reported. |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1829 | * |
| 1830 | * @see #AXIS_Y |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1831 | */ |
| 1832 | public final float getYPrecision() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1833 | return nativeGetYPrecision(mNativePtr); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1834 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1835 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1836 | /** |
| 1837 | * Returns the number of historical points in this event. These are |
| 1838 | * movements that have occurred between this event and the previous event. |
| 1839 | * This only applies to ACTION_MOVE events -- all other actions will have |
| 1840 | * a size of 0. |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1841 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1842 | * @return Returns the number of historical points in the event. |
| 1843 | */ |
| 1844 | public final int getHistorySize() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1845 | return nativeGetHistorySize(mNativePtr); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1846 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1847 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1848 | /** |
| 1849 | * Returns the time that a historical movement occurred between this event |
| 1850 | * and the previous event. Only applies to ACTION_MOVE events. |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1851 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1852 | * @param pos Which historical value to return; must be less than |
| 1853 | * {@link #getHistorySize} |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1854 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1855 | * @see #getHistorySize |
| 1856 | * @see #getEventTime |
| 1857 | */ |
| 1858 | public final long getHistoricalEventTime(int pos) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1859 | return nativeGetEventTimeNanos(mNativePtr, pos) / NS_PER_MS; |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1860 | } |
| 1861 | |
| 1862 | /** |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1863 | * {@link #getHistoricalX(int, int)} for the first pointer index (may be an |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1864 | * arbitrary pointer identifier). |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1865 | * |
| 1866 | * @param pos Which historical value to return; must be less than |
| 1867 | * {@link #getHistorySize} |
| 1868 | * |
| 1869 | * @see #getHistorySize |
| 1870 | * @see #getX() |
| 1871 | * @see #AXIS_X |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1872 | */ |
| 1873 | public final float getHistoricalX(int pos) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1874 | return nativeGetAxisValue(mNativePtr, AXIS_X, 0, pos); |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1875 | } |
| 1876 | |
| 1877 | /** |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1878 | * {@link #getHistoricalY(int, int)} for the first pointer index (may be an |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1879 | * arbitrary pointer identifier). |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1880 | * |
| 1881 | * @param pos Which historical value to return; must be less than |
| 1882 | * {@link #getHistorySize} |
| 1883 | * |
| 1884 | * @see #getHistorySize |
| 1885 | * @see #getY() |
| 1886 | * @see #AXIS_Y |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1887 | */ |
| 1888 | public final float getHistoricalY(int pos) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1889 | return nativeGetAxisValue(mNativePtr, AXIS_Y, 0, pos); |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1890 | } |
| 1891 | |
| 1892 | /** |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1893 | * {@link #getHistoricalPressure(int, int)} for the first pointer index (may be an |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1894 | * arbitrary pointer identifier). |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1895 | * |
| 1896 | * @param pos Which historical value to return; must be less than |
| 1897 | * {@link #getHistorySize} |
| 1898 | * |
| 1899 | * @see #getHistorySize |
| 1900 | * @see #getPressure() |
| 1901 | * @see #AXIS_PRESSURE |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1902 | */ |
| 1903 | public final float getHistoricalPressure(int pos) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1904 | return nativeGetAxisValue(mNativePtr, AXIS_PRESSURE, 0, pos); |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1905 | } |
| 1906 | |
| 1907 | /** |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1908 | * {@link #getHistoricalSize(int, int)} for the first pointer index (may be an |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1909 | * arbitrary pointer identifier). |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1910 | * |
| 1911 | * @param pos Which historical value to return; must be less than |
| 1912 | * {@link #getHistorySize} |
| 1913 | * |
| 1914 | * @see #getHistorySize |
| 1915 | * @see #getSize() |
| 1916 | * @see #AXIS_SIZE |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1917 | */ |
| 1918 | public final float getHistoricalSize(int pos) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1919 | return nativeGetAxisValue(mNativePtr, AXIS_SIZE, 0, pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1920 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1921 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1922 | /** |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1923 | * {@link #getHistoricalTouchMajor(int, int)} for the first pointer index (may be an |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1924 | * arbitrary pointer identifier). |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1925 | * |
| 1926 | * @param pos Which historical value to return; must be less than |
| 1927 | * {@link #getHistorySize} |
| 1928 | * |
| 1929 | * @see #getHistorySize |
| 1930 | * @see #getTouchMajor() |
| 1931 | * @see #AXIS_TOUCH_MAJOR |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1932 | */ |
| 1933 | public final float getHistoricalTouchMajor(int pos) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1934 | return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MAJOR, 0, pos); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1935 | } |
| 1936 | |
| 1937 | /** |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1938 | * {@link #getHistoricalTouchMinor(int, int)} for the first pointer index (may be an |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1939 | * arbitrary pointer identifier). |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1940 | * |
| 1941 | * @param pos Which historical value to return; must be less than |
| 1942 | * {@link #getHistorySize} |
| 1943 | * |
| 1944 | * @see #getHistorySize |
| 1945 | * @see #getTouchMinor() |
| 1946 | * @see #AXIS_TOUCH_MINOR |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1947 | */ |
| 1948 | public final float getHistoricalTouchMinor(int pos) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1949 | return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MINOR, 0, pos); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1950 | } |
| 1951 | |
| 1952 | /** |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1953 | * {@link #getHistoricalToolMajor(int, int)} for the first pointer index (may be an |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1954 | * arbitrary pointer identifier). |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1955 | * |
| 1956 | * @param pos Which historical value to return; must be less than |
| 1957 | * {@link #getHistorySize} |
| 1958 | * |
| 1959 | * @see #getHistorySize |
| 1960 | * @see #getToolMajor() |
| 1961 | * @see #AXIS_TOOL_MAJOR |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1962 | */ |
| 1963 | public final float getHistoricalToolMajor(int pos) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1964 | return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MAJOR, 0, pos); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1965 | } |
| 1966 | |
| 1967 | /** |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1968 | * {@link #getHistoricalToolMinor(int, int)} for the first pointer index (may be an |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1969 | * arbitrary pointer identifier). |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1970 | * |
| 1971 | * @param pos Which historical value to return; must be less than |
| 1972 | * {@link #getHistorySize} |
| 1973 | * |
| 1974 | * @see #getHistorySize |
| 1975 | * @see #getToolMinor() |
| 1976 | * @see #AXIS_TOOL_MINOR |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1977 | */ |
| 1978 | public final float getHistoricalToolMinor(int pos) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1979 | return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MINOR, 0, pos); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1980 | } |
| 1981 | |
| 1982 | /** |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1983 | * {@link #getHistoricalOrientation(int, int)} for the first pointer index (may be an |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1984 | * arbitrary pointer identifier). |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1985 | * |
| 1986 | * @param pos Which historical value to return; must be less than |
| 1987 | * {@link #getHistorySize} |
| 1988 | * |
| 1989 | * @see #getHistorySize |
| 1990 | * @see #getOrientation() |
| 1991 | * @see #AXIS_ORIENTATION |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1992 | */ |
| 1993 | public final float getHistoricalOrientation(int pos) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1994 | return nativeGetAxisValue(mNativePtr, AXIS_ORIENTATION, 0, pos); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1995 | } |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1996 | |
| 1997 | /** |
| 1998 | * {@link #getHistoricalAxisValue(int, int, int)} for the first pointer index (may be an |
| 1999 | * arbitrary pointer identifier). |
| 2000 | * |
| 2001 | * @param axis The axis identifier for the axis value to retrieve. |
| 2002 | * @param pos Which historical value to return; must be less than |
| 2003 | * {@link #getHistorySize} |
| 2004 | * |
| 2005 | * @see #getHistorySize |
| 2006 | * @see #getAxisValue(int) |
| 2007 | * @see #AXIS_X |
| 2008 | * @see #AXIS_Y |
| 2009 | */ |
| 2010 | public final float getHistoricalAxisValue(int axis, int pos) { |
| 2011 | return nativeGetAxisValue(mNativePtr, axis, 0, pos); |
| 2012 | } |
| 2013 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2014 | /** |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 2015 | * Returns a historical X coordinate, as per {@link #getX(int)}, that |
| 2016 | * occurred between this event and the previous event for the given pointer. |
| 2017 | * Only applies to ACTION_MOVE events. |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 2018 | * |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 2019 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 2020 | * (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] | 2021 | * @param pos Which historical value to return; must be less than |
| 2022 | * {@link #getHistorySize} |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 2023 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2024 | * @see #getHistorySize |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2025 | * @see #getX(int) |
| 2026 | * @see #AXIS_X |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2027 | */ |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 2028 | public final float getHistoricalX(int pointerIndex, int pos) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2029 | return nativeGetAxisValue(mNativePtr, AXIS_X, pointerIndex, pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2030 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 2031 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2032 | /** |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 2033 | * Returns a historical Y coordinate, as per {@link #getY(int)}, that |
| 2034 | * occurred between this event and the previous event for the given pointer. |
| 2035 | * Only applies to ACTION_MOVE events. |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 2036 | * |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 2037 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 2038 | * (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] | 2039 | * @param pos Which historical value to return; must be less than |
| 2040 | * {@link #getHistorySize} |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 2041 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2042 | * @see #getHistorySize |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2043 | * @see #getY(int) |
| 2044 | * @see #AXIS_Y |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2045 | */ |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 2046 | public final float getHistoricalY(int pointerIndex, int pos) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2047 | return nativeGetAxisValue(mNativePtr, AXIS_Y, pointerIndex, pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2048 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 2049 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2050 | /** |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 2051 | * Returns a historical pressure coordinate, as per {@link #getPressure(int)}, |
| 2052 | * that occurred between this event and the previous event for the given |
| 2053 | * pointer. Only applies to ACTION_MOVE events. |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 2054 | * |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 2055 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 2056 | * (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] | 2057 | * @param pos Which historical value to return; must be less than |
| 2058 | * {@link #getHistorySize} |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 2059 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2060 | * @see #getHistorySize |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2061 | * @see #getPressure(int) |
| 2062 | * @see #AXIS_PRESSURE |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2063 | */ |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 2064 | public final float getHistoricalPressure(int pointerIndex, int pos) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2065 | return nativeGetAxisValue(mNativePtr, AXIS_PRESSURE, pointerIndex, pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2066 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 2067 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2068 | /** |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 2069 | * Returns a historical size coordinate, as per {@link #getSize(int)}, that |
| 2070 | * occurred between this event and the previous event for the given pointer. |
| 2071 | * Only applies to ACTION_MOVE events. |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 2072 | * |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 2073 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 2074 | * (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] | 2075 | * @param pos Which historical value to return; must be less than |
| 2076 | * {@link #getHistorySize} |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 2077 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2078 | * @see #getHistorySize |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2079 | * @see #getSize(int) |
| 2080 | * @see #AXIS_SIZE |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2081 | */ |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 2082 | public final float getHistoricalSize(int pointerIndex, int pos) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2083 | return nativeGetAxisValue(mNativePtr, AXIS_SIZE, pointerIndex, pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2084 | } |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2085 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2086 | /** |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2087 | * Returns a historical touch major axis coordinate, as per {@link #getTouchMajor(int)}, that |
| 2088 | * occurred between this event and the previous event for the given pointer. |
| 2089 | * Only applies to ACTION_MOVE events. |
| 2090 | * |
| 2091 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 2092 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
| 2093 | * @param pos Which historical value to return; must be less than |
| 2094 | * {@link #getHistorySize} |
| 2095 | * |
| 2096 | * @see #getHistorySize |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2097 | * @see #getTouchMajor(int) |
| 2098 | * @see #AXIS_TOUCH_MAJOR |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2099 | */ |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2100 | public final float getHistoricalTouchMajor(int pointerIndex, int pos) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2101 | return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MAJOR, pointerIndex, pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2102 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 2103 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2104 | /** |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2105 | * Returns a historical touch minor axis coordinate, as per {@link #getTouchMinor(int)}, that |
| 2106 | * occurred between this event and the previous event for the given pointer. |
| 2107 | * Only applies to ACTION_MOVE events. |
| 2108 | * |
| 2109 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 2110 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
| 2111 | * @param pos Which historical value to return; must be less than |
| 2112 | * {@link #getHistorySize} |
| 2113 | * |
| 2114 | * @see #getHistorySize |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2115 | * @see #getTouchMinor(int) |
| 2116 | * @see #AXIS_TOUCH_MINOR |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2117 | */ |
| 2118 | public final float getHistoricalTouchMinor(int pointerIndex, int pos) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2119 | return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MINOR, pointerIndex, pos); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2120 | } |
| 2121 | |
| 2122 | /** |
| 2123 | * Returns a historical tool major axis coordinate, as per {@link #getToolMajor(int)}, that |
| 2124 | * occurred between this event and the previous event for the given pointer. |
| 2125 | * Only applies to ACTION_MOVE events. |
| 2126 | * |
| 2127 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 2128 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
| 2129 | * @param pos Which historical value to return; must be less than |
| 2130 | * {@link #getHistorySize} |
| 2131 | * |
| 2132 | * @see #getHistorySize |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2133 | * @see #getToolMajor(int) |
| 2134 | * @see #AXIS_TOOL_MAJOR |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2135 | */ |
| 2136 | public final float getHistoricalToolMajor(int pointerIndex, int pos) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2137 | return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MAJOR, pointerIndex, pos); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2138 | } |
| 2139 | |
| 2140 | /** |
| 2141 | * Returns a historical tool minor axis coordinate, as per {@link #getToolMinor(int)}, that |
| 2142 | * occurred between this event and the previous event for the given pointer. |
| 2143 | * Only applies to ACTION_MOVE events. |
| 2144 | * |
| 2145 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 2146 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
| 2147 | * @param pos Which historical value to return; must be less than |
| 2148 | * {@link #getHistorySize} |
| 2149 | * |
| 2150 | * @see #getHistorySize |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2151 | * @see #getToolMinor(int) |
| 2152 | * @see #AXIS_TOOL_MINOR |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2153 | */ |
| 2154 | public final float getHistoricalToolMinor(int pointerIndex, int pos) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2155 | return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MINOR, pointerIndex, pos); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2156 | } |
| 2157 | |
| 2158 | /** |
| 2159 | * Returns a historical orientation coordinate, as per {@link #getOrientation(int)}, that |
| 2160 | * occurred between this event and the previous event for the given pointer. |
| 2161 | * Only applies to ACTION_MOVE events. |
| 2162 | * |
| 2163 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 2164 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
| 2165 | * @param pos Which historical value to return; must be less than |
| 2166 | * {@link #getHistorySize} |
| 2167 | * |
| 2168 | * @see #getHistorySize |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2169 | * @see #getOrientation(int) |
| 2170 | * @see #AXIS_ORIENTATION |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2171 | */ |
| 2172 | public final float getHistoricalOrientation(int pointerIndex, int pos) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2173 | return nativeGetAxisValue(mNativePtr, AXIS_ORIENTATION, pointerIndex, pos); |
| 2174 | } |
| 2175 | |
| 2176 | /** |
| 2177 | * Returns the historical value of the requested axis, as per {@link #getAxisValue(int, int)}, |
| 2178 | * occurred between this event and the previous event for the given pointer. |
| 2179 | * Only applies to ACTION_MOVE events. |
| 2180 | * |
| 2181 | * @param axis The axis identifier for the axis value to retrieve. |
| 2182 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 2183 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
| 2184 | * @param pos Which historical value to return; must be less than |
| 2185 | * {@link #getHistorySize} |
| 2186 | * @return The value of the axis, or 0 if the axis is not available. |
| 2187 | * |
| 2188 | * @see #AXIS_X |
| 2189 | * @see #AXIS_Y |
| 2190 | */ |
| 2191 | public final float getHistoricalAxisValue(int axis, int pointerIndex, int pos) { |
| 2192 | return nativeGetAxisValue(mNativePtr, axis, pointerIndex, pos); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2193 | } |
| 2194 | |
| 2195 | /** |
| 2196 | * Populates a {@link PointerCoords} object with historical pointer coordinate data, |
| 2197 | * as per {@link #getPointerCoords}, that occurred between this event and the previous |
| 2198 | * event for the given pointer. |
| 2199 | * Only applies to ACTION_MOVE events. |
| 2200 | * |
| 2201 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 2202 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
| 2203 | * @param pos Which historical value to return; must be less than |
| 2204 | * {@link #getHistorySize} |
| 2205 | * @param outPointerCoords The pointer coordinate object to populate. |
| 2206 | * |
| 2207 | * @see #getHistorySize |
| 2208 | * @see #getPointerCoords |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2209 | * @see PointerCoords |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2210 | */ |
| 2211 | public final void getHistoricalPointerCoords(int pointerIndex, int pos, |
| 2212 | PointerCoords outPointerCoords) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2213 | nativeGetPointerCoords(mNativePtr, pointerIndex, pos, outPointerCoords); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2214 | } |
| 2215 | |
| 2216 | /** |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2217 | * Returns a bitfield indicating which edges, if any, were touched by this |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 2218 | * MotionEvent. For touch events, clients can use this to determine if the |
| 2219 | * user's finger was touching the edge of the display. |
| 2220 | * |
Jeff Brown | d41cff2 | 2011-03-03 02:09:54 -0800 | [diff] [blame] | 2221 | * This property is only set for {@link #ACTION_DOWN} events. |
| 2222 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2223 | * @see #EDGE_LEFT |
| 2224 | * @see #EDGE_TOP |
| 2225 | * @see #EDGE_RIGHT |
| 2226 | * @see #EDGE_BOTTOM |
| 2227 | */ |
| 2228 | public final int getEdgeFlags() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2229 | return nativeGetEdgeFlags(mNativePtr); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2230 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 2231 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2232 | /** |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 2233 | * Sets the bitfield indicating which edges, if any, were touched by this |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 2234 | * MotionEvent. |
| 2235 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2236 | * @see #getEdgeFlags() |
| 2237 | */ |
| 2238 | public final void setEdgeFlags(int flags) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2239 | nativeSetEdgeFlags(mNativePtr, flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2240 | } |
| 2241 | |
| 2242 | /** |
| 2243 | * Sets this event's action. |
| 2244 | */ |
| 2245 | public final void setAction(int action) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2246 | nativeSetAction(mNativePtr, action); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2247 | } |
| 2248 | |
| 2249 | /** |
| 2250 | * Adjust this event's location. |
| 2251 | * @param deltaX Amount to add to the current X coordinate of the event. |
| 2252 | * @param deltaY Amount to add to the current Y coordinate of the event. |
| 2253 | */ |
| 2254 | public final void offsetLocation(float deltaX, float deltaY) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2255 | nativeOffsetLocation(mNativePtr, deltaX, deltaY); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2256 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 2257 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2258 | /** |
| 2259 | * Set this event's location. Applies {@link #offsetLocation} with a |
| 2260 | * delta from the current location to the given new location. |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 2261 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2262 | * @param x New absolute X location. |
| 2263 | * @param y New absolute Y location. |
| 2264 | */ |
| 2265 | public final void setLocation(float x, float y) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2266 | float oldX = getX(); |
| 2267 | float oldY = getY(); |
| 2268 | nativeOffsetLocation(mNativePtr, x - oldX, y - oldY); |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 2269 | } |
| 2270 | |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 2271 | /** |
| 2272 | * Applies a transformation matrix to all of the points in the event. |
| 2273 | * |
| 2274 | * @param matrix The transformation matrix to apply. |
| 2275 | */ |
| 2276 | public final void transform(Matrix matrix) { |
| 2277 | if (matrix == null) { |
| 2278 | throw new IllegalArgumentException("matrix must not be null"); |
| 2279 | } |
| 2280 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2281 | nativeTransform(mNativePtr, matrix); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2282 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 2283 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2284 | /** |
| 2285 | * 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] | 2286 | * current location, position and size is updated to the new values. |
| 2287 | * 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] | 2288 | * |
Jeff Brown | cc0c159 | 2011-02-19 05:07:28 -0800 | [diff] [blame] | 2289 | * Only applies to {@link #ACTION_MOVE} or {@link #ACTION_HOVER_MOVE} events. |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 2290 | * |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2291 | * @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] | 2292 | * @param x The new X position. |
| 2293 | * @param y The new Y position. |
| 2294 | * @param pressure The new pressure. |
| 2295 | * @param size The new size. |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 2296 | * @param metaState Meta key state. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2297 | */ |
| 2298 | public final void addBatch(long eventTime, float x, float y, |
| 2299 | float pressure, float size, int metaState) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2300 | synchronized (gTmpPointerCoords) { |
| 2301 | final PointerCoords pc = gTmpPointerCoords[0]; |
| 2302 | pc.clear(); |
| 2303 | pc.x = x; |
| 2304 | pc.y = y; |
| 2305 | pc.pressure = pressure; |
| 2306 | pc.size = size; |
| 2307 | nativeAddBatch(mNativePtr, eventTime * NS_PER_MS, gTmpPointerCoords, metaState); |
| 2308 | } |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 2309 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 2310 | |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 2311 | /** |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2312 | * Add a new movement to the batch of movements in this event. The event's |
| 2313 | * current location, position and size is updated to the new values. |
| 2314 | * 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] | 2315 | * |
Jeff Brown | cc0c159 | 2011-02-19 05:07:28 -0800 | [diff] [blame] | 2316 | * Only applies to {@link #ACTION_MOVE} or {@link #ACTION_HOVER_MOVE} events. |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2317 | * |
| 2318 | * @param eventTime The time stamp (in ms) for this data. |
| 2319 | * @param pointerCoords The new pointer coordinates. |
| 2320 | * @param metaState Meta key state. |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 2321 | */ |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2322 | public final void addBatch(long eventTime, PointerCoords[] pointerCoords, int metaState) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2323 | nativeAddBatch(mNativePtr, eventTime * NS_PER_MS, pointerCoords, metaState); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2324 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 2325 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2326 | @Override |
| 2327 | public String toString() { |
| 2328 | return "MotionEvent{" + Integer.toHexString(System.identityHashCode(this)) |
Huahui Wu | e838a42 | 2011-01-13 16:03:43 -0800 | [diff] [blame] | 2329 | + " pointerId=" + getPointerId(0) |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2330 | + " action=" + actionToString(getAction()) |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2331 | + " x=" + getX() |
| 2332 | + " y=" + getY() |
| 2333 | + " pressure=" + getPressure() |
| 2334 | + " size=" + getSize() |
| 2335 | + " touchMajor=" + getTouchMajor() |
| 2336 | + " touchMinor=" + getTouchMinor() |
| 2337 | + " toolMajor=" + getToolMajor() |
| 2338 | + " toolMinor=" + getToolMinor() |
| 2339 | + " orientation=" + getOrientation() |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2340 | + " meta=" + KeyEvent.metaStateToString(getMetaState()) |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2341 | + " pointerCount=" + getPointerCount() |
| 2342 | + " historySize=" + getHistorySize() |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2343 | + " flags=0x" + Integer.toHexString(getFlags()) |
| 2344 | + " edgeFlags=0x" + Integer.toHexString(getEdgeFlags()) |
| 2345 | + " device=" + getDeviceId() |
| 2346 | + " source=0x" + Integer.toHexString(getSource()) |
Huahui Wu | e838a42 | 2011-01-13 16:03:43 -0800 | [diff] [blame] | 2347 | + (getPointerCount() > 1 ? |
Huahui Wu | f932469 | 2011-01-24 12:07:37 -0800 | [diff] [blame] | 2348 | " pointerId2=" + getPointerId(1) + " x2=" + getX(1) + " y2=" + getY(1) : "") |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2349 | + "}"; |
| 2350 | } |
| 2351 | |
| 2352 | /** |
| 2353 | * Returns a string that represents the symbolic name of the specified action |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2354 | * such as "ACTION_DOWN", "ACTION_POINTER_DOWN(3)" or an equivalent numeric constant |
| 2355 | * such as "35" if unknown. |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2356 | * |
| 2357 | * @param action The action. |
| 2358 | * @return The symbolic name of the specified action. |
| 2359 | * @hide |
| 2360 | */ |
| 2361 | public static String actionToString(int action) { |
| 2362 | switch (action) { |
| 2363 | case ACTION_DOWN: |
| 2364 | return "ACTION_DOWN"; |
| 2365 | case ACTION_UP: |
| 2366 | return "ACTION_UP"; |
| 2367 | case ACTION_CANCEL: |
| 2368 | return "ACTION_CANCEL"; |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 2369 | case ACTION_OUTSIDE: |
| 2370 | return "ACTION_OUTSIDE"; |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2371 | case ACTION_MOVE: |
| 2372 | return "ACTION_MOVE"; |
Jeff Brown | cc0c159 | 2011-02-19 05:07:28 -0800 | [diff] [blame] | 2373 | case ACTION_HOVER_MOVE: |
| 2374 | return "ACTION_HOVER_MOVE"; |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 2375 | case ACTION_SCROLL: |
| 2376 | return "ACTION_SCROLL"; |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 2377 | case ACTION_HOVER_ENTER: |
| 2378 | return "ACTION_HOVER_ENTER"; |
| 2379 | case ACTION_HOVER_EXIT: |
| 2380 | return "ACTION_HOVER_EXIT"; |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2381 | } |
| 2382 | int index = (action & ACTION_POINTER_INDEX_MASK) >> ACTION_POINTER_INDEX_SHIFT; |
| 2383 | switch (action & ACTION_MASK) { |
| 2384 | case ACTION_POINTER_DOWN: |
| 2385 | return "ACTION_POINTER_DOWN(" + index + ")"; |
| 2386 | case ACTION_POINTER_UP: |
| 2387 | return "ACTION_POINTER_UP(" + index + ")"; |
| 2388 | default: |
| 2389 | return Integer.toString(action); |
| 2390 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2391 | } |
| 2392 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2393 | /** |
| 2394 | * Returns a string that represents the symbolic name of the specified axis |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 2395 | * such as "AXIS_X" or an equivalent numeric constant such as "42" if unknown. |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2396 | * |
| 2397 | * @param axis The axis |
| 2398 | * @return The symbolic name of the specified axis. |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2399 | */ |
| 2400 | public static String axisToString(int axis) { |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 2401 | String symbolicName = AXIS_SYMBOLIC_NAMES.get(axis); |
| 2402 | return symbolicName != null ? symbolicName : Integer.toString(axis); |
| 2403 | } |
| 2404 | |
| 2405 | /** |
Jeff Brown | cc0c159 | 2011-02-19 05:07:28 -0800 | [diff] [blame] | 2406 | * Gets an axis by its symbolic name such as "AXIS_X" or an |
| 2407 | * equivalent numeric constant such as "42". |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 2408 | * |
| 2409 | * @param symbolicName The symbolic name of the axis. |
| 2410 | * @return The axis or -1 if not found. |
| 2411 | * @see #keycodeToString |
| 2412 | */ |
| 2413 | public static int axisFromString(String symbolicName) { |
| 2414 | if (symbolicName == null) { |
| 2415 | throw new IllegalArgumentException("symbolicName must not be null"); |
| 2416 | } |
| 2417 | |
| 2418 | final int count = AXIS_SYMBOLIC_NAMES.size(); |
| 2419 | for (int i = 0; i < count; i++) { |
| 2420 | if (symbolicName.equals(AXIS_SYMBOLIC_NAMES.valueAt(i))) { |
| 2421 | return i; |
| 2422 | } |
| 2423 | } |
| 2424 | |
| 2425 | try { |
| 2426 | return Integer.parseInt(symbolicName, 10); |
| 2427 | } catch (NumberFormatException ex) { |
| 2428 | return -1; |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2429 | } |
| 2430 | } |
| 2431 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2432 | public static final Parcelable.Creator<MotionEvent> CREATOR |
| 2433 | = new Parcelable.Creator<MotionEvent>() { |
| 2434 | public MotionEvent createFromParcel(Parcel in) { |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 2435 | in.readInt(); // skip token, we already know this is a MotionEvent |
| 2436 | return MotionEvent.createFromParcelBody(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2437 | } |
| 2438 | |
| 2439 | public MotionEvent[] newArray(int size) { |
| 2440 | return new MotionEvent[size]; |
| 2441 | } |
| 2442 | }; |
| 2443 | |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 2444 | /** @hide */ |
| 2445 | public static MotionEvent createFromParcelBody(Parcel in) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2446 | MotionEvent ev = obtain(); |
| 2447 | ev.mNativePtr = nativeReadFromParcel(ev.mNativePtr, in); |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 2448 | return ev; |
| 2449 | } |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2450 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2451 | public void writeToParcel(Parcel out, int flags) { |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 2452 | out.writeInt(PARCEL_TOKEN_MOTION_EVENT); |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2453 | nativeWriteToParcel(mNativePtr, out); |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 2454 | } |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2455 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2456 | /** |
| 2457 | * Transfer object for pointer coordinates. |
| 2458 | * |
| 2459 | * Objects of this type can be used to manufacture new {@link MotionEvent} objects |
| 2460 | * and to query pointer coordinate information in bulk. |
| 2461 | * |
| 2462 | * Refer to {@link InputDevice} for information about how different kinds of |
| 2463 | * input devices and sources represent pointer coordinates. |
| 2464 | */ |
| 2465 | public static final class PointerCoords { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2466 | private static final int INITIAL_PACKED_AXIS_VALUES = 8; |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 2467 | private long mPackedAxisBits; |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2468 | private float[] mPackedAxisValues; |
| 2469 | |
| 2470 | /** |
| 2471 | * Creates a pointer coords object with all axes initialized to zero. |
| 2472 | */ |
| 2473 | public PointerCoords() { |
| 2474 | } |
| 2475 | |
| 2476 | /** |
| 2477 | * Creates a pointer coords object as a copy of the |
| 2478 | * contents of another pointer coords object. |
| 2479 | * |
| 2480 | * @param other The pointer coords object to copy. |
| 2481 | */ |
| 2482 | public PointerCoords(PointerCoords other) { |
| 2483 | copyFrom(other); |
| 2484 | } |
| 2485 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2486 | /** |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 2487 | * The X component of the pointer movement. |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2488 | * |
| 2489 | * @see MotionEvent#AXIS_X |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2490 | */ |
| 2491 | public float x; |
| 2492 | |
| 2493 | /** |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 2494 | * The Y component of the pointer movement. |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2495 | * |
| 2496 | * @see MotionEvent#AXIS_Y |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2497 | */ |
| 2498 | public float y; |
| 2499 | |
| 2500 | /** |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2501 | * A normalized value that describes the pressure applied to the device |
| 2502 | * by a finger or other tool. |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2503 | * 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] | 2504 | * 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] | 2505 | * the input device. |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2506 | * |
| 2507 | * @see MotionEvent#AXIS_PRESSURE |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2508 | */ |
| 2509 | public float pressure; |
| 2510 | |
| 2511 | /** |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2512 | * A normalized value that describes the approximate size of the pointer touch area |
| 2513 | * in relation to the maximum detectable size of the device. |
| 2514 | * It represents some approximation of the area of the screen being |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2515 | * pressed; the actual value in pixels corresponding to the |
| 2516 | * touch is normalized with the device specific range of values |
| 2517 | * and scaled to a value between 0 and 1. The value of size can be used to |
| 2518 | * determine fat touch events. |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2519 | * |
| 2520 | * @see MotionEvent#AXIS_SIZE |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2521 | */ |
| 2522 | public float size; |
| 2523 | |
| 2524 | /** |
| 2525 | * The length of the major axis of an ellipse that describes the touch area at |
| 2526 | * the point of contact. |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2527 | * If the device is a touch screen, the length is reported in pixels, otherwise it is |
| 2528 | * reported in device-specific units. |
| 2529 | * |
| 2530 | * @see MotionEvent#AXIS_TOUCH_MAJOR |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2531 | */ |
| 2532 | public float touchMajor; |
| 2533 | |
| 2534 | /** |
| 2535 | * The length of the minor axis of an ellipse that describes the touch area at |
| 2536 | * the point of contact. |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2537 | * If the device is a touch screen, the length is reported in pixels, otherwise it is |
| 2538 | * reported in device-specific units. |
| 2539 | * |
| 2540 | * @see MotionEvent#AXIS_TOUCH_MINOR |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2541 | */ |
| 2542 | public float touchMinor; |
| 2543 | |
| 2544 | /** |
| 2545 | * The length of the major axis of an ellipse that describes the size of |
| 2546 | * the approaching tool. |
| 2547 | * The tool area represents the estimated size of the finger or pen that is |
| 2548 | * 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] | 2549 | * If the device is a touch screen, the length is reported in pixels, otherwise it is |
| 2550 | * reported in device-specific units. |
| 2551 | * |
| 2552 | * @see MotionEvent#AXIS_TOOL_MAJOR |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2553 | */ |
| 2554 | public float toolMajor; |
| 2555 | |
| 2556 | /** |
| 2557 | * The length of the minor axis of an ellipse that describes the size of |
| 2558 | * the approaching tool. |
| 2559 | * The tool area represents the estimated size of the finger or pen that is |
| 2560 | * 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] | 2561 | * If the device is a touch screen, the length is reported in pixels, otherwise it is |
| 2562 | * reported in device-specific units. |
| 2563 | * |
| 2564 | * @see MotionEvent#AXIS_TOOL_MINOR |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2565 | */ |
| 2566 | public float toolMinor; |
| 2567 | |
| 2568 | /** |
| 2569 | * The orientation of the touch area and tool area in radians clockwise from vertical. |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 2570 | * An angle of 0 radians indicates that the major axis of contact is oriented |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2571 | * upwards, is perfectly circular or is of unknown orientation. A positive angle |
| 2572 | * indicates that the major axis of contact is oriented to the right. A negative angle |
| 2573 | * indicates that the major axis of contact is oriented to the left. |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 2574 | * 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] | 2575 | * (finger pointing fully right). |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2576 | * |
| 2577 | * @see MotionEvent#AXIS_ORIENTATION |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2578 | */ |
| 2579 | public float orientation; |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2580 | |
| 2581 | /** |
| 2582 | * Clears the contents of this object. |
| 2583 | * Resets all axes to zero. |
| 2584 | */ |
| 2585 | public void clear() { |
| 2586 | mPackedAxisBits = 0; |
| 2587 | |
| 2588 | x = 0; |
| 2589 | y = 0; |
| 2590 | pressure = 0; |
| 2591 | size = 0; |
| 2592 | touchMajor = 0; |
| 2593 | touchMinor = 0; |
| 2594 | toolMajor = 0; |
| 2595 | toolMinor = 0; |
| 2596 | orientation = 0; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2597 | } |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2598 | |
| 2599 | /** |
| 2600 | * Copies the contents of another pointer coords object. |
| 2601 | * |
| 2602 | * @param other The pointer coords object to copy. |
| 2603 | */ |
| 2604 | public void copyFrom(PointerCoords other) { |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 2605 | final long bits = other.mPackedAxisBits; |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2606 | mPackedAxisBits = bits; |
| 2607 | if (bits != 0) { |
| 2608 | final float[] otherValues = other.mPackedAxisValues; |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 2609 | final int count = Long.bitCount(bits); |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2610 | float[] values = mPackedAxisValues; |
| 2611 | if (values == null || count > values.length) { |
| 2612 | values = new float[otherValues.length]; |
| 2613 | mPackedAxisValues = values; |
| 2614 | } |
| 2615 | System.arraycopy(otherValues, 0, values, 0, count); |
| 2616 | } |
| 2617 | |
| 2618 | x = other.x; |
| 2619 | y = other.y; |
| 2620 | pressure = other.pressure; |
| 2621 | size = other.size; |
| 2622 | touchMajor = other.touchMajor; |
| 2623 | touchMinor = other.touchMinor; |
| 2624 | toolMajor = other.toolMajor; |
| 2625 | toolMinor = other.toolMinor; |
| 2626 | orientation = other.orientation; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2627 | } |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2628 | |
| 2629 | /** |
| 2630 | * Gets the value associated with the specified axis. |
| 2631 | * |
| 2632 | * @param axis The axis identifier for the axis value to retrieve. |
| 2633 | * @return The value associated with the axis, or 0 if none. |
| 2634 | * |
| 2635 | * @see MotionEvent#AXIS_X |
| 2636 | * @see MotionEvent#AXIS_Y |
| 2637 | */ |
| 2638 | public float getAxisValue(int axis) { |
| 2639 | switch (axis) { |
| 2640 | case AXIS_X: |
| 2641 | return x; |
| 2642 | case AXIS_Y: |
| 2643 | return y; |
| 2644 | case AXIS_PRESSURE: |
| 2645 | return pressure; |
| 2646 | case AXIS_SIZE: |
| 2647 | return size; |
| 2648 | case AXIS_TOUCH_MAJOR: |
| 2649 | return touchMajor; |
| 2650 | case AXIS_TOUCH_MINOR: |
| 2651 | return touchMinor; |
| 2652 | case AXIS_TOOL_MAJOR: |
| 2653 | return toolMajor; |
| 2654 | case AXIS_TOOL_MINOR: |
| 2655 | return toolMinor; |
| 2656 | case AXIS_ORIENTATION: |
| 2657 | return orientation; |
| 2658 | default: { |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 2659 | if (axis < 0 || axis > 63) { |
| 2660 | throw new IllegalArgumentException("Axis out of range."); |
| 2661 | } |
| 2662 | final long bits = mPackedAxisBits; |
| 2663 | final long axisBit = 1L << axis; |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2664 | if ((bits & axisBit) == 0) { |
| 2665 | return 0; |
| 2666 | } |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 2667 | final int index = Long.bitCount(bits & (axisBit - 1L)); |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2668 | return mPackedAxisValues[index]; |
| 2669 | } |
| 2670 | } |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2671 | } |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2672 | |
| 2673 | /** |
| 2674 | * Sets the value associated with the specified axis. |
| 2675 | * |
| 2676 | * @param axis The axis identifier for the axis value to assign. |
| 2677 | * @param value The value to set. |
| 2678 | * |
| 2679 | * @see MotionEvent#AXIS_X |
| 2680 | * @see MotionEvent#AXIS_Y |
| 2681 | */ |
| 2682 | public void setAxisValue(int axis, float value) { |
| 2683 | switch (axis) { |
| 2684 | case AXIS_X: |
| 2685 | x = value; |
| 2686 | break; |
| 2687 | case AXIS_Y: |
| 2688 | y = value; |
| 2689 | break; |
| 2690 | case AXIS_PRESSURE: |
| 2691 | pressure = value; |
| 2692 | break; |
| 2693 | case AXIS_SIZE: |
| 2694 | size = value; |
| 2695 | break; |
| 2696 | case AXIS_TOUCH_MAJOR: |
| 2697 | touchMajor = value; |
| 2698 | break; |
| 2699 | case AXIS_TOUCH_MINOR: |
| 2700 | touchMinor = value; |
| 2701 | break; |
| 2702 | case AXIS_TOOL_MAJOR: |
| 2703 | toolMajor = value; |
| 2704 | break; |
| 2705 | case AXIS_TOOL_MINOR: |
| 2706 | toolMinor = value; |
| 2707 | break; |
| 2708 | case AXIS_ORIENTATION: |
| 2709 | orientation = value; |
| 2710 | break; |
| 2711 | default: { |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 2712 | if (axis < 0 || axis > 63) { |
| 2713 | throw new IllegalArgumentException("Axis out of range."); |
| 2714 | } |
| 2715 | final long bits = mPackedAxisBits; |
| 2716 | final long axisBit = 1L << axis; |
| 2717 | final int index = Long.bitCount(bits & (axisBit - 1L)); |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2718 | float[] values = mPackedAxisValues; |
| 2719 | if ((bits & axisBit) == 0) { |
| 2720 | if (values == null) { |
| 2721 | values = new float[INITIAL_PACKED_AXIS_VALUES]; |
| 2722 | mPackedAxisValues = values; |
| 2723 | } else { |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 2724 | final int count = Long.bitCount(bits); |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2725 | if (count < values.length) { |
| 2726 | if (index != count) { |
| 2727 | System.arraycopy(values, index, values, index + 1, |
| 2728 | count - index); |
| 2729 | } |
| 2730 | } else { |
| 2731 | float[] newValues = new float[count * 2]; |
| 2732 | System.arraycopy(values, 0, newValues, 0, index); |
| 2733 | System.arraycopy(values, index, newValues, index + 1, |
| 2734 | count - index); |
| 2735 | values = newValues; |
| 2736 | mPackedAxisValues = values; |
| 2737 | } |
| 2738 | } |
| 2739 | mPackedAxisBits = bits | axisBit; |
| 2740 | } |
| 2741 | values[index] = value; |
| 2742 | } |
| 2743 | } |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2744 | } |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2745 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2746 | } |