package T;

import M.J;
import M4.k;
import N1.Q;
import android.content.Context;
import android.util.Log;
import android.view.MotionEvent;
import android.view.VelocityTracker;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewParent;
import android.widget.OverScroller;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import com.google.android.gms.internal.measurement.X1;
import java.lang.reflect.Field;
import java.util.Arrays;

/* JADX INFO: loaded from: classes.dex */
public final class d {

    /* JADX INFO: renamed from: v, reason: collision with root package name */
    public static final Q f6316v = new Q(1);

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

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

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public float[] f6320d;

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

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

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public float[] f6323g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public int[] f6324h;
    public int[] i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public int[] f6325j;

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

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

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public final float f6328m;

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    public final float f6329n;

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

    /* JADX INFO: renamed from: p, reason: collision with root package name */
    public final OverScroller f6331p;

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

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public View f6333r;

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

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    public final CoordinatorLayout f6335t;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public int f6319c = -1;

    /* JADX INFO: renamed from: u, reason: collision with root package name */
    public final k f6336u = new k(8, this);

    public d(Context context, CoordinatorLayout coordinatorLayout, X1 x12) {
        if (coordinatorLayout == null) {
            throw new IllegalArgumentException("Parent view may not be null");
        }
        if (x12 == null) {
            throw new IllegalArgumentException("Callback may not be null");
        }
        this.f6335t = coordinatorLayout;
        this.f6332q = x12;
        ViewConfiguration viewConfiguration = ViewConfiguration.get(context);
        this.f6330o = (int) ((context.getResources().getDisplayMetrics().density * 20.0f) + 0.5f);
        this.f6318b = viewConfiguration.getScaledTouchSlop();
        this.f6328m = viewConfiguration.getScaledMaximumFlingVelocity();
        this.f6329n = viewConfiguration.getScaledMinimumFlingVelocity();
        this.f6331p = new OverScroller(context, f6316v);
    }

    public final void a() {
        this.f6319c = -1;
        float[] fArr = this.f6320d;
        if (fArr != null) {
            Arrays.fill(fArr, 0.0f);
            Arrays.fill(this.f6321e, 0.0f);
            Arrays.fill(this.f6322f, 0.0f);
            Arrays.fill(this.f6323g, 0.0f);
            Arrays.fill(this.f6324h, 0);
            Arrays.fill(this.i, 0);
            Arrays.fill(this.f6325j, 0);
            this.f6326k = 0;
        }
        VelocityTracker velocityTracker = this.f6327l;
        if (velocityTracker != null) {
            velocityTracker.recycle();
            this.f6327l = null;
        }
    }

    public final void b(View view, int i) {
        ViewParent parent = view.getParent();
        CoordinatorLayout coordinatorLayout = this.f6335t;
        if (parent != coordinatorLayout) {
            throw new IllegalArgumentException("captureChildView: parameter must be a descendant of the ViewDragHelper's tracked parent view (" + coordinatorLayout + ")");
        }
        this.f6333r = view;
        this.f6319c = i;
        this.f6332q.A(view, i);
        n(1);
    }

