Created
January 5, 2018 02:53
-
-
Save chiemy/35bc8c2fa4c6a75d409a70650bfda3d6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public boolean dispatchTouchEvent(MotionEvent ev) { | |
final int action = ev.getAction(); | |
final float xf = ev.getX(); | |
final float yf = ev.getY(); | |
final float scrolledXFloat = xf + mScrollX; | |
final float scrolledYFloat = yf + mScrollY; | |
final Rect frame = mTempRect; | |
boolean disallowIntercept = (mGroupFlags & FLAG_DISALLOW_INTERCEPT) != 0; | |
if (action == MotionEvent.ACTION_DOWN) { | |
if (mMotionTarget != null) { | |
mMotionTarget = null; | |
} | |
if (disallowIntercept || !onInterceptTouchEvent(ev)) { | |
ev.setAction(MotionEvent.ACTION_DOWN); | |
final int scrolledXInt = (int) scrolledXFloat; | |
final int scrolledYInt = (int) scrolledYFloat; | |
final View[] children = mChildren; | |
final int count = mChildrenCount; | |
for (int i = count - 1; i >= 0; i--) { | |
final View child = children[i]; | |
if ((child.mViewFlags & VISIBILITY_MASK) == VISIBLE | |
|| child.getAnimation() != null) { | |
child.getHitRect(frame); | |
if (frame.contains(scrolledXInt, scrolledYInt)) { | |
final float xc = scrolledXFloat - child.mLeft; | |
final float yc = scrolledYFloat - child.mTop; | |
ev.setLocation(xc, yc); | |
child.mPrivateFlags &= ~CANCEL_NEXT_UP_EVENT; | |
if (child.dispatchTouchEvent(ev)) { | |
mMotionTarget = child; | |
return true; | |
} | |
} | |
} | |
} | |
} | |
} | |
boolean isUpOrCancel = (action == MotionEvent.ACTION_UP) || | |
(action == MotionEvent.ACTION_CANCEL); | |
if (isUpOrCancel) { | |
mGroupFlags &= ~FLAG_DISALLOW_INTERCEPT; | |
} | |
final View target = mMotionTarget; | |
if (target == null) { | |
ev.setLocation(xf, yf); | |
if ((mPrivateFlags & CANCEL_NEXT_UP_EVENT) != 0) { | |
ev.setAction(MotionEvent.ACTION_CANCEL); | |
mPrivateFlags &= ~CANCEL_NEXT_UP_EVENT; | |
} | |
return super.dispatchTouchEvent(ev); | |
} | |
if (!disallowIntercept && onInterceptTouchEvent(ev)) { | |
final float xc = scrolledXFloat - (float) target.mLeft; | |
final float yc = scrolledYFloat - (float) target.mTop; | |
mPrivateFlags &= ~CANCEL_NEXT_UP_EVENT; | |
ev.setAction(MotionEvent.ACTION_CANCEL); | |
ev.setLocation(xc, yc); | |
if (!target.dispatchTouchEvent(ev)) { | |
} | |
mMotionTarget = null; | |
return true; | |
} | |
if (isUpOrCancel) { | |
mMotionTarget = null; | |
} | |
final float xc = scrolledXFloat - (float) target.mLeft; | |
final float yc = scrolledYFloat - (float) target.mTop; | |
ev.setLocation(xc, yc); | |
if ((target.mPrivateFlags & CANCEL_NEXT_UP_EVENT) != 0) { | |
ev.setAction(MotionEvent.ACTION_CANCEL); | |
target.mPrivateFlags &= ~CANCEL_NEXT_UP_EVENT; | |
mMotionTarget = null; | |
} | |
return target.dispatchTouchEvent(ev); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment