
com.xtremelabs.robolectric.res.DimenResourceLoader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of robolectric Show documentation
Show all versions of robolectric Show documentation
An alternative Android testing framework.
The newest version!
package com.xtremelabs.robolectric.res;
import org.w3c.dom.Node;
public class DimenResourceLoader extends XpathResourceXmlLoader implements ResourceValueConverter {
private static final String[] UNITS = { "dp", "dip", "pt", "px", "sp", "mm", "in" };
private ResourceReferenceResolver dimenResolver = new ResourceReferenceResolver("dimen");
public DimenResourceLoader(ResourceExtractor resourceExtractor) {
super(resourceExtractor, "/resources/dimen");
}
public float getValue(int resourceId) {
return dimenResolver.getValue(resourceExtractor.getResourceName(resourceId));
}
public float getValue(String resourceName, boolean isSystem) {
return getValue(resourceExtractor.getResourceId(resourceName, isSystem));
}
@Override
protected void processNode(Node node, String name, boolean isSystem) {
dimenResolver.processResource(name, node.getTextContent(), this, isSystem);
}
@Override
public Object convertRawValue(String rawValue) {
int end = rawValue.length();
for (String UNIT : UNITS) {
int index = rawValue.indexOf(UNIT);
if (index >= 0 && end > index) {
end = index;
}
}
return Float.parseFloat(rawValue.substring(0, end));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy