Add setIconContentDescription to EntityHeaderController
This lets us set a contentDescription on the icon in entity headers for accessibility. Bug: 62068874 Test: make RunSettingsRoboTests Change-Id: I1af7aad34aa65b616cf4edb8b144f315040a9fdd
This commit is contained in:
@@ -78,6 +78,7 @@ public class EntityHeaderController {
|
|||||||
private Lifecycle mLifecycle;
|
private Lifecycle mLifecycle;
|
||||||
private RecyclerView mRecyclerView;
|
private RecyclerView mRecyclerView;
|
||||||
private Drawable mIcon;
|
private Drawable mIcon;
|
||||||
|
private String mIconContentDescription;
|
||||||
private CharSequence mLabel;
|
private CharSequence mLabel;
|
||||||
private CharSequence mSummary;
|
private CharSequence mSummary;
|
||||||
private String mPackageName;
|
private String mPackageName;
|
||||||
@@ -122,6 +123,10 @@ public class EntityHeaderController {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the icon in the header. Callers should also consider calling setIconContentDescription
|
||||||
|
* to provide a description of this icon for accessibility purposes.
|
||||||
|
*/
|
||||||
public EntityHeaderController setIcon(Drawable icon) {
|
public EntityHeaderController setIcon(Drawable icon) {
|
||||||
if (icon != null) {
|
if (icon != null) {
|
||||||
mIcon = icon.getConstantState().newDrawable(mAppContext.getResources());
|
mIcon = icon.getConstantState().newDrawable(mAppContext.getResources());
|
||||||
@@ -129,6 +134,11 @@ public class EntityHeaderController {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convenience method to set the header icon from an ApplicationsState.AppEntry. Callers should
|
||||||
|
* also consider calling setIconContentDescription to provide a description of this icon for
|
||||||
|
* accessibility purposes.
|
||||||
|
*/
|
||||||
public EntityHeaderController setIcon(ApplicationsState.AppEntry appEntry) {
|
public EntityHeaderController setIcon(ApplicationsState.AppEntry appEntry) {
|
||||||
if (appEntry.icon != null) {
|
if (appEntry.icon != null) {
|
||||||
mIcon = appEntry.icon.getConstantState().newDrawable(mAppContext.getResources());
|
mIcon = appEntry.icon.getConstantState().newDrawable(mAppContext.getResources());
|
||||||
@@ -136,6 +146,11 @@ public class EntityHeaderController {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public EntityHeaderController setIconContentDescription(String contentDescription) {
|
||||||
|
mIconContentDescription = contentDescription;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public EntityHeaderController setLabel(CharSequence label) {
|
public EntityHeaderController setLabel(CharSequence label) {
|
||||||
mLabel = label;
|
mLabel = label;
|
||||||
return this;
|
return this;
|
||||||
@@ -204,6 +219,7 @@ public class EntityHeaderController {
|
|||||||
ImageView iconView = mHeader.findViewById(R.id.entity_header_icon);
|
ImageView iconView = mHeader.findViewById(R.id.entity_header_icon);
|
||||||
if (iconView != null) {
|
if (iconView != null) {
|
||||||
iconView.setImageDrawable(mIcon);
|
iconView.setImageDrawable(mIcon);
|
||||||
|
iconView.setContentDescription(mIconContentDescription);
|
||||||
}
|
}
|
||||||
setText(R.id.entity_header_title, mLabel);
|
setText(R.id.entity_header_title, mLabel);
|
||||||
setText(R.id.entity_header_summary, mSummary);
|
setText(R.id.entity_header_summary, mSummary);
|
||||||
|
@@ -233,6 +233,33 @@ public class EntityHeaderControllerTest {
|
|||||||
.isEqualTo("App info");
|
.isEqualTo("App info");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void iconContentDescription_shouldWorkWithSetIcon() {
|
||||||
|
final View view = mLayoutInflater
|
||||||
|
.inflate(R.layout.settings_entity_header, null /* root */);
|
||||||
|
when(mFragment.getActivity()).thenReturn(mock(Activity.class));
|
||||||
|
mController = EntityHeaderController.newInstance(mActivity, mFragment, view);
|
||||||
|
String description = "Fake Description";
|
||||||
|
mController.setIcon(mShadowContext.getDrawable(R.drawable.ic_add));
|
||||||
|
mController.setIconContentDescription(description);
|
||||||
|
mController.done(mActivity);
|
||||||
|
assertThat(view.findViewById(R.id.entity_header_icon).getContentDescription().toString())
|
||||||
|
.isEqualTo(description);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void iconContentDescription_shouldWorkWithoutSetIcon() {
|
||||||
|
final View view = mLayoutInflater
|
||||||
|
.inflate(R.layout.settings_entity_header, null /* root */);
|
||||||
|
when(mFragment.getActivity()).thenReturn(mock(Activity.class));
|
||||||
|
mController = EntityHeaderController.newInstance(mActivity, mFragment, view);
|
||||||
|
String description = "Fake Description";
|
||||||
|
mController.setIconContentDescription(description);
|
||||||
|
mController.done(mActivity);
|
||||||
|
assertThat(view.findViewById(R.id.entity_header_icon).getContentDescription().toString())
|
||||||
|
.isEqualTo(description);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void bindButton_hasAppNotifIntent_shouldShowButton() {
|
public void bindButton_hasAppNotifIntent_shouldShowButton() {
|
||||||
final View appLinks = mLayoutInflater
|
final View appLinks = mLayoutInflater
|
||||||
|
Reference in New Issue
Block a user