abouttreesummaryrefslogcommitdiff
path: root/srcs/juloo.keyboard2/CustomExtraKeysPreference.java
diff options
context:
space:
mode:
authorJules Aguillon2023-08-08 17:58:27 +0200
committerJules Aguillon2023-08-16 12:20:40 +0200
commit0269cd65ea57a5046783bcc88243f8f2407952d8 (patch)
tree784af928a8fffc5d5f8941cbfc053ca38af15097 /srcs/juloo.keyboard2/CustomExtraKeysPreference.java
parent20ab3915e8c7628e6e80c6bbb61b9a783b91d425 (diff)
downloadunexpected-keyboard-0269cd65ea57a5046783bcc88243f8f2407952d8.tar.gz
unexpected-keyboard-0269cd65ea57a5046783bcc88243f8f2407952d8.zip
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.
Diffstat (limited to 'srcs/juloo.keyboard2/CustomExtraKeysPreference.java')
-rw-r--r--srcs/juloo.keyboard2/CustomExtraKeysPreference.java13
1 files changed, 10 insertions, 3 deletions
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<String>
{
/** This pref stores a list of strings encoded as JSON. */
static final String KEY = "custom_extra_keys";
+ static final ListGroupPreference.Serializer<String> SERIALIZER =
+ new ListGroupPreference.StringSerializer();
public CustomExtraKeysPreference(Context context, AttributeSet attrs)
{
@@ -31,7 +33,7 @@ public class CustomExtraKeysPreference extends ListGroupPreference
public static List<KeyValue> get(SharedPreferences prefs)
{
List<KeyValue> kvs = new ArrayList<KeyValue>();
- List<String> key_names = load_from_preferences(KEY, prefs, null);
+ List<String> 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<String> 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<String> get_serializer() { return SERIALIZER; }
}