package androidx.customview.widget; 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 androidx.core.view.ViewCompat; import java.util.Arrays; /* loaded from: classes.dex */ public class ViewDragHelper { private static final Interpolator w = new Interpolator() { // from class: androidx.customview.widget.ViewDragHelper.1 @Override // android.animation.TimeInterpolator public float getInterpolation(float f) { float f2 = f - 1.0f; return (f2 * f2 * f2 * f2 * f2) + 1.0f; } }; private int a; private int b; private float[] d; private float[] e; private float[] f; private float[] g; private int[] h; private int[] i; private int[] j; private int k; private VelocityTracker l; private float m; private float n; private int o; private int p; private OverScroller q; private final Callback r; private View s; private boolean t; private final ViewGroup u; private int c = -1; private final Runnable v = new Runnable() { // from class: androidx.customview.widget.ViewDragHelper.2 @Override // java.lang.Runnable public void run() { ViewDragHelper.this.b(0); } }; public static abstract class Callback { public int a(int i) { return i; } public int a(View view) { return 0; } public abstract int a(View view, int i, int i2); public void a(int i, int i2) { } public void a(View view, float f, float f2) { } public void a(View view, int i) { } public abstract void a(View view, int i, int i2, int i3, int i4); public int b(View view) { return 0; } public abstract int b(View view, int i, int i2); public void b(int i, int i2) { } public boolean b(int i) { return false; } public abstract boolean b(View view, int i); public void c(int i) { } } private ViewDragHelper(Context context, ViewGroup viewGroup, Callback callback) { if (viewGroup == null) { throw new IllegalArgumentException("Parent view may not be null"); } if (callback == null) { throw new IllegalArgumentException("Callback may not be null"); } this.u = viewGroup; this.r = callback; ViewConfiguration viewConfiguration = ViewConfiguration.get(context); this.o = (int) ((context.getResources().getDisplayMetrics().density * 20.0f) + 0.5f); this.b = viewConfiguration.getScaledTouchSlop(); this.m = viewConfiguration.getScaledMaximumFlingVelocity(); this.n = viewConfiguration.getScaledMinimumFlingVelocity(); this.q = new OverScroller(context, w); } public static ViewDragHelper a(ViewGroup viewGroup, Callback callback) { return new ViewDragHelper(viewGroup.getContext(), viewGroup, callback); } private void d() { float[] fArr = this.d; if (fArr == null) { return; } Arrays.fill(fArr, 0.0f); Arrays.fill(this.e, 0.0f); Arrays.fill(this.f, 0.0f); Arrays.fill(this.g, 0.0f); Arrays.fill(this.h, 0); Arrays.fill(this.i, 0); Arrays.fill(this.j, 0); this.k = 0; } private void e() { this.l.computeCurrentVelocity(1000, this.m); a(a(this.l.getXVelocity(this.c), this.n, this.m), a(this.l.getYVelocity(this.c), this.n, this.m)); } public float b() { return this.n; } public int c() { return this.b; } public static ViewDragHelper a(ViewGroup viewGroup, float f, Callback callback) { ViewDragHelper a = a(viewGroup, callback); a.b = (int) (a.b * (1.0f / f)); return a; } public boolean b(View view, int i, int i2) { this.s = view; this.c = -1; boolean b = b(i, i2, 0, 0); if (!b && this.a == 0 && this.s != null) { this.s = null; } return b; } public boolean c(int i, int i2) { if (this.t) { return b(i, i2, (int) this.l.getXVelocity(this.c), (int) this.l.getYVelocity(this.c)); } throw new IllegalStateException("Cannot settleCapturedViewAt outside of a call to Callback#onViewReleased"); } public void a(View view, int i) { if (view.getParent() == this.u) { this.s = view; this.c = i; this.r.a(view, i); b(1); return; } throw new IllegalArgumentException("captureChildView: parameter must be a descendant of the ViewDragHelper's tracked parent view (" + this.u + ")"); } private boolean b(int i, int i2, int i3, int i4) { int left = this.s.getLeft(); int top = this.s.getTop(); int i5 = i - left; int i6 = i2 - top; if (i5 == 0 && i6 == 0) { this.q.abortAnimation(); b(0); return false; } this.q.startScroll(left, top, i5, i6, a(this.s, i5, i6, i3, i4)); b(2); return true; } private void c(int i) { if (this.d == null || !a(i)) { return; } this.d[i] = 0.0f; this.e[i] = 0.0f; this.f[i] = 0.0f; this.g[i] = 0.0f; this.h[i] = 0; this.i[i] = 0; this.j[i] = 0; this.k = (~(1 << i)) & this.k; } private boolean e(int i) { if (a(i)) { 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; } private void d(int i) { float[] fArr = this.d; if (fArr == null || fArr.length <= i) { int i2 = i + 1; float[] fArr2 = new float[i2]; float[] fArr3 = new float[i2]; float[] fArr4 = new float[i2]; float[] fArr5 = new float[i2]; int[] iArr = new int[i2]; int[] iArr2 = new int[i2]; int[] iArr3 = new int[i2]; float[] fArr6 = this.d; if (fArr6 != null) { System.arraycopy(fArr6, 0, fArr2, 0, fArr6.length); float[] fArr7 = this.e; System.arraycopy(fArr7, 0, fArr3, 0, fArr7.length); float[] fArr8 = this.f; System.arraycopy(fArr8, 0, fArr4, 0, fArr8.length); float[] fArr9 = this.g; System.arraycopy(fArr9, 0, fArr5, 0, fArr9.length); int[] iArr4 = this.h; System.arraycopy(iArr4, 0, iArr, 0, iArr4.length); int[] iArr5 = this.i; System.arraycopy(iArr5, 0, iArr2, 0, iArr5.length); int[] iArr6 = this.j; System.arraycopy(iArr6, 0, iArr3, 0, iArr6.length); } this.d = fArr2; this.e = fArr3; this.f = fArr4; this.g = fArr5; this.h = iArr; this.i = iArr2; this.j = iArr3; } } public void a() { this.c = -1; d(); VelocityTracker velocityTracker = this.l; if (velocityTracker != null) { velocityTracker.recycle(); this.l = null; } } private int b(int i, int i2, int i3) { int abs; if (i == 0) { return 0; } int width = this.u.getWidth(); float f = width / 2; float a = f + (a(Math.min(1.0f, Math.abs(i) / width)) * f); int abs2 = Math.abs(i2); if (abs2 > 0) { abs = Math.round(Math.abs(a / abs2) * 1000.0f) * 4; } else { abs = (int) (((Math.abs(i) / i3) + 1.0f) * 256.0f); } return Math.min(abs, 600); } private int a(View view, int i, int i2, int i3, int i4) { float f; float f2; float f3; float f4; int a = a(i3, (int) this.n, (int) this.m); int a2 = a(i4, (int) this.n, (int) this.m); int abs = Math.abs(i); int abs2 = Math.abs(i2); int abs3 = Math.abs(a); int abs4 = Math.abs(a2); int i5 = abs3 + abs4; int i6 = abs + abs2; if (a != 0) { f = abs3; f2 = i5; } else { f = abs; f2 = i6; } float f5 = f / f2; if (a2 != 0) { f3 = abs4; f4 = i5; } else { f3 = abs2; f4 = i6; } return (int) ((b(i, a, this.r.a(view)) * f5) + (b(i2, a2, this.r.b(view)) * (f3 / f4))); } private void c(MotionEvent motionEvent) { int pointerCount = motionEvent.getPointerCount(); for (int i = 0; i < pointerCount; i++) { int pointerId = motionEvent.getPointerId(i); if (e(pointerId)) { float x = motionEvent.getX(i); float y = motionEvent.getY(i); this.f[pointerId] = x; this.g[pointerId] = y; } } } private void b(float f, float f2, int i) { d(i); float[] fArr = this.d; this.f[i] = f; fArr[i] = f; float[] fArr2 = this.e; this.g[i] = f2; fArr2[i] = f2; this.h[i] = d((int) f, (int) f2); this.k |= 1 << i; } private int a(int i, int i2, int i3) { int abs = Math.abs(i); if (abs < i2) { return 0; } return abs > i3 ? i > 0 ? i3 : -i3 : i; } private float a(float f, float f2, float f3) { float abs = Math.abs(f); if (abs < f2) { return 0.0f; } return abs > f3 ? f > 0.0f ? f3 : -f3 : f; } private float a(float f) { return (float) Math.sin((f - 0.5f) * 0.47123894f); } public boolean a(boolean z) { if (this.a == 2) { boolean computeScrollOffset = 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) { ViewCompat.c(this.s, left); } if (top != 0) { ViewCompat.d(this.s, top); } if (left != 0 || top != 0) { this.r.a(this.s, currX, currY, left, top); } if (computeScrollOffset && currX == this.q.getFinalX() && currY == this.q.getFinalY()) { this.q.abortAnimation(); computeScrollOffset = false; } if (!computeScrollOffset) { if (z) { this.u.post(this.v); } else { b(0); } } } return this.a == 2; } void b(int i) { this.u.removeCallbacks(this.v); if (this.a != i) { this.a = i; this.r.c(i); if (this.a == 0) { this.s = null; } } } private int d(int i, int i2) { int i3 = i < this.u.getLeft() + this.o ? 1 : 0; if (i2 < this.u.getTop() + this.o) { i3 |= 4; } if (i > this.u.getRight() - this.o) { i3 |= 2; } return i2 > this.u.getBottom() - this.o ? i3 | 8 : i3; } boolean b(View view, int i) { if (view == this.s && this.c == i) { return true; } if (view == null || !this.r.b(view, i)) { return false; } this.c = i; a(view, i); return true; } /* JADX WARN: Code restructure failed: missing block: B:50:0x00dd, code lost: if (r12 != r11) goto L54; */ /* Code decompiled incorrectly, please refer to instructions dump. To view partially-correct code enable 'Show inconsistent code' option in preferences */ public boolean b(android.view.MotionEvent r17) { /* Method dump skipped, instructions count: 315 To view this dump change 'Code comments level' option to 'DEBUG' */ throw new UnsupportedOperationException("Method not decompiled: androidx.customview.widget.ViewDragHelper.b(android.view.MotionEvent):boolean"); } private void a(float f, float f2) { this.t = true; this.r.a(this.s, f, f2); this.t = false; if (this.a == 1) { b(0); } } public boolean a(int i) { return ((1 << i) & this.k) != 0; } public void a(MotionEvent motionEvent) { int i; 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 i2 = 0; if (actionMasked == 0) { float x = motionEvent.getX(); float y = motionEvent.getY(); int pointerId = motionEvent.getPointerId(0); View a = a((int) x, (int) y); b(x, y, pointerId); b(a, pointerId); int i3 = this.h[pointerId]; int i4 = this.p; if ((i3 & i4) != 0) { this.r.b(i3 & i4, pointerId); return; } return; } if (actionMasked == 1) { if (this.a == 1) { e(); } a(); return; } if (actionMasked == 2) { if (this.a == 1) { if (e(this.c)) { int findPointerIndex = motionEvent.findPointerIndex(this.c); float x2 = motionEvent.getX(findPointerIndex); float y2 = motionEvent.getY(findPointerIndex); float[] fArr = this.f; int i5 = this.c; int i6 = (int) (x2 - fArr[i5]); int i7 = (int) (y2 - this.g[i5]); a(this.s.getLeft() + i6, this.s.getTop() + i7, i6, i7); c(motionEvent); return; } return; } int pointerCount = motionEvent.getPointerCount(); while (i2 < pointerCount) { int pointerId2 = motionEvent.getPointerId(i2); if (e(pointerId2)) { float x3 = motionEvent.getX(i2); float y3 = motionEvent.getY(i2); float f = x3 - this.d[pointerId2]; float f2 = y3 - this.e[pointerId2]; a(f, f2, pointerId2); if (this.a != 1) { View a2 = a((int) x3, (int) y3); if (a(a2, f, f2) && b(a2, pointerId2)) { break; } } else { break; } } i2++; } c(motionEvent); return; } if (actionMasked == 3) { if (this.a == 1) { a(0.0f, 0.0f); } a(); return; } if (actionMasked == 5) { int pointerId3 = motionEvent.getPointerId(actionIndex); float x4 = motionEvent.getX(actionIndex); float y4 = motionEvent.getY(actionIndex); b(x4, y4, pointerId3); if (this.a == 0) { b(a((int) x4, (int) y4), pointerId3); int i8 = this.h[pointerId3]; int i9 = this.p; if ((i8 & i9) != 0) { this.r.b(i8 & i9, pointerId3); return; } return; } if (b((int) x4, (int) y4)) { b(this.s, pointerId3); return; } return; } if (actionMasked != 6) { return; } int pointerId4 = motionEvent.getPointerId(actionIndex); if (this.a == 1 && pointerId4 == this.c) { int pointerCount2 = motionEvent.getPointerCount(); while (true) { if (i2 >= pointerCount2) { i = -1; break; } int pointerId5 = motionEvent.getPointerId(i2); if (pointerId5 != this.c) { View a3 = a((int) motionEvent.getX(i2), (int) motionEvent.getY(i2)); View view = this.s; if (a3 == view && b(view, pointerId5)) { i = this.c; break; } } i2++; } if (i == -1) { e(); } } c(pointerId4); } public boolean b(int i, int i2) { return a(this.s, i, i2); } private void a(float f, float f2, int i) { int i2 = a(f, f2, i, 1) ? 1 : 0; if (a(f2, f, i, 4)) { i2 |= 4; } if (a(f, f2, i, 2)) { i2 |= 2; } if (a(f2, f, i, 8)) { i2 |= 8; } if (i2 != 0) { int[] iArr = this.i; iArr[i] = iArr[i] | i2; this.r.a(i2, i); } } private boolean a(float f, float f2, int i, int i2) { float abs = Math.abs(f); float abs2 = Math.abs(f2); if ((this.h[i] & i2) != i2 || (this.p & i2) == 0 || (this.j[i] & i2) == i2 || (this.i[i] & i2) == i2) { return false; } int i3 = this.b; if (abs <= i3 && abs2 <= i3) { return false; } if (abs >= abs2 * 0.5f || !this.r.b(i2)) { return (this.i[i] & i2) == 0 && abs > ((float) this.b); } int[] iArr = this.j; iArr[i] = iArr[i] | i2; return false; } private boolean a(View view, float f, float f2) { if (view == null) { return false; } boolean z = this.r.a(view) > 0; boolean z2 = this.r.b(view) > 0; if (!z || !z2) { return z ? Math.abs(f) > ((float) this.b) : z2 && Math.abs(f2) > ((float) this.b); } float f3 = (f * f) + (f2 * f2); int i = this.b; return f3 > ((float) (i * i)); } private void a(int i, int i2, int i3, int i4) { int left = this.s.getLeft(); int top = this.s.getTop(); if (i3 != 0) { i = this.r.a(this.s, i, i3); ViewCompat.c(this.s, i - left); } int i5 = i; if (i4 != 0) { i2 = this.r.b(this.s, i2, i4); ViewCompat.d(this.s, i2 - top); } int i6 = i2; if (i3 == 0 && i4 == 0) { return; } this.r.a(this.s, i5, i6, i5 - left, i6 - top); } public boolean a(View view, int i, int i2) { return view != null && i >= view.getLeft() && i < view.getRight() && i2 >= view.getTop() && i2 < view.getBottom(); } public View a(int i, int i2) { for (int childCount = this.u.getChildCount() - 1; childCount >= 0; childCount--) { ViewGroup viewGroup = this.u; this.r.a(childCount); View childAt = viewGroup.getChildAt(childCount); if (i >= childAt.getLeft() && i < childAt.getRight() && i2 >= childAt.getTop() && i2 < childAt.getBottom()) { return childAt; } } return null; } }