diff options
| author | Jules Aguillon | 2024-03-18 00:14:19 +0100 |
|---|---|---|
| committer | Jules Aguillon | 2024-03-18 00:40:15 +0100 |
| commit | dc3a303af1ef72602b58292e5cc938944d6954ba (patch) | |
| tree | 7bfdb51a267d684bd57fcf3b21f917cff3aa3536 /srcs/juloo.keyboard2/KeyValue.java | |
| parent | ec8e78d5cc8a7d3c4d1929761bd80806b1d5e7c8 (diff) | |
| download | unexpected-keyboard-dc3a303af1ef72602b58292e5cc938944d6954ba.tar.gz unexpected-keyboard-dc3a303af1ef72602b58292e5cc938944d6954ba.zip | |
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.
Diffstat (limited to 'srcs/juloo.keyboard2/KeyValue.java')
| -rw-r--r-- | srcs/juloo.keyboard2/KeyValue.java | 14 |
1 files changed, 13 insertions, 1 deletions
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<KeyValue> { 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) { |
