Skip to content

Commit 8f62228

Browse files
dsn5ftcketcham
authored andcommitted
Remove CSL theme attribute workarounds
Also update androidx dependencies to get latest fixes: appcompat to 1.1.0-alpha04 and core to 1.1.0-alpha05 PiperOrigin-RevId: 246804285
1 parent a842c21 commit 8f62228

24 files changed

Lines changed: 27 additions & 257 deletions

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ ext {
2626

2727
androidXVersions = [
2828
annotation : '1.0.1',
29-
appCompat : '1.1.0-alpha01',
29+
appCompat : '1.1.0-alpha04',
3030
cardView : '1.0.0',
3131
coordinatorlayout : '1.1.0-alpha01',
32-
core : '1.1.0-alpha03',
32+
core : '1.1.0-alpha05',
3333
fragment : '1.0.0',
3434
legacySupportCoreUi : '1.0.0',
3535
legacySupportCoreUtils: '1.0.0',

catalog/java/io/material/catalog/card/res/layout/cat_card_rich_media_demo_fragment.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
android:layout_marginLeft="@dimen/cat_card_single_spacing"
8282
android:background="@android:color/transparent"
8383
android:contentDescription="@string/cat_card_rich_media_image_view_description"
84-
app:backgroundTint="?attr/colorOnSurfaceEmphasisMedium"
84+
app:backgroundTint="@color/mtrl_on_surface_emphasis_medium"
8585
app:backgroundTintMode="add"
8686
app:srcCompat="@drawable/ic_components_24px"/>
8787
</LinearLayout>
@@ -178,7 +178,7 @@
178178
android:layout_height="194dp"
179179
android:background="@android:color/transparent"
180180
android:contentDescription="@string/cat_card_rich_media_image_view_description"
181-
app:backgroundTint="?attr/colorOnSurfaceEmphasisMedium"
181+
app:backgroundTint="@color/mtrl_on_surface_emphasis_medium"
182182
app:backgroundTintMode="add"
183183
app:srcCompat="@drawable/ic_components_24px"/>
184184

@@ -243,7 +243,7 @@
243243
android:layout_height="194dp"
244244
android:background="@android:color/transparent"
245245
android:contentDescription="@string/cat_card_rich_media_image_view_description"
246-
app:backgroundTint="?attr/colorOnSurfaceEmphasisMedium"
246+
app:backgroundTint="@color/mtrl_on_surface_emphasis_medium"
247247
app:backgroundTintMode="add"
248248
app:srcCompat="@drawable/ic_components_24px"/>
249249

catalog/java/io/material/catalog/feature/DemoLandingFragment.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import io.material.catalog.R;
2020

21+
import android.content.Context;
2122
import android.content.Intent;
2223
import android.content.res.ColorStateList;
2324
import android.content.res.TypedArray;
@@ -27,6 +28,7 @@
2728
import androidx.annotation.DimenRes;
2829
import androidx.annotation.Nullable;
2930
import androidx.annotation.StringRes;
31+
import com.google.android.material.resources.MaterialResources;
3032
import androidx.fragment.app.Fragment;
3133
import androidx.core.view.MarginLayoutParamsCompat;
3234
import androidx.core.view.MenuItemCompat;
@@ -57,6 +59,7 @@ public void onCreate(@Nullable Bundle bundle) {
5759
setHasOptionsMenu(true);
5860
}
5961

62+
@SuppressWarnings("RestrictTo")
6063
@Nullable
6164
@Override
6265
public View onCreateView(
@@ -72,12 +75,13 @@ public View onCreateView(
7275
activity.getSupportActionBar().setTitle(getTitleResId());
7376
activity.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
7477

78+
Context toolbarContext = toolbar.getContext();
7579
TypedArray a =
76-
toolbar
77-
.getContext()
80+
toolbarContext
7881
.getTheme()
7982
.obtainStyledAttributes(new int[] {R.attr.colorControlNormal, R.attr.colorAccent});
80-
colorControlNormal = a.getColor(0, 0);
83+
colorControlNormal =
84+
MaterialResources.getColorStateList(toolbarContext, a, 0).getDefaultColor();
8185
colorAccent = a.getColor(1, 0);
8286

8387
TextView descriptionTextView = view.findViewById(R.id.cat_demo_landing_description);

lib/java/com/google/android/material/appbar/res/values/styles.xml

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -53,34 +53,19 @@
5353
<item name="maxButtonHeight">@dimen/mtrl_toolbar_default_height</item>
5454
</style>
5555

56-
<!--
57-
We are currently waiting for better attribute support in ColorStateLists to land in the support
58-
library. https://android-review.googlesource.com/757091. Because we can't fully support color
59-
theming on all API levels for the Toolbar Primary and Surface styles, we are requiring you to
60-
opt in for now.
61-
62-
As a workaround to enable correct color theming in your app for API < 23, in addition to setting
63-
the colorOnPrimary and colorOnSurface attributes in your theme, redefine these color resources
64-
to match with the correct opacity. For example, if you set the colorOnPrimary attribute in your
65-
theme to red (#FF0000). You should redefine mtrl_on_primary_disabled to be #61FF000,
66-
mtrl_on_primary_emphasis_high_type to be #DEFF0000, and mtrl_on_primary_emphasis_medium to be
67-
#99FF0000. That sets the color values to be the correct color and opacity to match the correct
68-
color theming that will be applied on API level 23 and up. When the bugs are fixed in the
69-
support library you can remove these color definitions.
70-
-->
7156
<style name="Widget.MaterialComponents.Toolbar.Primary">
7257
<item name="android:elevation" tools:ignore="NewApi">@dimen/design_appbar_elevation</item>
7358
<item name="android:background">?attr/colorPrimary</item>
7459
<item name="titleTextColor">?attr/colorOnPrimary</item>
75-
<item name="subtitleTextColor">?attr/colorOnPrimaryEmphasisMedium</item>
60+
<item name="subtitleTextColor">@color/mtrl_on_primary_emphasis_medium</item>
7661
<!-- Note: this theme overlay will only work if the style is applied directly to a Toolbar. -->
7762
<item name="android:theme">@style/ThemeOverlay.MaterialComponents.Toolbar.Primary</item>
7863
</style>
7964

8065
<style name="Widget.MaterialComponents.Toolbar.Surface">
8166
<item name="android:background">?attr/colorSurface</item>
82-
<item name="titleTextColor">?attr/colorOnSurfaceEmphasisHighType</item>
83-
<item name="subtitleTextColor">?attr/colorOnSurfaceEmphasisMedium</item>
67+
<item name="titleTextColor">@color/mtrl_on_surface_emphasis_high_type</item>
68+
<item name="subtitleTextColor">@color/mtrl_on_surface_emphasis_medium</item>
8469
<!-- Note: this theme overlay will only work if the style is applied directly to a Toolbar. -->
8570
<item name="android:theme">@style/ThemeOverlay.MaterialComponents.Toolbar.Surface</item>
8671
</style>
@@ -91,8 +76,8 @@
9176
</style>
9277

9378
<style name="ThemeOverlay.MaterialComponents.Toolbar.Surface" parent="">
94-
<item name="colorControlNormal">?attr/colorOnSurfaceEmphasisMedium</item>
95-
<item name="actionMenuTextColor">?attr/colorOnSurfaceEmphasisMedium</item>
79+
<item name="colorControlNormal">@color/mtrl_on_surface_emphasis_medium</item>
80+
<item name="actionMenuTextColor">@color/mtrl_on_surface_emphasis_medium</item>
9681
</style>
9782

9883
<!-- ActionBar styles -->
@@ -124,7 +109,7 @@
124109

125110
<style name="ThemeOverlay.MaterialComponents.ActionBar.Primary" parent="">
126111
<item name="android:textColorPrimary">?attr/colorOnPrimary</item>
127-
<item name="android:textColorSecondary">?attr/colorOnPrimaryEmphasisMedium</item>
112+
<item name="android:textColorSecondary">@color/mtrl_on_primary_emphasis_medium</item>
128113
<item name="actionMenuTextColor">?attr/colorOnPrimary</item>
129114
<item name="colorControlNormal">?attr/colorOnPrimary</item>
130115
<!-- Counteracts the effect of setting textColorPrimary for popup menus. -->
@@ -134,10 +119,10 @@
134119
</style>
135120

136121
<style name="ThemeOverlay.MaterialComponents.ActionBar.Surface" parent="">
137-
<item name="android:textColorPrimary">?attr/colorOnSurfaceEmphasisHighType</item>
138-
<item name="android:textColorSecondary">?attr/colorOnSurfaceEmphasisMedium</item>
139-
<item name="actionMenuTextColor">?attr/colorOnSurfaceEmphasisMedium</item>
140-
<item name="colorControlNormal">?attr/colorOnSurfaceEmphasisMedium</item>
122+
<item name="android:textColorPrimary">@color/mtrl_on_surface_emphasis_high_type</item>
123+
<item name="android:textColorSecondary">@color/mtrl_on_surface_emphasis_medium</item>
124+
<item name="actionMenuTextColor">@color/mtrl_on_surface_emphasis_medium</item>
125+
<item name="colorControlNormal">@color/mtrl_on_surface_emphasis_medium</item>
141126
<!-- Counteracts the effect of setting textColorPrimary for popup menus. -->
142127
<item name="popupTheme">@style/ThemeOverlay.AppCompat.Light</item>
143128
<!-- Used to tint the ActionMode background and preserve the underline. -->

lib/java/com/google/android/material/bottomappbar/BottomAppBar.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -85,19 +85,6 @@
8585
* because the BottomAppBar manages its background internally. Instead use {@code
8686
* app:backgroundTint}.
8787
*
88-
* <p>We are currently waiting for better attribute support in ColorStateLists to land in the
89-
* support library. https://android-review.googlesource.com/757091. Because we can't fully support
90-
* color theming on all API levels for the BottomAppBar, to use the default theme, we are requiring
91-
* you to opt in for now.
92-
*
93-
* <p>As a workaround to enable correct color theming in your app for API < 23, in addition to
94-
* setting the colorOnSurface attribute in your theme, redefine {@code
95-
* mtrl_on_surface_emphasis_medium} to match with the correct opacity. For example, if you set
96-
* {@code colorOnSurface} in your theme to red (#FF0000). You should redefine {@code
97-
* mtrl_on_surface_emphasis_medium} to be #99FF0000. This sets the color value to be the correct
98-
* color and opacity to match the correct color theming that will be applied on API level 23 and up.
99-
* When the bugs are fixed in the support library you can remove these color definitions.
100-
*
10188
* <p>To enable color theming for menu items you will also need to set the {@code
10289
* materialThemeOverlay} attribute to a ThemeOverlay which sets the {@code colorControlNormal}
10390
* attribute to the correct color. For example, if the background of the BottomAppBar is {@code

lib/java/com/google/android/material/bottomappbar/res/values/styles.xml

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,7 @@
1515
~ limitations under the License.
1616
-->
1717
<resources>
18-
<!--
19-
We are currently waiting for better attribute support in ColorStateLists to land in the support
20-
library. https://android-review.googlesource.com/757091. Because we can't fully support color
21-
theming on all API levels for the BottomAppBar, we are requiring you to opt in for now.
2218

23-
As a workaround to enable correct color theming in your app for API < 23 if you are using this
24-
style, in addition to setting the colorOnSurface attributes in your theme, redefine
25-
mtrl_on_surface_emphasis_medium to match with the correct opacity. For example, if you set the
26-
colorOnSurface attribute in your theme to red (#FF0000). You should redefine
27-
mtrl_on_surface_emphasis_medium to be #99FF0000. This sets the color value to be the correct
28-
color and opacity to match the correct color theming that will be applied on API level 23 and
29-
up. When the bugs are fixed in the support library you can remove this color definition.
30-
-->
3119
<style name="Widget.MaterialComponents.BottomAppBar" parent="Widget.AppCompat.Toolbar">
3220
<item name="enforceMaterialTheme">true</item>
3321
<item name="backgroundTint">?attr/colorSurface</item>
@@ -47,8 +35,8 @@
4735
</style>
4836

4937
<style name="ThemeOverlay.MaterialComponents.BottomAppBar.Surface" parent="">
50-
<item name="colorControlNormal">?attr/colorOnSurfaceEmphasisMedium</item>
51-
<item name="actionMenuTextColor">?attr/colorOnSurfaceEmphasisMedium</item>
38+
<item name="colorControlNormal">@color/mtrl_on_surface_emphasis_medium</item>
39+
<item name="actionMenuTextColor">@color/mtrl_on_surface_emphasis_medium</item>
5240
</style>
5341

5442
<style name="ThemeOverlay.MaterialComponents.BottomAppBar.Primary" parent="">

lib/java/com/google/android/material/color/res-public/values/public.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,6 @@
4242
<public name="mtrl_on_surface_disabled" type="color"/>
4343
<public name="mtrl_on_surface_emphasis_high_type" type="color"/>
4444
<public name="mtrl_on_surface_emphasis_medium" type="color"/>
45-
<public name="mtrl_dark_on_primary_disabled" type="color"/>
46-
<public name="mtrl_dark_on_primary_emphasis_high_type" type="color"/>
47-
<public name="mtrl_dark_on_primary_emphasis_medium" type="color"/>
48-
<public name="mtrl_dark_on_surface_disabled" type="color"/>
49-
<public name="mtrl_dark_on_surface_emphasis_high_type" type="color"/>
50-
<public name="mtrl_dark_on_surface_emphasis_medium" type="color"/>
5145
<public name="mtrl_emphasis_high_type" format="float" type="dimen" />
5246
<public name="mtrl_emphasis_medium" format="float" type="dimen"/>
5347
<public name="mtrl_emphasis_disabled" format="float" type="dimen"/>

lib/java/com/google/android/material/color/res/color-v23/mtrl_dark_on_primary_disabled.xml

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

lib/java/com/google/android/material/color/res/color-v23/mtrl_dark_on_primary_emphasis_high_type.xml

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

lib/java/com/google/android/material/color/res/color-v23/mtrl_dark_on_primary_emphasis_medium.xml

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

0 commit comments

Comments
 (0)