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