package i;

import android.content.res.ColorStateList;
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;

/* JADX INFO: compiled from: RoundRectDrawableWithShadow.java */
/* JADX INFO: loaded from: classes.dex */
class h extends Drawable {

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    private static final double f4836q = Math.cos(Math.toRadians(45.0d));

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    static a f4837r;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    private final int f4838a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private Paint f4839b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private Paint f4840c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private Paint f4841d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    private final RectF f4842e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    private float f4843f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    private Path f4844g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    private float f4845h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    private float f4846i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    private float f4847j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    private ColorStateList f4848k;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    private boolean f4849l;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    private final int f4850m;

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    private final int f4851n;

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    private boolean f4852o;

    /* JADX INFO: renamed from: p, reason: collision with root package name */
    private boolean f4853p;

    /* JADX INFO: compiled from: RoundRectDrawableWithShadow.java */
    interface a {
        void a(Canvas canvas, RectF rectF, float f3, Paint paint);
    }

    private void a(Rect rect) {
        float f3 = this.f4845h;
        float f4 = 1.5f * f3;
        this.f4842e.set(rect.left + f3, rect.top + f4, rect.right - f3, rect.bottom - f4);
        b();
    }

    private void b() {
        float f3 = this.f4843f;
        RectF rectF = new RectF(-f3, -f3, f3, f3);
        RectF rectF2 = new RectF(rectF);
        float f4 = this.f4846i;
        rectF2.inset(-f4, -f4);
        Path path = this.f4844g;
        if (path == null) {
            this.f4844g = new Path();
        } else {
            path.reset();
        }
        this.f4844g.setFillType(Path.FillType.EVEN_ODD);
        this.f4844g.moveTo(-this.f4843f, 0.0f);
        this.f4844g.rLineTo(-this.f4846i, 0.0f);
        this.f4844g.arcTo(rectF2, 180.0f, 90.0f, false);
        this.f4844g.arcTo(rectF, 270.0f, -90.0f, false);
        this.f4844g.close();
        float f5 = this.f4843f;
        float f6 = f5 / (this.f4846i + f5);
        Paint paint = this.f4840c;
        float f7 = this.f4843f + this.f4846i;
        int i3 = this.f4850m;
        paint.setShader(new RadialGradient(0.0f, 0.0f, f7, new int[]{i3, i3, this.f4851n}, new float[]{0.0f, f6, 1.0f}, Shader.TileMode.CLAMP));
        Paint paint2 = this.f4841d;
        float f8 = this.f4843f;
        float f9 = this.f4846i;
        int i4 = this.f4850m;
        paint2.setShader(new LinearGradient(0.0f, (-f8) + f9, 0.0f, (-f8) - f9, new int[]{i4, i4, this.f4851n}, new float[]{0.0f, 0.5f, 1.0f}, Shader.TileMode.CLAMP));
        this.f4841d.setAntiAlias(false);
    }

    static float c(float f3, float f4, boolean z2) {
        return z2 ? (float) (((double) f3) + ((1.0d - f4836q) * ((double) f4))) : f3;
    }

    static float d(float f3, float f4, boolean z2) {
        return z2 ? (float) (((double) (f3 * 1.5f)) + ((1.0d - f4836q) * ((double) f4))) : f3 * 1.5f;
    }

    private void e(Canvas canvas) {
        float f3 = this.f4843f;
        float f4 = (-f3) - this.f4846i;
        float f5 = f3 + this.f4838a + (this.f4847j / 2.0f);
        float f6 = f5 * 2.0f;
        boolean z2 = this.f4842e.width() - f6 > 0.0f;
        boolean z3 = this.f4842e.height() - f6 > 0.0f;
        int iSave = canvas.save();
        RectF rectF = this.f4842e;
        canvas.translate(rectF.left + f5, rectF.top + f5);
        canvas.drawPath(this.f4844g, this.f4840c);
        if (z2) {
            canvas.drawRect(0.0f, f4, this.f4842e.width() - f6, -this.f4843f, this.f4841d);
        }
        canvas.restoreToCount(iSave);
        int iSave2 = canvas.save();
        RectF rectF2 = this.f4842e;
        canvas.translate(rectF2.right - f5, rectF2.bottom - f5);
        canvas.rotate(180.0f);
        canvas.drawPath(this.f4844g, this.f4840c);
        if (z2) {
            canvas.drawRect(0.0f, f4, this.f4842e.width() - f6, (-this.f4843f) + this.f4846i, this.f4841d);
        }
        canvas.restoreToCount(iSave2);
        int iSave3 = canvas.save();
        RectF rectF3 = this.f4842e;
        canvas.translate(rectF3.left + f5, rectF3.bottom - f5);
        canvas.rotate(270.0f);
        canvas.drawPath(this.f4844g, this.f4840c);
        if (z3) {
            canvas.drawRect(0.0f, f4, this.f4842e.height() - f6, -this.f4843f, this.f4841d);
        }
        canvas.restoreToCount(iSave3);
        int iSave4 = canvas.save();
        RectF rectF4 = this.f4842e;
        canvas.translate(rectF4.right - f5, rectF4.top + f5);
        canvas.rotate(90.0f);
        canvas.drawPath(this.f4844g, this.f4840c);
        if (z3) {
            canvas.drawRect(0.0f, f4, this.f4842e.height() - f6, -this.f4843f, this.f4841d);
        }
        canvas.restoreToCount(iSave4);
    }

