ADD week 5
This commit is contained in:
@ -0,0 +1,180 @@
|
||||
package androidx.cardview.widget;
|
||||
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.ColorFilter;
|
||||
import android.graphics.Outline;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.PorterDuffColorFilter;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.RectF;
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
class RoundRectDrawable extends Drawable {
|
||||
private ColorStateList mBackground;
|
||||
private final RectF mBoundsF;
|
||||
private final Rect mBoundsI;
|
||||
private float mPadding;
|
||||
private float mRadius;
|
||||
private ColorStateList mTint;
|
||||
private PorterDuffColorFilter mTintFilter;
|
||||
private boolean mInsetForPadding = false;
|
||||
private boolean mInsetForRadius = true;
|
||||
private PorterDuff.Mode mTintMode = PorterDuff.Mode.SRC_IN;
|
||||
private final Paint mPaint = new Paint(5);
|
||||
|
||||
public ColorStateList getColor() {
|
||||
return this.mBackground;
|
||||
}
|
||||
|
||||
@Override // android.graphics.drawable.Drawable
|
||||
public int getOpacity() {
|
||||
return -3;
|
||||
}
|
||||
|
||||
float getPadding() {
|
||||
return this.mPadding;
|
||||
}
|
||||
|
||||
public float getRadius() {
|
||||
return this.mRadius;
|
||||
}
|
||||
|
||||
RoundRectDrawable(ColorStateList colorStateList, float f) {
|
||||
this.mRadius = f;
|
||||
setBackground(colorStateList);
|
||||
this.mBoundsF = new RectF();
|
||||
this.mBoundsI = new Rect();
|
||||
}
|
||||
|
||||
private void setBackground(ColorStateList colorStateList) {
|
||||
if (colorStateList == null) {
|
||||
colorStateList = ColorStateList.valueOf(0);
|
||||
}
|
||||
this.mBackground = colorStateList;
|
||||
this.mPaint.setColor(colorStateList.getColorForState(getState(), this.mBackground.getDefaultColor()));
|
||||
}
|
||||
|
||||
void setPadding(float f, boolean z, boolean z2) {
|
||||
if (f == this.mPadding && this.mInsetForPadding == z && this.mInsetForRadius == z2) {
|
||||
return;
|
||||
}
|
||||
this.mPadding = f;
|
||||
this.mInsetForPadding = z;
|
||||
this.mInsetForRadius = z2;
|
||||
updateBounds(null);
|
||||
invalidateSelf();
|
||||
}
|
||||
|
||||
@Override // android.graphics.drawable.Drawable
|
||||
public void draw(Canvas canvas) {
|
||||
boolean z;
|
||||
Paint paint = this.mPaint;
|
||||
if (this.mTintFilter == null || paint.getColorFilter() != null) {
|
||||
z = false;
|
||||
} else {
|
||||
paint.setColorFilter(this.mTintFilter);
|
||||
z = true;
|
||||
}
|
||||
RectF rectF = this.mBoundsF;
|
||||
float f = this.mRadius;
|
||||
canvas.drawRoundRect(rectF, f, f, paint);
|
||||
if (z) {
|
||||
paint.setColorFilter(null);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateBounds(Rect rect) {
|
||||
if (rect == null) {
|
||||
rect = getBounds();
|
||||
}
|
||||
this.mBoundsF.set(rect.left, rect.top, rect.right, rect.bottom);
|
||||
this.mBoundsI.set(rect);
|
||||
if (this.mInsetForPadding) {
|
||||
this.mBoundsI.inset((int) Math.ceil(RoundRectDrawableWithShadow.calculateHorizontalPadding(this.mPadding, this.mRadius, this.mInsetForRadius)), (int) Math.ceil(RoundRectDrawableWithShadow.calculateVerticalPadding(this.mPadding, this.mRadius, this.mInsetForRadius)));
|
||||
this.mBoundsF.set(this.mBoundsI);
|
||||
}
|
||||
}
|
||||
|
||||
@Override // android.graphics.drawable.Drawable
|
||||
protected void onBoundsChange(Rect rect) {
|
||||
super.onBoundsChange(rect);
|
||||
updateBounds(rect);
|
||||
}
|
||||
|
||||
@Override // android.graphics.drawable.Drawable
|
||||
public void getOutline(Outline outline) {
|
||||
outline.setRoundRect(this.mBoundsI, this.mRadius);
|
||||
}
|
||||
|
||||
void setRadius(float f) {
|
||||
if (f == this.mRadius) {
|
||||
return;
|
||||
}
|
||||
this.mRadius = f;
|
||||
updateBounds(null);
|
||||
invalidateSelf();
|
||||
}
|
||||
|
||||
@Override // android.graphics.drawable.Drawable
|
||||
public void setAlpha(int i) {
|
||||
this.mPaint.setAlpha(i);
|
||||
}
|
||||
|
||||
@Override // android.graphics.drawable.Drawable
|
||||
public void setColorFilter(ColorFilter colorFilter) {
|
||||
this.mPaint.setColorFilter(colorFilter);
|
||||
}
|
||||
|
||||
public void setColor(ColorStateList colorStateList) {
|
||||
setBackground(colorStateList);
|
||||
invalidateSelf();
|
||||
}
|
||||
|
||||
@Override // android.graphics.drawable.Drawable
|
||||
public void setTintList(ColorStateList colorStateList) {
|
||||
this.mTint = colorStateList;
|
||||
this.mTintFilter = createTintFilter(colorStateList, this.mTintMode);
|
||||
invalidateSelf();
|
||||
}
|
||||
|
||||
@Override // android.graphics.drawable.Drawable
|
||||
public void setTintMode(PorterDuff.Mode mode) {
|
||||
this.mTintMode = mode;
|
||||
this.mTintFilter = createTintFilter(this.mTint, mode);
|
||||
invalidateSelf();
|
||||
}
|
||||
|
||||
@Override // android.graphics.drawable.Drawable
|
||||
protected boolean onStateChange(int[] iArr) {
|
||||
PorterDuff.Mode mode;
|
||||
ColorStateList colorStateList = this.mBackground;
|
||||
int colorForState = colorStateList.getColorForState(iArr, colorStateList.getDefaultColor());
|
||||
boolean z = colorForState != this.mPaint.getColor();
|
||||
if (z) {
|
||||
this.mPaint.setColor(colorForState);
|
||||
}
|
||||
ColorStateList colorStateList2 = this.mTint;
|
||||
if (colorStateList2 == null || (mode = this.mTintMode) == null) {
|
||||
return z;
|
||||
}
|
||||
this.mTintFilter = createTintFilter(colorStateList2, mode);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override // android.graphics.drawable.Drawable
|
||||
public boolean isStateful() {
|
||||
ColorStateList colorStateList;
|
||||
ColorStateList colorStateList2 = this.mTint;
|
||||
return (colorStateList2 != null && colorStateList2.isStateful()) || ((colorStateList = this.mBackground) != null && colorStateList.isStateful()) || super.isStateful();
|
||||
}
|
||||
|
||||
private PorterDuffColorFilter createTintFilter(ColorStateList colorStateList, PorterDuff.Mode mode) {
|
||||
if (colorStateList == null || mode == null) {
|
||||
return null;
|
||||
}
|
||||
return new PorterDuffColorFilter(colorStateList.getColorForState(getState(), 0), mode);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user