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

Commit c006cb42 authored by Hawkwood's avatar Hawkwood
Browse files

Share Calendar & SimpleDateFormat entries whenever possible

Bug: 416066990
Test: atest DefaultClockScreenshotTest
Flag: com.android.systemui.shared.clock_reactive_variants
Change-Id: Ic522121ba8de7374caa0120e2c07ee2ca8e314ab
parent eefed5ab
Loading
Loading
Loading
Loading
+30 −29
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@
package com.android.systemui.shared.clocks

import android.graphics.Rect
import androidx.annotation.VisibleForTesting
import android.icu.util.TimeZone
import com.android.app.animation.Interpolators
import com.android.systemui.log.core.Logger
import com.android.systemui.plugins.clocks.AlarmData
@@ -27,13 +27,13 @@ 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.ThemeConfig
import com.android.systemui.plugins.clocks.TimeFormatKind
import com.android.systemui.plugins.clocks.WeatherData
import com.android.systemui.plugins.clocks.ZenData
import com.android.systemui.shared.clocks.view.FlexClockView
import com.android.systemui.shared.clocks.view.HorizontalAlignment
import com.android.systemui.shared.clocks.view.VerticalAlignment
import java.util.Locale
import java.util.TimeZone

class ComposedDigitalLayerController(private val clockCtx: ClockContext) :
    SimpleClockLayerController {
@@ -63,24 +63,35 @@ class ComposedDigitalLayerController(private val clockCtx: ClockContext) :
                        transitionDuration = FlexClockView.AOD_TRANSITION_DURATION,
                    ),

                // Placeholders
                timespec = DigitalTimespec.TIME_FULL_FORMAT,
                dateTimeFormat = "hh:mm",
                // Placeholder Timespec Values
                timespec = DigitalTimespec.DIGIT_PAIR,
                timeFormatter = null,
            )

        DigitalTimeFormatter("hh", clockCtx.timeKeeper).also { timeFormatter ->
            createController(
            layerCfg.copy(timespec = DigitalTimespec.FIRST_DIGIT, dateTimeFormat = "hh")
                layerCfg.copy(timespec = DigitalTimespec.FIRST_DIGIT, timeFormatter = timeFormatter)
            )
            createController(
            layerCfg.copy(timespec = DigitalTimespec.SECOND_DIGIT, dateTimeFormat = "hh")
                layerCfg.copy(
                    timespec = DigitalTimespec.SECOND_DIGIT,
                    timeFormatter = timeFormatter,
                )
            )
        }

        DigitalTimeFormatter("mm", clockCtx.timeKeeper).also { timeFormatter ->
            createController(
            layerCfg.copy(timespec = DigitalTimespec.FIRST_DIGIT, dateTimeFormat = "mm")
                layerCfg.copy(timespec = DigitalTimespec.FIRST_DIGIT, timeFormatter = timeFormatter)
            )
            createController(
            layerCfg.copy(timespec = DigitalTimespec.SECOND_DIGIT, dateTimeFormat = "mm")
                layerCfg.copy(
                    timespec = DigitalTimespec.SECOND_DIGIT,
                    timeFormatter = timeFormatter,
                )
            )
        }
    }

    private fun refreshTime() {
        layerControllers.forEach { it.faceEvents.onTimeTick() }
@@ -94,8 +105,8 @@ class ComposedDigitalLayerController(private val clockCtx: ClockContext) :
                refreshTime()
            }

            override fun onTimeFormatChanged(is24Hr: Boolean) {
                layerControllers.forEach { it.events.onTimeFormatChanged(is24Hr) }
            override fun onTimeFormatChanged(formatKind: TimeFormatKind) {
                layerControllers.forEach { it.events.onTimeFormatChanged(formatKind) }
                refreshTime()
            }

@@ -184,14 +195,4 @@ class ComposedDigitalLayerController(private val clockCtx: ClockContext) :
            hasCustomWeatherDataDisplay = false,
            hasCustomPositionUpdatedAnimation = true,
        )

    @VisibleForTesting
    override var fakeTimeMills: Long? = null
        get() = field
        set(timeInMills) {
            field = timeInMills
            for (layerController in layerControllers) {
                layerController.fakeTimeMills = timeInMills
            }
        }
}
+8 −5
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ import android.content.res.Resources
import android.graphics.Color
import android.graphics.Rect
import android.icu.text.NumberFormat
import android.icu.util.TimeZone
import android.util.TypedValue
import android.view.LayoutInflater
import android.widget.FrameLayout
@@ -40,12 +41,12 @@ import com.android.systemui.plugins.clocks.ClockMessageBuffers
import com.android.systemui.plugins.clocks.ClockSettings
import com.android.systemui.plugins.clocks.ClockViewIds
import com.android.systemui.plugins.clocks.ThemeConfig
import com.android.systemui.plugins.clocks.TimeFormatKind
import com.android.systemui.plugins.clocks.WeatherData
import com.android.systemui.plugins.clocks.ZenData
import com.android.systemui.shared.Flags.ambientAod
import java.io.PrintWriter
import java.util.Locale
import java.util.TimeZone

