abouttreesummaryrefslogcommitdiff
path: root/srcs
diff options
context:
space:
mode:
authorJules Aguillon2023-08-10 20:48:24 +0200
committerJules Aguillon2023-08-16 12:21:25 +0200
commitddceb69d4e5a8eac458b20145fe121580c0d6444 (patch)
treef837ad485c1ea5806f8c1a4400015d6f63edec60 /srcs
parent4584e8289b241595e256b74787d8fbe650bb57cd (diff)
downloadunexpected-keyboard-ddceb69d4e5a8eac458b20145fe121580c0d6444.tar.gz
unexpected-keyboard-ddceb69d4e5a8eac458b20145fe121580c0d6444.zip
LayoutsPreference: Modify custom layout
Clicking on a custom layout opens a dialog for modifying the layout description instead of the dialog for selecting a layout.
Diffstat (limited to 'srcs')
-rw-r--r--srcs/juloo.keyboard2/LayoutsPreference.java23
-rw-r--r--srcs/juloo.keyboard2/ListGroupPreference.java9
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();