Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit db1986c2 authored by Hawkwood Glazier's avatar Hawkwood Glazier
Browse files

Updates for dual axis presets

Bug: 395647577
Test: Manually checked clocks still worked
Flag: com.android.systemui.shared.clock_reactive_variants
Change-Id: Ief7ef5856417f85dd93ce1e422d4bf0753dffe17
parent 31d71959
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -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)
            }

+2 −2
Original line number Diff line number Diff line
@@ -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(
+33 −13
Original line number Diff line number Diff line
@@ -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")
        }

        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 =
                if (!isClockReactiveVariantsEnabled) emptyList()
                else getDefaultAxes(settings).merge(settings.axes),
            axisPresets = if (!isClockReactiveVariantsEnabled) emptyList() else AXIS_PRESETS,
                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 {
+46 −62
Original line number Diff line number Diff line
@@ -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)
        }

        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)
                    }
                )

        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),
                ),
                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),
            )
        }
    }
}
+7 −12
Original line number Diff line number Diff line
@@ -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)
Loading