Loading tools/layoutlib/bridge/src/android/content/res/BridgeResources.java +1 −1 Original line number Diff line number Diff line Loading @@ -163,7 +163,7 @@ public final class BridgeResources extends Resources { Pair<String, ResourceValue> value = getResourceValue(id, mPlatformResourceFlag); if (value != null) { return ResourceHelper.getDrawable(value.getSecond(), mContext); return ResourceHelper.getDrawable(value.getSecond(), mContext, theme); } // id was not found or not resolved. Throw a NotFoundException. Loading tools/layoutlib/bridge/src/android/content/res/BridgeTypedArray.java +9 −1 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ import com.android.resources.ResourceType; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import android.content.res.Resources.Theme; import android.graphics.drawable.Drawable; import android.util.DisplayMetrics; import android.util.TypedValue; Loading Loading @@ -115,6 +116,13 @@ public final class BridgeTypedArray extends TypedArray { } } /** * Set the theme to be used for inflating drawables. */ public void setTheme(Theme theme) { mTheme = theme; } /** * Return the number of values in this array. */ Loading Loading @@ -663,7 +671,7 @@ public final class BridgeTypedArray extends TypedArray { } ResourceValue value = mResourceData[index]; return ResourceHelper.getDrawable(value, mContext); return ResourceHelper.getDrawable(value, mContext, mTheme); } Loading tools/layoutlib/bridge/src/android/content/res/Resources_Theme_Delegate.java +10 −6 Original line number Diff line number Diff line Loading @@ -58,7 +58,8 @@ public class Resources_Theme_Delegate { Resources thisResources, Theme thisTheme, int[] attrs) { boolean changed = setupResources(thisTheme); TypedArray ta = RenderSessionImpl.getCurrentContext().obtainStyledAttributes(attrs); BridgeTypedArray ta = RenderSessionImpl.getCurrentContext().obtainStyledAttributes(attrs); ta.setTheme(thisTheme); restoreResources(changed); return ta; } Loading @@ -69,7 +70,9 @@ public class Resources_Theme_Delegate { int resid, int[] attrs) throws NotFoundException { boolean changed = setupResources(thisTheme); TypedArray ta = RenderSessionImpl.getCurrentContext().obtainStyledAttributes(resid, attrs); BridgeTypedArray ta = RenderSessionImpl.getCurrentContext().obtainStyledAttributes(resid, attrs); ta.setTheme(thisTheme); restoreResources(changed); return ta; } Loading @@ -79,8 +82,9 @@ public class Resources_Theme_Delegate { Resources thisResources, Theme thisTheme, AttributeSet set, int[] attrs, int defStyleAttr, int defStyleRes) { boolean changed = setupResources(thisTheme); TypedArray ta = RenderSessionImpl.getCurrentContext().obtainStyledAttributes(set, attrs, defStyleAttr, defStyleRes); BridgeTypedArray ta = RenderSessionImpl.getCurrentContext().obtainStyledAttributes(set, attrs, defStyleAttr, defStyleRes); ta.setTheme(thisTheme); restoreResources(changed); return ta; } Loading @@ -91,8 +95,8 @@ public class Resources_Theme_Delegate { int resid, TypedValue outValue, boolean resolveRefs) { boolean changed = setupResources(thisTheme); boolean found = RenderSessionImpl.getCurrentContext().resolveThemeAttribute( resid, outValue, resolveRefs); boolean found = RenderSessionImpl.getCurrentContext().resolveThemeAttribute(resid, outValue, resolveRefs); restoreResources(changed); return found; } Loading tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java +10 −10 Original line number Diff line number Diff line Loading @@ -115,7 +115,7 @@ public final class BridgeContext extends Context { private int mDynamicIdGenerator = 0x02030000; // Base id for R.style in custom namespace // cache for TypedArray generated from IStyleResourceValue object private Map<int[], Map<Integer, TypedArray>> mTypedArrayCache; private Map<int[], Map<Integer, BridgeTypedArray>> mTypedArrayCache; private BridgeInflater mBridgeInflater; private BridgeContentResolver mContentResolver; Loading Loading @@ -467,7 +467,7 @@ public final class BridgeContext extends Context { @Override public final TypedArray obtainStyledAttributes(int[] attrs) { public final BridgeTypedArray obtainStyledAttributes(int[] attrs) { // No style is specified here, so create the typed array based on the default theme // and the styles already applied to it. A null value of style indicates that the default // theme should be used. Loading @@ -475,7 +475,7 @@ public final class BridgeContext extends Context { } @Override public final TypedArray obtainStyledAttributes(int resid, int[] attrs) public final BridgeTypedArray obtainStyledAttributes(int resid, int[] attrs) throws Resources.NotFoundException { // get the StyleResourceValue based on the resId; StyleResourceValue style = getStyleByDynamicId(resid); Loading @@ -485,9 +485,9 @@ public final class BridgeContext extends Context { } if (mTypedArrayCache == null) { mTypedArrayCache = new HashMap<int[], Map<Integer,TypedArray>>(); mTypedArrayCache = new HashMap<int[], Map<Integer,BridgeTypedArray>>(); Map<Integer, TypedArray> map = new HashMap<Integer, TypedArray>(); Map<Integer, BridgeTypedArray> map = new HashMap<Integer, BridgeTypedArray>(); mTypedArrayCache.put(attrs, map); BridgeTypedArray ta = createStyleBasedTypedArray(style, attrs); Loading @@ -497,14 +497,14 @@ public final class BridgeContext extends Context { } // get the 2nd map Map<Integer, TypedArray> map = mTypedArrayCache.get(attrs); Map<Integer, BridgeTypedArray> map = mTypedArrayCache.get(attrs); if (map == null) { map = new HashMap<Integer, TypedArray>(); map = new HashMap<Integer, BridgeTypedArray>(); mTypedArrayCache.put(attrs, map); } // get the array from the 2nd map TypedArray ta = map.get(resid); BridgeTypedArray ta = map.get(resid); if (ta == null) { ta = createStyleBasedTypedArray(style, attrs); Loading @@ -515,12 +515,12 @@ public final class BridgeContext extends Context { } @Override public final TypedArray obtainStyledAttributes(AttributeSet set, int[] attrs) { public final BridgeTypedArray obtainStyledAttributes(AttributeSet set, int[] attrs) { return obtainStyledAttributes(set, attrs, 0, 0); } @Override public TypedArray obtainStyledAttributes(AttributeSet set, int[] attrs, public BridgeTypedArray obtainStyledAttributes(AttributeSet set, int[] attrs, int defStyleAttr, int defStyleRes) { Map<String, String> defaultPropMap = null; Loading tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/ResourceHelper.java +13 −1 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import android.content.res.ColorStateList; import android.content.res.Resources.Theme; import android.graphics.Bitmap; import android.graphics.Bitmap_Delegate; import android.graphics.NinePatch_Delegate; Loading Loading @@ -166,6 +167,17 @@ public final class ResourceHelper { * @param context the current context */ public static Drawable getDrawable(ResourceValue value, BridgeContext context) { return getDrawable(value, context, null); } /** * Returns a drawable from the given value. * @param value The value that contains a path to a 9 patch, a bitmap or a xml based drawable, * or an hexadecimal color * @param context the current context * @param theme the theme to be used to inflate the drawable. */ public static Drawable getDrawable(ResourceValue value, BridgeContext context, Theme theme) { if (value == null) { return null; } Loading Loading @@ -209,7 +221,7 @@ public final class ResourceHelper { BridgeXmlBlockParser blockParser = new BridgeXmlBlockParser( parser, context, value.isFramework()); try { return Drawable.createFromXml(context.getResources(), blockParser); return Drawable.createFromXml(context.getResources(), blockParser, theme); } finally { blockParser.ensurePopped(); } Loading Loading
tools/layoutlib/bridge/src/android/content/res/BridgeResources.java +1 −1 Original line number Diff line number Diff line Loading @@ -163,7 +163,7 @@ public final class BridgeResources extends Resources { Pair<String, ResourceValue> value = getResourceValue(id, mPlatformResourceFlag); if (value != null) { return ResourceHelper.getDrawable(value.getSecond(), mContext); return ResourceHelper.getDrawable(value.getSecond(), mContext, theme); } // id was not found or not resolved. Throw a NotFoundException. Loading
tools/layoutlib/bridge/src/android/content/res/BridgeTypedArray.java +9 −1 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ import com.android.resources.ResourceType; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import android.content.res.Resources.Theme; import android.graphics.drawable.Drawable; import android.util.DisplayMetrics; import android.util.TypedValue; Loading Loading @@ -115,6 +116,13 @@ public final class BridgeTypedArray extends TypedArray { } } /** * Set the theme to be used for inflating drawables. */ public void setTheme(Theme theme) { mTheme = theme; } /** * Return the number of values in this array. */ Loading Loading @@ -663,7 +671,7 @@ public final class BridgeTypedArray extends TypedArray { } ResourceValue value = mResourceData[index]; return ResourceHelper.getDrawable(value, mContext); return ResourceHelper.getDrawable(value, mContext, mTheme); } Loading
tools/layoutlib/bridge/src/android/content/res/Resources_Theme_Delegate.java +10 −6 Original line number Diff line number Diff line Loading @@ -58,7 +58,8 @@ public class Resources_Theme_Delegate { Resources thisResources, Theme thisTheme, int[] attrs) { boolean changed = setupResources(thisTheme); TypedArray ta = RenderSessionImpl.getCurrentContext().obtainStyledAttributes(attrs); BridgeTypedArray ta = RenderSessionImpl.getCurrentContext().obtainStyledAttributes(attrs); ta.setTheme(thisTheme); restoreResources(changed); return ta; } Loading @@ -69,7 +70,9 @@ public class Resources_Theme_Delegate { int resid, int[] attrs) throws NotFoundException { boolean changed = setupResources(thisTheme); TypedArray ta = RenderSessionImpl.getCurrentContext().obtainStyledAttributes(resid, attrs); BridgeTypedArray ta = RenderSessionImpl.getCurrentContext().obtainStyledAttributes(resid, attrs); ta.setTheme(thisTheme); restoreResources(changed); return ta; } Loading @@ -79,8 +82,9 @@ public class Resources_Theme_Delegate { Resources thisResources, Theme thisTheme, AttributeSet set, int[] attrs, int defStyleAttr, int defStyleRes) { boolean changed = setupResources(thisTheme); TypedArray ta = RenderSessionImpl.getCurrentContext().obtainStyledAttributes(set, attrs, defStyleAttr, defStyleRes); BridgeTypedArray ta = RenderSessionImpl.getCurrentContext().obtainStyledAttributes(set, attrs, defStyleAttr, defStyleRes); ta.setTheme(thisTheme); restoreResources(changed); return ta; } Loading @@ -91,8 +95,8 @@ public class Resources_Theme_Delegate { int resid, TypedValue outValue, boolean resolveRefs) { boolean changed = setupResources(thisTheme); boolean found = RenderSessionImpl.getCurrentContext().resolveThemeAttribute( resid, outValue, resolveRefs); boolean found = RenderSessionImpl.getCurrentContext().resolveThemeAttribute(resid, outValue, resolveRefs); restoreResources(changed); return found; } Loading
tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java +10 −10 Original line number Diff line number Diff line Loading @@ -115,7 +115,7 @@ public final class BridgeContext extends Context { private int mDynamicIdGenerator = 0x02030000; // Base id for R.style in custom namespace // cache for TypedArray generated from IStyleResourceValue object private Map<int[], Map<Integer, TypedArray>> mTypedArrayCache; private Map<int[], Map<Integer, BridgeTypedArray>> mTypedArrayCache; private BridgeInflater mBridgeInflater; private BridgeContentResolver mContentResolver; Loading Loading @@ -467,7 +467,7 @@ public final class BridgeContext extends Context { @Override public final TypedArray obtainStyledAttributes(int[] attrs) { public final BridgeTypedArray obtainStyledAttributes(int[] attrs) { // No style is specified here, so create the typed array based on the default theme // and the styles already applied to it. A null value of style indicates that the default // theme should be used. Loading @@ -475,7 +475,7 @@ public final class BridgeContext extends Context { } @Override public final TypedArray obtainStyledAttributes(int resid, int[] attrs) public final BridgeTypedArray obtainStyledAttributes(int resid, int[] attrs) throws Resources.NotFoundException { // get the StyleResourceValue based on the resId; StyleResourceValue style = getStyleByDynamicId(resid); Loading @@ -485,9 +485,9 @@ public final class BridgeContext extends Context { } if (mTypedArrayCache == null) { mTypedArrayCache = new HashMap<int[], Map<Integer,TypedArray>>(); mTypedArrayCache = new HashMap<int[], Map<Integer,BridgeTypedArray>>(); Map<Integer, TypedArray> map = new HashMap<Integer, TypedArray>(); Map<Integer, BridgeTypedArray> map = new HashMap<Integer, BridgeTypedArray>(); mTypedArrayCache.put(attrs, map); BridgeTypedArray ta = createStyleBasedTypedArray(style, attrs); Loading @@ -497,14 +497,14 @@ public final class BridgeContext extends Context { } // get the 2nd map Map<Integer, TypedArray> map = mTypedArrayCache.get(attrs); Map<Integer, BridgeTypedArray> map = mTypedArrayCache.get(attrs); if (map == null) { map = new HashMap<Integer, TypedArray>(); map = new HashMap<Integer, BridgeTypedArray>(); mTypedArrayCache.put(attrs, map); } // get the array from the 2nd map TypedArray ta = map.get(resid); BridgeTypedArray ta = map.get(resid); if (ta == null) { ta = createStyleBasedTypedArray(style, attrs); Loading @@ -515,12 +515,12 @@ public final class BridgeContext extends Context { } @Override public final TypedArray obtainStyledAttributes(AttributeSet set, int[] attrs) { public final BridgeTypedArray obtainStyledAttributes(AttributeSet set, int[] attrs) { return obtainStyledAttributes(set, attrs, 0, 0); } @Override public TypedArray obtainStyledAttributes(AttributeSet set, int[] attrs, public BridgeTypedArray obtainStyledAttributes(AttributeSet set, int[] attrs, int defStyleAttr, int defStyleRes) { Map<String, String> defaultPropMap = null; Loading
tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/ResourceHelper.java +13 −1 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import android.content.res.ColorStateList; import android.content.res.Resources.Theme; import android.graphics.Bitmap; import android.graphics.Bitmap_Delegate; import android.graphics.NinePatch_Delegate; Loading Loading @@ -166,6 +167,17 @@ public final class ResourceHelper { * @param context the current context */ public static Drawable getDrawable(ResourceValue value, BridgeContext context) { return getDrawable(value, context, null); } /** * Returns a drawable from the given value. * @param value The value that contains a path to a 9 patch, a bitmap or a xml based drawable, * or an hexadecimal color * @param context the current context * @param theme the theme to be used to inflate the drawable. */ public static Drawable getDrawable(ResourceValue value, BridgeContext context, Theme theme) { if (value == null) { return null; } Loading Loading @@ -209,7 +221,7 @@ public final class ResourceHelper { BridgeXmlBlockParser blockParser = new BridgeXmlBlockParser( parser, context, value.isFramework()); try { return Drawable.createFromXml(context.getResources(), blockParser); return Drawable.createFromXml(context.getResources(), blockParser, theme); } finally { blockParser.ensurePopped(); } Loading