    /* JADX WARN: Removed duplicated region for block: B:25:0x0044 A[RETURN] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final boolean c(View view, float f3, float f7) {
        if (view != null) {
            X1 x12 = this.f6332q;
            boolean z8 = x12.q(view) > 0;
            boolean z9 = x12.r() > 0;
            if (z8 && z9) {
                float f8 = (f7 * f7) + (f3 * f3);
                int i = this.f6318b;
                if (f8 > i * i) {
                }
            } else if (!z8 ? !(!z9 || Math.abs(f7) <= this.f6318b) : Math.abs(f3) > this.f6318b) {
                return true;
            }
        }
        return false;
    }

    public final void d(int i) {
        float[] fArr = this.f6320d;
        if (fArr != null) {
            int i5 = this.f6326k;
            int i8 = 1 << i;
            if ((i5 & i8) != 0) {
                fArr[i] = 0.0f;
                this.f6321e[i] = 0.0f;
                this.f6322f[i] = 0.0f;
                this.f6323g[i] = 0.0f;
                this.f6324h[i] = 0;
                this.i[i] = 0;
                this.f6325j[i] = 0;
                this.f6326k = (~i8) & i5;
            }
        }
    }

    public final int e(int i, int i5, int i8) {
        if (i == 0) {
            return 0;
        }
        float width = this.f6335t.getWidth() / 2;
        float fSin = (((float) Math.sin((Math.min(1.0f, Math.abs(i) / r0) - 0.5f) * 0.47123894f)) * width) + width;
        int iAbs = Math.abs(i5);
        return Math.min(iAbs > 0 ? Math.round(Math.abs(fSin / iAbs) * 1000.0f) * 4 : (int) (((Math.abs(i) / i8) + 1.0f) * 256.0f), 600);
    }

    public final boolean f() {
        if (this.f6317a == 2) {
            OverScroller overScroller = this.f6331p;
            boolean zComputeScrollOffset = overScroller.computeScrollOffset();
            int currX = overScroller.getCurrX();
            int currY = overScroller.getCurrY();
            int left = currX - this.f6333r.getLeft();
            int top = currY - this.f6333r.getTop();
            if (left != 0) {
                View view = this.f6333r;
                Field field = J.f4065a;
                view.offsetLeftAndRight(left);
            }
            if (top != 0) {
                View view2 = this.f6333r;
                Field field2 = J.f4065a;
                view2.offsetTopAndBottom(top);
            }
            if (left != 0 || top != 0) {
                this.f6332q.C(this.f6333r, currX, currY);
            }
            if (zComputeScrollOffset && currX == overScroller.getFinalX() && currY == overScroller.getFinalY()) {
                overScroller.abortAnimation();
                zComputeScrollOffset = false;
            }
            if (!zComputeScrollOffset) {
                this.f6335t.post(this.f6336u);
            }
        }
        return this.f6317a == 2;
    }

    public final View g(int i, int i5) {
        CoordinatorLayout coordinatorLayout = this.f6335t;
        for (int childCount = coordinatorLayout.getChildCount() - 1; childCount >= 0; childCount--) {
            this.f6332q.getClass();
            View childAt = coordinatorLayout.getChildAt(childCount);
            if (i >= childAt.getLeft() && i < childAt.getRight() && i5 >= childAt.getTop() && i5 < childAt.getBottom()) {
                return childAt;
            }
        }
        return null;
    }

    public final boolean h(int i, int i5, int i8, int i9) {
        float f3;
        float f7;
        float f8;
        float f9;
        int left = this.f6333r.getLeft();
        int top = this.f6333r.getTop();
        int i10 = i - left;
        int i11 = i5 - top;
        OverScroller overScroller = this.f6331p;
        if (i10 == 0 && i11 == 0) {
            overScroller.abortAnimation();
            n(0);
            return false;
        }
        View view = this.f6333r;
        int i12 = (int) this.f6329n;
        int i13 = (int) this.f6328m;
        int iAbs = Math.abs(i8);
        if (iAbs < i12) {
            i8 = 0;
        } else if (iAbs > i13) {
            i8 = i8 > 0 ? i13 : -i13;
        }
        int iAbs2 = Math.abs(i9);
        if (iAbs2 < i12) {
            i9 = 0;
        } else if (iAbs2 > i13) {
            i9 = i9 > 0 ? i13 : -i13;
        }
        int iAbs3 = Math.abs(i10);
        int iAbs4 = Math.abs(i11);
        int iAbs5 = Math.abs(i8);
        int iAbs6 = Math.abs(i9);
        int i14 = iAbs5 + iAbs6;
        int i15 = iAbs3 + iAbs4;
        if (i8 != 0) {
            f3 = iAbs5;
            f7 = i14;
        } else {
            f3 = iAbs3;
            f7 = i15;
        }
        float f10 = f3 / f7;
        if (i9 != 0) {
            f8 = iAbs6;
            f9 = i14;
        } else {
            f8 = iAbs4;
            f9 = i15;
        }
        float f11 = f8 / f9;
        X1 x12 = this.f6332q;
        overScroller.startScroll(left, top, i10, i11, (int) ((e(i11, i9, x12.r()) * f11) + (e(i10, i8, x12.q(view)) * f10)));
        n(2);
        return true;
    }

    public final boolean i(int i) {
        if ((this.f6326k & (1 << i)) != 0) {
            return true;
        }
        Log.e("ViewDragHelper", "Ignoring pointerId=" + i + " because ACTION_DOWN was not received for this pointer before ACTION_MOVE. It likely happened because  ViewDragHelper did not receive all the events in the event stream.");
        return false;
    }

    public final void j(MotionEvent motionEvent) {
        int i;
        int actionMasked = motionEvent.getActionMasked();
        int actionIndex = motionEvent.getActionIndex();
        if (actionMasked == 0) {
            a();
        }
        if (this.f6327l == null) {
            this.f6327l = VelocityTracker.obtain();
        }
        this.f6327l.addMovement(motionEvent);
        int i5 = 0;
        if (actionMasked == 0) {
            float x8 = motionEvent.getX();
            float y8 = motionEvent.getY();
            int pointerId = motionEvent.getPointerId(0);
            View viewG = g((int) x8, (int) y8);
            l(x8, y8, pointerId);
            q(viewG, pointerId);
            int i8 = this.f6324h[pointerId];
            return;
        }
        if (actionMasked == 1) {
            if (this.f6317a == 1) {
                k();
            }
            a();
            return;
        }
        X1 x12 = this.f6332q;
        if (actionMasked != 2) {
            if (actionMasked == 3) {
                if (this.f6317a == 1) {
                    this.f6334s = true;
                    x12.D(this.f6333r, 0.0f, 0.0f);
                    this.f6334s = false;
                    if (this.f6317a == 1) {
                        n(0);
                    }
                }
                a();
                return;
            }
            if (actionMasked == 5) {
                int pointerId2 = motionEvent.getPointerId(actionIndex);
                float x9 = motionEvent.getX(actionIndex);
                float y9 = motionEvent.getY(actionIndex);
                l(x9, y9, pointerId2);
                if (this.f6317a == 0) {
                    q(g((int) x9, (int) y9), pointerId2);
                    int i9 = this.f6324h[pointerId2];
                    return;
                }
                int i10 = (int) x9;
                int i11 = (int) y9;
                View view = this.f6333r;
                if (view != null && i10 >= view.getLeft() && i10 < view.getRight() && i11 >= view.getTop() && i11 < view.getBottom()) {
                    q(this.f6333r, pointerId2);
                    return;
                }
                return;
            }
            if (actionMasked != 6) {
                return;
            }
            int pointerId3 = motionEvent.getPointerId(actionIndex);
            if (this.f6317a == 1 && pointerId3 == this.f6319c) {
                int pointerCount = motionEvent.getPointerCount();
                while (true) {
                    if (i5 >= pointerCount) {
                        i = -1;
                        break;
                    }
                    int pointerId4 = motionEvent.getPointerId(i5);
                    if (pointerId4 != this.f6319c) {
                        View viewG2 = g((int) motionEvent.getX(i5), (int) motionEvent.getY(i5));
                        View view2 = this.f6333r;
                        if (viewG2 == view2 && q(view2, pointerId4)) {
                            i = this.f6319c;
                            break;
                        }
                    }
                    i5++;
                }
                if (i == -1) {
                    k();
                }
            }
            d(pointerId3);
            return;
        }
        if (this.f6317a == 1) {
            if (i(this.f6319c)) {
                int iFindPointerIndex = motionEvent.findPointerIndex(this.f6319c);
                float x10 = motionEvent.getX(iFindPointerIndex);
                float y10 = motionEvent.getY(iFindPointerIndex);
                float[] fArr = this.f6322f;
                int i12 = this.f6319c;
                int i13 = (int) (x10 - fArr[i12]);
                int i14 = (int) (y10 - this.f6323g[i12]);
                int left = this.f6333r.getLeft() + i13;
                int top = this.f6333r.getTop() + i14;
                int left2 = this.f6333r.getLeft();
                int top2 = this.f6333r.getTop();
                if (i13 != 0) {
                    left = x12.g(this.f6333r, left);
                    Field field = J.f4065a;
                    this.f6333r.offsetLeftAndRight(left - left2);
                }
                if (i14 != 0) {
                    top = x12.h(this.f6333r, top);
                    Field field2 = J.f4065a;
                    this.f6333r.offsetTopAndBottom(top - top2);
                }
                if (i13 != 0 || i14 != 0) {
                    x12.C(this.f6333r, left, top);
                }
                m(motionEvent);
                return;
            }
            return;
        }
        int pointerCount2 = motionEvent.getPointerCount();
        while (i5 < pointerCount2) {
            int pointerId5 = motionEvent.getPointerId(i5);
            if (i(pointerId5)) {
                float x11 = motionEvent.getX(i5);
                float y11 = motionEvent.getY(i5);
                float f3 = x11 - this.f6320d[pointerId5];
                float f7 = y11 - this.f6321e[pointerId5];
                Math.abs(f3);
                Math.abs(f7);
                int i15 = this.f6324h[pointerId5];
                Math.abs(f7);
                Math.abs(f3);
                int i16 = this.f6324h[pointerId5];
                Math.abs(f3);
                Math.abs(f7);
                int i17 = this.f6324h[pointerId5];
                Math.abs(f7);
                Math.abs(f3);
                int i18 = this.f6324h[pointerId5];
                if (this.f6317a != 1) {
                    View viewG3 = g((int) x11, (int) y11);
                    if (c(viewG3, f3, f7) && q(viewG3, pointerId5)) {
                        break;
                    }
                } else {
                    break;
                }
            }
            i5++;
        }
        m(motionEvent);
    }

    public final void k() {
        VelocityTracker velocityTracker = this.f6327l;
        float f3 = this.f6328m;
        velocityTracker.computeCurrentVelocity(1000, f3);
        float xVelocity = this.f6327l.getXVelocity(this.f6319c);
        float f7 = this.f6329n;
        float fAbs = Math.abs(xVelocity);
        if (fAbs < f7) {
            xVelocity = 0.0f;
        } else if (fAbs > f3) {
            xVelocity = xVelocity > 0.0f ? f3 : -f3;
        }
        float yVelocity = this.f6327l.getYVelocity(this.f6319c);
        float fAbs2 = Math.abs(yVelocity);
        if (fAbs2 < f7) {
            f3 = 0.0f;
        } else if (fAbs2 <= f3) {
            f3 = yVelocity;
        } else if (yVelocity <= 0.0f) {
            f3 = -f3;
        }
        this.f6334s = true;
        this.f6332q.D(this.f6333r, xVelocity, f3);
        this.f6334s = false;
        if (this.f6317a == 1) {
            n(0);
        }
    }

    public final void l(float f3, float f7, int i) {
        float[] fArr = this.f6320d;
        if (fArr == null || fArr.length <= i) {
            int i5 = i + 1;
            float[] fArr2 = new float[i5];
            float[] fArr3 = new float[i5];
            float[] fArr4 = new float[i5];
            float[] fArr5 = new float[i5];
            int[] iArr = new int[i5];
            int[] iArr2 = new int[i5];
            int[] iArr3 = new int[i5];
            if (fArr != null) {
                System.arraycopy(fArr, 0, fArr2, 0, fArr.length);
                float[] fArr6 = this.f6321e;
                System.arraycopy(fArr6, 0, fArr3, 0, fArr6.length);
                float[] fArr7 = this.f6322f;
                System.arraycopy(fArr7, 0, fArr4, 0, fArr7.length);
                float[] fArr8 = this.f6323g;
                System.arraycopy(fArr8, 0, fArr5, 0, fArr8.length);
                int[] iArr4 = this.f6324h;
                System.arraycopy(iArr4, 0, iArr, 0, iArr4.length);
                int[] iArr5 = this.i;
                System.arraycopy(iArr5, 0, iArr2, 0, iArr5.length);
                int[] iArr6 = this.f6325j;
                System.arraycopy(iArr6, 0, iArr3, 0, iArr6.length);
            }
            this.f6320d = fArr2;
            this.f6321e = fArr3;
            this.f6322f = fArr4;
            this.f6323g = fArr5;
            this.f6324h = iArr;
            this.i = iArr2;
            this.f6325j = iArr3;
        }
        float[] fArr9 = this.f6320d;
        this.f6322f[i] = f3;
        fArr9[i] = f3;
        float[] fArr10 = this.f6321e;
        this.f6323g[i] = f7;
        fArr10[i] = f7;
        int[] iArr7 = this.f6324h;
        int i8 = (int) f3;
        int i9 = (int) f7;
        CoordinatorLayout coordinatorLayout = this.f6335t;
        int left = coordinatorLayout.getLeft();
        int i10 = this.f6330o;
        int i11 = i8 < left + i10 ? 1 : 0;
        if (i9 < coordinatorLayout.getTop() + i10) {
            i11 |= 4;
        }
        if (i8 > coordinatorLayout.getRight() - i10) {
            i11 |= 2;
        }
        if (i9 > coordinatorLayout.getBottom() - i10) {
            i11 |= 8;
        }
        iArr7[i] = i11;
        this.f6326k |= 1 << i;
    }

    public final void m(MotionEvent motionEvent) {
        int pointerCount = motionEvent.getPointerCount();
        for (int i = 0; i < pointerCount; i++) {
            int pointerId = motionEvent.getPointerId(i);
            if (i(pointerId)) {
                float x8 = motionEvent.getX(i);
                float y8 = motionEvent.getY(i);
                this.f6322f[pointerId] = x8;
                this.f6323g[pointerId] = y8;
            }
        }
    }

    public final void n(int i) {
        this.f6335t.removeCallbacks(this.f6336u);
        if (this.f6317a != i) {
            this.f6317a = i;
            this.f6332q.B(i);
            if (this.f6317a == 0) {
                this.f6333r = null;
            }
        }
    }

    public final boolean o(int i, int i5) {
        if (this.f6334s) {
            return h(i, i5, (int) this.f6327l.getXVelocity(this.f6319c), (int) this.f6327l.getYVelocity(this.f6319c));
        }
        throw new IllegalStateException("Cannot settleCapturedViewAt outside of a call to Callback#onViewReleased");
    }

    /* JADX WARN: Removed duplicated region for block: B:52:0x00d6  */
    /* JADX WARN: Removed duplicated region for block: B:61:0x0114  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final boolean p(MotionEvent motionEvent) {
        View viewG;
        int actionMasked = motionEvent.getActionMasked();
        int actionIndex = motionEvent.getActionIndex();
        if (actionMasked == 0) {
            a();
        }
        if (this.f6327l == null) {
            this.f6327l = VelocityTracker.obtain();
        }
        this.f6327l.addMovement(motionEvent);
        if (actionMasked == 0) {
            float x8 = motionEvent.getX();
            float y8 = motionEvent.getY();
            int pointerId = motionEvent.getPointerId(0);
            l(x8, y8, pointerId);
            View viewG2 = g((int) x8, (int) y8);
            if (viewG2 == this.f6333r && this.f6317a == 2) {
                q(viewG2, pointerId);
            }
            int i = this.f6324h[pointerId];
        } else if (actionMasked == 1) {
            a();
        } else if (actionMasked != 2) {
            if (actionMasked != 3) {
                if (actionMasked == 5) {
                    int pointerId2 = motionEvent.getPointerId(actionIndex);
                    float x9 = motionEvent.getX(actionIndex);
                    float y9 = motionEvent.getY(actionIndex);
                    l(x9, y9, pointerId2);
                    int i5 = this.f6317a;
                    if (i5 == 0) {
                        int i8 = this.f6324h[pointerId2];
                    } else if (i5 == 2 && (viewG = g((int) x9, (int) y9)) == this.f6333r) {
                        q(viewG, pointerId2);
                    }
                } else if (actionMasked == 6) {
                    d(motionEvent.getPointerId(actionIndex));
                }
            }
        } else if (this.f6320d != null && this.f6321e != null) {
            int pointerCount = motionEvent.getPointerCount();
            for (int i9 = 0; i9 < pointerCount; i9++) {
                int pointerId3 = motionEvent.getPointerId(i9);
                if (i(pointerId3)) {
                    float x10 = motionEvent.getX(i9);
                    float y10 = motionEvent.getY(i9);
                    float f3 = x10 - this.f6320d[pointerId3];
                    float f7 = y10 - this.f6321e[pointerId3];
                    View viewG3 = g((int) x10, (int) y10);
                    boolean z8 = viewG3 != null && c(viewG3, f3, f7);
                    if (z8) {
                        int left = viewG3.getLeft();
                        X1 x12 = this.f6332q;
                        int iG = x12.g(viewG3, ((int) f3) + left);
                        int top = viewG3.getTop();
                        int iH = x12.h(viewG3, ((int) f7) + top);
                        int iQ = x12.q(viewG3);
                        int iR = x12.r();
                        if ((iQ == 0 || (iQ > 0 && iG == left)) && (iR == 0 || (iR > 0 && iH == top))) {
                            break;
                        }
                        Math.abs(f3);
                        Math.abs(f7);
                        int i10 = this.f6324h[pointerId3];
                        Math.abs(f7);
                        Math.abs(f3);
                        int i11 = this.f6324h[pointerId3];
                        Math.abs(f3);
                        Math.abs(f7);
                        int i12 = this.f6324h[pointerId3];
                        Math.abs(f7);
                        Math.abs(f3);
                        int i13 = this.f6324h[pointerId3];
                        if (this.f6317a == 1 || (z8 && q(viewG3, pointerId3))) {
                            break;
                        }
                    }
                }
            }
            m(motionEvent);
        }
        return this.f6317a == 1;
    }

    public final boolean q(View view, int i) {
        if (view == this.f6333r && this.f6319c == i) {
            return true;
        }
        if (view == null || !this.f6332q.N(view, i)) {
            return false;
        }
        this.f6319c = i;
        b(view, i);
        return true;
    }
}
