Search in sources :

Example 1 with BatteryTip

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();
}
Also used : EarlyWarningTip(com.android.settings.fuelgauge.batterytip.tips.EarlyWarningTip) 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) Test(org.junit.Test)

Example 2 with BatteryTip

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();
}
Also used : EarlyWarningTip(com.android.settings.fuelgauge.batterytip.tips.EarlyWarningTip) Slice(androidx.slice.Slice) ArrayList(java.util.ArrayList) LowBatteryTip(com.android.settings.fuelgauge.batterytip.tips.LowBatteryTip) BatteryTip(com.android.settings.fuelgauge.batterytip.tips.BatteryTip) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 3 with BatteryTip

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);
}
Also used : BatteryTipDialogFragment(com.android.settings.fuelgauge.batterytip.BatteryTipDialogFragment) RestrictAppTip(com.android.settings.fuelgauge.batterytip.tips.RestrictAppTip) BatteryTip(com.android.settings.fuelgauge.batterytip.tips.BatteryTip) AppInfo(com.android.settings.fuelgauge.batterytip.AppInfo) UnrestrictAppTip(com.android.settings.fuelgauge.batterytip.tips.UnrestrictAppTip) VisibleForTesting(androidx.annotation.VisibleForTesting)

Example 4 with BatteryTip

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();
}
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 5 with BatteryTip

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;
}
Also used : BatteryTipLoader(com.android.settings.fuelgauge.batterytip.BatteryTipLoader) BatteryStatsHelperLoader(com.android.settings.fuelgauge.BatteryStatsHelperLoader) BatteryStatsHelper(com.android.internal.os.BatteryStatsHelper) BatteryTip(com.android.settings.fuelgauge.batterytip.tips.BatteryTip) WorkerThread(androidx.annotation.WorkerThread)

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