From 0269cd65ea57a5046783bcc88243f8f2407952d8 Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Tue, 8 Aug 2023 17:58:27 +0200 Subject: ListGroupPreference: Make items abstract Allow items to be of any class instead of strings. Item serialization and deserialization methods are in a separate class because they are also used in a static context. --- srcs/juloo.keyboard2/CustomExtraKeysPreference.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'srcs/juloo.keyboard2/CustomExtraKeysPreference.java') diff --git a/srcs/juloo.keyboard2/CustomExtraKeysPreference.java b/srcs/juloo.keyboard2/CustomExtraKeysPreference.java index 7bbc449..465b2e7 100644 --- a/srcs/juloo.keyboard2/CustomExtraKeysPreference.java +++ b/srcs/juloo.keyboard2/CustomExtraKeysPreference.java @@ -17,10 +17,12 @@ import org.json.JSONException; /** Allows to enter custom keys to be added to the keyboard. This shows up at the top of the "Add keys to the keyboard" option. */ -public class CustomExtraKeysPreference extends ListGroupPreference +public class CustomExtraKeysPreference extends ListGroupPreference { /** This pref stores a list of strings encoded as JSON. */ static final String KEY = "custom_extra_keys"; + static final ListGroupPreference.Serializer SERIALIZER = + new ListGroupPreference.StringSerializer(); public CustomExtraKeysPreference(Context context, AttributeSet attrs) { @@ -31,7 +33,7 @@ public class CustomExtraKeysPreference extends ListGroupPreference public static List get(SharedPreferences prefs) { List kvs = new ArrayList(); - List key_names = load_from_preferences(KEY, prefs, null); + List key_names = load_from_preferences(KEY, prefs, null, SERIALIZER); if (key_names != null) { for (String key_name : key_names) @@ -40,8 +42,10 @@ public class CustomExtraKeysPreference extends ListGroupPreference return kvs; } + String label_of_value(String value, int i) { return value; } + @Override - void select(final SelectionCallback callback) + void select(final SelectionCallback callback) { new AlertDialog.Builder(getContext()) .setView(R.layout.custom_extra_key_add_dialog) @@ -58,4 +62,7 @@ public class CustomExtraKeysPreference extends ListGroupPreference .setIcon(android.R.drawable.ic_dialog_alert) .show(); } + + @Override + Serializer get_serializer() { return SERIALIZER; } } -- cgit v1.2.3