diff options
author | Lasse Brudeskar Vikås <bvx89.at.cs@gmail.com> | 2014-01-19 22:01:57 +0100 |
---|---|---|
committer | Michael Bestas <mkbestas@lineageos.org> | 2019-12-11 23:45:53 +0200 |
commit | f94cb893ee34f32336ecd4e1b4aa83fc9b288133 (patch) | |
tree | 9b7fab9cf50f6fc75acd44975c53c47e3fb6cba8 /src | |
parent | e53e719a527c8463b29f5e9f5990864a7283b30d (diff) | |
download | android_packages_providers_DownloadProvider-f94cb893ee34f32336ecd4e1b4aa83fc9b288133.tar.gz android_packages_providers_DownloadProvider-f94cb893ee34f32336ecd4e1b4aa83fc9b288133.tar.bz2 android_packages_providers_DownloadProvider-f94cb893ee34f32336ecd4e1b4aa83fc9b288133.zip |
DownloadProvider: Display download speed in notification
Add the current total download speed to in-progress downloads
shown in the notification pane.
Change-Id: I801dbe61c7ee59d0c1d14d5851ad6dc3a7678499
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/providers/downloads/DownloadNotifier.java | 42 |
1 files changed, 36 insertions, 6 deletions
diff --git a/src/com/android/providers/downloads/DownloadNotifier.java b/src/com/android/providers/downloads/DownloadNotifier.java index d38aa755..e6a9864a 100644 --- a/src/com/android/providers/downloads/DownloadNotifier.java +++ b/src/com/android/providers/downloads/DownloadNotifier.java @@ -40,6 +40,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; @@ -285,6 +286,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; @@ -311,8 +313,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.plurals.duration_hours; + } else if (remainingMillis >= DateUtils.MINUTE_IN_MILLIS) { + duration = (int) ((remainingMillis + 30000) + / DateUtils.MINUTE_IN_MILLIS); + durationResId = R.plurals.duration_minutes; + } else { + duration = (int) ((remainingMillis + 500) + / DateUtils.SECOND_IN_MILLIS); + durationResId = R.plurals.duration_seconds; + } remainingText = res.getString(R.string.download_remaining, - DateUtils.formatDuration(remainingMillis)); + res.getQuantityString(durationResId, duration, duration)); + speedAsSizeText = Formatter.formatFileSize(mContext, speed); } final int percent = (int) ((current * 100) / total); @@ -329,11 +349,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); @@ -366,7 +391,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( |