2015-07-30 20:14:55 +02:00
|
|
|
package juloo.keyboard2;
|
|
|
|
|
2015-08-18 01:25:47 +02:00
|
|
|
import android.view.KeyCharacterMap;
|
2015-07-30 20:14:55 +02:00
|
|
|
import android.view.KeyEvent;
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
2015-08-01 00:49:09 +02:00
|
|
|
class KeyValue
|
2015-07-30 20:14:55 +02:00
|
|
|
{
|
2021-04-18 23:28:49 +02:00
|
|
|
public static final int EVENT_NONE = -1;
|
|
|
|
public static final int EVENT_CONFIG = -2;
|
|
|
|
public static final int EVENT_SWITCH_TEXT = -3;
|
|
|
|
public static final int EVENT_SWITCH_NUMERIC = -4;
|
|
|
|
public static final int EVENT_SWITCH_EMOJI = -5;
|
|
|
|
public static final int EVENT_SWITCH_BACK_EMOJI = -6;
|
|
|
|
public static final int EVENT_CHANGE_METHOD = -7;
|
|
|
|
public static final char CHAR_NONE = '\0';
|
|
|
|
|
2021-04-20 00:10:45 +02:00
|
|
|
// Behavior flags
|
|
|
|
public static final int FLAG_KEEP_ON = 1;
|
|
|
|
public static final int FLAG_LOCK = (1 << 1);
|
|
|
|
public static final int FLAG_NOREPEAT = (1 << 2);
|
|
|
|
public static final int FLAG_NOCHAR = (1 << 3);
|
|
|
|
public static final int FLAG_PRECISE_REPEAT = (1 << 4);
|
|
|
|
public static final int FLAG_KEY_FONT = (1 << 5);
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
|
|
|
// Accent flags
|
|
|
|
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
|
2021-05-08 02:00:47 +02:00
|
|
|
public static final int FLAG_ACCENT_SUPERSCRIPT = (1 << 22);
|
|
|
|
public static final int FLAG_ACCENT_SUBSCRIPT = (1 << 23);
|
2021-12-11 17:05:49 +01:00
|
|
|
public static final int FLAG_ACCENT_RING = (1 << 24);
|
2021-04-20 00:10:45 +02:00
|
|
|
|
|
|
|
public static final int FLAGS_ACCENTS = FLAG_ACCENT1 | FLAG_ACCENT2 |
|
2021-05-08 02:00:47 +02:00
|
|
|
FLAG_ACCENT3 | FLAG_ACCENT4 | FLAG_ACCENT5 | FLAG_ACCENT6 |
|
2021-12-11 17:05:49 +01:00
|
|
|
FLAG_ACCENT_SUPERSCRIPT | FLAG_ACCENT_SUBSCRIPT | FLAG_ACCENT_RING;
|
2021-04-13 02:00:08 +02:00
|
|
|
|
2021-04-18 23:28:49 +02:00
|
|
|
public final String name;
|
|
|
|
public final String symbol;
|
|
|
|
public final char char_;
|
|
|
|
public final int eventCode;
|
|
|
|
public final int flags;
|
|
|
|
|
2021-05-08 02:00:47 +02:00
|
|
|
/* Update the char and the symbol. */
|
|
|
|
public KeyValue withCharAndSymbol(char c)
|
|
|
|
{
|
|
|
|
return withCharAndSymbol(String.valueOf(c), c);
|
|
|
|
}
|
|
|
|
|
2021-04-18 23:28:49 +02:00
|
|
|
public KeyValue withCharAndSymbol(String s, char c)
|
|
|
|
{
|
|
|
|
return new KeyValue(name, s, c, eventCode, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static HashMap<String, KeyValue> keys = new HashMap<String, KeyValue>();
|
|
|
|
|
2021-04-18 23:58:35 +02:00
|
|
|
public KeyValue(String n, String s, char c, int e, int f)
|
2021-04-18 23:28:49 +02:00
|
|
|
{
|
|
|
|
name = n;
|
|
|
|
symbol = s;
|
|
|
|
char_ = c;
|
|
|
|
eventCode = e;
|
|
|
|
flags = f;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static KeyValue getKeyByName(String name)
|
|
|
|
{
|
2021-05-08 02:00:47 +02:00
|
|
|
if (name == null)
|
|
|
|
return null;
|
|
|
|
KeyValue kv = KeyValue.keys.get(name);
|
|
|
|
if (kv != null)
|
|
|
|
return kv;
|
|
|
|
return new KeyValue(name, name, CHAR_NONE, EVENT_NONE, 0);
|
2021-04-18 23:28:49 +02:00
|
|
|
}
|
2015-08-01 16:33:30 +02:00
|
|
|
|
2021-04-18 21:58:13 +02:00
|
|
|
private static void addKey(String name, String symbol, char c, int event, int flags)
|
|
|
|
{
|
|
|
|
keys.put(name, new KeyValue(name, symbol, c, event, flags));
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void addCharKey(char c, int event)
|
|
|
|
{
|
|
|
|
String name = String.valueOf(c);
|
|
|
|
addKey(name, name, c, event, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void addModifierKey(String name, String symbol, int extra_flags)
|
|
|
|
{
|
|
|
|
addKey(name, symbol, CHAR_NONE, EVENT_NONE,
|
|
|
|
FLAG_KEEP_ON | FLAG_NOCHAR | FLAG_NOREPEAT | extra_flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void addSpecialKey(String name, String symbol, int event)
|
|
|
|
{
|
|
|
|
addKey(name, symbol, CHAR_NONE, event, FLAG_NOREPEAT);
|
|
|
|
}
|
|
|
|
|
2021-04-19 22:29:20 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2021-04-18 21:58:13 +02:00
|
|
|
static
|
|
|
|
{
|
2021-04-29 00:13:40 +02:00
|
|
|
String chars = "<>&\"_°~{|^}$*:!£%µ?.§€";
|
2021-04-18 21:58:13 +02:00
|
|
|
for (int i = 0; i < chars.length(); i++)
|
|
|
|
addCharKey(chars.charAt(i), EVENT_NONE);
|
|
|
|
|
|
|
|
addModifierKey("shift", "⇧", FLAG_LOCK | FLAG_SHIFT);
|
|
|
|
addModifierKey("ctrl", "Ctrl", FLAG_CTRL);
|
|
|
|
addModifierKey("alt", "Alt", FLAG_ALT);
|
2021-05-07 22:15:43 +02:00
|
|
|
addModifierKey("accent_grave", "◌̀", FLAG_ACCENT1);
|
|
|
|
addModifierKey("accent_aigu", "◌́", FLAG_ACCENT2);
|
|
|
|
addModifierKey("accent_circonflexe", "◌̂", FLAG_ACCENT3);
|
|
|
|
addModifierKey("accent_tilde", "◌̃", FLAG_ACCENT4);
|
|
|
|
addModifierKey("accent_cedille", "◌̧", FLAG_ACCENT5);
|
|
|
|
addModifierKey("accent_trema", "◌̈", FLAG_ACCENT6);
|
2021-12-11 17:05:49 +01:00
|
|
|
addModifierKey("accent_ring", "◌̊", FLAG_ACCENT_RING);
|
2021-05-08 02:00:47 +02:00
|
|
|
addModifierKey("superscript", "◌͆", FLAG_ACCENT_SUPERSCRIPT);
|
|
|
|
addModifierKey("subscript", "◌̺", FLAG_ACCENT_SUBSCRIPT);
|
2021-04-18 23:58:35 +02:00
|
|
|
addModifierKey("fn", "Fn", FLAG_FN);
|
2021-04-18 21:58:13 +02:00
|
|
|
|
|
|
|
addCharKey('a', KeyEvent.KEYCODE_A);
|
|
|
|
addCharKey('b', KeyEvent.KEYCODE_B);
|
|
|
|
addCharKey('c', KeyEvent.KEYCODE_C);
|
|
|
|
addCharKey('d', KeyEvent.KEYCODE_D);
|
|
|
|
addCharKey('e', KeyEvent.KEYCODE_E);
|
|
|
|
addCharKey('f', KeyEvent.KEYCODE_F);
|
|
|
|
addCharKey('g', KeyEvent.KEYCODE_G);
|
|
|
|
addCharKey('h', KeyEvent.KEYCODE_H);
|
|
|
|
addCharKey('i', KeyEvent.KEYCODE_I);
|
|
|
|
addCharKey('j', KeyEvent.KEYCODE_J);
|
|
|
|
addCharKey('k', KeyEvent.KEYCODE_K);
|
|
|
|
addCharKey('l', KeyEvent.KEYCODE_L);
|
|
|
|
addCharKey('m', KeyEvent.KEYCODE_M);
|
|
|
|
addCharKey('n', KeyEvent.KEYCODE_N);
|
|
|
|
addCharKey('o', KeyEvent.KEYCODE_O);
|
|
|
|
addCharKey('p', KeyEvent.KEYCODE_P);
|
|
|
|
addCharKey('q', KeyEvent.KEYCODE_Q);
|
|
|
|
addCharKey('r', KeyEvent.KEYCODE_R);
|
|
|
|
addCharKey('s', KeyEvent.KEYCODE_S);
|
|
|
|
addCharKey('t', KeyEvent.KEYCODE_T);
|
|
|
|
addCharKey('u', KeyEvent.KEYCODE_U);
|
|
|
|
addCharKey('v', KeyEvent.KEYCODE_V);
|
|
|
|
addCharKey('w', KeyEvent.KEYCODE_W);
|
|
|
|
addCharKey('x', KeyEvent.KEYCODE_X);
|
|
|
|
addCharKey('y', KeyEvent.KEYCODE_Y);
|
|
|
|
addCharKey('z', KeyEvent.KEYCODE_Z);
|
|
|
|
addCharKey('0', KeyEvent.KEYCODE_0);
|
|
|
|
addCharKey('1', KeyEvent.KEYCODE_1);
|
|
|
|
addCharKey('2', KeyEvent.KEYCODE_2);
|
|
|
|
addCharKey('3', KeyEvent.KEYCODE_3);
|
|
|
|
addCharKey('4', KeyEvent.KEYCODE_4);
|
|
|
|
addCharKey('5', KeyEvent.KEYCODE_5);
|
|
|
|
addCharKey('6', KeyEvent.KEYCODE_6);
|
|
|
|
addCharKey('7', KeyEvent.KEYCODE_7);
|
|
|
|
addCharKey('8', KeyEvent.KEYCODE_8);
|
|
|
|
addCharKey('9', KeyEvent.KEYCODE_9);
|
2021-04-21 23:25:14 +02:00
|
|
|
addCharKey('`', KeyEvent.KEYCODE_GRAVE);
|
|
|
|
addCharKey('-', KeyEvent.KEYCODE_MINUS);
|
|
|
|
addCharKey('=', KeyEvent.KEYCODE_EQUALS);
|
|
|
|
addCharKey('[', KeyEvent.KEYCODE_LEFT_BRACKET);
|
|
|
|
addCharKey(']', KeyEvent.KEYCODE_RIGHT_BRACKET);
|
|
|
|
addCharKey('\\', KeyEvent.KEYCODE_BACKSLASH);
|
|
|
|
addCharKey(';', KeyEvent.KEYCODE_SEMICOLON);
|
|
|
|
addCharKey('\'', KeyEvent.KEYCODE_APOSTROPHE);
|
|
|
|
addCharKey('/', KeyEvent.KEYCODE_SLASH);
|
|
|
|
addCharKey('@', KeyEvent.KEYCODE_AT);
|
|
|
|
addCharKey('+', KeyEvent.KEYCODE_PLUS);
|
|
|
|
addCharKey(',', KeyEvent.KEYCODE_COMMA);
|
|
|
|
addCharKey('.', KeyEvent.KEYCODE_PERIOD);
|
|
|
|
addCharKey('*', KeyEvent.KEYCODE_STAR);
|
|
|
|
addCharKey('#', KeyEvent.KEYCODE_POUND);
|
|
|
|
addCharKey('(', KeyEvent.KEYCODE_NUMPAD_LEFT_PAREN);
|
|
|
|
addCharKey(')', KeyEvent.KEYCODE_NUMPAD_RIGHT_PAREN);
|
2021-04-18 21:58:13 +02:00
|
|
|
|
|
|
|
addSpecialKey("config", "Conf", EVENT_CONFIG);
|
|
|
|
addSpecialKey("switch_text", "ABC", EVENT_SWITCH_TEXT);
|
|
|
|
addSpecialKey("switch_numeric", "123+", EVENT_SWITCH_NUMERIC);
|
|
|
|
addSpecialKey("switch_emoji", ":)", EVENT_SWITCH_EMOJI);
|
|
|
|
addSpecialKey("switch_back_emoji", "ABC", EVENT_SWITCH_BACK_EMOJI);
|
|
|
|
addSpecialKey("change_method", "⊞", EVENT_CHANGE_METHOD);
|
|
|
|
|
2021-04-19 22:29:20 +02:00
|
|
|
addEventKey("esc", "Esc", KeyEvent.KEYCODE_ESCAPE);
|
|
|
|
addEventKey("enter", "\uE800", KeyEvent.KEYCODE_ENTER, FLAG_KEY_FONT);
|
2021-04-20 00:10:45 +02:00
|
|
|
addEventKey("up", "\uE80B", KeyEvent.KEYCODE_DPAD_UP, FLAG_KEY_FONT | FLAG_PRECISE_REPEAT);
|
|
|
|
addEventKey("right", "\uE80C", KeyEvent.KEYCODE_DPAD_RIGHT, FLAG_KEY_FONT | FLAG_PRECISE_REPEAT);
|
|
|
|
addEventKey("down", "\uE809", KeyEvent.KEYCODE_DPAD_DOWN, FLAG_KEY_FONT | FLAG_PRECISE_REPEAT);
|
|
|
|
addEventKey("left", "\uE80A", KeyEvent.KEYCODE_DPAD_LEFT, FLAG_KEY_FONT | FLAG_PRECISE_REPEAT);
|
2021-12-05 20:55:52 +01:00
|
|
|
addEventKey("page_up", "⇞", KeyEvent.KEYCODE_PAGE_UP);
|
|
|
|
addEventKey("page_down", "⇟", KeyEvent.KEYCODE_PAGE_DOWN);
|
2021-04-19 22:29:20 +02:00
|
|
|
addEventKey("home", "↖", KeyEvent.KEYCODE_HOME);
|
|
|
|
addEventKey("end", "↗", KeyEvent.KEYCODE_MOVE_END);
|
2021-04-20 00:10:45 +02:00
|
|
|
addEventKey("backspace", "⌫", KeyEvent.KEYCODE_DEL, FLAG_PRECISE_REPEAT);
|
|
|
|
addEventKey("delete", "⌦", KeyEvent.KEYCODE_FORWARD_DEL, FLAG_PRECISE_REPEAT);
|
2021-04-19 22:29:20 +02:00
|
|
|
addEventKey("insert", "Ins", KeyEvent.KEYCODE_INSERT);
|
|
|
|
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);
|
2021-04-18 21:58:13 +02:00
|
|
|
|
|
|
|
addKey("tab", "↹", '\t', KeyEvent.KEYCODE_TAB, 0);
|
2021-04-18 23:28:49 +02:00
|
|
|
addKey("space", " ", ' ', KeyEvent.KEYCODE_SPACE, 0);
|
2021-04-18 21:58:13 +02:00
|
|
|
}
|
2015-07-30 20:14:55 +02:00
|
|
|
}
|