Skip to content

Commit

Permalink
# Fixed not executing ClickListener on child views
Browse files Browse the repository at this point in the history
  • Loading branch information
sbra0902 committed Apr 3, 2017
1 parent 936b5fd commit 2cf3386
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import kaufland.com.demo.R;
import kaufland.com.demo.example.RecylerViewWithRestoreFragment.OnListFragmentInteractionListener;
import kaufland.com.demo.example.dummy.DummyContent.DummyItem;
import kaufland.com.swipelibrary.SurfaceView;
import kaufland.com.swipelibrary.SwipeLayout;
import kaufland.com.swipelibrary.SwipeState;

Expand Down Expand Up @@ -62,6 +64,13 @@ public void onBounce(SwipeState.DragViewState dragViewState) {

}
});

holder.mSurfaceView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(holder.mSwipeLayout.getContext(), "Clicked SwipeLayout", Toast.LENGTH_LONG).show();
}
});
}

@Override
Expand All @@ -72,10 +81,12 @@ public int getItemCount() {
public class ViewHolder extends RecyclerView.ViewHolder {

SwipeLayout mSwipeLayout;
SurfaceView mSurfaceView;

public ViewHolder(View view) {
super(view);
mSwipeLayout = (SwipeLayout) view.findViewById(R.id.swipe_example_2);
mSurfaceView = (SurfaceView) view.findViewById(R.id.surface_view_example2);
}

}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/match_parent_example.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
android:layout_width="match_parent"
android:paddingTop="20dp"
android:layout_weight="0.33"
android:id="@+id/surface_view_example2"
android:paddingBottom="20dp"
android:background="@android:color/holo_red_light"
android:layout_height="match_parent">
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 mIsDragging;

private boolean mDragAllowed;

private boolean mSwipeEnabled = true;
Expand Down Expand Up @@ -99,7 +97,7 @@ public boolean onTouchEvent(MotionEvent ev) {
mDragHelper.abort();
mSwipeDirectionDetector.onActionDown(ev.getX(), ev.getY(), this);
mDragHelper.processTouchEvent(ev);
return true;
break;

case MotionEvent.ACTION_MOVE:
mSwipeDirectionDetector.onAction(ev.getX(), ev.getY());
Expand All @@ -109,11 +107,8 @@ public boolean onTouchEvent(MotionEvent ev) {
mDragAllowed = canSwipe;

boolean isClick = mDragHelperTouchSlop > Math.abs(mSwipeDirectionDetector.getDifX());
if (!isClick) {
mIsDragging = true;
}

if (mIsDragging && mDragAllowed) {
if (!isClick && mDragAllowed) {
getParent().requestDisallowInterceptTouchEvent(true);
mDragHelper.processTouchEvent(ev);
}
Expand All @@ -123,15 +118,14 @@ public boolean onTouchEvent(MotionEvent ev) {
case MotionEvent.ACTION_UP:

mSwipeDirectionDetector.onActionUp(ev.getX(), ev.getY(), this);
mIsDragging = false;


if (ev.getX() < 0 || ev.getY() < 0 || ev.getX() > getMeasuredWidth() || ev.getY() > getMeasuredHeight()) {


ev.setAction(MotionEvent.ACTION_UP);
mDragHelper.processTouchEvent(ev);
return false;
return true;
}

if (mDragAllowed) {
Expand All @@ -141,7 +135,6 @@ public boolean onTouchEvent(MotionEvent ev) {
break;

case MotionEvent.ACTION_CANCEL:
mIsDragging = false;

mDragHelper.processTouchEvent(ev);

Expand All @@ -151,7 +144,7 @@ public boolean onTouchEvent(MotionEvent ev) {
mDragHelper.processTouchEvent(ev);
}

return mIsDragging;
return true;
}

@Override
Expand All @@ -169,11 +162,10 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
mSwipeDirectionDetector.onActionDown(ev.getX(), ev.getY(), this);
mDragHelper.abort();
mDragHelper.processTouchEvent(ev);
mIsDragging = false;
break;

case MotionEvent.ACTION_MOVE:

mSwipeDirectionDetector.onAction(ev.getX(), ev.getY());
try {
mDragHelper.processTouchEvent(ev);
} catch (IllegalArgumentException e) {
Expand All @@ -182,28 +174,25 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {

boolean isClick = mDragHelperTouchSlop > Math.abs(mSwipeDirectionDetector.getDifX());

if (!mIsDragging && isClick) {
return false;
}

if (mIsDragging) {
if (!isClick) {
ViewParent parent = getParent();
if (parent != null) {
parent.requestDisallowInterceptTouchEvent(true);
}
return true;
}

break;

case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:

mIsDragging = false;
mDragHelper.processTouchEvent(ev);
break;
}

return mIsDragging;
return false;
}


Expand Down Expand Up @@ -289,8 +278,9 @@ public void onViewReleased(View releasedChild, final float xvel, float yvel) {
} else if (mDraggingProxy.getDragDirection() == SwipeViewLayouter.DragDirection.HORIZONTAL) {

SwipeResult swipeResult = new SwipeResult(xBeforeDrag);
boolean isClick = mDragHelperTouchSlop > Math.abs(mSwipeDirectionDetector.getDifX());

if (!mSwipeDirectionDetector.isHorizontalScrollChangedWhileDragging()) {
if (!mSwipeDirectionDetector.isHorizontalScrollChangedWhileDragging() && !isClick) {
swipeResult = mDraggingProxy.determineSwipeHorizontalState(xvel, mSwipeDirectionDetector, mSwipeState, mSwipeListener, releasedChild);
}

Expand Down

0 comments on commit 2cf3386

Please sign in to comment.