Search in sources :

Example 1 with SliderPreferenceController

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

the class SliceBroadcastReceiver method handleSliderAction.

private void handleSliderAction(Context context, String key, int newPosition, boolean isPlatformSlice) {
    if (TextUtils.isEmpty(key)) {
        throw new IllegalArgumentException("No key passed to Intent for slider controller. Use extra: " + EXTRA_SLICE_KEY);
    }
    if (newPosition == -1) {
        throw new IllegalArgumentException("Invalid position passed to Slider controller");
    }
    final BasePreferenceController controller = getPreferenceController(context, key);
    if (!(controller instanceof SliderPreferenceController)) {
        throw new IllegalArgumentException("Slider action passed for a non-slider key: " + key);
    }
    if (!controller.isAvailable()) {
        Log.w(TAG, "Can't update " + key + " since the setting is unavailable");
        updateUri(context, key, isPlatformSlice);
        return;
    }
    final SliderPreferenceController sliderController = (SliderPreferenceController) controller;
    final int minValue = sliderController.getMin();
    final int maxValue = sliderController.getMax();
    if (newPosition < minValue || newPosition > maxValue) {
        throw new IllegalArgumentException("Invalid position passed to Slider controller. Expected between " + minValue + " and " + maxValue + " but found " + newPosition);
    }
    sliderController.setSliderPosition(newPosition);
    logSliceValueChange(context, key, newPosition);
    updateUri(context, key, isPlatformSlice);
}
Also used : BasePreferenceController(com.android.settings.core.BasePreferenceController) SliderPreferenceController(com.android.settings.core.SliderPreferenceController)

Example 2 with SliderPreferenceController

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

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 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();
    }
    final InputRangeBuilder inputRangeBuilder = new InputRangeBuilder().setTitle(sliceData.getTitle()).setPrimaryAction(primaryAction).setMax(sliderController.getMax()).setMin(sliderController.getMin()).setValue(cur).setInputAction(actionIntent);
    if (sliceData.getIconResource() != 0) {
        inputRangeBuilder.setTitleItem(icon, ListBuilder.ICON_IMAGE);
        color = CustomSliceable.COLOR_NOT_TINTED;
    }
    if (!Utils.isSettingsIntelligence(context)) {
        inputRangeBuilder.setSubtitle(subtitleText);
    }
    return new ListBuilder(context, sliceData.getUri(), ListBuilder.INFINITY).setAccentColor(color).addInputRange(inputRangeBuilder).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 3 with SliderPreferenceController

use of com.android.settings.core.SliderPreferenceController 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 4 with SliderPreferenceController

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

the class SliceBroadcastReceiver method handleSliderAction.

private void handleSliderAction(Context context, Uri sliceUri, String key, int newPosition) {
    if (TextUtils.isEmpty(key)) {
        throw new IllegalArgumentException("No key passed to Intent for slider controller. Use extra: " + EXTRA_SLICE_KEY);
    }
    if (newPosition == -1) {
        throw new IllegalArgumentException("Invalid position passed to Slider controller");
    }
    final BasePreferenceController controller = getPreferenceController(context, key);
    if (!(controller instanceof SliderPreferenceController)) {
        throw new IllegalArgumentException("Slider action passed for a non-slider key: " + key);
    }
    if (!controller.isAvailable()) {
        Log.w(TAG, "Can't update " + key + " since the setting is unavailable");
        context.getContentResolver().notifyChange(sliceUri, null);
        return;
    }
    final SliderPreferenceController sliderController = (SliderPreferenceController) controller;
    final int minValue = sliderController.getMin();
    final int maxValue = sliderController.getMax();
    if (newPosition < minValue || newPosition > maxValue) {
        throw new IllegalArgumentException("Invalid position passed to Slider controller. Expected between " + minValue + " and " + maxValue + " but found " + newPosition);
    }
    sliderController.setSliderPosition(newPosition);
    logSliceValueChange(context, key, newPosition);
    context.getContentResolver().notifyChange(sliceUri, null);
}
Also used : BasePreferenceController(com.android.settings.core.BasePreferenceController) SliderPreferenceController(com.android.settings.core.SliderPreferenceController)

Aggregations

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