Search in sources :

Example 1 with NotificationKeyData

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

the class PopupDataProvider method onNotificationPosted.

@Override
public void onNotificationPosted(PackageUserKey postedPackageUserKey, NotificationKeyData notificationKey) {
    DotInfo dotInfo = mPackageUserToDotInfos.get(postedPackageUserKey);
    if (dotInfo == null) {
        dotInfo = new DotInfo();
        mPackageUserToDotInfos.put(postedPackageUserKey, dotInfo);
    }
    if (dotInfo.addOrUpdateNotificationKey(notificationKey)) {
        updateNotificationDots(postedPackageUserKey::equals);
    }
}
Also used : DotInfo(com.android.launcher3.dot.DotInfo)

Example 2 with NotificationKeyData

use of com.android.launcher3.notification.NotificationKeyData 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)

Example 3 with NotificationKeyData

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

the class PopupContainerWithArrow method populateAndShow.

@TargetApi(Build.VERSION_CODES.P)
public void populateAndShow(final BubbleTextView originalIcon, int shortcutCount, final List<NotificationKeyData> notificationKeys, List<SystemShortcut> systemShortcuts) {
    mNumNotifications = notificationKeys.size();
    mOriginalIcon = originalIcon;
    boolean hasDeepShortcuts = shortcutCount > 0;
    int containerWidth = (int) getResources().getDimension(R.dimen.bg_popup_item_width);
    // horizontally laid out system shortcuts.
    if (hasDeepShortcuts) {
        containerWidth = (int) Math.max(containerWidth, systemShortcuts.size() * getResources().getDimension(R.dimen.system_shortcut_header_icon_touch_size));
    }
    // Add views
    if (mNumNotifications > 0) {
        // Add notification entries
        if (mNotificationContainer == null) {
            mNotificationContainer = findViewById(R.id.notification_container);
            mNotificationContainer.setVisibility(VISIBLE);
            mNotificationContainer.setPopupView(this);
        } else {
            mNotificationContainer.setVisibility(GONE);
        }
        updateNotificationHeader();
    }
    int viewsToFlip = getChildCount();
    mSystemShortcutContainer = this;
    if (mDeepShortcutContainer == null) {
        mDeepShortcutContainer = findViewById(R.id.deep_shortcuts_container);
    }
    if (hasDeepShortcuts) {
        mDeepShortcutContainer.setVisibility(View.VISIBLE);
        for (int i = shortcutCount; i > 0; i--) {
            DeepShortcutView v = inflateAndAdd(R.layout.deep_shortcut, mDeepShortcutContainer);
            v.getLayoutParams().width = containerWidth;
            mShortcuts.add(v);
        }
        updateHiddenShortcuts();
        if (!systemShortcuts.isEmpty()) {
            for (SystemShortcut shortcut : systemShortcuts) {
                if (shortcut instanceof SystemShortcut.Widgets) {
                    if (mWidgetContainer == null) {
                        mWidgetContainer = inflateAndAdd(R.layout.widget_shortcut_container, this);
                    }
                    initializeSystemShortcut(R.layout.system_shortcut, mWidgetContainer, shortcut);
                }
            }
            mSystemShortcutContainer = inflateAndAdd(R.layout.system_shortcut_icons, this);
            for (SystemShortcut shortcut : systemShortcuts) {
                if (!(shortcut instanceof SystemShortcut.Widgets)) {
                    initializeSystemShortcut(R.layout.system_shortcut_icon_only, mSystemShortcutContainer, shortcut);
                }
            }
        }
    } else {
        mDeepShortcutContainer.setVisibility(View.GONE);
        if (!systemShortcuts.isEmpty()) {
            for (SystemShortcut shortcut : systemShortcuts) {
                initializeSystemShortcut(R.layout.system_shortcut, this, shortcut);
            }
        }
    }
    reorderAndShow(viewsToFlip);
    ItemInfo originalItemInfo = (ItemInfo) originalIcon.getTag();
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
        setAccessibilityPaneTitle(getTitleForAccessibility());
    }
    mOriginalIcon.setForceHideDot(true);
    // All views are added. Animate layout from now on.
    setLayoutTransition(new LayoutTransition());
    // Load the shortcuts on a background thread and update the container as it animates.
    MODEL_EXECUTOR.getHandler().postAtFrontOfQueue(PopupPopulator.createUpdateRunnable(mLauncher, originalItemInfo, new Handler(Looper.getMainLooper()), this, mShortcuts, notificationKeys));
}
Also used : ItemInfo(com.android.launcher3.model.data.ItemInfo) WorkspaceItemInfo(com.android.launcher3.model.data.WorkspaceItemInfo) Handler(android.os.Handler) LayoutTransition(android.animation.LayoutTransition) Point(android.graphics.Point) DeepShortcutView(com.android.launcher3.shortcuts.DeepShortcutView) TargetApi(android.annotation.TargetApi)

Example 4 with NotificationKeyData

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

the class PopupDataProvider method onNotificationRemoved.

@Override
public void onNotificationRemoved(PackageUserKey removedPackageUserKey, NotificationKeyData notificationKey) {
    DotInfo oldDotInfo = mPackageUserToDotInfos.get(removedPackageUserKey);
    if (oldDotInfo != null && oldDotInfo.removeNotificationKey(notificationKey)) {
        if (oldDotInfo.getNotificationKeys().size() == 0) {
            mPackageUserToDotInfos.remove(removedPackageUserKey);
        }
        updateNotificationDots(removedPackageUserKey::equals);
        trimNotifications(mPackageUserToDotInfos);
    }
}
Also used : DotInfo(com.android.launcher3.dot.DotInfo)

Example 5 with NotificationKeyData

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

the class PopupDataProvider method getDotInfoForItem.

@Nullable
public DotInfo getDotInfoForItem(@NonNull ItemInfo info) {
    if (!ShortcutUtil.supportsShortcuts(info)) {
        return null;
    }
    DotInfo dotInfo = mPackageUserToDotInfos.get(PackageUserKey.fromItemInfo(info));
    if (dotInfo == null) {
        return null;
    }
    List<NotificationKeyData> notifications = getNotificationsForItem(info, dotInfo.getNotificationKeys());
    if (notifications.isEmpty()) {
        return null;
    }
    return dotInfo;
}
Also used : DotInfo(com.android.launcher3.dot.DotInfo) NotificationKeyData(com.android.launcher3.notification.NotificationKeyData) Nullable(androidx.annotation.Nullable)

Aggregations

DotInfo (com.android.launcher3.dot.DotInfo)3 NotificationKeyData (com.android.launcher3.notification.NotificationKeyData)3 Handler (android.os.Handler)2 Nullable (androidx.annotation.Nullable)2 ItemInfo (com.android.launcher3.model.data.ItemInfo)2 WorkspaceItemInfo (com.android.launcher3.model.data.WorkspaceItemInfo)2 DeepShortcutView (com.android.launcher3.shortcuts.DeepShortcutView)2 LayoutTransition (android.animation.LayoutTransition)1 TargetApi (android.annotation.TargetApi)1 ComponentName (android.content.ComponentName)1 ShortcutInfo (android.content.pm.ShortcutInfo)1 Point (android.graphics.Point)1 UserHandle (android.os.UserHandle)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 NotificationInfo (com.android.launcher3.notification.NotificationInfo)1 NotificationListener (com.android.launcher3.notification.NotificationListener)1