diff options
Diffstat (limited to 'srcs/juloo.keyboard2/KeyValue.java')
| -rw-r--r-- | srcs/juloo.keyboard2/KeyValue.java | 182 |
1 files changed, 88 insertions, 94 deletions
diff --git a/srcs/juloo.keyboard2/KeyValue.java b/srcs/juloo.keyboard2/KeyValue.java index d88f027..b29237e 100644 --- a/srcs/juloo.keyboard2/KeyValue.java +++ b/srcs/juloo.keyboard2/KeyValue.java @@ -6,6 +6,8 @@ import java.util.HashMap; class KeyValue { + /** Values for the [code] field. */ + public static final int EVENT_NONE = -1; public static final int EVENT_CONFIG = -2; public static final int EVENT_SWITCH_TEXT = -3; @@ -15,6 +17,35 @@ class KeyValue public static final int EVENT_CHANGE_METHOD = -7; public static final int EVENT_ACTION = -8; public static final int EVENT_SWITCH_PROGRAMMING = -9; + + // Modifiers + // Must be evaluated in the reverse order of their values. + public static final int MOD_SHIFT = -100; + public static final int MOD_FN = -101; + public static final int MOD_CTRL = -102; + public static final int MOD_ALT = -103; + public static final int MOD_META = -104; + + // Dead-keys + public static final int MOD_DOUBLE_AIGU = -200; + public static final int MOD_DOT_ABOVE = -201; + public static final int MOD_GRAVE = -202; + public static final int MOD_AIGU = -203; + public static final int MOD_CIRCONFLEXE = -204; + public static final int MOD_TILDE = -205; + public static final int MOD_CEDILLE = -206; + public static final int MOD_TREMA = -207; + public static final int MOD_SUPERSCRIPT = -208; + public static final int MOD_SUBSCRIPT = -209; + public static final int MOD_RING = -210; + public static final int MOD_CARON = -211; + public static final int MOD_MACRON = -212; + public static final int MOD_ORDINAL = -213; + public static final int MOD_ARROWS = -214; + public static final int MOD_BOX = -215; + public static final int MOD_OGONEK = -216; + + /** Special value for the [char_] field. */ public static final char CHAR_NONE = '\0'; // Behavior flags @@ -22,7 +53,7 @@ class KeyValue public static final int FLAG_LOCK = (1 << 1); // Special keys are not repeated and don't clear latched modifiers public static final int FLAG_SPECIAL = (1 << 2); - public static final int FLAG_NOCHAR = (1 << 3); + public static final int FLAG_MODIFIER = (1 << 3); public static final int FLAG_PRECISE_REPEAT = (1 << 4); // Rendering flags @@ -30,48 +61,25 @@ class KeyValue public static final int FLAG_SMALLER_FONT = (1 << 6); // Internal flags - public static final int FLAG_LOCKED = (1 << 8); - - // Modifier flags - public static final int FLAG_CTRL = (1 << 10); - public static final int FLAG_SHIFT = (1 << 11); - public static final int FLAG_ALT = (1 << 12); - public static final int FLAG_FN = (1 << 13); - public static final int FLAG_META = (1 << 14); - - // Accent flags - public static final int FLAG_ACCENT_DOUBLE_AIGU = (1 << 9); - public static final int FLAG_ACCENT_DOT_ABOVE = (1 << 15); - public static final int FLAG_ACCENT1 = (1 << 16); // Grave - public static final int FLAG_ACCENT2 = (1 << 17); // Aigu - public static final int FLAG_ACCENT3 = (1 << 18); // Circonflexe - public static final int FLAG_ACCENT4 = (1 << 19); // Tilde - public static final int FLAG_ACCENT5 = (1 << 20); // Cédille - public static final int FLAG_ACCENT6 = (1 << 21); // Tréma - public static final int FLAG_ACCENT_SUPERSCRIPT = (1 << 22); - public static final int FLAG_ACCENT_SUBSCRIPT = (1 << 23); - public static final int FLAG_ACCENT_RING = (1 << 24); - public static final int FLAG_ACCENT_CARON = (1 << 26); - public static final int FLAG_ACCENT_MACRON = (1 << 27); - public static final int FLAG_ACCENT_ORDINAL = (1 << 28); - public static final int FLAG_ACCENT_ARROWS = (1 << 29); - public static final int FLAG_ACCENT_BOX = (1 << 30); - public static final int FLAG_ACCENT_OGONEK = (1 << 31); - - public static final int FLAGS_ACCENTS = FLAG_ACCENT1 | FLAG_ACCENT2 | - FLAG_ACCENT3 | FLAG_ACCENT4 | FLAG_ACCENT5 | FLAG_ACCENT6 | - FLAG_ACCENT_CARON | FLAG_ACCENT_MACRON | FLAG_ACCENT_SUPERSCRIPT | - FLAG_ACCENT_SUBSCRIPT | FLAG_ACCENT_ORDINAL | FLAG_ACCENT_ARROWS | - FLAG_ACCENT_BOX | FLAG_ACCENT_RING | FLAG_ACCENT_OGONEK | - FLAG_ACCENT_DOT_ABOVE | FLAG_ACCENT_DOUBLE_AIGU; + public static final int FLAG_LOCKED = (1 << 7); // Language specific keys that are removed from the keyboard by default - public static final int FLAG_LOCALIZED = (1 << 25); + public static final int FLAG_LOCALIZED = (1 << 8); public final String name; public final String symbol; public final char char_; - public final int eventCode; + + /** Describe what the key does when it isn't a simple character. + Can be one of: + - When [FLAG_MODIFIER] is set, a modifier. See [KeyModifier]. + - [EVENT_NONE], no event is associated with the key. + - A positive integer, an Android [KeyEvent]. + - One of the [EVENT_*] constants, an action performed in [KeyEventHandler]. + A key can have both a character and a key event associated, the key event + is used when certain modifiers are active, the character is used + otherwise. See [KeyEventHandler]. */ + public final int code; public final int flags; /* Update the char and the symbol. */ @@ -82,17 +90,17 @@ class KeyValue public KeyValue withCharAndSymbol(String s, char c) { - return new KeyValue(name, s, c, eventCode, flags); + return new KeyValue(name, s, c, code, flags); } public KeyValue withNameAndSymbol(String n, String s) { - return new KeyValue(n, s, char_, eventCode, flags); + return new KeyValue(n, s, char_, code, flags); } public KeyValue withFlags(int f) { - return new KeyValue(name, symbol, char_, eventCode, f); + return new KeyValue(name, symbol, char_, code, f); } private static HashMap<String, KeyValue> keys = new HashMap<String, KeyValue>(); @@ -102,7 +110,7 @@ class KeyValue name = n; symbol = s; char_ = c; - eventCode = e; + code = e; flags = f; } @@ -136,26 +144,17 @@ class KeyValue keys.put(name, new KeyValue(name, symbol, c, event, flags)); } - private static void addCharKey(char c, int event, int flags) - { - String name = String.valueOf(c); - addKey(name, name, c, event, flags); - } - private static void addCharKey(char c, int event) { - addCharKey(c, event, 0); - } - - private static void addModifierKey(String name, String symbol, int extra_flags) - { - addKey(name, symbol, CHAR_NONE, EVENT_NONE, - FLAG_LATCH | FLAG_NOCHAR | FLAG_SPECIAL | extra_flags); + String name = String.valueOf(c); + addKey(name, name, c, event, 0); } - private static void addSpecialKey(String name, String symbol, int event) + private static void addModifierKey(String name, String symbol, int code, int extra_flags) { - addSpecialKey(name, symbol, event, 0); + assert(code >= 100 && code < 300); + addKey(name, symbol, CHAR_NONE, code, + FLAG_LATCH | FLAG_MODIFIER | FLAG_SPECIAL | extra_flags); } private static void addSpecialKey(String name, String symbol, int event, int flags) @@ -163,11 +162,6 @@ class KeyValue addKey(name, symbol, CHAR_NONE, event, flags | FLAG_SPECIAL); } - private static void addEventKey(String name, String symbol, int event) - { - addEventKey(name, symbol, event, 0); - } - private static void addEventKey(String name, String symbol, int event, int flags) { addKey(name, symbol, CHAR_NONE, event, flags); @@ -176,28 +170,28 @@ class KeyValue static { addModifierKey("shift", "\n", // Can't write u000A because Java is stupid - FLAG_SHIFT | FLAG_KEY_FONT | FLAG_SMALLER_FONT); - addModifierKey("ctrl", "Ctrl", FLAG_CTRL | FLAG_SMALLER_FONT); - addModifierKey("alt", "Alt", FLAG_ALT | FLAG_SMALLER_FONT); - addModifierKey("accent_aigu", "\u0050", FLAG_ACCENT2 | FLAG_KEY_FONT); - addModifierKey("accent_caron", "\u0051", FLAG_ACCENT_CARON | FLAG_KEY_FONT); - addModifierKey("accent_cedille", "\u0052", FLAG_ACCENT5 | FLAG_KEY_FONT); - addModifierKey("accent_circonflexe", "\u0053", FLAG_ACCENT3 | FLAG_KEY_FONT); - addModifierKey("accent_grave", "\u0054", FLAG_ACCENT1 | FLAG_KEY_FONT); - addModifierKey("accent_macron", "\u0055", FLAG_ACCENT_MACRON | FLAG_KEY_FONT); - addModifierKey("accent_ring", "\u0056", FLAG_ACCENT_RING | FLAG_KEY_FONT); - addModifierKey("accent_tilde", "\u0057", FLAG_ACCENT4 | FLAG_KEY_FONT); - addModifierKey("accent_trema", "\u0058", FLAG_ACCENT6 | FLAG_KEY_FONT); - addModifierKey("accent_ogonek", "\u0059", FLAG_ACCENT_OGONEK | FLAG_KEY_FONT); - addModifierKey("accent_dot_above", "\u005a", FLAG_ACCENT_DOT_ABOVE | FLAG_KEY_FONT); - addModifierKey("accent_double_aigu", "\u005b", FLAG_ACCENT_DOUBLE_AIGU | FLAG_KEY_FONT); - addModifierKey("superscript", "Sup", FLAG_ACCENT_SUPERSCRIPT | FLAG_SMALLER_FONT); - addModifierKey("subscript", "Sub", FLAG_ACCENT_SUBSCRIPT | FLAG_SMALLER_FONT); - addModifierKey("ordinal", "Ord", FLAG_ACCENT_ORDINAL | FLAG_SMALLER_FONT); - addModifierKey("arrows", "Arr", FLAG_ACCENT_ARROWS | FLAG_SMALLER_FONT); - addModifierKey("box", "Box", FLAG_ACCENT_BOX | FLAG_SMALLER_FONT); - addModifierKey("fn", "Fn", FLAG_FN | FLAG_SMALLER_FONT); - addModifierKey("meta", "Meta", FLAG_META | FLAG_SMALLER_FONT); + MOD_SHIFT, FLAG_KEY_FONT | FLAG_SMALLER_FONT); + addModifierKey("ctrl", "Ctrl", MOD_CTRL, FLAG_SMALLER_FONT); + addModifierKey("alt", "Alt", MOD_ALT, FLAG_SMALLER_FONT); + addModifierKey("accent_aigu", "\u0050", MOD_AIGU, FLAG_KEY_FONT); + addModifierKey("accent_caron", "\u0051", MOD_CARON, FLAG_KEY_FONT); + addModifierKey("accent_cedille", "\u0052", MOD_CEDILLE, FLAG_KEY_FONT); + addModifierKey("accent_circonflexe", "\u0053", MOD_CIRCONFLEXE, FLAG_KEY_FONT); + addModifierKey("accent_grave", "\u0054", MOD_GRAVE, FLAG_KEY_FONT); + addModifierKey("accent_macron", "\u0055", MOD_MACRON, FLAG_KEY_FONT); + addModifierKey("accent_ring", "\u0056", MOD_RING, FLAG_KEY_FONT); + addModifierKey("accent_tilde", "\u0057", MOD_TILDE, FLAG_KEY_FONT); + addModifierKey("accent_trema", "\u0058", MOD_TREMA, FLAG_KEY_FONT); + addModifierKey("accent_ogonek", "\u0059", MOD_OGONEK, FLAG_KEY_FONT); + addModifierKey("accent_dot_above", "\u005a", MOD_DOT_ABOVE, FLAG_KEY_FONT); + addModifierKey("accent_double_aigu", "\u005b", MOD_DOUBLE_AIGU, FLAG_KEY_FONT); + addModifierKey("superscript", "Sup", MOD_SUPERSCRIPT, FLAG_SMALLER_FONT); + addModifierKey("subscript", "Sub", MOD_SUBSCRIPT, FLAG_SMALLER_FONT); + addModifierKey("ordinal", "Ord", MOD_ORDINAL, FLAG_SMALLER_FONT); + addModifierKey("arrows", "Arr", MOD_ARROWS, FLAG_SMALLER_FONT); + addModifierKey("box", "Box", MOD_BOX, FLAG_SMALLER_FONT); + addModifierKey("fn", "Fn", MOD_FN, FLAG_SMALLER_FONT); + addModifierKey("meta", "Meta", MOD_META, FLAG_SMALLER_FONT); addCharKey('a', KeyEvent.KEYCODE_A); addCharKey('b', KeyEvent.KEYCODE_B); @@ -257,7 +251,7 @@ class KeyValue addSpecialKey("switch_text", "ABC", EVENT_SWITCH_TEXT, FLAG_SMALLER_FONT); addSpecialKey("switch_numeric", "123+", EVENT_SWITCH_NUMERIC, FLAG_SMALLER_FONT); addSpecialKey("switch_emoji", "\u0001" , EVENT_SWITCH_EMOJI, FLAG_KEY_FONT | FLAG_SMALLER_FONT); - addSpecialKey("switch_back_emoji", "ABC", EVENT_SWITCH_BACK_EMOJI); + addSpecialKey("switch_back_emoji", "ABC", EVENT_SWITCH_BACK_EMOJI, 0); addSpecialKey("switch_programming", "Prog", EVENT_SWITCH_PROGRAMMING, FLAG_SMALLER_FONT); addSpecialKey("change_method", "\u0009", EVENT_CHANGE_METHOD, FLAG_KEY_FONT | FLAG_SMALLER_FONT); addSpecialKey("action", "Action", EVENT_ACTION, FLAG_SMALLER_FONT); // Will always be replaced @@ -275,16 +269,16 @@ class KeyValue addEventKey("backspace", "\u0011", KeyEvent.KEYCODE_DEL, FLAG_KEY_FONT); addEventKey("delete", "\u0010", KeyEvent.KEYCODE_FORWARD_DEL, FLAG_KEY_FONT); addEventKey("insert", "Ins", KeyEvent.KEYCODE_INSERT, FLAG_SMALLER_FONT); - addEventKey("f1", "F1", KeyEvent.KEYCODE_F1); - addEventKey("f2", "F2", KeyEvent.KEYCODE_F2); - addEventKey("f3", "F3", KeyEvent.KEYCODE_F3); - addEventKey("f4", "F4", KeyEvent.KEYCODE_F4); - addEventKey("f5", "F5", KeyEvent.KEYCODE_F5); - addEventKey("f6", "F6", KeyEvent.KEYCODE_F6); - addEventKey("f7", "F7", KeyEvent.KEYCODE_F7); - addEventKey("f8", "F8", KeyEvent.KEYCODE_F8); - addEventKey("f9", "F9", KeyEvent.KEYCODE_F9); - addEventKey("f10", "F10", KeyEvent.KEYCODE_F10); + addEventKey("f1", "F1", KeyEvent.KEYCODE_F1, 0); + addEventKey("f2", "F2", KeyEvent.KEYCODE_F2, 0); + addEventKey("f3", "F3", KeyEvent.KEYCODE_F3, 0); + addEventKey("f4", "F4", KeyEvent.KEYCODE_F4, 0); + addEventKey("f5", "F5", KeyEvent.KEYCODE_F5, 0); + addEventKey("f6", "F6", KeyEvent.KEYCODE_F6, 0); + addEventKey("f7", "F7", KeyEvent.KEYCODE_F7, 0); + addEventKey("f8", "F8", KeyEvent.KEYCODE_F8, 0); + addEventKey("f9", "F9", KeyEvent.KEYCODE_F9, 0); + addEventKey("f10", "F10", KeyEvent.KEYCODE_F10, 0); addEventKey("f11", "F11", KeyEvent.KEYCODE_F11, FLAG_SMALLER_FONT); addEventKey("f12", "F12", KeyEvent.KEYCODE_F12, FLAG_SMALLER_FONT); addEventKey("tab", "\u000F", KeyEvent.KEYCODE_TAB, FLAG_KEY_FONT | FLAG_SMALLER_FONT); |
