summaryrefslogtreecommitdiff
path: root/core/java/android/widget/ProgressBar.java
diff options
context:
space:
mode:
authorSvetoslav Ganov <svetoslavganov@google.com>2011-03-18 16:19:55 -0700
committerSvetoslav Ganov <svetoslavganov@google.com>2011-03-18 16:22:27 -0700
commit6518ad760f98a0aa5db8c49ce1564bf5907a2c15 (patch)
tree5ba0db743a1ac44e999ab40a26c108b589ff93d7 /core/java/android/widget/ProgressBar.java
parentc42faa1e6179fb1bb538698e581b6e1868d73b9c (diff)
ProgressBar does not fire accessibility events on update.
bug:2866092 The progress bar fires accessibility events upon progress change but not more frequently of every 200 ms. Change-Id: I6560af61e3b3a7d28836723a5ab632fb467f47e1
Diffstat (limited to 'core/java/android/widget/ProgressBar.java')
-rw-r--r--core/java/android/widget/ProgressBar.java56
1 files changed, 52 insertions, 4 deletions
diff --git a/core/java/android/widget/ProgressBar.java b/core/java/android/widget/ProgressBar.java
index cf72ec40f604..8db34d91d74f 100644
--- a/core/java/android/widget/ProgressBar.java
+++ b/core/java/android/widget/ProgressBar.java
@@ -16,6 +16,8 @@
package android.widget;
+import com.android.internal.R;
+
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
@@ -41,6 +43,8 @@ import android.view.Gravity;
import android.view.RemotableViewMethod;
import android.view.View;
import android.view.ViewDebug;
+import android.view.accessibility.AccessibilityEvent;
+import android.view.accessibility.AccessibilityManager;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
@@ -49,8 +53,6 @@ import android.view.animation.LinearInterpolator;
import android.view.animation.Transformation;
import android.widget.RemoteViews.RemoteView;
-import com.android.internal.R;
-
/**
* <p>
@@ -125,6 +127,7 @@ import com.android.internal.R;
public class ProgressBar extends View {
private static final int MAX_LEVEL = 10000;
private static final int ANIMATION_RESOLUTION = 200;
+ private static final int TIMEOUT_SEND_ACCESSIBILITY_EVENT = 200;
int mMinWidth;
int mMaxWidth;
@@ -156,6 +159,8 @@ public class ProgressBar extends View {
private int mAnimationResolution;
+ private AccessibilityEventSender mAccessibilityEventSender;
+
/**
* Create a new progress bar with range 0...100 and initial progress of 0.
* @param context the application environment
@@ -542,8 +547,11 @@ public class ProgressBar extends View {
onProgressRefresh(scale, fromUser);
}
}
-
- void onProgressRefresh(float scale, boolean fromUser) {
+
+ void onProgressRefresh(float scale, boolean fromUser) {
+ if (AccessibilityManager.getInstance(mContext).isEnabled()) {
+ scheduleAccessibilityEventSender();
+ }
}
private synchronized void refreshProgress(int id, int progress, boolean fromUser) {
@@ -1007,8 +1015,48 @@ public class ProgressBar extends View {
if (mIndeterminate) {
stopAnimation();
}
+ if(mRefreshProgressRunnable != null) {
+ removeCallbacks(mRefreshProgressRunnable);
+ }
+ 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();
}
+
+ @Override
+ public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
+ if (!super.dispatchPopulateAccessibilityEvent(event)) {
+ event.setItemCount(mMax);
+ event.setCurrentItemIndex(mProgress);
+ }
+ return true;
+ }
+
+ /**
+ * Schedule a command for sending an accessibility event.
+ * </br>
+ * 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);
+ }
+
+ /**
+ * Command for sending an accessibility event.
+ */
+ private class AccessibilityEventSender implements Runnable {
+ public void run() {
+ sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
+ }
+ }
}