use of androidx.core.graphics.drawable.IconCompat in project android_packages_apps_Settings by omnirom.
the class SliceBuilderUtilsTest method getSafeIcon_invalidResource_shouldFallbackToSettingsIcon.
@Test
public void getSafeIcon_invalidResource_shouldFallbackToSettingsIcon() {
final int settingsIcon = R.drawable.ic_settings_accent;
final int badIcon = 0x12345678;
final SliceData data = getMockData(TOGGLE_CONTROLLER, SliceData.SliceType.SWITCH, badIcon);
final IconCompat actualIcon = SliceBuilderUtils.getSafeIcon(mContext, data);
final int actualIconResource = actualIcon.toIcon().getResId();
assertThat(actualIconResource).isEqualTo(settingsIcon);
}
use of androidx.core.graphics.drawable.IconCompat in project android_packages_apps_Settings by omnirom.
the class ContextualWifiSliceTest method assertWifiHeader.
private void assertWifiHeader(Slice slice) {
final SliceMetadata metadata = SliceMetadata.from(mContext, slice);
assertThat(metadata.getTitle()).isEqualTo(mContext.getString(R.string.wifi_settings));
final SliceAction primaryAction = metadata.getPrimaryAction();
final IconCompat expectedToggleIcon = IconCompat.createWithResource(mContext, R.drawable.ic_settings_wireless);
assertThat(primaryAction.getIcon().toString()).isEqualTo(expectedToggleIcon.toString());
final List<SliceAction> toggles = metadata.getToggles();
assertThat(toggles).hasSize(1);
}
use of androidx.core.graphics.drawable.IconCompat in project android_packages_apps_Settings by omnirom.
the class WifiSliceTest method getWifiSlice_shouldHaveTitleAndToggle.
@Test
public void getWifiSlice_shouldHaveTitleAndToggle() {
final Slice wifiSlice = mWifiSlice.getSlice();
final SliceMetadata metadata = SliceMetadata.from(mContext, wifiSlice);
assertThat(metadata.getTitle()).isEqualTo(mContext.getString(R.string.wifi_settings));
final List<SliceAction> toggles = metadata.getToggles();
assertThat(toggles).hasSize(1);
final SliceAction primaryAction = metadata.getPrimaryAction();
final IconCompat expectedToggleIcon = IconCompat.createWithResource(mContext, R.drawable.ic_settings_wireless);
assertThat(primaryAction.getIcon().toString()).isEqualTo(expectedToggleIcon.toString());
}
use of androidx.core.graphics.drawable.IconCompat in project android_packages_apps_Settings by omnirom.
the class MediaOutputIndicatorSlice method getSlice.
@Override
public Slice getSlice() {
if (!isVisible()) {
return new ListBuilder(mContext, getUri(), ListBuilder.INFINITY).setIsError(true).build();
}
final IconCompat icon = IconCompat.createWithResource(mContext, com.android.internal.R.drawable.ic_settings_bluetooth);
final CharSequence title = mContext.getString(R.string.media_output_label_title, Utils.getApplicationLabel(mContext, getWorker().getPackageName()));
final SliceAction primarySliceAction = SliceAction.create(getBroadcastIntent(mContext), icon, ListBuilder.ICON_IMAGE, title);
@ColorInt final int color = Utils.getColorAccentDefaultColor(mContext);
// To set an empty icon to indent the row
final ListBuilder listBuilder = new ListBuilder(mContext, getUri(), ListBuilder.INFINITY).setAccentColor(color).addRow(new ListBuilder.RowBuilder().setTitle(title).setTitleItem(createEmptyIcon(), ListBuilder.ICON_IMAGE).setSubtitle(getWorker().getCurrentConnectedMediaDevice().getName()).setPrimaryAction(primarySliceAction));
return listBuilder.build();
}
use of androidx.core.graphics.drawable.IconCompat in project android_packages_apps_Settings by omnirom.
the class RemoteMediaSlice method getSlice.
@Override
public Slice getSlice() {
final ListBuilder listBuilder = new ListBuilder(mContext, getUri(), ListBuilder.INFINITY).setAccentColor(COLOR_NOT_TINTED);
if (getWorker() == null) {
Log.e(TAG, "Unable to get the slice worker.");
return listBuilder.build();
}
if (mRouterManager == null) {
mRouterManager = MediaRouter2Manager.getInstance(mContext);
}
// Only displaying remote devices
final List<RoutingSessionInfo> infos = getWorker().getActiveRemoteMediaDevice();
if (infos.isEmpty()) {
Log.d(TAG, "No active remote media device");
return listBuilder.build();
}
final CharSequence castVolume = mContext.getText(R.string.remote_media_volume_option_title);
final IconCompat icon = IconCompat.createWithResource(mContext, R.drawable.ic_volume_remote);
// To create an empty icon to indent the row
final IconCompat emptyIcon = createEmptyIcon();
for (RoutingSessionInfo info : infos) {
final int maxVolume = info.getVolumeMax();
if (maxVolume <= 0) {
Log.d(TAG, "Unable to add Slice. " + info.getName() + ": max volume is " + maxVolume);
continue;
}
if (!getWorker().shouldEnableVolumeSeekBar(info)) {
// There is no disable state. We hide it directly.
Log.d(TAG, "Unable to add Slice. " + info.getName() + ": This is a group session");
continue;
}
final CharSequence appName = Utils.getApplicationLabel(mContext, info.getClientPackageName());
final CharSequence outputTitle = mContext.getString(R.string.media_output_label_title, appName);
listBuilder.addInputRange(new InputRangeBuilder().setTitleItem(icon, ListBuilder.ICON_IMAGE).setTitle(castVolume).setInputAction(getSliderInputAction(info.getId().hashCode(), info.getId())).setPrimaryAction(getSoundSettingAction(castVolume, icon, info.getId())).setMax(maxVolume).setValue(info.getVolume()));
final boolean isMediaOutputDisabled = getWorker().shouldDisableMediaOutput(info.getClientPackageName());
final SpannableString spannableTitle = new SpannableString(TextUtils.isEmpty(appName) ? "" : appName);
spannableTitle.setSpan(new ForegroundColorSpan(Utils.getColorAttrDefaultColor(mContext, android.R.attr.textColorSecondary)), 0, spannableTitle.length(), SPAN_EXCLUSIVE_EXCLUSIVE);
listBuilder.addRow(new ListBuilder.RowBuilder().setTitle(isMediaOutputDisabled ? spannableTitle : outputTitle).setSubtitle(info.getName()).setTitleItem(emptyIcon, ListBuilder.ICON_IMAGE).setPrimaryAction(getMediaOutputDialogAction(info, isMediaOutputDisabled)));
}
return listBuilder.build();
}
Aggregations