Skip to content

Commit b1552f1

Browse files
leticiarossipekingme
authored andcommitted
[OverflowLinearLayout] Added documentation, screenshot tests and updated catalog demos for docked toolbar and floating toolbar.
PiperOrigin-RevId: 759140193
1 parent de1ff7c commit b1552f1

16 files changed

+582
-187
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
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+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
17+
android:width="24dp"
18+
android:height="24dp"
19+
android:viewportWidth="960"
20+
android:viewportHeight="960"
21+
android:tint="?attr/colorControlNormal">
22+
<path
23+
android:fillColor="@android:color/white"
24+
android:pathData="M440,880L440,680L240,680L240,560L440,560L440,400L120,400L120,280L440,280L440,80L520,80L520,280L840,280L840,400L520,400L520,560L720,560L720,680L520,680L520,880L440,880Z"/>
25+
</vector>

catalog/java/io/material/catalog/dockedtoolbar/res/menu/overflow_menu.xml renamed to catalog/java/io/material/catalog/assets/res/drawable/ic_format_align_left_24px.xml

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,25 @@
1-
<?xml version="1.0" encoding="utf-8"?>
21
<!--
32
Copyright 2025 The Android Open Source Project
43
54
Licensed under the Apache License, Version 2.0 (the "License");
65
you may not use this file except in compliance with the License.
76
You may obtain a copy of the License at
87
9-
http://www.apache.org/licenses/LICENSE-2.0
8+
https://www.apache.org/licenses/LICENSE-2.0
109
1110
Unless required by applicable law or agreed to in writing, software
1211
distributed under the License is distributed on an "AS IS" BASIS,
1312
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1413
See the License for the specific language governing permissions and
1514
limitations under the License.
1615
-->
17-
18-
<menu xmlns:android="http://schemas.android.com/apk/res/android">
19-
20-
<item
21-
android:title="@string/cat_docked_toolbar_overflow_option_one"/>
22-
23-
<item
24-
android:title="@string/cat_docked_toolbar_overflow_option_two"/>
25-
26-
<item
27-
android:title="@string/cat_docked_toolbar_overflow_option_three"/>
28-
29-
</menu>
16+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
17+
android:width="24dp"
18+
android:height="24dp"
19+
android:viewportWidth="960"
20+
android:viewportHeight="960"
21+
android:tint="?attr/colorControlNormal">
22+
<path
23+
android:fillColor="@android:color/white"
24+
android:pathData="M80,880L80,80L160,80L160,880L80,880ZM240,680L240,560L640,560L640,680L240,680ZM240,400L240,280L880,280L880,400L240,400Z"/>
25+
</vector>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
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+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
17+
android:width="24dp"
18+
android:height="24dp"
19+
android:viewportWidth="960"
20+
android:viewportHeight="960"
21+
android:tint="?attr/colorControlNormal">
22+
<path
23+
android:fillColor="@android:color/white"
24+
android:pathData="M800,880L800,80L880,80L880,880L800,880ZM320,680L320,560L720,560L720,680L320,680ZM80,400L80,280L720,280L720,400L80,400Z"/>
25+
</vector>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
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+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
17+
android:width="24dp"
18+
android:height="24dp"
19+
android:viewportWidth="960"
20+
android:viewportHeight="960"
21+
android:tint="?attr/colorControlNormal">
22+
<path
23+
android:fillColor="@android:color/white"
24+
android:pathData="M486,800Q410,800 351,755Q292,710 266,632L354,594Q368,642 402.5,673Q437,704 488,704Q530,704 564,684Q598,664 598,620Q598,602 591,587Q584,572 572,560L684,560Q689,574 691.5,588.5Q694,603 694,620Q694,706 632.5,753Q571,800 486,800ZM80,480L80,400L880,400L880,480L80,480ZM482,154Q548,154 597.5,186.5Q647,219 674,286L586,325Q577,296 552.5,273Q528,250 484,250Q443,250 416,268.5Q389,287 386,320Q386,320 386,320Q386,320 386,320L290,320Q290,320 290,320Q290,320 290,320Q292,251 344.5,202.5Q397,154 482,154Z"/>
25+
</vector>

