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 androidx.core.view.y;

/* JADX INFO: compiled from: AutoScrollHelper.java */
/* JADX INFO: loaded from: classes.dex */
public abstract class a implements View.OnTouchListener {

    /* JADX INFO: renamed from: v, reason: collision with root package name */
    private static final int f1998v = ViewConfiguration.getTapTimeout();

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    final View f2001g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    private Runnable f2002h;

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

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

    /* JADX INFO: renamed from: p, reason: collision with root package name */
    private boolean f2010p;

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    boolean f2011q;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    boolean f2012r;

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    boolean f2013s;

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    private boolean f2014t;

    /* JADX INFO: renamed from: u, reason: collision with root package name */
    private boolean f2015u;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    final C0025a f1999e = new C0025a();

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    private final Interpolator f2000f = new AccelerateInterpolator();

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

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

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

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

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    private float[] f2009o = {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 C0025a {

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

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

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

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

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

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

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

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

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

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

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

        C0025a() {
        }

        private float e(long j3) {
            if (j3 < this.f2020e) {
                return 0.0f;
            }
            long j4 = this.f2024i;
            if (j4 < 0 || j3 < j4) {
                return a.e((j3 - r0) / this.f2016a, 0.0f, 1.0f) * 0.5f;
            }
            float f3 = this.f2025j;
            return (1.0f - f3) + (f3 * a.e((j3 - j4) / this.f2026k, 0.0f, 1.0f));
        }

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

        public void a() {
            if (this.f2021f == 0) {
                throw new RuntimeException("Cannot compute scroll delta before calling start()");
            }
            long jCurrentAnimationTimeMillis = AnimationUtils.currentAnimationTimeMillis();
            float fG = g(e(jCurrentAnimationTimeMillis));
            long j3 = jCurrentAnimationTimeMillis - this.f2021f;
            this.f2021f = jCurrentAnimationTimeMillis;
            float f3 = j3 * fG;
            this.f2022g = (int) (this.f2018c * f3);
            this.f2023h = (int) (f3 * this.f2019d);
        }

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

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

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

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

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

        public void i() {
            long jCurrentAnimationTimeMillis = AnimationUtils.currentAnimationTimeMillis();
            this.f2026k = a.f((int) (jCurrentAnimationTimeMillis - this.f2020e), 0, this.f2017b);
            this.f2025j = e(jCurrentAnimationTimeMillis);
            this.f2024i = jCurrentAnimationTimeMillis;
        }

        public void j(int i3) {
            this.f2017b = i3;
        }

        public void k(int i3) {
            this.f2016a = i3;
        }

        public void l(float f3, float f4) {
            this.f2018c = f3;
            this.f2019d = f4;
        }

        public void m() {
            long jCurrentAnimationTimeMillis = AnimationUtils.currentAnimationTimeMillis();
            this.f2020e = jCurrentAnimationTimeMillis;
            this.f2024i = -1L;
            this.f2021f = jCurrentAnimationTimeMillis;
            this.f2025j = 0.5f;
            this.f2022g = 0;
            this.f2023h = 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.f2013s) {
                if (aVar.f2011q) {
                    aVar.f2011q = false;
                    aVar.f1999e.m();
                }
                C0025a c0025a = a.this.f1999e;
                if (c0025a.h() || !a.this.u()) {
                    a.this.f2013s = false;
                    return;
                }
                a aVar2 = a.this;
                if (aVar2.f2012r) {
                    aVar2.f2012r = false;
                    aVar2.c();
                }
                c0025a.a();
                a.this.j(c0025a.b(), c0025a.c());
                y.j0(a.this.f2001g, this);
            }
        }
    }

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

    private float d(int i3, float f3, float f4, float f5) {
        float fH = h(this.f2003i[i3], f4, this.f2004j[i3], f3);
        if (fH == 0.0f) {
            return 0.0f;
        }
        float f6 = this.f2007m[i3];
        float f7 = this.f2008n[i3];
        float f8 = this.f2009o[i3];
        float f9 = f6 * f5;
        return fH > 0.0f ? e(fH * f9, f7, f8) : -e((-fH) * f9, f7, f8);
    }

    static float e(float f3, float f4, float f5) {
        return f3 > f5 ? f5 : f3 < f4 ? f4 : f3;
    }

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

    private float g(float f3, float f4) {
        if (f4 == 0.0f) {
            return 0.0f;
        }
        int i3 = this.f2005k;
        if (i3 == 0 || i3 == 1) {
            if (f3 < f4) {
                if (f3 >= 0.0f) {
                    return 1.0f - (f3 / f4);
                }
                if (this.f2013s && i3 == 1) {
                    return 1.0f;
                }
            }
        } else if (i3 == 2 && f3 < 0.0f) {
            return f3 / (-f4);
        }
        return 0.0f;
    }

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

    private void i() {
        if (this.f2011q) {
            this.f2013s = false;
        } else {
            this.f1999e.i();
        }
    }

    private void v() {
        int i3;
        if (this.f2002h == null) {
            this.f2002h = new b();
        }
        this.f2013s = true;
        this.f2011q = true;
        if (this.f2010p || (i3 = this.f2006l) <= 0) {
            this.f2002h.run();
        } else {
            y.k0(this.f2001g, this.f2002h, i3);
        }
        this.f2010p = true;
    }

    public abstract boolean a(int i3);

    public abstract boolean b(int i3);

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

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

    public a k(int i3) {
        this.f2006l = i3;
        return this;
    }

    public a l(int i3) {
        this.f2005k = i3;
        return this;
    }

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

    public a n(float f3, float f4) {
        float[] fArr = this.f2004j;
        fArr[0] = f3;
        fArr[1] = f4;
        return this;
    }

    public a o(float f3, float f4) {
        float[] fArr = this.f2009o;
        fArr[0] = f3 / 1000.0f;
        fArr[1] = f4 / 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.f2014t
            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.f2012r = r2
            r5.f2010p = r1
        L1e:
            float r0 = r7.getX()
            int r3 = r6.getWidth()
            float r3 = (float) r3
            android.view.View r4 = r5.f2001g
            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.f2001g
            int r3 = r3.getHeight()
            float r3 = (float) r3
            float r6 = r5.d(r2, r7, r6, r3)
            androidx.core.widget.a$a r7 = r5.f1999e
            r7.l(r0, r6)
            boolean r6 = r5.f2013s
            if (r6 != 0) goto L58
            boolean r6 = r5.u()
            if (r6 == 0) goto L58
            r5.v()
        L58:
            boolean r6 = r5.f2015u
            if (r6 == 0) goto L61
            boolean r5 = r5.f2013s
            if (r5 == 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 f3, float f4) {
        float[] fArr = this.f2008n;
        fArr[0] = f3 / 1000.0f;
        fArr[1] = f4 / 1000.0f;
        return this;
    }

    public a q(int i3) {
        this.f1999e.j(i3);
        return this;
    }

    public a r(int i3) {
        this.f1999e.k(i3);
        return this;
    }

    public a s(float f3, float f4) {
        float[] fArr = this.f2003i;
        fArr[0] = f3;
        fArr[1] = f4;
        return this;
    }

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

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