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

Commit d65dee81 authored by Alina Zaidi's avatar Alina Zaidi
Browse files

Revert^2 + fix tests for "Scale battery text size in shade in low display sizes."

This reverts commit 2239fa79 and corrects tests.

Reason for revert: Tests are not corrected, we are using ComposeTestRule instead of @Composable annotations. Ran the test locally and verified it passes

Bug: 438705602
Bug: 413620149
Change-Id: Ia4791f76426118ceeded17963933ebb9c65aa03b
parent 2239fa79
Loading
Loading
Loading
Loading
+52 −0
Original line number Diff line number Diff line
@@ -18,19 +18,29 @@ package com.android.systemui.statusbar.pipeline.battery.ui.viewmodel

import android.platform.test.annotations.DisableFlags
import android.platform.test.annotations.EnableFlags
import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.text.TextStyle
import com.android.systemui.Flags
import com.android.systemui.SysuiTestCase
import com.android.systemui.res.R
import com.android.systemui.statusbar.core.StatusBarConnectedDisplays
import com.google.common.truth.Truth.assertThat
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@SmallTest
@RunWith(AndroidJUnit4::class)
@OptIn(ExperimentalMaterial3ExpressiveApi::class) // Required for bodyMediumEmphasized style
class BatteryViewModelTest : SysuiTestCase() {

    @get:Rule val rule = createComposeRule()

    @Test
    @DisableFlags(StatusBarConnectedDisplays.FLAG_NAME)
    fun getStatusBarBatteryHeight_flagDisabled_scaleIsOne_returnsDefaultHeight() {
@@ -70,4 +80,46 @@ class BatteryViewModelTest : SysuiTestCase() {

        assertThat(height.value).isEqualTo(26f)
    }

    @Test
    @DisableFlags(Flags.FLAG_FIX_SHADE_HEADER_WRONG_ICON_SIZE)
    fun getStatusBarBatteryTextStyle_flagOff_scaleIsTwo_returnsDefautFontSize() {
        overrideResource(R.dimen.status_bar_icon_scale_factor, 2.0f)

        var baseFontSize: Float? = null
        var actualTextStyle: TextStyle? = null
        rule.setContent {
            baseFontSize = MaterialTheme.typography.bodyMediumEmphasized.fontSize.value
            actualTextStyle = BatteryViewModel.getStatusBarBatteryTextStyle(context)
        }
        assertThat(actualTextStyle!!.fontSize.value).isEqualTo(baseFontSize)
    }

    @Test
    @EnableFlags(Flags.FLAG_FIX_SHADE_HEADER_WRONG_ICON_SIZE)
    fun getStatusBarBatteryTextStyle_scaleIsOne_returnsDefaultFontSize() {
        overrideResource(R.dimen.status_bar_icon_scale_factor, 1.0f)

        var baseFontSize: Float? = null
        var actualTextStyle: TextStyle? = null
        rule.setContent {
            baseFontSize = MaterialTheme.typography.bodyMediumEmphasized.fontSize.value
            actualTextStyle = BatteryViewModel.getStatusBarBatteryTextStyle(context)
        }
        assertThat(actualTextStyle!!.fontSize.value).isEqualTo(baseFontSize)
    }

    @Test
    @EnableFlags(Flags.FLAG_FIX_SHADE_HEADER_WRONG_ICON_SIZE)
    fun getStatusBarBatteryTextStyle_scaleIsTwo_returnsScaledFontSize() {
        overrideResource(R.dimen.status_bar_icon_scale_factor, 2.0f)

        var baseFontSize: Float? = null
        var actualTextStyle: TextStyle? = null
        rule.setContent {
            baseFontSize = MaterialTheme.typography.bodyMediumEmphasized.fontSize.value
            actualTextStyle = BatteryViewModel.getStatusBarBatteryTextStyle(context)
        }
        assertThat(actualTextStyle!!.fontSize.value).isEqualTo(baseFontSize!! * 2)
    }
}
+6 −6
Original line number Diff line number Diff line
@@ -24,7 +24,6 @@ import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.wrapContentWidth
import androidx.compose.foundation.text.BasicText
import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
@@ -70,6 +69,11 @@ fun BatteryWithChargeStatus(
            BatteryViewModel.getStatusBarBatteryHeight(LocalContext.current).toDp()
        }

    val textStyle =
        with(LocalDensity.current) {
            BatteryViewModel.getStatusBarBatteryTextStyle(LocalContext.current)
        }

    var bounds by remember { mutableStateOf(Rect()) }

    Row(
@@ -120,11 +124,7 @@ fun BatteryWithChargeStatus(

            textToShow?.let {
                Spacer(modifier.width(4.dp))
                BasicText(
                    text = it,
                    color = colorProducer,
                    style = MaterialTheme.typography.bodyMediumEmphasized,
                )
                BasicText(text = it, color = colorProducer, style = textStyle)
            }
        }
    }
+6 −2
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.height
import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
@@ -52,6 +51,11 @@ fun BatteryWithEstimate(
            BatteryViewModel.getStatusBarBatteryHeight(LocalContext.current).toDp()
        }

    val textStyle =
        with(LocalDensity.current) {
            BatteryViewModel.getStatusBarBatteryTextStyle(LocalContext.current)
        }

    Row(
        modifier = modifier,
        horizontalArrangement = Arrangement.spacedBy(4.dp),
@@ -69,7 +73,7 @@ fun BatteryWithEstimate(
                Text(
                    text = it,
                    color = textColor,
                    style = MaterialTheme.typography.bodyMediumEmphasized,
                    style = textStyle,
                    maxLines = 1,
                    modifier = Modifier.basicMarquee(iterations = 1),
                )
+22 −0
Original line number Diff line number Diff line
@@ -17,9 +17,14 @@
package com.android.systemui.statusbar.pipeline.battery.ui.viewmodel

import android.content.Context
import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.sp
import com.android.systemui.Flags
import com.android.systemui.common.shared.model.ContentDescription
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.lifecycle.ExclusiveActivatable
@@ -308,6 +313,23 @@ sealed class BatteryViewModel(
            }
        }

        /**
         * [TextStyle] for status bar battery text [Composable]s. The size of this text will scale
         * consistent with display size changes
         */
        @OptIn(ExperimentalMaterial3ExpressiveApi::class) // Required for bodyMediumEmphasized style
        @Composable
        fun getStatusBarBatteryTextStyle(context: Context): TextStyle {
            val baseStyle = MaterialTheme.typography.bodyMediumEmphasized
            if (!Flags.fixShadeHeaderWrongIconSize()) {
                return baseStyle
            }

            val customStyle =
                baseStyle.copy(fontSize = baseStyle.fontSize * getScaleFactor(context))
            return customStyle
        }

        private fun getScaleFactor(context: Context): Float {
            return context.resources.getFloat(R.dimen.status_bar_icon_scale_factor)
        }