Search in sources :

Example 21 with BatteryTip

use of com.android.settings.fuelgauge.batterytip.tips.BatteryTip 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)

Example 22 with BatteryTip

use of com.android.settings.fuelgauge.batterytip.tips.BatteryTip in project android_packages_apps_Settings by omnirom.

the class BatteryTipPreferenceController method updateBatteryTips.

public void updateBatteryTips(List<BatteryTip> batteryTips) {
    if (batteryTips == null) {
        return;
    }
    if (mBatteryTips == null) {
        mBatteryTips = batteryTips;
    } else {
        // mBatteryTips and batteryTips always have the same length and same sequence.
        for (int i = 0, size = batteryTips.size(); i < size; i++) {
            mBatteryTips.get(i).updateState(batteryTips.get(i));
        }
    }
    mCardPreference.setVisible(false);
    for (int i = 0, size = batteryTips.size(); i < size; i++) {
        final BatteryTip batteryTip = mBatteryTips.get(i);
        batteryTip.validateCheck(mContext);
        if (batteryTip.getState() != BatteryTip.StateType.INVISIBLE) {
            mCardPreference.setVisible(true);
            batteryTip.updatePreference(mCardPreference);
            mBatteryTipMap.put(mCardPreference.getKey(), batteryTip);
            batteryTip.log(mContext, mMetricsFeatureProvider);
            mNeedUpdate = batteryTip.needUpdate();
            break;
        }
    }
}
Also used : BatteryTip(com.android.settings.fuelgauge.batterytip.tips.BatteryTip)

Example 23 with BatteryTip

use of com.android.settings.fuelgauge.batterytip.tips.BatteryTip in project android_packages_apps_Settings by omnirom.

the class BatteryFixSliceTest method getSlice_unimportantSlice_shouldSkip.

@Test
public void getSlice_unimportantSlice_shouldSkip() {
    final List<BatteryTip> tips = new ArrayList<>();
    final List<AppInfo> appList = new ArrayList<>();
    appList.add(new AppInfo.Builder().setPackageName("com.android.settings").setScreenOnTimeMs(10000L).build());
    tips.add(new LowBatteryTip(BatteryTip.StateType.INVISIBLE, false));
    tips.add(new EarlyWarningTip(BatteryTip.StateType.HANDLED, false));
    tips.add(new HighUsageTip(1000L, appList));
    ShadowBatteryTipLoader.setBatteryTips(tips);
    BatteryFixSlice.refreshBatteryTips(mContext);
    final Slice slice = mSlice.getSlice();
    assertThat(SliceMetadata.from(mContext, slice).isErrorSlice()).isTrue();
}
Also used : EarlyWarningTip(com.android.settings.fuelgauge.batterytip.tips.EarlyWarningTip) HighUsageTip(com.android.settings.fuelgauge.batterytip.tips.HighUsageTip) Slice(androidx.slice.Slice) ArrayList(java.util.ArrayList) LowBatteryTip(com.android.settings.fuelgauge.batterytip.tips.LowBatteryTip) BatteryTip(com.android.settings.fuelgauge.batterytip.tips.BatteryTip) LowBatteryTip(com.android.settings.fuelgauge.batterytip.tips.LowBatteryTip) AppInfo(com.android.settings.fuelgauge.batterytip.AppInfo) Test(org.junit.Test)

Aggregations

BatteryTip (com.android.settings.fuelgauge.batterytip.tips.BatteryTip)23 LowBatteryTip (com.android.settings.fuelgauge.batterytip.tips.LowBatteryTip)13 ArrayList (java.util.ArrayList)10 Test (org.junit.Test)9 EarlyWarningTip (com.android.settings.fuelgauge.batterytip.tips.EarlyWarningTip)6 Slice (androidx.slice.Slice)4 VisibleForTesting (androidx.annotation.VisibleForTesting)3 AppInfo (com.android.settings.fuelgauge.batterytip.AppInfo)3 SmartBatteryTip (com.android.settings.fuelgauge.batterytip.tips.SmartBatteryTip)3 Context (android.content.Context)2 PorterDuffColorFilter (android.graphics.PorterDuffColorFilter)2 Drawable (android.graphics.drawable.Drawable)2 WorkerThread (androidx.annotation.WorkerThread)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 BatteryInfo (com.android.settings.fuelgauge.BatteryInfo)2 BatteryTipDialogFragment (com.android.settings.fuelgauge.batterytip.BatteryTipDialogFragment)2 BatteryTipLoader (com.android.settings.fuelgauge.batterytip.BatteryTipLoader)2