From 9e3aebd8dde8618a28c5d124887b69c32b9cde63 Mon Sep 17 00:00:00 2001 From: Adam Cohen Date: Thu, 25 Jun 2020 19:22:37 -0700 Subject: [PATCH] During accessible drag, hover events were not properly getting dispatched to the DragAndDropAccessibilityDelegate => regressed in ag/10634216 which attemped to use onHoverListener => the problem is that onHoverListener is only triggered when the event is passed to the CellLayout, however, as with all dispatching, these events are handled depth first, and so in cases where a child handled the event, it would never bubble back up to the parent. => instead we have to continue to override dispatchHover event to always give presecedence to the delegate when it exists Bug: 155956518 Change-Id: Ic3ecf1b422c1821456328035a66a2fc1277e6746 (cherry picked from commit 6e7c37a2053c4334499c65b8a17dc0e85df5a54a) --- src/com/android/launcher3/CellLayout.java | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/com/android/launcher3/CellLayout.java b/src/com/android/launcher3/CellLayout.java index ed71ddc3b7..89d768c302 100644 --- a/src/com/android/launcher3/CellLayout.java +++ b/src/com/android/launcher3/CellLayout.java @@ -182,7 +182,7 @@ public class CellLayout extends ViewGroup { private static final Paint sPaint = new Paint(); // Related to accessible drag and drop - private boolean mUseTouchHelper = false; + DragAndDropAccessibilityDelegate mTouchHelper; public CellLayout(Context context) { this(context, null); @@ -290,17 +290,15 @@ public class CellLayout extends ViewGroup { addView(mShortcutsAndWidgets); } - /** * Sets or clears a delegate used for accessible drag and drop */ public void setDragAndDropAccessibilityDelegate(DragAndDropAccessibilityDelegate delegate) { setOnClickListener(delegate); - setOnHoverListener(delegate); ViewCompat.setAccessibilityDelegate(this, delegate); - mUseTouchHelper = delegate != null; - int accessibilityFlag = mUseTouchHelper + mTouchHelper = delegate; + int accessibilityFlag = mTouchHelper != null ? IMPORTANT_FOR_ACCESSIBILITY_YES : IMPORTANT_FOR_ACCESSIBILITY_NO; setImportantForAccessibility(accessibilityFlag); getShortcutsAndWidgets().setImportantForAccessibility(accessibilityFlag); @@ -312,10 +310,19 @@ public class CellLayout extends ViewGroup { } } + @Override + public boolean dispatchHoverEvent(MotionEvent event) { + // Always attempt to dispatch hover events to accessibility first. + if (mTouchHelper != null && mTouchHelper.dispatchHoverEvent(event)) { + return true; + } + return super.dispatchHoverEvent(event); + } + @Override public boolean onInterceptTouchEvent(MotionEvent ev) { - if (mUseTouchHelper || - (mInterceptTouchListener != null && mInterceptTouchListener.onTouch(this, ev))) { + if (mTouchHelper != null + || (mInterceptTouchListener != null && mInterceptTouchListener.onTouch(this, ev))) { return true; } return false;