package defpackage;

import android.animation.Animator;
import android.graphics.PointF;
import android.view.Choreographer;
import java.util.Iterator;

/* JADX INFO: loaded from: classes.dex */
public class gl5 extends z70 implements Choreographer.FrameCallback {
    public float d;
    public boolean e;
    public long f;
    public float i;
    public float j;
    public int k;
    public float l;
    public float m;
    public zj5 n;
    public boolean o;
    public boolean p;

    public final float c() {
        zj5 zj5Var = this.n;
        if (zj5Var == null) {
            return 0.0f;
        }
        float f = this.j;
        float f2 = zj5Var.l;
        return (f - f2) / (zj5Var.m - f2);
    }

    @Override // android.animation.ValueAnimator, android.animation.Animator
    public final void cancel() {
        Iterator it = this.b.iterator();
        while (it.hasNext()) {
            ((Animator.AnimatorListener) it.next()).onAnimationCancel(this);
        }
        a(f());
        g(true);
    }

    public final float d() {
        zj5 zj5Var = this.n;
        if (zj5Var == null) {
            return 0.0f;
        }
        float f = this.m;
        return f == 2.1474836E9f ? zj5Var.m : f;
    }

    @Override // android.view.Choreographer.FrameCallback
    public final void doFrame(long j) {
        boolean z = false;
        if (this.o) {
            g(false);
            Choreographer.getInstance().postFrameCallback(this);
        }
        zj5 zj5Var = this.n;
        if (zj5Var == null || !this.o) {
            return;
        }
        float fAbs = (this.f != 0 ? j - r2 : 0L) / ((1.0E9f / zj5Var.n) / Math.abs(this.d));
        float f = this.i;
        if (f()) {
            fAbs = -fAbs;
        }
        float f2 = f + fAbs;
        float fE = e();
        float fD = d();
        PointF pointF = mx5.a;
        if (f2 >= fE && f2 <= fD) {
            z = true;
        }
        float f3 = this.i;
        float fB = mx5.b(f2, e(), d());
        this.i = fB;
        if (this.p) {
            fB = (float) Math.floor(fB);
        }
        this.j = fB;
        this.f = j;
        if (z) {
            if (!this.p || this.i != f3) {
                b();
            }
        } else if (getRepeatCount() == -1 || this.k < getRepeatCount()) {
            if (getRepeatMode() == 2) {
                this.e = !this.e;
                this.d = -this.d;
            } else {
                float fD2 = f() ? d() : e();
                this.i = fD2;
                this.j = fD2;
            }
            this.f = j;
            if (!this.p || this.i != f3) {
                b();
            }
            Iterator it = this.b.iterator();
            while (it.hasNext()) {
                ((Animator.AnimatorListener) it.next()).onAnimationRepeat(this);
            }
            this.k++;
        } else {
            float fE2 = this.d < 0.0f ? e() : d();
            this.i = fE2;
            this.j = fE2;
            g(true);
            if (!this.p || this.i != f3) {
                b();
            }
            a(f());
        }
        if (this.n == null) {
            return;
        }
        float f4 = this.j;
        if (f4 < this.l || f4 > this.m) {
            throw new IllegalStateException(String.format("Frame must be [%f,%f]. It is %f", Float.valueOf(this.l), Float.valueOf(this.m), Float.valueOf(this.j)));
        }
    }

    public final float e() {
        zj5 zj5Var = this.n;
        if (zj5Var == null) {
            return 0.0f;
        }
        float f = this.l;
        return f == -2.1474836E9f ? zj5Var.l : f;
    }

    public final boolean f() {
        return this.d < 0.0f;
    }

    public final void g(boolean z) {
        Choreographer.getInstance().removeFrameCallback(this);
        if (z) {
            this.o = false;
        }
    }

    @Override // android.animation.ValueAnimator
    public final float getAnimatedFraction() {
        float fE;
        float fD;
        float fE2;
        if (this.n == null) {
            return 0.0f;
        }
        if (f()) {
            fE = d() - this.j;
            fD = d();
            fE2 = e();
        } else {
            fE = this.j - e();
            fD = d();
            fE2 = e();
        }
        return fE / (fD - fE2);
    }

    @Override // android.animation.ValueAnimator
    public final Object getAnimatedValue() {
        return Float.valueOf(c());
    }

    @Override // android.animation.ValueAnimator, android.animation.Animator
    public final long getDuration() {
        zj5 zj5Var = this.n;
        if (zj5Var == null) {
            return 0L;
        }
        return (long) zj5Var.b();
    }

    public final void h(float f) {
        if (this.i == f) {
            return;
        }
        float fB = mx5.b(f, e(), d());
        this.i = fB;
        if (this.p) {
            fB = (float) Math.floor(fB);
        }
        this.j = fB;
        this.f = 0L;
        b();
    }

    public final void i(float f, float f2) {
        if (f > f2) {
            throw new IllegalArgumentException("minFrame (" + f + ") must be <= maxFrame (" + f2 + ")");
        }
        zj5 zj5Var = this.n;
        float f3 = zj5Var == null ? -3.4028235E38f : zj5Var.l;
        float f4 = zj5Var == null ? Float.MAX_VALUE : zj5Var.m;
        float fB = mx5.b(f, f3, f4);
        float fB2 = mx5.b(f2, f3, f4);
        if (fB == this.l && fB2 == this.m) {
            return;
        }
        this.l = fB;
        this.m = fB2;
        h((int) mx5.b(this.j, fB, fB2));
    }

    @Override // android.animation.ValueAnimator, android.animation.Animator
    public final boolean isRunning() {
        return this.o;
    }

    @Override // android.animation.ValueAnimator
    public final void setRepeatMode(int i) {
        super.setRepeatMode(i);
        if (i == 2 || !this.e) {
            return;
        }
        this.e = false;
        this.d = -this.d;
    }
}
