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

The following examples show how to use com.android.ide.common.resources.configuration.VersionQualifier. 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: 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 #2
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 #3
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;
}
 
Example #4
Source File: LayoutPreviewPanelImpl.java    From NBANDROID-V2 with Apache License 2.0 4 votes vote down vote up
protected SessionParams getSessionParams(File platformFolder, ILayoutPullParser layoutParser,
        ConfigGenerator configGenerator, LayoutLibCallback layoutLibCallback,
        String themeName, boolean isProjectTheme, SessionParams.RenderingMode renderingMode,
        @SuppressWarnings("SameParameterValue") int targetSdk) {
    //****************
    FolderConfiguration config = configGenerator.getFolderConfig();
    config.setVersionQualifier(VersionQualifier.getQualifier(VersionQualifier.getFolderSegment(28)));

    //****************
    File platform_data_dir = new File(platformFolder, "data");
    File platform_res_dir = new File(platform_data_dir, "res");
    //****************
    Map<ResourceNamespace, Map<ResourceType, ResourceValueMap>> allResources
            = new DisjointUnionMap<>(FrameworkResourcesCache.getOrCreateFrameworkResources(platform_res_dir).getConfiguredResources(config).rowMap(), projectResourceRepository.getConfiguredResources(config).rowMap());

    if (themes.isEmpty()) {
        for (Map.Entry<ResourceNamespace, Map<ResourceType, ResourceValueMap>> entry : allResources.entrySet()) {
            if (entry.getKey().equals(ResourceNamespace.RES_AUTO)) {
                Map<ResourceType, ResourceValueMap> value = entry.getValue();
                ResourceValueMap m = value.get(ResourceType.STYLE);
                for (Map.Entry<String, ResourceValue> entry1 : m.entrySet()) {
                    String key = entry1.getKey();
                    ResourceValue value1 = entry1.getValue();
                    if (value1 instanceof StyleResourceValue) {
                        themes.add("@style/" + value1.getName());
                    }
                }
            }

        }
        Collections.sort(themes);
        themeCombo.setModel(new DefaultComboBoxModel<>(new Vector<>(themes)));
        themeCombo.setSelectedItem(themeName);
        themeCombo.addItemListener(this);
    }
    ResourceUrl themeUrl;
    if (themeMode.isSelected()) {
        //mode parent
        themeUrl = ResourceUrl.parse(themeName);
    } else {
        //mode theme
        LayoutIO.logInfo("Theme patch, current theme changed to: " + ((String) themeCombo.getSelectedItem()));
        themeUrl = ResourceUrl.parse((String) themeCombo.getSelectedItem());
    }
    ResourceReference theme = null;

    if (themeUrl != null) {
        theme = themeUrl.resolve(appNamespace, new ResourceNamespace.Resolver() {
            @Override
            public String prefixToUri(String namespacePrefix) {
                throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }
        });
    }
    ResourceResolver resourceResolver = ResourceResolver.create(allResources, theme);
    if (!((String) themeCombo.getSelectedItem()).equals(themeName) && themeMode.isSelected()) {
        //mode parent and another theme is selected
        resourceResolver.patchAutoStyleParent(themeName.replace("@style/", ""), ((String) themeCombo.getSelectedItem()).replace("@style/", ""));
        LayoutIO.logInfo("Theme patch, theme parent changed to: " + ((String) themeCombo.getSelectedItem()));
    }
    resourceResolver.setDeviceDefaults("Material");
    resourceLookupChain = new ArrayList<>();
    SessionParams sessionParams
            = new SessionParams(layoutParser, renderingMode, null /*used for caching*/,
                    configGenerator.getHardwareConfig(), resourceResolver.createRecorder(resourceLookupChain), layoutLibCallback, 0,
                    targetSdk, new LayoutLog());
    sessionParams.setFlag(RenderParamsFlags.FLAG_DO_NOT_RENDER_ON_CREATE, true);
    sessionParams.setAssetRepository(new LayoutAssetRepository());
    return sessionParams;
}