Fix only one battery stat showing sometimes.

Take into account the prefs we are currently caching within the
group when counting how many prefs have been added.

Change-Id: I962acd41592c1a9366882711d3f4944bffb54d22
Fixes: 27931457
This commit is contained in:
Jason Monk
2016-04-21 10:12:30 -04:00
parent 257355afde
commit a627844fed
2 changed files with 10 additions and 3 deletions

View File

@@ -399,6 +399,10 @@ public abstract class SettingsPreferenceFragment extends InstrumentedPreferenceF
}
}
protected int getCachedCount() {
return mPreferenceCache.size();
}
private void highlightPreference(String key) {
final int position = canUseListViewForHighLighting(key);
if (position >= 0) {

View File

@@ -368,7 +368,8 @@ public class PowerUsageSummary extends PowerUsageBase {
}
addedSome = true;
mAppListGroup.addPreference(pref);
if (mAppListGroup.getPreferenceCount() > (MAX_ITEMS_TO_LIST + 1)) {
if (mAppListGroup.getPreferenceCount() - getCachedCount()
> (MAX_ITEMS_TO_LIST + 1)) {
break;
}
}
@@ -391,8 +392,10 @@ public class PowerUsageSummary extends PowerUsageBase {
stats.add(new BatterySipper(type, null, use));
use += 5;
}
stats.add(new BatterySipper(DrainType.APP,
new FakeUid(Process.FIRST_APPLICATION_UID), use));
for (int i = 0; i < 100; i++) {
stats.add(new BatterySipper(DrainType.APP,
new FakeUid(Process.FIRST_APPLICATION_UID + i), use));
}
stats.add(new BatterySipper(DrainType.APP,
new FakeUid(0), use));