package X6FRs_4.NQvZgp_17.KQgRr5e_0.KQgRr5e_0;

import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Path;
import android.graphics.PathMeasure;
import android.util.AttributeSet;
import android.view.InflateException;
import android.view.animation.Interpolator;
import org.xmlpull.v1.XmlPullParser;
/* compiled from: PathInterpolatorCompat.java */
/* loaded from: classes.dex */
public class IMuAHx_6 implements Interpolator {
    public float[] KQgRr5e_0;
    public float[] QxJ9d_1;

    public IMuAHx_6(Context context, AttributeSet attributeSet, XmlPullParser xmlPullParser) {
        this(context.getResources(), context.getTheme(), attributeSet, xmlPullParser);
    }

    public final void KQgRr5e_0(TypedArray typedArray, XmlPullParser xmlPullParser) {
        if (X6FRs_4.IMuAHx_6.X6FRs_4.PGPF6hQ_2.IMuAHx_6.KQgRr5e_0(xmlPullParser, "pathData")) {
            String m334KQgRr5e_0 = X6FRs_4.IMuAHx_6.X6FRs_4.PGPF6hQ_2.IMuAHx_6.m334KQgRr5e_0(typedArray, xmlPullParser, "pathData", 4);
            Path KQgRr5e_0 = X6FRs_4.IMuAHx_6.IFxWkV_5.QxJ9d_1.KQgRr5e_0(m334KQgRr5e_0);
            if (KQgRr5e_0 != null) {
                KQgRr5e_0(KQgRr5e_0);
                return;
            }
            throw new InflateException("The path is null, which is created from " + m334KQgRr5e_0);
        } else if (X6FRs_4.IMuAHx_6.X6FRs_4.PGPF6hQ_2.IMuAHx_6.KQgRr5e_0(xmlPullParser, "controlX1")) {
            if (X6FRs_4.IMuAHx_6.X6FRs_4.PGPF6hQ_2.IMuAHx_6.KQgRr5e_0(xmlPullParser, "controlY1")) {
                float KQgRr5e_02 = X6FRs_4.IMuAHx_6.X6FRs_4.PGPF6hQ_2.IMuAHx_6.KQgRr5e_0(typedArray, xmlPullParser, "controlX1", 0, 0.0f);
                float KQgRr5e_03 = X6FRs_4.IMuAHx_6.X6FRs_4.PGPF6hQ_2.IMuAHx_6.KQgRr5e_0(typedArray, xmlPullParser, "controlY1", 1, 0.0f);
                boolean KQgRr5e_04 = X6FRs_4.IMuAHx_6.X6FRs_4.PGPF6hQ_2.IMuAHx_6.KQgRr5e_0(xmlPullParser, "controlX2");
                if (KQgRr5e_04 != X6FRs_4.IMuAHx_6.X6FRs_4.PGPF6hQ_2.IMuAHx_6.KQgRr5e_0(xmlPullParser, "controlY2")) {
                    throw new InflateException("pathInterpolator requires both controlX2 and controlY2 for cubic Beziers.");
                }
                if (!KQgRr5e_04) {
                    KQgRr5e_0(KQgRr5e_02, KQgRr5e_03);
                    return;
                } else {
                    KQgRr5e_0(KQgRr5e_02, KQgRr5e_03, X6FRs_4.IMuAHx_6.X6FRs_4.PGPF6hQ_2.IMuAHx_6.KQgRr5e_0(typedArray, xmlPullParser, "controlX2", 2, 0.0f), X6FRs_4.IMuAHx_6.X6FRs_4.PGPF6hQ_2.IMuAHx_6.KQgRr5e_0(typedArray, xmlPullParser, "controlY2", 3, 0.0f));
                    return;
                }
            }
            throw new InflateException("pathInterpolator requires the controlY1 attribute");
        } else {
            throw new InflateException("pathInterpolator requires the controlX1 attribute");
        }
    }

