diff options
Diffstat (limited to 'src/com/android/launcher3/popup')
4 files changed, 55 insertions, 363 deletions
diff --git a/src/com/android/launcher3/popup/ArrowPopup.java b/src/com/android/launcher3/popup/ArrowPopup.java index e0f245fd27..e3314d4b38 100644 --- a/src/com/android/launcher3/popup/ArrowPopup.java +++ b/src/com/android/launcher3/popup/ArrowPopup.java @@ -18,12 +18,9 @@ package com.android.launcher3.popup; import static androidx.core.content.ContextCompat.getColorStateList; -import static com.android.app.animation.Interpolators.ACCELERATED_EASE; -import static com.android.app.animation.Interpolators.DECELERATED_EASE; import static com.android.app.animation.Interpolators.EMPHASIZED_ACCELERATE; import static com.android.app.animation.Interpolators.EMPHASIZED_DECELERATE; import static com.android.app.animation.Interpolators.LINEAR; -import static com.android.launcher3.config.FeatureFlags.ENABLE_MATERIAL_U_POPUP; import android.animation.Animator; import android.animation.AnimatorListenerAdapter; @@ -130,6 +127,7 @@ public abstract class ArrowPopup<T extends Context & ActivityContext> protected final float mElevation; + // Tag for Views that have children that will need to be iterated to add styling. private final String mIterateChildrenTag; protected final int[] mColorIds; @@ -170,7 +168,7 @@ public abstract class ArrowPopup<T extends Context & ActivityContext> mIterateChildrenTag = getContext().getString(R.string.popup_container_iterate_children); - if (!ENABLE_MATERIAL_U_POPUP.get() && mActivityContext.canUseMultipleShadesForPopup()) { + if (mActivityContext.canUseMultipleShadesForPopup()) { mColorIds = new int[]{R.color.popup_shade_first, R.color.popup_shade_second, R.color.popup_shade_third}; } else { @@ -241,14 +239,13 @@ public abstract class ArrowPopup<T extends Context & ActivityContext> } } - int numVisibleChild = 0; int numVisibleShortcut = 0; View lastView = null; AnimatorSet colorAnimator = new AnimatorSet(); for (int i = 0; i < count; i++) { View view = viewGroup.getChildAt(i); if (view.getVisibility() == VISIBLE) { - if (lastView != null) { + if (lastView != null && (isShortcutContainer(lastView))) { MarginLayoutParams mlp = (MarginLayoutParams) lastView.getLayoutParams(); mlp.bottomMargin = mChildContainerMargin; } @@ -256,26 +253,13 @@ public abstract class ArrowPopup<T extends Context & ActivityContext> MarginLayoutParams mlp = (MarginLayoutParams) lastView.getLayoutParams(); mlp.bottomMargin = 0; - if (colors != null) { - if (!ENABLE_MATERIAL_U_POPUP.get()) { - backgroundColor = colors[numVisibleChild % colors.length]; - } - - if (ENABLE_MATERIAL_U_POPUP.get() && isShortcutContainer(view)) { - setChildColor(view, colors[0], colorAnimator); - mArrowColor = colors[0]; - } - } - - // Arrow color matches the first child or the last child. - if (!ENABLE_MATERIAL_U_POPUP.get() - && (mIsAboveIcon || (numVisibleChild == 0 && viewGroup == this))) { - mArrowColor = backgroundColor; + if (colors != null && isShortcutContainer(view)) { + setChildColor(view, colors[0], colorAnimator); + mArrowColor = colors[0]; } if (view instanceof ViewGroup && isShortcutContainer(view)) { assignMarginsAndBackgrounds((ViewGroup) view, backgroundColor); - numVisibleChild++; continue; } @@ -295,7 +279,6 @@ public abstract class ArrowPopup<T extends Context & ActivityContext> } setChildColor(view, backgroundColor, colorAnimator); - numVisibleChild++; } } @@ -433,8 +416,7 @@ public abstract class ArrowPopup<T extends Context & ActivityContext> private void orientAboutObject(boolean allowAlignLeft, boolean allowAlignRight) { measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED); - int extraVerticalSpace = mArrowHeight + mArrowOffsetVertical - + getResources().getDimensionPixelSize(R.dimen.popup_vertical_padding); + int extraVerticalSpace = mArrowHeight + mArrowOffsetVertical + getExtraVerticalOffset(); // The margins are added after we call this method, so we need to account for them here. int numVisibleChildren = 0; for (int i = getChildCount() - 1; i >= 0; --i) { @@ -573,23 +555,14 @@ public abstract class ArrowPopup<T extends Context & ActivityContext> protected void animateOpen() { setVisibility(View.VISIBLE); - mOpenCloseAnimator = ENABLE_MATERIAL_U_POPUP.get() - ? getMaterialUOpenCloseAnimator( + mOpenCloseAnimator = getOpenCloseAnimator( true, OPEN_DURATION_U, OPEN_FADE_START_DELAY_U, OPEN_FADE_DURATION_U, OPEN_CHILD_FADE_START_DELAY_U, OPEN_CHILD_FADE_DURATION_U, - EMPHASIZED_DECELERATE) - : getOpenCloseAnimator( - true, - mOpenDuration, - mOpenFadeStartDelay, - mOpenFadeDuration, - mOpenChildFadeStartDelay, - mOpenChildFadeDuration, - DECELERATED_EASE); + EMPHASIZED_DECELERATE); onCreateOpenAnimation(mOpenCloseAnimator); mOpenCloseAnimator.addListener(new AnimatorListenerAdapter() { @@ -603,44 +576,6 @@ public abstract class ArrowPopup<T extends Context & ActivityContext> mOpenCloseAnimator.start(); } - private AnimatorSet getOpenCloseAnimator(boolean isOpening, int totalDuration, - int fadeStartDelay, int fadeDuration, int childFadeStartDelay, - int childFadeDuration, Interpolator interpolator) { - final AnimatorSet animatorSet = new AnimatorSet(); - float[] alphaValues = isOpening ? new float[] {0, 1} : new float[] {1, 0}; - float[] scaleValues = isOpening ? new float[] {0.5f, 1} : new float[] {1, 0.5f}; - - ValueAnimator fade = ValueAnimator.ofFloat(alphaValues); - fade.setStartDelay(fadeStartDelay); - fade.setDuration(fadeDuration); - fade.setInterpolator(LINEAR); - fade.addUpdateListener(anim -> { - float alpha = (float) anim.getAnimatedValue(); - mArrow.setAlpha(alpha); - setAlpha(alpha); - }); - animatorSet.play(fade); - - setPivotX(mIsLeftAligned ? 0 : getMeasuredWidth()); - setPivotY(mIsAboveIcon ? getMeasuredHeight() : 0); - Animator scale = ObjectAnimator.ofFloat(this, View.SCALE_Y, scaleValues); - scale.setDuration(totalDuration); - scale.setInterpolator(interpolator); - animatorSet.play(scale); - - if (shouldScaleArrow) { - Animator arrowScaleAnimator = ObjectAnimator.ofFloat(mArrow, View.SCALE_Y, - scaleValues); - arrowScaleAnimator.setDuration(totalDuration); - arrowScaleAnimator.setInterpolator(interpolator); - animatorSet.play(arrowScaleAnimator); - } - - fadeInChildViews(this, alphaValues, childFadeStartDelay, childFadeDuration, animatorSet); - - return animatorSet; - } - private void fadeInChildViews(ViewGroup group, float[] alphaValues, long startDelay, long duration, AnimatorSet out) { for (int i = group.getChildCount() - 1; i >= 0; --i) { @@ -673,22 +608,14 @@ public abstract class ArrowPopup<T extends Context & ActivityContext> } mIsOpen = false; - mOpenCloseAnimator = ENABLE_MATERIAL_U_POPUP.get() - ? getMaterialUOpenCloseAnimator( + mOpenCloseAnimator = getOpenCloseAnimator( false, CLOSE_DURATION_U, CLOSE_FADE_START_DELAY_U, CLOSE_FADE_DURATION_U, CLOSE_CHILD_FADE_START_DELAY_U, CLOSE_CHILD_FADE_DURATION_U, - EMPHASIZED_ACCELERATE) - : getOpenCloseAnimator(false, - mCloseDuration, - mCloseFadeStartDelay, - mCloseFadeDuration, - mCloseChildFadeStartDelay, - mCloseChildFadeDuration, - ACCELERATED_EASE); + EMPHASIZED_ACCELERATE); onCreateCloseAnimation(mOpenCloseAnimator); mOpenCloseAnimator.addListener(new AnimatorListenerAdapter() { @@ -705,7 +632,11 @@ public abstract class ArrowPopup<T extends Context & ActivityContext> mOpenCloseAnimator.start(); } - protected AnimatorSet getMaterialUOpenCloseAnimator(boolean isOpening, int scaleDuration, + public int getExtraVerticalOffset() { + return getResources().getDimensionPixelSize(R.dimen.popup_vertical_padding); + } + + protected AnimatorSet getOpenCloseAnimator(boolean isOpening, int scaleDuration, int fadeStartDelay, int fadeDuration, int childFadeStartDelay, int childFadeDuration, Interpolator interpolator) { diff --git a/src/com/android/launcher3/popup/PopupContainerWithArrow.java b/src/com/android/launcher3/popup/PopupContainerWithArrow.java index 1f26bab502..934d43b187 100644 --- a/src/com/android/launcher3/popup/PopupContainerWithArrow.java +++ b/src/com/android/launcher3/popup/PopupContainerWithArrow.java @@ -20,21 +20,15 @@ import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_SHORTCU import static com.android.launcher3.Utilities.ATLEAST_P; import static com.android.launcher3.Utilities.squaredHypot; import static com.android.launcher3.Utilities.squaredTouchSlop; -import static com.android.launcher3.config.FeatureFlags.ENABLE_MATERIAL_U_POPUP; import static com.android.launcher3.popup.PopupPopulator.MAX_SHORTCUTS; -import static com.android.launcher3.popup.PopupPopulator.MAX_SHORTCUTS_IF_NOTIFICATIONS; import static com.android.launcher3.util.Executors.MODEL_EXECUTOR; -import static java.util.Collections.emptyList; - import android.animation.AnimatorSet; import android.animation.LayoutTransition; -import android.annotation.TargetApi; import android.content.Context; import android.graphics.Point; import android.graphics.PointF; import android.graphics.Rect; -import android.os.Build; import android.os.Handler; import android.os.Looper; import android.util.AttributeSet; @@ -55,17 +49,12 @@ import com.android.launcher3.Launcher; import com.android.launcher3.R; import com.android.launcher3.accessibility.LauncherAccessibilityDelegate; import com.android.launcher3.accessibility.ShortcutMenuAccessibilityDelegate; -import com.android.launcher3.dot.DotInfo; import com.android.launcher3.dragndrop.DragController; import com.android.launcher3.dragndrop.DragOptions; import com.android.launcher3.dragndrop.DragView; import com.android.launcher3.dragndrop.DraggableView; import com.android.launcher3.model.data.ItemInfo; -import com.android.launcher3.model.data.ItemInfoWithIcon; import com.android.launcher3.model.data.WorkspaceItemInfo; -import com.android.launcher3.notification.NotificationContainer; -import com.android.launcher3.notification.NotificationInfo; -import com.android.launcher3.notification.NotificationKeyData; import com.android.launcher3.shortcuts.DeepShortcutView; import com.android.launcher3.shortcuts.ShortcutDragPreviewProvider; import com.android.launcher3.touch.ItemLongClickListener; @@ -81,7 +70,7 @@ import java.util.Optional; import java.util.stream.Collectors; /** - * A container for shortcuts to deep links and notifications associated with an app. + * A container for shortcuts to deep links associated with an app. * * @param <T> The activity on with the popup shows */ @@ -98,8 +87,6 @@ public class PopupContainerWithArrow<T extends Context & ActivityContext> private final float mShortcutHeight; private BubbleTextView mOriginalIcon; - private int mNumNotifications; - private NotificationContainer mNotificationContainer; private int mContainerWidth; private ViewGroup mWidgetContainer; @@ -142,24 +129,12 @@ public class PopupContainerWithArrow<T extends Context & ActivityContext> if (ev.getAction() == MotionEvent.ACTION_DOWN) { mInterceptTouchDown.set(ev.getX(), ev.getY()); } - if (mNotificationContainer != null - && mNotificationContainer.onInterceptSwipeEvent(ev)) { - return true; - } // Stop sending touch events to deep shortcut views if user moved beyond touch slop. return squaredHypot(mInterceptTouchDown.x - ev.getX(), mInterceptTouchDown.y - ev.getY()) > squaredTouchSlop(getContext()); } @Override - public boolean onTouchEvent(MotionEvent ev) { - if (mNotificationContainer != null) { - return mNotificationContainer.onSwipeEvent(ev) || super.onTouchEvent(ev); - } - return super.onTouchEvent(ev); - } - - @Override protected boolean isOfType(int type) { return (type & TYPE_ACTION_POPUP) != 0; } @@ -194,14 +169,6 @@ public class PopupContainerWithArrow<T extends Context & ActivityContext> return false; } - @Override - protected void setChildColor(View view, int color, AnimatorSet animatorSetOut) { - super.setChildColor(view, color, animatorSetOut); - if (view.getId() == R.id.notification_container && mNotificationContainer != null) { - mNotificationContainer.updateBackgroundColor(color, animatorSetOut); - } - } - /** * Returns true if we can show the container. * @@ -213,7 +180,8 @@ public class PopupContainerWithArrow<T extends Context & ActivityContext> } /** - * Shows the notifications and deep shortcuts associated with a Launcher {@param icon}. + * Shows a popup with shortcuts associated with a Launcher icon + * @param icon the app icon to show the popup for * @return the container if shown or null. */ public static PopupContainerWithArrow<Launcher> showForIcon(BubbleTextView icon) { @@ -235,21 +203,10 @@ public class PopupContainerWithArrow<T extends Context & ActivityContext> .map(s -> s.getShortcut(launcher, item, icon)) .filter(Objects::nonNull) .collect(Collectors.toList()); - if (ENABLE_MATERIAL_U_POPUP.get()) { - container = (PopupContainerWithArrow) launcher.getLayoutInflater().inflate( - R.layout.popup_container_material_u, launcher.getDragLayer(), false); - container.configureForLauncher(launcher); - container.populateAndShowRowsMaterialU(icon, deepShortcutCount, systemShortcuts); - } else { - container = (PopupContainerWithArrow) launcher.getLayoutInflater().inflate( - R.layout.popup_container, launcher.getDragLayer(), false); - container.configureForLauncher(launcher); - container.populateAndShow( - icon, - deepShortcutCount, - popupDataProvider.getNotificationKeysForItem(item), - systemShortcuts); - } + container = (PopupContainerWithArrow) launcher.getLayoutInflater().inflate( + R.layout.popup_container, launcher.getDragLayer(), false); + container.configureForLauncher(launcher); + container.populateAndShowRows(icon, deepShortcutCount, systemShortcuts); launcher.refreshAndBindWidgetsForPackageUser(PackageUserKey.fromItemInfo(item)); container.requestFocus(); return container; @@ -263,91 +220,6 @@ public class PopupContainerWithArrow<T extends Context & ActivityContext> launcher.getDragController().addDragListener(this); } - private void initializeSystemShortcuts(List<SystemShortcut> shortcuts) { - if (shortcuts.isEmpty()) { - return; - } - // If there is only 1 shortcut, add it to its own container so it can show text and icon - if (shortcuts.size() == 1) { - mSystemShortcutContainer = inflateAndAdd(R.layout.system_shortcut_rows_container, - this, 0); - initializeSystemShortcut(R.layout.system_shortcut, mSystemShortcutContainer, - shortcuts.get(0), false); - return; - } - addSystemShortcutsIconsOnly(shortcuts); - } - - @TargetApi(Build.VERSION_CODES.P) - public void populateAndShow(final BubbleTextView originalIcon, int shortcutCount, - final List<NotificationKeyData> notificationKeys, List<SystemShortcut> shortcuts) { - mNumNotifications = notificationKeys.size(); - mOriginalIcon = originalIcon; - - boolean hasDeepShortcuts = shortcutCount > 0; - mContainerWidth = getResources().getDimensionPixelSize(R.dimen.bg_popup_item_width); - - // 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(); - } - mSystemShortcutContainer = this; - if (mDeepShortcutContainer == null) { - mDeepShortcutContainer = findViewById(R.id.deep_shortcuts_container); - } - if (hasDeepShortcuts) { - List<SystemShortcut> systemShortcuts = getNonWidgetSystemShortcuts(shortcuts); - // if there are deep shortcuts, we might want to increase the width of shortcuts to fit - // horizontally laid out system shortcuts. - mContainerWidth = Math.max(mContainerWidth, - systemShortcuts.size() * getResources() - .getDimensionPixelSize(R.dimen.system_shortcut_header_icon_touch_size) - ); - - mDeepShortcutContainer.setVisibility(View.VISIBLE); - - for (int i = shortcutCount; i > 0; i--) { - DeepShortcutView v = inflateAndAdd(R.layout.deep_shortcut, mDeepShortcutContainer); - v.getLayoutParams().width = mContainerWidth; - mDeepShortcuts.add(v); - } - updateHiddenShortcuts(); - Optional<SystemShortcut.Widgets> widgetShortcutOpt = getWidgetShortcut(shortcuts); - if (widgetShortcutOpt.isPresent()) { - if (mWidgetContainer == null) { - mWidgetContainer = inflateAndAdd(R.layout.widget_shortcut_container, this, 0); - } - initializeWidgetShortcut(mWidgetContainer, widgetShortcutOpt.get()); - } - - initializeSystemShortcuts(systemShortcuts); - } else { - mDeepShortcutContainer.setVisibility(View.GONE); - mSystemShortcutContainer = inflateAndAdd(R.layout.system_shortcut_rows_container, - this, 0); - mWidgetContainer = mSystemShortcutContainer; - if (!shortcuts.isEmpty()) { - for (int i = 0; i < shortcuts.size(); i++) { - initializeSystemShortcut( - R.layout.system_shortcut, - mSystemShortcutContainer, - shortcuts.get(i), - i < shortcuts.size() - 1); - } - } - } - show(); - loadAppShortcuts((ItemInfo) originalIcon.getTag(), notificationKeys); - } - /** * Populate and show shortcuts for the Launcher U app shortcut design. * Will inflate the container and shortcut View instances for the popup container. @@ -355,28 +227,27 @@ public class PopupContainerWithArrow<T extends Context & ActivityContext> * @param deepShortcutCount Number of DeepShortcutView instances to add to container * @param systemShortcuts List of SystemShortcuts to add to container */ - public void populateAndShowRowsMaterialU(final BubbleTextView originalIcon, + public void populateAndShowRows(final BubbleTextView originalIcon, int deepShortcutCount, List<SystemShortcut> systemShortcuts) { mOriginalIcon = originalIcon; mContainerWidth = getResources().getDimensionPixelSize(R.dimen.bg_popup_item_width); if (deepShortcutCount > 0) { - addAllShortcutsMaterialU(deepShortcutCount, systemShortcuts); + addAllShortcuts(deepShortcutCount, systemShortcuts); } else if (!systemShortcuts.isEmpty()) { - addSystemShortcutsMaterialU(systemShortcuts, - R.layout.system_shortcut_rows_container_material_u, + addSystemShortcuts(systemShortcuts, + R.layout.system_shortcut_rows_container, R.layout.system_shortcut); } show(); - loadAppShortcuts((ItemInfo) originalIcon.getTag(), /* notificationKeys= */ emptyList()); + loadAppShortcuts((ItemInfo) originalIcon.getTag()); } /** * Animates and loads shortcuts on background thread for this popup container */ - private void loadAppShortcuts(ItemInfo originalItemInfo, - List<NotificationKeyData> notificationKeys) { + private void loadAppShortcuts(ItemInfo originalItemInfo) { if (ATLEAST_P) { setAccessibilityPaneTitle(getTitleForAccessibility()); @@ -387,7 +258,7 @@ public class PopupContainerWithArrow<T extends Context & ActivityContext> // Load the shortcuts on a background thread and update the container as it animates. MODEL_EXECUTOR.getHandler().postAtFrontOfQueue(PopupPopulator.createUpdateRunnable( mActivityContext, originalItemInfo, new Handler(Looper.getMainLooper()), - this, mDeepShortcuts, notificationKeys)); + this, mDeepShortcuts)); } /** @@ -396,16 +267,16 @@ public class PopupContainerWithArrow<T extends Context & ActivityContext> * @param deepShortcutCount number of DeepShortcutView instances * @param systemShortcuts List of SystemShortcuts */ - private void addAllShortcutsMaterialU(int deepShortcutCount, + private void addAllShortcuts(int deepShortcutCount, List<SystemShortcut> systemShortcuts) { if (deepShortcutCount + systemShortcuts.size() <= SHORTCUT_COLLAPSE_THRESHOLD) { // add all system shortcuts including widgets shortcut to same container - addSystemShortcutsMaterialU(systemShortcuts, - R.layout.system_shortcut_rows_container_material_u, + addSystemShortcuts(systemShortcuts, + R.layout.system_shortcut_rows_container, R.layout.system_shortcut); float currentHeight = (mShortcutHeight * systemShortcuts.size()) + mChildContainerMargin; - addDeepShortcutsMaterialU(deepShortcutCount, currentHeight); + addDeepShortcuts(deepShortcutCount, currentHeight); return; } @@ -426,7 +297,7 @@ public class PopupContainerWithArrow<T extends Context & ActivityContext> initializeWidgetShortcut(mWidgetContainer, widgetShortcutOpt.get()); currentHeight += mShortcutHeight + mChildContainerMargin; } - addDeepShortcutsMaterialU(deepShortcutCount, currentHeight); + addDeepShortcuts(deepShortcutCount, currentHeight); } /** @@ -464,7 +335,7 @@ public class PopupContainerWithArrow<T extends Context & ActivityContext> * @param systemShortcutContainerLayout Layout Resource for the Container of shortcut Views * @param systemShortcutLayout Layout Resource for the individual shortcut Views */ - private void addSystemShortcutsMaterialU(List<SystemShortcut> systemShortcuts, + private void addSystemShortcuts(List<SystemShortcut> systemShortcuts, @LayoutRes int systemShortcutContainerLayout, @LayoutRes int systemShortcutLayout) { if (systemShortcuts.size() == 0) { @@ -486,9 +357,7 @@ public class PopupContainerWithArrow<T extends Context & ActivityContext> return; } - mSystemShortcutContainer = ENABLE_MATERIAL_U_POPUP.get() - ? inflateAndAdd(R.layout.system_shortcut_icons_container_material_u, this) - : inflateAndAdd(R.layout.system_shortcut_icons_container, this, 0); + mSystemShortcutContainer = inflateAndAdd(R.layout.system_shortcut_icons_container, this); for (int i = 0; i < systemShortcuts.size(); i++) { @LayoutRes int shortcutIconLayout = R.layout.system_shortcut_icon_only; @@ -513,13 +382,13 @@ public class PopupContainerWithArrow<T extends Context & ActivityContext> * @param deepShortcutCount number of DeepShortcutView instances to add * @param currentHeight height of popup before adding deep shortcuts */ - private void addDeepShortcutsMaterialU(int deepShortcutCount, float currentHeight) { + private void addDeepShortcuts(int deepShortcutCount, float currentHeight) { mDeepShortcutContainer = inflateAndAdd(R.layout.deep_shortcut_container, this); for (int i = deepShortcutCount; i > 0; i--) { currentHeight += mShortcutHeight; // when there is limited vertical screen space, limit total popup rows to fit if (currentHeight >= mActivityContext.getDeviceProfile().availableHeightPx) break; - DeepShortcutView v = inflateAndAdd(R.layout.deep_shortcut_material_u, + DeepShortcutView v = inflateAndAdd(R.layout.deep_shortcut, mDeepShortcutContainer); v.getLayoutParams().width = mContainerWidth; mDeepShortcuts.add(v); @@ -527,10 +396,6 @@ public class PopupContainerWithArrow<T extends Context & ActivityContext> updateHiddenShortcuts(); } - protected NotificationContainer getNotificationContainer() { - return mNotificationContainer; - } - protected BubbleTextView getOriginalIcon() { return mOriginalIcon; } @@ -548,9 +413,7 @@ public class PopupContainerWithArrow<T extends Context & ActivityContext> } private String getTitleForAccessibility() { - return getContext().getString(mNumNotifications == 0 ? - R.string.action_deep_shortcut : - R.string.shortcuts_menu_with_notifications_description); + return getContext().getString(R.string.action_deep_shortcut); } @Override @@ -564,20 +427,11 @@ public class PopupContainerWithArrow<T extends Context & ActivityContext> : mOriginalIcon.getHeight()); } - public void applyNotificationInfos(List<NotificationInfo> notificationInfos) { - if (mNotificationContainer != null) { - mNotificationContainer.applyNotificationInfos(notificationInfos); - } - } - protected void updateHiddenShortcuts() { - int allowedCount = mNotificationContainer != null - ? MAX_SHORTCUTS_IF_NOTIFICATIONS : MAX_SHORTCUTS; - int total = mDeepShortcuts.size(); for (int i = 0; i < total; i++) { DeepShortcutView view = mDeepShortcuts.get(i); - view.setVisibility(i >= allowedCount ? GONE : VISIBLE); + view.setVisibility(i >= MAX_SHORTCUTS ? GONE : VISIBLE); } } @@ -666,14 +520,6 @@ public class PopupContainerWithArrow<T extends Context & ActivityContext> }; } - protected void updateNotificationHeader() { - ItemInfoWithIcon itemInfo = (ItemInfoWithIcon) mOriginalIcon.getTag(); - DotInfo dotInfo = mActivityContext.getDotInfoForItem(itemInfo); - if (mNotificationContainer != null && dotInfo != null) { - mNotificationContainer.updateHeader(dotInfo.getNotificationCount()); - } - } - @Override public void onDropCompleted(View target, DragObject d, boolean success) { } diff --git a/src/com/android/launcher3/popup/PopupLiveUpdateHandler.java b/src/com/android/launcher3/popup/PopupLiveUpdateHandler.java index c5d545225c..9d6f2a5b51 100644 --- a/src/com/android/launcher3/popup/PopupLiveUpdateHandler.java +++ b/src/com/android/launcher3/popup/PopupLiveUpdateHandler.java @@ -15,22 +15,12 @@ */ package com.android.launcher3.popup; -import static android.view.View.GONE; - import android.content.Context; import android.view.View; import com.android.launcher3.BubbleTextView; -import com.android.launcher3.dot.DotInfo; -import com.android.launcher3.model.data.ItemInfo; -import com.android.launcher3.notification.NotificationContainer; -import com.android.launcher3.notification.NotificationKeyData; -import com.android.launcher3.util.PackageUserKey; import com.android.launcher3.views.ActivityContext; -import java.util.Map; -import java.util.function.Predicate; - /** * Utility class to handle updates while the popup is visible (like widgets and * notification changes) @@ -67,40 +57,6 @@ public abstract class PopupLiveUpdateHandler<T extends Context & ActivityContext } } - /** - * Updates the notification header if the original icon's dot updated. - */ - @Override - public void onNotificationDotsUpdated(Predicate<PackageUserKey> updatedDots) { - ItemInfo itemInfo = (ItemInfo) mPopupContainerWithArrow.getOriginalIcon().getTag(); - PackageUserKey packageUser = PackageUserKey.fromItemInfo(itemInfo); - if (updatedDots.test(packageUser)) { - mPopupContainerWithArrow.updateNotificationHeader(); - } - } - - - @Override - public void trimNotifications(Map<PackageUserKey, DotInfo> updatedDots) { - NotificationContainer notificationContainer = - mPopupContainerWithArrow.getNotificationContainer(); - if (notificationContainer == null) { - return; - } - ItemInfo originalInfo = (ItemInfo) mPopupContainerWithArrow.getOriginalIcon().getTag(); - DotInfo dotInfo = updatedDots.get(PackageUserKey.fromItemInfo(originalInfo)); - if (dotInfo == null || dotInfo.getNotificationKeys().size() == 0) { - // No more notifications, remove the notification views and expand all shortcuts. - notificationContainer.setVisibility(GONE); - mPopupContainerWithArrow.updateHiddenShortcuts(); - mPopupContainerWithArrow.assignMarginsAndBackgrounds(mPopupContainerWithArrow); - mPopupContainerWithArrow.updateArrowColor(); - } else { - notificationContainer.trimNotifications( - NotificationKeyData.extractKeysOnly(dotInfo.getNotificationKeys())); - } - } - @Override public void onSystemShortcutsUpdated() { mPopupContainerWithArrow.close(true); diff --git a/src/com/android/launcher3/popup/PopupPopulator.java b/src/com/android/launcher3/popup/PopupPopulator.java index 8be4e6c8d9..aa24f60b72 100644 --- a/src/com/android/launcher3/popup/PopupPopulator.java +++ b/src/com/android/launcher3/popup/PopupPopulator.java @@ -24,26 +24,19 @@ import android.content.pm.ShortcutInfo; import android.os.Handler; import android.os.UserHandle; -import androidx.annotation.Nullable; import androidx.annotation.VisibleForTesting; import com.android.launcher3.LauncherAppState; import com.android.launcher3.icons.IconCache; import com.android.launcher3.model.data.ItemInfo; import com.android.launcher3.model.data.WorkspaceItemInfo; -import com.android.launcher3.notification.NotificationInfo; -import com.android.launcher3.notification.NotificationKeyData; -import com.android.launcher3.notification.NotificationListener; import com.android.launcher3.shortcuts.DeepShortcutView; import com.android.launcher3.shortcuts.ShortcutRequest; import com.android.launcher3.views.ActivityContext; import java.util.ArrayList; -import java.util.Collections; import java.util.Comparator; -import java.util.Iterator; import java.util.List; -import java.util.stream.Collectors; /** * Contains logic relevant to populating a {@link PopupContainerWithArrow}. In particular, @@ -52,24 +45,20 @@ import java.util.stream.Collectors; public class PopupPopulator { public static final int MAX_SHORTCUTS = 4; - @VisibleForTesting static final int NUM_DYNAMIC = 2; - public static final int MAX_SHORTCUTS_IF_NOTIFICATIONS = 2; + @VisibleForTesting + static final int NUM_DYNAMIC = 2; /** * Sorts shortcuts in rank order, with manifest shortcuts coming before dynamic shortcuts. */ - private static final Comparator<ShortcutInfo> SHORTCUT_RANK_COMPARATOR - = new Comparator<ShortcutInfo>() { - @Override - public int compare(ShortcutInfo a, ShortcutInfo b) { - if (a.isDeclaredInManifest() && !b.isDeclaredInManifest()) { - return -1; - } - if (!a.isDeclaredInManifest() && b.isDeclaredInManifest()) { - return 1; - } - return Integer.compare(a.getRank(), b.getRank()); + private static final Comparator<ShortcutInfo> SHORTCUT_RANK_COMPARATOR = (a, b) -> { + if (a.isDeclaredInManifest() && !b.isDeclaredInManifest()) { + return -1; + } + if (!a.isDeclaredInManifest() && b.isDeclaredInManifest()) { + return 1; } + return Integer.compare(a.getRank(), b.getRank()); }; /** @@ -77,23 +66,10 @@ public class PopupPopulator { * We want the filter to include both static and dynamic shortcuts, so we always * include NUM_DYNAMIC dynamic shortcuts, if at least that many are present. * - * @param shortcutIdToRemoveFirst An id that should be filtered out first, if any. * @return a subset of shortcuts, in sorted order, with size <= MAX_SHORTCUTS. */ - public static List<ShortcutInfo> sortAndFilterShortcuts( - List<ShortcutInfo> shortcuts, @Nullable String shortcutIdToRemoveFirst) { - // Remove up to one specific shortcut before sorting and doing somewhat fancy filtering. - if (shortcutIdToRemoveFirst != null) { - Iterator<ShortcutInfo> shortcutIterator = shortcuts.iterator(); - while (shortcutIterator.hasNext()) { - if (shortcutIterator.next().getId().equals(shortcutIdToRemoveFirst)) { - shortcutIterator.remove(); - break; - } - } - } - - Collections.sort(shortcuts, SHORTCUT_RANK_COMPARATOR); + public static List<ShortcutInfo> sortAndFilterShortcuts(List<ShortcutInfo> shortcuts) { + shortcuts.sort(SHORTCUT_RANK_COMPARATOR); if (shortcuts.size() <= MAX_SHORTCUTS) { return shortcuts; } @@ -127,37 +103,20 @@ public class PopupPopulator { } /** - * Returns a runnable to update the provided shortcuts and notifications + * Returns a runnable to update the provided shortcuts */ public static <T extends Context & ActivityContext> Runnable createUpdateRunnable( final T context, final ItemInfo originalInfo, final Handler uiHandler, final PopupContainerWithArrow container, - final List<DeepShortcutView> shortcutViews, - final List<NotificationKeyData> notificationKeys) { + final List<DeepShortcutView> shortcutViews) { 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(context, sbn, originalInfo)) - .collect(Collectors.toList()); - } - uiHandler.post(() -> container.applyNotificationInfos(infos)); - } - List<ShortcutInfo> shortcuts = new ShortcutRequest(context, user) .withContainer(activity) .query(ShortcutRequest.PUBLISHED); - String shortcutIdToDeDupe = notificationKeys.isEmpty() ? null - : notificationKeys.get(0).shortcutId; - shortcuts = PopupPopulator.sortAndFilterShortcuts(shortcuts, shortcutIdToDeDupe); + shortcuts = PopupPopulator.sortAndFilterShortcuts(shortcuts); IconCache cache = LauncherAppState.getInstance(context).getIconCache(); for (int i = 0; i < shortcuts.size() && i < shortcutViews.size(); i++) { final ShortcutInfo shortcut = shortcuts.get(i); |