use of com.android.settings.fuelgauge.batterytip.tips.BatteryTip in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class BatteryFixSliceTest method getSlice_unimportantSlice_shouldSkip.
@Test
public void getSlice_unimportantSlice_shouldSkip() {
final List<BatteryTip> tips = new ArrayList<>();
tips.add(new LowBatteryTip(BatteryTip.StateType.INVISIBLE, false, ""));
tips.add(new EarlyWarningTip(BatteryTip.StateType.HANDLED, false));
ShadowBatteryTipLoader.setBatteryTips(tips);
BatteryFixSlice.updateBatteryTipAvailabilityCache(mContext);
final Slice slice = mSlice.getSlice();
assertThat(SliceMetadata.from(mContext, slice).isErrorSlice()).isTrue();
}
use of com.android.settings.fuelgauge.batterytip.tips.BatteryTip in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class BatteryFixSliceTest method getSlice_hasImportantTip_shouldTintIcon.
@Test
@Config(shadows = { BatteryFixSliceTest.ShadowEarlyWarningTip.class, BatteryFixSliceTest.ShadowSliceBackgroundWorker.class })
public void getSlice_hasImportantTip_shouldTintIcon() {
final List<BatteryTip> tips = new ArrayList<>();
tips.add(new EarlyWarningTip(BatteryTip.StateType.NEW, false));
// Create fake cache data
ShadowBatteryTipLoader.setBatteryTips(tips);
BatteryFixSlice.updateBatteryTipAvailabilityCache(mContext);
// Create fake background worker data
BatteryFixSlice.BatteryTipWorker batteryTipWorker = mock(BatteryFixSlice.BatteryTipWorker.class);
when(batteryTipWorker.getResults()).thenReturn(tips);
ShadowSliceBackgroundWorker.setBatteryTipWorkerWorker(batteryTipWorker);
final Slice slice = mSlice.getSlice();
assertThat(ShadowEarlyWarningTip.isIconTintColorIdCalled()).isTrue();
}
use of com.android.settings.fuelgauge.batterytip.tips.BatteryTip in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class BackgroundActivityPreferenceController method showDialog.
@VisibleForTesting
void showDialog(boolean restricted) {
final AppInfo appInfo = new AppInfo.Builder().setUid(mUid).setPackageName(mTargetPackage).build();
BatteryTip tip = restricted ? new UnrestrictAppTip(BatteryTip.StateType.NEW, appInfo) : new RestrictAppTip(BatteryTip.StateType.NEW, appInfo);
final BatteryTipDialogFragment dialogFragment = BatteryTipDialogFragment.newInstance(tip, mFragment.getMetricsCategory());
dialogFragment.setTargetFragment(mFragment, 0);
dialogFragment.show(mFragment.getFragmentManager(), TAG);
}
use of com.android.settings.fuelgauge.batterytip.tips.BatteryTip 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();
}
use of com.android.settings.fuelgauge.batterytip.tips.BatteryTip in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class BatteryFixSlice method refreshBatteryTips.
@WorkerThread
private static List<BatteryTip> refreshBatteryTips(Context context) {
final BatteryStatsHelperLoader statsLoader = new BatteryStatsHelperLoader(context);
final BatteryStatsHelper statsHelper = statsLoader.loadInBackground();
final BatteryTipLoader loader = new BatteryTipLoader(context, statsHelper);
final List<BatteryTip> batteryTips = loader.loadInBackground();
for (BatteryTip batteryTip : batteryTips) {
if (batteryTip.getState() != BatteryTip.StateType.INVISIBLE) {
context.getSharedPreferences(PREFS, MODE_PRIVATE).edit().putInt(KEY_CURRENT_TIPS_TYPE, batteryTip.getType()).putInt(KEY_CURRENT_TIPS_STATE, batteryTip.getState()).apply();
break;
}
}
return batteryTips;
}
Aggregations