diff --git a/src/com/android/launcher3/AbstractFloatingView.java b/src/com/android/launcher3/AbstractFloatingView.java index 7cab18d8d3..e75527e349 100644 --- a/src/com/android/launcher3/AbstractFloatingView.java +++ b/src/com/android/launcher3/AbstractFloatingView.java @@ -133,9 +133,6 @@ public abstract class AbstractFloatingView extends LinearLayout implements Touch return mIsOpen; } - protected void onWidgetsBound() { - } - protected abstract boolean isOfType(@FloatingViewType int type); /** @return Whether the back is consumed. If false, Launcher will handle the back as well. */ diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 73fba4eb61..245e4708c3 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -145,7 +145,6 @@ import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.List; -import java.util.Set; import java.util.function.Predicate; import androidx.annotation.Nullable; @@ -1122,11 +1121,6 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns, public void updateNotificationDots(Predicate updatedDots) { mWorkspace.updateNotificationDots(updatedDots); mAppsView.getAppsStore().updateNotificationDots(updatedDots); - - PopupContainerWithArrow popup = PopupContainerWithArrow.getOpen(Launcher.this); - if (popup != null) { - popup.updateNotificationHeader(updatedDots); - } } @Override @@ -2247,10 +2241,6 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns, @Override public void bindAllWidgets(final ArrayList allWidgets) { mPopupDataProvider.setAllWidgets(allWidgets); - AbstractFloatingView topView = AbstractFloatingView.getTopOpenView(this); - if (topView != null) { - topView.onWidgetsBound(); - } } /** diff --git a/src/com/android/launcher3/dot/DotInfo.java b/src/com/android/launcher3/dot/DotInfo.java index 15b2a3b016..4ff0539b6c 100644 --- a/src/com/android/launcher3/dot/DotInfo.java +++ b/src/com/android/launcher3/dot/DotInfo.java @@ -18,7 +18,6 @@ package com.android.launcher3.dot; import com.android.launcher3.notification.NotificationInfo; import com.android.launcher3.notification.NotificationKeyData; -import com.android.launcher3.util.PackageUserKey; import java.util.ArrayList; import java.util.List; @@ -30,14 +29,11 @@ public class DotInfo { public static final int MAX_COUNT = 999; - /** Used to link this DotInfo to icons on the workspace and all apps */ - private PackageUserKey mPackageUserKey; - /** * The keys of the notifications that this dot represents. These keys can later be * used to retrieve {@link NotificationInfo}'s. */ - private List mNotificationKeys; + private final List mNotificationKeys = new ArrayList<>(); /** * The current sum of the counts in {@link #mNotificationKeys}, @@ -45,11 +41,6 @@ public class DotInfo { */ private int mTotalCount; - public DotInfo(PackageUserKey packageUserKey) { - mPackageUserKey = packageUserKey; - mNotificationKeys = new ArrayList<>(); - } - /** * Returns whether the notification was added or its count changed. */ diff --git a/src/com/android/launcher3/dot/FolderDotInfo.java b/src/com/android/launcher3/dot/FolderDotInfo.java index b5eb8cd581..54800a07a8 100644 --- a/src/com/android/launcher3/dot/FolderDotInfo.java +++ b/src/com/android/launcher3/dot/FolderDotInfo.java @@ -30,10 +30,6 @@ public class FolderDotInfo extends DotInfo { private int mNumNotifications; - public FolderDotInfo() { - super(null); - } - public void addDotInfo(DotInfo dotToAdd) { if (dotToAdd == null) { return; diff --git a/src/com/android/launcher3/popup/PopupContainerWithArrow.java b/src/com/android/launcher3/popup/PopupContainerWithArrow.java index 9b23f3f217..b0af4c6786 100644 --- a/src/com/android/launcher3/popup/PopupContainerWithArrow.java +++ b/src/com/android/launcher3/popup/PopupContainerWithArrow.java @@ -61,6 +61,7 @@ import com.android.launcher3.logging.LoggerUtils; import com.android.launcher3.notification.NotificationInfo; import com.android.launcher3.notification.NotificationItemView; import com.android.launcher3.notification.NotificationKeyData; +import com.android.launcher3.popup.PopupDataProvider.PopupDataChangeListener; import com.android.launcher3.shortcuts.DeepShortcutManager; import com.android.launcher3.shortcuts.DeepShortcutView; import com.android.launcher3.shortcuts.ShortcutDragPreviewProvider; @@ -72,7 +73,6 @@ import com.android.launcher3.views.BaseDragLayer; import java.util.ArrayList; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.function.Predicate; /** @@ -80,7 +80,7 @@ import java.util.function.Predicate; */ public class PopupContainerWithArrow extends ArrowPopup implements DragSource, DragController.DragListener, View.OnLongClickListener, - View.OnTouchListener { + View.OnTouchListener, PopupDataChangeListener { private final List mShortcuts = new ArrayList<>(); private final PointF mInterceptTouchDown = new PointF(); @@ -114,6 +114,18 @@ public class PopupContainerWithArrow extends ArrowPopup implements DragSource, return mAccessibilityDelegate; } + @Override + protected void onAttachedToWindow() { + super.onAttachedToWindow(); + mLauncher.getPopupDataProvider().setChangeListener(this); + } + + @Override + protected void onDetachedFromWindow() { + super.onDetachedFromWindow(); + mLauncher.getPopupDataProvider().setChangeListener(null); + } + @Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (ev.getAction() == MotionEvent.ACTION_DOWN) { @@ -352,7 +364,7 @@ public class PopupContainerWithArrow extends ArrowPopup implements DragSource, } @Override - protected void onWidgetsBound() { + public void onWidgetsBound() { ItemInfo itemInfo = (ItemInfo) mOriginalIcon.getTag(); SystemShortcut widgetInfo = new SystemShortcut.Widgets(); View.OnClickListener onClickListener = widgetInfo.getOnClickListener(mLauncher, itemInfo); @@ -464,7 +476,8 @@ public class PopupContainerWithArrow extends ArrowPopup implements DragSource, /** * Updates the notification header if the original icon's dot updated. */ - public void updateNotificationHeader(Predicate updatedDots) { + @Override + public void onNotificationDotsUpdated(Predicate updatedDots) { ItemInfo itemInfo = (ItemInfo) mOriginalIcon.getTag(); PackageUserKey packageUser = PackageUserKey.fromItemInfo(itemInfo); if (updatedDots.test(packageUser)) { @@ -481,6 +494,7 @@ public class PopupContainerWithArrow extends ArrowPopup implements DragSource, } } + @Override public void trimNotifications(Map updatedDots) { if (mNotificationItemView == null) { return; diff --git a/src/com/android/launcher3/popup/PopupDataProvider.java b/src/com/android/launcher3/popup/PopupDataProvider.java index f4da858d14..2d301ac008 100644 --- a/src/com/android/launcher3/popup/PopupDataProvider.java +++ b/src/com/android/launcher3/popup/PopupDataProvider.java @@ -22,7 +22,6 @@ import android.util.Log; import com.android.launcher3.ItemInfo; import com.android.launcher3.Launcher; -import com.android.launcher3.Utilities; import com.android.launcher3.dot.DotInfo; import com.android.launcher3.model.WidgetItem; import com.android.launcher3.notification.NotificationKeyData; @@ -38,6 +37,7 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.function.Predicate; import androidx.annotation.NonNull; @@ -58,10 +58,17 @@ public class PopupDataProvider implements NotificationListener.NotificationsChan /** Maps packages to their Widgets */ private ArrayList mAllWidgets = new ArrayList<>(); + private PopupDataChangeListener mChangeListener = PopupDataChangeListener.INSTANCE; + public PopupDataProvider(Launcher launcher) { mLauncher = launcher; } + private void updateNotificationDots(Predicate updatedDots) { + mLauncher.updateNotificationDots(updatedDots); + mChangeListener.onNotificationDotsUpdated(updatedDots); + } + @Override public void onNotificationPosted(PackageUserKey postedPackageUserKey, NotificationKeyData notificationKey, boolean shouldBeFilteredOut) { @@ -69,7 +76,7 @@ public class PopupDataProvider implements NotificationListener.NotificationsChan boolean dotShouldBeRefreshed; if (dotInfo == null) { if (!shouldBeFilteredOut) { - DotInfo newDotInfo = new DotInfo(postedPackageUserKey); + DotInfo newDotInfo = new DotInfo(); newDotInfo.addOrUpdateNotificationKey(notificationKey); mPackageUserToDotInfos.put(postedPackageUserKey, newDotInfo); dotShouldBeRefreshed = true; @@ -85,7 +92,7 @@ public class PopupDataProvider implements NotificationListener.NotificationsChan } } if (dotShouldBeRefreshed) { - mLauncher.updateNotificationDots(t -> postedPackageUserKey.equals(t)); + updateNotificationDots(t -> postedPackageUserKey.equals(t)); } } @@ -97,7 +104,7 @@ public class PopupDataProvider implements NotificationListener.NotificationsChan if (oldDotInfo.getNotificationKeys().size() == 0) { mPackageUserToDotInfos.remove(removedPackageUserKey); } - mLauncher.updateNotificationDots(t -> removedPackageUserKey.equals(t)); + updateNotificationDots(t -> removedPackageUserKey.equals(t)); trimNotifications(mPackageUserToDotInfos); } } @@ -112,7 +119,7 @@ public class PopupDataProvider implements NotificationListener.NotificationsChan PackageUserKey packageUserKey = PackageUserKey.fromNotification(notification); DotInfo dotInfo = mPackageUserToDotInfos.get(packageUserKey); if (dotInfo == null) { - dotInfo = new DotInfo(packageUserKey); + dotInfo = new DotInfo(); mPackageUserToDotInfos.put(packageUserKey, dotInfo); } dotInfo.addOrUpdateNotificationKey(NotificationKeyData.fromNotification(notification)); @@ -133,16 +140,13 @@ public class PopupDataProvider implements NotificationListener.NotificationsChan } if (!updatedDots.isEmpty()) { - mLauncher.updateNotificationDots(updatedDots::containsKey); + updateNotificationDots(updatedDots::containsKey); } trimNotifications(updatedDots); } private void trimNotifications(Map updatedDots) { - PopupContainerWithArrow openContainer = PopupContainerWithArrow.getOpen(mLauncher); - if (openContainer != null) { - openContainer.trimNotifications(updatedDots); - } + mChangeListener.trimNotifications(updatedDots); } public void setDeepShortcutMap(HashMap deepShortcutMapCopy) { @@ -194,6 +198,11 @@ public class PopupDataProvider implements NotificationListener.NotificationsChan public void setAllWidgets(ArrayList allWidgets) { mAllWidgets = allWidgets; + mChangeListener.onWidgetsBound(); + } + + public void setChangeListener(PopupDataChangeListener listener) { + mChangeListener = listener == null ? PopupDataChangeListener.INSTANCE : listener; } public ArrayList getAllWidgets() { @@ -216,4 +225,15 @@ public class PopupDataProvider implements NotificationListener.NotificationsChan } return null; } + + public interface PopupDataChangeListener { + + PopupDataChangeListener INSTANCE = new PopupDataChangeListener() { }; + + default void onNotificationDotsUpdated(Predicate updatedDots) { } + + default void trimNotifications(Map updatedDots) { } + + default void onWidgetsBound() { } + } } diff --git a/src/com/android/launcher3/widget/BaseWidgetSheet.java b/src/com/android/launcher3/widget/BaseWidgetSheet.java index 508695ba26..df82661196 100644 --- a/src/com/android/launcher3/widget/BaseWidgetSheet.java +++ b/src/com/android/launcher3/widget/BaseWidgetSheet.java @@ -34,6 +34,7 @@ import com.android.launcher3.ItemInfo; import com.android.launcher3.R; import com.android.launcher3.Utilities; import com.android.launcher3.dragndrop.DragOptions; +import com.android.launcher3.popup.PopupDataProvider; import com.android.launcher3.touch.ItemLongClickListener; import com.android.launcher3.uioverrides.WallpaperColorInfo; import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType; @@ -47,7 +48,8 @@ import com.android.launcher3.views.BaseDragLayer; * Base class for various widgets popup */ abstract class BaseWidgetSheet extends AbstractSlideInView - implements OnClickListener, OnLongClickListener, DragSource { + implements OnClickListener, OnLongClickListener, DragSource, + PopupDataProvider.PopupDataChangeListener { /* Touch handling related member variables. */ @@ -60,6 +62,18 @@ abstract class BaseWidgetSheet extends AbstractSlideInView mColorScrim = createColorScrim(context); } + @Override + protected void onAttachedToWindow() { + super.onAttachedToWindow(); + mLauncher.getPopupDataProvider().setChangeListener(this); + } + + @Override + protected void onDetachedFromWindow() { + super.onDetachedFromWindow(); + mLauncher.getPopupDataProvider().setChangeListener(null); + } + @Override public final void onClick(View v) { // Let the user know that they have to long press to add a widget diff --git a/src/com/android/launcher3/widget/WidgetsBottomSheet.java b/src/com/android/launcher3/widget/WidgetsBottomSheet.java index 4bd6234bcd..05368faa62 100644 --- a/src/com/android/launcher3/widget/WidgetsBottomSheet.java +++ b/src/com/android/launcher3/widget/WidgetsBottomSheet.java @@ -76,7 +76,7 @@ public class WidgetsBottomSheet extends BaseWidgetSheet implements Insettable { } @Override - protected void onWidgetsBound() { + public void onWidgetsBound() { List widgets = mLauncher.getPopupDataProvider().getWidgetsForPackageUser( new PackageUserKey( mOriginalItemInfo.getTargetComponent().getPackageName(), diff --git a/src/com/android/launcher3/widget/WidgetsFullSheet.java b/src/com/android/launcher3/widget/WidgetsFullSheet.java index 11126861f8..ec06d1e6db 100644 --- a/src/com/android/launcher3/widget/WidgetsFullSheet.java +++ b/src/com/android/launcher3/widget/WidgetsFullSheet.java @@ -155,7 +155,7 @@ public class WidgetsFullSheet extends BaseWidgetSheet } @Override - protected void onWidgetsBound() { + public void onWidgetsBound() { mAdapter.setWidgets(mLauncher.getPopupDataProvider().getAllWidgets()); }