Merge "Fix start/end margin for CarListDialog's dividers." into oc-mr1-jetpack-dev
diff --git a/car/res/layout/car_list_dialog.xml b/car/res/layout/car_list_dialog.xml
index c6dc452..c3ff1bf 100644
--- a/car/res/layout/car_list_dialog.xml
+++ b/car/res/layout/car_list_dialog.xml
@@ -42,6 +42,8 @@
android:layout_height="wrap_content"
android:theme="?attr/dialogListTheme"
app:gutter="none"
+ app:dividerStartMargin="@dimen/car_keyline_1"
+ app:dividerEndMargin="@dimen/car_keyline_1"
app:showPagedListViewDivider="true"
app:scrollBarEnabled="false" />
</androidx.car.widget.ColumnCardView>
diff --git a/car/res/values/attrs.xml b/car/res/values/attrs.xml
index 6e47aef..076c342 100644
--- a/car/res/values/attrs.xml
+++ b/car/res/values/attrs.xml
@@ -67,6 +67,9 @@
<!-- A starting margin before the drawing of the dividing line. This margin will be an
offset from the view specified by "alignDividerStartTo" if given. -->
<attr name="dividerStartMargin" format="dimension" />
+ <!-- An ending margin before the drawing of the dividing line. This margin will be an
+ offset from the view specified by "alignDividerEndTo" if given. -->
+ <attr name="dividerEndMargin" format="dimension" />
<!-- The color of the list divider. -->
<attr name="listDividerColor" format="color" />
<!-- The width of the margin on the right side of the list.
diff --git a/car/src/main/java/androidx/car/widget/PagedListView.java b/car/src/main/java/androidx/car/widget/PagedListView.java
index adf1829..864e597 100644
--- a/car/src/main/java/androidx/car/widget/PagedListView.java
+++ b/car/src/main/java/androidx/car/widget/PagedListView.java
@@ -282,6 +282,8 @@
if (a.getBoolean(R.styleable.PagedListView_showPagedListViewDivider, true)) {
int dividerStartMargin = a.getDimensionPixelSize(
R.styleable.PagedListView_dividerStartMargin, 0);
+ int dividerEndMargin = a.getDimensionPixelSize(
+ R.styleable.PagedListView_dividerEndMargin, 0);
int dividerStartId = a.getResourceId(
R.styleable.PagedListView_alignDividerStartTo, INVALID_RESOURCE_ID);
int dividerEndId = a.getResourceId(
@@ -291,7 +293,7 @@
R.color.car_list_divider);
mRecyclerView.addItemDecoration(new DividerDecoration(context, dividerStartMargin,
- dividerStartId, dividerEndId, listDividerColor));
+ dividerEndMargin, dividerStartId, dividerEndId, listDividerColor));
}
int itemSpacing = a.getDimensionPixelSize(R.styleable.PagedListView_itemSpacing, 0);
@@ -1106,6 +1108,7 @@
private final Paint mPaint;
private final int mDividerHeight;
private final int mDividerStartMargin;
+ private final int mDividerEndMargin;
@IdRes private final int mDividerStartId;
@IdRes private final int mDividerEndId;
@ColorRes private final int mListDividerColor;
@@ -1122,10 +1125,11 @@
* container view of each child will be used.
*/
private DividerDecoration(Context context, int dividerStartMargin,
- @IdRes int dividerStartId, @IdRes int dividerEndId,
+ int dividerEndMargin, @IdRes int dividerStartId, @IdRes int dividerEndId,
@ColorRes int listDividerColor) {
mContext = context;
mDividerStartMargin = dividerStartMargin;
+ mDividerEndMargin = dividerEndMargin;
mDividerStartId = dividerStartId;
mDividerEndId = dividerEndId;
mListDividerColor = listDividerColor;
@@ -1133,7 +1137,7 @@
mPaint = new Paint();
mPaint.setColor(mContext.getColor(listDividerColor));
mDividerHeight = mContext.getResources().getDimensionPixelSize(
- R.dimen.car_list_divider_height);
+ R.dimen.car_list_divider_height);
}
/** Updates the list divider color which may have changed due to a day night transition. */
@@ -1206,7 +1210,8 @@
int left = container.getLeft() + mDividerStartMargin
+ (startRect.left - containerRect.left);
- int right = container.getRight() - (endRect.right - containerRect.right);
+ int right = container.getRight() - mDividerEndMargin
+ - (endRect.right - containerRect.right);
int bottom = container.getBottom() + spacing / 2 + mDividerHeight / 2;
int top = bottom - mDividerHeight;
@@ -1255,7 +1260,7 @@
// Otherwise the top items will be visually uneven.
outRect.top = mTopOffset;
} else if (position == 0) {
- // Only set the offset for the first item.
+ // Only set the offset for the first item.
outRect.top = mTopOffset;
}
}