summaryrefslogtreecommitdiffstats
path: root/src/com/android
diff options
context:
space:
mode:
authorLasse Brudeskar Vikås <bvx89.at.cs@gmail.com>2014-01-19 22:01:57 +0100
committerPawit Pornkitprasan <p.pawit@gmail.com>2014-12-27 11:14:41 +0700
commit161e1c75acbadae42ab9d9f55a23f2e27fab8e83 (patch)
tree4853d459674ec5c6e134ddbe3a5f350fbdd5017f /src/com/android
parent7a1c801909778e005a264d9b35926e31922fd732 (diff)
downloadandroid_packages_providers_DownloadProvider-161e1c75acbadae42ab9d9f55a23f2e27fab8e83.tar.gz
android_packages_providers_DownloadProvider-161e1c75acbadae42ab9d9f55a23f2e27fab8e83.tar.bz2
android_packages_providers_DownloadProvider-161e1c75acbadae42ab9d9f55a23f2e27fab8e83.zip
Add Download Speeds in notification
This commit adds the ability to show the current total download speed Screenshots: http://goo.gl/M3eRNR ps7 : remove download site, and make speed to bit/sec ps8 : make speed to byte/sec and cleanup ps9 : revert to B/sec ps10: fix some formatting issues ps13: rebased Conflicts: res/values/cm_strings.xml src/com/android/providers/downloads/DownloadNotifier.java Change-Id: I801dbe61c7ee59d0c1d14d5851ad6dc3a7678499
Diffstat (limited to 'src/com/android')
-rw-r--r--src/com/android/providers/downloads/DownloadNotifier.java32
1 files changed, 26 insertions, 6 deletions
diff --git a/src/com/android/providers/downloads/DownloadNotifier.java b/src/com/android/providers/downloads/DownloadNotifier.java
index bfd5568d..0fb5a583 100644
--- a/src/com/android/providers/downloads/DownloadNotifier.java
+++ b/src/com/android/providers/downloads/DownloadNotifier.java
@@ -35,6 +35,7 @@ import android.os.SystemClock;
import android.provider.Downloads;
import android.text.TextUtils;
import android.text.format.DateUtils;
+import android.text.format.Formatter;
import android.util.Log;
import android.util.LongSparseLongArray;
@@ -204,6 +205,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;
@@ -224,8 +226,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);
}
builder.setProgress(100, percent, false);
@@ -242,10 +262,9 @@ public class DownloadNotifier {
builder.setContentTitle(getDownloadTitle(res, info));
if (type == TYPE_ACTIVE) {
- if (!TextUtils.isEmpty(info.mDescription)) {
- builder.setContentText(info.mDescription);
- } else {
- builder.setContentText(remainingText);
+ if (speedAsSizeText != null) {
+ builder.setContentText(res.getString(R.string.download_speed_text,
+ remainingText, speedAsSizeText));
}
builder.setContentInfo(percentText);
@@ -275,7 +294,8 @@ public class DownloadNotifier {
builder.setContentTitle(res.getQuantityString(
R.plurals.notif_summary_active, cluster.size(), cluster.size()));
builder.setContentText(remainingText);
- builder.setContentInfo(percentText);
+ builder.setContentInfo(res.getString(R.string.download_speed_text,
+ percentText, speedAsSizeText));
inboxStyle.setSummaryText(remainingText);
} else if (type == TYPE_WAITING) {