summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteve Howard <showard@google.com>2010-09-16 17:03:39 -0700
committerSteve Howard <showard@google.com>2010-09-20 15:52:09 -0700
commit78f433c68f14dfba605ceb0e5f3dc54243efd2b2 (patch)
tree641ece0269e7a4a55cd60ea939c552972c1a069c
parentdc738781156d0f5ac1db62838d42c876d740810d (diff)
downloadandroid_packages_providers_DownloadProvider-78f433c68f14dfba605ceb0e5f3dc54243efd2b2.zip
android_packages_providers_DownloadProvider-78f433c68f14dfba605ceb0e5f3dc54243efd2b2.tar.gz
android_packages_providers_DownloadProvider-78f433c68f14dfba605ceb0e5f3dc54243efd2b2.tar.bz2
Display time for today's downloads, delete files on external
* in downloads UI, for downloads that occurred today, display the time of day rather than the date * when deleting a download on external from the downloads UI, explicitly delete the underlying file as well (the service only deletes cache files when deleting a download from the database, it intentionally leaves external files around) Change-Id: I9aa02dabe3c091a67e2c2196a0ea2f313bcdcef0
-rw-r--r--ui/src/com/android/providers/downloads/ui/DownloadAdapter.java19
-rw-r--r--ui/src/com/android/providers/downloads/ui/DownloadList.java30
2 files changed, 47 insertions, 2 deletions
diff --git a/ui/src/com/android/providers/downloads/ui/DownloadAdapter.java b/ui/src/com/android/providers/downloads/ui/DownloadAdapter.java
index b868ffc..ffb181c 100644
--- a/ui/src/com/android/providers/downloads/ui/DownloadAdapter.java
+++ b/ui/src/com/android/providers/downloads/ui/DownloadAdapter.java
@@ -38,7 +38,9 @@ import android.widget.TextView;
import com.android.providers.downloads.ui.DownloadItem.DownloadSelectListener;
import java.text.DateFormat;
+import java.util.Calendar;
import java.util.Date;
+import java.util.GregorianCalendar;
import java.util.List;
/**
@@ -50,6 +52,7 @@ public class DownloadAdapter extends CursorAdapter {
private DownloadSelectListener mDownloadSelectionListener;
private Resources mResources;
private DateFormat mDateFormat;
+ private DateFormat mTimeFormat;
private int mTitleColumnId;
private int mDescriptionColumnId;
@@ -67,6 +70,7 @@ public class DownloadAdapter extends CursorAdapter {
mResources = mContext.getResources();
mDownloadSelectionListener = selectionListener;
mDateFormat = DateFormat.getDateInstance(DateFormat.SHORT);
+ mTimeFormat = DateFormat.getTimeInstance(DateFormat.SHORT);
mIdColumnId = cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_ID);
mTitleColumnId = cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_TITLE);
@@ -112,7 +116,20 @@ public class DownloadAdapter extends CursorAdapter {
private String getDateString() {
Date date = new Date(mCursor.getLong(mDateColumnId));
- return mDateFormat.format(date);
+ if (date.before(getStartOfToday())) {
+ return mDateFormat.format(date);
+ } else {
+ return mTimeFormat.format(date);
+ }
+ }
+
+ private Date getStartOfToday() {
+ Calendar today = new GregorianCalendar();
+ today.set(Calendar.HOUR_OF_DAY, 0);
+ today.set(Calendar.MINUTE, 0);
+ today.set(Calendar.SECOND, 0);
+ today.set(Calendar.MILLISECOND, 0);
+ return today.getTime();
}
private String getSizeText() {
diff --git a/ui/src/com/android/providers/downloads/ui/DownloadList.java b/ui/src/com/android/providers/downloads/ui/DownloadList.java
index 0cbffeb..83bc102 100644
--- a/ui/src/com/android/providers/downloads/ui/DownloadList.java
+++ b/ui/src/com/android/providers/downloads/ui/DownloadList.java
@@ -50,6 +50,7 @@ import android.widget.Toast;
import com.android.providers.downloads.ui.DownloadItem.DownloadSelectListener;
+import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashSet;
@@ -533,10 +534,37 @@ public class DownloadList extends Activity
/**
* Delete a download from the Download Manager.
*/
- private void deleteDownload(Long downloadId) {
+ private void deleteDownload(long downloadId) {
+ if (moveToDownload(downloadId)) {
+ int status = mDateSortedCursor.getInt(mStatusColumnId);
+ if (status == DownloadManager.STATUS_SUCCESSFUL
+ || status == DownloadManager.STATUS_FAILED) {
+ String path = Uri.parse(mDateSortedCursor.getString(mLocalUriColumnId)).getPath();
+ if (path.startsWith(Environment.getExternalStorageDirectory().getPath())) {
+ String mediaType = mDateSortedCursor.getString(mMediaTypeColumnId);
+ deleteDownloadedFile(path, mediaType);
+ }
+ }
+ }
mDownloadManager.remove(downloadId);
}
+ /**
+ * Delete the file at the given path. Try sending an intent to delete it, but if that goes
+ * unhandled, delete it ourselves.
+ * @param path path to the file to delete
+ */
+ private void deleteDownloadedFile(String path, String mediaType) {
+ Intent intent = new Intent(Intent.ACTION_DELETE);
+ File file = new File(path);
+ intent.setDataAndType(Uri.fromFile(file), mediaType);
+ try {
+ startActivity(intent);
+ } catch (ActivityNotFoundException exc) {
+ file.delete();
+ }
+ }
+
@Override
public boolean isDownloadSelected(long id) {
return mSelectedIds.contains(id);