summaryrefslogtreecommitdiffstats
path: root/src/com/android/providers/downloads/DownloadNotifier.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/providers/downloads/DownloadNotifier.java')
-rw-r--r--src/com/android/providers/downloads/DownloadNotifier.java79
1 files changed, 75 insertions, 4 deletions
diff --git a/src/com/android/providers/downloads/DownloadNotifier.java b/src/com/android/providers/downloads/DownloadNotifier.java
index e6a9864a..db24db66 100644
--- a/src/com/android/providers/downloads/DownloadNotifier.java
+++ b/src/com/android/providers/downloads/DownloadNotifier.java
@@ -19,6 +19,7 @@ package com.android.providers.downloads;
import static android.app.DownloadManager.Request.VISIBILITY_VISIBLE;
import static android.app.DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED;
import static android.app.DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_ONLY_COMPLETION;
+import static android.provider.Downloads.Impl.STATUS_PAUSED_MANUAL;
import static android.provider.Downloads.Impl.STATUS_QUEUED_FOR_WIFI;
import static android.provider.Downloads.Impl.STATUS_RUNNING;
@@ -48,6 +49,7 @@ import android.util.LongSparseLongArray;
import com.android.internal.util.ArrayUtils;
+import java.lang.StringBuilder;
import java.text.NumberFormat;
import javax.annotation.concurrent.GuardedBy;
@@ -222,6 +224,36 @@ public class DownloadNotifier {
builder.setWhen(firstShown);
builder.setOnlyAlertOnce(true);
+ /**
+ * If *all* current downloads in the cluster are manually paused,
+ * display the appropriate notification icon and content.
+ *
+ * Also keep track of the number of paused downloads so as to
+ * display the current number of downloading files correctly.
+ */
+ int numPaused = 0;
+ for (int j = 0; j < cluster.size(); j++) {
+ cursor.moveToPosition(cluster.get(j));
+ int status = cursor.getInt(UpdateQuery.STATUS);
+ if (status == Downloads.Impl.STATUS_PAUSED_MANUAL) {
+ numPaused++;
+ }
+ }
+ boolean isClusterPaused = numPaused == cluster.size();
+
+ // Show relevant icon
+ if (type == TYPE_ACTIVE) {
+ if (isClusterPaused) {
+ builder.setSmallIcon(R.drawable.download_pause);
+ } else {
+ builder.setSmallIcon(android.R.drawable.stat_sys_download);
+ }
+ } else if (type == TYPE_WAITING) {
+ builder.setSmallIcon(android.R.drawable.stat_sys_warning);
+ } else if (type == TYPE_COMPLETE) {
+ builder.setSmallIcon(android.R.drawable.stat_sys_download_done);
+ }
+
// Build action intents
if (type == TYPE_ACTIVE || type == TYPE_WAITING) {
final long[] downloadIds = getDownloadIds(cursor, cluster);
@@ -253,6 +285,32 @@ public class DownloadNotifier {
PendingIntent.getBroadcast(mContext,
0, cancelIntent, PendingIntent.FLAG_UPDATE_CURRENT));
+ if (isClusterPaused) {
+ // Add a Resume action
+ final Intent resumeIntent = new Intent(Constants.ACTION_RESUME_QUEUE,
+ uri, mContext, DownloadReceiver.class);
+ resumeIntent.putExtra(DownloadManager.EXTRA_NOTIFICATION_CLICK_DOWNLOAD_IDS,
+ downloadIds);
+
+ builder.addAction(
+ com.android.internal.R.drawable.ic_media_play,
+ res.getString(R.string.button_resume_download),
+ PendingIntent.getBroadcast(mContext,
+ 0, resumeIntent, PendingIntent.FLAG_UPDATE_CURRENT));
+ } else {
+ // Add a Pause action
+ final Intent pauseIntent = new Intent(Constants.ACTION_PAUSE,
+ uri, mContext, DownloadReceiver.class);
+ pauseIntent.putExtra(DownloadManager.EXTRA_NOTIFICATION_CLICK_DOWNLOAD_IDS,
+ downloadIds);
+
+ builder.addAction(
+ com.android.internal.R.drawable.ic_media_pause,
+ res.getString(R.string.button_pause_download),
+ PendingIntent.getBroadcast(mContext,
+ 0, pauseIntent, PendingIntent.FLAG_UPDATE_CURRENT));
+ }
+
} else if (type == TYPE_COMPLETE) {
cursor.moveToPosition(cluster.get(0));
final long id = cursor.getLong(UpdateQuery._ID);
@@ -349,7 +407,9 @@ public class DownloadNotifier {
builder.setContentTitle(getDownloadTitle(res, cursor));
if (type == TYPE_ACTIVE) {
- if (speedAsSizeText != null) {
+ if (isClusterPaused) {
+ builder.setContentText(res.getText(R.string.download_paused));
+ } else if (speedAsSizeText != null) {
builder.setContentText(res.getString(R.string.text_download_speed,
remainingText, speedAsSizeText));
} else {
@@ -387,8 +447,19 @@ public class DownloadNotifier {
}
if (type == TYPE_ACTIVE) {
- builder.setContentTitle(res.getQuantityString(
- R.plurals.notif_summary_active, cluster.size(), cluster.size()));
+ if (isClusterPaused) {
+ builder.setContentTitle(res.getString(R.string.download_paused));
+ } else if (numPaused > 0) {
+ StringBuilder sb = new StringBuilder(res.getQuantityString(
+ R.plurals.notif_summary_active,
+ cluster.size() - numPaused, cluster.size()));
+ sb.append(", ");
+ sb.append(res.getString(R.string.notif_summary_paused, numPaused));
+ builder.setContentTitle(sb.toString());
+ } else {
+ builder.setContentTitle(res.getQuantityString(
+ R.plurals.notif_summary_active, cluster.size(), cluster.size()));
+ }
builder.setContentText(remainingText);
builder.setContentInfo(percentText);
if (speedAsSizeText != null) {
@@ -491,7 +562,7 @@ public class DownloadNotifier {
}
private static boolean isActiveAndVisible(int status, int visibility) {
- return status == STATUS_RUNNING &&
+ return (status == STATUS_RUNNING || status == STATUS_PAUSED_MANUAL) &&
(visibility == VISIBILITY_VISIBLE
|| visibility == VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
}