Skip to content

Commit

Permalink
[M3][Color] Color Component demo update
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 517511129
  • Loading branch information
Material Design Team authored and pekingme committed Mar 20, 2023
1 parent 9f1caa2 commit c786582
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<MainActivity> activityScenarioRule =
new ActivityScenarioRule<>(MainActivity.class);
Expand All @@ -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()));
}
}
55 changes: 52 additions & 3 deletions catalog/java/io/material/catalog/color/ColorMainDemoFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,26 @@ private List<ColorRow> 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<ColorRow> getColorRolesContent() {
Expand All @@ -92,6 +111,15 @@ private List<ColorRow> 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),
Expand All @@ -103,14 +131,34 @@ private List<ColorRow> 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)),
new ColorRow(
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<ColorRow> getColorRolesUtility() {
Expand All @@ -124,6 +172,7 @@ private List<ColorRow> 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)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp"
android:orientation="vertical">

<LinearLayout
Expand Down
20 changes: 20 additions & 0 deletions catalog/java/io/material/catalog/color/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@
<string name="cat_color_role_on_surface_variant" translatable="false">On Surface Variant</string>
<string name="cat_color_role_inverse_surface" translatable="false">Inverse Surface</string>
<string name="cat_color_role_inverse_on_surface" translatable="false">Inverse On Surface</string>
<string name="cat_color_role_surface_bright" translatable="false">Surface Bright</string>
<string name="cat_color_role_surface_dim" translatable="false">Surface Dim</string>
<string name="cat_color_role_surface_container" translatable="false">Surface Container</string>
<string name="cat_color_role_surface_container_low" translatable="false">Surface Container Low</string>
<string name="cat_color_role_surface_container_high" translatable="false">Surface Container High</string>
<string name="cat_color_role_surface_container_lowest" translatable="false">Surface Container Lowest</string>
<string name="cat_color_role_surface_container_highest" translatable="false">Surface Container Highest</string>

<string name="cat_color_surfaces" translatable="false">Surfaces</string>
<string name="cat_color_utility" translatable="false">Utility</string>
Expand All @@ -53,20 +60,33 @@
<string name="cat_color_role_on_primary" translatable="false">On Primary</string>
<string name="cat_color_role_primary_container" translatable="false">Primary Container</string>
<string name="cat_color_role_on_primary_container" translatable="false">On Primary Container</string>
<string name="cat_color_role_primary_fixed" translatable="false">Primary Fixed</string>
<string name="cat_color_role_primary_fixed_dim" translatable="false">Primary Fixed Dim</string>
<string name="cat_color_role_on_primary_fixed" translatable="false">On Primary Fixed</string>
<string name="cat_color_role_on_primary_fixed_variant" translatable="false">On Primary Fixed Variant</string>
<string name="cat_color_role_inverse_primary" translatable="false">Inverse Primary</string>
<string name="cat_color_role_secondary" translatable="false">Secondary</string>
<string name="cat_color_role_on_secondary" translatable="false">On Secondary</string>
<string name="cat_color_role_secondary_container" translatable="false">Secondary Container</string>
<string name="cat_color_role_on_secondary_container" translatable="false">On Secondary Container</string>
<string name="cat_color_role_secondary_fixed" translatable="false">Secondary Fixed</string>
<string name="cat_color_role_secondary_fixed_dim" translatable="false">Secondary Fixed Dim</string>
<string name="cat_color_role_on_secondary_fixed" translatable="false">On Secondary Fixed</string>
<string name="cat_color_role_on_secondary_fixed_variant" translatable="false">On Secondary Fixed Variant</string>
<string name="cat_color_role_tertiary" translatable="false">Tertiary</string>
<string name="cat_color_role_on_tertiary" translatable="false">On Tertiary</string>
<string name="cat_color_role_tertiary_container" translatable="false">Tertiary Container</string>
<string name="cat_color_role_on_tertiary_container" translatable="false">On Tertiary Container</string>
<string name="cat_color_role_tertiary_fixed" translatable="false">Tertiary Fixed</string>
<string name="cat_color_role_tertiary_fixed_dim" translatable="false">Tertiary Fixed Dim</string>
<string name="cat_color_role_on_tertiary_fixed" translatable="false">On Tertiary Fixed</string>
<string name="cat_color_role_on_tertiary_fixed_variant" translatable="false">On Tertiary Fixed Variant</string>
<string name="cat_color_role_error" translatable="false">Error</string>
<string name="cat_color_role_on_error" translatable="false">On Error</string>
<string name="cat_color_role_error_container" translatable="false">Error Container</string>
<string name="cat_color_role_on_error_container" translatable="false">On Error Container</string>
<string name="cat_color_role_outline" translatable="false">Outline</string>
<string name="cat_color_role_outline_variant" translatable="false">Outline Variant</string>

<string name="cat_color_role_yellow" translatable="false">Yellow</string>
<string name="cat_color_role_on_yellow" translatable="false">On Yellow</string>
Expand Down

0 comments on commit c786582

Please sign in to comment.