From e10c587dc5286db64a6f55010637f0c3f9f62d59 Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Sun, 5 Jun 2022 17:26:34 +0200 Subject: Refactor: Abstract KeyValue fields The meaning of the public fields of KeyValue was quite complicated and not handled consistently accross the app. Make these fields private and add a more abstract API on top. The meaning of these fields changed recently and it wasn't an easy change. I plan on making more changes in the future. --- srcs/juloo.keyboard2/Config.java | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) (limited to 'srcs/juloo.keyboard2/Config.java') diff --git a/srcs/juloo.keyboard2/Config.java b/srcs/juloo.keyboard2/Config.java index 6e4ea49..e014fbd 100644 --- a/srcs/juloo.keyboard2/Config.java +++ b/srcs/juloo.keyboard2/Config.java @@ -163,28 +163,31 @@ final class Config boolean is_extra_key = extra_keys.contains(key.name); if (is_extra_key) extra_keys.remove(key.name); - switch (key.code) + int flags = key.getFlags(); + if ((flags & KeyValue.FLAG_LOCALIZED) != 0 && !is_extra_key) + return null; + switch (key.getKind()) { - case KeyValue.EVENT_CHANGE_METHOD: - return shouldOfferSwitchingToNextInputMethod ? key : null; - case KeyEvent.KEYCODE_ENTER: - return (swapEnterActionKey && action_key != null) ? action_key : key; - case KeyValue.EVENT_ACTION: - return (swapEnterActionKey && action_key != null) ? - KeyValue.getKeyByName("enter") : action_key; - case KeyValue.EVENT_SWITCH_PROGRAMMING: - return shouldOfferSwitchingToProgramming ? key : null; - default: - if (key.flags != 0) + case Event: + switch (key.getEvent()) { - if ((key.flags & KeyValue.FLAG_LOCALIZED) != 0 && !is_extra_key) - return null; - if ((key.flags & KeyValue.FLAG_MODIFIER) != 0 - && lockable_modifiers.contains(key.code)) - return key.withFlags(key.flags | KeyValue.FLAG_LOCK); + case KeyValue.EVENT_CHANGE_METHOD: + return shouldOfferSwitchingToNextInputMethod ? key : null; + case KeyEvent.KEYCODE_ENTER: + return (swapEnterActionKey && action_key != null) ? action_key : key; + case KeyValue.EVENT_ACTION: + return (swapEnterActionKey && action_key != null) ? + KeyValue.getKeyByName("enter") : action_key; + case KeyValue.EVENT_SWITCH_PROGRAMMING: + return shouldOfferSwitchingToProgramming ? key : null; } - return key; + break; + case Modifier: + if (lockable_modifiers.contains(key.getModifier())) + return key.withFlags(flags | KeyValue.FLAG_LOCK); + break; } + return key; } }); if (extra_keys.size() > 0) -- cgit v1.2.3