summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Wenbo Jie <wenbojie@google.com> 2024-10-17 06:42:30 +0000
committer Wenbo Jie <wenbojie@google.com> 2024-10-24 00:38:42 +0000
commite307c50977d306b0770e4d17725345c573087b57 (patch)
tree1ad1d30db67fcb66662d69fa75faeca7912877df
parent73347e5f39962c54165348ed1faffc13f262d130 (diff)
[DocsUI M3] Add compose folder to experiment compose
Add a new folder "compose" inside DocumentsUI so we can have a isolate environment to experiment constructing Jetpack Compose components. It's independent from the original DocumentsUI and has its own build target. We could use this as a Compose Lab to build component here first and then reuse it in the original DocumentsUI. Bug: 374224390 Test: m DocumentsUICompose Flag: EXEMPT experiment for dev only Change-Id: I33d61d47889e16c39aa92de082c2fdba2193461b
-rw-r--r--compose/Android.bp60
-rw-r--r--compose/AndroidManifest.xml58
-rw-r--r--compose/OWNERS6
-rw-r--r--compose/README12
-rw-r--r--compose/res/values/strings.xml19
-rw-r--r--compose/src/com/android/documentsui/compose/MainActivity.kt46
-rw-r--r--compose/src/com/android/documentsui/compose/Theme.kt48
7 files changed, 249 insertions, 0 deletions
diff --git a/compose/Android.bp b/compose/Android.bp
new file mode 100644
index 000000000..072aa167d
--- /dev/null
+++ b/compose/Android.bp
@@ -0,0 +1,60 @@
+// Copyright (C) 2024 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 {
+ default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
+android_library {
+ name: "DocumentsUIComposelib",
+ manifest: "AndroidManifest.xml",
+
+ resource_dirs: [
+ "res",
+ ],
+ srcs: [
+ "src/**/*.kt",
+ ],
+
+ static_libs: [
+ "androidx.activity_activity-compose",
+ "androidx.appcompat_appcompat",
+ "androidx.compose.foundation_foundation",
+ "androidx.compose.material3_material3",
+ "androidx.compose.material3_material3-window-size-class",
+ "androidx.compose.material_material-icons-extended",
+ "androidx.compose.runtime_runtime",
+ "androidx.compose.ui_ui",
+ "androidx.core_core-ktx",
+ "androidx.lifecycle_lifecycle-runtime-compose",
+ "androidx.lifecycle_lifecycle-runtime-ktx",
+ "modules-utils-build_system",
+ ],
+
+ sdk_version: "system_current",
+ target_sdk_version: "33",
+ min_sdk_version: "29",
+}
+
+android_app {
+ name: "DocumentsUICompose",
+ manifest: "AndroidManifest.xml",
+ static_libs: ["DocumentsUIComposelib"],
+
+ privileged: true,
+ certificate: "platform",
+
+ sdk_version: "system_current",
+ min_sdk_version: "29",
+}
diff --git a/compose/AndroidManifest.xml b/compose/AndroidManifest.xml
new file mode 100644
index 000000000..234f38e67
--- /dev/null
+++ b/compose/AndroidManifest.xml
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+ * Copyright (C) 2024 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.documentsui.compose">
+
+ <uses-sdk android:minSdkVersion="29"/>
+
+ <!-- Permissions copied from com.android.documentsui AndroidManifest.xml -->
+ <uses-permission android:name="android.permission.MANAGE_DOCUMENTS" />
+ <uses-permission android:name="android.permission.REMOVE_TASKS" />
+ <uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
+ <uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC"/>
+ <uses-permission android:name="android.permission.WAKE_LOCK" />
+ <uses-permission android:name="android.permission.CACHE_CONTENT" />
+ <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
+ <uses-permission android:name="android.permission.CHANGE_OVERLAY_PACKAGES" />
+ <uses-permission android:name="android.permission.INTERACT_ACROSS_USERS" />
+ <uses-permission android:name="android.permission.MODIFY_QUIET_MODE" />
+ <uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />
+ <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
+ <uses-permission android:name="android.permission.HIDE_OVERLAY_WINDOWS"/>
+ <uses-permission android:name="android.permission.LOG_COMPAT_CHANGE"/>
+ <uses-permission android:name="android.permission.READ_COMPAT_CHANGE_CONFIG"/>
+ <uses-permission android:name="android.permission.START_FOREGROUND_SERVICES_FROM_BACKGROUND"/>
+ <uses-permission android:name="android.permission.READ_DEVICE_CONFIG"/>
+
+ <application
+ android:label="@string/app_label"
+ android:supportsRtl="true"
+ android:allowBackup="true">
+
+ <activity
+ android:name=".MainActivity"
+ android:exported="true">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+
+ </application>
+</manifest>
diff --git a/compose/OWNERS b/compose/OWNERS
new file mode 100644
index 000000000..ee4568b02
--- /dev/null
+++ b/compose/OWNERS
@@ -0,0 +1,6 @@
+# Bug component: 374224390
+
+wenbojie@google.com
+benreich@google.com
+lucmult@google.com
+tylersaunders@google.com
diff --git a/compose/README b/compose/README
new file mode 100644
index 000000000..5ccfbeda3
--- /dev/null
+++ b/compose/README
@@ -0,0 +1,12 @@
+This folder is intended for Sydney Files team to experiment constructing Jetpack Compose components
+for DocumentsUI.
+
+## Build and Install
+
+Use `brya` target as an example.
+
+```bash
+lunch brya-trunk_staging-eng
+m DocumentsUICompose
+adb install out/target/product/brya/system/priv-app/DocumentsUICompose/DocumentsUICompose.apk
+``` \ No newline at end of file
diff --git a/compose/res/values/strings.xml b/compose/res/values/strings.xml
new file mode 100644
index 000000000..a7acb0e66
--- /dev/null
+++ b/compose/res/values/strings.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2024 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.
+-->
+
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <string name="app_label">DocsUI Compose</string>
+</resources> \ No newline at end of file
diff --git a/compose/src/com/android/documentsui/compose/MainActivity.kt b/compose/src/com/android/documentsui/compose/MainActivity.kt
new file mode 100644
index 000000000..4f0fd644d
--- /dev/null
+++ b/compose/src/com/android/documentsui/compose/MainActivity.kt
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2024 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.documentsui.compose
+
+import android.os.Bundle
+import androidx.activity.ComponentActivity
+import androidx.activity.compose.setContent
+import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.fillMaxSize
+import androidx.compose.material3.MaterialTheme
+import androidx.compose.material3.Surface
+import androidx.compose.material3.Text
+import androidx.compose.ui.Modifier
+
+class MainActivity : ComponentActivity() {
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+
+ setContent {
+ DocumentsUITheme {
+ Surface(
+ modifier = Modifier.fillMaxSize(),
+ color = MaterialTheme.colorScheme.background
+ ) {
+ Column {
+ Text(text = "DocumentsUI Compose")
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/compose/src/com/android/documentsui/compose/Theme.kt b/compose/src/com/android/documentsui/compose/Theme.kt
new file mode 100644
index 000000000..de6f7f34f
--- /dev/null
+++ b/compose/src/com/android/documentsui/compose/Theme.kt
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2024 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.documentsui.compose
+
+import androidx.compose.foundation.isSystemInDarkTheme
+import androidx.compose.material3.MaterialTheme
+import androidx.compose.material3.darkColorScheme
+import androidx.compose.material3.dynamicDarkColorScheme
+import androidx.compose.material3.dynamicLightColorScheme
+import androidx.compose.material3.lightColorScheme
+import androidx.compose.runtime.Composable
+import androidx.compose.ui.platform.LocalContext
+import com.android.modules.utils.build.SdkLevel
+
+@Composable
+fun DocumentsUITheme(
+ darkTheme: Boolean = isSystemInDarkTheme(),
+ dynamicColor: Boolean = true,
+ content: @Composable () -> Unit
+) {
+ val colorScheme = when {
+ dynamicColor && SdkLevel.isAtLeastS() -> {
+ val context = LocalContext.current
+ if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
+ }
+ darkTheme -> darkColorScheme()
+ else -> lightColorScheme()
+ }
+
+ MaterialTheme(
+ colorScheme = colorScheme,
+ content = content
+ )
+}