Java Code Examples for com.android.resources.Density#ANYDPI

The following examples show how to use com.android.resources.Density#ANYDPI . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Project.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Adds in the resConfig values specified by the given flavor container, assuming
 * it's in one of the relevant variantFlavors, into the given set
 */
private static void addResConfigsFromFlavor(@NonNull Set<String> relevantDensities,
        @Nullable List<String> variantFlavors,
        @NonNull ProductFlavorContainer container) {
    ProductFlavor flavor = container.getProductFlavor();
    if (variantFlavors == null || variantFlavors.contains(flavor.getName())) {
        if (!flavor.getResourceConfigurations().isEmpty()) {
            for (String densityName : flavor.getResourceConfigurations()) {
                Density density = Density.getEnum(densityName);
                if (density != null && density.isRecommended()
                        && density != Density.NODPI && density != Density.ANYDPI) {
                    relevantDensities.add(densityName);
                }
            }
        }
    }
}
 
Example 2
Source File: IconDetector.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Adds in the resConfig values specified by the given flavor container, assuming
 * it's in one of the relevant variantFlavors, into the given set
 */
private static void addResConfigsFromFlavor(@NonNull Set<String> relevantDensities,
                                            @Nullable List<String> variantFlavors,
                                            @NonNull ProductFlavorContainer container) {
    ProductFlavor flavor = container.getProductFlavor();
    if (variantFlavors == null || variantFlavors.contains(flavor.getName())) {
        if (!flavor.getResourceConfigurations().isEmpty()) {
            for (String densityName : flavor.getResourceConfigurations()) {
                Density density = Density.getEnum(densityName);
                if (density != null && density.isRecommended()
                        && density != Density.NODPI && density != Density.ANYDPI) {
                    relevantDensities.add(densityName);
                }
            }
        }
    }
}
 
Example 3
Source File: DensityQualifier.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean isBetterMatchThan(ResourceQualifier compareTo, ResourceQualifier reference) {
    if (compareTo == null) {
        return true;
    }

    DensityQualifier compareQ = (DensityQualifier)compareTo;
    DensityQualifier referenceQ = (DensityQualifier)reference;

    if (compareQ.mValue == referenceQ.mValue || compareQ.mValue == Density.ANYDPI) {
        // what we have is already the best possible match (exact match)
        return false;
    } else if (mValue == referenceQ.mValue || mValue == Density.ANYDPI) {
        // got new exact value, this is the best!
        return true;
    } else {
        // in all case we're going to prefer the higher dpi.
        // if reference is high, we want highest dpi.
        // if reference is medium, we'll prefer to scale down high dpi, than scale up low dpi
        // if reference if low, we'll prefer to scale down high than medium (2:1 over 4:3)
        return mValue.getDpiValue() > compareQ.mValue.getDpiValue();
    }
}
 
Example 4
Source File: DensitySplitOptions.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected Set<String> getDefaultValues() {
    Density[] values = Density.values();
    Set<String> fullList = Sets.newHashSetWithExpectedSize(values.length - 2);
    for (Density value : values) {
        if (value != Density.NODPI && value != Density.ANYDPI && value.isRecommended()) {
            fullList.add(value.getResourceValue());
        }
    }

    return fullList;
}
 
Example 5
Source File: DensitySplitOptions.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected ImmutableSet<String> getAllowedValues() {
    ImmutableSet.Builder<String> builder = ImmutableSet.builder();

    for (Density value : Density.values()) {
        if (value != Density.NODPI && value != Density.ANYDPI) {
            builder.add(value.getResourceValue());
        }
    }

    return builder.build();
}
 
Example 6
Source File: FolderConfiguration.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Updates the {@link SmallestScreenWidthQualifier}, {@link ScreenWidthQualifier}, and
 * {@link ScreenHeightQualifier} based on the (required) values of
 * {@link ScreenDimensionQualifier} {@link DensityQualifier}, and
 * {@link ScreenOrientationQualifier}.
 *
 * Also the density cannot be {@link Density#NODPI} as it's not valid on a device.
 */
public void updateScreenWidthAndHeight() {

    ResourceQualifier sizeQ = mQualifiers[INDEX_SCREEN_DIMENSION];
    ResourceQualifier densityQ = mQualifiers[INDEX_PIXEL_DENSITY];
    ResourceQualifier orientQ = mQualifiers[INDEX_SCREEN_ORIENTATION];

    if (sizeQ != null && densityQ != null && orientQ != null) {
        Density density = ((DensityQualifier) densityQ).getValue();
        if (density == Density.NODPI || density == Density.ANYDPI) {
            return;
        }

        ScreenOrientation orientation = ((ScreenOrientationQualifier) orientQ).getValue();

        int size1 = ((ScreenDimensionQualifier) sizeQ).getValue1();
        int size2 = ((ScreenDimensionQualifier) sizeQ).getValue2();

        // make sure size1 is the biggest (should be the case, but make sure)
        if (size1 < size2) {
            int a = size1;
            size1 = size2;
            size2 = a;
        }

        // compute the dp. round them up since we want -w480dp to match a 480.5dp screen
        int dp1 = (int) Math.ceil(size1 * Density.DEFAULT_DENSITY / density.getDpiValue());
        int dp2 = (int) Math.ceil(size2 * Density.DEFAULT_DENSITY / density.getDpiValue());

        setSmallestScreenWidthQualifier(new SmallestScreenWidthQualifier(dp2));

        switch (orientation) {
            case PORTRAIT:
                setScreenWidthQualifier(new ScreenWidthQualifier(dp2));
                setScreenHeightQualifier(new ScreenHeightQualifier(dp1));
                break;
            case LANDSCAPE:
                setScreenWidthQualifier(new ScreenWidthQualifier(dp1));
                setScreenHeightQualifier(new ScreenHeightQualifier(dp2));
                break;
            case SQUARE:
                setScreenWidthQualifier(new ScreenWidthQualifier(dp2));
                setScreenHeightQualifier(new ScreenHeightQualifier(dp2));
                break;
        }
    }
}