Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 78a29c9f authored by Xavier Ducrohet's avatar Xavier Ducrohet Committed by Android (Google) Code Review
Browse files

Merge "Misc layoutlib fix in preparation of the access change in framework code."

parents 4f7c380d d2f664d4
Loading
Loading
Loading
Loading
+10 −13
Original line number Original line Diff line number Diff line
@@ -14,13 +14,15 @@
 * limitations under the License.
 * 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.IProjectCallback;
import com.android.ide.common.rendering.api.LayoutLog;
import com.android.ide.common.rendering.api.LayoutLog;
import com.android.ide.common.rendering.api.ResourceValue;
import com.android.ide.common.rendering.api.ResourceValue;
import com.android.layoutlib.bridge.Bridge;
import com.android.layoutlib.bridge.Bridge;
import com.android.layoutlib.bridge.BridgeConstants;
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.ParserFactory;
import com.android.layoutlib.bridge.impl.ResourceHelper;
import com.android.layoutlib.bridge.impl.ResourceHelper;
import com.android.ninepatch.NinePatch;
import com.android.ninepatch.NinePatch;
@@ -30,13 +32,6 @@ import com.android.util.Pair;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
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.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.DisplayMetrics;
@@ -94,7 +89,7 @@ public final class BridgeResources extends Resources {
     * <p/>
     * <p/>
     * {@link Bridge} calls this method after setting up a new bridge.
     * {@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,
            AssetManager assets,
            DisplayMetrics metrics,
            DisplayMetrics metrics,
            Configuration config,
            Configuration config,
@@ -110,7 +105,7 @@ public final class BridgeResources extends Resources {
     * Disposes the static {@link Resources#mSystem} to make sure we don't leave objects
     * Disposes the static {@link Resources#mSystem} to make sure we don't leave objects
     * around that would prevent us from unloading the library.
     * around that would prevent us from unloading the library.
     */
     */
    /*package*/ static void disposeSystem() {
    /*package*/ public static void disposeSystem() {
        if (Resources.mSystem instanceof BridgeResources) {
        if (Resources.mSystem instanceof BridgeResources) {
            ((BridgeResources)(Resources.mSystem)).mContext = null;
            ((BridgeResources)(Resources.mSystem)).mContext = null;
            ((BridgeResources)(Resources.mSystem)).mProjectCallback = null;
            ((BridgeResources)(Resources.mSystem)).mProjectCallback = null;
@@ -336,7 +331,7 @@ public final class BridgeResources extends Resources {
                if (ResourceHelper.parseFloatAttribute(
                if (ResourceHelper.parseFloatAttribute(
                        value.getFirst(), v, mTmpValue, true /*requireUnit*/) &&
                        value.getFirst(), v, mTmpValue, true /*requireUnit*/) &&
                        mTmpValue.type == TypedValue.TYPE_DIMENSION) {
                        mTmpValue.type == TypedValue.TYPE_DIMENSION) {
                    return mTmpValue.getDimension(mMetrics);
                    return mTmpValue.getDimension(getDisplayMetrics());
                }
                }
            }
            }
        }
        }
@@ -359,7 +354,8 @@ public final class BridgeResources extends Resources {
                if (ResourceHelper.parseFloatAttribute(
                if (ResourceHelper.parseFloatAttribute(
                        value.getFirst(), v, mTmpValue, true /*requireUnit*/) &&
                        value.getFirst(), v, mTmpValue, true /*requireUnit*/) &&
                        mTmpValue.type == TypedValue.TYPE_DIMENSION) {
                        mTmpValue.type == TypedValue.TYPE_DIMENSION) {
                    return TypedValue.complexToDimensionPixelOffset(mTmpValue.data, mMetrics);
                    return TypedValue.complexToDimensionPixelOffset(mTmpValue.data,
                            getDisplayMetrics());
                }
                }
            }
            }
        }
        }
@@ -382,7 +378,8 @@ public final class BridgeResources extends Resources {
                if (ResourceHelper.parseFloatAttribute(
                if (ResourceHelper.parseFloatAttribute(
                        value.getFirst(), v, mTmpValue, true /*requireUnit*/) &&
                        value.getFirst(), v, mTmpValue, true /*requireUnit*/) &&
                        mTmpValue.type == TypedValue.TYPE_DIMENSION) {
                        mTmpValue.type == TypedValue.TYPE_DIMENSION) {
                    return TypedValue.complexToDimensionPixelSize(mTmpValue.data, mMetrics);
                    return TypedValue.complexToDimensionPixelSize(mTmpValue.data,
                            getDisplayMetrics());
                }
                }
            }
            }
        }
        }
+5 −3
Original line number Original line Diff line number Diff line
@@ -14,7 +14,7 @@
 * limitations under the License.
 * 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.DeclareStyleableResourceValue;
