package v2;

import N1.C0222x;
import android.animation.ValueAnimator;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.LinearGradient;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.RadialGradient;
import android.graphics.Rect;
import android.graphics.Shader;
import android.graphics.drawable.Drawable;
import d5.AbstractC0844a;

/* JADX INFO: loaded from: classes.dex */
public final class d extends Drawable {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final C0222x f18090a = new C0222x(2, this);

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

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final Rect f18092c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final Matrix f18093d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public ValueAnimator f18094e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public C1673c f18095f;

    public d() {
        Paint paint = new Paint();
        this.f18091b = paint;
        this.f18092c = new Rect();
        this.f18093d = new Matrix();
        paint.setAntiAlias(true);
    }

    public final void a() {
        C1673c c1673c;
        ValueAnimator valueAnimator = this.f18094e;
        if (valueAnimator == null || valueAnimator.isStarted() || (c1673c = this.f18095f) == null || !c1673c.f18084o || getCallback() == null) {
            return;
        }
        this.f18094e.start();
    }

    public final void b() {
        C1673c c1673c;
        Shader radialGradient;
        Rect bounds = getBounds();
        int iWidth = bounds.width();
        int iHeight = bounds.height();
        if (iWidth == 0 || iHeight == 0 || (c1673c = this.f18095f) == null) {
            return;
        }
        int iRound = c1673c.f18077g;
        if (iRound <= 0) {
            iRound = Math.round(c1673c.i * iWidth);
        }
        C1673c c1673c2 = this.f18095f;
        int iRound2 = c1673c2.f18078h;
        if (iRound2 <= 0) {
            iRound2 = Math.round(c1673c2.f18079j * iHeight);
        }
        C1673c c1673c3 = this.f18095f;
        boolean z8 = true;
        if (c1673c3.f18076f != 1) {
            int i = c1673c3.f18073c;
            if (i != 1 && i != 3) {
                z8 = false;
            }
            if (z8) {
                iRound = 0;
            }
            if (!z8) {
                iRound2 = 0;
            }
            C1673c c1673c4 = this.f18095f;
            radialGradient = new LinearGradient(0.0f, 0.0f, iRound, iRound2, c1673c4.f18072b, c1673c4.f18071a, Shader.TileMode.CLAMP);
        } else {
            float fMax = (float) (((double) Math.max(iRound, iRound2)) / Math.sqrt(2.0d));
            C1673c c1673c5 = this.f18095f;
            radialGradient = new RadialGradient(iRound / 2.0f, iRound2 / 2.0f, fMax, c1673c5.f18072b, c1673c5.f18071a, Shader.TileMode.CLAMP);
        }
        this.f18091b.setShader(radialGradient);
    }

    @Override // android.graphics.drawable.Drawable
    public final void draw(Canvas canvas) {
        float f3;
        float f7;
        if (this.f18095f != null) {
            Paint paint = this.f18091b;
            if (paint.getShader() == null) {
                return;
            }
            float fTan = (float) Math.tan(Math.toRadians(this.f18095f.f18082m));
            Rect rect = this.f18092c;
            float fWidth = (rect.width() * fTan) + rect.height();
            float fHeight = (fTan * rect.height()) + rect.width();
            ValueAnimator valueAnimator = this.f18094e;
            float f8 = 0.0f;
            float animatedFraction = valueAnimator != null ? valueAnimator.getAnimatedFraction() : 0.0f;
            int i = this.f18095f.f18073c;
            if (i != 1) {
                if (i == 2) {
                    f7 = AbstractC0844a.f(-fHeight, fHeight, animatedFraction, fHeight);
                } else if (i != 3) {
                    float f9 = -fHeight;
                    f7 = AbstractC0844a.f(fHeight, f9, animatedFraction, f9);
                } else {
                    f3 = AbstractC0844a.f(-fWidth, fWidth, animatedFraction, fWidth);
                }
                f8 = f7;
                f3 = 0.0f;
            } else {
                float f10 = -fWidth;
                f3 = AbstractC0844a.f(fWidth, f10, animatedFraction, f10);
            }
            Matrix matrix = this.f18093d;
            matrix.reset();
            matrix.setRotate(this.f18095f.f18082m, rect.width() / 2.0f, rect.height() / 2.0f);
            matrix.postTranslate(f8, f3);
            paint.getShader().setLocalMatrix(matrix);
            canvas.drawRect(rect, paint);
        }
    }

    @Override // android.graphics.drawable.Drawable
    public final int getOpacity() {
        C1673c c1673c = this.f18095f;
        if (c1673c != null) {
            return (c1673c.f18083n || c1673c.f18085p) ? -3 : -1;
        }
        return -1;
    }

    @Override // android.graphics.drawable.Drawable
    public final void onBoundsChange(Rect rect) {
        super.onBoundsChange(rect);
        this.f18092c.set(0, 0, rect.width(), rect.height());
        b();
        a();
    }

    @Override // android.graphics.drawable.Drawable
    public final void setAlpha(int i) {
    }

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