Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 058ab3eb authored by Ben Lin's avatar Ben Lin
Browse files

Add a maxHeight LayoutParams for ResolverDrawerLayout.

This way when laying out the child views, each view can specify that
they don't want to grow past a certain height.

Bug: 73819520
Test: atest com.android.internal.app.ResolverActivityTest#setMaxHeight

Change-Id: Ibff3609746b4b6ec7b4debd8433487c7fc9ce0fa
parent 5798ef6a
Loading
Loading
Loading
Loading
+21 −2
Original line number Diff line number Diff line
@@ -814,7 +814,14 @@ public class ResolverDrawerLayout extends ViewGroup {
            final View child = getChildAt(i);
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            if (lp.alwaysShow && child.getVisibility() != GONE) {
                if (lp.maxHeight != -1) {
                    final int remainingHeight = heightSize - heightUsed;
                    measureChildWithMargins(child, widthSpec, widthPadding,
                            MeasureSpec.makeMeasureSpec(lp.maxHeight, MeasureSpec.AT_MOST),
                            lp.maxHeight > remainingHeight ? lp.maxHeight - remainingHeight : 0);
                } else {
                    measureChildWithMargins(child, widthSpec, widthPadding, heightSpec, heightUsed);
                }
                heightUsed += child.getMeasuredHeight();
            }
        }
@@ -824,9 +831,17 @@ public class ResolverDrawerLayout extends ViewGroup {
        // And now the rest.
        for (int i = 0; i < childCount; i++) {
            final View child = getChildAt(i);

            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            if (!lp.alwaysShow && child.getVisibility() != GONE) {
                if (lp.maxHeight != -1) {
                    final int remainingHeight = heightSize - heightUsed;
                    measureChildWithMargins(child, widthSpec, widthPadding,
                            MeasureSpec.makeMeasureSpec(lp.maxHeight, MeasureSpec.AT_MOST),
                            lp.maxHeight > remainingHeight ? lp.maxHeight - remainingHeight : 0);
                } else {
                    measureChildWithMargins(child, widthSpec, widthPadding, heightSpec, heightUsed);
                }
                heightUsed += child.getMeasuredHeight();
            }
        }
@@ -938,6 +953,7 @@ public class ResolverDrawerLayout extends ViewGroup {
        public boolean alwaysShow;
        public boolean ignoreOffset;
        public boolean hasNestedScrollIndicator;
        public int maxHeight;

        public LayoutParams(Context c, AttributeSet attrs) {
            super(c, attrs);
@@ -953,6 +969,8 @@ public class ResolverDrawerLayout extends ViewGroup {
            hasNestedScrollIndicator = a.getBoolean(
                    R.styleable.ResolverDrawerLayout_LayoutParams_layout_hasNestedScrollIndicator,
                    false);
            maxHeight = a.getDimensionPixelSize(
                    R.styleable.ResolverDrawerLayout_LayoutParams_layout_maxHeight, -1);
            a.recycle();
        }

@@ -965,6 +983,7 @@ public class ResolverDrawerLayout extends ViewGroup {
            this.alwaysShow = source.alwaysShow;
            this.ignoreOffset = source.ignoreOffset;
            this.hasNestedScrollIndicator = source.hasNestedScrollIndicator;
            this.maxHeight = source.maxHeight;
        }

        public LayoutParams(MarginLayoutParams source) {
+1 −0
Original line number Diff line number Diff line
@@ -8798,6 +8798,7 @@
        <attr name="layout_ignoreOffset" format="boolean" />
        <attr name="layout_gravity" />
        <attr name="layout_hasNestedScrollIndicator" format="boolean" />
        <attr name="layout_maxHeight" />
    </declare-styleable>

    <!-- @hide -->
+43 −0
Original line number Diff line number Diff line
@@ -102,6 +102,49 @@ public class ResolverActivityTest {
        assertThat(chosen[0], is(toChoose));
    }

    @Test
    public void setMaxHeight() throws Exception {
        Intent sendIntent = createSendImageIntent();
        List<ResolvedComponentInfo> resolvedComponentInfos = createResolvedComponentsForTest(2);

        when(sOverrides.resolverListController.getResolversForIntent(Mockito.anyBoolean(),
                Mockito.anyBoolean(),
                Mockito.isA(List.class))).thenReturn(resolvedComponentInfos);
        waitForIdle();

        final ResolverWrapperActivity activity = mActivityRule.launchActivity(sendIntent);
        final View resolverList = activity.findViewById(R.id.resolver_list);
        final int initialResolverHeight = resolverList.getHeight();

        activity.runOnUiThread(() -> {
            ResolverDrawerLayout layout = (ResolverDrawerLayout)
                    activity.findViewById(
                            R.id.contentPanel);
            ((ResolverDrawerLayout.LayoutParams) resolverList.getLayoutParams()).maxHeight
                = initialResolverHeight - 1;
            // Force a relayout
            layout.invalidate();
            layout.requestLayout();
        });
        waitForIdle();
        assertThat("Drawer should be capped at maxHeight",
            resolverList.getHeight() == (initialResolverHeight - 1));

        activity.runOnUiThread(() -> {
            ResolverDrawerLayout layout = (ResolverDrawerLayout)
                    activity.findViewById(
                            R.id.contentPanel);
            ((ResolverDrawerLayout.LayoutParams) resolverList.getLayoutParams()).maxHeight
                = initialResolverHeight + 1;
            // Force a relayout
            layout.invalidate();
            layout.requestLayout();
        });
        waitForIdle();
        assertThat("Drawer should not change height if its height is less than maxHeight",
            resolverList.getHeight() == initialResolverHeight);
    }

    @Test
    public void setShowAtTopToTrue() throws Exception {
        Intent sendIntent = createSendImageIntent();