package androidx.core.widget;

import android.content.res.Resources;
import android.os.SystemClock;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.AnimationUtils;
import android.view.animation.Interpolator;
import g.e.j.o;

/* JADX INFO: compiled from: AutoScrollHelper.java */
/* JADX INFO: loaded from: classes.dex */
public abstract class a implements View.OnTouchListener {
    private static final int t = ViewConfiguration.getTapTimeout();
    final View e;
    private Runnable f;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    private int f274i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    private int f275j;
    private boolean n;
    boolean o;
    boolean p;
    boolean q;
    private boolean r;
    private boolean s;
    final C0007a b = new C0007a();
    private final Interpolator d = new AccelerateInterpolator();

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    private float[] f272g = {0.0f, 0.0f};

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    private float[] f273h = {Float.MAX_VALUE, Float.MAX_VALUE};

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    private float[] f276k = {0.0f, 0.0f};

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    private float[] f277l = {0.0f, 0.0f};

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    private float[] f278m = {Float.MAX_VALUE, Float.MAX_VALUE};

    /* JADX INFO: renamed from: androidx.core.widget.a$a, reason: collision with other inner class name */
    /* JADX INFO: compiled from: AutoScrollHelper.java */
    private static class C0007a {
        private int a;
        private int b;
        private float c;
        private float d;

        /* JADX INFO: renamed from: j, reason: collision with root package name */
        private float f282j;

        /* JADX INFO: renamed from: k, reason: collision with root package name */
        private int f283k;
        private long e = Long.MIN_VALUE;

        /* JADX INFO: renamed from: i, reason: collision with root package name */
        private long f281i = -1;
        private long f = 0;

        /* JADX INFO: renamed from: g, reason: collision with root package name */
        private int f279g = 0;

        /* JADX INFO: renamed from: h, reason: collision with root package name */
        private int f280h = 0;

        C0007a() {
        }

        private float e(long j2) {
            if (j2 < this.e) {
                return 0.0f;
            }
            long j3 = this.f281i;
            if (j3 < 0 || j2 < j3) {
                return a.e((j2 - this.e) / this.a, 0.0f, 1.0f) * 0.5f;
            }
            long j4 = j2 - j3;
            float f = this.f282j;
            return (1.0f - f) + (f * a.e(j4 / this.f283k, 0.0f, 1.0f));
        }

        private float g(float f) {
            return ((-4.0f) * f * f) + (f * 4.0f);
        }

        public void a() {
            if (this.f == 0) {
                throw new RuntimeException("Cannot compute scroll delta before calling start()");
            }
            long jCurrentAnimationTimeMillis = AnimationUtils.currentAnimationTimeMillis();
            float fG = g(e(jCurrentAnimationTimeMillis));
            long j2 = jCurrentAnimationTimeMillis - this.f;
            this.f = jCurrentAnimationTimeMillis;
            float f = j2 * fG;
            this.f279g = (int) (this.c * f);
            this.f280h = (int) (f * this.d);
        }

        public int b() {
            return this.f279g;
        }

        public int c() {
            return this.f280h;
        }

        public int d() {
            float f = this.c;
            return (int) (f / Math.abs(f));
        }

        public int f() {
            float f = this.d;
            return (int) (f / Math.abs(f));
        }

        public boolean h() {
            return this.f281i > 0 && AnimationUtils.currentAnimationTimeMillis() > this.f281i + ((long) this.f283k);
        }

        public void i() {
            long jCurrentAnimationTimeMillis = AnimationUtils.currentAnimationTimeMillis();
            this.f283k = a.f((int) (jCurrentAnimationTimeMillis - this.e), 0, this.b);
            this.f282j = e(jCurrentAnimationTimeMillis);
            this.f281i = jCurrentAnimationTimeMillis;
        }

        public void j(int i2) {
            this.b = i2;
        }

        public void k(int i2) {
            this.a = i2;
        }

        public void l(float f, float f2) {
            this.c = f;
            this.d = f2;
        }

        public void m() {
            long jCurrentAnimationTimeMillis = AnimationUtils.currentAnimationTimeMillis();
            this.e = jCurrentAnimationTimeMillis;
            this.f281i = -1L;
            this.f = jCurrentAnimationTimeMillis;
            this.f282j = 0.5f;
            this.f279g = 0;
            this.f280h = 0;
        }
    }

    /* JADX INFO: compiled from: AutoScrollHelper.java */
    private class b implements Runnable {
        b() {
        }

        @Override // java.lang.Runnable
        public void run() {
            a aVar = a.this;
            if (aVar.q) {
                if (aVar.o) {
                    aVar.o = false;
                    aVar.b.m();
                }
                C0007a c0007a = a.this.b;
                if (c0007a.h() || !a.this.u()) {
                    a.this.q = false;
                    return;
                }
                a aVar2 = a.this;
                if (aVar2.p) {
                    aVar2.p = false;
                    aVar2.c();
                }
                c0007a.a();
                a.this.j(c0007a.b(), c0007a.c());
                o.p(a.this.e, this);
            }
        }
    }

    public a(View view) {
        this.e = view;
        float f = Resources.getSystem().getDisplayMetrics().density;
        float f2 = (int) ((1575.0f * f) + 0.5f);
        o(f2, f2);
        float f3 = (int) ((f * 315.0f) + 0.5f);
        p(f3, f3);
        l(1);
        n(Float.MAX_VALUE, Float.MAX_VALUE);
        s(0.2f, 0.2f);
        t(1.0f, 1.0f);
        k(t);
        r(500);
        q(500);
    }

