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

Commit 3316696b authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes from topic "retarget_flex" into main

* changes:
  Retarget DIGITAL_CLOCK_FLEX to new flex clock code
  Update aodFontVariation to be modified version of user set axes
parents 86feff95 76d1c921
Loading
Loading
Loading
Loading
+10 −7
Original line number Diff line number Diff line
@@ -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
+1 −1
Original line number Diff line number Diff line
@@ -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)
        }
+13 −26
Original line number Diff line number Diff line
@@ -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)
+19 −3
Original line number Diff line number Diff line
@@ -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,
@@ -135,7 +143,7 @@ class FlexClockController(private val clockCtx: ClockContext) : ClockController
                    key = GSFAxes.WIDTH,
                    type = AxisType.Float,
                    minValue = 25f,
                    currentValue = 100f,
                    currentValue = 85f,
                    maxValue = 151f,
                    name = "Width",
                    description = "Glyph Width",
@@ -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),
            )
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -60,7 +60,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 }
Loading