package u0;

import android.content.res.Resources;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.AnimationUtils;
import android.widget.ListView;
import androidx.core.view.s1;
import e.s0;
import java.util.WeakHashMap;
import tv.danmaku.ijk.media.player.IjkEventListener;

/* JADX INFO: loaded from: classes.dex */
public final class j implements View.OnTouchListener {
    public static final int U = ViewConfiguration.getTapTimeout();
    public boolean Q;
    public boolean R;
    public boolean S;
    public final ListView T;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final a f33178a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final AccelerateInterpolator f33179b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final View f33180c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public s0 f33181d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final float[] f33182e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final float[] f33183f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final int f33184g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final int f33185h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public final float[] f33186i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public final float[] f33187j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public final float[] f33188k;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public boolean f33189l;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public boolean f33190m;

    public j(ListView listView) {
        a aVar = new a();
        aVar.f33171e = Long.MIN_VALUE;
        aVar.f33173g = -1L;
        aVar.f33172f = 0L;
        this.f33178a = aVar;
        this.f33179b = new AccelerateInterpolator();
        this.f33182e = new float[]{0.0f, 0.0f};
        this.f33183f = new float[]{Float.MAX_VALUE, Float.MAX_VALUE};
        this.f33186i = new float[]{0.0f, 0.0f};
        this.f33187j = new float[]{0.0f, 0.0f};
        this.f33188k = new float[]{Float.MAX_VALUE, Float.MAX_VALUE};
        this.f33180c = listView;
        float f10 = Resources.getSystem().getDisplayMetrics().density;
        float[] fArr = this.f33188k;
        float f11 = ((int) ((1575.0f * f10) + 0.5f)) / 1000.0f;
        fArr[0] = f11;
        fArr[1] = f11;
        float[] fArr2 = this.f33187j;
        float f12 = ((int) ((f10 * 315.0f) + 0.5f)) / 1000.0f;
        fArr2[0] = f12;
        fArr2[1] = f12;
        this.f33184g = 1;
        float[] fArr3 = this.f33183f;
        fArr3[0] = Float.MAX_VALUE;
        fArr3[1] = Float.MAX_VALUE;
        float[] fArr4 = this.f33182e;
        fArr4[0] = 0.2f;
        fArr4[1] = 0.2f;
        float[] fArr5 = this.f33186i;
        fArr5[0] = 0.001f;
        fArr5[1] = 0.001f;
        this.f33185h = U;
        aVar.f33167a = IjkEventListener.BUFFERING_START;
        aVar.f33168b = IjkEventListener.BUFFERING_START;
        this.T = listView;
    }

    public static float b(float f10, float f11, float f12) {
        return f10 > f12 ? f12 : f10 < f11 ? f11 : f10;
    }

