use of com.android.build.FilterData in project kotlin by JetBrains.
the class Project method getApplicableDensities.
/**
* Returns the set of applicable densities for this project. If null, there are no density
* restrictions and all densities apply.
*
* @return the list of specific densities that apply in this project, or null if all densities
* apply
*/
@Nullable
public List<String> getApplicableDensities() {
if (mCachedApplicableDensities == null) {
// ...then we should only enforce hdpi densities, not all these others!
if (isGradleProject() && getGradleProjectModel() != null && getCurrentVariant() != null) {
Set<String> relevantDensities = Sets.newHashSet();
Variant variant = getCurrentVariant();
List<String> variantFlavors = variant.getProductFlavors();
AndroidProject gradleProjectModel = getGradleProjectModel();
addResConfigsFromFlavor(relevantDensities, null, getGradleProjectModel().getDefaultConfig());
for (ProductFlavorContainer container : gradleProjectModel.getProductFlavors()) {
addResConfigsFromFlavor(relevantDensities, variantFlavors, container);
}
// Are there any splits that specify densities?
if (relevantDensities.isEmpty()) {
AndroidArtifact mainArtifact = variant.getMainArtifact();
Collection<AndroidArtifactOutput> outputs = mainArtifact.getOutputs();
for (AndroidArtifactOutput output : outputs) {
for (OutputFile file : output.getOutputs()) {
final String DENSITY_NAME = OutputFile.FilterType.DENSITY.name();
if (file.getFilterTypes().contains(DENSITY_NAME)) {
for (FilterData data : file.getFilters()) {
if (DENSITY_NAME.equals(data.getFilterType())) {
relevantDensities.add(data.getIdentifier());
}
}
}
}
}
}
if (!relevantDensities.isEmpty()) {
mCachedApplicableDensities = Lists.newArrayListWithExpectedSize(10);
for (String density : relevantDensities) {
String folder = ResourceFolderType.DRAWABLE.getName() + '-' + density;
mCachedApplicableDensities.add(folder);
}
Collections.sort(mCachedApplicableDensities);
} else {
mCachedApplicableDensities = Collections.emptyList();
}
} else {
mCachedApplicableDensities = Collections.emptyList();
}
}
return mCachedApplicableDensities.isEmpty() ? null : mCachedApplicableDensities;
}
Aggregations