From c786582d6a78e44090d6769cda657dee10c19765 Mon Sep 17 00:00:00 2001 From: Material Design Team Date: Fri, 17 Mar 2023 21:34:14 +0000 Subject: [PATCH] [M3][Color] Color Component demo update PiperOrigin-RevId: 517511129 --- .../color/ColorMainDemoFragmentTest.java | 84 +++++++++++++------ .../catalog/color/ColorMainDemoFragment.java | 55 +++++++++++- .../color/res/layout/cat_colors_fragment.xml | 3 +- .../catalog/color/res/values/strings.xml | 20 +++++ 4 files changed, 131 insertions(+), 31 deletions(-) diff --git a/catalog/androidTest/javatests/io/material/catalog/color/ColorMainDemoFragmentTest.java b/catalog/androidTest/javatests/io/material/catalog/color/ColorMainDemoFragmentTest.java index 08eeaff8c90..6ec6a4265fd 100644 --- a/catalog/androidTest/javatests/io/material/catalog/color/ColorMainDemoFragmentTest.java +++ b/catalog/androidTest/javatests/io/material/catalog/color/ColorMainDemoFragmentTest.java @@ -17,6 +17,7 @@ package io.material.catalog.color; import static androidx.test.espresso.Espresso.onView; +import static androidx.test.espresso.action.ViewActions.scrollTo; import static androidx.test.espresso.assertion.ViewAssertions.matches; import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; import static androidx.test.espresso.matcher.ViewMatchers.withText; @@ -36,6 +37,56 @@ @RunWith(AndroidJUnit4.class) public final class ColorMainDemoFragmentTest { + private static final int[] STRING_RESOURCE_IDS = + new int[] { + R.string.cat_color_role_primary, + R.string.cat_color_role_on_primary, + R.string.cat_color_role_primary_container, + R.string.cat_color_role_on_primary_container, + R.string.cat_color_role_primary_fixed, + R.string.cat_color_role_primary_fixed_dim, + R.string.cat_color_role_on_primary_fixed, + R.string.cat_color_role_on_primary_fixed_variant, + R.string.cat_color_role_inverse_primary, + R.string.cat_color_role_secondary, + R.string.cat_color_role_on_secondary, + R.string.cat_color_role_secondary_container, + R.string.cat_color_role_on_secondary_container, + R.string.cat_color_role_secondary_fixed, + R.string.cat_color_role_secondary_fixed_dim, + R.string.cat_color_role_on_secondary_fixed, + R.string.cat_color_role_on_secondary_fixed_variant, + R.string.cat_color_role_tertiary, + R.string.cat_color_role_on_tertiary, + R.string.cat_color_role_tertiary_container, + R.string.cat_color_role_on_tertiary_container, + R.string.cat_color_role_tertiary_fixed, + R.string.cat_color_role_tertiary_fixed_dim, + R.string.cat_color_role_on_tertiary_fixed, + R.string.cat_color_role_on_tertiary_fixed_variant, + R.string.cat_color_role_error, + R.string.cat_color_role_on_error, + R.string.cat_color_role_error_container, + R.string.cat_color_role_on_error_container, + R.string.cat_color_role_outline, + R.string.cat_color_role_outline_variant, + R.string.cat_color_role_background, + R.string.cat_color_role_on_background, + R.string.cat_color_role_surface, + R.string.cat_color_role_on_surface, + R.string.cat_color_role_surface_variant, + R.string.cat_color_role_on_surface_variant, + R.string.cat_color_role_inverse_surface, + R.string.cat_color_role_inverse_on_surface, + R.string.cat_color_role_surface_bright, + R.string.cat_color_role_surface_dim, + R.string.cat_color_role_surface_container, + R.string.cat_color_role_surface_container_low, + R.string.cat_color_role_surface_container_high, + R.string.cat_color_role_surface_container_lowest, + R.string.cat_color_role_surface_container_highest, + }; + @Rule public final ActivityScenarioRule activityScenarioRule = new ActivityScenarioRule<>(MainActivity.class); @@ -57,33 +108,12 @@ public void setUpAndLaunchFragment() { @Test public void checkColorRowTextValueIsShown() { - onView(withText(R.string.cat_color_role_primary)).check(matches(isDisplayed())); - onView(withText(R.string.cat_color_role_on_primary)).check(matches(isDisplayed())); - onView(withText(R.string.cat_color_role_primary_container)).check(matches(isDisplayed())); - onView(withText(R.string.cat_color_role_on_primary_container)).check(matches(isDisplayed())); - onView(withText(R.string.cat_color_role_inverse_primary)).check(matches(isDisplayed())); - onView(withText(R.string.cat_color_role_secondary)).check(matches(isDisplayed())); - onView(withText(R.string.cat_color_role_on_secondary)).check(matches(isDisplayed())); - onView(withText(R.string.cat_color_role_secondary_container)).check(matches(isDisplayed())); - onView(withText(R.string.cat_color_role_on_secondary_container)).check(matches(isDisplayed())); - onView(withText(R.string.cat_color_role_tertiary)).check(matches(isDisplayed())); - onView(withText(R.string.cat_color_role_on_tertiary)).check(matches(isDisplayed())); - onView(withText(R.string.cat_color_role_tertiary_container)).check(matches(isDisplayed())); - onView(withText(R.string.cat_color_role_on_tertiary_container)).check(matches(isDisplayed())); - - onView(withText(R.string.cat_color_role_error)).check(matches(isDisplayed())); - onView(withText(R.string.cat_color_role_on_error)).check(matches(isDisplayed())); - onView(withText(R.string.cat_color_role_error_container)).check(matches(isDisplayed())); - onView(withText(R.string.cat_color_role_on_error_container)).check(matches(isDisplayed())); - onView(withText(R.string.cat_color_role_outline)).check(matches(isDisplayed())); + for (int stringResId : STRING_RESOURCE_IDS) { + checkIsTextDisplayed(stringResId); + } + } - onView(withText(R.string.cat_color_role_background)).check(matches(isDisplayed())); - onView(withText(R.string.cat_color_role_on_background)).check(matches(isDisplayed())); - onView(withText(R.string.cat_color_role_surface)).check(matches(isDisplayed())); - onView(withText(R.string.cat_color_role_on_surface)).check(matches(isDisplayed())); - onView(withText(R.string.cat_color_role_surface_variant)).check(matches(isDisplayed())); - onView(withText(R.string.cat_color_role_on_surface_variant)).check(matches(isDisplayed())); - onView(withText(R.string.cat_color_role_inverse_surface)).check(matches(isDisplayed())); - onView(withText(R.string.cat_color_role_inverse_on_surface)).check(matches(isDisplayed())); + private void checkIsTextDisplayed(int text) { + onView(withText(text)).perform(scrollTo()).check(matches(isDisplayed())); } } diff --git a/catalog/java/io/material/catalog/color/ColorMainDemoFragment.java b/catalog/java/io/material/catalog/color/ColorMainDemoFragment.java index e769dfaef06..cccccad5d2a 100644 --- a/catalog/java/io/material/catalog/color/ColorMainDemoFragment.java +++ b/catalog/java/io/material/catalog/color/ColorMainDemoFragment.java @@ -79,7 +79,26 @@ private List getColorRolesSurfaces() { new ColorRow( new ColorRoleItem(R.string.cat_color_role_inverse_surface, R.attr.colorSurfaceInverse), new ColorRoleItem( - R.string.cat_color_role_inverse_on_surface, R.attr.colorOnSurfaceInverse))); + R.string.cat_color_role_inverse_on_surface, R.attr.colorOnSurfaceInverse)), + new ColorRow( + new ColorRoleItem(R.string.cat_color_role_surface_bright, R.attr.colorSurfaceBright), + new ColorRoleItem(R.string.cat_color_role_surface_dim, R.attr.colorSurfaceDim)), + new ColorRow( + new ColorRoleItem( + R.string.cat_color_role_surface_container_low, R.attr.colorSurfaceContainerLow), + new ColorRoleItem( + R.string.cat_color_role_surface_container_high, R.attr.colorSurfaceContainerHigh)), + new ColorRow( + new ColorRoleItem( + R.string.cat_color_role_surface_container_lowest, + R.attr.colorSurfaceContainerLowest), + new ColorRoleItem( + R.string.cat_color_role_surface_container_highest, + R.attr.colorSurfaceContainerHighest)), + new ColorRow( + new ColorRoleItem( + R.string.cat_color_role_surface_container, R.attr.colorSurfaceContainer), + null)); } private List getColorRolesContent() { @@ -92,6 +111,15 @@ private List getColorRolesContent() { R.string.cat_color_role_primary_container, R.attr.colorPrimaryContainer), new ColorRoleItem( R.string.cat_color_role_on_primary_container, R.attr.colorOnPrimaryContainer)), + new ColorRow( + new ColorRoleItem(R.string.cat_color_role_primary_fixed, R.attr.colorPrimaryFixed), + new ColorRoleItem( + R.string.cat_color_role_primary_fixed_dim, R.attr.colorPrimaryFixedDim)), + new ColorRow( + new ColorRoleItem(R.string.cat_color_role_on_primary_fixed, R.attr.colorOnPrimaryFixed), + new ColorRoleItem( + R.string.cat_color_role_on_primary_fixed_variant, + R.attr.colorOnPrimaryFixedVariant)), new ColorRow( new ColorRoleItem(R.string.cat_color_role_inverse_primary, R.attr.colorPrimaryInverse), /* colorRoleItemRight= */ null), @@ -103,6 +131,16 @@ private List getColorRolesContent() { R.string.cat_color_role_secondary_container, R.attr.colorSecondaryContainer), new ColorRoleItem( R.string.cat_color_role_on_secondary_container, R.attr.colorOnSecondaryContainer)), + new ColorRow( + new ColorRoleItem(R.string.cat_color_role_secondary_fixed, R.attr.colorSecondaryFixed), + new ColorRoleItem( + R.string.cat_color_role_secondary_fixed_dim, R.attr.colorSecondaryFixedDim)), + new ColorRow( + new ColorRoleItem( + R.string.cat_color_role_on_secondary_fixed, R.attr.colorOnSecondaryFixed), + new ColorRoleItem( + R.string.cat_color_role_on_secondary_fixed_variant, + R.attr.colorOnSecondaryFixedVariant)), new ColorRow( new ColorRoleItem(R.string.cat_color_role_tertiary, R.attr.colorTertiary), new ColorRoleItem(R.string.cat_color_role_on_tertiary, R.attr.colorOnTertiary)), @@ -110,7 +148,17 @@ private List getColorRolesContent() { new ColorRoleItem( R.string.cat_color_role_tertiary_container, R.attr.colorTertiaryContainer), new ColorRoleItem( - R.string.cat_color_role_on_tertiary_container, R.attr.colorOnTertiaryContainer))); + R.string.cat_color_role_on_tertiary_container, R.attr.colorOnTertiaryContainer)), + new ColorRow( + new ColorRoleItem(R.string.cat_color_role_tertiary_fixed, R.attr.colorTertiaryFixed), + new ColorRoleItem( + R.string.cat_color_role_tertiary_fixed_dim, R.attr.colorTertiaryFixedDim)), + new ColorRow( + new ColorRoleItem( + R.string.cat_color_role_on_tertiary_fixed, R.attr.colorOnTertiaryFixed), + new ColorRoleItem( + R.string.cat_color_role_on_tertiary_fixed_variant, + R.attr.colorOnTertiaryFixedVariant))); } private List getColorRolesUtility() { @@ -124,6 +172,7 @@ private List getColorRolesUtility() { R.string.cat_color_role_on_error_container, R.attr.colorOnErrorContainer)), new ColorRow( new ColorRoleItem(R.string.cat_color_role_outline, R.attr.colorOutline), - /* colorRoleItemRight= */ null)); + new ColorRoleItem( + R.string.cat_color_role_outline_variant, R.attr.colorOutlineVariant))); } } diff --git a/catalog/java/io/material/catalog/color/res/layout/cat_colors_fragment.xml b/catalog/java/io/material/catalog/color/res/layout/cat_colors_fragment.xml index 5293643ef49..434c8e232c2 100644 --- a/catalog/java/io/material/catalog/color/res/layout/cat_colors_fragment.xml +++ b/catalog/java/io/material/catalog/color/res/layout/cat_colors_fragment.xml @@ -19,11 +19,12 @@ xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" - android:padding="8dp"> + android:layout_weight="1"> On Surface Variant Inverse Surface Inverse On Surface + Surface Bright + Surface Dim + Surface Container + Surface Container Low + Surface Container High + Surface Container Lowest + Surface Container Highest Surfaces Utility @@ -53,20 +60,33 @@ On Primary Primary Container On Primary Container + Primary Fixed + Primary Fixed Dim + On Primary Fixed + On Primary Fixed Variant Inverse Primary Secondary On Secondary Secondary Container On Secondary Container + Secondary Fixed + Secondary Fixed Dim + On Secondary Fixed + On Secondary Fixed Variant Tertiary On Tertiary Tertiary Container On Tertiary Container + Tertiary Fixed + Tertiary Fixed Dim + On Tertiary Fixed + On Tertiary Fixed Variant Error On Error Error Container On Error Container Outline + Outline Variant Yellow On Yellow