From 93ee47f729055dc8d012e0538eb3de9cd7c44d01 Mon Sep 17 00:00:00 2001 From: Shamali P Date: Tue, 28 May 2024 13:13:44 +0000 Subject: [PATCH] Measure recommendation children using the provided available height We always want to measure the pages based on the provided height. Bug: 335715046 Test: Manual Flag: NONE BUGFIX Change-Id: I9de2ed1e0d4cc37d24435b9077e60bf5f0456091 --- .../widget/picker/WidgetRecommendationsView.java | 16 +++++++++++++--- .../widget/picker/WidgetsTwoPaneSheet.java | 2 +- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/com/android/launcher3/widget/picker/WidgetRecommendationsView.java b/src/com/android/launcher3/widget/picker/WidgetRecommendationsView.java index 4f73e660d0..9260af9b22 100644 --- a/src/com/android/launcher3/widget/picker/WidgetRecommendationsView.java +++ b/src/com/android/launcher3/widget/picker/WidgetRecommendationsView.java @@ -53,6 +53,7 @@ import java.util.stream.Collectors; */ public final class WidgetRecommendationsView extends PagedView { private @Px float mAvailableHeight = Float.MAX_VALUE; + private @Px float mAvailableWidth = 0; private static final String INITIALLY_DISPLAYED_WIDGETS_STATE_KEY = "widgetRecommendationsView:mDisplayedWidgets"; private static final int MAX_CATEGORIES = 3; @@ -152,6 +153,7 @@ public final class WidgetRecommendationsView extends PagedView displayedWidgets = maybeDisplayInTable(recommendedWidgets, @@ -187,6 +189,7 @@ public final class WidgetRecommendationsView extends PagedView 0; if (hasMultiplePages) { - int finalWidth = MeasureSpec.getSize(widthMeasureSpec); int desiredHeight = 0; + int desiredWidth = Math.round(mAvailableWidth); for (int i = 0; i < getChildCount(); i++) { View child = getChildAt(i); - measureChild(child, widthMeasureSpec, heightMeasureSpec); + // Measure children based on available height and width. + measureChild(child, + MeasureSpec.makeMeasureSpec(desiredWidth, MeasureSpec.EXACTLY), + MeasureSpec.makeMeasureSpec(Math.round(mAvailableHeight), + MeasureSpec.AT_MOST)); // Use height of tallest child as we have limited height. - desiredHeight = Math.max(desiredHeight, child.getMeasuredHeight()); + int childHeight = child.getMeasuredHeight(); + desiredHeight = Math.max(desiredHeight, childHeight); } int finalHeight = resolveSizeAndState(desiredHeight, heightMeasureSpec, 0); + int finalWidth = resolveSizeAndState(desiredWidth, widthMeasureSpec, 0); + setMeasuredDimension(finalWidth, finalHeight); } else { super.onMeasure(widthMeasureSpec, heightMeasureSpec); diff --git a/src/com/android/launcher3/widget/picker/WidgetsTwoPaneSheet.java b/src/com/android/launcher3/widget/picker/WidgetsTwoPaneSheet.java index f835e1860e..5d71db6e39 100644 --- a/src/com/android/launcher3/widget/picker/WidgetsTwoPaneSheet.java +++ b/src/com/android/launcher3/widget/picker/WidgetsTwoPaneSheet.java @@ -67,7 +67,7 @@ public class WidgetsTwoPaneSheet extends WidgetsFullSheet { // This ratio defines the max percentage of content area that the recommendations can display // with respect to the bottom sheet's height. - private static final float RECOMMENDATION_SECTION_HEIGHT_RATIO_TWO_PANE = 0.60f; + private static final float RECOMMENDATION_SECTION_HEIGHT_RATIO_TWO_PANE = 0.70f; private FrameLayout mSuggestedWidgetsContainer; private WidgetsListHeader mSuggestedWidgetsHeader; private PackageUserKey mSuggestedWidgetsPackageUserKey;