Commit 51d278d3 authored by David Trainor's avatar David Trainor Committed by Commit Bot

Improve snackbar action accessibility.

1. Add the ability for clients to specify a string to announce when users
cluck on an action in a snackbar view.
2. Add Downloads Home download deletion / undo as the first client.

Skip-Translation-Screenshots-Check: True
Bug: 1090969
Change-Id: I97fb23a471542bbaa141ea0696e7ac3d60269e9c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2431455
Commit-Queue: David Trainor <dtrainor@chromium.org>
Reviewed-by: default avatarPavel Yatsuk <pavely@chromium.org>
Reviewed-by: default avatarShakti Sahu <shaktisahu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#816745}
parent 89726dd6
...@@ -46,6 +46,8 @@ public class DeleteUndoCoordinator { ...@@ -46,6 +46,8 @@ public class DeleteUndoCoordinator {
Snackbar.TYPE_ACTION, Snackbar.UMA_DOWNLOAD_DELETE_UNDO); Snackbar.TYPE_ACTION, Snackbar.UMA_DOWNLOAD_DELETE_UNDO);
snackbar.setAction(ContextUtils.getApplicationContext().getString(R.string.undo), callback); snackbar.setAction(ContextUtils.getApplicationContext().getString(R.string.undo), callback);
snackbar.setTemplateText(UndoUiUtils.getTemplateTextFor(itemsSelected)); snackbar.setTemplateText(UndoUiUtils.getTemplateTextFor(itemsSelected));
snackbar.setActionAccessibilityAnnouncement(
UndoUiUtils.getAccessibilityActionAnnouncementTextFor(itemsSelected));
mView.showSnackbar(snackbar); mView.showSnackbar(snackbar);
} }
......
...@@ -30,4 +30,15 @@ final class UndoUiUtils { ...@@ -30,4 +30,15 @@ final class UndoUiUtils {
? context.getString(R.string.delete_message) ? context.getString(R.string.delete_message)
: context.getString(R.string.undo_bar_multiple_downloads_delete_message); : context.getString(R.string.undo_bar_multiple_downloads_delete_message);
} }
/** @return A {@link String} representing the text to announce when an undo occurs. */
public static String getAccessibilityActionAnnouncementTextFor(Collection<OfflineItem> items) {
String title = getTitleFor(items);
Context context = ContextUtils.getApplicationContext();
return items.size() == 1
? context.getString(R.string.undo_bar_delete_restore_accessibility_message, title)
: context.getString(
R.string.undo_bar_multiple_downloads_delete_restore_accessibility_message,
title);
}
} }
\ No newline at end of file
...@@ -3363,6 +3363,12 @@ Data from your Incognito session will only be cleared from Chrome when you <ph n ...@@ -3363,6 +3363,12 @@ Data from your Incognito session will only be cleared from Chrome when you <ph n
<message name="IDS_UNDO_BAR_MULTIPLE_DOWNLOADS_DELETE_MESSAGE" desc="Message shown when you can undo deleting several downloads."> <message name="IDS_UNDO_BAR_MULTIPLE_DOWNLOADS_DELETE_MESSAGE" desc="Message shown when you can undo deleting several downloads.">
<ph name="NUMBER_OF_DOWNLOADS">%1$s<ex>3</ex></ph> downloads deleted <ph name="NUMBER_OF_DOWNLOADS">%1$s<ex>3</ex></ph> downloads deleted
</message> </message>
<message name="IDS_UNDO_BAR_DELETE_RESTORE_ACCESSIBILITY_MESSAGE" desc="Message spoken out loud for accessibility when a user decides to undo a download deletion.">
Restored <ph name="ITEM_TITLE">%1$s<ex>YouTube</ex></ph>
</message>
<message name="IDS_UNDO_BAR_MULTIPLE_DOWNLOADS_DELETE_RESTORE_ACCESSIBILITY_MESSAGE" desc="Message spoken out loud for accessibility when a user decides to undo multiple download deletions at once.">
<ph name="NUMBER_OF_DOWNLOADS">%1$s<ex>3</ex></ph> downloads restored
</message>
<!-- MultiWindow --> <!-- MultiWindow -->
<message name="IDS_UNSUPPORTED_NUMBER_OF_WINDOWS" desc="Popup message for when the user has tried to start too many concurrent versions of Chrome."> <message name="IDS_UNSUPPORTED_NUMBER_OF_WINDOWS" desc="Popup message for when the user has tried to start too many concurrent versions of Chrome.">
......
...@@ -95,6 +95,7 @@ public class Snackbar { ...@@ -95,6 +95,7 @@ public class Snackbar {
private String mTemplateText; private String mTemplateText;
private String mActionText; private String mActionText;
private Object mActionData; private Object mActionData;
private String mAccessibilityActionAnnouncement;
private int mBackgroundColor; private int mBackgroundColor;
private int mTextApperanceResId; private int mTextApperanceResId;
private boolean mSingleLine = true; private boolean mSingleLine = true;
...@@ -162,6 +163,16 @@ public class Snackbar { ...@@ -162,6 +163,16 @@ public class Snackbar {
return this; return this;
} }
/**
* Sets the text to accessibility announce when the action button is pressed.
* @param accessibilityActionAnnouncement An optional string to be announced when the action
* button is pressed.
*/
public Snackbar setActionAccessibilityAnnouncement(String accessibilityActionAnnouncement) {
mAccessibilityActionAnnouncement = accessibilityActionAnnouncement;
return this;
}
/** /**
* Sets the identity profile image that will be displayed at the beginning of the snackbar. * Sets the identity profile image that will be displayed at the beginning of the snackbar.
* If null, there won't be a profile image. The ability to have an icon is exclusive to * If null, there won't be a profile image. The ability to have an icon is exclusive to
...@@ -241,6 +252,10 @@ public class Snackbar { ...@@ -241,6 +252,10 @@ public class Snackbar {
return mActionData; return mActionData;
} }
String getActionAccessibilityAnnouncement() {
return mAccessibilityActionAnnouncement;
}
boolean getSingleLine() { boolean getSingleLine() {
return mSingleLine; return mSingleLine;
} }
......
...@@ -179,6 +179,7 @@ public class SnackbarManager implements OnClickListener, ActivityStateListener, ...@@ -179,6 +179,7 @@ public class SnackbarManager implements OnClickListener, ActivityStateListener,
*/ */
@Override @Override
public void onClick(View v) { public void onClick(View v) {
mView.announceActionForAccessibility();
mSnackbars.removeCurrentDueToAction(); mSnackbars.removeCurrentDueToAction();
updateView(); updateView();
} }
......
...@@ -12,6 +12,7 @@ import android.app.Activity; ...@@ -12,6 +12,7 @@ import android.app.Activity;
import android.graphics.Rect; import android.graphics.Rect;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable; import android.graphics.drawable.GradientDrawable;
import android.text.TextUtils;
import android.view.Gravity; import android.view.Gravity;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.SurfaceView; import android.view.SurfaceView;
...@@ -210,6 +211,15 @@ public class SnackbarView { ...@@ -210,6 +211,15 @@ public class SnackbarView {
+ mContainerView.getResources().getString(R.string.bottom_bar_screen_position)); + mContainerView.getResources().getString(R.string.bottom_bar_screen_position));
} }
/**
* Sends an accessibility event to mContainerView announcing that an action was taken based on
* the action button being pressed. May do nothing if no announcement was specified.
*/
public void announceActionForAccessibility() {
if (TextUtils.isEmpty(mSnackbar.getActionAccessibilityAnnouncement())) return;
mContainerView.announceForAccessibility(mSnackbar.getActionAccessibilityAnnouncement());
}
/** /**
* Updates the view to display data from the given snackbar. No-op if the view is already * Updates the view to display data from the given snackbar. No-op if the view is already
* showing the given snackbar. * showing the given snackbar.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment