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

Commit 59f7f71e authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Carousel clock color updates" into udc-dev

parents df602e63 8256fcec
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@
package com.android.customization.module

import android.app.UiModeManager
import android.app.WallpaperManager
import android.content.Context
import android.content.Intent
import android.net.Uri
@@ -394,7 +395,11 @@ open class ThemePickerInjector : WallpaperPicker2Injector(), CustomizationInject
                    activity.applicationContext,
                    ScreenSizeCalculator.getInstance()
                        .getScreenSize(activity.windowManager.defaultDisplay),
                    getClockRegistry(activity.applicationContext, activity),
                    WallpaperManager.getInstance(activity.applicationContext),
                    getClockRegistry(
                        context = activity.applicationContext,
                        lifecycleOwner = activity,
                    ),
                )
                .also {
                    clockViewFactories[activityHashCode] = it
+1 −0
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ object ClockCarouselViewBinder {
        lifecycleOwner: LifecycleOwner,
    ) {
        carouselView.setClockViewFactory(clockViewFactory)
        clockViewFactory.updateRegionDarkness()
        val singleClockHostView =
            singleClockView.requireViewById<FrameLayout>(R.id.single_clock_host_view)
        lifecycleOwner.lifecycleScope.launch {
+23 −11
Original line number Diff line number Diff line
@@ -15,11 +15,12 @@
 */
package com.android.customization.picker.clock.ui.view

import android.app.WallpaperColors
import android.app.WallpaperManager
import android.content.Context
import android.content.res.Resources
import android.graphics.Point
import android.graphics.Rect
import android.util.TypedValue
import android.view.View
import android.widget.FrameLayout
import androidx.annotation.ColorInt
@@ -39,6 +40,7 @@ import java.util.concurrent.ConcurrentHashMap
class ClockViewFactory(
    private val appContext: Context,
    val screenSize: Point,
    private val wallpaperManager: WallpaperManager,
    private val registry: ClockRegistry,
) {
    private val resources = appContext.resources
@@ -89,9 +91,21 @@ class ClockViewFactory(
    }

    fun updateColor(clockId: String, @ColorInt seedColor: Int?) {
        return (clockControllers[clockId] ?: initClockController(clockId))
            .events
            .onSeedColorChanged(seedColor)
        clockControllers[clockId]?.events?.onSeedColorChanged(seedColor)
    }

    fun updateRegionDarkness() {
        val isRegionDark = isLockscreenWallpaperDark()
        clockControllers.values.forEach {
            it.largeClock.events.onRegionDarknessChanged(isRegionDark)
            it.smallClock.events.onRegionDarknessChanged(isRegionDark)
        }
    }

    private fun isLockscreenWallpaperDark(): Boolean {
        val colors = wallpaperManager.getWallpaperColors(WallpaperManager.FLAG_LOCK)
        return (colors?.colorHints?.and(WallpaperColors.HINT_SUPPORTS_DARK_TEXT)) !=
            WallpaperColors.HINT_SUPPORTS_DARK_TEXT
    }

    fun updateTimeFormat(clockId: String) {
@@ -136,18 +150,16 @@ class ClockViewFactory(
            registry.createExampleClock(clockId).also { it?.initialize(resources, 0f, 0f) }
        checkNotNull(controller)

        // Configure light/dark theme
        val isLightTheme = TypedValue()
        appContext.theme.resolveAttribute(android.R.attr.isLightTheme, isLightTheme, true)
        val isRegionDark = isLightTheme.data == 0
        controller.largeClock.events.onRegionDarknessChanged(isRegionDark)
        // Configure font size
        val isWallpaperDark = isLockscreenWallpaperDark()
        // Initialize large clock
        controller.largeClock.events.onRegionDarknessChanged(isWallpaperDark)
        controller.largeClock.events.onFontSettingChanged(
            resources.getDimensionPixelSize(R.dimen.large_clock_text_size).toFloat()
        )
        controller.largeClock.events.onTargetRegionChanged(getLargeClockRegion())

        controller.smallClock.events.onRegionDarknessChanged(isRegionDark)
        // Initialize small clock
        controller.smallClock.events.onRegionDarknessChanged(isWallpaperDark)
        controller.smallClock.events.onFontSettingChanged(
            resources.getDimensionPixelSize(R.dimen.small_clock_text_size).toFloat()
        )