summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLasse Brudeskar Vikås <bvx89.at.cs@gmail.com>2014-01-19 22:01:57 +0100
committerZhao Wei Liew <zhaoweiliew@gmail.com>2016-10-04 15:23:54 +0800
commit383964e4289280610c9e6ff646c453e22bc99d5a (patch)
treef87fb5226a79bc576cf60f2c1586fdd3112d418a
parent684e701303ef8e8bc90f4c9f9b37d07cfe2b84ef (diff)
downloadandroid_packages_providers_DownloadProvider-383964e4289280610c9e6ff646c453e22bc99d5a.zip
android_packages_providers_DownloadProvider-383964e4289280610c9e6ff646c453e22bc99d5a.tar.gz
android_packages_providers_DownloadProvider-383964e4289280610c9e6ff646c453e22bc99d5a.tar.bz2
DownloadProvider: Display download speed in notification
Add the current total download speed to in-progress downloads shown in the notification pane. Change-Id: I801dbe61c7ee59d0c1d14d5851ad6dc3a7678499
-rw-r--r--res/values/cm_strings.xml29
-rw-r--r--src/com/android/providers/downloads/DownloadNotifier.java42
2 files changed, 65 insertions, 6 deletions
diff --git a/res/values/cm_strings.xml b/res/values/cm_strings.xml
new file mode 100644
index 0000000..100318a
--- /dev/null
+++ b/res/values/cm_strings.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2013-2016 The CyanogenMod Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <!-- Notification text containing download duration left and download speed -->
+ <string name="text_download_speed">%1$s, %2$s/s</string>
+
+ <!-- Phrase describing a time duration using seconds [CHAR LIMIT=16] -->
+ <string name="duration_seconds">%d s</string>
+
+ <!-- Phrase describing a time duration using minutes [CHAR LIMIT=16] -->
+ <string name="duration_minutes">%d min</string>
+
+ <!-- Phrase describing a time duration using hours [CHAR LIMIT=16] -->
+ <string name="duration_hours">%d h</string>
+</resources>
diff --git a/src/com/android/providers/downloads/DownloadNotifier.java b/src/com/android/providers/downloads/DownloadNotifier.java
index d580869..e6d898e 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;
@@ -263,6 +264,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;
@@ -289,8 +291,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);
@@ -307,11 +327,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);
@@ -344,7 +369,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(