use of com.android.resources.ResourceType in project platform_frameworks_base by android.
the class BridgeInflater method inflate.
@Override
public View inflate(int resource, ViewGroup root) {
Context context = getContext();
context = getBaseContext(context);
if (context instanceof BridgeContext) {
BridgeContext bridgeContext = (BridgeContext) context;
ResourceValue value = null;
@SuppressWarnings("deprecation") Pair<ResourceType, String> layoutInfo = Bridge.resolveResourceId(resource);
if (layoutInfo != null) {
value = bridgeContext.getRenderResources().getFrameworkResource(ResourceType.LAYOUT, layoutInfo.getSecond());
} else {
layoutInfo = mLayoutlibCallback.resolveResourceId(resource);
if (layoutInfo != null) {
value = bridgeContext.getRenderResources().getProjectResource(ResourceType.LAYOUT, layoutInfo.getSecond());
}
}
if (value != null) {
File f = new File(value.getValue());
if (f.isFile()) {
try {
XmlPullParser parser = ParserFactory.create(f, true);
BridgeXmlBlockParser bridgeParser = new BridgeXmlBlockParser(parser, bridgeContext, value.isFramework());
return inflate(bridgeParser, root);
} catch (Exception e) {
Bridge.getLog().error(LayoutLog.TAG_RESOURCES_READ, "Failed to parse file " + f.getAbsolutePath(), e, null);
return null;
}
}
}
}
return null;
}
use of com.android.resources.ResourceType in project platform_frameworks_base by android.
the class RenderDrawable method render.
public Result render() {
checkLock();
// get the drawable resource value
DrawableParams params = getParams();
HardwareConfig hardwareConfig = params.getHardwareConfig();
ResourceValue drawableResource = params.getDrawable();
// resolve it
BridgeContext context = getContext();
drawableResource = context.getRenderResources().resolveResValue(drawableResource);
if (drawableResource == null) {
return Status.ERROR_NOT_A_DRAWABLE.createResult();
}
ResourceType resourceType = drawableResource.getResourceType();
if (resourceType != ResourceType.DRAWABLE && resourceType != ResourceType.MIPMAP) {
return Status.ERROR_NOT_A_DRAWABLE.createResult();
}
Drawable d = ResourceHelper.getDrawable(drawableResource, context);
final Boolean allStates = params.getFlag(RenderParamsFlags.FLAG_KEY_RENDER_ALL_DRAWABLE_STATES);
if (allStates == Boolean.TRUE) {
final List<BufferedImage> result;
if (d instanceof StateListDrawable) {
result = new ArrayList<BufferedImage>();
final StateListDrawable stateList = (StateListDrawable) d;
for (int i = 0; i < stateList.getStateCount(); i++) {
final Drawable stateDrawable = stateList.getStateDrawable(i);
result.add(renderImage(hardwareConfig, stateDrawable, context));
}
} else {
result = Collections.singletonList(renderImage(hardwareConfig, d, context));
}
return Status.SUCCESS.createResult(result);
} else {
BufferedImage image = renderImage(hardwareConfig, d, context);
return Status.SUCCESS.createResult(image);
}
}
use of com.android.resources.ResourceType in project platform_frameworks_base by android.
the class LayoutLibTestCallback method initResources.
public void initResources() throws ClassNotFoundException {
Class<?> rClass = mModuleClassLoader.loadClass(PACKAGE_NAME + ".R");
Class<?>[] nestedClasses = rClass.getDeclaredClasses();
for (Class<?> resClass : nestedClasses) {
final ResourceType resType = ResourceType.getEnum(resClass.getSimpleName());
if (resType != null) {
final Map<String, Integer> resName2Id = Maps.newHashMap();
mResources.put(resType, resName2Id);
for (Field field : resClass.getDeclaredFields()) {
final int modifiers = field.getModifiers();
if (Modifier.isStatic(modifiers)) {
// May not be final in library projects
final Class<?> type = field.getType();
try {
if (type.isArray() && type.getComponentType() == int.class) {
mStyleableValueToNameMap.put(new IntArrayWrapper((int[]) field.get(null)), field.getName());
} else if (type == int.class) {
final Integer value = (Integer) field.get(null);
mProjectResources.put(value, Pair.of(resType, field.getName()));
resName2Id.put(field.getName(), value);
} else {
mLog.error(null, "Unknown field type in R class: %1$s", type);
}
} catch (IllegalAccessException ignored) {
mLog.error(ignored, "Malformed R class: %1$s", PACKAGE_NAME + ".R");
}
}
}
}
}
}
use of com.android.resources.ResourceType in project platform_frameworks_base by android.
the class CustomBar method getColor.
private static int getColor(RenderResources renderResources, String attr) {
// From ?attr/foo to @color/bar. This is most likely an ItemResourceValue.
ResourceValue resource = renderResources.findItemInTheme(attr, true);
// Form @color/bar to the #AARRGGBB
resource = renderResources.resolveResValue(resource);
if (resource != null) {
ResourceType type = resource.getResourceType();
if (type == null || type == ResourceType.COLOR) {
// file, rather than referencing a color resource value.
try {
return ResourceHelper.getColor(resource.getValue());
} catch (NumberFormatException e) {
// Conversion failed.
Bridge.getLog().warning(LayoutLog.TAG_RESOURCES_FORMAT, "Theme attribute @android:" + attr + " does not reference a color, instead is '" + resource.getValue() + "'.", resource);
}
}
}
return 0;
}
use of com.android.resources.ResourceType in project bazel by bazelbuild.
the class PublicXmlResourceValue method from.
@SuppressWarnings("deprecation")
public static XmlResourceValue from(SerializeFormat.DataValueXml proto) {
Map<String, String> protoValues = proto.getMappedStringValue();
ImmutableMap.Builder<ResourceType, Optional<Integer>> typeToId = ImmutableMap.builder();
for (Entry<String, String> entry : protoValues.entrySet()) {
ResourceType type = ResourceType.getEnum(entry.getKey());
Preconditions.checkNotNull(type);
Optional<Integer> id = MISSING_ID_VALUE.equals(entry.getValue()) ? Optional.<Integer>absent() : Optional.of(Integer.decode(entry.getValue()));
typeToId.put(type, id);
}
return of(typeToId.build());
}
Aggregations