From 9f25b7fdf216c9ef0bd2322cd223eeaf0d60f77f Mon Sep 17 00:00:00 2001 From: Jeff Brown Date: Tue, 10 Apr 2012 14:30:49 -0700 Subject: Request key maps from input manager service. Instead of each application loading the KeyCharacterMap from the file system, get them from the input manager service as part of the InputDevice object. Refactored InputManager to be a proper singleton instead of having a bunch of static methods. InputManager now maintains a cache of all InputDevice objects that it has loaded. Currently we never invalidate the cache which can cause InputDevice to return stale motion ranges if the device is reconfigured. This will be fixed in a future change. Added a fake InputDevice with ID -1 to represent the virtual keyboard. Change-Id: If7a695839ad0972317a5aab89e9d1e42ace28eb7 --- include/androidfw/KeyCharacterMap.h | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'include/androidfw/KeyCharacterMap.h') diff --git a/include/androidfw/KeyCharacterMap.h b/include/androidfw/KeyCharacterMap.h index 679dd2c04fdf..3cc1cb2a01db 100644 --- a/include/androidfw/KeyCharacterMap.h +++ b/include/androidfw/KeyCharacterMap.h @@ -19,12 +19,17 @@ #include +#if HAVE_ANDROID_OS +#include +#endif + #include #include #include #include #include #include +#include namespace android { @@ -32,8 +37,10 @@ namespace android { * Describes a mapping from Android key codes to characters. * Also specifies other functions of the keyboard such as the keyboard type * and key modifier semantics. + * + * This object is immutable after it has been loaded. */ -class KeyCharacterMap { +class KeyCharacterMap : public RefBase { public: enum KeyboardType { KEYBOARD_TYPE_UNKNOWN = 0, @@ -50,9 +57,11 @@ public: int32_t metaState; }; - ~KeyCharacterMap(); + /* Loads a key character map from a file. */ + static status_t load(const String8& filename, sp* outMap); - static status_t load(const String8& filename, KeyCharacterMap** outMap); + /* Returns an empty key character map. */ + static sp empty(); /* Gets the keyboard type. */ int32_t getKeyboardType() const; @@ -92,6 +101,17 @@ public: bool getEvents(int32_t deviceId, const char16_t* chars, size_t numChars, Vector& outEvents) const; +#if HAVE_ANDROID_OS + /* Reads a key map from a parcel. */ + static sp readFromParcel(Parcel* parcel); + + /* Writes a key map to a parcel. */ + void writeToParcel(Parcel* parcel) const; +#endif + +protected: + virtual ~KeyCharacterMap(); + private: struct Behavior { Behavior(); @@ -162,6 +182,8 @@ private: status_t parseCharacterLiteral(char16_t* outCharacter); }; + static sp sEmpty; + KeyedVector mKeys; int mType; -- cgit v1.2.3-59-g8ed1b