97 lines
3.7 KiB
Java
97 lines
3.7 KiB
Java
package com.ubt.jimu.connect.view;
|
|
|
|
import android.R;
|
|
import android.content.Context;
|
|
import android.content.res.TypedArray;
|
|
import android.graphics.Canvas;
|
|
import android.graphics.Paint;
|
|
import android.graphics.Rect;
|
|
import android.graphics.drawable.Drawable;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class RecycleViewDivider extends RecyclerView.ItemDecoration {
|
|
private static final int[] e = {R.attr.listDivider};
|
|
private Paint a;
|
|
private Drawable b;
|
|
private int c;
|
|
private int d;
|
|
|
|
public RecycleViewDivider(Context context, int i) {
|
|
this.c = 2;
|
|
if (i != 1 && i != 0) {
|
|
throw new IllegalArgumentException("请输入正确的参数!");
|
|
}
|
|
this.d = i;
|
|
TypedArray obtainStyledAttributes = context.obtainStyledAttributes(e);
|
|
this.b = obtainStyledAttributes.getDrawable(0);
|
|
obtainStyledAttributes.recycle();
|
|
}
|
|
|
|
private void a(Canvas canvas, RecyclerView recyclerView) {
|
|
int paddingLeft = recyclerView.getPaddingLeft();
|
|
int measuredWidth = recyclerView.getMeasuredWidth() - recyclerView.getPaddingRight();
|
|
int childCount = recyclerView.getChildCount();
|
|
for (int i = 0; i < childCount; i++) {
|
|
View childAt = recyclerView.getChildAt(i);
|
|
int bottom = childAt.getBottom() + ((ViewGroup.MarginLayoutParams) ((RecyclerView.LayoutParams) childAt.getLayoutParams())).bottomMargin;
|
|
int i2 = this.c + bottom;
|
|
Drawable drawable = this.b;
|
|
if (drawable != null) {
|
|
drawable.setBounds(paddingLeft, bottom, measuredWidth, i2);
|
|
this.b.draw(canvas);
|
|
}
|
|
Paint paint = this.a;
|
|
if (paint != null) {
|
|
canvas.drawRect(paddingLeft, bottom, measuredWidth, i2, paint);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void b(Canvas canvas, RecyclerView recyclerView) {
|
|
int paddingTop = recyclerView.getPaddingTop();
|
|
int measuredHeight = recyclerView.getMeasuredHeight() - recyclerView.getPaddingBottom();
|
|
int childCount = recyclerView.getChildCount();
|
|
for (int i = 0; i < childCount; i++) {
|
|
View childAt = recyclerView.getChildAt(i);
|
|
int right = childAt.getRight() + ((ViewGroup.MarginLayoutParams) ((RecyclerView.LayoutParams) childAt.getLayoutParams())).rightMargin;
|
|
int i2 = this.c + right;
|
|
Drawable drawable = this.b;
|
|
if (drawable != null) {
|
|
drawable.setBounds(right, paddingTop, i2, measuredHeight);
|
|
this.b.draw(canvas);
|
|
}
|
|
Paint paint = this.a;
|
|
if (paint != null) {
|
|
canvas.drawRect(right, paddingTop, i2, measuredHeight, paint);
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override // androidx.recyclerview.widget.RecyclerView.ItemDecoration
|
|
public void getItemOffsets(Rect rect, View view, RecyclerView recyclerView, RecyclerView.State state) {
|
|
super.getItemOffsets(rect, view, recyclerView, state);
|
|
rect.set(0, 0, 0, this.c);
|
|
}
|
|
|
|
@Override // androidx.recyclerview.widget.RecyclerView.ItemDecoration
|
|
public void onDraw(Canvas canvas, RecyclerView recyclerView, RecyclerView.State state) {
|
|
super.onDraw(canvas, recyclerView, state);
|
|
if (this.d == 1) {
|
|
b(canvas, recyclerView);
|
|
} else {
|
|
a(canvas, recyclerView);
|
|
}
|
|
}
|
|
|
|
public RecycleViewDivider(Context context, int i, int i2, int i3) {
|
|
this(context, i);
|
|
this.c = i2;
|
|
this.a = new Paint(1);
|
|
this.a.setColor(i3);
|
|
this.a.setStyle(Paint.Style.FILL);
|
|
}
|
|
}
|