[go: nahoru, domu]

Add Navigation Component

Add navigation dependency. It is the Compose navigation dependency which is required for
components such as the NavHostController in Compose.

Add Compose Icon dependency. This dependency allows us to access icons related to the camera.

Add ComposeCameraScreen enum. This enum denotes each destination we will have in the navigation graph.
We will use `Screen.name` as the route for navigation and each enum
will hold an Icon to display in the navigation tabs.

Add Navigation package which contains ComposeCameraScreen.kt and ComposeCameraNavHost.kt which contains a custom NavHost

Bug: 234080273
Test: n/a
Change-Id: Ie7150294ab4bc208e949152161f10736591c9aee
diff --git a/camera/integration-tests/uiwidgetstestapp/build.gradle b/camera/integration-tests/uiwidgetstestapp/build.gradle
index 57c2ba8..4879ddf 100644
--- a/camera/integration-tests/uiwidgetstestapp/build.gradle
+++ b/camera/integration-tests/uiwidgetstestapp/build.gradle
@@ -90,6 +90,8 @@
     implementation 'androidx.compose.animation:animation:1.1.1'
     implementation 'androidx.compose.ui:ui-tooling:1.1.1'
     implementation 'androidx.lifecycle:lifecycle-viewmodel-compose:2.4.1'
+    implementation 'androidx.navigation:navigation-compose:2.4.2'
+    implementation 'androidx.compose.material:material-icons-extended:1.1.1'
     androidTestImplementation 'androidx.compose.ui:ui-test-junit4:1.1.1'
 
     // Testing framework
diff --git a/camera/integration-tests/uiwidgetstestapp/src/main/java/androidx/camera/integration/uiwidgets/compose/ui/navigation/ComposeCameraNavHost.kt b/camera/integration-tests/uiwidgetstestapp/src/main/java/androidx/camera/integration/uiwidgets/compose/ui/navigation/ComposeCameraNavHost.kt
new file mode 100644
index 0000000..7516248
--- /dev/null
+++ b/camera/integration-tests/uiwidgetstestapp/src/main/java/androidx/camera/integration/uiwidgets/compose/ui/navigation/ComposeCameraNavHost.kt
@@ -0,0 +1,48 @@
+/*
+ * Copyright 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 androidx.camera.integration.uiwidgets.compose.ui.navigation
+
+import androidx.camera.integration.uiwidgets.compose.ui.Greeting
+import androidx.compose.runtime.Composable
+import androidx.compose.ui.Modifier
+import androidx.navigation.NavHostController
+import androidx.navigation.compose.NavHost
+import androidx.navigation.compose.composable
+
+@Composable
+fun ComposeCameraNavHost(
+    navController: NavHostController,
+    modifier: Modifier = Modifier
+) {
+    NavHost(
+        navController = navController,
+        startDestination = ComposeCameraScreen.ImageCapture.name,
+        modifier = modifier
+    ) {
+        composable(ComposeCameraScreen.ImageCapture.name) {
+            Greeting()
+        }
+
+        composable(ComposeCameraScreen.VideoCapture.name) {
+            Greeting()
+        }
+
+        composable(ComposeCameraScreen.Gallery.name) {
+            Greeting()
+        }
+    }
+}
\ No newline at end of file
diff --git a/camera/integration-tests/uiwidgetstestapp/src/main/java/androidx/camera/integration/uiwidgets/compose/ui/navigation/ComposeCameraScreen.kt b/camera/integration-tests/uiwidgetstestapp/src/main/java/androidx/camera/integration/uiwidgets/compose/ui/navigation/ComposeCameraScreen.kt
new file mode 100644
index 0000000..8923506
--- /dev/null
+++ b/camera/integration-tests/uiwidgetstestapp/src/main/java/androidx/camera/integration/uiwidgets/compose/ui/navigation/ComposeCameraScreen.kt
@@ -0,0 +1,51 @@
+/*
+ * Copyright 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 androidx.camera.integration.uiwidgets.compose.ui.navigation
+
+import androidx.compose.material.icons.Icons
+import androidx.compose.material.icons.filled.CameraAlt
+import androidx.compose.material.icons.filled.PhotoLibrary
+import androidx.compose.material.icons.filled.Videocam
+import androidx.compose.ui.graphics.vector.ImageVector
+
+// Contains each destination screen as an enum
+// and associates an icon to show in the navigation tabs
+enum class ComposeCameraScreen(
+    val icon: ImageVector
+) {
+    ImageCapture(
+        icon = Icons.Filled.CameraAlt
+    ),
+    VideoCapture(
+        icon = Icons.Filled.Videocam
+    ),
+    Gallery(
+        icon = Icons.Filled.PhotoLibrary
+    );
+
+    companion object {
+        fun fromRoute(route: String?, defaultRoute: ComposeCameraScreen): ComposeCameraScreen {
+            return when (route?.substringBefore("/")) {
+                ImageCapture.name -> ImageCapture
+                VideoCapture.name -> VideoCapture
+                Gallery.name -> Gallery
+                null -> defaultRoute
+                else -> throw IllegalArgumentException("Route $route is not recognized.")
+            }
+        }
+    }
+}
\ No newline at end of file