Search in sources :

Example 91 with IconCompat

use of androidx.core.graphics.drawable.IconCompat in project android_packages_apps_Settings by omnirom.

the class LowStorageSlice method getSlice.

@Override
public Slice getSlice() {
    // Get used storage percentage from StorageManager.
    final PrivateStorageInfo info = PrivateStorageInfo.getPrivateStorageInfo(new StorageManagerVolumeProvider(mContext.getSystemService(StorageManager.class)));
    final double usedPercentage = (double) (info.totalBytes - info.freeBytes) / info.totalBytes;
    // Generate Low storage Slice.
    final String percentageString = NumberFormat.getPercentInstance().format(usedPercentage);
    final String freeSizeString = Formatter.formatFileSize(mContext, info.freeBytes);
    final ListBuilder listBuilder = new ListBuilder(mContext, CustomSliceRegistry.LOW_STORAGE_SLICE_URI, ListBuilder.INFINITY).setAccentColor(Utils.getColorAccentDefaultColor(mContext));
    final IconCompat icon = IconCompat.createWithResource(mContext, R.drawable.ic_storage);
    if (usedPercentage < LOW_STORAGE_THRESHOLD) {
        // For clients that ignore error checking, a generic storage slice will be given.
        final CharSequence titleStorage = mContext.getText(R.string.storage_settings);
        final String summaryStorage = mContext.getString(R.string.storage_summary, percentageString, freeSizeString);
        return listBuilder.addRow(buildRowBuilder(titleStorage, summaryStorage, icon)).setIsError(true).build();
    }
    final CharSequence titleLowStorage = mContext.getText(R.string.storage_menu_free);
    final String summaryLowStorage = mContext.getString(R.string.low_storage_summary, percentageString, freeSizeString);
    return listBuilder.addRow(buildRowBuilder(titleLowStorage, summaryLowStorage, icon)).build();
}
Also used : PrivateStorageInfo(com.android.settingslib.deviceinfo.PrivateStorageInfo) IconCompat(androidx.core.graphics.drawable.IconCompat) StorageManagerVolumeProvider(com.android.settingslib.deviceinfo.StorageManagerVolumeProvider) ListBuilder(androidx.slice.builders.ListBuilder)

Example 92 with IconCompat

use of androidx.core.graphics.drawable.IconCompat in project android_packages_apps_Settings by omnirom.

the class WifiCallingSliceHelper method wifiPreferenceRowBuilder.

/**
 * Returns RowBuilder for a new row containing specific wifi calling preference.
 *
 * @param listBuilder          ListBuilder that will be the parent for this RowBuilder
 * @param preferenceTitleResId resource Id for the preference row title
 * @param action               action to be added for the row
 * @param subId                subscription id
 * @return RowBuilder for the row
 */
private RowBuilder wifiPreferenceRowBuilder(ListBuilder listBuilder, int preferenceTitleResId, String action, boolean checked, int subId) {
    final IconCompat icon = IconCompat.createWithResource(mContext, R.drawable.radio_button_check);
    final Resources res = getResourcesForSubId(subId);
    return new RowBuilder().setTitle(res.getText(preferenceTitleResId)).setTitleItem(SliceAction.createToggle(getBroadcastIntent(action), icon, res.getText(preferenceTitleResId), checked));
}
Also used : IconCompat(androidx.core.graphics.drawable.IconCompat) Resources(android.content.res.Resources) RowBuilder(androidx.slice.builders.ListBuilder.RowBuilder)

Example 93 with IconCompat

use of androidx.core.graphics.drawable.IconCompat in project android_packages_apps_Settings by omnirom.

the class BluetoothSliceBuilderTest method getBluetoothSlice_correctSliceContent.

@Test
public void getBluetoothSlice_correctSliceContent() {
    final Slice BluetoothSlice = BluetoothSliceBuilder.getSlice(mContext);
    final SliceMetadata metadata = SliceMetadata.from(mContext, BluetoothSlice);
    assertThat(metadata.getTitle()).isEqualTo(mContext.getString(R.string.bluetooth_settings_title));
    final List<SliceAction> toggles = metadata.getToggles();
    assertThat(toggles).hasSize(1);
    final SliceAction primaryAction = metadata.getPrimaryAction();
    final IconCompat expectedToggleIcon = IconCompat.createWithResource(mContext, com.android.internal.R.drawable.ic_settings_bluetooth);
    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 94 with IconCompat

use of androidx.core.graphics.drawable.IconCompat in project android_packages_apps_Settings by omnirom.

the class ProviderModelSlice method getSeeAllRow.

protected ListBuilder.RowBuilder getSeeAllRow() {
    final CharSequence title = mContext.getText(R.string.previous_connected_see_all);
    final IconCompat icon = getSeeAllIcon();
    return new ListBuilder.RowBuilder().setTitleItem(icon, ListBuilder.ICON_IMAGE).setTitle(title).setPrimaryAction(getPrimaryAction(icon, title));
}
Also used : IconCompat(androidx.core.graphics.drawable.IconCompat) ListBuilder(androidx.slice.builders.ListBuilder)

Example 95 with IconCompat

use of androidx.core.graphics.drawable.IconCompat in project android_packages_apps_Settings by omnirom.

the class UtilsTest method createIconWithDrawable_BitmapDrawable.

@Test
public void createIconWithDrawable_BitmapDrawable() {
    final Bitmap bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
    final BitmapDrawable drawable = new BitmapDrawable(mContext.getResources(), bitmap);
    final IconCompat icon = Utils.createIconWithDrawable(drawable);
    assertThat(icon.getBitmap()).isNotNull();
}
Also used : Bitmap(android.graphics.Bitmap) IconCompat(androidx.core.graphics.drawable.IconCompat) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Test(org.junit.Test)

Aggregations

IconCompat (androidx.core.graphics.drawable.IconCompat)103 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)15 Slice (androidx.slice.Slice)14 Drawable (android.graphics.drawable.Drawable)7 ShortcutInfoCompat (androidx.core.content.pm.ShortcutInfoCompat)7 SliceItem (androidx.slice.SliceItem)6 ColorDrawable (android.graphics.drawable.ColorDrawable)5 Bitmap (android.graphics.Bitmap)4 SpannableString (android.text.SpannableString)4 PrivateStorageInfo (com.android.settingslib.deviceinfo.PrivateStorageInfo)4 Resources (android.content.res.Resources)3 PorterDuffColorFilter (android.graphics.PorterDuffColorFilter)3