Loading tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeResources.java→tools/layoutlib/bridge/src/android/content/res/BridgeResources.java +10 −13 Original line number Diff line number Diff line Loading @@ -14,13 +14,15 @@ * limitations under the License. */ package com.android.layoutlib.bridge.android; package android.content.res; import com.android.ide.common.rendering.api.IProjectCallback; import com.android.ide.common.rendering.api.LayoutLog; import com.android.ide.common.rendering.api.ResourceValue; import com.android.layoutlib.bridge.Bridge; import com.android.layoutlib.bridge.BridgeConstants; import com.android.layoutlib.bridge.android.BridgeContext; import com.android.layoutlib.bridge.android.BridgeXmlBlockParser; import com.android.layoutlib.bridge.impl.ParserFactory; import com.android.layoutlib.bridge.impl.ResourceHelper; import com.android.ninepatch.NinePatch; Loading @@ -30,13 +32,6 @@ import com.android.util.Pair; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import android.content.res.AssetFileDescriptor; import android.content.res.AssetManager; import android.content.res.ColorStateList; import android.content.res.Configuration; import android.content.res.Resources; import android.content.res.TypedArray; import android.content.res.XmlResourceParser; import android.graphics.drawable.Drawable; import android.util.AttributeSet; import android.util.DisplayMetrics; Loading Loading @@ -94,7 +89,7 @@ public final class BridgeResources extends Resources { * <p/> * {@link Bridge} calls this method after setting up a new bridge. */ /*package*/ static Resources initSystem(BridgeContext context, /*package*/ public static Resources initSystem(BridgeContext context, AssetManager assets, DisplayMetrics metrics, Configuration config, Loading @@ -110,7 +105,7 @@ public final class BridgeResources extends Resources { * Disposes the static {@link Resources#mSystem} to make sure we don't leave objects * around that would prevent us from unloading the library. */ /*package*/ static void disposeSystem() { /*package*/ public static void disposeSystem() { if (Resources.mSystem instanceof BridgeResources) { ((BridgeResources)(Resources.mSystem)).mContext = null; ((BridgeResources)(Resources.mSystem)).mProjectCallback = null; Loading Loading @@ -336,7 +331,7 @@ public final class BridgeResources extends Resources { if (ResourceHelper.parseFloatAttribute( value.getFirst(), v, mTmpValue, true /*requireUnit*/) && mTmpValue.type == TypedValue.TYPE_DIMENSION) { return mTmpValue.getDimension(mMetrics); return mTmpValue.getDimension(getDisplayMetrics()); } } } Loading @@ -359,7 +354,8 @@ public final class BridgeResources extends Resources { if (ResourceHelper.parseFloatAttribute( value.getFirst(), v, mTmpValue, true /*requireUnit*/) && mTmpValue.type == TypedValue.TYPE_DIMENSION) { return TypedValue.complexToDimensionPixelOffset(mTmpValue.data, mMetrics); return TypedValue.complexToDimensionPixelOffset(mTmpValue.data, getDisplayMetrics()); } } } Loading @@ -382,7 +378,8 @@ public final class BridgeResources extends Resources { if (ResourceHelper.parseFloatAttribute( value.getFirst(), v, mTmpValue, true /*requireUnit*/) && mTmpValue.type == TypedValue.TYPE_DIMENSION) { return TypedValue.complexToDimensionPixelSize(mTmpValue.data, mMetrics); return TypedValue.complexToDimensionPixelSize(mTmpValue.data, getDisplayMetrics()); } } } Loading tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeTypedArray.java→tools/layoutlib/bridge/src/android/content/res/BridgeTypedArray.java +5 −3 Original line number Diff line number Diff line Loading @@ -14,7 +14,7 @@ * limitations under the License. */ package com.android.layoutlib.bridge.android; package android.content.res; import com.android.ide.common.rendering.api.DeclareStyleableResourceValue; import com.android.ide.common.rendering.api.LayoutLog; Loading @@ -24,6 +24,8 @@ import com.android.ide.common.rendering.api.StyleResourceValue; import com.android.internal.util.XmlUtils; import com.android.layoutlib.bridge.Bridge; import com.android.layoutlib.bridge.BridgeConstants; import com.android.layoutlib.bridge.android.BridgeContext; import com.android.layoutlib.bridge.android.BridgeXmlBlockParser; import com.android.layoutlib.bridge.impl.ParserFactory; import com.android.layoutlib.bridge.impl.ResourceHelper; import com.android.resources.ResourceType; Loading Loading @@ -445,7 +447,7 @@ public final class BridgeTypedArray extends TypedArray { } if (ResourceHelper.parseFloatAttribute(mNames[index], s, mValue, true /*requireUnit*/)) { return mValue.getDimension(mBridgeResources.mMetrics); return mValue.getDimension(mBridgeResources.getDisplayMetrics()); } // looks like we were unable to resolve the dimension value Loading Loading @@ -572,7 +574,7 @@ public final class BridgeTypedArray extends TypedArray { } if (ResourceHelper.parseFloatAttribute(mNames[index], s, mValue, true /*requireUnit*/)) { float f = mValue.getDimension(mBridgeResources.mMetrics); float f = mValue.getDimension(mBridgeResources.getDisplayMetrics()); final int res = (int)(f+0.5f); if (res != 0) return res; Loading tools/layoutlib/bridge/src/android/graphics/BitmapFactory_Delegate.java +1 −1 Original line number Diff line number Diff line Loading @@ -17,12 +17,12 @@ package android.graphics; import com.android.layoutlib.bridge.Bridge; import com.android.layoutlib.bridge.android.BridgeResources.NinePatchInputStream; import com.android.layoutlib.bridge.impl.DelegateManager; import com.android.ninepatch.NinePatchChunk; import com.android.resources.Density; import com.android.tools.layoutlib.annotations.LayoutlibDelegate; import android.content.res.BridgeResources.NinePatchInputStream; import android.graphics.BitmapFactory.Options; import java.io.FileDescriptor; Loading tools/layoutlib/bridge/src/android/view/LayoutInflater_Delegate.java +6 −32 Original line number Diff line number Diff line Loading @@ -38,11 +38,15 @@ import java.io.IOException; */ public class LayoutInflater_Delegate { private static final String TAG_MERGE = "merge"; public static boolean sIsInInclude = false; /** * Recursive method used to descend down the xml hierarchy and instantiate * views, instantiate their children, and then call onFinishInflate(). * * This implementation just records the merge status before calling the default implementation. */ @LayoutlibDelegate /*package*/ static void rInflate(LayoutInflater thisInflater, Loading @@ -58,37 +62,7 @@ public class LayoutInflater_Delegate { // ---- START DEFAULT IMPLEMENTATION. final int depth = parser.getDepth(); int type; while (((type = parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) { if (type != XmlPullParser.START_TAG) { continue; } final String name = parser.getName(); if (LayoutInflater.TAG_REQUEST_FOCUS.equals(name)) { thisInflater.parseRequestFocus(parser, parent); } else if (LayoutInflater.TAG_INCLUDE.equals(name)) { if (parser.getDepth() == 0) { throw new InflateException("<include /> cannot be the root element"); } thisInflater.parseInclude(parser, parent, attrs); } else if (LayoutInflater.TAG_MERGE.equals(name)) { throw new InflateException("<merge /> must be the root element"); } else { final View view = thisInflater.createViewFromTag(parent, name, attrs); final ViewGroup viewGroup = (ViewGroup) parent; final ViewGroup.LayoutParams params = viewGroup.generateLayoutParams(attrs); thisInflater.rInflate(parser, view, attrs, true); viewGroup.addView(view, params); } } if (finishInflate) parent.onFinishInflate(); thisInflater.rInflate_Original(parser, parent, attrs, finishInflate); // ---- END DEFAULT IMPLEMENTATION. Loading Loading @@ -138,7 +112,7 @@ public class LayoutInflater_Delegate { final String childName = childParser.getName(); if (LayoutInflater.TAG_MERGE.equals(childName)) { if (TAG_MERGE.equals(childName)) { // Inflate all children. thisInflater.rInflate(childParser, parent, childAttrs, false); } else { Loading tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java +5 −3 Original line number Diff line number Diff line Loading @@ -47,6 +47,8 @@ import android.content.SharedPreferences; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.res.AssetManager; import android.content.res.BridgeResources; import android.content.res.BridgeTypedArray; import android.content.res.Configuration; import android.content.res.Resources; import android.content.res.TypedArray; Loading Loading @@ -813,7 +815,7 @@ public final class BridgeContext extends Activity { return null; } int getDynamicIdByStyle(StyleResourceValue resValue) { public int getDynamicIdByStyle(StyleResourceValue resValue) { if (mDynamicIdToStyleMap == null) { // create the maps. mDynamicIdToStyleMap = new HashMap<Integer, StyleResourceValue>(); Loading Loading @@ -843,7 +845,7 @@ public final class BridgeContext extends Activity { return null; } int getFrameworkResourceValue(ResourceType resType, String resName, int defValue) { public int getFrameworkResourceValue(ResourceType resType, String resName, int defValue) { Integer value = Bridge.getResourceId(resType, resName); if (value != null) { return value.intValue(); Loading @@ -852,7 +854,7 @@ public final class BridgeContext extends Activity { return defValue; } int getProjectResourceValue(ResourceType resType, String resName, int defValue) { public int getProjectResourceValue(ResourceType resType, String resName, int defValue) { if (mProjectCallback != null) { Integer value = mProjectCallback.getResourceId(resType, resName); if (value != null) { Loading Loading
tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeResources.java→tools/layoutlib/bridge/src/android/content/res/BridgeResources.java +10 −13 Original line number Diff line number Diff line Loading @@ -14,13 +14,15 @@ * limitations under the License. */ package com.android.layoutlib.bridge.android; package android.content.res; import com.android.ide.common.rendering.api.IProjectCallback; import com.android.ide.common.rendering.api.LayoutLog; import com.android.ide.common.rendering.api.ResourceValue; import com.android.layoutlib.bridge.Bridge; import com.android.layoutlib.bridge.BridgeConstants; import com.android.layoutlib.bridge.android.BridgeContext; import com.android.layoutlib.bridge.android.BridgeXmlBlockParser; import com.android.layoutlib.bridge.impl.ParserFactory; import com.android.layoutlib.bridge.impl.ResourceHelper; import com.android.ninepatch.NinePatch; Loading @@ -30,13 +32,6 @@ import com.android.util.Pair; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import android.content.res.AssetFileDescriptor; import android.content.res.AssetManager; import android.content.res.ColorStateList; import android.content.res.Configuration; import android.content.res.Resources; import android.content.res.TypedArray; import android.content.res.XmlResourceParser; import android.graphics.drawable.Drawable; import android.util.AttributeSet; import android.util.DisplayMetrics; Loading Loading @@ -94,7 +89,7 @@ public final class BridgeResources extends Resources { * <p/> * {@link Bridge} calls this method after setting up a new bridge. */ /*package*/ static Resources initSystem(BridgeContext context, /*package*/ public static Resources initSystem(BridgeContext context, AssetManager assets, DisplayMetrics metrics, Configuration config, Loading @@ -110,7 +105,7 @@ public final class BridgeResources extends Resources { * Disposes the static {@link Resources#mSystem} to make sure we don't leave objects * around that would prevent us from unloading the library. */ /*package*/ static void disposeSystem() { /*package*/ public static void disposeSystem() { if (Resources.mSystem instanceof BridgeResources) { ((BridgeResources)(Resources.mSystem)).mContext = null; ((BridgeResources)(Resources.mSystem)).mProjectCallback = null; Loading Loading @@ -336,7 +331,7 @@ public final class BridgeResources extends Resources { if (ResourceHelper.parseFloatAttribute( value.getFirst(), v, mTmpValue, true /*requireUnit*/) && mTmpValue.type == TypedValue.TYPE_DIMENSION) { return mTmpValue.getDimension(mMetrics); return mTmpValue.getDimension(getDisplayMetrics()); } } } Loading @@ -359,7 +354,8 @@ public final class BridgeResources extends Resources { if (ResourceHelper.parseFloatAttribute( value.getFirst(), v, mTmpValue, true /*requireUnit*/) && mTmpValue.type == TypedValue.TYPE_DIMENSION) { return TypedValue.complexToDimensionPixelOffset(mTmpValue.data, mMetrics); return TypedValue.complexToDimensionPixelOffset(mTmpValue.data, getDisplayMetrics()); } } } Loading @@ -382,7 +378,8 @@ public final class BridgeResources extends Resources { if (ResourceHelper.parseFloatAttribute( value.getFirst(), v, mTmpValue, true /*requireUnit*/) && mTmpValue.type == TypedValue.TYPE_DIMENSION) { return TypedValue.complexToDimensionPixelSize(mTmpValue.data, mMetrics); return TypedValue.complexToDimensionPixelSize(mTmpValue.data, getDisplayMetrics()); } } } Loading
tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeTypedArray.java→tools/layoutlib/bridge/src/android/content/res/BridgeTypedArray.java +5 −3 Original line number Diff line number Diff line Loading @@ -14,7 +14,7 @@ * limitations under the License. */ package com.android.layoutlib.bridge.android; package android.content.res; import com.android.ide.common.rendering.api.DeclareStyleableResourceValue; import com.android.ide.common.rendering.api.LayoutLog; Loading @@ -24,6 +24,8 @@ import com.android.ide.common.rendering.api.StyleResourceValue; import com.android.internal.util.XmlUtils; import com.android.layoutlib.bridge.Bridge; import com.android.layoutlib.bridge.BridgeConstants; import com.android.layoutlib.bridge.android.BridgeContext; import com.android.layoutlib.bridge.android.BridgeXmlBlockParser; import com.android.layoutlib.bridge.impl.ParserFactory; import com.android.layoutlib.bridge.impl.ResourceHelper; import com.android.resources.ResourceType; Loading Loading @@ -445,7 +447,7 @@ public final class BridgeTypedArray extends TypedArray { } if (ResourceHelper.parseFloatAttribute(mNames[index], s, mValue, true /*requireUnit*/)) { return mValue.getDimension(mBridgeResources.mMetrics); return mValue.getDimension(mBridgeResources.getDisplayMetrics()); } // looks like we were unable to resolve the dimension value Loading Loading @@ -572,7 +574,7 @@ public final class BridgeTypedArray extends TypedArray { } if (ResourceHelper.parseFloatAttribute(mNames[index], s, mValue, true /*requireUnit*/)) { float f = mValue.getDimension(mBridgeResources.mMetrics); float f = mValue.getDimension(mBridgeResources.getDisplayMetrics()); final int res = (int)(f+0.5f); if (res != 0) return res; Loading
tools/layoutlib/bridge/src/android/graphics/BitmapFactory_Delegate.java +1 −1 Original line number Diff line number Diff line Loading @@ -17,12 +17,12 @@ package android.graphics; import com.android.layoutlib.bridge.Bridge; import com.android.layoutlib.bridge.android.BridgeResources.NinePatchInputStream; import com.android.layoutlib.bridge.impl.DelegateManager; import com.android.ninepatch.NinePatchChunk; import com.android.resources.Density; import com.android.tools.layoutlib.annotations.LayoutlibDelegate; import android.content.res.BridgeResources.NinePatchInputStream; import android.graphics.BitmapFactory.Options; import java.io.FileDescriptor; Loading
tools/layoutlib/bridge/src/android/view/LayoutInflater_Delegate.java +6 −32 Original line number Diff line number Diff line Loading @@ -38,11 +38,15 @@ import java.io.IOException; */ public class LayoutInflater_Delegate { private static final String TAG_MERGE = "merge"; public static boolean sIsInInclude = false; /** * Recursive method used to descend down the xml hierarchy and instantiate * views, instantiate their children, and then call onFinishInflate(). * * This implementation just records the merge status before calling the default implementation. */ @LayoutlibDelegate /*package*/ static void rInflate(LayoutInflater thisInflater, Loading @@ -58,37 +62,7 @@ public class LayoutInflater_Delegate { // ---- START DEFAULT IMPLEMENTATION. final int depth = parser.getDepth(); int type; while (((type = parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) { if (type != XmlPullParser.START_TAG) { continue; } final String name = parser.getName(); if (LayoutInflater.TAG_REQUEST_FOCUS.equals(name)) { thisInflater.parseRequestFocus(parser, parent); } else if (LayoutInflater.TAG_INCLUDE.equals(name)) { if (parser.getDepth() == 0) { throw new InflateException("<include /> cannot be the root element"); } thisInflater.parseInclude(parser, parent, attrs); } else if (LayoutInflater.TAG_MERGE.equals(name)) { throw new InflateException("<merge /> must be the root element"); } else { final View view = thisInflater.createViewFromTag(parent, name, attrs); final ViewGroup viewGroup = (ViewGroup) parent; final ViewGroup.LayoutParams params = viewGroup.generateLayoutParams(attrs); thisInflater.rInflate(parser, view, attrs, true); viewGroup.addView(view, params); } } if (finishInflate) parent.onFinishInflate(); thisInflater.rInflate_Original(parser, parent, attrs, finishInflate); // ---- END DEFAULT IMPLEMENTATION. Loading Loading @@ -138,7 +112,7 @@ public class LayoutInflater_Delegate { final String childName = childParser.getName(); if (LayoutInflater.TAG_MERGE.equals(childName)) { if (TAG_MERGE.equals(childName)) { // Inflate all children. thisInflater.rInflate(childParser, parent, childAttrs, false); } else { Loading
tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java +5 −3 Original line number Diff line number Diff line Loading @@ -47,6 +47,8 @@ import android.content.SharedPreferences; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.res.AssetManager; import android.content.res.BridgeResources; import android.content.res.BridgeTypedArray; import android.content.res.Configuration; import android.content.res.Resources; import android.content.res.TypedArray; Loading Loading @@ -813,7 +815,7 @@ public final class BridgeContext extends Activity { return null; } int getDynamicIdByStyle(StyleResourceValue resValue) { public int getDynamicIdByStyle(StyleResourceValue resValue) { if (mDynamicIdToStyleMap == null) { // create the maps. mDynamicIdToStyleMap = new HashMap<Integer, StyleResourceValue>(); Loading Loading @@ -843,7 +845,7 @@ public final class BridgeContext extends Activity { return null; } int getFrameworkResourceValue(ResourceType resType, String resName, int defValue) { public int getFrameworkResourceValue(ResourceType resType, String resName, int defValue) { Integer value = Bridge.getResourceId(resType, resName); if (value != null) { return value.intValue(); Loading @@ -852,7 +854,7 @@ public final class BridgeContext extends Activity { return defValue; } int getProjectResourceValue(ResourceType resType, String resName, int defValue) { public int getProjectResourceValue(ResourceType resType, String resName, int defValue) { if (mProjectCallback != null) { Integer value = mProjectCallback.getResourceId(resType, resName); if (value != null) { Loading