diff options
| author | 2025-01-29 17:17:32 +0000 | |
|---|---|---|
| committer | 2025-01-30 00:54:11 +0000 | |
| commit | 76d1c921d2837a5848ec90f659b199ead68276d6 (patch) | |
| tree | 3c5aa4547b4de08c9e99307bce24e1debb6ecd9d | |
| parent | 8f7be9ef332523bd133f2ea9fcb63bece8baf1df (diff) | |
Retarget DIGITAL_CLOCK_FLEX to new flex clock code
Bug: 364681643
Test: Checked legacy flex clock
Flag: com.android.systemui.shared.clock_reactive_variants
Change-Id: I26b2625ef528e59a8ae73da4203006ff9036d1c6
10 files changed, 89 insertions, 59 deletions
diff --git a/packages/SystemUI/customization/src/com/android/systemui/shared/clocks/ClockRegistry.kt b/packages/SystemUI/customization/src/com/android/systemui/shared/clocks/ClockRegistry.kt index 12b20a53df81..55654cd70bc3 100644 --- a/packages/SystemUI/customization/src/com/android/systemui/shared/clocks/ClockRegistry.kt +++ b/packages/SystemUI/customization/src/com/android/systemui/shared/clocks/ClockRegistry.kt @@ -145,7 +145,6 @@ open class ClockRegistry( var isCurrentClock = false var isClockListChanged = false for (metadata in knownClocks) { - isCurrentClock = isCurrentClock || currentClockId == metadata.clockId val id = metadata.clockId val info = availableClocks.concurrentGetOrPut(id, ClockInfo(metadata, null, manager)) { @@ -156,15 +155,17 @@ open class ClockRegistry( if (manager != info.manager) { logger.e({ "Clock Id conflict on attach: " + - "$str1 is double registered by $str2 and $str3" + "$str1 is double registered by $str2 and $str3. " + + "Using $str2 since it was attached first." }) { str1 = id - str2 = info.manager.toString() + str2 = info.manager?.toString() ?: info.provider?.toString() str3 = manager.toString() } continue } + isCurrentClock = isCurrentClock || currentClockId == metadata.clockId info.provider = null } @@ -197,10 +198,11 @@ open class ClockRegistry( if (manager != info.manager) { logger.e({ "Clock Id conflict on load: " + - "$str1 is double registered by $str2 and $str3" + "$str1 is double registered by $str2 and $str3. " + + "Using $str2 since it was attached first." }) { str1 = id - str2 = info.manager.toString() + str2 = info.manager?.toString() ?: info.provider?.toString() str3 = manager.toString() } manager.unloadPlugin() @@ -227,10 +229,11 @@ open class ClockRegistry( if (info?.manager != manager) { logger.e({ "Clock Id conflict on unload: " + - "$str1 is double registered by $str2 and $str3" + "$str1 is double registered by $str2 and $str3. " + + "Using $str2 since it was attached first." }) { str1 = id - str2 = info?.manager.toString() + str2 = info?.manager?.toString() ?: info?.provider?.toString() str3 = manager.toString() } continue diff --git a/packages/SystemUI/customization/src/com/android/systemui/shared/clocks/ComposedDigitalLayerController.kt b/packages/SystemUI/customization/src/com/android/systemui/shared/clocks/ComposedDigitalLayerController.kt index 9fb60c75b046..15e7718ad9f3 100644 --- a/packages/SystemUI/customization/src/com/android/systemui/shared/clocks/ComposedDigitalLayerController.kt +++ b/packages/SystemUI/customization/src/com/android/systemui/shared/clocks/ComposedDigitalLayerController.kt @@ -47,7 +47,7 @@ class ComposedDigitalLayerController(private val clockCtx: ClockContext) : init { fun createController(cfg: LayerConfig) { - val controller = SimpleDigitalHandLayerController(clockCtx, cfg) + val controller = SimpleDigitalHandLayerController(clockCtx, cfg, isLargeClock = true) view.addView(controller.view) layerControllers.add(controller) } diff --git a/packages/SystemUI/customization/src/com/android/systemui/shared/clocks/DefaultClockProvider.kt b/packages/SystemUI/customization/src/com/android/systemui/shared/clocks/DefaultClockProvider.kt index 6cc281ace481..af9f2ce9d73f 100644 --- a/packages/SystemUI/customization/src/com/android/systemui/shared/clocks/DefaultClockProvider.kt +++ b/packages/SystemUI/customization/src/com/android/systemui/shared/clocks/DefaultClockProvider.kt @@ -17,21 +17,21 @@ import android.content.Context import android.content.res.Resources import android.graphics.Typeface import android.view.LayoutInflater -import com.android.systemui.animation.GSFAxes import com.android.systemui.customization.R import com.android.systemui.log.core.MessageBuffer import com.android.systemui.plugins.clocks.ClockController -import com.android.systemui.plugins.clocks.ClockFontAxis -import com.android.systemui.plugins.clocks.ClockFontAxisSetting +import com.android.systemui.plugins.clocks.ClockFontAxis.Companion.merge import com.android.systemui.plugins.clocks.ClockLogger import com.android.systemui.plugins.clocks.ClockMessageBuffers import com.android.systemui.plugins.clocks.ClockMetadata import com.android.systemui.plugins.clocks.ClockPickerConfig import com.android.systemui.plugins.clocks.ClockProvider import com.android.systemui.plugins.clocks.ClockSettings +import com.android.systemui.shared.clocks.FlexClockController.Companion.getDefaultAxes private val TAG = DefaultClockProvider::class.simpleName const val DEFAULT_CLOCK_ID = "DEFAULT" +const val FLEX_CLOCK_ID = "DIGITAL_CLOCK_FLEX" data class ClockContext( val context: Context, @@ -55,16 +55,20 @@ class DefaultClockProvider( messageBuffers = buffers } - override fun getClocks(): List<ClockMetadata> = listOf(ClockMetadata(DEFAULT_CLOCK_ID)) + override fun getClocks(): List<ClockMetadata> { + var clocks = listOf(ClockMetadata(DEFAULT_CLOCK_ID)) + if (isClockReactiveVariantsEnabled) clocks += ClockMetadata(FLEX_CLOCK_ID) + return clocks + } override fun createClock(settings: ClockSettings): ClockController { - if (settings.clockId != DEFAULT_CLOCK_ID) { + if (getClocks().all { it.clockId != settings.clockId }) { throw IllegalArgumentException("${settings.clockId} is unsupported by $TAG") } return if (isClockReactiveVariantsEnabled) { val buffers = messageBuffers ?: ClockMessageBuffers(ClockLogger.DEFAULT_MESSAGE_BUFFER) - val fontAxes = ClockFontAxis.merge(FlexClockController.FONT_AXES, settings.axes) + val fontAxes = getDefaultAxes(settings).merge(settings.axes) val clockSettings = settings.copy(axes = fontAxes.map { it.toSetting() }) val typefaceCache = TypefaceCache(buffers.infraMessageBuffer, NUM_CLOCK_FONT_ANIMATION_STEPS) { @@ -86,15 +90,15 @@ class DefaultClockProvider( } override fun getClockPickerConfig(settings: ClockSettings): ClockPickerConfig { - if (settings.clockId != DEFAULT_CLOCK_ID) { + if (getClocks().all { it.clockId != settings.clockId }) { throw IllegalArgumentException("${settings.clockId} is unsupported by $TAG") } val fontAxes = if (!isClockReactiveVariantsEnabled) listOf() - else ClockFontAxis.merge(FlexClockController.FONT_AXES, settings.axes) + else getDefaultAxes(settings).merge(settings.axes) return ClockPickerConfig( - DEFAULT_CLOCK_ID, + settings.clockId ?: DEFAULT_CLOCK_ID, resources.getString(R.string.clock_default_name), resources.getString(R.string.clock_default_description), resources.getDrawable(R.drawable.clock_default_thumbnail, null), @@ -106,23 +110,6 @@ class DefaultClockProvider( companion object { const val NUM_CLOCK_FONT_ANIMATION_STEPS = 30 - // TODO(b/364681643): Variations for retargetted DIGITAL_CLOCK_FLEX - val LEGACY_FLEX_LS_VARIATION = - listOf( - ClockFontAxisSetting(GSFAxes.WEIGHT, 600f), - ClockFontAxisSetting(GSFAxes.WIDTH, 100f), - ClockFontAxisSetting(GSFAxes.ROUND, 100f), - ClockFontAxisSetting(GSFAxes.SLANT, 0f), - ) - - val LEGACY_FLEX_AOD_VARIATION = - listOf( - ClockFontAxisSetting(GSFAxes.WEIGHT, 74f), - ClockFontAxisSetting(GSFAxes.WIDTH, 43f), - ClockFontAxisSetting(GSFAxes.ROUND, 100f), - ClockFontAxisSetting(GSFAxes.SLANT, 0f), - ) - val FLEX_TYPEFACE by lazy { // TODO(b/364680873): Move constant to config_clockFontFamily when shipping Typeface.create("google-sans-flex-clock", Typeface.NORMAL) diff --git a/packages/SystemUI/customization/src/com/android/systemui/shared/clocks/FlexClockController.kt b/packages/SystemUI/customization/src/com/android/systemui/shared/clocks/FlexClockController.kt index 64deed46fe48..004d1aa1fe93 100644 --- a/packages/SystemUI/customization/src/com/android/systemui/shared/clocks/FlexClockController.kt +++ b/packages/SystemUI/customization/src/com/android/systemui/shared/clocks/FlexClockController.kt @@ -24,7 +24,9 @@ import com.android.systemui.plugins.clocks.ClockConfig import com.android.systemui.plugins.clocks.ClockController import com.android.systemui.plugins.clocks.ClockEvents import com.android.systemui.plugins.clocks.ClockFontAxis +import com.android.systemui.plugins.clocks.ClockFontAxis.Companion.merge import com.android.systemui.plugins.clocks.ClockFontAxisSetting +import com.android.systemui.plugins.clocks.ClockSettings import com.android.systemui.plugins.clocks.WeatherData import com.android.systemui.plugins.clocks.ZenData import com.android.systemui.shared.clocks.view.FlexClockView @@ -94,7 +96,7 @@ class FlexClockController(private val clockCtx: ClockContext) : ClockController } override fun onFontAxesChanged(axes: List<ClockFontAxisSetting>) { - val fontAxes = ClockFontAxis.merge(FONT_AXES, axes).map { it.toSetting() } + val fontAxes = getDefaultAxes(clockCtx.settings).merge(axes).map { it.toSetting() } smallClock.events.onFontAxesChanged(fontAxes) largeClock.events.onFontAxesChanged(fontAxes) } @@ -120,7 +122,13 @@ class FlexClockController(private val clockCtx: ClockContext) : ClockController override fun dump(pw: PrintWriter) {} companion object { - val FONT_AXES = + fun getDefaultAxes(settings: ClockSettings): List<ClockFontAxis> { + return if (settings.clockId == FLEX_CLOCK_ID) { + FONT_AXES.merge(LEGACY_FLEX_SETTINGS) + } else FONT_AXES + } + + private val FONT_AXES = listOf( ClockFontAxis( key = GSFAxes.WEIGHT, @@ -159,5 +167,13 @@ class FlexClockController(private val clockCtx: ClockContext) : ClockController description = "Glyph Slant", ), ) + + private val LEGACY_FLEX_SETTINGS = + listOf( + ClockFontAxisSetting(GSFAxes.WEIGHT, 600f), + ClockFontAxisSetting(GSFAxes.WIDTH, 100f), + ClockFontAxisSetting(GSFAxes.ROUND, 100f), + ClockFontAxisSetting(GSFAxes.SLANT, 0f), + ) } } diff --git a/packages/SystemUI/customization/src/com/android/systemui/shared/clocks/FlexClockFaceController.kt b/packages/SystemUI/customization/src/com/android/systemui/shared/clocks/FlexClockFaceController.kt index e2bbe0fef3c0..9a813def6f93 100644 --- a/packages/SystemUI/customization/src/com/android/systemui/shared/clocks/FlexClockFaceController.kt +++ b/packages/SystemUI/customization/src/com/android/systemui/shared/clocks/FlexClockFaceController.kt @@ -59,7 +59,7 @@ class FlexClockFaceController(clockCtx: ClockContext, private val isLargeClock: init { layerController = if (isLargeClock) ComposedDigitalLayerController(clockCtx) - else SimpleDigitalHandLayerController(clockCtx, SMALL_LAYER_CONFIG) + else SimpleDigitalHandLayerController(clockCtx, SMALL_LAYER_CONFIG, isLargeClock) layerController.view.layoutParams = FrameLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT).apply { gravity = Gravity.CENTER } diff --git a/packages/SystemUI/customization/src/com/android/systemui/shared/clocks/SimpleDigitalHandLayerController.kt b/packages/SystemUI/customization/src/com/android/systemui/shared/clocks/SimpleDigitalHandLayerController.kt index 82fc35012dbc..93a8badc9ebf 100644 --- a/packages/SystemUI/customization/src/com/android/systemui/shared/clocks/SimpleDigitalHandLayerController.kt +++ b/packages/SystemUI/customization/src/com/android/systemui/shared/clocks/SimpleDigitalHandLayerController.kt @@ -78,8 +78,9 @@ enum class DigitalTimespec { open class SimpleDigitalHandLayerController( private val clockCtx: ClockContext, private val layerCfg: LayerConfig, + isLargeClock: Boolean, ) : SimpleClockLayerController { - override val view = SimpleDigitalClockTextView(clockCtx) + override val view = SimpleDigitalClockTextView(clockCtx, isLargeClock) private val logger = Logger(clockCtx.messageBuffer, TAG) val timespec = DigitalTimespecHandler(layerCfg.timespec, layerCfg.dateTimeFormat) diff --git a/packages/SystemUI/customization/src/com/android/systemui/shared/clocks/view/SimpleDigitalClockTextView.kt b/packages/SystemUI/customization/src/com/android/systemui/shared/clocks/view/SimpleDigitalClockTextView.kt index fbfda72896c2..41cc11629f31 100644 --- a/packages/SystemUI/customization/src/com/android/systemui/shared/clocks/view/SimpleDigitalClockTextView.kt +++ b/packages/SystemUI/customization/src/com/android/systemui/shared/clocks/view/SimpleDigitalClockTextView.kt @@ -38,10 +38,13 @@ import com.android.systemui.animation.GSFAxes import com.android.systemui.animation.TextAnimator import com.android.systemui.customization.R import com.android.systemui.plugins.clocks.ClockFontAxisSetting +import com.android.systemui.plugins.clocks.ClockFontAxisSetting.Companion.replace +import com.android.systemui.plugins.clocks.ClockFontAxisSetting.Companion.toFVar import com.android.systemui.plugins.clocks.ClockLogger import com.android.systemui.shared.clocks.ClockContext import com.android.systemui.shared.clocks.DigitTranslateAnimator import com.android.systemui.shared.clocks.DimensionParser +import com.android.systemui.shared.clocks.FLEX_CLOCK_ID import com.android.systemui.shared.clocks.FontTextStyle import java.lang.Thread import kotlin.math.max @@ -63,14 +66,32 @@ enum class HorizontalAlignment { } @SuppressLint("AppCompatCustomView") -open class SimpleDigitalClockTextView(clockCtx: ClockContext, attrs: AttributeSet? = null) : - TextView(clockCtx.context, attrs) { +open class SimpleDigitalClockTextView( + clockCtx: ClockContext, + isLargeClock: Boolean, + attrs: AttributeSet? = null, +) : TextView(clockCtx.context, attrs) { val lockScreenPaint = TextPaint() lateinit var textStyle: FontTextStyle lateinit var aodStyle: FontTextStyle - private var lsFontVariation = ClockFontAxisSetting.toFVar(DEFAULT_LS_AXES) - private var aodFontVariation = ClockFontAxisSetting.toFVar(DEFAULT_AOD_AXES) + private val isLegacyFlex = clockCtx.settings.clockId == FLEX_CLOCK_ID + private val fixedAodAxes = + when { + !isLegacyFlex -> listOf(AOD_WEIGHT_AXIS, WIDTH_AXIS) + isLargeClock -> listOf(FLEX_AOD_LARGE_WEIGHT_AXIS, FLEX_AOD_WIDTH_AXIS) + else -> listOf(FLEX_AOD_SMALL_WEIGHT_AXIS, FLEX_AOD_WIDTH_AXIS) + } + + private var lsFontVariation = + if (!isLegacyFlex) listOf(LS_WEIGHT_AXIS, WIDTH_AXIS, ROUND_AXIS, SLANT_AXIS).toFVar() + else listOf(FLEX_LS_WEIGHT_AXIS, FLEX_LS_WIDTH_AXIS, FLEX_ROUND_AXIS, SLANT_AXIS).toFVar() + + private var aodFontVariation = run { + val roundAxis = if (!isLegacyFlex) ROUND_AXIS else FLEX_ROUND_AXIS + (fixedAodAxes + listOf(roundAxis, SLANT_AXIS)).toFVar() + } + private val parser = DimensionParser(clockCtx.context) var maxSingleDigitHeight = -1 var maxSingleDigitWidth = -1 @@ -130,9 +151,8 @@ open class SimpleDigitalClockTextView(clockCtx: ClockContext, attrs: AttributeSe } fun updateAxes(lsAxes: List<ClockFontAxisSetting>) { - val aodAxes = ClockFontAxisSetting.replace(lsAxes, AOD_FIXED_AXES) - lsFontVariation = ClockFontAxisSetting.toFVar(lsAxes) - aodFontVariation = ClockFontAxisSetting.toFVar(aodAxes) + lsFontVariation = lsAxes.toFVar() + aodFontVariation = lsAxes.replace(fixedAodAxes).toFVar() logger.i({ "updateAxes(LS = $str1, AOD = $str2)" }) { str1 = lsFontVariation str2 = aodFontVariation @@ -514,8 +534,12 @@ open class SimpleDigitalClockTextView(clockCtx: ClockContext, attrs: AttributeSe val ROUND_AXIS = ClockFontAxisSetting(GSFAxes.ROUND, 0f) val SLANT_AXIS = ClockFontAxisSetting(GSFAxes.SLANT, 0f) - val DEFAULT_LS_AXES = listOf(LS_WEIGHT_AXIS, WIDTH_AXIS, ROUND_AXIS, SLANT_AXIS) - val AOD_FIXED_AXES = listOf(AOD_WEIGHT_AXIS, WIDTH_AXIS) - val DEFAULT_AOD_AXES = AOD_FIXED_AXES + listOf(ROUND_AXIS, SLANT_AXIS) + // Axes for Legacy version of the Flex Clock + val FLEX_LS_WEIGHT_AXIS = ClockFontAxisSetting(GSFAxes.WEIGHT, 600f) + val FLEX_AOD_LARGE_WEIGHT_AXIS = ClockFontAxisSetting(GSFAxes.WEIGHT, 74f) + val FLEX_AOD_SMALL_WEIGHT_AXIS = ClockFontAxisSetting(GSFAxes.WEIGHT, 133f) + val FLEX_LS_WIDTH_AXIS = ClockFontAxisSetting(GSFAxes.WIDTH, 100f) + val FLEX_AOD_WIDTH_AXIS = ClockFontAxisSetting(GSFAxes.WIDTH, 43f) + val FLEX_ROUND_AXIS = ClockFontAxisSetting(GSFAxes.ROUND, 100f) } } diff --git a/packages/SystemUI/plugin/src/com/android/systemui/plugins/clocks/ClockPickerConfig.kt b/packages/SystemUI/plugin/src/com/android/systemui/plugins/clocks/ClockPickerConfig.kt index 1bc9367ce3c5..6e4dc1485c7b 100644 --- a/packages/SystemUI/plugin/src/com/android/systemui/plugins/clocks/ClockPickerConfig.kt +++ b/packages/SystemUI/plugin/src/com/android/systemui/plugins/clocks/ClockPickerConfig.kt @@ -62,12 +62,11 @@ data class ClockFontAxis( fun toSetting() = ClockFontAxisSetting(key, currentValue) companion object { - fun merge( - fontAxes: List<ClockFontAxis>, - axisSettings: List<ClockFontAxisSetting>, + fun List<ClockFontAxis>.merge( + axisSettings: List<ClockFontAxisSetting> ): List<ClockFontAxis> { val result = mutableListOf<ClockFontAxis>() - for (axis in fontAxes) { + for (axis in this) { val setting = axisSettings.firstOrNull { axis.key == it.key } val output = setting?.let { axis.copy(currentValue = it.value) } ?: axis result.add(output) diff --git a/packages/SystemUI/plugin/src/com/android/systemui/plugins/clocks/ClockSettings.kt b/packages/SystemUI/plugin/src/com/android/systemui/plugins/clocks/ClockSettings.kt index 970af71b9f9d..e7b36626a810 100644 --- a/packages/SystemUI/plugin/src/com/android/systemui/plugins/clocks/ClockSettings.kt +++ b/packages/SystemUI/plugin/src/com/android/systemui/plugins/clocks/ClockSettings.kt @@ -98,20 +98,19 @@ data class ClockFontAxisSetting( return result } - fun toFVar(settings: List<ClockFontAxisSetting>): String { + fun List<ClockFontAxisSetting>.toFVar(): String { val sb = StringBuilder() - for (axis in settings) { + for (axis in this) { if (sb.length > 0) sb.append(", ") sb.append("'${axis.key}' ${axis.value.toInt()}") } return sb.toString() } - fun replace( - list: List<ClockFontAxisSetting>, - replacements: List<ClockFontAxisSetting>, + fun List<ClockFontAxisSetting>.replace( + replacements: List<ClockFontAxisSetting> ): List<ClockFontAxisSetting> { - var remaining = list.filterNot { lhs -> replacements.any { rhs -> lhs.key == rhs.key } } + var remaining = this.filterNot { lhs -> replacements.any { rhs -> lhs.key == rhs.key } } return remaining + replacements } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/shared/clocks/view/SimpleDigitalClockTextViewTest.kt b/packages/SystemUI/tests/src/com/android/systemui/shared/clocks/view/SimpleDigitalClockTextViewTest.kt index 57c28580c063..b75dd0402175 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/shared/clocks/view/SimpleDigitalClockTextViewTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/shared/clocks/view/SimpleDigitalClockTextViewTest.kt @@ -58,7 +58,8 @@ class SimpleDigitalClockTextViewTest : SysuiTestCase() { }, ClockMessageBuffers(messageBuffer), messageBuffer, - ) + ), + isLargeClock = false, ) underTest.textStyle = FontTextStyle() underTest.aodStyle = FontTextStyle() |