    @Override // android.animation.TimeInterpolator
    public float getInterpolation(float f) {
        if (f <= 0.0f) {
            return 0.0f;
        }
        if (f >= 1.0f) {
            return 1.0f;
        }
        int i = 0;
        int length = this.KQgRr5e_0.length - 1;
        while (length - i > 1) {
            int i2 = (i + length) / 2;
            if (f < this.KQgRr5e_0[i2]) {
                length = i2;
            } else {
                i = i2;
            }
        }
        float[] fArr = this.KQgRr5e_0;
        float f2 = fArr[length] - fArr[i];
        if (f2 == 0.0f) {
            return this.QxJ9d_1[i];
        }
        float[] fArr2 = this.QxJ9d_1;
        float f3 = fArr2[i];
        return f3 + (((f - fArr[i]) / f2) * (fArr2[length] - f3));
    }

    public IMuAHx_6(Resources resources, Resources.Theme theme, AttributeSet attributeSet, XmlPullParser xmlPullParser) {
        TypedArray KQgRr5e_0 = X6FRs_4.IMuAHx_6.X6FRs_4.PGPF6hQ_2.IMuAHx_6.KQgRr5e_0(resources, theme, attributeSet, KQgRr5e_0.f3231KNBe_11);
        KQgRr5e_0(KQgRr5e_0, xmlPullParser);
        KQgRr5e_0.recycle();
    }

    public final void KQgRr5e_0(float f, float f2) {
        Path path = new Path();
        path.moveTo(0.0f, 0.0f);
        path.quadTo(f, f2, 1.0f, 1.0f);
        KQgRr5e_0(path);
    }

    public final void KQgRr5e_0(float f, float f2, float f3, float f4) {
        Path path = new Path();
        path.moveTo(0.0f, 0.0f);
        path.cubicTo(f, f2, f3, f4, 1.0f, 1.0f);
        KQgRr5e_0(path);
    }

    public final void KQgRr5e_0(Path path) {
        int i = 0;
        PathMeasure pathMeasure = new PathMeasure(path, false);
        float length = pathMeasure.getLength();
        int min = Math.min(3000, ((int) (length / 0.002f)) + 1);
        if (min > 0) {
            this.KQgRr5e_0 = new float[min];
            this.QxJ9d_1 = new float[min];
            float[] fArr = new float[2];
            for (int i2 = 0; i2 < min; i2++) {
                pathMeasure.getPosTan((i2 * length) / (min - 1), fArr, null);
                this.KQgRr5e_0[i2] = fArr[0];
                this.QxJ9d_1[i2] = fArr[1];
            }
            if (Math.abs(this.KQgRr5e_0[0]) <= 1.0E-5d && Math.abs(this.QxJ9d_1[0]) <= 1.0E-5d) {
                int i3 = min - 1;
                if (Math.abs(this.KQgRr5e_0[i3] - 1.0f) <= 1.0E-5d && Math.abs(this.QxJ9d_1[i3] - 1.0f) <= 1.0E-5d) {
                    float f = 0.0f;
                    int i4 = 0;
                    while (i < min) {
                        float[] fArr2 = this.KQgRr5e_0;
                        int i5 = i4 + 1;
                        float f2 = fArr2[i4];
                        if (f2 >= f) {
                            fArr2[i] = f2;
                            i++;
                            f = f2;
                            i4 = i5;
                        } else {
                            throw new IllegalArgumentException("The Path cannot loop back on itself, x :" + f2);
                        }
                    }
                    if (pathMeasure.nextContour()) {
                        throw new IllegalArgumentException("The Path should be continuous, can't have 2+ contours");
                    }
                    return;
                }
            }
            StringBuilder sb = new StringBuilder();
            sb.append("The Path must start at (0,0) and end at (1,1) start: ");
            sb.append(this.KQgRr5e_0[0]);
            sb.append(",");
            sb.append(this.QxJ9d_1[0]);
            sb.append(" end:");
            int i6 = min - 1;
            sb.append(this.KQgRr5e_0[i6]);
            sb.append(",");
            sb.append(this.QxJ9d_1[i6]);
            throw new IllegalArgumentException(sb.toString());
        }
        throw new IllegalArgumentException("The Path has a invalid length " + length);
    }
}
