diff --git a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarView.java b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarView.java index a1ac28c2a7..c9575e84aa 100644 --- a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarView.java +++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarView.java @@ -806,7 +806,6 @@ public class BubbleBarView extends FrameLayout { invalidate(); } }; - //TODO (b/359952121) fix scenario when overflow is being added mBubbleAnimator.animateNewAndRemoveOld(indexOfCurrentSelectedBubble, indexOfNewlySelectedBubble, indexOfBubbleToRemove, addedIndex, listener); } 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 84e13ba56b..3751ab2bc3 100644 --- a/quickstep/src/com/android/launcher3/taskbar/bubbles/animation/BubbleAnimator.kt +++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/animation/BubbleAnimator.kt @@ -18,6 +18,8 @@ package com.android.launcher3.taskbar.bubbles.animation import androidx.core.animation.Animator import androidx.core.animation.ValueAnimator +import kotlin.math.max +import kotlin.math.min /** * Animates individual bubbles within the bubble bar while the bubble bar is expanded. @@ -141,6 +143,7 @@ class BubbleAnimator( getBubbleTranslationXWhileAddingBubbleAtLimit( bubbleIndex = bubbleIndex, removedBubbleIndex = state.removedBubbleIndex, + addedBubbleIndex = state.addedBubbleIndex, addedBubbleScale = animator.animatedFraction, removedBubbleScale = 1 - animator.animatedFraction, ) @@ -294,7 +297,9 @@ class BubbleAnimator( return tx + iconSize / 2f } - private fun getBubblesToTheLeft(bubbleIndex: Int, bubbleCount: Int): Int = + private fun getBubblesToTheLeft(bubbleIndex: Int, bubbleCount: Int = this.bubbleCount): Int = + // when bar is on left the index - 0 corresponds to the right - most bubble and when the + // bubble bar is on the right - 0 corresponds to the left - most bubble. if (onLeft) bubbleCount - bubbleIndex - 1 else bubbleIndex @@ -322,6 +327,7 @@ class BubbleAnimator( // the bar is on the left and the current bubble is to the right of the scaling // bubble so account for its scale (bubbleCount - bubbleIndex - 2 + bubbleScale) * iconAndSpacing + bubbleIndex == scalingBubbleIndex -> { // the bar is on the left and this is the scaling bubble val totalIconSize = (bubbleCount - bubbleIndex - 1) * iconSize @@ -331,6 +337,7 @@ class BubbleAnimator( val scaledSpace = bubbleScale * expandedBarIconSpacing totalIconSize + totalSpacing + scaledSpace + pivotAdjustment } + else -> // the bar is on the left and the scaling bubble is on the right. the current // bubble is unaffected by the scaling bubble @@ -342,10 +349,12 @@ class BubbleAnimator( // the bar is on the right and the scaling bubble is on the right. the current // bubble is unaffected by the scaling bubble iconAndSpacing * bubbleIndex + bubbleIndex == scalingBubbleIndex -> // the bar is on the right, and this is the animating bubble. it only needs to // be adjusted for the scaling pivot. iconAndSpacing * bubbleIndex + pivotAdjustment + else -> // the bar is on the right and the scaling bubble is on the left so account for // its scale @@ -357,61 +366,67 @@ class BubbleAnimator( private fun getBubbleTranslationXWhileAddingBubbleAtLimit( bubbleIndex: Int, removedBubbleIndex: Int, + addedBubbleIndex: Int, addedBubbleScale: Float, removedBubbleScale: Float, ): Float { val iconAndSpacing = iconSize + expandedBarIconSpacing // the bubbles are scaling from the center, so we need to adjust their translation so // that the distance to the adjacent bubble scales at the same rate. - val addedBubblePivotAdjustment = -(1 - addedBubbleScale) * iconSize / 2f - val removedBubblePivotAdjustment = -(1 - removedBubbleScale) * iconSize / 2f + val addedBubblePivotAdjustment = (addedBubbleScale - 1) * iconSize / 2f + val removedBubblePivotAdjustment = (removedBubbleScale - 1) * iconSize / 2f - return if (onLeft) { - // this is how many bubbles there are to the left of the current bubble. - // when the bubble bar is on the right the added bubble is the right-most bubble so it - // doesn't affect the translation of any other bubble. - // when the removed bubble is to the left of the current bubble, we need to subtract it - // from bubblesToLeft and use removedBubbleScale instead when calculating the - // translation. - val bubblesToLeft = bubbleCount - bubbleIndex - 1 - when { - bubbleIndex == 0 -> - // this is the added bubble and it's the right-most bubble. account for all the - // other bubbles -- including the removed bubble -- and adjust for the added - // bubble pivot. - (bubblesToLeft - 1 + removedBubbleScale) * iconAndSpacing + - addedBubblePivotAdjustment - bubbleIndex < removedBubbleIndex -> + val minAddedRemovedIndex = min(addedBubbleIndex, removedBubbleIndex) + val maxAddedRemovedIndex = max(addedBubbleIndex, removedBubbleIndex) + val isBetweenAddedAndRemoved = + bubbleIndex in (minAddedRemovedIndex + 1).. { + if (isRemovedBubbleToLeftOfAddedBubble) { // the removed bubble is to the left so account for it (bubblesToLeft - 1 + removedBubbleScale) * iconAndSpacing - bubbleIndex == removedBubbleIndex -> { - // this is the removed bubble. all the bubbles to the left are at full scale - // but we need to scale the spacing between the removed bubble and the bubble to - // its left because the removed bubble disappears towards the left side + } else { + // the added bubble is to the left so account for it + (bubblesToLeft - 1 + addedBubbleScale) * iconAndSpacing + } + } + + bubbleIndex == addedBubbleIndex -> { + if (isRemovedBubbleToLeftOfAddedBubble) { + // the removed bubble is to the left so account for it + (bubblesToLeft - 1 + removedBubbleScale) * iconAndSpacing + } else { + // it's the left-most scaling bubble, all bubbles on the left are at full scale + bubblesToLeft * iconAndSpacing + } + addedBubblePivotAdjustment + } + + bubbleIndex == removedBubbleIndex -> { + if (isRemovedBubbleToLeftOfAddedBubble) { + // All the bubbles to the left are at full scale, but we need to scale the + // spacing between the removed bubble and the bubble next to it val totalIconSize = bubblesToLeft * iconSize val totalSpacing = (bubblesToLeft - 1 + removedBubbleScale) * expandedBarIconSpacing - totalIconSize + totalSpacing + removedBubblePivotAdjustment - } - else -> - // both added and removed bubbles are to the right so they don't affect the tx - bubblesToLeft * iconAndSpacing + totalIconSize + totalSpacing + } else { + // The added bubble is to the left, so account for it + (bubblesToLeft - 1 + addedBubbleScale) * iconAndSpacing + } + removedBubblePivotAdjustment } - } else { - when { - bubbleIndex == 0 -> addedBubblePivotAdjustment // we always add bubbles at index 0 - bubbleIndex < removedBubbleIndex -> - // the bar is on the right and the removed bubble is on the right. the current - // bubble is unaffected by the removed bubble. only need to factor in the added - // bubble's scale. - iconAndSpacing * (bubbleIndex - 1 + addedBubbleScale) - bubbleIndex == removedBubbleIndex -> - // the bar is on the right, and this is the animating bubble. - iconAndSpacing * (bubbleIndex - 1 + addedBubbleScale) + - removedBubblePivotAdjustment - else -> - // both the added and the removed bubbles are to the left of the current bubble - iconAndSpacing * (bubbleIndex - 2 + addedBubbleScale + removedBubbleScale) + + else -> { + // if bubble index is on the right side of the animated bubbles, we need to deduct + // one, since both the added and the removed bubbles takes a single place + val onTheRightOfAnimatedBubbles = + if (onLeft) { + bubbleIndex < minAddedRemovedIndex + } else { + bubbleIndex > maxAddedRemovedIndex + } + (bubblesToLeft - if (onTheRightOfAnimatedBubbles) 1 else 0) * iconAndSpacing } } }