From 8c9dea270bae6fdff8b24b29e4e0aa54e5b254af Mon Sep 17 00:00:00 2001 From: Jordan Demeulenaere Date: Tue, 3 May 2022 16:16:09 +0200 Subject: [PATCH] Introduce the SystemUIComposeCore library (1/2) This CL introduces the SystemUIComposeCore library, which will contain all generic Compose code used by SystemUI. This include theme definition, base composables, modifiers, etc. Bug: 231131244 Test: atest SystemUIComposeCoreTests Change-Id: Ib1162bfa7b5dcef8d5a258dd92eb9fb878e16bbc --- packages/SystemUI/compose/core/Android.bp | 38 +++++++++++++++ .../SystemUI/compose/core/AndroidManifest.xml | 22 +++++++++ packages/SystemUI/compose/core/TEST_MAPPING | 15 ++++++ .../systemui/compose/theme/SystemUITheme.kt | 48 +++++++++++++++++++ .../SystemUI/compose/core/tests/Android.bp | 48 +++++++++++++++++++ .../compose/core/tests/AndroidManifest.xml | 28 +++++++++++ .../compose/theme/SystemUIThemeTest.kt | 43 +++++++++++++++++ 7 files changed, 242 insertions(+) create mode 100644 packages/SystemUI/compose/core/Android.bp create mode 100644 packages/SystemUI/compose/core/AndroidManifest.xml create mode 100644 packages/SystemUI/compose/core/TEST_MAPPING create mode 100644 packages/SystemUI/compose/core/src/com/android/systemui/compose/theme/SystemUITheme.kt create mode 100644 packages/SystemUI/compose/core/tests/Android.bp create mode 100644 packages/SystemUI/compose/core/tests/AndroidManifest.xml create mode 100644 packages/SystemUI/compose/core/tests/src/com/android/systemui/compose/theme/SystemUIThemeTest.kt diff --git a/packages/SystemUI/compose/core/Android.bp b/packages/SystemUI/compose/core/Android.bp new file mode 100644 index 0000000000000..4cfe39225a9b4 --- /dev/null +++ b/packages/SystemUI/compose/core/Android.bp @@ -0,0 +1,38 @@ +// 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. + +package { + // See: http://go/android-license-faq + // A large-scale-change added 'default_applicable_licenses' to import + // all of the 'license_kinds' from "frameworks_base_packages_SystemUI_license" + // to get the below license kinds: + // SPDX-license-identifier-Apache-2.0 + default_applicable_licenses: ["frameworks_base_packages_SystemUI_license"], +} + +android_library { + name: "SystemUIComposeCore", + manifest: "AndroidManifest.xml", + + srcs: [ + "src/**/*.kt", + ], + + static_libs: [ + "androidx.compose.runtime_runtime", + "androidx.compose.material3_material3", + ], + + kotlincflags: ["-Xjvm-default=all"], +} diff --git a/packages/SystemUI/compose/core/AndroidManifest.xml b/packages/SystemUI/compose/core/AndroidManifest.xml new file mode 100644 index 0000000000000..83c442d2d6f24 --- /dev/null +++ b/packages/SystemUI/compose/core/AndroidManifest.xml @@ -0,0 +1,22 @@ + + + + + + + diff --git a/packages/SystemUI/compose/core/TEST_MAPPING b/packages/SystemUI/compose/core/TEST_MAPPING new file mode 100644 index 0000000000000..92a654a63228c --- /dev/null +++ b/packages/SystemUI/compose/core/TEST_MAPPING @@ -0,0 +1,15 @@ +{ + "presubmit": [ + { + "name": "SystemUIComposeCoreTests", + "options": [ + { + "exclude-annotation": "org.junit.Ignore" + }, + { + "exclude-annotation": "androidx.test.filters.FlakyTest" + } + ] + } + ] +} \ No newline at end of file diff --git a/packages/SystemUI/compose/core/src/com/android/systemui/compose/theme/SystemUITheme.kt b/packages/SystemUI/compose/core/src/com/android/systemui/compose/theme/SystemUITheme.kt new file mode 100644 index 0000000000000..e4d1bcf0bf89a --- /dev/null +++ b/packages/SystemUI/compose/core/src/com/android/systemui/compose/theme/SystemUITheme.kt @@ -0,0 +1,48 @@ +/* + * 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. + */ + +package com.android.systemui.compose.theme + +import androidx.compose.foundation.isSystemInDarkTheme +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Typography +import androidx.compose.material3.dynamicDarkColorScheme +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. + */ +@Composable +fun SystemUITheme( + isDarkTheme: Boolean = isSystemInDarkTheme(), + content: @Composable () -> Unit, +) { + val context = LocalContext.current + + // TODO(b/230605885): Define our typography and color scheme. + val colorScheme = if (isDarkTheme) { + dynamicDarkColorScheme(context) + } else { + dynamicLightColorScheme(context) + } + val typography = Typography() + + MaterialTheme(colorScheme, typography) { + content() + } +} \ No newline at end of file diff --git a/packages/SystemUI/compose/core/tests/Android.bp b/packages/SystemUI/compose/core/tests/Android.bp new file mode 100644 index 0000000000000..f8023e2519f82 --- /dev/null +++ b/packages/SystemUI/compose/core/tests/Android.bp @@ -0,0 +1,48 @@ +// 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. + +package { + // See: http://go/android-license-faq + // A large-scale-change added 'default_applicable_licenses' to import + // all of the 'license_kinds' from "frameworks_base_packages_SystemUI_license" + // to get the below license kinds: + // SPDX-license-identifier-Apache-2.0 + default_applicable_licenses: ["frameworks_base_packages_SystemUI_license"], +} + +// TODO(b/230606318): Make those host tests instead of device tests. +android_test { + name: "SystemUIComposeCoreTests", + manifest: "AndroidManifest.xml", + test_suites: ["device-tests"], + sdk_version: "current", + certificate: "platform", + + srcs: [ + "src/**/*.kt", + ], + + static_libs: [ + "SystemUIComposeCore", + + "androidx.test.runner", + "androidx.test.ext.junit", + + "androidx.compose.runtime_runtime", + "androidx.compose.ui_ui-test-junit4", + "androidx.compose.ui_ui-test-manifest", + ], + + kotlincflags: ["-Xjvm-default=enable"], +} diff --git a/packages/SystemUI/compose/core/tests/AndroidManifest.xml b/packages/SystemUI/compose/core/tests/AndroidManifest.xml new file mode 100644 index 0000000000000..729ab989cdc0c --- /dev/null +++ b/packages/SystemUI/compose/core/tests/AndroidManifest.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/SystemUI/compose/core/tests/src/com/android/systemui/compose/theme/SystemUIThemeTest.kt b/packages/SystemUI/compose/core/tests/src/com/android/systemui/compose/theme/SystemUIThemeTest.kt new file mode 100644 index 0000000000000..f1b9e9f58680a --- /dev/null +++ b/packages/SystemUI/compose/core/tests/src/com/android/systemui/compose/theme/SystemUIThemeTest.kt @@ -0,0 +1,43 @@ +/* + * 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. + */ + +package com.android.systemui.compose.theme + +import androidx.compose.material3.Text +import androidx.compose.ui.test.assertIsDisplayed +import androidx.compose.ui.test.junit4.createComposeRule +import androidx.compose.ui.test.onNodeWithText +import androidx.test.ext.junit.runners.AndroidJUnit4 +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith + +@RunWith(AndroidJUnit4::class) +class SystemUIThemeTest { + @get:Rule + val composeRule = createComposeRule() + + @Test + fun testThemeShowsContent() { + composeRule.setContent { + SystemUITheme { + Text("foo") + } + } + + composeRule.onNodeWithText("foo").assertIsDisplayed() + } +} \ No newline at end of file