From f918429d0c1927a19d688baa26a07c2c65765580 Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Thu, 7 Jun 2012 11:10:18 -0700 Subject: Uniform "when" to avoid flashing notifications. When showing a download, remember the first timestamp when we showed a notification, and use that time as "when" for all future updates to avoid flashing. Also bring back icon animation that had regressed. Bug: 6596416, 6237256 Change-Id: Ifdc5dc6870dac047515151c1b088e6e379b6a063 --- .../providers/downloads/DownloadNotification.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/com/android/providers/downloads/DownloadNotification.java b/src/com/android/providers/downloads/DownloadNotification.java index 81209b2b..bbd39f60 100644 --- a/src/com/android/providers/downloads/DownloadNotification.java +++ b/src/com/android/providers/downloads/DownloadNotification.java @@ -24,6 +24,7 @@ import android.content.Intent; import android.net.Uri; import android.provider.Downloads; import android.text.TextUtils; +import android.util.SparseLongArray; import java.util.Collection; import java.util.HashMap; @@ -41,6 +42,9 @@ class DownloadNotification { HashMap mNotifications; private SystemFacade mSystemFacade; + /** Time when each {@link DownloadInfo#mId} was first shown. */ + private SparseLongArray mFirstShown = new SparseLongArray(); + static final String LOGTAG = "DownloadNotification"; static final String WHERE_RUNNING = "(" + Downloads.Impl.COLUMN_STATUS + " >= '100') AND (" + @@ -62,6 +66,8 @@ class DownloadNotification { * */ static class NotificationItem { + // TODO: refactor to mNotifId and avoid building Uris based on it, since + // they can overflow int mId; // This first db _id for the download for the app long mTotalCurrent = 0; long mTotalTotal = 0; @@ -150,13 +156,22 @@ class DownloadNotification { final Notification.Builder builder = new Notification.Builder(mContext); boolean hasPausedText = (item.mPausedText != null); - int iconResource = android.R.drawable.stat_sys_download_done; + int iconResource = android.R.drawable.stat_sys_download; if (hasPausedText) { iconResource = android.R.drawable.stat_sys_warning; } builder.setSmallIcon(iconResource); builder.setOngoing(true); + // set notification "when" to be first time this DownloadInfo.mId + // was encountered, which avoids fighting with other notifs. + long firstShown = mFirstShown.get(item.mId, -1); + if (firstShown == -1) { + firstShown = System.currentTimeMillis(); + mFirstShown.put(item.mId, firstShown); + } + builder.setWhen(firstShown); + boolean hasContentText = false; StringBuilder title = new StringBuilder(item.mTitles[0]); if (item.mTitleCount > 1) { -- cgit v1.2.3