package defpackage;

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 androidx.credentials.CredentialOption;
import java.util.WeakHashMap;

/* JADX INFO: loaded from: classes.dex */
public abstract class k20 implements View.OnTouchListener {
    public static final int s = ViewConfiguration.getTapTimeout();
    public final a a;
    public final AccelerateInterpolator b;
    public final View c;
    public Runnable d;
    public final float[] e;
    public final float[] f;
    public final int i;
    public final int j;
    public final float[] k;
    public final float[] l;
    public final float[] m;
    public boolean n;
    public boolean o;
    public boolean p;
    public boolean q;
    public boolean r;

    public static class a {
        public int a;
        public int b;
        public float c;
        public float d;
        public long e;
        public long f;
        public long g;
        public float h;
        public int i;

        public final float a(long j) {
            if (j < this.e) {
                return 0.0f;
            }
            long j2 = this.g;
            if (j2 < 0 || j < j2) {
                return k20.c((j - r0) / this.a, 0.0f, 1.0f) * 0.5f;
            }
            float f = this.h;
            return (k20.c((j - j2) / this.i, 0.0f, 1.0f) * f) + (1.0f - f);
        }
    }

    public class b implements Runnable {
        public b() {
        }

        @Override // java.lang.Runnable
        public final void run() {
            k20 k20Var = k20.this;
            View view = k20Var.c;
            a aVar = k20Var.a;
            if (k20Var.q) {
                if (k20Var.o) {
                    k20Var.o = false;
                    long jCurrentAnimationTimeMillis = AnimationUtils.currentAnimationTimeMillis();
                    aVar.e = jCurrentAnimationTimeMillis;
                    aVar.g = -1L;
                    aVar.f = jCurrentAnimationTimeMillis;
                    aVar.h = 0.5f;
                }
                if ((aVar.g > 0 && AnimationUtils.currentAnimationTimeMillis() > aVar.g + ((long) aVar.i)) || !k20Var.g()) {
                    k20Var.q = false;
                    return;
                }
                if (k20Var.p) {
                    k20Var.p = false;
                    long jUptimeMillis = SystemClock.uptimeMillis();
                    MotionEvent motionEventObtain = MotionEvent.obtain(jUptimeMillis, jUptimeMillis, 3, 0.0f, 0.0f, 0);
                    view.onTouchEvent(motionEventObtain);
                    motionEventObtain.recycle();
                }
                if (aVar.f == 0) {
                    throw new RuntimeException("Cannot compute scroll delta before calling start()");
                }
                long jCurrentAnimationTimeMillis2 = AnimationUtils.currentAnimationTimeMillis();
                float fA = aVar.a(jCurrentAnimationTimeMillis2);
                long j = jCurrentAnimationTimeMillis2 - aVar.f;
                aVar.f = jCurrentAnimationTimeMillis2;
                k20Var.f((int) (j * ((fA * 4.0f) + ((-4.0f) * fA * fA)) * aVar.d));
                WeakHashMap weakHashMap = sia.a;
                view.postOnAnimation(this);
            }
        }
    }

    public k20(View view) {
        a aVar = new a();
        aVar.e = Long.MIN_VALUE;
        aVar.g = -1L;
        aVar.f = 0L;
        this.a = aVar;
        this.b = new AccelerateInterpolator();
        float[] fArr = {0.0f, 0.0f};
        this.e = fArr;
        float[] fArr2 = {Float.MAX_VALUE, Float.MAX_VALUE};
        this.f = fArr2;
        float[] fArr3 = {0.0f, 0.0f};
        this.k = fArr3;
        float[] fArr4 = {0.0f, 0.0f};
        this.l = fArr4;
        float[] fArr5 = {Float.MAX_VALUE, Float.MAX_VALUE};
        this.m = fArr5;
        this.c = view;
        float f = Resources.getSystem().getDisplayMetrics().density;
        float f2 = ((int) ((1575.0f * f) + 0.5f)) / 1000.0f;
        fArr5[0] = f2;
        fArr5[1] = f2;
        float f3 = ((int) ((f * 315.0f) + 0.5f)) / 1000.0f;
        fArr4[0] = f3;
        fArr4[1] = f3;
        this.i = 1;
        fArr2[0] = Float.MAX_VALUE;
        fArr2[1] = Float.MAX_VALUE;
        fArr[0] = 0.2f;
        fArr[1] = 0.2f;
        fArr3[0] = 0.001f;
        fArr3[1] = 0.001f;
        this.j = s;
        aVar.a = CredentialOption.PRIORITY_OIDC_OR_SIMILAR;
        aVar.b = CredentialOption.PRIORITY_OIDC_OR_SIMILAR;
    }

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

