summaryrefslogtreecommitdiff
path: root/src/com/android/launcher3/LauncherNotifications.java
blob: 3b73859f3d7e3416b6d21f2689be00a1eef0cc35 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package com.android.launcher3;

import android.service.notification.StatusBarNotification;

import com.android.launcher3.notification.NotificationKeyData;
import com.android.launcher3.notification.NotificationListener;
import com.android.launcher3.util.PackageUserKey;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class LauncherNotifications implements NotificationListener.NotificationsChangedListener {
    private static LauncherNotifications sInstance;

    public static synchronized LauncherNotifications getInstance() {
        if (sInstance == null) {
            sInstance = new LauncherNotifications();
        }
        return sInstance;
    }

    private final Set<NotificationListener.NotificationsChangedListener> mListeners = new HashSet<>();

    public void addListener(NotificationListener.NotificationsChangedListener listener) {
        mListeners.add(listener);
    }

    @Override
    public void onNotificationPosted(PackageUserKey postedPackageUserKey, NotificationKeyData notificationKey) {
        for (NotificationListener.NotificationsChangedListener listener : mListeners) {
            listener.onNotificationPosted(postedPackageUserKey, notificationKey);
        }
    }

    @Override
    public void onNotificationRemoved(PackageUserKey removedPackageUserKey, NotificationKeyData notificationKey) {
        for (NotificationListener.NotificationsChangedListener listener : mListeners) {
            listener.onNotificationRemoved(removedPackageUserKey, notificationKey);
        }
    }

    @Override
    public void onNotificationFullRefresh(List<StatusBarNotification> activeNotifications) {
        for (NotificationListener.NotificationsChangedListener listener : mListeners) {
            listener.onNotificationFullRefresh(activeNotifications);
        }
    }
}