Skip to content

Commit 0697f6f

Browse files
committed
[Gradle] Enable non transitive R classes (resource namespacing) and fix errors
PiperOrigin-RevId: 738871402
1 parent e3f29ec commit 0697f6f

34 files changed

+141
-77
lines changed

catalog/java/io/material/catalog/color/ColorHarmonizationDemoActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public class ColorHarmonizationDemoActivity extends DemoActivity {
6464
R.id.cat_colors_error,
6565
R.id.cat_colors_harmonized_error,
6666
new int[] {
67-
R.attr.colorError,
67+
androidx.appcompat.R.attr.colorError,
6868
com.google.android.material.R.attr.colorOnError,
6969
com.google.android.material.R.attr.colorErrorContainer,
7070
com.google.android.material.R.attr.colorOnErrorContainer

catalog/java/io/material/catalog/color/ColorMainDemoFragment.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ private List<ColorRow> getColorRolesSurfaces() {
104104
private List<ColorRow> getColorRolesContent() {
105105
return Arrays.asList(
106106
new ColorRow(
107-
new ColorRoleItem(R.string.cat_color_role_primary, R.attr.colorPrimary),
107+
new ColorRoleItem(
108+
R.string.cat_color_role_primary, androidx.appcompat.R.attr.colorPrimary),
108109
new ColorRoleItem(R.string.cat_color_role_on_primary, com.google.android.material.R.attr.colorOnPrimary)),
109110
new ColorRow(
110111
new ColorRoleItem(
@@ -164,7 +165,8 @@ private List<ColorRow> getColorRolesContent() {
164165
private List<ColorRow> getColorRolesUtility() {
165166
return Arrays.asList(
166167
new ColorRow(
167-
new ColorRoleItem(R.string.cat_color_role_error, R.attr.colorError),
168+
new ColorRoleItem(
169+
R.string.cat_color_role_error, androidx.appcompat.R.attr.colorError),
168170
new ColorRoleItem(R.string.cat_color_role_on_error, com.google.android.material.R.attr.colorOnError)),
169171
new ColorRow(
170172
new ColorRoleItem(R.string.cat_color_role_error_container, com.google.android.material.R.attr.colorErrorContainer),

catalog/java/io/material/catalog/datepicker/DatePickerMainDemoFragment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ private CharSequence getTitleWithDescription() {
267267
String titleAndDescriptionText =
268268
context.getString(R.string.cat_picker_title_description_main) + alarmTimes;
269269
SpannableString spannable = new SpannableString(titleAndDescriptionText);
270-
int alarmTimesColor = resolveOrThrow(context, R.attr.colorPrimary);
270+
int alarmTimesColor = resolveOrThrow(context, androidx.appcompat.R.attr.colorPrimary);
271271
int spanStart = titleAndDescriptionText.indexOf(alarmTimes);
272272
int spanEnd = spanStart + alarmTimes.length();
273273
spannable.setSpan(

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,10 @@ public View onCreateView(
9494
TypedArray a =
9595
toolbarContext
9696
.getTheme()
97-
.obtainStyledAttributes(new int[] {com.google.android.material.R.attr.colorOnSurfaceVariant, R.attr.colorPrimary});
97+
.obtainStyledAttributes(
98+
new int[] {
99+
com.google.android.material.R.attr.colorOnSurfaceVariant, androidx.appcompat.R.attr.colorPrimary
100+
});
98101
menuIconColorUnchecked = a.getColor(0, 0);
99102
menuIconColorChecked = a.getColor(1, 0);
100103
a.recycle();

catalog/java/io/material/catalog/feature/FeatureDemoUtils.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,10 @@ public static void startFragmentInternal(
9090
}
9191
} else {
9292
transaction.setCustomAnimations(
93-
R.anim.abc_grow_fade_in_from_bottom,
94-
R.anim.abc_fade_out,
95-
R.anim.abc_fade_in,
96-
R.anim.abc_shrink_fade_out_from_bottom);
93+
androidx.appcompat.R.anim.abc_grow_fade_in_from_bottom,
94+
androidx.appcompat.R.anim.abc_fade_out,
95+
androidx.appcompat.R.anim.abc_fade_in,
96+
androidx.appcompat.R.anim.abc_shrink_fade_out_from_bottom);
9797
}
9898

9999
transaction

catalog/java/io/material/catalog/feature/MemoryView.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ protected void onAttachedToWindow() {
124124
TypedValue typedValue = new TypedValue();
125125
getContext()
126126
.getTheme()
127-
.resolveAttribute(R.attr.colorPrimary, typedValue, true);
127+
.resolveAttribute(androidx.appcompat.R.attr.colorPrimary, typedValue, true);
128128

129129
int colorPrimary = typedValue.data;
130130
paint.setColor(colorPrimary);

catalog/java/io/material/catalog/menu/MenuMainDemoFragment.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ public void setPopupItemLayoutRes(@LayoutRes int popupItemRes) {
173173

174174
private ListPopupWindow initializeListPopupMenu(View v) {
175175
ListPopupWindow listPopupWindow =
176-
new ListPopupWindow(getContext(), null, R.attr.listPopupWindowStyle);
176+
new ListPopupWindow(
177+
getContext(), null, androidx.appcompat.R.attr.listPopupWindowStyle);
177178
ArrayAdapter<CharSequence> adapter =
178179
new ArrayAdapter<>(
179180
getContext(),
@@ -198,7 +199,9 @@ private void highlightText(TextView textView) {
198199
Context context = textView.getContext();
199200
CharSequence text = textView.getText();
200201
TypedValue value = new TypedValue();
201-
context.getTheme().resolveAttribute(R.attr.colorPrimary, value, true);
202+
context
203+
.getTheme()
204+
.resolveAttribute(androidx.appcompat.R.attr.colorPrimary, value, true);
202205
Spannable spanText = Spannable.Factory.getInstance().newSpannable(text);
203206
spanText.setSpan(
204207
new BackgroundColorSpan(value.data), 0, text.length(), SPAN_EXCLUSIVE_EXCLUSIVE);

catalog/java/io/material/catalog/shapetheming/ShapeThemingDemoFragment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public View onCreateView(
5252
final TypedValue value = new TypedValue();
5353
wrappedContext
5454
.getTheme()
55-
.resolveAttribute(R.attr.colorPrimaryDark, value, true);
55+
.resolveAttribute(androidx.appcompat.R.attr.colorPrimaryDark, value, true);
5656
window.setStatusBarColor(value.data);
5757

5858
return super.onCreateView(layoutInflaterWithThemedContext, viewGroup, bundle);

catalog/java/io/material/catalog/topappbar/TopAppBarCollapsingMultilineDemoFragment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public View onCreateDemoView(
6464
Toolbar toolbar = view.findViewById(R.id.toolbar);
6565
AppCompatActivity activity = (AppCompatActivity) getActivity();
6666
activity.setSupportActionBar(toolbar);
67-
colorPrimary = MaterialColors.getColor(view, R.attr.colorPrimary);
67+
colorPrimary = MaterialColors.getColor(view, androidx.appcompat.R.attr.colorPrimary);
6868

6969
return view;
7070
}

gradle.properties

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ org.gradle.parallel=true
1818

1919
android.useAndroidX=true
2020
android.enableUnitTestBinaryResources=true
21-
# (b/379121671) Non-transitive R classes were enabled by default in AGP 8+
22-
android.nonTransitiveRClass=false
2321

2422
# Disable "The option setting 'android.enableUnitTestBinaryResources=true' is experimental and unsupported" warning
2523
android.suppressUnsupportedOptionWarnings=android.suppressUnsupportedOptionWarnings,android.enableUnitTestBinaryResources

lib/build.gradle

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ publishing {
156156

157157
publications {
158158
release(MavenPublication) {
159+
from components.findByName('release')
159160
artifact androidSourcesJar
160161
groupId = 'com.google.android.material'
161162
artifactId = 'material'
@@ -185,10 +186,6 @@ publishing {
185186
url = 'https://github.com/material-components/material-components-android'
186187
}
187188
}
188-
189-
afterEvaluate {
190-
from components.release
191-
}
192189
}
193190
}
194191
}

lib/java/com/google/android/material/appbar/MaterialToolbar.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public MaterialToolbar(@NonNull Context context) {
9292
}
9393

9494
public MaterialToolbar(@NonNull Context context, @Nullable AttributeSet attrs) {
95-
this(context, attrs, R.attr.toolbarStyle);
95+
this(context, attrs, androidx.appcompat.R.attr.toolbarStyle);
9696
}
9797

9898
public MaterialToolbar(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {

lib/java/com/google/android/material/card/MaterialCardViewHelper.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,16 @@ public MaterialCardViewHelper(
143143

144144
TypedArray cardViewAttributes =
145145
card.getContext()
146-
.obtainStyledAttributes(attrs, R.styleable.CardView, defStyleAttr, R.style.CardView);
147-
if (cardViewAttributes.hasValue(R.styleable.CardView_cardCornerRadius)) {
146+
.obtainStyledAttributes(
147+
attrs,
148+
androidx.cardview.R.styleable.CardView,
149+
defStyleAttr,
150+
androidx.cardview.R.style.CardView);
151+
if (cardViewAttributes.hasValue(androidx.cardview.R.styleable.CardView_cardCornerRadius)) {
148152
// If cardCornerRadius is set, let it override the shape appearance.
149153
shapeAppearanceModelBuilder.setAllCornerSizes(
150-
cardViewAttributes.getDimension(R.styleable.CardView_cardCornerRadius, 0));
154+
cardViewAttributes.getDimension(
155+
androidx.cardview.R.styleable.CardView_cardCornerRadius, 0));
151156
}
152157

153158
foregroundContentDrawable = new MaterialShapeDrawable();
@@ -199,7 +204,8 @@ void loadFromAttributes(@NonNull TypedArray attributes) {
199204
if (rippleColor == null) {
200205
rippleColor =
201206
ColorStateList.valueOf(
202-
MaterialColors.getColor(materialCardView, R.attr.colorControlHighlight));
207+
MaterialColors.getColor(
208+
materialCardView, androidx.appcompat.R.attr.colorControlHighlight));
203209
}
204210

205211
ColorStateList foregroundColor =

lib/java/com/google/android/material/carousel/CarouselLayoutManager.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,10 @@ private void setCarouselAttributes(Context context, AttributeSet attrs) {
207207
if (attrs != null) {
208208
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Carousel);
209209
setCarouselAlignment(a.getInt(R.styleable.Carousel_carousel_alignment, ALIGNMENT_START));
210-
setOrientation(a.getInt(R.styleable.RecyclerView_android_orientation, HORIZONTAL));
210+
setOrientation(
211+
a.getInt(
212+
androidx.recyclerview.R.styleable.RecyclerView_android_orientation,
213+
HORIZONTAL));
211214
a.recycle();
212215
}
213216
}

lib/java/com/google/android/material/checkbox/MaterialCheckBox.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ public MaterialCheckBox(Context context) {
225225
}
226226

227227
public MaterialCheckBox(Context context, @Nullable AttributeSet attrs) {
228-
this(context, attrs, R.attr.checkboxStyle);
228+
this(context, attrs, androidx.appcompat.R.attr.checkboxStyle);
229229
}
230230

231231
public MaterialCheckBox(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
@@ -809,8 +809,10 @@ private boolean isButtonDrawableLegacy(TintTypedArray attributes) {
809809
private ColorStateList getMaterialThemeColorsTintList() {
810810
if (materialThemeColorsTintList == null) {
811811
int[] checkBoxColorsList = new int[CHECKBOX_STATES.length];
812-
int colorControlActivated = MaterialColors.getColor(this, R.attr.colorControlActivated);
813-
int colorError = MaterialColors.getColor(this, R.attr.colorError);
812+
int colorControlActivated =
813+
MaterialColors.getColor(this, androidx.appcompat.R.attr.colorControlActivated);
814+
int colorError =
815+
MaterialColors.getColor(this, androidx.appcompat.R.attr.colorError);
814816
int colorSurface = MaterialColors.getColor(this, R.attr.colorSurface);
815817
int colorOnSurface = MaterialColors.getColor(this, R.attr.colorOnSurface);
816818

lib/java/com/google/android/material/color/HarmonizedColorAttributes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public final class HarmonizedColorAttributes {
3333

3434
private static final int[] HARMONIZED_MATERIAL_ATTRIBUTES =
3535
new int[] {
36-
R.attr.colorError,
36+
androidx.appcompat.R.attr.colorError,
3737
R.attr.colorOnError,
3838
R.attr.colorErrorContainer,
3939
R.attr.colorOnErrorContainer

lib/java/com/google/android/material/color/HarmonizedColorsOptions.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
package com.google.android.material.color;
1818

19-
import com.google.android.material.R;
20-
2119
import androidx.annotation.AttrRes;
2220
import androidx.annotation.ColorRes;
2321
import androidx.annotation.NonNull;
@@ -80,7 +78,9 @@ public static class Builder {
8078

8179
@NonNull @ColorRes private int[] colorResourceIds = new int[] {};
8280
@Nullable private HarmonizedColorAttributes colorAttributes;
83-
@AttrRes private int colorAttributeToHarmonizeWith = R.attr.colorPrimary;
81+
82+
@AttrRes
83+
private int colorAttributeToHarmonizeWith = androidx.appcompat.R.attr.colorPrimary;
8484

8585
/**
8686
* Sets the array of color resource ids for harmonization.

lib/java/com/google/android/material/color/MaterialColors.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
*/
1616
package com.google.android.material.color;
1717

18-
import com.google.android.material.R;
19-
2018
import static android.graphics.Color.TRANSPARENT;
2119
import static androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP;
2220

@@ -263,7 +261,10 @@ public static boolean isColorLight(@ColorInt int color) {
263261
public static int harmonizeWithPrimary(@NonNull Context context, @ColorInt int colorToHarmonize) {
264262
return harmonize(
265263
colorToHarmonize,
266-
getColor(context, R.attr.colorPrimary, MaterialColors.class.getCanonicalName()));
264+
getColor(
265+
context,
266+
androidx.appcompat.R.attr.colorPrimary,
267+
MaterialColors.class.getCanonicalName()));
267268
}
268269

269270
/**
@@ -348,7 +349,7 @@ public static int getSurfaceContainerHighFromSeed(
348349

349350
static boolean isLightTheme(@NonNull Context context) {
350351
return MaterialAttributes.resolveBoolean(
351-
context, R.attr.isLightTheme, /* defaultValue= */ true);
352+
context, androidx.appcompat.R.attr.isLightTheme, /* defaultValue= */ true);
352353
}
353354

354355
@ColorInt

lib/java/com/google/android/material/dialog/MaterialAlertDialogBuilder.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@
7171
*/
7272
public class MaterialAlertDialogBuilder extends AlertDialog.Builder {
7373

74-
@AttrRes private static final int DEF_STYLE_ATTR = R.attr.alertDialogStyle;
74+
@AttrRes
75+
private static final int DEF_STYLE_ATTR = androidx.appcompat.R.attr.alertDialogStyle;
76+
7577
@StyleRes private static final int DEF_STYLE_RES = R.style.MaterialAlertDialog_MaterialComponents;
7678

7779
@AttrRes

lib/java/com/google/android/material/internal/ThemeEnforcement.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@
4141
@RestrictTo(LIBRARY_GROUP)
4242
public final class ThemeEnforcement {
4343

44-
private static final int[] APPCOMPAT_CHECK_ATTRS = {R.attr.colorPrimary};
44+
private static final int[] APPCOMPAT_CHECK_ATTRS = {
45+
androidx.appcompat.R.attr.colorPrimary
46+
};
4547
private static final String APPCOMPAT_THEME_NAME = "Theme.AppCompat";
4648

4749
private static final int[] MATERIAL_CHECK_ATTRS = {R.attr.colorPrimaryVariant};

lib/java/com/google/android/material/loadingindicator/LoadingIndicator.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,11 @@ public int getContainerHeight() {
274274
public void setIndicatorColor(@ColorInt int... indicatorColors) {
275275
if (indicatorColors.length == 0) {
276276
// Uses theme primary color for indicator by default. Indicator color cannot be empty.
277-
indicatorColors = new int[] {MaterialColors.getColor(getContext(), R.attr.colorPrimary, -1)};
277+
indicatorColors =
278+
new int[] {
279+
MaterialColors.getColor(
280+
getContext(), androidx.appcompat.R.attr.colorPrimary, -1)
281+
};
278282
}
279283
if (!Arrays.equals(getIndicatorColor(), indicatorColors)) {
280284
specs.indicatorColors = indicatorColors;

lib/java/com/google/android/material/loadingindicator/LoadingIndicatorSpec.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,10 @@ public LoadingIndicatorSpec(
8585
private void loadIndicatorColors(@NonNull Context context, @NonNull TypedArray typedArray) {
8686
if (!typedArray.hasValue(R.styleable.LoadingIndicator_indicatorColor)) {
8787
// Uses theme primary color for indicator if not provided in the attribute set.
88-
indicatorColors = new int[] {MaterialColors.getColor(context, R.attr.colorPrimary, -1)};
88+
indicatorColors =
89+
new int[] {
90+
MaterialColors.getColor(context, androidx.appcompat.R.attr.colorPrimary, -1)
91+
};
8992
return;
9093
}
9194

lib/java/com/google/android/material/progressindicator/BaseProgressIndicator.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,11 @@ public int[] getIndicatorColor() {
589589
public void setIndicatorColor(@ColorInt int... indicatorColors) {
590590
if (indicatorColors.length == 0) {
591591
// Uses theme primary color for indicator by default. Indicator color cannot be empty.
592-
indicatorColors = new int[] {MaterialColors.getColor(getContext(), R.attr.colorPrimary, -1)};
592+
indicatorColors =
593+
new int[] {
594+
MaterialColors.getColor(
595+
getContext(), androidx.appcompat.R.attr.colorPrimary, -1)
596+
};
593597
}
594598
if (!Arrays.equals(getIndicatorColor(), indicatorColors)) {
595599
spec.indicatorColors = indicatorColors;

lib/java/com/google/android/material/progressindicator/BaseProgressIndicatorSpec.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,10 @@ protected BaseProgressIndicatorSpec(
182182
private void loadIndicatorColors(@NonNull Context context, @NonNull TypedArray typedArray) {
183183
if (!typedArray.hasValue(R.styleable.BaseProgressIndicator_indicatorColor)) {
184184
// Uses theme primary color for indicator if not provided in the attribute set.
185-
indicatorColors = new int[] {MaterialColors.getColor(context, R.attr.colorPrimary, -1)};
185+
indicatorColors =
186+
new int[] {
187+
MaterialColors.getColor(context, androidx.appcompat.R.attr.colorPrimary, -1)
188+
};
186189
return;
187190
}
188191

lib/java/com/google/android/material/radiobutton/MaterialRadioButton.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public MaterialRadioButton(@NonNull Context context) {
6464
}
6565

6666
public MaterialRadioButton(@NonNull Context context, @Nullable AttributeSet attrs) {
67-
this(context, attrs, R.attr.radioButtonStyle);
67+
this(context, attrs, androidx.appcompat.R.attr.radioButtonStyle);
6868
}
6969

7070
public MaterialRadioButton(
@@ -122,7 +122,8 @@ public boolean isUseMaterialThemeColors() {
122122

123123
private ColorStateList getMaterialThemeColorsTintList() {
124124
if (materialThemeColorsTintList == null) {
125-
int colorControlActivated = MaterialColors.getColor(this, R.attr.colorControlActivated);
125+
int colorControlActivated =
126+
MaterialColors.getColor(this, androidx.appcompat.R.attr.colorControlActivated);
126127
int colorOnSurface = MaterialColors.getColor(this, R.attr.colorOnSurface);
127128
int colorSurface = MaterialColors.getColor(this, R.attr.colorSurface);
128129

lib/java/com/google/android/material/resources/MaterialResources.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,12 @@ public static int getUnscaledTextSize(
200200
return defValue;
201201
}
202202

203-
TypedArray a = context.obtainStyledAttributes(textAppearance, R.styleable.TextAppearance);
203+
TypedArray a =
204+
context.obtainStyledAttributes(
205+
textAppearance, androidx.appcompat.R.styleable.TextAppearance);
204206
TypedValue v = new TypedValue();
205-
boolean available = a.getValue(R.styleable.TextAppearance_android_textSize, v);
207+
boolean available =
208+
a.getValue(androidx.appcompat.R.styleable.TextAppearance_android_textSize, v);
206209
a.recycle();
207210

208211
if (!available) {

0 commit comments

Comments
 (0)