Skip to content

Commit 7085377

Browse files
committed
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
1 parent b11d09c commit 7085377

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed

core/java/android/widget/ActivityChooserView.java

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
import android.view.ViewGroup;
3434
import android.view.ViewTreeObserver;
3535
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
36+
import android.view.accessibility.AccessibilityEvent;
37+
import android.view.accessibility.AccessibilityManager;
3638
import android.widget.ActivityChooserModel.ActivityChooserModelClient;
3739

3840
/**
@@ -168,6 +170,11 @@ public void onGlobalLayout() {
168170
*/
169171
private boolean mIsAttachedToWindow;
170172

173+
/**
174+
* String resource for formatting content description of the default target.
175+
*/
176+
private int mDefaultActionButtonContentDescription;
177+
171178
/**
172179
* Create a new instance.
173180
*
@@ -259,7 +266,7 @@ public void setActivityChooserModel(ActivityChooserModel dataModel) {
259266
*
260267
* <strong>Note:</strong> Clients would like to set this drawable
261268
* as a clue about the action the chosen activity will perform. For
262-
* example, if share activity is to be chosen the drawable should
269+
* example, if a share activity is to be chosen the drawable should
263270
* give a clue that sharing is to be performed.
264271
*
265272
* @param drawable The drawable.
@@ -268,6 +275,21 @@ public void setExpandActivityOverflowButtonDrawable(Drawable drawable) {
268275
mExpandActivityOverflowButtonImage.setImageDrawable(drawable);
269276
}
270277

278+
/**
279+
* Sets the content description for the button that expands the activity
280+
* overflow list.
281+
*
282+
* description as a clue about the action performed by the button.
283+
* For example, if a share activity is to be chosen the content
284+
* description should be something like "Share with".
285+
*
286+
* @param resourceId The content description resource id.
287+
*/
288+
public void setExpandActivityOverflowButtonContentDescription(int resourceId) {
289+
CharSequence contentDescription = mContext.getString(resourceId);
290+
mExpandActivityOverflowButtonImage.setContentDescription(contentDescription);
291+
}
292+
271293
/**
272294
* Set the provider hosting this view, if applicable.
273295
* @hide Internal use only
@@ -329,6 +351,8 @@ private void showPopupUnchecked(int maxActivityCount) {
329351
if (mProvider != null) {
330352
mProvider.subUiVisibilityChanged(true);
331353
}
354+
popupWindow.getListView().setContentDescription(mContext.getString(
355+
R.string.activitychooserview_choose_application));
332356
}
333357
}
334358

@@ -430,6 +454,20 @@ public void setInitialActivityCount(int itemCount) {
430454
mInitialActivityCount = itemCount;
431455
}
432456

457+
/**
458+
* Sets a content description of the default action button. This
459+
* resource should be a string taking one formatting argument and
460+
* will be used for formatting the content description of the button
461+
* dynamically as the default target changes. For example, a resource
462+
* pointing to the string "share with %1$s" will result in a content
463+
* description "share with Bluetooth" for the Bluetooth activity.
464+
*
465+
* @param resourceId The resource id.
466+
*/
467+
public void setDefaultActionButtonContentDescription(int resourceId) {
468+
mDefaultActionButtonContentDescription = resourceId;
469+
}
470+
433471
/**
434472
* Gets the list popup window which is lazily initialized.
435473
*
@@ -465,6 +503,12 @@ private void updateAppearance() {
465503
ResolveInfo activity = mAdapter.getDefaultActivity();
466504
PackageManager packageManager = mContext.getPackageManager();
467505
mDefaultActivityButtonImage.setImageDrawable(activity.loadIcon(packageManager));
506+
if (mDefaultActionButtonContentDescription != 0) {
507+
CharSequence label = activity.loadLabel(packageManager);
508+
String contentDescription = mContext.getString(
509+
mDefaultActionButtonContentDescription, label);
510+
mDefaultActivityButton.setContentDescription(contentDescription);
511+
}
468512
} else {
469513
mDefaultActivityButton.setVisibility(View.GONE);
470514
}

core/java/android/widget/ShareActionProvider.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,12 @@ public View onCreateActionView() {
171171
activityChooserView.setExpandActivityOverflowButtonDrawable(drawable);
172172
activityChooserView.setProvider(this);
173173

174+
// Set content description.
175+
activityChooserView.setDefaultActionButtonContentDescription(
176+
R.string.shareactionprovider_share_with_application);
177+
activityChooserView.setExpandActivityOverflowButtonContentDescription(
178+
R.string.shareactionprovider_share_with);
179+
174180
return activityChooserView;
175181
}
176182

core/res/res/values/strings.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3182,6 +3182,16 @@
31823182
<!-- Description of the Enter button in a KeyboardView. [CHAR LIMIT=NONE] -->
31833183
<string name="keyboardview_keycode_enter">Enter</string>
31843184

3185+
<!-- ActivityChooserView - accessibility support -->
3186+
<!-- Description of the shwoing of a popup window with activities to choose from. [CHAR LIMIT=NONE] -->
3187+
<string name="activitychooserview_choose_application">Choose an application</string>
3188+
3189+
<!-- ShareActionProvider - accessibility support -->
3190+
<!-- Description of the choose target button in a ShareActionProvider (share UI). [CHAR LIMIT=NONE] -->
3191+
<string name="shareactionprovider_share_with">Share with</string>
3192+
<!-- Description of a share target (both in the list of such or the default share button) in a ShareActionProvider (share UI). [CHAR LIMIT=NONE] -->
3193+
<string name="shareactionprovider_share_with_application">Share with <xliff:g id="application_name" example="Bluetooth">%s</xliff:g></string>
3194+
31853195
<!-- Slide lock screen -->
31863196

31873197
<!-- Description of the sliding handle in the Slide unlock screen. [CHAR LIMIT=NONE] -->

0 commit comments

Comments
 (0)