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);
}
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;
}
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);
}
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;
}
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;
}
Aggregations