Loading core/java/com/android/internal/widget/ResolverDrawerLayout.java +21 −2 Original line number Diff line number Diff line Loading @@ -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(); } } Loading @@ -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(); } } Loading Loading @@ -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); Loading @@ -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(); } Loading @@ -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) { Loading core/res/res/values/attrs.xml +1 −0 Original line number Diff line number Diff line Loading @@ -8803,6 +8803,7 @@ <attr name="layout_ignoreOffset" format="boolean" /> <attr name="layout_gravity" /> <attr name="layout_hasNestedScrollIndicator" format="boolean" /> <attr name="layout_maxHeight" /> </declare-styleable> <!-- @hide --> Loading core/tests/coretests/src/com/android/internal/app/ResolverActivityTest.java +43 −0 Original line number Diff line number Diff line Loading @@ -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(); Loading Loading
core/java/com/android/internal/widget/ResolverDrawerLayout.java +21 −2 Original line number Diff line number Diff line Loading @@ -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(); } } Loading @@ -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(); } } Loading Loading @@ -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); Loading @@ -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(); } Loading @@ -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) { Loading
core/res/res/values/attrs.xml +1 −0 Original line number Diff line number Diff line Loading @@ -8803,6 +8803,7 @@ <attr name="layout_ignoreOffset" format="boolean" /> <attr name="layout_gravity" /> <attr name="layout_hasNestedScrollIndicator" format="boolean" /> <attr name="layout_maxHeight" /> </declare-styleable> <!-- @hide --> Loading
core/tests/coretests/src/com/android/internal/app/ResolverActivityTest.java +43 −0 Original line number Diff line number Diff line Loading @@ -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(); Loading