package androidx.swiperefreshlayout.widget;

import android.animation.Animator;
import android.animation.ValueAnimator;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.Animatable;
import android.graphics.drawable.Drawable;
import android.view.animation.Interpolator;
import android.view.animation.LinearInterpolator;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.firebase.perf.util.Constants;
import s3.i;

/* loaded from: classes.dex */
public class b extends Drawable implements Animatable {

    /* renamed from: v, reason: collision with root package name */
    private static final Interpolator f5677v = new LinearInterpolator();

    /* renamed from: w, reason: collision with root package name */
    private static final Interpolator f5678w = new o4.b();

    /* renamed from: x, reason: collision with root package name */
    private static final int[] f5679x = {-16777216};

    /* renamed from: p, reason: collision with root package name */
    private final c f5680p;

    /* renamed from: q, reason: collision with root package name */
    private float f5681q;

    /* renamed from: r, reason: collision with root package name */
    private Resources f5682r;

    /* renamed from: s, reason: collision with root package name */
    private Animator f5683s;

    /* renamed from: t, reason: collision with root package name */
    float f5684t;

    /* renamed from: u, reason: collision with root package name */
    boolean f5685u;

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public class a implements ValueAnimator.AnimatorUpdateListener {

        /* renamed from: a, reason: collision with root package name */
        final /* synthetic */ c f5686a;

        a(c cVar) {
            this.f5686a = cVar;
        }

        @Override // android.animation.ValueAnimator.AnimatorUpdateListener
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            float floatValue = ((Float) valueAnimator.getAnimatedValue()).floatValue();
            b.this.o(floatValue, this.f5686a);
            b.this.b(floatValue, this.f5686a, false);
            b.this.invalidateSelf();
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* renamed from: androidx.swiperefreshlayout.widget.b$b, reason: collision with other inner class name */
    /* loaded from: classes.dex */
    public class C0144b implements Animator.AnimatorListener {

        /* renamed from: a, reason: collision with root package name */
        final /* synthetic */ c f5688a;

        C0144b(c cVar) {
            this.f5688a = cVar;
        }

        @Override // android.animation.Animator.AnimatorListener
        public void onAnimationCancel(Animator animator) {
        }

        @Override // android.animation.Animator.AnimatorListener
        public void onAnimationEnd(Animator animator) {
        }

        @Override // android.animation.Animator.AnimatorListener
        public void onAnimationRepeat(Animator animator) {
            b.this.b(1.0f, this.f5688a, true);
            this.f5688a.A();
            this.f5688a.l();
            b bVar = b.this;
            if (!bVar.f5685u) {
                bVar.f5684t += 1.0f;
                return;
            }
            bVar.f5685u = false;
            animator.cancel();
            animator.setDuration(1332L);
            animator.start();
            this.f5688a.x(false);
        }

        @Override // android.animation.Animator.AnimatorListener
        public void onAnimationStart(Animator animator) {
            b.this.f5684t = BitmapDescriptorFactory.HUE_RED;
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* loaded from: classes.dex */
    public static class c {

        /* renamed from: a, reason: collision with root package name */
        final RectF f5690a = new RectF();

        /* renamed from: b, reason: collision with root package name */
        final Paint f5691b;

        /* renamed from: c, reason: collision with root package name */
        final Paint f5692c;

        /* renamed from: d, reason: collision with root package name */
        final Paint f5693d;

        /* renamed from: e, reason: collision with root package name */
        float f5694e;

        /* renamed from: f, reason: collision with root package name */
        float f5695f;

        /* renamed from: g, reason: collision with root package name */
        float f5696g;

        /* renamed from: h, reason: collision with root package name */
        float f5697h;

        /* renamed from: i, reason: collision with root package name */
        int[] f5698i;

        /* renamed from: j, reason: collision with root package name */
        int f5699j;

        /* renamed from: k, reason: collision with root package name */
        float f5700k;

        /* renamed from: l, reason: collision with root package name */
        float f5701l;

        /* renamed from: m, reason: collision with root package name */
        float f5702m;

        /* renamed from: n, reason: collision with root package name */
        boolean f5703n;

        /* renamed from: o, reason: collision with root package name */
        Path f5704o;

        /* renamed from: p, reason: collision with root package name */
        float f5705p;

        /* renamed from: q, reason: collision with root package name */
        float f5706q;

        /* renamed from: r, reason: collision with root package name */
        int f5707r;

        /* renamed from: s, reason: collision with root package name */
        int f5708s;

        /* renamed from: t, reason: collision with root package name */
        int f5709t;

        /* renamed from: u, reason: collision with root package name */
        int f5710u;

        c() {
            Paint paint = new Paint();
            this.f5691b = paint;
            Paint paint2 = new Paint();
            this.f5692c = paint2;
            Paint paint3 = new Paint();
            this.f5693d = paint3;
            this.f5694e = BitmapDescriptorFactory.HUE_RED;
            this.f5695f = BitmapDescriptorFactory.HUE_RED;
            this.f5696g = BitmapDescriptorFactory.HUE_RED;
            this.f5697h = 5.0f;
            this.f5705p = 1.0f;
            this.f5709t = Constants.MAX_HOST_LENGTH;
            paint.setStrokeCap(Paint.Cap.SQUARE);
            paint.setAntiAlias(true);
            paint.setStyle(Paint.Style.STROKE);
            paint2.setStyle(Paint.Style.FILL);
            paint2.setAntiAlias(true);
            paint3.setColor(0);
        }

        void A() {
            this.f5700k = this.f5694e;
            this.f5701l = this.f5695f;
            this.f5702m = this.f5696g;
        }

        void a(Canvas canvas, Rect rect) {
            RectF rectF = this.f5690a;
            float f10 = this.f5706q;
            float f11 = (this.f5697h / 2.0f) + f10;
            if (f10 <= BitmapDescriptorFactory.HUE_RED) {
                f11 = (Math.min(rect.width(), rect.height()) / 2.0f) - Math.max((this.f5707r * this.f5705p) / 2.0f, this.f5697h / 2.0f);
            }
            rectF.set(rect.centerX() - f11, rect.centerY() - f11, rect.centerX() + f11, rect.centerY() + f11);
            float f12 = this.f5694e;
            float f13 = this.f5696g;
            float f14 = (f12 + f13) * 360.0f;
            float f15 = ((this.f5695f + f13) * 360.0f) - f14;
            this.f5691b.setColor(this.f5710u);
            this.f5691b.setAlpha(this.f5709t);
            float f16 = this.f5697h / 2.0f;
            rectF.inset(f16, f16);
            canvas.drawCircle(rectF.centerX(), rectF.centerY(), rectF.width() / 2.0f, this.f5693d);
            float f17 = -f16;
            rectF.inset(f17, f17);
            canvas.drawArc(rectF, f14, f15, false, this.f5691b);
            b(canvas, f14, f15, rectF);
        }

        void b(Canvas canvas, float f10, float f11, RectF rectF) {
            if (this.f5703n) {
                Path path = this.f5704o;
                if (path == null) {
                    Path path2 = new Path();
                    this.f5704o = path2;
                    path2.setFillType(Path.FillType.EVEN_ODD);
                } else {
                    path.reset();
                }
                float min = Math.min(rectF.width(), rectF.height()) / 2.0f;
                float f12 = (this.f5707r * this.f5705p) / 2.0f;
                this.f5704o.moveTo(BitmapDescriptorFactory.HUE_RED, BitmapDescriptorFactory.HUE_RED);
                this.f5704o.lineTo(this.f5707r * this.f5705p, BitmapDescriptorFactory.HUE_RED);
                Path path3 = this.f5704o;
                float f13 = this.f5707r;
                float f14 = this.f5705p;
                path3.lineTo((f13 * f14) / 2.0f, this.f5708s * f14);
                this.f5704o.offset((min + rectF.centerX()) - f12, rectF.centerY() + (this.f5697h / 2.0f));
                this.f5704o.close();
                this.f5692c.setColor(this.f5710u);
                this.f5692c.setAlpha(this.f5709t);
                canvas.save();
                canvas.rotate(f10 + f11, rectF.centerX(), rectF.centerY());
                canvas.drawPath(this.f5704o, this.f5692c);
                canvas.restore();
            }
        }

        int c() {
            return this.f5709t;
        }

        float d() {
            return this.f5695f;
        }

        int e() {
            return this.f5698i[f()];
        }

        int f() {
            return (this.f5699j + 1) % this.f5698i.length;
        }

        float g() {
            return this.f5694e;
        }

        int h() {
            return this.f5698i[this.f5699j];
        }

        float i() {
            return this.f5701l;
        }

        float j() {
            return this.f5702m;
        }

        float k() {
            return this.f5700k;
        }

        void l() {
            t(f());
        }

        void m() {
            this.f5700k = BitmapDescriptorFactory.HUE_RED;
            this.f5701l = BitmapDescriptorFactory.HUE_RED;
            this.f5702m = BitmapDescriptorFactory.HUE_RED;
            y(BitmapDescriptorFactory.HUE_RED);
            v(BitmapDescriptorFactory.HUE_RED);
            w(BitmapDescriptorFactory.HUE_RED);
        }

        void n(int i10) {
            this.f5709t = i10;
        }

        void o(float f10, float f11) {
            this.f5707r = (int) f10;
            this.f5708s = (int) f11;
        }

        void p(float f10) {
            if (f10 != this.f5705p) {
                this.f5705p = f10;
            }
        }

        void q(float f10) {
            this.f5706q = f10;
        }

        void r(int i10) {
            this.f5710u = i10;
        }

        void s(ColorFilter colorFilter) {
            this.f5691b.setColorFilter(colorFilter);
        }

        void t(int i10) {
            this.f5699j = i10;
            this.f5710u = this.f5698i[i10];
        }

        void u(int[] iArr) {
            this.f5698i = iArr;
            t(0);
        }

        void v(float f10) {
            this.f5695f = f10;
        }

        void w(float f10) {
            this.f5696g = f10;
        }

        void x(boolean z10) {
            if (this.f5703n != z10) {
                this.f5703n = z10;
            }
        }

        void y(float f10) {
            this.f5694e = f10;
        }

        void z(float f10) {
            this.f5697h = f10;
            this.f5691b.setStrokeWidth(f10);
        }
    }

    public b(Context context) {
        this.f5682r = ((Context) i.g(context)).getResources();
        c cVar = new c();
        this.f5680p = cVar;
        cVar.u(f5679x);
        l(2.5f);
        n();
    }

    private void a(float f10, c cVar) {
        o(f10, cVar);
        float floor = (float) (Math.floor(cVar.j() / 0.8f) + 1.0d);
        cVar.y(cVar.k() + (((cVar.i() - 0.01f) - cVar.k()) * f10));
        cVar.v(cVar.i());
        cVar.w(cVar.j() + ((floor - cVar.j()) * f10));
    }

    private int c(float f10, int i10, int i11) {
        return ((((i10 >> 24) & Constants.MAX_HOST_LENGTH) + ((int) ((((i11 >> 24) & Constants.MAX_HOST_LENGTH) - r5) * f10))) << 24) | ((((i10 >> 16) & Constants.MAX_HOST_LENGTH) + ((int) ((((i11 >> 16) & Constants.MAX_HOST_LENGTH) - r0) * f10))) << 16) | ((((i10 >> 8) & Constants.MAX_HOST_LENGTH) + ((int) ((((i11 >> 8) & Constants.MAX_HOST_LENGTH) - r1) * f10))) << 8) | ((i10 & Constants.MAX_HOST_LENGTH) + ((int) (f10 * ((i11 & Constants.MAX_HOST_LENGTH) - r7))));
    }

    private void i(float f10) {
        this.f5681q = f10;
    }

    private void j(float f10, float f11, float f12, float f13) {
        c cVar = this.f5680p;
        float f14 = this.f5682r.getDisplayMetrics().density;
        cVar.z(f11 * f14);
        cVar.q(f10 * f14);
        cVar.t(0);
        cVar.o(f12 * f14, f13 * f14);
    }

    private void n() {
        c cVar = this.f5680p;
        ValueAnimator ofFloat = ValueAnimator.ofFloat(BitmapDescriptorFactory.HUE_RED, 1.0f);
        ofFloat.addUpdateListener(new a(cVar));
        ofFloat.setRepeatCount(-1);
        ofFloat.setRepeatMode(1);
        ofFloat.setInterpolator(f5677v);
        ofFloat.addListener(new C0144b(cVar));
        this.f5683s = ofFloat;
    }

    void b(float f10, c cVar, boolean z10) {
        float interpolation;
        float f11;
        if (this.f5685u) {
            a(f10, cVar);
            return;
        }
        if (f10 != 1.0f || z10) {
            float j10 = cVar.j();
            if (f10 < 0.5f) {
                interpolation = cVar.k();
                f11 = (f5678w.getInterpolation(f10 / 0.5f) * 0.79f) + 0.01f + interpolation;
            } else {
                float k10 = cVar.k() + 0.79f;
                interpolation = k10 - (((1.0f - f5678w.getInterpolation((f10 - 0.5f) / 0.5f)) * 0.79f) + 0.01f);
                f11 = k10;
            }
            float f12 = j10 + (0.20999998f * f10);
            float f13 = (f10 + this.f5684t) * 216.0f;
            cVar.y(interpolation);
            cVar.v(f11);
            cVar.w(f12);
            i(f13);
        }
    }

    public void d(boolean z10) {
        this.f5680p.x(z10);
        invalidateSelf();
    }

    @Override // android.graphics.drawable.Drawable
    public void draw(Canvas canvas) {
        Rect bounds = getBounds();
        canvas.save();
        canvas.rotate(this.f5681q, bounds.exactCenterX(), bounds.exactCenterY());
        this.f5680p.a(canvas, bounds);
        canvas.restore();
    }

    public void e(float f10) {
        this.f5680p.p(f10);
        invalidateSelf();
    }

    public void f(float f10) {
        this.f5680p.q(f10);
        invalidateSelf();
    }

    public void g(int... iArr) {
        this.f5680p.u(iArr);
        this.f5680p.t(0);
        invalidateSelf();
    }

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

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

    public void h(float f10) {
        this.f5680p.w(f10);
        invalidateSelf();
    }

    @Override // android.graphics.drawable.Animatable
    public boolean isRunning() {
        return this.f5683s.isRunning();
    }

    public void k(float f10, float f11) {
        this.f5680p.y(f10);
        this.f5680p.v(f11);
        invalidateSelf();
    }

    public void l(float f10) {
        this.f5680p.z(f10);
        invalidateSelf();
    }

    public void m(int i10) {
        if (i10 == 0) {
            j(11.0f, 3.0f, 12.0f, 6.0f);
        } else {
            j(7.5f, 2.5f, 10.0f, 5.0f);
        }
        invalidateSelf();
    }

    void o(float f10, c cVar) {
        if (f10 > 0.75f) {
            cVar.r(c((f10 - 0.75f) / 0.25f, cVar.h(), cVar.e()));
        } else {
            cVar.r(cVar.h());
        }
    }

    @Override // android.graphics.drawable.Drawable
    public void setAlpha(int i10) {
        this.f5680p.n(i10);
        invalidateSelf();
    }

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

    @Override // android.graphics.drawable.Animatable
    public void start() {
        this.f5683s.cancel();
        this.f5680p.A();
        if (this.f5680p.d() != this.f5680p.g()) {
            this.f5685u = true;
            this.f5683s.setDuration(666L);
            this.f5683s.start();
        } else {
            this.f5680p.t(0);
            this.f5680p.m();
            this.f5683s.setDuration(1332L);
            this.f5683s.start();
        }
    }

    @Override // android.graphics.drawable.Animatable
    public void stop() {
        this.f5683s.cancel();
        i(BitmapDescriptorFactory.HUE_RED);
        this.f5680p.x(false);
        this.f5680p.t(0);
        this.f5680p.m();
        invalidateSelf();
    }
}
