Skip to content

Commit 828c932

Browse files
pekingmehunterstich
authored andcommitted
[ButtonGroup] Added the button group distribution demo in catalog.
PiperOrigin-RevId: 732356180
1 parent b640078 commit 828c932

File tree

7 files changed

+279
-1
lines changed

7 files changed

+279
-1
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright 2025 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.material.catalog.button;
17+
18+
import io.material.catalog.R;
19+
20+
import android.os.Bundle;
21+
import android.view.LayoutInflater;
22+
import android.view.View;
23+
import android.view.ViewGroup;
24+
import androidx.annotation.NonNull;
25+
import androidx.annotation.Nullable;
26+
import com.google.android.material.button.MaterialButtonGroup;
27+
import io.material.catalog.feature.DemoFragment;
28+
29+
/**
30+
* A fragment that displays a button group demo for different button distribution options in the
31+
* Catalog app.
32+
*/
33+
public class ButtonGroupDistributionDemoFragment extends DemoFragment {
34+
35+
/** Create a Demo View with different types of {@link MaterialButtonGroup}. */
36+
@Nullable
37+
@Override
38+
public View onCreateDemoView(
39+
@NonNull LayoutInflater layoutInflater,
40+
@Nullable ViewGroup viewGroup,
41+
@Nullable Bundle bundle) {
42+
View view =
43+
layoutInflater.inflate(
44+
R.layout.cat_buttons_group_distribution_fragment, viewGroup, /* attachToRoot= */ false);
45+
46+
return view;
47+
}
48+
}

