package P;

import M.J;
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 java.lang.reflect.Field;
import n.Y;

/* JADX INFO: loaded from: classes.dex */
public final class d implements View.OnTouchListener {
    public static final int H = ViewConfiguration.getTapTimeout();

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

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

    /* JADX INFO: renamed from: C, reason: collision with root package name */
    public boolean f5230C;
    public boolean D;

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

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

    /* JADX INFO: renamed from: G, reason: collision with root package name */
    public final Y f5233G;

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

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

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    public final ListView f5236s;

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    public M4.k f5237t;

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

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

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

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

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

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

    public d(Y y8) {
        a aVar = new a();
        aVar.f5224e = Long.MIN_VALUE;
        aVar.f5226g = -1L;
        aVar.f5225f = 0L;
        this.f5234q = aVar;
        this.f5235r = new AccelerateInterpolator();
        float[] fArr = {0.0f, 0.0f};
        this.f5238u = fArr;
        float[] fArr2 = {Float.MAX_VALUE, Float.MAX_VALUE};
        this.f5239v = fArr2;
        float[] fArr3 = {0.0f, 0.0f};
        this.f5242y = fArr3;
        float[] fArr4 = {0.0f, 0.0f};
        this.f5243z = fArr4;
        float[] fArr5 = {Float.MAX_VALUE, Float.MAX_VALUE};
        this.f5228A = fArr5;
        this.f5236s = y8;
        float f3 = Resources.getSystem().getDisplayMetrics().density;
        float f7 = ((int) ((1575.0f * f3) + 0.5f)) / 1000.0f;
        fArr5[0] = f7;
        fArr5[1] = f7;
        float f8 = ((int) ((f3 * 315.0f) + 0.5f)) / 1000.0f;
        fArr4[0] = f8;
        fArr4[1] = f8;
        this.f5240w = 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.f5241x = H;
        aVar.f5220a = 500;
        aVar.f5221b = 500;
        this.f5233G = y8;
    }

    public static float b(float f3, float f7, float f8) {
        return f3 > f8 ? f8 : f3 < f7 ? f7 : f3;
    }

    /* 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 a(float f3, float f7, float f8, int i) {
        float fB;
        float interpolation;
        float fB2 = b(this.f5238u[i] * f7, 0.0f, this.f5239v[i]);
        float fC = c(f7 - f3, fB2) - c(f3, fB2);
        AccelerateInterpolator accelerateInterpolator = this.f5235r;
        if (fC < 0.0f) {
            interpolation = -accelerateInterpolator.getInterpolation(-fC);
        } else {
            if (fC <= 0.0f) {
                fB = 0.0f;
                if (fB != 0.0f) {
                    return 0.0f;
                }
                float f9 = this.f5242y[i];
                float f10 = this.f5243z[i];
                float f11 = this.f5228A[i];
                float f12 = f9 * f8;
                return fB > 0.0f ? b(fB * f12, f10, f11) : -b((-fB) * f12, f10, f11);
            }
            interpolation = accelerateInterpolator.getInterpolation(fC);
        }
        fB = b(interpolation, -1.0f, 1.0f);
        if (fB != 0.0f) {
        }
    }

    public final float c(float f3, float f7) {
        if (f7 != 0.0f) {
            int i = this.f5240w;
            if (i == 0 || i == 1) {
                if (f3 < f7) {
                    if (f3 >= 0.0f) {
                        return 1.0f - (f3 / f7);
                    }
                    if (this.f5231E && i == 1) {
                        return 1.0f;
                    }
                }
            } else if (i == 2 && f3 < 0.0f) {
                return f3 / (-f7);
            }
        }
        return 0.0f;
    }

    public final void d() {
        int i = 0;
        if (this.f5230C) {
            this.f5231E = false;
            return;
        }
        a aVar = this.f5234q;
        long jCurrentAnimationTimeMillis = AnimationUtils.currentAnimationTimeMillis();
        int i5 = (int) (jCurrentAnimationTimeMillis - aVar.f5224e);
        int i8 = aVar.f5221b;
        if (i5 > i8) {
            i = i8;
        } else if (i5 >= 0) {
            i = i5;
        }
        aVar.i = i;
        aVar.f5227h = aVar.a(jCurrentAnimationTimeMillis);
        aVar.f5226g = jCurrentAnimationTimeMillis;
    }

    public final boolean e() {
        Y y8;
        int count;
        a aVar = this.f5234q;
        float f3 = aVar.f5223d;
        int iAbs = (int) (f3 / Math.abs(f3));
        Math.abs(aVar.f5222c);
        if (iAbs != 0 && (count = (y8 = this.f5233G).getCount()) != 0) {
            int childCount = y8.getChildCount();
            int firstVisiblePosition = y8.getFirstVisiblePosition();
            int i = firstVisiblePosition + childCount;
            if (iAbs <= 0 ? !(iAbs >= 0 || (firstVisiblePosition <= 0 && y8.getChildAt(0).getTop() >= 0)) : !(i >= count && y8.getChildAt(childCount - 1).getBottom() <= y8.getHeight())) {
                return true;
            }
        }
        return false;
    }

    /* 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.f5232F) {
            int actionMasked = motionEvent.getActionMasked();
            if (actionMasked != 0) {
                if (actionMasked != 1) {
                    if (actionMasked != 2) {
                    }
                }
                d();
                return false;
            }
            this.D = true;
            this.f5229B = false;
            float x8 = motionEvent.getX();
            float width = view.getWidth();
            ListView listView = this.f5236s;
            float fA = a(x8, width, listView.getWidth(), 0);
            float fA2 = a(motionEvent.getY(), view.getHeight(), listView.getHeight(), 1);
            a aVar = this.f5234q;
            aVar.f5222c = fA;
            aVar.f5223d = fA2;
            if (!this.f5231E && e()) {
                if (this.f5237t == null) {
                    this.f5237t = new M4.k(6, this);
                }
                this.f5231E = true;
                this.f5230C = true;
                if (this.f5229B || (i = this.f5241x) <= 0) {
                    this.f5237t.run();
                } else {
                    M4.k kVar = this.f5237t;
                    long j8 = i;
                    Field field = J.f4065a;
                    listView.postOnAnimationDelayed(kVar, j8);
                }
                this.f5229B = true;
            }
        }
        return false;
    }
}
