From 7e741aa81231eac7343d85c9d06133600622978b Mon Sep 17 00:00:00 2001 From: Tamim Attafi Date: Tue, 31 Aug 2021 16:22:20 +0700 Subject: [PATCH] fix: Click listeners triggers even when swiping --- .../shawnlin/numberpicker/NumberPicker.java | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/library/src/main/java/com/shawnlin/numberpicker/NumberPicker.java b/library/src/main/java/com/shawnlin/numberpicker/NumberPicker.java index c320fea..73c59ba 100644 --- a/library/src/main/java/com/shawnlin/numberpicker/NumberPicker.java +++ b/library/src/main/java/com/shawnlin/numberpicker/NumberPicker.java @@ -1018,18 +1018,14 @@ public boolean onInterceptTouchEvent(MotionEvent event) { mFlingScroller.forceFinished(true); mAdjustScroller.forceFinished(true); onScrollerFinished(mAdjustScroller); - } else if (mLastDownEventX >= mLeftDividerLeft - && mLastDownEventX <= mRightDividerRight) { - if (mOnClickListener != null) { - mOnClickListener.onClick(this); - } } else if (mLastDownEventX < mLeftDividerLeft) { postChangeCurrentByOneFromLongPress(false); } else if (mLastDownEventX > mRightDividerRight) { postChangeCurrentByOneFromLongPress(true); } } else { - mLastDownOrMoveEventY = mLastDownEventY = event.getY(); + mLastDownOrMoveEventY = mLastDownEventY; + mLastDownEventY = event.getY(); if (!mFlingScroller.isFinished()) { mFlingScroller.forceFinished(true); mAdjustScroller.forceFinished(true); @@ -1037,11 +1033,6 @@ public boolean onInterceptTouchEvent(MotionEvent event) { } else if (!mAdjustScroller.isFinished()) { mFlingScroller.forceFinished(true); mAdjustScroller.forceFinished(true); - } else if (mLastDownEventY >= mTopDividerTop - && mLastDownEventY <= mBottomDividerBottom) { - if (mOnClickListener != null) { - mOnClickListener.onClick(this); - } } else if (mLastDownEventY < mTopDividerTop) { postChangeCurrentByOneFromLongPress(false); } else if (mLastDownEventY > mBottomDividerBottom) { @@ -1118,6 +1109,9 @@ public boolean onTouchEvent(MotionEvent event) { changeValueByOne(false); } else { ensureScrollWheelAdjusted(); + if (mOnClickListener != null) { + mOnClickListener.onClick(this); + } } } else { ensureScrollWheelAdjusted(); @@ -1141,6 +1135,9 @@ public boolean onTouchEvent(MotionEvent event) { changeValueByOne(false); } else { ensureScrollWheelAdjusted(); + if (mOnClickListener != null) { + mOnClickListener.onClick(this); + } } } else { ensureScrollWheelAdjusted(); @@ -1148,6 +1145,7 @@ public boolean onTouchEvent(MotionEvent event) { onScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE); } } + mVelocityTracker.recycle(); mVelocityTracker = null; }