Search in sources :

Example 1 with FilterData

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;
}
Also used : Variant(com.android.builder.model.Variant) OutputFile(com.android.build.OutputFile) ProductFlavorContainer(com.android.builder.model.ProductFlavorContainer) FilterData(com.android.build.FilterData) AndroidProject(com.android.builder.model.AndroidProject) AndroidArtifactOutput(com.android.builder.model.AndroidArtifactOutput) AndroidArtifact(com.android.builder.model.AndroidArtifact) Nullable(com.android.annotations.Nullable)

Aggregations

Nullable (com.android.annotations.Nullable)1 FilterData (com.android.build.FilterData)1 OutputFile (com.android.build.OutputFile)1 AndroidArtifact (com.android.builder.model.AndroidArtifact)1 AndroidArtifactOutput (com.android.builder.model.AndroidArtifactOutput)1 AndroidProject (com.android.builder.model.AndroidProject)1 ProductFlavorContainer (com.android.builder.model.ProductFlavorContainer)1 Variant (com.android.builder.model.Variant)1