summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/badge
diff options
context:
space:
mode:
authorTony Wickham <twickham@google.com>2017-01-20 08:15:28 -0800
committerTony Wickham <twickham@google.com>2017-01-25 09:51:06 -0800
commit010d2550184179785e4467ff1ffb4f4f4e850ec2 (patch)
tree533ad5bc79d26b10fda6a4ab7a88f5d43643c4ea /src/com/android/launcher3/badge
parentc711e6006f380a500a48383b4f079258b47d4a0d (diff)
downloadandroid_packages_apps_Trebuchet-010d2550184179785e4467ff1ffb4f4f4e850ec2.tar.gz
android_packages_apps_Trebuchet-010d2550184179785e4467ff1ffb4f4f4e850ec2.tar.bz2
android_packages_apps_Trebuchet-010d2550184179785e4467ff1ffb4f4f4e850ec2.zip
Add NotificationListener to launcher.
- NotificationListener extends NotificationListenerService, and is added to the manifest. - Added PopupDataProvider, which contains logic for storing and interacting with data that goes into the long-press popup menu (shortcuts and notifications). A follow-up CL will rename DeepShortcutsContainer to a generic PopupContainerWithArrow. - If Launcher has notification access, NotificationListener will get callbacks when notifications are posted and removed; upon receiving these callbacks, NotificationListener passes them to PopupDataProvider via a NotificationsChangedListener interface. - Upon receiving the changed notifications, PopupDataProvider maps them to the corresponding package/user and tells launcher to update relevant icons on the workspace and all apps. This is guarded by FeatureFlags.BADGE_ICONS. Bug: 32410600 Change-Id: I59aeb31a7f92399c9c4b831ab551e51e13f44f5c
Diffstat (limited to 'src/com/android/launcher3/badge')
-rw-r--r--src/com/android/launcher3/badge/BadgeInfo.java52
-rw-r--r--src/com/android/launcher3/badge/BadgeRenderer.java2
2 files changed, 48 insertions, 6 deletions
diff --git a/src/com/android/launcher3/badge/BadgeInfo.java b/src/com/android/launcher3/badge/BadgeInfo.java
index 0a9f87c6e..98d2277d0 100644
--- a/src/com/android/launcher3/badge/BadgeInfo.java
+++ b/src/com/android/launcher3/badge/BadgeInfo.java
@@ -16,18 +16,60 @@
package com.android.launcher3.badge;
+import com.android.launcher3.util.PackageUserKey;
+
+import java.util.HashSet;
+import java.util.Set;
+
/**
* Contains data to be used in an icon badge.
*/
public class BadgeInfo {
- private int mNotificationCount;
+ /** Used to link this BadgeInfo to icons on the workspace and all apps */
+ private PackageUserKey mPackageUserKey;
+ /**
+ * The keys of the notifications that this badge represents. These keys can later be
+ * used to retrieve {@link com.android.launcher3.badging.NotificationInfo}'s.
+ */
+ private Set<String> mNotificationKeys;
+
+ public BadgeInfo(PackageUserKey packageUserKey) {
+ mPackageUserKey = packageUserKey;
+ mNotificationKeys = new HashSet<>();
+ }
+
+ /**
+ * Returns whether the notification was added (false if it already existed).
+ */
+ public boolean addNotificationKey(String notificationKey) {
+ return mNotificationKeys.add(notificationKey);
+ }
+
+ /**
+ * Returns whether the notification was removed (false if it didn't exist).
+ */
+ public boolean removeNotificationKey(String notificationKey) {
+ return mNotificationKeys.remove(notificationKey);
+ }
+
+ public Set<String> getNotificationKeys() {
+ return mNotificationKeys;
+ }
- public void setNotificationCount(int count) {
- mNotificationCount = count;
+ public int getNotificationCount() {
+ return mNotificationKeys.size();
}
- public String getNotificationCount() {
- return mNotificationCount == 0 ? null : String.valueOf(mNotificationCount);
+ /**
+ * Whether newBadge represents the same PackageUserKey as this badge, and icons with
+ * this badge should be invalidated. So, for instance, if a badge has 3 notifications
+ * and one of those notifications is updated, this method should return false because
+ * the badge still says "3" and the contents of those notifications are only retrieved
+ * upon long-click. This method always returns true when adding or removing notifications.
+ */
+ public boolean shouldBeInvalidated(BadgeInfo newBadge) {
+ return mPackageUserKey.equals(newBadge.mPackageUserKey)
+ && getNotificationCount() != newBadge.getNotificationCount();
}
}
diff --git a/src/com/android/launcher3/badge/BadgeRenderer.java b/src/com/android/launcher3/badge/BadgeRenderer.java
index 238b9188f..787ee724e 100644
--- a/src/com/android/launcher3/badge/BadgeRenderer.java
+++ b/src/com/android/launcher3/badge/BadgeRenderer.java
@@ -61,7 +61,7 @@ public class BadgeRenderer {
mBackgroundRect.set(iconBounds.right - size, iconBounds.top, iconBounds.right,
iconBounds.top + size);
canvas.drawOval(mBackgroundRect, mBackgroundPaint);
- String notificationCount = badgeInfo.getNotificationCount();
+ String notificationCount = String.valueOf(badgeInfo.getNotificationCount());
canvas.drawText(notificationCount,
mBackgroundRect.centerX(),
mBackgroundRect.centerY() + mTextHeight / 2,