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();
}
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;
}
}
}
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();
}
Aggregations