com.android.ide.common.resources.configuration.DensityQualifier Java Examples

The following examples show how to use com.android.ide.common.resources.configuration.DensityQualifier. 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: SingleResourceFile.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
public SingleResourceFile(IAbstractFile file, ResourceFolder folder) {
    super(file, folder);

    // we need to infer the type of the resource from the folder type.
    // This is easy since this is a single Resource file.
    List<ResourceType> types = FolderTypeRelationship.getRelatedResourceTypes(folder.getType());
    mType = types.get(0);

    // compute the resource name
    mResourceName = getResourceName(mType);

    // test if there's a density qualifier associated with the resource
    DensityQualifier qualifier = folder.getConfiguration().getDensityQualifier();

    if (qualifier == null) {
        mValue = new ResourceValue(mType, getResourceName(mType),
                file.getOsLocation(), isFramework());
    } else {
        mValue = new DensityBasedResourceValue(
                mType,
                getResourceName(mType),
                file.getOsLocation(),
                qualifier.getValue(),
                isFramework());
    }
}
 
Example #2
Source File: SingleResourceFile.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
public SingleResourceFile(IAbstractFile file, ResourceFolder folder) {
    super(file, folder);

    // we need to infer the type of the resource from the folder type.
    // This is easy since this is a single Resource file.
    List<ResourceType> types = FolderTypeRelationship.getRelatedResourceTypes(folder.getType());
    mType = types.get(0);

    // compute the resource name
    mResourceName = getResourceName(mType);

    // test if there's a density qualifier associated with the resource
    DensityQualifier qualifier = folder.getConfiguration().getDensityQualifier();

    if (qualifier == null) {
        mValue = new ResourceValue(mType, getResourceName(mType),
                file.getOsLocation(), isFramework());
    } else {
        mValue = new DensityBasedResourceValue(
                mType,
                getResourceName(mType),
                file.getOsLocation(),
                qualifier.getValue(),
                isFramework());
    }
}
 
Example #3
Source File: IdGeneratingResourceFile.java    From NBANDROID-V2 with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the resource value associated with this whole file as a layout resource
 * @param file the file handler that represents this file
 * @param folder the folder this file is under
 * @return a resource value associated with this layout
 */
private ResourceValue getFileValue(IAbstractFile file, ResourceFolder folder) {
    // test if there's a density qualifier associated with the resource
    DensityQualifier qualifier = folder.getConfiguration().getDensityQualifier();

    ResourceValue value;
    if (!ResourceQualifier.isValid(qualifier)) {
        value =
                new ResourceValueImpl(
                        new ResourceReference(mFileType, mFileName, isFramework()),
                        file.getOsLocation());
    } else {
        value =
                new DensityBasedResourceValueImpl(
                        new ResourceReference(mFileType, mFileName, isFramework()),
                        file.getOsLocation(),
                        qualifier.getValue());
    }
    return value;
}
 
Example #4
Source File: ResourceItem.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
@Nullable
private Density getFolderDensity() {
    String qualifiers = getQualifiers();
    if (!qualifiers.isEmpty() && qualifiers.contains("dpi")) {
        Iterable<String> segments = Splitter.on('-').split(qualifiers);
        FolderConfiguration config = FolderConfiguration.getConfigFromQualifiers(segments);
        if (config != null) {
            DensityQualifier densityQualifier = config.getDensityQualifier();
            if (densityQualifier != null) {
                return densityQualifier.getValue();
            }
        }
    }
    return null;
}
 
Example #5
Source File: ResourceItem.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
private Density getFolderDensity() {
    String qualifiers = getQualifiers();
    if (!qualifiers.isEmpty() && qualifiers.contains("dpi")) {
        Iterable<String> segments = Splitter.on('-').split(qualifiers);
        FolderConfiguration config = FolderConfiguration.getConfigFromQualifiers(segments);
        if (config != null) {
            DensityQualifier densityQualifier = config.getDensityQualifier();
            if (densityQualifier != null) {
                return densityQualifier.getValue();
            }
        }
    }
    return null;
}
 
Example #6
Source File: VectorDrawableRenderer.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Collection<File> getFilesToBeGenerated(File inputXmlFile) {
    FolderConfiguration originalConfiguration = getFolderConfiguration(inputXmlFile);

    // Create all the PNG files and duplicate the XML into folders with the version qualifier.
    Collection<File> filesToBeGenerated = Lists.newArrayList();
    for (Density density : mDensities) {
        FolderConfiguration newConfiguration = FolderConfiguration.copyOf(originalConfiguration);
        newConfiguration.setDensityQualifier(new DensityQualifier(density));

        File directory = new File(
                mOutputDir,
                newConfiguration.getFolderName(ResourceFolderType.DRAWABLE));
        File pngFile = new File(
                directory,
                inputXmlFile.getName().replace(".xml", ".png"));

        filesToBeGenerated.add(pngFile);

        newConfiguration.setVersionQualifier(new VersionQualifier(MIN_SDK_WITH_VECTOR_SUPPORT));
        File destination = new File(
                mOutputDir,
                newConfiguration.getFolderName(ResourceFolderType.DRAWABLE));
        File xmlCopy = new File(destination, inputXmlFile.getName());
        filesToBeGenerated.add(xmlCopy);
    }

    return filesToBeGenerated;
}
 
