OSDN Git Service

Stop double notifying a11y about Toasts.
authorPhil Weaver <pweaver@google.com>
Mon, 29 Aug 2016 22:59:03 +0000 (15:59 -0700)
committerPhil Weaver <pweaver@google.com>
Tue, 30 Aug 2016 22:41:59 +0000 (15:41 -0700)
TalkBack was speaking all Toasts twice because we were
sending both NOTIFICATION and a WINDOW_STATE_CHANGE events
when Toasts were displayed.

Stop sending the WINDOW_STATE_CHANGE event for toasts.
Bug: 30570188
Change-Id: I26c6dc50350dfd4daf2a706b94fadcf5d1e03557

core/java/android/view/ViewRootImpl.java

index 7494b94..931bced 100644 (file)
@@ -2172,7 +2172,12 @@ public final class ViewRootImpl implements ViewParent,
         }
 
         if (changedVisibility || regainedFocus) {
-            host.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
+            // Toasts are presented as notifications - don't present them as windows as well
+            boolean isToast = (mWindowAttributes == null) ? false
+                    : (mWindowAttributes.type == WindowManager.LayoutParams.TYPE_TOAST);
+            if (!isToast) {
+                host.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
+            }
         }
 
         mFirst = false;