am b8ae1879: Merge "Fix android:theme parsing for custom views." into mnc-ub-dev
* commit 'b8ae187932ff783711ea8715d7f5891d9e4ebb32': Fix android:theme parsing for custom views.
This commit is contained in:
@@ -36,6 +36,7 @@ import org.xmlpull.v1.XmlPullParser;
|
|||||||
|
|
||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.res.TypedArray;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -54,6 +55,9 @@ public final class BridgeInflater extends LayoutInflater {
|
|||||||
private ResourceReference mResourceReference;
|
private ResourceReference mResourceReference;
|
||||||
private Map<View, String> mOpenDrawerLayouts;
|
private Map<View, String> mOpenDrawerLayouts;
|
||||||
|
|
||||||
|
// Keep in sync with the same value in LayoutInflater.
|
||||||
|
private static final int[] ATTRS_THEME = new int[] {com.android.internal.R.attr.theme };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List of class prefixes which are tried first by default.
|
* List of class prefixes which are tried first by default.
|
||||||
* <p/>
|
* <p/>
|
||||||
@@ -135,11 +139,23 @@ public final class BridgeInflater extends LayoutInflater {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View createViewFromTag(View parent, String name, Context context, AttributeSet attrs,
|
public View createViewFromTag(View parent, String name, Context context, AttributeSet attrs,
|
||||||
boolean ignoreThemeAttrs) {
|
boolean ignoreThemeAttr) {
|
||||||
View view;
|
View view;
|
||||||
try {
|
try {
|
||||||
view = super.createViewFromTag(parent, name, context, attrs, ignoreThemeAttrs);
|
view = super.createViewFromTag(parent, name, context, attrs, ignoreThemeAttr);
|
||||||
} catch (InflateException e) {
|
} catch (InflateException e) {
|
||||||
|
// Creation of ContextThemeWrapper code is same as in the super method.
|
||||||
|
// Apply a theme wrapper, if allowed and one is specified.
|
||||||
|
if (!ignoreThemeAttr) {
|
||||||
|
final TypedArray ta = context.obtainStyledAttributes(attrs, ATTRS_THEME);
|
||||||
|
final int themeResId = ta.getResourceId(0, 0);
|
||||||
|
if (themeResId != 0) {
|
||||||
|
context = new ContextThemeWrapper(context, themeResId);
|
||||||
|
}
|
||||||
|
ta.recycle();
|
||||||
|
}
|
||||||
|
final Object lastContext = mConstructorArgs[0];
|
||||||
|
mConstructorArgs[0] = context;
|
||||||
// try to load the class from using the custom view loader
|
// try to load the class from using the custom view loader
|
||||||
try {
|
try {
|
||||||
view = loadCustomView(name, attrs);
|
view = loadCustomView(name, attrs);
|
||||||
@@ -153,6 +169,8 @@ public final class BridgeInflater extends LayoutInflater {
|
|||||||
exception.initCause(e);
|
exception.initCause(e);
|
||||||
}
|
}
|
||||||
throw exception;
|
throw exception;
|
||||||
|
} finally {
|
||||||
|
mConstructorArgs[0] = lastContext;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user