package com.xtremelabs.robolectric.res;

import org.w3c.dom.Node;

/**
 *
 */
public class IntegerResourceLoader extends XpathResourceXmlLoader implements ResourceValueConverter {
    private ResourceReferenceResolver<Integer> intResolver = new ResourceReferenceResolver<Integer>("integer");

    public IntegerResourceLoader(ResourceExtractor resourceExtractor) {
        super(resourceExtractor, "/resources/integer");
    }

    public Integer getValue(int resourceId) {
        return intResolver.getValue(resourceExtractor.getResourceName(resourceId));
    }

    public Integer getValue(String resourceName, boolean isSystem) {
        return getValue(resourceExtractor.getResourceId(resourceName, isSystem));
    }

    @Override protected void processNode(Node node, String name, boolean isSystem) {
        final String textContent = node.getTextContent();
        try {
            intResolver.processResource(name, textContent, this, isSystem);
        } catch (NumberFormatException e) {
            throw new NumberFormatException("For input string \"" + textContent + "\" and resource " + name);
        }
    }

    @Override public Object convertRawValue(String rawValue) {
        if (rawValue != null && rawValue.startsWith("0x")) { // Hex strings are apparently valid.
            long color = Long.parseLong(rawValue.substring(2), 16);
            return (int) color;
        }
        return Integer.parseInt(rawValue);
    }
}

@@ -1195,248 +1195,276 @@
     
-if (rawValue != null && rawValue.startsWith(%220x%22)) %7B // Hex strings are apparently valid.%0A            long color = Long.parseLong(rawValue.substring(2), 16);%0A            return (int) color;%0A        %7D%0A        return Integer.parseInt(raw
+// This string could contain hex values, so we're going to use the %22decode%22 method.  Since Android can send us%0A        // an unsigned int larger than what Integer.decode is ok with, we parse it as a Long and convert down.%0A        return Long.decode(rawValue).int
 Value
+(
 );%0A 

Tweak to integer-loading logic