Skip to content

Commit 05253b8

Browse files
pekingmepaulfthomas
authored andcommitted
[TopAppBar] Added more demos.
PiperOrigin-RevId: 700395255
1 parent d4b9d90 commit 05253b8

10 files changed

+364
-10
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright 2024 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+
* https://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+
17+
package io.material.catalog.topappbar;
18+
19+
import io.material.catalog.R;
20+
21+
import android.os.Bundle;
22+
import androidx.appcompat.app.AppCompatActivity;
23+
import androidx.appcompat.widget.Toolbar;
24+
import android.view.LayoutInflater;
25+
import android.view.View;
26+
import android.view.ViewGroup;
27+
import android.widget.Button;
28+
import androidx.annotation.NonNull;
29+
import androidx.annotation.Nullable;
30+
import com.google.android.material.snackbar.Snackbar;
31+
import io.material.catalog.feature.DemoFragment;
32+
33+
/**
34+
* A fragment that displays a large Collapsing Toolbar Top App Bar with a filled action button demo
35+
* for the Catalog app.
36+
*/
37+
public class TopAppBarCollapsingFilledActionDemoFragment extends DemoFragment {
38+
39+
@Override
40+
@Nullable
41+
public View onCreateDemoView(
42+
@NonNull LayoutInflater layoutInflater,
43+
@Nullable ViewGroup viewGroup,
44+
@Nullable Bundle bundle) {
45+
View view =
46+
layoutInflater.inflate(
47+
R.layout.cat_topappbar_collapsing_filled_action_fragment, viewGroup, false);
48+
49+
Toolbar toolbar = view.findViewById(R.id.toolbar);
50+
AppCompatActivity activity = (AppCompatActivity) getActivity();
51+
activity.setSupportActionBar(toolbar);
52+
53+
Button actionButton = view.findViewById(R.id.action_button);
54+
actionButton.setOnClickListener(
55+
v -> Snackbar.make(v, "Action button is clicked.", Snackbar.LENGTH_SHORT).show());
56+
57+
return view;
58+
}
59+
60+
@Override
61+
public boolean shouldShowDefaultDemoActionBar() {
62+
return false;
63+
}
64+
}

