FileDocCategorySizeDatePackage
BridgeXmlPullAttributes.javaAPI DocAndroid 5.1 API8599Thu Mar 12 22:22:44 GMT 2015android.util

BridgeXmlPullAttributes

public class BridgeXmlPullAttributes extends XmlPullAttributes
A correct implementation of the {@link AttributeSet} interface on top of a XmlPullParser

Fields Summary
private final com.android.layoutlib.bridge.android.BridgeContext
mContext
private final boolean
mPlatformFile
Constructors Summary
public BridgeXmlPullAttributes(XmlPullParser parser, com.android.layoutlib.bridge.android.BridgeContext context, boolean platformFile)

        super(parser);
        mContext = context;
        mPlatformFile = platformFile;
    
Methods Summary
public booleangetAttributeBooleanValue(int index, boolean defaultValue)

        String value = getAttributeValue(index);
        if (value != null) {
            ResourceValue r = getResourceValue(value);

            if (r != null) {
                value = r.getValue();
            }

            return XmlUtils.convertValueToBoolean(value, defaultValue);
        }

        return defaultValue;
    
public booleangetAttributeBooleanValue(java.lang.String namespace, java.lang.String attribute, boolean defaultValue)

        String value = getAttributeValue(namespace, attribute);
        if (value != null) {
            ResourceValue r = getResourceValue(value);

            if (r != null) {
                value = r.getValue();
            }

            return XmlUtils.convertValueToBoolean(value, defaultValue);
        }

        return defaultValue;
    
public floatgetAttributeFloatValue(int index, float defaultValue)

        String s = getAttributeValue(index);
        if (s != null) {
            ResourceValue r = getResourceValue(s);

            if (r != null) {
                s = r.getValue();
            }

            return Float.parseFloat(s);
        }

        return defaultValue;
    
public floatgetAttributeFloatValue(java.lang.String namespace, java.lang.String attribute, float defaultValue)

        String s = getAttributeValue(namespace, attribute);
        if (s != null) {
            ResourceValue r = getResourceValue(s);

            if (r != null) {
                s = r.getValue();
            }

            return Float.parseFloat(s);
        }

        return defaultValue;
    
public intgetAttributeIntValue(int index, int defaultValue)

        String value = getAttributeValue(index);
        if (value != null) {
            ResourceValue r = getResourceValue(value);

            if (r != null) {
                value = r.getValue();
            }

            if (value.charAt(0) == '#") {
                return ResourceHelper.getColor(value);
            }
            return XmlUtils.convertValueToInt(value, defaultValue);
        }

        return defaultValue;
    
public intgetAttributeIntValue(java.lang.String namespace, java.lang.String attribute, int defaultValue)

        String value = getAttributeValue(namespace, attribute);
        if (value != null) {
            ResourceValue r = getResourceValue(value);

            if (r != null) {
                value = r.getValue();
            }

            return XmlUtils.convertValueToInt(value, defaultValue);
        }

        return defaultValue;
    
public intgetAttributeListValue(java.lang.String namespace, java.lang.String attribute, java.lang.String[] options, int defaultValue)

        String value = getAttributeValue(namespace, attribute);
        if (value != null) {
            ResourceValue r = getResourceValue(value);

            if (r != null) {
                value = r.getValue();
            }

            return XmlUtils.convertValueToList(value, options, defaultValue);
        }

        return defaultValue;
    
public intgetAttributeListValue(int index, java.lang.String[] options, int defaultValue)

        return XmlUtils.convertValueToList(
            getAttributeValue(index), options, defaultValue);
    
public intgetAttributeNameResource(int index)

        // get the attribute name.
        String name = getAttributeName(index);

        // get the attribute namespace
        String ns = mParser.getAttributeNamespace(index);

        if (BridgeConstants.NS_RESOURCES.equals(ns)) {
            Integer v = Bridge.getResourceId(ResourceType.ATTR, name);
            if (v != null) {
                return v.intValue();
            }

            return 0;
        }

        // this is not an attribute in the android namespace, we query the customviewloader, if
        // the namespaces match.
        if (mContext.getProjectCallback().getNamespace().equals(ns)) {
            Integer v = mContext.getProjectCallback().getResourceId(ResourceType.ATTR, name);
            if (v != null) {
                return v.intValue();
            }
        }

        return 0;
    
public intgetAttributeResourceValue(int index, int defaultValue)

        String value = getAttributeValue(index);

        return resolveResourceValue(value, defaultValue);
    
public intgetAttributeResourceValue(java.lang.String namespace, java.lang.String attribute, int defaultValue)

        String value = getAttributeValue(namespace, attribute);

        return resolveResourceValue(value, defaultValue);
    
public intgetAttributeUnsignedIntValue(int index, int defaultValue)

        String value = getAttributeValue(index);
        if (value != null) {
            ResourceValue r = getResourceValue(value);

            if (r != null) {
                value = r.getValue();
            }

            return XmlUtils.convertValueToUnsignedInt(value, defaultValue);
        }

        return defaultValue;
    
public intgetAttributeUnsignedIntValue(java.lang.String namespace, java.lang.String attribute, int defaultValue)

        String value = getAttributeValue(namespace, attribute);
        if (value != null) {
            ResourceValue r = getResourceValue(value);

            if (r != null) {
                value = r.getValue();
            }

            return XmlUtils.convertValueToUnsignedInt(value, defaultValue);
        }

        return defaultValue;
    
private com.android.ide.common.rendering.api.ResourceValuegetResourceValue(java.lang.String value)
Returns a resolved {@link ResourceValue} from a given value.

        // now look for this particular value
        RenderResources resources = mContext.getRenderResources();
        return resources.resolveResValue(resources.findResValue(value, mPlatformFile));
    
private intresolveResourceValue(java.lang.String value, int defaultValue)
Resolves and return a value to its associated integer.

        ResourceValue resource = getResourceValue(value);
        if (resource != null) {
            Integer id = null;
            if (mPlatformFile || resource.isFramework()) {
                id = Bridge.getResourceId(resource.getResourceType(), resource.getName());
            } else {
                id = mContext.getProjectCallback().getResourceId(
                        resource.getResourceType(), resource.getName());
            }

            if (id != null) {
                return id;
            }
        }

        return defaultValue;