use of com.android.resources.ResourceType in project bazel by bazelbuild.
the class FullyQualifiedName method createTypeFrom.
private static Type createTypeFrom(String rawType) {
ResourceType resourceType = ResourceType.getEnum(rawType);
VirtualType virtualType = VirtualType.getEnum(rawType);
if (resourceType != null) {
return new ResourceTypeWrapper(resourceType);
} else if (virtualType != null) {
return virtualType;
}
return null;
}
use of com.android.resources.ResourceType in project bazel by bazelbuild.
the class XmlResourceValues method parsePublic.
static XmlResourceValue parsePublic(XMLEventReader eventReader, StartElement start, Namespaces.Collector namespacesCollector) throws XMLStreamException {
namespacesCollector.collectFrom(start);
// The tag should be unary.
if (!isEndTag(eventReader.peek(), start.getName())) {
throw new XMLStreamException(String.format("<public> tag should be unary %s", start), start.getLocation());
}
// The tag should have a valid type attribute, and optionally an id attribute.
ImmutableMap<String, String> attributes = ImmutableMap.copyOf(parseTagAttributes(start));
String typeAttr = attributes.get(SdkConstants.ATTR_TYPE);
ResourceType type;
if (typeAttr != null) {
type = ResourceType.getEnum(typeAttr);
if (type == null || type == ResourceType.PUBLIC) {
throw new XMLStreamException(String.format("<public> tag has invalid type attribute %s", start), start.getLocation());
}
} else {
throw new XMLStreamException(String.format("<public> tag missing type attribute %s", start), start.getLocation());
}
String idValueAttr = attributes.get(SdkConstants.ATTR_ID);
Optional<Integer> id = Optional.absent();
if (idValueAttr != null) {
try {
id = Optional.of(Integer.decode(idValueAttr));
} catch (NumberFormatException e) {
throw new XMLStreamException(String.format("<public> has invalid id number %s", start), start.getLocation());
}
}
if (attributes.size() > 2) {
throw new XMLStreamException(String.format("<public> has unexpected attributes %s", start), start.getLocation());
}
return PublicXmlResourceValue.create(type, id);
}
use of com.android.resources.ResourceType in project bazel by bazelbuild.
the class AndroidResourceClassWriter method assignTypeIdsForPublic.
private Map<ResourceType, Integer> assignTypeIdsForPublic() {
Map<ResourceType, Integer> allocatedTypeIds = new EnumMap<>(ResourceType.class);
if (publicIds.isEmpty()) {
return allocatedTypeIds;
}
// Keep track of the reverse mapping from Int -> Type for validation.
Map<Integer, ResourceType> assignedIds = new HashMap<>();
for (Map.Entry<ResourceType, SortedMap<String, Optional<Integer>>> publicTypeEntry : publicIds.entrySet()) {
ResourceType currentType = publicTypeEntry.getKey();
Integer reservedTypeSlot = null;
String previousResource = null;
for (Map.Entry<String, Optional<Integer>> publicEntry : publicTypeEntry.getValue().entrySet()) {
Optional<Integer> reservedId = publicEntry.getValue();
if (!reservedId.isPresent()) {
continue;
}
Integer typePortion = extractTypeId(reservedId.get());
if (reservedTypeSlot == null) {
reservedTypeSlot = typePortion;
previousResource = publicEntry.getKey();
} else {
if (!reservedTypeSlot.equals(typePortion)) {
logger.warning(String.format("%s has conflicting type codes for its public identifiers (%s=%s vs %s=%s)", currentType.getName(), previousResource, reservedTypeSlot, publicEntry.getKey(), typePortion));
}
}
}
if (currentType == ResourceType.ATTR && reservedTypeSlot != null && !reservedTypeSlot.equals(ATTR_TYPE_ID)) {
logger.warning(String.format("Cannot force ATTR to have type code other than 0x%02x (got 0x%02x from %s)", ATTR_TYPE_ID, reservedTypeSlot, previousResource));
}
allocatedTypeIds.put(currentType, reservedTypeSlot);
ResourceType alreadyAssigned = assignedIds.put(reservedTypeSlot, currentType);
if (alreadyAssigned != null) {
logger.warning(String.format("Multiple type names declared for public type identifier 0x%x (%s vs %s)", reservedTypeSlot, alreadyAssigned, currentType));
}
}
return allocatedTypeIds;
}
use of com.android.resources.ResourceType in project android_frameworks_base by ParanoidAndroid.
the class BridgeContext method resolveThemeAttribute.
public boolean resolveThemeAttribute(int resid, TypedValue outValue, boolean resolveRefs) {
Pair<ResourceType, String> resourceInfo = Bridge.resolveResourceId(resid);
boolean isFrameworkRes = true;
if (resourceInfo == null) {
resourceInfo = mProjectCallback.resolveResourceId(resid);
isFrameworkRes = false;
}
if (resourceInfo == null) {
return false;
}
ResourceValue value = mRenderResources.findItemInTheme(resourceInfo.getSecond(), isFrameworkRes);
if (resolveRefs) {
value = mRenderResources.resolveResValue(value);
}
// check if this is a style resource
if (value instanceof StyleResourceValue) {
// get the id that will represent this style.
outValue.resourceId = getDynamicIdByStyle((StyleResourceValue) value);
return true;
}
int a;
// if this is a framework value.
if (value.isFramework()) {
// look for idName in the android R classes.
// use 0 a default res value as it's not a valid id value.
a = getFrameworkResourceValue(value.getResourceType(), value.getName(), 0);
} else {
// look for idName in the project R class.
// use 0 a default res value as it's not a valid id value.
a = getProjectResourceValue(value.getResourceType(), value.getName(), 0);
}
if (a != 0) {
outValue.resourceId = a;
return true;
}
return false;
}
use of com.android.resources.ResourceType in project android_frameworks_base by ResurrectionRemix.
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);
}
}
Aggregations