diff options
author | Lasse Brudeskar Vikås <bvx89.at.cs@gmail.com> | 2014-01-19 22:01:57 +0100 |
---|---|---|
committer | Michael Bestas <mikeioannina@gmail.com> | 2016-12-30 22:22:07 +0200 |
commit | 963a851d0b9bb13714caf875279e7d5473725843 (patch) | |
tree | 3cc82c4b9205cfb6093d2cf0ab9ea96e1e92ea2b /src/com/android/providers/downloads | |
parent | 659df283363c0119f9789572bd3567a91b610ece (diff) | |
download | android_packages_providers_DownloadProvider-963a851d0b9bb13714caf875279e7d5473725843.tar.gz android_packages_providers_DownloadProvider-963a851d0b9bb13714caf875279e7d5473725843.tar.bz2 android_packages_providers_DownloadProvider-963a851d0b9bb13714caf875279e7d5473725843.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/com/android/providers/downloads')
-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 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( |