mirror of
https://github.com/Julow/Unexpected-Keyboard.git
synced 2025-06-21 02:09:09 +02:00
Make key symbol smaller when 2 characters long or more
This was the case for string keys but not for macros or keys with custom symbols.
This commit is contained in:
parent
b7d1508d7b
commit
55cb5f5315
@ -233,7 +233,8 @@ public final class KeyValue implements Comparable<KeyValue>
|
||||
/* Update the char and the symbol. */
|
||||
public KeyValue withChar(char c)
|
||||
{
|
||||
return new KeyValue(String.valueOf(c), Kind.Char, c, getFlags());
|
||||
return new KeyValue(String.valueOf(c), Kind.Char, c,
|
||||
getFlags() & ~(FLAG_KEY_FONT | FLAG_SMALLER_FONT));
|
||||
}
|
||||
|
||||
public KeyValue withKeyevent(int code)
|
||||
@ -248,6 +249,7 @@ public final class KeyValue implements Comparable<KeyValue>
|
||||
|
||||
public KeyValue withSymbol(String symbol)
|
||||
{
|
||||
int flags = getFlags() & ~(FLAG_KEY_FONT | FLAG_SMALLER_FONT);
|
||||
switch (getKind())
|
||||
{
|
||||
case Char:
|
||||
@ -259,11 +261,13 @@ public final class KeyValue implements Comparable<KeyValue>
|
||||
case Modifier:
|
||||
case Editing:
|
||||
case Placeholder:
|
||||
return new KeyValue(symbol, _code, _code, getFlags());
|
||||
if (symbol.length() > 1)
|
||||
flags |= FLAG_SMALLER_FONT;
|
||||
return new KeyValue(symbol, _code, _code, flags);
|
||||
case Macro:
|
||||
return makeMacro(symbol, getMacro(), 0);
|
||||
return makeMacro(symbol, getMacro(), flags);
|
||||
default:
|
||||
return makeMacro(symbol, new KeyValue[]{ this }, 0);
|
||||
return makeMacro(symbol, new KeyValue[]{ this }, flags);
|
||||
}
|
||||
}
|
||||
|
||||
@ -477,6 +481,8 @@ public final class KeyValue implements Comparable<KeyValue>
|
||||
|
||||
public static KeyValue makeMacro(String symbol, KeyValue[] keys, int flags)
|
||||
{
|
||||
if (symbol.length() > 1)
|
||||
flags |= FLAG_SMALLER_FONT;
|
||||
return new KeyValue(new Macro(keys, symbol), Kind.Macro, 0, flags);
|
||||
}
|
||||
|
||||
|
@ -93,7 +93,7 @@ public class KeyValueParserTest
|
||||
public void parse_key_event() throws Exception
|
||||
{
|
||||
Utils.parse("a:keyevent:85", KeyValue.keyeventKey("a", 85, 0));
|
||||
Utils.parse("symbol:keyevent:85", KeyValue.keyeventKey("symbol", 85, 0));
|
||||
Utils.parse("symbol:keyevent:85", KeyValue.keyeventKey("symbol", 85, KeyValue.FLAG_SMALLER_FONT));
|
||||
Utils.parse("macro:keyevent:85,abc", KeyValue.makeMacro("macro", new KeyValue[]{
|
||||
KeyValue.keyeventKey("", 85, 0),
|
||||
KeyValue.makeStringKey("abc")
|
||||
@ -112,7 +112,7 @@ public class KeyValueParserTest
|
||||
Utils.parse(":str:'Foo'", KeyValue.makeStringKey("Foo"));
|
||||
Utils.parse(":str flags='dim':'Foo'", KeyValue.makeStringKey("Foo", KeyValue.FLAG_SECONDARY));
|
||||
Utils.parse(":str symbol='Symbol':'Foo'", KeyValue.makeStringKey("Foo").withSymbol("Symbol"));
|
||||
Utils.parse(":str symbol='Symbol' flags='dim':'f'", KeyValue.makeStringKey("f").withSymbol("Symbol").withFlags(KeyValue.FLAG_SECONDARY));
|
||||
Utils.parse(":str symbol='Symbol' flags='dim':'f'", KeyValue.makeStringKey("f").withSymbol("Symbol").withFlags(KeyValue.FLAG_SECONDARY | KeyValue.FLAG_SMALLER_FONT));
|
||||
Utils.parse(":str flags='dim,small':'Foo'", KeyValue.makeStringKey("Foo", KeyValue.FLAG_SECONDARY | KeyValue.FLAG_SMALLER_FONT));
|
||||
Utils.parse(":str flags=',,':'Foo'", KeyValue.makeStringKey("Foo")); // Unintentional
|
||||
Utils.expect_error(":unknown:Foo"); // Unknown kind
|
||||
|
@ -1,5 +1,6 @@
|
||||
package juloo.keyboard2;
|
||||
|
||||
import android.view.KeyEvent;
|
||||
import juloo.keyboard2.KeyValue;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
@ -13,6 +14,12 @@ public class KeyValueTest
|
||||
{
|
||||
assertEquals(KeyValue.makeStringKey("Foo").withSymbol("Symbol"),
|
||||
KeyValue.makeMacro("Symbol", new KeyValue[] { KeyValue.makeStringKey("Foo") }, 0));
|
||||
assertEquals(KeyValue.getSpecialKeyByName("tab"),
|
||||
KeyValue.keyeventKey(0xE00F, KeyEvent.KEYCODE_TAB, KeyValue.FLAG_KEY_FONT | KeyValue.FLAG_SMALLER_FONT));
|
||||
assertEquals(KeyValue.getSpecialKeyByName("tab").withSymbol("t"),
|
||||
KeyValue.keyeventKey("t", KeyEvent.KEYCODE_TAB, 0));
|
||||
assertEquals(KeyValue.getSpecialKeyByName("tab").withSymbol("tab"),
|
||||
KeyValue.keyeventKey("tab", KeyEvent.KEYCODE_TAB, KeyValue.FLAG_SMALLER_FONT));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
x
Reference in New Issue
Block a user