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