diff --git a/app/src/main/java/kaufland/com/demo/example/EasyExample.java b/app/src/main/java/kaufland/com/demo/example/EasyExample.java index bed65c1..85c0548 100644 --- a/app/src/main/java/kaufland/com/demo/example/EasyExample.java +++ b/app/src/main/java/kaufland/com/demo/example/EasyExample.java @@ -76,6 +76,13 @@ public void onClick(View v) { mViewById.closeSwipe(); } }); + + view.findViewById(R.id.surface_view_example2).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Toast.makeText(getActivity(), "Clicked", Toast.LENGTH_SHORT).show(); + } + }); view.findViewById(R.id.btn_open_left).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { diff --git a/swipelibrary/src/main/java/kaufland/com/swipelibrary/DraggingProxy.java b/swipelibrary/src/main/java/kaufland/com/swipelibrary/DraggingProxy.java index 3c9459c..8acf469 100644 --- a/swipelibrary/src/main/java/kaufland/com/swipelibrary/DraggingProxy.java +++ b/swipelibrary/src/main/java/kaufland/com/swipelibrary/DraggingProxy.java @@ -114,9 +114,9 @@ public boolean canSwipe(SwipeDirectionDetector swipeDirectionDetector, SwipeStat if (mSwipeViewLayouter.getDragDirection() == HORIZONTAL) { if (diffX > 0) { - canSwipe = absDiffX > absDiffY && (isLeftDraggable || state == SwipeState.DragViewState.RIGHT_OPEN || mSwipeViewLayouter.getSurfaceView().getLeft() < 0); + canSwipe = absDiffX > absDiffY && (isLeftDraggable || mSwipeViewLayouter.getSurfaceView().getX() < 0); } else { - canSwipe = absDiffX > absDiffY && (isRightDraggable || state == SwipeState.DragViewState.LEFT_OPEN || mSwipeViewLayouter.getSurfaceView().getLeft() > 0); + canSwipe = absDiffX > absDiffY && (isRightDraggable || mSwipeViewLayouter.getSurfaceView().getX() > 0); } } diff --git a/swipelibrary/src/main/java/kaufland/com/swipelibrary/SwipeDirectionDetector.java b/swipelibrary/src/main/java/kaufland/com/swipelibrary/SwipeDirectionDetector.java index e397704..6d60c2c 100644 --- a/swipelibrary/src/main/java/kaufland/com/swipelibrary/SwipeDirectionDetector.java +++ b/swipelibrary/src/main/java/kaufland/com/swipelibrary/SwipeDirectionDetector.java @@ -56,6 +56,14 @@ public int getDifY() { return yDown - yUp; } + public int getXDown() { + return xDown; + } + + public int getYDown() { + return yDown; + } + public int getSwipeDirection(){ return getDifX() > 0 ? SWIPE_DIRECTION_RIGHT : SWIPE_DIRECTION_LEFT; } diff --git a/swipelibrary/src/main/java/kaufland/com/swipelibrary/SwipeLayout.java b/swipelibrary/src/main/java/kaufland/com/swipelibrary/SwipeLayout.java index 9966820..90bcdfa 100644 --- a/swipelibrary/src/main/java/kaufland/com/swipelibrary/SwipeLayout.java +++ b/swipelibrary/src/main/java/kaufland/com/swipelibrary/SwipeLayout.java @@ -52,8 +52,6 @@ public class SwipeLayout extends FrameLayout { private SwipeListener mSwipeListener; - private boolean mDragAllowed; - private boolean mSwipeEnabled = true; private float mDragHelperTouchSlop; @@ -102,15 +100,19 @@ public boolean onTouchEvent(MotionEvent ev) { case MotionEvent.ACTION_MOVE: mSwipeDirectionDetector.onAction(ev.getX(), ev.getY()); - boolean canSwipe = mDraggingProxy.canSwipe(mSwipeDirectionDetector, mSwipeState.getState()); - - mDragAllowed = canSwipe; boolean isClick = mDragHelperTouchSlop > Math.abs(mSwipeDirectionDetector.getDifX()); - if (!isClick && mDragAllowed) { + if (!isClick) { getParent().requestDisallowInterceptTouchEvent(true); - mDragHelper.processTouchEvent(ev); + try { + mDragHelper.processTouchEvent(ev); + } catch (IllegalArgumentException e) { + // https://code.google.com/p/android/issues/detail?id=64553 + mSwipeDirectionDetector.onAction(mSwipeDirectionDetector.getXDown(), mSwipeDirectionDetector.getYDown()); + ev.setAction(MotionEvent.ACTION_UP); + mDragHelper.processTouchEvent(ev); + } } break; @@ -128,9 +130,9 @@ public boolean onTouchEvent(MotionEvent ev) { return true; } - if (mDragAllowed) { - mDragHelper.processTouchEvent(ev); - } + + mDragHelper.processTouchEvent(ev); + break; @@ -166,13 +168,18 @@ public boolean onInterceptTouchEvent(MotionEvent ev) { case MotionEvent.ACTION_MOVE: mSwipeDirectionDetector.onAction(ev.getX(), ev.getY()); - try { - mDragHelper.processTouchEvent(ev); - } catch (IllegalArgumentException e) { - // https://code.google.com/p/android/issues/detail?id=64553 - } boolean isClick = mDragHelperTouchSlop > Math.abs(mSwipeDirectionDetector.getDifX()); + if (!isClick) { + try { + mDragHelper.processTouchEvent(ev); + } catch (IllegalArgumentException e) { + // https://code.google.com/p/android/issues/detail?id=64553 + mSwipeDirectionDetector.onAction(mSwipeDirectionDetector.getXDown(), mSwipeDirectionDetector.getYDown()); + ev.setAction(MotionEvent.ACTION_UP); + mDragHelper.processTouchEvent(ev); + } + } if (!isClick) { @@ -312,6 +319,7 @@ public int clampViewPositionVertical(View child, int top, int dy) { public int clampViewPositionHorizontal(View child, int left, int dx) { if (mSwipeState.getState() == SwipeState.DragViewState.TOP_OPEN || mSwipeState.getState() == SwipeState.DragViewState.BOTTOM_OPEN || + !mDraggingProxy.canSwipe(mSwipeDirectionDetector, mSwipeState.getState()) || mDraggingProxy.getDragDirection() == SwipeViewLayouter.DragDirection.VERTICAL) { return 0; }