Search in sources :

Example 21 with SliceAction

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

the class WifiSlice method getHeaderRow.

protected ListBuilder.RowBuilder getHeaderRow(boolean isWifiEnabled, WifiSliceItem wifiSliceItem) {
    final IconCompat icon = IconCompat.createWithResource(mContext, R.drawable.ic_settings_wireless);
    final String title = mContext.getString(R.string.wifi_settings);
    final PendingIntent primaryAction = getPrimaryAction();
    final SliceAction primarySliceAction = SliceAction.createDeeplink(primaryAction, icon, ListBuilder.ICON_IMAGE, title);
    return new ListBuilder.RowBuilder().setTitle(title).setPrimaryAction(primarySliceAction);
}
Also used : IconCompat(androidx.core.graphics.drawable.IconCompat) SliceAction(androidx.slice.builders.SliceAction) PendingIntent(android.app.PendingIntent)

Example 22 with SliceAction

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

the class ProviderModelSliceHelper method createCarrierRow.

protected ListBuilder.RowBuilder createCarrierRow(String networkTypeDescription) {
    final String title = getMobileTitle();
    final String summary = getMobileSummary(networkTypeDescription);
    Drawable drawable = mContext.getDrawable(R.drawable.ic_signal_strength_zero_bar_no_internet);
    try {
        drawable = getMobileDrawable(drawable);
    } catch (Throwable e) {
        e.printStackTrace();
    }
    final IconCompat levelIcon = Utils.createIconWithDrawable(drawable);
    final PendingIntent rowIntent = mSliceable.getBroadcastIntent(mContext);
    final SliceAction primaryAction = SliceAction.create(rowIntent, levelIcon, ListBuilder.ICON_IMAGE, title);
    final SliceAction toggleAction = SliceAction.createToggle(rowIntent, "mobile_toggle", /* actionTitle */
    isMobileDataEnabled());
    final ListBuilder.RowBuilder rowBuilder = new ListBuilder.RowBuilder().setTitle(title).setTitleItem(levelIcon, ListBuilder.ICON_IMAGE).addEndItem(toggleAction).setPrimaryAction(primaryAction).setSubtitle(Html.fromHtml(summary, Html.FROM_HTML_MODE_LEGACY));
    return rowBuilder;
}
Also used : IconCompat(androidx.core.graphics.drawable.IconCompat) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) SliceAction(androidx.slice.builders.SliceAction) ListBuilder(androidx.slice.builders.ListBuilder) PendingIntent(android.app.PendingIntent)

Example 23 with SliceAction

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

the class ProviderModelSlice method createWifiToggleRow.

/**
 * @return a {@link ListBuilder.RowBuilder} of the Wi-Fi toggle.
 */
protected ListBuilder.RowBuilder createWifiToggleRow(Context context, boolean isWifiEnabled) {
    final Intent intent = new Intent(WIFI_SLICE_URI.toString()).setData(WIFI_SLICE_URI).setClass(context, SliceBroadcastReceiver.class).putExtra(EXTRA_TOGGLE_STATE, !isWifiEnabled).addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
    final PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
    final SliceAction toggleSliceAction = SliceAction.createToggle(pendingIntent, null, /* actionTitle */
    isWifiEnabled);
    return new ListBuilder.RowBuilder().setTitle(context.getString(R.string.wifi_settings)).setPrimaryAction(toggleSliceAction);
}
Also used : SliceAction(androidx.slice.builders.SliceAction) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent)

Example 24 with SliceAction

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

the class SliceBuilderUtils method buildUnavailableSlice.

private static Slice buildUnavailableSlice(Context context, SliceData data) {
    final String title = data.getTitle();
    final Set<String> keywords = buildSliceKeywords(data);
    @ColorInt final int color = Utils.getColorAccentDefaultColor(context);
    final String customSubtitle = data.getUnavailableSliceSubtitle();
    final CharSequence subtitle = !TextUtils.isEmpty(customSubtitle) ? customSubtitle : context.getText(R.string.disabled_dependent_setting_summary);
    final IconCompat icon = getSafeIcon(context, data);
    final SliceAction primaryAction = SliceAction.createDeeplink(getContentPendingIntent(context, data), icon, ListBuilder.ICON_IMAGE, title);
    final RowBuilder rowBuilder = new RowBuilder().setTitle(title).setTitleItem(icon, ListBuilder.ICON_IMAGE).setPrimaryAction(primaryAction);
    if (!Utils.isSettingsIntelligence(context)) {
        rowBuilder.setSubtitle(subtitle);
    }
    return new ListBuilder(context, data.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) RowBuilder(androidx.slice.builders.ListBuilder.RowBuilder)

Example 25 with SliceAction

use of androidx.slice.builders.SliceAction 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)

Aggregations

SliceAction (androidx.slice.builders.SliceAction)46 IconCompat (androidx.core.graphics.drawable.IconCompat)39 ListBuilder (androidx.slice.builders.ListBuilder)37 PendingIntent (android.app.PendingIntent)32 ColorInt (android.annotation.ColorInt)18 RowBuilder (androidx.slice.builders.ListBuilder.RowBuilder)16 Intent (android.content.Intent)10 Drawable (android.graphics.drawable.Drawable)6 PorterDuffColorFilter (android.graphics.PorterDuffColorFilter)3 InputRangeBuilder (androidx.slice.builders.ListBuilder.InputRangeBuilder)3 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 SliceBroadcastReceiver (com.android.settings.slices.SliceBroadcastReceiver)2 ColorDrawable (android.graphics.drawable.ColorDrawable)1 Uri (android.net.Uri)1 Bundle (android.os.Bundle)1 SubscriptionManager (android.telephony.SubscriptionManager)1 SpannableString (android.text.SpannableString)1