summaryrefslogtreecommitdiffstats
path: root/src/com/android/browser/BrowserDownloadPage.java
diff options
context:
space:
mode:
authorLeon Scroggins <scroggo@google.com>2010-01-14 15:44:06 -0500
committerLeon Scroggins <scroggo@google.com>2010-01-21 09:02:52 -0500
commit9be173303990c4cb24ce2d244a44e9af2fc32d4e (patch)
tree3a0a0835b4025a0d1092e7d594162915d46e8c7b /src/com/android/browser/BrowserDownloadPage.java
parent96afcb1a85b1d14be910bfe0a2c4104e6ec87964 (diff)
downloadpackages_apps_Browser-9be173303990c4cb24ce2d244a44e9af2fc32d4e.zip
packages_apps_Browser-9be173303990c4cb24ce2d244a44e9af2fc32d4e.tar.gz
packages_apps_Browser-9be173303990c4cb24ce2d244a44e9af2fc32d4e.tar.bz2
Replace clearing an item from the downloads list with deleting the item.
Fix for http://b/issue?id=2367238
Diffstat (limited to 'src/com/android/browser/BrowserDownloadPage.java')
-rw-r--r--src/com/android/browser/BrowserDownloadPage.java66
1 files changed, 62 insertions, 4 deletions
diff --git a/src/com/android/browser/BrowserDownloadPage.java b/src/com/android/browser/BrowserDownloadPage.java
index 979e9f1..3483c30 100644
--- a/src/com/android/browser/BrowserDownloadPage.java
+++ b/src/com/android/browser/BrowserDownloadPage.java
@@ -26,9 +26,11 @@ import android.content.ContentUris;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.database.Cursor;
+import android.database.DatabaseUtils;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Downloads;
+import android.provider.MediaStore;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.LayoutInflater;
@@ -140,6 +142,37 @@ public class BrowserDownloadPage extends ExpandableListActivity {
return false;
}
+ /**
+ * Remove the file from the list of downloads.
+ * @param id Unique ID of the download to remove.
+ */
+ private void clearFromDownloads(long id) {
+ getContentResolver().delete(ContentUris.withAppendedId(
+ Downloads.Impl.CONTENT_URI, id), null, null);
+ }
+
+ /**
+ * Remove the file from the SD card
+ * @param filename Name of the file to delete.
+ * @param mimetype Mimetype of the file to delete.
+ * @return boolean True on success, false on failure.
+ */
+ private boolean deleteFile(String filename, String mimetype) {
+ Uri uri;
+ if (mimetype.startsWith("image")) {
+ uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
+ } else if (mimetype.startsWith("audio")) {
+ uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
+ } else if (mimetype.startsWith("video")) {
+ uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
+ } else {
+ File file = new File(filename);
+ return file.delete();
+ }
+ return getContentResolver().delete(uri, MediaStore.MediaColumns.DATA
+ + " = " + DatabaseUtils.sqlEscapeString(filename), null) > 0;
+ }
+
@Override
public boolean onContextItemSelected(MenuItem item) {
if (!mDownloadAdapter.moveCursorToPackedChildPosition(
@@ -151,12 +184,37 @@ public class BrowserDownloadPage extends ExpandableListActivity {
hideCompletedDownload();
openCurrentDownload();
return true;
-
+
+ case R.id.download_menu_delete:
+ int filenameColumnId =
+ mDownloadCursor.getColumnIndexOrThrow(Downloads._DATA);
+ final String filename = mDownloadCursor.getString(
+ filenameColumnId);
+ int mimetypeColumnId = mDownloadCursor.getColumnIndexOrThrow(
+ Downloads.Impl.COLUMN_MIME_TYPE);
+ final String mimetype = mDownloadCursor.getString(
+ mimetypeColumnId);
+ final long id = mDownloadCursor.getLong(mIdColumnId);
+ new AlertDialog.Builder(this)
+ .setTitle(R.string.download_delete_file)
+ .setIcon(android.R.drawable.ic_dialog_alert)
+ .setMessage(filename)
+ .setNegativeButton(R.string.cancel, null)
+ .setPositiveButton(R.string.ok,
+ new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog,
+ int whichButton) {
+ if (deleteFile(filename, mimetype)) {
+ clearFromDownloads(id);
+ }
+ }
+ })
+ .show();
+ break;
+
case R.id.download_menu_clear:
case R.id.download_menu_cancel:
- getContentResolver().delete(
- ContentUris.withAppendedId(Downloads.Impl.CONTENT_URI,
- mDownloadCursor.getLong(mIdColumnId)), null, null);
+ clearFromDownloads(mDownloadCursor.getLong(mIdColumnId));
return true;
}
return false;