Commit 6229401d authored by Tommy Nyquist's avatar Tommy Nyquist Committed by Commit Bot

[Android] Fix accessibility issues for update menu.

The CL for updating the visuals of how a deprecated operating system
should be displayed did not correctly pass along enough information to
be able to always have an up to date content description, which is
important for accessibility.

The state of whether an update badge should be visible or not is always
known at the time it has to be updated, so the state should be passed
in. The reason is that whether the badge is really visible or not might
be correct in all cases when the check happens.

This CL therefore goes back to how things were before the visual update
by passing the state in.

In addition, the menu item itself did not always have a correct
content description, but now it is forcefully set during decoriation
of the item.

Bug: 899695
Change-Id: I9f7e2d4cc6b60ccfaf95d7c07fc351c5c9e2a8ac
Reviewed-on: https://chromium-review.googlesource.com/c/1306399
Commit-Queue: Tommy Nyquist <nyquist@chromium.org>
Reviewed-by: default avatarTheresa <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#604022}
parent 718c6717
...@@ -150,6 +150,8 @@ public class UpdateMenuItemHelper { ...@@ -150,6 +150,8 @@ public class UpdateMenuItemHelper {
switch (getUpdateType()) { switch (getUpdateType()) {
case UpdateType.UPDATE_AVAILABLE: case UpdateType.UPDATE_AVAILABLE:
title.setText(context.getString(R.string.menu_update)); title.setText(context.getString(R.string.menu_update));
// See crbug.com/899695 for why this line is necessary.
title.setContentDescription(context.getString(R.string.menu_update));
title.setTextColor(Color.RED); title.setTextColor(Color.RED);
String customSummary = getStringParamValue(CUSTOM_SUMMARY); String customSummary = getStringParamValue(CUSTOM_SUMMARY);
...@@ -164,6 +166,8 @@ public class UpdateMenuItemHelper { ...@@ -164,6 +166,8 @@ public class UpdateMenuItemHelper {
break; break;
case UpdateType.UNSUPPORTED_OS_VERSION: case UpdateType.UNSUPPORTED_OS_VERSION:
title.setText(R.string.menu_update_unsupported); title.setText(R.string.menu_update_unsupported);
// See crbug.com/899695 for why this line is necessary.
title.setContentDescription(context.getString(R.string.menu_update_unsupported));
title.setTextColor(ApiCompatibilityUtils.getColor( title.setTextColor(ApiCompatibilityUtils.getColor(
context.getResources(), R.color.default_text_color)); context.getResources(), R.color.default_text_color));
......
...@@ -70,6 +70,7 @@ class MenuButton extends FrameLayout { ...@@ -70,6 +70,7 @@ class MenuButton extends FrameLayout {
case UpdateMenuItemHelper.UpdateType.UNSUPPORTED_OS_VERSION: case UpdateMenuItemHelper.UpdateType.UNSUPPORTED_OS_VERSION:
mUpdateBadgeView.setVisibility(visible ? View.VISIBLE : View.GONE); mUpdateBadgeView.setVisibility(visible ? View.VISIBLE : View.GONE);
updateImageResources(); updateImageResources();
updateContentDescription(visible);
break; break;
case UpdateMenuItemHelper.UpdateType.NONE: case UpdateMenuItemHelper.UpdateType.NONE:
// Intentional fall through. // Intentional fall through.
...@@ -77,6 +78,7 @@ class MenuButton extends FrameLayout { ...@@ -77,6 +78,7 @@ class MenuButton extends FrameLayout {
// Intentional fall through. // Intentional fall through.
default: default:
mUpdateBadgeView.setVisibility(View.GONE); mUpdateBadgeView.setVisibility(View.GONE);
updateContentDescription(false);
break; break;
} }
} }
...@@ -110,8 +112,12 @@ class MenuButton extends FrameLayout { ...@@ -110,8 +112,12 @@ class MenuButton extends FrameLayout {
return mUpdateBadgeView.getVisibility() == View.VISIBLE; return mUpdateBadgeView.getVisibility() == View.VISIBLE;
} }
void updateContentDescription() { /**
if (isShowingAppMenuUpdateBadge()) { * Sets the content description for the menu button.
* @param isUpdateBadgeVisible Whether the update menu badge is visible.
*/
void updateContentDescription(boolean isUpdateBadgeVisible) {
if (isUpdateBadgeVisible) {
switch (UpdateMenuItemHelper.getInstance().getUpdateType()) { switch (UpdateMenuItemHelper.getInstance().getUpdateType()) {
case UpdateMenuItemHelper.UpdateType.UPDATE_AVAILABLE: case UpdateMenuItemHelper.UpdateType.UPDATE_AVAILABLE:
setContentDescription(getResources().getString( setContentDescription(getResources().getString(
......
...@@ -826,7 +826,7 @@ public abstract class ToolbarLayout extends FrameLayout implements Toolbar { ...@@ -826,7 +826,7 @@ public abstract class ToolbarLayout extends FrameLayout implements Toolbar {
if (mMenuBadge == null) return; if (mMenuBadge == null) return;
boolean wasShowingMenuBadge = mShowMenuBadge; boolean wasShowingMenuBadge = mShowMenuBadge;
mShowMenuBadge = false; mShowMenuBadge = false;
setMenuButtonContentDescription(); setMenuButtonContentDescription(false);
if (!animate || !wasShowingMenuBadge) { if (!animate || !wasShowingMenuBadge) {
mMenuButtonWrapper.setUpdateBadgeVisibilityIfValidState(false); mMenuButtonWrapper.setUpdateBadgeVisibilityIfValidState(false);
...@@ -890,7 +890,7 @@ public abstract class ToolbarLayout extends FrameLayout implements Toolbar { ...@@ -890,7 +890,7 @@ public abstract class ToolbarLayout extends FrameLayout implements Toolbar {
*/ */
protected void setAppMenuUpdateBadgeToVisible(boolean animate) { protected void setAppMenuUpdateBadgeToVisible(boolean animate) {
if (mMenuBadge == null || mMenuButton == null || mMenuButtonWrapper == null) return; if (mMenuBadge == null || mMenuButton == null || mMenuButtonWrapper == null) return;
setMenuButtonContentDescription(); setMenuButtonContentDescription(true);
if (!animate || mIsMenuBadgeAnimationRunning) { if (!animate || mIsMenuBadgeAnimationRunning) {
mMenuButtonWrapper.setUpdateBadgeVisibilityIfValidState(true); mMenuButtonWrapper.setUpdateBadgeVisibilityIfValidState(true);
return; return;
...@@ -964,10 +964,11 @@ public abstract class ToolbarLayout extends FrameLayout implements Toolbar { ...@@ -964,10 +964,11 @@ public abstract class ToolbarLayout extends FrameLayout implements Toolbar {
/** /**
* Sets the content description for the menu button. * Sets the content description for the menu button.
* @param isUpdateBadgeVisible Whether the update menu badge is visible
*/ */
protected void setMenuButtonContentDescription() { protected void setMenuButtonContentDescription(boolean isUpdateBadgeVisible) {
if (mMenuButtonWrapper == null) return; if (mMenuButtonWrapper == null) return;
mMenuButtonWrapper.updateContentDescription(); mMenuButtonWrapper.updateContentDescription(isUpdateBadgeVisible);
} }
/** /**
......
...@@ -1830,7 +1830,7 @@ public class ToolbarPhone extends ToolbarLayout ...@@ -1830,7 +1830,7 @@ public class ToolbarPhone extends ToolbarLayout
view.setVisibility(browsingViewsVisibility); view.setVisibility(browsingViewsVisibility);
} }
if (mShowMenuBadge) { if (mShowMenuBadge) {
setMenuButtonContentDescription(); setMenuButtonContentDescription(mTabSwitcherState == STATIC_TAB);
} }
updateProgressBarVisibility(); updateProgressBarVisibility();
......
...@@ -517,7 +517,7 @@ public class ToolbarTablet ...@@ -517,7 +517,7 @@ public class ToolbarTablet
mLocationBar.getContainerView().setVisibility(View.INVISIBLE); mLocationBar.getContainerView().setVisibility(View.INVISIBLE);
if (mShowMenuBadge) { if (mShowMenuBadge) {
getMenuBadge().setVisibility(View.GONE); getMenuBadge().setVisibility(View.GONE);
setMenuButtonContentDescription(); setMenuButtonContentDescription(false);
} }
} else { } else {
mIsInTabSwitcherMode = false; mIsInTabSwitcherMode = false;
......
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