diff options
author | 2025-03-04 04:43:01 +0000 | |
---|---|---|
committer | 2025-03-10 20:59:58 +0000 | |
commit | db1986c2c2225e3ce2a45084cf9ea90c5db256ea (patch) | |
tree | e3460f461a901ee24efb5dbe549e897db64047c1 | |
parent | 31d719591af4a33bdc2bed2a185922b3b8ce0ddc (diff) |
Updates for dual axis presets
Bug: 395647577
Test: Manually checked clocks still worked
Flag: com.android.systemui.shared.clock_reactive_variants
Change-Id: Ief7ef5856417f85dd93ce1e422d4bf0753dffe17
13 files changed, 299 insertions, 215 deletions
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 37acbe261f76..5f71b19fbc3f 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 @@ -22,10 +22,10 @@ import com.android.app.animation.Interpolators import com.android.systemui.log.core.Logger import com.android.systemui.plugins.clocks.AlarmData import com.android.systemui.plugins.clocks.ClockAnimations +import com.android.systemui.plugins.clocks.ClockAxisStyle import com.android.systemui.plugins.clocks.ClockEvents import com.android.systemui.plugins.clocks.ClockFaceConfig import com.android.systemui.plugins.clocks.ClockFaceEvents -import com.android.systemui.plugins.clocks.ClockFontAxisSetting import com.android.systemui.plugins.clocks.ThemeConfig import com.android.systemui.plugins.clocks.WeatherData import com.android.systemui.plugins.clocks.ZenData @@ -111,7 +111,7 @@ class ComposedDigitalLayerController(private val clockCtx: ClockContext) : override fun onZenDataChanged(data: ZenData) {} - override fun onFontAxesChanged(axes: List<ClockFontAxisSetting>) { + override fun onFontAxesChanged(axes: ClockAxisStyle) { view.updateAxes(axes) } diff --git a/packages/SystemUI/customization/src/com/android/systemui/shared/clocks/DefaultClockController.kt b/packages/SystemUI/customization/src/com/android/systemui/shared/clocks/DefaultClockController.kt index bc4bdf4243cb..3cfa78d17fe7 100644 --- a/packages/SystemUI/customization/src/com/android/systemui/shared/clocks/DefaultClockController.kt +++ b/packages/SystemUI/customization/src/com/android/systemui/shared/clocks/DefaultClockController.kt @@ -26,6 +26,7 @@ import com.android.systemui.customization.R import com.android.systemui.log.core.MessageBuffer import com.android.systemui.plugins.clocks.AlarmData import com.android.systemui.plugins.clocks.ClockAnimations +import com.android.systemui.plugins.clocks.ClockAxisStyle import com.android.systemui.plugins.clocks.ClockConfig import com.android.systemui.plugins.clocks.ClockController import com.android.systemui.plugins.clocks.ClockEventListener @@ -33,7 +34,6 @@ import com.android.systemui.plugins.clocks.ClockEvents import com.android.systemui.plugins.clocks.ClockFaceConfig import com.android.systemui.plugins.clocks.ClockFaceController import com.android.systemui.plugins.clocks.ClockFaceEvents -import com.android.systemui.plugins.clocks.ClockFontAxisSetting import com.android.systemui.plugins.clocks.ClockMessageBuffers import com.android.systemui.plugins.clocks.ClockSettings import com.android.systemui.plugins.clocks.DefaultClockFaceLayout @@ -232,7 +232,7 @@ class DefaultClockController( override fun onZenDataChanged(data: ZenData) {} - override fun onFontAxesChanged(axes: List<ClockFontAxisSetting>) {} + override fun onFontAxesChanged(axes: ClockAxisStyle) {} } open inner class DefaultClockAnimations( 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 c3935e68ca04..d778bc04ab8e 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 @@ -20,6 +20,8 @@ import android.os.Vibrator import android.view.LayoutInflater import com.android.systemui.customization.R import com.android.systemui.log.core.MessageBuffer +import com.android.systemui.plugins.clocks.AxisPresetConfig +import com.android.systemui.plugins.clocks.ClockAxisStyle import com.android.systemui.plugins.clocks.ClockController import com.android.systemui.plugins.clocks.ClockFontAxis.Companion.merge import com.android.systemui.plugins.clocks.ClockLogger @@ -28,7 +30,7 @@ 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.AXIS_PRESETS +import com.android.systemui.shared.clocks.FlexClockController.Companion.buildPresetGroup import com.android.systemui.shared.clocks.FlexClockController.Companion.getDefaultAxes private val TAG = DefaultClockProvider::class.simpleName @@ -80,7 +82,7 @@ class DefaultClockProvider( return if (isClockReactiveVariantsEnabled) { val buffers = messageBuffers ?: ClockMessageBuffers(ClockLogger.DEFAULT_MESSAGE_BUFFER) val fontAxes = getDefaultAxes(settings).merge(settings.axes) - val clockSettings = settings.copy(axes = fontAxes.map { it.toSetting() }) + val clockSettings = settings.copy(axes = ClockAxisStyle(fontAxes)) val typefaceCache = TypefaceCache(buffers.infraMessageBuffer, NUM_CLOCK_FONT_ANIMATION_STEPS) { FLEX_TYPEFACE @@ -106,17 +108,35 @@ class DefaultClockProvider( throw IllegalArgumentException("${settings.clockId} is unsupported by $TAG") } - return ClockPickerConfig( - 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), - isReactiveToTone = true, - axes = - if (!isClockReactiveVariantsEnabled) emptyList() - else getDefaultAxes(settings).merge(settings.axes), - axisPresets = if (!isClockReactiveVariantsEnabled) emptyList() else AXIS_PRESETS, - ) + if (!isClockReactiveVariantsEnabled) { + return ClockPickerConfig( + 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), + isReactiveToTone = true, + axes = emptyList(), + presetConfig = null, + ) + } else { + val fontAxes = getDefaultAxes(settings).merge(settings.axes) + return ClockPickerConfig( + 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), + isReactiveToTone = true, + axes = fontAxes, + presetConfig = + AxisPresetConfig( + listOf( + buildPresetGroup(resources, isRound = true), + buildPresetGroup(resources, isRound = false), + ) + ) + .let { cfg -> cfg.copy(current = cfg.findStyle(ClockAxisStyle(fontAxes))) }, + ) + } } companion object { 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 5acd4468fe92..96c3ac75587e 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 @@ -16,20 +16,24 @@ package com.android.systemui.shared.clocks +import android.content.res.Resources import com.android.systemui.animation.GSFAxes import com.android.systemui.customization.R import com.android.systemui.plugins.clocks.AlarmData +import com.android.systemui.plugins.clocks.AxisPresetConfig import com.android.systemui.plugins.clocks.AxisType +import com.android.systemui.plugins.clocks.ClockAxisStyle import com.android.systemui.plugins.clocks.ClockConfig import com.android.systemui.plugins.clocks.ClockController import com.android.systemui.plugins.clocks.ClockEventListener 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.FontUtils.put +import com.android.systemui.shared.clocks.FontUtils.toClockAxis import com.android.systemui.shared.clocks.view.FlexClockView import java.io.PrintWriter import java.util.Locale @@ -96,8 +100,8 @@ class FlexClockController(private val clockCtx: ClockContext) : ClockController largeClock.events.onZenDataChanged(data) } - override fun onFontAxesChanged(axes: List<ClockFontAxisSetting>) { - val fontAxes = getDefaultAxes(clockCtx.settings).merge(axes).map { it.toSetting() } + override fun onFontAxesChanged(axes: ClockAxisStyle) { + val fontAxes = ClockAxisStyle(getDefaultAxes(clockCtx.settings).merge(axes)) smallClock.events.onFontAxesChanged(fontAxes) largeClock.events.onFontAxesChanged(fontAxes) } @@ -162,66 +166,46 @@ class FlexClockController(private val clockCtx: ClockContext) : ClockController ), ) - private val LEGACY_FLEX_SETTINGS = - listOf( - GSFAxes.WEIGHT.toClockAxisSetting(600f), - GSFAxes.WIDTH.toClockAxisSetting(100f), - GSFAxes.ROUND.toClockAxisSetting(100f), - GSFAxes.SLANT.toClockAxisSetting(0f), - ) + private val LEGACY_FLEX_SETTINGS = ClockAxisStyle { + put(GSFAxes.WEIGHT, 600f) + put(GSFAxes.WIDTH, 100f) + put(GSFAxes.ROUND, 100f) + put(GSFAxes.SLANT, 0f) + } - val AXIS_PRESETS = - listOf( - FONT_AXES.map { it.toSetting() }, - LEGACY_FLEX_SETTINGS, - listOf( // Porcelain - GSFAxes.WEIGHT.toClockAxisSetting(500f), - GSFAxes.WIDTH.toClockAxisSetting(100f), - GSFAxes.ROUND.toClockAxisSetting(0f), - GSFAxes.SLANT.toClockAxisSetting(0f), - ), - listOf( // Midnight - GSFAxes.WEIGHT.toClockAxisSetting(300f), - GSFAxes.WIDTH.toClockAxisSetting(100f), - GSFAxes.ROUND.toClockAxisSetting(100f), - GSFAxes.SLANT.toClockAxisSetting(-10f), - ), - listOf( // Sterling - GSFAxes.WEIGHT.toClockAxisSetting(1000f), - GSFAxes.WIDTH.toClockAxisSetting(100f), - GSFAxes.ROUND.toClockAxisSetting(0f), - GSFAxes.SLANT.toClockAxisSetting(0f), - ), - listOf( // Smoky Green - GSFAxes.WEIGHT.toClockAxisSetting(150f), - GSFAxes.WIDTH.toClockAxisSetting(50f), - GSFAxes.ROUND.toClockAxisSetting(0f), - GSFAxes.SLANT.toClockAxisSetting(0f), - ), - listOf( // Iris - GSFAxes.WEIGHT.toClockAxisSetting(500f), - GSFAxes.WIDTH.toClockAxisSetting(100f), - GSFAxes.ROUND.toClockAxisSetting(100f), - GSFAxes.SLANT.toClockAxisSetting(0f), - ), - listOf( // Margarita - GSFAxes.WEIGHT.toClockAxisSetting(300f), - GSFAxes.WIDTH.toClockAxisSetting(30f), - GSFAxes.ROUND.toClockAxisSetting(100f), - GSFAxes.SLANT.toClockAxisSetting(-10f), - ), - listOf( // Raspberry - GSFAxes.WEIGHT.toClockAxisSetting(700f), - GSFAxes.WIDTH.toClockAxisSetting(140f), - GSFAxes.ROUND.toClockAxisSetting(100f), - GSFAxes.SLANT.toClockAxisSetting(-7f), - ), - listOf( // Ultra Blue - GSFAxes.WEIGHT.toClockAxisSetting(850f), - GSFAxes.WIDTH.toClockAxisSetting(130f), - GSFAxes.ROUND.toClockAxisSetting(0f), - GSFAxes.SLANT.toClockAxisSetting(0f), - ), + private val PRESET_COUNT = 8 + private val PRESET_WIDTH_INIT = 30f + private val PRESET_WIDTH_STEP = 12.5f + private val PRESET_WEIGHT_INIT = 800f + private val PRESET_WEIGHT_STEP = -100f + private val BASE_PRESETS: List<ClockAxisStyle> = run { + val presets = mutableListOf<ClockAxisStyle>() + var weight = PRESET_WEIGHT_INIT + var width = PRESET_WIDTH_INIT + for (i in 1..PRESET_COUNT) { + presets.add( + ClockAxisStyle { + put(GSFAxes.WEIGHT, weight) + put(GSFAxes.WIDTH, width) + put(GSFAxes.ROUND, 0f) + put(GSFAxes.SLANT, 0f) + } + ) + + weight += PRESET_WEIGHT_STEP + width += PRESET_WIDTH_STEP + } + + return@run presets + } + + fun buildPresetGroup(resources: Resources, isRound: Boolean): AxisPresetConfig.Group { + val round = if (isRound) GSFAxes.ROUND.maxValue else GSFAxes.ROUND.minValue + return AxisPresetConfig.Group( + presets = BASE_PRESETS.map { it.copy { put(GSFAxes.ROUND, round) } }, + // TODO(b/395647577): Placeholder Icon; Replace or remove + icon = resources.getDrawable(R.drawable.clock_default_thumbnail, null), ) + } } } 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 578a489c68c6..171a68f72e20 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 @@ -25,16 +25,18 @@ import com.android.systemui.animation.GSFAxes import com.android.systemui.customization.R import com.android.systemui.plugins.clocks.AlarmData import com.android.systemui.plugins.clocks.ClockAnimations +import com.android.systemui.plugins.clocks.ClockAxisStyle import com.android.systemui.plugins.clocks.ClockEvents import com.android.systemui.plugins.clocks.ClockFaceConfig import com.android.systemui.plugins.clocks.ClockFaceController import com.android.systemui.plugins.clocks.ClockFaceEvents import com.android.systemui.plugins.clocks.ClockFaceLayout -import com.android.systemui.plugins.clocks.ClockFontAxisSetting import com.android.systemui.plugins.clocks.DefaultClockFaceLayout import com.android.systemui.plugins.clocks.ThemeConfig import com.android.systemui.plugins.clocks.WeatherData import com.android.systemui.plugins.clocks.ZenData +import com.android.systemui.shared.clocks.FontUtils.get +import com.android.systemui.shared.clocks.FontUtils.set import com.android.systemui.shared.clocks.ViewUtils.computeLayoutDiff import com.android.systemui.shared.clocks.view.FlexClockView import com.android.systemui.shared.clocks.view.HorizontalAlignment @@ -129,17 +131,10 @@ class FlexClockFaceController(clockCtx: ClockContext, private val isLargeClock: layerController.faceEvents.onThemeChanged(theme) } - override fun onFontAxesChanged(settings: List<ClockFontAxisSetting>) { - var axes = settings - if (!isLargeClock) { - axes = - axes.map { axis -> - if (axis.key == GSFAxes.WIDTH.tag && axis.value > SMALL_CLOCK_MAX_WDTH) { - axis.copy(value = SMALL_CLOCK_MAX_WDTH) - } else { - axis - } - } + override fun onFontAxesChanged(settings: ClockAxisStyle) { + var axes = ClockAxisStyle(settings) + if (!isLargeClock && axes[GSFAxes.WIDTH] > SMALL_CLOCK_MAX_WDTH) { + axes[GSFAxes.WIDTH] = SMALL_CLOCK_MAX_WDTH } layerController.events.onFontAxesChanged(axes) diff --git a/packages/SystemUI/customization/src/com/android/systemui/shared/clocks/FontUtils.kt b/packages/SystemUI/customization/src/com/android/systemui/shared/clocks/FontUtils.kt index 212b1e29d1b8..722d76beedbb 100644 --- a/packages/SystemUI/customization/src/com/android/systemui/shared/clocks/FontUtils.kt +++ b/packages/SystemUI/customization/src/com/android/systemui/shared/clocks/FontUtils.kt @@ -18,26 +18,36 @@ package com.android.systemui.shared.clocks import com.android.systemui.animation.AxisDefinition import com.android.systemui.plugins.clocks.AxisType +import com.android.systemui.plugins.clocks.ClockAxisStyle import com.android.systemui.plugins.clocks.ClockFontAxis -import com.android.systemui.plugins.clocks.ClockFontAxisSetting -fun AxisDefinition.toClockAxis( - type: AxisType, - currentValue: Float? = null, - name: String, - description: String, -): ClockFontAxis { - return ClockFontAxis( - key = this.tag, - type = type, - maxValue = this.maxValue, - minValue = this.minValue, - currentValue = currentValue ?: this.defaultValue, - name = name, - description = description, - ) -} +object FontUtils { + fun AxisDefinition.toClockAxis( + type: AxisType, + currentValue: Float? = null, + name: String, + description: String, + ): ClockFontAxis { + return ClockFontAxis( + key = this.tag, + type = type, + maxValue = this.maxValue, + minValue = this.minValue, + currentValue = currentValue ?: this.defaultValue, + name = name, + description = description, + ) + } + + fun ClockAxisStyle.put(def: AxisDefinition, value: Float? = null) { + this.put(def.tag, value ?: def.defaultValue) + } + + operator fun ClockAxisStyle.set(def: AxisDefinition, value: Float) { + this[def.tag] = value + } -fun AxisDefinition.toClockAxisSetting(value: Float? = null): ClockFontAxisSetting { - return ClockFontAxisSetting(this.tag, value ?: this.defaultValue) + operator fun ClockAxisStyle.get(def: AxisDefinition): Float { + return this[def.tag] ?: def.defaultValue + } } 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 1d963af3ad22..7be9a936cbd3 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 @@ -26,10 +26,10 @@ import com.android.systemui.customization.R import com.android.systemui.log.core.Logger import com.android.systemui.plugins.clocks.AlarmData import com.android.systemui.plugins.clocks.ClockAnimations +import com.android.systemui.plugins.clocks.ClockAxisStyle import com.android.systemui.plugins.clocks.ClockEvents import com.android.systemui.plugins.clocks.ClockFaceConfig import com.android.systemui.plugins.clocks.ClockFaceEvents -import com.android.systemui.plugins.clocks.ClockFontAxisSetting import com.android.systemui.plugins.clocks.ThemeConfig import com.android.systemui.plugins.clocks.WeatherData import com.android.systemui.plugins.clocks.ZenData @@ -172,7 +172,7 @@ open class SimpleDigitalHandLayerController( override fun onZenDataChanged(data: ZenData) {} - override fun onFontAxesChanged(axes: List<ClockFontAxisSetting>) { + override fun onFontAxesChanged(axes: ClockAxisStyle) { view.updateAxes(axes) } } diff --git a/packages/SystemUI/customization/src/com/android/systemui/shared/clocks/view/FlexClockView.kt b/packages/SystemUI/customization/src/com/android/systemui/shared/clocks/view/FlexClockView.kt index ba32ab083063..4531aed0e83d 100644 --- a/packages/SystemUI/customization/src/com/android/systemui/shared/clocks/view/FlexClockView.kt +++ b/packages/SystemUI/customization/src/com/android/systemui/shared/clocks/view/FlexClockView.kt @@ -26,7 +26,7 @@ import androidx.annotation.VisibleForTesting import androidx.core.view.children import com.android.app.animation.Interpolators import com.android.systemui.customization.R -import com.android.systemui.plugins.clocks.ClockFontAxisSetting +import com.android.systemui.plugins.clocks.ClockAxisStyle import com.android.systemui.plugins.clocks.ClockLogger import com.android.systemui.plugins.clocks.VPoint import com.android.systemui.plugins.clocks.VPointF @@ -272,7 +272,7 @@ class FlexClockView(clockCtx: ClockContext) : ViewGroup(clockCtx.context) { invalidate() } - fun updateAxes(axes: List<ClockFontAxisSetting>) { + fun updateAxes(axes: ClockAxisStyle) { childViews.forEach { view -> view.updateAxes(axes) } requestLayout() } 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 2af25fe339a2..470ec8b957e5 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 @@ -37,12 +37,11 @@ import android.view.animation.PathInterpolator import android.widget.TextView import com.android.app.animation.Interpolators import com.android.internal.annotations.VisibleForTesting +import com.android.systemui.animation.AxisDefinition 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.ClockAxisStyle import com.android.systemui.plugins.clocks.ClockLogger import com.android.systemui.plugins.clocks.VPoint import com.android.systemui.plugins.clocks.VPointF @@ -56,9 +55,9 @@ 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 com.android.systemui.shared.clocks.FontUtils.set import com.android.systemui.shared.clocks.ViewUtils.measuredSize import com.android.systemui.shared.clocks.ViewUtils.size -import com.android.systemui.shared.clocks.toClockAxisSetting import java.lang.Thread import kotlin.math.max import kotlin.math.min @@ -123,9 +122,9 @@ open class SimpleDigitalClockTextView( 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) + !isLegacyFlex -> fromAxes(AOD_WEIGHT_AXIS, WIDTH_AXIS) + isLargeClock -> fromAxes(FLEX_AOD_LARGE_WEIGHT_AXIS, FLEX_AOD_WIDTH_AXIS) + else -> fromAxes(FLEX_AOD_SMALL_WEIGHT_AXIS, FLEX_AOD_WIDTH_AXIS) } private var lsFontVariation: String @@ -135,11 +134,11 @@ open class SimpleDigitalClockTextView( init { val roundAxis = if (!isLegacyFlex) ROUND_AXIS else FLEX_ROUND_AXIS val lsFontAxes = - if (!isLegacyFlex) listOf(LS_WEIGHT_AXIS, WIDTH_AXIS, ROUND_AXIS, SLANT_AXIS) - else listOf(FLEX_LS_WEIGHT_AXIS, FLEX_LS_WIDTH_AXIS, FLEX_ROUND_AXIS, SLANT_AXIS) + if (!isLegacyFlex) fromAxes(LS_WEIGHT_AXIS, WIDTH_AXIS, ROUND_AXIS, SLANT_AXIS) + else fromAxes(FLEX_LS_WEIGHT_AXIS, FLEX_LS_WIDTH_AXIS, FLEX_ROUND_AXIS, SLANT_AXIS) lsFontVariation = lsFontAxes.toFVar() - aodFontVariation = (fixedAodAxes + listOf(roundAxis, SLANT_AXIS)).toFVar() + aodFontVariation = fixedAodAxes.copyWith(fromAxes(roundAxis, SLANT_AXIS)).toFVar() fidgetFontVariation = buildFidgetVariation(lsFontAxes).toFVar() } @@ -206,9 +205,9 @@ open class SimpleDigitalClockTextView( invalidate() } - fun updateAxes(lsAxes: List<ClockFontAxisSetting>) { + fun updateAxes(lsAxes: ClockAxisStyle) { lsFontVariation = lsAxes.toFVar() - aodFontVariation = lsAxes.replace(fixedAodAxes).toFVar() + aodFontVariation = lsAxes.copyWith(fixedAodAxes).toFVar() fidgetFontVariation = buildFidgetVariation(lsAxes).toFVar() logger.updateAxes(lsFontVariation, aodFontVariation) @@ -225,19 +224,16 @@ open class SimpleDigitalClockTextView( invalidate() } - fun buildFidgetVariation(axes: List<ClockFontAxisSetting>): List<ClockFontAxisSetting> { - val result = mutableListOf<ClockFontAxisSetting>() - for (axis in axes) { - result.add( - FIDGET_DISTS.get(axis.key)?.let { (dist, midpoint) -> - ClockFontAxisSetting( - axis.key, - axis.value + dist * if (axis.value > midpoint) -1 else 1, - ) - } ?: axis - ) - } - return result + fun buildFidgetVariation(axes: ClockAxisStyle): ClockAxisStyle { + return ClockAxisStyle( + axes.items + .map { (key, value) -> + FIDGET_DISTS.get(key)?.let { (dist, midpoint) -> + key to value + dist * if (value > midpoint) -1 else 1 + } ?: (key to value) + } + .toMap() + ) } override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { @@ -656,18 +652,22 @@ open class SimpleDigitalClockTextView( ) val AOD_COLOR = Color.WHITE - val LS_WEIGHT_AXIS = GSFAxes.WEIGHT.toClockAxisSetting(400f) - val AOD_WEIGHT_AXIS = GSFAxes.WEIGHT.toClockAxisSetting(200f) - val WIDTH_AXIS = GSFAxes.WIDTH.toClockAxisSetting(85f) - val ROUND_AXIS = GSFAxes.ROUND.toClockAxisSetting(0f) - val SLANT_AXIS = GSFAxes.SLANT.toClockAxisSetting(0f) + private val LS_WEIGHT_AXIS = GSFAxes.WEIGHT to 400f + private val AOD_WEIGHT_AXIS = GSFAxes.WEIGHT to 200f + private val WIDTH_AXIS = GSFAxes.WIDTH to 85f + private val ROUND_AXIS = GSFAxes.ROUND to 0f + private val SLANT_AXIS = GSFAxes.SLANT to 0f // Axes for Legacy version of the Flex Clock - val FLEX_LS_WEIGHT_AXIS = GSFAxes.WEIGHT.toClockAxisSetting(600f) - val FLEX_AOD_LARGE_WEIGHT_AXIS = GSFAxes.WEIGHT.toClockAxisSetting(74f) - val FLEX_AOD_SMALL_WEIGHT_AXIS = GSFAxes.WEIGHT.toClockAxisSetting(133f) - val FLEX_LS_WIDTH_AXIS = GSFAxes.WIDTH.toClockAxisSetting(100f) - val FLEX_AOD_WIDTH_AXIS = GSFAxes.WIDTH.toClockAxisSetting(43f) - val FLEX_ROUND_AXIS = GSFAxes.ROUND.toClockAxisSetting(100f) + private val FLEX_LS_WEIGHT_AXIS = GSFAxes.WEIGHT to 600f + private val FLEX_AOD_LARGE_WEIGHT_AXIS = GSFAxes.WEIGHT to 74f + private val FLEX_AOD_SMALL_WEIGHT_AXIS = GSFAxes.WEIGHT to 133f + private val FLEX_LS_WIDTH_AXIS = GSFAxes.WIDTH to 100f + private val FLEX_AOD_WIDTH_AXIS = GSFAxes.WIDTH to 43f + private val FLEX_ROUND_AXIS = GSFAxes.ROUND to 100f + + private fun fromAxes(vararg axes: Pair<AxisDefinition, Float>): ClockAxisStyle { + return ClockAxisStyle(axes.map { (def, value) -> def.tag to value }.toMap()) + } } } diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/shared/clocks/ClockRegistryTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/shared/clocks/ClockRegistryTest.kt index ddad230f04e9..2f2fafab53d5 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/shared/clocks/ClockRegistryTest.kt +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/shared/clocks/ClockRegistryTest.kt @@ -25,8 +25,8 @@ import com.android.systemui.SysuiTestCase import com.android.systemui.plugins.PluginLifecycleManager import com.android.systemui.plugins.PluginListener import com.android.systemui.plugins.PluginManager +import com.android.systemui.plugins.clocks.ClockAxisStyle import com.android.systemui.plugins.clocks.ClockController -import com.android.systemui.plugins.clocks.ClockFontAxisSetting import com.android.systemui.plugins.clocks.ClockId import com.android.systemui.plugins.clocks.ClockMessageBuffers import com.android.systemui.plugins.clocks.ClockMetadata @@ -543,7 +543,7 @@ class ClockRegistryTest : SysuiTestCase() { @Test fun jsonDeserialization_fontAxes() { - val expected = ClockSettings(axes = listOf(ClockFontAxisSetting("KEY", 10f))) + val expected = ClockSettings(axes = ClockAxisStyle("KEY", 10f)) val json = JSONObject("""{"axes":[{"key":"KEY","value":10}]}""") val actual = ClockSettings.fromJson(json) assertEquals(expected, actual) @@ -576,7 +576,7 @@ class ClockRegistryTest : SysuiTestCase() { @Test fun jsonSerialization_axisSettings() { - val settings = ClockSettings(axes = listOf(ClockFontAxisSetting("KEY", 10f))) + val settings = ClockSettings(axes = ClockAxisStyle("KEY", 10f)) val actual = ClockSettings.toJson(settings) val expected = JSONObject("""{"metadata":{},"axes":[{"key":"KEY","value":10}]}""") assertEquals(expected.toString(), actual.toString()) diff --git a/packages/SystemUI/plugin/src/com/android/systemui/plugins/clocks/ClockEvents.kt b/packages/SystemUI/plugin/src/com/android/systemui/plugins/clocks/ClockEvents.kt index 235475f6b202..0fc3470716fe 100644 --- a/packages/SystemUI/plugin/src/com/android/systemui/plugins/clocks/ClockEvents.kt +++ b/packages/SystemUI/plugin/src/com/android/systemui/plugins/clocks/ClockEvents.kt @@ -44,5 +44,5 @@ interface ClockEvents { fun onZenDataChanged(data: ZenData) /** Update reactive axes for this clock */ - fun onFontAxesChanged(axes: List<ClockFontAxisSetting>) + fun onFontAxesChanged(axes: ClockAxisStyle) } 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 0cbc30d399d0..2147ca147b70 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 @@ -35,10 +35,54 @@ constructor( /** Font axes that can be modified on this clock */ val axes: List<ClockFontAxis> = listOf(), - /** List of font presets for this clock. Can be assigned directly. */ - val axisPresets: List<List<ClockFontAxisSetting>> = listOf(), + /** Presets for this clock. Null indicates the preset list should be disabled. */ + val presetConfig: AxisPresetConfig? = null, ) +data class AxisPresetConfig( + /** Groups of Presets. Each group can be used together in a single control. */ + val groups: List<Group>, + + /** Preset item currently being used, null when the current style is not a preset */ + val current: IndexedStyle? = null, +) { + /** The selected clock axis style, and its indices */ + data class IndexedStyle( + /** Index of the group that this clock axis style appears in */ + val groupIndex: Int, + + /** Index of the preset within the group */ + val presetIndex: Int, + + /** Reference to the style in question */ + val style: ClockAxisStyle, + ) + + /** A group of preset styles */ + data class Group( + /* List of preset styles in this group */ + val presets: List<ClockAxisStyle>, + + /* Icon to use when this preset-group is active */ + val icon: Drawable, + ) + + fun findStyle(style: ClockAxisStyle): IndexedStyle? { + groups.forEachIndexed { groupIndex, group -> + group.presets.forEachIndexed { presetIndex, preset -> + if (preset == style) { + return@findStyle IndexedStyle( + groupIndex = groupIndex, + presetIndex = presetIndex, + style = preset, + ) + } + } + } + return null + } +} + /** Represents an Axis that can be modified */ data class ClockFontAxis( /** Axis key, not user renderable */ @@ -62,19 +106,12 @@ data class ClockFontAxis( /** Description of the axis */ val description: String, ) { - fun toSetting() = ClockFontAxisSetting(key, currentValue) - companion object { - fun List<ClockFontAxis>.merge( - axisSettings: List<ClockFontAxisSetting> - ): List<ClockFontAxis> { - val result = mutableListOf<ClockFontAxis>() - 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) - } - return result + fun List<ClockFontAxis>.merge(axisStyle: ClockAxisStyle): List<ClockFontAxis> { + return this.map { axis -> + axisStyle.get(axis.key)?.let { axis.copy(currentValue = it) } ?: axis + } + .toList() } } } 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 e7b36626a810..cccc55835302 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 @@ -22,7 +22,7 @@ import org.json.JSONObject data class ClockSettings( val clockId: ClockId? = null, val seedColor: Int? = null, - val axes: List<ClockFontAxisSetting> = listOf(), + val axes: ClockAxisStyle = ClockAxisStyle(), ) { // Exclude metadata from equality checks var metadata: JSONObject = JSONObject() @@ -38,15 +38,15 @@ data class ClockSettings( put(KEY_CLOCK_ID, setting.clockId) put(KEY_SEED_COLOR, setting.seedColor) put(KEY_METADATA, setting.metadata) - put(KEY_AXIS_LIST, ClockFontAxisSetting.toJson(setting.axes)) + put(KEY_AXIS_LIST, ClockAxisStyle.toJson(setting.axes)) } } fun fromJson(json: JSONObject): ClockSettings { val clockId = if (!json.isNull(KEY_CLOCK_ID)) json.getString(KEY_CLOCK_ID) else null val seedColor = if (!json.isNull(KEY_SEED_COLOR)) json.getInt(KEY_SEED_COLOR) else null - val axisList = json.optJSONArray(KEY_AXIS_LIST)?.let(ClockFontAxisSetting::fromJson) - return ClockSettings(clockId, seedColor, axisList ?: listOf()).apply { + val axisList = json.optJSONArray(KEY_AXIS_LIST)?.let(ClockAxisStyle::fromJson) + return ClockSettings(clockId, seedColor, axisList ?: ClockAxisStyle()).apply { metadata = json.optJSONObject(KEY_METADATA) ?: JSONObject() } } @@ -54,64 +54,102 @@ data class ClockSettings( } @Keep -/** Axis setting value for a clock */ -data class ClockFontAxisSetting( - /** Axis key; matches ClockFontAxis.key */ - val key: String, +class ClockAxisStyle { + private val settings: MutableMap<String, Float> - /** Value to set this axis to */ - val value: Float, -) { - companion object { - private val KEY_AXIS_KEY = "key" - private val KEY_AXIS_VALUE = "value" + // Iterable would be implemented on ClockAxisStyle directly, + // but that doesn't appear to work with plugins/dynamic libs. + val items: Iterable<Map.Entry<String, Float>> + get() = settings.asIterable() - fun toJson(setting: ClockFontAxisSetting): JSONObject { - return JSONObject().apply { - put(KEY_AXIS_KEY, setting.key) - put(KEY_AXIS_VALUE, setting.value) - } - } + val isEmpty: Boolean + get() = settings.isEmpty() - fun toJson(settings: List<ClockFontAxisSetting>): JSONArray { - return JSONArray().apply { - for (axis in settings) { - put(toJson(axis)) - } - } + constructor(initialize: ClockAxisStyle.() -> Unit = {}) { + settings = mutableMapOf() + this.initialize() + } + + constructor(style: ClockAxisStyle) { + settings = style.settings.toMutableMap() + } + + constructor(items: Map<String, Float>) { + settings = items.toMutableMap() + } + + constructor(key: String, value: Float) { + settings = mutableMapOf(key to value) + } + + constructor(items: List<ClockFontAxis>) { + settings = items.associate { it.key to it.currentValue }.toMutableMap() + } + + fun copy(initialize: ClockAxisStyle.() -> Unit): ClockAxisStyle { + return ClockAxisStyle(this).apply { initialize() } + } + + operator fun get(key: String): Float? = settings[key] + + operator fun set(key: String, value: Float) = put(key, value) + + fun put(key: String, value: Float) { + settings.put(key, value) + } + + fun toFVar(): String { + val sb = StringBuilder() + for (axis in settings) { + if (sb.length > 0) sb.append(", ") + sb.append("'${axis.key}' ${axis.value.toInt()}") } + return sb.toString() + } - fun fromJson(jsonObj: JSONObject): ClockFontAxisSetting { - return ClockFontAxisSetting( - key = jsonObj.getString(KEY_AXIS_KEY), - value = jsonObj.getDouble(KEY_AXIS_VALUE).toFloat(), - ) + fun copyWith(replacements: ClockAxisStyle): ClockAxisStyle { + val result = ClockAxisStyle(this) + for ((key, value) in replacements.settings) { + result[key] = value } + return result + } + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (other !is ClockAxisStyle) return false + return settings == other.settings + } - fun fromJson(jsonArray: JSONArray): List<ClockFontAxisSetting> { - val result = mutableListOf<ClockFontAxisSetting>() + companion object { + private val KEY_AXIS_KEY = "key" + private val KEY_AXIS_VALUE = "value" + + fun fromJson(jsonArray: JSONArray): ClockAxisStyle { + val result = ClockAxisStyle() for (i in 0..jsonArray.length() - 1) { val obj = jsonArray.getJSONObject(i) if (obj == null) continue - result.add(fromJson(obj)) + + result.put( + key = obj.getString(KEY_AXIS_KEY), + value = obj.getDouble(KEY_AXIS_VALUE).toFloat(), + ) } return result } - fun List<ClockFontAxisSetting>.toFVar(): String { - val sb = StringBuilder() - for (axis in this) { - if (sb.length > 0) sb.append(", ") - sb.append("'${axis.key}' ${axis.value.toInt()}") + fun toJson(style: ClockAxisStyle): JSONArray { + return JSONArray().apply { + for ((key, value) in style.settings) { + put( + JSONObject().apply { + put(KEY_AXIS_KEY, key) + put(KEY_AXIS_VALUE, value) + } + ) + } } - return sb.toString() - } - - fun List<ClockFontAxisSetting>.replace( - replacements: List<ClockFontAxisSetting> - ): List<ClockFontAxisSetting> { - var remaining = this.filterNot { lhs -> replacements.any { rhs -> lhs.key == rhs.key } } - return remaining + replacements } } } |