package com.bytedance.adsdk.ro.ajl;

import android.view.Choreographer;
import com.bytedance.adsdk.ro.wsy;

/* JADX INFO: loaded from: classes.dex */
public class lb extends fm implements Choreographer.FrameCallback {
    private wsy vt;
    private float ro = 1.0f;

    /* JADX INFO: renamed from: lb, reason: collision with root package name */
    private boolean f6193lb = false;
    private long yz = 0;
    private float jnr = 0.0f;
    private float ajl = 0.0f;
    private int wsy = 0;
    private float wu = -2.1474836E9f;

    /* JADX INFO: renamed from: ef, reason: collision with root package name */
    private float f6192ef = 2.1474836E9f;
    protected boolean fm = false;
    private boolean ku = false;

    private float gqi() {
        wsy wsyVar = this.vt;
        if (wsyVar == null) {
            return Float.MAX_VALUE;
        }
        return (1.0E9f / wsyVar.duv()) / Math.abs(this.ro);
    }

    private void sds() {
        if (this.vt == null) {
            return;
        }
        float f10 = this.ajl;
        if (f10 < this.wu || f10 > this.f6192ef) {
            throw new IllegalStateException(String.format("Frame must be [%f,%f]. It is %f", Float.valueOf(this.wu), Float.valueOf(this.f6192ef), Float.valueOf(this.ajl)));
        }
    }

    private boolean wey() {
        return vt() < 0.0f;
    }

    public float ajl() {
        wsy wsyVar = this.vt;
        if (wsyVar == null) {
            return 0.0f;
        }
        return (this.ajl - wsyVar.ajl()) / (this.vt.wsy() - this.vt.ajl());
    }

    @Override // android.animation.ValueAnimator, android.animation.Animator
    public void cancel() {
        ro();
        gof();
    }

    @Override // android.view.Choreographer.FrameCallback
    public void doFrame(long j10) {
        qhl();
        if (this.vt == null || !isRunning()) {
            return;
        }
        com.bytedance.adsdk.ro.jnr.fm("LottieValueAnimator#doFrame");
        float fGqi = (this.yz != 0 ? j10 - r1 : 0L) / gqi();
        float f10 = this.jnr;
        if (wey()) {
            fGqi = -fGqi;
        }
        float f11 = f10 + fGqi;
        boolean z10 = !jnr.lb(f11, fhx(), irt());
        float f12 = this.jnr;
        float fRo = jnr.ro(f11, fhx(), irt());
        this.jnr = fRo;
        if (this.ku) {
            fRo = (float) Math.floor(fRo);
        }
        this.ajl = fRo;
        this.yz = j10;
        if (!this.ku || this.jnr != f12) {
            lb();
        }
        if (z10) {
            if (getRepeatCount() == -1 || this.wsy < getRepeatCount()) {
                fm();
                this.wsy++;
                if (getRepeatMode() == 2) {
                    this.f6193lb = !this.f6193lb;
                    ef();
                } else {
                    float fIrt = wey() ? irt() : fhx();
                    this.jnr = fIrt;
                    this.ajl = fIrt;
                }
                this.yz = j10;
            } else {
                float fFhx = this.ro < 0.0f ? fhx() : irt();
                this.jnr = fFhx;
                this.ajl = fFhx;
                gof();
                ro(wey());
            }
        }
        sds();
        com.bytedance.adsdk.ro.jnr.ro("LottieValueAnimator#doFrame");
    }

    public void dsz() {
        gof();
        yz();
    }

    public void duv() {
        gof();
        ro(wey());
    }

    public void ef() {
        lb(-vt());
    }

    public float fhx() {
        wsy wsyVar = this.vt;
        if (wsyVar == null) {
            return 0.0f;
        }
        float f10 = this.wu;
        return f10 == -2.1474836E9f ? wsyVar.ajl() : f10;
    }

    public void fm(wsy wsyVar) {
        boolean z10 = this.vt == null;
        this.vt = wsyVar;
        if (z10) {
            fm(Math.max(this.wu, wsyVar.ajl()), Math.min(this.f6192ef, wsyVar.wsy()));
        } else {
            fm((int) wsyVar.ajl(), (int) wsyVar.wsy());
        }
        float f10 = this.ajl;
        this.ajl = 0.0f;
        this.jnr = 0.0f;
        fm((int) f10);
        lb();
    }

