summaryrefslogtreecommitdiffstats
path: root/src/com/android/browser/DownloadSettings.java
diff options
context:
space:
mode:
authorAxesh R. Ajmera <aajmera@codeaurora.org>2015-04-09 17:23:31 -0700
committerWebTech Code Review <code-review@localhost>2015-04-23 14:58:21 -0700
commitf9cb0cb7cee31ea03beeca23bc396d44de3f2a8f (patch)
tree37a270f1afb23b2a01882838acb6f82689ac87cc /src/com/android/browser/DownloadSettings.java
parentc70ae6384e8a98afb98b937b490d0e1c9a88a35f (diff)
downloadandroid_packages_apps_Gello-f9cb0cb7cee31ea03beeca23bc396d44de3f2a8f.tar.gz
android_packages_apps_Gello-f9cb0cb7cee31ea03beeca23bc396d44de3f2a8f.tar.bz2
android_packages_apps_Gello-f9cb0cb7cee31ea03beeca23bc396d44de3f2a8f.zip
Autoupdate download file name
In case of downloading same file multiple the download handler auto adds suffix to the filename Additional fix for mimetype Change-Id: Ic441cc4796eba0119e44a8f0a7b33b6b43ec2c44
Diffstat (limited to 'src/com/android/browser/DownloadSettings.java')
-rw-r--r--src/com/android/browser/DownloadSettings.java26
1 files changed, 25 insertions, 1 deletions
diff --git a/src/com/android/browser/DownloadSettings.java b/src/com/android/browser/DownloadSettings.java
index 175f5f98..99be3568 100644
--- a/src/com/android/browser/DownloadSettings.java
+++ b/src/com/android/browser/DownloadSettings.java
@@ -49,6 +49,7 @@ import android.widget.EditText;
import android.widget.TextView;
import android.view.Window;
import android.widget.Toast;
+import android.webkit.MimeTypeMap;
import android.text.TextUtils;
import com.android.browser.reflect.ReflectHelper;
@@ -134,7 +135,7 @@ public class DownloadSettings extends Activity {
Object[] params = {updatedFileName};
Class[] type = new Class[] {String.class};
mimetype = (String) ReflectHelper.invokeMethod("android.media.MediaFile",
- "getMimeTypeForFile", type, params);
+ "getMimeTypeForFile", type, params);
}
//Add special check for .apk files with octet-stream mimetype
@@ -142,15 +143,38 @@ public class DownloadSettings extends Activity {
mimetype = "application/vnd.android.package-archive";
}
+ // last way to fetch for mimetype if its still null
+ if (mimetype == null || mimetype.isEmpty())
+ mimetype = MimeTypeMap.getSingleton().getMimeTypeFromExtension(filenameExtension);
+
downloadPath = chooseFolderFromMimeType(BrowserSettings.getInstance().getDownloadPath(),
mimetype);
downloadPathForUser = DownloadHandler.getDownloadPathForUser(DownloadSettings.this,
downloadPath);
+
+ autoupdateFileName(filenameBase, DownloadHandler.getFilenameExtension(filename), downloadPath);
setDownloadPathForUserText(downloadPathForUser);
setDownloadFileSizeText();
setDownloadFileTimeText();
}
+ private void autoupdateFileName(String filenameBase, String extension, String downloadPath) {
+ String fullPath = downloadPath + "/" + filenameBase + "." + extension;
+ int count = 1;
+ String newFilenameBase = "";
+
+ while(new File(fullPath).exists()) {
+ newFilenameBase = filenameBase+"-"+count++;
+ fullPath = downloadPath + "/" + newFilenameBase + "." + extension;
+ }
+
+ if(!TextUtils.isEmpty(newFilenameBase)) {
+ filenameBase = newFilenameBase;
+ }
+
+ downloadFilenameET.setText(filenameBase);
+ }
+
private OnClickListener downloadPathListener = new OnClickListener() {
@Override