55import android .graphics .Canvas ;
66import android .graphics .Color ;
77import android .graphics .Paint ;
8- import android .graphics .Rect ;
9- import android .graphics .drawable .BitmapDrawable ;
108import android .graphics .drawable .Drawable ;
119import android .os .Build ;
1210import android .support .v4 .view .KeyEventCompat ;
@@ -97,7 +95,7 @@ public float getInterpolation(float t) {
9795 private int mFlingDistance ;
9896
9997 private boolean mLastTouchAllowed = false ;
100- private final int mSlidingMenuThreshold = 10 ;
98+ private final int mSlidingMenuThreshold = 16 ;
10199 private CustomViewBehind mViewBehindLeft ;
102100 private CustomViewBehind mViewBehindRight ;
103101 private boolean mEnabled = true ;
@@ -772,6 +770,22 @@ private boolean thisTouchAllowed(MotionEvent ev) {
772770 }
773771 }
774772 }
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+ }
775789
776790 private boolean mIsUnableToDrag ;
777791
@@ -814,7 +828,7 @@ else if (mIsUnableToDrag)
814828 final float xDiff = Math .abs (dx );
815829 final float y = MotionEventCompat .getY (ev , pointerIndex );
816830 final float yDiff = Math .abs (y - mLastMotionY );
817- if (xDiff > mTouchSlop && xDiff > yDiff ) {
831+ if (xDiff > mTouchSlop && xDiff > yDiff && thisSlideAllowed ( dx ) ) {
818832 if (DEBUG ) Log .v (TAG , "Starting drag! from onInterceptTouch" );
819833 mIsBeingDragged = true ;
820834 mLastMotionX = x ;
@@ -825,8 +839,7 @@ else if (mIsUnableToDrag)
825839 break ;
826840
827841 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 ;
830843 mLastMotionX = mInitialMotionX = MotionEventCompat .getX (ev , mActivePointerId );
831844 mLastMotionY = MotionEventCompat .getY (ev , mActivePointerId );
832845 if (thisTouchAllowed (ev )) {
@@ -936,7 +949,6 @@ public boolean onTouchEvent(MotionEvent ev) {
936949 velocityTracker , mActivePointerId );
937950 final int widthWithMargin = getChildWidth (mCurItem );
938951 final int scrollX = getScrollX ();
939- final int currentPage = scrollX / widthWithMargin ;
940952 final float pageOffset = (float ) (scrollX % widthWithMargin ) / widthWithMargin ;
941953 final int activePointerIndex =
942954 MotionEventCompat .findPointerIndex (ev , mActivePointerId );
@@ -1044,15 +1056,13 @@ public void scrollTo(int x, int y) {
10441056 private int determineTargetPage (int currentPage , float pageOffset , int velocity , int deltaX ) {
10451057 int targetPage ;
10461058 if (Math .abs (deltaX ) > (float )mFlingDistance && Math .abs (velocity ) > mMinimumVelocity ) {
1047- Log .v (TAG , "in here!" );
10481059 targetPage = velocity > 0 ? currentPage - 1 : currentPage + 1 ;
10491060 } else {
10501061 targetPage = (int ) ((deltaX > 0 ) ?
10511062 (currentPage + pageOffset - 0.5f ) : (currentPage - pageOffset + 0.5f ));
10521063 if ((deltaX > 0 && targetPage > currentPage ) || (deltaX < 0 && targetPage < currentPage ))
10531064 targetPage = currentPage ;
10541065 }
1055- if (DEBUG ) Log .v (TAG , "targetPage : " + targetPage );
10561066 return targetPage ;
10571067 }
10581068
0 commit comments