abouttreesummaryrefslogcommitdiff
path: root/srcs/juloo.keyboard2
diff options
context:
space:
mode:
authorJules Aguillon2023-07-30 18:01:25 +0200
committerJules Aguillon2023-07-30 21:34:01 +0200
commitb4a1ac48bbd0256bce53f0fc36cd88f73b6d85e8 (patch)
tree852842c6927911bf1ea5ea781afc0c486e154cc3 /srcs/juloo.keyboard2
parent0856fb4e31a98b7f14f50006d95c89e23c19503d (diff)
downloadunexpected-keyboard-b4a1ac48bbd0256bce53f0fc36cd88f73b6d85e8.tar.gz
unexpected-keyboard-b4a1ac48bbd0256bce53f0fc36cd88f73b6d85e8.zip
ListGroupPreference: Overrideable "add" button
Diffstat (limited to 'srcs/juloo.keyboard2')
-rw-r--r--srcs/juloo.keyboard2/ListGroupPreference.java19
1 files changed, 17 insertions, 2 deletions
diff --git a/srcs/juloo.keyboard2/ListGroupPreference.java b/srcs/juloo.keyboard2/ListGroupPreference.java
index b7f2259..d7940c5 100644
--- a/srcs/juloo.keyboard2/ListGroupPreference.java
+++ b/srcs/juloo.keyboard2/ListGroupPreference.java
@@ -19,6 +19,7 @@ public abstract class ListGroupPreference extends PreferenceGroup
{
boolean _attached = false;
List<String> _values;
+ AddButton _prev_add_button;
public ListGroupPreference(Context context, AttributeSet attrs)
{
@@ -36,6 +37,16 @@ public abstract class ListGroupPreference extends PreferenceGroup
return value;
}
+ /** Called every time the list changes and allows to change the "Add" button
+ appearance.
+ [prev_btn] is the previously attached button, might be null. */
+ AddButton on_attach_add_button(AddButton prev_btn)
+ {
+ if (prev_btn == null)
+ return new AddButton(getContext());
+ return prev_btn;
+ }
+
/** Called when an item is added or modified. Returns [null] to cancel the
action. */
abstract void select(SelectionCallback callback);
@@ -125,6 +136,8 @@ public abstract class ListGroupPreference extends PreferenceGroup
void reattach()
{
+ if (!_attached)
+ return;
removeAll();
int i = 0;
for (String v : _values)
@@ -134,7 +147,9 @@ public abstract class ListGroupPreference extends PreferenceGroup
addPreference(item);
i++;
}
- addPreference(this.new AddButton(getContext()));
+ _prev_add_button = on_attach_add_button(_prev_add_button);
+ _prev_add_button.setOrder(Preference.DEFAULT_ORDER);
+ addPreference(_prev_add_button);
}
class Item extends Preference
@@ -165,7 +180,7 @@ public abstract class ListGroupPreference extends PreferenceGroup
}
}
- final class AddButton extends Preference
+ class AddButton extends Preference
{
public AddButton(Context ctx)
{