import com.android.ide.common.rendering.api.LayoutLog;
import com.android.ide.common.rendering.api.LayoutLog;
@@ -24,6 +24,8 @@ import com.android.ide.common.rendering.api.StyleResourceValue;
import com.android.internal.util.XmlUtils;
import com.android.internal.util.XmlUtils;
import com.android.layoutlib.bridge.Bridge;
import com.android.layoutlib.bridge.Bridge;
import com.android.layoutlib.bridge.BridgeConstants;
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.ParserFactory;
import com.android.layoutlib.bridge.impl.ResourceHelper;
import com.android.layoutlib.bridge.impl.ResourceHelper;
import com.android.resources.ResourceType;
import com.android.resources.ResourceType;
@@ -445,7 +447,7 @@ public final class BridgeTypedArray extends TypedArray {
        }
        }


        if (ResourceHelper.parseFloatAttribute(mNames[index], s, mValue, true /*requireUnit*/)) {
        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
        // looks like we were unable to resolve the dimension value
@@ -572,7 +574,7 @@ public final class BridgeTypedArray extends TypedArray {
        }
        }


        if (ResourceHelper.parseFloatAttribute(mNames[index], s, mValue, true /*requireUnit*/)) {
        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);
            final int res = (int)(f+0.5f);
            if (res != 0) return res;
            if (res != 0) return res;
+1 −1
Original line number Original line Diff line number Diff line
@@ -17,12 +17,12 @@
package android.graphics;
package android.graphics;


import com.android.layoutlib.bridge.Bridge;
import com.android.layoutlib.bridge.Bridge;
import com.android.layoutlib.bridge.android.BridgeResources.NinePatchInputStream;
import com.android.layoutlib.bridge.impl.DelegateManager;
import com.android.layoutlib.bridge.impl.DelegateManager;
import com.android.ninepatch.NinePatchChunk;
import com.android.ninepatch.NinePatchChunk;
import com.android.resources.Density;
import com.android.resources.Density;
import com.android.tools.layoutlib.annotations.LayoutlibDelegate;
import com.android.tools.layoutlib.annotations.LayoutlibDelegate;


import android.content.res.BridgeResources.NinePatchInputStream;
import android.graphics.BitmapFactory.Options;
import android.graphics.BitmapFactory.Options;


import java.io.FileDescriptor;
import java.io.FileDescriptor;
+6 −32
Original line number Original line Diff line number Diff line
@@ -38,11 +38,15 @@ import java.io.IOException;
 */
 */
public class LayoutInflater_Delegate {
public class LayoutInflater_Delegate {


    private static final String TAG_MERGE = "merge";

    public static boolean sIsInInclude = false;
    public static boolean sIsInInclude = false;


    /**
    /**
     * Recursive method used to descend down the xml hierarchy and instantiate
     * Recursive method used to descend down the xml hierarchy and instantiate
     * views, instantiate their children, and then call onFinishInflate().
     * views, instantiate their children, and then call onFinishInflate().
     *
     * This implementation just records the merge status before calling the default implementation.
     */
     */
    @LayoutlibDelegate
    @LayoutlibDelegate
    /*package*/ static void rInflate(LayoutInflater thisInflater,
    /*package*/ static void rInflate(LayoutInflater thisInflater,
@@ -58,37 +62,7 @@ public class LayoutInflater_Delegate {


        // ---- START DEFAULT IMPLEMENTATION.
        // ---- START DEFAULT IMPLEMENTATION.


        final int depth = parser.getDepth();
        thisInflater.rInflate_Original(parser, parent, attrs, finishInflate);
        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();


        // ---- END DEFAULT IMPLEMENTATION.
        // ---- END DEFAULT IMPLEMENTATION.


@@ -138,7 +112,7 @@ public class LayoutInflater_Delegate {


                    final String childName = childParser.getName();
                    final String childName = childParser.getName();


                    if (LayoutInflater.TAG_MERGE.equals(childName)) {
                    if (TAG_MERGE.equals(childName)) {
                        // Inflate all children.
                        // Inflate all children.
                        thisInflater.rInflate(childParser, parent, childAttrs, false);
                        thisInflater.rInflate(childParser, parent, childAttrs, false);
                    } else {
                    } else {
+5 −3
Original line number Original line Diff line number Diff line
@@ -47,6 +47,8 @@ import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager;
import android.content.res.AssetManager;
import android.content.res.AssetManager;
import android.content.res.BridgeResources;
import android.content.res.BridgeTypedArray;
import android.content.res.Configuration;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.content.res.TypedArray;
@@ -813,7 +815,7 @@ public final class BridgeContext extends Activity {
        return null;
        return null;
    }
    }


    int getDynamicIdByStyle(StyleResourceValue resValue) {
    public int getDynamicIdByStyle(StyleResourceValue resValue) {
        if (mDynamicIdToStyleMap == null) {
        if (mDynamicIdToStyleMap == null) {
            // create the maps.
            // create the maps.
            mDynamicIdToStyleMap = new HashMap<Integer, StyleResourceValue>();
            mDynamicIdToStyleMap = new HashMap<Integer, StyleResourceValue>();
@@ -843,7 +845,7 @@ public final class BridgeContext extends Activity {
        return null;
        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);
        Integer value = Bridge.getResourceId(resType, resName);
        if (value != null) {
        if (value != null) {
            return value.intValue();
            return value.intValue();
@@ -852,7 +854,7 @@ public final class BridgeContext extends Activity {
        return defValue;
        return defValue;
    }
    }


    int getProjectResourceValue(ResourceType resType, String resName, int defValue) {
    public int getProjectResourceValue(ResourceType resType, String resName, int defValue) {
        if (mProjectCallback != null) {
        if (mProjectCallback != null) {
            Integer value = mProjectCallback.getResourceId(resType, resName);
            Integer value = mProjectCallback.getResourceId(resType, resName);
            if (value != null) {
            if (value != null) {
Loading