package c.h.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 c.f.l.t;
import com.cvte.vman.impl.FwUpgradeManager;
import java.util.Arrays;

/* JADX INFO: compiled from: ViewDragHelper.java */
/* JADX INFO: loaded from: classes.dex */
public class a {
    private static final Interpolator w = new InterpolatorC0037a();
    private int a;

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

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

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

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

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

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    private int[] f1516h;

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

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

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    private int f1519k;
    private VelocityTracker l;
    private float m;
    private float n;
    private int o;
    private int p;
    private OverScroller q;
    private final c r;
    private View s;
    private boolean t;
    private final ViewGroup u;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private int f1511c = -1;
    private final Runnable v = new b();

    /* JADX INFO: renamed from: c.h.b.a$a, reason: collision with other inner class name */
    /* JADX INFO: compiled from: ViewDragHelper.java */
    static class InterpolatorC0037a implements Interpolator {
        InterpolatorC0037a() {
        }

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

    /* JADX INFO: compiled from: ViewDragHelper.java */
    class b implements Runnable {
        b() {
        }

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

    /* JADX INFO: compiled from: ViewDragHelper.java */
    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(int i2) {
            return i2;
        }

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

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

        public void f(int i2, int i3) {
        }

        public boolean g(int i2) {
            return false;
        }

        public void h(int i2, int i3) {
        }

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

        public abstract void j(int i2);

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

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

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

    private a(Context context, ViewGroup viewGroup, c cVar) {
        if (viewGroup == null) {
            throw new IllegalArgumentException("Parent view may not be null");
        }
        if (cVar == null) {
            throw new IllegalArgumentException("Callback may not be null");
        }
        this.u = viewGroup;
        this.r = cVar;
        ViewConfiguration viewConfiguration = ViewConfiguration.get(context);
        this.o = (int) ((context.getResources().getDisplayMetrics().density * 20.0f) + 0.5f);
        this.f1510b = viewConfiguration.getScaledTouchSlop();
        this.m = viewConfiguration.getScaledMaximumFlingVelocity();
        this.n = viewConfiguration.getScaledMinimumFlingVelocity();
        this.q = new OverScroller(context, w);
    }

    private void A() {
        this.l.computeCurrentVelocity(FwUpgradeManager.TYPE_FW_CVTE_CAMERA, this.m);
        n(e(this.l.getXVelocity(this.f1511c), this.n, this.m), e(this.l.getYVelocity(this.f1511c), this.n, this.m));
    }

    private void B(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.f1517i;
            iArr[i2] = iArr[i2] | i3;
            this.r.f(i3, i2);
        }
    }

    private void C(float f2, float f3, int i2) {
        q(i2);
        float[] fArr = this.f1512d;
        this.f1514f[i2] = f2;
        fArr[i2] = f2;
        float[] fArr2 = this.f1513e;
        this.f1515g[i2] = f3;
        fArr2[i2] = f3;
        this.f1516h[i2] = t((int) f2, (int) f3);
        this.f1519k |= 1 << i2;
    }

    private void D(MotionEvent motionEvent) {
        int pointerCount = motionEvent.getPointerCount();
        for (int i2 = 0; i2 < pointerCount; i2++) {
            int pointerId = motionEvent.getPointerId(i2);
            if (x(pointerId)) {
                float x = motionEvent.getX(i2);
                float y = motionEvent.getY(i2);
                this.f1514f[pointerId] = x;
                this.f1515g[pointerId] = y;
            }
        }
    }

    private boolean c(float f2, float f3, int i2, int i3) {
        float fAbs = Math.abs(f2);
        float fAbs2 = Math.abs(f3);
        if ((this.f1516h[i2] & i3) != i3 || (this.p & i3) == 0 || (this.f1518j[i2] & i3) == i3 || (this.f1517i[i2] & i3) == i3) {
            return false;
        }
        int i4 = this.f1510b;
        if (fAbs <= i4 && fAbs2 <= i4) {
            return false;
        }
        if (fAbs >= fAbs2 * 0.5f || !this.r.g(i3)) {
            return (this.f1517i[i2] & i3) == 0 && fAbs > ((float) this.f1510b);
        }
        int[] iArr = this.f1518j;
        iArr[i2] = iArr[i2] | i3;
        return false;
    }

