From f9a8f40c27f1b0188cbfa9b20af44ea04614cf93 Mon Sep 17 00:00:00 2001 From: Andrey Epin Date: Mon, 28 Nov 2022 11:54:33 -0800 Subject: ResolverDrawerLayout: unify mCollapsibleHeight calculation. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (an ag/20419209 cherry-pick) mCollapsibleHeight was calculated differently in two places: in onMeasure() and in setCollapsibleHeightReserved() methods. The latter is updated to use the same logic as the former. There was two particular aspects of the onMeasure() logic: - It calculated mCollapsibleHeight and mUncollapsibleHeight so the sum of the two yields the total children height; - mCollapsibleHeight was calculated based on the total childrens height. Thus a correct mCollapsibleHeight calculation in the setCollapsibleHeightReserved() method would need to know the total children height and maintain the invariant that mCollapsibleHeight + mUncollapsibleHeight would yield that height. Instead of deriving the total children height as a sum of mCollapsibleHeight + mUncollapsibleHeight, a new field, mHeightUsed, is added to store the total children height and mUncollapsibleHeight is deleted. This way we don’t have to also update mUncollapsibleHeight in setCollapsibleHeightReserved() plus mUncollapsibleHeight was always used as a part of the sum mCollapsibleHeight + mUncollapsibleHeight so it is a natural replacement. Flag: IntentResolver package entirely behind the CHOOSER_UNBUNDLED which is in teamfood Bug: 256869196 Test: reproduce the issue in a separate test environment, make sure that the change acutally fixes it Test: manual Chooser smoke test Test: manual Resolver smoke test Test: atest FrameworksCoreTests:ChooserActivityTest Test: atest FrameworksCoreTests:ResolverActivityTest Change-Id: Id169bd1c4b9f7270d75baab2e5e3841b76ab00e6 --- .../widget/ResolverDrawerLayout.java | 37 +++++++++++----------- 1 file changed, 18 insertions(+), 19 deletions(-) (limited to 'java/src') diff --git a/java/src/com/android/intentresolver/widget/ResolverDrawerLayout.java b/java/src/com/android/intentresolver/widget/ResolverDrawerLayout.java index a2c5afc6..f5e20510 100644 --- a/java/src/com/android/intentresolver/widget/ResolverDrawerLayout.java +++ b/java/src/com/android/intentresolver/widget/ResolverDrawerLayout.java @@ -89,8 +89,8 @@ public class ResolverDrawerLayout extends ViewGroup { * out of sync due to frequently dropping fractions of a pixel from '(int) dy' casts. */ private float mDragRemainder = 0.0f; + private int mHeightUsed; private int mCollapsibleHeight; - private int mUncollapsibleHeight; private int mAlwaysShowHeight; /** @@ -244,9 +244,7 @@ public class ResolverDrawerLayout extends ViewGroup { mLastTouchY -= dReserved; } - final int oldCollapsibleHeight = mCollapsibleHeight; - mCollapsibleHeight = Math.min(mCollapsibleHeight, getMaxCollapsedHeight()); - + final int oldCollapsibleHeight = updateCollapsibleHeight(); if (updateCollapseOffset(oldCollapsibleHeight, !isDragging())) { return; } @@ -485,7 +483,7 @@ public class ResolverDrawerLayout extends ViewGroup { } else { if (isDismissable() && yvel > 0 && mCollapseOffset > mCollapsibleHeight) { - smoothScrollTo(mCollapsibleHeight + mUncollapsibleHeight, yvel); + smoothScrollTo(mHeightUsed, yvel); mDismissOnScrollerFinished = true; } else { scrollNestedScrollableChildBackToTop(); @@ -575,8 +573,7 @@ public class ResolverDrawerLayout extends ViewGroup { return 0; } - final float newPos = Math.max(0, Math.min(mCollapseOffset + dy, - mCollapsibleHeight + mUncollapsibleHeight)); + final float newPos = Math.max(0, Math.min(mCollapseOffset + dy, mHeightUsed)); if (newPos != mCollapseOffset) { dy = newPos - mCollapseOffset; @@ -855,7 +852,7 @@ public class ResolverDrawerLayout extends ViewGroup { } else { if (isDismissable() && velocityY < 0 && mCollapseOffset > mCollapsibleHeight) { - smoothScrollTo(mCollapsibleHeight + mUncollapsibleHeight, velocityY); + smoothScrollTo(mHeightUsed, velocityY); mDismissOnScrollerFinished = true; } else { smoothScrollTo(velocityY > 0 ? 0 : mCollapsibleHeight, velocityY); @@ -883,9 +880,8 @@ public class ResolverDrawerLayout extends ViewGroup { } break; case AccessibilityNodeInfo.ACTION_DISMISS: - if ((mCollapseOffset < mCollapsibleHeight + mUncollapsibleHeight) - && isDismissable()) { - smoothScrollTo(mCollapsibleHeight + mUncollapsibleHeight, 0); + if ((mCollapseOffset < mHeightUsed) && isDismissable()) { + smoothScrollTo(mHeightUsed, 0); mDismissOnScrollerFinished = true; return true; } @@ -923,7 +919,7 @@ public class ResolverDrawerLayout extends ViewGroup { info.addAction(AccessibilityAction.ACTION_SCROLL_DOWN); info.setScrollable(true); } - if ((mCollapseOffset < mCollapsibleHeight + mUncollapsibleHeight) + if ((mCollapseOffset < mHeightUsed) && ((mCollapseOffset < mCollapsibleHeight) || isDismissable())) { info.addAction(AccessibilityAction.ACTION_SCROLL_UP); info.setScrollable(true); @@ -931,7 +927,7 @@ public class ResolverDrawerLayout extends ViewGroup { if (mCollapseOffset < mCollapsibleHeight) { info.addAction(AccessibilityAction.ACTION_COLLAPSE); } - if (mCollapseOffset < mCollapsibleHeight + mUncollapsibleHeight && isDismissable()) { + if (mCollapseOffset < mHeightUsed && isDismissable()) { info.addAction(AccessibilityAction.ACTION_DISMISS); } } @@ -1022,22 +1018,25 @@ public class ResolverDrawerLayout extends ViewGroup { } } - final int oldCollapsibleHeight = mCollapsibleHeight; - mCollapsibleHeight = Math.max(0, - heightUsed - mAlwaysShowHeight - getMaxCollapsedHeight()); - mUncollapsibleHeight = heightUsed - mCollapsibleHeight; - + mHeightUsed = heightUsed; + int oldCollapsibleHeight = updateCollapsibleHeight(); updateCollapseOffset(oldCollapsibleHeight, !isDragging()); if (getShowAtTop()) { mTopOffset = 0; } else { - mTopOffset = Math.max(0, heightSize - heightUsed) + (int) mCollapseOffset; + mTopOffset = Math.max(0, heightSize - mHeightUsed) + (int) mCollapseOffset; } setMeasuredDimension(sourceWidth, heightSize); } + private int updateCollapsibleHeight() { + final int oldCollapsibleHeight = mCollapsibleHeight; + mCollapsibleHeight = Math.max(0, mHeightUsed - mAlwaysShowHeight - getMaxCollapsedHeight()); + return oldCollapsibleHeight; + } + /** * @return The space reserved by views with 'alwaysShow=true' */ -- cgit v1.2.3-59-g8ed1b