From cca4b366f0ac7d4b25fd5ae195e412cd7dd9d573 Mon Sep 17 00:00:00 2001 From: jaimeagudo Date: Fri, 9 Jun 2017 20:59:01 +0200 Subject: [PATCH 1/2] Allow click over cards pass touch event handlers --- .../java/link/fls/swipestack/SwipeHelper.java | 15 +++++++++++++-- .../main/java/link/fls/swipestack/SwipeStack.java | 1 + 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/library/src/main/java/link/fls/swipestack/SwipeHelper.java b/library/src/main/java/link/fls/swipestack/SwipeHelper.java index 43b7b72..dec20fd 100644 --- a/library/src/main/java/link/fls/swipestack/SwipeHelper.java +++ b/library/src/main/java/link/fls/swipestack/SwipeHelper.java @@ -39,6 +39,9 @@ public class SwipeHelper implements View.OnTouchListener { private float mOpacityEnd = SwipeStack.DEFAULT_SWIPE_OPACITY; private int mAnimationDuration = SwipeStack.DEFAULT_ANIMATION_DURATION; + private boolean isClick = true; + + public SwipeHelper(SwipeStack swipeStack) { mSwipeStack = swipeStack; } @@ -48,7 +51,9 @@ public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: - if(!mListenForTouchEvents || !mSwipeStack.isEnabled()) { + isClick = true; + + if (!mListenForTouchEvents || !mSwipeStack.isEnabled()) { return false; } @@ -67,6 +72,8 @@ public boolean onTouch(View v, MotionEvent event) { float dx = event.getX(pointerIndex) - mDownX; float dy = event.getY(pointerIndex) - mDownY; + isClick = Math.abs(dx + dy) < SwipeStack.CLICK_DISTANCE_THRESHOLD; + float newX = mObservedView.getX() + dx; float newY = mObservedView.getY() + dy; @@ -92,6 +99,10 @@ public boolean onTouch(View v, MotionEvent event) { return true; case MotionEvent.ACTION_UP: + if (isClick) { + v.performClick(); + } + v.getParent().requestDisallowInterceptTouchEvent(false); mSwipeStack.onSwipeEnd(); checkViewPosition(); @@ -104,7 +115,7 @@ public boolean onTouch(View v, MotionEvent event) { } private void checkViewPosition() { - if(!mSwipeStack.isEnabled()) { + if (!mSwipeStack.isEnabled()) { resetViewPosition(); return; } diff --git a/library/src/main/java/link/fls/swipestack/SwipeStack.java b/library/src/main/java/link/fls/swipestack/SwipeStack.java index 175e28d..351f3de 100644 --- a/library/src/main/java/link/fls/swipestack/SwipeStack.java +++ b/library/src/main/java/link/fls/swipestack/SwipeStack.java @@ -44,6 +44,7 @@ public class SwipeStack extends ViewGroup { public static final float DEFAULT_SWIPE_OPACITY = 1f; public static final float DEFAULT_SCALE_FACTOR = 1f; public static final boolean DEFAULT_DISABLE_HW_ACCELERATION = true; + public static final float CLICK_DISTANCE_THRESHOLD = 6; private static final String KEY_SUPER_STATE = "superState"; private static final String KEY_CURRENT_INDEX = "currentIndex"; From 4a350ab15fe6a6dbf8b96b686a0b297992f965d9 Mon Sep 17 00:00:00 2001 From: jaimeagudo Date: Fri, 9 Jun 2017 22:46:22 +0200 Subject: [PATCH 2/2] Simplify and refine --- .../main/java/link/fls/swipestack/SwipeHelper.java | 11 +++-------- .../src/main/java/link/fls/swipestack/SwipeStack.java | 2 +- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/library/src/main/java/link/fls/swipestack/SwipeHelper.java b/library/src/main/java/link/fls/swipestack/SwipeHelper.java index dec20fd..5a7489b 100644 --- a/library/src/main/java/link/fls/swipestack/SwipeHelper.java +++ b/library/src/main/java/link/fls/swipestack/SwipeHelper.java @@ -39,9 +39,6 @@ public class SwipeHelper implements View.OnTouchListener { private float mOpacityEnd = SwipeStack.DEFAULT_SWIPE_OPACITY; private int mAnimationDuration = SwipeStack.DEFAULT_ANIMATION_DURATION; - private boolean isClick = true; - - public SwipeHelper(SwipeStack swipeStack) { mSwipeStack = swipeStack; } @@ -51,8 +48,6 @@ public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: - isClick = true; - if (!mListenForTouchEvents || !mSwipeStack.isEnabled()) { return false; } @@ -72,8 +67,6 @@ public boolean onTouch(View v, MotionEvent event) { float dx = event.getX(pointerIndex) - mDownX; float dy = event.getY(pointerIndex) - mDownY; - isClick = Math.abs(dx + dy) < SwipeStack.CLICK_DISTANCE_THRESHOLD; - float newX = mObservedView.getX() + dx; float newY = mObservedView.getY() + dy; @@ -99,7 +92,9 @@ public boolean onTouch(View v, MotionEvent event) { return true; case MotionEvent.ACTION_UP: - if (isClick) { + dx = event.getX() - mDownX; + dy = event.getY() - mDownY; + if (Math.abs(dx + dy) <= SwipeStack.CLICK_DISTANCE_THRESHOLD) { v.performClick(); } diff --git a/library/src/main/java/link/fls/swipestack/SwipeStack.java b/library/src/main/java/link/fls/swipestack/SwipeStack.java index 351f3de..93c5af0 100644 --- a/library/src/main/java/link/fls/swipestack/SwipeStack.java +++ b/library/src/main/java/link/fls/swipestack/SwipeStack.java @@ -44,7 +44,7 @@ public class SwipeStack extends ViewGroup { public static final float DEFAULT_SWIPE_OPACITY = 1f; public static final float DEFAULT_SCALE_FACTOR = 1f; public static final boolean DEFAULT_DISABLE_HW_ACCELERATION = true; - public static final float CLICK_DISTANCE_THRESHOLD = 6; + public static final float CLICK_DISTANCE_THRESHOLD = 0; private static final String KEY_SUPER_STATE = "superState"; private static final String KEY_CURRENT_INDEX = "currentIndex";