diff options
| author | 2024-05-03 16:48:53 +0000 | |
|---|---|---|
| committer | 2024-05-03 16:48:53 +0000 | |
| commit | 1469b0e71f4decb464cf7a31a08edb6ec4c597fc (patch) | |
| tree | 531fd66fd619067c741c96e21a5082c21ef6cfd2 | |
| parent | a3749d9d9efc728eee9fca25cda22efcb26312ef (diff) | |
| parent | 507f4652a766da428bf90ea1ef4ffb06273b3358 (diff) | |
Merge "Simplify bubble z ordering and fix various issues" into main
3 files changed, 57 insertions, 34 deletions
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubblePositioner.java b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubblePositioner.java index 14c3a0701c83..c4bbe32e3205 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubblePositioner.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubblePositioner.java @@ -76,6 +76,7 @@ public class BubblePositioner { private int mBubblePaddingTop; private int mBubbleOffscreenAmount; private int mStackOffset; + private int mBubbleElevation; private int mExpandedViewMinHeight; private int mExpandedViewLargeScreenWidth; @@ -147,6 +148,7 @@ public class BubblePositioner { mBubblePaddingTop = res.getDimensionPixelSize(R.dimen.bubble_padding_top); mBubbleOffscreenAmount = res.getDimensionPixelSize(R.dimen.bubble_stack_offscreen); mStackOffset = res.getDimensionPixelSize(R.dimen.bubble_stack_offset); + mBubbleElevation = res.getDimensionPixelSize(R.dimen.bubble_elevation); if (mShowingInBubbleBar) { mExpandedViewLargeScreenWidth = Math.min( @@ -662,6 +664,29 @@ public class BubblePositioner { } /** + * Returns the z translation a specific bubble should use. When expanded we keep a slight + * translation to ensure proper ordering when animating to / from collapsed state. When + * collapsed, only the top two bubbles appear so only their shadows show. + */ + public float getZTranslation(int index, boolean isOverflow, boolean isExpanded) { + if (isOverflow) { + return 0f; // overflow is lowest + } + return isExpanded + // When expanded use minimal amount to keep order + ? getMaxBubbles() - index + // When collapsed, only the top two bubbles have elevation + : index < NUM_VISIBLE_WHEN_RESTING + ? (getMaxBubbles() * mBubbleElevation) - index + : 0; + } + + /** The elevation to use for bubble UI elements. */ + public int getBubbleElevation() { + return mBubbleElevation; + } + + /** * @return whether the stack is considered on the left side of the screen. */ public boolean isStackOnLeft(PointF currentStackPosition) { diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleStackView.java b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleStackView.java index dcc536b5b043..3c788b18429c 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleStackView.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubbleStackView.java @@ -670,7 +670,7 @@ public class BubbleStackView extends FrameLayout // First, see if the magnetized object consumes the event - if so, we shouldn't move the // bubble since it's stuck to the target. if (!passEventToMagnetizedObject(ev)) { - updateBubbleShadows(true /* showForAllBubbles */); + updateBubbleShadows(true /* isExpanded */); if (mBubbleData.isExpanded()) { mExpandedAnimationController.dragBubbleOut( v, viewInitialX + dx, viewInitialY + dy); @@ -720,6 +720,7 @@ public class BubbleStackView extends FrameLayout } mIsDraggingStack = false; + mMagnetizedObject = null; // Hide the stack after a delay, if needed. updateTemporarilyInvisibleAnimation(false /* hideImmediately */); @@ -890,18 +891,17 @@ public class BubbleStackView extends FrameLayout mMainExecutor = mainExecutor; mManager = bubbleStackViewManager; + mPositioner = bubblePositioner; mBubbleData = data; mSysuiProxyProvider = sysuiProxyProvider; Resources res = getResources(); mBubbleSize = res.getDimensionPixelSize(R.dimen.bubble_size); - mBubbleElevation = res.getDimensionPixelSize(R.dimen.bubble_elevation); + mBubbleElevation = mPositioner.getBubbleElevation(); mBubbleTouchPadding = res.getDimensionPixelSize(R.dimen.bubble_touch_padding); mExpandedViewPadding = res.getDimensionPixelSize(R.dimen.bubble_expanded_view_padding); - int elevation = res.getDimensionPixelSize(R.dimen.bubble_elevation); - mPositioner = bubblePositioner; final TypedArray ta = mContext.obtainStyledAttributes( new int[]{android.R.attr.dialogCornerRadius}); @@ -934,12 +934,12 @@ public class BubbleStackView extends FrameLayout mBubbleContainer = new PhysicsAnimationLayout(context); mBubbleContainer.setActiveController(mStackAnimationController); - mBubbleContainer.setElevation(elevation); + mBubbleContainer.setElevation(mBubbleElevation); mBubbleContainer.setClipChildren(false); addView(mBubbleContainer, new FrameLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT)); mExpandedViewContainer = new FrameLayout(context); - mExpandedViewContainer.setElevation(elevation); + mExpandedViewContainer.setElevation(mBubbleElevation); mExpandedViewContainer.setClipChildren(false); addView(mExpandedViewContainer); @@ -1861,7 +1861,7 @@ public class BubbleStackView extends FrameLayout bubble.getIconView().setDotBadgeOnLeft(!mStackOnLeftOrWillBe /* onLeft */); bubble.getIconView().setOnClickListener(mBubbleClickListener); bubble.getIconView().setOnTouchListener(mBubbleTouchListener); - updateBubbleShadows(false /* showForAllBubbles */); + updateBubbleShadows(mIsExpanded); animateInFlyoutForBubble(bubble); requestUpdate(); logBubbleEvent(bubble, FrameworkStatsLog.BUBBLE_UICHANGED__ACTION__POSTED); @@ -1964,7 +1964,7 @@ public class BubbleStackView extends FrameLayout if (mIsExpanded || isExpansionAnimating()) { reorder.run(); updateBadges(false /* setBadgeForCollapsedStack */); - updateZOrder(); + updateBubbleShadows(true /* isExpanded */); } else { List<View> bubbleViews = bubbles.stream() .map(b -> b.getIconView()).collect(Collectors.toList()); @@ -2207,7 +2207,7 @@ public class BubbleStackView extends FrameLayout mBubbleContainer.addView(bubble.getIconView(), index, new LayoutParams(mPositioner.getBubbleSize(), mPositioner.getBubbleSize())); - updateBubbleShadows(false /* showForAllBubbles */); + updateBubbleShadows(mIsExpanded); requestUpdate(); } } @@ -2340,7 +2340,7 @@ public class BubbleStackView extends FrameLayout beforeExpandedViewAnimation(); showScrim(true, null /* runnable */); - updateZOrder(); + updateBubbleShadows(mIsExpanded); updateBadges(false /* setBadgeForCollapsedStack */); mBubbleContainer.setActiveController(mExpandedAnimationController); updateOverflowVisibility(); @@ -2493,6 +2493,7 @@ public class BubbleStackView extends FrameLayout () -> { mBubbleContainer.setActiveController(mStackAnimationController); updateOverflowVisibility(); + animateShadows(); }); final Runnable after = () -> { @@ -2503,7 +2504,6 @@ public class BubbleStackView extends FrameLayout mManageEduView.hide(); } - updateZOrder(); updateBadges(true /* setBadgeForCollapsedStack */); afterExpandedViewAnimation(); if (previouslySelected != null) { @@ -3338,19 +3338,23 @@ public class BubbleStackView extends FrameLayout * Updates whether each of the bubbles should show shadows. When collapsed & resting, only the * visible bubbles (top 2) will show a shadow. When the stack is being dragged, everything * shows a shadow. When an individual bubble is dragged out, it should show a shadow. - */ - private void updateBubbleShadows(boolean showForAllBubbles) { - int bubbleCount = getBubbleCount(); - for (int i = 0; i < bubbleCount; i++) { - final float z = (mPositioner.getMaxBubbles() * mBubbleElevation) - i; - BadgedImageView bv = (BadgedImageView) mBubbleContainer.getChildAt(i); - boolean isDraggedOut = mMagnetizedObject != null + * The bubble overflow is a special case and never has a shadow as it's ordered below the + * rest of the bubbles and isn't visible unless the stack is expanded. + * + * @param isExpanded whether the stack will be expanded or not when the shadows are applied. + */ + private void updateBubbleShadows(boolean isExpanded) { + final int childCount = mBubbleContainer.getChildCount(); + for (int i = 0; i < childCount; i++) { + final BadgedImageView bv = (BadgedImageView) mBubbleContainer.getChildAt(i); + final boolean isOverflow = BubbleOverflow.KEY.equals(bv.getKey()); + final boolean isDraggedOut = mMagnetizedObject != null && mMagnetizedObject.getUnderlyingObject().equals(bv); - if (showForAllBubbles || isDraggedOut) { - bv.setZ(z); + if (isDraggedOut) { + // If it's dragged out, it's above all the other bubbles + bv.setZ((mPositioner.getMaxBubbles() * mBubbleElevation) + 1); } else { - final float tz = i < NUM_VISIBLE_WHEN_RESTING ? z : 0f; - bv.setZ(tz); + bv.setZ(mPositioner.getZTranslation(i, isOverflow, isExpanded)); } } } @@ -3371,16 +3375,6 @@ public class BubbleStackView extends FrameLayout } } - private void updateZOrder() { - int bubbleCount = getBubbleCount(); - for (int i = 0; i < bubbleCount; i++) { - BadgedImageView bv = (BadgedImageView) mBubbleContainer.getChildAt(i); - bv.setZ(i < NUM_VISIBLE_WHEN_RESTING - ? (mPositioner.getMaxBubbles() * mBubbleElevation) - i - : 0f); - } - } - private void updateBadges(boolean setBadgeForCollapsedStack) { int bubbleCount = getBubbleCount(); for (int i = 0; i < bubbleCount; i++) { diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/animation/ExpandedAnimationController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/animation/ExpandedAnimationController.java index 9440e9835cdf..f925eaef2c77 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/animation/ExpandedAnimationController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/animation/ExpandedAnimationController.java @@ -356,7 +356,6 @@ public class ExpandedAnimationController MagnetizedObject.MagnetListener listener) { mLayout.cancelAnimationsOnView(bubble); - bubble.setTranslationZ(Short.MAX_VALUE); mMagnetizedBubbleDraggingOut = new MagnetizedObject<View>( mLayout.getContext(), bubble, DynamicAnimation.TRANSLATION_X, DynamicAnimation.TRANSLATION_Y) { @@ -460,6 +459,7 @@ public class ExpandedAnimationController /** * Snaps a bubble back to its position within the bubble row, and animates the rest of the * bubbles to accommodate it if it was previously dragged out past the threshold. + * Only happens while the stack is expanded. */ public void snapBubbleBack(View bubbleView, float velX, float velY) { if (mLayout == null) { @@ -467,8 +467,12 @@ public class ExpandedAnimationController } final int index = mLayout.indexOfChild(bubbleView); final PointF p = mPositioner.getExpandedBubbleXY(index, mBubbleStackView.getState()); + // overflow is not draggable so it's never the overflow + final float zTranslation = mPositioner.getZTranslation(index, + false /* isOverflow */, + true /* isExpanded */); animationForChildAtIndex(index) - .position(p.x, p.y, /* translationZ= */ 0f) + .position(p.x, p.y, zTranslation) .withPositionStartVelocities(velX, velY) .start(); |