Skip to content

Commit 68a79d7

Browse files
imhappihunterstich
authored andcommitted
[DockedToolbar] Add new demo to show fewer items
PiperOrigin-RevId: 729663570
1 parent ca0b870 commit 68a79d7

File tree

6 files changed

+319
-0
lines changed

6 files changed

+319
-0
lines changed

catalog/java/io/material/catalog/dockedtoolbar/DockedToolbarFragment.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import io.material.catalog.feature.Demo;
2828
import io.material.catalog.feature.DemoLandingFragment;
2929
import io.material.catalog.feature.FeatureDemo;
30+
import java.util.ArrayList;
31+
import java.util.List;
3032

3133
/** A fragment that displays Docked Toolbar demos for the Catalog app. */
3234
public class DockedToolbarFragment extends DemoLandingFragment {
@@ -51,6 +53,21 @@ public Fragment createFragment() {
5153
};
5254
}
5355

56+
@Override
57+
@NonNull
58+
public List<Demo> getAdditionalDemos() {
59+
List<Demo> additionalDemos = new ArrayList<>();
60+
additionalDemos.add(
61+
new Demo(
62+
R.string.cat_docked_toolbar_three_item_title) {
63+
@Override
64+
public Fragment createFragment() {
65+
return new DockedToolbarThreeItemDemoFragment();
66+
}
67+
});
68+
return additionalDemos;
69+
}
70+
5471
/** The Dagger module for {@link DockedToolbarFragment} dependencies. */
5572
@dagger.Module
5673
public abstract static class Module {
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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.dockedtoolbar;
17+
18+
import io.material.catalog.R;
19+
20+
import android.os.Bundle;
21+
import androidx.appcompat.app.AppCompatActivity;
22+
import androidx.appcompat.widget.Toolbar;
23+
import android.view.LayoutInflater;
24+
import android.view.View;
25+
import android.view.ViewGroup;
26+
import android.widget.Button;
27+
import androidx.annotation.LayoutRes;
28+
import androidx.annotation.NonNull;
29+
import androidx.annotation.Nullable;
30+
import com.google.android.material.dockedtoolbar.DockedToolbarLayout;
31+
import com.google.android.material.snackbar.Snackbar;
32+
import io.material.catalog.feature.DemoFragment;
33+
34+
/** A fragment that displays a Docked Toolbar demo with 3 items for the Catalog app. */
35+
public class DockedToolbarThreeItemDemoFragment extends DemoFragment {
36+
37+
private DockedToolbarLayout dockedToolbar;
38+
39+
@Override
40+
@NonNull
41+
public View onCreateDemoView(@NonNull LayoutInflater layoutInflater, @Nullable ViewGroup viewGroup,
42+
@Nullable Bundle bundle) {
43+
View view = layoutInflater.inflate(getLayoutResId(), viewGroup, /* attachToRoot= */ false);
44+
Toolbar toolbar = view.findViewById(R.id.toolbar);
45+
dockedToolbar = view.findViewById(R.id.docked_toolbar);
46+
((AppCompatActivity) requireActivity()).setSupportActionBar(toolbar);
47+
48+
Button leftArrowButton = view.findViewById(R.id.docked_toolbar_left_arrow_button);
49+
Button rightArrowButton = view.findViewById(R.id.docked_toolbar_right_arrow_button);
50+
Button addButton = view.findViewById(R.id.docked_toolbar_add_button);
51+
setupSnackbarOnClick(leftArrowButton);
52+
setupSnackbarOnClick(rightArrowButton);
53+
setupSnackbarOnClick(addButton);
54+
55+
return view;
56+
}
57+
58+
private void setupSnackbarOnClick(@NonNull View view) {
59+
view.setOnClickListener(
60+
v ->
61+
Snackbar.make(
62+
dockedToolbar,
63+
view.getContentDescription(),
64+
Snackbar.LENGTH_SHORT)
65+
.setAnchorView(dockedToolbar)
66+
.show());
67+
}
68+
69+
@LayoutRes
70+
protected int getLayoutResId() {
71+
return R.layout.cat_docked_toolbar_vibrant_fragment;
72+
}
73+
74+
@Override
75+
public boolean shouldShowDefaultDemoActionBar() {
76+
return false;
77+
}
78+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
~ Copyright (C) 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+
<merge>
18+
<LinearLayout
19+
xmlns:android="http://schemas.android.com/apk/res/android"
20+
xmlns:app="http://schemas.android.com/apk/res-auto"
21+
android:layout_width="wrap_content"
22+
android:layout_height="match_parent"
23+
android:orientation="horizontal"
24+
android:gravity="center">
25+
<Button
26+
android:id="@+id/docked_toolbar_left_arrow_button"
27+
android:layout_width="48dp"
28+
android:layout_height="48dp"
29+
style="?attr/materialIconButtonStyle"
30+
android:contentDescription="@string/cat_docked_toolbar_left_arrow_button_description"
31+
android:layout_marginEnd="32dp"
32+
app:icon="@drawable/ic_arrow_back_24px" />
33+
34+
<Button
35+
android:id="@+id/docked_toolbar_right_arrow_button"
36+
android:layout_width="48dp"
37+
android:layout_height="48dp"
38+
style="?attr/materialIconButtonStyle"
39+
android:contentDescription="@string/cat_docked_toolbar_right_arrow_button_description"
40+
app:icon="@drawable/ic_arrow_forward_24px" />
41+
</LinearLayout>
42+
43+
<Button
44+
xmlns:android="http://schemas.android.com/apk/res/android"
45+
xmlns:app="http://schemas.android.com/apk/res-auto"
46+
android:id="@+id/docked_toolbar_add_button"
47+
android:layout_gravity="center"
48+
android:layout_width="48dp"
49+
android:layout_height="48dp"
50+
android:gravity="center"
51+
android:paddingVertical="8dp"
52+
android:paddingHorizontal="8dp"
53+
app:iconSize="24dp"
54+
app:shapeAppearance="?attr/shapeAppearanceCornerMedium"
55+
style="?attr/materialIconButtonFilledStyle"
56+
android:contentDescription="@string/cat_docked_toolbar_add_button_description"
57+
app:icon="@drawable/ic_add_24px" />
58+
59+
</merge>
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
~ Copyright (C) 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+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
18+
xmlns:app="http://schemas.android.com/apk/res-auto"
19+
android:baselineAligned="false" android:orientation="horizontal"
20+
android:layout_width="match_parent"
21+
android:layout_height="wrap_content"
22+
android:gravity="center">
23+
24+
<FrameLayout
25+
android:layout_width="0dp"
26+
android:layout_height="wrap_content"
27+
android:layout_weight="1">
28+
<Button
29+
android:id="@+id/docked_toolbar_left_arrow_button"
30+
android:layout_width="48dp"
31+
android:layout_height="48dp"
32+
android:layout_gravity="center"
33+
style="?attr/materialIconButtonStyle"
34+
android:contentDescription="@string/cat_docked_toolbar_left_arrow_button_description"
35+
app:icon="@drawable/ic_arrow_back_24px" />
36+
</FrameLayout>
37+
38+
<FrameLayout
39+
android:layout_width="0dp"
40+
android:layout_height="wrap_content"
41+
android:layout_weight="1">
42+
<Button
43+
android:id="@+id/docked_toolbar_add_button"
44+
android:layout_width="48dp"
45+
android:layout_height="48dp"
46+
android:layout_gravity="center"
47+
android:gravity="center"
48+
android:paddingVertical="8dp"
49+
android:paddingHorizontal="8dp"
50+
app:iconSize="24dp"
51+
style="?attr/materialIconButtonFilledStyle"
52+
app:shapeAppearance="?attr/shapeAppearanceCornerMedium"
53+
android:contentDescription="@string/cat_docked_toolbar_add_button_description"
54+
app:icon="@drawable/ic_add_24px" />
55+
</FrameLayout>
56+
57+
<FrameLayout
58+
android:layout_width="0dp"
59+
android:layout_height="wrap_content"
60+
android:layout_weight="1">
61+
<Button
62+
android:id="@+id/docked_toolbar_right_arrow_button"
63+
android:layout_width="48dp"
64+
android:layout_height="48dp"
65+
android:layout_gravity="center"
66+
style="?attr/materialIconButtonStyle"
67+
android:contentDescription="@string/cat_docked_toolbar_right_arrow_button_description"
68+
app:icon="@drawable/ic_arrow_forward_24px" />
69+
</FrameLayout>
70+
71+
</LinearLayout>
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
~ Copyright (C) 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+
<androidx.constraintlayout.widget.ConstraintLayout
18+
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+
23+
<androidx.coordinatorlayout.widget.CoordinatorLayout
24+
android:layout_width="match_parent"
25+
android:layout_height="0dp"
26+
app:layout_constraintLeft_toLeftOf="parent"
27+
app:layout_constraintRight_toRightOf="parent"
28+
app:layout_constraintBottom_toTopOf="@id/docked_toolbar"
29+
app:layout_constraintTop_toTopOf="parent">
30+
31+
<com.google.android.material.appbar.AppBarLayout
32+
android:id="@+id/toolbar_container"
33+
android:layout_width="match_parent"
34+
android:layout_height="wrap_content"
35+
android:fitsSystemWindows="true">
36+
<androidx.appcompat.widget.Toolbar
37+
style="?attr/catalogToolbarWithCloseButtonStyle"
38+
android:id="@+id/toolbar"
39+
android:layout_width="match_parent"
40+
android:layout_height="wrap_content"
41+
app:title="@string/cat_docked_toolbar_title"/>
42+
</com.google.android.material.appbar.AppBarLayout>
43+
44+
<androidx.core.widget.NestedScrollView
45+
android:layout_width="match_parent"
46+
android:layout_height="wrap_content"
47+
android:id="@+id/scroll_view"
48+
app:layout_behavior="@string/appbar_scrolling_view_behavior">
49+
50+
<LinearLayout
51+
android:id="@+id/body_container"
52+
android:layout_width="match_parent"
53+
android:layout_height="wrap_content"
54+
android:gravity="center"
55+
android:orientation="vertical">
56+
57+
<TextView
58+
android:id="@+id/body_text"
59+
android:layout_width="match_parent"
60+
android:layout_height="wrap_content"
61+
android:layout_margin="16dp"
62+
android:lineSpacingMultiplier="1.2"
63+
android:text="@string/cat_docked_toolbar_filler_text" />
64+
65+
</LinearLayout>
66+
</androidx.core.widget.NestedScrollView>
67+
68+
</androidx.coordinatorlayout.widget.CoordinatorLayout>
69+
70+
<!-- TODO: b/393647677 - Update this toolbar styling to be vibrant once styles are ready -->
71+
<com.google.android.material.dockedtoolbar.DockedToolbarLayout
72+
android:id="@+id/docked_toolbar"
73+
android:layout_width="match_parent"
74+
android:layout_height="wrap_content"
75+
app:layout_constraintLeft_toLeftOf="parent"
76+
app:layout_constraintRight_toRightOf="parent"
77+
app:paddingBottomSystemWindowInsets="true"
78+
app:layout_constraintBottom_toBottomOf="parent">
79+
80+
<LinearLayout
81+
android:id="@+id/docked_toolbar_child"
82+
android:layout_width="match_parent"
83+
android:layout_height="match_parent"
84+
android:gravity="center"
85+
android:orientation="horizontal">
86+
<include layout="@layout/cat_docked_toolbar_small_content" />
87+
</LinearLayout>
88+
</com.google.android.material.dockedtoolbar.DockedToolbarLayout>
89+
90+
</androidx.constraintlayout.widget.ConstraintLayout>

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
<string name="cat_docked_toolbar_title"
1919
description="Title for the screen that showcases the Docked Toolbar widget [CHAR LIMIT=NONE]">
2020
Docked Toolbar
21+
</string>
22+
<string name="cat_docked_toolbar_three_item_title"
23+
description="Title for the screen that showcases the Docked Toolbar widget with three items [CHAR LIMIT=NONE]">
24+
Docked Toolbar with 3 items
2125
</string>
2226
<string name="cat_docked_toolbar_description"
2327
description="Body text describing the Docked Toolbar component within the design system [CHAR LIMIT=NONE]">

0 commit comments

Comments
 (0)