Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 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 | #ifndef _UI_INPUT_H |
| 18 | #define _UI_INPUT_H |
| 19 | |
| 20 | /** |
| 21 | * Native input event structures. |
| 22 | */ |
| 23 | |
| 24 | #include <android/input.h> |
| 25 | #include <utils/Vector.h> |
Jeff Brown | e57e895 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 26 | #include <utils/KeyedVector.h> |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 27 | #include <utils/Timers.h> |
Jeff Brown | e57e895 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 28 | #include <utils/RefBase.h> |
| 29 | #include <utils/String8.h> |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 30 | |
| 31 | /* |
| 32 | * Additional private constants not defined in ndk/ui/input.h. |
| 33 | */ |
| 34 | enum { |
| 35 | /* |
| 36 | * Private control to determine when an app is tracking a key sequence. |
| 37 | */ |
Jeff Brown | 5c1ed84 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 38 | AKEY_EVENT_FLAG_START_TRACKING = 0x40000000 |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 39 | }; |
| 40 | |
Jeff Brown | cb203b2 | 2011-01-19 20:35:47 -0800 | [diff] [blame] | 41 | enum { |
| 42 | /* |
| 43 | * Indicates that an input device has switches. |
| 44 | * This input source flag is hidden from the API because switches are only used by the system |
| 45 | * and applications have no way to interact with them. |
| 46 | */ |
| 47 | AINPUT_SOURCE_SWITCH = 0x80000000, |
| 48 | }; |
| 49 | |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 50 | /* |
| 51 | * Maximum number of pointers supported per motion event. |
Jeff Brown | d1b0a2b | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 52 | * Smallest number of pointers is 1. |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 53 | */ |
| 54 | #define MAX_POINTERS 10 |
| 55 | |
Dianne Hackborn | 4d96bb6 | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 56 | /* |
Jeff Brown | d1b0a2b | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 57 | * Maximum pointer id value supported in a motion event. |
| 58 | * Smallest pointer id is 0. |
| 59 | * (This is limited by our use of BitSet32 to track pointer assignments.) |
| 60 | */ |
| 61 | #define MAX_POINTER_ID 31 |
| 62 | |
| 63 | /* |
Dianne Hackborn | 4d96bb6 | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 64 | * Declare a concrete type for the NDK's input event forward declaration. |
| 65 | */ |
Dianne Hackborn | ce838a2 | 2010-07-13 17:48:30 -0700 | [diff] [blame] | 66 | struct AInputEvent { |
| 67 | virtual ~AInputEvent() { } |
| 68 | }; |
Dianne Hackborn | 4d96bb6 | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 69 | |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 70 | /* |
Jeff Brown | e57e895 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 71 | * Declare a concrete type for the NDK's input device forward declaration. |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 72 | */ |
Jeff Brown | e57e895 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 73 | struct AInputDevice { |
| 74 | virtual ~AInputDevice() { } |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 75 | }; |
| 76 | |
Jeff Brown | e57e895 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 77 | |
| 78 | namespace android { |
| 79 | |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 80 | /* |
| 81 | * Flags that flow alongside events in the input dispatch system to help with certain |
| 82 | * policy decisions such as waking from device sleep. |
Jeff Brown | 90f0cee | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 83 | * |
| 84 | * These flags are also defined in frameworks/base/core/java/android/view/WindowManagerPolicy.java. |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 85 | */ |
| 86 | enum { |
Jeff Brown | 956c0fb | 2010-10-01 14:55:30 -0700 | [diff] [blame] | 87 | /* These flags originate in RawEvents and are generally set in the key map. |
| 88 | * See also labels for policy flags in KeycodeLabels.h. */ |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 89 | |
| 90 | POLICY_FLAG_WAKE = 0x00000001, |
| 91 | POLICY_FLAG_WAKE_DROPPED = 0x00000002, |
| 92 | POLICY_FLAG_SHIFT = 0x00000004, |
| 93 | POLICY_FLAG_CAPS_LOCK = 0x00000008, |
| 94 | POLICY_FLAG_ALT = 0x00000010, |
| 95 | POLICY_FLAG_ALT_GR = 0x00000020, |
| 96 | POLICY_FLAG_MENU = 0x00000040, |
| 97 | POLICY_FLAG_LAUNCHER = 0x00000080, |
Jeff Brown | 956c0fb | 2010-10-01 14:55:30 -0700 | [diff] [blame] | 98 | POLICY_FLAG_VIRTUAL = 0x00000100, |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 99 | |
Jeff Brown | 51d45a7 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 100 | POLICY_FLAG_RAW_MASK = 0x0000ffff, |
| 101 | |
Jeff Brown | af30ff6 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 102 | /* These flags are set by the input dispatcher. */ |
| 103 | |
| 104 | // Indicates that the input event was injected. |
| 105 | POLICY_FLAG_INJECTED = 0x01000000, |
| 106 | |
Jeff Brown | 1fe6dec | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 107 | // Indicates that the input event is from a trusted source such as a directly attached |
| 108 | // input device or an application with system-wide event injection permission. |
| 109 | POLICY_FLAG_TRUSTED = 0x02000000, |
| 110 | |
Jeff Brown | 54bc281 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 111 | /* These flags are set by the input reader policy as it intercepts each event. */ |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 112 | |
| 113 | // Indicates that the screen was off when the event was received and the event |
| 114 | // should wake the device. |
| 115 | POLICY_FLAG_WOKE_HERE = 0x10000000, |
| 116 | |
| 117 | // Indicates that the screen was dim when the event was received and the event |
| 118 | // should brighten the device. |
| 119 | POLICY_FLAG_BRIGHT_HERE = 0x20000000, |
Jeff Brown | 90f0cee | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 120 | |
| 121 | // Indicates that the event should be dispatched to applications. |
| 122 | // The input event should still be sent to the InputDispatcher so that it can see all |
| 123 | // input events received include those that it will not deliver. |
| 124 | POLICY_FLAG_PASS_TO_USER = 0x40000000, |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 125 | }; |
| 126 | |
| 127 | /* |
Jeff Brown | 54bc281 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 128 | * Describes the basic configuration of input devices that are present. |
| 129 | */ |
| 130 | struct InputConfiguration { |
| 131 | enum { |
| 132 | TOUCHSCREEN_UNDEFINED = 0, |
| 133 | TOUCHSCREEN_NOTOUCH = 1, |
| 134 | TOUCHSCREEN_STYLUS = 2, |
| 135 | TOUCHSCREEN_FINGER = 3 |
| 136 | }; |
| 137 | |
| 138 | enum { |
| 139 | KEYBOARD_UNDEFINED = 0, |
| 140 | KEYBOARD_NOKEYS = 1, |
| 141 | KEYBOARD_QWERTY = 2, |
| 142 | KEYBOARD_12KEY = 3 |
| 143 | }; |
| 144 | |
| 145 | enum { |
| 146 | NAVIGATION_UNDEFINED = 0, |
| 147 | NAVIGATION_NONAV = 1, |
| 148 | NAVIGATION_DPAD = 2, |
| 149 | NAVIGATION_TRACKBALL = 3, |
| 150 | NAVIGATION_WHEEL = 4 |
| 151 | }; |
| 152 | |
| 153 | int32_t touchScreen; |
| 154 | int32_t keyboard; |
| 155 | int32_t navigation; |
| 156 | }; |
| 157 | |
| 158 | /* |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 159 | * Pointer coordinate data. |
| 160 | */ |
| 161 | struct PointerCoords { |
| 162 | float x; |
| 163 | float y; |
| 164 | float pressure; |
| 165 | float size; |
Jeff Brown | 5c1ed84 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 166 | float touchMajor; |
| 167 | float touchMinor; |
| 168 | float toolMajor; |
| 169 | float toolMinor; |
| 170 | float orientation; |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 171 | }; |
| 172 | |
| 173 | /* |
| 174 | * Input events. |
| 175 | */ |
Dianne Hackborn | 9c7f818 | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 176 | class InputEvent : public AInputEvent { |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 177 | public: |
| 178 | virtual ~InputEvent() { } |
| 179 | |
| 180 | virtual int32_t getType() const = 0; |
| 181 | |
| 182 | inline int32_t getDeviceId() const { return mDeviceId; } |
| 183 | |
Jeff Brown | 5c1ed84 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 184 | inline int32_t getSource() const { return mSource; } |
Dianne Hackborn | 189ed23 | 2010-06-29 19:20:40 -0700 | [diff] [blame] | 185 | |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 186 | protected: |
Jeff Brown | 5c1ed84 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 187 | void initialize(int32_t deviceId, int32_t source); |
Dianne Hackborn | 0e88527 | 2010-07-15 17:44:53 -0700 | [diff] [blame] | 188 | void initialize(const InputEvent& from); |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 189 | |
| 190 | private: |
| 191 | int32_t mDeviceId; |
Jeff Brown | 5c1ed84 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 192 | int32_t mSource; |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 193 | }; |
| 194 | |
Jeff Brown | f4a4ec2 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 195 | /* |
| 196 | * Key events. |
| 197 | */ |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 198 | class KeyEvent : public InputEvent { |
| 199 | public: |
| 200 | virtual ~KeyEvent() { } |
| 201 | |
Jeff Brown | 5c1ed84 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 202 | virtual int32_t getType() const { return AINPUT_EVENT_TYPE_KEY; } |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 203 | |
| 204 | inline int32_t getAction() const { return mAction; } |
| 205 | |
| 206 | inline int32_t getFlags() const { return mFlags; } |
| 207 | |
| 208 | inline int32_t getKeyCode() const { return mKeyCode; } |
| 209 | |
| 210 | inline int32_t getScanCode() const { return mScanCode; } |
| 211 | |
| 212 | inline int32_t getMetaState() const { return mMetaState; } |
| 213 | |
| 214 | inline int32_t getRepeatCount() const { return mRepeatCount; } |
| 215 | |
| 216 | inline nsecs_t getDownTime() const { return mDownTime; } |
| 217 | |
| 218 | inline nsecs_t getEventTime() const { return mEventTime; } |
| 219 | |
Dianne Hackborn | 189ed23 | 2010-06-29 19:20:40 -0700 | [diff] [blame] | 220 | // Return true if this event may have a default action implementation. |
| 221 | static bool hasDefaultAction(int32_t keyCode); |
| 222 | bool hasDefaultAction() const; |
| 223 | |
| 224 | // Return true if this event represents a system key. |
| 225 | static bool isSystemKey(int32_t keyCode); |
| 226 | bool isSystemKey() const; |
| 227 | |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 228 | void initialize( |
| 229 | int32_t deviceId, |
Jeff Brown | 5c1ed84 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 230 | int32_t source, |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 231 | int32_t action, |
| 232 | int32_t flags, |
| 233 | int32_t keyCode, |
| 234 | int32_t scanCode, |
| 235 | int32_t metaState, |
| 236 | int32_t repeatCount, |
| 237 | nsecs_t downTime, |
| 238 | nsecs_t eventTime); |
Dianne Hackborn | 0e88527 | 2010-07-15 17:44:53 -0700 | [diff] [blame] | 239 | void initialize(const KeyEvent& from); |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 240 | |
| 241 | private: |
| 242 | int32_t mAction; |
| 243 | int32_t mFlags; |
| 244 | int32_t mKeyCode; |
| 245 | int32_t mScanCode; |
| 246 | int32_t mMetaState; |
| 247 | int32_t mRepeatCount; |
| 248 | nsecs_t mDownTime; |
| 249 | nsecs_t mEventTime; |
| 250 | }; |
| 251 | |
Jeff Brown | f4a4ec2 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 252 | /* |
| 253 | * Motion events. |
| 254 | */ |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 255 | class MotionEvent : public InputEvent { |
| 256 | public: |
| 257 | virtual ~MotionEvent() { } |
| 258 | |
Jeff Brown | 5c1ed84 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 259 | virtual int32_t getType() const { return AINPUT_EVENT_TYPE_MOTION; } |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 260 | |
| 261 | inline int32_t getAction() const { return mAction; } |
| 262 | |
Jeff Brown | af30ff6 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 263 | inline int32_t getFlags() const { return mFlags; } |
| 264 | |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 265 | inline int32_t getEdgeFlags() const { return mEdgeFlags; } |
| 266 | |
| 267 | inline int32_t getMetaState() const { return mMetaState; } |
| 268 | |
Jeff Brown | f4a4ec2 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 269 | inline float getXOffset() const { return mXOffset; } |
| 270 | |
| 271 | inline float getYOffset() const { return mYOffset; } |
| 272 | |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 273 | inline float getXPrecision() const { return mXPrecision; } |
| 274 | |
| 275 | inline float getYPrecision() const { return mYPrecision; } |
| 276 | |
| 277 | inline nsecs_t getDownTime() const { return mDownTime; } |
| 278 | |
| 279 | inline size_t getPointerCount() const { return mPointerIds.size(); } |
| 280 | |
| 281 | inline int32_t getPointerId(size_t pointerIndex) const { return mPointerIds[pointerIndex]; } |
| 282 | |
| 283 | inline nsecs_t getEventTime() const { return mSampleEventTimes[getHistorySize()]; } |
| 284 | |
Jeff Brown | f4a4ec2 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 285 | inline float getRawX(size_t pointerIndex) const { |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 286 | return getCurrentPointerCoords(pointerIndex).x; |
| 287 | } |
| 288 | |
Jeff Brown | f4a4ec2 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 289 | inline float getRawY(size_t pointerIndex) const { |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 290 | return getCurrentPointerCoords(pointerIndex).y; |
| 291 | } |
| 292 | |
Jeff Brown | f4a4ec2 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 293 | inline float getX(size_t pointerIndex) const { |
| 294 | return getRawX(pointerIndex) + mXOffset; |
| 295 | } |
| 296 | |
| 297 | inline float getY(size_t pointerIndex) const { |
| 298 | return getRawY(pointerIndex) + mYOffset; |
| 299 | } |
| 300 | |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 301 | inline float getPressure(size_t pointerIndex) const { |
| 302 | return getCurrentPointerCoords(pointerIndex).pressure; |
| 303 | } |
| 304 | |
| 305 | inline float getSize(size_t pointerIndex) const { |
| 306 | return getCurrentPointerCoords(pointerIndex).size; |
| 307 | } |
| 308 | |
Jeff Brown | 5c1ed84 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 309 | inline float getTouchMajor(size_t pointerIndex) const { |
| 310 | return getCurrentPointerCoords(pointerIndex).touchMajor; |
| 311 | } |
| 312 | |
| 313 | inline float getTouchMinor(size_t pointerIndex) const { |
| 314 | return getCurrentPointerCoords(pointerIndex).touchMinor; |
| 315 | } |
| 316 | |
| 317 | inline float getToolMajor(size_t pointerIndex) const { |
| 318 | return getCurrentPointerCoords(pointerIndex).toolMajor; |
| 319 | } |
| 320 | |
| 321 | inline float getToolMinor(size_t pointerIndex) const { |
| 322 | return getCurrentPointerCoords(pointerIndex).toolMinor; |
| 323 | } |
| 324 | |
| 325 | inline float getOrientation(size_t pointerIndex) const { |
| 326 | return getCurrentPointerCoords(pointerIndex).orientation; |
| 327 | } |
| 328 | |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 329 | inline size_t getHistorySize() const { return mSampleEventTimes.size() - 1; } |
| 330 | |
| 331 | inline nsecs_t getHistoricalEventTime(size_t historicalIndex) const { |
| 332 | return mSampleEventTimes[historicalIndex]; |
| 333 | } |
| 334 | |
Jeff Brown | f4a4ec2 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 335 | inline float getHistoricalRawX(size_t pointerIndex, size_t historicalIndex) const { |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 336 | return getHistoricalPointerCoords(pointerIndex, historicalIndex).x; |
| 337 | } |
| 338 | |
Jeff Brown | f4a4ec2 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 339 | inline float getHistoricalRawY(size_t pointerIndex, size_t historicalIndex) const { |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 340 | return getHistoricalPointerCoords(pointerIndex, historicalIndex).y; |
| 341 | } |
| 342 | |
Jeff Brown | f4a4ec2 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 343 | inline float getHistoricalX(size_t pointerIndex, size_t historicalIndex) const { |
| 344 | return getHistoricalRawX(pointerIndex, historicalIndex) + mXOffset; |
| 345 | } |
| 346 | |
| 347 | inline float getHistoricalY(size_t pointerIndex, size_t historicalIndex) const { |
| 348 | return getHistoricalRawY(pointerIndex, historicalIndex) + mYOffset; |
| 349 | } |
| 350 | |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 351 | inline float getHistoricalPressure(size_t pointerIndex, size_t historicalIndex) const { |
| 352 | return getHistoricalPointerCoords(pointerIndex, historicalIndex).pressure; |
| 353 | } |
| 354 | |
| 355 | inline float getHistoricalSize(size_t pointerIndex, size_t historicalIndex) const { |
| 356 | return getHistoricalPointerCoords(pointerIndex, historicalIndex).size; |
| 357 | } |
| 358 | |
Jeff Brown | 5c1ed84 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 359 | inline float getHistoricalTouchMajor(size_t pointerIndex, size_t historicalIndex) const { |
| 360 | return getHistoricalPointerCoords(pointerIndex, historicalIndex).touchMajor; |
| 361 | } |
| 362 | |
| 363 | inline float getHistoricalTouchMinor(size_t pointerIndex, size_t historicalIndex) const { |
| 364 | return getHistoricalPointerCoords(pointerIndex, historicalIndex).touchMinor; |
| 365 | } |
| 366 | |
| 367 | inline float getHistoricalToolMajor(size_t pointerIndex, size_t historicalIndex) const { |
| 368 | return getHistoricalPointerCoords(pointerIndex, historicalIndex).toolMajor; |
| 369 | } |
| 370 | |
| 371 | inline float getHistoricalToolMinor(size_t pointerIndex, size_t historicalIndex) const { |
| 372 | return getHistoricalPointerCoords(pointerIndex, historicalIndex).toolMinor; |
| 373 | } |
| 374 | |
| 375 | inline float getHistoricalOrientation(size_t pointerIndex, size_t historicalIndex) const { |
| 376 | return getHistoricalPointerCoords(pointerIndex, historicalIndex).orientation; |
| 377 | } |
| 378 | |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 379 | void initialize( |
| 380 | int32_t deviceId, |
Jeff Brown | 5c1ed84 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 381 | int32_t source, |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 382 | int32_t action, |
Jeff Brown | af30ff6 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 383 | int32_t flags, |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 384 | int32_t edgeFlags, |
| 385 | int32_t metaState, |
Jeff Brown | f4a4ec2 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 386 | float xOffset, |
| 387 | float yOffset, |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 388 | float xPrecision, |
| 389 | float yPrecision, |
| 390 | nsecs_t downTime, |
| 391 | nsecs_t eventTime, |
| 392 | size_t pointerCount, |
| 393 | const int32_t* pointerIds, |
| 394 | const PointerCoords* pointerCoords); |
| 395 | |
| 396 | void addSample( |
| 397 | nsecs_t eventTime, |
| 398 | const PointerCoords* pointerCoords); |
| 399 | |
| 400 | void offsetLocation(float xOffset, float yOffset); |
| 401 | |
Jeff Brown | f4a4ec2 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 402 | // Low-level accessors. |
| 403 | inline const int32_t* getPointerIds() const { return mPointerIds.array(); } |
| 404 | inline const nsecs_t* getSampleEventTimes() const { return mSampleEventTimes.array(); } |
| 405 | inline const PointerCoords* getSamplePointerCoords() const { |
| 406 | return mSamplePointerCoords.array(); |
| 407 | } |
| 408 | |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 409 | private: |
| 410 | int32_t mAction; |
Jeff Brown | af30ff6 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 411 | int32_t mFlags; |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 412 | int32_t mEdgeFlags; |
| 413 | int32_t mMetaState; |
Jeff Brown | f4a4ec2 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 414 | float mXOffset; |
| 415 | float mYOffset; |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 416 | float mXPrecision; |
| 417 | float mYPrecision; |
| 418 | nsecs_t mDownTime; |
| 419 | Vector<int32_t> mPointerIds; |
| 420 | Vector<nsecs_t> mSampleEventTimes; |
| 421 | Vector<PointerCoords> mSamplePointerCoords; |
| 422 | |
| 423 | inline const PointerCoords& getCurrentPointerCoords(size_t pointerIndex) const { |
| 424 | return mSamplePointerCoords[getHistorySize() * getPointerCount() + pointerIndex]; |
| 425 | } |
| 426 | |
| 427 | inline const PointerCoords& getHistoricalPointerCoords( |
| 428 | size_t pointerIndex, size_t historicalIndex) const { |
| 429 | return mSamplePointerCoords[historicalIndex * getPointerCount() + pointerIndex]; |
| 430 | } |
| 431 | }; |
| 432 | |
| 433 | /* |
| 434 | * Input event factory. |
| 435 | */ |
| 436 | class InputEventFactoryInterface { |
| 437 | protected: |
| 438 | virtual ~InputEventFactoryInterface() { } |
| 439 | |
| 440 | public: |
| 441 | InputEventFactoryInterface() { } |
| 442 | |
| 443 | virtual KeyEvent* createKeyEvent() = 0; |
| 444 | virtual MotionEvent* createMotionEvent() = 0; |
| 445 | }; |
| 446 | |
| 447 | /* |
| 448 | * A simple input event factory implementation that uses a single preallocated instance |
| 449 | * of each type of input event that are reused for each request. |
| 450 | */ |
| 451 | class PreallocatedInputEventFactory : public InputEventFactoryInterface { |
| 452 | public: |
| 453 | PreallocatedInputEventFactory() { } |
| 454 | virtual ~PreallocatedInputEventFactory() { } |
| 455 | |
| 456 | virtual KeyEvent* createKeyEvent() { return & mKeyEvent; } |
| 457 | virtual MotionEvent* createMotionEvent() { return & mMotionEvent; } |
| 458 | |
| 459 | private: |
| 460 | KeyEvent mKeyEvent; |
| 461 | MotionEvent mMotionEvent; |
| 462 | }; |
| 463 | |
Jeff Brown | e57e895 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 464 | /* |
| 465 | * Describes the characteristics and capabilities of an input device. |
| 466 | */ |
| 467 | class InputDeviceInfo { |
| 468 | public: |
| 469 | InputDeviceInfo(); |
| 470 | InputDeviceInfo(const InputDeviceInfo& other); |
| 471 | ~InputDeviceInfo(); |
| 472 | |
| 473 | struct MotionRange { |
| 474 | float min; |
| 475 | float max; |
| 476 | float flat; |
| 477 | float fuzz; |
| 478 | }; |
| 479 | |
| 480 | void initialize(int32_t id, const String8& name); |
| 481 | |
| 482 | inline int32_t getId() const { return mId; } |
| 483 | inline const String8 getName() const { return mName; } |
| 484 | inline uint32_t getSources() const { return mSources; } |
| 485 | |
| 486 | const MotionRange* getMotionRange(int32_t rangeType) const; |
| 487 | |
| 488 | void addSource(uint32_t source); |
| 489 | void addMotionRange(int32_t rangeType, float min, float max, float flat, float fuzz); |
| 490 | void addMotionRange(int32_t rangeType, const MotionRange& range); |
| 491 | |
| 492 | inline void setKeyboardType(int32_t keyboardType) { mKeyboardType = keyboardType; } |
| 493 | inline int32_t getKeyboardType() const { return mKeyboardType; } |
| 494 | |
Jeff Brown | 38a7fab | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 495 | inline const KeyedVector<int32_t, MotionRange> getMotionRanges() const { |
| 496 | return mMotionRanges; |
| 497 | } |
| 498 | |
Jeff Brown | e57e895 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 499 | private: |
| 500 | int32_t mId; |
| 501 | String8 mName; |
| 502 | uint32_t mSources; |
| 503 | int32_t mKeyboardType; |
| 504 | |
| 505 | KeyedVector<int32_t, MotionRange> mMotionRanges; |
| 506 | }; |
| 507 | |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 508 | |
| 509 | } // namespace android |
| 510 | |
| 511 | #endif // _UI_INPUT_H |