package d.j.b;

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.ViewGroup;
import android.view.animation.Interpolator;
import android.widget.OverScroller;
import d.h.j.y;
import java.util.Arrays;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicInteger;

/* JADX INFO: loaded from: classes.dex */
public class e {
    public static final Interpolator a = new a();

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

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

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

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

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

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

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

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

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

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

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

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

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    public float f2878o;

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

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public OverScroller f2880q;

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

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

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

    /* JADX INFO: renamed from: u, reason: collision with root package name */
    public final ViewGroup f2884u;

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

    /* JADX INFO: renamed from: v, reason: collision with root package name */
    public final Runnable f2885v = new b();

    public static class a implements Interpolator {
        @Override // android.animation.TimeInterpolator
        public float getInterpolation(float f2) {
            float f3 = f2 - 1.0f;
            return (f3 * f3 * f3 * f3 * f3) + 1.0f;
        }
    }

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

        @Override // java.lang.Runnable
        public void run() {
            e.this.s(0);
        }
    }

    public static abstract class c {
        public abstract int a(View view, int i2, int i3);

        public abstract int b(View view, int i2, int i3);

        public int c(View view) {
            return 0;
        }

        public int d(View view) {
            return 0;
        }

        public void e(View view, int i2) {
        }

        public abstract void f(int i2);

        public abstract void g(View view, int i2, int i3, int i4, int i5);

        public abstract void h(View view, float f2, float f3);

        public abstract boolean i(View view, int i2);
    }

    public e(Context context, ViewGroup viewGroup, c cVar) {
        if (cVar == null) {
            throw new IllegalArgumentException("Callback may not be null");
        }
        this.f2884u = viewGroup;
        this.f2881r = cVar;
        ViewConfiguration viewConfiguration = ViewConfiguration.get(context);
        this.f2879p = (int) ((context.getResources().getDisplayMetrics().density * 20.0f) + 0.5f);
        this.f2866c = viewConfiguration.getScaledTouchSlop();
        this.f2877n = viewConfiguration.getScaledMaximumFlingVelocity();
        this.f2878o = viewConfiguration.getScaledMinimumFlingVelocity();
        this.f2880q = new OverScroller(context, a);
    }

    public void a() {
        this.f2867d = -1;
        float[] fArr = this.f2868e;
        if (fArr != null) {
            Arrays.fill(fArr, 0.0f);
            Arrays.fill(this.f2869f, 0.0f);
            Arrays.fill(this.f2870g, 0.0f);
            Arrays.fill(this.f2871h, 0.0f);
            Arrays.fill(this.f2872i, 0);
            Arrays.fill(this.f2873j, 0);
            Arrays.fill(this.f2874k, 0);
            this.f2875l = 0;
        }
        VelocityTracker velocityTracker = this.f2876m;
        if (velocityTracker != null) {
            velocityTracker.recycle();
            this.f2876m = null;
        }
    }

    public void b(View view, int i2) {
        if (view.getParent() != this.f2884u) {
            StringBuilder sbF = g.a.a.a.a.F("captureChildView: parameter must be a descendant of the ViewDragHelper's tracked parent view (");
            sbF.append(this.f2884u);
            sbF.append(")");
            throw new IllegalArgumentException(sbF.toString());
        }
        this.f2882s = view;
        this.f2867d = i2;
        this.f2881r.e(view, i2);
        s(1);
    }

    public final boolean c(float f2, float f3, int i2, int i3) {
        float fAbs = Math.abs(f2);
        float fAbs2 = Math.abs(f3);
        if ((this.f2872i[i2] & i3) != i3 || (0 & i3) == 0 || (this.f2874k[i2] & i3) == i3 || (this.f2873j[i2] & i3) == i3) {
            return false;
        }
        int i4 = this.f2866c;
        if (fAbs <= i4 && fAbs2 <= i4) {
            return false;
        }
        if (fAbs < fAbs2 * 0.5f) {
            Objects.requireNonNull(this.f2881r);
        }
        return (this.f2873j[i2] & i3) == 0 && fAbs > ((float) this.f2866c);
    }

    public final boolean d(View view, float f2, float f3) {
        if (view == null) {
            return false;
        }
        boolean z2 = this.f2881r.c(view) > 0;
        boolean z3 = this.f2881r.d(view) > 0;
        if (!z2 || !z3) {
            return z2 ? Math.abs(f2) > ((float) this.f2866c) : z3 && Math.abs(f3) > ((float) this.f2866c);
        }
        float f4 = (f3 * f3) + (f2 * f2);
        int i2 = this.f2866c;
        return f4 > ((float) (i2 * i2));
    }

    public final float e(float f2, float f3, float f4) {
        float fAbs = Math.abs(f2);
        if (fAbs < f3) {
            return 0.0f;
        }
        return fAbs > f4 ? f2 > 0.0f ? f4 : -f4 : f2;
    }

    public final int f(int i2, int i3, int i4) {
        int iAbs = Math.abs(i2);
        if (iAbs < i3) {
            return 0;
        }
        return iAbs > i4 ? i2 > 0 ? i4 : -i4 : i2;
    }

    public final void g(int i2) {
        float[] fArr = this.f2868e;
        if (fArr != null) {
            int i3 = this.f2875l;
            int i4 = 1 << i2;
            if ((i4 & i3) != 0) {
                fArr[i2] = 0.0f;
                this.f2869f[i2] = 0.0f;
                this.f2870g[i2] = 0.0f;
                this.f2871h[i2] = 0.0f;
                this.f2872i[i2] = 0;
                this.f2873j[i2] = 0;
                this.f2874k[i2] = 0;
                this.f2875l = (~i4) & i3;
            }
        }
    }

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

    public boolean i(boolean z2) {
        if (this.f2865b == 2) {
            boolean zComputeScrollOffset = this.f2880q.computeScrollOffset();
            int currX = this.f2880q.getCurrX();
            int currY = this.f2880q.getCurrY();
            int left = currX - this.f2882s.getLeft();
            int top = currY - this.f2882s.getTop();
            if (left != 0) {
                View view = this.f2882s;
                AtomicInteger atomicInteger = y.a;
                view.offsetLeftAndRight(left);
            }
            if (top != 0) {
                View view2 = this.f2882s;
                AtomicInteger atomicInteger2 = y.a;
                view2.offsetTopAndBottom(top);
            }
            if (left != 0 || top != 0) {
                this.f2881r.g(this.f2882s, currX, currY, left, top);
            }
            if (zComputeScrollOffset && currX == this.f2880q.getFinalX() && currY == this.f2880q.getFinalY()) {
                this.f2880q.abortAnimation();
                zComputeScrollOffset = false;
            }
            if (!zComputeScrollOffset) {
                if (z2) {
                    this.f2884u.post(this.f2885v);
                } else {
                    s(0);
                }
            }
        }
        return this.f2865b == 2;
    }

    public final void j(float f2, float f3) {
        this.f2883t = true;
        this.f2881r.h(this.f2882s, f2, f3);
        this.f2883t = false;
        if (this.f2865b == 1) {
            s(0);
        }
    }

    public View k(int i2, int i3) {
        for (int childCount = this.f2884u.getChildCount() - 1; childCount >= 0; childCount--) {
            ViewGroup viewGroup = this.f2884u;
            Objects.requireNonNull(this.f2881r);
            View childAt = viewGroup.getChildAt(childCount);
            if (i2 >= childAt.getLeft() && i2 < childAt.getRight() && i3 >= childAt.getTop() && i3 < childAt.getBottom()) {
                return childAt;
            }
        }
        return null;
    }

    public final boolean l(int i2, int i3, int i4, int i5) {
        float f2;
        float f3;
        float f4;
        float f5;
        int left = this.f2882s.getLeft();
        int top = this.f2882s.getTop();
        int i6 = i2 - left;
        int i7 = i3 - top;
        if (i6 == 0 && i7 == 0) {
            this.f2880q.abortAnimation();
            s(0);
            return false;
        }
        View view = this.f2882s;
        int iF = f(i4, (int) this.f2878o, (int) this.f2877n);
        int iF2 = f(i5, (int) this.f2878o, (int) this.f2877n);
        int iAbs = Math.abs(i6);
        int iAbs2 = Math.abs(i7);
        int iAbs3 = Math.abs(iF);
        int iAbs4 = Math.abs(iF2);
        int i8 = iAbs3 + iAbs4;
        int i9 = iAbs + iAbs2;
        if (iF != 0) {
            f2 = iAbs3;
            f3 = i8;
        } else {
            f2 = iAbs;
            f3 = i9;
        }
        float f6 = f2 / f3;
        if (iF2 != 0) {
            f4 = iAbs4;
            f5 = i8;
        } else {
            f4 = iAbs2;
            f5 = i9;
        }
        int iH = h(i6, iF, this.f2881r.c(view));
        this.f2880q.startScroll(left, top, i6, i7, (int) ((h(i7, iF2, this.f2881r.d(view)) * (f4 / f5)) + (iH * f6)));
        s(2);
        return true;
    }

    public final boolean m(int i2) {
        if ((this.f2875l & (1 << i2)) != 0) {
            return true;
        }
        Log.e("ViewDragHelper", "Ignoring pointerId=" + i2 + " 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 void n(MotionEvent motionEvent) {
        int i2;
        int actionMasked = motionEvent.getActionMasked();
        int actionIndex = motionEvent.getActionIndex();
        if (actionMasked == 0) {
            a();
        }
        if (this.f2876m == null) {
            this.f2876m = VelocityTracker.obtain();
        }
        this.f2876m.addMovement(motionEvent);
        int i3 = 0;
        if (actionMasked != 0) {
            if (actionMasked != 1) {
                if (actionMasked == 2) {
                    if (this.f2865b != 1) {
                        int pointerCount = motionEvent.getPointerCount();
                        while (i3 < pointerCount) {
                            int pointerId = motionEvent.getPointerId(i3);
                            if (m(pointerId)) {
                                float x2 = motionEvent.getX(i3);
                                float y2 = motionEvent.getY(i3);
                                float f2 = x2 - this.f2868e[pointerId];
                                float f3 = y2 - this.f2869f[pointerId];
                                p(f2, f3, pointerId);
                                if (this.f2865b != 1) {
                                    View viewK = k((int) x2, (int) y2);
                                    if (d(viewK, f2, f3) && v(viewK, pointerId)) {
                                        break;
                                    }
                                } else {
                                    break;
                                }
                            }
                            i3++;
                        }
                    } else {
                        if (!m(this.f2867d)) {
                            return;
                        }
                        int iFindPointerIndex = motionEvent.findPointerIndex(this.f2867d);
                        float x3 = motionEvent.getX(iFindPointerIndex);
                        float y3 = motionEvent.getY(iFindPointerIndex);
                        float[] fArr = this.f2870g;
                        int i4 = this.f2867d;
                        int i5 = (int) (x3 - fArr[i4]);
                        int i6 = (int) (y3 - this.f2871h[i4]);
                        int left = this.f2882s.getLeft() + i5;
                        int top = this.f2882s.getTop() + i6;
                        int left2 = this.f2882s.getLeft();
                        int top2 = this.f2882s.getTop();
                        if (i5 != 0) {
                            left = this.f2881r.a(this.f2882s, left, i5);
                            AtomicInteger atomicInteger = y.a;
                            this.f2882s.offsetLeftAndRight(left - left2);
                        }
                        int i7 = left;
                        if (i6 != 0) {
                            top = this.f2881r.b(this.f2882s, top, i6);
                            AtomicInteger atomicInteger2 = y.a;
                            this.f2882s.offsetTopAndBottom(top - top2);
                        }
                        int i8 = top;
                        if (i5 != 0 || i6 != 0) {
                            this.f2881r.g(this.f2882s, i7, i8, i7 - left2, i8 - top2);
                        }
                    }
                    r(motionEvent);
                    return;
                }
                if (actionMasked != 3) {
                    if (actionMasked != 5) {
                        if (actionMasked != 6) {
                            return;
                        }
                        int pointerId2 = motionEvent.getPointerId(actionIndex);
                        if (this.f2865b == 1 && pointerId2 == this.f2867d) {
                            int pointerCount2 = motionEvent.getPointerCount();
                            while (true) {
                                if (i3 >= pointerCount2) {
                                    i2 = -1;
                                    break;
                                }
                                int pointerId3 = motionEvent.getPointerId(i3);
                                if (pointerId3 != this.f2867d) {
                                    View viewK2 = k((int) motionEvent.getX(i3), (int) motionEvent.getY(i3));
                                    View view = this.f2882s;
                                    if (viewK2 == view && v(view, pointerId3)) {
                                        i2 = this.f2867d;
                                        break;
                                    }
                                }
                                i3++;
                            }
                            if (i2 == -1) {
                                o();
                            }
                        }
                        g(pointerId2);
                        return;
                    }
                    int pointerId4 = motionEvent.getPointerId(actionIndex);
                    float x4 = motionEvent.getX(actionIndex);
                    float y4 = motionEvent.getY(actionIndex);
                    q(x4, y4, pointerId4);
                    if (this.f2865b != 0) {
                        int i9 = (int) x4;
                        int i10 = (int) y4;
                        View view2 = this.f2882s;
                        if (view2 != null && i9 >= view2.getLeft() && i9 < view2.getRight() && i10 >= view2.getTop() && i10 < view2.getBottom()) {
                            i3 = 1;
                        }
                        if (i3 != 0) {
                            v(this.f2882s, pointerId4);
                            return;
                        }
                        return;
                    }
                    v(k((int) x4, (int) y4), pointerId4);
                    if ((this.f2872i[pointerId4] & 0) == 0) {
                        return;
                    }
                } else if (this.f2865b == 1) {
                    j(0.0f, 0.0f);
                }
            } else if (this.f2865b == 1) {
                o();
            }
            a();
            return;
        }
        float x5 = motionEvent.getX();
        float y5 = motionEvent.getY();
        int pointerId5 = motionEvent.getPointerId(0);
        View viewK3 = k((int) x5, (int) y5);
        q(x5, y5, pointerId5);
        v(viewK3, pointerId5);
        if ((this.f2872i[pointerId5] & 0) == 0) {
            return;
        }
        Objects.requireNonNull(this.f2881r);
    }

    public final void o() {
        this.f2876m.computeCurrentVelocity(1000, this.f2877n);
        j(e(this.f2876m.getXVelocity(this.f2867d), this.f2878o, this.f2877n), e(this.f2876m.getYVelocity(this.f2867d), this.f2878o, this.f2877n));
    }

    public final void p(float f2, float f3, int i2) {
        int i3 = c(f2, f3, i2, 1) ? 1 : 0;
        if (c(f3, f2, i2, 4)) {
            i3 |= 4;
        }
        if (c(f2, f3, i2, 2)) {
            i3 |= 2;
        }
        if (c(f3, f2, i2, 8)) {
            i3 |= 8;
        }
        if (i3 != 0) {
            int[] iArr = this.f2873j;
            iArr[i2] = iArr[i2] | i3;
            Objects.requireNonNull(this.f2881r);
        }
    }

    public final void q(float f2, float f3, int i2) {
        float[] fArr = this.f2868e;
        if (fArr == null || fArr.length <= i2) {
            int i3 = i2 + 1;
            float[] fArr2 = new float[i3];
            float[] fArr3 = new float[i3];
            float[] fArr4 = new float[i3];
            float[] fArr5 = new float[i3];
            int[] iArr = new int[i3];
            int[] iArr2 = new int[i3];
            int[] iArr3 = new int[i3];
            if (fArr != null) {
                System.arraycopy(fArr, 0, fArr2, 0, fArr.length);
                float[] fArr6 = this.f2869f;
                System.arraycopy(fArr6, 0, fArr3, 0, fArr6.length);
                float[] fArr7 = this.f2870g;
                System.arraycopy(fArr7, 0, fArr4, 0, fArr7.length);
                float[] fArr8 = this.f2871h;
                System.arraycopy(fArr8, 0, fArr5, 0, fArr8.length);
                int[] iArr4 = this.f2872i;
                System.arraycopy(iArr4, 0, iArr, 0, iArr4.length);
                int[] iArr5 = this.f2873j;
                System.arraycopy(iArr5, 0, iArr2, 0, iArr5.length);
                int[] iArr6 = this.f2874k;
                System.arraycopy(iArr6, 0, iArr3, 0, iArr6.length);
            }
            this.f2868e = fArr2;
            this.f2869f = fArr3;
            this.f2870g = fArr4;
            this.f2871h = fArr5;
            this.f2872i = iArr;
            this.f2873j = iArr2;
            this.f2874k = iArr3;
        }
        float[] fArr9 = this.f2868e;
        this.f2870g[i2] = f2;
        fArr9[i2] = f2;
        float[] fArr10 = this.f2869f;
        this.f2871h[i2] = f3;
        fArr10[i2] = f3;
        int[] iArr7 = this.f2872i;
        int i4 = (int) f2;
        int i5 = (int) f3;
        int i6 = i4 < this.f2884u.getLeft() + this.f2879p ? 1 : 0;
        if (i5 < this.f2884u.getTop() + this.f2879p) {
            i6 |= 4;
        }
        if (i4 > this.f2884u.getRight() - this.f2879p) {
            i6 |= 2;
        }
        if (i5 > this.f2884u.getBottom() - this.f2879p) {
            i6 |= 8;
        }
        iArr7[i2] = i6;
        this.f2875l |= 1 << i2;
    }

    public final void r(MotionEvent motionEvent) {
        int pointerCount = motionEvent.getPointerCount();
        for (int i2 = 0; i2 < pointerCount; i2++) {
            int pointerId = motionEvent.getPointerId(i2);
            if (m(pointerId)) {
                float x2 = motionEvent.getX(i2);
                float y2 = motionEvent.getY(i2);
                this.f2870g[pointerId] = x2;
                this.f2871h[pointerId] = y2;
            }
        }
    }

    public void s(int i2) {
        this.f2884u.removeCallbacks(this.f2885v);
        if (this.f2865b != i2) {
            this.f2865b = i2;
            this.f2881r.f(i2);
            if (this.f2865b == 0) {
                this.f2882s = null;
            }
        }
    }

    public boolean t(int i2, int i3) {
        if (this.f2883t) {
            return l(i2, i3, (int) this.f2876m.getXVelocity(this.f2867d), (int) this.f2876m.getYVelocity(this.f2867d));
        }
        throw new IllegalStateException("Cannot settleCapturedViewAt outside of a call to Callback#onViewReleased");
    }

    /* JADX WARN: Removed duplicated region for block: B:54:0x00e6  */
    /* JADX WARN: Removed duplicated region for block: B:63:0x00ff  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public boolean u(android.view.MotionEvent r17) {
        /*
            Method dump skipped, instruction units count: 313
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: d.j.b.e.u(android.view.MotionEvent):boolean");
    }

    public boolean v(View view, int i2) {
        if (view == this.f2882s && this.f2867d == i2) {
            return true;
        }
        if (view == null || !this.f2881r.i(view, i2)) {
            return false;
        }
        this.f2867d = i2;
        b(view, i2);
        return true;
    }
}
