diff options
| author | Bananeweizen <Bananeweizen@gmx.de> | 2013-12-27 15:56:42 +0100 |
|---|---|---|
| committer | Bananeweizen <Bananeweizen@gmx.de> | 2013-12-27 15:56:42 +0100 |
| commit | 22a071b84d0c2307f7073e646e853dc8525354d2 (patch) | |
| tree | 9d799a69553fb319efe1d187fe61ae17e977edbd /main | |
| parent | 7ab187a5d6e240118992f17e81f230d1dc4fefc0 (diff) | |
| download | cgeo-22a071b84d0c2307f7073e646e853dc8525354d2.zip cgeo-22a071b84d0c2307f7073e646e853dc8525354d2.tar.gz cgeo-22a071b84d0c2307f7073e646e853dc8525354d2.tar.bz2 | |
prohibit empty list name input
Diffstat (limited to 'main')
| -rw-r--r-- | main/res/layout/list_create_dialog.xml | 12 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/list/StoredList.java | 43 |
2 files changed, 34 insertions, 21 deletions
diff --git a/main/res/layout/list_create_dialog.xml b/main/res/layout/list_create_dialog.xml deleted file mode 100644 index 27212ea..0000000 --- a/main/res/layout/list_create_dialog.xml +++ /dev/null @@ -1,12 +0,0 @@ -<?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="fill_parent" - android:orientation="vertical" > - - <EditText - android:id="@+id/text" - style="@style/edittext_dialog" - android:inputType="textNoSuggestions" /> - -</LinearLayout>
\ No newline at end of file diff --git a/main/src/cgeo/geocaching/list/StoredList.java b/main/src/cgeo/geocaching/list/StoredList.java index d3729c0..fd16347 100644 --- a/main/src/cgeo/geocaching/list/StoredList.java +++ b/main/src/cgeo/geocaching/list/StoredList.java @@ -13,7 +13,9 @@ import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.content.res.Resources; -import android.view.View; +import android.text.Editable; +import android.text.InputType; +import android.text.TextWatcher; import android.widget.EditText; import java.text.Collator; @@ -158,14 +160,14 @@ public final class StoredList extends AbstractList { } private void handleListNameInput(final String defaultValue, int dialogTitle, int buttonTitle, final RunnableWithArgument<String> runnable) { - final AlertDialog.Builder alert = new AlertDialog.Builder(activity); - final View view = activity.getLayoutInflater().inflate(R.layout.list_create_dialog, null); - final EditText input = (EditText) view.findViewById(R.id.text); + final EditText input = new EditText(activity); + input.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_CLASS_TEXT); input.setText(defaultValue); - alert.setTitle(dialogTitle); - alert.setView(view); - alert.setPositiveButton(buttonTitle, new DialogInterface.OnClickListener() { + final AlertDialog.Builder builder = new AlertDialog.Builder(activity); + builder.setTitle(dialogTitle); + builder.setView(input); + builder.setPositiveButton(buttonTitle, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int whichButton) { // remove whitespaces added by autocompletion of Android keyboard @@ -175,14 +177,33 @@ public final class StoredList extends AbstractList { } } }); - alert.setNegativeButton(res.getString(R.string.list_dialog_cancel), new DialogInterface.OnClickListener() { + builder.setNegativeButton(res.getString(R.string.list_dialog_cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int whichButton) { dialog.dismiss(); } }); + final AlertDialog dialog = builder.create(); + input.addTextChangedListener(new TextWatcher() { - alert.show(); + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + // empty + } + + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + // empty + } + + @Override + public void afterTextChanged(Editable editable) { + enableDialogButton(dialog, editable.toString()); + } + }); + dialog.show(); + enableDialogButton(dialog, defaultValue); + input.setSelection(input.getText().length()); } public void promptForListRename(final int listId, @NonNull final Runnable runAfterRename) { @@ -196,6 +217,10 @@ public final class StoredList extends AbstractList { } }); } + + private static void enableDialogButton(final AlertDialog dialog, final String input) { + dialog.getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(StringUtils.isNotBlank(input)); + } } /** |
