Search in sources :

Example 56 with ListBuilder

use of androidx.slice.builders.ListBuilder 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 57 with ListBuilder

use of androidx.slice.builders.ListBuilder in project android_packages_apps_Settings by omnirom.

the class SliceFullCardRendererHelperTest method buildSlice.

private Slice buildSlice() {
    final String title = "test_title";
    final IconCompat icon = IconCompat.createWithResource(mActivity, R.drawable.empty_icon);
    final PendingIntent pendingIntent = PendingIntent.getActivity(mActivity, title.hashCode(), /* requestCode */
    new Intent("test action"), PendingIntent.FLAG_IMMUTABLE);
    final SliceAction action = SliceAction.createDeeplink(pendingIntent, icon, ListBuilder.SMALL_IMAGE, title);
    return new ListBuilder(mActivity, TEST_SLICE_URI, ListBuilder.INFINITY).addRow(new ListBuilder.RowBuilder().addEndItem(icon, ListBuilder.ICON_IMAGE).setTitle(title).setPrimaryAction(action)).build();
}
Also used : IconCompat(androidx.core.graphics.drawable.IconCompat) SliceAction(androidx.slice.builders.SliceAction) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) ListBuilder(androidx.slice.builders.ListBuilder) PendingIntent(android.app.PendingIntent)

Example 58 with ListBuilder

use of androidx.slice.builders.ListBuilder in project android_packages_apps_Settings by omnirom.

the class SliceHalfCardRendererHelperTest method buildSlice.

private Slice buildSlice() {
    final String title = "test_title";
    final IconCompat icon = IconCompat.createWithResource(mActivity, R.drawable.empty_icon);
    final PendingIntent pendingIntent = PendingIntent.getActivity(mActivity, title.hashCode(), /* requestCode */
    new Intent("test action"), PendingIntent.FLAG_IMMUTABLE);
    final SliceAction action = SliceAction.createDeeplink(pendingIntent, icon, ListBuilder.SMALL_IMAGE, title);
    return new ListBuilder(mActivity, TEST_SLICE_URI, ListBuilder.INFINITY).addRow(new ListBuilder.RowBuilder().addEndItem(icon, ListBuilder.ICON_IMAGE).setTitle(title).setPrimaryAction(action)).build();
}
Also used : IconCompat(androidx.core.graphics.drawable.IconCompat) SliceAction(androidx.slice.builders.SliceAction) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) ListBuilder(androidx.slice.builders.ListBuilder) PendingIntent(android.app.PendingIntent)

Aggregations

ListBuilder (androidx.slice.builders.ListBuilder)58 IconCompat (androidx.core.graphics.drawable.IconCompat)47 SliceAction (androidx.slice.builders.SliceAction)34 PendingIntent (android.app.PendingIntent)31 ColorInt (android.annotation.ColorInt)25 RowBuilder (androidx.slice.builders.ListBuilder.RowBuilder)20 Intent (android.content.Intent)6 PorterDuffColorFilter (android.graphics.PorterDuffColorFilter)3 Drawable (android.graphics.drawable.Drawable)3 InputRangeBuilder (androidx.slice.builders.ListBuilder.InputRangeBuilder)3 PrivateStorageInfo (com.android.settingslib.deviceinfo.PrivateStorageInfo)3 Resources (android.content.res.Resources)2 SpannableString (android.text.SpannableString)2 SliderPreferenceController (com.android.settings.core.SliderPreferenceController)2 TogglePreferenceController (com.android.settings.core.TogglePreferenceController)2 BatteryTip (com.android.settings.fuelgauge.batterytip.tips.BatteryTip)2 SliceBackgroundWorker (com.android.settings.slices.SliceBackgroundWorker)2 StorageManagerVolumeProvider (com.android.settingslib.deviceinfo.StorageManagerVolumeProvider)2 AlertDialog (android.app.AlertDialog)1 BluetoothAdapter (android.bluetooth.BluetoothAdapter)1