From 9937f81ac653ed08032c547147a0934422540a45 Mon Sep 17 00:00:00 2001 From: Phil Weaver Date: Mon, 1 Aug 2016 17:41:19 -0700 Subject: [PATCH] Reduce extra a11y events when alpha changes. 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 | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index e6481147c295..d53d69b61ca2 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -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); } } } -- 2.11.0