diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/regionsampling/RegionSamplingInstance.kt b/packages/SystemUI/shared/src/com/android/systemui/shared/regionsampling/RegionSamplingInstance.kt index dd2e55d4e7d7f..cd4b9994cccaa 100644 --- a/packages/SystemUI/shared/src/com/android/systemui/shared/regionsampling/RegionSamplingInstance.kt +++ b/packages/SystemUI/shared/src/com/android/systemui/shared/regionsampling/RegionSamplingInstance.kt @@ -15,6 +15,7 @@ */ package com.android.systemui.shared.regionsampling +import android.graphics.Color import android.graphics.Rect import android.view.View import androidx.annotation.VisibleForTesting @@ -33,18 +34,19 @@ open class RegionSamplingInstance( regionSamplingEnabled: Boolean, updateFun: UpdateColorCallback ) { - private var isDark = RegionDarkness.DEFAULT + private var regionDarkness = RegionDarkness.DEFAULT private var samplingBounds = Rect() private val tmpScreenLocation = IntArray(2) @VisibleForTesting var regionSampler: RegionSamplingHelper? = null - + private var lightForegroundColor = Color.WHITE + private var darkForegroundColor = Color.BLACK /** * Interface for method to be passed into RegionSamplingHelper */ @FunctionalInterface interface UpdateColorCallback { /** - * Method to update the text colors after clock darkness changed. + * Method to update the foreground colors after clock darkness changed. */ fun updateColors() } @@ -59,6 +61,30 @@ open class RegionSamplingInstance( return RegionSamplingHelper(sampledView, callback, mainExecutor, bgExecutor) } + /** + * Sets the colors to be used for Dark and Light Foreground. + * + * @param lightColor The color used for Light Foreground. + * @param darkColor The color used for Dark Foreground. + */ + fun setForegroundColors(lightColor: Int, darkColor: Int) { + lightForegroundColor = lightColor + darkForegroundColor = darkColor + } + + /** + * Determines which foreground color to use based on region darkness. + * + * @return the determined foreground color + */ + fun currentForegroundColor(): Int{ + return if (regionDarkness.isDark) { + lightForegroundColor + } else { + darkForegroundColor + } + } + private fun convertToClockDarkness(isRegionDark: Boolean): RegionDarkness { return if (isRegionDark) { RegionDarkness.DARK @@ -68,7 +94,7 @@ open class RegionSamplingInstance( } fun currentRegionDarkness(): RegionDarkness { - return isDark + return regionDarkness } /** @@ -97,7 +123,7 @@ open class RegionSamplingInstance( regionSampler = createRegionSamplingHelper(sampledView, object : SamplingCallback { override fun onRegionDarknessChanged(isRegionDark: Boolean) { - isDark = convertToClockDarkness(isRegionDark) + regionDarkness = convertToClockDarkness(isRegionDark) updateFun.updateColors() } /** diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/lockscreen/LockscreenSmartspaceController.kt b/packages/SystemUI/src/com/android/systemui/statusbar/lockscreen/LockscreenSmartspaceController.kt index dfba8cd4a081a..fc984618f1b08 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/lockscreen/LockscreenSmartspaceController.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/lockscreen/LockscreenSmartspaceController.kt @@ -119,6 +119,7 @@ class LockscreenSmartspaceController @Inject constructor( regionSamplingEnabled, updateFun ) + initializeTextColors(regionSamplingInstance) regionSamplingInstance.startRegionSampler() regionSamplingInstances.put(v, regionSamplingInstance) connectSession() @@ -362,18 +363,20 @@ class LockscreenSmartspaceController @Inject constructor( } } + private fun initializeTextColors(regionSamplingInstance: RegionSamplingInstance) { + val lightThemeContext = ContextThemeWrapper(context, R.style.Theme_SystemUI_LightWallpaper) + val darkColor = Utils.getColorAttrDefaultColor(lightThemeContext, R.attr.wallpaperTextColor) + + val darkThemeContext = ContextThemeWrapper(context, R.style.Theme_SystemUI) + val lightColor = Utils.getColorAttrDefaultColor(darkThemeContext, R.attr.wallpaperTextColor) + + regionSamplingInstance.setForegroundColors(lightColor, darkColor) + } + private fun updateTextColorFromRegionSampler() { smartspaceViews.forEach { - val isRegionDark = regionSamplingInstances.getValue(it).currentRegionDarkness() - val themeID = if (isRegionDark.isDark) { - R.style.Theme_SystemUI - } else { - R.style.Theme_SystemUI_LightWallpaper - } - val themedContext = ContextThemeWrapper(context, themeID) - val wallpaperTextColor = - Utils.getColorAttrDefaultColor(themedContext, R.attr.wallpaperTextColor) - it.setPrimaryTextColor(wallpaperTextColor) + val textColor = regionSamplingInstances.getValue(it).currentForegroundColor() + it.setPrimaryTextColor(textColor) } }