package androidx.cardview.widget; import android.content.res.ColorStateList; import android.content.res.Resources; import android.graphics.Canvas; import android.graphics.ColorFilter; import android.graphics.LinearGradient; import android.graphics.Paint; import android.graphics.Path; import android.graphics.RadialGradient; import android.graphics.Rect; import android.graphics.RectF; import android.graphics.Shader; import android.graphics.drawable.Drawable; import androidx.cardview.R$color; import androidx.cardview.R$dimen; /* loaded from: classes.dex */ class RoundRectDrawableWithShadow extends Drawable { private static final double q = Math.cos(Math.toRadians(45.0d)); static RoundRectHelper r; private final int a; private Paint c; private Paint d; private final RectF e; private float f; private Path g; private float h; private float i; private float j; private ColorStateList k; private final int m; private final int n; private boolean l = true; private boolean o = true; private boolean p = false; private Paint b = new Paint(5); interface RoundRectHelper { void a(Canvas canvas, RectF rectF, float f, Paint paint); } RoundRectDrawableWithShadow(Resources resources, ColorStateList colorStateList, float f, float f2, float f3) { this.m = resources.getColor(R$color.cardview_shadow_start_color); this.n = resources.getColor(R$color.cardview_shadow_end_color); this.a = resources.getDimensionPixelSize(R$dimen.cardview_compat_inset_shadow); b(colorStateList); this.c = new Paint(5); this.c.setStyle(Paint.Style.FILL); this.f = (int) (f + 0.5f); this.e = new RectF(); this.d = new Paint(this.c); this.d.setAntiAlias(false); a(f2, f3); } private void b(ColorStateList colorStateList) { if (colorStateList == null) { colorStateList = ColorStateList.valueOf(0); } this.k = colorStateList; this.b.setColor(this.k.getColorForState(getState(), this.k.getDefaultColor())); } private int d(float f) { int i = (int) (f + 0.5f); return i % 2 == 1 ? i - 1 : i; } private void g() { float f = this.f; RectF rectF = new RectF(-f, -f, f, f); RectF rectF2 = new RectF(rectF); float f2 = this.i; rectF2.inset(-f2, -f2); Path path = this.g; if (path == null) { this.g = new Path(); } else { path.reset(); } this.g.setFillType(Path.FillType.EVEN_ODD); this.g.moveTo(-this.f, 0.0f); this.g.rLineTo(-this.i, 0.0f); this.g.arcTo(rectF2, 180.0f, 90.0f, false); this.g.arcTo(rectF, 270.0f, -90.0f, false); this.g.close(); float f3 = this.f; float f4 = this.i; float f5 = f3 / (f3 + f4); Paint paint = this.c; float f6 = f3 + f4; int i = this.m; paint.setShader(new RadialGradient(0.0f, 0.0f, f6, new int[]{i, i, this.n}, new float[]{0.0f, f5, 1.0f}, Shader.TileMode.CLAMP)); Paint paint2 = this.d; float f7 = this.f; float f8 = this.i; int i2 = this.m; paint2.setShader(new LinearGradient(0.0f, (-f7) + f8, 0.0f, (-f7) - f8, new int[]{i2, i2, this.n}, new float[]{0.0f, 0.5f, 1.0f}, Shader.TileMode.CLAMP)); this.d.setAntiAlias(false); } void a(boolean z) { this.o = z; invalidateSelf(); } void c(float f) { a(f, this.h); } @Override // android.graphics.drawable.Drawable public void draw(Canvas canvas) { if (this.l) { b(getBounds()); this.l = false; } canvas.translate(0.0f, this.j / 2.0f); a(canvas); canvas.translate(0.0f, (-this.j) / 2.0f); r.a(canvas, this.e, this.f, this.b); } float e() { float f = this.h; return (Math.max(f, this.f + this.a + (f / 2.0f)) * 2.0f) + ((this.h + this.a) * 2.0f); } float f() { return this.j; } @Override // android.graphics.drawable.Drawable public int getOpacity() { return -3; } @Override // android.graphics.drawable.Drawable public boolean getPadding(Rect rect) { int ceil = (int) Math.ceil(b(this.h, this.f, this.o)); int ceil2 = (int) Math.ceil(a(this.h, this.f, this.o)); rect.set(ceil2, ceil, ceil2, ceil); return true; } @Override // android.graphics.drawable.Drawable public boolean isStateful() { ColorStateList colorStateList = this.k; return (colorStateList != null && colorStateList.isStateful()) || super.isStateful(); } @Override // android.graphics.drawable.Drawable protected void onBoundsChange(Rect rect) { super.onBoundsChange(rect); this.l = true; } @Override // android.graphics.drawable.Drawable protected boolean onStateChange(int[] iArr) { ColorStateList colorStateList = this.k; int colorForState = colorStateList.getColorForState(iArr, colorStateList.getDefaultColor()); if (this.b.getColor() == colorForState) { return false; } this.b.setColor(colorForState); this.l = true; invalidateSelf(); return true; } @Override // android.graphics.drawable.Drawable public void setAlpha(int i) { this.b.setAlpha(i); this.c.setAlpha(i); this.d.setAlpha(i); } @Override // android.graphics.drawable.Drawable public void setColorFilter(ColorFilter colorFilter) { this.b.setColorFilter(colorFilter); } float c() { return this.h; } float d() { float f = this.h; return (Math.max(f, this.f + this.a + ((f * 1.5f) / 2.0f)) * 2.0f) + (((this.h * 1.5f) + this.a) * 2.0f); } private void a(float f, float f2) { if (f < 0.0f) { throw new IllegalArgumentException("Invalid shadow size " + f + ". Must be >= 0"); } if (f2 >= 0.0f) { float d = d(f); float d2 = d(f2); if (d > d2) { if (!this.p) { this.p = true; } d = d2; } if (this.j == d && this.h == d2) { return; } this.j = d; this.h = d2; this.i = (int) ((d * 1.5f) + this.a + 0.5f); this.l = true; invalidateSelf(); return; } throw new IllegalArgumentException("Invalid max shadow size " + f2 + ". Must be >= 0"); } static float b(float f, float f2, boolean z) { return z ? (float) ((f * 1.5f) + ((1.0d - q) * f2)) : f * 1.5f; } private void b(Rect rect) { float f = this.h; float f2 = 1.5f * f; this.e.set(rect.left + f, rect.top + f2, rect.right - f, rect.bottom - f2); g(); } float b() { return this.f; } void b(float f) { a(this.j, f); } static float a(float f, float f2, boolean z) { return z ? (float) (f + ((1.0d - q) * f2)) : f; } void a(float f) { if (f < 0.0f) { throw new IllegalArgumentException("Invalid radius " + f + ". Must be >= 0"); } float f2 = (int) (f + 0.5f); if (this.f == f2) { return; } this.f = f2; this.l = true; invalidateSelf(); } private void a(Canvas canvas) { float f = this.f; float f2 = (-f) - this.i; float f3 = f + this.a + (this.j / 2.0f); float f4 = f3 * 2.0f; boolean z = this.e.width() - f4 > 0.0f; boolean z2 = this.e.height() - f4 > 0.0f; int save = canvas.save(); RectF rectF = this.e; canvas.translate(rectF.left + f3, rectF.top + f3); canvas.drawPath(this.g, this.c); if (z) { canvas.drawRect(0.0f, f2, this.e.width() - f4, -this.f, this.d); } canvas.restoreToCount(save); int save2 = canvas.save(); RectF rectF2 = this.e; canvas.translate(rectF2.right - f3, rectF2.bottom - f3); canvas.rotate(180.0f); canvas.drawPath(this.g, this.c); if (z) { canvas.drawRect(0.0f, f2, this.e.width() - f4, (-this.f) + this.i, this.d); } canvas.restoreToCount(save2); int save3 = canvas.save(); RectF rectF3 = this.e; canvas.translate(rectF3.left + f3, rectF3.bottom - f3); canvas.rotate(270.0f); canvas.drawPath(this.g, this.c); if (z2) { canvas.drawRect(0.0f, f2, this.e.height() - f4, -this.f, this.d); } canvas.restoreToCount(save3); int save4 = canvas.save(); RectF rectF4 = this.e; canvas.translate(rectF4.right - f3, rectF4.top + f3); canvas.rotate(90.0f); canvas.drawPath(this.g, this.c); if (z2) { canvas.drawRect(0.0f, f2, this.e.height() - f4, -this.f, this.d); } canvas.restoreToCount(save4); } void a(Rect rect) { getPadding(rect); } void a(ColorStateList colorStateList) { b(colorStateList); invalidateSelf(); } ColorStateList a() { return this.k; } }