Search in sources :

Example 11 with VersionQualifier

use of com.android.ide.common.resources.configuration.VersionQualifier in project android by JetBrains.

the class AndroidThemePreviewToolWindowManager method getBestConfiguration.

@Nullable
private static /*if there is no available configuration that would select the passed file*/
Configuration getBestConfiguration(@Nullable PsiFile psiFile) {
    Module module = psiFile != null ? ModuleUtilCore.findModuleForPsiElement(psiFile) : null;
    if (module == null) {
        return null;
    }
    AndroidFacet facet = AndroidFacet.getInstance(module);
    if (facet == null) {
        return null;
    }
    VirtualFile virtualFile = psiFile.getVirtualFile();
    ConfigurationManager manager = facet.getConfigurationManager();
    List<VirtualFile> variations = ResourceHelper.getResourceVariations(virtualFile, false);
    if (variations.isEmpty()) {
        return manager.getConfiguration(virtualFile);
    }
    // There is more than one resource folder available so make sure we select a configuration that only matches the current file.
    Collection<FolderConfiguration> incompatible = Collections2.transform(variations, new Function<VirtualFile, FolderConfiguration>() {

        @Nullable
        @Override
        public FolderConfiguration apply(VirtualFile input) {
            assert input != null;
            return ResourceHelper.getFolderConfiguration(input);
        }
    });
    FolderConfiguration selectedFileFolderConfiguration = ResourceHelper.getFolderConfiguration(psiFile);
    if (selectedFileFolderConfiguration == null) {
        // This folder probably has invalid qualifiers or they are in the wrong order
        return null;
    }
    RestrictedConfiguration restrictedConfiguration = RestrictedConfiguration.restrict(selectedFileFolderConfiguration, incompatible);
    if (restrictedConfiguration == null) {
        // Unable to create a configuration that only matches this file
        return null;
    }
    FolderConfiguration restricted = restrictedConfiguration.getAny();
    Configuration newConfiguration = Configuration.create(manager, virtualFile, null, restricted);
    VersionQualifier newVersionQualifier = restricted.getVersionQualifier();
    if (newVersionQualifier != null) {
        IAndroidTarget realTarget = manager.getHighestApiTarget() != null ? manager.getHighestApiTarget() : manager.getTarget();
        assert realTarget != null;
        newConfiguration.setTarget(new CompatibilityRenderTarget(realTarget, newVersionQualifier.getVersion(), null));
    }
    return newConfiguration;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Configuration(com.android.tools.idea.configurations.Configuration) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) RestrictedConfiguration(com.android.tools.idea.editors.theme.qualifiers.RestrictedConfiguration) VersionQualifier(com.android.ide.common.resources.configuration.VersionQualifier) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) IAndroidTarget(com.android.sdklib.IAndroidTarget) RestrictedConfiguration(com.android.tools.idea.editors.theme.qualifiers.RestrictedConfiguration) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) CompatibilityRenderTarget(com.android.tools.idea.rendering.multi.CompatibilityRenderTarget) Module(com.intellij.openapi.module.Module) ConfigurationManager(com.android.tools.idea.configurations.ConfigurationManager) Nullable(org.jetbrains.annotations.Nullable) Nullable(org.jetbrains.annotations.Nullable)

Example 12 with VersionQualifier

use of com.android.ide.common.resources.configuration.VersionQualifier in project android by JetBrains.

the class ThemeEditorUtils method getMinFolderApi.

/**
   * Returns the smallest api level of the folders in folderNames.
   * Returns Integer.MAX_VALUE if folderNames is empty.
   */
public static int getMinFolderApi(@NotNull List<String> folderNames, @NotNull Module module) {
    int minFolderApi = Integer.MAX_VALUE;
    int minModuleApi = getMinApiLevel(module);
    for (String folderName : folderNames) {
        FolderConfiguration folderConfig = FolderConfiguration.getConfigForFolder(folderName);
        if (folderConfig != null) {
            VersionQualifier version = folderConfig.getVersionQualifier();
            int folderApi = version != null ? version.getVersion() : minModuleApi;
            minFolderApi = Math.min(minFolderApi, folderApi);
        }
    }
    return minFolderApi;
}
Also used : VersionQualifier(com.android.ide.common.resources.configuration.VersionQualifier) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration)

