abouttreesummaryrefslogcommitdiff
diff options
context:
space:
mode:
authorJules Aguillon2025-02-28 00:35:43 +0100
committerJules Aguillon2025-02-28 00:36:14 +0100
commit55cb5f5315c9183f6e4821daa26997e329e30fd8 (patch)
treec17500664e69a78b5b9231704a1473bccc4a5523
parentb7d1508d7b74b3d634b8f3a547d56c27e10f80c8 (diff)
downloadunexpected-keyboard-55cb5f5315c9183f6e4821daa26997e329e30fd8.tar.gz
unexpected-keyboard-55cb5f5315c9183f6e4821daa26997e329e30fd8.zip
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.
-rw-r--r--srcs/juloo.keyboard2/KeyValue.java14
-rw-r--r--test/juloo.keyboard2/KeyValueParserTest.java4
-rw-r--r--test/juloo.keyboard2/KeyValueTest.java7
3 files changed, 19 insertions, 6 deletions
diff --git a/srcs/juloo.keyboard2/KeyValue.java b/srcs/juloo.keyboard2/KeyValue.java
index 7c5dada..2c5a03b 100644
--- a/srcs/juloo.keyboard2/KeyValue.java
+++ b/srcs/juloo.keyboard2/KeyValue.java
@@ -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);
}
diff --git a/test/juloo.keyboard2/KeyValueParserTest.java b/test/juloo.keyboard2/KeyValueParserTest.java
index b7abbef..d56b6b5 100644
--- a/test/juloo.keyboard2/KeyValueParserTest.java
+++ b/test/juloo.keyboard2/KeyValueParserTest.java
@@ -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
diff --git a/test/juloo.keyboard2/KeyValueTest.java b/test/juloo.keyboard2/KeyValueTest.java
index 8b1bfeb..6226d39 100644
--- a/test/juloo.keyboard2/KeyValueTest.java
+++ b/test/juloo.keyboard2/KeyValueTest.java
@@ -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