Skip to content

Commit a6478a3

Browse files
committed
Respect child drawing order when dispatching touch events
Make sure that touch events are always dispatched to the "topmost" view when views overlap. Bug 6996501 Change-Id: I4df25dd7531c4b268c8377c0bf0945ab862733b9
1 parent 9a994b5 commit a6478a3

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

core/java/android/view/ViewGroup.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1715,8 +1715,10 @@ protected boolean dispatchGenericPointerEvent(MotionEvent event) {
17151715
final float x = event.getX();
17161716
final float y = event.getY();
17171717

1718+
final boolean customOrder = isChildrenDrawingOrderEnabled();
17181719
for (int i = childrenCount - 1; i >= 0; i--) {
1719-
final View child = children[i];
1720+
final int childIndex = customOrder ? getChildDrawingOrder(childrenCount, i) : i;
1721+
final View child = children[childIndex];
17201722
if (!canViewReceivePointerEvents(child)
17211723
|| !isTransformedTouchPointInView(x, y, child, null)) {
17221724
continue;
@@ -1841,8 +1843,11 @@ public boolean dispatchTouchEvent(MotionEvent ev) {
18411843
final float x = ev.getX(actionIndex);
18421844
final float y = ev.getY(actionIndex);
18431845

1846+
final boolean customOrder = isChildrenDrawingOrderEnabled();
18441847
for (int i = childrenCount - 1; i >= 0; i--) {
1845-
final View child = children[i];
1848+
final int childIndex = customOrder ?
1849+
getChildDrawingOrder(childrenCount, i) : i;
1850+
final View child = children[childIndex];
18461851
if (!canViewReceivePointerEvents(child)
18471852
|| !isTransformedTouchPointInView(x, y, child, null)) {
18481853
continue;
@@ -1860,7 +1865,7 @@ public boolean dispatchTouchEvent(MotionEvent ev) {
18601865
if (dispatchTransformedTouchEvent(ev, false, child, idBitsToAssign)) {
18611866
// Child wants to receive touch within its bounds.
18621867
mLastTouchDownTime = ev.getDownTime();
1863-
mLastTouchDownIndex = i;
1868+
mLastTouchDownIndex = childIndex;
18641869
mLastTouchDownX = ev.getX();
18651870
mLastTouchDownY = ev.getY();
18661871
newTouchTarget = addTouchTarget(child, idBitsToAssign);

0 commit comments

Comments
 (0)