Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(586)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/notifications/CustomNotificationBuilder.java

Issue 1448283003: Notification custom layouts: remove any possible old buttons. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@CustomLayoutsIconColor
Patch Set: Rebase and amend comment. Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/java/src/org/chromium/chrome/browser/notifications/CustomNotificationBuilder.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/notifications/CustomNotificationBuilder.java b/chrome/android/java/src/org/chromium/chrome/browser/notifications/CustomNotificationBuilder.java
index 8acbcf5a8715c1d82328f75e2aedf1faed684c1a..0571b2e605e806ed23e2d945f8a92d82bb947cc4 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/notifications/CustomNotificationBuilder.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/notifications/CustomNotificationBuilder.java
@@ -100,6 +100,14 @@ public CustomNotificationBuilder(Context context) {
@Override
public Notification build() {
+ // A note about RemoteViews and updating notifications. When a notification is passed to the
+ // {@code NotificationManager} with the same tag and id as a previous notification, an
+ // in-place update will be performed. In that case, the actions of all new
+ // {@link RemoteViews} will be applied to the views of the old notification. This is safe
+ // for actions that overwrite old values such as setting the text of a {@code TextView}, but
+ // care must be taken for additive actions. Especially in the case of
+ // {@link RemoteViews#addView} the result could be to append new views below stale ones. In
+ // that case {@link RemoteViews#removeAllViews} must be called before adding new ones.
RemoteViews compactView =
new RemoteViews(mContext.getPackageName(), R.layout.web_notification);
RemoteViews bigView =
@@ -217,9 +225,13 @@ public NotificationBuilder setVibrate(long[] pattern) {
* If there are actions, shows the button related views, and adds a button for each action.
*/
private void addActionButtons(RemoteViews bigView) {
+ // Remove the existing buttons in case an existing notification is being updated.
+ bigView.removeAllViews(R.id.buttons);
+
if (mActions.isEmpty()) {
return;
}
+
bigView.setViewVisibility(R.id.button_divider, View.VISIBLE);
bigView.setViewVisibility(R.id.buttons, View.VISIBLE);
Resources resources = mContext.getResources();
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698