catalog/java/io/material/catalog/dockedtoolbar/DockedToolbarMainDemoFragment.java

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,14 @@
2121
import android.os.Build.VERSION_CODES;
2222
import android.os.Bundle;
2323
import androidx.appcompat.app.AppCompatActivity;
24-
import androidx.appcompat.widget.PopupMenu;
2524
import androidx.appcompat.widget.Toolbar;
2625
import android.view.LayoutInflater;
2726
import android.view.View;
2827
import android.view.ViewGroup;
2928
import android.view.accessibility.AccessibilityManager;
30-
import android.widget.Button;
29+
import android.widget.FrameLayout;
3130
import android.widget.LinearLayout;
3231
import androidx.annotation.LayoutRes;
33-
import androidx.annotation.MenuRes;
3432
import androidx.annotation.NonNull;
3533
import androidx.annotation.Nullable;
3634
import com.google.android.material.dockedtoolbar.DockedToolbarLayout;
@@ -54,21 +52,17 @@ public View onCreateDemoView(
5452
dockedToolbar = view.findViewById(R.id.docked_toolbar);
5553
((AppCompatActivity) requireActivity()).setSupportActionBar(toolbar);
5654

57-
Button leftArrowButton = view.findViewById(R.id.docked_toolbar_left_arrow_button);
58-
Button rightArrowButton = view.findViewById(R.id.docked_toolbar_right_arrow_button);
59-
Button addButton = view.findViewById(R.id.docked_toolbar_add_button);
60-
Button tabButton = view.findViewById(R.id.docked_toolbar_tab_button);
61-
setupSnackbarOnClick(leftArrowButton);
62-
setupSnackbarOnClick(rightArrowButton);
63-
setupSnackbarOnClick(addButton);
64-
setupSnackbarOnClick(tabButton);
55+
setupSnackbarAndButtonParentOnClick(view.findViewById(R.id.docked_toolbar_left_arrow_button));
56+
setupSnackbarAndButtonParentOnClick(view.findViewById(R.id.docked_toolbar_right_arrow_button));
57+
setupSnackbarAndButtonParentOnClick(view.findViewById(R.id.docked_toolbar_add_button));
58+
setupSnackbarAndButtonParentOnClick(view.findViewById(R.id.docked_toolbar_tab_button));
59+
setupSnackbarAndButtonParentOnClick(view.findViewById(R.id.docked_toolbar_star_button));
60+
setupSnackbarAndButtonParentOnClick(view.findViewById(R.id.docked_toolbar_alarm_button));
61+
setupSnackbarAndButtonParentOnClick(view.findViewById(R.id.docked_toolbar_search_button));
62+
setupSnackbarAndButtonParentOnClick(view.findViewById(R.id.docked_toolbar_settings_button));
6563

6664
LinearLayout bodyContainer = view.findViewById(R.id.body_container);
6765

68-
Button overflowClick = view.findViewById(R.id.docked_toolbar_button_overflow_button);
69-
70-
overflowClick.setOnClickListener(v -> showMenu(v, R.menu.overflow_menu));
71-
7266
if (VERSION.SDK_INT >= VERSION_CODES.M) {
7367
AccessibilityManager am = getContext().getSystemService(AccessibilityManager.class);
7468
if (am != null) {
@@ -92,24 +86,7 @@ private void updateContentPaddingOnTalkback(View content, boolean talkbackEnable
9286
talkbackEnabled ? dockedToolbar.getMeasuredHeight() : 0));
9387
}
9488

95-
private void showMenu(View v, @MenuRes int menuRes) {
96-
PopupMenu popup = new PopupMenu(getContext(), v);
97-
// Inflating the Popup using xml file
98-
popup.getMenuInflater().inflate(menuRes, popup.getMenu());
99-
popup.setOnMenuItemClickListener(
100-
menuItem -> {
101-
Snackbar.make(
102-
dockedToolbar,
103-
menuItem.getTitle(),
104-
Snackbar.LENGTH_SHORT)
105-
.setAnchorView(dockedToolbar)
106-
.show();
107-
return true;
108-
});
109-
popup.show();
110-
}
111-
112-
private void setupSnackbarOnClick(View view) {
89+
private void setupSnackbarAndButtonParentOnClick(View view) {
11390
view.setOnClickListener(
11491
v ->
11592
Snackbar.make(
@@ -118,6 +95,11 @@ private void setupSnackbarOnClick(View view) {
11895
Snackbar.LENGTH_SHORT)
11996
.setAnchorView(dockedToolbar)
12097
.show());
98+
99+
// Since each button is being wrapped by a FrameLayout, we set a click listener on each button's
100+
// parent so that any item that is in the overflow menu has its click action properly set up.
101+
FrameLayout parent = (FrameLayout) view.getParent();
102+
parent.setOnClickListener(v -> view.performClick());
121103
}
122104

123105
@LayoutRes

catalog/java/io/material/catalog/dockedtoolbar/res/layout-sw600dp/cat_docked_toolbar_content.xml

Lines changed: 0 additions & 77 deletions
This file was deleted.

0 commit comments

Comments
 (0)