package i2;

import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorFilter;
import android.graphics.Matrix;
import android.graphics.Outline;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Region;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Looper;
import android.util.AttributeSet;
import android.util.Log;
import c2.C0338a;
import h2.C0619a;
import java.util.BitSet;
import java.util.Objects;

/* JADX INFO: renamed from: i2.g, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public class C0630g extends Drawable implements v {

    /* JADX INFO: renamed from: G, reason: collision with root package name */
    public static final Paint f6575G;

    /* JADX INFO: renamed from: A, reason: collision with root package name */
    public final S.g f6576A;

    /* JADX INFO: renamed from: B, reason: collision with root package name */
    public final m f6577B;

    /* JADX INFO: renamed from: C, reason: collision with root package name */
    public PorterDuffColorFilter f6578C;

    /* JADX INFO: renamed from: D, reason: collision with root package name */
    public PorterDuffColorFilter f6579D;

    /* JADX INFO: renamed from: E, reason: collision with root package name */
    public final RectF f6580E;

    /* JADX INFO: renamed from: F, reason: collision with root package name */
    public final boolean f6581F;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public C0629f f6582k;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public final t[] f6583l;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public final t[] f6584m;

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    public final BitSet f6585n;

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    public boolean f6586o;
    public final Matrix p;
    public final Path q;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public final Path f6587r;

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    public final RectF f6588s;

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    public final RectF f6589t;

    /* JADX INFO: renamed from: u, reason: collision with root package name */
    public final Region f6590u;

    /* JADX INFO: renamed from: v, reason: collision with root package name */
    public final Region f6591v;

    /* JADX INFO: renamed from: w, reason: collision with root package name */
    public k f6592w;

    /* JADX INFO: renamed from: x, reason: collision with root package name */
    public final Paint f6593x;

    /* JADX INFO: renamed from: y, reason: collision with root package name */
    public final Paint f6594y;

    /* JADX INFO: renamed from: z, reason: collision with root package name */
    public final C0619a f6595z;

    static {
        Paint paint = new Paint(1);
        f6575G = paint;
        paint.setColor(-1);
        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT));
    }

    public C0630g() {
        this(new k());
    }

    public final void a(RectF rectF, Path path) {
        C0629f c0629f = this.f6582k;
        this.f6577B.a(c0629f.f6561a, c0629f.i, rectF, this.f6576A, path);
        if (this.f6582k.f6568h != 1.0f) {
            Matrix matrix = this.p;
            matrix.reset();
            float f6 = this.f6582k.f6568h;
            matrix.setScale(f6, f6, rectF.width() / 2.0f, rectF.height() / 2.0f);
            path.transform(matrix);
        }
        path.computeBounds(this.f6580E, true);
    }

    public final int b(int i) {
        int i5;
        C0629f c0629f = this.f6582k;
        float f6 = c0629f.f6572m + 0.0f + c0629f.f6571l;
        C0338a c0338a = c0629f.f6562b;
        if (c0338a == null || !c0338a.f4719a || G.a.d(i, 255) != c0338a.f4722d) {
            return i;
        }
        float fMin = (c0338a.f4723e <= 0.0f || f6 <= 0.0f) ? 0.0f : Math.min(((((float) Math.log1p(f6 / r4)) * 4.5f) + 2.0f) / 100.0f, 1.0f);
        int iAlpha = Color.alpha(i);
        int iY = b5.a.y(G.a.d(i, 255), c0338a.f4720b, fMin);
        if (fMin > 0.0f && (i5 = c0338a.f4721c) != 0) {
            iY = G.a.b(G.a.d(i5, C0338a.f4718f), iY);
        }
        return G.a.d(iY, iAlpha);
    }

    public final void c(Canvas canvas) {
        if (this.f6585n.cardinality() > 0) {
            Log.w("g", "Compatibility shadow requested but can't be drawn for all operations in this shape.");
        }
        int i = this.f6582k.f6574o;
        Path path = this.q;
        C0619a c0619a = this.f6595z;
        if (i != 0) {
            canvas.drawPath(path, c0619a.f6521a);
        }
        for (int i5 = 0; i5 < 4; i5++) {
            t tVar = this.f6583l[i5];
            int i6 = this.f6582k.f6573n;
            Matrix matrix = t.f6647b;
            tVar.a(matrix, c0619a, i6, canvas);
            this.f6584m[i5].a(matrix, c0619a, this.f6582k.f6573n, canvas);
        }
        if (this.f6581F) {
            double d3 = 0;
            int iSin = (int) (Math.sin(Math.toRadians(d3)) * ((double) this.f6582k.f6574o));
            int iCos = (int) (Math.cos(Math.toRadians(d3)) * ((double) this.f6582k.f6574o));
            canvas.translate(-iSin, -iCos);
            canvas.drawPath(path, f6575G);
            canvas.translate(iSin, iCos);
        }
    }

    public final void d(Canvas canvas, Paint paint, Path path, k kVar, RectF rectF) {
        if (!kVar.d(rectF)) {
            canvas.drawPath(path, paint);
        } else {
            float fA = kVar.f6613f.a(rectF) * this.f6582k.i;
            canvas.drawRoundRect(rectF, fA, fA, paint);
        }
    }

    @Override // android.graphics.drawable.Drawable
    public void draw(Canvas canvas) {
        Paint paint = this.f6593x;
        paint.setColorFilter(this.f6578C);
        int alpha = paint.getAlpha();
        int i = this.f6582k.f6570k;
        paint.setAlpha(((i + (i >>> 7)) * alpha) >>> 8);
        Paint paint2 = this.f6594y;
        paint2.setColorFilter(this.f6579D);
        paint2.setStrokeWidth(this.f6582k.f6569j);
        int alpha2 = paint2.getAlpha();
        int i5 = this.f6582k.f6570k;
        paint2.setAlpha(((i5 + (i5 >>> 7)) * alpha2) >>> 8);
        boolean z5 = this.f6586o;
        Path path = this.q;
        if (z5) {
            float f6 = -(g() ? paint2.getStrokeWidth() / 2.0f : 0.0f);
            k kVar = this.f6582k.f6561a;
            j jVarE = kVar.e();
            InterfaceC0626c c0625b = kVar.f6612e;
            if (!(c0625b instanceof C0631h)) {
                c0625b = new C0625b(f6, c0625b);
            }
            jVarE.f6601e = c0625b;
            InterfaceC0626c c0625b2 = kVar.f6613f;
            if (!(c0625b2 instanceof C0631h)) {
                c0625b2 = new C0625b(f6, c0625b2);
            }
            jVarE.f6602f = c0625b2;
            InterfaceC0626c c0625b3 = kVar.f6615h;
            if (!(c0625b3 instanceof C0631h)) {
                c0625b3 = new C0625b(f6, c0625b3);
            }
            jVarE.f6604h = c0625b3;
            InterfaceC0626c c0625b4 = kVar.f6614g;
            if (!(c0625b4 instanceof C0631h)) {
                c0625b4 = new C0625b(f6, c0625b4);
            }
            jVarE.f6603g = c0625b4;
            k kVarA = jVarE.a();
            this.f6592w = kVarA;
            float f7 = this.f6582k.i;
            RectF rectF = this.f6589t;
            rectF.set(f());
            float strokeWidth = g() ? paint2.getStrokeWidth() / 2.0f : 0.0f;
            rectF.inset(strokeWidth, strokeWidth);
            this.f6577B.a(kVarA, f7, rectF, null, this.f6587r);
            a(f(), path);
            this.f6586o = false;
        }
        C0629f c0629f = this.f6582k;
        c0629f.getClass();
        if (c0629f.f6573n > 0) {
            int i6 = Build.VERSION.SDK_INT;
            if (!this.f6582k.f6561a.d(f()) && !path.isConvex() && i6 < 29) {
                canvas.save();
                double d3 = 0;
                canvas.translate((int) (Math.sin(Math.toRadians(d3)) * ((double) this.f6582k.f6574o)), (int) (Math.cos(Math.toRadians(d3)) * ((double) this.f6582k.f6574o)));
                if (this.f6581F) {
                    RectF rectF2 = this.f6580E;
                    int iWidth = (int) (rectF2.width() - getBounds().width());
                    int iHeight = (int) (rectF2.height() - getBounds().height());
                    if (iWidth < 0 || iHeight < 0) {
                        throw new IllegalStateException("Invalid shadow bounds. Check that the treatments result in a valid path.");
                    }
                    Bitmap bitmapCreateBitmap = Bitmap.createBitmap((this.f6582k.f6573n * 2) + ((int) rectF2.width()) + iWidth, (this.f6582k.f6573n * 2) + ((int) rectF2.height()) + iHeight, Bitmap.Config.ARGB_8888);
                    Canvas canvas2 = new Canvas(bitmapCreateBitmap);
                    float f8 = (getBounds().left - this.f6582k.f6573n) - iWidth;
                    float f9 = (getBounds().top - this.f6582k.f6573n) - iHeight;
                    canvas2.translate(-f8, -f9);
                    c(canvas2);
                    canvas.drawBitmap(bitmapCreateBitmap, f8, f9, (Paint) null);
                    bitmapCreateBitmap.recycle();
                    canvas.restore();
                } else {
                    c(canvas);
                    canvas.restore();
                }
            }
        }
        C0629f c0629f2 = this.f6582k;
        Paint.Style style = c0629f2.p;
        if (style == Paint.Style.FILL_AND_STROKE || style == Paint.Style.FILL) {
            d(canvas, paint, path, c0629f2.f6561a, f());
        }
        if (g()) {
            e(canvas);
        }
        paint.setAlpha(alpha);
        paint2.setAlpha(alpha2);
    }

    public void e(Canvas canvas) {
        Paint paint = this.f6594y;
        Path path = this.f6587r;
        k kVar = this.f6592w;
        RectF rectF = this.f6589t;
        rectF.set(f());
        float strokeWidth = g() ? paint.getStrokeWidth() / 2.0f : 0.0f;
        rectF.inset(strokeWidth, strokeWidth);
        d(canvas, paint, path, kVar, rectF);
    }

    public final RectF f() {
        RectF rectF = this.f6588s;
        rectF.set(getBounds());
        return rectF;
    }

    public final boolean g() {
        Paint.Style style = this.f6582k.p;
        return (style == Paint.Style.FILL_AND_STROKE || style == Paint.Style.STROKE) && this.f6594y.getStrokeWidth() > 0.0f;
    }

    @Override // android.graphics.drawable.Drawable
    public int getAlpha() {
        return this.f6582k.f6570k;
    }

    @Override // android.graphics.drawable.Drawable
    public final Drawable.ConstantState getConstantState() {
        return this.f6582k;
    }

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

    @Override // android.graphics.drawable.Drawable
    public void getOutline(Outline outline) {
        this.f6582k.getClass();
        if (this.f6582k.f6561a.d(f())) {
            outline.setRoundRect(getBounds(), this.f6582k.f6561a.f6612e.a(f()) * this.f6582k.i);
            return;
        }
        RectF rectFF = f();
        Path path = this.q;
        a(rectFF, path);
        int i = Build.VERSION.SDK_INT;
        if (i >= 30) {
            outline.setPath(path);
            return;
        }
        if (i >= 29) {
            try {
                outline.setConvexPath(path);
            } catch (IllegalArgumentException unused) {
            }
        } else if (path.isConvex()) {
            outline.setConvexPath(path);
        }
    }

    @Override // android.graphics.drawable.Drawable
    public final boolean getPadding(Rect rect) {
        Rect rect2 = this.f6582k.f6567g;
        if (rect2 == null) {
            return super.getPadding(rect);
        }
        rect.set(rect2);
        return true;
    }

    @Override // android.graphics.drawable.Drawable
    public final Region getTransparentRegion() {
        Rect bounds = getBounds();
        Region region = this.f6590u;
        region.set(bounds);
        RectF rectFF = f();
        Path path = this.q;
        a(rectFF, path);
        Region region2 = this.f6591v;
        region2.setPath(path, region);
        region.op(region2, Region.Op.DIFFERENCE);
        return region;
    }

    public final void h(Context context) {
        this.f6582k.f6562b = new C0338a(context);
        m();
    }

    public final void i(float f6) {
        C0629f c0629f = this.f6582k;
        if (c0629f.f6572m != f6) {
            c0629f.f6572m = f6;
            m();
        }
    }

    @Override // android.graphics.drawable.Drawable
    public final void invalidateSelf() {
        this.f6586o = true;
        super.invalidateSelf();
    }

    @Override // android.graphics.drawable.Drawable
    public boolean isStateful() {
        if (super.isStateful()) {
            return true;
        }
        ColorStateList colorStateList = this.f6582k.f6565e;
        if (colorStateList != null && colorStateList.isStateful()) {
            return true;
        }
        this.f6582k.getClass();
        ColorStateList colorStateList2 = this.f6582k.f6564d;
        if (colorStateList2 != null && colorStateList2.isStateful()) {
            return true;
        }
        ColorStateList colorStateList3 = this.f6582k.f6563c;
        return colorStateList3 != null && colorStateList3.isStateful();
    }

    public final void j(ColorStateList colorStateList) {
        C0629f c0629f = this.f6582k;
        if (c0629f.f6563c != colorStateList) {
            c0629f.f6563c = colorStateList;
            onStateChange(getState());
        }
    }

    public final boolean k(int[] iArr) {
        boolean z5;
        Paint paint;
        int color;
        int colorForState;
        Paint paint2;
        int color2;
        int colorForState2;
        if (this.f6582k.f6563c == null || color2 == (colorForState2 = this.f6582k.f6563c.getColorForState(iArr, (color2 = (paint2 = this.f6593x).getColor())))) {
            z5 = false;
        } else {
            paint2.setColor(colorForState2);
            z5 = true;
        }
        if (this.f6582k.f6564d == null || color == (colorForState = this.f6582k.f6564d.getColorForState(iArr, (color = (paint = this.f6594y).getColor())))) {
            return z5;
        }
        paint.setColor(colorForState);
        return true;
    }

    public final boolean l() {
        PorterDuffColorFilter porterDuffColorFilter;
        PorterDuffColorFilter porterDuffColorFilter2 = this.f6578C;
        PorterDuffColorFilter porterDuffColorFilter3 = this.f6579D;
        C0629f c0629f = this.f6582k;
        ColorStateList colorStateList = c0629f.f6565e;
        PorterDuff.Mode mode = c0629f.f6566f;
        Paint paint = this.f6593x;
        if (colorStateList == null || mode == null) {
            int color = paint.getColor();
            int iB = b(color);
            porterDuffColorFilter = iB != color ? new PorterDuffColorFilter(iB, PorterDuff.Mode.SRC_IN) : null;
        } else {
            porterDuffColorFilter = new PorterDuffColorFilter(b(colorStateList.getColorForState(getState(), 0)), mode);
        }
        this.f6578C = porterDuffColorFilter;
        this.f6582k.getClass();
        this.f6579D = null;
        this.f6582k.getClass();
        return (Objects.equals(porterDuffColorFilter2, this.f6578C) && Objects.equals(porterDuffColorFilter3, this.f6579D)) ? false : true;
    }

    public final void m() {
        C0629f c0629f = this.f6582k;
        float f6 = c0629f.f6572m + 0.0f;
        c0629f.f6573n = (int) Math.ceil(0.75f * f6);
        this.f6582k.f6574o = (int) Math.ceil(f6 * 0.25f);
        l();
        super.invalidateSelf();
    }

    @Override // android.graphics.drawable.Drawable
    public Drawable mutate() {
        this.f6582k = new C0629f(this.f6582k);
        return this;
    }

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

    @Override // android.graphics.drawable.Drawable
    public boolean onStateChange(int[] iArr) {
        boolean z5 = k(iArr) || l();
        if (z5) {
            invalidateSelf();
        }
        return z5;
    }

    @Override // android.graphics.drawable.Drawable
    public void setAlpha(int i) {
        C0629f c0629f = this.f6582k;
        if (c0629f.f6570k != i) {
            c0629f.f6570k = i;
            super.invalidateSelf();
        }
    }

    @Override // android.graphics.drawable.Drawable
    public void setColorFilter(ColorFilter colorFilter) {
        this.f6582k.getClass();
        super.invalidateSelf();
    }

    @Override // i2.v
    public final void setShapeAppearanceModel(k kVar) {
        this.f6582k.f6561a = kVar;
        invalidateSelf();
    }

    @Override // android.graphics.drawable.Drawable
    public final void setTint(int i) {
        setTintList(ColorStateList.valueOf(i));
    }

    @Override // android.graphics.drawable.Drawable
    public void setTintList(ColorStateList colorStateList) {
        this.f6582k.f6565e = colorStateList;
        l();
        super.invalidateSelf();
    }

    @Override // android.graphics.drawable.Drawable
    public void setTintMode(PorterDuff.Mode mode) {
        C0629f c0629f = this.f6582k;
        if (c0629f.f6566f != mode) {
            c0629f.f6566f = mode;
            l();
            super.invalidateSelf();
        }
    }

    public C0630g(Context context, AttributeSet attributeSet, int i, int i5) {
        this(k.b(context, attributeSet, i, i5).a());
    }

    public C0630g(k kVar) {
        this(new C0629f(kVar));
    }

    public C0630g(C0629f c0629f) {
        m mVar;
        this.f6583l = new t[4];
        this.f6584m = new t[4];
        this.f6585n = new BitSet(8);
        this.p = new Matrix();
        this.q = new Path();
        this.f6587r = new Path();
        this.f6588s = new RectF();
        this.f6589t = new RectF();
        this.f6590u = new Region();
        this.f6591v = new Region();
        Paint paint = new Paint(1);
        this.f6593x = paint;
        Paint paint2 = new Paint(1);
        this.f6594y = paint2;
        this.f6595z = new C0619a();
        if (Looper.getMainLooper().getThread() == Thread.currentThread()) {
            mVar = l.f6619a;
        } else {
            mVar = new m();
        }
        this.f6577B = mVar;
        this.f6580E = new RectF();
        this.f6581F = true;
        this.f6582k = c0629f;
        paint2.setStyle(Paint.Style.STROKE);
        paint.setStyle(Paint.Style.FILL);
        l();
        k(getState());
        this.f6576A = new S.g(this);
    }
}