catalog/java/io/material/catalog/topappbar/TopAppBarCollapsingLargeDemoFragment.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
/** A fragment that displays a large collapsing Top App Bar demo for the Catalog app. */
2424
public class TopAppBarCollapsingLargeDemoFragment extends BaseTopAppBarCollapsingDemoFragment {
2525

26+
@Override
2627
@LayoutRes
2728
protected int getCollapsingToolbarLayoutResId() {
2829
return R.layout.cat_topappbar_collapsing_large_fragment;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright 2024 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+
* https://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+
17+
package io.material.catalog.topappbar;
18+
19+
import io.material.catalog.R;
20+
21+
import androidx.annotation.LayoutRes;
22+
23+
/** A fragment that displays a large Collapsing Toolbar Top App Bar demo for the Catalog app. */
24+
public class TopAppBarCollapsingLargeWithSubtitleDemoFragment
25+
extends BaseTopAppBarCollapsingDemoFragment {
26+
27+
@Override
28+
@LayoutRes
29+
protected int getCollapsingToolbarLayoutResId() {
30+
return R.layout.cat_topappbar_collapsing_large_with_subtitle_fragment;
31+
}
32+
}

catalog/java/io/material/catalog/topappbar/TopAppBarCollapsingMediumDemoFragment.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
/** A fragment that displays a medium collapsing Top App Bar demo for the Catalog app. */
2424
public class TopAppBarCollapsingMediumDemoFragment extends BaseTopAppBarCollapsingDemoFragment {
2525

26+
@Override
2627
@LayoutRes
2728
protected int getCollapsingToolbarLayoutResId() {
2829
return R.layout.cat_topappbar_collapsing_medium_fragment;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright 2024 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+
* https://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+
17+
package io.material.catalog.topappbar;
18+
19+
import io.material.catalog.R;
20+
21+
import androidx.annotation.LayoutRes;
22+
23+
/** A fragment that displays a medium Collapsing Toolbar Top App Bar demo for the Catalog app. */
24+
public class TopAppBarCollapsingMediumWithSubtitleDemoFragment
25+
extends BaseTopAppBarCollapsingDemoFragment {
26+
27+
@Override
28+
@LayoutRes
29+
protected int getCollapsingToolbarLayoutResId() {
30+
return R.layout.cat_topappbar_collapsing_medium_with_subtitle_fragment;
31+
}
32+
}

catalog/java/io/material/catalog/topappbar/TopAppBarFragment.java

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import android.content.Intent;
2222
import androidx.fragment.app.Fragment;
2323
import androidx.annotation.NonNull;
24+
import androidx.annotation.Nullable;
2425
import com.google.common.collect.ImmutableList;
2526
import dagger.Provides;
2627
import dagger.android.ContributesAndroidInjector;
@@ -97,23 +98,47 @@ public Fragment createFragment() {
9798
@NonNull
9899
protected List<Demo> getCollapsingToolbarDemos() {
99100
return Arrays.asList(
100-
new Demo(R.string.cat_topappbar_collapsing_medium_title) {
101+
new Demo(R.string.cat_topappbar_collapsing_medium_demo_title) {
102+
@Nullable
101103
@Override
102104
public Fragment createFragment() {
103105
return new TopAppBarCollapsingMediumDemoFragment();
104106
}
105107
},
106-
new Demo(R.string.cat_topappbar_collapsing_large_title) {
108+
new Demo(R.string.cat_topappbar_collapsing_medium_with_subtitle_demo_title) {
109+
@Nullable
110+
@Override
111+
public Fragment createFragment() {
112+
return new TopAppBarCollapsingMediumWithSubtitleDemoFragment();
113+
}
114+
},
115+
new Demo(R.string.cat_topappbar_collapsing_large_demo_title) {
116+
@Nullable
107117
@Override
108118
public Fragment createFragment() {
109119
return new TopAppBarCollapsingLargeDemoFragment();
110120
}
111121
},
112-
new Demo(R.string.cat_topappbar_collapsing_multiline_title) {
122+
new Demo(R.string.cat_topappbar_collapsing_large_with_subtitle_demo_title) {
123+
@Nullable
124+
@Override
125+
public Fragment createFragment() {
126+
return new TopAppBarCollapsingLargeWithSubtitleDemoFragment();
127+
}
128+
},
129+
new Demo(R.string.cat_topappbar_collapsing_multiline_demo_title) {
130+
@Nullable
113131
@Override
114132
public Fragment createFragment() {
115133
return new TopAppBarCollapsingMultilineDemoFragment();
116134
}
135+
},
136+
new Demo(R.string.cat_topappbar_collapsing_with_filled_action_demo_title) {
137+
@Nullable
138+
@Override
139+
public Fragment createFragment() {
140+
return new TopAppBarCollapsingFilledActionDemoFragment();
141+
}
117142
});
118143
}
119144

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
Copyright 2024 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+
https://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.coordinatorlayout.widget.CoordinatorLayout
18+
xmlns:android="http://schemas.android.com/apk/res/android"
19+
xmlns:app="http://schemas.android.com/apk/res-auto"
20+
android:id="@+id/coordinator"
21+
android:layout_width="match_parent"
22+
android:layout_height="match_parent">
23+
24+
<com.google.android.material.appbar.AppBarLayout
25+
android:id="@+id/appbarlayout"
26+
android:layout_width="match_parent"
27+
android:layout_height="wrap_content"
28+
android:fitsSystemWindows="true">
29+
30+
<com.google.android.material.appbar.CollapsingToolbarLayout
31+
style="?attr/collapsingToolbarLayoutMediumStyle"
32+
android:id="@+id/collapsingtoolbarlayout"
33+
android:layout_width="match_parent"
34+
android:layout_height="?attr/collapsingToolbarLayoutMediumWithSubtitleSize"
35+
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
36+
app:expandedTitleGravity="bottom|center_horizontal"
37+
app:expandedSubtitleGravity="bottom|center_horizontal"
38+
app:title="@string/cat_topappbar_collapsing_demo_toolbar_medium_title"
39+
app:subtitle="@string/cat_topappbar_collapsing_demo_toolbar_medium_subtitle"
40+
app:toolbarId="@id/toolbar">
41+
<LinearLayout
42+
android:layout_width="match_parent"
43+
android:layout_height="wrap_content"
44+
android:orientation="horizontal"
45+
app:layout_collapseMode="pin">
46+
<androidx.appcompat.widget.Toolbar
47+
android:id="@+id/toolbar"
48+
style="?attr/catalogToolbarWithCloseButtonStyle"
49+
android:layout_width="0dp"
50+
android:layout_height="?attr/actionBarSize"
51+
android:layout_weight="1"
52+
android:elevation="0dp"/>
53+
<Button
54+
android:id="@+id/action_button"
55+
android:layout_width="wrap_content"
56+
android:layout_height="wrap_content"
57+
android:layout_marginEnd="8dp"
58+
android:layout_gravity="center_vertical"
59+
android:text="@string/cat_topappbar_action_button_label"/>
60+
</LinearLayout>
61+
</com.google.android.material.appbar.CollapsingToolbarLayout>
62+
</com.google.android.material.appbar.AppBarLayout>
63+
64+
<androidx.core.widget.NestedScrollView
65+
android:layout_width="match_parent"
66+
android:layout_height="match_parent"
67+
app:layout_behavior="@string/appbar_scrolling_view_behavior">
68+
69+
<include layout="@layout/cat_topappbar_filler_text_view"/>
70+
</androidx.core.widget.NestedScrollView>
71+
72+
</androidx.coordinatorlayout.widget.CoordinatorLayout>
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 2024 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+
https://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.coordinatorlayout.widget.CoordinatorLayout
18+
xmlns:android="http://schemas.android.com/apk/res/android"
19+
xmlns:app="http://schemas.android.com/apk/res-auto"
20+
android:id="@+id/coordinator"
21+
android:layout_width="match_parent"
22+
android:layout_height="match_parent">
23+
24+
<com.google.android.material.appbar.AppBarLayout
25+
android:id="@+id/appbarlayout"
26+
android:layout_width="match_parent"
27+
android:layout_height="wrap_content"
28+
android:fitsSystemWindows="true">
29+
30+
<com.google.android.material.appbar.CollapsingToolbarLayout
31+
style="?attr/collapsingToolbarLayoutLargeStyle"
32+
android:id="@+id/collapsingtoolbarlayout"
33+
android:layout_width="match_parent"
34+
android:layout_height="?attr/collapsingToolbarLayoutLargeWithSubtitleSize"
35+
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
36+
app:expandedTitleGravity="bottom|center_horizontal"
37+
app:expandedSubtitleGravity="bottom|center_horizontal"
38+
app:title="@string/cat_topappbar_collapsing_demo_toolbar_large_title"
39+
app:subtitle="@string/cat_topappbar_collapsing_demo_toolbar_large_subtitle">
40+
41+
<androidx.appcompat.widget.Toolbar
42+
android:id="@+id/toolbar"
43+
style="?attr/catalogToolbarWithCloseButtonStyle"
44+
android:layout_width="match_parent"
45+
android:layout_height="?attr/actionBarSize"
46+
android:elevation="0dp"
47+
app:layout_collapseMode="pin"/>
48+
</com.google.android.material.appbar.CollapsingToolbarLayout>
49+
</com.google.android.material.appbar.AppBarLayout>
50+
51+
<androidx.core.widget.NestedScrollView
52+
android:layout_width="match_parent"
53+
android:layout_height="match_parent"
54+
app:layout_behavior="@string/appbar_scrolling_view_behavior">
55+
56+
<include layout="@layout/cat_topappbar_filler_text_view"/>
57+
</androidx.core.widget.NestedScrollView>
58+
59+
</androidx.coordinatorlayout.widget.CoordinatorLayout>
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 2024 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+
https://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.coordinatorlayout.widget.CoordinatorLayout
18+
xmlns:android="http://schemas.android.com/apk/res/android"
19+
xmlns:app="http://schemas.android.com/apk/res-auto"
20+
android:id="@+id/coordinator"
21+
android:layout_width="match_parent"
22+
android:layout_height="match_parent">
23+
24+
<com.google.android.material.appbar.AppBarLayout
25+
android:id="@+id/appbarlayout"
26+
android:layout_width="match_parent"
27+
android:layout_height="wrap_content"
28+
android:fitsSystemWindows="true">
29+
30+
<com.google.android.material.appbar.CollapsingToolbarLayout
31+
style="?attr/collapsingToolbarLayoutMediumStyle"
32+
android:id="@+id/collapsingtoolbarlayout"
33+
android:layout_width="match_parent"
34+
android:layout_height="?attr/collapsingToolbarLayoutMediumWithSubtitleSize"
35+
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
36+
app:expandedTitleGravity="bottom|center_horizontal"
37+
app:expandedSubtitleGravity="bottom|center_horizontal"
38+
app:title="@string/cat_topappbar_collapsing_demo_toolbar_medium_title"
39+
app:subtitle="@string/cat_topappbar_collapsing_demo_toolbar_medium_subtitle">
40+
41+
<androidx.appcompat.widget.Toolbar
42+
android:id="@+id/toolbar"
43+
style="?attr/catalogToolbarWithCloseButtonStyle"
44+
android:layout_width="match_parent"
45+
android:layout_height="?attr/actionBarSize"
46+
android:elevation="0dp"
47+
app:layout_collapseMode="pin"/>
48+
</com.google.android.material.appbar.CollapsingToolbarLayout>
49+
</com.google.android.material.appbar.AppBarLayout>
50+
51+
<androidx.core.widget.NestedScrollView
52+
android:layout_width="match_parent"
53+
android:layout_height="match_parent"
54+
app:layout_behavior="@string/appbar_scrolling_view_behavior">
55+
56+
<include layout="@layout/cat_topappbar_filler_text_view"/>
57+
</androidx.core.widget.NestedScrollView>
58+
59+
</androidx.coordinatorlayout.widget.CoordinatorLayout>

0 commit comments

Comments
 (0)