Search in sources :

Example 36 with ListBuilder

use of androidx.slice.builders.ListBuilder in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class SliceBuilderUtils method buildSliderSlice.

private static Slice buildSliderSlice(Context context, SliceData sliceData, BasePreferenceController controller) {
    final SliderPreferenceController sliderController = (SliderPreferenceController) controller;
    if (sliderController.getMax() <= sliderController.getMin()) {
        Log.e(TAG, "Invalid sliderController: " + sliderController.getPreferenceKey());
        return null;
    }
    final PendingIntent actionIntent = getSliderAction(context, sliceData);
    final PendingIntent contentIntent = getContentPendingIntent(context, sliceData);
    final IconCompat icon = getSafeIcon(context, sliceData);
    @ColorInt final int color = Utils.getColorAccentDefaultColor(context);
    final CharSequence subtitleText = getSubtitleText(context, controller, sliceData);
    final SliceAction primaryAction = SliceAction.createDeeplink(contentIntent, icon, ListBuilder.ICON_IMAGE, sliceData.getTitle());
    final Set<String> keywords = buildSliceKeywords(sliceData);
    int cur = sliderController.getSliderPosition();
    if (cur < sliderController.getMin()) {
        cur = sliderController.getMin();
    }
    if (cur > sliderController.getMax()) {
        cur = sliderController.getMax();
    }
    return new ListBuilder(context, sliceData.getUri(), ListBuilder.INFINITY).setAccentColor(color).addInputRange(new InputRangeBuilder().setTitle(sliceData.getTitle()).setSubtitle(subtitleText).setPrimaryAction(primaryAction).setMax(sliderController.getMax()).setMin(sliderController.getMin()).setValue(cur).setInputAction(actionIntent)).setKeywords(keywords).build();
}
Also used : ColorInt(android.annotation.ColorInt) IconCompat(androidx.core.graphics.drawable.IconCompat) SliceAction(androidx.slice.builders.SliceAction) InputRangeBuilder(androidx.slice.builders.ListBuilder.InputRangeBuilder) ListBuilder(androidx.slice.builders.ListBuilder) PendingIntent(android.app.PendingIntent) SliderPreferenceController(com.android.settings.core.SliderPreferenceController)

Example 37 with ListBuilder

use of androidx.slice.builders.ListBuilder in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class FlashlightSlice method getSlice.

@Override
public Slice getSlice() {
    if (!isFlashlightAvailable(mContext)) {
        return null;
    }
    final PendingIntent toggleAction = getBroadcastIntent(mContext);
    @ColorInt final int color = Utils.getColorAccentDefaultColor(mContext);
    final IconCompat icon = IconCompat.createWithResource(mContext, R.drawable.ic_signal_flashlight);
    return new ListBuilder(mContext, CustomSliceRegistry.FLASHLIGHT_SLICE_URI, ListBuilder.INFINITY).setAccentColor(color).addRow(new RowBuilder().setTitle(mContext.getText(R.string.power_flashlight)).setTitleItem(icon, ICON_IMAGE).setPrimaryAction(SliceAction.createToggle(toggleAction, null, isFlashlightEnabled(mContext)))).build();
}
Also used : ColorInt(android.annotation.ColorInt) IconCompat(androidx.core.graphics.drawable.IconCompat) ListBuilder(androidx.slice.builders.ListBuilder) PendingIntent(android.app.PendingIntent) RowBuilder(androidx.slice.builders.ListBuilder.RowBuilder)

Example 38 with ListBuilder

use of androidx.slice.builders.ListBuilder in project Resurrection_packages_apps_Settings by ResurrectionRemix.

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 39 with ListBuilder

use of androidx.slice.builders.ListBuilder in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class FaceSetupSlice method getSlice.

@Override
public Slice getSlice() {
    mFaceManager = Utils.getFaceManagerOrNull(mContext);
    if (mFaceManager == null) {
        return new ListBuilder(mContext, CustomSliceRegistry.FACE_ENROLL_SLICE_URI, ListBuilder.INFINITY).setIsError(true).build();
    }
    final int userId = UserHandle.myUserId();
    final boolean hasEnrolledTemplates = mFaceManager.hasEnrolledTemplates(userId);
    final int shouldReEnroll = FaceSetupSlice.getReEnrollSetting(mContext, userId);
    CharSequence title = "";
    CharSequence subtitle = "";
    // stay the same.
    if (!hasEnrolledTemplates) {
        title = mContext.getText(R.string.security_settings_face_settings_enroll);
        subtitle = mContext.getText(R.string.security_settings_face_settings_context_subtitle);
    } else if (shouldReEnroll == FACE_RE_ENROLL_SUGGESTED) {
        title = mContext.getText(R.string.security_settings_face_enroll_should_re_enroll_title);
        subtitle = mContext.getText(R.string.security_settings_face_enroll_should_re_enroll_subtitle);
    } else if (shouldReEnroll == FACE_RE_ENROLL_REQUIRED) {
        title = mContext.getText(R.string.security_settings_face_enroll_must_re_enroll_title);
        subtitle = mContext.getText(R.string.security_settings_face_enroll_must_re_enroll_subtitle);
    } else {
        return new ListBuilder(mContext, CustomSliceRegistry.FACE_ENROLL_SLICE_URI, ListBuilder.INFINITY).setIsError(true).build();
    }
    final ListBuilder listBuilder = new ListBuilder(mContext, CustomSliceRegistry.FACE_ENROLL_SLICE_URI, ListBuilder.INFINITY).setAccentColor(Utils.getColorAccentDefaultColor(mContext));
    final IconCompat icon = IconCompat.createWithResource(mContext, R.drawable.ic_face_24dp);
    return listBuilder.addRow(buildRowBuilder(title, subtitle, icon, mContext, getIntent())).build();
}
Also used : IconCompat(androidx.core.graphics.drawable.IconCompat) ListBuilder(androidx.slice.builders.ListBuilder)

Example 40 with ListBuilder

use of androidx.slice.builders.ListBuilder in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class NotificationChannelSlice method getSlice.

@Override
public Slice getSlice() {
    final ListBuilder listBuilder = new ListBuilder(mContext, getUri(), ListBuilder.INFINITY).setAccentColor(COLOR_NOT_TINTED);
    /**
     * Get package which is satisfied with:
     * 1. Recently installed.
     * 2. Multiple channels.
     * 3. Sent at least ~10 notifications.
     */
    mPackageName = getEligibleNotificationsPackage(getRecentlyInstalledPackages());
    if (mPackageName == null) {
        // Return a header with IsError flag, if package is not found.
        return listBuilder.setHeader(getNoSuggestedAppHeader()).setIsError(true).build();
    }
    mUid = getApplicationUid(mPackageName);
    // Add notification channel header.
    final IconCompat icon = getApplicationIcon(mPackageName);
    final CharSequence title = mContext.getString(R.string.manage_app_notification, Utils.getApplicationLabel(mContext, mPackageName));
    listBuilder.addRow(new ListBuilder.RowBuilder().setTitleItem(icon, ListBuilder.ICON_IMAGE).setTitle(title).setSubtitle(getSubTitle(mPackageName, mUid)).setPrimaryAction(getPrimarySliceAction(icon, title, getIntent())));
    // Add notification channel rows.
    final List<ListBuilder.RowBuilder> rows = getNotificationChannelRows(icon);
    for (ListBuilder.RowBuilder rowBuilder : rows) {
        listBuilder.addRow(rowBuilder);
    }
    return listBuilder.build();
}
Also used : IconCompat(androidx.core.graphics.drawable.IconCompat) ListBuilder(androidx.slice.builders.ListBuilder)

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