[go: nahoru, domu]

Introduce Vector Icon Buttons in Rally

This allows us to have vector icons using the current APIs

Test: build, run, check interaction
Change-Id: Ia60866869e61edd36b0495328449ed8fcff4d85f
diff --git a/ui/ui-material/integration-tests/material-studies/src/main/java/androidx/ui/material/studies/rally/RallyCards.kt b/ui/ui-material/integration-tests/material-studies/src/main/java/androidx/ui/material/studies/rally/RallyCards.kt
index 6513435..8db4ee8 100644
--- a/ui/ui-material/integration-tests/material-studies/src/main/java/androidx/ui/material/studies/rally/RallyCards.kt
+++ b/ui/ui-material/integration-tests/material-studies/src/main/java/androidx/ui/material/studies/rally/RallyCards.kt
@@ -36,6 +36,8 @@
 import androidx.ui.material.Divider
 import androidx.ui.material.MaterialTheme
 import androidx.ui.material.TextButton
+import androidx.ui.material.icons.Icons
+import androidx.ui.material.icons.filled.Sort
 import androidx.ui.material.ripple.Ripple
 import androidx.ui.material.surface.Card
 import androidx.ui.unit.dp
@@ -80,24 +82,17 @@
                 color = MaterialTheme.colors().background,
                 height = 2.dp
             )
-            Ripple(bounded = true) {
-                Clickable( openDialog.value = true }) {
-                    Container {
-                        Row(LayoutPadding(12.dp)) {
-                            Text(
-                                style = MaterialTheme.typography().body1,
-                                modifier = LayoutFlexible(1f),
-                                text = alertMessage
-                            )
-                            // TODO: icons still don't work
-//                            <vectorResource res=context.resources
-//                                resId=androidx.ui.material.studies.R.drawable.sort_icon/>
-                            TextButton( }) {
-                                Text("Sort")
-                            }
-                        }
-                    }
-                }
+            Row(LayoutPadding(12.dp)) {
+                Text(
+                    style = MaterialTheme.typography().body1,
+                    modifier = LayoutFlexible(1f),
+                    text = alertMessage
+                )
+                RallyIconButton(
+                    vectorImage = Icons.Filled.Sort,
+                    >
+                    modifier = LayoutGravity.Top
+                )
             }
         }
     }
diff --git a/ui/ui-material/integration-tests/material-studies/src/main/java/androidx/ui/material/studies/rally/RallyIcons.kt b/ui/ui-material/integration-tests/material-studies/src/main/java/androidx/ui/material/studies/rally/RallyIcons.kt
new file mode 100644
index 0000000..4bba46d
--- /dev/null
+++ b/ui/ui-material/integration-tests/material-studies/src/main/java/androidx/ui/material/studies/rally/RallyIcons.kt
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2020 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.ui.material.studies.rally
+
+import androidx.compose.Composable
+import androidx.ui.core.Modifier
+import androidx.ui.foundation.Box
+import androidx.ui.foundation.Clickable
+import androidx.ui.graphics.Color
+import androidx.ui.graphics.vector.DrawVector
+import androidx.ui.graphics.vector.VectorAsset
+import androidx.ui.layout.LayoutHeight
+import androidx.ui.layout.LayoutWidth
+import androidx.ui.material.ripple.Ripple
+import androidx.ui.unit.dp
+
+@Composable
+fun RallyIconButton(
+    vectorImage: VectorAsset,
+    onClick: () -> Unit,
+    modifier: Modifier = Modifier.None
+) {
+    Box(modifier = modifier) {
+        Ripple(bounded = false) {
+            Clickable(onClick) {
+                Box(modifier = LayoutHeight(24.dp) + LayoutWidth(24.dp)) {
+                    DrawVector(vectorImage = vectorImage, tintColor = Color.White)
+                }
+            }
+        }
+    }
+}
\ No newline at end of file