diff options
| author | Jules Aguillon | 2023-07-09 18:06:12 +0200 |
|---|---|---|
| committer | Jules Aguillon | 2023-07-09 18:14:43 +0200 |
| commit | 4669192a01cacba288b5fdd3671ad7c8db9df7d8 (patch) | |
| tree | 6f9bcdee2e5a75642c003e06610a69f602a2b841 /srcs/juloo.keyboard2/ExtraKeyCheckBoxPreference.java | |
| parent | a2957a43d68f51e10c84be07b8725ea241dc8580 (diff) | |
| download | unexpected-keyboard-4669192a01cacba288b5fdd3671ad7c8db9df7d8.tar.gz unexpected-keyboard-4669192a01cacba288b5fdd3671ad7c8db9df7d8.zip | |
Refactor: Don't define extra keys in xml
The current approach is hard to maintain, for example the last key
"autofill" was not displayed.
This implements a PreferenceGroup that contains the check boxes for
every extra keys without involving listing the preferences in
settings.xml.
A custom layout is used to remove the 'title' text view.
The list of extra keys is moved into the new class.
'ExtraKeyCheckBoxPreference' becomes a nested class.
Diffstat (limited to 'srcs/juloo.keyboard2/ExtraKeyCheckBoxPreference.java')
| -rw-r--r-- | srcs/juloo.keyboard2/ExtraKeyCheckBoxPreference.java | 110 |
1 files changed, 0 insertions, 110 deletions
diff --git a/srcs/juloo.keyboard2/ExtraKeyCheckBoxPreference.java b/srcs/juloo.keyboard2/ExtraKeyCheckBoxPreference.java deleted file mode 100644 index 8f7471a..0000000 --- a/srcs/juloo.keyboard2/ExtraKeyCheckBoxPreference.java +++ /dev/null @@ -1,110 +0,0 @@ -package juloo.keyboard2; - -import android.content.Context; -import android.content.res.TypedArray; -import android.content.SharedPreferences; -import android.preference.CheckBoxPreference; -import android.util.AttributeSet; -import android.view.View; -import android.widget.TextView; -import java.util.HashSet; -import java.util.Set; - -public class ExtraKeyCheckBoxPreference extends CheckBoxPreference -{ - public static String[] extra_keys = new String[] - { - "alt", - "meta", - "voice_typing", - "accent_aigu", - "accent_grave", - "accent_double_aigu", - "accent_dot_above", - "accent_circonflexe", - "accent_tilde", - "accent_cedille", - "accent_trema", - "accent_ring", - "accent_caron", - "accent_macron", - "accent_ogonek", - "accent_breve", - "accent_slash", - "accent_bar", - "accent_dot_below", - "accent_hook_above", - "accent_horn", - "€", - "ß", - "£", - "switch_greekmath", - "capslock", - "copy", - "paste", - "cut", - "selectAll", - "shareText", - "pasteAsPlainText", - "undo", - "redo", - "replaceText", - "textAssist", - "autofill", - }; - - public static boolean default_checked(String name) - { - switch (name) - { - case "voice_typing": - return true; - default: - return false; - } - } - - boolean _key_font; - - public ExtraKeyCheckBoxPreference(Context context, AttributeSet attrs) - { - super(context, attrs); - final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ExtraKeyCheckBoxPreference); - int index = a.getInteger(R.styleable.ExtraKeyCheckBoxPreference_index, 0); - a.recycle(); - String key_name = extra_keys[index]; - KeyValue kv = KeyValue.getKeyByName(key_name); - String title = kv.getString(); - String descr = KeyValue.getKeyDescription(key_name); - if (descr != null) - title += " (" + descr + ")"; - setKey(pref_key_of_key_name(key_name)); - setDefaultValue(default_checked(key_name)); - setTitle(title); - _key_font = kv.hasFlags(KeyValue.FLAG_KEY_FONT); - } - - @Override - protected void onBindView(View view) - { - super.onBindView(view); - TextView title = (TextView)view.findViewById(android.R.id.title); - title.setTypeface(_key_font ? Theme.getKeyFont(getContext()) : null); - } - - static String pref_key_of_key_name(String key_name) - { - return "extra_key_" + key_name; - } - - public static Set<KeyValue> get_extra_keys(SharedPreferences prefs) - { - HashSet<KeyValue> ks = new HashSet<KeyValue>(); - for (String key_name : extra_keys) - { - if (prefs.getBoolean(pref_key_of_key_name(key_name), default_checked(key_name))) - ks.add(KeyValue.getKeyByName(key_name)); - } - return ks; - } -} |
