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