forked from extern/Unexpected-Keyboard
Refactor: Separate Events and Keyevents and use enums
Negative values for internal events are preventing further refactoring. Add a new kind of key and split internal events (now Event) and Android's key events (now Keyevent). Use enums events and modifiers outside of the KeyValue class. Internally, they are converted to and from integer.
This commit is contained in:
parent
cc571ea1ca
commit
5cc7fdf6d7
@ -36,7 +36,7 @@ final class Config
|
||||
public float keyVerticalInterval;
|
||||
public float keyHorizontalInterval;
|
||||
public boolean preciseRepeat;
|
||||
public Set<Integer> lockable_modifiers = new HashSet<Integer>();
|
||||
public Set<KeyValue.Modifier> lockable_modifiers = new HashSet<KeyValue.Modifier>();
|
||||
public float characterSize; // Ratio
|
||||
public int accents; // Values are R.values.pref_accents_v_*
|
||||
public int theme; // Values are R.style.*
|
||||
@ -128,14 +128,14 @@ final class Config
|
||||
horizontalMargin = getDipPref(dm, prefs, "horizontal_margin", horizontalMargin) + res.getDimension(R.dimen.extra_horizontal_margin);
|
||||
preciseRepeat = prefs.getBoolean("precise_repeat", preciseRepeat);
|
||||
lockable_modifiers.clear();
|
||||
if (prefs.getBoolean("lockable_shift", true)) lockable_modifiers.add(KeyValue.MOD_SHIFT);
|
||||
if (prefs.getBoolean("lockable_ctrl", false)) lockable_modifiers.add(KeyValue.MOD_CTRL);
|
||||
if (prefs.getBoolean("lockable_alt", false)) lockable_modifiers.add(KeyValue.MOD_ALT);
|
||||
if (prefs.getBoolean("lockable_fn", false)) lockable_modifiers.add(KeyValue.MOD_FN);
|
||||
if (prefs.getBoolean("lockable_meta", false)) lockable_modifiers.add(KeyValue.MOD_META);
|
||||
if (prefs.getBoolean("lockable_sup", false)) lockable_modifiers.add(KeyValue.MOD_SUPERSCRIPT);
|
||||
if (prefs.getBoolean("lockable_sub", false)) lockable_modifiers.add(KeyValue.MOD_SUBSCRIPT);
|
||||
if (prefs.getBoolean("lockable_box", false)) lockable_modifiers.add(KeyValue.MOD_BOX);
|
||||
if (prefs.getBoolean("lockable_shift", true)) lockable_modifiers.add(KeyValue.Modifier.SHIFT);
|
||||
if (prefs.getBoolean("lockable_ctrl", false)) lockable_modifiers.add(KeyValue.Modifier.CTRL);
|
||||
if (prefs.getBoolean("lockable_alt", false)) lockable_modifiers.add(KeyValue.Modifier.ALT);
|
||||
if (prefs.getBoolean("lockable_fn", false)) lockable_modifiers.add(KeyValue.Modifier.FN);
|
||||
if (prefs.getBoolean("lockable_meta", false)) lockable_modifiers.add(KeyValue.Modifier.META);
|
||||
if (prefs.getBoolean("lockable_sup", false)) lockable_modifiers.add(KeyValue.Modifier.SUPERSCRIPT);
|
||||
if (prefs.getBoolean("lockable_sub", false)) lockable_modifiers.add(KeyValue.Modifier.SUBSCRIPT);
|
||||
if (prefs.getBoolean("lockable_box", false)) lockable_modifiers.add(KeyValue.Modifier.BOX);
|
||||
characterSize = prefs.getFloat("character_size", characterSize);
|
||||
accents = Integer.valueOf(prefs.getString("accents", "1"));
|
||||
theme = getThemeId(res, prefs.getString("theme", ""));
|
||||
@ -171,17 +171,22 @@ final class Config
|
||||
case Event:
|
||||
switch (key.getEvent())
|
||||
{
|
||||
case KeyValue.EVENT_CHANGE_METHOD:
|
||||
case CHANGE_METHOD:
|
||||
return shouldOfferSwitchingToNextInputMethod ? key : null;
|
||||
case KeyEvent.KEYCODE_ENTER:
|
||||
return (swapEnterActionKey && action_key != null) ? action_key : key;
|
||||
case KeyValue.EVENT_ACTION:
|
||||
case ACTION:
|
||||
return (swapEnterActionKey && action_key != null) ?
|
||||
KeyValue.getKeyByName("enter") : action_key;
|
||||
case KeyValue.EVENT_SWITCH_PROGRAMMING:
|
||||
case SWITCH_PROGRAMMING:
|
||||
return shouldOfferSwitchingToProgramming ? key : null;
|
||||
}
|
||||
break;
|
||||
case Keyevent:
|
||||
switch (key.getKeyevent())
|
||||
{
|
||||
case KeyEvent.KEYCODE_ENTER:
|
||||
return (swapEnterActionKey && action_key != null) ? action_key : key;
|
||||
}
|
||||
break;
|
||||
case Modifier:
|
||||
if (lockable_modifiers.contains(key.getModifier()))
|
||||
return key.withFlags(flags | KeyValue.FLAG_LOCK);
|
||||
|
@ -15,7 +15,6 @@ class KeyEventHandler implements Config.IKeyEventHandler
|
||||
{
|
||||
if (key == null)
|
||||
return;
|
||||
int event;
|
||||
switch (key.getKind())
|
||||
{
|
||||
case Char:
|
||||
@ -25,22 +24,21 @@ class KeyEventHandler implements Config.IKeyEventHandler
|
||||
_recv.commitText(key.getString());
|
||||
break;
|
||||
case Event:
|
||||
event = key.getEvent();
|
||||
switch (event)
|
||||
switch (key.getEvent())
|
||||
{
|
||||
case KeyValue.EVENT_CONFIG: _recv.showKeyboardConfig(); break;
|
||||
case KeyValue.EVENT_SWITCH_TEXT: _recv.switchMain(); break;
|
||||
case KeyValue.EVENT_SWITCH_NUMERIC: _recv.switchNumeric(); break;
|
||||
case KeyValue.EVENT_SWITCH_EMOJI: _recv.setPane_emoji(); break;
|
||||
case KeyValue.EVENT_SWITCH_BACK_EMOJI: _recv.setPane_normal(); break;
|
||||
case KeyValue.EVENT_CHANGE_METHOD: _recv.switchToNextInputMethod(); break;
|
||||
case KeyValue.EVENT_ACTION: _recv.performAction(); break;
|
||||
case KeyValue.EVENT_SWITCH_PROGRAMMING: _recv.switchProgramming(); break;
|
||||
default:
|
||||
handleKeyUpWithModifier(event, mods);
|
||||
break;
|
||||
case CONFIG: _recv.showKeyboardConfig(); break;
|
||||
case SWITCH_TEXT: _recv.switchMain(); break;
|
||||
case SWITCH_NUMERIC: _recv.switchNumeric(); break;
|
||||
case SWITCH_EMOJI: _recv.setPane_emoji(); break;
|
||||
case SWITCH_BACK_EMOJI: _recv.setPane_normal(); break;
|
||||
case CHANGE_METHOD: _recv.switchToNextInputMethod(); break;
|
||||
case ACTION: _recv.performAction(); break;
|
||||
case SWITCH_PROGRAMMING: _recv.switchProgramming(); break;
|
||||
}
|
||||
break;
|
||||
case Keyevent:
|
||||
handleKeyUpWithModifier(key.getKeyevent(), mods);
|
||||
break;
|
||||
case Modifier:
|
||||
break;
|
||||
}
|
||||
@ -66,17 +64,17 @@ class KeyEventHandler implements Config.IKeyEventHandler
|
||||
return updatedMetaState;
|
||||
}
|
||||
|
||||
private int sendMetaKeyForModifier(int mod, int metaState, boolean down)
|
||||
private int sendMetaKeyForModifier(KeyValue.Modifier mod, int metaState, boolean down)
|
||||
{
|
||||
switch (mod)
|
||||
{
|
||||
case KeyValue.MOD_CTRL:
|
||||
case CTRL:
|
||||
return sendMetaKey(KeyEvent.KEYCODE_CTRL_LEFT, KeyEvent.META_CTRL_LEFT_ON | KeyEvent.META_CTRL_ON, metaState, down);
|
||||
case KeyValue.MOD_ALT:
|
||||
case ALT:
|
||||
return sendMetaKey(KeyEvent.KEYCODE_ALT_LEFT, KeyEvent.META_ALT_LEFT_ON | KeyEvent.META_ALT_ON, metaState, down);
|
||||
case KeyValue.MOD_SHIFT:
|
||||
case SHIFT:
|
||||
return sendMetaKey(KeyEvent.KEYCODE_SHIFT_LEFT, KeyEvent.META_SHIFT_LEFT_ON | KeyEvent.META_SHIFT_ON, metaState, down);
|
||||
case KeyValue.MOD_META:
|
||||
case META:
|
||||
return sendMetaKey(KeyEvent.KEYCODE_META_LEFT, KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_ON, metaState, down);
|
||||
default: return metaState;
|
||||
}
|
||||
|
@ -33,34 +33,34 @@ class KeyModifier
|
||||
return (r == removed_key) ? null : r;
|
||||
}
|
||||
|
||||
public static KeyValue modify(KeyValue k, int mod)
|
||||
public static KeyValue modify(KeyValue k, KeyValue.Modifier mod)
|
||||
{
|
||||
switch (mod)
|
||||
{
|
||||
case KeyValue.MOD_CTRL:
|
||||
case KeyValue.MOD_ALT:
|
||||
case KeyValue.MOD_META: return turn_into_keyevent(k);
|
||||
case KeyValue.MOD_FN: return apply_fn(k);
|
||||
case KeyValue.MOD_SHIFT: return apply_shift(k);
|
||||
case KeyValue.MOD_GRAVE: return apply_dead_char(k, '\u02CB');
|
||||
case KeyValue.MOD_AIGU: return apply_dead_char(k, '\u00B4');
|
||||
case KeyValue.MOD_CIRCONFLEXE: return apply_dead_char(k, '\u02C6');
|
||||
case KeyValue.MOD_TILDE: return apply_dead_char(k, '\u02DC');
|
||||
case KeyValue.MOD_CEDILLE: return apply_dead_char(k, '\u00B8');
|
||||
case KeyValue.MOD_TREMA: return apply_dead_char(k, '\u00A8');
|
||||
case KeyValue.MOD_CARON: return apply_dead_char(k, '\u02C7');
|
||||
case KeyValue.MOD_RING: return apply_dead_char(k, '\u02DA');
|
||||
case KeyValue.MOD_MACRON: return apply_dead_char(k, '\u00AF');
|
||||
case KeyValue.MOD_OGONEK: return apply_dead_char(k, '\u02DB');
|
||||
case KeyValue.MOD_DOT_ABOVE: return apply_dead_char(k, '\u02D9');
|
||||
case KeyValue.MOD_DOUBLE_AIGU: return apply_map_char(k, map_char_double_aigu);
|
||||
case KeyValue.MOD_ORDINAL: return apply_map_char(k, map_char_ordinal);
|
||||
case KeyValue.MOD_SUPERSCRIPT: return apply_map_char(k, map_char_superscript);
|
||||
case KeyValue.MOD_SUBSCRIPT: return apply_map_char(k, map_char_subscript);
|
||||
case KeyValue.MOD_ARROWS: return apply_map_char(k, map_char_arrows);
|
||||
case KeyValue.MOD_BOX: return apply_map_char(k, map_char_box);
|
||||
case KeyValue.MOD_SLASH: return apply_map_char(k, map_char_slash);
|
||||
case KeyValue.MOD_ARROW_RIGHT: return apply_combining(k, "\u20D7");
|
||||
case CTRL:
|
||||
case ALT:
|
||||
case META: return turn_into_keyevent(k);
|
||||
case FN: return apply_fn(k);
|
||||
case SHIFT: return apply_shift(k);
|
||||
case GRAVE: return apply_dead_char(k, '\u02CB');
|
||||
case AIGU: return apply_dead_char(k, '\u00B4');
|
||||
case CIRCONFLEXE: return apply_dead_char(k, '\u02C6');
|
||||
case TILDE: return apply_dead_char(k, '\u02DC');
|
||||
case CEDILLE: return apply_dead_char(k, '\u00B8');
|
||||
case TREMA: return apply_dead_char(k, '\u00A8');
|
||||
case CARON: return apply_dead_char(k, '\u02C7');
|
||||
case RING: return apply_dead_char(k, '\u02DA');
|
||||
case MACRON: return apply_dead_char(k, '\u00AF');
|
||||
case OGONEK: return apply_dead_char(k, '\u02DB');
|
||||
case DOT_ABOVE: return apply_dead_char(k, '\u02D9');
|
||||
case DOUBLE_AIGU: return apply_map_char(k, map_char_double_aigu);
|
||||
case ORDINAL: return apply_map_char(k, map_char_ordinal);
|
||||
case SUPERSCRIPT: return apply_map_char(k, map_char_superscript);
|
||||
case SUBSCRIPT: return apply_map_char(k, map_char_subscript);
|
||||
case ARROWS: return apply_map_char(k, map_char_arrows);
|
||||
case BOX: return apply_map_char(k, map_char_box);
|
||||
case SLASH: return apply_map_char(k, map_char_slash);
|
||||
case ARROW_RIGHT: return apply_combining(k, "\u20D7");
|
||||
default: return k;
|
||||
}
|
||||
}
|
||||
@ -246,7 +246,7 @@ class KeyModifier
|
||||
case ' ': e = KeyEvent.KEYCODE_SPACE; break;
|
||||
default: return k;
|
||||
}
|
||||
return k.withEvent(e);
|
||||
return k.withKeyevent(e);
|
||||
}
|
||||
|
||||
/** Remove placeholder keys that haven't been modified into something. */
|
||||
|
@ -6,45 +6,46 @@ import java.util.HashMap;
|
||||
|
||||
class KeyValue
|
||||
{
|
||||
/** Values for the [code] field. */
|
||||
public static enum Event
|
||||
{
|
||||
CONFIG,
|
||||
SWITCH_TEXT,
|
||||
SWITCH_NUMERIC,
|
||||
SWITCH_EMOJI,
|
||||
SWITCH_BACK_EMOJI,
|
||||
CHANGE_METHOD,
|
||||
ACTION,
|
||||
SWITCH_PROGRAMMING
|
||||
}
|
||||
|
||||
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 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;
|
||||
public static final int MOD_SLASH = -217;
|
||||
public static final int MOD_ARROW_RIGHT = -218;
|
||||
public static enum Modifier
|
||||
{
|
||||
SHIFT,
|
||||
FN,
|
||||
CTRL,
|
||||
ALT,
|
||||
META,
|
||||
DOUBLE_AIGU,
|
||||
DOT_ABOVE,
|
||||
GRAVE,
|
||||
AIGU,
|
||||
CIRCONFLEXE,
|
||||
TILDE,
|
||||
CEDILLE,
|
||||
TREMA,
|
||||
SUPERSCRIPT,
|
||||
SUBSCRIPT,
|
||||
RING,
|
||||
CARON,
|
||||
MACRON,
|
||||
ORDINAL,
|
||||
ARROWS,
|
||||
BOX,
|
||||
OGONEK,
|
||||
SLASH,
|
||||
ARROW_RIGHT
|
||||
}
|
||||
|
||||
// Behavior flags
|
||||
public static final int FLAG_LATCH = 1;
|
||||
@ -64,12 +65,13 @@ class KeyValue
|
||||
public static final int FLAG_LOCALIZED = (1 << 8);
|
||||
|
||||
// Kind flags
|
||||
public static final int KIND_CHAR = (0 << 30);
|
||||
public static final int KIND_STRING = (1 << 30);
|
||||
public static final int KIND_EVENT = (2 << 30);
|
||||
public static final int KIND_MODIFIER = (3 << 30);
|
||||
public static final int KIND_CHAR = (0 << 29);
|
||||
public static final int KIND_STRING = (1 << 29);
|
||||
public static final int KIND_KEYEVENT = (2 << 29);
|
||||
public static final int KIND_EVENT = (3 << 29);
|
||||
public static final int KIND_MODIFIER = (4 << 29);
|
||||
|
||||
public static final int KIND_FLAGS = (0b11 << 30);
|
||||
public static final int KIND_FLAGS = (0b111 << 29);
|
||||
|
||||
public final String name;
|
||||
private final String _symbol;
|
||||
@ -82,7 +84,7 @@ class KeyValue
|
||||
|
||||
public static enum Kind
|
||||
{
|
||||
Char, String, Event, Modifier
|
||||
Char, String, Keyevent, Event, Modifier
|
||||
}
|
||||
|
||||
public Kind getKind()
|
||||
@ -91,6 +93,7 @@ class KeyValue
|
||||
{
|
||||
case KIND_CHAR: return Kind.Char;
|
||||
case KIND_STRING: return Kind.String;
|
||||
case KIND_KEYEVENT: return Kind.Keyevent;
|
||||
case KIND_EVENT: return Kind.Event;
|
||||
case KIND_MODIFIER: return Kind.Modifier;
|
||||
default: throw new RuntimeException("Corrupted kind flags");
|
||||
@ -114,25 +117,28 @@ class KeyValue
|
||||
return _symbol;
|
||||
}
|
||||
|
||||
/** The char to be sent when the key is pressed.
|
||||
Defined only when [getKind() == Kind.Char]. */
|
||||
/** Defined only when [getKind() == Kind.Char]. */
|
||||
public char getChar()
|
||||
{
|
||||
return (char)_code;
|
||||
}
|
||||
|
||||
/** An Android event or one of the [EVENT_*] constants.
|
||||
Defined only when [getKind() == Kind.Event]. */
|
||||
public int getEvent()
|
||||
/** Defined only when [getKind() == Kind.Keyevent]. */
|
||||
public int getKeyevent()
|
||||
{
|
||||
return _code;
|
||||
}
|
||||
|
||||
/** Modifier activated by this key.
|
||||
Defined only when [getKind() == Kind.Modifier]. */
|
||||
public int getModifier()
|
||||
/** Defined only when [getKind() == Kind.Event]. */
|
||||
public Event getEvent()
|
||||
{
|
||||
return _code;
|
||||
return Event.values()[_code];
|
||||
}
|
||||
|
||||
/** Defined only when [getKind() == Kind.Modifier]. */
|
||||
public Modifier getModifier()
|
||||
{
|
||||
return Modifier.values()[_code];
|
||||
}
|
||||
|
||||
/* Update the char and the symbol. */
|
||||
@ -151,9 +157,9 @@ class KeyValue
|
||||
return new KeyValue(n, s, (_flags & KIND_FLAGS), _code, _flags);
|
||||
}
|
||||
|
||||
public KeyValue withEvent(int e)
|
||||
public KeyValue withKeyevent(int code)
|
||||
{
|
||||
return new KeyValue(name, _symbol, KIND_EVENT, e, _flags);
|
||||
return new KeyValue(name, _symbol, KIND_KEYEVENT, code, _flags);
|
||||
}
|
||||
|
||||
public KeyValue withFlags(int f)
|
||||
@ -209,87 +215,86 @@ class KeyValue
|
||||
addKey(name, symbol, KIND_CHAR, c, flags);
|
||||
}
|
||||
|
||||
private static void addModifierKey(String name, String symbol, int code, int extra_flags)
|
||||
private static void addModifierKey(String name, String symbol, Modifier m, int extra_flags)
|
||||
{
|
||||
assert(code >= 100 && code < 300);
|
||||
addKey(name, symbol, KIND_MODIFIER, code,
|
||||
addKey(name, symbol, KIND_MODIFIER, m.ordinal(),
|
||||
FLAG_LATCH | FLAG_SPECIAL | extra_flags);
|
||||
}
|
||||
|
||||
private static void addSpecialKey(String name, String symbol, int event, int flags)
|
||||
private static void addEventKey(String name, String symbol, Event e, int flags)
|
||||
{
|
||||
addKey(name, symbol, KIND_EVENT, event, flags | FLAG_SPECIAL);
|
||||
addKey(name, symbol, KIND_EVENT, e.ordinal(), flags | FLAG_SPECIAL);
|
||||
}
|
||||
|
||||
private static void addEventKey(String name, String symbol, int event, int flags)
|
||||
private static void addKeyeventKey(String name, String symbol, int code, int flags)
|
||||
{
|
||||
addKey(name, symbol, KIND_EVENT, event, flags);
|
||||
addKey(name, symbol, KIND_KEYEVENT, code, flags);
|
||||
}
|
||||
|
||||
static
|
||||
{
|
||||
addModifierKey("shift", "\n", // Can't write u000A because Java is stupid
|
||||
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);
|
||||
Modifier.SHIFT, FLAG_KEY_FONT | FLAG_SMALLER_FONT);
|
||||
addModifierKey("ctrl", "Ctrl", Modifier.CTRL, FLAG_SMALLER_FONT);
|
||||
addModifierKey("alt", "Alt", Modifier.ALT, FLAG_SMALLER_FONT);
|
||||
addModifierKey("accent_aigu", "\u0050", Modifier.AIGU, FLAG_KEY_FONT);
|
||||
addModifierKey("accent_caron", "\u0051", Modifier.CARON, FLAG_KEY_FONT);
|
||||
addModifierKey("accent_cedille", "\u0052", Modifier.CEDILLE, FLAG_KEY_FONT);
|
||||
addModifierKey("accent_circonflexe", "\u0053", Modifier.CIRCONFLEXE, FLAG_KEY_FONT);
|
||||
addModifierKey("accent_grave", "\u0054", Modifier.GRAVE, FLAG_KEY_FONT);
|
||||
addModifierKey("accent_macron", "\u0055", Modifier.MACRON, FLAG_KEY_FONT);
|
||||
addModifierKey("accent_ring", "\u0056", Modifier.RING, FLAG_KEY_FONT);
|
||||
addModifierKey("accent_tilde", "\u0057", Modifier.TILDE, FLAG_KEY_FONT);
|
||||
addModifierKey("accent_trema", "\u0058", Modifier.TREMA, FLAG_KEY_FONT);
|
||||
addModifierKey("accent_ogonek", "\u0059", Modifier.OGONEK, FLAG_KEY_FONT);
|
||||
addModifierKey("accent_dot_above", "\u005a", Modifier.DOT_ABOVE, FLAG_KEY_FONT);
|
||||
addModifierKey("accent_double_aigu", "\u005b", Modifier.DOUBLE_AIGU, FLAG_KEY_FONT);
|
||||
addModifierKey("accent_slash", "\134", // Can't write u005c
|
||||
MOD_SLASH, FLAG_KEY_FONT);
|
||||
addModifierKey("accent_arrow_right", "\u005d", MOD_ARROW_RIGHT, 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);
|
||||
Modifier.SLASH, FLAG_KEY_FONT);
|
||||
addModifierKey("accent_arrow_right", "\u005d", Modifier.ARROW_RIGHT, FLAG_KEY_FONT);
|
||||
addModifierKey("superscript", "Sup", Modifier.SUPERSCRIPT, FLAG_SMALLER_FONT);
|
||||
addModifierKey("subscript", "Sub", Modifier.SUBSCRIPT, FLAG_SMALLER_FONT);
|
||||
addModifierKey("ordinal", "Ord", Modifier.ORDINAL, FLAG_SMALLER_FONT);
|
||||
addModifierKey("arrows", "Arr", Modifier.ARROWS, FLAG_SMALLER_FONT);
|
||||
addModifierKey("box", "Box", Modifier.BOX, FLAG_SMALLER_FONT);
|
||||
addModifierKey("fn", "Fn", Modifier.FN, FLAG_SMALLER_FONT);
|
||||
addModifierKey("meta", "Meta", Modifier.META, FLAG_SMALLER_FONT);
|
||||
|
||||
addSpecialKey("config", "\u0004", EVENT_CONFIG, FLAG_KEY_FONT | FLAG_SMALLER_FONT);
|
||||
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, 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
|
||||
addEventKey("config", "\u0004", Event.CONFIG, FLAG_KEY_FONT | FLAG_SMALLER_FONT);
|
||||
addEventKey("switch_text", "ABC", Event.SWITCH_TEXT, FLAG_SMALLER_FONT);
|
||||
addEventKey("switch_numeric", "123+", Event.SWITCH_NUMERIC, FLAG_SMALLER_FONT);
|
||||
addEventKey("switch_emoji", "\u0001" , Event.SWITCH_EMOJI, FLAG_KEY_FONT | FLAG_SMALLER_FONT);
|
||||
addEventKey("switch_back_emoji", "ABC", Event.SWITCH_BACK_EMOJI, 0);
|
||||
addEventKey("switch_programming", "Prog", Event.SWITCH_PROGRAMMING, FLAG_SMALLER_FONT);
|
||||
addEventKey("change_method", "\u0009", Event.CHANGE_METHOD, FLAG_KEY_FONT | FLAG_SMALLER_FONT);
|
||||
addEventKey("action", "Action", Event.ACTION, FLAG_SMALLER_FONT); // Will always be replaced
|
||||
|
||||
addEventKey("esc", "Esc", KeyEvent.KEYCODE_ESCAPE, FLAG_SMALLER_FONT);
|
||||
addEventKey("enter", "\u000E", KeyEvent.KEYCODE_ENTER, FLAG_KEY_FONT);
|
||||
addEventKey("up", "\u0005", KeyEvent.KEYCODE_DPAD_UP, FLAG_KEY_FONT | FLAG_PRECISE_REPEAT);
|
||||
addEventKey("right", "\u0006", KeyEvent.KEYCODE_DPAD_RIGHT, FLAG_KEY_FONT | FLAG_PRECISE_REPEAT);
|
||||
addEventKey("down", "\u0007", KeyEvent.KEYCODE_DPAD_DOWN, FLAG_KEY_FONT | FLAG_PRECISE_REPEAT);
|
||||
addEventKey("left", "\u0008", KeyEvent.KEYCODE_DPAD_LEFT, FLAG_KEY_FONT | FLAG_PRECISE_REPEAT);
|
||||
addEventKey("page_up", "\u0002", KeyEvent.KEYCODE_PAGE_UP, FLAG_KEY_FONT);
|
||||
addEventKey("page_down", "\u0003", KeyEvent.KEYCODE_PAGE_DOWN, FLAG_KEY_FONT);
|
||||
addEventKey("home", "\u000B", KeyEvent.KEYCODE_MOVE_HOME, FLAG_KEY_FONT);
|
||||
addEventKey("end", "\u000C", KeyEvent.KEYCODE_MOVE_END, FLAG_KEY_FONT);
|
||||
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, 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);
|
||||
addKeyeventKey("esc", "Esc", KeyEvent.KEYCODE_ESCAPE, FLAG_SMALLER_FONT);
|
||||
addKeyeventKey("enter", "\u000E", KeyEvent.KEYCODE_ENTER, FLAG_KEY_FONT);
|
||||
addKeyeventKey("up", "\u0005", KeyEvent.KEYCODE_DPAD_UP, FLAG_KEY_FONT | FLAG_PRECISE_REPEAT);
|
||||
addKeyeventKey("right", "\u0006", KeyEvent.KEYCODE_DPAD_RIGHT, FLAG_KEY_FONT | FLAG_PRECISE_REPEAT);
|
||||
addKeyeventKey("down", "\u0007", KeyEvent.KEYCODE_DPAD_DOWN, FLAG_KEY_FONT | FLAG_PRECISE_REPEAT);
|
||||
addKeyeventKey("left", "\u0008", KeyEvent.KEYCODE_DPAD_LEFT, FLAG_KEY_FONT | FLAG_PRECISE_REPEAT);
|
||||
addKeyeventKey("page_up", "\u0002", KeyEvent.KEYCODE_PAGE_UP, FLAG_KEY_FONT);
|
||||
addKeyeventKey("page_down", "\u0003", KeyEvent.KEYCODE_PAGE_DOWN, FLAG_KEY_FONT);
|
||||
addKeyeventKey("home", "\u000B", KeyEvent.KEYCODE_MOVE_HOME, FLAG_KEY_FONT);
|
||||
addKeyeventKey("end", "\u000C", KeyEvent.KEYCODE_MOVE_END, FLAG_KEY_FONT);
|
||||
addKeyeventKey("backspace", "\u0011", KeyEvent.KEYCODE_DEL, FLAG_KEY_FONT);
|
||||
addKeyeventKey("delete", "\u0010", KeyEvent.KEYCODE_FORWARD_DEL, FLAG_KEY_FONT);
|
||||
addKeyeventKey("insert", "Ins", KeyEvent.KEYCODE_INSERT, FLAG_SMALLER_FONT);
|
||||
addKeyeventKey("f1", "F1", KeyEvent.KEYCODE_F1, 0);
|
||||
addKeyeventKey("f2", "F2", KeyEvent.KEYCODE_F2, 0);
|
||||
addKeyeventKey("f3", "F3", KeyEvent.KEYCODE_F3, 0);
|
||||
addKeyeventKey("f4", "F4", KeyEvent.KEYCODE_F4, 0);
|
||||
addKeyeventKey("f5", "F5", KeyEvent.KEYCODE_F5, 0);
|
||||
addKeyeventKey("f6", "F6", KeyEvent.KEYCODE_F6, 0);
|
||||
addKeyeventKey("f7", "F7", KeyEvent.KEYCODE_F7, 0);
|
||||
addKeyeventKey("f8", "F8", KeyEvent.KEYCODE_F8, 0);
|
||||
addKeyeventKey("f9", "F9", KeyEvent.KEYCODE_F9, 0);
|
||||
addKeyeventKey("f10", "F10", KeyEvent.KEYCODE_F10, 0);
|
||||
addKeyeventKey("f11", "F11", KeyEvent.KEYCODE_F11, FLAG_SMALLER_FONT);
|
||||
addKeyeventKey("f12", "F12", KeyEvent.KEYCODE_F12, FLAG_SMALLER_FONT);
|
||||
addKeyeventKey("tab", "\u000F", KeyEvent.KEYCODE_TAB, FLAG_KEY_FONT | FLAG_SMALLER_FONT);
|
||||
|
||||
addCharKey("\\t", "\\t", '\t', 0); // Send the tab character
|
||||
addCharKey("space", "\r", ' ', FLAG_KEY_FONT);
|
||||
|
@ -300,7 +300,7 @@ public class Keyboard2 extends InputMethodService
|
||||
{
|
||||
if (key != null
|
||||
&& key.getKind() == KeyValue.Kind.Event
|
||||
&& key.getEvent() == KeyValue.EVENT_SWITCH_PROGRAMMING)
|
||||
&& key.getEvent() == KeyValue.Event.SWITCH_PROGRAMMING)
|
||||
return KeyValue.getKeyByName("switch_text");
|
||||
return key;
|
||||
}
|
||||
|
@ -32,19 +32,18 @@ public final class Pointers implements Handler.Callback
|
||||
/** When [skip_latched] is true, don't take flags of latched keys into account. */
|
||||
private Modifiers getModifiers(boolean skip_latched)
|
||||
{
|
||||
int size = _ptrs.size();
|
||||
int[] mods = new int[size];
|
||||
for (int i = 0; i < size; i++)
|
||||
int n_ptrs = _ptrs.size();
|
||||
KeyValue.Modifier[] mods = new KeyValue.Modifier[n_ptrs];
|
||||
int n_mods = 0;
|
||||
for (int i = 0; i < n_ptrs; i++)
|
||||
{
|
||||
Pointer p = _ptrs.get(i);
|
||||
mods[i] =
|
||||
((skip_latched && p.pointerId == -1
|
||||
&& (p.flags & KeyValue.FLAG_LOCKED) == 0)
|
||||
|| p.value == null
|
||||
|| p.value.getKind() != KeyValue.Kind.Modifier)
|
||||
? 0 : p.value.getModifier();
|
||||
if (p.value != null && p.value.getKind() == KeyValue.Kind.Modifier
|
||||
&& !(skip_latched && p.pointerId == -1
|
||||
&& (p.flags & KeyValue.FLAG_LOCKED) == 0))
|
||||
mods[n_mods++] = p.value.getModifier();
|
||||
}
|
||||
return Modifiers.ofArray(mods);
|
||||
return Modifiers.ofArray(mods, n_mods);
|
||||
}
|
||||
|
||||
public void clear()
|
||||
@ -386,12 +385,15 @@ public final class Pointers implements Handler.Callback
|
||||
Sorted in the order they should be evaluated. */
|
||||
public static final class Modifiers
|
||||
{
|
||||
private final int[] _mods;
|
||||
private final KeyValue.Modifier[] _mods;
|
||||
private final int _size;
|
||||
|
||||
private Modifiers(int[] m, int s) { _mods = m; _size = s; }
|
||||
private Modifiers(KeyValue.Modifier[] m, int s)
|
||||
{
|
||||
_mods = m; _size = s;
|
||||
}
|
||||
|
||||
public int get(int i) { return _mods[i]; }
|
||||
public KeyValue.Modifier get(int i) { return _mods[_size - 1 - i]; }
|
||||
public int size() { return _size; }
|
||||
|
||||
@Override
|
||||
@ -402,20 +404,20 @@ public final class Pointers implements Handler.Callback
|
||||
return Arrays.equals(_mods, ((Modifiers)obj)._mods);
|
||||
}
|
||||
|
||||
public static final Modifiers EMPTY = new Modifiers(new int[0], 0);
|
||||
public static final Modifiers EMPTY =
|
||||
new Modifiers(new KeyValue.Modifier[0], 0);
|
||||
|
||||
protected static Modifiers ofArray(int[] mods)
|
||||
protected static Modifiers ofArray(KeyValue.Modifier[] mods, int size)
|
||||
{
|
||||
int size = mods.length;
|
||||
// Sort and remove duplicates and [0]s.
|
||||
// Sort and remove duplicates and nulls.
|
||||
if (size > 1)
|
||||
{
|
||||
Arrays.sort(mods);
|
||||
Arrays.sort(mods, 0, size);
|
||||
int j = 0;
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
int m = mods[i];
|
||||
if (m != 0 && (i + 1 >= size || m != mods[i + 1]))
|
||||
KeyValue.Modifier m = mods[i];
|
||||
if (m != null && (i + 1 >= size || m != mods[i + 1]))
|
||||
{
|
||||
mods[j] = m;
|
||||
j++;
|
||||
|
Loading…
Reference in New Issue
Block a user