package xyz.stream.view.refresh.hearder;

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.View;
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
import android.view.animation.Transformation;
import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import l1.b;

/* JADX INFO: loaded from: classes3.dex */
public class MaterialProgressDrawable extends Drawable implements Animatable {
    public static final byte DEFAULT = 1;
    public static final byte LARGE = 0;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public static final LinearInterpolator f36565j = new LinearInterpolator();

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public static final b f36566k = new b();

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public static final int[] f36567l = {-16777216};

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final Ring f36568a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public float f36569b;

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

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

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

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

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public float f36574g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public boolean f36575h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public boolean f36576i;

    @Retention(RetentionPolicy.SOURCE)
    public @interface ProgressDrawableSize {
    }

    public static class Ring {

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

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

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

        /* JADX INFO: renamed from: d, reason: collision with root package name */
        public float f36584d;

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

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

        /* JADX INFO: renamed from: g, reason: collision with root package name */
        public float f36587g;

        /* JADX INFO: renamed from: h, reason: collision with root package name */
        public float f36588h;

        /* JADX INFO: renamed from: i, reason: collision with root package name */
        public int[] f36589i;

        /* JADX INFO: renamed from: j, reason: collision with root package name */
        public int f36590j;

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

        /* JADX INFO: renamed from: l, reason: collision with root package name */
        public float f36592l;

        /* JADX INFO: renamed from: m, reason: collision with root package name */
        public float f36593m;

        /* JADX INFO: renamed from: n, reason: collision with root package name */
        public boolean f36594n;

        /* JADX INFO: renamed from: o, reason: collision with root package name */
        public Path f36595o;

        /* JADX INFO: renamed from: p, reason: collision with root package name */
        public float f36596p;

        /* JADX INFO: renamed from: q, reason: collision with root package name */
        public double f36597q;

        /* JADX INFO: renamed from: r, reason: collision with root package name */
        public int f36598r;

        /* JADX INFO: renamed from: s, reason: collision with root package name */
        public int f36599s;

        /* JADX INFO: renamed from: t, reason: collision with root package name */
        public int f36600t;

        public Ring() {
            Paint paint = new Paint();
            this.f36582b = paint;
            Paint paint2 = new Paint();
            this.f36583c = paint2;
            this.f36584d = 0.0f;
            this.f36585e = 0.0f;
            this.f36586f = 0.0f;
            this.f36587g = 5.0f;
            this.f36588h = 2.5f;
            paint.setStrokeCap(Paint.Cap.SQUARE);
            paint.setAntiAlias(true);
            paint.setStyle(Paint.Style.STROKE);
            paint2.setStyle(Paint.Style.FILL);
            paint2.setAntiAlias(true);
        }

        public void draw(Canvas canvas, Rect rect) {
            RectF rectF = this.f36581a;
            rectF.set(rect);
            float f10 = this.f36588h;
            rectF.inset(f10, f10);
            float f11 = this.f36584d;
            float f12 = this.f36586f;
            float f13 = (f11 + f12) * 360.0f;
            float f14 = ((this.f36585e + f12) * 360.0f) - f13;
            if (f14 != 0.0f) {
                Paint paint = this.f36582b;
                paint.setColor(this.f36600t);
                canvas.drawArc(rectF, f13, f14, false, paint);
            }
            if (this.f36594n) {
                Path path = this.f36595o;
                if (path == null) {
                    Path path2 = new Path();
                    this.f36595o = path2;
                    path2.setFillType(Path.FillType.EVEN_ODD);
                } else {
                    path.reset();
                }
                float f15 = (((int) this.f36588h) / 2) * this.f36596p;
                float fCos = (float) ((Math.cos(0.0d) * this.f36597q) + ((double) rect.exactCenterX()));
                float fSin = (float) ((Math.sin(0.0d) * this.f36597q) + ((double) rect.exactCenterY()));
                this.f36595o.moveTo(0.0f, 0.0f);
                this.f36595o.lineTo(this.f36598r * this.f36596p, 0.0f);
                Path path3 = this.f36595o;
                float f16 = this.f36598r;
                float f17 = this.f36596p;
                path3.lineTo((f16 * f17) / 2.0f, this.f36599s * f17);
                this.f36595o.offset(fCos - f15, fSin);
                this.f36595o.close();
                Paint paint2 = this.f36583c;
                paint2.setColor(this.f36600t);
                canvas.rotate((f13 + f14) - 5.0f, rect.exactCenterX(), rect.exactCenterY());
                canvas.drawPath(this.f36595o, paint2);
            }
        }

