diff options
author | Jeff Sharkey <jsharkey@android.com> | 2012-11-12 16:50:17 -0800 |
---|---|---|
committer | Jeff Sharkey <jsharkey@android.com> | 2012-11-14 16:21:54 -0800 |
commit | 52b703c5d0c4cff72bafdec0e2229368d3cc20d0 (patch) | |
tree | 0f5674a22b1113f32927f1585a8dc1adc9d2ea7b /src/com/android/providers/downloads/DownloadNotifier.java | |
parent | a40a349c0107660bfb4004467550725a3ca3ec97 (diff) | |
download | android_packages_providers_DownloadProvider-52b703c5d0c4cff72bafdec0e2229368d3cc20d0.tar.gz android_packages_providers_DownloadProvider-52b703c5d0c4cff72bafdec0e2229368d3cc20d0.tar.bz2 android_packages_providers_DownloadProvider-52b703c5d0c4cff72bafdec0e2229368d3cc20d0.zip |
Show remaining time in download notifications.
Calculate speed of in-progress downloads and estimate time remaining
until completion. Uses a moving average that is weighted 1:1 with
the most recent 500ms sample. Funnels timing data to notifications
through DownloadHandler.
Bug: 6777872
Change-Id: I9155f2979aa330bd1172f63bbfca1d053815cee5
Diffstat (limited to 'src/com/android/providers/downloads/DownloadNotifier.java')
-rw-r--r-- | src/com/android/providers/downloads/DownloadNotifier.java | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/com/android/providers/downloads/DownloadNotifier.java b/src/com/android/providers/downloads/DownloadNotifier.java index a1805e5e..f6e7a2ee 100644 --- a/src/com/android/providers/downloads/DownloadNotifier.java +++ b/src/com/android/providers/downloads/DownloadNotifier.java @@ -31,16 +31,15 @@ import android.content.res.Resources; import android.net.Uri; import android.provider.Downloads; import android.text.TextUtils; +import android.text.format.DateUtils; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.Maps; import com.google.common.collect.Multimap; -import com.google.common.collect.Sets; import java.util.Collection; import java.util.HashMap; import java.util.Iterator; -import java.util.Set; import javax.annotation.concurrent.GuardedBy; @@ -160,18 +159,26 @@ public class DownloadNotifier { String remainingText = null; String percentText = null; if (type == TYPE_ACTIVE) { + final DownloadHandler handler = DownloadHandler.getInstance(); + long current = 0; long total = 0; + long remainingMillis = -1; for (DownloadInfo info : cluster) { if (info.mTotalBytes != -1) { current += info.mCurrentBytes; total += info.mTotalBytes; + remainingMillis = Math.max( + handler.getRemainingMillis(info.mId), remainingMillis); } } if (total > 0) { final int percent = (int) ((current * 100) / total); - // TODO: calculate remaining time based on recent bandwidth + if (remainingMillis != -1) { + remainingText = res.getString(R.string.download_remaining, + DateUtils.formatDuration(remainingMillis)); + } percentText = res.getString(R.string.download_percent, percent); builder.setProgress(100, percent, false); |