Merge "Improvements to measuring view / handling padding"
diff --git a/samples/SupportSliceDemos/src/main/res/values/styles.xml b/samples/SupportSliceDemos/src/main/res/values/styles.xml
index a01e0aa..38d7298 100644
--- a/samples/SupportSliceDemos/src/main/res/values/styles.xml
+++ b/samples/SupportSliceDemos/src/main/res/values/styles.xml
@@ -33,13 +33,9 @@
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light"/>
<style name="CustomSliceView" parent="Widget.SliceView">
- <item name="titleColor">@color/colorAccent</item>
- <item name="tintColor">@color/colorAccent</item>
- <item name="headerTitleSize">20sp</item>
- <item name="headerSubtitleSize">16sp</item>
- <item name="android:paddingLeft">14dp</item>
+ <item name="android:paddingLeft">8dp</item>
<item name="android:paddingTop">8dp</item>
- <item name="android:paddingRight">20dp</item>
+ <item name="android:paddingRight">8dp</item>
<item name="android:paddingBottom">8dp</item>
</style>
</resources>
diff --git a/slices/view/src/androidTest/java/androidx/slice/render/SliceRenderer.java b/slices/view/src/androidTest/java/androidx/slice/render/SliceRenderer.java
index 1c33115..ad540c3 100644
--- a/slices/view/src/androidTest/java/androidx/slice/render/SliceRenderer.java
+++ b/slices/view/src/androidTest/java/androidx/slice/render/SliceRenderer.java
@@ -63,7 +63,7 @@
mParent = new ViewGroup(mContext) {
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
- int width = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 900,
+ int width = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1000,
mContext.getResources().getDisplayMetrics());
int height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 300,
mContext.getResources().getDisplayMetrics());
diff --git a/slices/view/src/main/java/androidx/slice/widget/SliceView.java b/slices/view/src/main/java/androidx/slice/widget/SliceView.java
index df786b3..e46513a 100644
--- a/slices/view/src/main/java/androidx/slice/widget/SliceView.java
+++ b/slices/view/src/main/java/androidx/slice/widget/SliceView.java
@@ -125,6 +125,8 @@
private final int mShortcutSize;
private final int mMinLargeHeight;
+ private final int mMaxLargeHeight;
+ private final int mActionRowHeight;
private AttributeSet mAttrs;
private int mThemeTintColor = -1;
@@ -163,6 +165,9 @@
mShortcutSize = getContext().getResources()
.getDimensionPixelSize(R.dimen.abc_slice_shortcut_size);
mMinLargeHeight = getResources().getDimensionPixelSize(R.dimen.abc_slice_large_height);
+ mMaxLargeHeight = getResources().getDimensionPixelSize(R.dimen.abc_slice_max_large_height);
+ mActionRowHeight = getResources().getDimensionPixelSize(
+ R.dimen.abc_slice_action_row_height);
}
private int getHeightForMode() {
@@ -182,49 +187,51 @@
if (MODE_SHORTCUT == mMode) {
// TODO: consider scaling the shortcut to fit if too small
childWidth = mShortcutSize;
- width = mShortcutSize;
+ width = mShortcutSize + getPaddingLeft() + getPaddingRight();
}
-
final int actionHeight = mActionRow.getVisibility() != View.GONE
- ? mActionRow.getMeasuredHeight()
+ ? mActionRowHeight
: 0;
- final int sliceHeight = getHeightForMode() + actionHeight;
+ final int sliceHeight = getHeightForMode();
final int heightAvailable = MeasureSpec.getSize(heightMeasureSpec);
final int heightMode = MeasureSpec.getMode(heightMeasureSpec);
- int height = heightAvailable;
- if (heightAvailable >= sliceHeight || heightMode == MeasureSpec.UNSPECIFIED) {
+ // Remove the padding from our available height
+ int height = heightAvailable - getPaddingTop() - getPaddingBottom();
+ if (heightAvailable >= sliceHeight + actionHeight
+ || heightMode == MeasureSpec.UNSPECIFIED) {
// Available space is larger than the slice or we be what we want
if (heightMode != MeasureSpec.EXACTLY) {
- int maxHeight = mIsScrollable ? mMinLargeHeight + actionHeight : sliceHeight;
- height = Math.min(maxHeight, sliceHeight);
+ if (!mIsScrollable) {
+ height = Math.min(mMaxLargeHeight, sliceHeight);
+ } else {
+ // If we want to be bigger than max, then we can be a good scrollable at min
+ // large height, if it's not larger lets just use its desired height
+ height = sliceHeight > mMaxLargeHeight ? mMinLargeHeight : sliceHeight;
+ }
}
} else {
// Not enough space available for slice in current mode
if (getMode() == MODE_LARGE && heightAvailable >= mMinLargeHeight + actionHeight) {
// It's just a slice with scrolling content; cap it to height available.
- height = Math.min(mMinLargeHeight + actionHeight, heightAvailable);
+ height = Math.min(mMinLargeHeight, heightAvailable);
} else if (getMode() == MODE_SHORTCUT) {
// TODO: consider scaling the shortcut to fit if too small
height = mShortcutSize;
}
}
- heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY);
- // Measure the children without the padding
- final int left = getPaddingLeft();
- final int top = getPaddingTop();
- final int right = getPaddingRight();
- final int bot = getPaddingBottom();
- int childHeight = MeasureSpec.getSize(heightMeasureSpec);
- childWidth -= left + right;
- childHeight -= top + bot;
+ int childHeight = height + getPaddingTop() + getPaddingBottom();
int childWidthMeasureSpec = MeasureSpec.makeMeasureSpec(childWidth, MeasureSpec.EXACTLY);
int childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(childHeight, MeasureSpec.EXACTLY);
- measureChildren(childWidthMeasureSpec, childHeightMeasureSpec);
+ measureChild(mCurrentView, childWidthMeasureSpec, childHeightMeasureSpec);
- // Figure out parent width
- width += left + right;
- setMeasuredDimension(width, heightMeasureSpec);
+ int actionPaddedHeight = actionHeight + getPaddingTop() + getPaddingBottom();
+ int actionHeightSpec = MeasureSpec.makeMeasureSpec(actionPaddedHeight, MeasureSpec.EXACTLY);
+ measureChild(mActionRow, childWidthMeasureSpec, actionHeightSpec);
+
+ // Total height should include action row and our padding
+ height += actionHeight + getPaddingTop() + getPaddingBottom();
+ setMeasuredDimension(width, height);
}
@Override
@@ -232,14 +239,12 @@
View v = mCurrentView.getView();
final int left = getPaddingLeft();
final int top = getPaddingTop();
- final int right = getPaddingRight();
- final int bottom = getPaddingBottom();
v.layout(left, top, left + v.getMeasuredWidth(), top + v.getMeasuredHeight());
if (mActionRow.getVisibility() != View.GONE) {
mActionRow.layout(left,
- top + v.getMeasuredHeight() + bottom,
- left + mActionRow.getMeasuredWidth() + right,
- top + v.getMeasuredHeight() + bottom + mActionRow.getMeasuredHeight());
+ top + v.getMeasuredHeight(),
+ left + mActionRow.getMeasuredWidth(),
+ top + v.getMeasuredHeight() + mActionRow.getMeasuredHeight());
}
}
diff --git a/slices/view/src/main/res/values/dimens.xml b/slices/view/src/main/res/values/dimens.xml
index 04d74f3..bb90106 100644
--- a/slices/view/src/main/res/values/dimens.xml
+++ b/slices/view/src/main/res/values/dimens.xml
@@ -30,6 +30,10 @@
<dimen name="abc_slice_small_height">48dp</dimen>
<!-- Minimum height of a large template -->
<dimen name="abc_slice_large_height">240dp</dimen>
+ <!-- Maximum height of a large template -->
+ <dimen name="abc_slice_max_large_height">320dp</dimen>
+ <!-- Height of the action row -->
+ <dimen name="abc_slice_action_row_height">48dp</dimen>
<!-- Row view sizes-->
<!-- Min height of row view; default size if one line of text -->