From 2efcdd0c783e6ef9a52a25bec1a2508040760bb6 Mon Sep 17 00:00:00 2001 From: Tony Wickham Date: Thu, 26 Jan 2017 09:54:48 -0800 Subject: Store notification keys in a List instead of a Set. This will preserve the order when iterating over the notifications to populate the popup container. Bug: 34735689 Change-Id: Ic390ffef140e454566ffc6ab1763950349df25ce --- src/com/android/launcher3/badge/BadgeInfo.java | 15 +++++++++------ .../launcher3/notification/NotificationFooterLayout.java | 3 +-- .../launcher3/notification/NotificationItemView.java | 10 ++++++---- src/com/android/launcher3/popup/PopupDataProvider.java | 9 ++++----- 4 files changed, 20 insertions(+), 17 deletions(-) (limited to 'src/com/android') diff --git a/src/com/android/launcher3/badge/BadgeInfo.java b/src/com/android/launcher3/badge/BadgeInfo.java index 673c297dc..77355c75e 100644 --- a/src/com/android/launcher3/badge/BadgeInfo.java +++ b/src/com/android/launcher3/badge/BadgeInfo.java @@ -19,8 +19,8 @@ package com.android.launcher3.badge; import com.android.launcher3.notification.NotificationInfo; import com.android.launcher3.util.PackageUserKey; -import java.util.HashSet; -import java.util.Set; +import java.util.ArrayList; +import java.util.List; /** * Contains data to be used in an icon badge. @@ -33,17 +33,20 @@ public class BadgeInfo { * The keys of the notifications that this badge represents. These keys can later be * used to retrieve {@link NotificationInfo}'s. */ - private Set mNotificationKeys; + private List mNotificationKeys; public BadgeInfo(PackageUserKey packageUserKey) { mPackageUserKey = packageUserKey; - mNotificationKeys = new HashSet<>(); + mNotificationKeys = new ArrayList<>(); } /** * Returns whether the notification was added (false if it already existed). */ - public boolean addNotificationKey(String notificationKey) { + public boolean addNotificationKeyIfNotExists(String notificationKey) { + if (mNotificationKeys.contains(notificationKey)) { + return false; + } return mNotificationKeys.add(notificationKey); } @@ -54,7 +57,7 @@ public class BadgeInfo { return mNotificationKeys.remove(notificationKey); } - public Set getNotificationKeys() { + public List getNotificationKeys() { return mNotificationKeys; } diff --git a/src/com/android/launcher3/notification/NotificationFooterLayout.java b/src/com/android/launcher3/notification/NotificationFooterLayout.java index 2965e4a63..eef1d6194 100644 --- a/src/com/android/launcher3/notification/NotificationFooterLayout.java +++ b/src/com/android/launcher3/notification/NotificationFooterLayout.java @@ -40,7 +40,6 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.Set; /** * A {@link LinearLayout} that contains icons of notifications. If there is only one icon, @@ -191,7 +190,7 @@ public class NotificationFooterLayout extends LinearLayout { animation.start(); } - public void trimNotifications(Set notifications) { + public void trimNotifications(List notifications) { if (!isAttachedToWindow() || mIconRow.getChildCount() == 0) { return; } diff --git a/src/com/android/launcher3/notification/NotificationItemView.java b/src/com/android/launcher3/notification/NotificationItemView.java index f38838261..b74cd4e1e 100644 --- a/src/com/android/launcher3/notification/NotificationItemView.java +++ b/src/com/android/launcher3/notification/NotificationItemView.java @@ -34,9 +34,8 @@ import com.android.launcher3.R; import com.android.launcher3.graphics.IconPalette; import com.android.launcher3.popup.PopupItemView; -import java.util.HashSet; +import java.util.ArrayList; import java.util.List; -import java.util.Set; import static com.android.launcher3.LauncherAnimUtils.animateViewHeight; @@ -122,7 +121,7 @@ public class NotificationItemView extends PopupItemView { mFooter.applyColors(iconPalette); } - public void trimNotifications(final Set notificationKeys) { + public void trimNotifications(final List notificationKeys) { boolean dismissedMainNotification = !notificationKeys.contains( mMainView.getNotificationInfo().notificationKey); if (dismissedMainNotification && !mAnimatingNextIcon) { @@ -137,7 +136,10 @@ public class NotificationItemView extends PopupItemView { public void onIconAnimationEnd(NotificationInfo newMainNotification) { if (newMainNotification != null) { mMainView.applyNotificationInfo(newMainNotification, mIconView, mIconPalette); - Set footerNotificationKeys = new HashSet<>(notificationKeys); + // Remove the animated notification from the footer by calling trim + // TODO: Remove the notification in NotificationFooterLayout directly + // instead of relying on this hack. + List footerNotificationKeys = new ArrayList<>(notificationKeys); footerNotificationKeys.remove(newMainNotification.notificationKey); mFooter.trimNotifications(footerNotificationKeys); mMainView.setVisibility(VISIBLE); diff --git a/src/com/android/launcher3/popup/PopupDataProvider.java b/src/com/android/launcher3/popup/PopupDataProvider.java index f6fdb767f..c773079fe 100644 --- a/src/com/android/launcher3/popup/PopupDataProvider.java +++ b/src/com/android/launcher3/popup/PopupDataProvider.java @@ -33,7 +33,6 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Set; /** * Provides data for the popup menu that appears after long-clicking on apps. @@ -59,10 +58,10 @@ public class PopupDataProvider implements NotificationListener.NotificationsChan BadgeInfo oldBadgeInfo = mPackageUserToBadgeInfos.get(postedPackageUserKey); if (oldBadgeInfo == null) { BadgeInfo newBadgeInfo = new BadgeInfo(postedPackageUserKey); - newBadgeInfo.addNotificationKey(notificationKey); + newBadgeInfo.addNotificationKeyIfNotExists(notificationKey); mPackageUserToBadgeInfos.put(postedPackageUserKey, newBadgeInfo); mLauncher.updateIconBadges(Collections.singleton(postedPackageUserKey)); - } else if (oldBadgeInfo.addNotificationKey(notificationKey)) { + } else if (oldBadgeInfo.addNotificationKeyIfNotExists(notificationKey)) { mLauncher.updateIconBadges(Collections.singleton(postedPackageUserKey)); } } @@ -96,7 +95,7 @@ public class PopupDataProvider implements NotificationListener.NotificationsChan badgeInfo = new BadgeInfo(packageUserKey); mPackageUserToBadgeInfos.put(packageUserKey, badgeInfo); } - badgeInfo.addNotificationKey(notification.getKey()); + badgeInfo.addNotificationKeyIfNotExists(notification.getKey()); } // Add and remove from updatedBadges so it contains the PackageUserKeys of updated badges. @@ -151,7 +150,7 @@ public class PopupDataProvider implements NotificationListener.NotificationsChan public String[] getNotificationKeysForItem(ItemInfo info) { BadgeInfo badgeInfo = mPackageUserToBadgeInfos.get(PackageUserKey.fromItemInfo(info)); if (badgeInfo == null) { return new String[0]; } - Set notificationKeys = badgeInfo.getNotificationKeys(); + List notificationKeys = badgeInfo.getNotificationKeys(); return notificationKeys.toArray(new String[notificationKeys.size()]); } -- cgit v1.2.3