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