Forked from tcw165/ViewGroup_dispatchTouchEvent.java
Created
August 14, 2018 07:01
-
-
Save flyfire/ffc07938386789a88f44390e8152e0f4 to your computer and use it in GitHub Desktop.
dispatchTouchEvent sample of a ViewGroup in the Android framework.
This file contains hidden or 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
// Complete source code: | |
// https://github.com/android/platform_frameworks_base/blob/master/core/java/android/view/ViewGroup.java#L2143-L2357 | |
public boolean dispatchTouchEvent(MotionEvent ev) { | |
boolean handled = false; | |
// Ignore ... | |
final boolean intercepted; | |
if (actionMasked == MotionEvent.ACTION_DOWN | |
|| mFirstTouchTarget != null) { | |
final boolean disallowIntercept = (mGroupFlags & FLAG_DISALLOW_INTERCEPT) != 0; | |
if (!disallowIntercept) { | |
intercepted = onInterceptTouchEvent(ev); | |
ev.setAction(action); // restore action in case it was changed | |
} else { | |
intercepted = false; | |
} | |
} else { | |
// There are no touch targets and this action is not an initial down | |
// so this view group continues to intercept touches. | |
intercepted = true; | |
} | |
// Ignore ... | |
// Check for cancelation. | |
final boolean canceled = resetCancelNextUpFlag(this) | |
|| actionMasked == MotionEvent.ACTION_CANCEL; | |
if (!canceled && !intercepted) { | |
// Ignore ... | |
for (int i = childrenCount - 1; i >= 0; i--) { | |
final int childIndex = getAndVerifyPreorderedIndex( | |
childrenCount, i, customOrder); | |
final View child = getAndVerifyPreorderedView( | |
preorderedList, children, childIndex); | |
resetCancelNextUpFlag(child); | |
// dispatchTransformedTouchEvent will call dispatchTouchEvent | |
if (dispatchTransformedTouchEvent(ev, false, child, idBitsToAssign)) { | |
// Child wants to receive touch within its bounds. | |
// Ignore ... | |
break; | |
} | |
} | |
} | |
// Ignore ... | |
return handled; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment