Search in sources :

Example 1 with SliceBackgroundWorker

use of com.android.settings.slices.SliceBackgroundWorker in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class BatteryFixSlice method getSlice.

@Override
public Slice getSlice() {
    final ListBuilder sliceBuilder = new ListBuilder(mContext, BATTERY_FIX_SLICE_URI, ListBuilder.INFINITY).setAccentColor(COLOR_NOT_TINTED);
    if (!isBatteryTipAvailableFromCache(mContext)) {
        return buildBatteryGoodSlice(sliceBuilder, true);
    }
    final SliceBackgroundWorker worker = SliceBackgroundWorker.getInstance(getUri());
    final List<BatteryTip> batteryTips = worker != null ? worker.getResults() : null;
    if (batteryTips == null) {
        // Because we need wait slice background worker return data
        return buildBatteryGoodSlice(sliceBuilder, false);
    }
    for (BatteryTip batteryTip : batteryTips) {
        if (batteryTip.getState() == BatteryTip.StateType.INVISIBLE) {
            continue;
        }
        final Drawable drawable = mContext.getDrawable(batteryTip.getIconId());
        final int iconTintColorId = batteryTip.getIconTintColorId();
        if (iconTintColorId != View.NO_ID) {
            drawable.setColorFilter(new PorterDuffColorFilter(mContext.getResources().getColor(iconTintColorId), PorterDuff.Mode.SRC_IN));
        }
        final IconCompat icon = Utils.createIconWithDrawable(drawable);
        final SliceAction primaryAction = SliceAction.createDeeplink(getPrimaryAction(), icon, ListBuilder.ICON_IMAGE, batteryTip.getTitle(mContext));
        sliceBuilder.addRow(new RowBuilder().setTitleItem(icon, ListBuilder.ICON_IMAGE).setTitle(batteryTip.getTitle(mContext)).setSubtitle(batteryTip.getSummary(mContext)).setPrimaryAction(primaryAction));
        break;
    }
    return sliceBuilder.build();
}
Also used : SliceBackgroundWorker(com.android.settings.slices.SliceBackgroundWorker) IconCompat(androidx.core.graphics.drawable.IconCompat) Drawable(android.graphics.drawable.Drawable) SliceAction(androidx.slice.builders.SliceAction) ListBuilder(androidx.slice.builders.ListBuilder) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) RowBuilder(androidx.slice.builders.ListBuilder.RowBuilder) BatteryTip(com.android.settings.fuelgauge.batterytip.tips.BatteryTip)

Example 2 with SliceBackgroundWorker

use of com.android.settings.slices.SliceBackgroundWorker in project android_packages_apps_Settings by omnirom.

the class WifiSliceTest method setWorkerResults.

private void setWorkerResults(WifiSliceItem... wifiSliceItems) {
    final ArrayList<WifiSliceItem> results = new ArrayList<>();
    for (WifiSliceItem wifiSliceItem : wifiSliceItems) {
        results.add(wifiSliceItem);
    }
    final SliceBackgroundWorker worker = SliceBackgroundWorker.getInstance(mWifiSlice.getUri());
    doReturn(results).when(worker).getResults();
}
Also used : SliceBackgroundWorker(com.android.settings.slices.SliceBackgroundWorker) ArrayList(java.util.ArrayList)

Example 3 with SliceBackgroundWorker

use of com.android.settings.slices.SliceBackgroundWorker in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class WifiSliceTest method setWorkerResults.

private void setWorkerResults(AccessPoint... accessPoints) {
    final ArrayList<AccessPoint> results = new ArrayList<>();
    for (AccessPoint ap : accessPoints) {
        results.add(ap);
    }
    final SliceBackgroundWorker worker = SliceBackgroundWorker.getInstance(mWifiSlice.getUri());
    doReturn(results).when(worker).getResults();
}
Also used : SliceBackgroundWorker(com.android.settings.slices.SliceBackgroundWorker) AccessPoint(com.android.settingslib.wifi.AccessPoint) ArrayList(java.util.ArrayList)

Example 4 with SliceBackgroundWorker

use of com.android.settings.slices.SliceBackgroundWorker in project android_packages_apps_Settings by omnirom.

the class BatteryFixSlice method getSlice.

@Override
public Slice getSlice() {
    final ListBuilder sliceBuilder = new ListBuilder(mContext, BATTERY_FIX_SLICE_URI, ListBuilder.INFINITY).setAccentColor(COLOR_NOT_TINTED);
    if (!isBatteryTipAvailableFromCache(mContext)) {
        return buildBatteryGoodSlice(sliceBuilder, true);
    }
    final SliceBackgroundWorker worker = SliceBackgroundWorker.getInstance(getUri());
    final List<BatteryTip> batteryTips = worker != null ? worker.getResults() : null;
    if (batteryTips == null) {
        // Because we need wait slice background worker return data
        return buildBatteryGoodSlice(sliceBuilder, false);
    }
    for (BatteryTip batteryTip : batteryTips) {
        if (batteryTip.getState() == BatteryTip.StateType.INVISIBLE) {
            continue;
        }
        final Drawable drawable = mContext.getDrawable(batteryTip.getIconId());
        final int iconTintColorId = batteryTip.getIconTintColorId();
        if (iconTintColorId != View.NO_ID) {
            drawable.setColorFilter(new PorterDuffColorFilter(mContext.getResources().getColor(iconTintColorId), PorterDuff.Mode.SRC_IN));
        }
        final IconCompat icon = Utils.createIconWithDrawable(drawable);
        final SliceAction primaryAction = SliceAction.createDeeplink(getPrimaryAction(), icon, ListBuilder.ICON_IMAGE, batteryTip.getTitle(mContext));
        sliceBuilder.addRow(new RowBuilder().setTitleItem(icon, ListBuilder.ICON_IMAGE).setTitle(batteryTip.getTitle(mContext)).setSubtitle(batteryTip.getSummary(mContext)).setPrimaryAction(primaryAction));
        break;
    }
    return sliceBuilder.build();
}
Also used : SliceBackgroundWorker(com.android.settings.slices.SliceBackgroundWorker) IconCompat(androidx.core.graphics.drawable.IconCompat) Drawable(android.graphics.drawable.Drawable) SliceAction(androidx.slice.builders.SliceAction) ListBuilder(androidx.slice.builders.ListBuilder) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) RowBuilder(androidx.slice.builders.ListBuilder.RowBuilder) BatteryTip(com.android.settings.fuelgauge.batterytip.tips.BatteryTip)

Aggregations

SliceBackgroundWorker (com.android.settings.slices.SliceBackgroundWorker)4 PorterDuffColorFilter (android.graphics.PorterDuffColorFilter)2 Drawable (android.graphics.drawable.Drawable)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 BatteryTip (com.android.settings.fuelgauge.batterytip.tips.BatteryTip)2 ArrayList (java.util.ArrayList)2 AccessPoint (com.android.settingslib.wifi.AccessPoint)1