Loading packages/SystemUI/compose/features/src/com/android/systemui/ExampleFeature.kt +42 −1 Original line number Diff line number Diff line Loading @@ -17,8 +17,12 @@ package com.android.systemui import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.BoxWithConstraints import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Surface Loading @@ -29,14 +33,37 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp import kotlin.math.roundToInt /** * This is an example Compose feature, which shows a text and a count that is incremented when * clicked. * clicked. We also show the max width available to this component, which is displayed either next * to or below the text depending on that max width. */ @Composable fun ExampleFeature(text: String, modifier: Modifier = Modifier) { BoxWithConstraints(modifier) { val maxWidth = maxWidth if (maxWidth < 600.dp) { Column { CounterTile(text) Spacer(Modifier.size(16.dp)) MaxWidthTile(maxWidth) } } else { Row { CounterTile(text) Spacer(Modifier.size(16.dp)) MaxWidthTile(maxWidth) } } } } @Composable private fun CounterTile(text: String, modifier: Modifier = Modifier) { Surface( modifier, color = MaterialTheme.colorScheme.primaryContainer, Loading @@ -51,3 +78,17 @@ fun ExampleFeature(text: String, modifier: Modifier = Modifier) { } } } @Composable private fun MaxWidthTile(maxWidth: Dp, modifier: Modifier = Modifier) { Surface( modifier, color = MaterialTheme.colorScheme.tertiaryContainer, shape = RoundedCornerShape(28.dp), ) { Text( "The max available width to me is: ${maxWidth.value.roundToInt()}dp", Modifier.padding(16.dp) ) } } packages/SystemUI/compose/gallery/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -52,6 +52,7 @@ android_library { android_app { name: "SystemUIComposeGallery", defaults: ["platform_app_defaults"], manifest: "app/AndroidManifest.xml", static_libs: [ "SystemUIComposeGalleryLib", Loading packages/SystemUI/compose/gallery/AndroidManifest.xml +1 −17 Original line number Diff line number Diff line Loading @@ -17,21 +17,5 @@ <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.android.systemui.compose.gallery"> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/Theme.SystemUIGallery"> <activity android:name=".GalleryActivity" android:exported="true" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> packages/SystemUI/compose/gallery/app/AndroidManifest.xml 0 → 100644 +37 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2022 The Android Open Source Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.android.systemui.compose.gallery"> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/Theme.SystemUIGallery"> <activity android:name=".GalleryActivity" android:exported="true" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> packages/SystemUI/compose/gallery/src/com/android/systemui/compose/gallery/ExampleFeatureScreen.kt +3 −2 Original line number Diff line number Diff line Loading @@ -18,10 +18,11 @@ package com.android.systemui.compose.gallery import androidx.compose.foundation.layout.Column import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import com.android.systemui.ExampleFeature /** The screen that shows ExampleFeature. */ @Composable fun ExampleFeatureScreen() { Column { ExampleFeature("This is an example feature!") } fun ExampleFeatureScreen(modifier: Modifier = Modifier) { Column(modifier) { ExampleFeature("This is an example feature!") } } Loading
packages/SystemUI/compose/features/src/com/android/systemui/ExampleFeature.kt +42 −1 Original line number Diff line number Diff line Loading @@ -17,8 +17,12 @@ package com.android.systemui import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.BoxWithConstraints import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Surface Loading @@ -29,14 +33,37 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp import kotlin.math.roundToInt /** * This is an example Compose feature, which shows a text and a count that is incremented when * clicked. * clicked. We also show the max width available to this component, which is displayed either next * to or below the text depending on that max width. */ @Composable fun ExampleFeature(text: String, modifier: Modifier = Modifier) { BoxWithConstraints(modifier) { val maxWidth = maxWidth if (maxWidth < 600.dp) { Column { CounterTile(text) Spacer(Modifier.size(16.dp)) MaxWidthTile(maxWidth) } } else { Row { CounterTile(text) Spacer(Modifier.size(16.dp)) MaxWidthTile(maxWidth) } } } } @Composable private fun CounterTile(text: String, modifier: Modifier = Modifier) { Surface( modifier, color = MaterialTheme.colorScheme.primaryContainer, Loading @@ -51,3 +78,17 @@ fun ExampleFeature(text: String, modifier: Modifier = Modifier) { } } } @Composable private fun MaxWidthTile(maxWidth: Dp, modifier: Modifier = Modifier) { Surface( modifier, color = MaterialTheme.colorScheme.tertiaryContainer, shape = RoundedCornerShape(28.dp), ) { Text( "The max available width to me is: ${maxWidth.value.roundToInt()}dp", Modifier.padding(16.dp) ) } }
packages/SystemUI/compose/gallery/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -52,6 +52,7 @@ android_library { android_app { name: "SystemUIComposeGallery", defaults: ["platform_app_defaults"], manifest: "app/AndroidManifest.xml", static_libs: [ "SystemUIComposeGalleryLib", Loading
packages/SystemUI/compose/gallery/AndroidManifest.xml +1 −17 Original line number Diff line number Diff line Loading @@ -17,21 +17,5 @@ <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.android.systemui.compose.gallery"> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/Theme.SystemUIGallery"> <activity android:name=".GalleryActivity" android:exported="true" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
packages/SystemUI/compose/gallery/app/AndroidManifest.xml 0 → 100644 +37 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2022 The Android Open Source Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.android.systemui.compose.gallery"> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/Theme.SystemUIGallery"> <activity android:name=".GalleryActivity" android:exported="true" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
packages/SystemUI/compose/gallery/src/com/android/systemui/compose/gallery/ExampleFeatureScreen.kt +3 −2 Original line number Diff line number Diff line Loading @@ -18,10 +18,11 @@ package com.android.systemui.compose.gallery import androidx.compose.foundation.layout.Column import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import com.android.systemui.ExampleFeature /** The screen that shows ExampleFeature. */ @Composable fun ExampleFeatureScreen() { Column { ExampleFeature("This is an example feature!") } fun ExampleFeatureScreen(modifier: Modifier = Modifier) { Column(modifier) { ExampleFeature("This is an example feature!") } }