    private float d(int i2, float f, float f2, float f3) {
        float fH = h(this.f272g[i2], f2, this.f273h[i2], f);
        if (fH == 0.0f) {
            return 0.0f;
        }
        float f4 = this.f276k[i2];
        float f5 = this.f277l[i2];
        float f6 = this.f278m[i2];
        float f7 = f4 * f3;
        return fH > 0.0f ? e(fH * f7, f5, f6) : -e((-fH) * f7, f5, f6);
    }

    static float e(float f, float f2, float f3) {
        return f > f3 ? f3 : f < f2 ? f2 : f;
    }

    static int f(int i2, int i3, int i4) {
        return i2 > i4 ? i4 : i2 < i3 ? i3 : i2;
    }

    private float g(float f, float f2) {
        if (f2 == 0.0f) {
            return 0.0f;
        }
        int i2 = this.f274i;
        if (i2 == 0 || i2 == 1) {
            if (f < f2) {
                if (f >= 0.0f) {
                    return 1.0f - (f / f2);
                }
                if (this.q && this.f274i == 1) {
                    return 1.0f;
                }
            }
        } else if (i2 == 2 && f < 0.0f) {
            return f / (-f2);
        }
        return 0.0f;
    }

    private float h(float f, float f2, float f3, float f4) {
        float interpolation;
        float fE = e(f * f2, 0.0f, f3);
        float fG = g(f2 - f4, fE) - g(f4, fE);
        if (fG < 0.0f) {
            interpolation = -this.d.getInterpolation(-fG);
        } else {
            if (fG <= 0.0f) {
                return 0.0f;
            }
            interpolation = this.d.getInterpolation(fG);
        }
        return e(interpolation, -1.0f, 1.0f);
    }

    private void i() {
        if (this.o) {
            this.q = false;
        } else {
            this.b.i();
        }
    }

    private void v() {
        int i2;
        if (this.f == null) {
            this.f = new b();
        }
        this.q = true;
        this.o = true;
        if (this.n || (i2 = this.f275j) <= 0) {
            this.f.run();
        } else {
            o.q(this.e, this.f, i2);
        }
        this.n = true;
    }

    public abstract boolean a(int i2);

    public abstract boolean b(int i2);

    void c() {
        long jUptimeMillis = SystemClock.uptimeMillis();
        MotionEvent motionEventObtain = MotionEvent.obtain(jUptimeMillis, jUptimeMillis, 3, 0.0f, 0.0f, 0);
        this.e.onTouchEvent(motionEventObtain);
        motionEventObtain.recycle();
    }

    public abstract void j(int i2, int i3);

    public a k(int i2) {
        this.f275j = i2;
        return this;
    }

    public a l(int i2) {
        this.f274i = i2;
        return this;
    }

    public a m(boolean z) {
        if (this.r && !z) {
            i();
        }
        this.r = z;
        return this;
    }

    public a n(float f, float f2) {
        float[] fArr = this.f273h;
        fArr[0] = f;
        fArr[1] = f2;
        return this;
    }

    public a o(float f, float f2) {
        float[] fArr = this.f278m;
        fArr[0] = f / 1000.0f;
        fArr[1] = f2 / 1000.0f;
        return this;
    }

    /* JADX WARN: Removed duplicated region for block: B:13:0x0016  */
    @Override // android.view.View.OnTouchListener
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public boolean onTouch(android.view.View r6, android.view.MotionEvent r7) {
        /*
            r5 = this;
            boolean r0 = r5.r
            r1 = 0
            if (r0 != 0) goto L6
            return r1
        L6:
            int r0 = r7.getActionMasked()
            r2 = 1
            if (r0 == 0) goto L1a
            if (r0 == r2) goto L16
            r3 = 2
            if (r0 == r3) goto L1e
            r6 = 3
            if (r0 == r6) goto L16
            goto L58
        L16:
            r5.i()
            goto L58
        L1a:
            r5.p = r2
            r5.n = r1
        L1e:
            float r0 = r7.getX()
            int r3 = r6.getWidth()
            float r3 = (float) r3
            android.view.View r4 = r5.e
            int r4 = r4.getWidth()
            float r4 = (float) r4
            float r0 = r5.d(r1, r0, r3, r4)
            float r7 = r7.getY()
            int r6 = r6.getHeight()
            float r6 = (float) r6
            android.view.View r3 = r5.e
            int r3 = r3.getHeight()
            float r3 = (float) r3
            float r6 = r5.d(r2, r7, r6, r3)
            androidx.core.widget.a$a r7 = r5.b
            r7.l(r0, r6)
            boolean r6 = r5.q
            if (r6 != 0) goto L58
            boolean r6 = r5.u()
            if (r6 == 0) goto L58
            r5.v()
        L58:
            boolean r6 = r5.s
            if (r6 == 0) goto L61
            boolean r6 = r5.q
            if (r6 == 0) goto L61
            r1 = r2
        L61:
            return r1
        */
        throw new UnsupportedOperationException("Method not decompiled: androidx.core.widget.a.onTouch(android.view.View, android.view.MotionEvent):boolean");
    }

    public a p(float f, float f2) {
        float[] fArr = this.f277l;
        fArr[0] = f / 1000.0f;
        fArr[1] = f2 / 1000.0f;
        return this;
    }

    public a q(int i2) {
        this.b.j(i2);
        return this;
    }

    public a r(int i2) {
        this.b.k(i2);
        return this;
    }

    public a s(float f, float f2) {
        float[] fArr = this.f272g;
        fArr[0] = f;
        fArr[1] = f2;
        return this;
    }

    public a t(float f, float f2) {
        float[] fArr = this.f276k;
        fArr[0] = f / 1000.0f;
        fArr[1] = f2 / 1000.0f;
        return this;
    }

    boolean u() {
        C0007a c0007a = this.b;
        int iF = c0007a.f();
        int iD = c0007a.d();
        return (iF != 0 && b(iF)) || (iD != 0 && a(iD));
    }
}