        public int getNextColor() {
            int[] iArr = this.f36589i;
            return iArr[(this.f36590j + 1) % iArr.length];
        }

        public int getStartingColor() {
            return this.f36589i[this.f36590j];
        }

        public void goToNextColor() {
            setColorIndex((this.f36590j + 1) % this.f36589i.length);
        }

        public void resetOriginals() {
            this.f36591k = 0.0f;
            this.f36592l = 0.0f;
            this.f36593m = 0.0f;
            this.f36584d = 0.0f;
            this.f36585e = 0.0f;
            this.f36586f = 0.0f;
        }

        public void setColorIndex(int i10) {
            this.f36590j = i10;
            this.f36600t = this.f36589i[i10];
        }

        public void setInsets(int i10, int i11) {
            float fMin = Math.min(i10, i11);
            double d10 = this.f36597q;
            this.f36588h = (float) ((d10 <= 0.0d || fMin < 0.0f) ? Math.ceil(this.f36587g / 2.0f) : ((double) (fMin / 2.0f)) - d10);
        }

        public void storeOriginals() {
            this.f36591k = this.f36584d;
            this.f36592l = this.f36585e;
            this.f36593m = this.f36586f;
        }
    }

    public MaterialProgressDrawable(View view) {
        final Ring ring = new Ring();
        this.f36568a = ring;
        this.f36570c = view;
        setColorSchemeColors(f36567l);
        updateSizes(1);
        Animation animation = new Animation() { // from class: xyz.stream.view.refresh.hearder.MaterialProgressDrawable.1
            @Override // android.view.animation.Animation
            public void applyTransformation(float f10, Transformation transformation) {
                MaterialProgressDrawable materialProgressDrawable = MaterialProgressDrawable.this;
                boolean z10 = materialProgressDrawable.f36575h;
                Ring ring2 = ring;
                if (z10) {
                    MaterialProgressDrawable.b(f10, ring2);
                    float fFloor = (float) (Math.floor(ring2.f36593m / 0.8f) + 1.0d);
                    float radians = (float) Math.toRadians(((double) ring2.f36587g) / (ring2.f36597q * 6.283185307179586d));
                    float f11 = ring2.f36591k;
                    float f12 = ring2.f36592l;
                    materialProgressDrawable.setStartEndTrim((((f12 - radians) - f11) * f10) + f11, f12);
                    float f13 = ring2.f36593m;
                    materialProgressDrawable.setProgressRotation(((fFloor - f13) * f10) + f13);
                    return;
                }
                float radians2 = (float) Math.toRadians(((double) ring2.f36587g) / (ring2.f36597q * 6.283185307179586d));
                float f14 = ring2.f36592l;
                float f15 = ring2.f36591k;
                float f16 = ring2.f36593m;
                MaterialProgressDrawable.b(f10, ring2);
                if (f10 <= 0.5f) {
                    ring2.f36584d = (MaterialProgressDrawable.f36566k.getInterpolation(f10 / 0.5f) * (0.8f - radians2)) + f15;
                }
                if (f10 > 0.5f) {
                    ring2.f36585e = (MaterialProgressDrawable.f36566k.getInterpolation((f10 - 0.5f) / 0.5f) * (0.8f - radians2)) + f14;
                }
                materialProgressDrawable.setProgressRotation((0.25f * f10) + f16);
                materialProgressDrawable.f36569b = ((materialProgressDrawable.f36572e / 5.0f) * 1080.0f) + (f10 * 216.0f);
                materialProgressDrawable.invalidateSelf();
            }
        };
        animation.setRepeatCount(-1);
        animation.setRepeatMode(1);
        animation.setInterpolator(f36565j);
        animation.setAnimationListener(new Animation.AnimationListener() { // from class: xyz.stream.view.refresh.hearder.MaterialProgressDrawable.2
            @Override // android.view.animation.Animation.AnimationListener
            public void onAnimationEnd(Animation animation2) {
            }

            @Override // android.view.animation.Animation.AnimationListener
            public void onAnimationRepeat(Animation animation2) {
                Ring ring2 = ring;
                ring2.storeOriginals();
                ring2.goToNextColor();
                ring2.f36584d = ring2.f36585e;
                MaterialProgressDrawable materialProgressDrawable = MaterialProgressDrawable.this;
                if (!materialProgressDrawable.f36575h) {
                    materialProgressDrawable.f36572e = (materialProgressDrawable.f36572e + 1.0f) % 5.0f;
                    return;
                }
                materialProgressDrawable.f36575h = false;
                animation2.setDuration(1332L);
                materialProgressDrawable.showArrow(false);
            }

            @Override // android.view.animation.Animation.AnimationListener
            public void onAnimationStart(Animation animation2) {
                MaterialProgressDrawable.this.f36572e = 0.0f;
            }
        });
        this.f36571d = animation;
    }

