Search in sources :

Example 26 with ListBuilder

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

the class LocationSlice method getSlice.

@Override
public Slice getSlice() {
    final IconCompat icon = IconCompat.createWithResource(mContext, com.android.internal.R.drawable.ic_signal_location);
    final CharSequence title = mContext.getText(R.string.location_settings_title);
    @ColorInt final int color = Utils.getColorAccentDefaultColor(mContext);
    final PendingIntent primaryAction = getPrimaryAction();
    final SliceAction primarySliceAction = SliceAction.createDeeplink(primaryAction, icon, ListBuilder.ICON_IMAGE, title);
    return new ListBuilder(mContext, CustomSliceRegistry.LOCATION_SLICE_URI, ListBuilder.INFINITY).setAccentColor(color).addRow(new RowBuilder().setTitle(title).setTitleItem(icon, ICON_IMAGE).setPrimaryAction(primarySliceAction)).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)

Example 27 with ListBuilder

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

the class WifiSlice method getSlice.

@Override
public Slice getSlice() {
    final boolean isWifiEnabled = isWifiEnabled();
    ListBuilder listBuilder = getListBuilder(isWifiEnabled, null);
    if (!isWifiEnabled) {
        return listBuilder.build();
    }
    final WifiScanWorker worker = SliceBackgroundWorker.getInstance(getUri());
    final List<WifiSliceItem> apList = worker != null ? worker.getResults() : null;
    final int apCount = apList == null ? 0 : apList.size();
    final boolean isFirstApActive = apCount > 0 && apList.get(0).getConnectedState() != WifiEntry.CONNECTED_STATE_DISCONNECTED;
    if (isFirstApActive) {
        // refresh header subtext
        listBuilder = getListBuilder(true, /* isWifiEnabled */
        apList.get(0));
    }
    if (isApRowCollapsed()) {
        return listBuilder.build();
    }
    // Add AP rows
    final CharSequence placeholder = mContext.getText(R.string.summary_placeholder);
    for (int i = 0; i < DEFAULT_EXPANDED_ROW_COUNT; i++) {
        if (i < apCount) {
            listBuilder.addRow(getWifiSliceItemRow(apList.get(i)));
        } else if (i == apCount) {
            listBuilder.addRow(getLoadingRow(placeholder));
        } else {
            listBuilder.addRow(new ListBuilder.RowBuilder().setTitle(placeholder).setSubtitle(placeholder));
        }
    }
    return listBuilder.build();
}
Also used : ListBuilder(androidx.slice.builders.ListBuilder)

Example 28 with ListBuilder

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

the class ProviderModelSlice method getSlice.

@Override
public Slice getSlice() {
    // The provider model slice step:
    // First section: Add the Ethernet item.
    // Second section: Add the carrier item.
    // Third section: Add the Wi-Fi toggle item.
    // Fourth section: Add the connected Wi-Fi item.
    // Fifth section: Add the Wi-Fi items which are not connected.
    // Sixth section: Add the See All item.
    final ListBuilder listBuilder = mHelper.createListBuilder(getUri());
    int maxListSize = 0;
    final NetworkProviderWorker worker = getWorker();
    if (worker != null) {
        maxListSize = worker.getApRowCount();
    } else {
        log("network provider worker is null.");
    }
    // First section: Add the Ethernet item.
    if (getInternetType() == InternetUpdater.INTERNET_ETHERNET) {
        log("get Ethernet item which is connected");
        listBuilder.addRow(createEthernetRow());
        maxListSize--;
    }
    // Second section: Add the carrier item.
    if (!mHelper.isAirplaneModeEnabled()) {
        final boolean hasCarrier = mHelper.hasCarrier();
        log("hasCarrier: " + hasCarrier);
        if (hasCarrier) {
            mHelper.updateTelephony();
            listBuilder.addRow(mHelper.createCarrierRow(worker != null ? worker.getNetworkTypeDescription() : ""));
            maxListSize--;
        }
    }
    // Third section: Add the Wi-Fi toggle item.
    final boolean isWifiEnabled = mWifiManager.isWifiEnabled();
    listBuilder.addRow(createWifiToggleRow(mContext, isWifiEnabled));
    maxListSize--;
    if (!isWifiEnabled) {
        log("Wi-Fi is disabled");
        return listBuilder.build();
    }
    List<WifiSliceItem> wifiList = (worker != null) ? worker.getResults() : null;
    if (wifiList == null || wifiList.size() <= 0) {
        log("Wi-Fi list is empty");
        return listBuilder.build();
    }
    // Fourth section: Add the connected Wi-Fi item.
    final WifiSliceItem connectedWifiItem = mHelper.getConnectedWifiItem(wifiList);
    if (connectedWifiItem != null) {
        log("get Wi-Fi item which is connected");
        listBuilder.addRow(getWifiSliceItemRow(connectedWifiItem));
        maxListSize--;
    }
    // Fifth section: Add the Wi-Fi items which are not connected.
    log("get Wi-Fi items which are not connected. Wi-Fi items : " + wifiList.size());
    final List<WifiSliceItem> disconnectedWifiList = wifiList.stream().filter(item -> item.getConnectedState() != WifiEntry.CONNECTED_STATE_CONNECTED).limit(maxListSize - 1).collect(Collectors.toList());
    for (WifiSliceItem item : disconnectedWifiList) {
        listBuilder.addRow(getWifiSliceItemRow(item));
    }
    // Sixth section: Add the See All item.
    log("add See-All");
    listBuilder.addRow(getSeeAllRow());
    return listBuilder.build();
}
Also used : WifiSliceItem(com.android.settings.wifi.slice.WifiSliceItem) ListBuilder(androidx.slice.builders.ListBuilder) NetworkProviderWorker(com.android.settings.network.telephony.NetworkProviderWorker)

Example 29 with ListBuilder

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

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

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