Merge "Refine the update process of battery tip" into pi-dev am: 227f056c8b
am: 5072234808
Change-Id: I92a29efd4c58a002c23a5d97f3cba5a581a44212
This commit is contained in:
@@ -105,6 +105,8 @@ public class PowerUsageSummary extends PowerUsageBase implements OnLongClickList
|
||||
SparseArray<List<Anomaly>> mAnomalySparseArray;
|
||||
@VisibleForTesting
|
||||
BatteryHeaderPreferenceController mBatteryHeaderPreferenceController;
|
||||
@VisibleForTesting
|
||||
boolean mNeedUpdateBatteryTip;
|
||||
private BatteryTipPreferenceController mBatteryTipPreferenceController;
|
||||
private int mStatsType = BatteryStats.STATS_SINCE_CHARGED;
|
||||
|
||||
@@ -211,6 +213,8 @@ public class PowerUsageSummary extends PowerUsageBase implements OnLongClickList
|
||||
mAnomalySparseArray = new SparseArray<>();
|
||||
|
||||
restartBatteryInfoLoader();
|
||||
mNeedUpdateBatteryTip = icicle == null;
|
||||
mBatteryTipPreferenceController.restoreInstanceState(icicle);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -291,7 +295,12 @@ public class PowerUsageSummary extends PowerUsageBase implements OnLongClickList
|
||||
return;
|
||||
}
|
||||
|
||||
restartBatteryTipLoader();
|
||||
// Only skip BatteryTipLoader for the first time when device is rotated
|
||||
if (mNeedUpdateBatteryTip) {
|
||||
restartBatteryTipLoader();
|
||||
} else {
|
||||
mNeedUpdateBatteryTip = true;
|
||||
}
|
||||
|
||||
// reload BatteryInfo and updateUI
|
||||
restartBatteryInfoLoader();
|
||||
@@ -385,6 +394,12 @@ public class PowerUsageSummary extends PowerUsageBase implements OnLongClickList
|
||||
restartBatteryStatsLoader(true /* clearHeader */);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
mBatteryTipPreferenceController.saveInstanceState(outState);
|
||||
}
|
||||
|
||||
void restartBatteryStatsLoader(boolean clearHeader) {
|
||||
super.restartBatteryStatsLoader();
|
||||
if (clearHeader) {
|
||||
|
@@ -17,8 +17,8 @@
|
||||
package com.android.settings.fuelgauge.batterytip;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.support.v14.preference.PreferenceFragment;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceGroup;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
@@ -34,6 +34,7 @@ import com.android.settings.fuelgauge.batterytip.tips.SummaryTip;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -44,6 +45,7 @@ import java.util.Map;
|
||||
public class BatteryTipPreferenceController extends BasePreferenceController {
|
||||
private static final String TAG = "BatteryTipPreferenceController";
|
||||
private static final int REQUEST_ANOMALY_ACTION = 0;
|
||||
private static final String KEY_BATTERY_TIPS = "key_battery_tips";
|
||||
|
||||
private BatteryTipListener mBatteryTipListener;
|
||||
private List<BatteryTip> mBatteryTips;
|
||||
@@ -138,6 +140,17 @@ public class BatteryTipPreferenceController extends BasePreferenceController {
|
||||
return super.handlePreferenceTreeClick(preference);
|
||||
}
|
||||
|
||||
public void restoreInstanceState(Bundle bundle) {
|
||||
if (bundle != null) {
|
||||
List<BatteryTip> batteryTips = bundle.getParcelableArrayList(KEY_BATTERY_TIPS);
|
||||
updateBatteryTips(batteryTips);
|
||||
}
|
||||
}
|
||||
|
||||
public void saveInstanceState(Bundle outState) {
|
||||
outState.putParcelableList(KEY_BATTERY_TIPS, mBatteryTips);
|
||||
}
|
||||
|
||||
/**
|
||||
* Listener to give the control back to target fragment
|
||||
*/
|
||||
|
@@ -98,6 +98,9 @@ public class RestrictAppTip extends BatteryTip {
|
||||
// If anomaly becomes invisible, show it as handled
|
||||
mState = StateType.HANDLED;
|
||||
mShowDialog = false;
|
||||
} else {
|
||||
mState = tip.getState();
|
||||
mShowDialog = tip.shouldShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user