CustomExtraKeysPreference: Reusable edit text layout

This layout is generically used by CustomExtraKeysPreference and
LayoutsPreference.
This commit is contained in:
Jules Aguillon 2023-08-10 12:55:27 +02:00
parent 03f2b8df70
commit 8611dbcfa0
3 changed files with 7 additions and 7 deletions

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content"> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content">
<EditText android:id="@+id/key_name" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_margin="10dp"/> <EditText android:id="@+id/text" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_margin="10dp"/>
</LinearLayout> </LinearLayout>

View File

@ -48,18 +48,17 @@ public class CustomExtraKeysPreference extends ListGroupPreference<String>
void select(final SelectionCallback<String> callback) void select(final SelectionCallback<String> callback)
{ {
new AlertDialog.Builder(getContext()) new AlertDialog.Builder(getContext())
.setView(R.layout.custom_extra_key_add_dialog) .setView(R.layout.dialog_edit_text)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener(){ .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.key_name); EditText input = (EditText)((AlertDialog)dialog).findViewById(R.id.text);
final String k = input.getText().toString(); final String k = input.getText().toString();
if (!k.equals("")) if (!k.equals(""))
callback.select(k); callback.select(k);
} }
}) })
.setNegativeButton(android.R.string.cancel, null) .setNegativeButton(android.R.string.cancel, null)
.setIcon(android.R.drawable.ic_dialog_alert)
.show(); .show();
} }

View File

@ -72,13 +72,14 @@ public class LayoutsPreference extends ListGroupPreference<String>
@Override @Override
Serializer<String> get_serializer() { return SERIALIZER; } Serializer<String> get_serializer() { return SERIALIZER; }
@Override
void select(final SelectionCallback callback) void select(final SelectionCallback callback)
{ {
ArrayAdapter layouts = new ArrayAdapter(getContext(), android.R.layout.simple_list_item_1, _layout_display_names); ArrayAdapter layouts = new ArrayAdapter(getContext(), android.R.layout.simple_list_item_1, _layout_display_names);
new AlertDialog.Builder(getContext()) new AlertDialog.Builder(getContext())
.setView(R.layout.custom_extra_key_add_dialog) .setView(R.layout.dialog_edit_text)
.setAdapter(layouts, new DialogInterface.OnClickListener(){ .setAdapter(layouts, new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int which) public void onClick(DialogInterface _dialog, int which)
{ {
callback.select(_layout_names.get(which)); callback.select(_layout_names.get(which));
} }