Loading packages/SystemUI/customization/src/com/android/systemui/shared/clocks/FlexClockFaceController.kt +1 −1 Original line number Diff line number Diff line Loading @@ -129,7 +129,7 @@ class FlexClockFaceController( } override fun onLocaleChanged(locale: Locale) { timeFormatter.updateLocale(locale) timeFormatter.locale = locale layerController.events.onLocaleChanged(locale) } Loading packages/SystemUI/customization/src/com/android/systemui/shared/clocks/SimpleDigitalHandLayerController.kt +3 −1 Original line number Diff line number Diff line Loading @@ -123,15 +123,17 @@ open class SimpleDigitalHandLayerController( override var isReactiveTouchInteractionEnabled = false override fun onLocaleChanged(locale: Locale) { timespec.formatter.updateLocale(locale) timespec.formatter.locale = locale refreshTime() } override fun onTimeFormatChanged(formatKind: TimeFormatKind) { timespec.formatter.formatKind = formatKind refreshTime() } override fun onTimeZoneChanged(timeZone: TimeZone) { timespec.formatter.timeKeeper.timeZone = timeZone refreshTime() } Loading packages/SystemUI/customization/src/com/android/systemui/shared/clocks/TimespecHandler.kt +26 −14 Original line number Diff line number Diff line Loading @@ -43,9 +43,11 @@ open class TimeKeeperImpl(private val cal: Calendar = Calendar.getInstance()) : override var timeZone: TimeZone get() = cal.timeZone set(value) { if (cal.timeZone != value) { cal.timeZone = value callbacks.forEach { it.onTimeZoneChanged() } } } override val callbacks = mutableListOf<TimeKeeper.Callback>() Loading Loading @@ -82,35 +84,45 @@ private fun TimeFormatKind.getContentDescriptionPattern(pattern: String): String class DigitalTimeFormatter( val pattern: String, private val timeKeeper: TimeKeeper, private val enableContentDescription: Boolean = false, val timeKeeper: TimeKeeper, val enableContentDescription: Boolean = false, ) : TimeKeeper.Callback { var formatKind = TimeFormatKind.HALF_DAY set(value) { if (field != value) { field = value applyPattern() } } var locale = Locale.getDefault() set(value) { if (field != value) { field = value onLocaleChanged() } } private lateinit var textFormat: SimpleDateFormat private var contentDescriptionFormat: SimpleDateFormat? = null init { timeKeeper.callbacks.add(this) updateLocale(Locale.getDefault()) onLocaleChanged() } override fun onTimeZoneChanged() { textFormat.timeZone = TimeZone.getTimeZone(timeKeeper.timeZone.id) contentDescriptionFormat?.timeZone = TimeZone.getTimeZone(timeKeeper.timeZone.id) applyPattern() } fun updateLocale(locale: Locale) { fun onLocaleChanged() { textFormat = getTextFormat(locale) contentDescriptionFormat = getContentDescriptionFormat(locale) onTimeZoneChanged() } override fun onTimeZoneChanged() { textFormat.timeZone = timeKeeper.timeZone contentDescriptionFormat?.timeZone = timeKeeper.timeZone applyPattern() } private fun getTextFormat(locale: Locale): SimpleDateFormat { if (locale.language.equals(Locale.ENGLISH.language)) { // force date format in English, and time format to use format defined in json Loading Loading
packages/SystemUI/customization/src/com/android/systemui/shared/clocks/FlexClockFaceController.kt +1 −1 Original line number Diff line number Diff line Loading @@ -129,7 +129,7 @@ class FlexClockFaceController( } override fun onLocaleChanged(locale: Locale) { timeFormatter.updateLocale(locale) timeFormatter.locale = locale layerController.events.onLocaleChanged(locale) } Loading
packages/SystemUI/customization/src/com/android/systemui/shared/clocks/SimpleDigitalHandLayerController.kt +3 −1 Original line number Diff line number Diff line Loading @@ -123,15 +123,17 @@ open class SimpleDigitalHandLayerController( override var isReactiveTouchInteractionEnabled = false override fun onLocaleChanged(locale: Locale) { timespec.formatter.updateLocale(locale) timespec.formatter.locale = locale refreshTime() } override fun onTimeFormatChanged(formatKind: TimeFormatKind) { timespec.formatter.formatKind = formatKind refreshTime() } override fun onTimeZoneChanged(timeZone: TimeZone) { timespec.formatter.timeKeeper.timeZone = timeZone refreshTime() } Loading
packages/SystemUI/customization/src/com/android/systemui/shared/clocks/TimespecHandler.kt +26 −14 Original line number Diff line number Diff line Loading @@ -43,9 +43,11 @@ open class TimeKeeperImpl(private val cal: Calendar = Calendar.getInstance()) : override var timeZone: TimeZone get() = cal.timeZone set(value) { if (cal.timeZone != value) { cal.timeZone = value callbacks.forEach { it.onTimeZoneChanged() } } } override val callbacks = mutableListOf<TimeKeeper.Callback>() Loading Loading @@ -82,35 +84,45 @@ private fun TimeFormatKind.getContentDescriptionPattern(pattern: String): String class DigitalTimeFormatter( val pattern: String, private val timeKeeper: TimeKeeper, private val enableContentDescription: Boolean = false, val timeKeeper: TimeKeeper, val enableContentDescription: Boolean = false, ) : TimeKeeper.Callback { var formatKind = TimeFormatKind.HALF_DAY set(value) { if (field != value) { field = value applyPattern() } } var locale = Locale.getDefault() set(value) { if (field != value) { field = value onLocaleChanged() } } private lateinit var textFormat: SimpleDateFormat private var contentDescriptionFormat: SimpleDateFormat? = null init { timeKeeper.callbacks.add(this) updateLocale(Locale.getDefault()) onLocaleChanged() } override fun onTimeZoneChanged() { textFormat.timeZone = TimeZone.getTimeZone(timeKeeper.timeZone.id) contentDescriptionFormat?.timeZone = TimeZone.getTimeZone(timeKeeper.timeZone.id) applyPattern() } fun updateLocale(locale: Locale) { fun onLocaleChanged() { textFormat = getTextFormat(locale) contentDescriptionFormat = getContentDescriptionFormat(locale) onTimeZoneChanged() } override fun onTimeZoneChanged() { textFormat.timeZone = timeKeeper.timeZone contentDescriptionFormat?.timeZone = timeKeeper.timeZone applyPattern() } private fun getTextFormat(locale: Locale): SimpleDateFormat { if (locale.language.equals(Locale.ENGLISH.language)) { // force date format in English, and time format to use format defined in json Loading