abouttreesummaryrefslogcommitdiff
diff options
context:
space:
mode:
-rw-r--r--srcs/juloo.keyboard2/ListGroupPreference.java30
1 files changed, 21 insertions, 9 deletions
diff --git a/srcs/juloo.keyboard2/ListGroupPreference.java b/srcs/juloo.keyboard2/ListGroupPreference.java
index d7940c5..771bb1c 100644
--- a/srcs/juloo.keyboard2/ListGroupPreference.java
+++ b/srcs/juloo.keyboard2/ListGroupPreference.java
@@ -19,7 +19,8 @@ public abstract class ListGroupPreference extends PreferenceGroup
{
boolean _attached = false;
List<String> _values;
- AddButton _prev_add_button;
+ /** The "add" button currently displayed. */
+ AddButton _add_button = null;
public ListGroupPreference(Context context, AttributeSet attrs)
{
@@ -47,6 +48,14 @@ public abstract class ListGroupPreference extends PreferenceGroup
return prev_btn;
}
+ /** Called every time the list changes and allows to disable the "Remove"
+ buttons on every items. Might be used to enforce a minimum number of
+ items. */
+ boolean should_allow_remove_item()
+ {
+ return true;
+ }
+
/** Called when an item is added or modified. Returns [null] to cancel the
action. */
abstract void select(SelectionCallback callback);
@@ -139,37 +148,40 @@ public abstract class ListGroupPreference extends PreferenceGroup
if (!_attached)
return;
removeAll();
+ boolean allow_remove_item = should_allow_remove_item();
int i = 0;
for (String v : _values)
{
- Item item = this.new Item(getContext(), v);
+ Item item = this.new Item(getContext(), v, allow_remove_item);
item.setTitle(label_of_value(v, i));
addPreference(item);
i++;
}
- _prev_add_button = on_attach_add_button(_prev_add_button);
- _prev_add_button.setOrder(Preference.DEFAULT_ORDER);
- addPreference(_prev_add_button);
+ _add_button = on_attach_add_button(_add_button);
+ _add_button.setOrder(Preference.DEFAULT_ORDER);
+ addPreference(_add_button);
}
class Item extends Preference
{
final String _value;
- public Item(Context ctx, String value)
+ public Item(Context ctx, String value, boolean allow_remove)
{
super(ctx);
_value = value;
setPersistent(false);
- setWidgetLayoutResource(R.layout.pref_listgroup_item_widget);
+ if (allow_remove)
+ setWidgetLayoutResource(R.layout.pref_listgroup_item_widget);
}
@Override
protected View onCreateView(ViewGroup parent)
{
View v = super.onCreateView(parent);
- v.findViewById(R.id.pref_listgroup_remove_btn)
- .setOnClickListener(new View.OnClickListener() {
+ View remove_btn = v.findViewById(R.id.pref_listgroup_remove_btn);
+ if (remove_btn != null)
+ remove_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View _v)
{