    public static void b(float f10, Ring ring) {
        if (f10 > 0.75f) {
            float f11 = (f10 - 0.75f) / 0.25f;
            int startingColor = ring.getStartingColor();
            int nextColor = ring.getNextColor();
            ring.f36600t = ((((startingColor >> 24) & 255) + ((int) ((((nextColor >> 24) & 255) - r2) * f11))) << 24) | ((((startingColor >> 16) & 255) + ((int) ((((nextColor >> 16) & 255) - r3) * f11))) << 16) | ((((startingColor >> 8) & 255) + ((int) ((((nextColor >> 8) & 255) - r4) * f11))) << 8) | ((startingColor & 255) + ((int) (f11 * ((nextColor & 255) - r0))));
        }
    }

    public final void a(int i10, int i11, float f10, float f11, float f12, float f13) {
        float f14 = Resources.getSystem().getDisplayMetrics().density;
        this.f36573f = i10 * f14;
        this.f36574g = i11 * f14;
        Ring ring = this.f36568a;
        ring.setColorIndex(0);
        float f15 = f11 * f14;
        ring.f36582b.setStrokeWidth(f15);
        ring.f36587g = f15;
        ring.f36597q = f10 * f14;
        ring.f36598r = (int) (f12 * f14);
        ring.f36599s = (int) (f13 * f14);
        ring.setInsets((int) this.f36573f, (int) this.f36574g);
        invalidateSelf();
    }

    @Override // android.graphics.drawable.Drawable
    public void draw(@NonNull Canvas canvas) {
        Rect bounds = getBounds();
        int iSave = canvas.save();
        canvas.rotate(this.f36569b, bounds.exactCenterX(), bounds.exactCenterY());
        this.f36568a.draw(canvas, bounds);
        canvas.restoreToCount(iSave);
    }

    @Override // android.graphics.drawable.Drawable
    public int getIntrinsicHeight() {
        return (int) this.f36574g;
    }

    @Override // android.graphics.drawable.Drawable
    public int getIntrinsicWidth() {
        return (int) this.f36573f;
    }

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

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

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

    public void setArrowScale(float f10) {
        Ring ring = this.f36568a;
        if (ring.f36596p != f10) {
            ring.f36596p = f10;
            invalidateSelf();
        }
    }

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

    public void setColorSchemeColors(@ColorInt int... iArr) {
        Ring ring = this.f36568a;
        ring.f36589i = iArr;
        ring.setColorIndex(0);
    }

    public void setProgressRotation(float f10) {
        this.f36568a.f36586f = f10;
        invalidateSelf();
    }

    public void setStartEndTrim(float f10, float f11) {
        Ring ring = this.f36568a;
        ring.f36584d = f10;
        ring.f36585e = f11;
        invalidateSelf();
    }

    public void showArrow(boolean z10) {
        Ring ring = this.f36568a;
        if (ring.f36594n != z10) {
            ring.f36594n = z10;
            invalidateSelf();
        }
    }

    @Override // android.graphics.drawable.Animatable
    public void start() {
        if (this.f36576i) {
            return;
        }
        this.f36571d.reset();
        Ring ring = this.f36568a;
        ring.storeOriginals();
        float f10 = ring.f36585e;
        float f11 = ring.f36584d;
        View view = this.f36570c;
        if (f10 != f11) {
            this.f36575h = true;
            this.f36571d.setDuration(666L);
            view.startAnimation(this.f36571d);
        } else {
            ring.setColorIndex(0);
            ring.resetOriginals();
            this.f36571d.setDuration(1332L);
            view.startAnimation(this.f36571d);
        }
        this.f36576i = true;
    }

    @Override // android.graphics.drawable.Animatable
    public void stop() {
        if (this.f36576i) {
            this.f36570c.clearAnimation();
            Ring ring = this.f36568a;
            ring.setColorIndex(0);
            ring.resetOriginals();
            showArrow(false);
            this.f36569b = 0.0f;
            invalidateSelf();
            this.f36576i = false;
        }
    }

    public void updateSizes(int i10) {
        if (i10 == 0) {
            a(56, 56, 12.5f, 3.0f, 12.0f, 6.0f);
        } else {
            a(40, 40, 8.75f, 2.5f, 10.0f, 5.0f);
        }
    }
}
