am e0e2f4fd: Fix accessibility in action bars and add extra customization
* commit 'e0e2f4fd3ac8e70e341ae52d6376d8d67bd9edce': Fix accessibility in action bars and add extra customization
This commit is contained in:
@@ -2595,6 +2595,10 @@ package android.app {
|
||||
method public abstract void setDisplayShowHomeEnabled(boolean);
|
||||
method public abstract void setDisplayShowTitleEnabled(boolean);
|
||||
method public abstract void setDisplayUseLogoEnabled(boolean);
|
||||
method public void setHomeActionContentDescription(java.lang.CharSequence);
|
||||
method public void setHomeActionContentDescription(int);
|
||||
method public void setHomeAsUpIndicator(android.graphics.drawable.Drawable);
|
||||
method public void setHomeAsUpIndicator(int);
|
||||
method public void setHomeButtonEnabled(boolean);
|
||||
method public abstract void setIcon(int);
|
||||
method public abstract void setIcon(android.graphics.drawable.Drawable);
|
||||
|
||||
@@ -694,6 +694,86 @@ public abstract class ActionBar {
|
||||
*/
|
||||
public boolean isTitleTruncated() { return false; }
|
||||
|
||||
/**
|
||||
* Set an alternate drawable to display next to the icon/logo/title
|
||||
* when {@link #DISPLAY_HOME_AS_UP} is enabled. This can be useful if you are using
|
||||
* this mode to display an alternate selection for up navigation, such as a sliding drawer.
|
||||
*
|
||||
* <p>If you pass <code>null</code> to this method, the default drawable from the theme
|
||||
* will be used.</p>
|
||||
*
|
||||
* <p>If you implement alternate or intermediate behavior around Up, you should also
|
||||
* call {@link #setHomeActionContentDescription(int) setHomeActionContentDescription()}
|
||||
* to provide a correct description of the action for accessibility support.</p>
|
||||
*
|
||||
* @param indicator A drawable to use for the up indicator, or null to use the theme's default
|
||||
*
|
||||
* @see #setDisplayOptions(int, int)
|
||||
* @see #setDisplayHomeAsUpEnabled(boolean)
|
||||
* @see #setHomeActionContentDescription(int)
|
||||
*/
|
||||
public void setHomeAsUpIndicator(Drawable indicator) { }
|
||||
|
||||
/**
|
||||
* Set an alternate drawable to display next to the icon/logo/title
|
||||
* when {@link #DISPLAY_HOME_AS_UP} is enabled. This can be useful if you are using
|
||||
* this mode to display an alternate selection for up navigation, such as a sliding drawer.
|
||||
*
|
||||
* <p>If you pass <code>0</code> to this method, the default drawable from the theme
|
||||
* will be used.</p>
|
||||
*
|
||||
* <p>If you implement alternate or intermediate behavior around Up, you should also
|
||||
* call {@link #setHomeActionContentDescription(int) setHomeActionContentDescription()}
|
||||
* to provide a correct description of the action for accessibility support.</p>
|
||||
*
|
||||
* @param resId Resource ID of a drawable to use for the up indicator, or null
|
||||
* to use the theme's default
|
||||
*
|
||||
* @see #setDisplayOptions(int, int)
|
||||
* @see #setDisplayHomeAsUpEnabled(boolean)
|
||||
* @see #setHomeActionContentDescription(int)
|
||||
*/
|
||||
public void setHomeAsUpIndicator(int resId) { }
|
||||
|
||||
/**
|
||||
* Set an alternate description for the Home/Up action, when enabled.
|
||||
*
|
||||
* <p>This description is commonly used for accessibility/screen readers when
|
||||
* the Home action is enabled. (See {@link #setDisplayHomeAsUpEnabled(boolean)}.)
|
||||
* Examples of this are, "Navigate Home" or "Navigate Up" depending on the
|
||||
* {@link #DISPLAY_HOME_AS_UP} display option. If you have changed the home-as-up
|
||||
* indicator using {@link #setHomeAsUpIndicator(int)} to indicate more specific
|
||||
* functionality such as a sliding drawer, you should also set this to accurately
|
||||
* describe the action.</p>
|
||||
*
|
||||
* <p>Setting this to <code>null</code> will use the system default description.</p>
|
||||
*
|
||||
* @param description New description for the Home action when enabled
|
||||
* @see #setHomeAsUpIndicator(int)
|
||||
* @see #setHomeAsUpIndicator(android.graphics.drawable.Drawable)
|
||||
*/
|
||||
public void setHomeActionContentDescription(CharSequence description) { }
|
||||
|
||||
/**
|
||||
* Set an alternate description for the Home/Up action, when enabled.
|
||||
*
|
||||
* <p>This description is commonly used for accessibility/screen readers when
|
||||
* the Home action is enabled. (See {@link #setDisplayHomeAsUpEnabled(boolean)}.)
|
||||
* Examples of this are, "Navigate Home" or "Navigate Up" depending on the
|
||||
* {@link #DISPLAY_HOME_AS_UP} display option. If you have changed the home-as-up
|
||||
* indicator using {@link #setHomeAsUpIndicator(int)} to indicate more specific
|
||||
* functionality such as a sliding drawer, you should also set this to accurately
|
||||
* describe the action.</p>
|
||||
*
|
||||
* <p>Setting this to <code>0</code> will use the system default description.</p>
|
||||
*
|
||||
* @param resId Resource ID of a string to use as the new description
|
||||
* for the Home action when enabled
|
||||
* @see #setHomeAsUpIndicator(int)
|
||||
* @see #setHomeAsUpIndicator(android.graphics.drawable.Drawable)
|
||||
*/
|
||||
public void setHomeActionContentDescription(int resId) { }
|
||||
|
||||
/**
|
||||
* Listener interface for ActionBar navigation events.
|
||||
*/
|
||||
|
||||
@@ -812,6 +812,26 @@ public class ActionBarImpl extends ActionBar {
|
||||
return mActionView != null && mActionView.isTitleTruncated();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHomeAsUpIndicator(Drawable indicator) {
|
||||
mActionView.setHomeAsUpIndicator(indicator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHomeAsUpIndicator(int resId) {
|
||||
mActionView.setHomeAsUpIndicator(resId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHomeActionContentDescription(CharSequence description) {
|
||||
mActionView.setHomeActionContentDescription(description);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHomeActionContentDescription(int resId) {
|
||||
mActionView.setHomeActionContentDescription(resId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @hide
|
||||
*/
|
||||
|
||||
@@ -107,7 +107,7 @@ public class ActionMenuItem implements MenuItem {
|
||||
}
|
||||
|
||||
public CharSequence getTitleCondensed() {
|
||||
return mTitleCondensed;
|
||||
return mTitleCondensed != null ? mTitleCondensed : mTitle;
|
||||
}
|
||||
|
||||
public boolean hasSubMenu() {
|
||||
|
||||
@@ -93,6 +93,8 @@ public class ActionBarView extends AbsActionBarView {
|
||||
private CharSequence mSubtitle;
|
||||
private Drawable mIcon;
|
||||
private Drawable mLogo;
|
||||
private CharSequence mHomeDescription;
|
||||
private int mHomeDescriptionRes;
|
||||
|
||||
private HomeView mHomeLayout;
|
||||
private HomeView mExpandedHomeLayout;
|
||||
@@ -288,6 +290,10 @@ public class ActionBarView extends AbsActionBarView {
|
||||
initTitle();
|
||||
}
|
||||
|
||||
if (mHomeDescriptionRes != 0) {
|
||||
setHomeActionContentDescription(mHomeDescriptionRes);
|
||||
}
|
||||
|
||||
if (mTabScrollView != null && mIncludeTabs) {
|
||||
ViewGroup.LayoutParams lp = mTabScrollView.getLayoutParams();
|
||||
if (lp != null) {
|
||||
@@ -589,14 +595,43 @@ public class ActionBarView extends AbsActionBarView {
|
||||
mUpGoerFive.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO);
|
||||
} else {
|
||||
mUpGoerFive.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_AUTO);
|
||||
mUpGoerFive.setContentDescription(buildHomeContentDescription());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Compose a content description for the Home/Up affordance.
|
||||
*
|
||||
* <p>As this encompasses the icon/logo, title and subtitle all in one, we need
|
||||
* a description for the whole wad of stuff that can be localized properly.</p>
|
||||
*/
|
||||
private CharSequence buildHomeContentDescription() {
|
||||
final CharSequence homeDesc;
|
||||
if (mHomeDescription != null) {
|
||||
homeDesc = mHomeDescription;
|
||||
} else {
|
||||
if ((mDisplayOptions & ActionBar.DISPLAY_HOME_AS_UP) != 0) {
|
||||
mUpGoerFive.setContentDescription(mContext.getResources().getText(
|
||||
R.string.action_bar_up_description));
|
||||
homeDesc = mContext.getResources().getText(R.string.action_bar_up_description);
|
||||
} else {
|
||||
mUpGoerFive.setContentDescription(mContext.getResources().getText(
|
||||
R.string.action_bar_home_description));
|
||||
homeDesc = mContext.getResources().getText(R.string.action_bar_home_description);
|
||||
}
|
||||
}
|
||||
|
||||
final CharSequence title = getTitle();
|
||||
final CharSequence subtitle = getSubtitle();
|
||||
if (!TextUtils.isEmpty(title)) {
|
||||
final String result;
|
||||
if (!TextUtils.isEmpty(subtitle)) {
|
||||
result = getResources().getString(
|
||||
R.string.action_bar_home_subtitle_description_format,
|
||||
title, subtitle, homeDesc);
|
||||
} else {
|
||||
result = getResources().getString(R.string.action_bar_home_description_format,
|
||||
title, homeDesc);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return homeDesc;
|
||||
}
|
||||
|
||||
public void setDisplayOptions(int options) {
|
||||
@@ -1305,6 +1340,23 @@ public class ActionBarView extends AbsActionBarView {
|
||||
}
|
||||
}
|
||||
|
||||
public void setHomeAsUpIndicator(Drawable indicator) {
|
||||
mHomeLayout.setUpIndicator(indicator);
|
||||
}
|
||||
|
||||
public void setHomeAsUpIndicator(int resId) {
|
||||
mHomeLayout.setUpIndicator(resId);
|
||||
}
|
||||
|
||||
public void setHomeActionContentDescription(CharSequence description) {
|
||||
mHomeDescription = description;
|
||||
}
|
||||
|
||||
public void setHomeActionContentDescription(int resId) {
|
||||
mHomeDescriptionRes = resId;
|
||||
mHomeDescription = getResources().getText(resId);
|
||||
}
|
||||
|
||||
static class SavedState extends BaseSavedState {
|
||||
int expandedMenuItemId;
|
||||
boolean isOverflowOpen;
|
||||
@@ -1339,9 +1391,11 @@ public class ActionBarView extends AbsActionBarView {
|
||||
}
|
||||
|
||||
private static class HomeView extends FrameLayout {
|
||||
private View mUpView;
|
||||
private ImageView mUpView;
|
||||
private ImageView mIconView;
|
||||
private int mUpWidth;
|
||||
private int mUpIndicatorRes;
|
||||
private Drawable mDefaultUpIndicator;
|
||||
|
||||
private static final long DEFAULT_TRANSITION_DURATION = 150;
|
||||
|
||||
@@ -1366,6 +1420,25 @@ public class ActionBarView extends AbsActionBarView {
|
||||
mIconView.setImageDrawable(icon);
|
||||
}
|
||||
|
||||
public void setUpIndicator(Drawable d) {
|
||||
mUpView.setImageDrawable(d != null ? d : mDefaultUpIndicator);
|
||||
mUpIndicatorRes = 0;
|
||||
}
|
||||
|
||||
public void setUpIndicator(int resId) {
|
||||
mUpIndicatorRes = resId;
|
||||
mUpView.setImageDrawable(resId != 0 ? getResources().getDrawable(resId) : null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onConfigurationChanged(Configuration newConfig) {
|
||||
super.onConfigurationChanged(newConfig);
|
||||
if (mUpIndicatorRes != 0) {
|
||||
// Reload for config change
|
||||
setUpIndicator(mUpIndicatorRes);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
|
||||
onPopulateAccessibilityEvent(event);
|
||||
@@ -1389,8 +1462,9 @@ public class ActionBarView extends AbsActionBarView {
|
||||
|
||||
@Override
|
||||
protected void onFinishInflate() {
|
||||
mUpView = findViewById(com.android.internal.R.id.up);
|
||||
mUpView = (ImageView) findViewById(com.android.internal.R.id.up);
|
||||
mIconView = (ImageView) findViewById(com.android.internal.R.id.home);
|
||||
mDefaultUpIndicator = mUpView.getDrawable();
|
||||
}
|
||||
|
||||
public int getStartOffset() {
|
||||
|
||||
@@ -3771,6 +3771,17 @@
|
||||
<string name="action_bar_up_description">Navigate up</string>
|
||||
<!-- Content description for the action menu overflow button. [CHAR LIMIT=NONE] -->
|
||||
<string name="action_menu_overflow_description">More options</string>
|
||||
<!-- Formatting string for describing the action bar's title/home/up affordance.
|
||||
This is a single tappable "button" that includes the app icon, the Up indicator
|
||||
(usually a "<" chevron) and the window title text.
|
||||
%1$s is the title. %2$s is the description of what tapping/clicking the whole
|
||||
thing is going to do. -->
|
||||
<string name="action_bar_home_description_format">%1$s, %2$s</string>
|
||||
<!-- Just like action_bar_home_description_format, but this one will be used
|
||||
if the window is also providing subtitle text.
|
||||
%1$s is the title. %2$s is the subtitle. %3$s is the description of what
|
||||
tapping/clicking the whole thing is going to do. -->
|
||||
<string name="action_bar_home_subtitle_description_format">%1$s, %2$s, %3$s</string>
|
||||
|
||||
<!-- Storage description for internal storage. [CHAR LIMIT=NONE] -->
|
||||
<string name="storage_internal">Internal storage</string>
|
||||
|
||||
@@ -870,6 +870,8 @@
|
||||
<java-symbol type="string" name="config_chooseTypeAndAccountActivity" />
|
||||
<java-symbol type="string" name="config_appsAuthorizedForSharedAccounts" />
|
||||
<java-symbol type="string" name="error_message_title" />
|
||||
<java-symbol type="string" name="action_bar_home_description_format" />
|
||||
<java-symbol type="string" name="action_bar_home_subtitle_description_format" />
|
||||
|
||||
<java-symbol type="plurals" name="abbrev_in_num_days" />
|
||||
<java-symbol type="plurals" name="abbrev_in_num_hours" />
|
||||
|
||||
Reference in New Issue
Block a user