diff options
Diffstat (limited to 'main/src/cgeo/geocaching/ui/dialog/Dialogs.java')
| -rw-r--r-- | main/src/cgeo/geocaching/ui/dialog/Dialogs.java | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/main/src/cgeo/geocaching/ui/dialog/Dialogs.java b/main/src/cgeo/geocaching/ui/dialog/Dialogs.java index 865ba70..cbd5c94 100644 --- a/main/src/cgeo/geocaching/ui/dialog/Dialogs.java +++ b/main/src/cgeo/geocaching/ui/dialog/Dialogs.java @@ -1,11 +1,12 @@ package cgeo.geocaching.ui.dialog; import cgeo.geocaching.CgeoApplication; -import cgeo.geocaching.utils.RunnableWithArgument; import org.apache.commons.lang3.StringUtils; import org.eclipse.jdt.annotation.Nullable; +import rx.util.functions.Action1; + import android.app.Activity; import android.app.AlertDialog; import android.app.AlertDialog.Builder; @@ -298,7 +299,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,7 +311,7 @@ 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) { + public static void input(final Activity context, final int title, final String defaultValue, final int buttonTitle, final Action1<String> okayListener) { final EditText input = new EditText(context); input.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_CLASS_TEXT); input.setText(defaultValue); @@ -322,7 +323,7 @@ public final class Dialogs { @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 +358,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) { |
