Loading packages/SystemUI/shared/src/com/android/systemui/shared/regionsampling/RegionSamplingInstance.kt +31 −5 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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() } Loading @@ -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 Loading @@ -68,7 +94,7 @@ open class RegionSamplingInstance( } fun currentRegionDarkness(): RegionDarkness { return isDark return regionDarkness } /** Loading Loading @@ -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() } /** Loading packages/SystemUI/src/com/android/systemui/statusbar/lockscreen/LockscreenSmartspaceController.kt +13 −10 Original line number Diff line number Diff line Loading @@ -118,6 +118,7 @@ class LockscreenSmartspaceController @Inject constructor( regionSamplingEnabled, updateFun ) initializeTextColors(regionSamplingInstance) regionSamplingInstance.startRegionSampler() regionSamplingInstances.put(v, regionSamplingInstance) connectSession() Loading Loading @@ -361,18 +362,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) } } Loading Loading
packages/SystemUI/shared/src/com/android/systemui/shared/regionsampling/RegionSamplingInstance.kt +31 −5 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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() } Loading @@ -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 Loading @@ -68,7 +94,7 @@ open class RegionSamplingInstance( } fun currentRegionDarkness(): RegionDarkness { return isDark return regionDarkness } /** Loading Loading @@ -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() } /** Loading
packages/SystemUI/src/com/android/systemui/statusbar/lockscreen/LockscreenSmartspaceController.kt +13 −10 Original line number Diff line number Diff line Loading @@ -118,6 +118,7 @@ class LockscreenSmartspaceController @Inject constructor( regionSamplingEnabled, updateFun ) initializeTextColors(regionSamplingInstance) regionSamplingInstance.startRegionSampler() regionSamplingInstances.put(v, regionSamplingInstance) connectSession() Loading Loading @@ -361,18 +362,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) } } Loading