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