diff --git a/res/xml/azerty.xml b/res/xml/azerty.xml index c1347f9..fb59638 100644 --- a/res/xml/azerty.xml +++ b/res/xml/azerty.xml @@ -22,7 +22,7 @@ - + diff --git a/res/xml/qwerty.xml b/res/xml/qwerty.xml index 0e26e9c..c61c086 100644 --- a/res/xml/qwerty.xml +++ b/res/xml/qwerty.xml @@ -21,7 +21,7 @@ - + diff --git a/srcs/juloo.keyboard2/KeyModifier.java b/srcs/juloo.keyboard2/KeyModifier.java index d14d254..969cc88 100644 --- a/srcs/juloo.keyboard2/KeyModifier.java +++ b/srcs/juloo.keyboard2/KeyModifier.java @@ -2,6 +2,7 @@ package juloo.keyboard2; import android.util.SparseArray; import android.view.KeyCharacterMap; +import android.view.KeyEvent; import java.util.HashMap; class KeyModifier @@ -19,24 +20,26 @@ class KeyModifier KeyValue r = ks.get(flags); if (r != null) // Found in cache return r; - char c = handleChar(k.char_, flags); - if (c == k.char_) // Don't override the symbol if the char didn't change - r = k; - else - r = k.withCharAndSymbol(String.valueOf(c), c); + if ((r = handleChar(k, flags)) != null) ; + else if ((r = handleFn(k, flags)) != null) ; + else r = k; ks.put(flags, r); return r; } - private static char handleChar(char c, int flags) + /* Returns [null] if had no effect. */ + private static KeyValue handleChar(KeyValue k, int flags) { + char c = k.char_; if (c == KeyValue.CHAR_NONE) - return c; + return null; if ((flags & KeyValue.FLAG_SHIFT) != 0) // Shift c = Character.toUpperCase(c); if ((flags & KeyValue.FLAGS_ACCENTS) != 0) // Accents, after shift is applied c = handleAccentChar(c, flags); - return c; + if (c == k.char_) + return null; + return k.withCharAndSymbol(String.valueOf(c), c); } private static char handleAccentChar(char c, int flags) @@ -56,6 +59,31 @@ class KeyModifier return (r == 0) ? c : r; } + private static KeyValue handleFn(KeyValue k, int flags) + { + if ((flags & KeyValue.FLAG_FN) == 0) + return null; + switch (k.char_) + { + case '1': return makeFnKey("F1", KeyEvent.KEYCODE_F1); + case '2': return makeFnKey("F2", KeyEvent.KEYCODE_F2); + case '3': return makeFnKey("F3", KeyEvent.KEYCODE_F3); + case '4': return makeFnKey("F4", KeyEvent.KEYCODE_F4); + case '5': return makeFnKey("F5", KeyEvent.KEYCODE_F5); + case '6': return makeFnKey("F6", KeyEvent.KEYCODE_F6); + case '7': return makeFnKey("F7", KeyEvent.KEYCODE_F7); + case '8': return makeFnKey("F8", KeyEvent.KEYCODE_F8); + case '9': return makeFnKey("F9", KeyEvent.KEYCODE_F9); + case '0': return makeFnKey("F10", KeyEvent.KEYCODE_F10); + default: return null; + } + } + + private static KeyValue makeFnKey(String symbol, int eventCode) + { + return new KeyValue(symbol, symbol, KeyValue.CHAR_NONE, eventCode, 0); + } + /* Lookup the cache entry for a key. Create it needed. */ private static SparseArray cacheEntry(KeyValue k) { diff --git a/srcs/juloo.keyboard2/KeyValue.java b/srcs/juloo.keyboard2/KeyValue.java index 4c4a5a0..a62ec07 100644 --- a/srcs/juloo.keyboard2/KeyValue.java +++ b/srcs/juloo.keyboard2/KeyValue.java @@ -23,6 +23,7 @@ class KeyValue public static final int FLAG_NOREPEAT = (1 << 5); public static final int FLAG_NOCHAR = (1 << 6); public static final int FLAG_LOCKED = (1 << 8); + public static final int FLAG_FN = (1 << 9); public static final int FLAG_KEY_FONT = (1 << 12); @@ -49,7 +50,7 @@ class KeyValue private static HashMap keys = new HashMap(); - protected KeyValue(String n, String s, char c, int e, int f) + public KeyValue(String n, String s, char c, int e, int f) { name = n; symbol = s; @@ -102,6 +103,7 @@ class KeyValue addModifierKey("accent4", "\u02DC", FLAG_ACCENT4); addModifierKey("accent5", "\u00B8", FLAG_ACCENT5); addModifierKey("accent6", "\u00A8", FLAG_ACCENT6); + addModifierKey("fn", "Fn", FLAG_FN); addCharKey('a', KeyEvent.KEYCODE_A); addCharKey('b', KeyEvent.KEYCODE_B);