From ee849a3547895306176d6aca448596546f21b7a0 Mon Sep 17 00:00:00 2001 From: Ivan Tkachenko Date: Fri, 14 Apr 2023 14:55:11 +0100 Subject: [PATCH] Bubble Manage menu initial position MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * The problem is, when `showManageMenu` method is called Manage menu view might have incorrect dimensions, which are used to calculate the target position for animation. This happens when option items are hidden/presented for app/conversation bubbles, as modifying the option view visibility doesn’t get reflected in the Manage menu view dimensions up until the layout is applied. * In order to resolve incorrect dimensions Manage menu options setup is moved to `showNewlySelectedBubble` method, which ensures that Manage menu view dimensions will be correct when `showManageMenu` is called. * Steps for manual testing: 1. Create conversation and app bubble 2. Expand conversation bubble 3. Tap `Manage` button to show Manage menu 4. Verify that there’re 3 option items on top of the `Manage` button aligned with it’s bottom left (right for RTL) corner 5. Expand app bubble 6. Tap `Manage` button to show Manage menu 7. Verify that there’s 1 option item on top of the `Manage` button aligned with it’s bottom left (right for RTL) corner Test: atest BubblesTest Bug: 278197402 Change-Id: I628681b3d26e3dd69c0bdd660371a6c7d6dc0cd6 --- .../wm/shell/bubbles/BubbleStackView.java | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) 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 1b20f67e42abf..60111aadd6af6 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 @@ -2922,14 +2922,15 @@ public class BubbleStackView extends FrameLayout final float targetX = isLtr ? mTempRect.left - margin : mTempRect.right + margin - mManageMenu.getWidth(); - final float targetY = mTempRect.bottom - mManageMenu.getHeight(); + final float menuHeight = getVisibleManageMenuHeight(); + final float targetY = mTempRect.bottom - menuHeight; final float xOffsetForAnimation = (isLtr ? 1 : -1) * mManageMenu.getWidth() / 4f; if (show) { mManageMenu.setScaleX(0.5f); mManageMenu.setScaleY(0.5f); mManageMenu.setTranslationX(targetX - xOffsetForAnimation); - mManageMenu.setTranslationY(targetY + mManageMenu.getHeight() / 4f); + mManageMenu.setTranslationY(targetY + menuHeight / 4f); mManageMenu.setAlpha(0f); PhysicsAnimator.getInstance(mManageMenu) @@ -2955,7 +2956,7 @@ public class BubbleStackView extends FrameLayout .spring(DynamicAnimation.SCALE_X, 0.5f) .spring(DynamicAnimation.SCALE_Y, 0.5f) .spring(DynamicAnimation.TRANSLATION_X, targetX - xOffsetForAnimation) - .spring(DynamicAnimation.TRANSLATION_Y, targetY + mManageMenu.getHeight() / 4f) + .spring(DynamicAnimation.TRANSLATION_Y, targetY + menuHeight / 4f) .withEndActions(() -> { mManageMenu.setVisibility(View.INVISIBLE); if (mExpandedBubble != null && mExpandedBubble.getExpandedView() != null) { @@ -3271,6 +3272,24 @@ public class BubbleStackView extends FrameLayout return mBubbleContainer.indexOfChild(provider.getIconView()); } + /** + * Menu height calculated for animation + * It takes into account view visibility to get the correct total height + */ + private float getVisibleManageMenuHeight() { + float menuHeight = 0; + + for (int i = 0; i < mManageMenu.getChildCount(); i++) { + View subview = mManageMenu.getChildAt(i); + + if (subview.getVisibility() == VISIBLE) { + menuHeight += subview.getHeight(); + } + } + + return menuHeight; + } + /** * @return the normalized x-axis position of the bubble stack rounded to 4 decimal places. */