Merge "Wrap generating battery history keys into another method" into sc-dev am: 5c2a472b39

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/14542665

Change-Id: If3946af373bfc92875e11d9a7a007823095a717a
This commit is contained in:
TreeHugger Robot
2021-05-14 09:36:21 +00:00
committed by Automerger Merge Worker

View File

@@ -236,16 +236,7 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
mBatteryHistoryLevels = null;
return;
}
// Generates battery history timestamp slots.
final List<Long> batteryHistoryKeyList =
new ArrayList<>(batteryHistoryMap.keySet());
Collections.sort(batteryHistoryKeyList);
mBatteryHistoryKeys = new long[CHART_KEY_ARRAY_SIZE];
for (int index = 0; index < CHART_KEY_ARRAY_SIZE; index++) {
mBatteryHistoryKeys[index] = batteryHistoryKeyList.get(index);
}
// Generates the battery history levels for chart graph.
mBatteryHistoryKeys = getBatteryHistoryKeys(batteryHistoryMap);
mBatteryHistoryLevels = new int[CHART_LEVEL_ARRAY_SIZE];
for (int index = 0; index < CHART_LEVEL_ARRAY_SIZE; index++) {
final long timestamp = mBatteryHistoryKeys[index * 2];
@@ -273,7 +264,7 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
Log.d(TAG, String.format(
"setBatteryHistoryMap() size=%d\nkeys=%s\nlevels=%s",
batteryHistoryKeyList.size(),
batteryHistoryMap.size(),
utcToLocalTime(mBatteryHistoryKeys),
Arrays.toString(mBatteryHistoryLevels)));
}
@@ -599,4 +590,16 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
}
return true;
}
private static long[] getBatteryHistoryKeys(
final Map<Long, Map<String, BatteryHistEntry>> batteryHistoryMap) {
final List<Long> batteryHistoryKeyList =
new ArrayList<>(batteryHistoryMap.keySet());
Collections.sort(batteryHistoryKeyList);
final long[] batteryHistoryKeys = new long[CHART_KEY_ARRAY_SIZE];
for (int index = 0; index < CHART_KEY_ARRAY_SIZE; index++) {
batteryHistoryKeys[index] = batteryHistoryKeyList.get(index);
}
return batteryHistoryKeys;
}
}