    public abstract boolean a(int i);

    /* JADX WARN: Removed duplicated region for block: B:12:0x003b A[RETURN] */
    /* JADX WARN: Removed duplicated region for block: B:13:0x003c  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final float b(float f, float f2, float f3, int i) {
        float fC;
        float interpolation;
        float fC2 = c(this.e[i] * f2, 0.0f, this.f[i]);
        float fD = d(f2 - f, fC2) - d(f, fC2);
        AccelerateInterpolator accelerateInterpolator = this.b;
        if (fD < 0.0f) {
            interpolation = -accelerateInterpolator.getInterpolation(-fD);
        } else {
            if (fD <= 0.0f) {
                fC = 0.0f;
                if (fC != 0.0f) {
                    return 0.0f;
                }
                float f4 = this.k[i];
                float f5 = this.l[i];
                float f6 = this.m[i];
                float f7 = f4 * f3;
                return fC > 0.0f ? c(fC * f7, f5, f6) : -c((-fC) * f7, f5, f6);
            }
            interpolation = accelerateInterpolator.getInterpolation(fD);
        }
        fC = c(interpolation, -1.0f, 1.0f);
        if (fC != 0.0f) {
        }
    }

    public final float d(float f, float f2) {
        if (f2 != 0.0f) {
            int i = this.i;
            if (i == 0 || i == 1) {
                if (f < f2) {
                    if (f >= 0.0f) {
                        return 1.0f - (f / f2);
                    }
                    if (this.q && i == 1) {
                        return 1.0f;
                    }
                }
            } else if (i == 2 && f < 0.0f) {
                return f / (-f2);
            }
        }
        return 0.0f;
    }

    public final void e() {
        int i = 0;
        if (this.o) {
            this.q = false;
            return;
        }
        long jCurrentAnimationTimeMillis = AnimationUtils.currentAnimationTimeMillis();
        a aVar = this.a;
        int i2 = (int) (jCurrentAnimationTimeMillis - aVar.e);
        int i3 = aVar.b;
        if (i2 > i3) {
            i = i3;
        } else if (i2 >= 0) {
            i = i2;
        }
        aVar.i = i;
        aVar.h = aVar.a(jCurrentAnimationTimeMillis);
        aVar.g = jCurrentAnimationTimeMillis;
    }

    public abstract void f(int i);

    public final boolean g() {
        a aVar = this.a;
        float f = aVar.d;
        int iAbs = (int) (f / Math.abs(f));
        Math.abs(aVar.c);
        return iAbs != 0 && a(iAbs);
    }

    /* JADX WARN: Code restructure failed: missing block: B:11:0x0014, code lost:
    
        if (r0 != 3) goto L30;
     */
    @Override // android.view.View.OnTouchListener
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final boolean onTouch(View view, MotionEvent motionEvent) {
        int i;
        if (this.r) {
            int actionMasked = motionEvent.getActionMasked();
            if (actionMasked != 0) {
                if (actionMasked != 1) {
                    if (actionMasked != 2) {
                    }
                }
                e();
                return false;
            }
            this.p = true;
            this.n = false;
            float x = motionEvent.getX();
            float width = view.getWidth();
            View view2 = this.c;
            float fB = b(x, width, view2.getWidth(), 0);
            float fB2 = b(motionEvent.getY(), view.getHeight(), view2.getHeight(), 1);
            a aVar = this.a;
            aVar.c = fB;
            aVar.d = fB2;
            if (!this.q && g()) {
                if (this.d == null) {
                    this.d = new b();
                }
                this.q = true;
                this.o = true;
                if (this.n || (i = this.j) <= 0) {
                    ((b) this.d).run();
                } else {
                    Runnable runnable = this.d;
                    long j = i;
                    WeakHashMap weakHashMap = sia.a;
                    view2.postOnAnimationDelayed(runnable, j);
                }
                this.n = true;
            }
        }
        return false;
    }
}
