From dc3a303af1ef72602b58292e5cc938944d6954ba Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Mon, 18 Mar 2024 00:14:19 +0100 Subject: refactor: Allow modifier of other key kinds Allow keys of a kind other than Modifier to be a modifier. This requires writing a compareTo function for KeyValue. Fields are compared in this order: Kind, value, flags, symbol. --- srcs/juloo.keyboard2/KeyValue.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'srcs/juloo.keyboard2/KeyValue.java') diff --git a/srcs/juloo.keyboard2/KeyValue.java b/srcs/juloo.keyboard2/KeyValue.java index c9ecd66..f63f558 100644 --- a/srcs/juloo.keyboard2/KeyValue.java +++ b/srcs/juloo.keyboard2/KeyValue.java @@ -3,7 +3,7 @@ package juloo.keyboard2; import android.view.KeyEvent; import java.util.HashMap; -public final class KeyValue +public final class KeyValue implements Comparable { public static enum Event { @@ -224,6 +224,18 @@ public final class KeyValue return sameKey((KeyValue)obj); } + public int compareTo(KeyValue snd) + { + // Compare the kind and value first, then the flags. + int d = (_code & ~FLAGS_BITS) - (snd._code & ~FLAGS_BITS); + if (d != 0) + return d; + d = _code - snd._code; + if (d != 0) + return d; + return _symbol.compareTo(snd._symbol); + } + /** Type-safe alternative to [equals]. */ public boolean sameKey(KeyValue snd) { -- cgit v1.2.3