package o;

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 java.util.BitSet;
import java.util.Objects;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* renamed from: o.eO, reason: case insensitive filesystem */
/* loaded from: classes.dex */
public class C1092eO extends Drawable implements InterfaceC0693a80 {
    public static final Paint H;
    public final J70 A;
    public final C0247Jn B;
    public final P70 C;
    public PorterDuffColorFilter D;
    public PorterDuffColorFilter E;
    public final RectF F;
    public final boolean G;
    public C0997dO l;
    public final X70[] m;
    public final X70[] n;

    /* renamed from: o, reason: collision with root package name */
    public final BitSet f508o;
    public boolean p;
    public final Matrix q;
    public final Path r;
    public final Path s;
    public final RectF t;
    public final RectF u;
    public final Region v;
    public final Region w;
    public N70 x;
    public final Paint y;
    public final Paint z;

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

    public C1092eO() {
        this(new N70());
    }

    public final void a(RectF rectF, Path path) {
        C0997dO c0997dO = this.l;
        this.C.a(c0997dO.a, c0997dO.i, rectF, this.B, path);
        if (this.l.h != 1.0f) {
            Matrix matrix = this.q;
            matrix.reset();
            float f = this.l.h;
            matrix.setScale(f, f, rectF.width() / 2.0f, rectF.height() / 2.0f);
            path.transform(matrix);
        }
        path.computeBounds(this.F, true);
    }

    public final int b(int i) {
        int i2;
        C0997dO c0997dO = this.l;
        float f = c0997dO.m + 0.0f + c0997dO.l;
        C1338gv c1338gv = c0997dO.b;
        if (c1338gv == null || !c1338gv.a || AbstractC0501Ti.d(i, 255) != c1338gv.d) {
            return i;
        }
        float fMin = (c1338gv.e <= 0.0f || f <= 0.0f) ? 0.0f : Math.min(((((float) Math.log1p(f / r4)) * 4.5f) + 2.0f) / 100.0f, 1.0f);
        int iAlpha = Color.alpha(i);
        int iD = AbstractC1692kh0.D(fMin, AbstractC0501Ti.d(i, 255), c1338gv.b);
        if (fMin > 0.0f && (i2 = c1338gv.c) != 0) {
            iD = AbstractC0501Ti.b(AbstractC0501Ti.d(i2, C1338gv.f), iD);
        }
        return AbstractC0501Ti.d(iD, iAlpha);
    }

    public final void c(Canvas canvas) {
        this.f508o.cardinality();
        int i = this.l.f492o;
        Path path = this.r;
        J70 j70 = this.A;
        if (i != 0) {
            canvas.drawPath(path, j70.a);
        }
        for (int i2 = 0; i2 < 4; i2++) {
            X70 x70 = this.m[i2];
            int i3 = this.l.n;
            Matrix matrix = X70.b;
            x70.a(matrix, j70, i3, canvas);
            this.n[i2].a(matrix, j70, this.l.n, canvas);
        }
        if (this.G) {
            double d = 0;
            int iSin = (int) (Math.sin(Math.toRadians(d)) * this.l.f492o);
            int iCos = (int) (Math.cos(Math.toRadians(d)) * this.l.f492o);
            canvas.translate(-iSin, -iCos);
            canvas.drawPath(path, H);
            canvas.translate(iSin, iCos);
        }
    }

    public final void d(Canvas canvas, Paint paint, Path path, N70 n70, RectF rectF) {
        if (!n70.d(rectF)) {
            canvas.drawPath(path, paint);
        } else {
            float fA = n70.f.a(rectF) * this.l.i;
            canvas.drawRoundRect(rectF, fA, fA, paint);
        }
    }

