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