    /* JADX WARN: Removed duplicated region for block: B:13:0x003c  */
    /* JADX WARN: Removed duplicated region for block: B:19:? A[RETURN, SYNTHETIC] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final float a(float f10, int i10, float f11, float f12) {
        float fB;
        float interpolation;
        float fB2 = b(this.f33182e[i10] * f11, 0.0f, this.f33183f[i10]);
        float fC = c(f11 - f10, fB2) - c(f10, fB2);
        AccelerateInterpolator accelerateInterpolator = this.f33179b;
        if (fC < 0.0f) {
            interpolation = -accelerateInterpolator.getInterpolation(-fC);
        } else {
            if (fC <= 0.0f) {
                fB = 0.0f;
                if (fB != 0.0f) {
                    return 0.0f;
                }
                float f13 = this.f33186i[i10];
                float f14 = this.f33187j[i10];
                float f15 = this.f33188k[i10];
                float f16 = f13 * f12;
                return fB > 0.0f ? b(fB * f16, f14, f15) : -b((-fB) * f16, f14, f15);
            }
            interpolation = accelerateInterpolator.getInterpolation(fC);
        }
        fB = b(interpolation, -1.0f, 1.0f);
        if (fB != 0.0f) {
        }
    }

    public final float c(float f10, float f11) {
        if (f11 == 0.0f) {
            return 0.0f;
        }
        int i10 = this.f33184g;
        if (i10 == 0 || i10 == 1) {
            if (f10 < f11) {
                return f10 >= 0.0f ? 1.0f - (f10 / f11) : (this.R && i10 == 1) ? 1.0f : 0.0f;
            }
            return 0.0f;
        }
        if (i10 == 2 && f10 < 0.0f) {
            return f10 / (-f11);
        }
        return 0.0f;
    }

    /* JADX WARN: Removed duplicated region for block: B:13:0x0016  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final boolean d(View view, MotionEvent motionEvent) {
        int i10;
        if (!this.S) {
            return false;
        }
        int actionMasked = motionEvent.getActionMasked();
        if (actionMasked != 0) {
            if (actionMasked == 1) {
                e();
            } else if (actionMasked != 2) {
                if (actionMasked == 3) {
                }
            }
            return false;
        }
        this.Q = true;
        this.f33189l = false;
        float x10 = motionEvent.getX();
        float width = view.getWidth();
        View view2 = this.f33180c;
        float fA = a(x10, 0, width, view2.getWidth());
        float fA2 = a(motionEvent.getY(), 1, view.getHeight(), view2.getHeight());
        a aVar = this.f33178a;
        aVar.f33169c = fA;
        aVar.f33170d = fA2;
        if (!this.R && f()) {
            if (this.f33181d == null) {
                this.f33181d = new s0(this, 5);
            }
            this.R = true;
            this.f33190m = true;
            if (this.f33189l || (i10 = this.f33185h) <= 0) {
                this.f33181d.run();
            } else {
                s0 s0Var = this.f33181d;
                long j10 = i10;
                WeakHashMap weakHashMap = s1.f1815a;
                view2.postOnAnimationDelayed(s0Var, j10);
            }
            this.f33189l = true;
        }
        return false;
    }

    public final void e() {
        int i10 = 0;
        if (this.f33190m) {
            this.R = false;
            return;
        }
        a aVar = this.f33178a;
        aVar.getClass();
        long jCurrentAnimationTimeMillis = AnimationUtils.currentAnimationTimeMillis();
        int i11 = (int) (jCurrentAnimationTimeMillis - aVar.f33171e);
        int i12 = aVar.f33168b;
        if (i11 > i12) {
            i10 = i12;
        } else if (i11 >= 0) {
            i10 = i11;
        }
        aVar.f33175i = i10;
        aVar.f33174h = aVar.a(jCurrentAnimationTimeMillis);
        aVar.f33173g = jCurrentAnimationTimeMillis;
    }

    public final boolean f() {
        ListView listView;
        int count;
        a aVar = this.f33178a;
        float f10 = aVar.f33170d;
        int iAbs = (int) (f10 / Math.abs(f10));
        Math.abs(aVar.f33169c);
        if (iAbs == 0 || (count = (listView = this.T).getCount()) == 0) {
            return false;
        }
        int childCount = listView.getChildCount();
        int firstVisiblePosition = listView.getFirstVisiblePosition();
        int i10 = firstVisiblePosition + childCount;
        if (iAbs > 0) {
            if (i10 >= count && listView.getChildAt(childCount - 1).getBottom() <= listView.getHeight()) {
                return false;
            }
        } else {
            if (iAbs >= 0) {
                return false;
            }
            if (firstVisiblePosition <= 0 && listView.getChildAt(0).getTop() >= 0) {
                return false;
            }
        }
        return true;
    }

    @Override // android.view.View.OnTouchListener
    public final /* bridge */ /* synthetic */ boolean onTouch(View view, MotionEvent motionEvent) {
        d(view, motionEvent);
        return false;
    }
}
