Search in sources :

Example 1 with IntFieldInitializer

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();
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) IntFieldInitializer(com.google.devtools.build.android.resources.IntFieldInitializer) ImmutableList(com.google.common.collect.ImmutableList) FieldInitializer(com.google.devtools.build.android.resources.FieldInitializer) IntArrayFieldInitializer(com.google.devtools.build.android.resources.IntArrayFieldInitializer) IntFieldInitializer(com.google.devtools.build.android.resources.IntFieldInitializer)

Example 2 with IntFieldInitializer

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();
}
Also used : IntArrayFieldInitializer(com.google.devtools.build.android.resources.IntArrayFieldInitializer) ImmutableList(com.google.common.collect.ImmutableList) FieldInitializer(com.google.devtools.build.android.resources.FieldInitializer) IntArrayFieldInitializer(com.google.devtools.build.android.resources.IntArrayFieldInitializer) IntFieldInitializer(com.google.devtools.build.android.resources.IntFieldInitializer) ImmutableMap(com.google.common.collect.ImmutableMap) AttrLookupException(com.google.devtools.build.android.AndroidFrameworkAttrIdProvider.AttrLookupException) IntFieldInitializer(com.google.devtools.build.android.resources.IntFieldInitializer)

Example 3 with IntFieldInitializer

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();
}
Also used : IntFieldInitializer(com.google.devtools.build.android.resources.IntFieldInitializer) ImmutableList(com.google.common.collect.ImmutableList) FieldInitializer(com.google.devtools.build.android.resources.FieldInitializer) IntArrayFieldInitializer(com.google.devtools.build.android.resources.IntArrayFieldInitializer) IntFieldInitializer(com.google.devtools.build.android.resources.IntFieldInitializer)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)3 FieldInitializer (com.google.devtools.build.android.resources.FieldInitializer)3 IntArrayFieldInitializer (com.google.devtools.build.android.resources.IntArrayFieldInitializer)3 IntFieldInitializer (com.google.devtools.build.android.resources.IntFieldInitializer)3 ImmutableMap (com.google.common.collect.ImmutableMap)1 AttrLookupException (com.google.devtools.build.android.AndroidFrameworkAttrIdProvider.AttrLookupException)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1