OSDN Git Service

Adding accessibility support to the share UI.
authorSvetoslav Ganov <svetoslavganov@google.com>
Sat, 1 Oct 2011 02:57:35 +0000 (19:57 -0700)
committerSvetoslav Ganov <svetoslavganov@google.com>
Mon, 3 Oct 2011 18:16:40 +0000 (11:16 -0700)
Added content description to the overflow button and default
action target as well as content description for the popup
list with share targets.

bug:5398787

Change-Id: Iea1e9d85893899f7d161986cb958595083c79b93

core/java/android/widget/ActivityChooserView.java
core/java/android/widget/ShareActionProvider.java
core/res/res/values/strings.xml

index c37cc52..60b24bc 100644 (file)
@@ -33,6 +33,8 @@ import android.view.View;
 import android.view.ViewGroup;
 import android.view.ViewTreeObserver;
 import android.view.ViewTreeObserver.OnGlobalLayoutListener;
+import android.view.accessibility.AccessibilityEvent;
+import android.view.accessibility.AccessibilityManager;
 import android.widget.ActivityChooserModel.ActivityChooserModelClient;
 
 /**
@@ -169,6 +171,11 @@ public class ActivityChooserView extends ViewGroup implements ActivityChooserMod
     private boolean mIsAttachedToWindow;
 
     /**
+     * String resource for formatting content description of the default target.
+     */
+    private int mDefaultActionButtonContentDescription;
+
+    /**
      * Create a new instance.
      *
      * @param context The application environment.
@@ -259,7 +266,7 @@ public class ActivityChooserView extends ViewGroup implements ActivityChooserMod
      *
      * <strong>Note:</strong> Clients would like to set this drawable
      * as a clue about the action the chosen activity will perform. For
-     * example, if share activity is to be chosen the drawable should
+     * example, if share activity is to be chosen the drawable should
      * give a clue that sharing is to be performed.
      *
      * @param drawable The drawable.
@@ -269,6 +276,21 @@ public class ActivityChooserView extends ViewGroup implements ActivityChooserMod
     }
 
     /**
+     * Sets the content description for the button that expands the activity
+     * overflow list.
+     *
+     * description as a clue about the action performed by the button.
+     * For example, if a share activity is to be chosen the content
+     * description should be something like "Share with".
+     *
+     * @param resourceId The content description resource id.
+     */
+    public void setExpandActivityOverflowButtonContentDescription(int resourceId) {
+        CharSequence contentDescription = mContext.getString(resourceId);
+        mExpandActivityOverflowButtonImage.setContentDescription(contentDescription);
+    }
+
+    /**
      * Set the provider hosting this view, if applicable.
      * @hide Internal use only
      */
@@ -329,6 +351,8 @@ public class ActivityChooserView extends ViewGroup implements ActivityChooserMod
             if (mProvider != null) {
                 mProvider.subUiVisibilityChanged(true);
             }
+            popupWindow.getListView().setContentDescription(mContext.getString(
+                    R.string.activitychooserview_choose_application));
         }
     }
 
@@ -431,6 +455,20 @@ public class ActivityChooserView extends ViewGroup implements ActivityChooserMod
     }
 
     /**
+     * Sets a content description of the default action button. This
+     * resource should be a string taking one formatting argument and
+     * will be used for formatting the content description of the button
+     * dynamically as the default target changes. For example, a resource
+     * pointing to the string "share with %1$s" will result in a content
+     * description "share with Bluetooth" for the Bluetooth activity.
+     *
+     * @param resourceId The resource id.
+     */
+    public void setDefaultActionButtonContentDescription(int resourceId) {
+        mDefaultActionButtonContentDescription = resourceId;
+    }
+
+    /**
      * Gets the list popup window which is lazily initialized.
      *
      * @return The popup.
@@ -465,6 +503,12 @@ public class ActivityChooserView extends ViewGroup implements ActivityChooserMod
             ResolveInfo activity = mAdapter.getDefaultActivity();
             PackageManager packageManager = mContext.getPackageManager();
             mDefaultActivityButtonImage.setImageDrawable(activity.loadIcon(packageManager));
+            if (mDefaultActionButtonContentDescription != 0) {
+                CharSequence label = activity.loadLabel(packageManager);
+                String contentDescription = mContext.getString(
+                        mDefaultActionButtonContentDescription, label);
+                mDefaultActivityButton.setContentDescription(contentDescription);
+            }
         } else {
             mDefaultActivityButton.setVisibility(View.GONE);
         }
index 3627890..bb27b73 100644 (file)
@@ -171,6 +171,12 @@ public class ShareActionProvider extends ActionProvider {
         activityChooserView.setExpandActivityOverflowButtonDrawable(drawable);
         activityChooserView.setProvider(this);
 
+        // Set content description.
+        activityChooserView.setDefaultActionButtonContentDescription(
+                R.string.shareactionprovider_share_with_application);
+        activityChooserView.setExpandActivityOverflowButtonContentDescription(
+                R.string.shareactionprovider_share_with);
+
         return activityChooserView;
     }
 
index 2d5d4cc..1e0151a 100755 (executable)
     <!-- Description of the Enter button in a KeyboardView. [CHAR LIMIT=NONE] -->
     <string name="keyboardview_keycode_enter">Enter</string>
 
+    <!-- ActivityChooserView - accessibility support -->
+    <!-- Description of the shwoing of a popup window with activities to choose from. [CHAR LIMIT=NONE] -->
+    <string name="activitychooserview_choose_application">Choose an application</string>
+
+    <!-- ShareActionProvider - accessibility support -->
+    <!-- Description of the choose target button in a ShareActionProvider (share UI). [CHAR LIMIT=NONE] -->
+    <string name="shareactionprovider_share_with">Share with</string>
+    <!-- Description of a share target (both in the list of such or the default share button) in a ShareActionProvider (share UI). [CHAR LIMIT=NONE] -->
+    <string name="shareactionprovider_share_with_application">Share with <xliff:g id="application_name" example="Bluetooth">%s</xliff:g></string>
+
     <!-- Slide lock screen -->
 
     <!-- Description of the sliding handle in the Slide unlock screen. [CHAR LIMIT=NONE] -->