package c.p.a; import android.animation.Animator; import android.animation.AnimatorListenerAdapter; import android.animation.ValueAnimator; import android.content.Context; import android.view.MotionEvent; import android.view.VelocityTracker; import android.view.View; import android.view.ViewConfiguration; import android.view.ViewGroup; import androidx.annotation.RequiresApi; import d0.z.d.m; /* compiled from: SwipeDismissTouchListener.kt */ public final class l implements View.OnTouchListener { public final int i; public final int j; public final long k; public int l = 1; public float m; public float n; public boolean o; public int p; public VelocityTracker q; public float r; /* renamed from: s reason: collision with root package name */ public final View f1520s; public final a t; /* compiled from: SwipeDismissTouchListener.kt */ public interface a { void a(View view, boolean z2); boolean b(); void onDismiss(View view); } /* compiled from: SwipeDismissTouchListener.kt */ public static final class b extends AnimatorListenerAdapter { public final /* synthetic */ l a; public b(l lVar, MotionEvent motionEvent, View view) { this.a = lVar; } @Override // android.animation.AnimatorListenerAdapter, android.animation.Animator.AnimatorListener public void onAnimationEnd(Animator animator) { m.checkNotNullParameter(animator, "animation"); l lVar = this.a; ViewGroup.LayoutParams layoutParams = lVar.f1520s.getLayoutParams(); int height = lVar.f1520s.getHeight(); ValueAnimator duration = ValueAnimator.ofInt(height, 1).setDuration(lVar.k); duration.addListener(new m(lVar, layoutParams, height)); duration.addUpdateListener(new n(lVar, layoutParams)); duration.start(); } } public l(View view, a aVar) { m.checkNotNullParameter(view, "mView"); m.checkNotNullParameter(aVar, "mCallbacks"); this.f1520s = view; this.t = aVar; ViewConfiguration viewConfiguration = ViewConfiguration.get(view.getContext()); m.checkNotNullExpressionValue(viewConfiguration, "vc"); this.i = viewConfiguration.getScaledTouchSlop(); this.j = viewConfiguration.getScaledMinimumFlingVelocity() * 16; Context context = view.getContext(); m.checkNotNullExpressionValue(context, "mView.context"); this.k = (long) context.getResources().getInteger(17694720); } @Override // android.view.View.OnTouchListener @RequiresApi(api = 12) public boolean onTouch(View view, MotionEvent motionEvent) { boolean z2; m.checkNotNullParameter(view, "view"); m.checkNotNullParameter(motionEvent, "motionEvent"); motionEvent.offsetLocation(this.r, 0.0f); if (this.l < 2) { this.l = this.f1520s.getWidth(); } int actionMasked = motionEvent.getActionMasked(); boolean z3 = true; if (actionMasked != 0) { if (actionMasked == 1) { VelocityTracker velocityTracker = this.q; if (velocityTracker != null) { float rawX = motionEvent.getRawX() - this.m; velocityTracker.addMovement(motionEvent); velocityTracker.computeCurrentVelocity(1000); float xVelocity = velocityTracker.getXVelocity(); float abs = Math.abs(xVelocity); float abs2 = Math.abs(velocityTracker.getYVelocity()); if (Math.abs(rawX) > ((float) (this.l / 2)) && this.o) { z2 = rawX > ((float) 0); } else if (((float) this.j) > abs || abs2 >= abs || !this.o) { z2 = false; z3 = false; } else { float f = (float) 0; boolean z4 = ((xVelocity > f ? 1 : (xVelocity == f ? 0 : -1)) < 0) == ((rawX > f ? 1 : (rawX == f ? 0 : -1)) < 0); if (velocityTracker.getXVelocity() <= f) { z3 = false; } z2 = z3; z3 = z4; } if (z3) { this.f1520s.animate().translationX((float) (z2 ? this.l : -this.l)).alpha(0.0f).setDuration(this.k).setListener(new b(this, motionEvent, view)); } else if (this.o) { this.f1520s.animate().translationX(0.0f).alpha(1.0f).setDuration(this.k).setListener(null); this.t.a(view, false); } velocityTracker.recycle(); this.q = null; this.r = 0.0f; this.m = 0.0f; this.n = 0.0f; this.o = false; } } else if (actionMasked == 2) { VelocityTracker velocityTracker2 = this.q; if (velocityTracker2 != null) { velocityTracker2.addMovement(motionEvent); float rawX2 = motionEvent.getRawX() - this.m; float rawY = motionEvent.getRawY() - this.n; if (Math.abs(rawX2) > ((float) this.i) && Math.abs(rawY) < Math.abs(rawX2) / ((float) 2)) { this.o = true; this.p = rawX2 > ((float) 0) ? this.i : -this.i; this.f1520s.getParent().requestDisallowInterceptTouchEvent(true); MotionEvent obtain = MotionEvent.obtain(motionEvent); m.checkNotNullExpressionValue(obtain, "cancelEvent"); obtain.setAction((motionEvent.getActionIndex() << 8) | 3); this.f1520s.onTouchEvent(obtain); obtain.recycle(); } if (this.o) { this.r = rawX2; this.f1520s.setTranslationX(rawX2 - ((float) this.p)); this.f1520s.setAlpha(Math.max(0.0f, Math.min(1.0f, 1.0f - ((Math.abs(rawX2) * 2.0f) / ((float) this.l))))); return true; } } } else if (actionMasked != 3) { view.performClick(); return false; } else { VelocityTracker velocityTracker3 = this.q; if (velocityTracker3 != null) { this.f1520s.animate().translationX(0.0f).alpha(1.0f).setDuration(this.k).setListener(null); velocityTracker3.recycle(); this.q = null; this.r = 0.0f; this.m = 0.0f; this.n = 0.0f; this.o = false; } } return false; } this.m = motionEvent.getRawX(); this.n = motionEvent.getRawY(); if (this.t.b()) { VelocityTracker obtain2 = VelocityTracker.obtain(); this.q = obtain2; m.checkNotNull(obtain2); obtain2.addMovement(motionEvent); } this.t.a(view, true); return false; } }