@@ -630,29 +630,13 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
630
630
631
631
switch (action ) {
632
632
case MotionEvent .ACTION_MOVE :
633
- final int activePointerId = mActivePointerId ;
634
- if (activePointerId == INVALID_POINTER )
635
- break ;
636
- final int pointerIndex = this .getPointerIndex (ev , activePointerId );
637
- final float x = MotionEventCompat .getX (ev , pointerIndex );
638
- final float dx = x - mLastMotionX ;
639
- final float xDiff = Math .abs (dx );
640
- final float y = MotionEventCompat .getY (ev , pointerIndex );
641
- final float yDiff = Math .abs (y - mLastMotionY );
642
- if (DEBUG ) Log .v (TAG , "onInterceptTouch moved to:(" + x + ", " + y + "), diff:(" + xDiff + ", " + yDiff + "), mLastMotionX:" + mLastMotionX );
643
- if (xDiff > mTouchSlop && xDiff > yDiff && thisSlideAllowed (dx )) {
644
- if (DEBUG ) Log .v (TAG , "Starting drag! from onInterceptTouch" );
645
- startDrag ();
646
- mLastMotionX = x ;
647
- setScrollingCacheEnabled (true );
648
- } else if (yDiff > mTouchSlop ) {
649
- mIsUnableToDrag = true ;
650
- }
633
+ determineDrag (ev );
651
634
break ;
652
-
653
635
case MotionEvent .ACTION_DOWN :
654
- mActivePointerId = ev .getAction () & ((Build .VERSION .SDK_INT >= 8 ) ? MotionEvent .ACTION_POINTER_INDEX_MASK :
655
- MotionEvent .ACTION_POINTER_INDEX_MASK );
636
+ int index = MotionEventCompat .getActionIndex (ev );
637
+ mActivePointerId = MotionEventCompat .getPointerId (ev , index );
638
+ if (mActivePointerId == INVALID_POINTER )
639
+ break ;
656
640
mLastMotionX = mInitialMotionX = MotionEventCompat .getX (ev , mActivePointerId );
657
641
mLastMotionY = MotionEventCompat .getY (ev , mActivePointerId );
658
642
if (thisTouchAllowed (ev )) {
@@ -708,37 +692,21 @@ public boolean onTouchEvent(MotionEvent ev) {
708
692
completeScroll ();
709
693
710
694
// Remember where the motion event started
695
+ int index = MotionEventCompat .getActionIndex (ev );
696
+ mActivePointerId = MotionEventCompat .getPointerId (ev , index );
711
697
mLastMotionX = mInitialMotionX = ev .getX ();
712
- mActivePointerId = MotionEventCompat .getPointerId (ev , 0 );
713
698
break ;
714
699
case MotionEvent .ACTION_MOVE :
715
- if (!mIsBeingDragged ) {
716
- if (mActivePointerId == INVALID_POINTER )
717
- break ;
718
- final int pointerIndex = getPointerIndex (ev , mActivePointerId );
719
- final float x = MotionEventCompat .getX (ev , pointerIndex );
720
- final float dx = x - mLastMotionX ;
721
- final float xDiff = Math .abs (dx );
722
- final float y = MotionEventCompat .getY (ev , pointerIndex );
723
- final float yDiff = Math .abs (y - mLastMotionY );
724
- if (DEBUG ) Log .v (TAG , "onTouch moved to:(" + x + ", " + y + "), diff:(" + xDiff + ", " + yDiff + ")\n mIsBeingDragged:" + mIsBeingDragged + ", mLastMotionX:" + mLastMotionX );
725
- if ((xDiff > mTouchSlop || (mQuickReturn && xDiff > mTouchSlop / 4 ))
726
- && xDiff > yDiff && thisSlideAllowed (dx )) {
727
- if (DEBUG ) Log .v (TAG , "Starting drag! from onTouch" );
728
- startDrag ();
729
- mLastMotionX = x ;
730
- setScrollingCacheEnabled (true );
731
- } else {
732
- if (DEBUG ) Log .v (TAG , "onTouch returning false" );
700
+ if (!mIsBeingDragged ) {
701
+ determineDrag (ev );
702
+ if (mIsUnableToDrag )
733
703
return false ;
734
- }
735
704
}
736
705
if (mIsBeingDragged ) {
737
706
// Scroll to follow the motion event
738
707
final int activePointerIndex = getPointerIndex (ev , mActivePointerId );
739
- if (mActivePointerId == INVALID_POINTER ) {
708
+ if (mActivePointerId == INVALID_POINTER )
740
709
break ;
741
- }
742
710
final float x = MotionEventCompat .getX (ev , activePointerIndex );
743
711
final float deltaX = mLastMotionX - x ;
744
712
mLastMotionX = x ;
@@ -793,22 +761,43 @@ && xDiff > yDiff && thisSlideAllowed(dx)) {
793
761
}
794
762
break ;
795
763
case MotionEventCompat .ACTION_POINTER_DOWN : {
796
- final int index = MotionEventCompat .getActionIndex (ev );
797
- final float x = MotionEventCompat .getX (ev , index );
798
- mLastMotionX = x ;
799
- mActivePointerId = MotionEventCompat .getPointerId (ev , index );
764
+ final int indexx = MotionEventCompat .getActionIndex (ev );
765
+ mLastMotionX = MotionEventCompat .getX (ev , indexx );
766
+ mActivePointerId = MotionEventCompat .getPointerId (ev , indexx );
800
767
break ;
801
768
}
802
769
case MotionEventCompat .ACTION_POINTER_UP :
803
770
onSecondaryPointerUp (ev );
804
- int pointerIndex = this . getPointerIndex (ev , mActivePointerId );
771
+ int pointerIndex = getPointerIndex (ev , mActivePointerId );
805
772
if (mActivePointerId == INVALID_POINTER )
806
773
break ;
807
774
mLastMotionX = MotionEventCompat .getX (ev , pointerIndex );
808
775
break ;
809
776
}
810
777
return true ;
811
778
}
779
+
780
+ private void determineDrag (MotionEvent ev ) {
781
+ final int activePointerId = mActivePointerId ;
782
+ if (activePointerId == INVALID_POINTER )
783
+ return ;
784
+ final int pointerIndex = this .getPointerIndex (ev , activePointerId );
785
+ final float x = MotionEventCompat .getX (ev , pointerIndex );
786
+ final float dx = x - mLastMotionX ;
787
+ final float xDiff = Math .abs (dx );
788
+ final float y = MotionEventCompat .getY (ev , pointerIndex );
789
+ final float dy = y - mLastMotionY ;
790
+ final float yDiff = Math .abs (dy );
791
+ if (xDiff > (isMenuOpen ()?mTouchSlop /2 :mTouchSlop ) && xDiff > yDiff && thisSlideAllowed (dx )) {
792
+ startDrag ();
793
+ mLastMotionX = x ;
794
+ mLastMotionY = y ;
795
+ setScrollingCacheEnabled (true );
796
+ // TODO add back in touch slop check
797
+ } else if (xDiff > mTouchSlop ) {
798
+ mIsUnableToDrag = true ;
799
+ }
800
+ }
812
801
813
802
@ Override
814
803
public void scrollTo (int x , int y ) {
0 commit comments