Only show one tip at a time

1. Update the order for each tip.
2. Change BatteryTipPreferenceController and only show one precedent
tip.
3. Update the SummaryDetector since now it doesn't need visibleTips

Bug: 70570352
Test: RunSettingsRoboTests
Change-Id: I9e2b8e72aad263f8a210c9320e0ea1eaaf8d5042
This commit is contained in:
jackqdyulei
2018-01-10 18:21:11 -08:00
parent 62d6a9dca7
commit 2e0bdc34f2
6 changed files with 48 additions and 65 deletions

View File

@@ -22,7 +22,6 @@ import android.support.annotation.VisibleForTesting;
import com.android.internal.os.BatteryStatsHelper;
import com.android.settings.fuelgauge.BatteryInfo;
import com.android.settings.fuelgauge.BatteryUtils;
import com.android.settings.fuelgauge.batterytip.detectors.BatteryTipDetector;
import com.android.settings.fuelgauge.batterytip.detectors.EarlyWarningDetector;
import com.android.settings.fuelgauge.batterytip.detectors.HighUsageDetector;
import com.android.settings.fuelgauge.batterytip.detectors.LowBatteryDetector;
@@ -47,9 +46,8 @@ public class BatteryTipLoader extends AsyncLoader<List<BatteryTip>> {
private static final boolean USE_FAKE_DATA = false;
private BatteryStatsHelper mBatteryStatsHelper;
private BatteryUtils mBatteryUtils;
@VisibleForTesting
int mVisibleTips;
BatteryUtils mBatteryUtils;
public BatteryTipLoader(Context context, BatteryStatsHelper batteryStatsHelper) {
super(context);
@@ -66,16 +64,12 @@ public class BatteryTipLoader extends AsyncLoader<List<BatteryTip>> {
final BatteryTipPolicy policy = new BatteryTipPolicy(getContext());
final BatteryInfo batteryInfo = mBatteryUtils.getBatteryInfo(mBatteryStatsHelper, TAG);
final Context context = getContext();
mVisibleTips = 0;
addBatteryTipFromDetector(tips, new LowBatteryDetector(policy, batteryInfo));
addBatteryTipFromDetector(tips,
new HighUsageDetector(context, policy, mBatteryStatsHelper));
addBatteryTipFromDetector(tips,
new SmartBatteryDetector(policy, context.getContentResolver()));
addBatteryTipFromDetector(tips, new EarlyWarningDetector(policy, context));
// Add summary detector at last since it need other detectors to update the mVisibleTips
addBatteryTipFromDetector(tips, new SummaryDetector(policy, mVisibleTips));
tips.add(new LowBatteryDetector(policy, batteryInfo).detect());
tips.add(new HighUsageDetector(context, policy, mBatteryStatsHelper).detect());
tips.add(new SmartBatteryDetector(policy, context.getContentResolver()).detect());
tips.add(new EarlyWarningDetector(policy, context).detect());
tips.add(new SummaryDetector(policy).detect());
Collections.sort(tips);
return tips;
@@ -93,12 +87,4 @@ public class BatteryTipLoader extends AsyncLoader<List<BatteryTip>> {
return tips;
}
@VisibleForTesting
void addBatteryTipFromDetector(final List<BatteryTip> tips,
final BatteryTipDetector detector) {
final BatteryTip batteryTip = detector.detect();
mVisibleTips += batteryTip.isVisible() ? 1 : 0;
tips.add(batteryTip);
}
}

View File

@@ -98,6 +98,7 @@ public class BatteryTipPreferenceController extends BasePreferenceController {
final Preference preference = batteryTip.buildPreference(mPrefContext);
mBatteryTipMap.put(preference.getKey(), batteryTip);
mPreferenceGroup.addPreference(preference);
break;
}
}
}

View File

@@ -26,17 +26,15 @@ import com.android.settings.fuelgauge.batterytip.tips.SummaryTip;
*/
public class SummaryDetector implements BatteryTipDetector {
private BatteryTipPolicy mPolicy;
private int mVisibleTips;
public SummaryDetector(BatteryTipPolicy policy, int visibleTips) {
public SummaryDetector(BatteryTipPolicy policy) {
mPolicy = policy;
mVisibleTips = visibleTips;
}
@Override
public BatteryTip detect() {
// Show it if there is no other tips shown
final int state = mPolicy.summaryEnabled && mVisibleTips == 0
final int state = mPolicy.summaryEnabled
? BatteryTip.StateType.NEW
: BatteryTip.StateType.INVISIBLE;
return new SummaryTip(state);

View File

@@ -52,13 +52,13 @@ public abstract class BatteryTip implements Comparable<BatteryTip>, Parcelable {
TipType.REDUCED_BATTERY,
TipType.LOW_BATTERY})
public @interface TipType {
int SUMMARY = 0;
int BATTERY_SAVER = 1;
int SMART_BATTERY_MANAGER = 0;
int APP_RESTRICTION = 1;
int HIGH_DEVICE_USAGE = 2;
int SMART_BATTERY_MANAGER = 3;
int APP_RESTRICTION = 4;
int REDUCED_BATTERY = 5;
int LOW_BATTERY = 6;
int BATTERY_SAVER = 3;
int REDUCED_BATTERY = 4;
int LOW_BATTERY = 5;
int SUMMARY = 6;
}
private static final String KEY_PREFIX = "key_battery_tip";