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