Search in sources :

Example 36 with IconCompat

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);
}
Also used : IconCompat(androidx.core.graphics.drawable.IconCompat) Test(org.junit.Test)

Example 37 with IconCompat

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);
}
Also used : IconCompat(androidx.core.graphics.drawable.IconCompat) SliceMetadata(androidx.slice.SliceMetadata) SliceAction(androidx.slice.core.SliceAction)

Example 38 with IconCompat

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());
}
Also used : Slice(androidx.slice.Slice) IconCompat(androidx.core.graphics.drawable.IconCompat) SliceMetadata(androidx.slice.SliceMetadata) SliceAction(androidx.slice.core.SliceAction) Test(org.junit.Test)

Example 39 with IconCompat

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();
}
Also used : ColorInt(android.annotation.ColorInt) IconCompat(androidx.core.graphics.drawable.IconCompat) SliceAction(androidx.slice.builders.SliceAction) ListBuilder(androidx.slice.builders.ListBuilder)

Example 40 with IconCompat

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();
}
Also used : SpannableString(android.text.SpannableString) ForegroundColorSpan(android.text.style.ForegroundColorSpan) IconCompat(androidx.core.graphics.drawable.IconCompat) InputRangeBuilder(androidx.slice.builders.ListBuilder.InputRangeBuilder) ListBuilder(androidx.slice.builders.ListBuilder) RoutingSessionInfo(android.media.RoutingSessionInfo)

Aggregations

IconCompat (androidx.core.graphics.drawable.IconCompat)102 ListBuilder (androidx.slice.builders.ListBuilder)55 PendingIntent (android.app.PendingIntent)42 SliceAction (androidx.slice.builders.SliceAction)39 Test (org.junit.Test)25 ColorInt (android.annotation.ColorInt)22 RowBuilder (androidx.slice.builders.ListBuilder.RowBuilder)21 SliceMetadata (androidx.slice.SliceMetadata)18 SliceAction (androidx.slice.core.SliceAction)18 Intent (android.content.Intent)14 Slice (androidx.slice.Slice)14 Drawable (android.graphics.drawable.Drawable)7 ShortcutInfoCompat (androidx.core.content.pm.ShortcutInfoCompat)6 SliceItem (androidx.slice.SliceItem)6 ColorDrawable (android.graphics.drawable.ColorDrawable)5 SpannableString (android.text.SpannableString)4 PrivateStorageInfo (com.android.settingslib.deviceinfo.PrivateStorageInfo)4 Resources (android.content.res.Resources)3 Bitmap (android.graphics.Bitmap)3 PorterDuffColorFilter (android.graphics.PorterDuffColorFilter)3