forked from extern/Unexpected-Keyboard
Add function keys
Add the Fn modifier that change the digits into F1 to F10.
This commit is contained in:
parent
2f8eae628f
commit
471375d50c
@ -22,7 +22,7 @@
|
||||
<key key0="j" key2="accent6" key3="^" />
|
||||
<key key0="k" key2="£" key3="$" key4="accent3" />
|
||||
<key key0="l" key1="accent4" key2="%" />
|
||||
<key key0="m" key2="µ" key4="*" />
|
||||
<key key0="m" key1="fn" key2="µ" key4="*" />
|
||||
</row>
|
||||
<row>
|
||||
<key width="2.0" key0="shift" />
|
||||
|
@ -21,7 +21,7 @@
|
||||
<key key0="h" key2="=" key3="+" />
|
||||
<key key0="j" key4="}" key3="{" />
|
||||
<key key0="k" key4="]" key3="[" />
|
||||
<key key0="l" key2="|" key3="\\" />
|
||||
<key key0="l" key1="fn" key2="|" key3="\\" />
|
||||
</row>
|
||||
<row>
|
||||
<key width="1.5" key0="shift" />
|
||||
|
@ -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<KeyValue> cacheEntry(KeyValue k)
|
||||
{
|
||||
|
@ -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<String, KeyValue> keys = new HashMap<String, KeyValue>();
|
||||
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user