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

Commit f2099996 authored by Xavier Ducrohet's avatar Xavier Ducrohet
Browse files

LayoutLib: properly handle @null references in more places.

Change-Id: I240298ab79c19ab0e49cb6da19d6b0187493d3b5
parent 754537cf
Loading
Loading
Loading
Loading
+24 −0
Original line number Original line Diff line number Diff line
@@ -188,6 +188,10 @@ public final class BridgeTypedArray extends TypedArray {


        String s = mResourceData[index].getValue();
        String s = mResourceData[index].getValue();


        if (RenderResources.REFERENCE_NULL.equals(s)) {
            return defValue;
        }

        try {
        try {
            return (s == null) ? defValue : XmlUtils.convertValueToInt(s, defValue);
            return (s == null) ? defValue : XmlUtils.convertValueToInt(s, defValue);
        } catch (NumberFormatException e) {
        } catch (NumberFormatException e) {
@@ -301,6 +305,10 @@ public final class BridgeTypedArray extends TypedArray {
            return null;
            return null;
        }
        }


        if (RenderResources.REFERENCE_NULL.equals(value)) {
            return null;
        }

        // let the framework inflate the ColorStateList from the XML file.
        // let the framework inflate the ColorStateList from the XML file.
        File f = new File(value);
        File f = new File(value);
        if (f.isFile()) {
        if (f.isFile()) {
@@ -408,6 +416,10 @@ public final class BridgeTypedArray extends TypedArray {
            return LayoutParams.WRAP_CONTENT;
            return LayoutParams.WRAP_CONTENT;
        }
        }


        if (RenderResources.REFERENCE_NULL.equals(s)) {
            return defValue;
        }

        if (ResourceHelper.stringToFloat(s, mValue)) {
        if (ResourceHelper.stringToFloat(s, mValue)) {
            return mValue.getDimension(mBridgeResources.mMetrics);
            return mValue.getDimension(mBridgeResources.mMetrics);
        }
        }
@@ -480,6 +492,10 @@ public final class BridgeTypedArray extends TypedArray {
            return LayoutParams.WRAP_CONTENT;
            return LayoutParams.WRAP_CONTENT;
        }
        }


        if (RenderResources.REFERENCE_NULL.equals(s)) {
            return defValue;
        }

        // FIXME huh?
        // FIXME huh?


        float f = getDimension(index, defValue);
        float f = getDimension(index, defValue);
@@ -588,6 +604,10 @@ public final class BridgeTypedArray extends TypedArray {
            return mContext.getDynamicIdByStyle((StyleResourceValue)resValue);
            return mContext.getDynamicIdByStyle((StyleResourceValue)resValue);
        }
        }


        if (RenderResources.REFERENCE_NULL.equals(resValue.getValue())) {
            return defValue;
        }

        // if the attribute was a reference to a resource, and not a declaration of an id (@+id),
        // if the attribute was a reference to a resource, and not a declaration of an id (@+id),
        // then the xml attribute value was "resolved" which leads us to a ResourceValue with a
        // then the xml attribute value was "resolved" which leads us to a ResourceValue with a
        // valid getType() and getName() returning a resource name.
        // valid getType() and getName() returning a resource name.
@@ -715,6 +735,10 @@ public final class BridgeTypedArray extends TypedArray {


        String value = mResourceData[index].getValue();
        String value = mResourceData[index].getValue();
        if (value != null) {
        if (value != null) {
            if (RenderResources.REFERENCE_NULL.equals(value)) {
                return null;
            }

            return new CharSequence[] { value };
            return new CharSequence[] { value };
        }
        }