OSDN Git Service

Reduce extra a11y events when alpha changes.
authorPhil Weaver <pweaver@google.com>
Tue, 2 Aug 2016 00:41:19 +0000 (17:41 -0700)
committerPhil Weaver <pweaver@google.com>
Tue, 2 Aug 2016 00:41:19 +0000 (17:41 -0700)
Changes in alpha only matter if they affect visibility,
so only 0 <-> nonzero changes are worth reporting. Report
them as subtree changes, as visibility affects subviews.

Not reporting every change greatly reduces the number of
event reported when alpha is animated.

Bug: 30183085
Change-Id: I905d53aa81ca8248b3aed86a91842ef499f303a8

core/java/android/view/View.java

index e648114..d53d69b 100644 (file)
@@ -12303,6 +12303,10 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
     public void setAlpha(@FloatRange(from=0.0, to=1.0) float alpha) {
         ensureTransformationInfo();
         if (mTransformationInfo.mAlpha != alpha) {
+            // Report visibility changes, which can affect children, to accessibility
+            if ((alpha == 0) ^ (mTransformationInfo.mAlpha == 0)) {
+                notifySubtreeAccessibilityStateChangedIfNeeded();
+            }
             mTransformationInfo.mAlpha = alpha;
             if (onSetAlpha((int) (alpha * 255))) {
                 mPrivateFlags |= PFLAG_ALPHA_SET;
@@ -12313,8 +12317,6 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
                 mPrivateFlags &= ~PFLAG_ALPHA_SET;
                 invalidateViewProperty(true, false);
                 mRenderNode.setAlpha(getFinalAlpha());
-                notifyViewAccessibilityStateChangedIfNeeded(
-                        AccessibilityEvent.CONTENT_CHANGE_TYPE_UNDEFINED);
             }
         }
     }