From ee6e892ef4b85d3f9e57f03efcbf971b6fb373b2 Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Sun, 13 Mar 2022 00:14:18 +0100 Subject: Define localized keys as a set instead of flags Using flags for removing keys like € and ß need too many flags and won't scale to more localized keys. --- srcs/juloo.keyboard2/Keyboard2.java | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) (limited to 'srcs/juloo.keyboard2/Keyboard2.java') diff --git a/srcs/juloo.keyboard2/Keyboard2.java b/srcs/juloo.keyboard2/Keyboard2.java index 2db63e6..0cc2512 100644 --- a/srcs/juloo.keyboard2/Keyboard2.java +++ b/srcs/juloo.keyboard2/Keyboard2.java @@ -19,6 +19,8 @@ import android.view.View; import android.view.ViewGroup; import android.view.ViewParent; import java.util.List; +import java.util.HashSet; +import java.util.Set; public class Keyboard2 extends InputMethodService implements SharedPreferences.OnSharedPreferenceChangeListener @@ -70,32 +72,34 @@ public class Keyboard2 extends InputMethodService _currentTextLayout = l; } - private int extra_keys_of_subtype(InputMethodSubtype subtype) + private void extra_keys_of_subtype(Set dst, InputMethodSubtype subtype) { String extra_keys = subtype.getExtraValueOf("extra_keys"); - int flags = 0; - if (extra_keys != null) - for (String acc : extra_keys.split("\\|")) - flags |= Config.extra_key_flag_of_name(acc); - return flags; + if (extra_keys == null) + return; + String[] ks = extra_keys.split("\\|"); + for (int i = 0; i < ks.length; i++) + dst.add(ks[i]); } private void refreshAccentsOption(InputMethodManager imm, InputMethodSubtype subtype) { - int to_keep = 0; + HashSet extra_keys = new HashSet(); switch (_config.accents) { case 1: - to_keep |= extra_keys_of_subtype(subtype); + extra_keys_of_subtype(extra_keys, subtype); for (InputMethodSubtype s : getEnabledSubtypes(imm)) - to_keep |= extra_keys_of_subtype(s); + extra_keys_of_subtype(extra_keys, s); break; - case 2: to_keep |= extra_keys_of_subtype(subtype); break; - case 3: to_keep = KeyValue.FLAGS_HIDDEN_KEYS; break; + case 2: + extra_keys_of_subtype(extra_keys, subtype); + break; + case 3: extra_keys = null; break; case 4: break; default: throw new IllegalArgumentException(); } - _config.key_flags_to_remove = ~to_keep & KeyValue.FLAGS_HIDDEN_KEYS; + _config.extra_keys = extra_keys; } private void refreshSubtypeLegacyFallback() @@ -103,8 +107,8 @@ public class Keyboard2 extends InputMethodService // Fallback for the accents option: Only respect the "None" case switch (_config.accents) { - case 1: case 2: case 3: _config.key_flags_to_remove = 0; break; - case 4: _config.key_flags_to_remove = KeyValue.FLAGS_HIDDEN_KEYS; break; + case 1: case 2: case 3: _config.extra_keys = null; break; + case 4: _config.extra_keys = new HashSet(); break; } // Fallback for the layout option: Use qwerty in the "system settings" case _currentTextLayout = (_config.layout == -1) ? R.xml.qwerty : _config.layout; -- cgit v1.2.3