From 70853772bd119339244a4fc8e020ad78495228be Mon Sep 17 00:00:00 2001 From: Svetoslav Ganov Date: Fri, 30 Sep 2011 19:57:35 -0700 Subject: [PATCH] Adding accessibility support to the share UI. 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 --- .../android/widget/ActivityChooserView.java | 46 ++++++++++++++++++- .../android/widget/ShareActionProvider.java | 6 +++ core/res/res/values/strings.xml | 10 ++++ 3 files changed, 61 insertions(+), 1 deletion(-) diff --git a/core/java/android/widget/ActivityChooserView.java b/core/java/android/widget/ActivityChooserView.java index c37cc52238300..60b24bc1207ec 100644 --- a/core/java/android/widget/ActivityChooserView.java +++ b/core/java/android/widget/ActivityChooserView.java @@ -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; /** @@ -168,6 +170,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. * @@ -259,7 +266,7 @@ public class ActivityChooserView extends ViewGroup implements ActivityChooserMod * * Note: 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 a share activity is to be chosen the drawable should * give a clue that sharing is to be performed. * * @param drawable The drawable. @@ -268,6 +275,21 @@ public class ActivityChooserView extends ViewGroup implements ActivityChooserMod mExpandActivityOverflowButtonImage.setImageDrawable(drawable); } + /** + * 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)); } } @@ -430,6 +454,20 @@ public class ActivityChooserView extends ViewGroup implements ActivityChooserMod mInitialActivityCount = itemCount; } + /** + * 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. * @@ -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); } diff --git a/core/java/android/widget/ShareActionProvider.java b/core/java/android/widget/ShareActionProvider.java index 36278907cea24..bb27b73fc2968 100644 --- a/core/java/android/widget/ShareActionProvider.java +++ b/core/java/android/widget/ShareActionProvider.java @@ -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; } diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml index 2d5d4cc8ff292..1e0151afee7a1 100755 --- a/core/res/res/values/strings.xml +++ b/core/res/res/values/strings.xml @@ -3182,6 +3182,16 @@ Enter + + + Choose an application + + + + Share with + + Share with %s +