Skip to content

Commit 29547a0

Browse files
author
jfeinstein10
committed
Pointer out of range fix
1 parent 24893d0 commit 29547a0

File tree

1 file changed

+37
-48
lines changed

1 file changed

+37
-48
lines changed

library/src/com/slidingmenu/lib/CustomViewAbove.java

Lines changed: 37 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -630,29 +630,13 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
630630

631631
switch (action) {
632632
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);
651634
break;
652-
653635
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;
656640
mLastMotionX = mInitialMotionX = MotionEventCompat.getX(ev, mActivePointerId);
657641
mLastMotionY = MotionEventCompat.getY(ev, mActivePointerId);
658642
if (thisTouchAllowed(ev)) {
@@ -708,37 +692,21 @@ public boolean onTouchEvent(MotionEvent ev) {
708692
completeScroll();
709693

710694
// Remember where the motion event started
695+
int index = MotionEventCompat.getActionIndex(ev);
696+
mActivePointerId = MotionEventCompat.getPointerId(ev, index);
711697
mLastMotionX = mInitialMotionX = ev.getX();
712-
mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
713698
break;
714699
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 + ")\nmIsBeingDragged:" + 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)
733703
return false;
734-
}
735704
}
736705
if (mIsBeingDragged) {
737706
// Scroll to follow the motion event
738707
final int activePointerIndex = getPointerIndex(ev, mActivePointerId);
739-
if (mActivePointerId == INVALID_POINTER) {
708+
if (mActivePointerId == INVALID_POINTER)
740709
break;
741-
}
742710
final float x = MotionEventCompat.getX(ev, activePointerIndex);
743711
final float deltaX = mLastMotionX - x;
744712
mLastMotionX = x;
@@ -793,22 +761,43 @@ && xDiff > yDiff && thisSlideAllowed(dx)) {
793761
}
794762
break;
795763
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);
800767
break;
801768
}
802769
case MotionEventCompat.ACTION_POINTER_UP:
803770
onSecondaryPointerUp(ev);
804-
int pointerIndex = this.getPointerIndex(ev, mActivePointerId);
771+
int pointerIndex = getPointerIndex(ev, mActivePointerId);
805772
if (mActivePointerId == INVALID_POINTER)
806773
break;
807774
mLastMotionX = MotionEventCompat.getX(ev, pointerIndex);
808775
break;
809776
}
810777
return true;
811778
}
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+
}
812801

813802
@Override
814803
public void scrollTo(int x, int y) {

0 commit comments

Comments
 (0)