diff --git a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarController.java b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarController.java index 3dcf2b4ebf..7d39bf8d4d 100644 --- a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarController.java +++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarController.java @@ -342,10 +342,10 @@ public class BubbleBarController extends IBubblesListener.Stub { mBubbleBarViewController.showOverflow(update.showOverflow); } - BubbleBarBubble bubbleToSelect = null; if (update.addedBubble != null) { mBubbles.put(update.addedBubble.getKey(), update.addedBubble); } + BubbleBarBubble bubbleToSelect = null; if (update.selectedBubbleKey != null) { if (mSelectedBubble == null || !update.selectedBubbleKey.equals(mSelectedBubble.getKey())) { @@ -363,7 +363,7 @@ public class BubbleBarController extends IBubblesListener.Stub { && update.removedBubbles.isEmpty() && !mBubbles.isEmpty()) { // A bubble was added from the overflow (& now it's empty / not showing) - mBubbleBarViewController.removeOverflowAndAddBubble(update.addedBubble); + mBubbleBarViewController.removeOverflowAndAddBubble(update.addedBubble, bubbleToSelect); } else if (update.addedBubble != null && update.removedBubbles.size() == 1) { // we're adding and removing a bubble at the same time. handle this as a single update. RemovedBubble removedBubble = update.removedBubbles.get(0); @@ -371,7 +371,8 @@ public class BubbleBarController extends IBubblesListener.Stub { boolean showOverflow = update.showOverflowChanged && update.showOverflow; if (bubbleToRemove != null) { mBubbleBarViewController.addBubbleAndRemoveBubble(update.addedBubble, - bubbleToRemove, isExpanding, suppressAnimation, showOverflow); + bubbleToRemove, bubbleToSelect, isExpanding, suppressAnimation, + showOverflow); } else { mBubbleBarViewController.addBubble(update.addedBubble, isExpanding, suppressAnimation, bubbleToSelect); @@ -387,7 +388,7 @@ public class BubbleBarController extends IBubblesListener.Stub { if (bubble != null && overflowNeedsToBeAdded) { // First removal, show the overflow overflowNeedsToBeAdded = false; - mBubbleBarViewController.addOverflowAndRemoveBubble(bubble); + mBubbleBarViewController.addOverflowAndRemoveBubble(bubble, bubbleToSelect); } else if (bubble != null) { mBubbleBarViewController.removeBubble(bubble); } else { diff --git a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarView.java b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarView.java index c9575e84aa..2d4d279564 100644 --- a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarView.java +++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarView.java @@ -741,12 +741,10 @@ public class BubbleBarView extends FrameLayout { /** Add a new bubble and remove an old bubble from the bubble bar. */ public void addBubbleAndRemoveBubble(BubbleView addedBubble, BubbleView removedBubble, - Runnable onEndRunnable) { + @Nullable BubbleView bubbleToSelect, Runnable onEndRunnable) { FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams((int) mIconSize, (int) mIconSize, Gravity.LEFT); - boolean removingOverflow = removedBubble.isOverflow(); - boolean addingOverflow = addedBubble.isOverflow(); - int addedIndex = addingOverflow ? getChildCount() : 0; + int addedIndex = addedBubble.isOverflow() ? getChildCount() : 0; if (!isExpanded()) { removeView(removedBubble); addView(addedBubble, addedIndex, lp); @@ -760,19 +758,14 @@ public class BubbleBarView extends FrameLayout { addView(addedBubble, addedIndex, lp); int indexOfCurrentSelectedBubble = indexOfChild(mSelectedBubbleView); int indexOfBubbleToRemove = indexOfChild(removedBubble); - int indexOfNewlySelectedBubble = indexOfCurrentSelectedBubble; - boolean removingSelectedBubble = mSelectedBubbleView == removedBubble; - if (removingSelectedBubble) { - if (removingOverflow) { - // The added bubble will be selected - mSelectedBubbleView = addedBubble; - indexOfNewlySelectedBubble = indexOfChild(mSelectedBubbleView); - } else { - boolean isRemovedNextToOverflow = - indexOfBubbleToRemove == getChildCount() - (hasOverflow() ? 2 : 1); - indexOfNewlySelectedBubble = - indexOfCurrentSelectedBubble + (isRemovedNextToOverflow ? -1 : 1); - } + int indexOfNewlySelectedBubble = bubbleToSelect == null + ? indexOfCurrentSelectedBubble : indexOfChild(bubbleToSelect); + // Since removed bubble is kept till the end of the animation we should check if there are + // more than one bubble. In such a case the bar will remain open without the selected bubble + if (mSelectedBubbleView == removedBubble + && bubbleToSelect == null + && getBubbleChildCount() > 1) { + Log.w(TAG, "Remove the currently selected bubble without selecting a new one."); } mBubbleAnimator = new BubbleAnimator(mIconSize, mExpandedBarIconsSpacing, getChildCount(), mBubbleBarLocation.isOnLeft(isLayoutRtl())); diff --git a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarViewController.java b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarViewController.java index 5685093097..d85f7b4e1c 100644 --- a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarViewController.java +++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarViewController.java @@ -843,11 +843,12 @@ public class BubbleBarViewController { } /** Adds a new bubble and removes an old bubble at the same time. */ - public void addBubbleAndRemoveBubble(BubbleBarBubble addedBubble, - BubbleBarBubble removedBubble, boolean isExpanding, boolean suppressAnimation, - boolean addOverflowToo) { + public void addBubbleAndRemoveBubble(BubbleBarBubble addedBubble, BubbleBarBubble removedBubble, + @Nullable BubbleBarBubble bubbleToSelect, boolean isExpanding, + boolean suppressAnimation, boolean addOverflowToo) { + BubbleView bubbleToSelectView = bubbleToSelect == null ? null : bubbleToSelect.getView(); mBarView.addBubbleAndRemoveBubble(addedBubble.getView(), removedBubble.getView(), - addOverflowToo ? () -> showOverflow(true) : null); + bubbleToSelectView, addOverflowToo ? () -> showOverflow(true) : null); addedBubble.getView().setOnClickListener(mBubbleClickListener); addedBubble.getView().setController(mBubbleViewController); removedBubble.getView().setController(null); @@ -878,22 +879,26 @@ public class BubbleBarViewController { } /** Adds the overflow view to the bubble bar while animating a view away. */ - public void addOverflowAndRemoveBubble(BubbleBarBubble removedBubble) { + public void addOverflowAndRemoveBubble(BubbleBarBubble removedBubble, + @Nullable BubbleBarBubble bubbleToSelect) { if (mOverflowAdded) return; mOverflowAdded = true; + BubbleView bubbleToSelectView = bubbleToSelect == null ? null : bubbleToSelect.getView(); mBarView.addBubbleAndRemoveBubble(mOverflowBubble.getView(), removedBubble.getView(), - null /* onEndRunnable */); + bubbleToSelectView, null /* onEndRunnable */); mOverflowBubble.getView().setOnClickListener(mBubbleClickListener); mOverflowBubble.getView().setController(mBubbleViewController); removedBubble.getView().setController(null); } /** Removes the overflow view to the bubble bar while animating a view in. */ - public void removeOverflowAndAddBubble(BubbleBarBubble addedBubble) { + public void removeOverflowAndAddBubble(BubbleBarBubble addedBubble, + @Nullable BubbleBarBubble bubbleToSelect) { if (!mOverflowAdded) return; mOverflowAdded = false; + BubbleView bubbleToSelectView = bubbleToSelect == null ? null : bubbleToSelect.getView(); mBarView.addBubbleAndRemoveBubble(addedBubble.getView(), mOverflowBubble.getView(), - null /* onEndRunnable */); + bubbleToSelectView, null /* onEndRunnable */); addedBubble.getView().setOnClickListener(mBubbleClickListener); addedBubble.getView().setController(mBubbleViewController); mOverflowBubble.getView().setController(null); diff --git a/quickstep/src/com/android/launcher3/taskbar/bubbles/animation/BubbleAnimator.kt b/quickstep/src/com/android/launcher3/taskbar/bubbles/animation/BubbleAnimator.kt index 3751ab2bc3..26d6cccc7d 100644 --- a/quickstep/src/com/android/launcher3/taskbar/bubbles/animation/BubbleAnimator.kt +++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/animation/BubbleAnimator.kt @@ -200,18 +200,20 @@ class BubbleAnimator( private fun getArrowPositionWhenAddingBubble(state: State.AddingBubble): Float { val scale = animator.animatedFraction - var tx = getBubbleTranslationXWhileScalingBubble( - bubbleIndex = state.selectedBubbleIndex, - scalingBubbleIndex = 0, - bubbleScale = scale - ) + iconSize / 2f + var tx = + getBubbleTranslationXWhileScalingBubble( + bubbleIndex = state.selectedBubbleIndex, + scalingBubbleIndex = 0, + bubbleScale = scale, + ) + iconSize / 2f if (state.newlySelectedBubbleIndex != null) { val selectedBubbleScale = if (state.newlySelectedBubbleIndex == 0) scale else 1f - val finalTx = getBubbleTranslationXWhileScalingBubble( - bubbleIndex = state.newlySelectedBubbleIndex, - scalingBubbleIndex = 0, - bubbleScale = scale - ) + iconSize * selectedBubbleScale / 2f + val finalTx = + getBubbleTranslationXWhileScalingBubble( + bubbleIndex = state.newlySelectedBubbleIndex, + scalingBubbleIndex = 0, + bubbleScale = scale, + ) + iconSize * selectedBubbleScale / 2f tx += (finalTx - tx) * animator.animatedFraction } return tx @@ -302,7 +304,6 @@ class BubbleAnimator( // bubble bar is on the right - 0 corresponds to the left - most bubble. if (onLeft) bubbleCount - bubbleIndex - 1 else bubbleIndex - /** * Returns the translation X for the bubble at index {@code bubbleIndex} when the bubble bar is * expanded and a bubble is animating in or out.