Skip to content

Commit 4e78a59

Browse files
wcshicketcham
authored andcommitted
Add button to switch the Catalog app in and out of edge to edge mode.
PiperOrigin-RevId: 262378430
1 parent 440eec1 commit 4e78a59

11 files changed

Lines changed: 187 additions & 18 deletions

File tree

catalog/baseline.xml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,17 +1427,6 @@
14271427
column="4"/>
14281428
</issue>
14291429

1430-
<issue
1431-
id="ContentDescription"
1432-
message="Missing `contentDescription` attribute on image"
1433-
errorLine1=" &lt;ImageButton"
1434-
errorLine2=" ~~~~~~~~~~~">
1435-
<location
1436-
file="java/io/material/catalog/tableofcontents/res/layout/cat_toc_header.xml"
1437-
line="45"
1438-
column="4"/>
1439-
</issue>
1440-
14411430
<issue
14421431
id="KeyboardInaccessibleWidget"
14431432
message="&apos;clickable&apos; attribute found, please also add &apos;focusable&apos;"

catalog/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ def srcDirs = [
5757
'textfield',
5858
'themeswitcher',
5959
'topappbar',
60-
'transformation'
60+
'transformation',
61+
'windowpreferences'
6162
]
6263

6364
android {

catalog/java/io/material/catalog/application/theme/res/values/ids.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@
1717
<resources>
1818

1919
<item name="cat_toc_theme_button" type="id"/>
20+
<item name="cat_edge_to_edge_button" type="id"/>
2021

2122
</resources>

catalog/java/io/material/catalog/application/theme/res/values/styles.xml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,24 @@
2626
<item name="navigationIcon">@drawable/ic_close_vd_theme_24px</item>
2727
</style>
2828

29-
<style name="Widget.Catalog.ChooseThemeButton" parent="Widget.AppCompat.ImageButton">
30-
<item name="android:id">@id/cat_toc_theme_button</item>
29+
<style name="Widget.Catalog.TocButton" parent="Widget.AppCompat.ImageButton">
3130
<item name="android:layout_width">@dimen/mtrl_min_touch_target_size</item>
3231
<item name="android:layout_height">@dimen/mtrl_min_touch_target_size</item>
33-
<item name="android:layout_gravity">center_vertical|end</item>
3432
<item name="android:background">?attr/actionBarItemBackground</item>
33+
</style>
34+
35+
<style name="Widget.Catalog.ChooseThemeButton" parent="Widget.Catalog.TocButton">
36+
<item name="android:id">@id/cat_toc_theme_button</item>
37+
<item name="android:layout_gravity">center_vertical|end</item>
3538
<item name="srcCompat">@drawable/abc_ic_menu_overflow_material</item>
3639
</style>
3740

41+
<style name="Widget.Catalog.EdgeToEdgeButton" parent="Widget.Catalog.TocButton">
42+
<item name="android:id">@id/cat_edge_to_edge_button</item>
43+
<item name="android:layout_gravity">center_vertical</item>
44+
<item name="srcCompat">@drawable/ic_edge_to_edge_enable_24dp</item>
45+
</style>
46+
3847
<style name="ThemeOverlay.Catalog.AppBarLayout" parent="">
3948
<item name="android:textColorPrimary">?attr/colorOnPrimarySurface</item>
4049
<item name="colorControlNormal">?attr/colorOnPrimarySurface</item>
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 (C) 2019 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:tint="?attr/colorControlNormal"
21+
android:viewportHeight="24.0"
22+
android:viewportWidth="24.0">
23+
<path
24+
android:fillColor="@android:color/white"
25+
android:pathData="M5,16h3v3h2v-5L5,14v2zM8,8L5,8v2h5L10,5L8,5v3zM14,19h2v-3h3v-2h-5v5zM16,8L16,5h-2v5h5L19,8h-3z"/>
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 (C) 2019 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:viewportHeight="24.0"
21+
android:viewportWidth="24.0"
22+
android:tint="?attr/colorControlNormal">
23+
<path
24+
android:fillColor="@android:color/white"
25+
android:pathData="M7,14L5,14v5h5v-2L7,17v-3zM5,10h2L7,7h3L10,5L5,5v5zM17,17h-3v2h5v-5h-2v3zM14,5v2h3v3h2L19,5h-5z"/>
26+
</vector>

catalog/java/io/material/catalog/main/MainActivity.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import io.material.catalog.tableofcontents.TocModule;
3636
import io.material.catalog.themeswitcher.ThemeOverlayUtils;
3737
import io.material.catalog.themeswitcher.ThemeSwitcherHelper.ThemeSwitcherActivity;
38+
import io.material.catalog.windowpreferences.WindowPreferencesManager;
3839
import javax.inject.Inject;
3940

4041
/**
@@ -49,8 +50,10 @@ public class MainActivity extends DaggerAppCompatActivity implements ThemeSwitch
4950
@Override
5051
protected void onCreate(Bundle savedInstanceState) {
5152
ThemeOverlayUtils.applyThemeOverlays(this);
52-
5353
super.onCreate(savedInstanceState);
54+
WindowPreferencesManager windowPreferencesManager = new WindowPreferencesManager(this);
55+
windowPreferencesManager.applyEdgeToEdgePreference(getWindow());
56+
5457
setContentView(R.layout.cat_main_activity);
5558

5659
if (savedInstanceState == null) {

catalog/java/io/material/catalog/tableofcontents/TocFragment.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import io.material.catalog.feature.FeatureDemoUtils;
4141
import io.material.catalog.themeswitcher.ThemePreferencesManager;
4242
import io.material.catalog.themeswitcher.ThemeSwitcherResourceProvider;
43+
import io.material.catalog.windowpreferences.WindowPreferencesManager;
4344
import java.text.Collator;
4445
import java.util.ArrayList;
4546
import java.util.Collections;
@@ -58,17 +59,20 @@ public class TocFragment extends DaggerFragment {
5859
@Inject ThemeSwitcherResourceProvider themeSwitcherResourceProvider;
5960

6061
private ThemePreferencesManager themePreferencesManager;
62+
private WindowPreferencesManager windowPreferencesManager;
6163
private AppBarLayout appBarLayout;
6264
private View gridTopDivider;
6365
private RecyclerView recyclerView;
6466
private ImageButton themeButton;
67+
private ImageButton edgeToEdgeButton;
6568

6669
@Override
6770
public void onCreate(@Nullable Bundle bundle) {
6871
super.onCreate(bundle);
6972

7073
themePreferencesManager =
7174
new ThemePreferencesManager(getContext(), themeSwitcherResourceProvider);
75+
windowPreferencesManager = new WindowPreferencesManager(getContext());
7276

7377
String defaultDemo = FeatureDemoUtils.getDefaultDemo(getContext());
7478
if (!defaultDemo.isEmpty() && bundle == null) {
@@ -102,6 +106,7 @@ public View onCreateView(
102106
gridTopDivider = view.findViewById(R.id.cat_toc_grid_top_divider);
103107
recyclerView = view.findViewById(R.id.cat_toc_grid);
104108
themeButton = view.findViewById(R.id.cat_toc_theme_button);
109+
edgeToEdgeButton = view.findViewById(R.id.cat_edge_to_edge_button);
105110

106111
if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
107112
addGridTopDividerVisibilityListener();
@@ -133,6 +138,7 @@ public View onCreateView(
133138

134139
initThemeButton();
135140

141+
initEdgeToEdgeButton();
136142
return view;
137143
}
138144

@@ -168,4 +174,26 @@ private void initThemeButton() {
168174
themePreferencesManager.applyTheme();
169175
themeButton.setOnClickListener(v -> themePreferencesManager.showChooseThemePopup(themeButton));
170176
}
177+
178+
private void initEdgeToEdgeButton() {
179+
if (VERSION.SDK_INT < VERSION_CODES.LOLLIPOP) {
180+
// Hide button because setting system ui flags is not supported pre-Lollipop.
181+
edgeToEdgeButton.setVisibility(View.GONE);
182+
return;
183+
}
184+
edgeToEdgeButton.setImageResource(
185+
windowPreferencesManager.isEdgeToEdgeEnabled()
186+
? R.drawable.ic_edge_to_edge_disable_24dp
187+
: R.drawable.ic_edge_to_edge_enable_24dp);
188+
edgeToEdgeButton.setContentDescription(
189+
getString(
190+
windowPreferencesManager.isEdgeToEdgeEnabled()
191+
? R.string.cat_edge_to_edge_enable_description
192+
: R.string.cat_edge_to_edge_disable_description));
193+
edgeToEdgeButton.setOnClickListener(
194+
v -> {
195+
windowPreferencesManager.toggleEdgeToEdgeEnabled();
196+
getActivity().recreate();
197+
});
198+
}
171199
}

catalog/java/io/material/catalog/tableofcontents/res/layout/cat_toc_header.xml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
<ImageView
3030
android:layout_width="wrap_content"
3131
android:layout_height="wrap_content"
32-
android:layout_marginRight="4dp"
3332
android:layout_marginEnd="4dp"
33+
android:layout_marginRight="4dp"
3434
android:contentDescription="@null"
3535
android:importantForAccessibility="no"
3636
app:srcCompat="@drawable/ic_logo_components_48px"/>
@@ -43,5 +43,11 @@
4343
</LinearLayout>
4444

4545
<ImageButton
46-
style="@style/Widget.Catalog.ChooseThemeButton"/>
46+
style="@style/Widget.Catalog.EdgeToEdgeButton"
47+
android:contentDescription="@string/cat_choose_theme_description"/>
48+
49+
<ImageButton
50+
style="@style/Widget.Catalog.ChooseThemeButton"
51+
android:contentDescription="@string/cat_edge_to_edge_enable_description"/>
52+
4753
</FrameLayout>

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,7 @@
1818
<resources>
1919
<string name="cat_toc_title">Material Components</string>
2020
<string name="cat_toc_status_wip">WIP</string>
21+
<string name="cat_edge_to_edge_enable_description">Enable edge to edge</string>
22+
<string name="cat_edge_to_edge_disable_description">Disable edge to edge</string>
23+
<string name="cat_choose_theme_description">Choose theme</string>
2124
</resources>

0 commit comments

Comments
 (0)