diff options
| -rw-r--r-- | srcs/juloo.keyboard2/LayoutsPreference.java | 23 | ||||
| -rw-r--r-- | srcs/juloo.keyboard2/ListGroupPreference.java | 9 |
2 files changed, 25 insertions, 7 deletions
diff --git a/srcs/juloo.keyboard2/LayoutsPreference.java b/srcs/juloo.keyboard2/LayoutsPreference.java index a65b350..87a7c3b 100644 --- a/srcs/juloo.keyboard2/LayoutsPreference.java +++ b/srcs/juloo.keyboard2/LayoutsPreference.java @@ -146,7 +146,7 @@ public class LayoutsPreference extends ListGroupPreference<LayoutsPreference.Lay callback.select(new SystemLayout()); break; case "custom": - select_custom(callback); + select_custom(callback, ""); break; default: callback.select(new NamedLayout(name)); @@ -157,15 +157,18 @@ public class LayoutsPreference extends ListGroupPreference<LayoutsPreference.Lay .show(); } - void select_custom(final SelectionCallback callback) + /** Dialog for specifying a custom layout. [initial_text] is the layout + description when modifying a layout. */ + void select_custom(final SelectionCallback callback, String initial_text) { + final EditText input = new EditText(getContext()); + input.setText(initial_text); new AlertDialog.Builder(getContext()) - .setView(R.layout.dialog_edit_text) + .setView(input) .setTitle(R.string.pref_custom_layout_title) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener(){ - public void onClick(DialogInterface dialog, int _which) + public void onClick(DialogInterface _dialog, int _which) { - EditText input = (EditText)((AlertDialog)dialog).findViewById(R.id.text); callback.select(new CustomLayout(input.getText().toString())); } }) @@ -173,6 +176,16 @@ public class LayoutsPreference extends ListGroupPreference<LayoutsPreference.Lay .show(); } + /** Called when modifying a layout. Custom layouts behave differently. */ + @Override + void select(final SelectionCallback callback, Layout prev_layout) + { + if (prev_layout instanceof CustomLayout) + select_custom(callback, ((CustomLayout)prev_layout).xml); + else + select(callback); + } + class LayoutsAddButton extends AddButton { public LayoutsAddButton(Context ctx) diff --git a/srcs/juloo.keyboard2/ListGroupPreference.java b/srcs/juloo.keyboard2/ListGroupPreference.java index 61fc361..72ff9d3 100644 --- a/srcs/juloo.keyboard2/ListGroupPreference.java +++ b/srcs/juloo.keyboard2/ListGroupPreference.java @@ -53,10 +53,15 @@ public abstract class ListGroupPreference<E> extends PreferenceGroup return true; } - /** Called when an item is added or modified. Returns [null] to cancel the - action. */ + /** Called when an item is added or modified. */ abstract void select(SelectionCallback<E> callback); + /** Called when an item is modified. */ + void select(SelectionCallback<E> callback, E _old_value) + { + select(callback); + } + /** A separate class is used as the same serializer must be used in the static context. See [Serializer] below. */ abstract Serializer<E> get_serializer(); |
