Skip to content

Commit c0d5737

Browse files
committed
1 parent 5a21533 commit c0d5737

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

library/src/main/java/com/daimajia/swipe/SwipeLayout.java

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,20 +639,82 @@ public boolean dispatchTouchEvent(MotionEvent ev) {
639639
return super.dispatchTouchEvent(ev);
640640
}
641641

642+
private View childNeeded = null;
643+
642644
@Override
643645
public boolean onInterceptTouchEvent(MotionEvent ev) {
644646
for (SwipeDenier denier : mSwipeDeniers) {
645647
if (denier != null && denier.shouldDenySwipe(ev)) {
646648
return false;
647649
}
648650
}
651+
//
652+
//if a child in SurfaceView wants to handle the touch event,
653+
//then let it do it.
654+
//
655+
int action = ev.getActionMasked();
656+
switch (action){
657+
case MotionEvent.ACTION_DOWN:
658+
View child = childNeed(getSurfaceView(), ev);
659+
if(child != null){
660+
childNeeded = child;
661+
return false;
662+
}
663+
break;
664+
case MotionEvent.ACTION_MOVE:
665+
if(childNeeded != null){
666+
return false;
667+
}
668+
break;
669+
case MotionEvent.ACTION_UP:
670+
case MotionEvent.ACTION_CANCEL:
671+
childNeeded = null;
672+
return false;
673+
}
649674

650675
return mDragHelper.shouldInterceptTouchEvent(ev);
651676
}
652677

678+
/**
679+
* if the ViewGroup children want to handle this event.
680+
* @param v
681+
* @param event
682+
* @return
683+
*/
684+
private View childNeed(ViewGroup v, MotionEvent event){
685+
int childCount = v.getChildCount();
686+
for(int i = childCount - 1; i >= 0; i--){
687+
View child = v.getChildAt(i);
688+
if(child instanceof ViewGroup){
689+
View grandChild = childNeed((ViewGroup)child, event);
690+
if(grandChild != null)
691+
return grandChild;
692+
}else{
693+
if(childNeed(v.getChildAt(i), event))
694+
return v.getChildAt(i);
695+
}
696+
}
697+
return null;
698+
}
699+
700+
/**
701+
* if the view (v) wants to handle this event.
702+
* @param v
703+
* @param event
704+
* @return
705+
*/
706+
private boolean childNeed(View v, MotionEvent event){
707+
if(event.getX() > v.getLeft() && event.getX() < v.getRight()
708+
&& event.getY() > v.getTop() && event.getY() < v.getBottom()){
709+
return v.onTouchEvent(event);
710+
}
711+
return false;
712+
}
713+
653714
private float sX = -1 , sY = -1;
654715
@Override
655716
public boolean onTouchEvent(MotionEvent event) {
717+
656718
int action = event.getActionMasked();
657719
ViewParent parent = getParent();
658720
gestureDetector.onTouchEvent(event);

0 commit comments

Comments
 (0)