1 /* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.systemui.shared.clocks 18 19 import com.android.systemui.customization.R 20 import com.android.systemui.plugins.clocks.AlarmData 21 import com.android.systemui.plugins.clocks.AxisType 22 import com.android.systemui.plugins.clocks.ClockConfig 23 import com.android.systemui.plugins.clocks.ClockController 24 import com.android.systemui.plugins.clocks.ClockEvents 25 import com.android.systemui.plugins.clocks.ClockFontAxis 26 import com.android.systemui.plugins.clocks.ClockFontAxisSetting 27 import com.android.systemui.plugins.clocks.WeatherData 28 import com.android.systemui.plugins.clocks.ZenData 29 import com.android.systemui.shared.clocks.view.FlexClockView 30 import java.io.PrintWriter 31 import java.util.Locale 32 import java.util.TimeZone 33 34 /** Controller for the default flex clock */ 35 class FlexClockController( 36 private val clockCtx: ClockContext, 37 val design: ClockDesign, // TODO(b/364680879): Remove when done inlining 38 ) : ClockController { 39 override val smallClock = 40 FlexClockFaceController( 41 clockCtx.copy(messageBuffer = clockCtx.messageBuffers.smallClockMessageBuffer), 42 design.small ?: design.large!!, 43 isLargeClock = false, 44 ) 45 46 override val largeClock = 47 FlexClockFaceController( 48 clockCtx.copy(messageBuffer = clockCtx.messageBuffers.largeClockMessageBuffer), 49 design.large ?: design.small!!, 50 isLargeClock = true, 51 ) 52 <lambda>null53 override val config: ClockConfig by lazy { 54 ClockConfig( 55 DEFAULT_CLOCK_ID, 56 clockCtx.resources.getString(R.string.clock_default_name), 57 clockCtx.resources.getString(R.string.clock_default_description), 58 isReactiveToTone = true, 59 ) 60 } 61 62 override val events = 63 object : ClockEvents { 64 override var isReactiveTouchInteractionEnabled = false 65 set(value) { 66 field = value 67 val view = largeClock.view as FlexClockView 68 view.isReactiveTouchInteractionEnabled = value 69 } 70 onTimeZoneChangednull71 override fun onTimeZoneChanged(timeZone: TimeZone) { 72 smallClock.events.onTimeZoneChanged(timeZone) 73 largeClock.events.onTimeZoneChanged(timeZone) 74 } 75 onTimeFormatChangednull76 override fun onTimeFormatChanged(is24Hr: Boolean) { 77 smallClock.events.onTimeFormatChanged(is24Hr) 78 largeClock.events.onTimeFormatChanged(is24Hr) 79 } 80 onLocaleChangednull81 override fun onLocaleChanged(locale: Locale) { 82 smallClock.events.onLocaleChanged(locale) 83 largeClock.events.onLocaleChanged(locale) 84 } 85 onWeatherDataChangednull86 override fun onWeatherDataChanged(data: WeatherData) { 87 smallClock.events.onWeatherDataChanged(data) 88 largeClock.events.onWeatherDataChanged(data) 89 } 90 onAlarmDataChangednull91 override fun onAlarmDataChanged(data: AlarmData) { 92 smallClock.events.onAlarmDataChanged(data) 93 largeClock.events.onAlarmDataChanged(data) 94 } 95 onZenDataChangednull96 override fun onZenDataChanged(data: ZenData) { 97 smallClock.events.onZenDataChanged(data) 98 largeClock.events.onZenDataChanged(data) 99 } 100 onFontAxesChangednull101 override fun onFontAxesChanged(axes: List<ClockFontAxisSetting>) { 102 val fontAxes = ClockFontAxis.merge(FONT_AXES, axes).map { it.toSetting() } 103 smallClock.events.onFontAxesChanged(fontAxes) 104 largeClock.events.onFontAxesChanged(fontAxes) 105 } 106 } 107 initializenull108 override fun initialize(isDarkTheme: Boolean, dozeFraction: Float, foldFraction: Float) { 109 events.onFontAxesChanged(clockCtx.settings.axes) 110 smallClock.run { 111 events.onThemeChanged(theme.copy(isDarkTheme = isDarkTheme)) 112 animations.doze(dozeFraction) 113 animations.fold(foldFraction) 114 events.onTimeTick() 115 } 116 117 largeClock.run { 118 events.onThemeChanged(theme.copy(isDarkTheme = isDarkTheme)) 119 animations.doze(dozeFraction) 120 animations.fold(foldFraction) 121 events.onTimeTick() 122 } 123 } 124 dumpnull125 override fun dump(pw: PrintWriter) {} 126 127 companion object { 128 val FONT_AXES = 129 listOf( 130 ClockFontAxis( 131 key = "wght", 132 type = AxisType.Float, 133 minValue = 1f, 134 currentValue = 400f, 135 maxValue = 1000f, 136 name = "Weight", 137 description = "Glyph Weight", 138 ), 139 ClockFontAxis( 140 key = "wdth", 141 type = AxisType.Float, 142 minValue = 25f, 143 currentValue = 100f, 144 maxValue = 151f, 145 name = "Width", 146 description = "Glyph Width", 147 ), 148 ClockFontAxis( 149 key = "ROND", 150 type = AxisType.Boolean, 151 minValue = 0f, 152 currentValue = 0f, 153 maxValue = 100f, 154 name = "Round", 155 description = "Glyph Roundness", 156 ), 157 ClockFontAxis( 158 key = "slnt", 159 type = AxisType.Boolean, 160 minValue = 0f, 161 currentValue = 0f, 162 maxValue = -10f, 163 name = "Slant", 164 description = "Glyph Slant", 165 ), 166 ) 167 } 168 } 169