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 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 26 | * Object used to report movement (mouse, pen, finger, trackball) events. |
| 27 | * Motion events may hold either absolute or relative movements and other data, |
| 28 | * depending on the type of device. |
| 29 | * |
| 30 | * <h3>Overview</h3> |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 31 | * <p> |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 32 | * Motion events describe movements in terms of an action code and a set of axis values. |
| 33 | * The action code specifies the state change that occurred such as a pointer going |
| 34 | * down or up. The axis values describe the position and other movement properties. |
| 35 | * </p><p> |
| 36 | * For example, when the user first touches the screen, the system delivers a touch |
| 37 | * event to the appropriate {@link View} with the action code {@link #ACTION_DOWN} |
| 38 | * and a set of axis values that include the X and Y coordinates of the touch and |
| 39 | * information about the pressure, size and orientation of the contact area. |
| 40 | * </p><p> |
| 41 | * Some devices can report multiple movement traces at the same time. Multi-touch |
| 42 | * screens emit one movement trace for each finger. The individual fingers or |
| 43 | * other objects that generate movement traces are referred to as <em>pointers</em>. |
| 44 | * Motion events contain information about all of the pointers that are currently active |
| 45 | * even if some of them have not moved since the last event was delivered. |
| 46 | * </p><p> |
| 47 | * The number of pointers only ever changes by one as individual pointers go up and down, |
| 48 | * except when the gesture is canceled. |
| 49 | * </p><p> |
| 50 | * Each pointer has a unique id that is assigned when it first goes down |
| 51 | * (indicated by {@link #ACTION_DOWN} or {@link #ACTION_POINTER_DOWN}). A pointer id |
| 52 | * remains valid until the pointer eventually goes up (indicated by {@link #ACTION_UP} |
| 53 | * or {@link #ACTION_POINTER_UP}) or when the gesture is canceled (indicated by |
| 54 | * {@link #ACTION_CANCEL}). |
| 55 | * </p><p> |
| 56 | * The MotionEvent class provides many methods to query the position and other properties of |
| 57 | * pointers, such as {@link #getX(int)}, {@link #getY(int)}, {@link #getAxisValue}, |
| 58 | * {@link #getPointerId(int)}, {@link #getToolType(int)}, and many others. Most of these |
| 59 | * methods accept the pointer index as a parameter rather than the pointer id. |
| 60 | * The pointer index of each pointer in the event ranges from 0 to one less than the value |
| 61 | * returned by {@link #getPointerCount()}. |
| 62 | * </p><p> |
| 63 | * The order in which individual pointers appear within a motion event is undefined. |
| 64 | * Thus the pointer index of a pointer can change from one event to the next but |
| 65 | * the pointer id of a pointer is guaranteed to remain constant as long as the pointer |
| 66 | * remains active. Use the {@link #getPointerId(int)} method to obtain the |
| 67 | * pointer id of a pointer to track it across all subsequent motion events in a gesture. |
| 68 | * Then for successive motion events, use the {@link #findPointerIndex(int)} method |
| 69 | * to obtain the pointer index for a given pointer id in that motion event. |
| 70 | * </p><p> |
| 71 | * Mouse and stylus buttons can be retrieved using {@link #getButtonState()}. It is a |
| 72 | * good idea to check the button state while handling {@link #ACTION_DOWN} as part |
| 73 | * of a touch event. The application may choose to perform some different action |
| 74 | * if the touch event starts due to a secondary button click, such as presenting a |
| 75 | * context menu. |
| 76 | * </p> |
| 77 | * |
| 78 | * <h3>Batching</h3> |
| 79 | * <p> |
| 80 | * For efficiency, motion events with {@link #ACTION_MOVE} may batch together |
| 81 | * multiple movement samples within a single object. The most current |
| 82 | * pointer coordinates are available using {@link #getX(int)} and {@link #getY(int)}. |
| 83 | * Earlier coordinates within the batch are accessed using {@link #getHistoricalX(int, int)} |
| 84 | * and {@link #getHistoricalY(int, int)}. The coordinates are "historical" only |
| 85 | * insofar as they are older than the current coordinates in the batch; however, |
| 86 | * they are still distinct from any other coordinates reported in prior motion events. |
| 87 | * To process all coordinates in the batch in time order, first consume the historical |
| 88 | * coordinates then consume the current coordinates. |
| 89 | * </p><p> |
| 90 | * Example: Consuming all samples for all pointers in a motion event in time order. |
| 91 | * </p><p><pre><code> |
| 92 | * void printSamples(MotionEvent ev) { |
| 93 | * final int historySize = ev.getHistorySize(); |
| 94 | * final int pointerCount = ev.getPointerCount(); |
| 95 | * for (int h = 0; h < historySize; h++) { |
| 96 | * System.out.printf("At time %d:", ev.getHistoricalEventTime(h)); |
| 97 | * for (int p = 0; p < pointerCount; p++) { |
| 98 | * System.out.printf(" pointer %d: (%f,%f)", |
| 99 | * ev.getPointerId(p), ev.getHistoricalX(p, h), ev.getHistoricalY(p, h)); |
| 100 | * } |
| 101 | * } |
| 102 | * System.out.printf("At time %d:", ev.getEventTime()); |
| 103 | * for (int p = 0; p < pointerCount; p++) { |
| 104 | * System.out.printf(" pointer %d: (%f,%f)", |
| 105 | * ev.getPointerId(p), ev.getX(p), ev.getY(p)); |
| 106 | * } |
| 107 | * } |
| 108 | * </code></pre></p> |
| 109 | * |
| 110 | * <h3>Device Types</h3> |
| 111 | * <p> |
| 112 | * The interpretation of the contents of a MotionEvent varies significantly depending |
| 113 | * on the source class of the device. |
| 114 | * </p><p> |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 115 | * On pointing devices with source class {@link InputDevice#SOURCE_CLASS_POINTER} |
| 116 | * such as touch screens, the pointer coordinates specify absolute |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 117 | * positions such as view X/Y coordinates. Each complete gesture is represented |
| 118 | * by a sequence of motion events with actions that describe pointer state transitions |
| 119 | * and movements. A gesture starts with a motion event with {@link #ACTION_DOWN} |
| 120 | * that provides the location of the first pointer down. As each additional |
| 121 | * pointer that goes down or up, the framework will generate a motion event with |
| 122 | * {@link #ACTION_POINTER_DOWN} or {@link #ACTION_POINTER_UP} accordingly. |
| 123 | * Pointer movements are described by motion events with {@link #ACTION_MOVE}. |
| 124 | * Finally, a gesture end either when the final pointer goes up as represented |
| 125 | * by a motion event with {@link #ACTION_UP} or when gesture is canceled |
| 126 | * with {@link #ACTION_CANCEL}. |
| 127 | * </p><p> |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 128 | * Some pointing devices such as mice may support vertical and/or horizontal scrolling. |
| 129 | * A scroll event is reported as a generic motion event with {@link #ACTION_SCROLL} that |
| 130 | * includes the relative scroll offset in the {@link #AXIS_VSCROLL} and |
| 131 | * {@link #AXIS_HSCROLL} axes. See {@link #getAxisValue(int)} for information |
| 132 | * about retrieving these additional axes. |
| 133 | * </p><p> |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 134 | * On trackball devices with source class {@link InputDevice#SOURCE_CLASS_TRACKBALL}, |
| 135 | * the pointer coordinates specify relative movements as X/Y deltas. |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 136 | * A trackball gesture consists of a sequence of movements described by motion |
| 137 | * events with {@link #ACTION_MOVE} interspersed with occasional {@link #ACTION_DOWN} |
| 138 | * or {@link #ACTION_UP} motion events when the trackball button is pressed or released. |
| 139 | * </p><p> |
Jeff Brown | cb1404e | 2011-01-15 18:14:15 -0800 | [diff] [blame] | 140 | * On joystick devices with source class {@link InputDevice#SOURCE_CLASS_JOYSTICK}, |
| 141 | * the pointer coordinates specify the absolute position of the joystick axes. |
| 142 | * The joystick axis values are normalized to a range of -1.0 to 1.0 where 0.0 corresponds |
| 143 | * to the center position. More information about the set of available axes and the |
| 144 | * range of motion can be obtained using {@link InputDevice#getMotionRange}. |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 145 | * Some common joystick axes are {@link #AXIS_X}, {@link #AXIS_Y}, |
| 146 | * {@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] | 147 | * </p><p> |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 148 | * Refer to {@link InputDevice} for more information about how different kinds of |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 149 | * input devices and sources represent pointer coordinates. |
Jeff Brown | dc1ab4b | 2010-09-14 18:03:38 -0700 | [diff] [blame] | 150 | * </p> |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 151 | * |
| 152 | * <h3>Consistency Guarantees</h3> |
| 153 | * <p> |
| 154 | * Motion events are always delivered to views as a consistent stream of events. |
| 155 | * What constitutes a consistent stream varies depending on the type of device. |
| 156 | * For touch events, consistency implies that pointers go down one at a time, |
| 157 | * move around as a group and then go up one at a time or are canceled. |
| 158 | * </p><p> |
| 159 | * While the framework tries to deliver consistent streams of motion events to |
| 160 | * views, it cannot guarantee it. Some events may be dropped or modified by |
| 161 | * containing views in the application before they are delivered thereby making |
| 162 | * the stream of events inconsistent. Views should always be prepared to |
| 163 | * handle {@link #ACTION_CANCEL} and should tolerate anomalous |
| 164 | * situations such as receiving a new {@link #ACTION_DOWN} without first having |
| 165 | * received an {@link #ACTION_UP} for the prior gesture. |
| 166 | * </p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 167 | */ |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 168 | public final class MotionEvent extends InputEvent implements Parcelable { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 169 | private static final long NS_PER_MS = 1000000; |
Michael Wright | 337d9d2 | 2014-04-22 15:03:48 -0700 | [diff] [blame] | 170 | private static final String LABEL_PREFIX = "AXIS_"; |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 171 | |
| 172 | /** |
| 173 | * An invalid pointer id. |
| 174 | * |
| 175 | * This value (-1) can be used as a placeholder to indicate that a pointer id |
| 176 | * has not been assigned or is not available. It cannot appear as |
| 177 | * a pointer id inside a {@link MotionEvent}. |
| 178 | */ |
| 179 | public static final int INVALID_POINTER_ID = -1; |
| 180 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 181 | /** |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 182 | * Bit mask of the parts of the action code that are the action itself. |
| 183 | */ |
| 184 | public static final int ACTION_MASK = 0xff; |
| 185 | |
| 186 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 187 | * Constant for {@link #getActionMasked}: A pressed gesture has started, the |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 188 | * motion contains the initial starting location. |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 189 | * <p> |
| 190 | * This is also a good time to check the button state to distinguish |
| 191 | * secondary and tertiary button clicks and handle them appropriately. |
| 192 | * Use {@link #getButtonState} to retrieve the button state. |
| 193 | * </p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 194 | */ |
| 195 | public static final int ACTION_DOWN = 0; |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 196 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 197 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 198 | * Constant for {@link #getActionMasked}: A pressed gesture has finished, the |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 199 | * motion contains the final release location as well as any intermediate |
| 200 | * points since the last down or move event. |
| 201 | */ |
| 202 | public static final int ACTION_UP = 1; |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 203 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 204 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 205 | * Constant for {@link #getActionMasked}: A change has happened during a |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 206 | * press gesture (between {@link #ACTION_DOWN} and {@link #ACTION_UP}). |
| 207 | * The motion contains the most recent point, as well as any intermediate |
| 208 | * points since the last down or move event. |
| 209 | */ |
| 210 | public static final int ACTION_MOVE = 2; |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 211 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 212 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 213 | * Constant for {@link #getActionMasked}: The current gesture has been aborted. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 214 | * You will not receive any more points in it. You should treat this as |
| 215 | * an up event, but not perform any action that you normally would. |
| 216 | */ |
| 217 | public static final int ACTION_CANCEL = 3; |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 218 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 219 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 220 | * Constant for {@link #getActionMasked}: A movement has happened outside of the |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 221 | * normal bounds of the UI element. This does not provide a full gesture, |
| 222 | * but only the initial location of the movement/touch. |
| 223 | */ |
| 224 | public static final int ACTION_OUTSIDE = 4; |
| 225 | |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 226 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 227 | * Constant for {@link #getActionMasked}: A non-primary pointer has gone down. |
| 228 | * <p> |
| 229 | * Use {@link #getActionIndex} to retrieve the index of the pointer that changed. |
| 230 | * </p><p> |
| 231 | * The index is encoded in the {@link #ACTION_POINTER_INDEX_MASK} bits of the |
| 232 | * unmasked action returned by {@link #getAction}. |
| 233 | * </p> |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 234 | */ |
| 235 | public static final int ACTION_POINTER_DOWN = 5; |
| 236 | |
| 237 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 238 | * Constant for {@link #getActionMasked}: A non-primary pointer has gone up. |
| 239 | * <p> |
| 240 | * Use {@link #getActionIndex} to retrieve the index of the pointer that changed. |
| 241 | * </p><p> |
| 242 | * The index is encoded in the {@link #ACTION_POINTER_INDEX_MASK} bits of the |
| 243 | * unmasked action returned by {@link #getAction}. |
| 244 | * </p> |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 245 | */ |
| 246 | public static final int ACTION_POINTER_UP = 6; |
Jeff Brown | cc0c159 | 2011-02-19 05:07:28 -0800 | [diff] [blame] | 247 | |
| 248 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 249 | * Constant for {@link #getActionMasked}: A change happened but the pointer |
Jeff Brown | cc0c159 | 2011-02-19 05:07:28 -0800 | [diff] [blame] | 250 | * is not down (unlike {@link #ACTION_MOVE}). The motion contains the most |
| 251 | * recent point, as well as any intermediate points since the last |
| 252 | * hover move event. |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 253 | * <p> |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 254 | * This action is always delivered to the window or view under the pointer. |
| 255 | * </p><p> |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 256 | * This action is not a touch event so it is delivered to |
| 257 | * {@link View#onGenericMotionEvent(MotionEvent)} rather than |
| 258 | * {@link View#onTouchEvent(MotionEvent)}. |
| 259 | * </p> |
Jeff Brown | cc0c159 | 2011-02-19 05:07:28 -0800 | [diff] [blame] | 260 | */ |
| 261 | public static final int ACTION_HOVER_MOVE = 7; |
| 262 | |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 263 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 264 | * Constant for {@link #getActionMasked}: The motion event contains relative |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 265 | * vertical and/or horizontal scroll offsets. Use {@link #getAxisValue(int)} |
| 266 | * to retrieve the information from {@link #AXIS_VSCROLL} and {@link #AXIS_HSCROLL}. |
| 267 | * The pointer may or may not be down when this event is dispatched. |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 268 | * <p> |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 269 | * This action is always delivered to the window or view under the pointer, which |
| 270 | * may not be the window or view currently touched. |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 271 | * </p><p> |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 272 | * This action is not a touch event so it is delivered to |
| 273 | * {@link View#onGenericMotionEvent(MotionEvent)} rather than |
| 274 | * {@link View#onTouchEvent(MotionEvent)}. |
| 275 | * </p> |
| 276 | */ |
| 277 | public static final int ACTION_SCROLL = 8; |
| 278 | |
| 279 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 280 | * Constant for {@link #getActionMasked}: The pointer is not down but has entered the |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 281 | * boundaries of a window or view. |
| 282 | * <p> |
| 283 | * This action is always delivered to the window or view under the pointer. |
| 284 | * </p><p> |
| 285 | * This action is not a touch event so it is delivered to |
| 286 | * {@link View#onGenericMotionEvent(MotionEvent)} rather than |
| 287 | * {@link View#onTouchEvent(MotionEvent)}. |
| 288 | * </p> |
| 289 | */ |
| 290 | public static final int ACTION_HOVER_ENTER = 9; |
| 291 | |
| 292 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 293 | * Constant for {@link #getActionMasked}: The pointer is not down but has exited the |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 294 | * boundaries of a window or view. |
| 295 | * <p> |
| 296 | * This action is always delivered to the window or view that was previously under the pointer. |
| 297 | * </p><p> |
| 298 | * This action is not a touch event so it is delivered to |
| 299 | * {@link View#onGenericMotionEvent(MotionEvent)} rather than |
| 300 | * {@link View#onTouchEvent(MotionEvent)}. |
| 301 | * </p> |
| 302 | */ |
| 303 | public static final int ACTION_HOVER_EXIT = 10; |
| 304 | |
| 305 | /** |
Michael Wright | 5bd69e6 | 2015-05-14 14:48:08 +0100 | [diff] [blame] | 306 | * Constant for {@link #getActionMasked}: A button has been pressed. |
| 307 | * |
| 308 | * <p> |
| 309 | * Use {@link #getActionButton()} to get which button was pressed. |
| 310 | * </p><p> |
| 311 | * This action is not a touch event so it is delivered to |
| 312 | * {@link View#onGenericMotionEvent(MotionEvent)} rather than |
| 313 | * {@link View#onTouchEvent(MotionEvent)}. |
| 314 | * </p> |
| 315 | */ |
| 316 | public static final int ACTION_BUTTON_PRESS = 11; |
| 317 | |
| 318 | /** |
| 319 | * Constant for {@link #getActionMasked}: A button has been released. |
| 320 | * |
| 321 | * <p> |
| 322 | * Use {@link #getActionButton()} to get which button was released. |
| 323 | * </p><p> |
| 324 | * This action is not a touch event so it is delivered to |
| 325 | * {@link View#onGenericMotionEvent(MotionEvent)} rather than |
| 326 | * {@link View#onTouchEvent(MotionEvent)}. |
| 327 | * </p> |
| 328 | */ |
| 329 | public static final int ACTION_BUTTON_RELEASE = 12; |
| 330 | |
| 331 | /** |
Dianne Hackborn | b125dc5 | 2010-02-12 15:52:09 -0800 | [diff] [blame] | 332 | * Bits in the action code that represent a pointer index, used with |
| 333 | * {@link #ACTION_POINTER_DOWN} and {@link #ACTION_POINTER_UP}. Shifting |
| 334 | * down by {@link #ACTION_POINTER_INDEX_SHIFT} provides the actual pointer |
| 335 | * index where the data for the pointer going up or down can be found; you can |
| 336 | * get its identifier with {@link #getPointerId(int)} and the actual |
| 337 | * data with {@link #getX(int)} etc. |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 338 | * |
| 339 | * @see #getActionIndex |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 340 | */ |
Dianne Hackborn | b125dc5 | 2010-02-12 15:52:09 -0800 | [diff] [blame] | 341 | public static final int ACTION_POINTER_INDEX_MASK = 0xff00; |
| 342 | |
| 343 | /** |
| 344 | * Bit shift for the action bits holding the pointer index as |
| 345 | * defined by {@link #ACTION_POINTER_INDEX_MASK}. |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 346 | * |
| 347 | * @see #getActionIndex |
Dianne Hackborn | b125dc5 | 2010-02-12 15:52:09 -0800 | [diff] [blame] | 348 | */ |
| 349 | public static final int ACTION_POINTER_INDEX_SHIFT = 8; |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 350 | |
Dianne Hackborn | b125dc5 | 2010-02-12 15:52:09 -0800 | [diff] [blame] | 351 | /** |
| 352 | * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the |
| 353 | * data index associated with {@link #ACTION_POINTER_DOWN}. |
| 354 | */ |
| 355 | @Deprecated |
| 356 | public static final int ACTION_POINTER_1_DOWN = ACTION_POINTER_DOWN | 0x0000; |
| 357 | |
| 358 | /** |
| 359 | * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the |
| 360 | * data index associated with {@link #ACTION_POINTER_DOWN}. |
| 361 | */ |
| 362 | @Deprecated |
| 363 | public static final int ACTION_POINTER_2_DOWN = ACTION_POINTER_DOWN | 0x0100; |
| 364 | |
| 365 | /** |
| 366 | * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the |
| 367 | * data index associated with {@link #ACTION_POINTER_DOWN}. |
| 368 | */ |
| 369 | @Deprecated |
| 370 | public static final int ACTION_POINTER_3_DOWN = ACTION_POINTER_DOWN | 0x0200; |
| 371 | |
| 372 | /** |
| 373 | * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the |
| 374 | * data index associated with {@link #ACTION_POINTER_UP}. |
| 375 | */ |
| 376 | @Deprecated |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 377 | public static final int ACTION_POINTER_1_UP = ACTION_POINTER_UP | 0x0000; |
| 378 | |
| 379 | /** |
Dianne Hackborn | b125dc5 | 2010-02-12 15:52:09 -0800 | [diff] [blame] | 380 | * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the |
| 381 | * data index associated with {@link #ACTION_POINTER_UP}. |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 382 | */ |
Dianne Hackborn | b125dc5 | 2010-02-12 15:52:09 -0800 | [diff] [blame] | 383 | @Deprecated |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 384 | public static final int ACTION_POINTER_2_UP = ACTION_POINTER_UP | 0x0100; |
| 385 | |
| 386 | /** |
Dianne Hackborn | b125dc5 | 2010-02-12 15:52:09 -0800 | [diff] [blame] | 387 | * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the |
| 388 | * data index associated with {@link #ACTION_POINTER_UP}. |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 389 | */ |
Dianne Hackborn | b125dc5 | 2010-02-12 15:52:09 -0800 | [diff] [blame] | 390 | @Deprecated |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 391 | public static final int ACTION_POINTER_3_UP = ACTION_POINTER_UP | 0x0200; |
| 392 | |
| 393 | /** |
Dianne Hackborn | b125dc5 | 2010-02-12 15:52:09 -0800 | [diff] [blame] | 394 | * @deprecated Renamed to {@link #ACTION_POINTER_INDEX_MASK} to match |
| 395 | * the actual data contained in these bits. |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 396 | */ |
Dianne Hackborn | b125dc5 | 2010-02-12 15:52:09 -0800 | [diff] [blame] | 397 | @Deprecated |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 398 | public static final int ACTION_POINTER_ID_MASK = 0xff00; |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 399 | |
| 400 | /** |
Dianne Hackborn | b125dc5 | 2010-02-12 15:52:09 -0800 | [diff] [blame] | 401 | * @deprecated Renamed to {@link #ACTION_POINTER_INDEX_SHIFT} to match |
| 402 | * the actual data contained in these bits. |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 403 | */ |
Dianne Hackborn | b125dc5 | 2010-02-12 15:52:09 -0800 | [diff] [blame] | 404 | @Deprecated |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 405 | public static final int ACTION_POINTER_ID_SHIFT = 8; |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 406 | |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 407 | /** |
| 408 | * This flag indicates that the window that received this motion event is partly |
| 409 | * or wholly obscured by another visible window above it. This flag is set to true |
| 410 | * even if the event did not directly pass through the obscured area. |
| 411 | * A security sensitive application can check this flag to identify situations in which |
| 412 | * a malicious application may have covered up part of its content for the purpose |
| 413 | * of misleading the user or hijacking touches. An appropriate response might be |
| 414 | * to drop the suspect touches or to take additional precautions to confirm the user's |
| 415 | * actual intent. |
| 416 | */ |
| 417 | public static final int FLAG_WINDOW_IS_OBSCURED = 0x1; |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 418 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 419 | /** |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 420 | * Private flag that indicates when the system has detected that this motion event |
| 421 | * may be inconsistent with respect to the sequence of previously delivered motion events, |
| 422 | * such as when a pointer move event is sent but the pointer is not down. |
| 423 | * |
| 424 | * @hide |
| 425 | * @see #isTainted |
| 426 | * @see #setTainted |
| 427 | */ |
| 428 | public static final int FLAG_TAINTED = 0x80000000; |
| 429 | |
| 430 | /** |
Svetoslav | ded133c | 2015-01-30 20:28:41 -0800 | [diff] [blame] | 431 | * Private flag indicating that this event was synthesized by the system and |
| 432 | * should be delivered to the accessibility focused view first. When being |
| 433 | * dispatched such an event is not handled by predecessors of the accessibility |
| 434 | * focused view and after the event reaches that view the flag is cleared and |
| 435 | * normal event dispatch is performed. This ensures that the platform can click |
| 436 | * on any view that has accessibility focus which is semantically equivalent to |
| 437 | * asking the view to perform a click accessibility action but more generic as |
| 438 | * views not implementing click action correctly can still be activated. |
| 439 | * |
| 440 | * @hide |
| 441 | * @see #isTargetAccessibilityFocus() |
| 442 | * @see #setTargetAccessibilityFocus(boolean) |
| 443 | */ |
| 444 | public static final int FLAG_TARGET_ACCESSIBILITY_FOCUS = 0x40000000; |
| 445 | |
| 446 | |
| 447 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 448 | * Flag indicating the motion event intersected the top edge of the screen. |
| 449 | */ |
| 450 | public static final int EDGE_TOP = 0x00000001; |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 451 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 452 | /** |
| 453 | * Flag indicating the motion event intersected the bottom edge of the screen. |
| 454 | */ |
| 455 | public static final int EDGE_BOTTOM = 0x00000002; |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 456 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 457 | /** |
| 458 | * Flag indicating the motion event intersected the left edge of the screen. |
| 459 | */ |
| 460 | public static final int EDGE_LEFT = 0x00000004; |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 461 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 462 | /** |
| 463 | * Flag indicating the motion event intersected the right edge of the screen. |
| 464 | */ |
| 465 | public static final int EDGE_RIGHT = 0x00000008; |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 466 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 467 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 468 | * Axis constant: X axis of a motion event. |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 469 | * <p> |
| 470 | * <ul> |
| 471 | * <li>For a touch screen, reports the absolute X screen position of the center of |
| 472 | * the touch contact area. The units are display pixels. |
| 473 | * <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] | 474 | * contact area. The units are device-dependent; use {@link InputDevice#getMotionRange(int)} |
| 475 | * to query the effective range of values. |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 476 | * <li>For a mouse, reports the absolute X screen position of the mouse pointer. |
| 477 | * The units are display pixels. |
| 478 | * <li>For a trackball, reports the relative horizontal displacement of the trackball. |
| 479 | * The value is normalized to a range from -1.0 (left) to 1.0 (right). |
| 480 | * <li>For a joystick, reports the absolute X position of the joystick. |
| 481 | * The value is normalized to a range from -1.0 (left) to 1.0 (right). |
| 482 | * </ul> |
| 483 | * </p> |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 484 | * |
| 485 | * @see #getX(int) |
| 486 | * @see #getHistoricalX(int, int) |
| 487 | * @see MotionEvent.PointerCoords#x |
| 488 | * @see InputDevice#getMotionRange |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 489 | */ |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 490 | public static final int AXIS_X = 0; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 491 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 492 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 493 | * Axis constant: Y axis of a motion event. |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 494 | * <p> |
| 495 | * <ul> |
| 496 | * <li>For a touch screen, reports the absolute Y screen position of the center of |
| 497 | * the touch contact area. The units are display pixels. |
| 498 | * <li>For a touch pad, reports the absolute Y surface position of the center of the touch |
| 499 | * contact area. The units are device-dependent; use {@link InputDevice#getMotionRange(int)} |
| 500 | * to query the effective range of values. |
| 501 | * <li>For a mouse, reports the absolute Y screen position of the mouse pointer. |
| 502 | * The units are display pixels. |
| 503 | * <li>For a trackball, reports the relative vertical displacement of the trackball. |
| 504 | * The value is normalized to a range from -1.0 (up) to 1.0 (down). |
| 505 | * <li>For a joystick, reports the absolute Y position of the joystick. |
| 506 | * The value is normalized to a range from -1.0 (up or far) to 1.0 (down or near). |
| 507 | * </ul> |
| 508 | * </p> |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 509 | * |
| 510 | * @see #getY(int) |
| 511 | * @see #getHistoricalY(int, int) |
| 512 | * @see MotionEvent.PointerCoords#y |
| 513 | * @see InputDevice#getMotionRange |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 514 | */ |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 515 | public static final int AXIS_Y = 1; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 516 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 517 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 518 | * Axis constant: Pressure axis of a motion event. |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 519 | * <p> |
| 520 | * <ul> |
Jeff Brown | cc0c159 | 2011-02-19 05:07:28 -0800 | [diff] [blame] | 521 | * <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] | 522 | * by a finger or other tool. The value is normalized to a range from |
| 523 | * 0 (no pressure at all) to 1 (normal pressure), although values higher than 1 |
| 524 | * may be generated depending on the calibration of the input device. |
| 525 | * <li>For a trackball, the value is set to 1 if the trackball button is pressed |
| 526 | * or 0 otherwise. |
| 527 | * <li>For a mouse, the value is set to 1 if the primary mouse button is pressed |
| 528 | * or 0 otherwise. |
| 529 | * </ul> |
| 530 | * </p> |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 531 | * |
| 532 | * @see #getPressure(int) |
| 533 | * @see #getHistoricalPressure(int, int) |
| 534 | * @see MotionEvent.PointerCoords#pressure |
| 535 | * @see InputDevice#getMotionRange |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 536 | */ |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 537 | public static final int AXIS_PRESSURE = 2; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 538 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 539 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 540 | * Axis constant: Size axis of a motion event. |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 541 | * <p> |
| 542 | * <ul> |
| 543 | * <li>For a touch screen or touch pad, reports the approximate size of the contact area in |
| 544 | * relation to the maximum detectable size for the device. The value is normalized |
| 545 | * 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] | 546 | * 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] | 547 | * To obtain calibrated size information, use |
| 548 | * {@link #AXIS_TOUCH_MAJOR} or {@link #AXIS_TOOL_MAJOR}. |
| 549 | * </ul> |
| 550 | * </p> |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 551 | * |
| 552 | * @see #getSize(int) |
| 553 | * @see #getHistoricalSize(int, int) |
| 554 | * @see MotionEvent.PointerCoords#size |
| 555 | * @see InputDevice#getMotionRange |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 556 | */ |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 557 | public static final int AXIS_SIZE = 3; |
| 558 | |
| 559 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 560 | * Axis constant: TouchMajor axis of a motion event. |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 561 | * <p> |
| 562 | * <ul> |
| 563 | * <li>For a touch screen, reports the length of the major axis of an ellipse that |
| 564 | * represents the touch area at the point of contact. |
| 565 | * The units are display pixels. |
| 566 | * <li>For a touch pad, reports the length of the major axis of an ellipse that |
| 567 | * represents the touch area at the point of contact. |
| 568 | * The units are device-dependent; use {@link InputDevice#getMotionRange(int)} |
| 569 | * to query the effective range of values. |
| 570 | * </ul> |
| 571 | * </p> |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 572 | * |
| 573 | * @see #getTouchMajor(int) |
| 574 | * @see #getHistoricalTouchMajor(int, int) |
| 575 | * @see MotionEvent.PointerCoords#touchMajor |
| 576 | * @see InputDevice#getMotionRange |
Dianne Hackborn | 1e8dfc7 | 2009-08-06 12:43:01 -0700 | [diff] [blame] | 577 | */ |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 578 | public static final int AXIS_TOUCH_MAJOR = 4; |
| 579 | |
| 580 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 581 | * Axis constant: TouchMinor axis of a motion event. |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 582 | * <p> |
| 583 | * <ul> |
| 584 | * <li>For a touch screen, reports the length of the minor axis of an ellipse that |
| 585 | * represents the touch area at the point of contact. |
| 586 | * The units are display pixels. |
| 587 | * <li>For a touch pad, reports the length of the minor axis of an ellipse that |
| 588 | * represents the touch area at the point of contact. |
| 589 | * The units are device-dependent; use {@link InputDevice#getMotionRange(int)} |
| 590 | * to query the effective range of values. |
| 591 | * </ul> |
| 592 | * </p><p> |
| 593 | * When the touch is circular, the major and minor axis lengths will be equal to one another. |
| 594 | * </p> |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 595 | * |
| 596 | * @see #getTouchMinor(int) |
| 597 | * @see #getHistoricalTouchMinor(int, int) |
| 598 | * @see MotionEvent.PointerCoords#touchMinor |
| 599 | * @see InputDevice#getMotionRange |
Jeff Brown | 9e2ad36 | 2010-07-30 19:20:11 -0700 | [diff] [blame] | 600 | */ |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 601 | public static final int AXIS_TOUCH_MINOR = 5; |
| 602 | |
| 603 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 604 | * Axis constant: ToolMajor axis of a motion event. |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 605 | * <p> |
| 606 | * <ul> |
| 607 | * <li>For a touch screen, reports the length of the major axis of an ellipse that |
| 608 | * represents the size of the approaching finger or tool used to make contact. |
| 609 | * <li>For a touch pad, reports the length of the major axis of an ellipse that |
| 610 | * represents the size of the approaching finger or tool used to make contact. |
| 611 | * The units are device-dependent; use {@link InputDevice#getMotionRange(int)} |
| 612 | * to query the effective range of values. |
| 613 | * </ul> |
| 614 | * </p><p> |
| 615 | * When the touch is circular, the major and minor axis lengths will be equal to one another. |
| 616 | * </p><p> |
| 617 | * The tool size may be larger than the touch size since the tool may not be fully |
| 618 | * in contact with the touch sensor. |
| 619 | * </p> |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 620 | * |
| 621 | * @see #getToolMajor(int) |
| 622 | * @see #getHistoricalToolMajor(int, int) |
| 623 | * @see MotionEvent.PointerCoords#toolMajor |
| 624 | * @see InputDevice#getMotionRange |
| 625 | */ |
| 626 | public static final int AXIS_TOOL_MAJOR = 6; |
| 627 | |
| 628 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 629 | * Axis constant: ToolMinor axis of a motion event. |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 630 | * <p> |
| 631 | * <ul> |
| 632 | * <li>For a touch screen, reports the length of the minor axis of an ellipse that |
| 633 | * represents the size of the approaching finger or tool used to make contact. |
| 634 | * <li>For a touch pad, reports the length of the minor axis of an ellipse that |
| 635 | * represents the size of the approaching finger or tool used to make contact. |
| 636 | * The units are device-dependent; use {@link InputDevice#getMotionRange(int)} |
| 637 | * to query the effective range of values. |
| 638 | * </ul> |
| 639 | * </p><p> |
| 640 | * When the touch is circular, the major and minor axis lengths will be equal to one another. |
| 641 | * </p><p> |
| 642 | * The tool size may be larger than the touch size since the tool may not be fully |
| 643 | * in contact with the touch sensor. |
| 644 | * </p> |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 645 | * |
| 646 | * @see #getToolMinor(int) |
| 647 | * @see #getHistoricalToolMinor(int, int) |
| 648 | * @see MotionEvent.PointerCoords#toolMinor |
| 649 | * @see InputDevice#getMotionRange |
| 650 | */ |
| 651 | public static final int AXIS_TOOL_MINOR = 7; |
| 652 | |
| 653 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 654 | * Axis constant: Orientation axis of a motion event. |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 655 | * <p> |
| 656 | * <ul> |
| 657 | * <li>For a touch screen or touch pad, reports the orientation of the finger |
| 658 | * or tool in radians relative to the vertical plane of the device. |
| 659 | * 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] | 660 | * upwards, is perfectly circular or is of unknown orientation. A positive angle |
| 661 | * indicates that the major axis of contact is oriented to the right. A negative angle |
| 662 | * indicates that the major axis of contact is oriented to the left. |
| 663 | * The full range is from -PI/2 radians (finger pointing fully left) to PI/2 radians |
| 664 | * (finger pointing fully right). |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 665 | * <li>For a stylus, the orientation indicates the direction in which the stylus |
| 666 | * is pointing in relation to the vertical axis of the current orientation of the screen. |
| 667 | * The range is from -PI radians to PI radians, where 0 is pointing up, |
| 668 | * -PI/2 radians is pointing left, -PI or PI radians is pointing down, and PI/2 radians |
| 669 | * is pointing right. See also {@link #AXIS_TILT}. |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 670 | * </ul> |
| 671 | * </p> |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 672 | * |
| 673 | * @see #getOrientation(int) |
| 674 | * @see #getHistoricalOrientation(int, int) |
| 675 | * @see MotionEvent.PointerCoords#orientation |
| 676 | * @see InputDevice#getMotionRange |
| 677 | */ |
| 678 | public static final int AXIS_ORIENTATION = 8; |
| 679 | |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 680 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 681 | * Axis constant: Vertical Scroll axis of a motion event. |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 682 | * <p> |
| 683 | * <ul> |
Jeff Brown | cc0c159 | 2011-02-19 05:07:28 -0800 | [diff] [blame] | 684 | * <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] | 685 | * 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] | 686 | * </ul> |
| 687 | * </p><p> |
| 688 | * This axis should be used to scroll views vertically. |
| 689 | * </p> |
| 690 | * |
| 691 | * @see #getAxisValue(int, int) |
| 692 | * @see #getHistoricalAxisValue(int, int, int) |
| 693 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 694 | * @see InputDevice#getMotionRange |
| 695 | */ |
| 696 | public static final int AXIS_VSCROLL = 9; |
| 697 | |
| 698 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 699 | * Axis constant: Horizontal Scroll axis of a motion event. |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 700 | * <p> |
| 701 | * <ul> |
Jeff Brown | cc0c159 | 2011-02-19 05:07:28 -0800 | [diff] [blame] | 702 | * <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] | 703 | * The value is normalized to a range from -1.0 (left) to 1.0 (right). |
| 704 | * </ul> |
| 705 | * </p><p> |
| 706 | * This axis should be used to scroll views horizontally. |
| 707 | * </p> |
| 708 | * |
| 709 | * @see #getAxisValue(int, int) |
| 710 | * @see #getHistoricalAxisValue(int, int, int) |
| 711 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 712 | * @see InputDevice#getMotionRange |
| 713 | */ |
| 714 | public static final int AXIS_HSCROLL = 10; |
| 715 | |
| 716 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 717 | * Axis constant: Z axis of a motion event. |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 718 | * <p> |
| 719 | * <ul> |
| 720 | * <li>For a joystick, reports the absolute Z position of the joystick. |
| 721 | * The value is normalized to a range from -1.0 (high) to 1.0 (low). |
| 722 | * <em>On game pads with two analog joysticks, this axis is often reinterpreted |
| 723 | * to report the absolute X position of the second joystick instead.</em> |
| 724 | * </ul> |
| 725 | * </p> |
| 726 | * |
| 727 | * @see #getAxisValue(int, int) |
| 728 | * @see #getHistoricalAxisValue(int, int, int) |
| 729 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 730 | * @see InputDevice#getMotionRange |
| 731 | */ |
| 732 | public static final int AXIS_Z = 11; |
| 733 | |
| 734 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 735 | * Axis constant: X Rotation axis of a motion event. |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 736 | * <p> |
| 737 | * <ul> |
| 738 | * <li>For a joystick, reports the absolute rotation angle about the X axis. |
| 739 | * The value is normalized to a range from -1.0 (counter-clockwise) to 1.0 (clockwise). |
| 740 | * </ul> |
| 741 | * </p> |
| 742 | * |
| 743 | * @see #getAxisValue(int, int) |
| 744 | * @see #getHistoricalAxisValue(int, int, int) |
| 745 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 746 | * @see InputDevice#getMotionRange |
| 747 | */ |
| 748 | public static final int AXIS_RX = 12; |
| 749 | |
| 750 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 751 | * Axis constant: Y Rotation axis of a motion event. |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 752 | * <p> |
| 753 | * <ul> |
| 754 | * <li>For a joystick, reports the absolute rotation angle about the Y axis. |
| 755 | * The value is normalized to a range from -1.0 (counter-clockwise) to 1.0 (clockwise). |
| 756 | * </ul> |
| 757 | * </p> |
| 758 | * |
| 759 | * @see #getAxisValue(int, int) |
| 760 | * @see #getHistoricalAxisValue(int, int, int) |
| 761 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 762 | * @see InputDevice#getMotionRange |
| 763 | */ |
| 764 | public static final int AXIS_RY = 13; |
| 765 | |
| 766 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 767 | * Axis constant: Z Rotation axis of a motion event. |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 768 | * <p> |
| 769 | * <ul> |
| 770 | * <li>For a joystick, reports the absolute rotation angle about the Z axis. |
| 771 | * The value is normalized to a range from -1.0 (counter-clockwise) to 1.0 (clockwise). |
| 772 | * <em>On game pads with two analog joysticks, this axis is often reinterpreted |
| 773 | * to report the absolute Y position of the second joystick instead.</em> |
| 774 | * </ul> |
| 775 | * </p> |
| 776 | * |
| 777 | * @see #getAxisValue(int, int) |
| 778 | * @see #getHistoricalAxisValue(int, int, int) |
| 779 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 780 | * @see InputDevice#getMotionRange |
| 781 | */ |
| 782 | public static final int AXIS_RZ = 14; |
| 783 | |
| 784 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 785 | * Axis constant: Hat X axis of a motion event. |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 786 | * <p> |
| 787 | * <ul> |
| 788 | * <li>For a joystick, reports the absolute X position of the directional hat control. |
| 789 | * The value is normalized to a range from -1.0 (left) to 1.0 (right). |
| 790 | * </ul> |
| 791 | * </p> |
| 792 | * |
| 793 | * @see #getAxisValue(int, int) |
| 794 | * @see #getHistoricalAxisValue(int, int, int) |
| 795 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 796 | * @see InputDevice#getMotionRange |
| 797 | */ |
| 798 | public static final int AXIS_HAT_X = 15; |
| 799 | |
| 800 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 801 | * Axis constant: Hat Y axis of a motion event. |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 802 | * <p> |
| 803 | * <ul> |
| 804 | * <li>For a joystick, reports the absolute Y position of the directional hat control. |
| 805 | * The value is normalized to a range from -1.0 (up) to 1.0 (down). |
| 806 | * </ul> |
| 807 | * </p> |
| 808 | * |
| 809 | * @see #getAxisValue(int, int) |
| 810 | * @see #getHistoricalAxisValue(int, int, int) |
| 811 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 812 | * @see InputDevice#getMotionRange |
| 813 | */ |
| 814 | public static final int AXIS_HAT_Y = 16; |
| 815 | |
| 816 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 817 | * Axis constant: Left Trigger axis of a motion event. |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 818 | * <p> |
| 819 | * <ul> |
| 820 | * <li>For a joystick, reports the absolute position of the left trigger control. |
| 821 | * The value is normalized to a range from 0.0 (released) to 1.0 (fully pressed). |
| 822 | * </ul> |
| 823 | * </p> |
| 824 | * |
| 825 | * @see #getAxisValue(int, int) |
| 826 | * @see #getHistoricalAxisValue(int, int, int) |
| 827 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 828 | * @see InputDevice#getMotionRange |
| 829 | */ |
| 830 | public static final int AXIS_LTRIGGER = 17; |
| 831 | |
| 832 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 833 | * Axis constant: Right Trigger axis of a motion event. |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 834 | * <p> |
| 835 | * <ul> |
| 836 | * <li>For a joystick, reports the absolute position of the right trigger control. |
| 837 | * The value is normalized to a range from 0.0 (released) to 1.0 (fully pressed). |
| 838 | * </ul> |
| 839 | * </p> |
| 840 | * |
| 841 | * @see #getAxisValue(int, int) |
| 842 | * @see #getHistoricalAxisValue(int, int, int) |
| 843 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 844 | * @see InputDevice#getMotionRange |
| 845 | */ |
| 846 | public static final int AXIS_RTRIGGER = 18; |
| 847 | |
| 848 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 849 | * Axis constant: Throttle axis of a motion event. |
Jeff Brown | 3a22fa0 | 2011-03-04 13:07:49 -0800 | [diff] [blame] | 850 | * <p> |
| 851 | * <ul> |
| 852 | * <li>For a joystick, reports the absolute position of the throttle control. |
| 853 | * The value is normalized to a range from 0.0 (fully open) to 1.0 (fully closed). |
| 854 | * </ul> |
| 855 | * </p> |
| 856 | * |
| 857 | * @see #getAxisValue(int, int) |
| 858 | * @see #getHistoricalAxisValue(int, int, int) |
| 859 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 860 | * @see InputDevice#getMotionRange |
| 861 | */ |
| 862 | public static final int AXIS_THROTTLE = 19; |
| 863 | |
| 864 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 865 | * Axis constant: Rudder axis of a motion event. |
Jeff Brown | 3a22fa0 | 2011-03-04 13:07:49 -0800 | [diff] [blame] | 866 | * <p> |
| 867 | * <ul> |
| 868 | * <li>For a joystick, reports the absolute position of the rudder control. |
| 869 | * The value is normalized to a range from -1.0 (turn left) to 1.0 (turn right). |
| 870 | * </ul> |
| 871 | * </p> |
| 872 | * |
| 873 | * @see #getAxisValue(int, int) |
| 874 | * @see #getHistoricalAxisValue(int, int, int) |
| 875 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 876 | * @see InputDevice#getMotionRange |
| 877 | */ |
| 878 | public static final int AXIS_RUDDER = 20; |
| 879 | |
| 880 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 881 | * Axis constant: Wheel axis of a motion event. |
Jeff Brown | 3a22fa0 | 2011-03-04 13:07:49 -0800 | [diff] [blame] | 882 | * <p> |
| 883 | * <ul> |
| 884 | * <li>For a joystick, reports the absolute position of the steering wheel control. |
| 885 | * The value is normalized to a range from -1.0 (turn left) to 1.0 (turn right). |
| 886 | * </ul> |
| 887 | * </p> |
| 888 | * |
| 889 | * @see #getAxisValue(int, int) |
| 890 | * @see #getHistoricalAxisValue(int, int, int) |
| 891 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 892 | * @see InputDevice#getMotionRange |
| 893 | */ |
| 894 | public static final int AXIS_WHEEL = 21; |
| 895 | |
| 896 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 897 | * Axis constant: Gas axis of a motion event. |
Jeff Brown | 3a22fa0 | 2011-03-04 13:07:49 -0800 | [diff] [blame] | 898 | * <p> |
| 899 | * <ul> |
| 900 | * <li>For a joystick, reports the absolute position of the gas (accelerator) control. |
| 901 | * The value is normalized to a range from 0.0 (no acceleration) |
| 902 | * to 1.0 (maximum acceleration). |
| 903 | * </ul> |
| 904 | * </p> |
| 905 | * |
| 906 | * @see #getAxisValue(int, int) |
| 907 | * @see #getHistoricalAxisValue(int, int, int) |
| 908 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 909 | * @see InputDevice#getMotionRange |
| 910 | */ |
| 911 | public static final int AXIS_GAS = 22; |
| 912 | |
| 913 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 914 | * Axis constant: Brake axis of a motion event. |
Jeff Brown | 3a22fa0 | 2011-03-04 13:07:49 -0800 | [diff] [blame] | 915 | * <p> |
| 916 | * <ul> |
| 917 | * <li>For a joystick, reports the absolute position of the brake control. |
| 918 | * The value is normalized to a range from 0.0 (no braking) to 1.0 (maximum braking). |
| 919 | * </ul> |
| 920 | * </p> |
| 921 | * |
| 922 | * @see #getAxisValue(int, int) |
| 923 | * @see #getHistoricalAxisValue(int, int, int) |
| 924 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 925 | * @see InputDevice#getMotionRange |
| 926 | */ |
| 927 | public static final int AXIS_BRAKE = 23; |
| 928 | |
| 929 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 930 | * Axis constant: Distance axis of a motion event. |
| 931 | * <p> |
| 932 | * <ul> |
| 933 | * <li>For a stylus, reports the distance of the stylus from the screen. |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 934 | * A value of 0.0 indicates direct contact and larger values indicate increasing |
| 935 | * distance from the surface. |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 936 | * </ul> |
| 937 | * </p> |
| 938 | * |
| 939 | * @see #getAxisValue(int, int) |
| 940 | * @see #getHistoricalAxisValue(int, int, int) |
| 941 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 942 | * @see InputDevice#getMotionRange |
| 943 | */ |
| 944 | public static final int AXIS_DISTANCE = 24; |
| 945 | |
| 946 | /** |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 947 | * Axis constant: Tilt axis of a motion event. |
| 948 | * <p> |
| 949 | * <ul> |
| 950 | * <li>For a stylus, reports the tilt angle of the stylus in radians where |
| 951 | * 0 radians indicates that the stylus is being held perpendicular to the |
| 952 | * surface, and PI/2 radians indicates that the stylus is being held flat |
| 953 | * against the surface. |
| 954 | * </ul> |
| 955 | * </p> |
| 956 | * |
| 957 | * @see #getAxisValue(int, int) |
| 958 | * @see #getHistoricalAxisValue(int, int, int) |
| 959 | * @see MotionEvent.PointerCoords#getAxisValue(int, int) |
| 960 | * @see InputDevice#getMotionRange |
| 961 | */ |
| 962 | public static final int AXIS_TILT = 25; |
| 963 | |
| 964 | /** |
Prashant Malani | 67322b1 | 2015-08-25 17:41:34 -0700 | [diff] [blame] | 965 | * Axis constant: Generic scroll axis of a motion event. |
| 966 | * <p> |
| 967 | * <ul> |
| 968 | * <li>Reports the relative movement of the generic scrolling device. |
| 969 | * </ul> |
| 970 | * </p><p> |
| 971 | * This axis should be used for scroll events that are neither strictly vertical nor horizontal. |
| 972 | * A good example would be the rotation of a rotary encoder input device. |
| 973 | * </p> |
| 974 | * |
| 975 | * @see #getAxisValue(int, int) |
Prashant Malani | 8171658 | 2016-01-06 13:31:14 -0800 | [diff] [blame] | 976 | * {@hide} |
Prashant Malani | 67322b1 | 2015-08-25 17:41:34 -0700 | [diff] [blame] | 977 | */ |
| 978 | public static final int AXIS_SCROLL = 26; |
| 979 | |
| 980 | /** |
Jun Mukai | 347e5d4 | 2015-12-03 01:13:31 -0800 | [diff] [blame] | 981 | * Axis constant: The movement of x position of a motion event. |
| 982 | * <p> |
| 983 | * <ul> |
| 984 | * <li>For a mouse, reports a difference of x position between the previous position. |
| 985 | * This is useful when pointer is captured, in that case the mouse pointer doesn't change |
| 986 | * the location but this axis reports the difference which allows the app to see |
| 987 | * how the mouse is moved. |
| 988 | * </ul> |
| 989 | * </p> |
| 990 | * |
| 991 | * @see #getAxisValue(int, int) |
| 992 | * @see #getHistoricalAxisValue(int, int, int) |
| 993 | * @see MotionEvent.PointerCoords#getAxisValue(int, int) |
| 994 | * @see InputDevice#getMotionRange |
| 995 | */ |
| 996 | public static final int AXIS_RELATIVE_X = 27; |
| 997 | |
| 998 | /** |
| 999 | * Axis constant: The movement of y position of a motion event. |
| 1000 | * <p> |
| 1001 | * This is similar to {@link #AXIS_RELATIVE_X} but for y-axis. |
| 1002 | * </p> |
| 1003 | * |
| 1004 | * @see #getAxisValue(int, int) |
| 1005 | * @see #getHistoricalAxisValue(int, int, int) |
| 1006 | * @see MotionEvent.PointerCoords#getAxisValue(int, int) |
| 1007 | * @see InputDevice#getMotionRange |
| 1008 | */ |
| 1009 | public static final int AXIS_RELATIVE_Y = 28; |
| 1010 | |
| 1011 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 1012 | * Axis constant: Generic 1 axis of a motion event. |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 1013 | * The interpretation of a generic axis is device-specific. |
| 1014 | * |
| 1015 | * @see #getAxisValue(int, int) |
| 1016 | * @see #getHistoricalAxisValue(int, int, int) |
| 1017 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 1018 | * @see InputDevice#getMotionRange |
| 1019 | */ |
| 1020 | public static final int AXIS_GENERIC_1 = 32; |
| 1021 | |
| 1022 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 1023 | * Axis constant: Generic 2 axis of a motion event. |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 1024 | * The interpretation of a generic axis is device-specific. |
| 1025 | * |
| 1026 | * @see #getAxisValue(int, int) |
| 1027 | * @see #getHistoricalAxisValue(int, int, int) |
| 1028 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 1029 | * @see InputDevice#getMotionRange |
| 1030 | */ |
| 1031 | public static final int AXIS_GENERIC_2 = 33; |
| 1032 | |
| 1033 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 1034 | * Axis constant: Generic 3 axis of a motion event. |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 1035 | * The interpretation of a generic axis is device-specific. |
| 1036 | * |
| 1037 | * @see #getAxisValue(int, int) |
| 1038 | * @see #getHistoricalAxisValue(int, int, int) |
| 1039 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 1040 | * @see InputDevice#getMotionRange |
| 1041 | */ |
| 1042 | public static final int AXIS_GENERIC_3 = 34; |
| 1043 | |
| 1044 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 1045 | * Axis constant: Generic 4 axis of a motion event. |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 1046 | * The interpretation of a generic axis is device-specific. |
| 1047 | * |
| 1048 | * @see #getAxisValue(int, int) |
| 1049 | * @see #getHistoricalAxisValue(int, int, int) |
| 1050 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 1051 | * @see InputDevice#getMotionRange |
| 1052 | */ |
| 1053 | public static final int AXIS_GENERIC_4 = 35; |
| 1054 | |
| 1055 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 1056 | * Axis constant: Generic 5 axis of a motion event. |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 1057 | * The interpretation of a generic axis is device-specific. |
| 1058 | * |
| 1059 | * @see #getAxisValue(int, int) |
| 1060 | * @see #getHistoricalAxisValue(int, int, int) |
| 1061 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 1062 | * @see InputDevice#getMotionRange |
| 1063 | */ |
| 1064 | public static final int AXIS_GENERIC_5 = 36; |
| 1065 | |
| 1066 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 1067 | * Axis constant: Generic 6 axis of a motion event. |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 1068 | * The interpretation of a generic axis is device-specific. |
| 1069 | * |
| 1070 | * @see #getAxisValue(int, int) |
| 1071 | * @see #getHistoricalAxisValue(int, int, int) |
| 1072 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 1073 | * @see InputDevice#getMotionRange |
| 1074 | */ |
| 1075 | public static final int AXIS_GENERIC_6 = 37; |
| 1076 | |
| 1077 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 1078 | * Axis constant: Generic 7 axis of a motion event. |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 1079 | * The interpretation of a generic axis is device-specific. |
| 1080 | * |
| 1081 | * @see #getAxisValue(int, int) |
| 1082 | * @see #getHistoricalAxisValue(int, int, int) |
| 1083 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 1084 | * @see InputDevice#getMotionRange |
| 1085 | */ |
| 1086 | public static final int AXIS_GENERIC_7 = 38; |
| 1087 | |
| 1088 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 1089 | * Axis constant: Generic 8 axis of a motion event. |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 1090 | * The interpretation of a generic axis is device-specific. |
| 1091 | * |
| 1092 | * @see #getAxisValue(int, int) |
| 1093 | * @see #getHistoricalAxisValue(int, int, int) |
| 1094 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 1095 | * @see InputDevice#getMotionRange |
| 1096 | */ |
| 1097 | public static final int AXIS_GENERIC_8 = 39; |
| 1098 | |
| 1099 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 1100 | * Axis constant: Generic 9 axis of a motion event. |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 1101 | * The interpretation of a generic axis is device-specific. |
| 1102 | * |
| 1103 | * @see #getAxisValue(int, int) |
| 1104 | * @see #getHistoricalAxisValue(int, int, int) |
| 1105 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 1106 | * @see InputDevice#getMotionRange |
| 1107 | */ |
| 1108 | public static final int AXIS_GENERIC_9 = 40; |
| 1109 | |
| 1110 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 1111 | * Axis constant: Generic 10 axis of a motion event. |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 1112 | * The interpretation of a generic axis is device-specific. |
| 1113 | * |
| 1114 | * @see #getAxisValue(int, int) |
| 1115 | * @see #getHistoricalAxisValue(int, int, int) |
| 1116 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 1117 | * @see InputDevice#getMotionRange |
| 1118 | */ |
| 1119 | public static final int AXIS_GENERIC_10 = 41; |
| 1120 | |
| 1121 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 1122 | * Axis constant: Generic 11 axis of a motion event. |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 1123 | * The interpretation of a generic axis is device-specific. |
| 1124 | * |
| 1125 | * @see #getAxisValue(int, int) |
| 1126 | * @see #getHistoricalAxisValue(int, int, int) |
| 1127 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 1128 | * @see InputDevice#getMotionRange |
| 1129 | */ |
| 1130 | public static final int AXIS_GENERIC_11 = 42; |
| 1131 | |
| 1132 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 1133 | * Axis constant: Generic 12 axis of a motion event. |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 1134 | * The interpretation of a generic axis is device-specific. |
| 1135 | * |
| 1136 | * @see #getAxisValue(int, int) |
| 1137 | * @see #getHistoricalAxisValue(int, int, int) |
| 1138 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 1139 | * @see InputDevice#getMotionRange |
| 1140 | */ |
| 1141 | public static final int AXIS_GENERIC_12 = 43; |
| 1142 | |
| 1143 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 1144 | * Axis constant: Generic 13 axis of a motion event. |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 1145 | * The interpretation of a generic axis is device-specific. |
| 1146 | * |
| 1147 | * @see #getAxisValue(int, int) |
| 1148 | * @see #getHistoricalAxisValue(int, int, int) |
| 1149 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 1150 | * @see InputDevice#getMotionRange |
| 1151 | */ |
| 1152 | public static final int AXIS_GENERIC_13 = 44; |
| 1153 | |
| 1154 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 1155 | * Axis constant: Generic 14 axis of a motion event. |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 1156 | * The interpretation of a generic axis is device-specific. |
| 1157 | * |
| 1158 | * @see #getAxisValue(int, int) |
| 1159 | * @see #getHistoricalAxisValue(int, int, int) |
| 1160 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 1161 | * @see InputDevice#getMotionRange |
| 1162 | */ |
| 1163 | public static final int AXIS_GENERIC_14 = 45; |
| 1164 | |
| 1165 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 1166 | * Axis constant: Generic 15 axis of a motion event. |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 1167 | * The interpretation of a generic axis is device-specific. |
| 1168 | * |
| 1169 | * @see #getAxisValue(int, int) |
| 1170 | * @see #getHistoricalAxisValue(int, int, int) |
| 1171 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 1172 | * @see InputDevice#getMotionRange |
| 1173 | */ |
| 1174 | public static final int AXIS_GENERIC_15 = 46; |
| 1175 | |
| 1176 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 1177 | * Axis constant: Generic 16 axis of a motion event. |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 1178 | * The interpretation of a generic axis is device-specific. |
| 1179 | * |
| 1180 | * @see #getAxisValue(int, int) |
| 1181 | * @see #getHistoricalAxisValue(int, int, int) |
| 1182 | * @see MotionEvent.PointerCoords#getAxisValue(int) |
| 1183 | * @see InputDevice#getMotionRange |
| 1184 | */ |
| 1185 | public static final int AXIS_GENERIC_16 = 47; |
| 1186 | |
| 1187 | // NOTE: If you add a new axis here you must also add it to: |
| 1188 | // native/include/android/input.h |
| 1189 | // frameworks/base/include/ui/KeycodeLabels.h |
| 1190 | |
| 1191 | // Symbolic names of all axes. |
| 1192 | private static final SparseArray<String> AXIS_SYMBOLIC_NAMES = new SparseArray<String>(); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 1193 | static { |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 1194 | SparseArray<String> names = AXIS_SYMBOLIC_NAMES; |
| 1195 | names.append(AXIS_X, "AXIS_X"); |
| 1196 | names.append(AXIS_Y, "AXIS_Y"); |
| 1197 | names.append(AXIS_PRESSURE, "AXIS_PRESSURE"); |
| 1198 | names.append(AXIS_SIZE, "AXIS_SIZE"); |
| 1199 | names.append(AXIS_TOUCH_MAJOR, "AXIS_TOUCH_MAJOR"); |
| 1200 | names.append(AXIS_TOUCH_MINOR, "AXIS_TOUCH_MINOR"); |
| 1201 | names.append(AXIS_TOOL_MAJOR, "AXIS_TOOL_MAJOR"); |
| 1202 | names.append(AXIS_TOOL_MINOR, "AXIS_TOOL_MINOR"); |
| 1203 | names.append(AXIS_ORIENTATION, "AXIS_ORIENTATION"); |
| 1204 | names.append(AXIS_VSCROLL, "AXIS_VSCROLL"); |
| 1205 | names.append(AXIS_HSCROLL, "AXIS_HSCROLL"); |
| 1206 | names.append(AXIS_Z, "AXIS_Z"); |
| 1207 | names.append(AXIS_RX, "AXIS_RX"); |
| 1208 | names.append(AXIS_RY, "AXIS_RY"); |
| 1209 | names.append(AXIS_RZ, "AXIS_RZ"); |
| 1210 | names.append(AXIS_HAT_X, "AXIS_HAT_X"); |
| 1211 | names.append(AXIS_HAT_Y, "AXIS_HAT_Y"); |
| 1212 | names.append(AXIS_LTRIGGER, "AXIS_LTRIGGER"); |
| 1213 | names.append(AXIS_RTRIGGER, "AXIS_RTRIGGER"); |
Jeff Brown | 3a22fa0 | 2011-03-04 13:07:49 -0800 | [diff] [blame] | 1214 | names.append(AXIS_THROTTLE, "AXIS_THROTTLE"); |
| 1215 | names.append(AXIS_RUDDER, "AXIS_RUDDER"); |
| 1216 | names.append(AXIS_WHEEL, "AXIS_WHEEL"); |
| 1217 | names.append(AXIS_GAS, "AXIS_GAS"); |
| 1218 | names.append(AXIS_BRAKE, "AXIS_BRAKE"); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 1219 | names.append(AXIS_DISTANCE, "AXIS_DISTANCE"); |
Jeff Brown | 65fd251 | 2011-08-18 11:20:58 -0700 | [diff] [blame] | 1220 | names.append(AXIS_TILT, "AXIS_TILT"); |
Prashant Malani | 67322b1 | 2015-08-25 17:41:34 -0700 | [diff] [blame] | 1221 | names.append(AXIS_SCROLL, "AXIS_SCROLL"); |
Jun Mukai | 347e5d4 | 2015-12-03 01:13:31 -0800 | [diff] [blame] | 1222 | names.append(AXIS_RELATIVE_X, "AXIS_REALTIVE_X"); |
| 1223 | names.append(AXIS_RELATIVE_Y, "AXIS_REALTIVE_Y"); |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 1224 | names.append(AXIS_GENERIC_1, "AXIS_GENERIC_1"); |
| 1225 | names.append(AXIS_GENERIC_2, "AXIS_GENERIC_2"); |
| 1226 | names.append(AXIS_GENERIC_3, "AXIS_GENERIC_3"); |
| 1227 | names.append(AXIS_GENERIC_4, "AXIS_GENERIC_4"); |
| 1228 | names.append(AXIS_GENERIC_5, "AXIS_GENERIC_5"); |
| 1229 | names.append(AXIS_GENERIC_6, "AXIS_GENERIC_6"); |
| 1230 | names.append(AXIS_GENERIC_7, "AXIS_GENERIC_7"); |
| 1231 | names.append(AXIS_GENERIC_8, "AXIS_GENERIC_8"); |
| 1232 | names.append(AXIS_GENERIC_9, "AXIS_GENERIC_9"); |
| 1233 | names.append(AXIS_GENERIC_10, "AXIS_GENERIC_10"); |
| 1234 | names.append(AXIS_GENERIC_11, "AXIS_GENERIC_11"); |
| 1235 | names.append(AXIS_GENERIC_12, "AXIS_GENERIC_12"); |
| 1236 | names.append(AXIS_GENERIC_13, "AXIS_GENERIC_13"); |
| 1237 | names.append(AXIS_GENERIC_14, "AXIS_GENERIC_14"); |
| 1238 | names.append(AXIS_GENERIC_15, "AXIS_GENERIC_15"); |
| 1239 | names.append(AXIS_GENERIC_16, "AXIS_GENERIC_16"); |
| 1240 | } |
| 1241 | |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 1242 | /** |
Jeff Brown | 49754db | 2011-07-01 17:37:58 -0700 | [diff] [blame] | 1243 | * Button constant: Primary button (left mouse button). |
| 1244 | * |
| 1245 | * This button constant is not set in response to simple touches with a finger |
| 1246 | * or stylus tip. The user must actually push a button. |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 1247 | * |
| 1248 | * @see #getButtonState |
| 1249 | */ |
| 1250 | public static final int BUTTON_PRIMARY = 1 << 0; |
| 1251 | |
| 1252 | /** |
Michael Wright | 5bd69e6 | 2015-05-14 14:48:08 +0100 | [diff] [blame] | 1253 | * Button constant: Secondary button (right mouse button). |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 1254 | * |
| 1255 | * @see #getButtonState |
| 1256 | */ |
| 1257 | public static final int BUTTON_SECONDARY = 1 << 1; |
| 1258 | |
| 1259 | /** |
Michael Wright | 5bd69e6 | 2015-05-14 14:48:08 +0100 | [diff] [blame] | 1260 | * Button constant: Tertiary button (middle mouse button). |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 1261 | * |
| 1262 | * @see #getButtonState |
| 1263 | */ |
| 1264 | public static final int BUTTON_TERTIARY = 1 << 2; |
| 1265 | |
| 1266 | /** |
| 1267 | * Button constant: Back button pressed (mouse back button). |
| 1268 | * <p> |
| 1269 | * The system may send a {@link KeyEvent#KEYCODE_BACK} key press to the application |
| 1270 | * when this button is pressed. |
| 1271 | * </p> |
| 1272 | * |
| 1273 | * @see #getButtonState |
| 1274 | */ |
| 1275 | public static final int BUTTON_BACK = 1 << 3; |
| 1276 | |
| 1277 | /** |
| 1278 | * Button constant: Forward button pressed (mouse forward button). |
| 1279 | * <p> |
| 1280 | * The system may send a {@link KeyEvent#KEYCODE_FORWARD} key press to the application |
| 1281 | * when this button is pressed. |
| 1282 | * </p> |
| 1283 | * |
| 1284 | * @see #getButtonState |
| 1285 | */ |
| 1286 | public static final int BUTTON_FORWARD = 1 << 4; |
| 1287 | |
Michael Wright | 5bd69e6 | 2015-05-14 14:48:08 +0100 | [diff] [blame] | 1288 | /** |
| 1289 | * Button constant: Primary stylus button pressed. |
| 1290 | * |
| 1291 | * @see #getButtonState |
| 1292 | */ |
| 1293 | public static final int BUTTON_STYLUS_PRIMARY = 1 << 5; |
| 1294 | |
| 1295 | /** |
| 1296 | * Button constant: Secondary stylus button pressed. |
| 1297 | * |
| 1298 | * @see #getButtonState |
| 1299 | */ |
| 1300 | public static final int BUTTON_STYLUS_SECONDARY = 1 << 6; |
| 1301 | |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 1302 | // NOTE: If you add a new axis here you must also add it to: |
| 1303 | // native/include/android/input.h |
| 1304 | |
| 1305 | // Symbolic names of all button states in bit order from least significant |
| 1306 | // to most significant. |
| 1307 | private static final String[] BUTTON_SYMBOLIC_NAMES = new String[] { |
| 1308 | "BUTTON_PRIMARY", |
| 1309 | "BUTTON_SECONDARY", |
| 1310 | "BUTTON_TERTIARY", |
| 1311 | "BUTTON_BACK", |
| 1312 | "BUTTON_FORWARD", |
Michael Wright | 5bd69e6 | 2015-05-14 14:48:08 +0100 | [diff] [blame] | 1313 | "BUTTON_STYLUS_PRIMARY", |
| 1314 | "BUTTON_STYLUS_SECONDARY", |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 1315 | "0x00000080", |
| 1316 | "0x00000100", |
| 1317 | "0x00000200", |
| 1318 | "0x00000400", |
| 1319 | "0x00000800", |
| 1320 | "0x00001000", |
| 1321 | "0x00002000", |
| 1322 | "0x00004000", |
| 1323 | "0x00008000", |
| 1324 | "0x00010000", |
| 1325 | "0x00020000", |
| 1326 | "0x00040000", |
| 1327 | "0x00080000", |
| 1328 | "0x00100000", |
| 1329 | "0x00200000", |
| 1330 | "0x00400000", |
| 1331 | "0x00800000", |
| 1332 | "0x01000000", |
| 1333 | "0x02000000", |
| 1334 | "0x04000000", |
| 1335 | "0x08000000", |
| 1336 | "0x10000000", |
| 1337 | "0x20000000", |
| 1338 | "0x40000000", |
| 1339 | "0x80000000", |
| 1340 | }; |
| 1341 | |
| 1342 | /** |
| 1343 | * Tool type constant: Unknown tool type. |
| 1344 | * This constant is used when the tool type is not known or is not relevant, |
| 1345 | * such as for a trackball or other non-pointing device. |
| 1346 | * |
| 1347 | * @see #getToolType |
| 1348 | */ |
| 1349 | public static final int TOOL_TYPE_UNKNOWN = 0; |
| 1350 | |
| 1351 | /** |
Jeff Brown | 49754db | 2011-07-01 17:37:58 -0700 | [diff] [blame] | 1352 | * Tool type constant: The tool is a finger. |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 1353 | * |
| 1354 | * @see #getToolType |
| 1355 | */ |
| 1356 | public static final int TOOL_TYPE_FINGER = 1; |
| 1357 | |
| 1358 | /** |
Jeff Brown | 49754db | 2011-07-01 17:37:58 -0700 | [diff] [blame] | 1359 | * Tool type constant: The tool is a stylus. |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 1360 | * |
| 1361 | * @see #getToolType |
| 1362 | */ |
| 1363 | public static final int TOOL_TYPE_STYLUS = 2; |
| 1364 | |
| 1365 | /** |
Jeff Brown | 49754db | 2011-07-01 17:37:58 -0700 | [diff] [blame] | 1366 | * Tool type constant: The tool is a mouse or trackpad. |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 1367 | * |
| 1368 | * @see #getToolType |
| 1369 | */ |
| 1370 | public static final int TOOL_TYPE_MOUSE = 3; |
| 1371 | |
| 1372 | /** |
Jeff Brown | 49754db | 2011-07-01 17:37:58 -0700 | [diff] [blame] | 1373 | * Tool type constant: The tool is an eraser or a stylus being used in an inverted posture. |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 1374 | * |
| 1375 | * @see #getToolType |
| 1376 | */ |
Jeff Brown | 49754db | 2011-07-01 17:37:58 -0700 | [diff] [blame] | 1377 | public static final int TOOL_TYPE_ERASER = 4; |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 1378 | |
| 1379 | // NOTE: If you add a new tool type here you must also add it to: |
| 1380 | // native/include/android/input.h |
| 1381 | |
| 1382 | // Symbolic names of all tool types. |
| 1383 | private static final SparseArray<String> TOOL_TYPE_SYMBOLIC_NAMES = new SparseArray<String>(); |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 1384 | static { |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 1385 | SparseArray<String> names = TOOL_TYPE_SYMBOLIC_NAMES; |
| 1386 | names.append(TOOL_TYPE_UNKNOWN, "TOOL_TYPE_UNKNOWN"); |
| 1387 | names.append(TOOL_TYPE_FINGER, "TOOL_TYPE_FINGER"); |
| 1388 | names.append(TOOL_TYPE_STYLUS, "TOOL_TYPE_STYLUS"); |
| 1389 | names.append(TOOL_TYPE_MOUSE, "TOOL_TYPE_MOUSE"); |
Jeff Brown | 49754db | 2011-07-01 17:37:58 -0700 | [diff] [blame] | 1390 | names.append(TOOL_TYPE_ERASER, "TOOL_TYPE_ERASER"); |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 1391 | } |
| 1392 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1393 | // Private value for history pos that obtains the current sample. |
| 1394 | private static final int HISTORY_CURRENT = -0x80000000; |
| 1395 | |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 1396 | private static final int MAX_RECYCLED = 10; |
| 1397 | private static final Object gRecyclerLock = new Object(); |
| 1398 | private static int gRecyclerUsed; |
| 1399 | private static MotionEvent gRecyclerTop; |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1400 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1401 | // Shared temporary objects used when translating coordinates supplied by |
| 1402 | // the caller into single element PointerCoords and pointer id arrays. |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 1403 | private static final Object gSharedTempLock = new Object(); |
| 1404 | private static PointerCoords[] gSharedTempPointerCoords; |
| 1405 | private static PointerProperties[] gSharedTempPointerProperties; |
| 1406 | private static int[] gSharedTempPointerIndexMap; |
| 1407 | |
| 1408 | private static final void ensureSharedTempPointerCapacity(int desiredCapacity) { |
| 1409 | if (gSharedTempPointerCoords == null |
| 1410 | || gSharedTempPointerCoords.length < desiredCapacity) { |
| 1411 | int capacity = gSharedTempPointerCoords != null ? gSharedTempPointerCoords.length : 8; |
| 1412 | while (capacity < desiredCapacity) { |
| 1413 | capacity *= 2; |
| 1414 | } |
| 1415 | gSharedTempPointerCoords = PointerCoords.createArray(capacity); |
| 1416 | gSharedTempPointerProperties = PointerProperties.createArray(capacity); |
| 1417 | gSharedTempPointerIndexMap = new int[capacity]; |
| 1418 | } |
| 1419 | } |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1420 | |
| 1421 | // Pointer to the native MotionEvent object that contains the actual data. |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 1422 | private long mNativePtr; |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 1423 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1424 | private MotionEvent mNext; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1425 | |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 1426 | private static native long nativeInitialize(long nativePtr, |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 1427 | int deviceId, int source, int action, int flags, int edgeFlags, |
| 1428 | int metaState, int buttonState, |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1429 | float xOffset, float yOffset, float xPrecision, float yPrecision, |
| 1430 | long downTimeNanos, long eventTimeNanos, |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 1431 | int pointerCount, PointerProperties[] pointerIds, PointerCoords[] pointerCoords); |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 1432 | private static native long nativeCopy(long destNativePtr, long sourceNativePtr, |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1433 | boolean keepHistory); |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 1434 | private static native void nativeDispose(long nativePtr); |
| 1435 | private static native void nativeAddBatch(long nativePtr, long eventTimeNanos, |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1436 | PointerCoords[] pointerCoords, int metaState); |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 1437 | |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 1438 | private static native int nativeGetDeviceId(long nativePtr); |
| 1439 | private static native int nativeGetSource(long nativePtr); |
| 1440 | private static native int nativeSetSource(long nativePtr, int source); |
| 1441 | private static native int nativeGetAction(long nativePtr); |
| 1442 | private static native void nativeSetAction(long nativePtr, int action); |
| 1443 | private static native boolean nativeIsTouchEvent(long nativePtr); |
| 1444 | private static native int nativeGetFlags(long nativePtr); |
| 1445 | private static native void nativeSetFlags(long nativePtr, int flags); |
| 1446 | private static native int nativeGetEdgeFlags(long nativePtr); |
| 1447 | private static native void nativeSetEdgeFlags(long nativePtr, int action); |
| 1448 | private static native int nativeGetMetaState(long nativePtr); |
| 1449 | private static native int nativeGetButtonState(long nativePtr); |
Michael Wright | 5bd69e6 | 2015-05-14 14:48:08 +0100 | [diff] [blame] | 1450 | private static native void nativeSetButtonState(long nativePtr, int buttonState); |
| 1451 | private static native int nativeGetActionButton(long nativePtr); |
Michael Wright | 6b819b4 | 2015-06-17 21:06:03 +0100 | [diff] [blame] | 1452 | private static native void nativeSetActionButton(long nativePtr, int actionButton); |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 1453 | private static native void nativeOffsetLocation(long nativePtr, float deltaX, float deltaY); |
| 1454 | private static native float nativeGetXOffset(long nativePtr); |
| 1455 | private static native float nativeGetYOffset(long nativePtr); |
| 1456 | private static native float nativeGetXPrecision(long nativePtr); |
| 1457 | private static native float nativeGetYPrecision(long nativePtr); |
| 1458 | private static native long nativeGetDownTimeNanos(long nativePtr); |
| 1459 | private static native void nativeSetDownTimeNanos(long nativePtr, long downTime); |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1460 | |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 1461 | private static native int nativeGetPointerCount(long nativePtr); |
| 1462 | private static native int nativeGetPointerId(long nativePtr, int pointerIndex); |
| 1463 | private static native int nativeGetToolType(long nativePtr, int pointerIndex); |
| 1464 | private static native int nativeFindPointerIndex(long nativePtr, int pointerId); |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1465 | |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 1466 | private static native int nativeGetHistorySize(long nativePtr); |
| 1467 | private static native long nativeGetEventTimeNanos(long nativePtr, int historyPos); |
| 1468 | private static native float nativeGetRawAxisValue(long nativePtr, |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1469 | int axis, int pointerIndex, int historyPos); |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 1470 | private static native float nativeGetAxisValue(long nativePtr, |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1471 | int axis, int pointerIndex, int historyPos); |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 1472 | private static native void nativeGetPointerCoords(long nativePtr, |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1473 | int pointerIndex, int historyPos, PointerCoords outPointerCoords); |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 1474 | private static native void nativeGetPointerProperties(long nativePtr, |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 1475 | int pointerIndex, PointerProperties outPointerProperties); |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1476 | |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 1477 | private static native void nativeScale(long nativePtr, float scale); |
| 1478 | private static native void nativeTransform(long nativePtr, Matrix matrix); |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1479 | |
Ashok Bhat | 99a1ef2 | 2014-01-08 14:45:08 +0000 | [diff] [blame] | 1480 | private static native long nativeReadFromParcel(long nativePtr, Parcel parcel); |
| 1481 | private static native void nativeWriteToParcel(long nativePtr, Parcel parcel); |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1482 | |
Michael Wright | 337d9d2 | 2014-04-22 15:03:48 -0700 | [diff] [blame] | 1483 | private static native String nativeAxisToString(int axis); |
| 1484 | private static native int nativeAxisFromString(String label); |
| 1485 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1486 | private MotionEvent() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1487 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1488 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1489 | @Override |
| 1490 | protected void finalize() throws Throwable { |
| 1491 | try { |
| 1492 | if (mNativePtr != 0) { |
| 1493 | nativeDispose(mNativePtr); |
| 1494 | mNativePtr = 0; |
| 1495 | } |
| 1496 | } finally { |
| 1497 | super.finalize(); |
| 1498 | } |
| 1499 | } |
| 1500 | |
| 1501 | static private MotionEvent obtain() { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1502 | final MotionEvent ev; |
| 1503 | synchronized (gRecyclerLock) { |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 1504 | ev = gRecyclerTop; |
| 1505 | if (ev == null) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1506 | return new MotionEvent(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1507 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1508 | gRecyclerTop = ev.mNext; |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1509 | gRecyclerUsed -= 1; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1510 | } |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1511 | ev.mNext = null; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 1512 | ev.prepareForReuse(); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1513 | return ev; |
| 1514 | } |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1515 | |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 1516 | /** |
| 1517 | * Create a new MotionEvent, filling in all of the basic values that |
| 1518 | * define the motion. |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 1519 | * |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 1520 | * @param downTime The time (in ms) when the user originally pressed down to start |
| 1521 | * 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] | 1522 | * @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] | 1523 | * must be obtained from {@link SystemClock#uptimeMillis()}. |
Jeff Brown | cc0c159 | 2011-02-19 05:07:28 -0800 | [diff] [blame] | 1524 | * @param action The kind of action being performed, such as {@link #ACTION_DOWN}. |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 1525 | * @param pointerCount The number of pointers that will be in this event. |
| 1526 | * @param pointerProperties An array of <em>pointerCount</em> values providing |
| 1527 | * a {@link PointerProperties} property object for each pointer, which must |
| 1528 | * include the pointer identifier. |
| 1529 | * @param pointerCoords An array of <em>pointerCount</em> values providing |
| 1530 | * a {@link PointerCoords} coordinate object for each pointer. |
| 1531 | * @param metaState The state of any meta / modifier keys that were in effect when |
| 1532 | * the event was generated. |
| 1533 | * @param buttonState The state of buttons that are pressed. |
| 1534 | * @param xPrecision The precision of the X coordinate being reported. |
| 1535 | * @param yPrecision The precision of the Y coordinate being reported. |
| 1536 | * @param deviceId The id for the device that this event came from. An id of |
| 1537 | * zero indicates that the event didn't come from a physical device; other |
| 1538 | * numbers are arbitrary and you shouldn't depend on the values. |
| 1539 | * @param edgeFlags A bitfield indicating which edges, if any, were touched by this |
| 1540 | * MotionEvent. |
| 1541 | * @param source The source of this event. |
| 1542 | * @param flags The motion event flags. |
| 1543 | */ |
| 1544 | static public MotionEvent obtain(long downTime, long eventTime, |
| 1545 | int action, int pointerCount, PointerProperties[] pointerProperties, |
| 1546 | PointerCoords[] pointerCoords, int metaState, int buttonState, |
| 1547 | float xPrecision, float yPrecision, int deviceId, |
| 1548 | int edgeFlags, int source, int flags) { |
| 1549 | MotionEvent ev = obtain(); |
| 1550 | ev.mNativePtr = nativeInitialize(ev.mNativePtr, |
| 1551 | deviceId, source, action, flags, edgeFlags, metaState, buttonState, |
| 1552 | 0, 0, xPrecision, yPrecision, |
| 1553 | downTime * NS_PER_MS, eventTime * NS_PER_MS, |
| 1554 | pointerCount, pointerProperties, pointerCoords); |
| 1555 | return ev; |
| 1556 | } |
| 1557 | |
| 1558 | /** |
| 1559 | * Create a new MotionEvent, filling in all of the basic values that |
| 1560 | * define the motion. |
| 1561 | * |
| 1562 | * @param downTime The time (in ms) when the user originally pressed down to start |
| 1563 | * a stream of position events. This must be obtained from {@link SystemClock#uptimeMillis()}. |
| 1564 | * @param eventTime The the time (in ms) when this specific event was generated. This |
| 1565 | * must be obtained from {@link SystemClock#uptimeMillis()}. |
| 1566 | * @param action The kind of action being performed, such as {@link #ACTION_DOWN}. |
| 1567 | * @param pointerCount The number of pointers that will be in this event. |
| 1568 | * @param pointerIds An array of <em>pointerCount</em> values providing |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1569 | * an identifier for each pointer. |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 1570 | * @param pointerCoords An array of <em>pointerCount</em> values providing |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1571 | * a {@link PointerCoords} coordinate object for each pointer. |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 1572 | * @param metaState The state of any meta / modifier keys that were in effect when |
| 1573 | * the event was generated. |
| 1574 | * @param xPrecision The precision of the X coordinate being reported. |
| 1575 | * @param yPrecision The precision of the Y coordinate being reported. |
| 1576 | * @param deviceId The id for the device that this event came from. An id of |
| 1577 | * zero indicates that the event didn't come from a physical device; other |
| 1578 | * numbers are arbitrary and you shouldn't depend on the values. |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 1579 | * @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] | 1580 | * MotionEvent. |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1581 | * @param source The source of this event. |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 1582 | * @param flags The motion event flags. |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 1583 | * |
| 1584 | * @deprecated Use {@link #obtain(long, long, int, int, PointerProperties[], PointerCoords[], int, int, float, float, int, int, int, int)} |
| 1585 | * instead. |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 1586 | */ |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 1587 | @Deprecated |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1588 | static public MotionEvent obtain(long downTime, long eventTime, |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 1589 | int action, int pointerCount, int[] pointerIds, PointerCoords[] pointerCoords, |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1590 | int metaState, float xPrecision, float yPrecision, int deviceId, |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 1591 | int edgeFlags, int source, int flags) { |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 1592 | synchronized (gSharedTempLock) { |
| 1593 | ensureSharedTempPointerCapacity(pointerCount); |
| 1594 | final PointerProperties[] pp = gSharedTempPointerProperties; |
| 1595 | for (int i = 0; i < pointerCount; i++) { |
| 1596 | pp[i].clear(); |
| 1597 | pp[i].id = pointerIds[i]; |
| 1598 | } |
| 1599 | return obtain(downTime, eventTime, action, pointerCount, pp, |
| 1600 | pointerCoords, metaState, 0, xPrecision, yPrecision, deviceId, |
| 1601 | edgeFlags, source, flags); |
| 1602 | } |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 1603 | } |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1604 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1605 | /** |
| 1606 | * Create a new MotionEvent, filling in all of the basic values that |
| 1607 | * define the motion. |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1608 | * |
| 1609 | * @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] | 1610 | * 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] | 1611 | * @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] | 1612 | * must be obtained from {@link SystemClock#uptimeMillis()}. |
Jeff Brown | cc0c159 | 2011-02-19 05:07:28 -0800 | [diff] [blame] | 1613 | * @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] | 1614 | * @param x The X coordinate of this event. |
| 1615 | * @param y The Y coordinate of this event. |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1616 | * @param pressure The current pressure of this event. The pressure generally |
| 1617 | * ranges from 0 (no pressure at all) to 1 (normal pressure), however |
| 1618 | * 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] | 1619 | * the input device. |
| 1620 | * @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] | 1621 | * 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] | 1622 | * touch is normalized with a device specific range of values |
| 1623 | * and scaled to a value between 0 and 1. |
| 1624 | * @param metaState The state of any meta / modifier keys that were in effect when |
| 1625 | * the event was generated. |
| 1626 | * @param xPrecision The precision of the X coordinate being reported. |
| 1627 | * @param yPrecision The precision of the Y coordinate being reported. |
| 1628 | * @param deviceId The id for the device that this event came from. An id of |
| 1629 | * zero indicates that the event didn't come from a physical device; other |
| 1630 | * numbers are arbitrary and you shouldn't depend on the values. |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 1631 | * @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] | 1632 | * MotionEvent. |
| 1633 | */ |
| 1634 | static public MotionEvent obtain(long downTime, long eventTime, int action, |
| 1635 | float x, float y, float pressure, float size, int metaState, |
| 1636 | float xPrecision, float yPrecision, int deviceId, int edgeFlags) { |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 1637 | MotionEvent ev = obtain(); |
| 1638 | synchronized (gSharedTempLock) { |
| 1639 | ensureSharedTempPointerCapacity(1); |
| 1640 | final PointerProperties[] pp = gSharedTempPointerProperties; |
| 1641 | pp[0].clear(); |
| 1642 | pp[0].id = 0; |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1643 | |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 1644 | final PointerCoords pc[] = gSharedTempPointerCoords; |
| 1645 | pc[0].clear(); |
| 1646 | pc[0].x = x; |
| 1647 | pc[0].y = y; |
| 1648 | pc[0].pressure = pressure; |
| 1649 | pc[0].size = size; |
| 1650 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1651 | ev.mNativePtr = nativeInitialize(ev.mNativePtr, |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 1652 | deviceId, InputDevice.SOURCE_UNKNOWN, action, 0, edgeFlags, metaState, 0, |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1653 | 0, 0, xPrecision, yPrecision, |
| 1654 | downTime * NS_PER_MS, eventTime * NS_PER_MS, |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 1655 | 1, pp, pc); |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1656 | return ev; |
| 1657 | } |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1658 | } |
| 1659 | |
| 1660 | /** |
| 1661 | * Create a new MotionEvent, filling in all of the basic values that |
| 1662 | * define the motion. |
| 1663 | * |
| 1664 | * @param downTime The time (in ms) when the user originally pressed down to start |
| 1665 | * a stream of position events. This must be obtained from {@link SystemClock#uptimeMillis()}. |
| 1666 | * @param eventTime The the time (in ms) when this specific event was generated. This |
| 1667 | * must be obtained from {@link SystemClock#uptimeMillis()}. |
Jeff Brown | cc0c159 | 2011-02-19 05:07:28 -0800 | [diff] [blame] | 1668 | * @param action The kind of action being performed, such as {@link #ACTION_DOWN}. |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 1669 | * @param pointerCount The number of pointers that are active in this event. |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1670 | * @param x The X coordinate of this event. |
| 1671 | * @param y The Y coordinate of this event. |
| 1672 | * @param pressure The current pressure of this event. The pressure generally |
| 1673 | * ranges from 0 (no pressure at all) to 1 (normal pressure), however |
| 1674 | * values higher than 1 may be generated depending on the calibration of |
| 1675 | * the input device. |
| 1676 | * @param size A scaled value of the approximate size of the area being pressed when |
| 1677 | * touched with the finger. The actual value in pixels corresponding to the finger |
| 1678 | * touch is normalized with a device specific range of values |
| 1679 | * and scaled to a value between 0 and 1. |
| 1680 | * @param metaState The state of any meta / modifier keys that were in effect when |
| 1681 | * the event was generated. |
| 1682 | * @param xPrecision The precision of the X coordinate being reported. |
| 1683 | * @param yPrecision The precision of the Y coordinate being reported. |
| 1684 | * @param deviceId The id for the device that this event came from. An id of |
| 1685 | * zero indicates that the event didn't come from a physical device; other |
| 1686 | * numbers are arbitrary and you shouldn't depend on the values. |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 1687 | * @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] | 1688 | * MotionEvent. |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1689 | * |
| 1690 | * @deprecated Use {@link #obtain(long, long, int, float, float, float, float, int, float, float, int, int)} |
| 1691 | * instead. |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1692 | */ |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1693 | @Deprecated |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1694 | static public MotionEvent obtain(long downTime, long eventTime, int action, |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 1695 | int pointerCount, float x, float y, float pressure, float size, int metaState, |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1696 | float xPrecision, float yPrecision, int deviceId, int edgeFlags) { |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1697 | return obtain(downTime, eventTime, action, x, y, pressure, size, |
| 1698 | metaState, xPrecision, yPrecision, deviceId, edgeFlags); |
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 | * Create a new MotionEvent, filling in a subset of the basic motion |
| 1703 | * values. Those not specified here are: device id (always 0), pressure |
| 1704 | * 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] | 1705 | * |
| 1706 | * @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] | 1707 | * 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] | 1708 | * @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] | 1709 | * must be obtained from {@link SystemClock#uptimeMillis()}. |
Jeff Brown | cc0c159 | 2011-02-19 05:07:28 -0800 | [diff] [blame] | 1710 | * @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] | 1711 | * @param x The X coordinate of this event. |
| 1712 | * @param y The Y coordinate of this event. |
| 1713 | * @param metaState The state of any meta / modifier keys that were in effect when |
| 1714 | * the event was generated. |
| 1715 | */ |
| 1716 | static public MotionEvent obtain(long downTime, long eventTime, int action, |
| 1717 | float x, float y, int metaState) { |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1718 | return obtain(downTime, eventTime, action, x, y, 1.0f, 1.0f, |
| 1719 | metaState, 1.0f, 1.0f, 0, 0); |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 1720 | } |
| 1721 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1722 | /** |
| 1723 | * Create a new MotionEvent, copying from an existing one. |
| 1724 | */ |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1725 | static public MotionEvent obtain(MotionEvent other) { |
| 1726 | if (other == null) { |
| 1727 | throw new IllegalArgumentException("other motion event must not be null"); |
| 1728 | } |
| 1729 | |
| 1730 | MotionEvent ev = obtain(); |
| 1731 | ev.mNativePtr = nativeCopy(ev.mNativePtr, other.mNativePtr, true /*keepHistory*/); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1732 | return ev; |
| 1733 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1734 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1735 | /** |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 1736 | * Create a new MotionEvent, copying from an existing one, but not including |
| 1737 | * any historical point information. |
| 1738 | */ |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1739 | static public MotionEvent obtainNoHistory(MotionEvent other) { |
| 1740 | if (other == null) { |
| 1741 | throw new IllegalArgumentException("other motion event must not be null"); |
| 1742 | } |
| 1743 | |
| 1744 | MotionEvent ev = obtain(); |
| 1745 | ev.mNativePtr = nativeCopy(ev.mNativePtr, other.mNativePtr, false /*keepHistory*/); |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 1746 | return ev; |
| 1747 | } |
| 1748 | |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 1749 | /** @hide */ |
| 1750 | @Override |
| 1751 | public MotionEvent copy() { |
| 1752 | return obtain(this); |
| 1753 | } |
| 1754 | |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 1755 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1756 | * Recycle the MotionEvent, to be re-used by a later caller. After calling |
| 1757 | * this function you must not ever touch the event again. |
| 1758 | */ |
Jeff Brown | 92cc2d8 | 2011-12-02 01:19:47 -0800 | [diff] [blame] | 1759 | @Override |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1760 | public final void recycle() { |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 1761 | super.recycle(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1762 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1763 | synchronized (gRecyclerLock) { |
| 1764 | if (gRecyclerUsed < MAX_RECYCLED) { |
| 1765 | gRecyclerUsed++; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1766 | mNext = gRecyclerTop; |
| 1767 | gRecyclerTop = this; |
| 1768 | } |
| 1769 | } |
| 1770 | } |
Jeff Brown | 9ea77fc | 2012-03-21 19:49:27 -0700 | [diff] [blame] | 1771 | |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1772 | /** |
Jeff Brown | 9ea77fc | 2012-03-21 19:49:27 -0700 | [diff] [blame] | 1773 | * Applies a scale factor to all points within this event. |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1774 | * |
Jeff Brown | 9ea77fc | 2012-03-21 19:49:27 -0700 | [diff] [blame] | 1775 | * This method is used to adjust touch events to simulate different density |
| 1776 | * displays for compatibility mode. The values returned by {@link #getRawX()}, |
| 1777 | * {@link #getRawY()}, {@link #getXPrecision()} and {@link #getYPrecision()} |
| 1778 | * are also affected by the scale factor. |
| 1779 | * |
| 1780 | * @param scale The scale factor to apply. |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1781 | * @hide |
| 1782 | */ |
| 1783 | public final void scale(float scale) { |
Jeff Brown | 9ea77fc | 2012-03-21 19:49:27 -0700 | [diff] [blame] | 1784 | if (scale != 1.0f) { |
| 1785 | nativeScale(mNativePtr, scale); |
| 1786 | } |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1787 | } |
| 1788 | |
| 1789 | /** {@inheritDoc} */ |
| 1790 | @Override |
| 1791 | public final int getDeviceId() { |
| 1792 | return nativeGetDeviceId(mNativePtr); |
| 1793 | } |
| 1794 | |
| 1795 | /** {@inheritDoc} */ |
| 1796 | @Override |
| 1797 | public final int getSource() { |
| 1798 | return nativeGetSource(mNativePtr); |
| 1799 | } |
| 1800 | |
| 1801 | /** {@inheritDoc} */ |
| 1802 | @Override |
| 1803 | public final void setSource(int source) { |
| 1804 | nativeSetSource(mNativePtr, source); |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1805 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1806 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1807 | /** |
Jeff Brown | cc0c159 | 2011-02-19 05:07:28 -0800 | [diff] [blame] | 1808 | * Return the kind of action being performed. |
| 1809 | * Consider using {@link #getActionMasked} and {@link #getActionIndex} to retrieve |
| 1810 | * the separate masked action and pointer index. |
| 1811 | * @return The action, such as {@link #ACTION_DOWN} or |
| 1812 | * 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] | 1813 | */ |
| 1814 | public final int getAction() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1815 | return nativeGetAction(mNativePtr); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1816 | } |
| 1817 | |
| 1818 | /** |
Jeff Brown | cc0c159 | 2011-02-19 05:07:28 -0800 | [diff] [blame] | 1819 | * Return the masked action being performed, without pointer index information. |
| 1820 | * Use {@link #getActionIndex} to return the index associated with pointer actions. |
| 1821 | * @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] | 1822 | */ |
| 1823 | public final int getActionMasked() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1824 | return nativeGetAction(mNativePtr) & ACTION_MASK; |
Dianne Hackborn | b125dc5 | 2010-02-12 15:52:09 -0800 | [diff] [blame] | 1825 | } |
| 1826 | |
| 1827 | /** |
| 1828 | * For {@link #ACTION_POINTER_DOWN} or {@link #ACTION_POINTER_UP} |
| 1829 | * as returned by {@link #getActionMasked}, this returns the associated |
Jeff Brown | cc0c159 | 2011-02-19 05:07:28 -0800 | [diff] [blame] | 1830 | * pointer index. |
| 1831 | * The index may be used with {@link #getPointerId(int)}, |
Dianne Hackborn | b125dc5 | 2010-02-12 15:52:09 -0800 | [diff] [blame] | 1832 | * {@link #getX(int)}, {@link #getY(int)}, {@link #getPressure(int)}, |
| 1833 | * and {@link #getSize(int)} to get information about the pointer that has |
| 1834 | * gone down or up. |
Jeff Brown | cc0c159 | 2011-02-19 05:07:28 -0800 | [diff] [blame] | 1835 | * @return The index associated with the action. |
Dianne Hackborn | b125dc5 | 2010-02-12 15:52:09 -0800 | [diff] [blame] | 1836 | */ |
| 1837 | public final int getActionIndex() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1838 | return (nativeGetAction(mNativePtr) & ACTION_POINTER_INDEX_MASK) |
| 1839 | >> ACTION_POINTER_INDEX_SHIFT; |
Dianne Hackborn | b125dc5 | 2010-02-12 15:52:09 -0800 | [diff] [blame] | 1840 | } |
| 1841 | |
| 1842 | /** |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 1843 | * Returns true if this motion event is a touch event. |
| 1844 | * <p> |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 1845 | * Specifically excludes pointer events with action {@link #ACTION_HOVER_MOVE}, |
| 1846 | * {@link #ACTION_HOVER_ENTER}, {@link #ACTION_HOVER_EXIT}, or {@link #ACTION_SCROLL} |
| 1847 | * because they are not actually touch events (the pointer is not down). |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 1848 | * </p> |
| 1849 | * @return True if this motion event is a touch event. |
| 1850 | * @hide |
| 1851 | */ |
| 1852 | public final boolean isTouchEvent() { |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 1853 | return nativeIsTouchEvent(mNativePtr); |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 1854 | } |
| 1855 | |
| 1856 | /** |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 1857 | * Gets the motion event flags. |
| 1858 | * |
| 1859 | * @see #FLAG_WINDOW_IS_OBSCURED |
| 1860 | */ |
| 1861 | public final int getFlags() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1862 | return nativeGetFlags(mNativePtr); |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 1863 | } |
| 1864 | |
Jeff Brown | 21bc5c9 | 2011-02-28 18:27:14 -0800 | [diff] [blame] | 1865 | /** @hide */ |
| 1866 | @Override |
| 1867 | public final boolean isTainted() { |
| 1868 | final int flags = getFlags(); |
| 1869 | return (flags & FLAG_TAINTED) != 0; |
| 1870 | } |
| 1871 | |
| 1872 | /** @hide */ |
| 1873 | @Override |
| 1874 | public final void setTainted(boolean tainted) { |
| 1875 | final int flags = getFlags(); |
| 1876 | nativeSetFlags(mNativePtr, tainted ? flags | FLAG_TAINTED : flags & ~FLAG_TAINTED); |
| 1877 | } |
| 1878 | |
Svetoslav | ded133c | 2015-01-30 20:28:41 -0800 | [diff] [blame] | 1879 | /** @hide */ |
| 1880 | public final boolean isTargetAccessibilityFocus() { |
| 1881 | final int flags = getFlags(); |
| 1882 | return (flags & FLAG_TARGET_ACCESSIBILITY_FOCUS) != 0; |
| 1883 | } |
| 1884 | |
| 1885 | /** @hide */ |
| 1886 | public final void setTargetAccessibilityFocus(boolean targetsFocus) { |
| 1887 | final int flags = getFlags(); |
| 1888 | nativeSetFlags(mNativePtr, targetsFocus |
| 1889 | ? flags | FLAG_TARGET_ACCESSIBILITY_FOCUS |
| 1890 | : flags & ~FLAG_TARGET_ACCESSIBILITY_FOCUS); |
| 1891 | } |
| 1892 | |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 1893 | /** |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1894 | * Returns the time (in ms) when the user originally pressed down to start |
| 1895 | * a stream of position events. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1896 | */ |
| 1897 | public final long getDownTime() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1898 | return nativeGetDownTimeNanos(mNativePtr) / NS_PER_MS; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1899 | } |
| 1900 | |
| 1901 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 1902 | * Sets the time (in ms) when the user originally pressed down to start |
| 1903 | * a stream of position events. |
| 1904 | * |
| 1905 | * @hide |
| 1906 | */ |
| 1907 | public final void setDownTime(long downTime) { |
| 1908 | nativeSetDownTimeNanos(mNativePtr, downTime * NS_PER_MS); |
| 1909 | } |
| 1910 | |
| 1911 | /** |
Jeff Brown | b11499d | 2012-04-20 19:54:22 -0700 | [diff] [blame] | 1912 | * Retrieve the time this event occurred, |
| 1913 | * in the {@link android.os.SystemClock#uptimeMillis} time base. |
| 1914 | * |
| 1915 | * @return Returns the time this event occurred, |
| 1916 | * in the {@link android.os.SystemClock#uptimeMillis} time base. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1917 | */ |
Jeff Brown | b11499d | 2012-04-20 19:54:22 -0700 | [diff] [blame] | 1918 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1919 | public final long getEventTime() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1920 | return nativeGetEventTimeNanos(mNativePtr, HISTORY_CURRENT) / NS_PER_MS; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1921 | } |
| 1922 | |
| 1923 | /** |
Jeff Brown | b11499d | 2012-04-20 19:54:22 -0700 | [diff] [blame] | 1924 | * Retrieve the time this event occurred, |
| 1925 | * in the {@link android.os.SystemClock#uptimeMillis} time base but with |
| 1926 | * nanosecond precision. |
| 1927 | * <p> |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 1928 | * The value is in nanosecond precision but it may not have nanosecond accuracy. |
Jeff Brown | b11499d | 2012-04-20 19:54:22 -0700 | [diff] [blame] | 1929 | * </p> |
| 1930 | * |
| 1931 | * @return Returns the time this event occurred, |
| 1932 | * in the {@link android.os.SystemClock#uptimeMillis} time base but with |
| 1933 | * nanosecond precision. |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 1934 | * |
| 1935 | * @hide |
| 1936 | */ |
Jeff Brown | b11499d | 2012-04-20 19:54:22 -0700 | [diff] [blame] | 1937 | @Override |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 1938 | public final long getEventTimeNano() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1939 | return nativeGetEventTimeNanos(mNativePtr, HISTORY_CURRENT); |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 1940 | } |
| 1941 | |
| 1942 | /** |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1943 | * {@link #getX(int)} for the first pointer index (may be an |
| 1944 | * arbitrary pointer identifier). |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1945 | * |
| 1946 | * @see #AXIS_X |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1947 | */ |
| 1948 | public final float getX() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1949 | return nativeGetAxisValue(mNativePtr, AXIS_X, 0, HISTORY_CURRENT); |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1950 | } |
| 1951 | |
| 1952 | /** |
| 1953 | * {@link #getY(int)} for the first pointer index (may be an |
| 1954 | * arbitrary pointer identifier). |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1955 | * |
| 1956 | * @see #AXIS_Y |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1957 | */ |
| 1958 | public final float getY() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1959 | return nativeGetAxisValue(mNativePtr, AXIS_Y, 0, HISTORY_CURRENT); |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1960 | } |
| 1961 | |
| 1962 | /** |
| 1963 | * {@link #getPressure(int)} for the first pointer index (may be an |
| 1964 | * arbitrary pointer identifier). |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1965 | * |
| 1966 | * @see #AXIS_PRESSURE |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1967 | */ |
| 1968 | public final float getPressure() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1969 | return nativeGetAxisValue(mNativePtr, AXIS_PRESSURE, 0, HISTORY_CURRENT); |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1970 | } |
| 1971 | |
| 1972 | /** |
| 1973 | * {@link #getSize(int)} for the first pointer index (may be an |
| 1974 | * arbitrary pointer identifier). |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1975 | * |
| 1976 | * @see #AXIS_SIZE |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1977 | */ |
| 1978 | public final float getSize() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1979 | return nativeGetAxisValue(mNativePtr, AXIS_SIZE, 0, HISTORY_CURRENT); |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1980 | } |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1981 | |
| 1982 | /** |
| 1983 | * {@link #getTouchMajor(int)} for the first pointer index (may be an |
| 1984 | * arbitrary pointer identifier). |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1985 | * |
| 1986 | * @see #AXIS_TOUCH_MAJOR |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1987 | */ |
| 1988 | public final float getTouchMajor() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1989 | return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MAJOR, 0, HISTORY_CURRENT); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1990 | } |
| 1991 | |
| 1992 | /** |
| 1993 | * {@link #getTouchMinor(int)} for the first pointer index (may be an |
| 1994 | * arbitrary pointer identifier). |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1995 | * |
| 1996 | * @see #AXIS_TOUCH_MINOR |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1997 | */ |
| 1998 | public final float getTouchMinor() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 1999 | return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MINOR, 0, HISTORY_CURRENT); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2000 | } |
| 2001 | |
| 2002 | /** |
| 2003 | * {@link #getToolMajor(int)} for the first pointer index (may be an |
| 2004 | * arbitrary pointer identifier). |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2005 | * |
| 2006 | * @see #AXIS_TOOL_MAJOR |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2007 | */ |
| 2008 | public final float getToolMajor() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2009 | return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MAJOR, 0, HISTORY_CURRENT); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2010 | } |
| 2011 | |
| 2012 | /** |
| 2013 | * {@link #getToolMinor(int)} for the first pointer index (may be an |
| 2014 | * arbitrary pointer identifier). |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2015 | * |
| 2016 | * @see #AXIS_TOOL_MINOR |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2017 | */ |
| 2018 | public final float getToolMinor() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2019 | return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MINOR, 0, HISTORY_CURRENT); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2020 | } |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2021 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2022 | /** |
| 2023 | * {@link #getOrientation(int)} for the first pointer index (may be an |
| 2024 | * arbitrary pointer identifier). |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2025 | * |
| 2026 | * @see #AXIS_ORIENTATION |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2027 | */ |
| 2028 | public final float getOrientation() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2029 | return nativeGetAxisValue(mNativePtr, AXIS_ORIENTATION, 0, HISTORY_CURRENT); |
| 2030 | } |
| 2031 | |
| 2032 | /** |
| 2033 | * {@link #getAxisValue(int)} for the first pointer index (may be an |
| 2034 | * arbitrary pointer identifier). |
| 2035 | * |
| 2036 | * @param axis The axis identifier for the axis value to retrieve. |
| 2037 | * |
| 2038 | * @see #AXIS_X |
| 2039 | * @see #AXIS_Y |
| 2040 | */ |
| 2041 | public final float getAxisValue(int axis) { |
| 2042 | return nativeGetAxisValue(mNativePtr, axis, 0, HISTORY_CURRENT); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2043 | } |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 2044 | |
| 2045 | /** |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 2046 | * The number of pointers of data contained in this event. Always |
| 2047 | * >= 1. |
| 2048 | */ |
| 2049 | public final int getPointerCount() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2050 | return nativeGetPointerCount(mNativePtr); |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 2051 | } |
| 2052 | |
| 2053 | /** |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 2054 | * Return the pointer identifier associated with a particular pointer |
| 2055 | * data index is this event. The identifier tells you the actual pointer |
| 2056 | * number associated with the data, accounting for individual pointers |
| 2057 | * going up and down since the start of the current gesture. |
| 2058 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 2059 | * (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] | 2060 | */ |
Dianne Hackborn | d41ba66 | 2009-08-05 15:30:56 -0700 | [diff] [blame] | 2061 | public final int getPointerId(int pointerIndex) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2062 | return nativeGetPointerId(mNativePtr, pointerIndex); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2063 | } |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 2064 | |
| 2065 | /** |
| 2066 | * Gets the tool type of a pointer for the given pointer index. |
| 2067 | * The tool type indicates the type of tool used to make contact such |
| 2068 | * as a finger or stylus, if known. |
| 2069 | * |
| 2070 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 2071 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
| 2072 | * @return The tool type of the pointer. |
| 2073 | * |
| 2074 | * @see #TOOL_TYPE_UNKNOWN |
| 2075 | * @see #TOOL_TYPE_FINGER |
| 2076 | * @see #TOOL_TYPE_STYLUS |
| 2077 | * @see #TOOL_TYPE_MOUSE |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 2078 | */ |
| 2079 | public final int getToolType(int pointerIndex) { |
| 2080 | return nativeGetToolType(mNativePtr, pointerIndex); |
| 2081 | } |
| 2082 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2083 | /** |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 2084 | * Given a pointer identifier, find the index of its data in the event. |
| 2085 | * |
| 2086 | * @param pointerId The identifier of the pointer to be found. |
| 2087 | * @return Returns either the index of the pointer (for use with |
Gilles Debunne | b0d6ba1 | 2010-08-17 20:01:42 -0700 | [diff] [blame] | 2088 | * {@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] | 2089 | * that pointer identifier. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2090 | */ |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 2091 | public final int findPointerIndex(int pointerId) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2092 | return nativeFindPointerIndex(mNativePtr, pointerId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2093 | } |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 2094 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2095 | /** |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 2096 | * Returns the X coordinate of this event for the given pointer |
| 2097 | * <em>index</em> (use {@link #getPointerId(int)} to find the pointer |
| 2098 | * identifier for this index). |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 2099 | * Whole numbers are pixels; the |
| 2100 | * 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] | 2101 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 2102 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2103 | * |
| 2104 | * @see #AXIS_X |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 2105 | */ |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 2106 | public final float getX(int pointerIndex) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2107 | return nativeGetAxisValue(mNativePtr, AXIS_X, pointerIndex, HISTORY_CURRENT); |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 2108 | } |
| 2109 | |
| 2110 | /** |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 2111 | * Returns the Y coordinate of this event for the given pointer |
| 2112 | * <em>index</em> (use {@link #getPointerId(int)} to find the pointer |
| 2113 | * identifier for this index). |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 2114 | * Whole numbers are pixels; the |
| 2115 | * 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] | 2116 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 2117 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2118 | * |
| 2119 | * @see #AXIS_Y |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 2120 | */ |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 2121 | public final float getY(int pointerIndex) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2122 | return nativeGetAxisValue(mNativePtr, AXIS_Y, pointerIndex, HISTORY_CURRENT); |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 2123 | } |
| 2124 | |
| 2125 | /** |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 2126 | * Returns the current pressure of this event for the given pointer |
| 2127 | * <em>index</em> (use {@link #getPointerId(int)} to find the pointer |
| 2128 | * identifier for this index). |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 2129 | * The pressure generally |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 2130 | * ranges from 0 (no pressure at all) to 1 (normal pressure), however |
| 2131 | * 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] | 2132 | * the input device. |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 2133 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 2134 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2135 | * |
| 2136 | * @see #AXIS_PRESSURE |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2137 | */ |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 2138 | public final float getPressure(int pointerIndex) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2139 | return nativeGetAxisValue(mNativePtr, AXIS_PRESSURE, pointerIndex, HISTORY_CURRENT); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2140 | } |
| 2141 | |
| 2142 | /** |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 2143 | * Returns a scaled value of the approximate size for the given pointer |
| 2144 | * <em>index</em> (use {@link #getPointerId(int)} to find the pointer |
| 2145 | * identifier for this index). |
| 2146 | * This represents some approximation of the area of the screen being |
| 2147 | * pressed; the actual value in pixels corresponding to the |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 2148 | * touch is normalized with the device specific range of values |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 2149 | * 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] | 2150 | * determine fat touch events. |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 2151 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 2152 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2153 | * |
| 2154 | * @see #AXIS_SIZE |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2155 | */ |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 2156 | public final float getSize(int pointerIndex) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2157 | return nativeGetAxisValue(mNativePtr, AXIS_SIZE, pointerIndex, HISTORY_CURRENT); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2158 | } |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2159 | |
| 2160 | /** |
| 2161 | * Returns the length of the major axis of an ellipse that describes the touch |
| 2162 | * area at the point of contact for the given pointer |
| 2163 | * <em>index</em> (use {@link #getPointerId(int)} to find the pointer |
| 2164 | * identifier for this index). |
| 2165 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 2166 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2167 | * |
| 2168 | * @see #AXIS_TOUCH_MAJOR |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2169 | */ |
| 2170 | public final float getTouchMajor(int pointerIndex) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2171 | return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MAJOR, pointerIndex, HISTORY_CURRENT); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2172 | } |
| 2173 | |
| 2174 | /** |
| 2175 | * Returns the length of the minor axis of an ellipse that describes the touch |
| 2176 | * area at the point of contact for the given pointer |
| 2177 | * <em>index</em> (use {@link #getPointerId(int)} to find the pointer |
| 2178 | * identifier for this index). |
| 2179 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 2180 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2181 | * |
| 2182 | * @see #AXIS_TOUCH_MINOR |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2183 | */ |
| 2184 | public final float getTouchMinor(int pointerIndex) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2185 | return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MINOR, pointerIndex, HISTORY_CURRENT); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2186 | } |
| 2187 | |
| 2188 | /** |
| 2189 | * Returns the length of the major axis of an ellipse that describes the size of |
| 2190 | * the approaching tool for the given pointer |
| 2191 | * <em>index</em> (use {@link #getPointerId(int)} to find the pointer |
| 2192 | * identifier for this index). |
| 2193 | * The tool area represents the estimated size of the finger or pen that is |
| 2194 | * touching the device independent of its actual touch area at the point of contact. |
| 2195 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 2196 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2197 | * |
| 2198 | * @see #AXIS_TOOL_MAJOR |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2199 | */ |
| 2200 | public final float getToolMajor(int pointerIndex) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2201 | return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MAJOR, pointerIndex, HISTORY_CURRENT); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2202 | } |
| 2203 | |
| 2204 | /** |
| 2205 | * Returns the length of the minor axis of an ellipse that describes the size of |
| 2206 | * the approaching tool for the given pointer |
| 2207 | * <em>index</em> (use {@link #getPointerId(int)} to find the pointer |
| 2208 | * identifier for this index). |
| 2209 | * The tool area represents the estimated size of the finger or pen that is |
| 2210 | * touching the device independent of its actual touch area at the point of contact. |
| 2211 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 2212 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2213 | * |
| 2214 | * @see #AXIS_TOOL_MINOR |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2215 | */ |
| 2216 | public final float getToolMinor(int pointerIndex) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2217 | return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MINOR, pointerIndex, HISTORY_CURRENT); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2218 | } |
| 2219 | |
| 2220 | /** |
| 2221 | * Returns the orientation of the touch area and tool area in radians clockwise from vertical |
| 2222 | * for the given pointer <em>index</em> (use {@link #getPointerId(int)} to find the pointer |
| 2223 | * identifier for this index). |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 2224 | * 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] | 2225 | * upwards, is perfectly circular or is of unknown orientation. A positive angle |
| 2226 | * indicates that the major axis of contact is oriented to the right. A negative angle |
| 2227 | * indicates that the major axis of contact is oriented to the left. |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 2228 | * 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] | 2229 | * (finger pointing fully right). |
| 2230 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 2231 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2232 | * |
| 2233 | * @see #AXIS_ORIENTATION |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2234 | */ |
| 2235 | public final float getOrientation(int pointerIndex) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2236 | return nativeGetAxisValue(mNativePtr, AXIS_ORIENTATION, pointerIndex, HISTORY_CURRENT); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2237 | } |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2238 | |
| 2239 | /** |
| 2240 | * Returns the value of the requested axis for the given pointer <em>index</em> |
| 2241 | * (use {@link #getPointerId(int)} to find the pointer identifier for this index). |
| 2242 | * |
| 2243 | * @param axis The axis identifier for the axis value to retrieve. |
| 2244 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 2245 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
| 2246 | * @return The value of the axis, or 0 if the axis is not available. |
| 2247 | * |
| 2248 | * @see #AXIS_X |
| 2249 | * @see #AXIS_Y |
| 2250 | */ |
| 2251 | public final float getAxisValue(int axis, int pointerIndex) { |
| 2252 | return nativeGetAxisValue(mNativePtr, axis, pointerIndex, HISTORY_CURRENT); |
| 2253 | } |
| 2254 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2255 | /** |
| 2256 | * Populates a {@link PointerCoords} object with pointer coordinate data for |
| 2257 | * the specified pointer index. |
| 2258 | * |
| 2259 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 2260 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
| 2261 | * @param outPointerCoords The pointer coordinate object to populate. |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2262 | * |
| 2263 | * @see PointerCoords |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2264 | */ |
| 2265 | public final void getPointerCoords(int pointerIndex, PointerCoords outPointerCoords) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2266 | nativeGetPointerCoords(mNativePtr, pointerIndex, HISTORY_CURRENT, outPointerCoords); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2267 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2268 | |
| 2269 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 2270 | * Populates a {@link PointerProperties} object with pointer properties for |
| 2271 | * the specified pointer index. |
| 2272 | * |
| 2273 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 2274 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
| 2275 | * @param outPointerProperties The pointer properties object to populate. |
| 2276 | * |
| 2277 | * @see PointerProperties |
| 2278 | */ |
| 2279 | public final void getPointerProperties(int pointerIndex, |
| 2280 | PointerProperties outPointerProperties) { |
| 2281 | nativeGetPointerProperties(mNativePtr, pointerIndex, outPointerProperties); |
| 2282 | } |
| 2283 | |
| 2284 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2285 | * Returns the state of any meta / modifier keys that were in effect when |
| 2286 | * the event was generated. This is the same values as those |
| 2287 | * returned by {@link KeyEvent#getMetaState() KeyEvent.getMetaState}. |
| 2288 | * |
| 2289 | * @return an integer in which each bit set to 1 represents a pressed |
| 2290 | * meta key |
| 2291 | * |
| 2292 | * @see KeyEvent#getMetaState() |
| 2293 | */ |
| 2294 | public final int getMetaState() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2295 | return nativeGetMetaState(mNativePtr); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2296 | } |
| 2297 | |
| 2298 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 2299 | * Gets the state of all buttons that are pressed such as a mouse or stylus button. |
| 2300 | * |
| 2301 | * @return The button state. |
| 2302 | * |
| 2303 | * @see #BUTTON_PRIMARY |
| 2304 | * @see #BUTTON_SECONDARY |
| 2305 | * @see #BUTTON_TERTIARY |
| 2306 | * @see #BUTTON_FORWARD |
| 2307 | * @see #BUTTON_BACK |
Michael Wright | 5bd69e6 | 2015-05-14 14:48:08 +0100 | [diff] [blame] | 2308 | * @see #BUTTON_STYLUS_PRIMARY |
| 2309 | * @see #BUTTON_STYLUS_SECONDARY |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 2310 | */ |
| 2311 | public final int getButtonState() { |
| 2312 | return nativeGetButtonState(mNativePtr); |
| 2313 | } |
| 2314 | |
| 2315 | /** |
Michael Wright | 5bd69e6 | 2015-05-14 14:48:08 +0100 | [diff] [blame] | 2316 | * Sets the bitfield indicating which buttons are pressed. |
| 2317 | * |
| 2318 | * @see #getButtonState() |
| 2319 | * @hide |
| 2320 | */ |
| 2321 | public final void setButtonState(int buttonState) { |
| 2322 | nativeSetButtonState(mNativePtr, buttonState); |
| 2323 | } |
| 2324 | |
| 2325 | /** |
| 2326 | * Gets which button has been modified during a press or release action. |
| 2327 | * |
| 2328 | * For actions other than {@link #ACTION_BUTTON_PRESS} and {@link #ACTION_BUTTON_RELEASE} |
| 2329 | * the returned value is undefined. |
| 2330 | * |
| 2331 | * @see #getButtonState() |
| 2332 | */ |
| 2333 | public final int getActionButton() { |
| 2334 | return nativeGetActionButton(mNativePtr); |
| 2335 | } |
| 2336 | |
| 2337 | /** |
Michael Wright | 6b819b4 | 2015-06-17 21:06:03 +0100 | [diff] [blame] | 2338 | * Sets the action button for the event. |
| 2339 | * |
| 2340 | * @see #getActionButton() |
| 2341 | * @hide |
| 2342 | */ |
| 2343 | public final void setActionButton(int button) { |
| 2344 | nativeSetActionButton(mNativePtr, button); |
| 2345 | } |
| 2346 | |
| 2347 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2348 | * Returns the original raw X coordinate of this event. For touch |
| 2349 | * events on the screen, this is the original location of the event |
| 2350 | * on the screen, before it had been adjusted for the containing window |
| 2351 | * and views. |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2352 | * |
Michael Wright | 072137c | 2013-04-24 20:41:20 -0700 | [diff] [blame] | 2353 | * @see #getX(int) |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2354 | * @see #AXIS_X |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2355 | */ |
| 2356 | public final float getRawX() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2357 | return nativeGetRawAxisValue(mNativePtr, AXIS_X, 0, HISTORY_CURRENT); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2358 | } |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2359 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2360 | /** |
| 2361 | * Returns the original raw Y coordinate of this event. For touch |
| 2362 | * events on the screen, this is the original location of the event |
| 2363 | * on the screen, before it had been adjusted for the containing window |
| 2364 | * and views. |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2365 | * |
Michael Wright | 072137c | 2013-04-24 20:41:20 -0700 | [diff] [blame] | 2366 | * @see #getY(int) |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2367 | * @see #AXIS_Y |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2368 | */ |
| 2369 | public final float getRawY() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2370 | return nativeGetRawAxisValue(mNativePtr, AXIS_Y, 0, HISTORY_CURRENT); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2371 | } |
| 2372 | |
| 2373 | /** |
| 2374 | * Return the precision of the X coordinates being reported. You can |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2375 | * 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] | 2376 | * value of the X coordinate. |
| 2377 | * @return Returns the precision of X coordinates being reported. |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2378 | * |
| 2379 | * @see #AXIS_X |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2380 | */ |
| 2381 | public final float getXPrecision() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2382 | return nativeGetXPrecision(mNativePtr); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2383 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 2384 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2385 | /** |
| 2386 | * Return the precision of the Y coordinates being reported. You can |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2387 | * 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] | 2388 | * value of the Y coordinate. |
| 2389 | * @return Returns the precision of Y coordinates being reported. |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2390 | * |
| 2391 | * @see #AXIS_Y |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2392 | */ |
| 2393 | public final float getYPrecision() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2394 | return nativeGetYPrecision(mNativePtr); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2395 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 2396 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2397 | /** |
| 2398 | * Returns the number of historical points in this event. These are |
| 2399 | * movements that have occurred between this event and the previous event. |
| 2400 | * This only applies to ACTION_MOVE events -- all other actions will have |
| 2401 | * a size of 0. |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 2402 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2403 | * @return Returns the number of historical points in the event. |
| 2404 | */ |
| 2405 | public final int getHistorySize() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2406 | return nativeGetHistorySize(mNativePtr); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2407 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 2408 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2409 | /** |
| 2410 | * Returns the time that a historical movement occurred between this event |
Jeff Brown | b11499d | 2012-04-20 19:54:22 -0700 | [diff] [blame] | 2411 | * and the previous event, in the {@link android.os.SystemClock#uptimeMillis} time base. |
| 2412 | * <p> |
| 2413 | * This only applies to ACTION_MOVE events. |
| 2414 | * </p> |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 2415 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2416 | * @param pos Which historical value to return; must be less than |
| 2417 | * {@link #getHistorySize} |
Jeff Brown | b11499d | 2012-04-20 19:54:22 -0700 | [diff] [blame] | 2418 | * @return Returns the time that a historical movement occurred between this |
| 2419 | * event and the previous event, |
| 2420 | * in the {@link android.os.SystemClock#uptimeMillis} time base. |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 2421 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2422 | * @see #getHistorySize |
| 2423 | * @see #getEventTime |
| 2424 | */ |
| 2425 | public final long getHistoricalEventTime(int pos) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2426 | return nativeGetEventTimeNanos(mNativePtr, pos) / NS_PER_MS; |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 2427 | } |
| 2428 | |
| 2429 | /** |
Jeff Brown | b11499d | 2012-04-20 19:54:22 -0700 | [diff] [blame] | 2430 | * Returns the time that a historical movement occurred between this event |
| 2431 | * and the previous event, in the {@link android.os.SystemClock#uptimeMillis} time base |
| 2432 | * but with nanosecond (instead of millisecond) precision. |
| 2433 | * <p> |
| 2434 | * This only applies to ACTION_MOVE events. |
| 2435 | * </p><p> |
| 2436 | * The value is in nanosecond precision but it may not have nanosecond accuracy. |
| 2437 | * </p> |
| 2438 | * |
| 2439 | * @param pos Which historical value to return; must be less than |
| 2440 | * {@link #getHistorySize} |
| 2441 | * @return Returns the time that a historical movement occurred between this |
| 2442 | * event and the previous event, |
| 2443 | * in the {@link android.os.SystemClock#uptimeMillis} time base but with |
| 2444 | * nanosecond (instead of millisecond) precision. |
| 2445 | * |
| 2446 | * @see #getHistorySize |
| 2447 | * @see #getEventTime |
| 2448 | * |
| 2449 | * @hide |
| 2450 | */ |
| 2451 | public final long getHistoricalEventTimeNano(int pos) { |
| 2452 | return nativeGetEventTimeNanos(mNativePtr, pos); |
| 2453 | } |
| 2454 | |
| 2455 | /** |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2456 | * {@link #getHistoricalX(int, int)} for the first pointer index (may be an |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 2457 | * arbitrary pointer identifier). |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2458 | * |
| 2459 | * @param pos Which historical value to return; must be less than |
| 2460 | * {@link #getHistorySize} |
| 2461 | * |
| 2462 | * @see #getHistorySize |
| 2463 | * @see #getX() |
| 2464 | * @see #AXIS_X |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 2465 | */ |
| 2466 | public final float getHistoricalX(int pos) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2467 | return nativeGetAxisValue(mNativePtr, AXIS_X, 0, pos); |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 2468 | } |
| 2469 | |
| 2470 | /** |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2471 | * {@link #getHistoricalY(int, int)} for the first pointer index (may be an |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 2472 | * arbitrary pointer identifier). |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2473 | * |
| 2474 | * @param pos Which historical value to return; must be less than |
| 2475 | * {@link #getHistorySize} |
| 2476 | * |
| 2477 | * @see #getHistorySize |
| 2478 | * @see #getY() |
| 2479 | * @see #AXIS_Y |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 2480 | */ |
| 2481 | public final float getHistoricalY(int pos) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2482 | return nativeGetAxisValue(mNativePtr, AXIS_Y, 0, pos); |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 2483 | } |
| 2484 | |
| 2485 | /** |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2486 | * {@link #getHistoricalPressure(int, int)} for the first pointer index (may be an |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 2487 | * arbitrary pointer identifier). |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2488 | * |
| 2489 | * @param pos Which historical value to return; must be less than |
| 2490 | * {@link #getHistorySize} |
| 2491 | * |
| 2492 | * @see #getHistorySize |
| 2493 | * @see #getPressure() |
| 2494 | * @see #AXIS_PRESSURE |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 2495 | */ |
| 2496 | public final float getHistoricalPressure(int pos) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2497 | return nativeGetAxisValue(mNativePtr, AXIS_PRESSURE, 0, pos); |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 2498 | } |
| 2499 | |
| 2500 | /** |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2501 | * {@link #getHistoricalSize(int, int)} for the first pointer index (may be an |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 2502 | * arbitrary pointer identifier). |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2503 | * |
| 2504 | * @param pos Which historical value to return; must be less than |
| 2505 | * {@link #getHistorySize} |
| 2506 | * |
| 2507 | * @see #getHistorySize |
| 2508 | * @see #getSize() |
| 2509 | * @see #AXIS_SIZE |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 2510 | */ |
| 2511 | public final float getHistoricalSize(int pos) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2512 | return nativeGetAxisValue(mNativePtr, AXIS_SIZE, 0, pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2513 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 2514 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2515 | /** |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2516 | * {@link #getHistoricalTouchMajor(int, int)} for the first pointer index (may be an |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2517 | * arbitrary pointer identifier). |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2518 | * |
| 2519 | * @param pos Which historical value to return; must be less than |
| 2520 | * {@link #getHistorySize} |
| 2521 | * |
| 2522 | * @see #getHistorySize |
| 2523 | * @see #getTouchMajor() |
| 2524 | * @see #AXIS_TOUCH_MAJOR |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2525 | */ |
| 2526 | public final float getHistoricalTouchMajor(int pos) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2527 | return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MAJOR, 0, pos); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2528 | } |
| 2529 | |
| 2530 | /** |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2531 | * {@link #getHistoricalTouchMinor(int, int)} for the first pointer index (may be an |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2532 | * arbitrary pointer identifier). |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2533 | * |
| 2534 | * @param pos Which historical value to return; must be less than |
| 2535 | * {@link #getHistorySize} |
| 2536 | * |
| 2537 | * @see #getHistorySize |
| 2538 | * @see #getTouchMinor() |
| 2539 | * @see #AXIS_TOUCH_MINOR |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2540 | */ |
| 2541 | public final float getHistoricalTouchMinor(int pos) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2542 | return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MINOR, 0, pos); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2543 | } |
| 2544 | |
| 2545 | /** |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2546 | * {@link #getHistoricalToolMajor(int, int)} for the first pointer index (may be an |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2547 | * arbitrary pointer identifier). |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2548 | * |
| 2549 | * @param pos Which historical value to return; must be less than |
| 2550 | * {@link #getHistorySize} |
| 2551 | * |
| 2552 | * @see #getHistorySize |
| 2553 | * @see #getToolMajor() |
| 2554 | * @see #AXIS_TOOL_MAJOR |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2555 | */ |
| 2556 | public final float getHistoricalToolMajor(int pos) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2557 | return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MAJOR, 0, pos); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2558 | } |
| 2559 | |
| 2560 | /** |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2561 | * {@link #getHistoricalToolMinor(int, int)} for the first pointer index (may be an |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2562 | * arbitrary pointer identifier). |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2563 | * |
| 2564 | * @param pos Which historical value to return; must be less than |
| 2565 | * {@link #getHistorySize} |
| 2566 | * |
| 2567 | * @see #getHistorySize |
| 2568 | * @see #getToolMinor() |
| 2569 | * @see #AXIS_TOOL_MINOR |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2570 | */ |
| 2571 | public final float getHistoricalToolMinor(int pos) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2572 | return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MINOR, 0, pos); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2573 | } |
| 2574 | |
| 2575 | /** |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2576 | * {@link #getHistoricalOrientation(int, int)} for the first pointer index (may be an |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2577 | * arbitrary pointer identifier). |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2578 | * |
| 2579 | * @param pos Which historical value to return; must be less than |
| 2580 | * {@link #getHistorySize} |
| 2581 | * |
| 2582 | * @see #getHistorySize |
| 2583 | * @see #getOrientation() |
| 2584 | * @see #AXIS_ORIENTATION |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2585 | */ |
| 2586 | public final float getHistoricalOrientation(int pos) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2587 | return nativeGetAxisValue(mNativePtr, AXIS_ORIENTATION, 0, pos); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2588 | } |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2589 | |
| 2590 | /** |
| 2591 | * {@link #getHistoricalAxisValue(int, int, int)} for the first pointer index (may be an |
| 2592 | * arbitrary pointer identifier). |
| 2593 | * |
| 2594 | * @param axis The axis identifier for the axis value to retrieve. |
| 2595 | * @param pos Which historical value to return; must be less than |
| 2596 | * {@link #getHistorySize} |
| 2597 | * |
| 2598 | * @see #getHistorySize |
| 2599 | * @see #getAxisValue(int) |
| 2600 | * @see #AXIS_X |
| 2601 | * @see #AXIS_Y |
| 2602 | */ |
| 2603 | public final float getHistoricalAxisValue(int axis, int pos) { |
| 2604 | return nativeGetAxisValue(mNativePtr, axis, 0, pos); |
| 2605 | } |
| 2606 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2607 | /** |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 2608 | * Returns a historical X coordinate, as per {@link #getX(int)}, that |
| 2609 | * occurred between this event and the previous event for the given pointer. |
| 2610 | * Only applies to ACTION_MOVE events. |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 2611 | * |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 2612 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 2613 | * (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] | 2614 | * @param pos Which historical value to return; must be less than |
| 2615 | * {@link #getHistorySize} |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 2616 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2617 | * @see #getHistorySize |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2618 | * @see #getX(int) |
| 2619 | * @see #AXIS_X |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2620 | */ |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 2621 | public final float getHistoricalX(int pointerIndex, int pos) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2622 | return nativeGetAxisValue(mNativePtr, AXIS_X, pointerIndex, pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2623 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 2624 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2625 | /** |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 2626 | * Returns a historical Y coordinate, as per {@link #getY(int)}, that |
| 2627 | * occurred between this event and the previous event for the given pointer. |
| 2628 | * Only applies to ACTION_MOVE events. |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 2629 | * |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 2630 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 2631 | * (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] | 2632 | * @param pos Which historical value to return; must be less than |
| 2633 | * {@link #getHistorySize} |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 2634 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2635 | * @see #getHistorySize |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2636 | * @see #getY(int) |
| 2637 | * @see #AXIS_Y |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2638 | */ |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 2639 | public final float getHistoricalY(int pointerIndex, int pos) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2640 | return nativeGetAxisValue(mNativePtr, AXIS_Y, pointerIndex, pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2641 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 2642 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2643 | /** |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 2644 | * Returns a historical pressure coordinate, as per {@link #getPressure(int)}, |
| 2645 | * that occurred between this event and the previous event for the given |
| 2646 | * pointer. Only applies to ACTION_MOVE events. |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 2647 | * |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 2648 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 2649 | * (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] | 2650 | * @param pos Which historical value to return; must be less than |
| 2651 | * {@link #getHistorySize} |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 2652 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2653 | * @see #getHistorySize |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2654 | * @see #getPressure(int) |
| 2655 | * @see #AXIS_PRESSURE |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2656 | */ |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 2657 | public final float getHistoricalPressure(int pointerIndex, int pos) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2658 | return nativeGetAxisValue(mNativePtr, AXIS_PRESSURE, pointerIndex, pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2659 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 2660 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2661 | /** |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 2662 | * Returns a historical size coordinate, as per {@link #getSize(int)}, that |
| 2663 | * occurred between this event and the previous event for the given pointer. |
| 2664 | * Only applies to ACTION_MOVE events. |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 2665 | * |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 2666 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 2667 | * (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] | 2668 | * @param pos Which historical value to return; must be less than |
| 2669 | * {@link #getHistorySize} |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 2670 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2671 | * @see #getHistorySize |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2672 | * @see #getSize(int) |
| 2673 | * @see #AXIS_SIZE |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2674 | */ |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 2675 | public final float getHistoricalSize(int pointerIndex, int pos) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2676 | return nativeGetAxisValue(mNativePtr, AXIS_SIZE, pointerIndex, pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2677 | } |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2678 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2679 | /** |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2680 | * Returns a historical touch major axis coordinate, as per {@link #getTouchMajor(int)}, that |
| 2681 | * occurred between this event and the previous event for the given pointer. |
| 2682 | * Only applies to ACTION_MOVE events. |
| 2683 | * |
| 2684 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 2685 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
| 2686 | * @param pos Which historical value to return; must be less than |
| 2687 | * {@link #getHistorySize} |
| 2688 | * |
| 2689 | * @see #getHistorySize |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2690 | * @see #getTouchMajor(int) |
| 2691 | * @see #AXIS_TOUCH_MAJOR |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2692 | */ |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2693 | public final float getHistoricalTouchMajor(int pointerIndex, int pos) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2694 | return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MAJOR, pointerIndex, pos); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2695 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 2696 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2697 | /** |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2698 | * Returns a historical touch minor axis coordinate, as per {@link #getTouchMinor(int)}, that |
| 2699 | * occurred between this event and the previous event for the given pointer. |
| 2700 | * Only applies to ACTION_MOVE events. |
| 2701 | * |
| 2702 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 2703 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
| 2704 | * @param pos Which historical value to return; must be less than |
| 2705 | * {@link #getHistorySize} |
| 2706 | * |
| 2707 | * @see #getHistorySize |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2708 | * @see #getTouchMinor(int) |
| 2709 | * @see #AXIS_TOUCH_MINOR |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2710 | */ |
| 2711 | public final float getHistoricalTouchMinor(int pointerIndex, int pos) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2712 | return nativeGetAxisValue(mNativePtr, AXIS_TOUCH_MINOR, pointerIndex, pos); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2713 | } |
| 2714 | |
| 2715 | /** |
| 2716 | * Returns a historical tool major axis coordinate, as per {@link #getToolMajor(int)}, that |
| 2717 | * occurred between this event and the previous event for the given pointer. |
| 2718 | * Only applies to ACTION_MOVE events. |
| 2719 | * |
| 2720 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 2721 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
| 2722 | * @param pos Which historical value to return; must be less than |
| 2723 | * {@link #getHistorySize} |
| 2724 | * |
| 2725 | * @see #getHistorySize |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2726 | * @see #getToolMajor(int) |
| 2727 | * @see #AXIS_TOOL_MAJOR |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2728 | */ |
| 2729 | public final float getHistoricalToolMajor(int pointerIndex, int pos) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2730 | return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MAJOR, pointerIndex, pos); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2731 | } |
| 2732 | |
| 2733 | /** |
| 2734 | * Returns a historical tool minor axis coordinate, as per {@link #getToolMinor(int)}, that |
| 2735 | * occurred between this event and the previous event for the given pointer. |
| 2736 | * Only applies to ACTION_MOVE events. |
| 2737 | * |
| 2738 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 2739 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
| 2740 | * @param pos Which historical value to return; must be less than |
| 2741 | * {@link #getHistorySize} |
| 2742 | * |
| 2743 | * @see #getHistorySize |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2744 | * @see #getToolMinor(int) |
| 2745 | * @see #AXIS_TOOL_MINOR |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2746 | */ |
| 2747 | public final float getHistoricalToolMinor(int pointerIndex, int pos) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2748 | return nativeGetAxisValue(mNativePtr, AXIS_TOOL_MINOR, pointerIndex, pos); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2749 | } |
| 2750 | |
| 2751 | /** |
| 2752 | * Returns a historical orientation coordinate, as per {@link #getOrientation(int)}, that |
| 2753 | * occurred between this event and the previous event for the given pointer. |
| 2754 | * Only applies to ACTION_MOVE events. |
| 2755 | * |
| 2756 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 2757 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
| 2758 | * @param pos Which historical value to return; must be less than |
| 2759 | * {@link #getHistorySize} |
| 2760 | * |
| 2761 | * @see #getHistorySize |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2762 | * @see #getOrientation(int) |
| 2763 | * @see #AXIS_ORIENTATION |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2764 | */ |
| 2765 | public final float getHistoricalOrientation(int pointerIndex, int pos) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2766 | return nativeGetAxisValue(mNativePtr, AXIS_ORIENTATION, pointerIndex, pos); |
| 2767 | } |
| 2768 | |
| 2769 | /** |
| 2770 | * Returns the historical value of the requested axis, as per {@link #getAxisValue(int, int)}, |
| 2771 | * occurred between this event and the previous event for the given pointer. |
| 2772 | * Only applies to ACTION_MOVE events. |
| 2773 | * |
| 2774 | * @param axis The axis identifier for the axis value to retrieve. |
| 2775 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 2776 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
| 2777 | * @param pos Which historical value to return; must be less than |
| 2778 | * {@link #getHistorySize} |
| 2779 | * @return The value of the axis, or 0 if the axis is not available. |
| 2780 | * |
| 2781 | * @see #AXIS_X |
| 2782 | * @see #AXIS_Y |
| 2783 | */ |
| 2784 | public final float getHistoricalAxisValue(int axis, int pointerIndex, int pos) { |
| 2785 | return nativeGetAxisValue(mNativePtr, axis, pointerIndex, pos); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2786 | } |
| 2787 | |
| 2788 | /** |
| 2789 | * Populates a {@link PointerCoords} object with historical pointer coordinate data, |
| 2790 | * as per {@link #getPointerCoords}, that occurred between this event and the previous |
| 2791 | * event for the given pointer. |
| 2792 | * Only applies to ACTION_MOVE events. |
| 2793 | * |
| 2794 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 2795 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
| 2796 | * @param pos Which historical value to return; must be less than |
| 2797 | * {@link #getHistorySize} |
| 2798 | * @param outPointerCoords The pointer coordinate object to populate. |
| 2799 | * |
| 2800 | * @see #getHistorySize |
| 2801 | * @see #getPointerCoords |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2802 | * @see PointerCoords |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2803 | */ |
| 2804 | public final void getHistoricalPointerCoords(int pointerIndex, int pos, |
| 2805 | PointerCoords outPointerCoords) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2806 | nativeGetPointerCoords(mNativePtr, pointerIndex, pos, outPointerCoords); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2807 | } |
| 2808 | |
| 2809 | /** |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2810 | * Returns a bitfield indicating which edges, if any, were touched by this |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 2811 | * MotionEvent. For touch events, clients can use this to determine if the |
| 2812 | * user's finger was touching the edge of the display. |
| 2813 | * |
Jeff Brown | d41cff2 | 2011-03-03 02:09:54 -0800 | [diff] [blame] | 2814 | * This property is only set for {@link #ACTION_DOWN} events. |
| 2815 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2816 | * @see #EDGE_LEFT |
| 2817 | * @see #EDGE_TOP |
| 2818 | * @see #EDGE_RIGHT |
| 2819 | * @see #EDGE_BOTTOM |
| 2820 | */ |
| 2821 | public final int getEdgeFlags() { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2822 | return nativeGetEdgeFlags(mNativePtr); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2823 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 2824 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2825 | /** |
Jeff Brown | 85a3176 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 2826 | * Sets the bitfield indicating which edges, if any, were touched by this |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 2827 | * MotionEvent. |
| 2828 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2829 | * @see #getEdgeFlags() |
| 2830 | */ |
| 2831 | public final void setEdgeFlags(int flags) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2832 | nativeSetEdgeFlags(mNativePtr, flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2833 | } |
| 2834 | |
| 2835 | /** |
| 2836 | * Sets this event's action. |
| 2837 | */ |
| 2838 | public final void setAction(int action) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2839 | nativeSetAction(mNativePtr, action); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2840 | } |
| 2841 | |
| 2842 | /** |
| 2843 | * Adjust this event's location. |
| 2844 | * @param deltaX Amount to add to the current X coordinate of the event. |
| 2845 | * @param deltaY Amount to add to the current Y coordinate of the event. |
| 2846 | */ |
| 2847 | public final void offsetLocation(float deltaX, float deltaY) { |
Jeff Brown | 9ea77fc | 2012-03-21 19:49:27 -0700 | [diff] [blame] | 2848 | if (deltaX != 0.0f || deltaY != 0.0f) { |
| 2849 | nativeOffsetLocation(mNativePtr, deltaX, deltaY); |
| 2850 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2851 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 2852 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2853 | /** |
| 2854 | * Set this event's location. Applies {@link #offsetLocation} with a |
| 2855 | * delta from the current location to the given new location. |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 2856 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2857 | * @param x New absolute X location. |
| 2858 | * @param y New absolute Y location. |
| 2859 | */ |
| 2860 | public final void setLocation(float x, float y) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2861 | float oldX = getX(); |
| 2862 | float oldY = getY(); |
Jeff Brown | 9ea77fc | 2012-03-21 19:49:27 -0700 | [diff] [blame] | 2863 | offsetLocation(x - oldX, y - oldY); |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 2864 | } |
| 2865 | |
Jeff Brown | 20e987b | 2010-08-23 12:01:02 -0700 | [diff] [blame] | 2866 | /** |
| 2867 | * Applies a transformation matrix to all of the points in the event. |
| 2868 | * |
| 2869 | * @param matrix The transformation matrix to apply. |
| 2870 | */ |
| 2871 | public final void transform(Matrix matrix) { |
| 2872 | if (matrix == null) { |
| 2873 | throw new IllegalArgumentException("matrix must not be null"); |
| 2874 | } |
| 2875 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2876 | nativeTransform(mNativePtr, matrix); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2877 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 2878 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2879 | /** |
| 2880 | * 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] | 2881 | * current location, position and size is updated to the new values. |
| 2882 | * 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] | 2883 | * |
Jeff Brown | cc0c159 | 2011-02-19 05:07:28 -0800 | [diff] [blame] | 2884 | * Only applies to {@link #ACTION_MOVE} or {@link #ACTION_HOVER_MOVE} events. |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 2885 | * |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2886 | * @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] | 2887 | * @param x The new X position. |
| 2888 | * @param y The new Y position. |
| 2889 | * @param pressure The new pressure. |
| 2890 | * @param size The new size. |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 2891 | * @param metaState Meta key state. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2892 | */ |
| 2893 | public final void addBatch(long eventTime, float x, float y, |
| 2894 | float pressure, float size, int metaState) { |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 2895 | synchronized (gSharedTempLock) { |
| 2896 | ensureSharedTempPointerCapacity(1); |
| 2897 | final PointerCoords[] pc = gSharedTempPointerCoords; |
| 2898 | pc[0].clear(); |
| 2899 | pc[0].x = x; |
| 2900 | pc[0].y = y; |
| 2901 | pc[0].pressure = pressure; |
| 2902 | pc[0].size = size; |
| 2903 | |
| 2904 | nativeAddBatch(mNativePtr, eventTime * NS_PER_MS, pc, metaState); |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2905 | } |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 2906 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 2907 | |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 2908 | /** |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2909 | * Add a new movement to the batch of movements in this event. The event's |
| 2910 | * current location, position and size is updated to the new values. |
| 2911 | * 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] | 2912 | * |
Jeff Brown | cc0c159 | 2011-02-19 05:07:28 -0800 | [diff] [blame] | 2913 | * Only applies to {@link #ACTION_MOVE} or {@link #ACTION_HOVER_MOVE} events. |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2914 | * |
| 2915 | * @param eventTime The time stamp (in ms) for this data. |
| 2916 | * @param pointerCoords The new pointer coordinates. |
| 2917 | * @param metaState Meta key state. |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 2918 | */ |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 2919 | public final void addBatch(long eventTime, PointerCoords[] pointerCoords, int metaState) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 2920 | nativeAddBatch(mNativePtr, eventTime * NS_PER_MS, pointerCoords, metaState); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2921 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 2922 | |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 2923 | /** |
Jeff Brown | 9d3bdbd | 2012-03-21 11:50:06 -0700 | [diff] [blame] | 2924 | * Adds all of the movement samples of the specified event to this one if |
| 2925 | * it is compatible. To be compatible, the event must have the same device id, |
| 2926 | * source, action, flags, pointer count, pointer properties. |
| 2927 | * |
| 2928 | * Only applies to {@link #ACTION_MOVE} or {@link #ACTION_HOVER_MOVE} events. |
| 2929 | * |
| 2930 | * @param event The event whose movements samples should be added to this one |
| 2931 | * if possible. |
| 2932 | * @return True if batching was performed or false if batching was not possible. |
| 2933 | * @hide |
| 2934 | */ |
| 2935 | public final boolean addBatch(MotionEvent event) { |
| 2936 | final int action = nativeGetAction(mNativePtr); |
| 2937 | if (action != ACTION_MOVE && action != ACTION_HOVER_MOVE) { |
| 2938 | return false; |
| 2939 | } |
| 2940 | if (action != nativeGetAction(event.mNativePtr)) { |
| 2941 | return false; |
| 2942 | } |
| 2943 | |
| 2944 | if (nativeGetDeviceId(mNativePtr) != nativeGetDeviceId(event.mNativePtr) |
| 2945 | || nativeGetSource(mNativePtr) != nativeGetSource(event.mNativePtr) |
| 2946 | || nativeGetFlags(mNativePtr) != nativeGetFlags(event.mNativePtr)) { |
| 2947 | return false; |
| 2948 | } |
| 2949 | |
| 2950 | final int pointerCount = nativeGetPointerCount(mNativePtr); |
| 2951 | if (pointerCount != nativeGetPointerCount(event.mNativePtr)) { |
| 2952 | return false; |
| 2953 | } |
| 2954 | |
| 2955 | synchronized (gSharedTempLock) { |
| 2956 | ensureSharedTempPointerCapacity(Math.max(pointerCount, 2)); |
| 2957 | final PointerProperties[] pp = gSharedTempPointerProperties; |
| 2958 | final PointerCoords[] pc = gSharedTempPointerCoords; |
| 2959 | |
| 2960 | for (int i = 0; i < pointerCount; i++) { |
| 2961 | nativeGetPointerProperties(mNativePtr, i, pp[0]); |
| 2962 | nativeGetPointerProperties(event.mNativePtr, i, pp[1]); |
| 2963 | if (!pp[0].equals(pp[1])) { |
| 2964 | return false; |
| 2965 | } |
| 2966 | } |
| 2967 | |
| 2968 | final int metaState = nativeGetMetaState(event.mNativePtr); |
| 2969 | final int historySize = nativeGetHistorySize(event.mNativePtr); |
| 2970 | for (int h = 0; h <= historySize; h++) { |
| 2971 | final int historyPos = (h == historySize ? HISTORY_CURRENT : h); |
| 2972 | |
| 2973 | for (int i = 0; i < pointerCount; i++) { |
| 2974 | nativeGetPointerCoords(event.mNativePtr, i, historyPos, pc[i]); |
| 2975 | } |
| 2976 | |
| 2977 | final long eventTimeNanos = nativeGetEventTimeNanos(event.mNativePtr, historyPos); |
| 2978 | nativeAddBatch(mNativePtr, eventTimeNanos, pc, metaState); |
| 2979 | } |
| 2980 | } |
| 2981 | return true; |
| 2982 | } |
| 2983 | |
| 2984 | /** |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 2985 | * Returns true if all points in the motion event are completely within the specified bounds. |
| 2986 | * @hide |
| 2987 | */ |
| 2988 | public final boolean isWithinBoundsNoHistory(float left, float top, |
| 2989 | float right, float bottom) { |
| 2990 | final int pointerCount = nativeGetPointerCount(mNativePtr); |
| 2991 | for (int i = 0; i < pointerCount; i++) { |
| 2992 | final float x = nativeGetAxisValue(mNativePtr, AXIS_X, i, HISTORY_CURRENT); |
| 2993 | final float y = nativeGetAxisValue(mNativePtr, AXIS_Y, i, HISTORY_CURRENT); |
| 2994 | if (x < left || x > right || y < top || y > bottom) { |
| 2995 | return false; |
| 2996 | } |
| 2997 | } |
| 2998 | return true; |
| 2999 | } |
| 3000 | |
| 3001 | private static final float clamp(float value, float low, float high) { |
| 3002 | if (value < low) { |
| 3003 | return low; |
| 3004 | } else if (value > high) { |
| 3005 | return high; |
| 3006 | } |
| 3007 | return value; |
| 3008 | } |
| 3009 | |
| 3010 | /** |
| 3011 | * Returns a new motion events whose points have been clamped to the specified bounds. |
| 3012 | * @hide |
| 3013 | */ |
| 3014 | public final MotionEvent clampNoHistory(float left, float top, float right, float bottom) { |
| 3015 | MotionEvent ev = obtain(); |
| 3016 | synchronized (gSharedTempLock) { |
| 3017 | final int pointerCount = nativeGetPointerCount(mNativePtr); |
| 3018 | |
| 3019 | ensureSharedTempPointerCapacity(pointerCount); |
| 3020 | final PointerProperties[] pp = gSharedTempPointerProperties; |
| 3021 | final PointerCoords[] pc = gSharedTempPointerCoords; |
| 3022 | |
| 3023 | for (int i = 0; i < pointerCount; i++) { |
| 3024 | nativeGetPointerProperties(mNativePtr, i, pp[i]); |
| 3025 | nativeGetPointerCoords(mNativePtr, i, HISTORY_CURRENT, pc[i]); |
| 3026 | pc[i].x = clamp(pc[i].x, left, right); |
| 3027 | pc[i].y = clamp(pc[i].y, top, bottom); |
| 3028 | } |
| 3029 | ev.mNativePtr = nativeInitialize(ev.mNativePtr, |
| 3030 | nativeGetDeviceId(mNativePtr), nativeGetSource(mNativePtr), |
| 3031 | nativeGetAction(mNativePtr), nativeGetFlags(mNativePtr), |
| 3032 | nativeGetEdgeFlags(mNativePtr), nativeGetMetaState(mNativePtr), |
| 3033 | nativeGetButtonState(mNativePtr), |
| 3034 | nativeGetXOffset(mNativePtr), nativeGetYOffset(mNativePtr), |
| 3035 | nativeGetXPrecision(mNativePtr), nativeGetYPrecision(mNativePtr), |
| 3036 | nativeGetDownTimeNanos(mNativePtr), |
| 3037 | nativeGetEventTimeNanos(mNativePtr, HISTORY_CURRENT), |
| 3038 | pointerCount, pp, pc); |
| 3039 | return ev; |
| 3040 | } |
| 3041 | } |
| 3042 | |
| 3043 | /** |
| 3044 | * Gets an integer where each pointer id present in the event is marked as a bit. |
| 3045 | * @hide |
| 3046 | */ |
| 3047 | public final int getPointerIdBits() { |
| 3048 | int idBits = 0; |
| 3049 | final int pointerCount = nativeGetPointerCount(mNativePtr); |
| 3050 | for (int i = 0; i < pointerCount; i++) { |
| 3051 | idBits |= 1 << nativeGetPointerId(mNativePtr, i); |
| 3052 | } |
| 3053 | return idBits; |
| 3054 | } |
| 3055 | |
| 3056 | /** |
| 3057 | * Splits a motion event such that it includes only a subset of pointer ids. |
| 3058 | * @hide |
| 3059 | */ |
| 3060 | public final MotionEvent split(int idBits) { |
| 3061 | MotionEvent ev = obtain(); |
| 3062 | synchronized (gSharedTempLock) { |
| 3063 | final int oldPointerCount = nativeGetPointerCount(mNativePtr); |
| 3064 | ensureSharedTempPointerCapacity(oldPointerCount); |
| 3065 | final PointerProperties[] pp = gSharedTempPointerProperties; |
| 3066 | final PointerCoords[] pc = gSharedTempPointerCoords; |
| 3067 | final int[] map = gSharedTempPointerIndexMap; |
| 3068 | |
| 3069 | final int oldAction = nativeGetAction(mNativePtr); |
| 3070 | final int oldActionMasked = oldAction & ACTION_MASK; |
| 3071 | final int oldActionPointerIndex = (oldAction & ACTION_POINTER_INDEX_MASK) |
| 3072 | >> ACTION_POINTER_INDEX_SHIFT; |
| 3073 | int newActionPointerIndex = -1; |
| 3074 | int newPointerCount = 0; |
| 3075 | int newIdBits = 0; |
| 3076 | for (int i = 0; i < oldPointerCount; i++) { |
| 3077 | nativeGetPointerProperties(mNativePtr, i, pp[newPointerCount]); |
| 3078 | final int idBit = 1 << pp[newPointerCount].id; |
| 3079 | if ((idBit & idBits) != 0) { |
| 3080 | if (i == oldActionPointerIndex) { |
| 3081 | newActionPointerIndex = newPointerCount; |
| 3082 | } |
| 3083 | map[newPointerCount] = i; |
| 3084 | newPointerCount += 1; |
| 3085 | newIdBits |= idBit; |
| 3086 | } |
| 3087 | } |
| 3088 | |
| 3089 | if (newPointerCount == 0) { |
| 3090 | throw new IllegalArgumentException("idBits did not match any ids in the event"); |
| 3091 | } |
| 3092 | |
| 3093 | final int newAction; |
| 3094 | if (oldActionMasked == ACTION_POINTER_DOWN || oldActionMasked == ACTION_POINTER_UP) { |
| 3095 | if (newActionPointerIndex < 0) { |
| 3096 | // An unrelated pointer changed. |
| 3097 | newAction = ACTION_MOVE; |
| 3098 | } else if (newPointerCount == 1) { |
| 3099 | // The first/last pointer went down/up. |
| 3100 | newAction = oldActionMasked == ACTION_POINTER_DOWN |
| 3101 | ? ACTION_DOWN : ACTION_UP; |
| 3102 | } else { |
| 3103 | // A secondary pointer went down/up. |
| 3104 | newAction = oldActionMasked |
| 3105 | | (newActionPointerIndex << ACTION_POINTER_INDEX_SHIFT); |
| 3106 | } |
| 3107 | } else { |
| 3108 | // Simple up/down/cancel/move or other motion action. |
| 3109 | newAction = oldAction; |
| 3110 | } |
| 3111 | |
| 3112 | final int historySize = nativeGetHistorySize(mNativePtr); |
| 3113 | for (int h = 0; h <= historySize; h++) { |
| 3114 | final int historyPos = h == historySize ? HISTORY_CURRENT : h; |
| 3115 | |
| 3116 | for (int i = 0; i < newPointerCount; i++) { |
| 3117 | nativeGetPointerCoords(mNativePtr, map[i], historyPos, pc[i]); |
| 3118 | } |
| 3119 | |
| 3120 | final long eventTimeNanos = nativeGetEventTimeNanos(mNativePtr, historyPos); |
| 3121 | if (h == 0) { |
| 3122 | ev.mNativePtr = nativeInitialize(ev.mNativePtr, |
| 3123 | nativeGetDeviceId(mNativePtr), nativeGetSource(mNativePtr), |
| 3124 | newAction, nativeGetFlags(mNativePtr), |
| 3125 | nativeGetEdgeFlags(mNativePtr), nativeGetMetaState(mNativePtr), |
| 3126 | nativeGetButtonState(mNativePtr), |
| 3127 | nativeGetXOffset(mNativePtr), nativeGetYOffset(mNativePtr), |
| 3128 | nativeGetXPrecision(mNativePtr), nativeGetYPrecision(mNativePtr), |
| 3129 | nativeGetDownTimeNanos(mNativePtr), eventTimeNanos, |
| 3130 | newPointerCount, pp, pc); |
| 3131 | } else { |
| 3132 | nativeAddBatch(ev.mNativePtr, eventTimeNanos, pc, 0); |
| 3133 | } |
| 3134 | } |
| 3135 | return ev; |
| 3136 | } |
| 3137 | } |
| 3138 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3139 | @Override |
| 3140 | public String toString() { |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 3141 | StringBuilder msg = new StringBuilder(); |
| 3142 | msg.append("MotionEvent { action=").append(actionToString(getAction())); |
Michael Wright | 5bd69e6 | 2015-05-14 14:48:08 +0100 | [diff] [blame] | 3143 | msg.append(", actionButton=").append(buttonStateToString(getActionButton())); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 3144 | |
| 3145 | final int pointerCount = getPointerCount(); |
| 3146 | for (int i = 0; i < pointerCount; i++) { |
| 3147 | msg.append(", id[").append(i).append("]=").append(getPointerId(i)); |
| 3148 | msg.append(", x[").append(i).append("]=").append(getX(i)); |
| 3149 | msg.append(", y[").append(i).append("]=").append(getY(i)); |
| 3150 | msg.append(", toolType[").append(i).append("]=").append( |
| 3151 | toolTypeToString(getToolType(i))); |
| 3152 | } |
| 3153 | |
Jeff Brown | 8134681 | 2011-06-28 20:08:48 -0700 | [diff] [blame] | 3154 | msg.append(", buttonState=").append(MotionEvent.buttonStateToString(getButtonState())); |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 3155 | msg.append(", metaState=").append(KeyEvent.metaStateToString(getMetaState())); |
| 3156 | msg.append(", flags=0x").append(Integer.toHexString(getFlags())); |
| 3157 | msg.append(", edgeFlags=0x").append(Integer.toHexString(getEdgeFlags())); |
| 3158 | msg.append(", pointerCount=").append(pointerCount); |
| 3159 | msg.append(", historySize=").append(getHistorySize()); |
| 3160 | msg.append(", eventTime=").append(getEventTime()); |
| 3161 | msg.append(", downTime=").append(getDownTime()); |
| 3162 | msg.append(", deviceId=").append(getDeviceId()); |
| 3163 | msg.append(", source=0x").append(Integer.toHexString(getSource())); |
| 3164 | msg.append(" }"); |
| 3165 | return msg.toString(); |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 3166 | } |
| 3167 | |
| 3168 | /** |
John Spurlock | 4dad6ca | 2013-06-05 13:17:05 -0400 | [diff] [blame] | 3169 | * Returns a string that represents the symbolic name of the specified unmasked action |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 3170 | * such as "ACTION_DOWN", "ACTION_POINTER_DOWN(3)" or an equivalent numeric constant |
| 3171 | * such as "35" if unknown. |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 3172 | * |
John Spurlock | 4dad6ca | 2013-06-05 13:17:05 -0400 | [diff] [blame] | 3173 | * @param action The unmasked action. |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 3174 | * @return The symbolic name of the specified action. |
John Spurlock | 4dad6ca | 2013-06-05 13:17:05 -0400 | [diff] [blame] | 3175 | * @see #getAction() |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 3176 | */ |
| 3177 | public static String actionToString(int action) { |
| 3178 | switch (action) { |
| 3179 | case ACTION_DOWN: |
| 3180 | return "ACTION_DOWN"; |
| 3181 | case ACTION_UP: |
| 3182 | return "ACTION_UP"; |
| 3183 | case ACTION_CANCEL: |
| 3184 | return "ACTION_CANCEL"; |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 3185 | case ACTION_OUTSIDE: |
| 3186 | return "ACTION_OUTSIDE"; |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 3187 | case ACTION_MOVE: |
| 3188 | return "ACTION_MOVE"; |
Jeff Brown | cc0c159 | 2011-02-19 05:07:28 -0800 | [diff] [blame] | 3189 | case ACTION_HOVER_MOVE: |
| 3190 | return "ACTION_HOVER_MOVE"; |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 3191 | case ACTION_SCROLL: |
| 3192 | return "ACTION_SCROLL"; |
Jeff Brown | a032cc0 | 2011-03-07 16:56:21 -0800 | [diff] [blame] | 3193 | case ACTION_HOVER_ENTER: |
| 3194 | return "ACTION_HOVER_ENTER"; |
| 3195 | case ACTION_HOVER_EXIT: |
| 3196 | return "ACTION_HOVER_EXIT"; |
Michael Wright | 5bd69e6 | 2015-05-14 14:48:08 +0100 | [diff] [blame] | 3197 | case ACTION_BUTTON_PRESS: |
| 3198 | return "ACTION_BUTTON_PRESS"; |
| 3199 | case ACTION_BUTTON_RELEASE: |
| 3200 | return "ACTION_BUTTON_RELEASE"; |
Jeff Brown | 497a92c | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 3201 | } |
| 3202 | int index = (action & ACTION_POINTER_INDEX_MASK) >> ACTION_POINTER_INDEX_SHIFT; |
| 3203 | switch (action & ACTION_MASK) { |
| 3204 | case ACTION_POINTER_DOWN: |
| 3205 | return "ACTION_POINTER_DOWN(" + index + ")"; |
| 3206 | case ACTION_POINTER_UP: |
| 3207 | return "ACTION_POINTER_UP(" + index + ")"; |
| 3208 | default: |
| 3209 | return Integer.toString(action); |
| 3210 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3211 | } |
| 3212 | |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 3213 | /** |
| 3214 | * Returns a string that represents the symbolic name of the specified axis |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 3215 | * 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] | 3216 | * |
John Spurlock | 4dad6ca | 2013-06-05 13:17:05 -0400 | [diff] [blame] | 3217 | * @param axis The axis. |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 3218 | * @return The symbolic name of the specified axis. |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 3219 | */ |
| 3220 | public static String axisToString(int axis) { |
Michael Wright | 337d9d2 | 2014-04-22 15:03:48 -0700 | [diff] [blame] | 3221 | String symbolicName = nativeAxisToString(axis); |
| 3222 | return symbolicName != null ? LABEL_PREFIX + symbolicName : Integer.toString(axis); |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 3223 | } |
| 3224 | |
| 3225 | /** |
Jeff Brown | cc0c159 | 2011-02-19 05:07:28 -0800 | [diff] [blame] | 3226 | * Gets an axis by its symbolic name such as "AXIS_X" or an |
| 3227 | * equivalent numeric constant such as "42". |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 3228 | * |
| 3229 | * @param symbolicName The symbolic name of the axis. |
| 3230 | * @return The axis or -1 if not found. |
John Spurlock | 4dad6ca | 2013-06-05 13:17:05 -0400 | [diff] [blame] | 3231 | * @see KeyEvent#keyCodeToString(int) |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 3232 | */ |
| 3233 | public static int axisFromString(String symbolicName) { |
Michael Wright | 337d9d2 | 2014-04-22 15:03:48 -0700 | [diff] [blame] | 3234 | if (symbolicName.startsWith(LABEL_PREFIX)) { |
| 3235 | symbolicName = symbolicName.substring(LABEL_PREFIX.length()); |
Michael Wright | 973efa0 | 2014-05-13 15:38:56 -0700 | [diff] [blame] | 3236 | int axis = nativeAxisFromString(symbolicName); |
| 3237 | if (axis >= 0) { |
| 3238 | return axis; |
| 3239 | } |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 3240 | } |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 3241 | try { |
| 3242 | return Integer.parseInt(symbolicName, 10); |
| 3243 | } catch (NumberFormatException ex) { |
| 3244 | return -1; |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 3245 | } |
| 3246 | } |
| 3247 | |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 3248 | /** |
| 3249 | * Returns a string that represents the symbolic name of the specified combined |
| 3250 | * button state flags such as "0", "BUTTON_PRIMARY", |
| 3251 | * "BUTTON_PRIMARY|BUTTON_SECONDARY" or an equivalent numeric constant such as "0x10000000" |
| 3252 | * if unknown. |
| 3253 | * |
| 3254 | * @param buttonState The button state. |
| 3255 | * @return The symbolic name of the specified combined button state flags. |
| 3256 | * @hide |
| 3257 | */ |
| 3258 | public static String buttonStateToString(int buttonState) { |
| 3259 | if (buttonState == 0) { |
| 3260 | return "0"; |
| 3261 | } |
| 3262 | StringBuilder result = null; |
| 3263 | int i = 0; |
| 3264 | while (buttonState != 0) { |
| 3265 | final boolean isSet = (buttonState & 1) != 0; |
| 3266 | buttonState >>>= 1; // unsigned shift! |
| 3267 | if (isSet) { |
| 3268 | final String name = BUTTON_SYMBOLIC_NAMES[i]; |
| 3269 | if (result == null) { |
| 3270 | if (buttonState == 0) { |
| 3271 | return name; |
| 3272 | } |
| 3273 | result = new StringBuilder(name); |
| 3274 | } else { |
| 3275 | result.append('|'); |
| 3276 | result.append(name); |
| 3277 | } |
| 3278 | } |
| 3279 | i += 1; |
| 3280 | } |
| 3281 | return result.toString(); |
| 3282 | } |
| 3283 | |
| 3284 | /** |
| 3285 | * Returns a string that represents the symbolic name of the specified tool type |
| 3286 | * such as "TOOL_TYPE_FINGER" or an equivalent numeric constant such as "42" if unknown. |
| 3287 | * |
| 3288 | * @param toolType The tool type. |
| 3289 | * @return The symbolic name of the specified tool type. |
| 3290 | * @hide |
| 3291 | */ |
| 3292 | public static String toolTypeToString(int toolType) { |
| 3293 | String symbolicName = TOOL_TYPE_SYMBOLIC_NAMES.get(toolType); |
| 3294 | return symbolicName != null ? symbolicName : Integer.toString(toolType); |
| 3295 | } |
| 3296 | |
Sujith Ramakrishnan | cc32bd8 | 2014-05-19 15:32:13 -0700 | [diff] [blame] | 3297 | /** |
| 3298 | * Checks if a mouse or stylus button (or combination of buttons) is pressed. |
| 3299 | * @param button Button (or combination of buttons). |
| 3300 | * @return True if specified buttons are pressed. |
| 3301 | * |
| 3302 | * @see #BUTTON_PRIMARY |
| 3303 | * @see #BUTTON_SECONDARY |
| 3304 | * @see #BUTTON_TERTIARY |
| 3305 | * @see #BUTTON_FORWARD |
| 3306 | * @see #BUTTON_BACK |
Michael Wright | 5bd69e6 | 2015-05-14 14:48:08 +0100 | [diff] [blame] | 3307 | * @see #BUTTON_STYLUS_PRIMARY |
| 3308 | * @see #BUTTON_STYLUS_SECONDARY |
Sujith Ramakrishnan | cc32bd8 | 2014-05-19 15:32:13 -0700 | [diff] [blame] | 3309 | */ |
| 3310 | public final boolean isButtonPressed(int button) { |
| 3311 | if (button == 0) { |
| 3312 | return false; |
| 3313 | } |
| 3314 | return (getButtonState() & button) == button; |
| 3315 | } |
| 3316 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3317 | public static final Parcelable.Creator<MotionEvent> CREATOR |
| 3318 | = new Parcelable.Creator<MotionEvent>() { |
| 3319 | public MotionEvent createFromParcel(Parcel in) { |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 3320 | in.readInt(); // skip token, we already know this is a MotionEvent |
| 3321 | return MotionEvent.createFromParcelBody(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3322 | } |
| 3323 | |
| 3324 | public MotionEvent[] newArray(int size) { |
| 3325 | return new MotionEvent[size]; |
| 3326 | } |
| 3327 | }; |
| 3328 | |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 3329 | /** @hide */ |
| 3330 | public static MotionEvent createFromParcelBody(Parcel in) { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 3331 | MotionEvent ev = obtain(); |
| 3332 | ev.mNativePtr = nativeReadFromParcel(ev.mNativePtr, in); |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 3333 | return ev; |
| 3334 | } |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 3335 | |
Wale Ogunwale | c3672cd | 2014-11-05 15:17:35 -0800 | [diff] [blame] | 3336 | /** @hide */ |
| 3337 | @Override |
| 3338 | public final void cancel() { |
| 3339 | setAction(ACTION_CANCEL); |
| 3340 | } |
| 3341 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3342 | public void writeToParcel(Parcel out, int flags) { |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 3343 | out.writeInt(PARCEL_TOKEN_MOTION_EVENT); |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 3344 | nativeWriteToParcel(mNativePtr, out); |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 3345 | } |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 3346 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 3347 | /** |
| 3348 | * Transfer object for pointer coordinates. |
| 3349 | * |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 3350 | * Objects of this type can be used to specify the pointer coordinates when |
| 3351 | * creating new {@link MotionEvent} objects and to query pointer coordinates |
| 3352 | * in bulk. |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 3353 | * |
| 3354 | * Refer to {@link InputDevice} for information about how different kinds of |
| 3355 | * input devices and sources represent pointer coordinates. |
| 3356 | */ |
| 3357 | public static final class PointerCoords { |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 3358 | private static final int INITIAL_PACKED_AXIS_VALUES = 8; |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 3359 | private long mPackedAxisBits; |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 3360 | private float[] mPackedAxisValues; |
| 3361 | |
| 3362 | /** |
| 3363 | * Creates a pointer coords object with all axes initialized to zero. |
| 3364 | */ |
| 3365 | public PointerCoords() { |
| 3366 | } |
| 3367 | |
| 3368 | /** |
| 3369 | * Creates a pointer coords object as a copy of the |
| 3370 | * contents of another pointer coords object. |
| 3371 | * |
| 3372 | * @param other The pointer coords object to copy. |
| 3373 | */ |
| 3374 | public PointerCoords(PointerCoords other) { |
| 3375 | copyFrom(other); |
| 3376 | } |
| 3377 | |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 3378 | /** @hide */ |
| 3379 | public static PointerCoords[] createArray(int size) { |
| 3380 | PointerCoords[] array = new PointerCoords[size]; |
| 3381 | for (int i = 0; i < size; i++) { |
| 3382 | array[i] = new PointerCoords(); |
| 3383 | } |
| 3384 | return array; |
| 3385 | } |
| 3386 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 3387 | /** |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 3388 | * The X component of the pointer movement. |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 3389 | * |
| 3390 | * @see MotionEvent#AXIS_X |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 3391 | */ |
| 3392 | public float x; |
| 3393 | |
| 3394 | /** |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 3395 | * The Y component of the pointer movement. |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 3396 | * |
| 3397 | * @see MotionEvent#AXIS_Y |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 3398 | */ |
| 3399 | public float y; |
| 3400 | |
| 3401 | /** |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 3402 | * A normalized value that describes the pressure applied to the device |
| 3403 | * by a finger or other tool. |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 3404 | * 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] | 3405 | * 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] | 3406 | * the input device. |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 3407 | * |
| 3408 | * @see MotionEvent#AXIS_PRESSURE |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 3409 | */ |
| 3410 | public float pressure; |
| 3411 | |
| 3412 | /** |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 3413 | * A normalized value that describes the approximate size of the pointer touch area |
| 3414 | * in relation to the maximum detectable size of the device. |
| 3415 | * It represents some approximation of the area of the screen being |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 3416 | * pressed; the actual value in pixels corresponding to the |
| 3417 | * touch is normalized with the device specific range of values |
| 3418 | * and scaled to a value between 0 and 1. The value of size can be used to |
| 3419 | * determine fat touch events. |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 3420 | * |
| 3421 | * @see MotionEvent#AXIS_SIZE |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 3422 | */ |
| 3423 | public float size; |
| 3424 | |
| 3425 | /** |
| 3426 | * The length of the major axis of an ellipse that describes the touch area at |
| 3427 | * the point of contact. |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 3428 | * If the device is a touch screen, the length is reported in pixels, otherwise it is |
| 3429 | * reported in device-specific units. |
| 3430 | * |
| 3431 | * @see MotionEvent#AXIS_TOUCH_MAJOR |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 3432 | */ |
| 3433 | public float touchMajor; |
| 3434 | |
| 3435 | /** |
| 3436 | * The length of the minor axis of an ellipse that describes the touch area at |
| 3437 | * the point of contact. |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 3438 | * If the device is a touch screen, the length is reported in pixels, otherwise it is |
| 3439 | * reported in device-specific units. |
| 3440 | * |
| 3441 | * @see MotionEvent#AXIS_TOUCH_MINOR |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 3442 | */ |
| 3443 | public float touchMinor; |
| 3444 | |
| 3445 | /** |
| 3446 | * The length of the major axis of an ellipse that describes the size of |
| 3447 | * the approaching tool. |
| 3448 | * The tool area represents the estimated size of the finger or pen that is |
| 3449 | * 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] | 3450 | * If the device is a touch screen, the length is reported in pixels, otherwise it is |
| 3451 | * reported in device-specific units. |
| 3452 | * |
| 3453 | * @see MotionEvent#AXIS_TOOL_MAJOR |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 3454 | */ |
| 3455 | public float toolMajor; |
| 3456 | |
| 3457 | /** |
| 3458 | * The length of the minor axis of an ellipse that describes the size of |
| 3459 | * the approaching tool. |
| 3460 | * The tool area represents the estimated size of the finger or pen that is |
| 3461 | * 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] | 3462 | * If the device is a touch screen, the length is reported in pixels, otherwise it is |
| 3463 | * reported in device-specific units. |
| 3464 | * |
| 3465 | * @see MotionEvent#AXIS_TOOL_MINOR |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 3466 | */ |
| 3467 | public float toolMinor; |
| 3468 | |
| 3469 | /** |
| 3470 | * 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] | 3471 | * 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] | 3472 | * upwards, is perfectly circular or is of unknown orientation. A positive angle |
| 3473 | * indicates that the major axis of contact is oriented to the right. A negative angle |
| 3474 | * indicates that the major axis of contact is oriented to the left. |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 3475 | * 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] | 3476 | * (finger pointing fully right). |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 3477 | * |
| 3478 | * @see MotionEvent#AXIS_ORIENTATION |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 3479 | */ |
| 3480 | public float orientation; |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 3481 | |
| 3482 | /** |
| 3483 | * Clears the contents of this object. |
| 3484 | * Resets all axes to zero. |
| 3485 | */ |
| 3486 | public void clear() { |
| 3487 | mPackedAxisBits = 0; |
| 3488 | |
| 3489 | x = 0; |
| 3490 | y = 0; |
| 3491 | pressure = 0; |
| 3492 | size = 0; |
| 3493 | touchMajor = 0; |
| 3494 | touchMinor = 0; |
| 3495 | toolMajor = 0; |
| 3496 | toolMinor = 0; |
| 3497 | orientation = 0; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 3498 | } |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 3499 | |
| 3500 | /** |
| 3501 | * Copies the contents of another pointer coords object. |
| 3502 | * |
| 3503 | * @param other The pointer coords object to copy. |
| 3504 | */ |
| 3505 | public void copyFrom(PointerCoords other) { |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 3506 | final long bits = other.mPackedAxisBits; |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 3507 | mPackedAxisBits = bits; |
| 3508 | if (bits != 0) { |
| 3509 | final float[] otherValues = other.mPackedAxisValues; |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 3510 | final int count = Long.bitCount(bits); |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 3511 | float[] values = mPackedAxisValues; |
| 3512 | if (values == null || count > values.length) { |
| 3513 | values = new float[otherValues.length]; |
| 3514 | mPackedAxisValues = values; |
| 3515 | } |
| 3516 | System.arraycopy(otherValues, 0, values, 0, count); |
| 3517 | } |
| 3518 | |
| 3519 | x = other.x; |
| 3520 | y = other.y; |
| 3521 | pressure = other.pressure; |
| 3522 | size = other.size; |
| 3523 | touchMajor = other.touchMajor; |
| 3524 | touchMinor = other.touchMinor; |
| 3525 | toolMajor = other.toolMajor; |
| 3526 | toolMinor = other.toolMinor; |
| 3527 | orientation = other.orientation; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 3528 | } |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 3529 | |
| 3530 | /** |
| 3531 | * Gets the value associated with the specified axis. |
| 3532 | * |
| 3533 | * @param axis The axis identifier for the axis value to retrieve. |
| 3534 | * @return The value associated with the axis, or 0 if none. |
| 3535 | * |
| 3536 | * @see MotionEvent#AXIS_X |
| 3537 | * @see MotionEvent#AXIS_Y |
| 3538 | */ |
| 3539 | public float getAxisValue(int axis) { |
| 3540 | switch (axis) { |
| 3541 | case AXIS_X: |
| 3542 | return x; |
| 3543 | case AXIS_Y: |
| 3544 | return y; |
| 3545 | case AXIS_PRESSURE: |
| 3546 | return pressure; |
| 3547 | case AXIS_SIZE: |
| 3548 | return size; |
| 3549 | case AXIS_TOUCH_MAJOR: |
| 3550 | return touchMajor; |
| 3551 | case AXIS_TOUCH_MINOR: |
| 3552 | return touchMinor; |
| 3553 | case AXIS_TOOL_MAJOR: |
| 3554 | return toolMajor; |
| 3555 | case AXIS_TOOL_MINOR: |
| 3556 | return toolMinor; |
| 3557 | case AXIS_ORIENTATION: |
| 3558 | return orientation; |
| 3559 | default: { |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 3560 | if (axis < 0 || axis > 63) { |
| 3561 | throw new IllegalArgumentException("Axis out of range."); |
| 3562 | } |
| 3563 | final long bits = mPackedAxisBits; |
Michael Wright | 9adca06 | 2014-03-19 11:51:26 -0700 | [diff] [blame] | 3564 | final long axisBit = 0x8000000000000000L >>> axis; |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 3565 | if ((bits & axisBit) == 0) { |
| 3566 | return 0; |
| 3567 | } |
Michael Wright | 9adca06 | 2014-03-19 11:51:26 -0700 | [diff] [blame] | 3568 | final int index = Long.bitCount(bits & ~(0xFFFFFFFFFFFFFFFFL >>> axis)); |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 3569 | return mPackedAxisValues[index]; |
| 3570 | } |
| 3571 | } |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 3572 | } |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 3573 | |
| 3574 | /** |
| 3575 | * Sets the value associated with the specified axis. |
| 3576 | * |
| 3577 | * @param axis The axis identifier for the axis value to assign. |
| 3578 | * @param value The value to set. |
| 3579 | * |
| 3580 | * @see MotionEvent#AXIS_X |
| 3581 | * @see MotionEvent#AXIS_Y |
| 3582 | */ |
| 3583 | public void setAxisValue(int axis, float value) { |
| 3584 | switch (axis) { |
| 3585 | case AXIS_X: |
| 3586 | x = value; |
| 3587 | break; |
| 3588 | case AXIS_Y: |
| 3589 | y = value; |
| 3590 | break; |
| 3591 | case AXIS_PRESSURE: |
| 3592 | pressure = value; |
| 3593 | break; |
| 3594 | case AXIS_SIZE: |
| 3595 | size = value; |
| 3596 | break; |
| 3597 | case AXIS_TOUCH_MAJOR: |
| 3598 | touchMajor = value; |
| 3599 | break; |
| 3600 | case AXIS_TOUCH_MINOR: |
| 3601 | touchMinor = value; |
| 3602 | break; |
| 3603 | case AXIS_TOOL_MAJOR: |
| 3604 | toolMajor = value; |
| 3605 | break; |
| 3606 | case AXIS_TOOL_MINOR: |
| 3607 | toolMinor = value; |
| 3608 | break; |
| 3609 | case AXIS_ORIENTATION: |
| 3610 | orientation = value; |
| 3611 | break; |
| 3612 | default: { |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 3613 | if (axis < 0 || axis > 63) { |
| 3614 | throw new IllegalArgumentException("Axis out of range."); |
| 3615 | } |
| 3616 | final long bits = mPackedAxisBits; |
Michael Wright | 9adca06 | 2014-03-19 11:51:26 -0700 | [diff] [blame] | 3617 | final long axisBit = 0x8000000000000000L >>> axis; |
| 3618 | final int index = Long.bitCount(bits & ~(0xFFFFFFFFFFFFFFFFL >>> axis)); |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 3619 | float[] values = mPackedAxisValues; |
| 3620 | if ((bits & axisBit) == 0) { |
| 3621 | if (values == null) { |
| 3622 | values = new float[INITIAL_PACKED_AXIS_VALUES]; |
| 3623 | mPackedAxisValues = values; |
| 3624 | } else { |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 3625 | final int count = Long.bitCount(bits); |
Jeff Brown | 91c69ab | 2011-02-14 17:03:18 -0800 | [diff] [blame] | 3626 | if (count < values.length) { |
| 3627 | if (index != count) { |
| 3628 | System.arraycopy(values, index, values, index + 1, |
| 3629 | count - index); |
| 3630 | } |
| 3631 | } else { |
| 3632 | float[] newValues = new float[count * 2]; |
| 3633 | System.arraycopy(values, 0, newValues, 0, index); |
| 3634 | System.arraycopy(values, index, newValues, index + 1, |
| 3635 | count - index); |
| 3636 | values = newValues; |
| 3637 | mPackedAxisValues = values; |
| 3638 | } |
| 3639 | } |
| 3640 | mPackedAxisBits = bits | axisBit; |
| 3641 | } |
| 3642 | values[index] = value; |
| 3643 | } |
| 3644 | } |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 3645 | } |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 3646 | } |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 3647 | |
| 3648 | /** |
| 3649 | * Transfer object for pointer properties. |
| 3650 | * |
| 3651 | * Objects of this type can be used to specify the pointer id and tool type |
| 3652 | * when creating new {@link MotionEvent} objects and to query pointer properties in bulk. |
| 3653 | */ |
| 3654 | public static final class PointerProperties { |
| 3655 | /** |
| 3656 | * Creates a pointer properties object with an invalid pointer id. |
| 3657 | */ |
| 3658 | public PointerProperties() { |
| 3659 | clear(); |
| 3660 | } |
| 3661 | |
| 3662 | /** |
| 3663 | * Creates a pointer properties object as a copy of the contents of |
| 3664 | * another pointer properties object. |
| 3665 | * @param other |
| 3666 | */ |
| 3667 | public PointerProperties(PointerProperties other) { |
| 3668 | copyFrom(other); |
| 3669 | } |
| 3670 | |
| 3671 | /** @hide */ |
| 3672 | public static PointerProperties[] createArray(int size) { |
| 3673 | PointerProperties[] array = new PointerProperties[size]; |
| 3674 | for (int i = 0; i < size; i++) { |
| 3675 | array[i] = new PointerProperties(); |
| 3676 | } |
| 3677 | return array; |
| 3678 | } |
| 3679 | |
| 3680 | /** |
| 3681 | * The pointer id. |
| 3682 | * Initially set to {@link #INVALID_POINTER_ID} (-1). |
| 3683 | * |
| 3684 | * @see MotionEvent#getPointerId(int) |
| 3685 | */ |
| 3686 | public int id; |
| 3687 | |
| 3688 | /** |
| 3689 | * The pointer tool type. |
| 3690 | * Initially set to 0. |
| 3691 | * |
| 3692 | * @see MotionEvent#getToolType(int) |
| 3693 | */ |
| 3694 | public int toolType; |
| 3695 | |
| 3696 | /** |
| 3697 | * Resets the pointer properties to their initial values. |
| 3698 | */ |
| 3699 | public void clear() { |
| 3700 | id = INVALID_POINTER_ID; |
| 3701 | toolType = TOOL_TYPE_UNKNOWN; |
| 3702 | } |
| 3703 | |
| 3704 | /** |
| 3705 | * Copies the contents of another pointer properties object. |
| 3706 | * |
| 3707 | * @param other The pointer properties object to copy. |
| 3708 | */ |
| 3709 | public void copyFrom(PointerProperties other) { |
| 3710 | id = other.id; |
| 3711 | toolType = other.toolType; |
| 3712 | } |
Jeff Brown | 9d3bdbd | 2012-03-21 11:50:06 -0700 | [diff] [blame] | 3713 | |
| 3714 | @Override |
| 3715 | public boolean equals(Object other) { |
| 3716 | if (other instanceof PointerProperties) { |
| 3717 | return equals((PointerProperties)other); |
| 3718 | } |
| 3719 | return false; |
| 3720 | } |
| 3721 | |
| 3722 | private boolean equals(PointerProperties other) { |
| 3723 | return other != null && id == other.id && toolType == other.toolType; |
| 3724 | } |
| 3725 | |
| 3726 | @Override |
| 3727 | public int hashCode() { |
| 3728 | return id | (toolType << 8); |
| 3729 | } |
Jeff Brown | fe9f8ab | 2011-05-06 18:20:01 -0700 | [diff] [blame] | 3730 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3731 | } |