    private void n(ColorStateList colorStateList) {
        if (colorStateList == null) {
            colorStateList = ColorStateList.valueOf(0);
        }
        this.f4848k = colorStateList;
        this.f4839b.setColor(colorStateList.getColorForState(getState(), this.f4848k.getDefaultColor()));
    }

    private void s(float f3, float f4) {
        if (f3 < 0.0f) {
            throw new IllegalArgumentException("Invalid shadow size " + f3 + ". Must be >= 0");
        }
        if (f4 < 0.0f) {
            throw new IllegalArgumentException("Invalid max shadow size " + f4 + ". Must be >= 0");
        }
        float fT = t(f3);
        float fT2 = t(f4);
        if (fT > fT2) {
            if (!this.f4853p) {
                this.f4853p = true;
            }
            fT = fT2;
        }
        if (this.f4847j == fT && this.f4845h == fT2) {
            return;
        }
        this.f4847j = fT;
        this.f4845h = fT2;
        this.f4846i = (int) ((fT * 1.5f) + this.f4838a + 0.5f);
        this.f4849l = true;
        invalidateSelf();
    }

    private int t(float f3) {
        int i3 = (int) (f3 + 0.5f);
        return i3 % 2 == 1 ? i3 - 1 : i3;
    }

    @Override // android.graphics.drawable.Drawable
    public void draw(Canvas canvas) {
        if (this.f4849l) {
            a(getBounds());
            this.f4849l = false;
        }
        canvas.translate(0.0f, this.f4847j / 2.0f);
        e(canvas);
        canvas.translate(0.0f, (-this.f4847j) / 2.0f);
        f4837r.a(canvas, this.f4842e, this.f4843f, this.f4839b);
    }

    ColorStateList f() {
        return this.f4848k;
    }

    float g() {
        return this.f4843f;
    }

    @Override // android.graphics.drawable.Drawable
    public int getOpacity() {
        return -3;
    }

    @Override // android.graphics.drawable.Drawable
    public boolean getPadding(Rect rect) {
        int iCeil = (int) Math.ceil(d(this.f4845h, this.f4843f, this.f4852o));
        int iCeil2 = (int) Math.ceil(c(this.f4845h, this.f4843f, this.f4852o));
        rect.set(iCeil2, iCeil, iCeil2, iCeil);
        return true;
    }

    void h(Rect rect) {
        getPadding(rect);
    }

    float i() {
        return this.f4845h;
    }

    @Override // android.graphics.drawable.Drawable
    public boolean isStateful() {
        ColorStateList colorStateList = this.f4848k;
        return (colorStateList != null && colorStateList.isStateful()) || super.isStateful();
    }

    float j() {
        float f3 = this.f4845h;
        return (Math.max(f3, this.f4843f + this.f4838a + ((f3 * 1.5f) / 2.0f)) * 2.0f) + (((this.f4845h * 1.5f) + this.f4838a) * 2.0f);
    }

    float k() {
        float f3 = this.f4845h;
        return (Math.max(f3, this.f4843f + this.f4838a + (f3 / 2.0f)) * 2.0f) + ((this.f4845h + this.f4838a) * 2.0f);
    }

    float l() {
        return this.f4847j;
    }

    void m(boolean z2) {
        this.f4852o = z2;
        invalidateSelf();
    }

    void o(ColorStateList colorStateList) {
        n(colorStateList);
        invalidateSelf();
    }

    @Override // android.graphics.drawable.Drawable
    protected void onBoundsChange(Rect rect) {
        super.onBoundsChange(rect);
        this.f4849l = true;
    }

    @Override // android.graphics.drawable.Drawable
    protected boolean onStateChange(int[] iArr) {
        ColorStateList colorStateList = this.f4848k;
        int colorForState = colorStateList.getColorForState(iArr, colorStateList.getDefaultColor());
        if (this.f4839b.getColor() == colorForState) {
            return false;
        }
        this.f4839b.setColor(colorForState);
        this.f4849l = true;
        invalidateSelf();
        return true;
    }

    void p(float f3) {
        if (f3 < 0.0f) {
            throw new IllegalArgumentException("Invalid radius " + f3 + ". Must be >= 0");
        }
        float f4 = (int) (f3 + 0.5f);
        if (this.f4843f == f4) {
            return;
        }
        this.f4843f = f4;
        this.f4849l = true;
        invalidateSelf();
    }

    void q(float f3) {
        s(this.f4847j, f3);
    }

    void r(float f3) {
        s(f3, this.f4845h);
    }

    @Override // android.graphics.drawable.Drawable
    public void setAlpha(int i3) {
        this.f4839b.setAlpha(i3);
        this.f4840c.setAlpha(i3);
        this.f4841d.setAlpha(i3);
    }

    @Override // android.graphics.drawable.Drawable
    public void setColorFilter(ColorFilter colorFilter) {
        this.f4839b.setColorFilter(colorFilter);
    }
}
