content: package androidx.core.view;
  
  import android.content.Context;
  import android.os.Build;
  import android.os.Handler;
  import android.os.Message;
  import android.view.GestureDetector;
  import android.view.MotionEvent;
  import android.view.VelocityTracker;
  import android.view.ViewConfiguration;
  
  public final class GestureDetectorCompat {
      private final GestureDetectorCompatImpl mImpl;
  
      interface GestureDetectorCompatImpl {
          boolean isLongpressEnabled();
  
          boolean onTouchEvent(MotionEvent motionEvent);
  
          void setIsLongpressEnabled(boolean z);
  
          void setOnDoubleTapListener(GestureDetector.OnDoubleTapListener onDoubleTapListener);
      }
  
      static class GestureDetectorCompatImplBase implements GestureDetectorCompatImpl {
          private static final int DOUBLE_TAP_TIMEOUT = ViewConfiguration.getDoubleTapTimeout();
          private static final int LONG_PRESS = 2;
          private static final int SHOW_PRESS = 1;
          private static final int TAP = 3;
          private static final int TAP_TIMEOUT = ViewConfiguration.getTapTimeout();
          private boolean mAlwaysInBiggerTapRegion;
          private boolean mAlwaysInTapRegion;
          MotionEvent mCurrentDownEvent;
          boolean mDeferConfirmSingleTap;
          GestureDetector.OnDoubleTapListener mDoubleTapListener;
          private int mDoubleTapSlopSquare;
          private float mDownFocusX;
          private float mDownFocusY;
          private final Handler mHandler;
          private boolean mInLongPress;
          private boolean mIsDoubleTapping;
          private boolean mIsLongpressEnabled;
          private float mLastFocusX;
          private float mLastFocusY;
          final GestureDetector.OnGestureListener mListener;
          private int mMaximumFlingVelocity;
          private int mMinimumFlingVelocity;
          private MotionEvent mPreviousUpEvent;
          boolean mStillDown;
          private int mTouchSlopSquare;
          private VelocityTracker mVelocityTracker;
  
          private class GestureHandler extends Handler {
              GestureHandler() {
              }
  
              GestureHandler(Handler handler) {
                  super(handler.getLooper());
              }
  
              public void handleMessage(Message msg) {
                  switch (msg.what) {
                      case 1:
                          GestureDetectorCompatImplBase.this.mListener.onShowPress(GestureDetectorCompatImplBase.this.mCurrentDownEvent);
                          return;
                      case 2:
                          GestureDetectorCompatImplBase.this.dispatchLongPress();
                          return;
                      case 3:
                          if (GestureDetectorCompatImplBase.this.mDoubleTapListener == null) {
                              return;
                          }
                          if (!GestureDetectorCompatImplBase.this.mStillDown) {
                              GestureDetectorCompatImplBase.this.mDoubleTapListener.onSingleTapConfirmed(GestureDetectorCompatImplBase.this.mCurrentDownEvent);
                              return;
                          } else {
                              GestureDetectorCompatImplBase.this.mDeferConfirmSingleTap = true;
                              return;
                          }
                      default:
                          throw new RuntimeException("Unknown message " + msg);
                  }
              }
          }
  
          GestureDetectorCompatImplBase(Context context, GestureDetector.OnGestureListener listener, Handler handler) {
              if (handler != null) {
                  this.mHandler = new GestureHandler(handler);
              } else {
                  this.mHandler = new GestureHandler();
              }
              this.mListener = listener;
              if (listener instanceof GestureDetector.OnDoubleTapListener) {
                  setOnDoubleTapListener((GestureDetector.OnDoubleTapListener) listener);
              }
              init(context);
          }
  
          private void cancel() {
              this.mHandler.removeMessages(1);
              this.mHandler.removeMessages(2);
              this.mHandler.removeMessages(3);
              this.mVelocityTracker.recycle();
              this.mVelocityTracker = null;
              this.mIsDoubleTapping = false;
              this.mStillDown = false;
              this.mAlwaysInTapRegion = false;
              this.mAlwaysInBiggerTapRegion = false;
              this.mDeferConfirmSingleTap = false;
              if (this.mInLongPress) {
                  this.mInLongPress = false;
              }
          }
  
          private void cancelTaps() {
              this.mHandler.removeMessages(1);
              this.mHandler.removeMessages(2);
              this.mHandler.removeMessages(3);
              this.mIsDoubleTapping = false;
              this.mAlwaysInTapRegion = false;
              this.mAlwaysInBiggerTapRegion = false;
              this.mDeferConfirmSingleTap = false;
              if (this.mInLongPress) {
                  this.mInLongPress = false;
              }
          }
  
          private void init(Context context) {
              if (context == null) {
                  throw new IllegalArgumentException("Context must not be null");
              } else if (this.mListener != null) {
                  this.mIsLongpressEnabled = true;
                  ViewConfiguration viewConfiguration = ViewConfiguration.get(context);
                  int scaledTouchSlop = viewConfiguration.getScaledTouchSlop();
                  int scaledDoubleTapSlop = viewConfiguration.getScaledDoubleTapSlop();
                  this.mMinimumFlingVelocity = viewConfiguration.getScaledMinimumFlingVelocity();
                  this.mMaximumFlingVelocity = viewConfiguration.getScaledMaximumFlingVelocity();
                  this.mTouchSlopSquare = scaledTouchSlop * scaledTouchSlop;
                  this.mDoubleTapSlopSquare = scaledDoubleTapSlop * scaledDoubleTapSlop;
              } else {
                  throw new IllegalArgumentException("OnGestureListener must not be null");
              }
          }
  
          private boolean isConsideredDoubleTap(MotionEvent firstDown, MotionEvent firstUp, MotionEvent secondDown) {
              if (!this.mAlwaysInBiggerTapRegion || secondDown.getEventTime() - firstUp.getEventTime() > ((long) DOUBLE_TAP_TIMEOUT)) {
                  return false;
              }
              int x = ((int) firstDown.getX()) - ((int) secondDown.getX());
              int y = ((int) firstDown.getY()) - ((int) secondDown.getY());
              return (x * x) + (y * y) < this.mDoubleTapSlopSquare;
          }
  
          /* access modifiers changed from: package-private */
          public void dispatchLongPress() {
              this.mHandler.removeMessages(3);
              this.mDeferConfirmSingleTap = false;
              this.mInLongPress = true;
              this.mListener.onLongPress(this.mCurrentDownEvent);
          }
  
          public boolean isLongpressEnabled() {
              return this.mIsLongpressEnabled;
          }
  
          public boolean onTouchEvent(MotionEvent ev) {
              MotionEvent motionEvent;
              GestureDetector.OnDoubleTapListener onDoubleTapListener;
              int i;
              boolean z;
              int i2;
              MotionEvent motionEvent2 = ev;
              int action = ev.getAction();
              if (this.mVelocityTracker == null) {
                  this.mVelocityTracker = VelocityTracker.obtain();
              }
              this.mVelocityTracker.addMovement(motionEvent2);
              boolean z2 = (action & 255) == 6;
              int actionIndex = z2 ? ev.getActionIndex() : -1;
              float f = 0.0f;
              float f2 = 0.0f;
              int pointerCount = ev.getPointerCount();
              for (int i3 = 0; i3 < pointerCount; i3++) {
                  if (actionIndex != i3) {
                      f += motionEvent2.getX(i3);
                      f2 += motionEvent2.getY(i3);
                  }
              }
              int i4 = z2 ? pointerCount - 1 : pointerCount;
              float f3 = f / ((float) i4);
              float f4 = f2 / ((float) i4);
              boolean z3 = false;
              switch (action & 255) {
                  case 0:
                      int i5 = action;
                      boolean z4 = z2;
                      int i6 = actionIndex;
                      if (this.mDoubleTapListener != null) {
                          boolean hasMessages = this.mHandler.hasMessages(3);
                          if (hasMessages) {
                              this.mHandler.removeMessages(3);
                          }
                          MotionEvent motionEvent3 = this.mCurrentDownEvent;
                          if (motionEvent3 == null || (motionEvent = this.mPreviousUpEvent) == null || !hasMessages || !isConsideredDoubleTap(motionEvent3, motionEvent, motionEvent2)) {
                              this.mHandler.sendEmptyMessageDelayed(3, (long) DOUBLE_TAP_TIMEOUT);
                          } else {
                              this.mIsDoubleTapping = true;
                              z3 = this.mDoubleTapListener.onDoubleTap(this.mCurrentDownEvent) | false | this.mDoubleTapListener.onDoubleTapEvent(motionEvent2);
                          }
                      }
                      this.mLastFocusX = f3;
                      this.mDownFocusX = f3;
                      this.mLastFocusY = f4;
                      this.mDownFocusY = f4;
                      MotionEvent motionEvent4 = this.mCurrentDownEvent;
                      if (motionEvent4 != null) {
                          motionEvent4.recycle();
                      }
                      this.mCurrentDownEvent = MotionEvent.obtain(ev);
                      this.mAlwaysInTapRegion = true;
                      this.mAlwaysInBiggerTapRegion = true;
                      this.mStillDown = true;
                      this.mInLongPress = false;
                      this.mDeferConfirmSingleTap = false;
                      if (this.mIsLongpressEnabled) {
                          this.mHandler.removeMessages(2);
                          this.mHandler.sendEmptyMessageAtTime(2, this.mCurrentDownEvent.getDownTime() + ((long) TAP_TIMEOUT) + ((long) ViewConfiguration.getLongPressTimeout()));
                      }
                      this.mHandler.sendEmptyMessageAtTime(1, this.mCurrentDownEvent.getDownTime() + ((long) TAP_TIMEOUT));
                      return z3 | this.mListener.onDown(motionEvent2);
                  case 1:
                      int i7 = action;
                      boolean z5 = z2;
                      int i8 = actionIndex;
                      this.mStillDown = false;
                      MotionEvent obtain = MotionEvent.obtain(ev);
                      if (this.mIsDoubleTapping) {
                          z3 = false | this.mDoubleTapListener.onDoubleTapEvent(motionEvent2);
                      } else if (this.mInLongPress) {
                          this.mHandler.removeMessages(3);
                          this.mInLongPress = false;
                      } else if (this.mAlwaysInTapRegion) {
                          z3 = this.mListener.onSingleTapUp(motionEvent2);
                          if (this.mDeferConfirmSingleTap && (onDoubleTapListener = this.mDoubleTapListener) != null) {
                              onDoubleTapListener.onSingleTapConfirmed(motionEvent2);
                          }
                      } else {
                          VelocityTracker velocityTracker = this.mVelocityTracker;
                          int pointerId = motionEvent2.getPointerId(0);
                          velocityTracker.computeCurrentVelocity(1000, (float) this.mMaximumFlingVelocity);
                          float yVelocity = velocityTracker.getYVelocity(pointerId);
                          float xVelocity = velocityTracker.getXVelocity(pointerId);
                          if (Math.abs(yVelocity) > ((float) this.mMinimumFlingVelocity) || Math.abs(xVelocity) > ((float) this.mMinimumFlingVelocity)) {
                              z3 = this.mListener.onFling(this.mCurrentDownEvent, motionEvent2, xVelocity, yVelocity);
                          }
                      }
                      MotionEvent motionEvent5 = this.mPreviousUpEvent;
                      if (motionEvent5 != null) {
                          motionEvent5.recycle();
                      }
                      this.mPreviousUpEvent = obtain;
                      VelocityTracker velocityTracker2 = this.mVelocityTracker;
                      if (velocityTracker2 != null) {
                          velocityTracker2.recycle();
                          this.mVelocityTracker = null;
                      }
                      this.mIsDoubleTapping = false;
                      this.mDeferConfirmSingleTap = false;
                      this.mHandler.removeMessages(1);
                      this.mHandler.removeMessages(2);
                      return z3;
                  case 2:
                      int i9 = action;
                      boolean z6 = z2;
                      int i10 = actionIndex;
                      if (this.mInLongPress) {
                          return false;
                      }
                      float f5 = this.mLastFocusX - f3;
                      float f6 = this.mLastFocusY - f4;
                      if (this.mIsDoubleTapping) {
                          return false | this.mDoubleTapListener.onDoubleTapEvent(motionEvent2);
                      }
                      if (this.mAlwaysInTapRegion) {
                          int i11 = (int) (f3 - this.mDownFocusX);
                          int i12 = (int) (f4 - this.mDownFocusY);
                          int i13 = (i11 * i11) + (i12 * i12);
                          if (i13 > this.mTouchSlopSquare) {
                              boolean onScroll = this.mListener.onScroll(this.mCurrentDownEvent, motionEvent2, f5, f6);
                              this.mLastFocusX = f3;
                              this.mLastFocusY = f4;
                              this.mAlwaysInTapRegion = false;
                              this.mHandler.removeMessages(3);
                              this.mHandler.removeMessages(1);
                              this.mHandler.removeMessages(2);
                              z3 = onScroll;
                          }
                          if (i13 <= this.mTouchSlopSquare) {
                              return z3;
                          }
                          this.mAlwaysInBiggerTapRegion = false;
                          return z3;
                      } else if (Math.abs(f5) < 1.0f && Math.abs(f6) < 1.0f) {
                          return false;
                      } else {
                          boolean onScroll2 = this.mListener.onScroll(this.mCurrentDownEvent, motionEvent2, f5, f6);
                          this.mLastFocusX = f3;
                          this.mLastFocusY = f4;
                          return onScroll2;
                      }
                  case 3:
                      int i14 = action;
                      boolean z7 = z2;
                      int i15 = actionIndex;
                      cancel();
                      return false;
                  case 5:
                      int i16 = action;
                      boolean z8 = z2;
                      int i17 = actionIndex;
                      this.mLastFocusX = f3;
                      this.mDownFocusX = f3;
                      this.mLastFocusY = f4;
                      this.mDownFocusY = f4;
                      cancelTaps();
                      return false;
                  case 6:
                      this.mLastFocusX = f3;
                      this.mDownFocusX = f3;
                      this.mLastFocusY = f4;
                      this.mDownFocusY = f4;
                      this.mVelocityTracker.computeCurrentVelocity(1000, (float) this.mMaximumFlingVelocity);
                      int actionIndex2 = ev.getActionIndex();
                      int pointerId2 = motionEvent2.getPointerId(actionIndex2);
                      float xVelocity2 = this.mVelocityTracker.getXVelocity(pointerId2);
                      float yVelocity2 = this.mVelocityTracker.getYVelocity(pointerId2);
                      int i18 = action;
                      int i19 = 0;
                      while (i19 < pointerCount) {
                          if (i19 == actionIndex2) {
                              z = z2;
                              i = actionIndex;
                              i2 = actionIndex2;
                          } else {
                              z = z2;
                              int pointerId3 = motionEvent2.getPointerId(i19);
                              i = actionIndex;
                              i2 = actionIndex2;
                              if ((this.mVelocityTracker.getXVelocity(pointerId3) * xVelocity2) + (this.mVelocityTracker.getYVelocity(pointerId3) * yVelocity2) < 0.0f) {
                                  int i20 = pointerId3;
                                  this.mVelocityTracker.clear();
                                  return false;
                              }
                              int i21 = pointerId3;
                          }
                          i19++;
                          actionIndex2 = i2;
                          z2 = z;
                          actionIndex = i;
                      }
                      boolean z9 = z2;
                      int i22 = actionIndex;
                      int i23 = actionIndex2;
                      return false;
                  default:
                      int i24 = action;
                      boolean z10 = z2;
                      int i25 = actionIndex;
                      return false;
              }
          }
  
          public void setIsLongpressEnabled(boolean isLongpressEnabled) {
              this.mIsLongpressEnabled = isLongpressEnabled;
          }
  
          public void setOnDoubleTapListener(GestureDetector.OnDoubleTapListener onDoubleTapListener) {
              this.mDoubleTapListener = onDoubleTapListener;
          }
      }
  
      static class GestureDetectorCompatImplJellybeanMr2 implements GestureDetectorCompatImpl {
          private final GestureDetector mDetector;
  
          GestureDetectorCompatImplJellybeanMr2(Context context, GestureDetector.OnGestureListener listener, Handler handler) {
              this.mDetector = new GestureDetector(context, listener, handler);
          }
  
          public boolean isLongpressEnabled() {
              return this.mDetector.isLongpressEnabled();
          }
  
          public boolean onTouchEvent(MotionEvent ev) {
              return this.mDetector.onTouchEvent(ev);
          }
  
          public void setIsLongpressEnabled(boolean enabled) {
              this.mDetector.setIsLongpressEnabled(enabled);
          }
  
          public void setOnDoubleTapListener(GestureDetector.OnDoubleTapListener listener) {
              this.mDetector.setOnDoubleTapListener(listener);
          }
      }
  
      public GestureDetectorCompat(Context context, GestureDetector.OnGestureListener listener) {
          this(context, listener, (Handler) null);
      }
  
      public GestureDetectorCompat(Context context, GestureDetector.OnGestureListener listener, Handler handler) {
          if (Build.VERSION.SDK_INT > 17) {
              this.mImpl = new GestureDetectorCompatImplJellybeanMr2(context, listener, handler);
          } else {
              this.mImpl = new GestureDetectorCompatImplBase(context, listener, handler);
          }
      }
  
      public boolean isLongpressEnabled() {
          return this.mImpl.isLongpressEnabled();
      }
  
      public boolean onTouchEvent(MotionEvent event) {
          return this.mImpl.onTouchEvent(event);
      }
  
      public void setIsLongpressEnabled(boolean enabled) {
          this.mImpl.setIsLongpressEnabled(enabled);
      }
  
      public void setOnDoubleTapListener(GestureDetector.OnDoubleTapListener listener) {
          this.mImpl.setOnDoubleTapListener(listener);
      }
  }
  