Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…etail?id=163954

# Fixed disable dragview
  • Loading branch information
sbra0902 committed Apr 3, 2017
1 parent 2cf3386 commit 3fa9ae9
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 17 deletions.
7 changes: 7 additions & 0 deletions app/src/main/java/kaufland/com/demo/example/EasyExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ public class SwipeLayout extends FrameLayout {

private SwipeListener mSwipeListener;

private boolean mDragAllowed;

private boolean mSwipeEnabled = true;

private float mDragHelperTouchSlop;
Expand Down Expand Up @@ -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;
Expand All @@ -128,9 +130,9 @@ public boolean onTouchEvent(MotionEvent ev) {
return true;
}

if (mDragAllowed) {
mDragHelper.processTouchEvent(ev);
}

mDragHelper.processTouchEvent(ev);


break;

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 3fa9ae9

Please sign in to comment.