OSDN Git Service

add a11y announcement when multi toggle button changes
authorAlan Newberger <alann@google.com>
Tue, 4 Feb 2014 17:15:47 +0000 (09:15 -0800)
committerAlan Newberger <alann@google.com>
Tue, 4 Feb 2014 17:15:47 +0000 (09:15 -0800)
addressing TODO with a manual announcement whenever the content
description of a button changes. Does checking of existing content
description to reduce chattiness when options are set by the system
e.g. on a resolution or orientation change. Still a bit of chattiness
on startup if the app is setting a button to a nonstandard value, but
I think its acceptable, it's giving user useful information about
nonstandard options on startup.

Bug: 10745077
Change-Id: I81089b2f4f7f14b90c4436199895a0f67075c3d3

res/values/strings.xml
src/com/android/camera/MultiToggleImageButton.java

index 924d35d..c72b384 100644 (file)
@@ -748,6 +748,9 @@ CHAR LIMIT=NONE] -->
     <!-- Accessibility text for filmstrip delete button [CHAR_LIMIT=NONE] -->
     <string name="delete_button_description">Delete</string>
 
+    <!-- Accessibility announcement when option button changes on screen after tap, e.g. from flash auto to flash off [CHAR_LIMIT=NONE] -->
+    <string name="button_change_announcement">Button is now %s</string>
+
     <!-- Text shown in camera settings list for toggling photo location on or off [CHAR LIMIT=25] -->
     <string name="setting_location">Location</string>
     <!-- Text shown in camera settings list for selecting the size of photos that will be captured [CHAR LIMIT=25] -->
index 6b43cd6..361eefa 100644 (file)
@@ -109,9 +109,15 @@ public class MultiToggleImageButton extends ImageButton {
     public void setState(int state, boolean callListener) {
         mState = state;
         setImageResource(mImageIds[mState]);
-        setContentDescription(getResources().getString(mDescIds[mState]));
-        // TODO get talkback to announce the current button state
-        //sendAccessibilityEvent(AccessibilityEvent.CONTENT_CHANGE_TYPE_CONTENT_DESCRIPTION);
+        String oldContentDescription = String.valueOf(getContentDescription());
+        String newContentDescription = getResources().getString(mDescIds[mState]);
+        if (oldContentDescription != null && !oldContentDescription.isEmpty()
+                && !oldContentDescription.equals(newContentDescription)) {
+            setContentDescription(newContentDescription);
+            String announceChange = getResources().getString(
+                    R.string.button_change_announcement, newContentDescription);
+            announceForAccessibility(announceChange);
+        }
         super.setImageLevel(mLevel);
         if (callListener && mOnStateChangeListener != null) {
             mOnStateChangeListener.stateChanged(this, getState());