use of com.android.tools.build.bundletool.model.utils.ResourcesUtils.DEFAULT_DENSITY_VALUE in project bundletool by google.
the class ScreenDensityResourcesSplitter method filterEntryForDensity.
/**
* Only leaves the density specific config values optimized for a given density.
*
* <p>As any other resource qualifiers can be requested when delivering resources, the algorithm
* chooses the best match only within group of resources differing by density only.
*
* @param tableEntry the entry to be updated
* @param targetDensity the desired density to match
* @return the entry with the best matching density config values.
*/
private Entry filterEntryForDensity(ResourceTableEntry tableEntry, DensityAlias targetDensity) {
Entry initialEntry = tableEntry.getEntry();
// Groups together configs that only differ on density.
ImmutableMap<Configuration, ? extends List<ConfigValue>> configValuesByConfiguration = initialEntry.getConfigValueList().stream().filter(configValue -> RESOURCES_WITH_NO_ALTERNATIVES_IN_MASTER_SPLIT.enabledForVersion(bundleVersion) || configValue.getConfig().getDensity() != DEFAULT_DENSITY_VALUE).collect(groupingByDeterministic(configValue -> clearDensity(configValue.getConfig())));
// the master split.
if (RESOURCES_WITH_NO_ALTERNATIVES_IN_MASTER_SPLIT.enabledForVersion(bundleVersion)) {
configValuesByConfiguration = ImmutableMap.copyOf(Maps.filterValues(configValuesByConfiguration, configValues -> configValues.size() > 1));
}
ImmutableList<List<ConfigValue>> densityGroups = ImmutableList.copyOf(configValuesByConfiguration.values());
// We want to pin specific configs to the master, instead of putting them into a density split.
Predicate<ConfigValue> pinConfigToMaster;
if (pinWholeResourceToMaster.test(tableEntry.getResourceId())) {
pinConfigToMaster = anyConfig -> true;
} else if (pinLowestBucketToMaster(tableEntry)) {
ImmutableSet<ConfigValue> lowDensityConfigsPinnedToMaster = pickBestDensityForEachGroup(densityGroups, getLowestDensity(densityBuckets)).collect(toImmutableSet());
pinConfigToMaster = lowDensityConfigsPinnedToMaster::contains;
} else {
pinConfigToMaster = anyConfig -> false;
}
ImmutableList<ConfigValue> valuesToKeep = pickBestDensityForEachGroup(densityGroups, targetDensity).filter(config -> !pinConfigToMaster.test(config)).collect(toImmutableList());
return initialEntry.toBuilder().clearConfigValue().addAllConfigValue(valuesToKeep).build();
}
Aggregations