    @Override // android.animation.ValueAnimator
    public float getAnimatedFraction() {
        float fFhx;
        float fIrt;
        float fFhx2;
        if (this.vt == null) {
            return 0.0f;
        }
        if (wey()) {
            fFhx = irt() - this.ajl;
            fIrt = irt();
            fFhx2 = fhx();
        } else {
            fFhx = this.ajl - fhx();
            fIrt = irt();
            fFhx2 = fhx();
        }
        return fFhx / (fIrt - fFhx2);
    }

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

    @Override // android.animation.ValueAnimator, android.animation.Animator
    public long getDuration() {
        wsy wsyVar = this.vt;
        if (wsyVar == null) {
            return 0L;
        }
        return (long) wsyVar.jnr();
    }

    public void gof() {
        yz(true);
    }

    public float irt() {
        wsy wsyVar = this.vt;
        if (wsyVar == null) {
            return 0.0f;
        }
        float f10 = this.f6192ef;
        return f10 == 2.1474836E9f ? wsyVar.wsy() : f10;
    }

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

    public void ku() {
        this.fm = true;
        fm(wey());
        fm((int) (wey() ? irt() : fhx()));
        this.yz = 0L;
        this.wsy = 0;
        qhl();
    }

    public void lb(float f10) {
        this.ro = f10;
    }

    public void onz() {
        this.fm = true;
        qhl();
        this.yz = 0L;
        if (wey() && wsy() == fhx()) {
            fm(irt());
        } else if (!wey() && wsy() == irt()) {
            fm(fhx());
        }
        jnr();
    }

    public void qhl() {
        if (isRunning()) {
            yz(false);
            Choreographer.getInstance().postFrameCallback(this);
        }
    }

    public void ro(float f10) {
        fm(this.wu, f10);
    }

    @Override // android.animation.ValueAnimator
    public void setRepeatMode(int i10) {
        super.setRepeatMode(i10);
        if (i10 == 2 || !this.f6193lb) {
            return;
        }
        this.f6193lb = false;
        ef();
    }

    public float vt() {
        return this.ro;
    }

    public float wsy() {
        return this.ajl;
    }

    public void wu() {
        this.vt = null;
        this.wu = -2.1474836E9f;
        this.f6192ef = 2.1474836E9f;
    }

    public void yz(boolean z10) {
        Choreographer.getInstance().removeFrameCallback(this);
        if (z10) {
            this.fm = false;
        }
    }

    public void lb(boolean z10) {
        this.ku = z10;
    }

    @Override // com.bytedance.adsdk.ro.ajl.fm
    public void ro() {
        super.ro();
        ro(wey());
    }

    public void fm(float f10) {
        if (this.jnr == f10) {
            return;
        }
        float fRo = jnr.ro(f10, fhx(), irt());
        this.jnr = fRo;
        if (this.ku) {
            fRo = (float) Math.floor(fRo);
        }
        this.ajl = fRo;
        this.yz = 0L;
        lb();
    }

    public void fm(int i10) {
        fm(i10, (int) this.f6192ef);
    }

    public void fm(float f10, float f11) {
        if (f10 <= f11) {
            wsy wsyVar = this.vt;
            float fAjl = wsyVar == null ? -3.4028235E38f : wsyVar.ajl();
            wsy wsyVar2 = this.vt;
            float fWsy = wsyVar2 == null ? Float.MAX_VALUE : wsyVar2.wsy();
            float fRo = jnr.ro(f10, fAjl, fWsy);
            float fRo2 = jnr.ro(f11, fAjl, fWsy);
            if (fRo == this.wu && fRo2 == this.f6192ef) {
                return;
            }
            this.wu = fRo;
            this.f6192ef = fRo2;
            fm((int) jnr.ro(this.ajl, fRo, fRo2));
            return;
        }
        throw new IllegalArgumentException(String.format("minFrame (%s) must be <= maxFrame (%s)", Float.valueOf(f10), Float.valueOf(f11)));
    }
}
