5
5
import android .graphics .Canvas ;
6
6
import android .graphics .Color ;
7
7
import android .graphics .Paint ;
8
- import android .graphics .Rect ;
9
- import android .graphics .drawable .BitmapDrawable ;
10
8
import android .graphics .drawable .Drawable ;
11
9
import android .os .Build ;
12
10
import android .support .v4 .view .KeyEventCompat ;
@@ -97,7 +95,7 @@ public float getInterpolation(float t) {
97
95
private int mFlingDistance ;
98
96
99
97
private boolean mLastTouchAllowed = false ;
100
- private final int mSlidingMenuThreshold = 10 ;
98
+ private final int mSlidingMenuThreshold = 16 ;
101
99
private CustomViewBehind mViewBehindLeft ;
102
100
private CustomViewBehind mViewBehindRight ;
103
101
private boolean mEnabled = true ;
@@ -772,6 +770,22 @@ private boolean thisTouchAllowed(MotionEvent ev) {
772
770
}
773
771
}
774
772
}
773
+
774
+ private boolean thisSlideAllowed (float dx ) {
775
+ boolean allowed = false ;
776
+ if (isLeftOpen ()) {
777
+ allowed = dx < 0 ;
778
+ } else if (isRightOpen ()) {
779
+ allowed = dx > 0 ;
780
+ } else {
781
+ if (mViewBehindLeft != null )
782
+ allowed |= dx > 0 ;
783
+ if (mViewBehindRight != null )
784
+ allowed |= dx < 0 ;
785
+ }
786
+ Log .v (TAG , "this slide allowed " + allowed );
787
+ return allowed ;
788
+ }
775
789
776
790
private boolean mIsUnableToDrag ;
777
791
@@ -814,7 +828,7 @@ else if (mIsUnableToDrag)
814
828
final float xDiff = Math .abs (dx );
815
829
final float y = MotionEventCompat .getY (ev , pointerIndex );
816
830
final float yDiff = Math .abs (y - mLastMotionY );
817
- if (xDiff > mTouchSlop && xDiff > yDiff ) {
831
+ if (xDiff > mTouchSlop && xDiff > yDiff && thisSlideAllowed ( dx ) ) {
818
832
if (DEBUG ) Log .v (TAG , "Starting drag! from onInterceptTouch" );
819
833
mIsBeingDragged = true ;
820
834
mLastMotionX = x ;
@@ -825,8 +839,7 @@ else if (mIsUnableToDrag)
825
839
break ;
826
840
827
841
case MotionEvent .ACTION_DOWN :
828
- mActivePointerId = ev .getAction () & ((Build .VERSION .SDK_INT >= 8 ) ? MotionEvent .ACTION_POINTER_INDEX_MASK :
829
- MotionEvent .ACTION_POINTER_ID_MASK );
842
+ mActivePointerId = ev .getAction () & MotionEvent .ACTION_POINTER_INDEX_MASK ;
830
843
mLastMotionX = mInitialMotionX = MotionEventCompat .getX (ev , mActivePointerId );
831
844
mLastMotionY = MotionEventCompat .getY (ev , mActivePointerId );
832
845
if (thisTouchAllowed (ev )) {
@@ -936,7 +949,6 @@ public boolean onTouchEvent(MotionEvent ev) {
936
949
velocityTracker , mActivePointerId );
937
950
final int widthWithMargin = getChildWidth (mCurItem );
938
951
final int scrollX = getScrollX ();
939
- final int currentPage = scrollX / widthWithMargin ;
940
952
final float pageOffset = (float ) (scrollX % widthWithMargin ) / widthWithMargin ;
941
953
final int activePointerIndex =
942
954
MotionEventCompat .findPointerIndex (ev , mActivePointerId );
@@ -1044,15 +1056,13 @@ public void scrollTo(int x, int y) {
1044
1056
private int determineTargetPage (int currentPage , float pageOffset , int velocity , int deltaX ) {
1045
1057
int targetPage ;
1046
1058
if (Math .abs (deltaX ) > (float )mFlingDistance && Math .abs (velocity ) > mMinimumVelocity ) {
1047
- Log .v (TAG , "in here!" );
1048
1059
targetPage = velocity > 0 ? currentPage - 1 : currentPage + 1 ;
1049
1060
} else {
1050
1061
targetPage = (int ) ((deltaX > 0 ) ?
1051
1062
(currentPage + pageOffset - 0.5f ) : (currentPage - pageOffset + 0.5f ));
1052
1063
if ((deltaX > 0 && targetPage > currentPage ) || (deltaX < 0 && targetPage < currentPage ))
1053
1064
targetPage = currentPage ;
1054
1065
}
1055
- if (DEBUG ) Log .v (TAG , "targetPage : " + targetPage );
1056
1066
return targetPage ;
1057
1067
}
1058
1068
0 commit comments