    @Override // android.graphics.drawable.Drawable
    public void draw(Canvas canvas) {
        PorterDuffColorFilter porterDuffColorFilter = this.D;
        Paint paint = this.y;
        paint.setColorFilter(porterDuffColorFilter);
        int alpha = paint.getAlpha();
        int i = this.l.k;
        paint.setAlpha(((i + (i >>> 7)) * alpha) >>> 8);
        PorterDuffColorFilter porterDuffColorFilter2 = this.E;
        Paint paint2 = this.z;
        paint2.setColorFilter(porterDuffColorFilter2);
        paint2.setStrokeWidth(this.l.j);
        int alpha2 = paint2.getAlpha();
        int i2 = this.l.k;
        paint2.setAlpha(((i2 + (i2 >>> 7)) * alpha2) >>> 8);
        boolean z = this.p;
        Path path = this.r;
        if (z) {
            float f = -(g() ? paint2.getStrokeWidth() / 2.0f : 0.0f);
            N70 n70 = this.l.a;
            M70 m70E = n70.e();
            InterfaceC2273qn v1 = n70.e;
            if (!(v1 instanceof O10)) {
                v1 = new V1(f, v1);
            }
            m70E.e = v1;
            InterfaceC2273qn v12 = n70.f;
            if (!(v12 instanceof O10)) {
                v12 = new V1(f, v12);
            }
            m70E.f = v12;
            InterfaceC2273qn v13 = n70.h;
            if (!(v13 instanceof O10)) {
                v13 = new V1(f, v13);
            }
            m70E.h = v13;
            InterfaceC2273qn v14 = n70.g;
            if (!(v14 instanceof O10)) {
                v14 = new V1(f, v14);
            }
            m70E.g = v14;
            N70 n70A = m70E.a();
            this.x = n70A;
            float f2 = this.l.i;
            RectF rectFF = f();
            RectF rectF = this.u;
            rectF.set(rectFF);
            float strokeWidth = g() ? paint2.getStrokeWidth() / 2.0f : 0.0f;
            rectF.inset(strokeWidth, strokeWidth);
            this.C.a(n70A, f2, rectF, null, this.s);
            a(f(), path);
            this.p = false;
        }
        C0997dO c0997dO = this.l;
        c0997dO.getClass();
        if (c0997dO.n > 0) {
            int i3 = Build.VERSION.SDK_INT;
            if (!this.l.a.d(f()) && !path.isConvex() && i3 < 29) {
                canvas.save();
                double d = 0;
                canvas.translate((int) (Math.sin(Math.toRadians(d)) * this.l.f492o), (int) (Math.cos(Math.toRadians(d)) * this.l.f492o));
                if (this.G) {
                    RectF rectF2 = this.F;
                    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.l.n * 2) + ((int) rectF2.width()) + iWidth, (this.l.n * 2) + ((int) rectF2.height()) + iHeight, Bitmap.Config.ARGB_8888);
                    Canvas canvas2 = new Canvas(bitmapCreateBitmap);
                    float f3 = (getBounds().left - this.l.n) - iWidth;
                    float f4 = (getBounds().top - this.l.n) - iHeight;
                    canvas2.translate(-f3, -f4);
                    c(canvas2);
                    canvas.drawBitmap(bitmapCreateBitmap, f3, f4, (Paint) null);
                    bitmapCreateBitmap.recycle();
                    canvas.restore();
                } else {
                    c(canvas);
                    canvas.restore();
                }
            }
        }
        C0997dO c0997dO2 = this.l;
        Paint.Style style = c0997dO2.p;
        if (style == Paint.Style.FILL_AND_STROKE || style == Paint.Style.FILL) {
            d(canvas, paint, path, c0997dO2.a, f());
        }
        if (g()) {
            e(canvas);
        }
        paint.setAlpha(alpha);
        paint2.setAlpha(alpha2);
    }

    public void e(Canvas canvas) {
        N70 n70 = this.x;
        RectF rectFF = f();
        RectF rectF = this.u;
        rectF.set(rectFF);
        boolean zG = g();
        Paint paint = this.z;
        float strokeWidth = zG ? paint.getStrokeWidth() / 2.0f : 0.0f;
        rectF.inset(strokeWidth, strokeWidth);
        d(canvas, paint, this.s, n70, rectF);
    }

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

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

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

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

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

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

    @Override // android.graphics.drawable.Drawable
    public final boolean getPadding(Rect rect) {
        Rect rect2 = this.l.g;
        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.v;
        region.set(bounds);
        RectF rectFF = f();
        Path path = this.r;
        a(rectFF, path);
        Region region2 = this.w;
        region2.setPath(path, region);
        region.op(region2, Region.Op.DIFFERENCE);
        return region;
    }

    public final void h(Context context) {
        this.l.b = new C1338gv(context);
        m();
    }

    public final void i(float f) {
        C0997dO c0997dO = this.l;
        if (c0997dO.m != f) {
            c0997dO.m = f;
            m();
        }
    }

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

    @Override // android.graphics.drawable.Drawable
    public boolean isStateful() {
        if (super.isStateful()) {
            return true;
        }
        ColorStateList colorStateList = this.l.e;
        if (colorStateList != null && colorStateList.isStateful()) {
            return true;
        }
        this.l.getClass();
        ColorStateList colorStateList2 = this.l.d;
        if (colorStateList2 != null && colorStateList2.isStateful()) {
            return true;
        }
        ColorStateList colorStateList3 = this.l.c;
        return colorStateList3 != null && colorStateList3.isStateful();
    }

    public final void j(ColorStateList colorStateList) {
        C0997dO c0997dO = this.l;
        if (c0997dO.c != colorStateList) {
            c0997dO.c = colorStateList;
            onStateChange(getState());
        }
    }

    public final boolean k(int[] iArr) {
        boolean z;
        Paint paint;
        int color;
        int colorForState;
        Paint paint2;
        int color2;
        int colorForState2;
        if (this.l.c == null || color2 == (colorForState2 = this.l.c.getColorForState(iArr, (color2 = (paint2 = this.y).getColor())))) {
            z = false;
        } else {
            paint2.setColor(colorForState2);
            z = true;
        }
        if (this.l.d == null || color == (colorForState = this.l.d.getColorForState(iArr, (color = (paint = this.z).getColor())))) {
            return z;
        }
        paint.setColor(colorForState);
        return true;
    }

    public final boolean l() {
        PorterDuffColorFilter porterDuffColorFilter;
        PorterDuffColorFilter porterDuffColorFilter2 = this.D;
        PorterDuffColorFilter porterDuffColorFilter3 = this.E;
        C0997dO c0997dO = this.l;
        ColorStateList colorStateList = c0997dO.e;
        PorterDuff.Mode mode = c0997dO.f;
        if (colorStateList == null || mode == null) {
            int color = this.y.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.D = porterDuffColorFilter;
        this.l.getClass();
        this.E = null;
        this.l.getClass();
        return (Objects.equals(porterDuffColorFilter2, this.D) && Objects.equals(porterDuffColorFilter3, this.E)) ? false : true;
    }

    public final void m() {
        C0997dO c0997dO = this.l;
        float f = c0997dO.m + 0.0f;
        c0997dO.n = (int) Math.ceil(0.75f * f);
        this.l.f492o = (int) Math.ceil(f * 0.25f);
        l();
        super.invalidateSelf();
    }

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

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

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

    @Override // android.graphics.drawable.Drawable
    public void setAlpha(int i) {
        C0997dO c0997dO = this.l;
        if (c0997dO.k != i) {
            c0997dO.k = i;
            super.invalidateSelf();
        }
    }

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

    @Override // o.InterfaceC0693a80
    public final void setShapeAppearanceModel(N70 n70) {
        this.l.a = n70;
        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.l.e = colorStateList;
        l();
        super.invalidateSelf();
    }

    @Override // android.graphics.drawable.Drawable
    public void setTintMode(PorterDuff.Mode mode) {
        C0997dO c0997dO = this.l;
        if (c0997dO.f != mode) {
            c0997dO.f = mode;
            l();
            super.invalidateSelf();
        }
    }

    public C1092eO(Context context, AttributeSet attributeSet, int i, int i2) {
        this(N70.b(context, attributeSet, i, i2).a());
    }

    public C1092eO(N70 n70) {
        this(new C0997dO(n70));
    }

    public C1092eO(C0997dO c0997dO) {
        P70 p70;
        this.m = new X70[4];
        this.n = new X70[4];
        this.f508o = new BitSet(8);
        this.q = new Matrix();
        this.r = new Path();
        this.s = new Path();
        this.t = new RectF();
        this.u = new RectF();
        this.v = new Region();
        this.w = new Region();
        Paint paint = new Paint(1);
        this.y = paint;
        Paint paint2 = new Paint(1);
        this.z = paint2;
        this.A = new J70();
        if (Looper.getMainLooper().getThread() == Thread.currentThread()) {
            p70 = O70.a;
        } else {
            p70 = new P70();
        }
        this.C = p70;
        this.F = new RectF();
        this.G = true;
        this.l = c0997dO;
        paint2.setStyle(Paint.Style.STROKE);
        paint.setStyle(Paint.Style.FILL);
        l();
        k(getState());
        this.B = new C0247Jn(25, this);
    }
}
