use of com.google.devtools.build.android.resources.IntFieldInitializer in project bazel by bazelbuild.
the class AndroidResourceClassWriter method getResourceInitializers.
private List<FieldInitializer> getResourceInitializers(ResourceType type, int typeId, Collection<String> sortedFields) {
ImmutableList.Builder<FieldInitializer> initList = ImmutableList.builder();
Map<String, Integer> publicNameToId = new HashMap<>();
Set<Integer> assignedIds = ImmutableSet.of();
if (publicIds.containsKey(type)) {
assignedIds = assignPublicIds(publicNameToId, publicIds.get(type), typeId);
}
int resourceIds = nextFreeId(getInitialIdForTypeId(typeId), assignedIds);
for (String field : sortedFields) {
Integer fieldValue = publicNameToId.get(field);
if (fieldValue == null) {
fieldValue = resourceIds;
resourceIds = nextFreeId(resourceIds + 1, assignedIds);
}
initList.add(new IntFieldInitializer(field, fieldValue));
}
return initList.build();
}
use of com.google.devtools.build.android.resources.IntFieldInitializer in project bazel by bazelbuild.
the class AndroidResourceClassWriter method getStyleableInitializers.
private List<FieldInitializer> getStyleableInitializers(Map<String, Integer> attrAssignments, Collection<String> styleableFields) throws AttrLookupException {
ImmutableList.Builder<FieldInitializer> initList = ImmutableList.builder();
for (String field : styleableFields) {
Set<String> attrs = styleableAttrs.get(field).keySet();
ImmutableMap.Builder<String, Integer> arrayInitValues = ImmutableMap.builder();
for (String attr : attrs) {
Integer attrId = attrAssignments.get(attr);
if (attrId == null) {
// It should be a framework resource, otherwise we don't know about the resource.
if (!attr.startsWith(NORMALIZED_ANDROID_PREFIX)) {
throw new AttrLookupException("App attribute not found: " + attr);
}
String attrWithoutPrefix = attr.substring(NORMALIZED_ANDROID_PREFIX.length());
attrId = androidIdProvider.getAttrId(attrWithoutPrefix);
}
arrayInitValues.put(attr, attrId);
}
// The styleable array should be sorted by ID value.
// Make sure that if we have android: framework attributes, their IDs are listed first.
ImmutableMap<String, Integer> arrayInitMap = arrayInitValues.orderEntriesByValue(Ordering.<Integer>natural()).build();
initList.add(new IntArrayFieldInitializer(field, arrayInitMap.values()));
int index = 0;
for (String attr : arrayInitMap.keySet()) {
initList.add(new IntFieldInitializer(field + "_" + attr, index));
++index;
}
}
return initList.build();
}
use of com.google.devtools.build.android.resources.IntFieldInitializer in project bazel by bazelbuild.
the class AndroidResourceClassWriter method getAttrInitializers.
private List<FieldInitializer> getAttrInitializers(Map<String, Integer> attrAssignments, Collection<String> sortedFields) {
ImmutableList.Builder<FieldInitializer> initList = ImmutableList.builder();
for (String field : sortedFields) {
int attrId = attrAssignments.get(field);
initList.add(new IntFieldInitializer(field, attrId));
}
return initList.build();
}
Aggregations