Wrap generating battery history keys into another method

Bug: 188123855
Test: make SettingsRoboTests
Change-Id: I82a48e66ec4f7b4c0d9a6756799aa8d7a3a96848
This commit is contained in:
ykhung
2021-05-14 15:17:37 +08:00
committed by YUKAI HUNG
parent f6712e330a
commit 637d34ed71

View File

@@ -236,16 +236,7 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
mBatteryHistoryLevels = null; mBatteryHistoryLevels = null;
return; return;
} }
// Generates battery history timestamp slots. mBatteryHistoryKeys = getBatteryHistoryKeys(batteryHistoryMap);
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.
mBatteryHistoryLevels = new int[CHART_LEVEL_ARRAY_SIZE]; mBatteryHistoryLevels = new int[CHART_LEVEL_ARRAY_SIZE];
for (int index = 0; index < CHART_LEVEL_ARRAY_SIZE; index++) { for (int index = 0; index < CHART_LEVEL_ARRAY_SIZE; index++) {
final long timestamp = mBatteryHistoryKeys[index * 2]; final long timestamp = mBatteryHistoryKeys[index * 2];
@@ -273,7 +264,7 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
Log.d(TAG, String.format( Log.d(TAG, String.format(
"setBatteryHistoryMap() size=%d\nkeys=%s\nlevels=%s", "setBatteryHistoryMap() size=%d\nkeys=%s\nlevels=%s",
batteryHistoryKeyList.size(), batteryHistoryMap.size(),
utcToLocalTime(mBatteryHistoryKeys), utcToLocalTime(mBatteryHistoryKeys),
Arrays.toString(mBatteryHistoryLevels))); Arrays.toString(mBatteryHistoryLevels)));
} }
@@ -599,4 +590,16 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
} }
return true; 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;
}
} }