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

Commit f6093b2b authored by Hawkwood Glazier's avatar Hawkwood Glazier Committed by Hawkwood
Browse files

Add common clock lib for sharing code between infra and plugins

This intends to remove as many instances of resource lookups by name
as possible in the custom clocks and related code. These have been a
source of bugs, and by creating a common lib, we can directly share
resources to every context where they are needed.

This also refactors the way we handle non-primary view contexts. We
apply this to preview contexts in this change, but we'll reuse the same
approach for copies of clocks rendering on secondary display contexts.

Bug: 397680831
Bug: 364680879
Test: Checked rebuilt plugins
Flag: NONE Build & API change
Change-Id: I0dec6d4ca5b4d2890dd5df9c3d8440968d8afe32
parent 3872f296
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -127,7 +127,7 @@ constructor(
        val scaleFactor = authController.scaleFactor
        val bottomPaddingPx =
            context.resources.getDimensionPixelSize(
                com.android.systemui.customization.R.dimen.lock_icon_margin_bottom
                com.android.systemui.customization.clocks.R.dimen.lock_icon_margin_bottom
            )
        val heightPx = windowViewBounds.bottom.toFloat()
        val (center, radius) =
+3 −3
Original line number Diff line number Diff line
@@ -32,7 +32,7 @@ import androidx.compose.ui.viewinterop.AndroidView
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.android.compose.animation.scene.ContentScope
import com.android.compose.modifiers.padding
import com.android.systemui.customization.R
import com.android.systemui.customization.clocks.R as clocksR
import com.android.systemui.keyguard.ui.composable.blueprint.ClockElementKeys.largeClockElementKey
import com.android.systemui.keyguard.ui.composable.blueprint.ClockElementKeys.smallClockElementKey
import com.android.systemui.keyguard.ui.composable.blueprint.ClockScenes.largeClockScene
@@ -92,8 +92,8 @@ constructor(
            checkNotNull(currentClock).smallClock.view,
            modifier =
                modifier
                    .height(dimensionResource(R.dimen.small_clock_height))
                    .padding(horizontal = dimensionResource(R.dimen.clock_padding_start))
                    .height(dimensionResource(clocksR.dimen.small_clock_height))
                    .padding(horizontal = dimensionResource(clocksR.dimen.clock_padding_start))
                    .padding(top = { smallTopMargin })
                    .onTopPlacementChanged(onTopChanged)
                    .burnInAware(viewModel = aodBurnInViewModel, params = burnInParams)
+2 −2
Original line number Diff line number Diff line
@@ -31,7 +31,7 @@ import androidx.compose.ui.viewinterop.AndroidView
import com.android.compose.animation.scene.ContentScope
import com.android.compose.animation.scene.ElementKey
import com.android.systemui.biometrics.AuthController
import com.android.systemui.customization.R as customR
import com.android.systemui.customization.clocks.R as clocksR
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.flags.FeatureFlagsClassic
@@ -155,7 +155,7 @@ constructor(
            } else {
                val scaleFactor = authController.scaleFactor
                val bottomPaddingPx =
                    context.resources.getDimensionPixelSize(customR.dimen.lock_icon_margin_bottom)
                    context.resources.getDimensionPixelSize(clocksR.dimen.lock_icon_margin_bottom)
                val heightPx = windowViewBounds.bottom.toFloat()

                Pair(
+1 −0
Original line number Diff line number Diff line
@@ -246,6 +246,7 @@ constructor(
     * @param name Name of resources
     * @param density Density required to convert dimen from Int To Dp
     */
    @Deprecated("Prefer reading dimensions directly")
    private fun getDimen(context: Context, name: String, density: Density): Dp {
        val res = context.packageManager.getResourcesForApplication(context.packageName)
        val id = res.getIdentifier(name, "dimen", context.packageName)
+10 −9
Original line number Diff line number Diff line
@@ -29,13 +29,14 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.res.dimensionResource
import com.android.compose.animation.scene.ContentScope
import com.android.compose.animation.scene.ElementKey
import com.android.systemui.customization.R as customR
import com.android.systemui.customization.clocks.R as clocksR
import com.android.systemui.keyguard.ui.composable.blueprint.WeatherClockElementKeys
import com.android.systemui.keyguard.ui.composable.modifier.burnInAware
import com.android.systemui.keyguard.ui.viewmodel.AodBurnInViewModel
import com.android.systemui.keyguard.ui.viewmodel.BurnInParameters
import com.android.systemui.keyguard.ui.viewmodel.KeyguardClockViewModel
import com.android.systemui.plugins.clocks.ClockController
import com.android.systemui.plugins.clocks.ClockViewIds
import javax.inject.Inject

/** Provides small clock and large clock composables for the weather clock layout. */
@@ -49,11 +50,11 @@ constructor(
    fun ContentScope.Time(clock: ClockController, burnInParams: BurnInParameters) {
        Row(
            modifier =
                Modifier.padding(horizontal = dimensionResource(customR.dimen.clock_padding_start))
                Modifier.padding(horizontal = dimensionResource(clocksR.dimen.clock_padding_start))
                    .burnInAware(aodBurnInViewModel, burnInParams, isClock = true)
        ) {
            WeatherElement(
                weatherClockElementViewId = customR.id.weather_clock_time,
                weatherClockElementViewId = ClockViewIds.WEATHER_CLOCK_TIME,
                clock = clock,
                elementKey = WeatherClockElementKeys.timeElementKey,
            )
@@ -63,7 +64,7 @@ constructor(
    @Composable
    private fun ContentScope.Date(clock: ClockController, modifier: Modifier = Modifier) {
        WeatherElement(
            weatherClockElementViewId = customR.id.weather_clock_date,
            weatherClockElementViewId = ClockViewIds.WEATHER_CLOCK_DATE,
            clock = clock,
            elementKey = WeatherClockElementKeys.dateElementKey,
            modifier = modifier,
@@ -73,7 +74,7 @@ constructor(
    @Composable
    private fun ContentScope.Weather(clock: ClockController, modifier: Modifier = Modifier) {
        WeatherElement(
            weatherClockElementViewId = customR.id.weather_clock_weather_icon,
            weatherClockElementViewId = ClockViewIds.WEATHER_CLOCK_ICON,
            clock = clock,
            elementKey = WeatherClockElementKeys.weatherIconElementKey,
            modifier = modifier.wrapContentSize(),
@@ -83,7 +84,7 @@ constructor(
    @Composable
    private fun ContentScope.DndAlarmStatus(clock: ClockController, modifier: Modifier = Modifier) {
        WeatherElement(
            weatherClockElementViewId = customR.id.weather_clock_alarm_dnd,
            weatherClockElementViewId = ClockViewIds.WEATHER_CLOCK_ALARM_DND,
            clock = clock,
            elementKey = WeatherClockElementKeys.dndAlarmElementKey,
            modifier = modifier.wrapContentSize(),
@@ -93,7 +94,7 @@ constructor(
    @Composable
    private fun ContentScope.Temperature(clock: ClockController, modifier: Modifier = Modifier) {
        WeatherElement(
            weatherClockElementViewId = customR.id.weather_clock_temperature,
            weatherClockElementViewId = ClockViewIds.WEATHER_CLOCK_TEMP,
            clock = clock,
            elementKey = WeatherClockElementKeys.temperatureElementKey,
            modifier = modifier.wrapContentSize(),
@@ -123,14 +124,14 @@ constructor(
        Row(
            modifier =
                Modifier.height(IntrinsicSize.Max)
                    .padding(horizontal = dimensionResource(customR.dimen.clock_padding_start))
                    .padding(horizontal = dimensionResource(clocksR.dimen.clock_padding_start))
                    .burnInAware(aodBurnInViewModel, burnInParams, isClock = true)
        ) {
            Date(clock = clock, modifier = Modifier.wrapContentSize())
            Box(
                modifier =
                    Modifier.fillMaxSize()
                        .padding(start = dimensionResource(customR.dimen.clock_padding_start))
                        .padding(start = dimensionResource(clocksR.dimen.clock_padding_start))
            ) {
                Weather(clock = clock, modifier = Modifier.align(Alignment.TopStart))
                Temperature(clock = clock, modifier = Modifier.align(Alignment.BottomEnd))
Loading