1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/widget/gonk/libui/Input.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,622 @@ 1.4 +/* 1.5 + * Copyright (C) 2010 The Android Open Source Project 1.6 + * 1.7 + * Licensed under the Apache License, Version 2.0 (the "License"); 1.8 + * you may not use this file except in compliance with the License. 1.9 + * You may obtain a copy of the License at 1.10 + * 1.11 + * http://www.apache.org/licenses/LICENSE-2.0 1.12 + * 1.13 + * Unless required by applicable law or agreed to in writing, software 1.14 + * distributed under the License is distributed on an "AS IS" BASIS, 1.15 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1.16 + * See the License for the specific language governing permissions and 1.17 + * limitations under the License. 1.18 + */ 1.19 + 1.20 +#ifndef _ANDROIDFW_INPUT_H 1.21 +#define _ANDROIDFW_INPUT_H 1.22 + 1.23 +/** 1.24 + * Native input event structures. 1.25 + */ 1.26 + 1.27 +#include "android_input.h" 1.28 +#include <utils/Vector.h> 1.29 +#include <utils/KeyedVector.h> 1.30 +#include <utils/Timers.h> 1.31 +#include <utils/RefBase.h> 1.32 +#include <utils/String8.h> 1.33 + 1.34 +#ifdef HAVE_ANDROID_OS 1.35 +class SkMatrix; 1.36 +#endif 1.37 + 1.38 +/* 1.39 + * Additional private constants not defined in ndk/ui/input.h. 1.40 + */ 1.41 +enum { 1.42 + /* Signifies that the key is being predispatched */ 1.43 + AKEY_EVENT_FLAG_PREDISPATCH = 0x20000000, 1.44 + 1.45 + /* Private control to determine when an app is tracking a key sequence. */ 1.46 + AKEY_EVENT_FLAG_START_TRACKING = 0x40000000, 1.47 + 1.48 + /* Key event is inconsistent with previously sent key events. */ 1.49 + AKEY_EVENT_FLAG_TAINTED = 0x80000000, 1.50 +}; 1.51 + 1.52 +enum { 1.53 + /* Motion event is inconsistent with previously sent motion events. */ 1.54 + AMOTION_EVENT_FLAG_TAINTED = 0x80000000, 1.55 +}; 1.56 + 1.57 +enum { 1.58 + /* Used when a motion event is not associated with any display. 1.59 + * Typically used for non-pointer events. */ 1.60 + ADISPLAY_ID_NONE = -1, 1.61 + 1.62 + /* The default display id. */ 1.63 + ADISPLAY_ID_DEFAULT = 0, 1.64 +}; 1.65 + 1.66 +enum { 1.67 + /* 1.68 + * Indicates that an input device has switches. 1.69 + * This input source flag is hidden from the API because switches are only used by the system 1.70 + * and applications have no way to interact with them. 1.71 + */ 1.72 + AINPUT_SOURCE_SWITCH = 0x80000000, 1.73 +}; 1.74 + 1.75 +/* 1.76 + * SystemUiVisibility constants from View. 1.77 + */ 1.78 +enum { 1.79 + ASYSTEM_UI_VISIBILITY_STATUS_BAR_VISIBLE = 0, 1.80 + ASYSTEM_UI_VISIBILITY_STATUS_BAR_HIDDEN = 0x00000001, 1.81 +}; 1.82 + 1.83 +/* 1.84 + * Maximum number of pointers supported per motion event. 1.85 + * Smallest number of pointers is 1. 1.86 + * (We want at least 10 but some touch controllers obstensibly configured for 10 pointers 1.87 + * will occasionally emit 11. There is not much harm making this constant bigger.) 1.88 + */ 1.89 +#define MAX_POINTERS 16 1.90 + 1.91 +/* 1.92 + * Maximum pointer id value supported in a motion event. 1.93 + * Smallest pointer id is 0. 1.94 + * (This is limited by our use of BitSet32 to track pointer assignments.) 1.95 + */ 1.96 +#define MAX_POINTER_ID 31 1.97 + 1.98 +/* 1.99 + * Declare a concrete type for the NDK's input event forward declaration. 1.100 + */ 1.101 +struct AInputEvent { 1.102 + virtual ~AInputEvent() { } 1.103 +}; 1.104 + 1.105 +/* 1.106 + * Declare a concrete type for the NDK's input device forward declaration. 1.107 + */ 1.108 +struct AInputDevice { 1.109 + virtual ~AInputDevice() { } 1.110 +}; 1.111 + 1.112 + 1.113 +namespace android { 1.114 + 1.115 +#ifdef HAVE_ANDROID_OS 1.116 +class Parcel; 1.117 +#endif 1.118 + 1.119 +/* 1.120 + * Flags that flow alongside events in the input dispatch system to help with certain 1.121 + * policy decisions such as waking from device sleep. 1.122 + * 1.123 + * These flags are also defined in frameworks/base/core/java/android/view/WindowManagerPolicy.java. 1.124 + */ 1.125 +enum { 1.126 + /* These flags originate in RawEvents and are generally set in the key map. 1.127 + * NOTE: If you edit these flags, also edit labels in KeycodeLabels.h. */ 1.128 + 1.129 + POLICY_FLAG_WAKE = 0x00000001, 1.130 + POLICY_FLAG_WAKE_DROPPED = 0x00000002, 1.131 + POLICY_FLAG_SHIFT = 0x00000004, 1.132 + POLICY_FLAG_CAPS_LOCK = 0x00000008, 1.133 + POLICY_FLAG_ALT = 0x00000010, 1.134 + POLICY_FLAG_ALT_GR = 0x00000020, 1.135 + POLICY_FLAG_MENU = 0x00000040, 1.136 + POLICY_FLAG_LAUNCHER = 0x00000080, 1.137 + POLICY_FLAG_VIRTUAL = 0x00000100, 1.138 + POLICY_FLAG_FUNCTION = 0x00000200, 1.139 + 1.140 + POLICY_FLAG_RAW_MASK = 0x0000ffff, 1.141 + 1.142 + /* These flags are set by the input dispatcher. */ 1.143 + 1.144 + // Indicates that the input event was injected. 1.145 + POLICY_FLAG_INJECTED = 0x01000000, 1.146 + 1.147 + // Indicates that the input event is from a trusted source such as a directly attached 1.148 + // input device or an application with system-wide event injection permission. 1.149 + POLICY_FLAG_TRUSTED = 0x02000000, 1.150 + 1.151 + // Indicates that the input event has passed through an input filter. 1.152 + POLICY_FLAG_FILTERED = 0x04000000, 1.153 + 1.154 + // Disables automatic key repeating behavior. 1.155 + POLICY_FLAG_DISABLE_KEY_REPEAT = 0x08000000, 1.156 + 1.157 + /* These flags are set by the input reader policy as it intercepts each event. */ 1.158 + 1.159 + // Indicates that the screen was off when the event was received and the event 1.160 + // should wake the device. 1.161 + POLICY_FLAG_WOKE_HERE = 0x10000000, 1.162 + 1.163 + // Indicates that the screen was dim when the event was received and the event 1.164 + // should brighten the device. 1.165 + POLICY_FLAG_BRIGHT_HERE = 0x20000000, 1.166 + 1.167 + // Indicates that the event should be dispatched to applications. 1.168 + // The input event should still be sent to the InputDispatcher so that it can see all 1.169 + // input events received include those that it will not deliver. 1.170 + POLICY_FLAG_PASS_TO_USER = 0x40000000, 1.171 +}; 1.172 + 1.173 +/* 1.174 + * Pointer coordinate data. 1.175 + */ 1.176 +struct PointerCoords { 1.177 + enum { MAX_AXES = 14 }; // 14 so that sizeof(PointerCoords) == 64 1.178 + 1.179 + // Bitfield of axes that are present in this structure. 1.180 + uint64_t bits; 1.181 + 1.182 + // Values of axes that are stored in this structure packed in order by axis id 1.183 + // for each axis that is present in the structure according to 'bits'. 1.184 + float values[MAX_AXES]; 1.185 + 1.186 + inline void clear() { 1.187 + bits = 0; 1.188 + } 1.189 + 1.190 + float getAxisValue(int32_t axis) const; 1.191 + status_t setAxisValue(int32_t axis, float value); 1.192 + 1.193 + void scale(float scale); 1.194 + 1.195 + inline float getX() const { 1.196 + return getAxisValue(AMOTION_EVENT_AXIS_X); 1.197 + } 1.198 + 1.199 + inline float getY() const { 1.200 + return getAxisValue(AMOTION_EVENT_AXIS_Y); 1.201 + } 1.202 + 1.203 +#ifdef HAVE_ANDROID_OS 1.204 + status_t readFromParcel(Parcel* parcel); 1.205 + status_t writeToParcel(Parcel* parcel) const; 1.206 +#endif 1.207 + 1.208 + bool operator==(const PointerCoords& other) const; 1.209 + inline bool operator!=(const PointerCoords& other) const { 1.210 + return !(*this == other); 1.211 + } 1.212 + 1.213 + void copyFrom(const PointerCoords& other); 1.214 + 1.215 +private: 1.216 + void tooManyAxes(int axis); 1.217 +}; 1.218 + 1.219 +/* 1.220 + * Pointer property data. 1.221 + */ 1.222 +struct PointerProperties { 1.223 + // The id of the pointer. 1.224 + int32_t id; 1.225 + 1.226 + // The pointer tool type. 1.227 + int32_t toolType; 1.228 + 1.229 + inline void clear() { 1.230 + id = -1; 1.231 + toolType = 0; 1.232 + } 1.233 + 1.234 + bool operator==(const PointerProperties& other) const; 1.235 + inline bool operator!=(const PointerProperties& other) const { 1.236 + return !(*this == other); 1.237 + } 1.238 + 1.239 + void copyFrom(const PointerProperties& other); 1.240 +}; 1.241 + 1.242 +/* 1.243 + * Input events. 1.244 + */ 1.245 +class InputEvent : public AInputEvent { 1.246 +public: 1.247 + virtual ~InputEvent() { } 1.248 + 1.249 + virtual int32_t getType() const = 0; 1.250 + 1.251 + inline int32_t getDeviceId() const { return mDeviceId; } 1.252 + 1.253 + inline int32_t getSource() const { return mSource; } 1.254 + 1.255 + inline void setSource(int32_t source) { mSource = source; } 1.256 + 1.257 +protected: 1.258 + void initialize(int32_t deviceId, int32_t source); 1.259 + void initialize(const InputEvent& from); 1.260 + 1.261 + int32_t mDeviceId; 1.262 + int32_t mSource; 1.263 +}; 1.264 + 1.265 +/* 1.266 + * Key events. 1.267 + */ 1.268 +class KeyEvent : public InputEvent { 1.269 +public: 1.270 + virtual ~KeyEvent() { } 1.271 + 1.272 + virtual int32_t getType() const { return AINPUT_EVENT_TYPE_KEY; } 1.273 + 1.274 + inline int32_t getAction() const { return mAction; } 1.275 + 1.276 + inline int32_t getFlags() const { return mFlags; } 1.277 + 1.278 + inline void setFlags(int32_t flags) { mFlags = flags; } 1.279 + 1.280 + inline int32_t getKeyCode() const { return mKeyCode; } 1.281 + 1.282 + inline int32_t getScanCode() const { return mScanCode; } 1.283 + 1.284 + inline int32_t getMetaState() const { return mMetaState; } 1.285 + 1.286 + inline int32_t getRepeatCount() const { return mRepeatCount; } 1.287 + 1.288 + inline nsecs_t getDownTime() const { return mDownTime; } 1.289 + 1.290 + inline nsecs_t getEventTime() const { return mEventTime; } 1.291 + 1.292 + // Return true if this event may have a default action implementation. 1.293 + static bool hasDefaultAction(int32_t keyCode); 1.294 + bool hasDefaultAction() const; 1.295 + 1.296 + // Return true if this event represents a system key. 1.297 + static bool isSystemKey(int32_t keyCode); 1.298 + bool isSystemKey() const; 1.299 + 1.300 + void initialize( 1.301 + int32_t deviceId, 1.302 + int32_t source, 1.303 + int32_t action, 1.304 + int32_t flags, 1.305 + int32_t keyCode, 1.306 + int32_t scanCode, 1.307 + int32_t metaState, 1.308 + int32_t repeatCount, 1.309 + nsecs_t downTime, 1.310 + nsecs_t eventTime); 1.311 + void initialize(const KeyEvent& from); 1.312 + 1.313 +protected: 1.314 + int32_t mAction; 1.315 + int32_t mFlags; 1.316 + int32_t mKeyCode; 1.317 + int32_t mScanCode; 1.318 + int32_t mMetaState; 1.319 + int32_t mRepeatCount; 1.320 + nsecs_t mDownTime; 1.321 + nsecs_t mEventTime; 1.322 +}; 1.323 + 1.324 +/* 1.325 + * Motion events. 1.326 + */ 1.327 +class MotionEvent : public InputEvent { 1.328 +public: 1.329 + virtual ~MotionEvent() { } 1.330 + 1.331 + virtual int32_t getType() const { return AINPUT_EVENT_TYPE_MOTION; } 1.332 + 1.333 + inline int32_t getAction() const { return mAction; } 1.334 + 1.335 + inline int32_t getActionMasked() const { return mAction & AMOTION_EVENT_ACTION_MASK; } 1.336 + 1.337 + inline int32_t getActionIndex() const { 1.338 + return (mAction & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) 1.339 + >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT; 1.340 + } 1.341 + 1.342 + inline void setAction(int32_t action) { mAction = action; } 1.343 + 1.344 + inline int32_t getFlags() const { return mFlags; } 1.345 + 1.346 + inline void setFlags(int32_t flags) { mFlags = flags; } 1.347 + 1.348 + inline int32_t getEdgeFlags() const { return mEdgeFlags; } 1.349 + 1.350 + inline void setEdgeFlags(int32_t edgeFlags) { mEdgeFlags = edgeFlags; } 1.351 + 1.352 + inline int32_t getMetaState() const { return mMetaState; } 1.353 + 1.354 + inline void setMetaState(int32_t metaState) { mMetaState = metaState; } 1.355 + 1.356 + inline int32_t getButtonState() const { return mButtonState; } 1.357 + 1.358 + inline float getXOffset() const { return mXOffset; } 1.359 + 1.360 + inline float getYOffset() const { return mYOffset; } 1.361 + 1.362 + inline float getXPrecision() const { return mXPrecision; } 1.363 + 1.364 + inline float getYPrecision() const { return mYPrecision; } 1.365 + 1.366 + inline nsecs_t getDownTime() const { return mDownTime; } 1.367 + 1.368 + inline void setDownTime(nsecs_t downTime) { mDownTime = downTime; } 1.369 + 1.370 + inline size_t getPointerCount() const { return mPointerProperties.size(); } 1.371 + 1.372 + inline const PointerProperties* getPointerProperties(size_t pointerIndex) const { 1.373 + return &mPointerProperties[pointerIndex]; 1.374 + } 1.375 + 1.376 + inline int32_t getPointerId(size_t pointerIndex) const { 1.377 + return mPointerProperties[pointerIndex].id; 1.378 + } 1.379 + 1.380 + inline int32_t getToolType(size_t pointerIndex) const { 1.381 + return mPointerProperties[pointerIndex].toolType; 1.382 + } 1.383 + 1.384 + inline nsecs_t getEventTime() const { return mSampleEventTimes[getHistorySize()]; } 1.385 + 1.386 + const PointerCoords* getRawPointerCoords(size_t pointerIndex) const; 1.387 + 1.388 + float getRawAxisValue(int32_t axis, size_t pointerIndex) const; 1.389 + 1.390 + inline float getRawX(size_t pointerIndex) const { 1.391 + return getRawAxisValue(AMOTION_EVENT_AXIS_X, pointerIndex); 1.392 + } 1.393 + 1.394 + inline float getRawY(size_t pointerIndex) const { 1.395 + return getRawAxisValue(AMOTION_EVENT_AXIS_Y, pointerIndex); 1.396 + } 1.397 + 1.398 + float getAxisValue(int32_t axis, size_t pointerIndex) const; 1.399 + 1.400 + inline float getX(size_t pointerIndex) const { 1.401 + return getAxisValue(AMOTION_EVENT_AXIS_X, pointerIndex); 1.402 + } 1.403 + 1.404 + inline float getY(size_t pointerIndex) const { 1.405 + return getAxisValue(AMOTION_EVENT_AXIS_Y, pointerIndex); 1.406 + } 1.407 + 1.408 + inline float getPressure(size_t pointerIndex) const { 1.409 + return getAxisValue(AMOTION_EVENT_AXIS_PRESSURE, pointerIndex); 1.410 + } 1.411 + 1.412 + inline float getSize(size_t pointerIndex) const { 1.413 + return getAxisValue(AMOTION_EVENT_AXIS_SIZE, pointerIndex); 1.414 + } 1.415 + 1.416 + inline float getTouchMajor(size_t pointerIndex) const { 1.417 + return getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR, pointerIndex); 1.418 + } 1.419 + 1.420 + inline float getTouchMinor(size_t pointerIndex) const { 1.421 + return getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR, pointerIndex); 1.422 + } 1.423 + 1.424 + inline float getToolMajor(size_t pointerIndex) const { 1.425 + return getAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR, pointerIndex); 1.426 + } 1.427 + 1.428 + inline float getToolMinor(size_t pointerIndex) const { 1.429 + return getAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR, pointerIndex); 1.430 + } 1.431 + 1.432 + inline float getOrientation(size_t pointerIndex) const { 1.433 + return getAxisValue(AMOTION_EVENT_AXIS_ORIENTATION, pointerIndex); 1.434 + } 1.435 + 1.436 + inline size_t getHistorySize() const { return mSampleEventTimes.size() - 1; } 1.437 + 1.438 + inline nsecs_t getHistoricalEventTime(size_t historicalIndex) const { 1.439 + return mSampleEventTimes[historicalIndex]; 1.440 + } 1.441 + 1.442 + const PointerCoords* getHistoricalRawPointerCoords( 1.443 + size_t pointerIndex, size_t historicalIndex) const; 1.444 + 1.445 + float getHistoricalRawAxisValue(int32_t axis, size_t pointerIndex, 1.446 + size_t historicalIndex) const; 1.447 + 1.448 + inline float getHistoricalRawX(size_t pointerIndex, size_t historicalIndex) const { 1.449 + return getHistoricalRawAxisValue( 1.450 + AMOTION_EVENT_AXIS_X, pointerIndex, historicalIndex); 1.451 + } 1.452 + 1.453 + inline float getHistoricalRawY(size_t pointerIndex, size_t historicalIndex) const { 1.454 + return getHistoricalRawAxisValue( 1.455 + AMOTION_EVENT_AXIS_Y, pointerIndex, historicalIndex); 1.456 + } 1.457 + 1.458 + float getHistoricalAxisValue(int32_t axis, size_t pointerIndex, size_t historicalIndex) const; 1.459 + 1.460 + inline float getHistoricalX(size_t pointerIndex, size_t historicalIndex) const { 1.461 + return getHistoricalAxisValue( 1.462 + AMOTION_EVENT_AXIS_X, pointerIndex, historicalIndex); 1.463 + } 1.464 + 1.465 + inline float getHistoricalY(size_t pointerIndex, size_t historicalIndex) const { 1.466 + return getHistoricalAxisValue( 1.467 + AMOTION_EVENT_AXIS_Y, pointerIndex, historicalIndex); 1.468 + } 1.469 + 1.470 + inline float getHistoricalPressure(size_t pointerIndex, size_t historicalIndex) const { 1.471 + return getHistoricalAxisValue( 1.472 + AMOTION_EVENT_AXIS_PRESSURE, pointerIndex, historicalIndex); 1.473 + } 1.474 + 1.475 + inline float getHistoricalSize(size_t pointerIndex, size_t historicalIndex) const { 1.476 + return getHistoricalAxisValue( 1.477 + AMOTION_EVENT_AXIS_SIZE, pointerIndex, historicalIndex); 1.478 + } 1.479 + 1.480 + inline float getHistoricalTouchMajor(size_t pointerIndex, size_t historicalIndex) const { 1.481 + return getHistoricalAxisValue( 1.482 + AMOTION_EVENT_AXIS_TOUCH_MAJOR, pointerIndex, historicalIndex); 1.483 + } 1.484 + 1.485 + inline float getHistoricalTouchMinor(size_t pointerIndex, size_t historicalIndex) const { 1.486 + return getHistoricalAxisValue( 1.487 + AMOTION_EVENT_AXIS_TOUCH_MINOR, pointerIndex, historicalIndex); 1.488 + } 1.489 + 1.490 + inline float getHistoricalToolMajor(size_t pointerIndex, size_t historicalIndex) const { 1.491 + return getHistoricalAxisValue( 1.492 + AMOTION_EVENT_AXIS_TOOL_MAJOR, pointerIndex, historicalIndex); 1.493 + } 1.494 + 1.495 + inline float getHistoricalToolMinor(size_t pointerIndex, size_t historicalIndex) const { 1.496 + return getHistoricalAxisValue( 1.497 + AMOTION_EVENT_AXIS_TOOL_MINOR, pointerIndex, historicalIndex); 1.498 + } 1.499 + 1.500 + inline float getHistoricalOrientation(size_t pointerIndex, size_t historicalIndex) const { 1.501 + return getHistoricalAxisValue( 1.502 + AMOTION_EVENT_AXIS_ORIENTATION, pointerIndex, historicalIndex); 1.503 + } 1.504 + 1.505 + ssize_t findPointerIndex(int32_t pointerId) const; 1.506 + 1.507 + void initialize( 1.508 + int32_t deviceId, 1.509 + int32_t source, 1.510 + int32_t action, 1.511 + int32_t flags, 1.512 + int32_t edgeFlags, 1.513 + int32_t metaState, 1.514 + int32_t buttonState, 1.515 + float xOffset, 1.516 + float yOffset, 1.517 + float xPrecision, 1.518 + float yPrecision, 1.519 + nsecs_t downTime, 1.520 + nsecs_t eventTime, 1.521 + size_t pointerCount, 1.522 + const PointerProperties* pointerProperties, 1.523 + const PointerCoords* pointerCoords); 1.524 + 1.525 + void copyFrom(const MotionEvent* other, bool keepHistory); 1.526 + 1.527 + void addSample( 1.528 + nsecs_t eventTime, 1.529 + const PointerCoords* pointerCoords); 1.530 + 1.531 + void offsetLocation(float xOffset, float yOffset); 1.532 + 1.533 + void scale(float scaleFactor); 1.534 + 1.535 +#ifdef HAVE_ANDROID_OS 1.536 + void transform(const SkMatrix* matrix); 1.537 + 1.538 + status_t readFromParcel(Parcel* parcel); 1.539 + status_t writeToParcel(Parcel* parcel) const; 1.540 +#endif 1.541 + 1.542 + static bool isTouchEvent(int32_t source, int32_t action); 1.543 + inline bool isTouchEvent() const { 1.544 + return isTouchEvent(mSource, mAction); 1.545 + } 1.546 + 1.547 + // Low-level accessors. 1.548 + inline const PointerProperties* getPointerProperties() const { 1.549 + return mPointerProperties.array(); 1.550 + } 1.551 + inline const nsecs_t* getSampleEventTimes() const { return mSampleEventTimes.array(); } 1.552 + inline const PointerCoords* getSamplePointerCoords() const { 1.553 + return mSamplePointerCoords.array(); 1.554 + } 1.555 + 1.556 +protected: 1.557 + int32_t mAction; 1.558 + int32_t mFlags; 1.559 + int32_t mEdgeFlags; 1.560 + int32_t mMetaState; 1.561 + int32_t mButtonState; 1.562 + float mXOffset; 1.563 + float mYOffset; 1.564 + float mXPrecision; 1.565 + float mYPrecision; 1.566 + nsecs_t mDownTime; 1.567 + Vector<PointerProperties> mPointerProperties; 1.568 + Vector<nsecs_t> mSampleEventTimes; 1.569 + Vector<PointerCoords> mSamplePointerCoords; 1.570 +}; 1.571 + 1.572 +/* 1.573 + * Input event factory. 1.574 + */ 1.575 +class InputEventFactoryInterface { 1.576 +protected: 1.577 + virtual ~InputEventFactoryInterface() { } 1.578 + 1.579 +public: 1.580 + InputEventFactoryInterface() { } 1.581 + 1.582 + virtual KeyEvent* createKeyEvent() = 0; 1.583 + virtual MotionEvent* createMotionEvent() = 0; 1.584 +}; 1.585 + 1.586 +/* 1.587 + * A simple input event factory implementation that uses a single preallocated instance 1.588 + * of each type of input event that are reused for each request. 1.589 + */ 1.590 +class PreallocatedInputEventFactory : public InputEventFactoryInterface { 1.591 +public: 1.592 + PreallocatedInputEventFactory() { } 1.593 + virtual ~PreallocatedInputEventFactory() { } 1.594 + 1.595 + virtual KeyEvent* createKeyEvent() { return & mKeyEvent; } 1.596 + virtual MotionEvent* createMotionEvent() { return & mMotionEvent; } 1.597 + 1.598 +private: 1.599 + KeyEvent mKeyEvent; 1.600 + MotionEvent mMotionEvent; 1.601 +}; 1.602 + 1.603 +/* 1.604 + * An input event factory implementation that maintains a pool of input events. 1.605 + */ 1.606 +class PooledInputEventFactory : public InputEventFactoryInterface { 1.607 +public: 1.608 + PooledInputEventFactory(size_t maxPoolSize = 20); 1.609 + virtual ~PooledInputEventFactory(); 1.610 + 1.611 + virtual KeyEvent* createKeyEvent(); 1.612 + virtual MotionEvent* createMotionEvent(); 1.613 + 1.614 + void recycle(InputEvent* event); 1.615 + 1.616 +private: 1.617 + const size_t mMaxPoolSize; 1.618 + 1.619 + Vector<KeyEvent*> mKeyEventPool; 1.620 + Vector<MotionEvent*> mMotionEventPool; 1.621 +}; 1.622 + 1.623 +} // namespace android 1.624 + 1.625 +#endif // _ANDROIDFW_INPUT_H