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 | /** |
| 678 | * Constant used to identify the Generic 1 axis of a motion event. |
| 679 | * The interpretation of a generic axis is device-specific. |
| 680 | * |
| 681 | * @see #getAxisValue(int, int) |
| 682 | * @see #getHistoricalAxisValue(int, int, int) |
| 683 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 684 | * @see InputDevice#getMotionRange |
| 685 | */ |
| 686 | public static final int AXIS_GENERIC_1 = 32; |
| 687 | |
| 688 | /** |
| 689 | * Constant used to identify the Generic 2 axis of a motion event. |
| 690 | * The interpretation of a generic axis is device-specific. |
| 691 | * |
| 692 | * @see #getAxisValue(int, int) |
| 693 | * @see #getHistoricalAxisValue(int, int, int) |
| 694 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 695 | * @see InputDevice#getMotionRange |
| 696 | */ |
| 697 | public static final int AXIS_GENERIC_2 = 33; |
| 698 | |
| 699 | /** |
| 700 | * Constant used to identify the Generic 3 axis of a motion event. |
| 701 | * The interpretation of a generic axis is device-specific. |
| 702 | * |
| 703 | * @see #getAxisValue(int, int) |
| 704 | * @see #getHistoricalAxisValue(int, int, int) |
| 705 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 706 | * @see InputDevice#getMotionRange |
| 707 | */ |
| 708 | public static final int AXIS_GENERIC_3 = 34; |
| 709 | |
| 710 | /** |
| 711 | * Constant used to identify the Generic 4 axis of a motion event. |
| 712 | * The interpretation of a generic axis is device-specific. |
| 713 | * |
| 714 | * @see #getAxisValue(int, int) |
| 715 | * @see #getHistoricalAxisValue(int, int, int) |
| 716 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 717 | * @see InputDevice#getMotionRange |
| 718 | */ |
| 719 | public static final int AXIS_GENERIC_4 = 35; |
| 720 | |
| 721 | /** |
| 722 | * Constant used to identify the Generic 5 axis of a motion event. |
| 723 | * The interpretation of a generic axis is device-specific. |
| 724 | * |
| 725 | * @see #getAxisValue(int, int) |
| 726 | * @see #getHistoricalAxisValue(int, int, int) |
| 727 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 728 | * @see InputDevice#getMotionRange |
| 729 | */ |
| 730 | public static final int AXIS_GENERIC_5 = 36; |
| 731 | |
| 732 | /** |
| 733 | * Constant used to identify the Generic 6 axis of a motion event. |
| 734 | * The interpretation of a generic axis is device-specific. |
| 735 | * |
| 736 | * @see #getAxisValue(int, int) |
| 737 | * @see #getHistoricalAxisValue(int, int, int) |
| 738 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 739 | * @see InputDevice#getMotionRange |
| 740 | */ |
| 741 | public static final int AXIS_GENERIC_6 = 37; |
| 742 | |
| 743 | /** |
| 744 | * Constant used to identify the Generic 7 axis of a motion event. |
| 745 | * The interpretation of a generic axis is device-specific. |
| 746 | * |
| 747 | * @see #getAxisValue(int, int) |
| 748 | * @see #getHistoricalAxisValue(int, int, int) |
| 749 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 750 | * @see InputDevice#getMotionRange |
| 751 | */ |
| 752 | public static final int AXIS_GENERIC_7 = 38; |
| 753 | |
| 754 | /** |
| 755 | * Constant used to identify the Generic 8 axis of a motion event. |
| 756 | * The interpretation of a generic axis is device-specific. |
| 757 | * |
| 758 | * @see #getAxisValue(int, int) |
| 759 | * @see #getHistoricalAxisValue(int, int, int) |
| 760 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 761 | * @see InputDevice#getMotionRange |
| 762 | */ |
| 763 | public static final int AXIS_GENERIC_8 = 39; |
| 764 | |
| 765 | /** |
| 766 | * Constant used to identify the Generic 9 axis of a motion event. |
| 767 | * The interpretation of a generic axis is device-specific. |
| 768 | * |
| 769 | * @see #getAxisValue(int, int) |
| 770 | * @see #getHistoricalAxisValue(int, int, int) |
| 771 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 772 | * @see InputDevice#getMotionRange |
| 773 | */ |
| 774 | public static final int AXIS_GENERIC_9 = 40; |
| 775 | |
| 776 | /** |
| 777 | * Constant used to identify the Generic 10 axis of a motion event. |
| 778 | * The interpretation of a generic axis is device-specific. |
| 779 | * |
| 780 | * @see #getAxisValue(int, int) |
| 781 | * @see #getHistoricalAxisValue(int, int, int) |
| 782 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 783 | * @see InputDevice#getMotionRange |
| 784 | */ |
| 785 | public static final int AXIS_GENERIC_10 = 41; |
| 786 | |
| 787 | /** |
| 788 | * Constant used to identify the Generic 11 axis of a motion event. |
| 789 | * The interpretation of a generic axis is device-specific. |
| 790 | * |
| 791 | * @see #getAxisValue(int, int) |
| 792 | * @see #getHistoricalAxisValue(int, int, int) |
| 793 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 794 | * @see InputDevice#getMotionRange |
| 795 | */ |
| 796 | public static final int AXIS_GENERIC_11 = 42; |
| 797 | |
| 798 | /** |
| 799 | * Constant used to identify the Generic 12 axis of a motion event. |
| 800 | * The interpretation of a generic axis is device-specific. |
| 801 | * |
| 802 | * @see #getAxisValue(int, int) |
| 803 | * @see #getHistoricalAxisValue(int, int, int) |
| 804 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 805 | * @see InputDevice#getMotionRange |
| 806 | */ |
| 807 | public static final int AXIS_GENERIC_12 = 43; |
| 808 | |
| 809 | /** |
| 810 | * Constant used to identify the Generic 13 axis of a motion event. |
| 811 | * The interpretation of a generic axis is device-specific. |
| 812 | * |
| 813 | * @see #getAxisValue(int, int) |
| 814 | * @see #getHistoricalAxisValue(int, int, int) |
| 815 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 816 | * @see InputDevice#getMotionRange |
| 817 | */ |
| 818 | public static final int AXIS_GENERIC_13 = 44; |
| 819 | |
| 820 | /** |
| 821 | * Constant used to identify the Generic 14 axis of a motion event. |
| 822 | * The interpretation of a generic axis is device-specific. |
| 823 | * |
| 824 | * @see #getAxisValue(int, int) |
| 825 | * @see #getHistoricalAxisValue(int, int, int) |
| 826 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 827 | * @see InputDevice#getMotionRange |
| 828 | */ |
| 829 | public static final int AXIS_GENERIC_14 = 45; |
| 830 | |
| 831 | /** |
| 832 | * Constant used to identify the Generic 15 axis of a motion event. |
| 833 | * The interpretation of a generic axis is device-specific. |
| 834 | * |
| 835 | * @see #getAxisValue(int, int) |
| 836 | * @see #getHistoricalAxisValue(int, int, int) |
| 837 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 838 | * @see InputDevice#getMotionRange |
| 839 | */ |
| 840 | public static final int AXIS_GENERIC_15 = 46; |
| 841 | |
| 842 | /** |
| 843 | * Constant used to identify the Generic 16 axis of a motion event. |
| 844 | * The interpretation of a generic axis is device-specific. |
| 845 | * |
| 846 | * @see #getAxisValue(int, int) |
| 847 | * @see #getHistoricalAxisValue(int, int, int) |
| 848 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 849 | * @see InputDevice#getMotionRange |
| 850 | */ |
| 851 | public static final int AXIS_GENERIC_16 = 47; |
| 852 | |
| 853 | // NOTE: If you add a new axis here you must also add it to: |
| 854 | // native/include/android/input.h |
| 855 | // frameworks/base/include/ui/KeycodeLabels.h |
| 856 | |
| 857 | // Symbolic names of all axes. |
| 858 | private static final SparseArray<String> AXIS_SYMBOLIC_NAMES = new SparseArray<String>(); |
| 859 | private static void populateAxisSymbolicNames() { |
| 860 | SparseArray<String> names = AXIS_SYMBOLIC_NAMES; |
| 861 | names.append(AXIS_X, "AXIS_X"); |
| 862 | names.append(AXIS_Y, "AXIS_Y"); |
| 863 | names.append(AXIS_PRESSURE, "AXIS_PRESSURE"); |
| 864 | names.append(AXIS_SIZE, "AXIS_SIZE"); |
| 865 | names.append(AXIS_TOUCH_MAJOR, "AXIS_TOUCH_MAJOR"); |
| 866 | names.append(AXIS_TOUCH_MINOR, "AXIS_TOUCH_MINOR"); |
| 867 | names.append(AXIS_TOOL_MAJOR, "AXIS_TOOL_MAJOR"); |
| 868 | names.append(AXIS_TOOL_MINOR, "AXIS_TOOL_MINOR"); |
| 869 | names.append(AXIS_ORIENTATION, "AXIS_ORIENTATION"); |
| 870 | names.append(AXIS_VSCROLL, "AXIS_VSCROLL"); |
| 871 | names.append(AXIS_HSCROLL, "AXIS_HSCROLL"); |
| 872 | names.append(AXIS_Z, "AXIS_Z"); |
| 873 | names.append(AXIS_RX, "AXIS_RX"); |
| 874 | names.append(AXIS_RY, "AXIS_RY"); |
| 875 | names.append(AXIS_RZ, "AXIS_RZ"); |
| 876 | names.append(AXIS_HAT_X, "AXIS_HAT_X"); |
| 877 | names.append(AXIS_HAT_Y, "AXIS_HAT_Y"); |
| 878 | names.append(AXIS_LTRIGGER, "AXIS_LTRIGGER"); |
| 879 | names.append(AXIS_RTRIGGER, "AXIS_RTRIGGER"); |
| 880 | names.append(AXIS_GENERIC_1, "AXIS_GENERIC_1"); |
| 881 | names.append(AXIS_GENERIC_2, "AXIS_GENERIC_2"); |
| 882 | names.append(AXIS_GENERIC_3, "AXIS_GENERIC_3"); |
| 883 | names.append(AXIS_GENERIC_4, "AXIS_GENERIC_4"); |
| 884 | names.append(AXIS_GENERIC_5, "AXIS_GENERIC_5"); |
| 885 | names.append(AXIS_GENERIC_6, "AXIS_GENERIC_6"); |
| 886 | names.append(AXIS_GENERIC_7, "AXIS_GENERIC_7"); |
| 887 | names.append(AXIS_GENERIC_8, "AXIS_GENERIC_8"); |
| 888 | names.append(AXIS_GENERIC_9, "AXIS_GENERIC_9"); |
| 889 | names.append(AXIS_GENERIC_10, "AXIS_GENERIC_10"); |
| 890 | names.append(AXIS_GENERIC_11, "AXIS_GENERIC_11"); |
| 891 | names.append(AXIS_GENERIC_12, "AXIS_GENERIC_12"); |
| 892 | names.append(AXIS_GENERIC_13, "AXIS_GENERIC_13"); |
| 893 | names.append(AXIS_GENERIC_14, "AXIS_GENERIC_14"); |
| 894 | names.append(AXIS_GENERIC_15, "AXIS_GENERIC_15"); |
| 895 | names.append(AXIS_GENERIC_16, "AXIS_GENERIC_16"); |
| 896 | } |
| 897 | |
| 898 | static { |
| 899 | populateAxisSymbolicNames(); |
| 900 | } |
| 901 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 902 | // Private value for history pos that obtains the current sample. |
| 903 | private static final int HISTORY_CURRENT = -0x80000000; |
| 904 | |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 905 | private static final int MAX_RECYCLED = 10; |
| 906 | private static final Object gRecyclerLock = new Object(); |
| 907 | private static int gRecyclerUsed; |
| 908 | private static MotionEvent gRecyclerTop; |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 909 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 910 | // Shared temporary objects used when translating coordinates supplied by |
| 911 | // the caller into single element PointerCoords and pointer id arrays. |
| 912 | // Must lock gTmpPointerCoords prior to use. |
| 913 | private static final PointerCoords[] gTmpPointerCoords = |
| 914 | new PointerCoords[] { new PointerCoords() }; |
| 915 | private static final int[] gTmpPointerIds = new int[] { 0 /*always 0*/ }; |
| 916 | |
| 917 | // Pointer to the native MotionEvent object that contains the actual data. |
| 918 | private int mNativePtr; |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 919 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 920 | private MotionEvent mNext; |
| 921 | private RuntimeException mRecycledLocation; |
| 922 | private boolean mRecycled; |
| 923 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 924 | private static native int nativeInitialize(int nativePtr, |
| 925 | int deviceId, int source, int action, int flags, int edgeFlags, int metaState, |
| 926 | float xOffset, float yOffset, float xPrecision, float yPrecision, |
| 927 | long downTimeNanos, long eventTimeNanos, |
| 928 | int pointerCount, int[] pointerIds, PointerCoords[] pointerCoords); |
| 929 | private static native int nativeCopy(int destNativePtr, int sourceNativePtr, |
| 930 | boolean keepHistory); |
| 931 | private static native void nativeDispose(int nativePtr); |
| 932 | private static native void nativeAddBatch(int nativePtr, long eventTimeNanos, |
| 933 | PointerCoords[] pointerCoords, int metaState); |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 934 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 935 | private static native int nativeGetDeviceId(int nativePtr); |
| 936 | private static native int nativeGetSource(int nativePtr); |
| 937 | private static native int nativeSetSource(int nativePtr, int source); |
| 938 | private static native int nativeGetAction(int nativePtr); |
| 939 | private static native void nativeSetAction(int nativePtr, int action); |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame^] | 940 | private static native boolean nativeIsTouchEvent(int nativePtr); |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 941 | private static native int nativeGetFlags(int nativePtr); |
| 942 | private static native int nativeGetEdgeFlags(int nativePtr); |
| 943 | private static native void nativeSetEdgeFlags(int nativePtr, int action); |
| 944 | private static native int nativeGetMetaState(int nativePtr); |
| 945 | private static native void nativeOffsetLocation(int nativePtr, float deltaX, float deltaY); |
| 946 | private static native float nativeGetXPrecision(int nativePtr); |
| 947 | private static native float nativeGetYPrecision(int nativePtr); |
| 948 | private static native long nativeGetDownTimeNanos(int nativePtr); |
| 949 | |
| 950 | private static native int nativeGetPointerCount(int nativePtr); |
| 951 | private static native int nativeGetPointerId(int nativePtr, int pointerIndex); |
| 952 | private static native int nativeFindPointerIndex(int nativePtr, int pointerId); |
| 953 | |
| 954 | private static native int nativeGetHistorySize(int nativePtr); |
| 955 | private static native long nativeGetEventTimeNanos(int nativePtr, int historyPos); |
| 956 | private static native float nativeGetRawAxisValue(int nativePtr, |
| 957 | int axis, int pointerIndex, int historyPos); |
| 958 | private static native float nativeGetAxisValue(int nativePtr, |
| 959 | int axis, int pointerIndex, int historyPos); |
| 960 | private static native void nativeGetPointerCoords(int nativePtr, |
| 961 | int pointerIndex, int historyPos, PointerCoords outPointerCoords); |
| 962 | |
| 963 | private static native void nativeScale(int nativePtr, float scale); |
| 964 | private static native void nativeTransform(int nativePtr, Matrix matrix); |
| 965 | |
| 966 | private static native int nativeReadFromParcel(int nativePtr, Parcel parcel); |
| 967 | private static native void nativeWriteToParcel(int nativePtr, Parcel parcel); |
| 968 | |
| 969 | private MotionEvent() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 970 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 971 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 972 | @Override |
| 973 | protected void finalize() throws Throwable { |
| 974 | try { |
| 975 | if (mNativePtr != 0) { |
| 976 | nativeDispose(mNativePtr); |
| 977 | mNativePtr = 0; |
| 978 | } |
| 979 | } finally { |
| 980 | super.finalize(); |
| 981 | } |
| 982 | } |
| 983 | |
| 984 | static private MotionEvent obtain() { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 985 | final MotionEvent ev; |
| 986 | synchronized (gRecyclerLock) { |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 987 | ev = gRecyclerTop; |
| 988 | if (ev == null) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 989 | return new MotionEvent(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 990 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 991 | gRecyclerTop = ev.mNext; |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 992 | gRecyclerUsed -= 1; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 993 | } |
| 994 | ev.mRecycledLocation = null; |
| 995 | ev.mRecycled = false; |
| 996 | ev.mNext = null; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 997 | return ev; |
| 998 | } |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 999 | |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 1000 | /** |
| 1001 | * Create a new MotionEvent, filling in all of the basic values that |
| 1002 | * define the motion. |
| 1003 | * |
| 1004 | * @param downTime The time (in ms) when the user originally pressed down to start |
| 1005 | * 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] | 1006 | * @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] | 1007 | * must be obtained from {@link SystemClock#uptimeMillis()}. |
Jeff Brown | cc0c159 | 2011-02-19 05:07:28 -0800 | [diff] [blame] | 1008 | * @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] | 1009 | * @param pointers The number of points that will be in this event. |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1010 | * @param pointerIds An array of <em>pointers</em> values providing |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1011 | * an identifier for each pointer. |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1012 | * @param pointerCoords An array of <em>pointers</em> values providing |
| 1013 | * a {@link PointerCoords} coordinate object for each pointer. |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 1014 | * @param metaState The state of any meta / modifier keys that were in effect when |
| 1015 | * the event was generated. |
| 1016 | * @param xPrecision The precision of the X coordinate being reported. |
| 1017 | * @param yPrecision The precision of the Y coordinate being reported. |
| 1018 | * @param deviceId The id for the device that this event came from. An id of |
| 1019 | * zero indicates that the event didn't come from a physical device; other |
| 1020 | * numbers are arbitrary and you shouldn't depend on the values. |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 1021 | * @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] | 1022 | * MotionEvent. |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1023 | * @param source The source of this event. |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 1024 | * @param flags The motion event flags. |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 1025 | */ |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1026 | static public MotionEvent obtain(long downTime, long eventTime, |
| 1027 | int action, int pointers, int[] pointerIds, PointerCoords[] pointerCoords, |
| 1028 | int metaState, float xPrecision, float yPrecision, int deviceId, |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 1029 | int edgeFlags, int source, int flags) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1030 | MotionEvent ev = obtain(); |
| 1031 | ev.mNativePtr = nativeInitialize(ev.mNativePtr, |
| 1032 | deviceId, source, action, flags, edgeFlags, metaState, |
| 1033 | 0, 0, xPrecision, yPrecision, |
| 1034 | downTime * NS_PER_MS, eventTime * NS_PER_MS, |
| 1035 | pointers, pointerIds, pointerCoords); |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 1036 | return ev; |
| 1037 | } |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1038 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1039 | /** |
| 1040 | * Create a new MotionEvent, filling in all of the basic values that |
| 1041 | * define the motion. |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1042 | * |
| 1043 | * @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] | 1044 | * 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] | 1045 | * @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] | 1046 | * must be obtained from {@link SystemClock#uptimeMillis()}. |
Jeff Brown | cc0c159 | 2011-02-19 05:07:28 -0800 | [diff] [blame] | 1047 | * @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] | 1048 | * @param x The X coordinate of this event. |
| 1049 | * @param y The Y coordinate of this event. |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1050 | * @param pressure The current pressure of this event. The pressure generally |
| 1051 | * ranges from 0 (no pressure at all) to 1 (normal pressure), however |
| 1052 | * 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] | 1053 | * the input device. |
| 1054 | * @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] | 1055 | * 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] | 1056 | * touch is normalized with a device specific range of values |
| 1057 | * and scaled to a value between 0 and 1. |
| 1058 | * @param metaState The state of any meta / modifier keys that were in effect when |
| 1059 | * the event was generated. |
| 1060 | * @param xPrecision The precision of the X coordinate being reported. |
| 1061 | * @param yPrecision The precision of the Y coordinate being reported. |
| 1062 | * @param deviceId The id for the device that this event came from. An id of |
| 1063 | * zero indicates that the event didn't come from a physical device; other |
| 1064 | * numbers are arbitrary and you shouldn't depend on the values. |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 1065 | * @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] | 1066 | * MotionEvent. |
| 1067 | */ |
| 1068 | static public MotionEvent obtain(long downTime, long eventTime, int action, |
| 1069 | float x, float y, float pressure, float size, int metaState, |
| 1070 | float xPrecision, float yPrecision, int deviceId, int edgeFlags) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1071 | synchronized (gTmpPointerCoords) { |
| 1072 | final PointerCoords pc = gTmpPointerCoords[0]; |
| 1073 | pc.clear(); |
| 1074 | pc.x = x; |
| 1075 | pc.y = y; |
| 1076 | pc.pressure = pressure; |
| 1077 | pc.size = size; |
| 1078 | |
| 1079 | MotionEvent ev = obtain(); |
| 1080 | ev.mNativePtr = nativeInitialize(ev.mNativePtr, |
| 1081 | deviceId, InputDevice.SOURCE_UNKNOWN, action, 0, edgeFlags, metaState, |
| 1082 | 0, 0, xPrecision, yPrecision, |
| 1083 | downTime * NS_PER_MS, eventTime * NS_PER_MS, |
| 1084 | 1, gTmpPointerIds, gTmpPointerCoords); |
| 1085 | return ev; |
| 1086 | } |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1087 | } |
| 1088 | |
| 1089 | /** |
| 1090 | * Create a new MotionEvent, filling in all of the basic values that |
| 1091 | * define the motion. |
| 1092 | * |
| 1093 | * @param downTime The time (in ms) when the user originally pressed down to start |
| 1094 | * a stream of position events. This must be obtained from {@link SystemClock#uptimeMillis()}. |
| 1095 | * @param eventTime The the time (in ms) when this specific event was generated. This |
| 1096 | * must be obtained from {@link SystemClock#uptimeMillis()}. |
Jeff Brown | cc0c159 | 2011-02-19 05:07:28 -0800 | [diff] [blame] | 1097 | * @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] | 1098 | * @param pointers The number of pointers that are active in this event. |
| 1099 | * @param x The X coordinate of this event. |
| 1100 | * @param y The Y coordinate of this event. |
| 1101 | * @param pressure The current pressure of this event. The pressure generally |
| 1102 | * ranges from 0 (no pressure at all) to 1 (normal pressure), however |
| 1103 | * values higher than 1 may be generated depending on the calibration of |
| 1104 | * the input device. |
| 1105 | * @param size A scaled value of the approximate size of the area being pressed when |
| 1106 | * touched with the finger. The actual value in pixels corresponding to the finger |
| 1107 | * touch is normalized with a device specific range of values |
| 1108 | * and scaled to a value between 0 and 1. |
| 1109 | * @param metaState The state of any meta / modifier keys that were in effect when |
| 1110 | * the event was generated. |
| 1111 | * @param xPrecision The precision of the X coordinate being reported. |
| 1112 | * @param yPrecision The precision of the Y coordinate being reported. |
| 1113 | * @param deviceId The id for the device that this event came from. An id of |
| 1114 | * zero indicates that the event didn't come from a physical device; other |
| 1115 | * numbers are arbitrary and you shouldn't depend on the values. |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 1116 | * @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] | 1117 | * MotionEvent. |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1118 | * |
| 1119 | * @deprecated Use {@link #obtain(long, long, int, float, float, float, float, int, float, float, int, int)} |
| 1120 | * instead. |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1121 | */ |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1122 | @Deprecated |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1123 | static public MotionEvent obtain(long downTime, long eventTime, int action, |
| 1124 | int pointers, float x, float y, float pressure, float size, int metaState, |
| 1125 | float xPrecision, float yPrecision, int deviceId, int edgeFlags) { |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1126 | return obtain(downTime, eventTime, action, x, y, pressure, size, |
| 1127 | metaState, xPrecision, yPrecision, deviceId, edgeFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1128 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1129 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1130 | /** |
| 1131 | * Create a new MotionEvent, filling in a subset of the basic motion |
| 1132 | * values. Those not specified here are: device id (always 0), pressure |
| 1133 | * 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] | 1134 | * |
| 1135 | * @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] | 1136 | * 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] | 1137 | * @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] | 1138 | * must be obtained from {@link SystemClock#uptimeMillis()}. |
Jeff Brown | cc0c159 | 2011-02-19 05:07:28 -0800 | [diff] [blame] | 1139 | * @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] | 1140 | * @param x The X coordinate of this event. |
| 1141 | * @param y The Y coordinate of this event. |
| 1142 | * @param metaState The state of any meta / modifier keys that were in effect when |
| 1143 | * the event was generated. |
| 1144 | */ |
| 1145 | static public MotionEvent obtain(long downTime, long eventTime, int action, |
| 1146 | float x, float y, int metaState) { |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1147 | return obtain(downTime, eventTime, action, x, y, 1.0f, 1.0f, |
| 1148 | metaState, 1.0f, 1.0f, 0, 0); |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 1149 | } |
| 1150 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1151 | /** |
| 1152 | * Create a new MotionEvent, copying from an existing one. |
| 1153 | */ |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1154 | static public MotionEvent obtain(MotionEvent other) { |
| 1155 | if (other == null) { |
| 1156 | throw new IllegalArgumentException("other motion event must not be null"); |
| 1157 | } |
| 1158 | |
| 1159 | MotionEvent ev = obtain(); |
| 1160 | ev.mNativePtr = nativeCopy(ev.mNativePtr, other.mNativePtr, true /*keepHistory*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1161 | return ev; |
| 1162 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1163 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1164 | /** |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 1165 | * Create a new MotionEvent, copying from an existing one, but not including |
| 1166 | * any historical point information. |
| 1167 | */ |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1168 | static public MotionEvent obtainNoHistory(MotionEvent other) { |
| 1169 | if (other == null) { |
| 1170 | throw new IllegalArgumentException("other motion event must not be null"); |
| 1171 | } |
| 1172 | |
| 1173 | MotionEvent ev = obtain(); |
| 1174 | ev.mNativePtr = nativeCopy(ev.mNativePtr, other.mNativePtr, false /*keepHistory*/); |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 1175 | return ev; |
| 1176 | } |
| 1177 | |
| 1178 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1179 | * Recycle the MotionEvent, to be re-used by a later caller. After calling |
| 1180 | * this function you must not ever touch the event again. |
| 1181 | */ |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1182 | public final void recycle() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1183 | // Ensure recycle is only called once! |
| 1184 | if (TRACK_RECYCLED_LOCATION) { |
| 1185 | if (mRecycledLocation != null) { |
| 1186 | throw new RuntimeException(toString() + " recycled twice!", mRecycledLocation); |
| 1187 | } |
| 1188 | mRecycledLocation = new RuntimeException("Last recycled here"); |
Jeff Brown | d28f4be | 2010-06-02 15:35:46 -0700 | [diff] [blame] | 1189 | //Log.w("MotionEvent", "Recycling event " + this, mRecycledLocation); |
| 1190 | } else { |
| 1191 | if (mRecycled) { |
| 1192 | throw new RuntimeException(toString() + " recycled twice!"); |
| 1193 | } |
| 1194 | mRecycled = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1195 | } |
| 1196 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1197 | synchronized (gRecyclerLock) { |
| 1198 | if (gRecyclerUsed < MAX_RECYCLED) { |
| 1199 | gRecyclerUsed++; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1200 | mNext = gRecyclerTop; |
| 1201 | gRecyclerTop = this; |
| 1202 | } |
| 1203 | } |
| 1204 | } |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1205 | |
| 1206 | /** |
| 1207 | * Scales down the coordination of this event by the given scale. |
| 1208 | * |
| 1209 | * @hide |
| 1210 | */ |
| 1211 | public final void scale(float scale) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1212 | nativeScale(mNativePtr, scale); |
| 1213 | } |
| 1214 | |
| 1215 | /** {@inheritDoc} */ |
| 1216 | @Override |
| 1217 | public final int getDeviceId() { |
| 1218 | return nativeGetDeviceId(mNativePtr); |
| 1219 | } |
| 1220 | |
| 1221 | /** {@inheritDoc} */ |
| 1222 | @Override |
| 1223 | public final int getSource() { |
| 1224 | return nativeGetSource(mNativePtr); |
| 1225 | } |
| 1226 | |
| 1227 | /** {@inheritDoc} */ |
| 1228 | @Override |
| 1229 | public final void setSource(int source) { |
| 1230 | nativeSetSource(mNativePtr, source); |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1231 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1232 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1233 | /** |
Jeff Brown | cc0c159 | 2011-02-19 05:07:28 -0800 | [diff] [blame] | 1234 | * Return the kind of action being performed. |
| 1235 | * Consider using {@link #getActionMasked} and {@link #getActionIndex} to retrieve |
| 1236 | * the separate masked action and pointer index. |
| 1237 | * @return The action, such as {@link #ACTION_DOWN} or |
| 1238 | * 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] | 1239 | */ |
| 1240 | public final int getAction() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1241 | return nativeGetAction(mNativePtr); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1242 | } |
| 1243 | |
| 1244 | /** |
Jeff Brown | cc0c159 | 2011-02-19 05:07:28 -0800 | [diff] [blame] | 1245 | * Return the masked action being performed, without pointer index information. |
| 1246 | * Use {@link #getActionIndex} to return the index associated with pointer actions. |
| 1247 | * @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] | 1248 | */ |
| 1249 | public final int getActionMasked() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1250 | return nativeGetAction(mNativePtr) & ACTION_MASK; |
Dianne Hackborn | b125dc5 | 2010-02-12 15:52:09 -0800 | [diff] [blame] | 1251 | } |
| 1252 | |
| 1253 | /** |
| 1254 | * For {@link #ACTION_POINTER_DOWN} or {@link #ACTION_POINTER_UP} |
| 1255 | * as returned by {@link #getActionMasked}, this returns the associated |
Jeff Brown | cc0c159 | 2011-02-19 05:07:28 -0800 | [diff] [blame] | 1256 | * pointer index. |
| 1257 | * The index may be used with {@link #getPointerId(int)}, |
Dianne Hackborn | b125dc5 | 2010-02-12 15:52:09 -0800 | [diff] [blame] | 1258 | * {@link #getX(int)}, {@link #getY(int)}, {@link #getPressure(int)}, |
| 1259 | * and {@link #getSize(int)} to get information about the pointer that has |
| 1260 | * gone down or up. |
Jeff Brown | cc0c159 | 2011-02-19 05:07:28 -0800 | [diff] [blame] | 1261 | * @return The index associated with the action. |
Dianne Hackborn | b125dc5 | 2010-02-12 15:52:09 -0800 | [diff] [blame] | 1262 | */ |
| 1263 | public final int getActionIndex() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1264 | return (nativeGetAction(mNativePtr) & ACTION_POINTER_INDEX_MASK) |
| 1265 | >> ACTION_POINTER_INDEX_SHIFT; |
Dianne Hackborn | b125dc5 | 2010-02-12 15:52:09 -0800 | [diff] [blame] | 1266 | } |
| 1267 | |
| 1268 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 1269 | * Returns true if this motion event is a touch event. |
| 1270 | * <p> |
| 1271 | * Specifically excludes pointer events with action {@link #ACTION_HOVER_MOVE} |
| 1272 | * or {@link #ACTION_SCROLL} because they are not actually touch events |
| 1273 | * (the pointer is not down). |
| 1274 | * </p> |
| 1275 | * @return True if this motion event is a touch event. |
| 1276 | * @hide |
| 1277 | */ |
| 1278 | public final boolean isTouchEvent() { |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame^] | 1279 | return nativeIsTouchEvent(mNativePtr); |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 1280 | } |
| 1281 | |
| 1282 | /** |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 1283 | * Gets the motion event flags. |
| 1284 | * |
| 1285 | * @see #FLAG_WINDOW_IS_OBSCURED |
| 1286 | */ |
| 1287 | public final int getFlags() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1288 | return nativeGetFlags(mNativePtr); |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 1289 | } |
| 1290 | |
| 1291 | /** |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1292 | * Returns the time (in ms) when the user originally pressed down to start |
| 1293 | * a stream of position events. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1294 | */ |
| 1295 | public final long getDownTime() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1296 | return nativeGetDownTimeNanos(mNativePtr) / NS_PER_MS; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1297 | } |
| 1298 | |
| 1299 | /** |
| 1300 | * Returns the time (in ms) when this specific event was generated. |
| 1301 | */ |
| 1302 | public final long getEventTime() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1303 | return nativeGetEventTimeNanos(mNativePtr, HISTORY_CURRENT) / NS_PER_MS; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1304 | } |
| 1305 | |
| 1306 | /** |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 1307 | * Returns the time (in ns) when this specific event was generated. |
| 1308 | * The value is in nanosecond precision but it may not have nanosecond accuracy. |
| 1309 | * |
| 1310 | * @hide |
| 1311 | */ |
| 1312 | public final long getEventTimeNano() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1313 | return nativeGetEventTimeNanos(mNativePtr, HISTORY_CURRENT); |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 1314 | } |
| 1315 | |
| 1316 | /** |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1317 | * {@link #getX(int)} for the first pointer index (may be an |
| 1318 | * arbitrary pointer identifier). |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1319 | * |
| 1320 | * @see #AXIS_X |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1321 | */ |
| 1322 | public final float getX() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1323 | return nativeGetAxisValue(mNativePtr, AXIS_X, 0, HISTORY_CURRENT); |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1324 | } |
| 1325 | |
| 1326 | /** |
| 1327 | * {@link #getY(int)} for the first pointer index (may be an |
| 1328 | * arbitrary pointer identifier). |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1329 | * |
| 1330 | * @see #AXIS_Y |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1331 | */ |
| 1332 | public final float getY() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1333 | return nativeGetAxisValue(mNativePtr, AXIS_Y, 0, HISTORY_CURRENT); |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1334 | } |
| 1335 | |
| 1336 | /** |
| 1337 | * {@link #getPressure(int)} for the first pointer index (may be an |
| 1338 | * arbitrary pointer identifier). |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1339 | * |
| 1340 | * @see #AXIS_PRESSURE |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1341 | */ |
| 1342 | public final float getPressure() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1343 | return nativeGetAxisValue(mNativePtr, AXIS_PRESSURE, 0, HISTORY_CURRENT); |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1344 | } |
| 1345 | |
| 1346 | /** |
| 1347 | * {@link #getSize(int)} for the first pointer index (may be an |
| 1348 | * arbitrary pointer identifier). |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1349 | * |
| 1350 | * @see #AXIS_SIZE |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1351 | */ |
| 1352 | public final float getSize() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1353 | return nativeGetAxisValue(mNativePtr, AXIS_SIZE, 0, HISTORY_CURRENT); |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1354 | } |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1355 | |
| 1356 | /** |
| 1357 | * {@link #getTouchMajor(int)} for the first pointer index (may be an |
| 1358 | * arbitrary pointer identifier). |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1359 | * |
| 1360 | * @see #AXIS_TOUCH_MAJOR |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1361 | */ |
| 1362 | public final float getTouchMajor() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1363 | return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MAJOR, 0, HISTORY_CURRENT); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1364 | } |
| 1365 | |
| 1366 | /** |
| 1367 | * {@link #getTouchMinor(int)} for the first pointer index (may be an |
| 1368 | * arbitrary pointer identifier). |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1369 | * |
| 1370 | * @see #AXIS_TOUCH_MINOR |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1371 | */ |
| 1372 | public final float getTouchMinor() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1373 | return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MINOR, 0, HISTORY_CURRENT); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1374 | } |
| 1375 | |
| 1376 | /** |
| 1377 | * {@link #getToolMajor(int)} for the first pointer index (may be an |
| 1378 | * arbitrary pointer identifier). |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1379 | * |
| 1380 | * @see #AXIS_TOOL_MAJOR |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1381 | */ |
| 1382 | public final float getToolMajor() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1383 | return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MAJOR, 0, HISTORY_CURRENT); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1384 | } |
| 1385 | |
| 1386 | /** |
| 1387 | * {@link #getToolMinor(int)} for the first pointer index (may be an |
| 1388 | * arbitrary pointer identifier). |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1389 | * |
| 1390 | * @see #AXIS_TOOL_MINOR |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1391 | */ |
| 1392 | public final float getToolMinor() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1393 | return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MINOR, 0, HISTORY_CURRENT); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1394 | } |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1395 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1396 | /** |
| 1397 | * {@link #getOrientation(int)} for the first pointer index (may be an |
| 1398 | * arbitrary pointer identifier). |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1399 | * |
| 1400 | * @see #AXIS_ORIENTATION |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1401 | */ |
| 1402 | public final float getOrientation() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1403 | return nativeGetAxisValue(mNativePtr, AXIS_ORIENTATION, 0, HISTORY_CURRENT); |
| 1404 | } |
| 1405 | |
| 1406 | /** |
| 1407 | * {@link #getAxisValue(int)} for the first pointer index (may be an |
| 1408 | * arbitrary pointer identifier). |
| 1409 | * |
| 1410 | * @param axis The axis identifier for the axis value to retrieve. |
| 1411 | * |
| 1412 | * @see #AXIS_X |
| 1413 | * @see #AXIS_Y |
| 1414 | */ |
| 1415 | public final float getAxisValue(int axis) { |
| 1416 | return nativeGetAxisValue(mNativePtr, axis, 0, HISTORY_CURRENT); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1417 | } |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1418 | |
| 1419 | /** |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1420 | * The number of pointers of data contained in this event. Always |
| 1421 | * >= 1. |
| 1422 | */ |
| 1423 | public final int getPointerCount() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1424 | return nativeGetPointerCount(mNativePtr); |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1425 | } |
| 1426 | |
| 1427 | /** |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1428 | * Return the pointer identifier associated with a particular pointer |
| 1429 | * data index is this event. The identifier tells you the actual pointer |
| 1430 | * number associated with the data, accounting for individual pointers |
| 1431 | * going up and down since the start of the current gesture. |
| 1432 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 1433 | * (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] | 1434 | */ |
Dianne Hackborn | d41ba66 | 2009-08-05 15:30:56 -0700 | [diff] [blame] | 1435 | public final int getPointerId(int pointerIndex) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1436 | return nativeGetPointerId(mNativePtr, pointerIndex); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1437 | } |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1438 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1439 | /** |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1440 | * Given a pointer identifier, find the index of its data in the event. |
| 1441 | * |
| 1442 | * @param pointerId The identifier of the pointer to be found. |
| 1443 | * @return Returns either the index of the pointer (for use with |
Gilles Debunne | b0d6ba1 | 2010-08-17 20:01:42 -0700 | [diff] [blame] | 1444 | * {@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] | 1445 | * that pointer identifier. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1446 | */ |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1447 | public final int findPointerIndex(int pointerId) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1448 | return nativeFindPointerIndex(mNativePtr, pointerId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1449 | } |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1450 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1451 | /** |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1452 | * Returns the X coordinate of this event for the given pointer |
| 1453 | * <em>index</em> (use {@link #getPointerId(int)} to find the pointer |
| 1454 | * identifier for this index). |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1455 | * Whole numbers are pixels; the |
| 1456 | * 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] | 1457 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 1458 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1459 | * |
| 1460 | * @see #AXIS_X |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1461 | */ |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1462 | public final float getX(int pointerIndex) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1463 | return nativeGetAxisValue(mNativePtr, AXIS_X, pointerIndex, HISTORY_CURRENT); |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1464 | } |
| 1465 | |
| 1466 | /** |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1467 | * Returns the Y coordinate of this event for the given pointer |
| 1468 | * <em>index</em> (use {@link #getPointerId(int)} to find the pointer |
| 1469 | * identifier for this index). |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1470 | * Whole numbers are pixels; the |
| 1471 | * 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] | 1472 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 1473 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1474 | * |
| 1475 | * @see #AXIS_Y |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1476 | */ |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1477 | public final float getY(int pointerIndex) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1478 | return nativeGetAxisValue(mNativePtr, AXIS_Y, pointerIndex, HISTORY_CURRENT); |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1479 | } |
| 1480 | |
| 1481 | /** |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1482 | * Returns the current pressure of this event for the given pointer |
| 1483 | * <em>index</em> (use {@link #getPointerId(int)} to find the pointer |
| 1484 | * identifier for this index). |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1485 | * The pressure generally |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1486 | * ranges from 0 (no pressure at all) to 1 (normal pressure), however |
| 1487 | * 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] | 1488 | * the input device. |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1489 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 1490 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1491 | * |
| 1492 | * @see #AXIS_PRESSURE |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1493 | */ |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1494 | public final float getPressure(int pointerIndex) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1495 | return nativeGetAxisValue(mNativePtr, AXIS_PRESSURE, pointerIndex, HISTORY_CURRENT); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1496 | } |
| 1497 | |
| 1498 | /** |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1499 | * Returns a scaled value of the approximate size for the given pointer |
| 1500 | * <em>index</em> (use {@link #getPointerId(int)} to find the pointer |
| 1501 | * identifier for this index). |
| 1502 | * This represents some approximation of the area of the screen being |
| 1503 | * pressed; the actual value in pixels corresponding to the |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1504 | * touch is normalized with the device specific range of values |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1505 | * 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] | 1506 | * determine fat touch events. |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1507 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 1508 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1509 | * |
| 1510 | * @see #AXIS_SIZE |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1511 | */ |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1512 | public final float getSize(int pointerIndex) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1513 | return nativeGetAxisValue(mNativePtr, AXIS_SIZE, pointerIndex, HISTORY_CURRENT); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1514 | } |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1515 | |
| 1516 | /** |
| 1517 | * Returns the length of the major axis of an ellipse that describes the touch |
| 1518 | * area at the point of contact for the given pointer |
| 1519 | * <em>index</em> (use {@link #getPointerId(int)} to find the pointer |
| 1520 | * identifier for this index). |
| 1521 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 1522 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1523 | * |
| 1524 | * @see #AXIS_TOUCH_MAJOR |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1525 | */ |
| 1526 | public final float getTouchMajor(int pointerIndex) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1527 | return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MAJOR, pointerIndex, HISTORY_CURRENT); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1528 | } |
| 1529 | |
| 1530 | /** |
| 1531 | * Returns the length of the minor axis of an ellipse that describes the touch |
| 1532 | * area at the point of contact for the given pointer |
| 1533 | * <em>index</em> (use {@link #getPointerId(int)} to find the pointer |
| 1534 | * identifier for this index). |
| 1535 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 1536 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1537 | * |
| 1538 | * @see #AXIS_TOUCH_MINOR |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1539 | */ |
| 1540 | public final float getTouchMinor(int pointerIndex) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1541 | return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MINOR, pointerIndex, HISTORY_CURRENT); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1542 | } |
| 1543 | |
| 1544 | /** |
| 1545 | * Returns the length of the major axis of an ellipse that describes the size of |
| 1546 | * the approaching tool for the given pointer |
| 1547 | * <em>index</em> (use {@link #getPointerId(int)} to find the pointer |
| 1548 | * identifier for this index). |
| 1549 | * The tool area represents the estimated size of the finger or pen that is |
| 1550 | * touching the device independent of its actual touch area at the point of contact. |
| 1551 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 1552 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1553 | * |
| 1554 | * @see #AXIS_TOOL_MAJOR |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1555 | */ |
| 1556 | public final float getToolMajor(int pointerIndex) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1557 | return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MAJOR, pointerIndex, HISTORY_CURRENT); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1558 | } |
| 1559 | |
| 1560 | /** |
| 1561 | * Returns the length of the minor axis of an ellipse that describes the size of |
| 1562 | * the approaching tool for the given pointer |
| 1563 | * <em>index</em> (use {@link #getPointerId(int)} to find the pointer |
| 1564 | * identifier for this index). |
| 1565 | * The tool area represents the estimated size of the finger or pen that is |
| 1566 | * touching the device independent of its actual touch area at the point of contact. |
| 1567 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 1568 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1569 | * |
| 1570 | * @see #AXIS_TOOL_MINOR |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1571 | */ |
| 1572 | public final float getToolMinor(int pointerIndex) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1573 | return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MINOR, pointerIndex, HISTORY_CURRENT); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1574 | } |
| 1575 | |
| 1576 | /** |
| 1577 | * Returns the orientation of the touch area and tool area in radians clockwise from vertical |
| 1578 | * for the given pointer <em>index</em> (use {@link #getPointerId(int)} to find the pointer |
| 1579 | * identifier for this index). |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 1580 | * 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] | 1581 | * upwards, is perfectly circular or is of unknown orientation. A positive angle |
| 1582 | * indicates that the major axis of contact is oriented to the right. A negative angle |
| 1583 | * indicates that the major axis of contact is oriented to the left. |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1584 | * 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] | 1585 | * (finger pointing fully right). |
| 1586 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 1587 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1588 | * |
| 1589 | * @see #AXIS_ORIENTATION |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1590 | */ |
| 1591 | public final float getOrientation(int pointerIndex) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1592 | return nativeGetAxisValue(mNativePtr, AXIS_ORIENTATION, pointerIndex, HISTORY_CURRENT); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1593 | } |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1594 | |
| 1595 | /** |
| 1596 | * Returns the value of the requested axis for the given pointer <em>index</em> |
| 1597 | * (use {@link #getPointerId(int)} to find the pointer identifier for this index). |
| 1598 | * |
| 1599 | * @param axis The axis identifier for the axis value to retrieve. |
| 1600 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 1601 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
| 1602 | * @return The value of the axis, or 0 if the axis is not available. |
| 1603 | * |
| 1604 | * @see #AXIS_X |
| 1605 | * @see #AXIS_Y |
| 1606 | */ |
| 1607 | public final float getAxisValue(int axis, int pointerIndex) { |
| 1608 | return nativeGetAxisValue(mNativePtr, axis, pointerIndex, HISTORY_CURRENT); |
| 1609 | } |
| 1610 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1611 | /** |
| 1612 | * Populates a {@link PointerCoords} object with pointer coordinate data for |
| 1613 | * the specified pointer index. |
| 1614 | * |
| 1615 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 1616 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
| 1617 | * @param outPointerCoords The pointer coordinate object to populate. |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1618 | * |
| 1619 | * @see PointerCoords |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1620 | */ |
| 1621 | public final void getPointerCoords(int pointerIndex, PointerCoords outPointerCoords) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1622 | nativeGetPointerCoords(mNativePtr, pointerIndex, HISTORY_CURRENT, outPointerCoords); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1623 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1624 | |
| 1625 | /** |
| 1626 | * Returns the state of any meta / modifier keys that were in effect when |
| 1627 | * the event was generated. This is the same values as those |
| 1628 | * returned by {@link KeyEvent#getMetaState() KeyEvent.getMetaState}. |
| 1629 | * |
| 1630 | * @return an integer in which each bit set to 1 represents a pressed |
| 1631 | * meta key |
| 1632 | * |
| 1633 | * @see KeyEvent#getMetaState() |
| 1634 | */ |
| 1635 | public final int getMetaState() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1636 | return nativeGetMetaState(mNativePtr); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1637 | } |
| 1638 | |
| 1639 | /** |
| 1640 | * Returns the original raw X coordinate of this event. For touch |
| 1641 | * events on the screen, this is the original location of the event |
| 1642 | * on the screen, before it had been adjusted for the containing window |
| 1643 | * and views. |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1644 | * |
| 1645 | * @see getX() |
| 1646 | * @see #AXIS_X |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1647 | */ |
| 1648 | public final float getRawX() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1649 | return nativeGetRawAxisValue(mNativePtr, AXIS_X, 0, HISTORY_CURRENT); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1650 | } |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1651 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1652 | /** |
| 1653 | * Returns the original raw Y coordinate of this event. For touch |
| 1654 | * events on the screen, this is the original location of the event |
| 1655 | * on the screen, before it had been adjusted for the containing window |
| 1656 | * and views. |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1657 | * |
| 1658 | * @see getY() |
| 1659 | * @see #AXIS_Y |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1660 | */ |
| 1661 | public final float getRawY() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1662 | return nativeGetRawAxisValue(mNativePtr, AXIS_Y, 0, HISTORY_CURRENT); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1663 | } |
| 1664 | |
| 1665 | /** |
| 1666 | * Return the precision of the X coordinates being reported. You can |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1667 | * 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] | 1668 | * value of the X coordinate. |
| 1669 | * @return Returns the precision of X coordinates being reported. |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1670 | * |
| 1671 | * @see #AXIS_X |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1672 | */ |
| 1673 | public final float getXPrecision() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1674 | return nativeGetXPrecision(mNativePtr); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1675 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1676 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1677 | /** |
| 1678 | * Return the precision of the Y coordinates being reported. You can |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1679 | * 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] | 1680 | * value of the Y coordinate. |
| 1681 | * @return Returns the precision of Y coordinates being reported. |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1682 | * |
| 1683 | * @see #AXIS_Y |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1684 | */ |
| 1685 | public final float getYPrecision() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1686 | return nativeGetYPrecision(mNativePtr); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1687 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1688 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1689 | /** |
| 1690 | * Returns the number of historical points in this event. These are |
| 1691 | * movements that have occurred between this event and the previous event. |
| 1692 | * This only applies to ACTION_MOVE events -- all other actions will have |
| 1693 | * a size of 0. |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1694 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1695 | * @return Returns the number of historical points in the event. |
| 1696 | */ |
| 1697 | public final int getHistorySize() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1698 | return nativeGetHistorySize(mNativePtr); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1699 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1700 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1701 | /** |
| 1702 | * Returns the time that a historical movement occurred between this event |
| 1703 | * and the previous event. Only applies to ACTION_MOVE events. |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1704 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1705 | * @param pos Which historical value to return; must be less than |
| 1706 | * {@link #getHistorySize} |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1707 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1708 | * @see #getHistorySize |
| 1709 | * @see #getEventTime |
| 1710 | */ |
| 1711 | public final long getHistoricalEventTime(int pos) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1712 | return nativeGetEventTimeNanos(mNativePtr, pos) / NS_PER_MS; |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1713 | } |
| 1714 | |
| 1715 | /** |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1716 | * {@link #getHistoricalX(int, int)} for the first pointer index (may be an |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1717 | * arbitrary pointer identifier). |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1718 | * |
| 1719 | * @param pos Which historical value to return; must be less than |
| 1720 | * {@link #getHistorySize} |
| 1721 | * |
| 1722 | * @see #getHistorySize |
| 1723 | * @see #getX() |
| 1724 | * @see #AXIS_X |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1725 | */ |
| 1726 | public final float getHistoricalX(int pos) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1727 | return nativeGetAxisValue(mNativePtr, AXIS_X, 0, pos); |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1728 | } |
| 1729 | |
| 1730 | /** |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1731 | * {@link #getHistoricalY(int, int)} for the first pointer index (may be an |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1732 | * arbitrary pointer identifier). |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1733 | * |
| 1734 | * @param pos Which historical value to return; must be less than |
| 1735 | * {@link #getHistorySize} |
| 1736 | * |
| 1737 | * @see #getHistorySize |
| 1738 | * @see #getY() |
| 1739 | * @see #AXIS_Y |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1740 | */ |
| 1741 | public final float getHistoricalY(int pos) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1742 | return nativeGetAxisValue(mNativePtr, AXIS_Y, 0, pos); |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1743 | } |
| 1744 | |
| 1745 | /** |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1746 | * {@link #getHistoricalPressure(int, int)} for the first pointer index (may be an |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1747 | * arbitrary pointer identifier). |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1748 | * |
| 1749 | * @param pos Which historical value to return; must be less than |
| 1750 | * {@link #getHistorySize} |
| 1751 | * |
| 1752 | * @see #getHistorySize |
| 1753 | * @see #getPressure() |
| 1754 | * @see #AXIS_PRESSURE |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1755 | */ |
| 1756 | public final float getHistoricalPressure(int pos) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1757 | return nativeGetAxisValue(mNativePtr, AXIS_PRESSURE, 0, pos); |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1758 | } |
| 1759 | |
| 1760 | /** |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1761 | * {@link #getHistoricalSize(int, int)} for the first pointer index (may be an |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1762 | * arbitrary pointer identifier). |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1763 | * |
| 1764 | * @param pos Which historical value to return; must be less than |
| 1765 | * {@link #getHistorySize} |
| 1766 | * |
| 1767 | * @see #getHistorySize |
| 1768 | * @see #getSize() |
| 1769 | * @see #AXIS_SIZE |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1770 | */ |
| 1771 | public final float getHistoricalSize(int pos) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1772 | return nativeGetAxisValue(mNativePtr, AXIS_SIZE, 0, pos); |
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 | /** |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1776 | * {@link #getHistoricalTouchMajor(int, int)} for the first pointer index (may be an |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1777 | * arbitrary pointer identifier). |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1778 | * |
| 1779 | * @param pos Which historical value to return; must be less than |
| 1780 | * {@link #getHistorySize} |
| 1781 | * |
| 1782 | * @see #getHistorySize |
| 1783 | * @see #getTouchMajor() |
| 1784 | * @see #AXIS_TOUCH_MAJOR |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1785 | */ |
| 1786 | public final float getHistoricalTouchMajor(int pos) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1787 | return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MAJOR, 0, pos); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1788 | } |
| 1789 | |
| 1790 | /** |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1791 | * {@link #getHistoricalTouchMinor(int, int)} for the first pointer index (may be an |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1792 | * arbitrary pointer identifier). |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1793 | * |
| 1794 | * @param pos Which historical value to return; must be less than |
| 1795 | * {@link #getHistorySize} |
| 1796 | * |
| 1797 | * @see #getHistorySize |
| 1798 | * @see #getTouchMinor() |
| 1799 | * @see #AXIS_TOUCH_MINOR |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1800 | */ |
| 1801 | public final float getHistoricalTouchMinor(int pos) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1802 | return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MINOR, 0, pos); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1803 | } |
| 1804 | |
| 1805 | /** |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1806 | * {@link #getHistoricalToolMajor(int, int)} for the first pointer index (may be an |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1807 | * arbitrary pointer identifier). |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1808 | * |
| 1809 | * @param pos Which historical value to return; must be less than |
| 1810 | * {@link #getHistorySize} |
| 1811 | * |
| 1812 | * @see #getHistorySize |
| 1813 | * @see #getToolMajor() |
| 1814 | * @see #AXIS_TOOL_MAJOR |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1815 | */ |
| 1816 | public final float getHistoricalToolMajor(int pos) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1817 | return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MAJOR, 0, pos); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1818 | } |
| 1819 | |
| 1820 | /** |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1821 | * {@link #getHistoricalToolMinor(int, int)} for the first pointer index (may be an |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1822 | * arbitrary pointer identifier). |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1823 | * |
| 1824 | * @param pos Which historical value to return; must be less than |
| 1825 | * {@link #getHistorySize} |
| 1826 | * |
| 1827 | * @see #getHistorySize |
| 1828 | * @see #getToolMinor() |
| 1829 | * @see #AXIS_TOOL_MINOR |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1830 | */ |
| 1831 | public final float getHistoricalToolMinor(int pos) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1832 | return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MINOR, 0, pos); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1833 | } |
| 1834 | |
| 1835 | /** |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1836 | * {@link #getHistoricalOrientation(int, int)} for the first pointer index (may be an |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1837 | * arbitrary pointer identifier). |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1838 | * |
| 1839 | * @param pos Which historical value to return; must be less than |
| 1840 | * {@link #getHistorySize} |
| 1841 | * |
| 1842 | * @see #getHistorySize |
| 1843 | * @see #getOrientation() |
| 1844 | * @see #AXIS_ORIENTATION |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1845 | */ |
| 1846 | public final float getHistoricalOrientation(int pos) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1847 | return nativeGetAxisValue(mNativePtr, AXIS_ORIENTATION, 0, pos); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1848 | } |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1849 | |
| 1850 | /** |
| 1851 | * {@link #getHistoricalAxisValue(int, int, int)} for the first pointer index (may be an |
| 1852 | * arbitrary pointer identifier). |
| 1853 | * |
| 1854 | * @param axis The axis identifier for the axis value to retrieve. |
| 1855 | * @param pos Which historical value to return; must be less than |
| 1856 | * {@link #getHistorySize} |
| 1857 | * |
| 1858 | * @see #getHistorySize |
| 1859 | * @see #getAxisValue(int) |
| 1860 | * @see #AXIS_X |
| 1861 | * @see #AXIS_Y |
| 1862 | */ |
| 1863 | public final float getHistoricalAxisValue(int axis, int pos) { |
| 1864 | return nativeGetAxisValue(mNativePtr, axis, 0, pos); |
| 1865 | } |
| 1866 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1867 | /** |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1868 | * Returns a historical X coordinate, as per {@link #getX(int)}, that |
| 1869 | * occurred between this event and the previous event for the given pointer. |
| 1870 | * Only applies to ACTION_MOVE events. |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1871 | * |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1872 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 1873 | * (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] | 1874 | * @param pos Which historical value to return; must be less than |
| 1875 | * {@link #getHistorySize} |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1876 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1877 | * @see #getHistorySize |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1878 | * @see #getX(int) |
| 1879 | * @see #AXIS_X |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1880 | */ |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1881 | public final float getHistoricalX(int pointerIndex, int pos) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1882 | return nativeGetAxisValue(mNativePtr, AXIS_X, pointerIndex, pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1883 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1884 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1885 | /** |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1886 | * Returns a historical Y coordinate, as per {@link #getY(int)}, that |
| 1887 | * occurred between this event and the previous event for the given pointer. |
| 1888 | * Only applies to ACTION_MOVE events. |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1889 | * |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1890 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 1891 | * (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] | 1892 | * @param pos Which historical value to return; must be less than |
| 1893 | * {@link #getHistorySize} |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1894 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1895 | * @see #getHistorySize |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1896 | * @see #getY(int) |
| 1897 | * @see #AXIS_Y |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1898 | */ |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1899 | public final float getHistoricalY(int pointerIndex, int pos) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1900 | return nativeGetAxisValue(mNativePtr, AXIS_Y, pointerIndex, pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1901 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1902 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1903 | /** |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1904 | * Returns a historical pressure coordinate, as per {@link #getPressure(int)}, |
| 1905 | * that occurred between this event and the previous event for the given |
| 1906 | * pointer. Only applies to ACTION_MOVE events. |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1907 | * |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1908 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 1909 | * (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] | 1910 | * @param pos Which historical value to return; must be less than |
| 1911 | * {@link #getHistorySize} |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1912 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1913 | * @see #getHistorySize |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1914 | * @see #getPressure(int) |
| 1915 | * @see #AXIS_PRESSURE |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1916 | */ |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1917 | public final float getHistoricalPressure(int pointerIndex, int pos) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1918 | return nativeGetAxisValue(mNativePtr, AXIS_PRESSURE, pointerIndex, pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1919 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1920 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1921 | /** |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1922 | * Returns a historical size coordinate, as per {@link #getSize(int)}, that |
| 1923 | * occurred between this event and the previous event for the given pointer. |
| 1924 | * Only applies to ACTION_MOVE events. |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1925 | * |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1926 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 1927 | * (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] | 1928 | * @param pos Which historical value to return; must be less than |
| 1929 | * {@link #getHistorySize} |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1930 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1931 | * @see #getHistorySize |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1932 | * @see #getSize(int) |
| 1933 | * @see #AXIS_SIZE |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1934 | */ |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1935 | public final float getHistoricalSize(int pointerIndex, int pos) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1936 | return nativeGetAxisValue(mNativePtr, AXIS_SIZE, pointerIndex, pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1937 | } |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1938 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1939 | /** |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1940 | * Returns a historical touch major axis coordinate, as per {@link #getTouchMajor(int)}, that |
| 1941 | * occurred between this event and the previous event for the given pointer. |
| 1942 | * Only applies to ACTION_MOVE events. |
| 1943 | * |
| 1944 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 1945 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
| 1946 | * @param pos Which historical value to return; must be less than |
| 1947 | * {@link #getHistorySize} |
| 1948 | * |
| 1949 | * @see #getHistorySize |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1950 | * @see #getTouchMajor(int) |
| 1951 | * @see #AXIS_TOUCH_MAJOR |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1952 | */ |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1953 | public final float getHistoricalTouchMajor(int pointerIndex, int pos) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1954 | return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MAJOR, pointerIndex, pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1955 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1956 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1957 | /** |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1958 | * Returns a historical touch minor axis coordinate, as per {@link #getTouchMinor(int)}, that |
| 1959 | * occurred between this event and the previous event for the given pointer. |
| 1960 | * Only applies to ACTION_MOVE events. |
| 1961 | * |
| 1962 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 1963 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
| 1964 | * @param pos Which historical value to return; must be less than |
| 1965 | * {@link #getHistorySize} |
| 1966 | * |
| 1967 | * @see #getHistorySize |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1968 | * @see #getTouchMinor(int) |
| 1969 | * @see #AXIS_TOUCH_MINOR |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1970 | */ |
| 1971 | public final float getHistoricalTouchMinor(int pointerIndex, int pos) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1972 | return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MINOR, pointerIndex, pos); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1973 | } |
| 1974 | |
| 1975 | /** |
| 1976 | * Returns a historical tool major axis coordinate, as per {@link #getToolMajor(int)}, that |
| 1977 | * occurred between this event and the previous event for the given pointer. |
| 1978 | * Only applies to ACTION_MOVE events. |
| 1979 | * |
| 1980 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 1981 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
| 1982 | * @param pos Which historical value to return; must be less than |
| 1983 | * {@link #getHistorySize} |
| 1984 | * |
| 1985 | * @see #getHistorySize |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1986 | * @see #getToolMajor(int) |
| 1987 | * @see #AXIS_TOOL_MAJOR |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1988 | */ |
| 1989 | public final float getHistoricalToolMajor(int pointerIndex, int pos) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1990 | return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MAJOR, pointerIndex, pos); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1991 | } |
| 1992 | |
| 1993 | /** |
| 1994 | * Returns a historical tool minor axis coordinate, as per {@link #getToolMinor(int)}, that |
| 1995 | * occurred between this event and the previous event for the given pointer. |
| 1996 | * Only applies to ACTION_MOVE events. |
| 1997 | * |
| 1998 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 1999 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
| 2000 | * @param pos Which historical value to return; must be less than |
| 2001 | * {@link #getHistorySize} |
| 2002 | * |
| 2003 | * @see #getHistorySize |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2004 | * @see #getToolMinor(int) |
| 2005 | * @see #AXIS_TOOL_MINOR |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2006 | */ |
| 2007 | public final float getHistoricalToolMinor(int pointerIndex, int pos) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2008 | return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MINOR, pointerIndex, pos); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2009 | } |
| 2010 | |
| 2011 | /** |
| 2012 | * Returns a historical orientation coordinate, as per {@link #getOrientation(int)}, that |
| 2013 | * occurred between this event and the previous event for the given pointer. |
| 2014 | * Only applies to ACTION_MOVE events. |
| 2015 | * |
| 2016 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 2017 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
| 2018 | * @param pos Which historical value to return; must be less than |
| 2019 | * {@link #getHistorySize} |
| 2020 | * |
| 2021 | * @see #getHistorySize |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2022 | * @see #getOrientation(int) |
| 2023 | * @see #AXIS_ORIENTATION |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2024 | */ |
| 2025 | public final float getHistoricalOrientation(int pointerIndex, int pos) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2026 | return nativeGetAxisValue(mNativePtr, AXIS_ORIENTATION, pointerIndex, pos); |
| 2027 | } |
| 2028 | |
| 2029 | /** |
| 2030 | * Returns the historical value of the requested axis, as per {@link #getAxisValue(int, int)}, |
| 2031 | * occurred between this event and the previous event for the given pointer. |
| 2032 | * Only applies to ACTION_MOVE events. |
| 2033 | * |
| 2034 | * @param axis The axis identifier for the axis value to retrieve. |
| 2035 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 2036 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
| 2037 | * @param pos Which historical value to return; must be less than |
| 2038 | * {@link #getHistorySize} |
| 2039 | * @return The value of the axis, or 0 if the axis is not available. |
| 2040 | * |
| 2041 | * @see #AXIS_X |
| 2042 | * @see #AXIS_Y |
| 2043 | */ |
| 2044 | public final float getHistoricalAxisValue(int axis, int pointerIndex, int pos) { |
| 2045 | return nativeGetAxisValue(mNativePtr, axis, pointerIndex, pos); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2046 | } |
| 2047 | |
| 2048 | /** |
| 2049 | * Populates a {@link PointerCoords} object with historical pointer coordinate data, |
| 2050 | * as per {@link #getPointerCoords}, that occurred between this event and the previous |
| 2051 | * event for the given pointer. |
| 2052 | * Only applies to ACTION_MOVE events. |
| 2053 | * |
| 2054 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 2055 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
| 2056 | * @param pos Which historical value to return; must be less than |
| 2057 | * {@link #getHistorySize} |
| 2058 | * @param outPointerCoords The pointer coordinate object to populate. |
| 2059 | * |
| 2060 | * @see #getHistorySize |
| 2061 | * @see #getPointerCoords |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2062 | * @see PointerCoords |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2063 | */ |
| 2064 | public final void getHistoricalPointerCoords(int pointerIndex, int pos, |
| 2065 | PointerCoords outPointerCoords) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2066 | nativeGetPointerCoords(mNativePtr, pointerIndex, pos, outPointerCoords); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2067 | } |
| 2068 | |
| 2069 | /** |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2070 | * Returns a bitfield indicating which edges, if any, were touched by this |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 2071 | * MotionEvent. For touch events, clients can use this to determine if the |
| 2072 | * user's finger was touching the edge of the display. |
| 2073 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2074 | * @see #EDGE_LEFT |
| 2075 | * @see #EDGE_TOP |
| 2076 | * @see #EDGE_RIGHT |
| 2077 | * @see #EDGE_BOTTOM |
| 2078 | */ |
| 2079 | public final int getEdgeFlags() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2080 | return nativeGetEdgeFlags(mNativePtr); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2081 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 2082 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2083 | /** |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 2084 | * Sets the bitfield indicating which edges, if any, were touched by this |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 2085 | * MotionEvent. |
| 2086 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2087 | * @see #getEdgeFlags() |
| 2088 | */ |
| 2089 | public final void setEdgeFlags(int flags) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2090 | nativeSetEdgeFlags(mNativePtr, flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2091 | } |
| 2092 | |
| 2093 | /** |
| 2094 | * Sets this event's action. |
| 2095 | */ |
| 2096 | public final void setAction(int action) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2097 | nativeSetAction(mNativePtr, action); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2098 | } |
| 2099 | |
| 2100 | /** |
| 2101 | * Adjust this event's location. |
| 2102 | * @param deltaX Amount to add to the current X coordinate of the event. |
| 2103 | * @param deltaY Amount to add to the current Y coordinate of the event. |
| 2104 | */ |
| 2105 | public final void offsetLocation(float deltaX, float deltaY) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2106 | nativeOffsetLocation(mNativePtr, deltaX, deltaY); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2107 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 2108 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2109 | /** |
| 2110 | * Set this event's location. Applies {@link #offsetLocation} with a |
| 2111 | * delta from the current location to the given new location. |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 2112 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2113 | * @param x New absolute X location. |
| 2114 | * @param y New absolute Y location. |
| 2115 | */ |
| 2116 | public final void setLocation(float x, float y) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2117 | float oldX = getX(); |
| 2118 | float oldY = getY(); |
| 2119 | nativeOffsetLocation(mNativePtr, x - oldX, y - oldY); |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 2120 | } |
| 2121 | |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 2122 | /** |
| 2123 | * Applies a transformation matrix to all of the points in the event. |
| 2124 | * |
| 2125 | * @param matrix The transformation matrix to apply. |
| 2126 | */ |
| 2127 | public final void transform(Matrix matrix) { |
| 2128 | if (matrix == null) { |
| 2129 | throw new IllegalArgumentException("matrix must not be null"); |
| 2130 | } |
| 2131 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2132 | nativeTransform(mNativePtr, matrix); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2133 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 2134 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2135 | /** |
| 2136 | * 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] | 2137 | * current location, position and size is updated to the new values. |
| 2138 | * 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] | 2139 | * |
Jeff Brown | cc0c159 | 2011-02-19 05:07:28 -0800 | [diff] [blame] | 2140 | * Only applies to {@link #ACTION_MOVE} or {@link #ACTION_HOVER_MOVE} events. |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 2141 | * |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2142 | * @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] | 2143 | * @param x The new X position. |
| 2144 | * @param y The new Y position. |
| 2145 | * @param pressure The new pressure. |
| 2146 | * @param size The new size. |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 2147 | * @param metaState Meta key state. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2148 | */ |
| 2149 | public final void addBatch(long eventTime, float x, float y, |
| 2150 | float pressure, float size, int metaState) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2151 | synchronized (gTmpPointerCoords) { |
| 2152 | final PointerCoords pc = gTmpPointerCoords[0]; |
| 2153 | pc.clear(); |
| 2154 | pc.x = x; |
| 2155 | pc.y = y; |
| 2156 | pc.pressure = pressure; |
| 2157 | pc.size = size; |
| 2158 | nativeAddBatch(mNativePtr, eventTime * NS_PER_MS, gTmpPointerCoords, metaState); |
| 2159 | } |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 2160 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 2161 | |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 2162 | /** |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2163 | * Add a new movement to the batch of movements in this event. The event's |
| 2164 | * current location, position and size is updated to the new values. |
| 2165 | * 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] | 2166 | * |
Jeff Brown | cc0c159 | 2011-02-19 05:07:28 -0800 | [diff] [blame] | 2167 | * Only applies to {@link #ACTION_MOVE} or {@link #ACTION_HOVER_MOVE} events. |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2168 | * |
| 2169 | * @param eventTime The time stamp (in ms) for this data. |
| 2170 | * @param pointerCoords The new pointer coordinates. |
| 2171 | * @param metaState Meta key state. |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 2172 | */ |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2173 | public final void addBatch(long eventTime, PointerCoords[] pointerCoords, int metaState) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2174 | nativeAddBatch(mNativePtr, eventTime * NS_PER_MS, pointerCoords, metaState); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2175 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 2176 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2177 | @Override |
| 2178 | public String toString() { |
| 2179 | return "MotionEvent{" + Integer.toHexString(System.identityHashCode(this)) |
Huahui Wu | e838a42 | 2011-01-13 16:03:43 -0800 | [diff] [blame] | 2180 | + " pointerId=" + getPointerId(0) |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2181 | + " action=" + actionToString(getAction()) |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2182 | + " x=" + getX() |
| 2183 | + " y=" + getY() |
| 2184 | + " pressure=" + getPressure() |
| 2185 | + " size=" + getSize() |
| 2186 | + " touchMajor=" + getTouchMajor() |
| 2187 | + " touchMinor=" + getTouchMinor() |
| 2188 | + " toolMajor=" + getToolMajor() |
| 2189 | + " toolMinor=" + getToolMinor() |
| 2190 | + " orientation=" + getOrientation() |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2191 | + " meta=" + KeyEvent.metaStateToString(getMetaState()) |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2192 | + " pointerCount=" + getPointerCount() |
| 2193 | + " historySize=" + getHistorySize() |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2194 | + " flags=0x" + Integer.toHexString(getFlags()) |
| 2195 | + " edgeFlags=0x" + Integer.toHexString(getEdgeFlags()) |
| 2196 | + " device=" + getDeviceId() |
| 2197 | + " source=0x" + Integer.toHexString(getSource()) |
Huahui Wu | e838a42 | 2011-01-13 16:03:43 -0800 | [diff] [blame] | 2198 | + (getPointerCount() > 1 ? |
Huahui Wu | f932469 | 2011-01-24 12:07:37 -0800 | [diff] [blame] | 2199 | " pointerId2=" + getPointerId(1) + " x2=" + getX(1) + " y2=" + getY(1) : "") |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2200 | + "}"; |
| 2201 | } |
| 2202 | |
| 2203 | /** |
| 2204 | * Returns a string that represents the symbolic name of the specified action |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2205 | * such as "ACTION_DOWN", "ACTION_POINTER_DOWN(3)" or an equivalent numeric constant |
| 2206 | * such as "35" if unknown. |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2207 | * |
| 2208 | * @param action The action. |
| 2209 | * @return The symbolic name of the specified action. |
| 2210 | * @hide |
| 2211 | */ |
| 2212 | public static String actionToString(int action) { |
| 2213 | switch (action) { |
| 2214 | case ACTION_DOWN: |
| 2215 | return "ACTION_DOWN"; |
| 2216 | case ACTION_UP: |
| 2217 | return "ACTION_UP"; |
| 2218 | case ACTION_CANCEL: |
| 2219 | return "ACTION_CANCEL"; |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 2220 | case ACTION_OUTSIDE: |
| 2221 | return "ACTION_OUTSIDE"; |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2222 | case ACTION_MOVE: |
| 2223 | return "ACTION_MOVE"; |
Jeff Brown | cc0c159 | 2011-02-19 05:07:28 -0800 | [diff] [blame] | 2224 | case ACTION_HOVER_MOVE: |
| 2225 | return "ACTION_HOVER_MOVE"; |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 2226 | case ACTION_SCROLL: |
| 2227 | return "ACTION_SCROLL"; |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 2228 | } |
| 2229 | int index = (action & ACTION_POINTER_INDEX_MASK) >> ACTION_POINTER_INDEX_SHIFT; |
| 2230 | switch (action & ACTION_MASK) { |
| 2231 | case ACTION_POINTER_DOWN: |
| 2232 | return "ACTION_POINTER_DOWN(" + index + ")"; |
| 2233 | case ACTION_POINTER_UP: |
| 2234 | return "ACTION_POINTER_UP(" + index + ")"; |
| 2235 | default: |
| 2236 | return Integer.toString(action); |
| 2237 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2238 | } |
| 2239 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2240 | /** |
| 2241 | * Returns a string that represents the symbolic name of the specified axis |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 2242 | * 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] | 2243 | * |
| 2244 | * @param axis The axis |
| 2245 | * @return The symbolic name of the specified axis. |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2246 | */ |
| 2247 | public static String axisToString(int axis) { |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 2248 | String symbolicName = AXIS_SYMBOLIC_NAMES.get(axis); |
| 2249 | return symbolicName != null ? symbolicName : Integer.toString(axis); |
| 2250 | } |
| 2251 | |
| 2252 | /** |
Jeff Brown | cc0c159 | 2011-02-19 05:07:28 -0800 | [diff] [blame] | 2253 | * Gets an axis by its symbolic name such as "AXIS_X" or an |
| 2254 | * equivalent numeric constant such as "42". |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 2255 | * |
| 2256 | * @param symbolicName The symbolic name of the axis. |
| 2257 | * @return The axis or -1 if not found. |
| 2258 | * @see #keycodeToString |
| 2259 | */ |
| 2260 | public static int axisFromString(String symbolicName) { |
| 2261 | if (symbolicName == null) { |
| 2262 | throw new IllegalArgumentException("symbolicName must not be null"); |
| 2263 | } |
| 2264 | |
| 2265 | final int count = AXIS_SYMBOLIC_NAMES.size(); |
| 2266 | for (int i = 0; i < count; i++) { |
| 2267 | if (symbolicName.equals(AXIS_SYMBOLIC_NAMES.valueAt(i))) { |
| 2268 | return i; |
| 2269 | } |
| 2270 | } |
| 2271 | |
| 2272 | try { |
| 2273 | return Integer.parseInt(symbolicName, 10); |
| 2274 | } catch (NumberFormatException ex) { |
| 2275 | return -1; |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2276 | } |
| 2277 | } |
| 2278 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2279 | public static final Parcelable.Creator<MotionEvent> CREATOR |
| 2280 | = new Parcelable.Creator<MotionEvent>() { |
| 2281 | public MotionEvent createFromParcel(Parcel in) { |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 2282 | in.readInt(); // skip token, we already know this is a MotionEvent |
| 2283 | return MotionEvent.createFromParcelBody(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2284 | } |
| 2285 | |
| 2286 | public MotionEvent[] newArray(int size) { |
| 2287 | return new MotionEvent[size]; |
| 2288 | } |
| 2289 | }; |
| 2290 | |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 2291 | /** @hide */ |
| 2292 | public static MotionEvent createFromParcelBody(Parcel in) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2293 | MotionEvent ev = obtain(); |
| 2294 | ev.mNativePtr = nativeReadFromParcel(ev.mNativePtr, in); |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 2295 | return ev; |
| 2296 | } |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2297 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2298 | public void writeToParcel(Parcel out, int flags) { |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 2299 | out.writeInt(PARCEL_TOKEN_MOTION_EVENT); |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2300 | nativeWriteToParcel(mNativePtr, out); |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 2301 | } |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2302 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2303 | /** |
| 2304 | * Transfer object for pointer coordinates. |
| 2305 | * |
| 2306 | * Objects of this type can be used to manufacture new {@link MotionEvent} objects |
| 2307 | * and to query pointer coordinate information in bulk. |
| 2308 | * |
| 2309 | * Refer to {@link InputDevice} for information about how different kinds of |
| 2310 | * input devices and sources represent pointer coordinates. |
| 2311 | */ |
| 2312 | public static final class PointerCoords { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2313 | private static final int INITIAL_PACKED_AXIS_VALUES = 8; |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 2314 | private long mPackedAxisBits; |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2315 | private float[] mPackedAxisValues; |
| 2316 | |
| 2317 | /** |
| 2318 | * Creates a pointer coords object with all axes initialized to zero. |
| 2319 | */ |
| 2320 | public PointerCoords() { |
| 2321 | } |
| 2322 | |
| 2323 | /** |
| 2324 | * Creates a pointer coords object as a copy of the |
| 2325 | * contents of another pointer coords object. |
| 2326 | * |
| 2327 | * @param other The pointer coords object to copy. |
| 2328 | */ |
| 2329 | public PointerCoords(PointerCoords other) { |
| 2330 | copyFrom(other); |
| 2331 | } |
| 2332 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2333 | /** |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 2334 | * The X component of the pointer movement. |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2335 | * |
| 2336 | * @see MotionEvent#AXIS_X |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2337 | */ |
| 2338 | public float x; |
| 2339 | |
| 2340 | /** |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 2341 | * The Y component of the pointer movement. |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2342 | * |
| 2343 | * @see MotionEvent#AXIS_Y |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2344 | */ |
| 2345 | public float y; |
| 2346 | |
| 2347 | /** |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2348 | * A normalized value that describes the pressure applied to the device |
| 2349 | * by a finger or other tool. |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2350 | * 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] | 2351 | * 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] | 2352 | * the input device. |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2353 | * |
| 2354 | * @see MotionEvent#AXIS_PRESSURE |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2355 | */ |
| 2356 | public float pressure; |
| 2357 | |
| 2358 | /** |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2359 | * A normalized value that describes the approximate size of the pointer touch area |
| 2360 | * in relation to the maximum detectable size of the device. |
| 2361 | * It represents some approximation of the area of the screen being |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2362 | * pressed; the actual value in pixels corresponding to the |
| 2363 | * touch is normalized with the device specific range of values |
| 2364 | * and scaled to a value between 0 and 1. The value of size can be used to |
| 2365 | * determine fat touch events. |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2366 | * |
| 2367 | * @see MotionEvent#AXIS_SIZE |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2368 | */ |
| 2369 | public float size; |
| 2370 | |
| 2371 | /** |
| 2372 | * The length of the major axis of an ellipse that describes the touch area at |
| 2373 | * the point of contact. |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2374 | * If the device is a touch screen, the length is reported in pixels, otherwise it is |
| 2375 | * reported in device-specific units. |
| 2376 | * |
| 2377 | * @see MotionEvent#AXIS_TOUCH_MAJOR |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2378 | */ |
| 2379 | public float touchMajor; |
| 2380 | |
| 2381 | /** |
| 2382 | * The length of the minor axis of an ellipse that describes the touch area at |
| 2383 | * the point of contact. |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2384 | * If the device is a touch screen, the length is reported in pixels, otherwise it is |
| 2385 | * reported in device-specific units. |
| 2386 | * |
| 2387 | * @see MotionEvent#AXIS_TOUCH_MINOR |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2388 | */ |
| 2389 | public float touchMinor; |
| 2390 | |
| 2391 | /** |
| 2392 | * The length of the major axis of an ellipse that describes the size of |
| 2393 | * the approaching tool. |
| 2394 | * The tool area represents the estimated size of the finger or pen that is |
| 2395 | * 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] | 2396 | * If the device is a touch screen, the length is reported in pixels, otherwise it is |
| 2397 | * reported in device-specific units. |
| 2398 | * |
| 2399 | * @see MotionEvent#AXIS_TOOL_MAJOR |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2400 | */ |
| 2401 | public float toolMajor; |
| 2402 | |
| 2403 | /** |
| 2404 | * The length of the minor axis of an ellipse that describes the size of |
| 2405 | * the approaching tool. |
| 2406 | * The tool area represents the estimated size of the finger or pen that is |
| 2407 | * 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] | 2408 | * If the device is a touch screen, the length is reported in pixels, otherwise it is |
| 2409 | * reported in device-specific units. |
| 2410 | * |
| 2411 | * @see MotionEvent#AXIS_TOOL_MINOR |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2412 | */ |
| 2413 | public float toolMinor; |
| 2414 | |
| 2415 | /** |
| 2416 | * 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] | 2417 | * 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] | 2418 | * upwards, is perfectly circular or is of unknown orientation. A positive angle |
| 2419 | * indicates that the major axis of contact is oriented to the right. A negative angle |
| 2420 | * indicates that the major axis of contact is oriented to the left. |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 2421 | * 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] | 2422 | * (finger pointing fully right). |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2423 | * |
| 2424 | * @see MotionEvent#AXIS_ORIENTATION |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2425 | */ |
| 2426 | public float orientation; |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2427 | |
| 2428 | /** |
| 2429 | * Clears the contents of this object. |
| 2430 | * Resets all axes to zero. |
| 2431 | */ |
| 2432 | public void clear() { |
| 2433 | mPackedAxisBits = 0; |
| 2434 | |
| 2435 | x = 0; |
| 2436 | y = 0; |
| 2437 | pressure = 0; |
| 2438 | size = 0; |
| 2439 | touchMajor = 0; |
| 2440 | touchMinor = 0; |
| 2441 | toolMajor = 0; |
| 2442 | toolMinor = 0; |
| 2443 | orientation = 0; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2444 | } |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2445 | |
| 2446 | /** |
| 2447 | * Copies the contents of another pointer coords object. |
| 2448 | * |
| 2449 | * @param other The pointer coords object to copy. |
| 2450 | */ |
| 2451 | public void copyFrom(PointerCoords other) { |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 2452 | final long bits = other.mPackedAxisBits; |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2453 | mPackedAxisBits = bits; |
| 2454 | if (bits != 0) { |
| 2455 | final float[] otherValues = other.mPackedAxisValues; |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 2456 | final int count = Long.bitCount(bits); |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2457 | float[] values = mPackedAxisValues; |
| 2458 | if (values == null || count > values.length) { |
| 2459 | values = new float[otherValues.length]; |
| 2460 | mPackedAxisValues = values; |
| 2461 | } |
| 2462 | System.arraycopy(otherValues, 0, values, 0, count); |
| 2463 | } |
| 2464 | |
| 2465 | x = other.x; |
| 2466 | y = other.y; |
| 2467 | pressure = other.pressure; |
| 2468 | size = other.size; |
| 2469 | touchMajor = other.touchMajor; |
| 2470 | touchMinor = other.touchMinor; |
| 2471 | toolMajor = other.toolMajor; |
| 2472 | toolMinor = other.toolMinor; |
| 2473 | orientation = other.orientation; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2474 | } |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2475 | |
| 2476 | /** |
| 2477 | * Gets the value associated with the specified axis. |
| 2478 | * |
| 2479 | * @param axis The axis identifier for the axis value to retrieve. |
| 2480 | * @return The value associated with the axis, or 0 if none. |
| 2481 | * |
| 2482 | * @see MotionEvent#AXIS_X |
| 2483 | * @see MotionEvent#AXIS_Y |
| 2484 | */ |
| 2485 | public float getAxisValue(int axis) { |
| 2486 | switch (axis) { |
| 2487 | case AXIS_X: |
| 2488 | return x; |
| 2489 | case AXIS_Y: |
| 2490 | return y; |
| 2491 | case AXIS_PRESSURE: |
| 2492 | return pressure; |
| 2493 | case AXIS_SIZE: |
| 2494 | return size; |
| 2495 | case AXIS_TOUCH_MAJOR: |
| 2496 | return touchMajor; |
| 2497 | case AXIS_TOUCH_MINOR: |
| 2498 | return touchMinor; |
| 2499 | case AXIS_TOOL_MAJOR: |
| 2500 | return toolMajor; |
| 2501 | case AXIS_TOOL_MINOR: |
| 2502 | return toolMinor; |
| 2503 | case AXIS_ORIENTATION: |
| 2504 | return orientation; |
| 2505 | default: { |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 2506 | if (axis < 0 || axis > 63) { |
| 2507 | throw new IllegalArgumentException("Axis out of range."); |
| 2508 | } |
| 2509 | final long bits = mPackedAxisBits; |
| 2510 | final long axisBit = 1L << axis; |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2511 | if ((bits & axisBit) == 0) { |
| 2512 | return 0; |
| 2513 | } |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 2514 | final int index = Long.bitCount(bits & (axisBit - 1L)); |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2515 | return mPackedAxisValues[index]; |
| 2516 | } |
| 2517 | } |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2518 | } |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2519 | |
| 2520 | /** |
| 2521 | * Sets the value associated with the specified axis. |
| 2522 | * |
| 2523 | * @param axis The axis identifier for the axis value to assign. |
| 2524 | * @param value The value to set. |
| 2525 | * |
| 2526 | * @see MotionEvent#AXIS_X |
| 2527 | * @see MotionEvent#AXIS_Y |
| 2528 | */ |
| 2529 | public void setAxisValue(int axis, float value) { |
| 2530 | switch (axis) { |
| 2531 | case AXIS_X: |
| 2532 | x = value; |
| 2533 | break; |
| 2534 | case AXIS_Y: |
| 2535 | y = value; |
| 2536 | break; |
| 2537 | case AXIS_PRESSURE: |
| 2538 | pressure = value; |
| 2539 | break; |
| 2540 | case AXIS_SIZE: |
| 2541 | size = value; |
| 2542 | break; |
| 2543 | case AXIS_TOUCH_MAJOR: |
| 2544 | touchMajor = value; |
| 2545 | break; |
| 2546 | case AXIS_TOUCH_MINOR: |
| 2547 | touchMinor = value; |
| 2548 | break; |
| 2549 | case AXIS_TOOL_MAJOR: |
| 2550 | toolMajor = value; |
| 2551 | break; |
| 2552 | case AXIS_TOOL_MINOR: |
| 2553 | toolMinor = value; |
| 2554 | break; |
| 2555 | case AXIS_ORIENTATION: |
| 2556 | orientation = value; |
| 2557 | break; |
| 2558 | default: { |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 2559 | if (axis < 0 || axis > 63) { |
| 2560 | throw new IllegalArgumentException("Axis out of range."); |
| 2561 | } |
| 2562 | final long bits = mPackedAxisBits; |
| 2563 | final long axisBit = 1L << axis; |
| 2564 | final int index = Long.bitCount(bits & (axisBit - 1L)); |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2565 | float[] values = mPackedAxisValues; |
| 2566 | if ((bits & axisBit) == 0) { |
| 2567 | if (values == null) { |
| 2568 | values = new float[INITIAL_PACKED_AXIS_VALUES]; |
| 2569 | mPackedAxisValues = values; |
| 2570 | } else { |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 2571 | final int count = Long.bitCount(bits); |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2572 | if (count < values.length) { |
| 2573 | if (index != count) { |
| 2574 | System.arraycopy(values, index, values, index + 1, |
| 2575 | count - index); |
| 2576 | } |
| 2577 | } else { |
| 2578 | float[] newValues = new float[count * 2]; |
| 2579 | System.arraycopy(values, 0, newValues, 0, index); |
| 2580 | System.arraycopy(values, index, newValues, index + 1, |
| 2581 | count - index); |
| 2582 | values = newValues; |
| 2583 | mPackedAxisValues = values; |
| 2584 | } |
| 2585 | } |
| 2586 | mPackedAxisBits = bits | axisBit; |
| 2587 | } |
| 2588 | values[index] = value; |
| 2589 | } |
| 2590 | } |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2591 | } |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2592 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2593 | } |