Update ThemeEnforcement context to read only the android:theme attribute from the style

PiperOrigin-RevId: 206313825
This commit is contained in:
cketcham 2018-07-27 07:20:19 -07:00 committed by gsajith
parent ffa7b10cae
commit 6f714ecc4f

View File

@ -231,10 +231,6 @@ public final class ThemeEnforcement {
* defStyleAttr to use a theme overlay if one has been defined.
*/
public static Context createThemedContext(Context context, int defStyleAttr) {
if (context instanceof ContextThemeWrapper) {
return context;
}
TypedArray a = context.getTheme().obtainStyledAttributes(new int[] {defStyleAttr});
int style = a.getResourceId(0 /* index */, 0 /* defaultVal */);
a.recycle();
@ -244,6 +240,16 @@ public final class ThemeEnforcement {
return context;
}
return new ContextThemeWrapper(context, style);
a = context.obtainStyledAttributes(style, new int[] {android.R.attr.theme});
int themeId = a.getResourceId(0 /* index */, 0 /* defaultVal */);
a.recycle();
if (themeId != 0 && (!(context instanceof ContextThemeWrapper)
|| ((ContextThemeWrapper) context).getThemeResId() != themeId)) {
// If the context isn't a ContextThemeWrapper, or it is but does not have
// the same theme as we need, wrap it in a new wrapper
context = new ContextThemeWrapper(context, themeId);
}
return context;
}
}