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

Commit 9c9c9e20 authored by Daniel Norman's avatar Daniel Norman
Browse files

cleanup: Rename and clarify some status bar icon tint methods.

See http://b/423390143#comment13 header (1).

Bug: 423390143
Test: N/A (presubmit, no logic change)
Flag: EXEMPT mechanical refactoring
Change-Id: I19a492679eecd84b1c656c02480bd656f22a9f56
parent 108ab7fc
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -55,7 +55,13 @@ public interface SysuiDarkIconDispatcher extends DarkIconDispatcher, Dumpable {
            this.tint = tint;
        }

        /**
         * Regions where icons should be dark. Icons outside of these regions should be light.
         * Note: This is empty if all icons should be the same color, regardless of light or dark.
         * This is only non-empty when some icons should be light and others dark.
         */
        public final Collection<Rect> areas;
        /** 0.0f = white icons, 1.0f = black icons */
        public final float darkIntensity;
        public final int tint;
    }
+15 −7
Original line number Diff line number Diff line
@@ -36,7 +36,7 @@ class DarkIconInteractor @Inject constructor(private val repository: DarkIconRep

    /**
     * Given a display id: returns a flow of [IsAreaDark], a function that can tell you if a given
     * [Rect] should be tinted dark or not. This flow ignores [DarkChange.tint] and
     * [Rect] should be tinted dark theme or not. This flow ignores [DarkChange.tint] and
     * [DarkChange.darkIntensity]
     */
    fun isAreaDark(displayId: Int): Flow<IsAreaDark> {
@@ -51,13 +51,18 @@ class DarkIconInteractor @Inject constructor(private val repository: DarkIconRep
        @JvmStatic
        fun Flow<DarkChange>.toIsAreaDark(): Flow<IsAreaDark> =
            map { darkChange ->
                    DarkStateWithoutIntensity(darkChange.areas, darkChange.darkIntensity < 0.5f)
                    // Note: DarkChange.darkIntensity is 0.0f when icons should be white (for dark
                    // theme) and 1.0f when icons should be black (for light theme).
                    DarkStateWithoutIntensity(
                        darkChange.areas,
                        isDarkTheme = darkChange.darkIntensity < 0.5f,
                    )
                }
                .distinctUntilChanged()
                .map { darkState ->
                    IsAreaDark { viewBounds: Rect ->
                        if (DarkIconDispatcher.isInAreas(darkState.areas, viewBounds)) {
                            darkState.isDark
                        if (DarkIconDispatcher.isInAreas(darkState.darkIconAreas, viewBounds)) {
                            darkState.isDarkTheme
                        } else {
                            false
                        }
@@ -69,9 +74,12 @@ class DarkIconInteractor @Inject constructor(private val repository: DarkIconRep
}

/** So we can map between [DarkState] and a single boolean, but based on intensity */
private data class DarkStateWithoutIntensity(val areas: Collection<Rect>, val isDark: Boolean)
private data class DarkStateWithoutIntensity(
    val darkIconAreas: Collection<Rect>,
    val isDarkTheme: Boolean,
)

/** Given a region on screen, determine if the foreground should be dark or light */
/** Given a region on screen, determine if content in this region should use dark or light theme */
fun interface IsAreaDark {
    fun isDark(viewBounds: Rect): Boolean
    fun isDarkTheme(viewBounds: Rect): Boolean
}
+2 −2
Original line number Diff line number Diff line
@@ -83,7 +83,7 @@ fun BatteryWithChargeStatus(
        val path = viewModel.batteryFrame

        val colorProvider = {
            if (isDarkProvider().isDark(bounds)) {
            if (isDarkProvider().isDarkTheme(bounds)) {
                viewModel.colorProfile.dark
            } else {
                viewModel.colorProfile.light
@@ -105,7 +105,7 @@ fun BatteryWithChargeStatus(
        if (shouldShowPercent(showPercentMode, viewModel)) {
            // The text can just use the Default.fill color, since we don't want to colorize it
            val colorProducer = {
                if (isDarkProvider().isDark(bounds)) {
                if (isDarkProvider().isDarkTheme(bounds)) {
                    BatteryColors.DarkTheme.Default.fill
                } else {
                    BatteryColors.LightTheme.Default.fill
+1 −1
Original line number Diff line number Diff line
@@ -170,7 +170,7 @@ fun UnifiedBattery(
    var bounds by remember { mutableStateOf(Rect()) }

    val colorProvider = {
        if (isDarkProvider().isDark(bounds)) {
        if (isDarkProvider().isDarkTheme(bounds)) {
            viewModel.colorProfile.dark
        } else {
            viewModel.colorProfile.light