Search in sources :

Example 1 with NotificationListener

use of com.android.launcher3.notification.NotificationListener in project android_packages_apps_Launcher3 by crdroidandroid.

the class PopupDataProvider method cancelNotification.

public void cancelNotification(String notificationKey) {
    NotificationListener notificationListener = NotificationListener.getInstanceIfConnected();
    if (notificationListener == null) {
        return;
    }
    notificationListener.cancelNotificationFromLauncher(notificationKey);
}
Also used : NotificationListener(com.android.launcher3.notification.NotificationListener)

Example 2 with NotificationListener

use of com.android.launcher3.notification.NotificationListener in project android_packages_apps_Launcher3 by crdroidandroid.

the class PopupPopulator method createUpdateRunnable.

/**
 * Returns a runnable to update the provided shortcuts and notifications
 */
public static Runnable createUpdateRunnable(final BaseDraggingActivity launcher, final ItemInfo originalInfo, final Handler uiHandler, final PopupContainerWithArrow container, final List<DeepShortcutView> shortcutViews, final List<NotificationKeyData> notificationKeys) {
    final ComponentName activity = originalInfo.getTargetComponent();
    final UserHandle user = originalInfo.user;
    return () -> {
        if (!notificationKeys.isEmpty()) {
            NotificationListener notificationListener = NotificationListener.getInstanceIfConnected();
            final List<NotificationInfo> infos;
            if (notificationListener == null) {
                infos = Collections.emptyList();
            } else {
                infos = notificationListener.getNotificationsForKeys(notificationKeys).stream().map(sbn -> new NotificationInfo(launcher, sbn, originalInfo)).collect(Collectors.toList());
            }
            uiHandler.post(() -> container.applyNotificationInfos(infos));
        }
        List<ShortcutInfo> shortcuts = new ShortcutRequest(launcher, user).withContainer(activity).query(ShortcutRequest.PUBLISHED);
        String shortcutIdToDeDupe = notificationKeys.isEmpty() ? null : notificationKeys.get(0).shortcutId;
        shortcuts = PopupPopulator.sortAndFilterShortcuts(shortcuts, shortcutIdToDeDupe);
        IconCache cache = LauncherAppState.getInstance(launcher).getIconCache();
        for (int i = 0; i < shortcuts.size() && i < shortcutViews.size(); i++) {
            final ShortcutInfo shortcut = shortcuts.get(i);
            final WorkspaceItemInfo si = new WorkspaceItemInfo(shortcut, launcher);
            cache.getUnbadgedShortcutIcon(si, shortcut);
            si.rank = i;
            si.container = CONTAINER_SHORTCUTS;
            final DeepShortcutView view = shortcutViews.get(i);
            uiHandler.post(() -> view.applyShortcutInfo(si, shortcut, container));
        }
    };
}
Also used : Iterator(java.util.Iterator) ComponentName(android.content.ComponentName) ShortcutInfo(android.content.pm.ShortcutInfo) CONTAINER_SHORTCUTS(com.android.launcher3.LauncherSettings.Favorites.CONTAINER_SHORTCUTS) LauncherAppState(com.android.launcher3.LauncherAppState) ItemInfo(com.android.launcher3.model.data.ItemInfo) DeepShortcutView(com.android.launcher3.shortcuts.DeepShortcutView) BaseDraggingActivity(com.android.launcher3.BaseDraggingActivity) IconCache(com.android.launcher3.icons.IconCache) Collectors(java.util.stream.Collectors) NotificationInfo(com.android.launcher3.notification.NotificationInfo) NotificationKeyData(com.android.launcher3.notification.NotificationKeyData) ArrayList(java.util.ArrayList) List(java.util.List) Nullable(androidx.annotation.Nullable) NotificationListener(com.android.launcher3.notification.NotificationListener) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) Handler(android.os.Handler) UserHandle(android.os.UserHandle) ShortcutRequest(com.android.launcher3.shortcuts.ShortcutRequest) Comparator(java.util.Comparator) VisibleForTesting(androidx.annotation.VisibleForTesting) Collections(java.util.Collections) NotificationInfo(com.android.launcher3.notification.NotificationInfo) ShortcutInfo(android.content.pm.ShortcutInfo) UserHandle(android.os.UserHandle) IconCache(com.android.launcher3.icons.IconCache) ComponentName(android.content.ComponentName) ArrayList(java.util.ArrayList) List(java.util.List) ShortcutRequest(com.android.launcher3.shortcuts.ShortcutRequest) DeepShortcutView(com.android.launcher3.shortcuts.DeepShortcutView) NotificationListener(com.android.launcher3.notification.NotificationListener) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo)

Aggregations

NotificationListener (com.android.launcher3.notification.NotificationListener)2 ComponentName (android.content.ComponentName)1 ShortcutInfo (android.content.pm.ShortcutInfo)1 Handler (android.os.Handler)1 UserHandle (android.os.UserHandle)1 Nullable (androidx.annotation.Nullable)1 VisibleForTesting (androidx.annotation.VisibleForTesting)1 BaseDraggingActivity (com.android.launcher3.BaseDraggingActivity)1 LauncherAppState (com.android.launcher3.LauncherAppState)1 CONTAINER_SHORTCUTS (com.android.launcher3.LauncherSettings.Favorites.CONTAINER_SHORTCUTS)1 IconCache (com.android.launcher3.icons.IconCache)1 ItemInfo (com.android.launcher3.model.data.ItemInfo)1 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)1 NotificationInfo (com.android.launcher3.notification.NotificationInfo)1 NotificationKeyData (com.android.launcher3.notification.NotificationKeyData)1 DeepShortcutView (com.android.launcher3.shortcuts.DeepShortcutView)1 ShortcutRequest (com.android.launcher3.shortcuts.ShortcutRequest)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1