3333import android .view .ViewGroup ;
3434import android .view .ViewTreeObserver ;
3535import android .view .ViewTreeObserver .OnGlobalLayoutListener ;
36+ import android .view .accessibility .AccessibilityEvent ;
37+ import android .view .accessibility .AccessibilityManager ;
3638import 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 }
0 commit comments