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