Resolve locale not update issues in the chart view

- read locale from configuration rather than Locale.getDefault
- refine 12-24 format to align the current status bar short style
- resolve locale change not update chart percentage label
- extend timestamp label in the chart graph from 4 to 5 labels

Bug: 190150515
Bug: 190422902
Bug: 190226837
Test: make SettingsRoboTests
Change-Id: I5347964900123a6d112dbc37c2af87eb7d73f1d2
This commit is contained in:
ykhung
2021-06-09 11:41:33 +08:00
parent ae1797ec46
commit 2a75186e4b
7 changed files with 104 additions and 50 deletions

View File

@@ -35,6 +35,7 @@ import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.LocaleList;
import android.text.format.DateUtils;
import android.util.Pair;
@@ -100,6 +101,8 @@ public final class BatteryChartPreferenceControllerTest {
mFeatureFactory = FakeFeatureFactory.setupForTest();
mMetricsFeatureProvider = mFeatureFactory.metricsFeatureProvider;
mContext = spy(RuntimeEnvironment.application);
mContext.getResources().getConfiguration().setLocales(
new LocaleList(new Locale("en_US")));
mBatteryChartPreferenceController = createController();
mBatteryChartPreferenceController.mPrefContext = mContext;
mBatteryChartPreferenceController.mAppListPrefGroup = mAppListGroup;
@@ -573,14 +576,12 @@ public final class BatteryChartPreferenceControllerTest {
// Verifies the title in the preference group.
verify(mBatteryChartPreferenceController.mAppListPrefGroup)
.setTitle(captor.capture());
assertThat(captor.getValue())
.isEqualTo("App usage for 4 pm - 7 am");
assertThat(captor.getValue()).isEqualTo("App usage for 4 - 7");
// Verifies the title in the expandable divider.
captor = ArgumentCaptor.forClass(String.class);
verify(mBatteryChartPreferenceController.mExpandDividerPreference)
.setTitle(captor.capture());
assertThat(captor.getValue())
.isEqualTo("System usage for 4 pm - 7 am");
assertThat(captor.getValue()).isEqualTo("System usage for 4 - 7");
}
@Test
@@ -716,7 +717,8 @@ public final class BatteryChartPreferenceControllerTest {
private void setUpBatteryHistoryKeys() {
mBatteryChartPreferenceController.mBatteryHistoryKeys =
new long[] {1619196786769L, 0L, 1619247636826L};
ConvertUtils.utcToLocalTimeHour(/*timestamp=*/ 0, /*is24HourFormat=*/ false);
ConvertUtils.utcToLocalTimeHour(
mContext, /*timestamp=*/ 0, /*is24HourFormat=*/ false);
// Simulates the locale in GMT.
ConvertUtils.sSimpleDateFormatForHour
.setTimeZone(TimeZone.getTimeZone("GMT"));