summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorDeepanshu Gupta <deepanshu@google.com>2015-08-28 11:53:46 -0700
committerDeepanshu Gupta <deepanshu@google.com>2015-08-28 14:49:04 -0700
commit753517700dc6ee95b9945a6c8857aa8c633cde2a (patch)
tree40e7d1d51e024a8359c128fa399157ac3aa22961 /tools
parent7b933895481813425358bcfe56e0c1afa902a6d2 (diff)
downloadframeworks_base-753517700dc6ee95b9945a6c8857aa8c633cde2a.zip
frameworks_base-753517700dc6ee95b9945a6c8857aa8c633cde2a.tar.gz
frameworks_base-753517700dc6ee95b9945a6c8857aa8c633cde2a.tar.bz2
Fix android:theme parsing for custom views.
Change-Id: Iba83ba1d2e4a96461cc298a759e32e4e51e311a0
Diffstat (limited to 'tools')
-rw-r--r--tools/layoutlib/bridge/src/android/view/BridgeInflater.java22
1 files changed, 20 insertions, 2 deletions
diff --git a/tools/layoutlib/bridge/src/android/view/BridgeInflater.java b/tools/layoutlib/bridge/src/android/view/BridgeInflater.java
index 1e33e3a..f1726eb 100644
--- a/tools/layoutlib/bridge/src/android/view/BridgeInflater.java
+++ b/tools/layoutlib/bridge/src/android/view/BridgeInflater.java
@@ -36,6 +36,7 @@ import org.xmlpull.v1.XmlPullParser;
import android.annotation.NonNull;
import android.content.Context;
+import android.content.res.TypedArray;
import android.util.AttributeSet;
import java.io.File;
@@ -54,6 +55,9 @@ public final class BridgeInflater extends LayoutInflater {
private ResourceReference mResourceReference;
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.
* <p/>
@@ -135,11 +139,23 @@ public final class BridgeInflater extends LayoutInflater {
@Override
public View createViewFromTag(View parent, String name, Context context, AttributeSet attrs,
- boolean ignoreThemeAttrs) {
+ boolean ignoreThemeAttr) {
View view;
try {
- view = super.createViewFromTag(parent, name, context, attrs, ignoreThemeAttrs);
+ view = super.createViewFromTag(parent, name, context, attrs, ignoreThemeAttr);
} 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 {
view = loadCustomView(name, attrs);
@@ -153,6 +169,8 @@ public final class BridgeInflater extends LayoutInflater {
exception.initCause(e);
}
throw exception;
+ } finally {
+ mConstructorArgs[0] = lastContext;
}
}