Search in sources :

Example 6 with VersionQualifier

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

the class VariantItemListener method itemStateChanged.

@Override
public void itemStateChanged(ItemEvent e) {
    if (e.getStateChange() != ItemEvent.SELECTED) {
        return;
    }
    VariantsComboItem item = (VariantsComboItem) e.getItem();
    Configuration oldConfiguration = myContext.getConfiguration();
    ConfigurationManager manager = oldConfiguration.getConfigurationManager();
    Configuration newConfiguration = Configuration.create(manager, null, null, item.getRestrictedConfiguration());
    // Target and locale are global so we need to set them in the configuration manager when updated
    VersionQualifier newVersionQualifier = item.getRestrictedConfiguration().getVersionQualifier();
    if (newVersionQualifier != null) {
        IAndroidTarget realTarget = manager.getHighestApiTarget() != null ? manager.getHighestApiTarget() : manager.getTarget();
        assert realTarget != null;
        manager.setTarget(new CompatibilityRenderTarget(realTarget, newVersionQualifier.getVersion(), null));
    } else {
        manager.setTarget(null);
    }
    LocaleQualifier newLocaleQualifier = item.getRestrictedConfiguration().getLocaleQualifier();
    manager.setLocale(newLocaleQualifier != null ? Locale.create(newLocaleQualifier) : Locale.ANY);
    oldConfiguration.setDevice(null, false);
    Configuration.copyCompatible(newConfiguration, oldConfiguration);
    oldConfiguration.updated(ConfigurationListener.MASK_FOLDERCONFIG);
}
Also used : Configuration(com.android.tools.idea.configurations.Configuration) VersionQualifier(com.android.ide.common.resources.configuration.VersionQualifier) CompatibilityRenderTarget(com.android.tools.idea.rendering.multi.CompatibilityRenderTarget) IAndroidTarget(com.android.sdklib.IAndroidTarget) ConfigurationManager(com.android.tools.idea.configurations.ConfigurationManager) LocaleQualifier(com.android.ide.common.resources.configuration.LocaleQualifier)

Example 7 with VersionQualifier

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

the class AndroidLintNewApiInspection method getApiDetectorFixes.

public static AndroidLintQuickFix[] getApiDetectorFixes(@NotNull Issue issue, @NotNull PsiElement startElement, @SuppressWarnings("UnusedParameters") @NotNull PsiElement endElement, @NotNull String message) {
    // TODO: Return one for each parent context (declaration, method, class, outer class(es)
    int api = ApiDetector.getRequiredVersion(issue, message, RAW);
    if (api != -1) {
        List<AndroidLintQuickFix> list = Lists.newArrayList();
        PsiFile file = startElement.getContainingFile();
        boolean isXml = false;
        if (file instanceof XmlFile) {
            isXml = true;
            ResourceFolderType folderType = ResourceHelper.getFolderType(file);
            if (folderType != null) {
                FolderConfiguration config = ResourceHelper.getFolderConfiguration(file);
                if (config != null) {
                    config.setVersionQualifier(new VersionQualifier(api));
                    String folder = config.getFolderName(folderType);
                    list.add(OverrideResourceAction.createFix(folder));
                }
            }
        }
        list.add(new AddTargetVersionCheckQuickFix(api));
        list.add(new AddTargetApiQuickFix(api, false, startElement));
        ApplicationManager.getApplication().assertReadAccessAllowed();
        Project project = startElement.getProject();
        if (!isXml && JavaPsiFacade.getInstance(project).findClass(REQUIRES_API_ANNOTATION, GlobalSearchScope.allScope(project)) != null) {
            list.add(new AddTargetApiQuickFix(api, true, startElement));
        }
        return list.toArray(new AndroidLintQuickFix[list.size()]);
    }
    return AndroidLintQuickFix.EMPTY_ARRAY;
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) VersionQualifier(com.android.ide.common.resources.configuration.VersionQualifier) AndroidLintQuickFix(org.jetbrains.android.inspections.lint.AndroidLintQuickFix) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) Project(com.intellij.openapi.project.Project) ResourceFolderType(com.android.resources.ResourceFolderType) PsiFile(com.intellij.psi.PsiFile)

Example 8 with VersionQualifier

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

the class ConfigurationTest method testTargetSpecificFolder.

public void testTargetSpecificFolder() throws Exception {
    final AndroidFacet facet = AndroidFacet.getInstance(myModule);
    assertNotNull(facet);
    ConfigurationManager manager = facet.getConfigurationManager();
    assertNotNull(manager);
    assertSame(manager, facet.getConfigurationManager());
    for (IAndroidTarget target : manager.getTargets()) {
        if (ConfigurationManager.isLayoutLibTarget(target)) {
            manager.setTarget(target);
            break;
        }
    }
    FolderConfiguration folderConfig = new FolderConfiguration();
    folderConfig.setVersionQualifier(new VersionQualifier(11));
    Configuration configuration = Configuration.create(manager, null, folderConfig);
    assertNotNull(configuration);
    IAndroidTarget target = configuration.getTarget();
    assertNotNull(target);
    assertTrue(target.getVersion().getFeatureLevel() >= 11);
}
Also used : VersionQualifier(com.android.ide.common.resources.configuration.VersionQualifier) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) IAndroidTarget(com.android.sdklib.IAndroidTarget) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 9 with VersionQualifier

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

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)

Example 10 with VersionQualifier

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

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