From 3bb9a248a46b1989008d1fbf196d246daefe45dd Mon Sep 17 00:00:00 2001 From: Material Design Team Date: Thu, 23 Aug 2018 15:41:19 -0400 Subject: [PATCH] Catalog Demo for Material Radio Button PiperOrigin-RevId: 209981850 --- catalog/build.gradle | 1 + .../radiobutton/RadioButtonFragment.java | 75 ++++++++++++++++++ .../RadioButtonMainDemoFragment.java | 38 +++++++++ .../ic_radio_button_checked_black_24dp.xml | 25 ++++++ .../res/layout/cat_radiobutton.xml | 78 +++++++++++++++++++ .../catalog/radiobutton/res/values/dimens.xml | 22 ++++++ .../radiobutton/res/values/strings.xml | 30 +++++++ .../catalog/tableofcontents/TocModule.java | 2 + 8 files changed, 271 insertions(+) create mode 100644 catalog/java/io/material/catalog/radiobutton/RadioButtonFragment.java create mode 100644 catalog/java/io/material/catalog/radiobutton/RadioButtonMainDemoFragment.java create mode 100644 catalog/java/io/material/catalog/radiobutton/res/drawable/ic_radio_button_checked_black_24dp.xml create mode 100644 catalog/java/io/material/catalog/radiobutton/res/layout/cat_radiobutton.xml create mode 100644 catalog/java/io/material/catalog/radiobutton/res/values/dimens.xml create mode 100644 catalog/java/io/material/catalog/radiobutton/res/values/strings.xml diff --git a/catalog/build.gradle b/catalog/build.gradle index 230cda290..24ea1fee1 100644 --- a/catalog/build.gradle +++ b/catalog/build.gradle @@ -31,6 +31,7 @@ def srcDirs = [ 'feature', 'font', 'main', + 'radiobutton', 'switchmaterial', 'tableofcontents', 'tabs', diff --git a/catalog/java/io/material/catalog/radiobutton/RadioButtonFragment.java b/catalog/java/io/material/catalog/radiobutton/RadioButtonFragment.java new file mode 100644 index 000000000..3702b09f2 --- /dev/null +++ b/catalog/java/io/material/catalog/radiobutton/RadioButtonFragment.java @@ -0,0 +1,75 @@ +/* + * Copyright 2018 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 io.material.catalog.radiobutton; + +import io.material.catalog.R; + +import android.support.v4.app.Fragment; +import dagger.Provides; +import dagger.android.ContributesAndroidInjector; +import dagger.multibindings.IntoSet; +import io.material.catalog.application.scope.ActivityScope; +import io.material.catalog.application.scope.FragmentScope; +import io.material.catalog.feature.Demo; +import io.material.catalog.feature.DemoLandingFragment; +import io.material.catalog.feature.FeatureDemo; + +/** A fragment that displays radio button demos for the Catalog app. */ +public class RadioButtonFragment extends DemoLandingFragment { + + @Override + public int getTitleResId() { + return R.string.cat_radiobutton_title; + } + + @Override + public int getDescriptionResId() { + return R.string.cat_radiobutton_description; + } + + @Override + public Demo getMainDemo() { + return new Demo() { + @Override + public Fragment createFragment() { + return new RadioButtonMainDemoFragment(); + } + }; + } + + /** The Dagger module for {@link RadioButtonFragment} dependencies. */ + @dagger.Module + public abstract static class Module { + + @FragmentScope + @ContributesAndroidInjector + abstract RadioButtonFragment contributeInjector(); + + @IntoSet + @Provides + @ActivityScope + static FeatureDemo provideFeatureDemo() { + return new FeatureDemo( + R.string.cat_radiobutton_title, R.drawable.ic_radio_button_checked_black_24dp) { + @Override + public Fragment createFragment() { + return new RadioButtonFragment(); + } + }; + } + } +} diff --git a/catalog/java/io/material/catalog/radiobutton/RadioButtonMainDemoFragment.java b/catalog/java/io/material/catalog/radiobutton/RadioButtonMainDemoFragment.java new file mode 100644 index 000000000..496468946 --- /dev/null +++ b/catalog/java/io/material/catalog/radiobutton/RadioButtonMainDemoFragment.java @@ -0,0 +1,38 @@ +package io.material.catalog.radiobutton; + +import io.material.catalog.R; + +/* + * Copyright 2018 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 + * + * https://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. + */ + +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import io.material.catalog.feature.DemoFragment; + +/** A fragment that displays the main RadioButton demo for the Catalog app. */ +public class RadioButtonMainDemoFragment extends DemoFragment { + + @Override + public View onCreateDemoView( + LayoutInflater layoutInflater, @Nullable ViewGroup viewGroup, @Nullable Bundle bundle) { + View view = + layoutInflater.inflate(R.layout.cat_radiobutton, viewGroup, false /* attachToRoot */); + return view; + } +} diff --git a/catalog/java/io/material/catalog/radiobutton/res/drawable/ic_radio_button_checked_black_24dp.xml b/catalog/java/io/material/catalog/radiobutton/res/drawable/ic_radio_button_checked_black_24dp.xml new file mode 100644 index 000000000..a9349764a --- /dev/null +++ b/catalog/java/io/material/catalog/radiobutton/res/drawable/ic_radio_button_checked_black_24dp.xml @@ -0,0 +1,25 @@ + + + + + diff --git a/catalog/java/io/material/catalog/radiobutton/res/layout/cat_radiobutton.xml b/catalog/java/io/material/catalog/radiobutton/res/layout/cat_radiobutton.xml new file mode 100644 index 000000000..ecb6a18f0 --- /dev/null +++ b/catalog/java/io/material/catalog/radiobutton/res/layout/cat_radiobutton.xml @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + diff --git a/catalog/java/io/material/catalog/radiobutton/res/values/dimens.xml b/catalog/java/io/material/catalog/radiobutton/res/values/dimens.xml new file mode 100644 index 000000000..752b51dc2 --- /dev/null +++ b/catalog/java/io/material/catalog/radiobutton/res/values/dimens.xml @@ -0,0 +1,22 @@ + + + + 8dp + 8dp + 8dp + 12sp + diff --git a/catalog/java/io/material/catalog/radiobutton/res/values/strings.xml b/catalog/java/io/material/catalog/radiobutton/res/values/strings.xml new file mode 100644 index 000000000..042f1f307 --- /dev/null +++ b/catalog/java/io/material/catalog/radiobutton/res/values/strings.xml @@ -0,0 +1,30 @@ + + + + + + Radio Button + + The RadioButton provides a clickable element, usually part of a RadioButtonGroup. Within a single RadioGroup, only 1 RadioButton can be selected. + + RadioButton elements respond to changes in colorSecondary. + They cannot be deselected by a direct click. + RadioButton elements that are disabled cannot be interacted with and will appear faded. + Enabled + Disabled + + diff --git a/catalog/java/io/material/catalog/tableofcontents/TocModule.java b/catalog/java/io/material/catalog/tableofcontents/TocModule.java index 9a2af6697..b0ad17b6d 100644 --- a/catalog/java/io/material/catalog/tableofcontents/TocModule.java +++ b/catalog/java/io/material/catalog/tableofcontents/TocModule.java @@ -27,6 +27,7 @@ import io.material.catalog.checkbox.CheckBoxFragment; import io.material.catalog.chip.ChipFragment; import io.material.catalog.fab.FabFragment; import io.material.catalog.font.FontFragment; +import io.material.catalog.radiobutton.RadioButtonFragment; import io.material.catalog.switchmaterial.SwitchFragment; import io.material.catalog.tabs.TabsFragment; import io.material.catalog.textfield.TextFieldFragment; @@ -49,6 +50,7 @@ import io.material.catalog.transformation.TransformationFragment; ChipFragment.Module.class, FabFragment.Module.class, FontFragment.Module.class, + RadioButtonFragment.Module.class, SwitchFragment.Module.class, TabsFragment.Module.class, TextFieldFragment.Module.class,