catalog/java/io/material/catalog/button/ButtonsFragment.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,17 @@ public Fragment createFragment() {
5757

5858
@Override
5959
public List<Demo> getAdditionalDemos() {
60-
return Arrays.asList(getButtonGroupDemo(), getButtonToggleGroupDemo(), getSplitButtonDemo());
60+
return Arrays.asList(
61+
getButtonGroupDemo(),
62+
getButtonToggleGroupDemo(),
63+
getSplitButtonDemo(),
64+
new Demo(R.string.cat_buttons_group_distribution) {
65+
@Nullable
66+
@Override
67+
public Fragment createFragment() {
68+
return new ButtonGroupDistributionDemoFragment();
69+
}
70+
});
6171
}
6272

6373
@NonNull
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
Copyright 2025 The Android Open Source Project
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
18+
android:width="24dp"
19+
android:height="24dp"
20+
android:viewportWidth="960"
21+
android:viewportHeight="960"
22+
android:tint="?attr/colorControlNormal">
23+
<path
24+
android:fillColor="@android:color/white"
25+
android:pathData="M660,720L660,240L740,240L740,720L660,720ZM220,720L220,240L580,480L220,720Z"/>
26+
</vector>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
Copyright 2025 The Android Open Source Project
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
18+
android:width="24dp"
19+
android:height="24dp"
20+
android:viewportWidth="960"
21+
android:viewportHeight="960"
22+
android:tint="?attr/colorControlNormal">
23+
<path
24+
android:fillColor="@android:color/white"
25+
android:pathData="M320,760L320,200L760,480L320,760Z"/>
26+
</vector>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
Copyright 2025 The Android Open Source Project
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
18+
android:width="24dp"
19+
android:height="24dp"
20+
android:viewportWidth="960"
21+
android:viewportHeight="960"
22+
android:tint="?attr/colorControlNormal">
23+
<path
24+
android:fillColor="@android:color/white"
25+
android:pathData="M220,720L220,240L300,240L300,720L220,720ZM740,720L380,480L740,240L740,720Z"/>
26+
</vector>
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
Copyright 2025 The Android Open Source Project
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
18+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
19+
xmlns:app="http://schemas.android.com/apk/res-auto"
20+
android:layout_width="match_parent"
21+
android:layout_height="match_parent"
22+
android:paddingTop="8dp"
23+
android:paddingHorizontal="8dp"
24+
android:gravity="center_horizontal"
25+
android:orientation="vertical">
26+
<TextView
27+
android:layout_width="wrap_content"
28+
android:layout_height="wrap_content"
29+
android:text="@string/cat_buttons_fixed_width_text"/>
30+
<com.google.android.material.button.MaterialButtonGroup
31+
android:layout_width="match_parent"
32+
android:layout_height="wrap_content"
33+
android:paddingBottom="8dp"
34+
android:gravity="center_horizontal"
35+
android:spacing="4dp">
36+
<Button
37+
style="?attr/materialIconButtonFilledStyle"
38+
android:layout_width="wrap_content"
39+
android:layout_height="wrap_content"
40+
android:contentDescription="@string/cat_button_previous_icon"
41+
android:gravity="center"
42+
app:iconGravity="textStart"
43+
app:icon="@drawable/cat_button_previous_icon"/>
44+
<Button
45+
style="?attr/materialIconButtonFilledStyle"
46+
android:layout_width="wrap_content"
47+
android:layout_height="wrap_content"
48+
android:contentDescription="@string/cat_button_play_icon"
49+
android:gravity="center"
50+
app:iconGravity="textStart"
51+
app:icon="@drawable/cat_button_play_icon"/>
52+
<Button
53+
style="?attr/materialIconButtonFilledStyle"
54+
android:layout_width="wrap_content"
55+
android:layout_height="wrap_content"
56+
android:contentDescription="@string/cat_button_next_icon"
57+
android:gravity="center"
58+
app:iconGravity="textStart"
59+
app:icon="@drawable/cat_button_next_icon"/>
60+
</com.google.android.material.button.MaterialButtonGroup>
61+
<TextView
62+
android:layout_width="wrap_content"
63+
android:layout_height="wrap_content"
64+
android:text="@string/cat_buttons_dynamic_width"/>
65+
<com.google.android.material.button.MaterialButtonGroup
66+
android:layout_width="match_parent"
67+
android:layout_height="wrap_content"
68+
android:paddingBottom="8dp"
69+
android:gravity="center_horizontal"
70+
android:spacing="4dp">
71+
<Button
72+
style="?attr/materialIconButtonFilledStyle"
73+
android:layout_width="0dp"
74+
android:layout_height="wrap_content"
75+
android:layout_weight="1"
76+
android:contentDescription="@string/cat_button_previous_icon"
77+
android:gravity="center"
78+
app:iconGravity="textStart"
79+
app:icon="@drawable/cat_button_previous_icon"/>
80+
<Button
81+
style="?attr/materialIconButtonFilledStyle"
82+
android:layout_width="0dp"
83+
android:layout_height="wrap_content"
84+
android:layout_weight="2"
85+
android:contentDescription="@string/cat_button_play_icon"
86+
android:gravity="center"
87+
app:iconGravity="textStart"
88+
app:icon="@drawable/cat_button_play_icon"/>
89+
<Button
90+
style="?attr/materialIconButtonFilledStyle"
91+
android:layout_width="0dp"
92+
android:layout_height="wrap_content"
93+
android:layout_weight="1"
94+
android:contentDescription="@string/cat_button_next_icon"
95+
android:gravity="center"
96+
app:iconGravity="textStart"
97+
app:icon="@drawable/cat_button_next_icon"/>
98+
</com.google.android.material.button.MaterialButtonGroup>
99+
<TextView
100+
android:layout_width="wrap_content"
101+
android:layout_height="wrap_content"
102+
android:text="@string/cat_buttons_mixed_width"/>
103+
<com.google.android.material.button.MaterialButtonGroup
104+
android:layout_width="match_parent"
105+
android:layout_height="wrap_content"
106+
android:paddingBottom="8dp"
107+
android:gravity="center_horizontal"
108+
android:spacing="4dp">
109+
<Button
110+
style="?attr/materialIconButtonFilledStyle"
111+
android:layout_width="wrap_content"
112+
android:layout_height="wrap_content"
113+
android:contentDescription="@string/cat_button_previous_icon"
114+
android:gravity="center"
115+
app:iconGravity="textStart"
116+
app:icon="@drawable/cat_button_previous_icon"/>
117+
<Button
118+
style="?attr/materialIconButtonFilledStyle"
119+
android:layout_width="0dp"
120+
android:layout_height="wrap_content"
121+
android:layout_weight="2"
122+
android:contentDescription="@string/cat_button_play_icon"
123+
android:gravity="center"
124+
app:iconGravity="textStart"
125+
app:icon="@drawable/cat_button_play_icon"/>
126+
<Button
127+
style="?attr/materialIconButtonFilledStyle"
128+
android:layout_width="wrap_content"
129+
android:layout_height="wrap_content"
130+
android:contentDescription="@string/cat_button_next_icon"
131+
android:gravity="center"
132+
app:iconGravity="textStart"
133+
app:icon="@drawable/cat_button_next_icon"/>
134+
</com.google.android.material.button.MaterialButtonGroup>
135+
</LinearLayout>

catalog/java/io/material/catalog/button/res/values/strings.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
<string name="cat_toc_buttons">Buttons</string>
2121
<string name="cat_buttons_group" translatable="false">Buttons Group</string>
22+
<string name="cat_buttons_group_distribution" translatable="false">Buttons Group Distribution</string>
2223
<string name="cat_buttons_toggle_group">Buttons Toggle Group</string>
2324
<string name="cat_split_button" translatable="false">Split Button</string>
2425
<string name="cat_buttons_title">Buttons</string>
@@ -128,4 +129,10 @@
128129
<string name="cat_button_require_selection" translatable="false">Require Selection</string>
129130
<string name="cat_button_vertical_orientation" translatable="false">Vertical Orientation</string>
130131
<string name="cat_button_enable" translatable="false">Enabled</string>
132+
<string name="cat_buttons_fixed_width_text">Buttons with fixed width</string>
133+
<string name="cat_buttons_dynamic_width">Buttons with dynamic width (1:2:1)</string>
134+
<string name="cat_buttons_mixed_width">Buttons with mixed width</string>
135+
<string name="cat_button_previous_icon">previous button</string>
136+
<string name="cat_button_play_icon">play button</string>
137+
<string name="cat_button_next_icon">next button</string>
131138
</resources>

0 commit comments

Comments
 (0)