diff options
author | Martin Brabham <optedoblivion@cyngn.com> | 2015-04-02 15:42:49 -0700 |
---|---|---|
committer | Martin Brabham <mbrabham@cyngn.com> | 2015-04-03 01:45:05 +0000 |
commit | b20d670dac8f5855593e98f6e1fcc3af266d7c66 (patch) | |
tree | 640e83270d4d725d71ea8f9db7163ca6426c6fb9 | |
parent | 374fe7785d0a130407978a3fa9a633d6371b1301 (diff) | |
download | android_packages_apps_CMFileManager-b20d670dac8f5855593e98f6e1fcc3af266d7c66.tar.gz android_packages_apps_CMFileManager-b20d670dac8f5855593e98f6e1fcc3af266d7c66.tar.bz2 android_packages_apps_CMFileManager-b20d670dac8f5855593e98f6e1fcc3af266d7c66.zip |
Add character limit for name input dialog.
Change-Id: I75539bbe90dbc278b360e1246c5218101d77abf7
(cherry picked from commit d34dfc6892760eb14a553bd9774a65aa211f6d7b)
-rw-r--r-- | res/layout/input_name_dialog.xml | 3 | ||||
-rw-r--r-- | res/values/strings.xml | 2 | ||||
-rw-r--r-- | src/com/cyanogenmod/filemanager/ui/dialogs/InputNameDialog.java | 20 |
3 files changed, 22 insertions, 3 deletions
diff --git a/res/layout/input_name_dialog.xml b/res/layout/input_name_dialog.xml index a5b7b02f..aed6fd93 100644 --- a/res/layout/input_name_dialog.xml +++ b/res/layout/input_name_dialog.xml @@ -43,6 +43,7 @@ android:imeOptions="actionDone|flagNoFullscreen" android:scrollHorizontally="true" android:selectAllOnFocus="true" + android:maxLength="255" android:inputType="textNoSuggestions"> <requestFocus /> </EditText> @@ -64,4 +65,4 @@ android:textSize="@dimen/note_text_size" android:visibility="gone" /> -</LinearLayout>
\ No newline at end of file +</LinearLayout> diff --git a/res/values/strings.xml b/res/values/strings.xml index f2282f7f..0fe06ac5 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -507,6 +507,8 @@ <string name="input_name_dialog_message_empty_name">The name cannot be empty.</string> <!-- Enter Name Dialog - Message - Invalid name --> <string name="input_name_dialog_message_invalid_path_name">Invalid name. The characters \'<xliff:g id="invalid_characters">%1$s</xliff:g>\' are not allowed.</string> + <!-- Enter Name Dialog - Message - Invalid name length --> + <string name="input_name_dialog_message_invalid_name_length">File name is too long, please consider something 255 characters or less.</string> <!-- Enter Name Dialog - Message - Invalid name --> <string name="input_name_dialog_message_invalid_name">Invalid name. The names \'.\' and \'..\' are not allowed.</string> <!-- Enter Name Dialog - Message - Name exists --> diff --git a/src/com/cyanogenmod/filemanager/ui/dialogs/InputNameDialog.java b/src/com/cyanogenmod/filemanager/ui/dialogs/InputNameDialog.java index 04140501..c2f5a6a6 100644 --- a/src/com/cyanogenmod/filemanager/ui/dialogs/InputNameDialog.java +++ b/src/com/cyanogenmod/filemanager/ui/dialogs/InputNameDialog.java @@ -20,6 +20,7 @@ import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; import android.text.Editable; +import android.text.TextUtils; import android.text.TextWatcher; import android.view.LayoutInflater; import android.view.View; @@ -43,6 +44,8 @@ import java.util.List; public class InputNameDialog implements TextWatcher, DialogInterface.OnCancelListener, DialogInterface.OnDismissListener { + private static final int FILENAME_CHAR_LIMIT = 255; + private final Context mContext; /** * @hide @@ -249,21 +252,31 @@ public class InputNameDialog * @hide */ void checkName(String name) { + //The name is empty - if (name.length() == 0) { + if (TextUtils.isEmpty(name)) { setMsg( InputNameDialog.this.mContext.getString( R.string.input_name_dialog_message_empty_name), false); return; } + + // Too long + if (name.length() > FILENAME_CHAR_LIMIT) { + setMsg(InputNameDialog.this.mContext.getString( + R.string.input_name_dialog_message_invalid_name_length), false); + return; + } + // The path is invalid - if (name.indexOf(File.separator) != -1) { + if (name.contains(File.separator)) { setMsg( InputNameDialog.this.mContext.getString( R.string.input_name_dialog_message_invalid_path_name, File.separator), false); return; } + // No allow . or .. if (name.compareTo(FileHelper.CURRENT_DIRECTORY) == 0 || name.compareTo(FileHelper.PARENT_DIRECTORY) == 0) { @@ -272,11 +285,13 @@ public class InputNameDialog R.string.input_name_dialog_message_invalid_name), false); return; } + // The same name if (this.mFso != null && !this.mAllowFsoName && name.compareTo(this.mFso.getName()) == 0) { setMsg(null, false); return; } + // Name exists if (FileHelper.isNameExists(this.mFiles, name)) { setMsg( @@ -287,6 +302,7 @@ public class InputNameDialog //Valid name setMsg(null, true); + } /** |