Skip to content

Commit e647265

Browse files
committed
[Internal] Replaced MaterialThemeOverlay#wrap existing public wrap method.
PiperOrigin-RevId: 698796795
1 parent afc392c commit e647265

File tree

4 files changed

+62
-8
lines changed

4 files changed

+62
-8
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
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+
17+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
18+
xmlns:tools="http://schemas.android.com/tools"
19+
android:width="24dp"
20+
android:height="24dp"
21+
android:viewportWidth="960"
22+
android:viewportHeight="960"
23+
android:tint="?attr/colorControlNormal"
24+
android:autoMirrored="true"
25+
tools:ignore="NewApi">
26+
<path
27+
android:fillColor="@android:color/white"
28+
android:pathData="M120,720v-80L640,640v80L120,720ZM784,680L584,480L784,280l56,56L696,480L840,624l-56,56ZM120,520v-80L520,440v80L120,520ZM120,320v-80L640,240v80L120,320Z"/>
29+
</vector>

catalog/java/io/material/catalog/navigationrail/NavigationRailSubMenuDemoFragment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public View onCreateDemoView(
8383
efab.extend();
8484
navigationRailView.expand();
8585
button.setContentDescription(getResources().getString(R.string.cat_navigation_rail_collapse_button_description));
86-
button.setImageResource(R.drawable.gs_menu_open_vd_theme_24);
86+
button.setImageResource(R.drawable.ic_drawer_menu_open_24px);
8787
}
8888
});
8989
return view;

lib/java/com/google/android/material/button/MaterialButton.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ public MaterialButton(@NonNull Context context, @Nullable AttributeSet attrs) {
265265

266266
public MaterialButton(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
267267
super(
268-
wrap(context, attrs, defStyleAttr, DEF_STYLE_RES, MATERIAL_SIZE_OVERLAY_ATTR),
268+
wrap(context, attrs, defStyleAttr, DEF_STYLE_RES, new int[] { MATERIAL_SIZE_OVERLAY_ATTR }),
269269
attrs,
270270
defStyleAttr);
271271
// Ensure we are using the correctly themed context rather than the context that was passed in.

lib/java/com/google/android/material/theme/overlay/MaterialThemeOverlay.java

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,44 @@ private MaterialThemeOverlay() {}
5050
private static final int[] MATERIAL_THEME_OVERLAY_ATTR = new int[] {R.attr.materialThemeOverlay};
5151

5252
/**
53-
* Uses the materialThemeOverlay attribute to create a themed context. This allows us to use
54-
* MaterialThemeOverlay with a default style, and gives us some protection against losing our
55-
* ThemeOverlay by clients who set android:theme or app:theme. If android:theme or app:theme is
56-
* specified by the client, any attributes defined there will take precedence over attributes
57-
* defined in materialThemeOverlay.
53+
* Uses the materialThemeOverlay attribute to create a themed context.
54+
*
55+
* <p>This allows us to use MaterialThemeOverlay with a default style, and gives us some
56+
* protection against losing our ThemeOverlay by clients who set android:theme or app:theme.
57+
* If android:theme or app:theme is specified by the client, any attributes defined there
58+
* will take precedence over attributes defined in materialThemeOverlay.
59+
*/
60+
@NonNull
61+
public static Context wrap(
62+
@NonNull Context context,
63+
@Nullable AttributeSet set,
64+
@AttrRes int defStyleAttr,
65+
@StyleRes int defStyleRes) {
66+
return wrap(context, set, defStyleAttr, defStyleRes, new int[] {});
67+
}
68+
69+
/**
70+
* Uses the materialThemeOverlay attribute and optionalAttr attributes to create a combined
71+
* themed context.
72+
*
73+
* <p>The final theme overlay will apply materialThemeOverlay first, then the optionalAttr
74+
* overlays in order.
75+
*
76+
* <p>This facilitates creating locally scoped, re-usable overlays for component variants. For
77+
* example, if buttons can be one of two colors and one of three shapes, instead of creating a
78+
* style for each color-shape combination, an overlay can be created for each color and
79+
* each shape. The button can then wrap its context and pass both overlay attributes to
80+
* optionalAttrs before reading color and shape values.
81+
*
82+
* @see #wrap(Context, AttributeSet, int, int)
5883
*/
5984
@NonNull
6085
public static Context wrap(
6186
@NonNull Context context,
6287
@Nullable AttributeSet set,
6388
@AttrRes int defStyleAttr,
6489
@StyleRes int defStyleRes,
65-
@NonNull int... optionalAttrs) {
90+
@NonNull int[] optionalAttrs) {
6691
int materialThemeOverlayId =
6792
obtainMaterialThemeOverlayId(context, set, defStyleAttr, defStyleRes);
6893
boolean contextHasOverlay =

0 commit comments

Comments
 (0)