From 3e7bf9063469b424bb867820cf8567f4ee4a9576 Mon Sep 17 00:00:00 2001 From: yingleiw Date: Mon, 21 Oct 2019 16:04:05 -0700 Subject: [PATCH] remove accessibility event throttling in Progressbar The current throttling is not good: when we update progress periodically at an interval smaller than 200ms, no progress is announced except for the last 100% in talkback. We will reply on the throttling when sending out state change events after adopting the accessibility state api: we only send out state change events when the state description actually changes. Bug: 143079143 Test: tested with talkback test when updating progress at different frequencies. Change-Id: I7480a3420130fc42645df17074b093cdced430ae --- core/java/android/widget/ProgressBar.java | 33 +---------------------- 1 file changed, 1 insertion(+), 32 deletions(-) diff --git a/core/java/android/widget/ProgressBar.java b/core/java/android/widget/ProgressBar.java index 2e95743456926..d58d858c3b8a3 100644 --- a/core/java/android/widget/ProgressBar.java +++ b/core/java/android/widget/ProgressBar.java @@ -163,7 +163,6 @@ import java.util.ArrayList; public class ProgressBar extends View { private static final int MAX_LEVEL = 10000; - private static final int TIMEOUT_SEND_ACCESSIBILITY_EVENT = 200; /** Interpolator used for smooth progress animations. */ private static final DecelerateInterpolator PROGRESS_ANIM_INTERPOLATOR = @@ -244,8 +243,6 @@ public class ProgressBar extends View { private final ArrayList mRefreshData = new ArrayList(); - private AccessibilityEventSender mAccessibilityEventSender; - /** * Create a new progress bar with range 0...100 and initial progress of 0. * @param context the application environment @@ -1556,7 +1553,7 @@ public class ProgressBar extends View { void onProgressRefresh(float scale, boolean fromUser, int progress) { if (AccessibilityManager.getInstance(mContext).isEnabled()) { - scheduleAccessibilityEventSender(); + sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED); } } @@ -2250,9 +2247,6 @@ public class ProgressBar extends View { removeCallbacks(mRefreshProgressRunnable); mRefreshIsPosted = false; } - if (mAccessibilityEventSender != null) { - removeCallbacks(mAccessibilityEventSender); - } // This should come after stopAnimation(), otherwise an invalidate message remains in the // queue, which can prevent the entire view hierarchy from being GC'ed during a rotation super.onDetachedFromWindow(); @@ -2285,22 +2279,6 @@ public class ProgressBar extends View { } } - /** - * Schedule a command for sending an accessibility event. - *
- * Note: A command is used to ensure that accessibility events - * are sent at most one in a given time frame to save - * system resources while the progress changes quickly. - */ - private void scheduleAccessibilityEventSender() { - if (mAccessibilityEventSender == null) { - mAccessibilityEventSender = new AccessibilityEventSender(); - } else { - removeCallbacks(mAccessibilityEventSender); - } - postDelayed(mAccessibilityEventSender, TIMEOUT_SEND_ACCESSIBILITY_EVENT); - } - /** @hide */ @Override protected void encodeProperties(@NonNull ViewHierarchyEncoder stream) { @@ -2324,15 +2302,6 @@ public class ProgressBar extends View { return isIndeterminate() && getWindowVisibility() == VISIBLE && isShown(); } - /** - * Command for sending an accessibility event. - */ - private class AccessibilityEventSender implements Runnable { - public void run() { - sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED); - } - } - private static class ProgressTintInfo { ColorStateList mIndeterminateTintList; BlendMode mIndeterminateBlendMode;