Search in sources :

Example 1 with TogglePreferenceController

use of com.android.settings.core.TogglePreferenceController in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class SliceBuilderUtils method buildToggleSlice.

private static Slice buildToggleSlice(Context context, SliceData sliceData, BasePreferenceController controller) {
    final PendingIntent contentIntent = getContentPendingIntent(context, sliceData);
    final IconCompat icon = getSafeIcon(context, sliceData);
    final CharSequence subtitleText = getSubtitleText(context, controller, sliceData);
    @ColorInt final int color = Utils.getColorAccentDefaultColor(context);
    final TogglePreferenceController toggleController = (TogglePreferenceController) controller;
    final SliceAction sliceAction = getToggleAction(context, sliceData, toggleController.isChecked());
    final Set<String> keywords = buildSliceKeywords(sliceData);
    return new ListBuilder(context, sliceData.getUri(), ListBuilder.INFINITY).setAccentColor(color).addRow(new RowBuilder().setTitle(sliceData.getTitle()).setSubtitle(subtitleText).setPrimaryAction(SliceAction.createDeeplink(contentIntent, icon, ListBuilder.ICON_IMAGE, sliceData.getTitle())).addEndItem(sliceAction)).setKeywords(keywords).build();
}
Also used : ColorInt(android.annotation.ColorInt) IconCompat(androidx.core.graphics.drawable.IconCompat) SliceAction(androidx.slice.builders.SliceAction) ListBuilder(androidx.slice.builders.ListBuilder) PendingIntent(android.app.PendingIntent) RowBuilder(androidx.slice.builders.ListBuilder.RowBuilder) TogglePreferenceController(com.android.settings.core.TogglePreferenceController)

Example 2 with TogglePreferenceController

use of com.android.settings.core.TogglePreferenceController in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class SliceBroadcastReceiver method handleToggleAction.

private void handleToggleAction(Context context, String key, boolean isChecked, boolean isPlatformSlice) {
    if (TextUtils.isEmpty(key)) {
        throw new IllegalStateException("No key passed to Intent for toggle controller");
    }
    final BasePreferenceController controller = getPreferenceController(context, key);
    if (!(controller instanceof TogglePreferenceController)) {
        throw new IllegalStateException("Toggle action passed for a non-toggle key: " + key);
    }
    if (!controller.isAvailable()) {
        Log.w(TAG, "Can't update " + key + " since the setting is unavailable");
        if (!controller.hasAsyncUpdate()) {
            updateUri(context, key, isPlatformSlice);
        }
        return;
    }
    // TODO post context.getContentResolver().notifyChanged(uri, null) in the Toggle controller
    // so that it's automatically broadcast to any slice.
    final TogglePreferenceController toggleController = (TogglePreferenceController) controller;
    toggleController.setChecked(isChecked);
    logSliceValueChange(context, key, isChecked ? 1 : 0);
    if (!controller.hasAsyncUpdate()) {
        updateUri(context, key, isPlatformSlice);
    }
}
Also used : BasePreferenceController(com.android.settings.core.BasePreferenceController) TogglePreferenceController(com.android.settings.core.TogglePreferenceController)

Example 3 with TogglePreferenceController

use of com.android.settings.core.TogglePreferenceController in project android_packages_apps_Settings by omnirom.

the class SliceBroadcastReceiver method handleToggleAction.

private void handleToggleAction(Context context, Uri sliceUri, String key, boolean isChecked) {
    if (TextUtils.isEmpty(key)) {
        throw new IllegalStateException("No key passed to Intent for toggle controller");
    }
    final BasePreferenceController controller = getPreferenceController(context, key);
    if (!(controller instanceof TogglePreferenceController)) {
        throw new IllegalStateException("Toggle action passed for a non-toggle key: " + key);
    }
    if (!controller.isAvailable()) {
        Log.w(TAG, "Can't update " + key + " since the setting is unavailable");
        if (!controller.hasAsyncUpdate()) {
            context.getContentResolver().notifyChange(sliceUri, null);
        }
        return;
    }
    // TODO post context.getContentResolver().notifyChanged(uri, null) in the Toggle controller
    // so that it's automatically broadcast to any slice.
    final TogglePreferenceController toggleController = (TogglePreferenceController) controller;
    toggleController.setChecked(isChecked);
    logSliceValueChange(context, key, isChecked ? 1 : 0);
    if (!controller.hasAsyncUpdate()) {
        context.getContentResolver().notifyChange(sliceUri, null);
    }
}
Also used : BasePreferenceController(com.android.settings.core.BasePreferenceController) TogglePreferenceController(com.android.settings.core.TogglePreferenceController)

Example 4 with TogglePreferenceController

use of com.android.settings.core.TogglePreferenceController in project android_packages_apps_Settings by omnirom.

the class SliceBuilderUtils method buildToggleSlice.

private static Slice buildToggleSlice(Context context, SliceData sliceData, BasePreferenceController controller) {
    final PendingIntent contentIntent = getContentPendingIntent(context, sliceData);
    final IconCompat icon = getSafeIcon(context, sliceData);
    final CharSequence subtitleText = getSubtitleText(context, controller, sliceData);
    @ColorInt final int color = Utils.getColorAccentDefaultColor(context);
    final TogglePreferenceController toggleController = (TogglePreferenceController) controller;
    final SliceAction sliceAction = getToggleAction(context, sliceData, toggleController.isChecked());
    final Set<String> keywords = buildSliceKeywords(sliceData);
    final RowBuilder rowBuilder = new RowBuilder().setTitle(sliceData.getTitle()).setPrimaryAction(SliceAction.createDeeplink(contentIntent, icon, ListBuilder.ICON_IMAGE, sliceData.getTitle())).addEndItem(sliceAction);
    if (!Utils.isSettingsIntelligence(context)) {
        rowBuilder.setSubtitle(subtitleText);
    }
    return new ListBuilder(context, sliceData.getUri(), ListBuilder.INFINITY).setAccentColor(color).addRow(rowBuilder).setKeywords(keywords).build();
}
Also used : ColorInt(android.annotation.ColorInt) IconCompat(androidx.core.graphics.drawable.IconCompat) SliceAction(androidx.slice.builders.SliceAction) ListBuilder(androidx.slice.builders.ListBuilder) PendingIntent(android.app.PendingIntent) RowBuilder(androidx.slice.builders.ListBuilder.RowBuilder) TogglePreferenceController(com.android.settings.core.TogglePreferenceController)

Aggregations

TogglePreferenceController (com.android.settings.core.TogglePreferenceController)4 ColorInt (android.annotation.ColorInt)2 PendingIntent (android.app.PendingIntent)2 IconCompat (androidx.core.graphics.drawable.IconCompat)2 ListBuilder (androidx.slice.builders.ListBuilder)2 RowBuilder (androidx.slice.builders.ListBuilder.RowBuilder)2 SliceAction (androidx.slice.builders.SliceAction)2 BasePreferenceController (com.android.settings.core.BasePreferenceController)2