package r6;

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.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.RadialGradient;
import android.graphics.Rect;
import android.graphics.Shader;
import android.graphics.drawable.Drawable;
import androidx.annotation.Nullable;
import com.google.android.gms.measurement.internal.u1;

/* JADX INFO: loaded from: classes2.dex */
public final class e extends Drawable {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final d f32505a = new d(this, 0);

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

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

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

    @Nullable
    private c mShimmer;

    @Nullable
    private ValueAnimator mValueAnimator;

    public e() {
        Paint paint = new Paint();
        this.f32506b = paint;
        this.f32507c = new Rect();
        this.f32508d = new Matrix();
        paint.setAntiAlias(true);
    }

    public final void a() {
        c cVar;
        ValueAnimator valueAnimator = this.mValueAnimator;
        if (valueAnimator == null || valueAnimator.isStarted() || (cVar = this.mShimmer) == null || !cVar.f32497o || getCallback() == null) {
            return;
        }
        this.mValueAnimator.start();
    }

    public final void b() {
        ValueAnimator valueAnimator = this.mValueAnimator;
        if (valueAnimator == null || valueAnimator == null || !valueAnimator.isStarted()) {
            return;
        }
        this.mValueAnimator.cancel();
    }

    public final void c() {
        c cVar;
        Shader radialGradient;
        Rect bounds = getBounds();
        int iWidth = bounds.width();
        int iHeight = bounds.height();
        if (iWidth == 0 || iHeight == 0 || (cVar = this.mShimmer) == null) {
            return;
        }
        int iRound = cVar.f32489g;
        if (iRound <= 0) {
            iRound = Math.round(cVar.f32491i * iWidth);
        }
        c cVar2 = this.mShimmer;
        int iRound2 = cVar2.f32490h;
        if (iRound2 <= 0) {
            iRound2 = Math.round(cVar2.f32492j * iHeight);
        }
        c cVar3 = this.mShimmer;
        boolean z10 = true;
        if (cVar3.f32488f != 1) {
            int i10 = cVar3.f32485c;
            if (i10 != 1 && i10 != 3) {
                z10 = false;
            }
            if (z10) {
                iRound = 0;
            }
            if (!z10) {
                iRound2 = 0;
            }
            c cVar4 = this.mShimmer;
            radialGradient = new LinearGradient(0.0f, 0.0f, iRound, iRound2, cVar4.f32484b, cVar4.f32483a, Shader.TileMode.CLAMP);
        } else {
            float f10 = iRound2 / 2.0f;
            float fMax = (float) (((double) Math.max(iRound, iRound2)) / Math.sqrt(2.0d));
            c cVar5 = this.mShimmer;
            radialGradient = new RadialGradient(iRound / 2.0f, f10, fMax, cVar5.f32484b, cVar5.f32483a, Shader.TileMode.CLAMP);
        }
        this.f32506b.setShader(radialGradient);
    }

    @Override // android.graphics.drawable.Drawable
    public final void draw(Canvas canvas) {
        float fA;
        float fA2;
        if (this.mShimmer != null) {
            Paint paint = this.f32506b;
            if (paint.getShader() == null) {
                return;
            }
            float fTan = (float) Math.tan(Math.toRadians(this.mShimmer.f32495m));
            Rect rect = this.f32507c;
            float fWidth = (rect.width() * fTan) + rect.height();
            float fHeight = (fTan * rect.height()) + rect.width();
            ValueAnimator valueAnimator = this.mValueAnimator;
            float f10 = 0.0f;
            float animatedFraction = valueAnimator != null ? valueAnimator.getAnimatedFraction() : 0.0f;
            int i10 = this.mShimmer.f32485c;
            if (i10 != 1) {
                if (i10 == 2) {
                    fA2 = u1.a(-fHeight, fHeight, animatedFraction, fHeight);
                } else if (i10 != 3) {
                    float f11 = -fHeight;
                    fA2 = u1.a(fHeight, f11, animatedFraction, f11);
                } else {
                    fA = u1.a(-fWidth, fWidth, animatedFraction, fWidth);
                }
                f10 = fA2;
                fA = 0.0f;
            } else {
                float f12 = -fWidth;
                fA = u1.a(fWidth, f12, animatedFraction, f12);
            }
            Matrix matrix = this.f32508d;
            matrix.reset();
            matrix.setRotate(this.mShimmer.f32495m, rect.width() / 2.0f, rect.height() / 2.0f);
            matrix.postTranslate(f10, fA);
            paint.getShader().setLocalMatrix(matrix);
            canvas.drawRect(rect, paint);
        }
    }

    @Override // android.graphics.drawable.Drawable
    public final int getOpacity() {
        c cVar = this.mShimmer;
        return (cVar == null || !(cVar.f32496n || cVar.f32498p)) ? -1 : -3;
    }

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

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

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

    public void setShimmer(@Nullable c cVar) {
        boolean zIsStarted;
        this.mShimmer = cVar;
        if (cVar != null) {
            this.f32506b.setXfermode(new PorterDuffXfermode(this.mShimmer.f32498p ? PorterDuff.Mode.DST_IN : PorterDuff.Mode.SRC_IN));
        }
        c();
        if (this.mShimmer != null) {
            ValueAnimator valueAnimator = this.mValueAnimator;
            if (valueAnimator != null) {
                zIsStarted = valueAnimator.isStarted();
                this.mValueAnimator.cancel();
                this.mValueAnimator.removeAllUpdateListeners();
            } else {
                zIsStarted = false;
            }
            c cVar2 = this.mShimmer;
            ValueAnimator valueAnimatorOfFloat = ValueAnimator.ofFloat(0.0f, (cVar2.f32502t / cVar2.f32501s) + 1.0f);
            this.mValueAnimator = valueAnimatorOfFloat;
            valueAnimatorOfFloat.setRepeatMode(this.mShimmer.f32500r);
            this.mValueAnimator.setRepeatCount(this.mShimmer.f32499q);
            ValueAnimator valueAnimator2 = this.mValueAnimator;
            c cVar3 = this.mShimmer;
            valueAnimator2.setDuration(cVar3.f32501s + cVar3.f32502t);
            this.mValueAnimator.addUpdateListener(this.f32505a);
            if (zIsStarted) {
                this.mValueAnimator.start();
            }
        }
        invalidateSelf();
    }
}