Example #7
Source File: SingleResourceFile.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
public SingleResourceFile(IAbstractFile file, ResourceFolder folder) {
    super(file, folder);

    // we need to infer the type of the resource from the folder type.
    // This is easy since this is a single Resource file.
    List<ResourceType> types = FolderTypeRelationship.getRelatedResourceTypes(folder.getType());
    mType = types.get(0);

    // compute the resource name
    mResourceName = getResourceName(mType);

    // test if there's a density qualifier associated with the resource
    DensityQualifier qualifier = folder.getConfiguration().getDensityQualifier();

    if (!ResourceQualifier.isValid(qualifier)) {
        mValue =
                new ResourceValueImpl(
                        new ResourceReference(mType, getResourceName(mType), isFramework()),
                        file.getOsLocation());
    } else {
        mValue =
                new DensityBasedResourceValueImpl(
                        new ResourceReference(mType, getResourceName(mType), isFramework()),
                        file.getOsLocation(),
                        qualifier.getValue());
    }
}
 
Example #8
Source File: ConfigGenerator.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
public FolderConfiguration getFolderConfig() {
    FolderConfiguration config = new FolderConfiguration();
    // config.createDefault();
    config.setDensityQualifier(new DensityQualifier(mDensity));
    config.setNavigationMethodQualifier(new NavigationMethodQualifier(mNavigation));
    if (mScreenWidth > mScreenHeight) {
        config.setScreenDimensionQualifier(new ScreenDimensionQualifier(mScreenWidth,
                mScreenHeight));
    } else {
        config.setScreenDimensionQualifier(new ScreenDimensionQualifier(mScreenHeight,
                mScreenWidth));
    }
    config.setScreenRatioQualifier(new ScreenRatioQualifier(mRatio));
    config.setScreenSizeQualifier(new ScreenSizeQualifier(mSize));
    config.setTextInputMethodQualifier(new TextInputMethodQualifier(mKeyboard));
    config.setTouchTypeQualifier(new TouchScreenQualifier(mTouchScreen));
    config.setKeyboardStateQualifier(new KeyboardStateQualifier(mKeyboardState));
    config.setScreenOrientationQualifier(new ScreenOrientationQualifier(mOrientation));

    config.updateScreenWidthAndHeight();

    // some default qualifiers.
    config.setUiModeQualifier(new UiModeQualifier(UiMode.NORMAL));
    config.setNightModeQualifier(new NightModeQualifier(NightMode.NOTNIGHT));
    config.setCountryCodeQualifier(new CountryCodeQualifier());
    config.setLayoutDirectionQualifier(new LayoutDirectionQualifier());
    config.setNetworkCodeQualifier(new NetworkCodeQualifier());
    config.setLocaleQualifier(new LocaleQualifier());
    config.setVersionQualifier(new VersionQualifier(28));
    return config;
}
 
Example #9
Source File: RenderServiceFactory.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Creates a config. This must be a valid config like a device would return. This is to
 * prevent issues where some resources don't exist in all cases and not in the default
 * (for instance only available in hdpi and mdpi but not in default).
 *
 * @param size1
 * @param size2
 * @param screenSize
 * @param screenRatio
 * @param orientation
 * @param density
 * @param touchScreen
 * @param keyboardState
 * @param keyboard
 * @param navigationState
 * @param navigation
 * @param apiLevel
 * @return
 */
public static FolderConfiguration createConfig(
        int size1,
        int size2,
        ScreenSize screenSize,
        ScreenRatio screenRatio,
        ScreenOrientation orientation,
        Density density,
        TouchScreen touchScreen,
        KeyboardState keyboardState,
        Keyboard keyboard,
        NavigationState navigationState,
        Navigation navigation,
        int apiLevel) {
    FolderConfiguration config = new FolderConfiguration();

    int width = size1, height = size2;
    switch (orientation) {
        case LANDSCAPE:
            width = size1 < size2 ? size2 : size1;
            height = size1 < size2 ? size1 : size2;
            break;
        case PORTRAIT:
            width = size1 < size2 ? size1 : size2;
            height = size1 < size2 ? size2 : size1;
            break;
        case SQUARE:
            width = height = size1;
            break;
    }

    int wdp = (width * Density.DEFAULT_DENSITY) / density.getDpiValue();
    int hdp = (height * Density.DEFAULT_DENSITY) / density.getDpiValue();

    config.addQualifier(new SmallestScreenWidthQualifier(wdp < hdp ? wdp : hdp));
    config.addQualifier(new ScreenWidthQualifier(wdp));
    config.addQualifier(new ScreenHeightQualifier(hdp));

    config.addQualifier(new ScreenSizeQualifier(screenSize));
    config.addQualifier(new ScreenRatioQualifier(screenRatio));
    config.addQualifier(new ScreenOrientationQualifier(orientation));
    config.addQualifier(new DensityQualifier(density));
    config.addQualifier(new TouchScreenQualifier(touchScreen));
    config.addQualifier(new KeyboardStateQualifier(keyboardState));
    config.addQualifier(new TextInputMethodQualifier(keyboard));
    config.addQualifier(new NavigationStateQualifier(navigationState));
    config.addQualifier(new NavigationMethodQualifier(navigation));
    config.addQualifier(width > height ? new ScreenDimensionQualifier(width, height) :
        new ScreenDimensionQualifier(height, width));
    config.addQualifier(new VersionQualifier(apiLevel));

    config.updateScreenWidthAndHeight();

    return config;
}