aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/ui/dialog/Dialogs.java
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/cgeo/geocaching/ui/dialog/Dialogs.java')
-rw-r--r--main/src/cgeo/geocaching/ui/dialog/Dialogs.java29
1 files changed, 21 insertions, 8 deletions
diff --git a/main/src/cgeo/geocaching/ui/dialog/Dialogs.java b/main/src/cgeo/geocaching/ui/dialog/Dialogs.java
index 865ba70..cb8926a 100644
--- a/main/src/cgeo/geocaching/ui/dialog/Dialogs.java
+++ b/main/src/cgeo/geocaching/ui/dialog/Dialogs.java
@@ -1,20 +1,24 @@
package cgeo.geocaching.ui.dialog;
import cgeo.geocaching.CgeoApplication;
-import cgeo.geocaching.utils.RunnableWithArgument;
+import cgeo.geocaching.R;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.jdt.annotation.Nullable;
+import rx.functions.Action1;
+
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
+import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.graphics.drawable.Drawable;
import android.text.Editable;
import android.text.InputType;
import android.text.TextWatcher;
+import android.view.ContextThemeWrapper;
import android.view.WindowManager;
import android.widget.EditText;
@@ -298,7 +302,7 @@ public final class Dialogs {
/**
* Show a message dialog for input from the user. The okay button is only enabled on non empty input.
- *
+ *
* @param context
* activity owning the dialog
* @param title
@@ -310,19 +314,20 @@ public final class Dialogs {
* @param okayListener
* listener to be run on okay
*/
- public static void input(final Activity context, final int title, final String defaultValue, final int buttonTitle, final RunnableWithArgument<String> okayListener) {
- final EditText input = new EditText(context);
+ public static void input(final Activity context, final int title, final String defaultValue, final int buttonTitle, final Action1<String> okayListener) {
+ final Context themedContext = new ContextThemeWrapper(context, R.style.dark);
+ final EditText input = new EditText(themedContext);
input.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_CLASS_TEXT);
input.setText(defaultValue);
- final AlertDialog.Builder builder = new AlertDialog.Builder(context);
+ final AlertDialog.Builder builder = new AlertDialog.Builder(themedContext);
builder.setTitle(title);
builder.setView(input);
builder.setPositiveButton(buttonTitle, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
- okayListener.run(input.getText().toString());
+ okayListener.call(input.getText().toString());
}
});
builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
@@ -357,8 +362,16 @@ public final class Dialogs {
dialog.show();
enableDialogButtonIfNotEmpty(dialog, defaultValue);
- // position cursor after text
- input.setSelection(input.getText().length());
+ moveCursorToEnd(input);
+ }
+
+ /**
+ * Move the cursor to the end of the input field.
+ *
+ * @param input
+ */
+ public static void moveCursorToEnd(final EditText input) {
+ input.setSelection(input.getText().length(), input.getText().length());
}
private static void enableDialogButtonIfNotEmpty(final AlertDialog dialog, final String input) {