107 lines
4.0 KiB
Java
107 lines
4.0 KiB
Java
package androidx.recyclerview.widget;
|
|
|
|
import android.R;
|
|
import android.content.Context;
|
|
import android.content.res.TypedArray;
|
|
import android.graphics.Canvas;
|
|
import android.graphics.Rect;
|
|
import android.graphics.drawable.Drawable;
|
|
import android.util.Log;
|
|
import android.view.View;
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class DividerItemDecoration extends RecyclerView.ItemDecoration {
|
|
private static final int[] d = {R.attr.listDivider};
|
|
private Drawable a;
|
|
private int b;
|
|
private final Rect c = new Rect();
|
|
|
|
public DividerItemDecoration(Context context, int i) {
|
|
TypedArray obtainStyledAttributes = context.obtainStyledAttributes(d);
|
|
this.a = obtainStyledAttributes.getDrawable(0);
|
|
if (this.a == null) {
|
|
Log.w("DividerItem", "@android:attr/listDivider was not set in the theme used for this DividerItemDecoration. Please set that attribute all call setDrawable()");
|
|
}
|
|
obtainStyledAttributes.recycle();
|
|
setOrientation(i);
|
|
}
|
|
|
|
private void a(Canvas canvas, RecyclerView recyclerView) {
|
|
int height;
|
|
int i;
|
|
canvas.save();
|
|
if (recyclerView.getClipToPadding()) {
|
|
i = recyclerView.getPaddingTop();
|
|
height = recyclerView.getHeight() - recyclerView.getPaddingBottom();
|
|
canvas.clipRect(recyclerView.getPaddingLeft(), i, recyclerView.getWidth() - recyclerView.getPaddingRight(), height);
|
|
} else {
|
|
height = recyclerView.getHeight();
|
|
i = 0;
|
|
}
|
|
int childCount = recyclerView.getChildCount();
|
|
for (int i2 = 0; i2 < childCount; i2++) {
|
|
View childAt = recyclerView.getChildAt(i2);
|
|
recyclerView.getLayoutManager().b(childAt, this.c);
|
|
int round = this.c.right + Math.round(childAt.getTranslationX());
|
|
this.a.setBounds(round - this.a.getIntrinsicWidth(), i, round, height);
|
|
this.a.draw(canvas);
|
|
}
|
|
canvas.restore();
|
|
}
|
|
|
|
private void b(Canvas canvas, RecyclerView recyclerView) {
|
|
int width;
|
|
int i;
|
|
canvas.save();
|
|
if (recyclerView.getClipToPadding()) {
|
|
i = recyclerView.getPaddingLeft();
|
|
width = recyclerView.getWidth() - recyclerView.getPaddingRight();
|
|
canvas.clipRect(i, recyclerView.getPaddingTop(), width, recyclerView.getHeight() - recyclerView.getPaddingBottom());
|
|
} else {
|
|
width = recyclerView.getWidth();
|
|
i = 0;
|
|
}
|
|
int childCount = recyclerView.getChildCount();
|
|
for (int i2 = 0; i2 < childCount; i2++) {
|
|
View childAt = recyclerView.getChildAt(i2);
|
|
recyclerView.a(childAt, this.c);
|
|
int round = this.c.bottom + Math.round(childAt.getTranslationY());
|
|
this.a.setBounds(i, round - this.a.getIntrinsicHeight(), width, round);
|
|
this.a.draw(canvas);
|
|
}
|
|
canvas.restore();
|
|
}
|
|
|
|
@Override // androidx.recyclerview.widget.RecyclerView.ItemDecoration
|
|
public void getItemOffsets(Rect rect, View view, RecyclerView recyclerView, RecyclerView.State state) {
|
|
Drawable drawable = this.a;
|
|
if (drawable == null) {
|
|
rect.set(0, 0, 0, 0);
|
|
} else if (this.b == 1) {
|
|
rect.set(0, 0, 0, drawable.getIntrinsicHeight());
|
|
} else {
|
|
rect.set(0, 0, drawable.getIntrinsicWidth(), 0);
|
|
}
|
|
}
|
|
|
|
@Override // androidx.recyclerview.widget.RecyclerView.ItemDecoration
|
|
public void onDraw(Canvas canvas, RecyclerView recyclerView, RecyclerView.State state) {
|
|
if (recyclerView.getLayoutManager() == null || this.a == null) {
|
|
return;
|
|
}
|
|
if (this.b == 1) {
|
|
b(canvas, recyclerView);
|
|
} else {
|
|
a(canvas, recyclerView);
|
|
}
|
|
}
|
|
|
|
public void setOrientation(int i) {
|
|
if (i != 0 && i != 1) {
|
|
throw new IllegalArgumentException("Invalid orientation. It should be either HORIZONTAL or VERTICAL");
|
|
}
|
|
this.b = i;
|
|
}
|
|
}
|