forked from extern/Unexpected-Keyboard
Improve the numeric keyboard
This commit is contained in:
parent
3fbc35135e
commit
8fb89c5c71
@ -3,11 +3,11 @@
|
|||||||
<row>
|
<row>
|
||||||
<key width="0.75" key0="esc" key2="~" key4="!" />
|
<key width="0.75" key0="esc" key2="~" key4="!" />
|
||||||
<key width="0.75" key0="(" key2="[" key4="{" />
|
<key width="0.75" key0="(" key2="[" key4="{" />
|
||||||
<key key0="7" key2="<" key3="home" />
|
<key key0="7" key3="<" key4=">" />
|
||||||
<key key0="8" />
|
<key key0="8" key2="∞" />
|
||||||
<key key0="9" key2="page_up" key3=">" />
|
<key key0="9" key2="π" />
|
||||||
<key width="0.75" key0="*" />
|
<key width="0.75" key0="*" key1="√" key2="×" />
|
||||||
<key width="0.75" key0="/" key1="%" key3=":" />
|
<key width="0.75" key0="/" key1="%" key3="÷" />
|
||||||
</row>
|
</row>
|
||||||
<row>
|
<row>
|
||||||
<key width="0.75" key0="tab" key1=";" key2="|" key4="\\" />
|
<key width="0.75" key0="tab" key1=";" key2="|" key4="\\" />
|
||||||
@ -15,14 +15,14 @@
|
|||||||
<key key0="4" />
|
<key key0="4" />
|
||||||
<key key0="5" key1="up" key2="right" key3="left" key4="down" />
|
<key key0="5" key1="up" key2="right" key3="left" key4="down" />
|
||||||
<key key0="6" />
|
<key key0="6" />
|
||||||
<key width="0.75" key0="+" key2="$" />
|
<key width="0.75" key0="+" key1="Σ" key2="$" />
|
||||||
<key width="0.75" key0="-" key2="^" />
|
<key width="0.75" key0="-" key2="^" />
|
||||||
</row>
|
</row>
|
||||||
<row>
|
<row>
|
||||||
<key shift="0.35" width="1.15" key0="shift" key4="alt" />
|
<key shift="0.35" width="1.15" key0="shift" key2="fn" key4="alt" />
|
||||||
<key key0="1" key3="end" />
|
<key key0="1" key1="superscript" key3="subscript" />
|
||||||
<key key0="2" />
|
<key key0="2" />
|
||||||
<key key0="3" key4="page_down" />
|
<key key0="3" />
|
||||||
<key width="1.15" key0="backspace" key2="delete" />
|
<key width="1.15" key0="backspace" key2="delete" />
|
||||||
</row>
|
</row>
|
||||||
<row height="0.95">
|
<row height="0.95">
|
||||||
@ -30,6 +30,6 @@
|
|||||||
<key width="1.5" key0="0" />
|
<key width="1.5" key0="0" />
|
||||||
<key width="0.75" key0="." key2="," />
|
<key width="0.75" key0="." key2="," />
|
||||||
<key width="0.75" key0="space" key1=""" key2="'" key4="_" />
|
<key width="0.75" key0="space" key1=""" key2="'" key4="_" />
|
||||||
<key width="1.5" key0="enter" key3="=" />
|
<key width="1.5" key0="enter" key2="±" key3="=" />
|
||||||
</row>
|
</row>
|
||||||
</keyboard>
|
</keyboard>
|
||||||
|
@ -20,31 +20,43 @@ class KeyModifier
|
|||||||
KeyValue r = ks.get(flags);
|
KeyValue r = ks.get(flags);
|
||||||
if (r != null) // Found in cache
|
if (r != null) // Found in cache
|
||||||
return r;
|
return r;
|
||||||
if ((r = handleChar(k, flags)) != null) ;
|
r = k;
|
||||||
else if ((r = handleFn(k, flags)) != null) ;
|
r = handleFn(r, flags);
|
||||||
else r = k;
|
r = handleShift(r, flags);
|
||||||
|
r = handleAccents(r, flags);
|
||||||
ks.put(flags, r);
|
ks.put(flags, r);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Returns [null] if had no effect. */
|
private static KeyValue handleAccents(KeyValue k, int flags)
|
||||||
private static KeyValue handleChar(KeyValue k, int flags)
|
|
||||||
{
|
{
|
||||||
char c = k.char_;
|
if (k.char_ == KeyValue.CHAR_NONE || (flags & KeyValue.FLAGS_ACCENTS) == 0)
|
||||||
if (c == KeyValue.CHAR_NONE)
|
return k;
|
||||||
return null;
|
char c = handleAccentChar(k.char_, flags);
|
||||||
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);
|
|
||||||
if (c == 0 || c == k.char_)
|
if (c == 0 || c == k.char_)
|
||||||
return null;
|
return k;
|
||||||
return k.withCharAndSymbol(String.valueOf(c), c);
|
return k.withCharAndSymbol(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static KeyValue handleShift(KeyValue k, int flags)
|
||||||
|
{
|
||||||
|
if ((flags & KeyValue.FLAG_SHIFT) == 0)
|
||||||
|
return k;
|
||||||
|
char c = k.char_;
|
||||||
|
if (k.char_ != KeyValue.CHAR_NONE)
|
||||||
|
c = Character.toUpperCase(c);
|
||||||
|
if (c == k.char_) // More rules if toUpperCase() did nothing
|
||||||
|
switch (k.symbol)
|
||||||
|
{
|
||||||
|
case "→": c = '⇒'; break;
|
||||||
|
case "←": c = '⇐'; break;
|
||||||
|
default: return k;
|
||||||
|
}
|
||||||
|
return k.withCharAndSymbol(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static char handleAccentChar(char c, int flags)
|
private static char handleAccentChar(char c, int flags)
|
||||||
{
|
{
|
||||||
char accent;
|
|
||||||
switch ((flags & KeyValue.FLAGS_ACCENTS))
|
switch ((flags & KeyValue.FLAGS_ACCENTS))
|
||||||
{
|
{
|
||||||
case KeyValue.FLAG_ACCENT1:
|
case KeyValue.FLAG_ACCENT1:
|
||||||
@ -58,6 +70,32 @@ class KeyModifier
|
|||||||
default: return (char)KeyCharacterMap.getDeadChar('\u00B4', c);
|
default: return (char)KeyCharacterMap.getDeadChar('\u00B4', c);
|
||||||
}
|
}
|
||||||
case KeyValue.FLAG_ACCENT3:
|
case KeyValue.FLAG_ACCENT3:
|
||||||
|
switch (c)
|
||||||
|
{
|
||||||
|
case '*': return '°';
|
||||||
|
default: return (char)KeyCharacterMap.getDeadChar('\u02C6', c);
|
||||||
|
}
|
||||||
|
case KeyValue.FLAG_ACCENT4:
|
||||||
|
return (char)KeyCharacterMap.getDeadChar('\u02DC', c);
|
||||||
|
case KeyValue.FLAG_ACCENT5:
|
||||||
|
switch (c)
|
||||||
|
{
|
||||||
|
case 'u': return 'µ';
|
||||||
|
case '"': return '„';
|
||||||
|
case '-': return '¬';
|
||||||
|
case 'a': return 'æ';
|
||||||
|
case 'o': return 'œ';
|
||||||
|
default: return (char)KeyCharacterMap.getDeadChar('\u00B8', c);
|
||||||
|
}
|
||||||
|
case KeyValue.FLAG_ACCENT6:
|
||||||
|
switch (c)
|
||||||
|
{
|
||||||
|
case '-': return '÷';
|
||||||
|
case '?': return '¿';
|
||||||
|
case '!': return '¡';
|
||||||
|
default: return (char)KeyCharacterMap.getDeadChar('\u00A8', c);
|
||||||
|
}
|
||||||
|
case KeyValue.FLAG_ACCENT_SUPERSCRIPT:
|
||||||
switch (c)
|
switch (c)
|
||||||
{
|
{
|
||||||
case '1': return '¹';
|
case '1': return '¹';
|
||||||
@ -70,12 +108,16 @@ class KeyModifier
|
|||||||
case '8': return '⁸';
|
case '8': return '⁸';
|
||||||
case '9': return '⁹';
|
case '9': return '⁹';
|
||||||
case '0': return '⁰';
|
case '0': return '⁰';
|
||||||
case '*': return '°';
|
case 'i': return 'ⁱ';
|
||||||
default: return (char)KeyCharacterMap.getDeadChar('\u02C6', c);
|
case '+': return '⁺';
|
||||||
|
case '-': return '⁻';
|
||||||
|
case '=': return '⁼';
|
||||||
|
case '(': return '⁽';
|
||||||
|
case ')': return '⁾';
|
||||||
|
case 'n': return 'ⁿ';
|
||||||
|
default: return c;
|
||||||
}
|
}
|
||||||
case KeyValue.FLAG_ACCENT4:
|
case KeyValue.FLAG_ACCENT_SUBSCRIPT:
|
||||||
return (char)KeyCharacterMap.getDeadChar('\u02DC', c);
|
|
||||||
case KeyValue.FLAG_ACCENT5:
|
|
||||||
switch (c)
|
switch (c)
|
||||||
{
|
{
|
||||||
case '1': return '₁';
|
case '1': return '₁';
|
||||||
@ -88,18 +130,16 @@ class KeyModifier
|
|||||||
case '8': return '₈';
|
case '8': return '₈';
|
||||||
case '9': return '₉';
|
case '9': return '₉';
|
||||||
case '0': return '₀';
|
case '0': return '₀';
|
||||||
case 'u': return 'µ';
|
case '+': return '₊';
|
||||||
case '"': return '„';
|
case '-': return '₋';
|
||||||
case '-': return '¬';
|
case '=': return '₌';
|
||||||
default: return (char)KeyCharacterMap.getDeadChar('\u00B8', c);
|
case '(': return '₍';
|
||||||
}
|
case ')': return '₎';
|
||||||
case KeyValue.FLAG_ACCENT6:
|
case 'e': return 'ₑ';
|
||||||
switch (c)
|
case 'a': return 'ₐ';
|
||||||
{
|
case 'x': return 'ₓ';
|
||||||
case '-': return '÷';
|
case 'o': return 'ₒ';
|
||||||
case '?': return '¿';
|
default: return c;
|
||||||
case '!': return '¡';
|
|
||||||
default: return (char)KeyCharacterMap.getDeadChar('\u00A8', c);
|
|
||||||
}
|
}
|
||||||
default: return c; // Can't happen
|
default: return c; // Can't happen
|
||||||
}
|
}
|
||||||
@ -108,7 +148,7 @@ class KeyModifier
|
|||||||
private static KeyValue handleFn(KeyValue k, int flags)
|
private static KeyValue handleFn(KeyValue k, int flags)
|
||||||
{
|
{
|
||||||
if ((flags & KeyValue.FLAG_FN) == 0)
|
if ((flags & KeyValue.FLAG_FN) == 0)
|
||||||
return null;
|
return k;
|
||||||
String name;
|
String name;
|
||||||
switch (k.name)
|
switch (k.name)
|
||||||
{
|
{
|
||||||
@ -126,7 +166,9 @@ class KeyModifier
|
|||||||
case "down": name = "page_down"; break;
|
case "down": name = "page_down"; break;
|
||||||
case "left": name = "home"; break;
|
case "left": name = "home"; break;
|
||||||
case "right": name = "end"; break;
|
case "right": name = "end"; break;
|
||||||
default: return null;
|
case ">": name = "→"; break;
|
||||||
|
case "<": name = "←"; break;
|
||||||
|
default: return k;
|
||||||
}
|
}
|
||||||
return KeyValue.getKeyByName(name);
|
return KeyValue.getKeyByName(name);
|
||||||
}
|
}
|
||||||
|
@ -39,9 +39,12 @@ class KeyValue
|
|||||||
public static final int FLAG_ACCENT4 = (1 << 19); // Tilde
|
public static final int FLAG_ACCENT4 = (1 << 19); // Tilde
|
||||||
public static final int FLAG_ACCENT5 = (1 << 20); // Cédille
|
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_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 FLAGS_ACCENTS = FLAG_ACCENT1 | FLAG_ACCENT2 |
|
public static final int FLAGS_ACCENTS = FLAG_ACCENT1 | FLAG_ACCENT2 |
|
||||||
FLAG_ACCENT3 | FLAG_ACCENT4 | FLAG_ACCENT5 | FLAG_ACCENT6;
|
FLAG_ACCENT3 | FLAG_ACCENT4 | FLAG_ACCENT5 | FLAG_ACCENT6 |
|
||||||
|
FLAG_ACCENT_SUPERSCRIPT | FLAG_ACCENT_SUBSCRIPT;
|
||||||
|
|
||||||
public final String name;
|
public final String name;
|
||||||
public final String symbol;
|
public final String symbol;
|
||||||
@ -49,6 +52,12 @@ class KeyValue
|
|||||||
public final int eventCode;
|
public final int eventCode;
|
||||||
public final int flags;
|
public final int flags;
|
||||||
|
|
||||||
|
/* Update the char and the symbol. */
|
||||||
|
public KeyValue withCharAndSymbol(char c)
|
||||||
|
{
|
||||||
|
return withCharAndSymbol(String.valueOf(c), c);
|
||||||
|
}
|
||||||
|
|
||||||
public KeyValue withCharAndSymbol(String s, char c)
|
public KeyValue withCharAndSymbol(String s, char c)
|
||||||
{
|
{
|
||||||
return new KeyValue(name, s, c, eventCode, flags);
|
return new KeyValue(name, s, c, eventCode, flags);
|
||||||
@ -67,7 +76,12 @@ class KeyValue
|
|||||||
|
|
||||||
public static KeyValue getKeyByName(String name)
|
public static KeyValue getKeyByName(String name)
|
||||||
{
|
{
|
||||||
return (KeyValue.keys.get(name));
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void addKey(String name, String symbol, char c, int event, int flags)
|
private static void addKey(String name, String symbol, char c, int event, int flags)
|
||||||
@ -117,6 +131,8 @@ class KeyValue
|
|||||||
addModifierKey("accent_tilde", "◌̃", FLAG_ACCENT4);
|
addModifierKey("accent_tilde", "◌̃", FLAG_ACCENT4);
|
||||||
addModifierKey("accent_cedille", "◌̧", FLAG_ACCENT5);
|
addModifierKey("accent_cedille", "◌̧", FLAG_ACCENT5);
|
||||||
addModifierKey("accent_trema", "◌̈", FLAG_ACCENT6);
|
addModifierKey("accent_trema", "◌̈", FLAG_ACCENT6);
|
||||||
|
addModifierKey("superscript", "◌͆", FLAG_ACCENT_SUPERSCRIPT);
|
||||||
|
addModifierKey("subscript", "◌̺", FLAG_ACCENT_SUBSCRIPT);
|
||||||
addModifierKey("fn", "Fn", FLAG_FN);
|
addModifierKey("fn", "Fn", FLAG_FN);
|
||||||
|
|
||||||
addCharKey('a', KeyEvent.KEYCODE_A);
|
addCharKey('a', KeyEvent.KEYCODE_A);
|
||||||
|
Loading…
Reference in New Issue
Block a user