Use safe icon when building unavailable slices.
And move ic_a11y_generic from mipmap to drawable. IconCompat doesn't support mipmap. Bug: 118691898 Test: robotests Change-Id: I6799f3d31d2c5654319e5a97bf8ca14992e785a7
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 2.1 KiB |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.8 KiB |
Before Width: | Height: | Size: 4.3 KiB After Width: | Height: | Size: 4.3 KiB |
Before Width: | Height: | Size: 5.9 KiB After Width: | Height: | Size: 5.9 KiB |
@@ -550,7 +550,7 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
|
||||
|
||||
Drawable icon;
|
||||
if (resolveInfo.getIconResource() == 0) {
|
||||
icon = ContextCompat.getDrawable(getContext(), R.mipmap.ic_accessibility_generic);
|
||||
icon = ContextCompat.getDrawable(getContext(), R.drawable.ic_accessibility_generic);
|
||||
} else {
|
||||
icon = resolveInfo.loadIcon(getPackageManager());
|
||||
}
|
||||
|
@@ -258,7 +258,7 @@ public class ShortcutServicePickerFragment extends RadioButtonPickerFragment {
|
||||
public Drawable loadIcon() {
|
||||
final ResolveInfo resolveInfo = mServiceInfo.getResolveInfo();
|
||||
return (resolveInfo.getIconResource() == 0)
|
||||
? getContext().getDrawable(R.mipmap.ic_accessibility_generic)
|
||||
? getContext().getDrawable(R.drawable.ic_accessibility_generic)
|
||||
: resolveInfo.loadIcon(getContext().getPackageManager());
|
||||
}
|
||||
|
||||
|
@@ -43,7 +43,7 @@ public class SettingsContextualCardProvider extends ContextualCardProvider {
|
||||
.build();
|
||||
final ContextualCard batteryInfoCard =
|
||||
ContextualCard.newBuilder()
|
||||
.setSliceUri(BatterySlice.BATTERY_CARD_URI.toSafeString())
|
||||
.setSliceUri(BatterySlice.BATTERY_CARD_URI.toString())
|
||||
.setCardName(BatterySlice.PATH_BATTERY_INFO)
|
||||
.build();
|
||||
final ContextualCard connectedDeviceCard =
|
||||
|
@@ -385,7 +385,7 @@ public class SliceBuilderUtils {
|
||||
final Set<String> keywords = buildSliceKeywords(data);
|
||||
@ColorInt final int color = Utils.getColorAccentDefaultColor(context);
|
||||
final CharSequence summary = context.getText(R.string.disabled_dependent_setting_summary);
|
||||
final IconCompat icon = IconCompat.createWithResource(context, data.getIconResource());
|
||||
final IconCompat icon = getSafeIcon(context, data);
|
||||
final SliceAction primaryAction = new SliceAction(getContentPendingIntent(context, data),
|
||||
icon, title);
|
||||
|
||||
|
@@ -277,7 +277,7 @@ class SliceDataConverter {
|
||||
final String title = resolveInfo.loadLabel(packageManager).toString();
|
||||
int iconResource = resolveInfo.getIconResource();
|
||||
if (iconResource == 0) {
|
||||
iconResource = R.mipmap.ic_accessibility_generic;
|
||||
iconResource = R.drawable.ic_accessibility_generic;
|
||||
}
|
||||
|
||||
sliceDataBuilder.setKey(flattenedName)
|
||||
|
@@ -432,6 +432,25 @@ public class SliceBuilderUtilsTest {
|
||||
assertThat(actualIconResource).isEqualTo(expectedIconResource);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildDisabledDependentSlice_noIconPassed_returnsSliceWithIcon() {
|
||||
final int expectedIconResource = IconCompat.createWithResource(mContext,
|
||||
R.drawable.ic_settings).toIcon().getResId();
|
||||
final SliceData data = getDummyData(FakeUnavailablePreferenceController.class,
|
||||
SUMMARY, SliceData.SliceType.SWITCH, SCREEN_TITLE, 0 /* icon */,
|
||||
IS_DYNAMIC_SUMMARY_ALLOWED);
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
FakeUnavailablePreferenceController.AVAILABILITY_KEY,
|
||||
BasePreferenceController.DISABLED_DEPENDENT_SETTING);
|
||||
|
||||
final Slice slice = SliceBuilderUtils.buildSlice(mContext, data);
|
||||
|
||||
final SliceMetadata metadata = SliceMetadata.from(mContext, slice);
|
||||
final SliceAction primaryAction = metadata.getPrimaryAction();
|
||||
final int actualIconResource = primaryAction.getIcon().toIcon().getResId();
|
||||
assertThat(actualIconResource).isEqualTo(expectedIconResource);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildToggleSlice_noIconPassed_returnsSliceWithIcon() {
|
||||
final int expectedIconResource = IconCompat.createWithResource(mContext,
|
||||
|