Init the pref summary in onCreate()

The visibility of bottom summary in BatteryHistoryPrefence will
be changed dynamically(charging status + flags). Before this cl,
we only update it in a callback, which makes other preference
may have unnecessary moves.

This cl add init method in onCreate(), which removes the uncessary
preference position moves.

Bug: 65529494
Test: RoboTest still pass
Change-Id: I09d2e26fc3caaeb272422997c16957770cdc1d3f
(cherry picked from commit 65dea0a7b2)
This commit is contained in:
jackqdyulei
2017-09-11 14:33:28 -07:00
committed by Lei Yu
parent adef5b23e0
commit 1c5d663ed7

View File

@@ -124,6 +124,9 @@ public class PowerUsageAdvanced extends PowerUsageBase {
mPackageManager = context.getPackageManager(); mPackageManager = context.getPackageManager();
mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE); mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
mBatteryUtils = BatteryUtils.getInstance(context); mBatteryUtils = BatteryUtils.getInstance(context);
// init the summary so other preferences won't have unnecessary move
updateHistPrefSummary(context);
} }
@Override @Override
@@ -175,7 +178,13 @@ public class PowerUsageAdvanced extends PowerUsageBase {
} }
updatePreference(mHistPref); updatePreference(mHistPref);
refreshPowerUsageDataList(mStatsHelper, mUsageListGroup); refreshPowerUsageDataList(mStatsHelper, mUsageListGroup);
updateHistPrefSummary(context);
BatteryEntry.startRequestQueue();
BatteryUtils.logRuntime(TAG, "refreshUI", startTime);
}
private void updateHistPrefSummary(Context context) {
Intent batteryIntent = Intent batteryIntent =
context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
final boolean plugged = batteryIntent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1) != 0; final boolean plugged = batteryIntent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1) != 0;
@@ -186,9 +195,6 @@ public class PowerUsageAdvanced extends PowerUsageBase {
} else { } else {
mHistPref.hideBottomSummary(); mHistPref.hideBottomSummary();
} }
BatteryEntry.startRequestQueue();
BatteryUtils.logRuntime(TAG, "refreshUI", startTime);
} }
@VisibleForTesting @VisibleForTesting