From 66b1bdc9c90e1f29ecec096286136b527ec6b8ed Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Fri, 15 Sep 2023 18:00:27 +0200 Subject: Refactor: Preferred positions for extra keys The new PreferredPos class represents where an extra key should be placed Currently used to place keys at the same positions they were placed before. --- srcs/juloo.keyboard2/Config.java | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'srcs/juloo.keyboard2/Config.java') diff --git a/srcs/juloo.keyboard2/Config.java b/srcs/juloo.keyboard2/Config.java index da78f7f..bde4aea 100644 --- a/srcs/juloo.keyboard2/Config.java +++ b/srcs/juloo.keyboard2/Config.java @@ -9,8 +9,10 @@ import android.util.TypedValue; import android.view.KeyEvent; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Set; final class Config @@ -59,8 +61,8 @@ final class Config public int actionId; // Meaningful only when 'actionLabel' isn't 'null' public boolean swapEnterActionKey; // Swap the "enter" and "action" keys public ExtraKeys extra_keys_subtype; - public Set extra_keys_param; - public List extra_keys_custom; + public Map extra_keys_param; + public Map extra_keys_custom; public final IKeyEventHandler handler; public boolean orientation_landscape = false; @@ -174,16 +176,16 @@ final class Config final KeyValue action_key = action_key(); // Extra keys are removed from the set as they are encountered during the // first iteration then automatically added. - final Set extra_keys = new HashSet(); + final Map extra_keys = new HashMap(); final Set remove_keys = new HashSet(); - extra_keys.addAll(extra_keys_param); - extra_keys.addAll(extra_keys_custom); + extra_keys.putAll(extra_keys_param); + extra_keys.putAll(extra_keys_custom); if (extra_keys_subtype != null) { Set present = new HashSet(); present.addAll(kw.getKeys().keySet()); - present.addAll(extra_keys_param); - present.addAll(extra_keys_custom); + present.addAll(extra_keys_param.keySet()); + present.addAll(extra_keys_custom.keySet()); extra_keys_subtype.compute(extra_keys, new ExtraKeys.Query(kw.script, present)); } @@ -193,7 +195,7 @@ final class Config kw = kw.mapKeys(new KeyboardData.MapKeyValues() { public KeyValue apply(KeyValue key, boolean localized) { - boolean is_extra_key = extra_keys.contains(key); + boolean is_extra_key = extra_keys.containsKey(key); if (is_extra_key) extra_keys.remove(key); if (localized && !is_extra_key) @@ -246,7 +248,7 @@ final class Config if (number_row) kw = kw.addNumberRow(); if (extra_keys.size() > 0) - kw = kw.addExtraKeys(extra_keys.iterator()); + kw = kw.addExtraKeys(extra_keys.entrySet().iterator()); return kw; } -- cgit v1.2.3