Loading src/com/android/settings/display/darkmode/TimeFormatter.java +7 −2 Original line number Original line Diff line number Diff line Loading @@ -19,6 +19,7 @@ import android.content.Context; import java.time.LocalTime; import java.time.LocalTime; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter; import java.util.Locale; /** /** * Formats LocalTime to the locale time string format * Formats LocalTime to the locale time string format Loading @@ -28,11 +29,15 @@ public class TimeFormatter { private final DateTimeFormatter mFormatter; private final DateTimeFormatter mFormatter; public TimeFormatter(Context context) { public TimeFormatter(Context context) { mContext = context; mContext = context; mFormatter = DateTimeFormatter.ofPattern("hh:mm a"); Locale locale = mContext.getResources().getConfiguration().locale; if (locale == null) { locale = Locale.getDefault(); } mFormatter = DateTimeFormatter.ofPattern("hh:mm a", locale); } } public String of(LocalTime time) { public String of(LocalTime time) { return is24HourFormat() ? time.toString() : mFormatter.format(time); return mFormatter.format(time); } } public boolean is24HourFormat() { public boolean is24HourFormat() { Loading tests/robotests/src/com/android/settings/display/darkmode/DarkModeActivationPreferenceControllerTest.java +1 −0 Original line number Original line Diff line number Diff line Loading @@ -82,6 +82,7 @@ public class DarkModeActivationPreferenceControllerTest { MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this); mService = mock(UiModeManager.class); mService = mock(UiModeManager.class); when(mContext.getResources()).thenReturn(res); when(mContext.getResources()).thenReturn(res); when(res.getConfiguration()).thenReturn(mConfigNightNo); when(mContext.getSystemService(UiModeManager.class)).thenReturn(mService); when(mContext.getSystemService(UiModeManager.class)).thenReturn(mService); when(mContext.getSystemService(PowerManager.class)).thenReturn(mPM); when(mContext.getSystemService(PowerManager.class)).thenReturn(mPM); when(mScreen.findPreference(anyString())).thenReturn(mPreference); when(mScreen.findPreference(anyString())).thenReturn(mPreference); Loading Loading
src/com/android/settings/display/darkmode/TimeFormatter.java +7 −2 Original line number Original line Diff line number Diff line Loading @@ -19,6 +19,7 @@ import android.content.Context; import java.time.LocalTime; import java.time.LocalTime; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter; import java.util.Locale; /** /** * Formats LocalTime to the locale time string format * Formats LocalTime to the locale time string format Loading @@ -28,11 +29,15 @@ public class TimeFormatter { private final DateTimeFormatter mFormatter; private final DateTimeFormatter mFormatter; public TimeFormatter(Context context) { public TimeFormatter(Context context) { mContext = context; mContext = context; mFormatter = DateTimeFormatter.ofPattern("hh:mm a"); Locale locale = mContext.getResources().getConfiguration().locale; if (locale == null) { locale = Locale.getDefault(); } mFormatter = DateTimeFormatter.ofPattern("hh:mm a", locale); } } public String of(LocalTime time) { public String of(LocalTime time) { return is24HourFormat() ? time.toString() : mFormatter.format(time); return mFormatter.format(time); } } public boolean is24HourFormat() { public boolean is24HourFormat() { Loading
tests/robotests/src/com/android/settings/display/darkmode/DarkModeActivationPreferenceControllerTest.java +1 −0 Original line number Original line Diff line number Diff line Loading @@ -82,6 +82,7 @@ public class DarkModeActivationPreferenceControllerTest { MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this); mService = mock(UiModeManager.class); mService = mock(UiModeManager.class); when(mContext.getResources()).thenReturn(res); when(mContext.getResources()).thenReturn(res); when(res.getConfiguration()).thenReturn(mConfigNightNo); when(mContext.getSystemService(UiModeManager.class)).thenReturn(mService); when(mContext.getSystemService(UiModeManager.class)).thenReturn(mService); when(mContext.getSystemService(PowerManager.class)).thenReturn(mPM); when(mContext.getSystemService(PowerManager.class)).thenReturn(mPM); when(mScreen.findPreference(anyString())).thenReturn(mPreference); when(mScreen.findPreference(anyString())).thenReturn(mPreference); Loading