summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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 b868ffc4..ffb181ca 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 0cbffeb2..83bc1027 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);