/**
 * Controls the default clock visuals.
@@ -213,11 +214,13 @@ class DefaultClockController(
    inner class DefaultClockEvents : ClockEvents {
        override var isReactiveTouchInteractionEnabled: Boolean = false

        override fun onTimeFormatChanged(is24Hr: Boolean) =
            clocks.forEach { it.refreshFormat(is24Hr) }
        override fun onTimeFormatChanged(formatKind: TimeFormatKind) =
            clocks.forEach { it.refreshFormat(formatKind == TimeFormatKind.FULL_DAY) }

        override fun onTimeZoneChanged(timeZone: TimeZone) =
            clocks.forEach { it.onTimeZoneChanged(timeZone) }
        override fun onTimeZoneChanged(timeZone: TimeZone) {
            val legacyTimezone = java.util.TimeZone.getTimeZone(timeZone.getID())
            clocks.forEach { it.onTimeZoneChanged(legacyTimezone) }
        }

        override fun onLocaleChanged(locale: Locale) {
            val nf = NumberFormat.getInstance(locale)
+6 −1
Original line number Diff line number Diff line
@@ -45,14 +45,18 @@ data class ClockContext(
    val messageBuffers: ClockMessageBuffers,
    val messageBuffer: MessageBuffer,
    val vibrator: Vibrator?,
    val timeKeeper: TimeKeeper,
)

/** Provides the default system clock */
class DefaultClockProvider(
class DefaultClockProvider
@JvmOverloads
constructor(
    val layoutInflater: LayoutInflater,
    val resources: Resources,
    private val isClockReactiveVariantsEnabled: Boolean = false,
    private val vibrator: Vibrator?,
    private val timeKeeperFactory: () -> TimeKeeper = { TimeKeeperImpl() },
) : ClockProvider {
    private var messageBuffers: ClockMessageBuffers? = null

@@ -95,6 +99,7 @@ class DefaultClockProvider(
                    buffers,
                    buffers.infraMessageBuffer,
                    vibrator,
                    timeKeeperFactory(),
                )
            )
        } else {
+5 −4
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.systemui.shared.clocks

import android.content.res.Resources
import android.icu.util.TimeZone
import com.android.systemui.animation.GSFAxes
import com.android.systemui.customization.R
import com.android.systemui.customization.clocks.FontUtils.put
@@ -32,12 +33,12 @@ 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.ClockSettings
import com.android.systemui.plugins.clocks.TimeFormatKind
import com.android.systemui.plugins.clocks.WeatherData
import com.android.systemui.plugins.clocks.ZenData
import com.android.systemui.shared.clocks.view.FlexClockView
import java.io.PrintWriter
import java.util.Locale
import java.util.TimeZone

/** Controller for the default flex clock */
class FlexClockController(private val clockCtx: ClockContext) : ClockController {
@@ -75,9 +76,9 @@ class FlexClockController(private val clockCtx: ClockContext) : ClockController
                largeClock.events.onTimeZoneChanged(timeZone)
            }

            override fun onTimeFormatChanged(is24Hr: Boolean) {
                smallClock.events.onTimeFormatChanged(is24Hr)
                largeClock.events.onTimeFormatChanged(is24Hr)
            override fun onTimeFormatChanged(formatKind: TimeFormatKind) {
                smallClock.events.onTimeFormatChanged(formatKind)
                largeClock.events.onTimeFormatChanged(formatKind)
            }

            override fun onLocaleChanged(locale: Locale) {
+23 −16
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.systemui.shared.clocks

import android.graphics.Rect
import android.icu.util.TimeZone
import android.view.Gravity
import android.view.View
import android.view.ViewGroup.LayoutParams.MATCH_PARENT
@@ -39,6 +40,7 @@ import com.android.systemui.plugins.clocks.ClockFaceLayout
import com.android.systemui.plugins.clocks.ClockFontAxis.Companion.merge
import com.android.systemui.plugins.clocks.ClockViewIds
import com.android.systemui.plugins.clocks.ThemeConfig
import com.android.systemui.plugins.clocks.TimeFormatKind
import com.android.systemui.plugins.clocks.WeatherData
import com.android.systemui.plugins.clocks.ZenData
import com.android.systemui.shared.clocks.FlexClockController.Companion.getDefaultAxes
@@ -46,13 +48,14 @@ import com.android.systemui.shared.clocks.view.FlexClockView
import com.android.systemui.shared.clocks.view.HorizontalAlignment
import com.android.systemui.shared.clocks.view.VerticalAlignment
import java.util.Locale
import java.util.TimeZone
import kotlin.math.max
import kotlin.math.roundToInt

// TODO(b/364680879): Merge w/ ComposedDigitalLayerController
class FlexClockFaceController(clockCtx: ClockContext, private val isLargeClock: Boolean) :
    ClockFaceController {
class FlexClockFaceController(
    private val clockCtx: ClockContext,
    private val isLargeClock: Boolean,
) : ClockFaceController {
    override val view: View
        get() = layerController.view

@@ -62,14 +65,18 @@ class FlexClockFaceController(clockCtx: ClockContext, private val isLargeClock:

    private val keyguardLargeClockTopMargin =
        clockCtx.resources.getDimensionPixelSize(R.dimen.keyguard_large_clock_top_margin)
    private val timeFormatter =
        DigitalTimeFormatter("h:mm", clockCtx.timeKeeper, enableContentDescription = true)
    val layerController: SimpleClockLayerController
    val timespecHandler = DigitalTimespecHandler(DigitalTimespec.TIME_FULL_FORMAT, "hh:mm")

    init {
        layerController =
            if (isLargeClock) ComposedDigitalLayerController(clockCtx)
            else SimpleDigitalHandLayerController(clockCtx, SMALL_LAYER_CONFIG, isLargeClock)

            if (isLargeClock) {
                ComposedDigitalLayerController(clockCtx)
            } else {
                val cfg = SMALL_LAYER_CONFIG.copy(timeFormatter = timeFormatter)
                SimpleDigitalHandLayerController(clockCtx, cfg, isLargeClock)
            }
        layerController.view.layoutParams =
            FrameLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT).apply { gravity = Gravity.CENTER }
    }
@@ -106,23 +113,23 @@ class FlexClockFaceController(clockCtx: ClockContext, private val isLargeClock:
            }

        override fun onTimeTick() {
            timespecHandler.updateTime()
            view.contentDescription = timespecHandler.getContentDescription()
            clockCtx.timeKeeper.updateTime()
            view.contentDescription = timeFormatter.getContentDescription()
            layerController.faceEvents.onTimeTick()
        }

        override fun onTimeZoneChanged(timeZone: TimeZone) {
            timespecHandler.timeZone = timeZone
            clockCtx.timeKeeper.timeZone = timeZone
            layerController.events.onTimeZoneChanged(timeZone)
        }

        override fun onTimeFormatChanged(is24Hr: Boolean) {
            timespecHandler.is24Hr = is24Hr
            layerController.events.onTimeFormatChanged(is24Hr)
        override fun onTimeFormatChanged(formatKind: TimeFormatKind) {
            timeFormatter.formatKind = formatKind
            layerController.events.onTimeFormatChanged(formatKind)
        }

        override fun onLocaleChanged(locale: Locale) {
            timespecHandler.updateLocale(locale)
            timeFormatter.updateLocale(locale)
            layerController.events.onLocaleChanged(locale)
        }

@@ -244,7 +251,6 @@ class FlexClockFaceController(clockCtx: ClockContext, private val isLargeClock:

        val SMALL_LAYER_CONFIG =
            LayerConfig(
                timespec = DigitalTimespec.TIME_FULL_FORMAT,
                style = FontTextStyle(fontSizeScale = 0.98f),
                aodStyle =
                    FontTextStyle(
@@ -252,7 +258,8 @@ class FlexClockFaceController(clockCtx: ClockContext, private val isLargeClock:
                        transitionDuration = FlexClockView.AOD_TRANSITION_DURATION,
                    ),
                alignment = DigitalAlignment(HorizontalAlignment.START, VerticalAlignment.CENTER),
                dateTimeFormat = "h:mm",
                timespec = DigitalTimespec.TIME_FULL_FORMAT,
                timeFormatter = null, // Placeholder
            )
    }
}
Loading