[Checkbox][Catalog] Updated checkbox catalog demo to include error state.

PiperOrigin-RevId: 455130475
This commit is contained in:
leticiars 2022-06-15 14:56:55 +00:00 committed by raajkumars
parent 3fdfb6e230
commit 0cb355b26a
4 changed files with 55 additions and 29 deletions

View File

@ -25,6 +25,7 @@ import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import androidx.annotation.Nullable;
import com.google.android.material.checkbox.MaterialCheckBox;
import io.material.catalog.feature.DemoFragment;
import io.material.catalog.feature.DemoUtils;
import java.util.List;
@ -38,6 +39,8 @@ public class CheckBoxMainDemoFragment extends DemoFragment {
View view = layoutInflater.inflate(R.layout.cat_checkbox, viewGroup, false /* attachToRoot */);
ViewGroup toggleContainer = view.findViewById(R.id.checkbox_toggle_container);
List<CheckBox> toggledCheckBoxes = DemoUtils.findViewsWithType(toggleContainer, CheckBox.class);
List<MaterialCheckBox> allCheckBoxes =
DemoUtils.findViewsWithType(view, MaterialCheckBox.class);
CheckBox checkBoxToggle = view.findViewById(R.id.checkbox_toggle);
checkBoxToggle.setOnCheckedChangeListener(
@ -47,6 +50,13 @@ public class CheckBoxMainDemoFragment extends DemoFragment {
}
});
CheckBox checkBoxToggleError = view.findViewById(R.id.checkbox_toggle_error);
checkBoxToggleError.setOnCheckedChangeListener(
(CompoundButton buttonView, boolean isChecked) -> {
for (MaterialCheckBox cb : allCheckBoxes) {
cb.setErrorShown(isChecked);
}
});
return view;
}
}

View File

@ -18,7 +18,6 @@
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_viewGroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -33,8 +32,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_columnSpan="2"
android:text="@string/cat_checkbox_color_guide"
android:textSize="@dimen/cat_checkbox_header_size"/>
android:text="@string/cat_checkbox_intro" />
<CheckBox
android:layout_width="match_parent"
android:layout_height="match_parent"
@ -51,8 +49,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_columnSpan="2"
android:text="@string/cat_checkbox_disabled_guide"
android:textSize="@dimen/cat_checkbox_header_size"/>
android:text="@string/cat_checkbox_disabled_guide" />
<CheckBox
android:layout_width="match_parent"
android:layout_height="match_parent"
@ -66,20 +63,20 @@
android:enabled="false"
android:text="@string/cat_checkbox_disabled"/>
</GridLayout>
<ImageView
android:layout_width="match_parent"
android:layout_height="@dimen/cat_checkbox_line_separator_thickness"
android:layout_marginTop="@dimen/cat_checkbox_line_separator_margin"
android:layout_marginBottom="@dimen/cat_checkbox_line_separator_margin"
android:background="?attr/colorSecondary"/>
<com.google.android.material.divider.MaterialDivider
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/cat_checkbox_line_separator_margin"
android:layout_marginBottom="@dimen/cat_checkbox_line_separator_margin"/>
<CheckBox
android:id="@+id/checkbox_toggle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:checked="false"
android:enabled="true"
android:text="@string/cat_checkbox_enablable_description"
android:textSize="@dimen/cat_checkbox_header_size"/>
android:text="@string/cat_checkbox_enablable_description"/>
<LinearLayout
android:id="@+id/checkbox_toggle_container"
android:layout_width="match_parent"
@ -99,18 +96,30 @@
android:enabled="false"
android:text="@string/cat_checkbox_toggle"/>
</LinearLayout>
<ImageView
<com.google.android.material.divider.MaterialDivider
android:layout_width="match_parent"
android:layout_height="@dimen/cat_checkbox_line_separator_thickness"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/cat_checkbox_line_separator_margin"
android:layout_marginBottom="@dimen/cat_checkbox_line_separator_margin"
android:background="?attr/colorSecondary"/>
android:layout_marginBottom="@dimen/cat_checkbox_line_separator_margin"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/cat_checkbox_no_text"
android:textSize="@dimen/cat_checkbox_header_size"/>
android:text="@string/cat_checkbox_no_text"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<com.google.android.material.divider.MaterialDivider
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/cat_checkbox_line_separator_margin"
android:layout_marginBottom="@dimen/cat_checkbox_line_separator_margin"/>
<CheckBox
android:id="@+id/checkbox_toggle_error"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/cat_checkbox_toggle_error"/>
</LinearLayout>

View File

@ -19,5 +19,4 @@
<dimen name="cat_checkbox_line_separator_margin">8dp</dimen>
<dimen name="cat_checkbox_padding">8dp</dimen>
<dimen name="cat_checkbox_indent">8dp</dimen>
<dimen name="cat_checkbox_header_size">12dp</dimen>
</resources>

View File

@ -16,15 +16,23 @@
-->
<resources>
<string name="cat_checkbox_title">Checkbox</string>
<string name="cat_checkbox_description">
<string name="cat_checkbox_title" translatable="false">Checkbox</string>
<string name="cat_checkbox_description" translatable="false">
The CheckBox provides a selectable element, usually part of a list,
that toggles between two states.</string>
<string name="cat_checkbox_color_guide">CheckBox elements respond to changes in colorSecondary</string>
<string name="cat_checkbox_disabled_guide">CheckBox elements that are disabled cannot be interacted with and will appear faded</string>
<string name="cat_checkbox_enabled">Enabled</string>
<string name="cat_checkbox_disabled">Disabled</string>
<string name="cat_checkbox_enablable_description">Check this checkbox to control the enabled state of the boxes below.</string>
<string name="cat_checkbox_toggle">Controlled by a checkbox</string>
<string name="cat_checkbox_no_text">Below is a checkbox with no text.</string>
<string name="cat_checkbox_intro" translatable="false">
Below are Material checkboxes.</string>
<string name="cat_checkbox_disabled_guide" translatable="false">
CheckBox elements that are disabled cannot be interacted with and will
appear faded.</string>
<string name="cat_checkbox_enabled" translatable="false">Enabled</string>
<string name="cat_checkbox_disabled" translatable="false">Disabled</string>
<string name="cat_checkbox_enablable_description" translatable="false">
Check this checkbox to control the enabled state of the boxes below.</string>
<string name="cat_checkbox_toggle" translatable="false">
Controlled by a checkbox</string>
<string name="cat_checkbox_no_text" translatable="false">
Below is a checkbox with no text.</string>
<string name="cat_checkbox_toggle_error" translatable="false">
Check this checkbox to control the error state of all checkboxes in this page.</string>
</resources>