    private boolean d(View view, float f2, float f3) {
        if (view == null) {
            return false;
        }
        boolean z = this.r.d(view) > 0;
        boolean z2 = this.r.e(view) > 0;
        if (!z || !z2) {
            return z ? Math.abs(f2) > ((float) this.f1510b) : z2 && Math.abs(f3) > ((float) this.f1510b);
        }
        float f4 = (f2 * f2) + (f3 * f3);
        int i2 = this.f1510b;
        return f4 > ((float) (i2 * i2));
    }

    private 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;
    }

    private 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;
    }

    private void g() {
        float[] fArr = this.f1512d;
        if (fArr == null) {
            return;
        }
        Arrays.fill(fArr, 0.0f);
        Arrays.fill(this.f1513e, 0.0f);
        Arrays.fill(this.f1514f, 0.0f);
        Arrays.fill(this.f1515g, 0.0f);
        Arrays.fill(this.f1516h, 0);
        Arrays.fill(this.f1517i, 0);
        Arrays.fill(this.f1518j, 0);
        this.f1519k = 0;
    }

    private void h(int i2) {
        if (this.f1512d == null || !w(i2)) {
            return;
        }
        this.f1512d[i2] = 0.0f;
        this.f1513e[i2] = 0.0f;
        this.f1514f[i2] = 0.0f;
        this.f1515g[i2] = 0.0f;
        this.f1516h[i2] = 0;
        this.f1517i[i2] = 0;
        this.f1518j[i2] = 0;
        this.f1519k = (~(1 << i2)) & this.f1519k;
    }

    private int i(int i2, int i3, int i4) {
        if (i2 == 0) {
            return 0;
        }
        int width = this.u.getWidth();
        float f2 = width / 2;
        float fO = f2 + (o(Math.min(1.0f, Math.abs(i2) / width)) * f2);
        int iAbs = Math.abs(i3);
        return Math.min(iAbs > 0 ? Math.round(Math.abs(fO / iAbs) * 1000.0f) * 4 : (int) (((Math.abs(i2) / i4) + 1.0f) * 256.0f), 600);
    }

    private int j(View view, int i2, int i3, int i4, int i5) {
        float f2;
        float f3;
        float f4;
        float f5;
        int iF = f(i4, (int) this.n, (int) this.m);
        int iF2 = f(i5, (int) this.n, (int) this.m);
        int iAbs = Math.abs(i2);
        int iAbs2 = Math.abs(i3);
        int iAbs3 = Math.abs(iF);
        int iAbs4 = Math.abs(iF2);
        int i6 = iAbs3 + iAbs4;
        int i7 = iAbs + iAbs2;
        if (iF != 0) {
            f2 = iAbs3;
            f3 = i6;
        } else {
            f2 = iAbs;
            f3 = i7;
        }
        float f6 = f2 / f3;
        if (iF2 != 0) {
            f4 = iAbs4;
            f5 = i6;
        } else {
            f4 = iAbs2;
            f5 = i7;
        }
        return (int) ((i(i2, iF, this.r.d(view)) * f6) + (i(i3, iF2, this.r.e(view)) * (f4 / f5)));
    }

    public static a l(ViewGroup viewGroup, float f2, c cVar) {
        a aVarM = m(viewGroup, cVar);
        aVarM.f1510b = (int) (aVarM.f1510b * (1.0f / f2));
        return aVarM;
    }

    public static a m(ViewGroup viewGroup, c cVar) {
        return new a(viewGroup.getContext(), viewGroup, cVar);
    }

    private void n(float f2, float f3) {
        this.t = true;
        this.r.l(this.s, f2, f3);
        this.t = false;
        if (this.a == 1) {
            E(0);
        }
    }

    private float o(float f2) {
        return (float) Math.sin((f2 - 0.5f) * 0.47123894f);
    }

    private void p(int i2, int i3, int i4, int i5) {
        int left = this.s.getLeft();
        int top = this.s.getTop();
        if (i4 != 0) {
            i2 = this.r.a(this.s, i2, i4);
            t.M(this.s, i2 - left);
        }
        int i6 = i2;
        if (i5 != 0) {
            i3 = this.r.b(this.s, i3, i5);
            t.N(this.s, i3 - top);
        }
        int i7 = i3;
        if (i4 == 0 && i5 == 0) {
            return;
        }
        this.r.k(this.s, i6, i7, i6 - left, i7 - top);
    }

    private void q(int i2) {
        float[] fArr = this.f1512d;
        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];
            float[] fArr6 = this.f1512d;
            if (fArr6 != null) {
                System.arraycopy(fArr6, 0, fArr2, 0, fArr6.length);
                float[] fArr7 = this.f1513e;
                System.arraycopy(fArr7, 0, fArr3, 0, fArr7.length);
                float[] fArr8 = this.f1514f;
                System.arraycopy(fArr8, 0, fArr4, 0, fArr8.length);
                float[] fArr9 = this.f1515g;
                System.arraycopy(fArr9, 0, fArr5, 0, fArr9.length);
                int[] iArr4 = this.f1516h;
                System.arraycopy(iArr4, 0, iArr, 0, iArr4.length);
                int[] iArr5 = this.f1517i;
                System.arraycopy(iArr5, 0, iArr2, 0, iArr5.length);
                int[] iArr6 = this.f1518j;
                System.arraycopy(iArr6, 0, iArr3, 0, iArr6.length);
            }
            this.f1512d = fArr2;
            this.f1513e = fArr3;
            this.f1514f = fArr4;
            this.f1515g = fArr5;
            this.f1516h = iArr;
            this.f1517i = iArr2;
            this.f1518j = iArr3;
        }
    }

    private boolean s(int i2, int i3, int i4, int i5) {
        int left = this.s.getLeft();
        int top = this.s.getTop();
        int i6 = i2 - left;
        int i7 = i3 - top;
        if (i6 == 0 && i7 == 0) {
            this.q.abortAnimation();
            E(0);
            return false;
        }
        this.q.startScroll(left, top, i6, i7, j(this.s, i6, i7, i4, i5));
        E(2);
        return true;
    }

    private int t(int i2, int i3) {
        int i4 = i2 < this.u.getLeft() + this.o ? 1 : 0;
        if (i3 < this.u.getTop() + this.o) {
            i4 |= 4;
        }
        if (i2 > this.u.getRight() - this.o) {
            i4 |= 2;
        }
        return i3 > this.u.getBottom() - this.o ? i4 | 8 : i4;
    }

    private boolean x(int i2) {
        if (w(i2)) {
            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;
    }

    void E(int i2) {
        this.u.removeCallbacks(this.v);
        if (this.a != i2) {
            this.a = i2;
            this.r.j(i2);
            if (this.a == 0) {
                this.s = null;
            }
        }
    }

    public boolean F(int i2, int i3) {
        if (this.t) {
            return s(i2, i3, (int) this.l.getXVelocity(this.f1511c), (int) this.l.getYVelocity(this.f1511c));
        }
        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 G(android.view.MotionEvent r17) {
        /*
            Method dump skipped, instruction units count: 315
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: c.h.b.a.G(android.view.MotionEvent):boolean");
    }

    public boolean H(View view, int i2, int i3) {
        this.s = view;
        this.f1511c = -1;
        boolean zS = s(i2, i3, 0, 0);
        if (!zS && this.a == 0 && this.s != null) {
            this.s = null;
        }
        return zS;
    }

    boolean I(View view, int i2) {
        if (view == this.s && this.f1511c == i2) {
            return true;
        }
        if (view == null || !this.r.m(view, i2)) {
            return false;
        }
        this.f1511c = i2;
        b(view, i2);
        return true;
    }

    public void a() {
        this.f1511c = -1;
        g();
        VelocityTracker velocityTracker = this.l;
        if (velocityTracker != null) {
            velocityTracker.recycle();
            this.l = null;
        }
    }

    public void b(View view, int i2) {
        if (view.getParent() == this.u) {
            this.s = view;
            this.f1511c = i2;
            this.r.i(view, i2);
            E(1);
            return;
        }
        throw new IllegalArgumentException("captureChildView: parameter must be a descendant of the ViewDragHelper's tracked parent view (" + this.u + ")");
    }

    public boolean k(boolean z) {
        if (this.a == 2) {
            boolean zComputeScrollOffset = this.q.computeScrollOffset();
            int currX = this.q.getCurrX();
            int currY = this.q.getCurrY();
            int left = currX - this.s.getLeft();
            int top = currY - this.s.getTop();
            if (left != 0) {
                t.M(this.s, left);
            }
            if (top != 0) {
                t.N(this.s, top);
            }
            if (left != 0 || top != 0) {
                this.r.k(this.s, currX, currY, left, top);
            }
            if (zComputeScrollOffset && currX == this.q.getFinalX() && currY == this.q.getFinalY()) {
                this.q.abortAnimation();
                zComputeScrollOffset = false;
            }
            if (!zComputeScrollOffset) {
                if (z) {
                    this.u.post(this.v);
                } else {
                    E(0);
                }
            }
        }
        return this.a == 2;
    }

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

    public int u() {
        return this.f1510b;
    }

    public boolean v(int i2, int i3) {
        return y(this.s, i2, i3);
    }

    public boolean w(int i2) {
        return ((1 << i2) & this.f1519k) != 0;
    }

    public boolean y(View view, int i2, int i3) {
        return view != null && i2 >= view.getLeft() && i2 < view.getRight() && i3 >= view.getTop() && i3 < view.getBottom();
    }

    public void z(MotionEvent motionEvent) {
        int i2;
        int actionMasked = motionEvent.getActionMasked();
        int actionIndex = motionEvent.getActionIndex();
        if (actionMasked == 0) {
            a();
        }
        if (this.l == null) {
            this.l = VelocityTracker.obtain();
        }
        this.l.addMovement(motionEvent);
        int i3 = 0;
        if (actionMasked == 0) {
            float x = motionEvent.getX();
            float y = motionEvent.getY();
            int pointerId = motionEvent.getPointerId(0);
            View viewR = r((int) x, (int) y);
            C(x, y, pointerId);
            I(viewR, pointerId);
            int i4 = this.f1516h[pointerId];
            int i5 = this.p;
            if ((i4 & i5) != 0) {
                this.r.h(i4 & i5, pointerId);
                return;
            }
            return;
        }
        if (actionMasked == 1) {
            if (this.a == 1) {
                A();
            }
            a();
            return;
        }
        if (actionMasked == 2) {
            if (this.a == 1) {
                if (x(this.f1511c)) {
                    int iFindPointerIndex = motionEvent.findPointerIndex(this.f1511c);
                    float x2 = motionEvent.getX(iFindPointerIndex);
                    float y2 = motionEvent.getY(iFindPointerIndex);
                    float[] fArr = this.f1514f;
                    int i6 = this.f1511c;
                    int i7 = (int) (x2 - fArr[i6]);
                    int i8 = (int) (y2 - this.f1515g[i6]);
                    p(this.s.getLeft() + i7, this.s.getTop() + i8, i7, i8);
                    D(motionEvent);
                    return;
                }
                return;
            }
            int pointerCount = motionEvent.getPointerCount();
            while (i3 < pointerCount) {
                int pointerId2 = motionEvent.getPointerId(i3);
                if (x(pointerId2)) {
                    float x3 = motionEvent.getX(i3);
                    float y3 = motionEvent.getY(i3);
                    float f2 = x3 - this.f1512d[pointerId2];
                    float f3 = y3 - this.f1513e[pointerId2];
                    B(f2, f3, pointerId2);
                    if (this.a != 1) {
                        View viewR2 = r((int) x3, (int) y3);
                        if (d(viewR2, f2, f3) && I(viewR2, pointerId2)) {
                            break;
                        }
                    } else {
                        break;
                    }
                }
                i3++;
            }
            D(motionEvent);
            return;
        }
        if (actionMasked == 3) {
            if (this.a == 1) {
                n(0.0f, 0.0f);
            }
            a();
            return;
        }
        if (actionMasked == 5) {
            int pointerId3 = motionEvent.getPointerId(actionIndex);
            float x4 = motionEvent.getX(actionIndex);
            float y4 = motionEvent.getY(actionIndex);
            C(x4, y4, pointerId3);
            if (this.a != 0) {
                if (v((int) x4, (int) y4)) {
                    I(this.s, pointerId3);
                    return;
                }
                return;
            } else {
                I(r((int) x4, (int) y4), pointerId3);
                int i9 = this.f1516h[pointerId3];
                int i10 = this.p;
                if ((i9 & i10) != 0) {
                    this.r.h(i9 & i10, pointerId3);
                    return;
                }
                return;
            }
        }
        if (actionMasked != 6) {
            return;
        }
        int pointerId4 = motionEvent.getPointerId(actionIndex);
        if (this.a == 1 && pointerId4 == this.f1511c) {
            int pointerCount2 = motionEvent.getPointerCount();
            while (true) {
                if (i3 >= pointerCount2) {
                    i2 = -1;
                    break;
                }
                int pointerId5 = motionEvent.getPointerId(i3);
                if (pointerId5 != this.f1511c) {
                    View viewR3 = r((int) motionEvent.getX(i3), (int) motionEvent.getY(i3));
                    View view = this.s;
                    if (viewR3 == view && I(view, pointerId5)) {
                        i2 = this.f1511c;
                        break;
                    }
                }
                i3++;
            }
            if (i2 == -1) {
                A();
            }
        }
        h(pointerId4);
    }
}
