Merge "Abstract out the logic to determine text color" into tm-qpr-dev am: e13d22fbcc
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/19758591 Change-Id: I5d48938e2e2cb05b91c1c6d860b2249a61bfa066 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.android.systemui.shared.regionsampling
|
package com.android.systemui.shared.regionsampling
|
||||||
|
|
||||||
|
import android.graphics.Color
|
||||||
import android.graphics.Rect
|
import android.graphics.Rect
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.annotation.VisibleForTesting
|
import androidx.annotation.VisibleForTesting
|
||||||
@@ -33,18 +34,19 @@ open class RegionSamplingInstance(
|
|||||||
regionSamplingEnabled: Boolean,
|
regionSamplingEnabled: Boolean,
|
||||||
updateFun: UpdateColorCallback
|
updateFun: UpdateColorCallback
|
||||||
) {
|
) {
|
||||||
private var isDark = RegionDarkness.DEFAULT
|
private var regionDarkness = RegionDarkness.DEFAULT
|
||||||
private var samplingBounds = Rect()
|
private var samplingBounds = Rect()
|
||||||
private val tmpScreenLocation = IntArray(2)
|
private val tmpScreenLocation = IntArray(2)
|
||||||
@VisibleForTesting var regionSampler: RegionSamplingHelper? = null
|
@VisibleForTesting var regionSampler: RegionSamplingHelper? = null
|
||||||
|
private var lightForegroundColor = Color.WHITE
|
||||||
|
private var darkForegroundColor = Color.BLACK
|
||||||
/**
|
/**
|
||||||
* Interface for method to be passed into RegionSamplingHelper
|
* Interface for method to be passed into RegionSamplingHelper
|
||||||
*/
|
*/
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
interface UpdateColorCallback {
|
interface UpdateColorCallback {
|
||||||
/**
|
/**
|
||||||
* Method to update the text colors after clock darkness changed.
|
* Method to update the foreground colors after clock darkness changed.
|
||||||
*/
|
*/
|
||||||
fun updateColors()
|
fun updateColors()
|
||||||
}
|
}
|
||||||
@@ -59,6 +61,30 @@ open class RegionSamplingInstance(
|
|||||||
return RegionSamplingHelper(sampledView, callback, mainExecutor, bgExecutor)
|
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 {
|
private fun convertToClockDarkness(isRegionDark: Boolean): RegionDarkness {
|
||||||
return if (isRegionDark) {
|
return if (isRegionDark) {
|
||||||
RegionDarkness.DARK
|
RegionDarkness.DARK
|
||||||
@@ -68,7 +94,7 @@ open class RegionSamplingInstance(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun currentRegionDarkness(): RegionDarkness {
|
fun currentRegionDarkness(): RegionDarkness {
|
||||||
return isDark
|
return regionDarkness
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -97,7 +123,7 @@ open class RegionSamplingInstance(
|
|||||||
regionSampler = createRegionSamplingHelper(sampledView,
|
regionSampler = createRegionSamplingHelper(sampledView,
|
||||||
object : SamplingCallback {
|
object : SamplingCallback {
|
||||||
override fun onRegionDarknessChanged(isRegionDark: Boolean) {
|
override fun onRegionDarknessChanged(isRegionDark: Boolean) {
|
||||||
isDark = convertToClockDarkness(isRegionDark)
|
regionDarkness = convertToClockDarkness(isRegionDark)
|
||||||
updateFun.updateColors()
|
updateFun.updateColors()
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -118,6 +118,7 @@ class LockscreenSmartspaceController @Inject constructor(
|
|||||||
regionSamplingEnabled,
|
regionSamplingEnabled,
|
||||||
updateFun
|
updateFun
|
||||||
)
|
)
|
||||||
|
initializeTextColors(regionSamplingInstance)
|
||||||
regionSamplingInstance.startRegionSampler()
|
regionSamplingInstance.startRegionSampler()
|
||||||
regionSamplingInstances.put(v, regionSamplingInstance)
|
regionSamplingInstances.put(v, regionSamplingInstance)
|
||||||
connectSession()
|
connectSession()
|
||||||
@@ -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() {
|
private fun updateTextColorFromRegionSampler() {
|
||||||
smartspaceViews.forEach {
|
smartspaceViews.forEach {
|
||||||
val isRegionDark = regionSamplingInstances.getValue(it).currentRegionDarkness()
|
val textColor = regionSamplingInstances.getValue(it).currentForegroundColor()
|
||||||
val themeID = if (isRegionDark.isDark) {
|
it.setPrimaryTextColor(textColor)
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user