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 | |
| 19 | import android.os.Parcel; |
| 20 | import android.os.Parcelable; |
| 21 | import android.os.SystemClock; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 22 | |
| 23 | /** |
| 24 | * Object used to report movement (mouse, pen, finger, trackball) events. This |
| 25 | * class may hold either absolute or relative movements, depending on what |
| 26 | * it is being used for. |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 27 | * |
| 28 | * Refer to {@link InputDevice} for information about how different kinds of |
| 29 | * input devices and sources represent pointer coordinates. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | */ |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 31 | public final class MotionEvent extends InputEvent implements Parcelable { |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 32 | private static final long MS_PER_NS = 1000000; |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 33 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | /** |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 35 | * Bit mask of the parts of the action code that are the action itself. |
| 36 | */ |
| 37 | public static final int ACTION_MASK = 0xff; |
| 38 | |
| 39 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | * Constant for {@link #getAction}: A pressed gesture has started, the |
| 41 | * motion contains the initial starting location. |
| 42 | */ |
| 43 | public static final int ACTION_DOWN = 0; |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 44 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 45 | /** |
| 46 | * Constant for {@link #getAction}: A pressed gesture has finished, the |
| 47 | * motion contains the final release location as well as any intermediate |
| 48 | * points since the last down or move event. |
| 49 | */ |
| 50 | public static final int ACTION_UP = 1; |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 51 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | /** |
| 53 | * Constant for {@link #getAction}: A change has happened during a |
| 54 | * press gesture (between {@link #ACTION_DOWN} and {@link #ACTION_UP}). |
| 55 | * The motion contains the most recent point, as well as any intermediate |
| 56 | * points since the last down or move event. |
| 57 | */ |
| 58 | public static final int ACTION_MOVE = 2; |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 59 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 60 | /** |
| 61 | * Constant for {@link #getAction}: The current gesture has been aborted. |
| 62 | * You will not receive any more points in it. You should treat this as |
| 63 | * an up event, but not perform any action that you normally would. |
| 64 | */ |
| 65 | public static final int ACTION_CANCEL = 3; |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 66 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | /** |
| 68 | * Constant for {@link #getAction}: A movement has happened outside of the |
| 69 | * normal bounds of the UI element. This does not provide a full gesture, |
| 70 | * but only the initial location of the movement/touch. |
| 71 | */ |
| 72 | public static final int ACTION_OUTSIDE = 4; |
| 73 | |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 74 | /** |
| 75 | * A non-primary pointer has gone down. The bits in |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 76 | * {@link #ACTION_POINTER_ID_MASK} indicate which pointer changed. |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 77 | */ |
| 78 | public static final int ACTION_POINTER_DOWN = 5; |
| 79 | |
| 80 | /** |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 81 | * A non-primary pointer has gone up. The bits in |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 82 | * {@link #ACTION_POINTER_ID_MASK} indicate which pointer changed. |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 83 | */ |
| 84 | public static final int ACTION_POINTER_UP = 6; |
| 85 | |
| 86 | /** |
Dianne Hackborn | b125dc5 | 2010-02-12 15:52:09 -0800 | [diff] [blame] | 87 | * Bits in the action code that represent a pointer index, used with |
| 88 | * {@link #ACTION_POINTER_DOWN} and {@link #ACTION_POINTER_UP}. Shifting |
| 89 | * down by {@link #ACTION_POINTER_INDEX_SHIFT} provides the actual pointer |
| 90 | * index where the data for the pointer going up or down can be found; you can |
| 91 | * get its identifier with {@link #getPointerId(int)} and the actual |
| 92 | * data with {@link #getX(int)} etc. |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 93 | */ |
Dianne Hackborn | b125dc5 | 2010-02-12 15:52:09 -0800 | [diff] [blame] | 94 | public static final int ACTION_POINTER_INDEX_MASK = 0xff00; |
| 95 | |
| 96 | /** |
| 97 | * Bit shift for the action bits holding the pointer index as |
| 98 | * defined by {@link #ACTION_POINTER_INDEX_MASK}. |
| 99 | */ |
| 100 | public static final int ACTION_POINTER_INDEX_SHIFT = 8; |
| 101 | |
| 102 | /** |
| 103 | * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the |
| 104 | * data index associated with {@link #ACTION_POINTER_DOWN}. |
| 105 | */ |
| 106 | @Deprecated |
| 107 | public static final int ACTION_POINTER_1_DOWN = ACTION_POINTER_DOWN | 0x0000; |
| 108 | |
| 109 | /** |
| 110 | * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the |
| 111 | * data index associated with {@link #ACTION_POINTER_DOWN}. |
| 112 | */ |
| 113 | @Deprecated |
| 114 | public static final int ACTION_POINTER_2_DOWN = ACTION_POINTER_DOWN | 0x0100; |
| 115 | |
| 116 | /** |
| 117 | * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the |
| 118 | * data index associated with {@link #ACTION_POINTER_DOWN}. |
| 119 | */ |
| 120 | @Deprecated |
| 121 | public static final int ACTION_POINTER_3_DOWN = ACTION_POINTER_DOWN | 0x0200; |
| 122 | |
| 123 | /** |
| 124 | * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the |
| 125 | * data index associated with {@link #ACTION_POINTER_UP}. |
| 126 | */ |
| 127 | @Deprecated |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 128 | public static final int ACTION_POINTER_1_UP = ACTION_POINTER_UP | 0x0000; |
| 129 | |
| 130 | /** |
Dianne Hackborn | b125dc5 | 2010-02-12 15:52:09 -0800 | [diff] [blame] | 131 | * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the |
| 132 | * data index associated with {@link #ACTION_POINTER_UP}. |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 133 | */ |
Dianne Hackborn | b125dc5 | 2010-02-12 15:52:09 -0800 | [diff] [blame] | 134 | @Deprecated |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 135 | public static final int ACTION_POINTER_2_UP = ACTION_POINTER_UP | 0x0100; |
| 136 | |
| 137 | /** |
Dianne Hackborn | b125dc5 | 2010-02-12 15:52:09 -0800 | [diff] [blame] | 138 | * @deprecated Use {@link #ACTION_POINTER_INDEX_MASK} to retrieve the |
| 139 | * data index associated with {@link #ACTION_POINTER_UP}. |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 140 | */ |
Dianne Hackborn | b125dc5 | 2010-02-12 15:52:09 -0800 | [diff] [blame] | 141 | @Deprecated |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 142 | public static final int ACTION_POINTER_3_UP = ACTION_POINTER_UP | 0x0200; |
| 143 | |
| 144 | /** |
Dianne Hackborn | b125dc5 | 2010-02-12 15:52:09 -0800 | [diff] [blame] | 145 | * @deprecated Renamed to {@link #ACTION_POINTER_INDEX_MASK} to match |
| 146 | * the actual data contained in these bits. |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 147 | */ |
Dianne Hackborn | b125dc5 | 2010-02-12 15:52:09 -0800 | [diff] [blame] | 148 | @Deprecated |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 149 | public static final int ACTION_POINTER_ID_MASK = 0xff00; |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 150 | |
| 151 | /** |
Dianne Hackborn | b125dc5 | 2010-02-12 15:52:09 -0800 | [diff] [blame] | 152 | * @deprecated Renamed to {@link #ACTION_POINTER_INDEX_SHIFT} to match |
| 153 | * the actual data contained in these bits. |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 154 | */ |
Dianne Hackborn | b125dc5 | 2010-02-12 15:52:09 -0800 | [diff] [blame] | 155 | @Deprecated |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 156 | public static final int ACTION_POINTER_ID_SHIFT = 8; |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 157 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 158 | private static final boolean TRACK_RECYCLED_LOCATION = false; |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 159 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 160 | /** |
| 161 | * Flag indicating the motion event intersected the top edge of the screen. |
| 162 | */ |
| 163 | public static final int EDGE_TOP = 0x00000001; |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 164 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 165 | /** |
| 166 | * Flag indicating the motion event intersected the bottom edge of the screen. |
| 167 | */ |
| 168 | public static final int EDGE_BOTTOM = 0x00000002; |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 169 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 170 | /** |
| 171 | * Flag indicating the motion event intersected the left edge of the screen. |
| 172 | */ |
| 173 | public static final int EDGE_LEFT = 0x00000004; |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 174 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 175 | /** |
| 176 | * Flag indicating the motion event intersected the right edge of the screen. |
| 177 | */ |
| 178 | public static final int EDGE_RIGHT = 0x00000008; |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 179 | |
Jeff Brown | 9e2ad36 | 2010-07-30 19:20:11 -0700 | [diff] [blame^] | 180 | /* |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 181 | * Offset for the sample's X coordinate. |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 182 | */ |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 183 | static private final int SAMPLE_X = 0; |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 184 | |
Jeff Brown | 9e2ad36 | 2010-07-30 19:20:11 -0700 | [diff] [blame^] | 185 | /* |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 186 | * Offset for the sample's Y coordinate. |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 187 | */ |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 188 | static private final int SAMPLE_Y = 1; |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 189 | |
Jeff Brown | 9e2ad36 | 2010-07-30 19:20:11 -0700 | [diff] [blame^] | 190 | /* |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 191 | * Offset for the sample's pressure. |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 192 | */ |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 193 | static private final int SAMPLE_PRESSURE = 2; |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 194 | |
Jeff Brown | 9e2ad36 | 2010-07-30 19:20:11 -0700 | [diff] [blame^] | 195 | /* |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 196 | * Offset for the sample's size |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 197 | */ |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 198 | static private final int SAMPLE_SIZE = 3; |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 199 | |
Jeff Brown | 9e2ad36 | 2010-07-30 19:20:11 -0700 | [diff] [blame^] | 200 | /* |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 201 | * Offset for the sample's touch major axis length. |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 202 | */ |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 203 | static private final int SAMPLE_TOUCH_MAJOR = 4; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 204 | |
Jeff Brown | 9e2ad36 | 2010-07-30 19:20:11 -0700 | [diff] [blame^] | 205 | /* |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 206 | * Offset for the sample's touch minor axis length. |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 207 | */ |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 208 | static private final int SAMPLE_TOUCH_MINOR = 5; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 209 | |
Jeff Brown | 9e2ad36 | 2010-07-30 19:20:11 -0700 | [diff] [blame^] | 210 | /* |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 211 | * Offset for the sample's tool major axis length. |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 212 | */ |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 213 | static private final int SAMPLE_TOOL_MAJOR = 6; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 214 | |
Jeff Brown | 9e2ad36 | 2010-07-30 19:20:11 -0700 | [diff] [blame^] | 215 | /* |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 216 | * Offset for the sample's tool minor axis length. |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 217 | */ |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 218 | static private final int SAMPLE_TOOL_MINOR = 7; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 219 | |
Jeff Brown | 9e2ad36 | 2010-07-30 19:20:11 -0700 | [diff] [blame^] | 220 | /* |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 221 | * Offset for the sample's orientation. |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 222 | */ |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 223 | static private final int SAMPLE_ORIENTATION = 8; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 224 | |
Jeff Brown | 9e2ad36 | 2010-07-30 19:20:11 -0700 | [diff] [blame^] | 225 | /* |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 226 | * Number of data items for each sample. |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 227 | */ |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 228 | static private final int NUM_SAMPLE_DATA = 9; |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 229 | |
Jeff Brown | 9e2ad36 | 2010-07-30 19:20:11 -0700 | [diff] [blame^] | 230 | /* |
| 231 | * Minimum number of pointers for which to reserve space when allocating new |
| 232 | * motion events. This is explicitly not a bound on the maximum number of pointers. |
Dianne Hackborn | 1e8dfc7 | 2009-08-06 12:43:01 -0700 | [diff] [blame] | 233 | */ |
Jeff Brown | 9e2ad36 | 2010-07-30 19:20:11 -0700 | [diff] [blame^] | 234 | static private final int BASE_AVAIL_POINTERS = 5; |
Dianne Hackborn | 1e8dfc7 | 2009-08-06 12:43:01 -0700 | [diff] [blame] | 235 | |
Jeff Brown | 9e2ad36 | 2010-07-30 19:20:11 -0700 | [diff] [blame^] | 236 | /* |
| 237 | * Minimum number of samples for which to reserve space when allocating new motion events. |
| 238 | */ |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 239 | static private final int BASE_AVAIL_SAMPLES = 8; |
| 240 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 241 | static private final int MAX_RECYCLED = 10; |
| 242 | static private Object gRecyclerLock = new Object(); |
| 243 | static private int gRecyclerUsed = 0; |
| 244 | static private MotionEvent gRecyclerTop = null; |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 245 | |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 246 | private long mDownTimeNano; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 247 | private int mAction; |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 248 | private float mXOffset; |
| 249 | private float mYOffset; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 250 | private float mXPrecision; |
| 251 | private float mYPrecision; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 252 | private int mEdgeFlags; |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 253 | private int mMetaState; |
| 254 | |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 255 | private int mNumPointers; |
| 256 | private int mNumSamples; |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 257 | |
| 258 | private int mLastDataSampleIndex; |
| 259 | private int mLastEventTimeNanoSampleIndex; |
| 260 | |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 261 | // Array of mNumPointers size of identifiers for each pointer of data. |
| 262 | private int[] mPointerIdentifiers; |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 263 | |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 264 | // Array of (mNumSamples * mNumPointers * NUM_SAMPLE_DATA) size of event data. |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 265 | // Samples are ordered from oldest to newest. |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 266 | private float[] mDataSamples; |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 267 | |
| 268 | // Array of mNumSamples size of event time stamps in nanoseconds. |
| 269 | // Samples are ordered from oldest to newest. |
| 270 | private long[] mEventTimeNanoSamples; |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 271 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 272 | private MotionEvent mNext; |
| 273 | private RuntimeException mRecycledLocation; |
| 274 | private boolean mRecycled; |
| 275 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 276 | private MotionEvent(int pointerCount, int sampleCount) { |
| 277 | mPointerIdentifiers = new int[pointerCount]; |
| 278 | mDataSamples = new float[pointerCount * sampleCount * NUM_SAMPLE_DATA]; |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 279 | mEventTimeNanoSamples = new long[sampleCount]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 280 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 281 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 282 | static private MotionEvent obtain(int pointerCount, int sampleCount) { |
| 283 | final MotionEvent ev; |
| 284 | synchronized (gRecyclerLock) { |
| 285 | if (gRecyclerTop == null) { |
| 286 | if (pointerCount < BASE_AVAIL_POINTERS) { |
| 287 | pointerCount = BASE_AVAIL_POINTERS; |
| 288 | } |
| 289 | if (sampleCount < BASE_AVAIL_SAMPLES) { |
| 290 | sampleCount = BASE_AVAIL_SAMPLES; |
| 291 | } |
| 292 | return new MotionEvent(pointerCount, sampleCount); |
| 293 | } |
| 294 | ev = gRecyclerTop; |
| 295 | gRecyclerTop = ev.mNext; |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 296 | gRecyclerUsed -= 1; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 297 | } |
| 298 | ev.mRecycledLocation = null; |
| 299 | ev.mRecycled = false; |
| 300 | ev.mNext = null; |
| 301 | |
| 302 | if (ev.mPointerIdentifiers.length < pointerCount) { |
| 303 | ev.mPointerIdentifiers = new int[pointerCount]; |
| 304 | } |
| 305 | |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 306 | if (ev.mEventTimeNanoSamples.length < sampleCount) { |
| 307 | ev.mEventTimeNanoSamples = new long[sampleCount]; |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 308 | } |
| 309 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 310 | final int neededDataSamplesLength = pointerCount * sampleCount * NUM_SAMPLE_DATA; |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 311 | if (ev.mDataSamples.length < neededDataSamplesLength) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 312 | ev.mDataSamples = new float[neededDataSamplesLength]; |
| 313 | } |
| 314 | |
| 315 | return ev; |
| 316 | } |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 317 | |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 318 | /** |
| 319 | * Create a new MotionEvent, filling in all of the basic values that |
| 320 | * define the motion. |
| 321 | * |
| 322 | * @param downTime The time (in ms) when the user originally pressed down to start |
| 323 | * a stream of position events. This must be obtained from {@link SystemClock#uptimeMillis()}. |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 324 | * @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] | 325 | * must be obtained from {@link SystemClock#uptimeMillis()}. |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 326 | * @param action The kind of action being performed -- one of either |
| 327 | * {@link #ACTION_DOWN}, {@link #ACTION_MOVE}, {@link #ACTION_UP}, or |
| 328 | * {@link #ACTION_CANCEL}. |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 329 | * @param pointers The number of points that will be in this event. |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 330 | * @param pointerIds An array of <em>pointers</em> values providing |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 331 | * an identifier for each pointer. |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 332 | * @param pointerCoords An array of <em>pointers</em> values providing |
| 333 | * a {@link PointerCoords} coordinate object for each pointer. |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 334 | * @param metaState The state of any meta / modifier keys that were in effect when |
| 335 | * the event was generated. |
| 336 | * @param xPrecision The precision of the X coordinate being reported. |
| 337 | * @param yPrecision The precision of the Y coordinate being reported. |
| 338 | * @param deviceId The id for the device that this event came from. An id of |
| 339 | * zero indicates that the event didn't come from a physical device; other |
| 340 | * numbers are arbitrary and you shouldn't depend on the values. |
| 341 | * @param edgeFlags A bitfield indicating which edges, if any, where touched by this |
| 342 | * MotionEvent. |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 343 | * @param source The source of this event. |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 344 | */ |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 345 | static public MotionEvent obtain(long downTime, long eventTime, |
| 346 | int action, int pointers, int[] pointerIds, PointerCoords[] pointerCoords, |
| 347 | int metaState, float xPrecision, float yPrecision, int deviceId, |
| 348 | int edgeFlags, int source) { |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 349 | MotionEvent ev = obtain(pointers, 1); |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 350 | ev.mDeviceId = deviceId; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 351 | ev.mSource = source; |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 352 | ev.mEdgeFlags = edgeFlags; |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 353 | ev.mDownTimeNano = downTime * MS_PER_NS; |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 354 | ev.mAction = action; |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 355 | ev.mMetaState = metaState; |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 356 | ev.mXOffset = 0; |
| 357 | ev.mYOffset = 0; |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 358 | ev.mXPrecision = xPrecision; |
| 359 | ev.mYPrecision = yPrecision; |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 360 | |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 361 | ev.mNumPointers = pointers; |
| 362 | ev.mNumSamples = 1; |
| 363 | |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 364 | ev.mLastDataSampleIndex = 0; |
| 365 | ev.mLastEventTimeNanoSampleIndex = 0; |
Dianne Hackborn | 1e8dfc7 | 2009-08-06 12:43:01 -0700 | [diff] [blame] | 366 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 367 | System.arraycopy(pointerIds, 0, ev.mPointerIdentifiers, 0, pointers); |
Dianne Hackborn | 1e8dfc7 | 2009-08-06 12:43:01 -0700 | [diff] [blame] | 368 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 369 | ev.mEventTimeNanoSamples[0] = eventTime * MS_PER_NS; |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 370 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 371 | ev.setPointerCoordsAtSampleIndex(0, pointerCoords); |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 372 | |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 373 | return ev; |
| 374 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 375 | |
| 376 | /** |
| 377 | * Create a new MotionEvent, filling in all of the basic values that |
| 378 | * define the motion. |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 379 | * |
| 380 | * @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] | 381 | * 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] | 382 | * @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] | 383 | * must be obtained from {@link SystemClock#uptimeMillis()}. |
| 384 | * @param action The kind of action being performed -- one of either |
| 385 | * {@link #ACTION_DOWN}, {@link #ACTION_MOVE}, {@link #ACTION_UP}, or |
| 386 | * {@link #ACTION_CANCEL}. |
| 387 | * @param x The X coordinate of this event. |
| 388 | * @param y The Y coordinate of this event. |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 389 | * @param pressure The current pressure of this event. The pressure generally |
| 390 | * ranges from 0 (no pressure at all) to 1 (normal pressure), however |
| 391 | * 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] | 392 | * the input device. |
| 393 | * @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] | 394 | * 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] | 395 | * touch is normalized with a device specific range of values |
| 396 | * and scaled to a value between 0 and 1. |
| 397 | * @param metaState The state of any meta / modifier keys that were in effect when |
| 398 | * the event was generated. |
| 399 | * @param xPrecision The precision of the X coordinate being reported. |
| 400 | * @param yPrecision The precision of the Y coordinate being reported. |
| 401 | * @param deviceId The id for the device that this event came from. An id of |
| 402 | * zero indicates that the event didn't come from a physical device; other |
| 403 | * numbers are arbitrary and you shouldn't depend on the values. |
| 404 | * @param edgeFlags A bitfield indicating which edges, if any, where touched by this |
| 405 | * MotionEvent. |
| 406 | */ |
| 407 | static public MotionEvent obtain(long downTime, long eventTime, int action, |
| 408 | float x, float y, float pressure, float size, int metaState, |
| 409 | float xPrecision, float yPrecision, int deviceId, int edgeFlags) { |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 410 | MotionEvent ev = obtain(1, 1); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 411 | ev.mDeviceId = deviceId; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 412 | ev.mSource = InputDevice.SOURCE_UNKNOWN; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 413 | ev.mEdgeFlags = edgeFlags; |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 414 | ev.mDownTimeNano = downTime * MS_PER_NS; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 415 | ev.mAction = action; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 416 | ev.mMetaState = metaState; |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 417 | ev.mXOffset = 0; |
| 418 | ev.mYOffset = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 419 | ev.mXPrecision = xPrecision; |
| 420 | ev.mYPrecision = yPrecision; |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 421 | |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 422 | ev.mNumPointers = 1; |
| 423 | ev.mNumSamples = 1; |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 424 | |
| 425 | ev.mLastDataSampleIndex = 0; |
| 426 | ev.mLastEventTimeNanoSampleIndex = 0; |
| 427 | |
| 428 | ev.mPointerIdentifiers[0] = 0; |
| 429 | |
| 430 | ev.mEventTimeNanoSamples[0] = eventTime * MS_PER_NS; |
| 431 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 432 | ev.setPointerCoordsAtSampleIndex(0, x, y, pressure, size); |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 433 | return ev; |
| 434 | } |
| 435 | |
| 436 | /** |
| 437 | * Create a new MotionEvent, filling in all of the basic values that |
| 438 | * define the motion. |
| 439 | * |
| 440 | * @param downTime The time (in ms) when the user originally pressed down to start |
| 441 | * a stream of position events. This must be obtained from {@link SystemClock#uptimeMillis()}. |
| 442 | * @param eventTime The the time (in ms) when this specific event was generated. This |
| 443 | * must be obtained from {@link SystemClock#uptimeMillis()}. |
| 444 | * @param action The kind of action being performed -- one of either |
| 445 | * {@link #ACTION_DOWN}, {@link #ACTION_MOVE}, {@link #ACTION_UP}, or |
| 446 | * {@link #ACTION_CANCEL}. |
| 447 | * @param pointers The number of pointers that are active in this event. |
| 448 | * @param x The X coordinate of this event. |
| 449 | * @param y The Y coordinate of this event. |
| 450 | * @param pressure The current pressure of this event. The pressure generally |
| 451 | * ranges from 0 (no pressure at all) to 1 (normal pressure), however |
| 452 | * values higher than 1 may be generated depending on the calibration of |
| 453 | * the input device. |
| 454 | * @param size A scaled value of the approximate size of the area being pressed when |
| 455 | * touched with the finger. The actual value in pixels corresponding to the finger |
| 456 | * touch is normalized with a device specific range of values |
| 457 | * and scaled to a value between 0 and 1. |
| 458 | * @param metaState The state of any meta / modifier keys that were in effect when |
| 459 | * the event was generated. |
| 460 | * @param xPrecision The precision of the X coordinate being reported. |
| 461 | * @param yPrecision The precision of the Y coordinate being reported. |
| 462 | * @param deviceId The id for the device that this event came from. An id of |
| 463 | * zero indicates that the event didn't come from a physical device; other |
| 464 | * numbers are arbitrary and you shouldn't depend on the values. |
| 465 | * @param edgeFlags A bitfield indicating which edges, if any, where touched by this |
| 466 | * MotionEvent. |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 467 | * |
| 468 | * @deprecated Use {@link #obtain(long, long, int, float, float, float, float, int, float, float, int, int)} |
| 469 | * instead. |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 470 | */ |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 471 | @Deprecated |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 472 | static public MotionEvent obtain(long downTime, long eventTime, int action, |
| 473 | int pointers, float x, float y, float pressure, float size, int metaState, |
| 474 | float xPrecision, float yPrecision, int deviceId, int edgeFlags) { |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 475 | return obtain(downTime, eventTime, action, x, y, pressure, size, |
| 476 | metaState, xPrecision, yPrecision, deviceId, edgeFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 477 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 478 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 479 | /** |
| 480 | * Create a new MotionEvent, filling in a subset of the basic motion |
| 481 | * values. Those not specified here are: device id (always 0), pressure |
| 482 | * 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] | 483 | * |
| 484 | * @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] | 485 | * 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] | 486 | * @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] | 487 | * must be obtained from {@link SystemClock#uptimeMillis()}. |
| 488 | * @param action The kind of action being performed -- one of either |
| 489 | * {@link #ACTION_DOWN}, {@link #ACTION_MOVE}, {@link #ACTION_UP}, or |
| 490 | * {@link #ACTION_CANCEL}. |
| 491 | * @param x The X coordinate of this event. |
| 492 | * @param y The Y coordinate of this event. |
| 493 | * @param metaState The state of any meta / modifier keys that were in effect when |
| 494 | * the event was generated. |
| 495 | */ |
| 496 | static public MotionEvent obtain(long downTime, long eventTime, int action, |
| 497 | float x, float y, int metaState) { |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 498 | return obtain(downTime, eventTime, action, x, y, 1.0f, 1.0f, |
| 499 | metaState, 1.0f, 1.0f, 0, 0); |
Mitsuru Oshima | 8169dae | 2009-04-28 18:12:09 -0700 | [diff] [blame] | 500 | } |
| 501 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 502 | /** |
| 503 | * Create a new MotionEvent, copying from an existing one. |
| 504 | */ |
| 505 | static public MotionEvent obtain(MotionEvent o) { |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 506 | MotionEvent ev = obtain(o.mNumPointers, o.mNumSamples); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 507 | ev.mDeviceId = o.mDeviceId; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 508 | ev.mSource = o.mSource; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 509 | ev.mEdgeFlags = o.mEdgeFlags; |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 510 | ev.mDownTimeNano = o.mDownTimeNano; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 511 | ev.mAction = o.mAction; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 512 | ev.mMetaState = o.mMetaState; |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 513 | ev.mXOffset = o.mXOffset; |
| 514 | ev.mYOffset = o.mYOffset; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 515 | ev.mXPrecision = o.mXPrecision; |
| 516 | ev.mYPrecision = o.mYPrecision; |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 517 | int numPointers = ev.mNumPointers = o.mNumPointers; |
| 518 | int numSamples = ev.mNumSamples = o.mNumSamples; |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 519 | |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 520 | ev.mLastDataSampleIndex = o.mLastDataSampleIndex; |
| 521 | ev.mLastEventTimeNanoSampleIndex = o.mLastEventTimeNanoSampleIndex; |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 522 | |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 523 | System.arraycopy(o.mPointerIdentifiers, 0, ev.mPointerIdentifiers, 0, numPointers); |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 524 | |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 525 | System.arraycopy(o.mEventTimeNanoSamples, 0, ev.mEventTimeNanoSamples, 0, numSamples); |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 526 | |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 527 | System.arraycopy(o.mDataSamples, 0, ev.mDataSamples, 0, |
| 528 | numPointers * numSamples * NUM_SAMPLE_DATA); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 529 | return ev; |
| 530 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 531 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 532 | /** |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 533 | * Create a new MotionEvent, copying from an existing one, but not including |
| 534 | * any historical point information. |
| 535 | */ |
| 536 | static public MotionEvent obtainNoHistory(MotionEvent o) { |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 537 | MotionEvent ev = obtain(o.mNumPointers, 1); |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 538 | ev.mDeviceId = o.mDeviceId; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 539 | ev.mSource = o.mSource; |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 540 | ev.mEdgeFlags = o.mEdgeFlags; |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 541 | ev.mDownTimeNano = o.mDownTimeNano; |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 542 | ev.mAction = o.mAction; |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 543 | ev.mMetaState = o.mMetaState; |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 544 | ev.mXOffset = o.mXOffset; |
| 545 | ev.mYOffset = o.mYOffset; |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 546 | ev.mXPrecision = o.mXPrecision; |
| 547 | ev.mYPrecision = o.mYPrecision; |
| 548 | |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 549 | int numPointers = ev.mNumPointers = o.mNumPointers; |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 550 | ev.mNumSamples = 1; |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 551 | |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 552 | ev.mLastDataSampleIndex = 0; |
| 553 | ev.mLastEventTimeNanoSampleIndex = 0; |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 554 | |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 555 | System.arraycopy(o.mPointerIdentifiers, 0, ev.mPointerIdentifiers, 0, numPointers); |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 556 | |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 557 | ev.mEventTimeNanoSamples[0] = o.mEventTimeNanoSamples[o.mLastEventTimeNanoSampleIndex]; |
| 558 | |
| 559 | System.arraycopy(o.mDataSamples, o.mLastDataSampleIndex, ev.mDataSamples, 0, |
| 560 | numPointers * NUM_SAMPLE_DATA); |
Dianne Hackborn | 8df8b2b | 2009-08-17 15:15:18 -0700 | [diff] [blame] | 561 | return ev; |
| 562 | } |
| 563 | |
| 564 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 565 | * Recycle the MotionEvent, to be re-used by a later caller. After calling |
| 566 | * this function you must not ever touch the event again. |
| 567 | */ |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 568 | public final void recycle() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 569 | // Ensure recycle is only called once! |
| 570 | if (TRACK_RECYCLED_LOCATION) { |
| 571 | if (mRecycledLocation != null) { |
| 572 | throw new RuntimeException(toString() + " recycled twice!", mRecycledLocation); |
| 573 | } |
| 574 | mRecycledLocation = new RuntimeException("Last recycled here"); |
Jeff Brown | d28f4be | 2010-06-02 15:35:46 -0700 | [diff] [blame] | 575 | //Log.w("MotionEvent", "Recycling event " + this, mRecycledLocation); |
| 576 | } else { |
| 577 | if (mRecycled) { |
| 578 | throw new RuntimeException(toString() + " recycled twice!"); |
| 579 | } |
| 580 | mRecycled = true; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 581 | } |
| 582 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 583 | synchronized (gRecyclerLock) { |
| 584 | if (gRecyclerUsed < MAX_RECYCLED) { |
| 585 | gRecyclerUsed++; |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 586 | mNumSamples = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 587 | mNext = gRecyclerTop; |
| 588 | gRecyclerTop = this; |
| 589 | } |
| 590 | } |
| 591 | } |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 592 | |
| 593 | /** |
| 594 | * Scales down the coordination of this event by the given scale. |
| 595 | * |
| 596 | * @hide |
| 597 | */ |
| 598 | public final void scale(float scale) { |
| 599 | mXOffset *= scale; |
| 600 | mYOffset *= scale; |
| 601 | mXPrecision *= scale; |
| 602 | mYPrecision *= scale; |
| 603 | |
| 604 | float[] history = mDataSamples; |
| 605 | final int length = mNumPointers * mNumSamples * NUM_SAMPLE_DATA; |
| 606 | for (int i = 0; i < length; i += NUM_SAMPLE_DATA) { |
| 607 | history[i + SAMPLE_X] *= scale; |
| 608 | history[i + SAMPLE_Y] *= scale; |
| 609 | // no need to scale pressure |
| 610 | history[i + SAMPLE_SIZE] *= scale; // TODO: square this? |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 611 | history[i + SAMPLE_TOUCH_MAJOR] *= scale; |
| 612 | history[i + SAMPLE_TOUCH_MINOR] *= scale; |
| 613 | history[i + SAMPLE_TOOL_MAJOR] *= scale; |
| 614 | history[i + SAMPLE_TOOL_MINOR] *= scale; |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 615 | } |
| 616 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 617 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 618 | /** |
| 619 | * Return the kind of action being performed -- one of either |
| 620 | * {@link #ACTION_DOWN}, {@link #ACTION_MOVE}, {@link #ACTION_UP}, or |
Dianne Hackborn | b125dc5 | 2010-02-12 15:52:09 -0800 | [diff] [blame] | 621 | * {@link #ACTION_CANCEL}. Consider using {@link #getActionMasked} |
| 622 | * and {@link #getActionIndex} to retrieve the separate masked action |
| 623 | * and pointer index. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 624 | */ |
| 625 | public final int getAction() { |
| 626 | return mAction; |
| 627 | } |
| 628 | |
| 629 | /** |
Dianne Hackborn | b125dc5 | 2010-02-12 15:52:09 -0800 | [diff] [blame] | 630 | * Return the masked action being performed, without pointer index |
| 631 | * information. May be any of the actions: {@link #ACTION_DOWN}, |
| 632 | * {@link #ACTION_MOVE}, {@link #ACTION_UP}, {@link #ACTION_CANCEL}, |
| 633 | * {@link #ACTION_POINTER_DOWN}, or {@link #ACTION_POINTER_UP}. |
| 634 | * Use {@link #getActionIndex} to return the index associated with |
| 635 | * pointer actions. |
| 636 | */ |
| 637 | public final int getActionMasked() { |
| 638 | return mAction & ACTION_MASK; |
| 639 | } |
| 640 | |
| 641 | /** |
| 642 | * For {@link #ACTION_POINTER_DOWN} or {@link #ACTION_POINTER_UP} |
| 643 | * as returned by {@link #getActionMasked}, this returns the associated |
| 644 | * pointer index. The index may be used with {@link #getPointerId(int)}, |
| 645 | * {@link #getX(int)}, {@link #getY(int)}, {@link #getPressure(int)}, |
| 646 | * and {@link #getSize(int)} to get information about the pointer that has |
| 647 | * gone down or up. |
| 648 | */ |
| 649 | public final int getActionIndex() { |
| 650 | return (mAction & ACTION_POINTER_INDEX_MASK) >> ACTION_POINTER_INDEX_SHIFT; |
| 651 | } |
| 652 | |
| 653 | /** |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 654 | * Returns the time (in ms) when the user originally pressed down to start |
| 655 | * a stream of position events. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 656 | */ |
| 657 | public final long getDownTime() { |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 658 | return mDownTimeNano / MS_PER_NS; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 659 | } |
| 660 | |
| 661 | /** |
| 662 | * Returns the time (in ms) when this specific event was generated. |
| 663 | */ |
| 664 | public final long getEventTime() { |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 665 | return mEventTimeNanoSamples[mLastEventTimeNanoSampleIndex] / MS_PER_NS; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | /** |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 669 | * Returns the time (in ns) when this specific event was generated. |
| 670 | * The value is in nanosecond precision but it may not have nanosecond accuracy. |
| 671 | * |
| 672 | * @hide |
| 673 | */ |
| 674 | public final long getEventTimeNano() { |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 675 | return mEventTimeNanoSamples[mLastEventTimeNanoSampleIndex]; |
Michael Chan | 53071d6 | 2009-05-13 17:29:48 -0700 | [diff] [blame] | 676 | } |
| 677 | |
| 678 | /** |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 679 | * {@link #getX(int)} for the first pointer index (may be an |
| 680 | * arbitrary pointer identifier). |
| 681 | */ |
| 682 | public final float getX() { |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 683 | return mDataSamples[mLastDataSampleIndex + SAMPLE_X] + mXOffset; |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 684 | } |
| 685 | |
| 686 | /** |
| 687 | * {@link #getY(int)} for the first pointer index (may be an |
| 688 | * arbitrary pointer identifier). |
| 689 | */ |
| 690 | public final float getY() { |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 691 | return mDataSamples[mLastDataSampleIndex + SAMPLE_Y] + mYOffset; |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | /** |
| 695 | * {@link #getPressure(int)} for the first pointer index (may be an |
| 696 | * arbitrary pointer identifier). |
| 697 | */ |
| 698 | public final float getPressure() { |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 699 | return mDataSamples[mLastDataSampleIndex + SAMPLE_PRESSURE]; |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 700 | } |
| 701 | |
| 702 | /** |
| 703 | * {@link #getSize(int)} for the first pointer index (may be an |
| 704 | * arbitrary pointer identifier). |
| 705 | */ |
| 706 | public final float getSize() { |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 707 | return mDataSamples[mLastDataSampleIndex + SAMPLE_SIZE]; |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 708 | } |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 709 | |
| 710 | /** |
| 711 | * {@link #getTouchMajor(int)} for the first pointer index (may be an |
| 712 | * arbitrary pointer identifier). |
| 713 | */ |
| 714 | public final float getTouchMajor() { |
| 715 | return mDataSamples[mLastDataSampleIndex + SAMPLE_TOUCH_MAJOR]; |
| 716 | } |
| 717 | |
| 718 | /** |
| 719 | * {@link #getTouchMinor(int)} for the first pointer index (may be an |
| 720 | * arbitrary pointer identifier). |
| 721 | */ |
| 722 | public final float getTouchMinor() { |
| 723 | return mDataSamples[mLastDataSampleIndex + SAMPLE_TOUCH_MINOR]; |
| 724 | } |
| 725 | |
| 726 | /** |
| 727 | * {@link #getToolMajor(int)} for the first pointer index (may be an |
| 728 | * arbitrary pointer identifier). |
| 729 | */ |
| 730 | public final float getToolMajor() { |
| 731 | return mDataSamples[mLastDataSampleIndex + SAMPLE_TOOL_MAJOR]; |
| 732 | } |
| 733 | |
| 734 | /** |
| 735 | * {@link #getToolMinor(int)} for the first pointer index (may be an |
| 736 | * arbitrary pointer identifier). |
| 737 | */ |
| 738 | public final float getToolMinor() { |
| 739 | return mDataSamples[mLastDataSampleIndex + SAMPLE_TOOL_MINOR]; |
| 740 | } |
| 741 | |
| 742 | /** |
| 743 | * {@link #getOrientation(int)} for the first pointer index (may be an |
| 744 | * arbitrary pointer identifier). |
| 745 | */ |
| 746 | public final float getOrientation() { |
| 747 | return mDataSamples[mLastDataSampleIndex + SAMPLE_ORIENTATION]; |
| 748 | } |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 749 | |
| 750 | /** |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 751 | * The number of pointers of data contained in this event. Always |
| 752 | * >= 1. |
| 753 | */ |
| 754 | public final int getPointerCount() { |
| 755 | return mNumPointers; |
| 756 | } |
| 757 | |
| 758 | /** |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 759 | * Return the pointer identifier associated with a particular pointer |
| 760 | * data index is this event. The identifier tells you the actual pointer |
| 761 | * number associated with the data, accounting for individual pointers |
| 762 | * going up and down since the start of the current gesture. |
| 763 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 764 | * (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] | 765 | */ |
Dianne Hackborn | d41ba66 | 2009-08-05 15:30:56 -0700 | [diff] [blame] | 766 | public final int getPointerId(int pointerIndex) { |
| 767 | return mPointerIdentifiers[pointerIndex]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 768 | } |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 769 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 770 | /** |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 771 | * Given a pointer identifier, find the index of its data in the event. |
| 772 | * |
| 773 | * @param pointerId The identifier of the pointer to be found. |
| 774 | * @return Returns either the index of the pointer (for use with |
| 775 | * {@link #getX(int) et al.), or -1 if there is no data available for |
| 776 | * that pointer identifier. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 777 | */ |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 778 | public final int findPointerIndex(int pointerId) { |
| 779 | int i = mNumPointers; |
| 780 | while (i > 0) { |
| 781 | i--; |
| 782 | if (mPointerIdentifiers[i] == pointerId) { |
| 783 | return i; |
| 784 | } |
| 785 | } |
| 786 | return -1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 787 | } |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 788 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 789 | /** |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 790 | * Returns the X coordinate of this event for the given pointer |
| 791 | * <em>index</em> (use {@link #getPointerId(int)} to find the pointer |
| 792 | * identifier for this index). |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 793 | * Whole numbers are pixels; the |
| 794 | * 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] | 795 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 796 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 797 | */ |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 798 | public final float getX(int pointerIndex) { |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 799 | return mDataSamples[mLastDataSampleIndex |
| 800 | + pointerIndex * NUM_SAMPLE_DATA + SAMPLE_X] + mXOffset; |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 801 | } |
| 802 | |
| 803 | /** |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 804 | * Returns the Y coordinate of this event for the given pointer |
| 805 | * <em>index</em> (use {@link #getPointerId(int)} to find the pointer |
| 806 | * identifier for this index). |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 807 | * Whole numbers are pixels; the |
| 808 | * 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] | 809 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 810 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 811 | */ |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 812 | public final float getY(int pointerIndex) { |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 813 | return mDataSamples[mLastDataSampleIndex |
| 814 | + pointerIndex * NUM_SAMPLE_DATA + SAMPLE_Y] + mYOffset; |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | /** |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 818 | * Returns the current pressure of this event for the given pointer |
| 819 | * <em>index</em> (use {@link #getPointerId(int)} to find the pointer |
| 820 | * identifier for this index). |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 821 | * The pressure generally |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 822 | * ranges from 0 (no pressure at all) to 1 (normal pressure), however |
| 823 | * 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] | 824 | * the input device. |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 825 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 826 | * (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] | 827 | */ |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 828 | public final float getPressure(int pointerIndex) { |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 829 | return mDataSamples[mLastDataSampleIndex |
| 830 | + pointerIndex * NUM_SAMPLE_DATA + SAMPLE_PRESSURE]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 831 | } |
| 832 | |
| 833 | /** |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 834 | * Returns a scaled value of the approximate size for the given pointer |
| 835 | * <em>index</em> (use {@link #getPointerId(int)} to find the pointer |
| 836 | * identifier for this index). |
| 837 | * This represents some approximation of the area of the screen being |
| 838 | * pressed; the actual value in pixels corresponding to the |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 839 | * touch is normalized with the device specific range of values |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 840 | * 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] | 841 | * determine fat touch events. |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 842 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 843 | * (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] | 844 | */ |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 845 | public final float getSize(int pointerIndex) { |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 846 | return mDataSamples[mLastDataSampleIndex |
| 847 | + pointerIndex * NUM_SAMPLE_DATA + SAMPLE_SIZE]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 848 | } |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 849 | |
| 850 | /** |
| 851 | * Returns the length of the major axis of an ellipse that describes the touch |
| 852 | * area at the point of contact for the given pointer |
| 853 | * <em>index</em> (use {@link #getPointerId(int)} to find the pointer |
| 854 | * identifier for this index). |
| 855 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 856 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
| 857 | */ |
| 858 | public final float getTouchMajor(int pointerIndex) { |
| 859 | return mDataSamples[mLastDataSampleIndex |
| 860 | + pointerIndex * NUM_SAMPLE_DATA + SAMPLE_TOUCH_MAJOR]; |
| 861 | } |
| 862 | |
| 863 | /** |
| 864 | * Returns the length of the minor axis of an ellipse that describes the touch |
| 865 | * area at the point of contact for the given pointer |
| 866 | * <em>index</em> (use {@link #getPointerId(int)} to find the pointer |
| 867 | * identifier for this index). |
| 868 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 869 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
| 870 | */ |
| 871 | public final float getTouchMinor(int pointerIndex) { |
| 872 | return mDataSamples[mLastDataSampleIndex |
| 873 | + pointerIndex * NUM_SAMPLE_DATA + SAMPLE_TOUCH_MINOR]; |
| 874 | } |
| 875 | |
| 876 | /** |
| 877 | * Returns the length of the major axis of an ellipse that describes the size of |
| 878 | * the approaching tool for the given pointer |
| 879 | * <em>index</em> (use {@link #getPointerId(int)} to find the pointer |
| 880 | * identifier for this index). |
| 881 | * The tool area represents the estimated size of the finger or pen that is |
| 882 | * touching the device independent of its actual touch area at the point of contact. |
| 883 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 884 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
| 885 | */ |
| 886 | public final float getToolMajor(int pointerIndex) { |
| 887 | return mDataSamples[mLastDataSampleIndex |
| 888 | + pointerIndex * NUM_SAMPLE_DATA + SAMPLE_TOOL_MAJOR]; |
| 889 | } |
| 890 | |
| 891 | /** |
| 892 | * Returns the length of the minor axis of an ellipse that describes the size of |
| 893 | * the approaching tool for the given pointer |
| 894 | * <em>index</em> (use {@link #getPointerId(int)} to find the pointer |
| 895 | * identifier for this index). |
| 896 | * The tool area represents the estimated size of the finger or pen that is |
| 897 | * touching the device independent of its actual touch area at the point of contact. |
| 898 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 899 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
| 900 | */ |
| 901 | public final float getToolMinor(int pointerIndex) { |
| 902 | return mDataSamples[mLastDataSampleIndex |
| 903 | + pointerIndex * NUM_SAMPLE_DATA + SAMPLE_TOOL_MINOR]; |
| 904 | } |
| 905 | |
| 906 | /** |
| 907 | * Returns the orientation of the touch area and tool area in radians clockwise from vertical |
| 908 | * for the given pointer <em>index</em> (use {@link #getPointerId(int)} to find the pointer |
| 909 | * identifier for this index). |
| 910 | * An angle of 0 degrees indicates that the major axis of contact is oriented |
| 911 | * upwards, is perfectly circular or is of unknown orientation. A positive angle |
| 912 | * indicates that the major axis of contact is oriented to the right. A negative angle |
| 913 | * indicates that the major axis of contact is oriented to the left. |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 914 | * 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] | 915 | * (finger pointing fully right). |
| 916 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 917 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
| 918 | */ |
| 919 | public final float getOrientation(int pointerIndex) { |
| 920 | return mDataSamples[mLastDataSampleIndex |
| 921 | + pointerIndex * NUM_SAMPLE_DATA + SAMPLE_ORIENTATION]; |
| 922 | } |
| 923 | |
| 924 | /** |
| 925 | * Populates a {@link PointerCoords} object with pointer coordinate data for |
| 926 | * the specified pointer index. |
| 927 | * |
| 928 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 929 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
| 930 | * @param outPointerCoords The pointer coordinate object to populate. |
| 931 | */ |
| 932 | public final void getPointerCoords(int pointerIndex, PointerCoords outPointerCoords) { |
| 933 | final int sampleIndex = mLastDataSampleIndex + pointerIndex * NUM_SAMPLE_DATA; |
| 934 | getPointerCoordsAtSampleIndex(sampleIndex, outPointerCoords); |
| 935 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 936 | |
| 937 | /** |
| 938 | * Returns the state of any meta / modifier keys that were in effect when |
| 939 | * the event was generated. This is the same values as those |
| 940 | * returned by {@link KeyEvent#getMetaState() KeyEvent.getMetaState}. |
| 941 | * |
| 942 | * @return an integer in which each bit set to 1 represents a pressed |
| 943 | * meta key |
| 944 | * |
| 945 | * @see KeyEvent#getMetaState() |
| 946 | */ |
| 947 | public final int getMetaState() { |
| 948 | return mMetaState; |
| 949 | } |
| 950 | |
| 951 | /** |
| 952 | * Returns the original raw X coordinate of this event. For touch |
| 953 | * events on the screen, this is the original location of the event |
| 954 | * on the screen, before it had been adjusted for the containing window |
| 955 | * and views. |
| 956 | */ |
| 957 | public final float getRawX() { |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 958 | return mDataSamples[mLastDataSampleIndex + SAMPLE_X]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 959 | } |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 960 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 961 | /** |
| 962 | * Returns the original raw Y coordinate of this event. For touch |
| 963 | * events on the screen, this is the original location of the event |
| 964 | * on the screen, before it had been adjusted for the containing window |
| 965 | * and views. |
| 966 | */ |
| 967 | public final float getRawY() { |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 968 | return mDataSamples[mLastDataSampleIndex + SAMPLE_Y]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 969 | } |
| 970 | |
| 971 | /** |
| 972 | * Return the precision of the X coordinates being reported. You can |
| 973 | * multiple this number with {@link #getX} to find the actual hardware |
| 974 | * value of the X coordinate. |
| 975 | * @return Returns the precision of X coordinates being reported. |
| 976 | */ |
| 977 | public final float getXPrecision() { |
| 978 | return mXPrecision; |
| 979 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 980 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 981 | /** |
| 982 | * Return the precision of the Y coordinates being reported. You can |
| 983 | * multiple this number with {@link #getY} to find the actual hardware |
| 984 | * value of the Y coordinate. |
| 985 | * @return Returns the precision of Y coordinates being reported. |
| 986 | */ |
| 987 | public final float getYPrecision() { |
| 988 | return mYPrecision; |
| 989 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 990 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 991 | /** |
| 992 | * Returns the number of historical points in this event. These are |
| 993 | * movements that have occurred between this event and the previous event. |
| 994 | * This only applies to ACTION_MOVE events -- all other actions will have |
| 995 | * a size of 0. |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 996 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 997 | * @return Returns the number of historical points in the event. |
| 998 | */ |
| 999 | public final int getHistorySize() { |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1000 | return mLastEventTimeNanoSampleIndex; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1001 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1002 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1003 | /** |
| 1004 | * Returns the time that a historical movement occurred between this event |
| 1005 | * and the previous event. Only applies to ACTION_MOVE events. |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1006 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1007 | * @param pos Which historical value to return; must be less than |
| 1008 | * {@link #getHistorySize} |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1009 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1010 | * @see #getHistorySize |
| 1011 | * @see #getEventTime |
| 1012 | */ |
| 1013 | public final long getHistoricalEventTime(int pos) { |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1014 | return mEventTimeNanoSamples[pos] / MS_PER_NS; |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1015 | } |
| 1016 | |
| 1017 | /** |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1018 | * {@link #getHistoricalX(int)} for the first pointer index (may be an |
| 1019 | * arbitrary pointer identifier). |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1020 | */ |
| 1021 | public final float getHistoricalX(int pos) { |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1022 | return mDataSamples[pos * mNumPointers * NUM_SAMPLE_DATA + SAMPLE_X] + mXOffset; |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1023 | } |
| 1024 | |
| 1025 | /** |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1026 | * {@link #getHistoricalY(int)} for the first pointer index (may be an |
| 1027 | * arbitrary pointer identifier). |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1028 | */ |
| 1029 | public final float getHistoricalY(int pos) { |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1030 | return mDataSamples[pos * mNumPointers * NUM_SAMPLE_DATA + SAMPLE_Y] + mYOffset; |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1031 | } |
| 1032 | |
| 1033 | /** |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1034 | * {@link #getHistoricalPressure(int)} for the first pointer index (may be an |
| 1035 | * arbitrary pointer identifier). |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1036 | */ |
| 1037 | public final float getHistoricalPressure(int pos) { |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1038 | return mDataSamples[pos * mNumPointers * NUM_SAMPLE_DATA + SAMPLE_PRESSURE]; |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1039 | } |
| 1040 | |
| 1041 | /** |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1042 | * {@link #getHistoricalSize(int)} for the first pointer index (may be an |
| 1043 | * arbitrary pointer identifier). |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1044 | */ |
| 1045 | public final float getHistoricalSize(int pos) { |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1046 | return mDataSamples[pos * mNumPointers * NUM_SAMPLE_DATA + SAMPLE_SIZE]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1047 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1048 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1049 | /** |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1050 | * {@link #getHistoricalTouchMajor(int)} for the first pointer index (may be an |
| 1051 | * arbitrary pointer identifier). |
| 1052 | */ |
| 1053 | public final float getHistoricalTouchMajor(int pos) { |
| 1054 | return mDataSamples[pos * mNumPointers * NUM_SAMPLE_DATA + SAMPLE_TOUCH_MAJOR]; |
| 1055 | } |
| 1056 | |
| 1057 | /** |
| 1058 | * {@link #getHistoricalTouchMinor(int)} for the first pointer index (may be an |
| 1059 | * arbitrary pointer identifier). |
| 1060 | */ |
| 1061 | public final float getHistoricalTouchMinor(int pos) { |
| 1062 | return mDataSamples[pos * mNumPointers * NUM_SAMPLE_DATA + SAMPLE_TOUCH_MINOR]; |
| 1063 | } |
| 1064 | |
| 1065 | /** |
| 1066 | * {@link #getHistoricalToolMajor(int)} for the first pointer index (may be an |
| 1067 | * arbitrary pointer identifier). |
| 1068 | */ |
| 1069 | public final float getHistoricalToolMajor(int pos) { |
| 1070 | return mDataSamples[pos * mNumPointers * NUM_SAMPLE_DATA + SAMPLE_TOOL_MAJOR]; |
| 1071 | } |
| 1072 | |
| 1073 | /** |
| 1074 | * {@link #getHistoricalToolMinor(int)} for the first pointer index (may be an |
| 1075 | * arbitrary pointer identifier). |
| 1076 | */ |
| 1077 | public final float getHistoricalToolMinor(int pos) { |
| 1078 | return mDataSamples[pos * mNumPointers * NUM_SAMPLE_DATA + SAMPLE_TOOL_MINOR]; |
| 1079 | } |
| 1080 | |
| 1081 | /** |
| 1082 | * {@link #getHistoricalOrientation(int)} for the first pointer index (may be an |
| 1083 | * arbitrary pointer identifier). |
| 1084 | */ |
| 1085 | public final float getHistoricalOrientation(int pos) { |
| 1086 | return mDataSamples[pos * mNumPointers * NUM_SAMPLE_DATA + SAMPLE_ORIENTATION]; |
| 1087 | } |
| 1088 | |
| 1089 | /** |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1090 | * Returns a historical X coordinate, as per {@link #getX(int)}, that |
| 1091 | * occurred between this event and the previous event for the given pointer. |
| 1092 | * Only applies to ACTION_MOVE events. |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1093 | * |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1094 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 1095 | * (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] | 1096 | * @param pos Which historical value to return; must be less than |
| 1097 | * {@link #getHistorySize} |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1098 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1099 | * @see #getHistorySize |
| 1100 | * @see #getX |
| 1101 | */ |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1102 | public final float getHistoricalX(int pointerIndex, int pos) { |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1103 | return mDataSamples[(pos * mNumPointers + pointerIndex) |
| 1104 | * NUM_SAMPLE_DATA + SAMPLE_X] + mXOffset; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1105 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1106 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1107 | /** |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1108 | * Returns a historical Y coordinate, as per {@link #getY(int)}, that |
| 1109 | * occurred between this event and the previous event for the given pointer. |
| 1110 | * Only applies to ACTION_MOVE events. |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1111 | * |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1112 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 1113 | * (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] | 1114 | * @param pos Which historical value to return; must be less than |
| 1115 | * {@link #getHistorySize} |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1116 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1117 | * @see #getHistorySize |
| 1118 | * @see #getY |
| 1119 | */ |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1120 | public final float getHistoricalY(int pointerIndex, int pos) { |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1121 | return mDataSamples[(pos * mNumPointers + pointerIndex) |
| 1122 | * NUM_SAMPLE_DATA + SAMPLE_Y] + mYOffset; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1123 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1124 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1125 | /** |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1126 | * Returns a historical pressure coordinate, as per {@link #getPressure(int)}, |
| 1127 | * that occurred between this event and the previous event for the given |
| 1128 | * pointer. Only applies to ACTION_MOVE events. |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1129 | * |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1130 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 1131 | * (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] | 1132 | * @param pos Which historical value to return; must be less than |
| 1133 | * {@link #getHistorySize} |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1134 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1135 | * @see #getHistorySize |
| 1136 | * @see #getPressure |
| 1137 | */ |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1138 | public final float getHistoricalPressure(int pointerIndex, int pos) { |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1139 | return mDataSamples[(pos * mNumPointers + pointerIndex) |
| 1140 | * NUM_SAMPLE_DATA + SAMPLE_PRESSURE]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1141 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1142 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1143 | /** |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1144 | * Returns a historical size coordinate, as per {@link #getSize(int)}, that |
| 1145 | * occurred between this event and the previous event for the given pointer. |
| 1146 | * Only applies to ACTION_MOVE events. |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1147 | * |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1148 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 1149 | * (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] | 1150 | * @param pos Which historical value to return; must be less than |
| 1151 | * {@link #getHistorySize} |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1152 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1153 | * @see #getHistorySize |
| 1154 | * @see #getSize |
| 1155 | */ |
Dianne Hackborn | 0dd7cb4 | 2009-08-04 05:49:43 -0700 | [diff] [blame] | 1156 | public final float getHistoricalSize(int pointerIndex, int pos) { |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1157 | return mDataSamples[(pos * mNumPointers + pointerIndex) |
| 1158 | * NUM_SAMPLE_DATA + SAMPLE_SIZE]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1159 | } |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1160 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1161 | /** |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1162 | * Returns a historical touch major axis coordinate, as per {@link #getTouchMajor(int)}, that |
| 1163 | * occurred between this event and the previous event for the given pointer. |
| 1164 | * Only applies to ACTION_MOVE events. |
| 1165 | * |
| 1166 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 1167 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
| 1168 | * @param pos Which historical value to return; must be less than |
| 1169 | * {@link #getHistorySize} |
| 1170 | * |
| 1171 | * @see #getHistorySize |
| 1172 | * @see #getTouchMajor |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1173 | */ |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1174 | public final float getHistoricalTouchMajor(int pointerIndex, int pos) { |
| 1175 | return mDataSamples[(pos * mNumPointers + pointerIndex) |
| 1176 | * NUM_SAMPLE_DATA + SAMPLE_TOUCH_MAJOR]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1177 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1178 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1179 | /** |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1180 | * Returns a historical touch minor axis coordinate, as per {@link #getTouchMinor(int)}, that |
| 1181 | * occurred between this event and the previous event for the given pointer. |
| 1182 | * Only applies to ACTION_MOVE events. |
| 1183 | * |
| 1184 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 1185 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
| 1186 | * @param pos Which historical value to return; must be less than |
| 1187 | * {@link #getHistorySize} |
| 1188 | * |
| 1189 | * @see #getHistorySize |
| 1190 | * @see #getTouchMinor |
| 1191 | */ |
| 1192 | public final float getHistoricalTouchMinor(int pointerIndex, int pos) { |
| 1193 | return mDataSamples[(pos * mNumPointers + pointerIndex) |
| 1194 | * NUM_SAMPLE_DATA + SAMPLE_TOUCH_MINOR]; |
| 1195 | } |
| 1196 | |
| 1197 | /** |
| 1198 | * Returns a historical tool major axis coordinate, as per {@link #getToolMajor(int)}, that |
| 1199 | * occurred between this event and the previous event for the given pointer. |
| 1200 | * Only applies to ACTION_MOVE events. |
| 1201 | * |
| 1202 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 1203 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
| 1204 | * @param pos Which historical value to return; must be less than |
| 1205 | * {@link #getHistorySize} |
| 1206 | * |
| 1207 | * @see #getHistorySize |
| 1208 | * @see #getToolMajor |
| 1209 | */ |
| 1210 | public final float getHistoricalToolMajor(int pointerIndex, int pos) { |
| 1211 | return mDataSamples[(pos * mNumPointers + pointerIndex) |
| 1212 | * NUM_SAMPLE_DATA + SAMPLE_TOOL_MAJOR]; |
| 1213 | } |
| 1214 | |
| 1215 | /** |
| 1216 | * Returns a historical tool minor axis coordinate, as per {@link #getToolMinor(int)}, that |
| 1217 | * occurred between this event and the previous event for the given pointer. |
| 1218 | * Only applies to ACTION_MOVE events. |
| 1219 | * |
| 1220 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 1221 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
| 1222 | * @param pos Which historical value to return; must be less than |
| 1223 | * {@link #getHistorySize} |
| 1224 | * |
| 1225 | * @see #getHistorySize |
| 1226 | * @see #getToolMinor |
| 1227 | */ |
| 1228 | public final float getHistoricalToolMinor(int pointerIndex, int pos) { |
| 1229 | return mDataSamples[(pos * mNumPointers + pointerIndex) |
| 1230 | * NUM_SAMPLE_DATA + SAMPLE_TOOL_MINOR]; |
| 1231 | } |
| 1232 | |
| 1233 | /** |
| 1234 | * Returns a historical orientation coordinate, as per {@link #getOrientation(int)}, that |
| 1235 | * occurred between this event and the previous event for the given pointer. |
| 1236 | * Only applies to ACTION_MOVE events. |
| 1237 | * |
| 1238 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 1239 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
| 1240 | * @param pos Which historical value to return; must be less than |
| 1241 | * {@link #getHistorySize} |
| 1242 | * |
| 1243 | * @see #getHistorySize |
| 1244 | * @see #getOrientation |
| 1245 | */ |
| 1246 | public final float getHistoricalOrientation(int pointerIndex, int pos) { |
| 1247 | return mDataSamples[(pos * mNumPointers + pointerIndex) |
| 1248 | * NUM_SAMPLE_DATA + SAMPLE_ORIENTATION]; |
| 1249 | } |
| 1250 | |
| 1251 | /** |
| 1252 | * Populates a {@link PointerCoords} object with historical pointer coordinate data, |
| 1253 | * as per {@link #getPointerCoords}, that occurred between this event and the previous |
| 1254 | * event for the given pointer. |
| 1255 | * Only applies to ACTION_MOVE events. |
| 1256 | * |
| 1257 | * @param pointerIndex Raw index of pointer to retrieve. Value may be from 0 |
| 1258 | * (the first pointer that is down) to {@link #getPointerCount()}-1. |
| 1259 | * @param pos Which historical value to return; must be less than |
| 1260 | * {@link #getHistorySize} |
| 1261 | * @param outPointerCoords The pointer coordinate object to populate. |
| 1262 | * |
| 1263 | * @see #getHistorySize |
| 1264 | * @see #getPointerCoords |
| 1265 | */ |
| 1266 | public final void getHistoricalPointerCoords(int pointerIndex, int pos, |
| 1267 | PointerCoords outPointerCoords) { |
| 1268 | final int sampleIndex = (pos * mNumPointers + pointerIndex) * NUM_SAMPLE_DATA; |
| 1269 | getPointerCoordsAtSampleIndex(sampleIndex, outPointerCoords); |
| 1270 | } |
| 1271 | |
| 1272 | /** |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1273 | * Returns a bitfield indicating which edges, if any, were touched by this |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1274 | * MotionEvent. For touch events, clients can use this to determine if the |
| 1275 | * user's finger was touching the edge of the display. |
| 1276 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1277 | * @see #EDGE_LEFT |
| 1278 | * @see #EDGE_TOP |
| 1279 | * @see #EDGE_RIGHT |
| 1280 | * @see #EDGE_BOTTOM |
| 1281 | */ |
| 1282 | public final int getEdgeFlags() { |
| 1283 | return mEdgeFlags; |
| 1284 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1285 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1286 | |
| 1287 | /** |
| 1288 | * Sets the bitfield indicating which edges, if any, where touched by this |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1289 | * MotionEvent. |
| 1290 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1291 | * @see #getEdgeFlags() |
| 1292 | */ |
| 1293 | public final void setEdgeFlags(int flags) { |
| 1294 | mEdgeFlags = flags; |
| 1295 | } |
| 1296 | |
| 1297 | /** |
| 1298 | * Sets this event's action. |
| 1299 | */ |
| 1300 | public final void setAction(int action) { |
| 1301 | mAction = action; |
| 1302 | } |
| 1303 | |
| 1304 | /** |
| 1305 | * Adjust this event's location. |
| 1306 | * @param deltaX Amount to add to the current X coordinate of the event. |
| 1307 | * @param deltaY Amount to add to the current Y coordinate of the event. |
| 1308 | */ |
| 1309 | public final void offsetLocation(float deltaX, float deltaY) { |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1310 | mXOffset += deltaX; |
| 1311 | mYOffset += deltaY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1312 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1313 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1314 | /** |
| 1315 | * Set this event's location. Applies {@link #offsetLocation} with a |
| 1316 | * delta from the current location to the given new location. |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1317 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1318 | * @param x New absolute X location. |
| 1319 | * @param y New absolute Y location. |
| 1320 | */ |
| 1321 | public final void setLocation(float x, float y) { |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1322 | mXOffset = x - mDataSamples[mLastDataSampleIndex + SAMPLE_X]; |
| 1323 | mYOffset = y - mDataSamples[mLastDataSampleIndex + SAMPLE_Y]; |
| 1324 | } |
| 1325 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1326 | private final void getPointerCoordsAtSampleIndex(int sampleIndex, |
| 1327 | PointerCoords outPointerCoords) { |
| 1328 | outPointerCoords.x = mDataSamples[sampleIndex + SAMPLE_X] + mXOffset; |
| 1329 | outPointerCoords.y = mDataSamples[sampleIndex + SAMPLE_Y] + mYOffset; |
| 1330 | outPointerCoords.pressure = mDataSamples[sampleIndex + SAMPLE_PRESSURE]; |
| 1331 | outPointerCoords.size = mDataSamples[sampleIndex + SAMPLE_SIZE]; |
| 1332 | outPointerCoords.touchMajor = mDataSamples[sampleIndex + SAMPLE_TOUCH_MAJOR]; |
| 1333 | outPointerCoords.touchMinor = mDataSamples[sampleIndex + SAMPLE_TOUCH_MINOR]; |
| 1334 | outPointerCoords.toolMajor = mDataSamples[sampleIndex + SAMPLE_TOOL_MAJOR]; |
| 1335 | outPointerCoords.toolMinor = mDataSamples[sampleIndex + SAMPLE_TOOL_MINOR]; |
| 1336 | outPointerCoords.orientation = mDataSamples[sampleIndex + SAMPLE_ORIENTATION]; |
| 1337 | } |
| 1338 | |
| 1339 | private final void setPointerCoordsAtSampleIndex(int sampleIndex, |
| 1340 | PointerCoords[] pointerCoords) { |
| 1341 | final int numPointers = mNumPointers; |
| 1342 | for (int i = 0; i < numPointers; i++) { |
| 1343 | setPointerCoordsAtSampleIndex(sampleIndex, pointerCoords[i]); |
| 1344 | sampleIndex += NUM_SAMPLE_DATA; |
| 1345 | } |
| 1346 | } |
| 1347 | |
| 1348 | private final void setPointerCoordsAtSampleIndex(int sampleIndex, |
| 1349 | PointerCoords pointerCoords) { |
| 1350 | mDataSamples[sampleIndex + SAMPLE_X] = pointerCoords.x - mXOffset; |
| 1351 | mDataSamples[sampleIndex + SAMPLE_Y] = pointerCoords.y - mYOffset; |
| 1352 | mDataSamples[sampleIndex + SAMPLE_PRESSURE] = pointerCoords.pressure; |
| 1353 | mDataSamples[sampleIndex + SAMPLE_SIZE] = pointerCoords.size; |
| 1354 | mDataSamples[sampleIndex + SAMPLE_TOUCH_MAJOR] = pointerCoords.touchMajor; |
| 1355 | mDataSamples[sampleIndex + SAMPLE_TOUCH_MINOR] = pointerCoords.touchMinor; |
| 1356 | mDataSamples[sampleIndex + SAMPLE_TOOL_MAJOR] = pointerCoords.toolMajor; |
| 1357 | mDataSamples[sampleIndex + SAMPLE_TOOL_MINOR] = pointerCoords.toolMinor; |
| 1358 | mDataSamples[sampleIndex + SAMPLE_ORIENTATION] = pointerCoords.orientation; |
| 1359 | } |
| 1360 | |
| 1361 | private final void setPointerCoordsAtSampleIndex(int sampleIndex, |
| 1362 | float x, float y, float pressure, float size) { |
| 1363 | mDataSamples[sampleIndex + SAMPLE_X] = x - mXOffset; |
| 1364 | mDataSamples[sampleIndex + SAMPLE_Y] = y - mYOffset; |
| 1365 | mDataSamples[sampleIndex + SAMPLE_PRESSURE] = pressure; |
| 1366 | mDataSamples[sampleIndex + SAMPLE_SIZE] = size; |
| 1367 | mDataSamples[sampleIndex + SAMPLE_TOUCH_MAJOR] = pressure; |
| 1368 | mDataSamples[sampleIndex + SAMPLE_TOUCH_MINOR] = pressure; |
| 1369 | mDataSamples[sampleIndex + SAMPLE_TOOL_MAJOR] = size; |
| 1370 | mDataSamples[sampleIndex + SAMPLE_TOOL_MINOR] = size; |
| 1371 | mDataSamples[sampleIndex + SAMPLE_ORIENTATION] = 0; |
| 1372 | } |
| 1373 | |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1374 | private final void incrementNumSamplesAndReserveStorage(int dataSampleStride) { |
| 1375 | if (mNumSamples == mEventTimeNanoSamples.length) { |
| 1376 | long[] newEventTimeNanoSamples = new long[mNumSamples + BASE_AVAIL_SAMPLES]; |
| 1377 | System.arraycopy(mEventTimeNanoSamples, 0, newEventTimeNanoSamples, 0, mNumSamples); |
| 1378 | mEventTimeNanoSamples = newEventTimeNanoSamples; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1379 | } |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1380 | |
| 1381 | int nextDataSampleIndex = mLastDataSampleIndex + dataSampleStride; |
| 1382 | if (nextDataSampleIndex + dataSampleStride > mDataSamples.length) { |
| 1383 | float[] newDataSamples = new float[nextDataSampleIndex |
| 1384 | + BASE_AVAIL_SAMPLES * dataSampleStride]; |
| 1385 | System.arraycopy(mDataSamples, 0, newDataSamples, 0, nextDataSampleIndex); |
| 1386 | mDataSamples = newDataSamples; |
| 1387 | } |
| 1388 | |
| 1389 | mLastEventTimeNanoSampleIndex = mNumSamples; |
| 1390 | mLastDataSampleIndex = nextDataSampleIndex; |
| 1391 | mNumSamples += 1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1392 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1393 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1394 | /** |
| 1395 | * 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] | 1396 | * current location, position and size is updated to the new values. |
| 1397 | * The current values in the event are added to a list of historical values. |
| 1398 | * |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1399 | * Only applies to {@link #ACTION_MOVE} events. |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1400 | * |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1401 | * @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] | 1402 | * @param x The new X position. |
| 1403 | * @param y The new Y position. |
| 1404 | * @param pressure The new pressure. |
| 1405 | * @param size The new size. |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1406 | * @param metaState Meta key state. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1407 | */ |
| 1408 | public final void addBatch(long eventTime, float x, float y, |
| 1409 | float pressure, float size, int metaState) { |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1410 | incrementNumSamplesAndReserveStorage(NUM_SAMPLE_DATA); |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1411 | |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1412 | mEventTimeNanoSamples[mLastEventTimeNanoSampleIndex] = eventTime * MS_PER_NS; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1413 | setPointerCoordsAtSampleIndex(mLastDataSampleIndex, x, y, pressure, size); |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1414 | |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1415 | mMetaState |= metaState; |
| 1416 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1417 | |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1418 | /** |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1419 | * Add a new movement to the batch of movements in this event. The event's |
| 1420 | * current location, position and size is updated to the new values. |
| 1421 | * The current values in the event are added to a list of historical values. |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1422 | * |
Jeff Brown | e33348b | 2010-07-15 23:54:05 -0700 | [diff] [blame] | 1423 | * Only applies to {@link #ACTION_MOVE} events. |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1424 | * |
| 1425 | * @param eventTime The time stamp (in ms) for this data. |
| 1426 | * @param pointerCoords The new pointer coordinates. |
| 1427 | * @param metaState Meta key state. |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1428 | */ |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1429 | public final void addBatch(long eventTime, PointerCoords[] pointerCoords, int metaState) { |
| 1430 | final int dataSampleStride = mNumPointers * NUM_SAMPLE_DATA; |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1431 | incrementNumSamplesAndReserveStorage(dataSampleStride); |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1432 | |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1433 | mEventTimeNanoSamples[mLastEventTimeNanoSampleIndex] = eventTime * MS_PER_NS; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1434 | setPointerCoordsAtSampleIndex(mLastDataSampleIndex, pointerCoords); |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1435 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1436 | mMetaState |= metaState; |
| 1437 | } |
Romain Guy | cafdea6 | 2009-06-12 10:51:36 -0700 | [diff] [blame] | 1438 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1439 | @Override |
| 1440 | public String toString() { |
| 1441 | return "MotionEvent{" + Integer.toHexString(System.identityHashCode(this)) |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1442 | + " action=" + mAction + " x=" + getX() |
| 1443 | + " y=" + getY() + " pressure=" + getPressure() + " size=" + getSize() + "}"; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1444 | } |
| 1445 | |
| 1446 | public static final Parcelable.Creator<MotionEvent> CREATOR |
| 1447 | = new Parcelable.Creator<MotionEvent>() { |
| 1448 | public MotionEvent createFromParcel(Parcel in) { |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 1449 | in.readInt(); // skip token, we already know this is a MotionEvent |
| 1450 | return MotionEvent.createFromParcelBody(in); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1451 | } |
| 1452 | |
| 1453 | public MotionEvent[] newArray(int size) { |
| 1454 | return new MotionEvent[size]; |
| 1455 | } |
| 1456 | }; |
| 1457 | |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 1458 | /** @hide */ |
| 1459 | public static MotionEvent createFromParcelBody(Parcel in) { |
| 1460 | final int NP = in.readInt(); |
| 1461 | final int NS = in.readInt(); |
| 1462 | final int NI = NP * NS * NUM_SAMPLE_DATA; |
| 1463 | |
| 1464 | MotionEvent ev = obtain(NP, NS); |
| 1465 | ev.mNumPointers = NP; |
| 1466 | ev.mNumSamples = NS; |
| 1467 | |
| 1468 | ev.readBaseFromParcel(in); |
| 1469 | |
| 1470 | ev.mDownTimeNano = in.readLong(); |
| 1471 | ev.mAction = in.readInt(); |
| 1472 | ev.mXOffset = in.readFloat(); |
| 1473 | ev.mYOffset = in.readFloat(); |
| 1474 | ev.mXPrecision = in.readFloat(); |
| 1475 | ev.mYPrecision = in.readFloat(); |
| 1476 | ev.mEdgeFlags = in.readInt(); |
| 1477 | ev.mMetaState = in.readInt(); |
| 1478 | |
| 1479 | final int[] pointerIdentifiers = ev.mPointerIdentifiers; |
| 1480 | for (int i = 0; i < NP; i++) { |
| 1481 | pointerIdentifiers[i] = in.readInt(); |
| 1482 | } |
| 1483 | |
| 1484 | final long[] eventTimeNanoSamples = ev.mEventTimeNanoSamples; |
| 1485 | for (int i = 0; i < NS; i++) { |
| 1486 | eventTimeNanoSamples[i] = in.readLong(); |
| 1487 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1488 | |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 1489 | final float[] dataSamples = ev.mDataSamples; |
| 1490 | for (int i = 0; i < NI; i++) { |
| 1491 | dataSamples[i] = in.readFloat(); |
| 1492 | } |
| 1493 | |
| 1494 | ev.mLastEventTimeNanoSampleIndex = NS - 1; |
| 1495 | ev.mLastDataSampleIndex = (NS - 1) * NP * NUM_SAMPLE_DATA; |
| 1496 | return ev; |
| 1497 | } |
| 1498 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1499 | public void writeToParcel(Parcel out, int flags) { |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 1500 | out.writeInt(PARCEL_TOKEN_MOTION_EVENT); |
| 1501 | |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1502 | final int NP = mNumPointers; |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1503 | final int NS = mNumSamples; |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1504 | final int NI = NP * NS * NUM_SAMPLE_DATA; |
| 1505 | |
| 1506 | out.writeInt(NP); |
Dianne Hackborn | 9822d2b | 2009-07-20 17:33:15 -0700 | [diff] [blame] | 1507 | out.writeInt(NS); |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1508 | |
Jeff Brown | 6ec402b | 2010-07-28 15:48:59 -0700 | [diff] [blame] | 1509 | writeBaseToParcel(out); |
| 1510 | |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1511 | out.writeLong(mDownTimeNano); |
| 1512 | out.writeInt(mAction); |
| 1513 | out.writeFloat(mXOffset); |
| 1514 | out.writeFloat(mYOffset); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1515 | out.writeFloat(mXPrecision); |
| 1516 | out.writeFloat(mYPrecision); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1517 | out.writeInt(mEdgeFlags); |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1518 | out.writeInt(mMetaState); |
| 1519 | |
| 1520 | final int[] pointerIdentifiers = mPointerIdentifiers; |
| 1521 | for (int i = 0; i < NP; i++) { |
| 1522 | out.writeInt(pointerIdentifiers[i]); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1523 | } |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1524 | |
| 1525 | final long[] eventTimeNanoSamples = mEventTimeNanoSamples; |
| 1526 | for (int i = 0; i < NS; i++) { |
| 1527 | out.writeLong(eventTimeNanoSamples[i]); |
| 1528 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1529 | |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 1530 | final float[] dataSamples = mDataSamples; |
| 1531 | for (int i = 0; i < NI; i++) { |
| 1532 | out.writeFloat(dataSamples[i]); |
| 1533 | } |
| 1534 | } |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1535 | |
| 1536 | /** |
| 1537 | * Transfer object for pointer coordinates. |
| 1538 | * |
| 1539 | * Objects of this type can be used to manufacture new {@link MotionEvent} objects |
| 1540 | * and to query pointer coordinate information in bulk. |
| 1541 | * |
| 1542 | * Refer to {@link InputDevice} for information about how different kinds of |
| 1543 | * input devices and sources represent pointer coordinates. |
| 1544 | */ |
| 1545 | public static final class PointerCoords { |
| 1546 | /** |
| 1547 | * The X coordinate of the pointer movement. |
| 1548 | * The interpretation varies by input source and may represent the position of |
| 1549 | * the center of the contact area, a relative displacement in device-specific units |
| 1550 | * or something else. |
| 1551 | */ |
| 1552 | public float x; |
| 1553 | |
| 1554 | /** |
| 1555 | * The Y coordinate of the pointer movement. |
| 1556 | * The interpretation varies by input source and may represent the position of |
| 1557 | * the center of the contact area, a relative displacement in device-specific units |
| 1558 | * or something else. |
| 1559 | */ |
| 1560 | public float y; |
| 1561 | |
| 1562 | /** |
| 1563 | * A scaled value that describes the pressure applied to the pointer. |
| 1564 | * The pressure generally ranges from 0 (no pressure at all) to 1 (normal pressure), |
| 1565 | * however values higher than 1 may be generated depending on the calibration of |
| 1566 | * the input device. |
| 1567 | */ |
| 1568 | public float pressure; |
| 1569 | |
| 1570 | /** |
| 1571 | * A scaled value of the approximate size of the pointer touch area. |
| 1572 | * This represents some approximation of the area of the screen being |
| 1573 | * pressed; the actual value in pixels corresponding to the |
| 1574 | * touch is normalized with the device specific range of values |
| 1575 | * and scaled to a value between 0 and 1. The value of size can be used to |
| 1576 | * determine fat touch events. |
| 1577 | */ |
| 1578 | public float size; |
| 1579 | |
| 1580 | /** |
| 1581 | * The length of the major axis of an ellipse that describes the touch area at |
| 1582 | * the point of contact. |
| 1583 | */ |
| 1584 | public float touchMajor; |
| 1585 | |
| 1586 | /** |
| 1587 | * The length of the minor axis of an ellipse that describes the touch area at |
| 1588 | * the point of contact. |
| 1589 | */ |
| 1590 | public float touchMinor; |
| 1591 | |
| 1592 | /** |
| 1593 | * The length of the major axis of an ellipse that describes the size of |
| 1594 | * the approaching tool. |
| 1595 | * The tool area represents the estimated size of the finger or pen that is |
| 1596 | * touching the device independent of its actual touch area at the point of contact. |
| 1597 | */ |
| 1598 | public float toolMajor; |
| 1599 | |
| 1600 | /** |
| 1601 | * The length of the minor axis of an ellipse that describes the size of |
| 1602 | * the approaching tool. |
| 1603 | * The tool area represents the estimated size of the finger or pen that is |
| 1604 | * touching the device independent of its actual touch area at the point of contact. |
| 1605 | */ |
| 1606 | public float toolMinor; |
| 1607 | |
| 1608 | /** |
| 1609 | * The orientation of the touch area and tool area in radians clockwise from vertical. |
| 1610 | * An angle of 0 degrees indicates that the major axis of contact is oriented |
| 1611 | * upwards, is perfectly circular or is of unknown orientation. A positive angle |
| 1612 | * indicates that the major axis of contact is oriented to the right. A negative angle |
| 1613 | * indicates that the major axis of contact is oriented to the left. |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1614 | * 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] | 1615 | * (finger pointing fully right). |
| 1616 | */ |
| 1617 | public float orientation; |
| 1618 | |
| 1619 | /* |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1620 | private static final float PI_4 = (float) (Math.PI / 4); |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1621 | |
| 1622 | public float getTouchWidth() { |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1623 | return Math.abs(orientation) > PI_4 ? touchMajor : touchMinor; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1624 | } |
| 1625 | |
| 1626 | public float getTouchHeight() { |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1627 | return Math.abs(orientation) > PI_4 ? touchMinor : touchMajor; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1628 | } |
| 1629 | |
| 1630 | public float getToolWidth() { |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1631 | return Math.abs(orientation) > PI_4 ? toolMajor : toolMinor; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1632 | } |
| 1633 | |
| 1634 | public float getToolHeight() { |
Jeff Brown | 6d0fec2 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 1635 | return Math.abs(orientation) > PI_4 ? toolMinor : toolMajor; |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 1636 | } |
| 1637 | */ |
| 1638 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1639 | } |