Example 13 with VersionQualifier

use of com.android.ide.common.resources.configuration.VersionQualifier in project android_frameworks_base by DirtyUnicorns.

the class ConfigGenerator method getFolderConfig.

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());
    return config;
}
Also used : VersionQualifier(com.android.ide.common.resources.configuration.VersionQualifier) NavigationMethodQualifier(com.android.ide.common.resources.configuration.NavigationMethodQualifier) ScreenSizeQualifier(com.android.ide.common.resources.configuration.ScreenSizeQualifier) KeyboardStateQualifier(com.android.ide.common.resources.configuration.KeyboardStateQualifier) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) NightModeQualifier(com.android.ide.common.resources.configuration.NightModeQualifier) ScreenOrientationQualifier(com.android.ide.common.resources.configuration.ScreenOrientationQualifier) UiModeQualifier(com.android.ide.common.resources.configuration.UiModeQualifier) TouchScreenQualifier(com.android.ide.common.resources.configuration.TouchScreenQualifier) LayoutDirectionQualifier(com.android.ide.common.resources.configuration.LayoutDirectionQualifier) ScreenDimensionQualifier(com.android.ide.common.resources.configuration.ScreenDimensionQualifier) ScreenRatioQualifier(com.android.ide.common.resources.configuration.ScreenRatioQualifier) TextInputMethodQualifier(com.android.ide.common.resources.configuration.TextInputMethodQualifier) DensityQualifier(com.android.ide.common.resources.configuration.DensityQualifier) NetworkCodeQualifier(com.android.ide.common.resources.configuration.NetworkCodeQualifier) LocaleQualifier(com.android.ide.common.resources.configuration.LocaleQualifier) CountryCodeQualifier(com.android.ide.common.resources.configuration.CountryCodeQualifier)

Aggregations

VersionQualifier (com.android.ide.common.resources.configuration.VersionQualifier)13 FolderConfiguration (com.android.ide.common.resources.configuration.FolderConfiguration)12 LocaleQualifier (com.android.ide.common.resources.configuration.LocaleQualifier)6 CountryCodeQualifier (com.android.ide.common.resources.configuration.CountryCodeQualifier)5 DensityQualifier (com.android.ide.common.resources.configuration.DensityQualifier)5 KeyboardStateQualifier (com.android.ide.common.resources.configuration.KeyboardStateQualifier)5 LayoutDirectionQualifier (com.android.ide.common.resources.configuration.LayoutDirectionQualifier)5 NavigationMethodQualifier (com.android.ide.common.resources.configuration.NavigationMethodQualifier)5 NetworkCodeQualifier (com.android.ide.common.resources.configuration.NetworkCodeQualifier)5 NightModeQualifier (com.android.ide.common.resources.configuration.NightModeQualifier)5 ScreenDimensionQualifier (com.android.ide.common.resources.configuration.ScreenDimensionQualifier)5 ScreenOrientationQualifier (com.android.ide.common.resources.configuration.ScreenOrientationQualifier)5 ScreenRatioQualifier (com.android.ide.common.resources.configuration.ScreenRatioQualifier)5 ScreenSizeQualifier (com.android.ide.common.resources.configuration.ScreenSizeQualifier)5 TextInputMethodQualifier (com.android.ide.common.resources.configuration.TextInputMethodQualifier)5 TouchScreenQualifier (com.android.ide.common.resources.configuration.TouchScreenQualifier)5 UiModeQualifier (com.android.ide.common.resources.configuration.UiModeQualifier)5 IAndroidTarget (com.android.sdklib.IAndroidTarget)3 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)3 ResourceFolderType (com.android.resources.ResourceFolderType)2