From 963a851d0b9bb13714caf875279e7d5473725843 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lasse=20Brudeskar=20Vik=C3=A5s?= Date: Sun, 19 Jan 2014 22:01:57 +0100 Subject: DownloadProvider: Display download speed in notification Add the current total download speed to in-progress downloads shown in the notification pane. Change-Id: I801dbe61c7ee59d0c1d14d5851ad6dc3a7678499 --- .../providers/downloads/DownloadNotifier.java | 42 ++++++++++++++++++---- 1 file changed, 36 insertions(+), 6 deletions(-) (limited to 'src/com/android/providers/downloads') diff --git a/src/com/android/providers/downloads/DownloadNotifier.java b/src/com/android/providers/downloads/DownloadNotifier.java index d13bb5e2..b325117d 100644 --- a/src/com/android/providers/downloads/DownloadNotifier.java +++ b/src/com/android/providers/downloads/DownloadNotifier.java @@ -39,6 +39,7 @@ import android.provider.Downloads; import android.service.notification.StatusBarNotification; import android.text.TextUtils; import android.text.format.DateUtils; +import android.text.format.Formatter; import android.util.ArrayMap; import android.util.IntArray; import android.util.Log; @@ -265,6 +266,7 @@ public class DownloadNotifier { // Calculate and show progress String remainingText = null; String percentText = null; + String speedAsSizeText = null; if (type == TYPE_ACTIVE) { long current = 0; long total = 0; @@ -291,8 +293,26 @@ public class DownloadNotifier { if (speed > 0) { final long remainingMillis = ((total - current) * 1000) / speed; + final int duration, durationResId; + + // This duplicates DateUtils.formatDuration(), + // but uses our abbreviated plurals. + if (remainingMillis >= DateUtils.HOUR_IN_MILLIS) { + duration = (int) ((remainingMillis + 1800000) + / DateUtils.HOUR_IN_MILLIS); + durationResId = R.string.duration_hours; + } else if (remainingMillis >= DateUtils.MINUTE_IN_MILLIS) { + duration = (int) ((remainingMillis + 30000) + / DateUtils.MINUTE_IN_MILLIS); + durationResId = R.string.duration_minutes; + } else { + duration = (int) ((remainingMillis + 500) + / DateUtils.SECOND_IN_MILLIS); + durationResId = R.string.duration_seconds; + } remainingText = res.getString(R.string.download_remaining, - DateUtils.formatDuration(remainingMillis)); + res.getString(durationResId, duration)); + speedAsSizeText = Formatter.formatFileSize(mContext, speed); } final int percent = (int) ((current * 100) / total); @@ -309,11 +329,16 @@ public class DownloadNotifier { builder.setContentTitle(getDownloadTitle(res, cursor)); if (type == TYPE_ACTIVE) { - final String description = cursor.getString(UpdateQuery.DESCRIPTION); - if (!TextUtils.isEmpty(description)) { - builder.setContentText(description); + if (speedAsSizeText != null) { + builder.setContentText(res.getString(R.string.text_download_speed, + remainingText, speedAsSizeText)); } else { - builder.setContentText(remainingText); + final String description = cursor.getString(UpdateQuery.DESCRIPTION); + if (!TextUtils.isEmpty(description)) { + builder.setContentText(description); + } else { + builder.setContentText(remainingText); + } } builder.setContentInfo(percentText); @@ -346,7 +371,12 @@ public class DownloadNotifier { R.plurals.notif_summary_active, cluster.size(), cluster.size())); builder.setContentText(remainingText); builder.setContentInfo(percentText); - inboxStyle.setSummaryText(remainingText); + if (speedAsSizeText != null) { + inboxStyle.setSummaryText(res.getString(R.string.text_download_speed, + remainingText, speedAsSizeText)); + } else { + inboxStyle.setSummaryText(remainingText); + } } else if (type == TYPE_WAITING) { builder.setContentTitle(res.getQuantityString( -- cgit v1.2.3