From fc1c96bde840c352fb6811641bf941e175a607dd Mon Sep 17 00:00:00 2001 From: George Hodulik Date: Thu, 14 Dec 2017 11:28:04 -0800 Subject: Added StatusBarNotificationsListener interface. Change-Id: I62da2da4169835edf043bc085583adfb027bebbe --- .../notification/NotificationListener.java | 29 +++++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'src/com/android/launcher3/notification') diff --git a/src/com/android/launcher3/notification/NotificationListener.java b/src/com/android/launcher3/notification/NotificationListener.java index 7b70df77e..114b2b8df 100644 --- a/src/com/android/launcher3/notification/NotificationListener.java +++ b/src/com/android/launcher3/notification/NotificationListener.java @@ -62,6 +62,7 @@ public class NotificationListener extends NotificationListenerService { private static NotificationListener sNotificationListenerInstance = null; private static NotificationsChangedListener sNotificationsChangedListener; + private static StatusBarNotificationsChangedListener sStatusBarNotificationsChangedListener; private static boolean sIsConnected; private static boolean sIsCreated; @@ -180,10 +181,19 @@ public class NotificationListener extends NotificationListenerService { } } + public static void setStatusBarNotificationsChangedListener + (StatusBarNotificationsChangedListener listener) { + sStatusBarNotificationsChangedListener = listener; + } + public static void removeNotificationsChangedListener() { sNotificationsChangedListener = null; } + public static void removeStatusBarNotificationsChangedListener() { + sStatusBarNotificationsChangedListener = null; + } + @Override public void onListenerConnected() { super.onListenerConnected(); @@ -205,7 +215,10 @@ public class NotificationListener extends NotificationListenerService { public void onNotificationPosted(final StatusBarNotification sbn) { super.onNotificationPosted(sbn); mWorkerHandler.obtainMessage(MSG_NOTIFICATION_POSTED, new NotificationPostedMsg(sbn)) - .sendToTarget(); + .sendToTarget(); + if (sStatusBarNotificationsChangedListener != null) { + sStatusBarNotificationsChangedListener.onNotificationPosted(sbn); + } } /** @@ -227,10 +240,13 @@ public class NotificationListener extends NotificationListenerService { public void onNotificationRemoved(final StatusBarNotification sbn) { super.onNotificationRemoved(sbn); Pair packageUserKeyAndNotificationKey - = new Pair<>(PackageUserKey.fromNotification(sbn), - NotificationKeyData.fromNotification(sbn)); + = new Pair<>(PackageUserKey.fromNotification(sbn), + NotificationKeyData.fromNotification(sbn)); mWorkerHandler.obtainMessage(MSG_NOTIFICATION_REMOVED, packageUserKeyAndNotificationKey) - .sendToTarget(); + .sendToTarget(); + if (sStatusBarNotificationsChangedListener != null) { + sStatusBarNotificationsChangedListener.onNotificationRemoved(sbn); + } NotificationGroup notificationGroup = mNotificationGroupMap.get(sbn.getGroupKey()); if (notificationGroup != null) { @@ -318,4 +334,9 @@ public class NotificationListener extends NotificationListenerService { NotificationKeyData notificationKey); void onNotificationFullRefresh(List activeNotifications); } + + public interface StatusBarNotificationsChangedListener { + void onNotificationPosted(StatusBarNotification sbn); + void onNotificationRemoved(StatusBarNotification sbn); + } } -- cgit v1.2.3