summaryrefslogtreecommitdiff
path: root/include/input/KeyCharacterMap.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/input/KeyCharacterMap.h')
-rw-r--r--include/input/KeyCharacterMap.h65
1 files changed, 33 insertions, 32 deletions
diff --git a/include/input/KeyCharacterMap.h b/include/input/KeyCharacterMap.h
index a1a32a63de..451ca3c6cd 100644
--- a/include/input/KeyCharacterMap.h
+++ b/include/input/KeyCharacterMap.h
@@ -19,16 +19,16 @@
#include <stdint.h>
-#ifdef __ANDROID__
+#ifdef __linux__
#include <binder/IBinder.h>
#endif
+#include <android-base/result.h>
#include <input/Input.h>
#include <utils/Errors.h>
#include <utils/KeyedVector.h>
#include <utils/Tokenizer.h>
#include <utils/Unicode.h>
-#include <utils/RefBase.h>
// Maximum number of keys supported by KeyCharacterMaps
#define MAX_KEYS 8192
@@ -42,29 +42,29 @@ namespace android {
*
* This object is immutable after it has been loaded.
*/
-class KeyCharacterMap : public RefBase {
+class KeyCharacterMap {
public:
- enum KeyboardType {
- KEYBOARD_TYPE_UNKNOWN = 0,
- KEYBOARD_TYPE_NUMERIC = 1,
- KEYBOARD_TYPE_PREDICTIVE = 2,
- KEYBOARD_TYPE_ALPHA = 3,
- KEYBOARD_TYPE_FULL = 4,
+ enum class KeyboardType : int32_t {
+ UNKNOWN = 0,
+ NUMERIC = 1,
+ PREDICTIVE = 2,
+ ALPHA = 3,
+ FULL = 4,
/**
* Deprecated. Set 'keyboard.specialFunction' to '1' in the device's IDC file instead.
*/
- KEYBOARD_TYPE_SPECIAL_FUNCTION = 5,
- KEYBOARD_TYPE_OVERLAY = 6,
+ SPECIAL_FUNCTION = 5,
+ OVERLAY = 6,
};
- enum Format {
+ enum class Format {
// Base keyboard layout, may contain device-specific options, such as "type" declaration.
- FORMAT_BASE = 0,
+ BASE = 0,
// Overlay keyboard layout, more restrictive, may be published by applications,
// cannot override device-specific options.
- FORMAT_OVERLAY = 1,
+ OVERLAY = 1,
// Either base or overlay layout ok.
- FORMAT_ANY = 2,
+ ANY = 2,
};
// Substitute key code and meta state for fallback action.
@@ -74,21 +74,21 @@ public:
};
/* Loads a key character map from a file. */
- static status_t load(const std::string& filename, Format format, sp<KeyCharacterMap>* outMap);
+ static base::Result<std::shared_ptr<KeyCharacterMap>> load(const std::string& filename,
+ Format format);
/* Loads a key character map from its string contents. */
- static status_t loadContents(const std::string& filename,
- const char* contents, Format format, sp<KeyCharacterMap>* outMap);
+ static base::Result<std::shared_ptr<KeyCharacterMap>> loadContents(const std::string& filename,
+ const char* contents,
+ Format format);
- /* Combines a base key character map and an overlay. */
- static sp<KeyCharacterMap> combine(const sp<KeyCharacterMap>& base,
- const sp<KeyCharacterMap>& overlay);
+ const std::string getLoadFileName() const;
- /* Returns an empty key character map. */
- static sp<KeyCharacterMap> empty();
+ /* Combines this key character map with an overlay. */
+ void combine(const KeyCharacterMap& overlay);
/* Gets the keyboard type. */
- int32_t getKeyboardType() const;
+ KeyboardType getKeyboardType() const;
/* Gets the primary character for this key as in the label physically printed on it.
* Returns 0 if none (eg. for non-printing keys). */
@@ -134,15 +134,18 @@ public:
void tryRemapKey(int32_t scanCode, int32_t metaState,
int32_t* outKeyCode, int32_t* outMetaState) const;
-#ifdef __ANDROID__
+#ifdef __linux__
/* Reads a key map from a parcel. */
- static sp<KeyCharacterMap> readFromParcel(Parcel* parcel);
+ static std::shared_ptr<KeyCharacterMap> readFromParcel(Parcel* parcel);
/* Writes a key map to a parcel. */
void writeToParcel(Parcel* parcel) const;
#endif
-protected:
+ bool operator==(const KeyCharacterMap& other) const;
+
+ KeyCharacterMap(const KeyCharacterMap& other);
+
virtual ~KeyCharacterMap();
private:
@@ -224,16 +227,14 @@ private:
status_t parseCharacterLiteral(char16_t* outCharacter);
};
- static sp<KeyCharacterMap> sEmpty;
-
KeyedVector<int32_t, Key*> mKeys;
- int mType;
+ KeyboardType mType;
+ std::string mLoadFileName;
KeyedVector<int32_t, int32_t> mKeysByScanCode;
KeyedVector<int32_t, int32_t> mKeysByUsageCode;
KeyCharacterMap();
- KeyCharacterMap(const KeyCharacterMap& other);
bool getKey(int32_t keyCode, const Key** outKey) const;
bool getKeyBehavior(int32_t keyCode, int32_t metaState,
@@ -242,7 +243,7 @@ private:
bool findKey(char16_t ch, int32_t* outKeyCode, int32_t* outMetaState) const;
- static status_t load(Tokenizer* tokenizer, Format format, sp<KeyCharacterMap>* outMap);
+ static base::Result<std::shared_ptr<KeyCharacterMap>> load(Tokenizer* tokenizer, Format format);
static void addKey(Vector<KeyEvent>& outEvents,
int32_t deviceId, int32_t keyCode, int32_t metaState, bool down, nsecs_t time);