aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--main/res/layout/list_create_dialog.xml12
-rw-r--r--main/src/cgeo/geocaching/list/StoredList.java43
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));
+ }
}
/**