Loading packages/SystemUI/compose/core/src/com/android/systemui/compose/SystemUiController.kt +36 −43 Original line number Diff line number Diff line Loading @@ -35,15 +35,16 @@ import androidx.core.view.ViewCompat import androidx.core.view.WindowCompat import androidx.core.view.WindowInsetsCompat /*************************************************************************************************** /** * ************************************************************************************************* * This file was forked from * https://github.com/google/accompanist/blob/main/systemuicontroller/src/main/java/com/google/accompanist/systemuicontroller/SystemUiController.kt * and will be removed once it lands in AndroidX. **************************************************************************************************/ */ /** * A class which provides easy-to-use utilities for updating the System UI bar * colors within Jetpack Compose. * A class which provides easy-to-use utilities for updating the System UI bar colors within Jetpack * Compose. * * @sample com.google.accompanist.sample.systemuicontroller.SystemUiControllerSample */ Loading Loading @@ -98,9 +99,9 @@ interface SystemUiController { * and [Color.Transparent] will be used on API 29+ where gesture navigation is preferred or the * system UI automatically applies background protection in other navigation modes. * @param darkIcons Whether dark navigation bar icons would be preferable. * @param navigationBarContrastEnforced Whether the system should ensure that the navigation * bar has enough contrast when a fully transparent background is requested. Only supported on * API 29+. * @param navigationBarContrastEnforced Whether the system should ensure that the navigation bar * has enough contrast when a fully transparent background is requested. Only supported on API * 29+. * @param transformColorForLightContent A lambda which will be invoked to transform [color] if * dark icons were requested but are not available. Defaults to applying a black scrim. * Loading Loading @@ -135,14 +136,10 @@ interface SystemUiController { ) } /** * Property which holds whether the status bar icons + content are 'dark' or not. */ /** Property which holds whether the status bar icons + content are 'dark' or not. */ var statusBarDarkContentEnabled: Boolean /** * Property which holds whether the navigation bar icons + content are 'dark' or not. */ /** Property which holds whether the navigation bar icons + content are 'dark' or not. */ var navigationBarDarkContentEnabled: Boolean /** Loading @@ -157,8 +154,8 @@ interface SystemUiController { /** * Property which holds whether the system is ensuring that the navigation bar has enough * contrast when a fully transparent background is requested. Only has an affect when running * on Android API 29+ devices. * contrast when a fully transparent background is requested. Only has an affect when running on * Android API 29+ devices. */ var isNavigationBarContrastEnforced: Boolean } Loading Loading @@ -202,13 +199,9 @@ private tailrec fun Context.findWindow(): Window? = * * Typically you would use [rememberSystemUiController] to remember an instance of this. */ internal class AndroidSystemUiController( private val view: View, private val window: Window? ) : SystemUiController { private val windowInsetsController = window?.let { WindowCompat.getInsetsController(it, view) } internal class AndroidSystemUiController(private val view: View, private val window: Window?) : SystemUiController { private val windowInsetsController = window?.let { WindowCompat.getInsetsController(it, view) } override fun setStatusBarColor( color: Color, Loading @@ -217,11 +210,12 @@ internal class AndroidSystemUiController( ) { statusBarDarkContentEnabled = darkIcons window?.statusBarColor = when { window?.statusBarColor = when { darkIcons && windowInsetsController?.isAppearanceLightStatusBars != true -> { // If we're set to use dark icons, but our windowInsetsController call didn't // succeed (usually due to API level), we instead transform the color to maintain // contrast // succeed (usually due to API level), we instead transform the color to // maintain contrast transformColorForLightContent(color) } else -> color Loading @@ -237,11 +231,12 @@ internal class AndroidSystemUiController( navigationBarDarkContentEnabled = darkIcons isNavigationBarContrastEnforced = navigationBarContrastEnforced window?.navigationBarColor = when { window?.navigationBarColor = when { darkIcons && windowInsetsController?.isAppearanceLightNavigationBars != true -> { // If we're set to use dark icons, but our windowInsetsController call didn't // succeed (usually due to API level), we instead transform the color to maintain // contrast // succeed (usually due to API level), we instead transform the color to // maintain contrast transformColorForLightContent(color) } else -> color Loading Loading @@ -296,6 +291,4 @@ internal class AndroidSystemUiController( } private val BlackScrim = Color(0f, 0f, 0f, 0.3f) // 30% opaque black private val BlackScrimmed: (Color) -> Color = { original -> BlackScrim.compositeOver(original) } No newline at end of file private val BlackScrimmed: (Color) -> Color = { original -> BlackScrim.compositeOver(original) } packages/SystemUI/compose/core/src/com/android/systemui/compose/theme/SystemUITheme.kt +9 −12 Original line number Diff line number Diff line Loading @@ -24,9 +24,7 @@ import androidx.compose.material3.dynamicLightColorScheme import androidx.compose.runtime.Composable import androidx.compose.ui.platform.LocalContext /** * The Material 3 theme that should wrap all SystemUI Composables. */ /** The Material 3 theme that should wrap all SystemUI Composables. */ @Composable fun SystemUITheme( isDarkTheme: Boolean = isSystemInDarkTheme(), Loading @@ -35,14 +33,13 @@ fun SystemUITheme( val context = LocalContext.current // TODO(b/230605885): Define our typography and color scheme. val colorScheme = if (isDarkTheme) { val colorScheme = if (isDarkTheme) { dynamicDarkColorScheme(context) } else { dynamicLightColorScheme(context) } val typography = Typography() MaterialTheme(colorScheme, typography) { content() } MaterialTheme(colorScheme, typography) { content() } } packages/SystemUI/compose/core/tests/src/com/android/systemui/compose/theme/SystemUIThemeTest.kt +3 −8 Original line number Diff line number Diff line Loading @@ -27,16 +27,11 @@ import org.junit.runner.RunWith @RunWith(AndroidJUnit4::class) class SystemUIThemeTest { @get:Rule val composeRule = createComposeRule() @get:Rule val composeRule = createComposeRule() @Test fun testThemeShowsContent() { composeRule.setContent { SystemUITheme { Text("foo") } } composeRule.setContent { SystemUITheme { Text("foo") } } composeRule.onNodeWithText("foo").assertIsDisplayed() } Loading packages/SystemUI/compose/features/src/com/android/systemui/ExampleFeature.kt +2 −4 Original line number Diff line number Diff line Loading @@ -44,9 +44,7 @@ fun ExampleFeature(text: String, modifier: Modifier = Modifier) { ) { var count by remember { mutableStateOf(0) } Column( Modifier .clickable { count++ } .padding(16.dp), Modifier.clickable { count++ }.padding(16.dp), ) { Text(text) Text("I was clicked $count times.") Loading packages/SystemUI/compose/features/tests/src/com/android/systemui/ExampleFeatureTest.kt +5 −12 Original line number Diff line number Diff line Loading @@ -27,27 +27,20 @@ import org.junit.runner.RunWith @RunWith(AndroidJUnit4::class) class ExampleFeatureTest { @get:Rule val composeRule = createComposeRule() @get:Rule val composeRule = createComposeRule() @Test fun testProvidedTextIsDisplayed() { composeRule.setContent { ExampleFeature("foo") } composeRule.setContent { ExampleFeature("foo") } composeRule.onNodeWithText("foo").assertIsDisplayed() } @Test fun testCountIsIncreasedWhenClicking() { composeRule.setContent { ExampleFeature("foo") } composeRule.setContent { ExampleFeature("foo") } composeRule.onNodeWithText("I was clicked 0 times.") .assertIsDisplayed() .performClick() composeRule.onNodeWithText("I was clicked 0 times.").assertIsDisplayed().performClick() composeRule.onNodeWithText("I was clicked 1 times.").assertIsDisplayed() } } Loading
packages/SystemUI/compose/core/src/com/android/systemui/compose/SystemUiController.kt +36 −43 Original line number Diff line number Diff line Loading @@ -35,15 +35,16 @@ import androidx.core.view.ViewCompat import androidx.core.view.WindowCompat import androidx.core.view.WindowInsetsCompat /*************************************************************************************************** /** * ************************************************************************************************* * This file was forked from * https://github.com/google/accompanist/blob/main/systemuicontroller/src/main/java/com/google/accompanist/systemuicontroller/SystemUiController.kt * and will be removed once it lands in AndroidX. **************************************************************************************************/ */ /** * A class which provides easy-to-use utilities for updating the System UI bar * colors within Jetpack Compose. * A class which provides easy-to-use utilities for updating the System UI bar colors within Jetpack * Compose. * * @sample com.google.accompanist.sample.systemuicontroller.SystemUiControllerSample */ Loading Loading @@ -98,9 +99,9 @@ interface SystemUiController { * and [Color.Transparent] will be used on API 29+ where gesture navigation is preferred or the * system UI automatically applies background protection in other navigation modes. * @param darkIcons Whether dark navigation bar icons would be preferable. * @param navigationBarContrastEnforced Whether the system should ensure that the navigation * bar has enough contrast when a fully transparent background is requested. Only supported on * API 29+. * @param navigationBarContrastEnforced Whether the system should ensure that the navigation bar * has enough contrast when a fully transparent background is requested. Only supported on API * 29+. * @param transformColorForLightContent A lambda which will be invoked to transform [color] if * dark icons were requested but are not available. Defaults to applying a black scrim. * Loading Loading @@ -135,14 +136,10 @@ interface SystemUiController { ) } /** * Property which holds whether the status bar icons + content are 'dark' or not. */ /** Property which holds whether the status bar icons + content are 'dark' or not. */ var statusBarDarkContentEnabled: Boolean /** * Property which holds whether the navigation bar icons + content are 'dark' or not. */ /** Property which holds whether the navigation bar icons + content are 'dark' or not. */ var navigationBarDarkContentEnabled: Boolean /** Loading @@ -157,8 +154,8 @@ interface SystemUiController { /** * Property which holds whether the system is ensuring that the navigation bar has enough * contrast when a fully transparent background is requested. Only has an affect when running * on Android API 29+ devices. * contrast when a fully transparent background is requested. Only has an affect when running on * Android API 29+ devices. */ var isNavigationBarContrastEnforced: Boolean } Loading Loading @@ -202,13 +199,9 @@ private tailrec fun Context.findWindow(): Window? = * * Typically you would use [rememberSystemUiController] to remember an instance of this. */ internal class AndroidSystemUiController( private val view: View, private val window: Window? ) : SystemUiController { private val windowInsetsController = window?.let { WindowCompat.getInsetsController(it, view) } internal class AndroidSystemUiController(private val view: View, private val window: Window?) : SystemUiController { private val windowInsetsController = window?.let { WindowCompat.getInsetsController(it, view) } override fun setStatusBarColor( color: Color, Loading @@ -217,11 +210,12 @@ internal class AndroidSystemUiController( ) { statusBarDarkContentEnabled = darkIcons window?.statusBarColor = when { window?.statusBarColor = when { darkIcons && windowInsetsController?.isAppearanceLightStatusBars != true -> { // If we're set to use dark icons, but our windowInsetsController call didn't // succeed (usually due to API level), we instead transform the color to maintain // contrast // succeed (usually due to API level), we instead transform the color to // maintain contrast transformColorForLightContent(color) } else -> color Loading @@ -237,11 +231,12 @@ internal class AndroidSystemUiController( navigationBarDarkContentEnabled = darkIcons isNavigationBarContrastEnforced = navigationBarContrastEnforced window?.navigationBarColor = when { window?.navigationBarColor = when { darkIcons && windowInsetsController?.isAppearanceLightNavigationBars != true -> { // If we're set to use dark icons, but our windowInsetsController call didn't // succeed (usually due to API level), we instead transform the color to maintain // contrast // succeed (usually due to API level), we instead transform the color to // maintain contrast transformColorForLightContent(color) } else -> color Loading Loading @@ -296,6 +291,4 @@ internal class AndroidSystemUiController( } private val BlackScrim = Color(0f, 0f, 0f, 0.3f) // 30% opaque black private val BlackScrimmed: (Color) -> Color = { original -> BlackScrim.compositeOver(original) } No newline at end of file private val BlackScrimmed: (Color) -> Color = { original -> BlackScrim.compositeOver(original) }
packages/SystemUI/compose/core/src/com/android/systemui/compose/theme/SystemUITheme.kt +9 −12 Original line number Diff line number Diff line Loading @@ -24,9 +24,7 @@ import androidx.compose.material3.dynamicLightColorScheme import androidx.compose.runtime.Composable import androidx.compose.ui.platform.LocalContext /** * The Material 3 theme that should wrap all SystemUI Composables. */ /** The Material 3 theme that should wrap all SystemUI Composables. */ @Composable fun SystemUITheme( isDarkTheme: Boolean = isSystemInDarkTheme(), Loading @@ -35,14 +33,13 @@ fun SystemUITheme( val context = LocalContext.current // TODO(b/230605885): Define our typography and color scheme. val colorScheme = if (isDarkTheme) { val colorScheme = if (isDarkTheme) { dynamicDarkColorScheme(context) } else { dynamicLightColorScheme(context) } val typography = Typography() MaterialTheme(colorScheme, typography) { content() } MaterialTheme(colorScheme, typography) { content() } }
packages/SystemUI/compose/core/tests/src/com/android/systemui/compose/theme/SystemUIThemeTest.kt +3 −8 Original line number Diff line number Diff line Loading @@ -27,16 +27,11 @@ import org.junit.runner.RunWith @RunWith(AndroidJUnit4::class) class SystemUIThemeTest { @get:Rule val composeRule = createComposeRule() @get:Rule val composeRule = createComposeRule() @Test fun testThemeShowsContent() { composeRule.setContent { SystemUITheme { Text("foo") } } composeRule.setContent { SystemUITheme { Text("foo") } } composeRule.onNodeWithText("foo").assertIsDisplayed() } Loading
packages/SystemUI/compose/features/src/com/android/systemui/ExampleFeature.kt +2 −4 Original line number Diff line number Diff line Loading @@ -44,9 +44,7 @@ fun ExampleFeature(text: String, modifier: Modifier = Modifier) { ) { var count by remember { mutableStateOf(0) } Column( Modifier .clickable { count++ } .padding(16.dp), Modifier.clickable { count++ }.padding(16.dp), ) { Text(text) Text("I was clicked $count times.") Loading
packages/SystemUI/compose/features/tests/src/com/android/systemui/ExampleFeatureTest.kt +5 −12 Original line number Diff line number Diff line Loading @@ -27,27 +27,20 @@ import org.junit.runner.RunWith @RunWith(AndroidJUnit4::class) class ExampleFeatureTest { @get:Rule val composeRule = createComposeRule() @get:Rule val composeRule = createComposeRule() @Test fun testProvidedTextIsDisplayed() { composeRule.setContent { ExampleFeature("foo") } composeRule.setContent { ExampleFeature("foo") } composeRule.onNodeWithText("foo").assertIsDisplayed() } @Test fun testCountIsIncreasedWhenClicking() { composeRule.setContent { ExampleFeature("foo") } composeRule.setContent { ExampleFeature("foo") } composeRule.onNodeWithText("I was clicked 0 times.") .assertIsDisplayed() .performClick() composeRule.onNodeWithText("I was clicked 0 times.").assertIsDisplayed().performClick() composeRule.onNodeWithText("I was clicked 1 times.").assertIsDisplayed() } }