From 116e94e0a7017ff417470db19f2d4b547218eefc Mon Sep 17 00:00:00 2001 From: Jon Miranda Date: Fri, 19 Mar 2021 17:21:22 -0400 Subject: [PATCH] Account for children margins when orienting popup container. Instead of recalculating the orientation after adding margins, we account for the margins in the initial calls to orientAboutObject. This ensures consistent mIsAboveIcon throughout calls to show the popup. - Also updates the smaller radius to match the middle items. Bug: 175329686 Test: long press on item where height and height without margins would result in differing mIsAboveIcon values eg. the 3rd item in a folder in the top middle of 5x5 workspace Change-Id: I6132b544a89c7948339d17f219ad75c797233f55 --- res/drawable/middle_item_primary.xml | 2 +- res/values/dimens.xml | 2 +- .../android/launcher3/popup/ArrowPopup.java | 21 ++++++++++++------- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/res/drawable/middle_item_primary.xml b/res/drawable/middle_item_primary.xml index c9757142da..0c04ea14ec 100644 --- a/res/drawable/middle_item_primary.xml +++ b/res/drawable/middle_item_primary.xml @@ -16,5 +16,5 @@ - + \ No newline at end of file diff --git a/res/values/dimens.xml b/res/values/dimens.xml index b60b6113e4..36ee6bb38c 100644 --- a/res/values/dimens.xml +++ b/res/values/dimens.xml @@ -192,7 +192,7 @@ 32dp 2dp 100dp - 4dp + 4dp 12dp 16dp 10dp diff --git a/src/com/android/launcher3/popup/ArrowPopup.java b/src/com/android/launcher3/popup/ArrowPopup.java index a53fe1f848..373653829b 100644 --- a/src/com/android/launcher3/popup/ArrowPopup.java +++ b/src/com/android/launcher3/popup/ArrowPopup.java @@ -130,13 +130,14 @@ public abstract class ArrowPopup extends Abstrac R.dimen.popup_arrow_horizontal_center_offset) - (mArrowWidth / 2); mArrowPointRadius = resources.getDimensionPixelSize(R.dimen.popup_arrow_corner_radius); + int smallerRadius = resources.getDimensionPixelSize(R.dimen.popup_smaller_radius); mRoundedTop = new GradientDrawable(); mRoundedTop.setCornerRadii(new float[] { mOutlineRadius, mOutlineRadius, mOutlineRadius, - mOutlineRadius, 0, 0, 0, 0}); + mOutlineRadius, smallerRadius, smallerRadius, smallerRadius, smallerRadius}); mRoundedBottom = new GradientDrawable(); - mRoundedBottom.setCornerRadii(new float[] { 0, 0, 0, 0, mOutlineRadius, mOutlineRadius, - mOutlineRadius, mOutlineRadius}); + mRoundedBottom.setCornerRadii(new float[] { smallerRadius, smallerRadius, smallerRadius, + smallerRadius, mOutlineRadius, mOutlineRadius, mOutlineRadius, mOutlineRadius}); int primaryColor = Themes.getAttrColor(context, R.attr.popupColorPrimary); int secondaryColor = Themes.getAttrColor(context, R.attr.popupColorSecondary); @@ -272,7 +273,6 @@ public abstract class ArrowPopup extends Abstrac } onInflationComplete(reverseOrder); assignMarginsAndBackgrounds(); - orientAboutObject(); if (shouldAddArrow()) { addArrow(); } @@ -286,7 +286,6 @@ public abstract class ArrowPopup extends Abstrac setupForDisplay(); onInflationComplete(false); assignMarginsAndBackgrounds(); - orientAboutObject(); if (shouldAddArrow()) { addArrow(); } @@ -383,10 +382,18 @@ public abstract class ArrowPopup extends Abstrac private void orientAboutObject(boolean allowAlignLeft, boolean allowAlignRight) { measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED); - int width = getMeasuredWidth(); int extraVerticalSpace = mArrowHeight + mArrowOffsetVertical + getResources().getDimensionPixelSize(R.dimen.popup_vertical_padding); - int height = getMeasuredHeight() + extraVerticalSpace; + // 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) { + if (getChildAt(i).getVisibility() == VISIBLE) { + numVisibleChildren++; + } + } + int childMargins = (numVisibleChildren - 1) * mMargin; + int height = getMeasuredHeight() + extraVerticalSpace + childMargins; + int width = getMeasuredWidth(); getTargetObjectLocation(mTempRect); InsettableFrameLayout dragLayer = getPopupContainer();