X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/4c50eb4d2dd1fba177d743315ae52223430db8cb..c3d88a0594e32043b2599a37789b7ada4a9ac85a:/src/com/owncloud/android/ui/dialog/EditNameDialog.java diff --git a/src/com/owncloud/android/ui/dialog/EditNameDialog.java b/src/com/owncloud/android/ui/dialog/EditNameDialog.java index 41d65d4d..862715fd 100644 --- a/src/com/owncloud/android/ui/dialog/EditNameDialog.java +++ b/src/com/owncloud/android/ui/dialog/EditNameDialog.java @@ -1,10 +1,10 @@ /* ownCloud Android client application * Copyright (C) 2011 Bartek Przybylski + * Copyright (C) 2012-2013 ownCloud Inc. * * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -16,7 +16,6 @@ * */ - package com.owncloud.android.ui.dialog; import android.app.AlertDialog; @@ -26,10 +25,13 @@ import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.WindowManager.LayoutParams; +import android.widget.EditText; import android.widget.TextView; +import android.widget.Toast; import com.actionbarsherlock.app.SherlockDialogFragment; import com.owncloud.android.R; +import com.owncloud.android.oc_framework.utils.FileUtils; /** @@ -42,8 +44,10 @@ public class EditNameDialog extends SherlockDialogFragment implements DialogInte public static final String TAG = EditNameDialog.class.getSimpleName(); - protected static final String ARG_TITLE = "title"; - protected static final String ARG_NAME = "name"; + protected static final String ARG_TITLE = "TITLE"; + protected static final String ARG_NAME = "NAME"; + protected static final String ARG_SELECTION_START = "SELECTION_START"; + protected static final String ARG_SELECTION_END = "SELECTION_END"; private String mNewFilename; private boolean mResult; @@ -52,16 +56,20 @@ public class EditNameDialog extends SherlockDialogFragment implements DialogInte /** * Public factory method to get dialog instances. * - * @param title Text to show as title in the dialog. - * @param name Optional text to include in the text input field when the dialog is shown. - * @param listener Instance to notify when the dialog is dismissed. + * @param title Text to show as title in the dialog. + * @param name Optional text to include in the text input field when the dialog is shown. + * @param listener Instance to notify when the dialog is dismissed. + * @param selectionStart Index to the first character to be selected in the input field; negative value for none + * @param selectionEnd Index to the last character to be selected in the input field; negative value for none * @return New dialog instance, ready to show. */ - static public EditNameDialog newInstance(String title, String name, EditNameDialogListener listener) { + static public EditNameDialog newInstance(String title, String name, int selectionStart, int selectionEnd, EditNameDialogListener listener) { EditNameDialog f = new EditNameDialog(); Bundle args = new Bundle(); args.putString(ARG_TITLE, title); args.putString(ARG_NAME, name); + args.putInt(ARG_SELECTION_START, selectionStart); + args.putInt(ARG_SELECTION_END, selectionEnd); f.setArguments(args); f.setOnDismissListener(listener); return f; @@ -81,7 +89,7 @@ public class EditNameDialog extends SherlockDialogFragment implements DialogInte // Inflate the layout for the dialog LayoutInflater inflater = getSherlockActivity().getLayoutInflater(); View v = inflater.inflate(R.layout.edit_box_dialog, null); // null parent view because it will go in the dialog layout - TextView inputText = ((TextView)v.findViewById(R.id.user_input)); + EditText inputText = ((EditText)v.findViewById(R.id.user_input)); inputText.setText(currentName); // Set it to the dialog @@ -99,6 +107,11 @@ public class EditNameDialog extends SherlockDialogFragment implements DialogInte Dialog d = builder.create(); inputText.requestFocus(); + int selectionStart = getArguments().getInt(ARG_SELECTION_START, -1); + int selectionEnd = getArguments().getInt(ARG_SELECTION_END, -1); + if (selectionStart >= 0 && selectionEnd >= 0) { + inputText.setSelection(Math.min(selectionStart, selectionEnd), Math.max(selectionStart, selectionEnd)); + } d.getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE); return d; } @@ -117,6 +130,10 @@ public class EditNameDialog extends SherlockDialogFragment implements DialogInte switch (which) { case AlertDialog.BUTTON_POSITIVE: { mNewFilename = ((TextView)(getDialog().findViewById(R.id.user_input))).getText().toString(); + if (!FileUtils.isValidName(mNewFilename)) { + Toast.makeText(getSherlockActivity(), R.string.filename_forbidden_characters, Toast.LENGTH_LONG).show(); + return; + } mResult = true; } case AlertDialog.BUTTON_NEGATIVE: { // fall through