use of com.android.sdklib.IAndroidTarget in project android by JetBrains.
the class AndroidFacetImporterBase method isAppropriateSdk.
private boolean isAppropriateSdk(@NotNull Sdk sdk, MavenProject mavenProject) {
if (!AndroidSdks.getInstance().isAndroidSdk(sdk)) {
return false;
}
final String platformId = getPlatformFromConfig(mavenProject);
final AndroidPlatform androidPlatform = AndroidPlatform.getInstance(sdk);
if (androidPlatform == null) {
return false;
}
final IAndroidTarget target = androidPlatform.getTarget();
return (platformId == null || AndroidSdkUtils.targetHasId(target, platformId)) && AndroidSdkUtils.checkSdkRoots(sdk, target, true);
}
use of com.android.sdklib.IAndroidTarget in project android by JetBrains.
the class NestedConfigurationTest method test.
public void test() throws Exception {
VirtualFile file = myFixture.copyFileToProject(TEST_FILE, "res/layout/layout1.xml");
final AndroidFacet facet = AndroidFacet.getInstance(myModule);
assertNotNull(facet);
ConfigurationManager manager = facet.getConfigurationManager();
assertNotNull(manager);
assertSame(manager, facet.getConfigurationManager());
Configuration parent = Configuration.create(manager, file, new FolderConfiguration());
assertNotNull(parent);
parent.startBulkEditing();
parent.setDisplayName("myconfig");
parent.setTheme("@style/Theme1");
parent.setNightMode(NightMode.NIGHT);
parent.setActivity("tes.tpkg.MyActivity1");
parent.setUiMode(UiMode.TELEVISION);
IAndroidTarget target = parent.getConfigurationManager().getTarget();
Device device = parent.getConfigurationManager().getDefaultDevice();
State deviceState = device != null ? device.getState("Portrait") : null;
if (target != null) {
parent.setTarget(target);
}
if (device != null) {
parent.setDevice(device, false);
assertNotNull(deviceState);
parent.setDeviceState(deviceState);
}
parent.setLocale(Locale.create("en-rUS"));
parent.finishBulkEditing();
NestedConfiguration configuration = NestedConfiguration.create(parent);
// Inherit locale
assertFalse(configuration.isOverridingLocale());
parent.setLocale(Locale.create("en-rUS"));
assertEquals(Locale.create("en-rUS"), configuration.getLocale());
parent.setLocale(Locale.create("de"));
assertEquals(Locale.create("de"), configuration.getLocale());
// Override locale
configuration.setOverrideLocale(true);
assertTrue(configuration.isOverridingLocale());
configuration.setLocale(Locale.create("no"));
assertEquals(Locale.create("no"), configuration.getLocale());
parent.setLocale(Locale.create("es"));
assertEquals(Locale.create("no"), configuration.getLocale());
// Inherit UI mode
assertFalse(configuration.isOverridingUiMode());
parent.setUiMode(UiMode.DESK);
assertSame(UiMode.DESK, configuration.getUiMode());
parent.setUiMode(UiMode.APPLIANCE);
assertSame(UiMode.APPLIANCE, configuration.getUiMode());
// Override UI mode
configuration.setOverrideUiMode(true);
assertTrue(configuration.isOverridingUiMode());
configuration.setUiMode(UiMode.CAR);
assertSame(UiMode.CAR, configuration.getUiMode());
parent.setUiMode(UiMode.DESK);
assertSame(UiMode.CAR, configuration.getUiMode());
// Inherit orientation
assertNotNull(device);
State portrait = device.getState("Portrait");
State landscape = device.getState("Landscape");
assertNotNull(portrait);
assertNotNull(landscape);
assertFalse(configuration.isOverridingDeviceState());
assertEquals(ScreenOrientation.PORTRAIT, configuration.getFullConfig().getScreenOrientationQualifier().getValue());
parent.setDeviceState(landscape);
assertEquals(ScreenOrientation.LANDSCAPE, configuration.getFullConfig().getScreenOrientationQualifier().getValue());
assertEquals(landscape, configuration.getDeviceState());
parent.setDeviceState(portrait);
assertEquals(portrait, configuration.getDeviceState());
// Override orientation
configuration.setOverrideDeviceState(true);
assertTrue(configuration.isOverridingDeviceState());
configuration.setDeviceState(landscape);
assertEquals(landscape, configuration.getDeviceState());
parent.setDeviceState(landscape);
parent.setDeviceState(portrait);
assertEquals(landscape, configuration.getDeviceState());
// TODO: Inherit device -- with overridden state
// TODO: Test listener; I should NOT fire when a parent changes an attribute I don't
// care about!!
// Also test that calling the setters are firing events, clear resources, etc
// In order for this to work, I would need to have listeners attach and detach... How
// can I do this?
}
use of com.android.sdklib.IAndroidTarget 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.sdklib.IAndroidTarget in project android by JetBrains.
the class AndroidSdkUtilsTest method testGetTargetLabel.
public void testGetTargetLabel() throws Exception {
IAndroidTarget platformTarget = new MockPlatformTarget(18, 2);
assertEquals("API 18: Android 4.3 (Jelly Bean)", AndroidSdkUtils.getTargetLabel(platformTarget));
IAndroidTarget unknownTarget = new MockPlatformTarget(-1, 1);
assertEquals("API -1", AndroidSdkUtils.getTargetLabel(unknownTarget));
IAndroidTarget anotherUnknownTarget = new MockPlatformTarget(100, 1);
assertEquals("API 100", AndroidSdkUtils.getTargetLabel(anotherUnknownTarget));
IAndroidTarget platformPreviewTarget = new MockPlatformTarget(100, 1) {
@NonNull
@Override
public AndroidVersion getVersion() {
return new AndroidVersion(100, "Z");
}
};
assertEquals("API 100+: platform r100", AndroidSdkUtils.getTargetLabel(platformPreviewTarget));
}
use of com.android.sdklib.IAndroidTarget in project android by JetBrains.
the class LayoutPullParserFactory method prefCapableTargetInstalled.
/**
* Returns if a target capable of rendering preferences file is found.
*/
private static boolean prefCapableTargetInstalled(@NotNull PsiFile file) {
Module module = ModuleUtilCore.findModuleForPsiElement(file);
if (module != null) {
AndroidPlatform platform = AndroidPlatform.getInstance(module);
if (platform != null) {
IAndroidTarget[] targets = platform.getSdkData().getTargets();
for (int i = targets.length - 1; i >= 0; i--) {
IAndroidTarget target = targets[i];
if (target.isPlatform()) {
AndroidVersion version = target.getVersion();
int featureLevel = version.getFeatureLevel();
if (featureLevel >= PREFERENCES_MIN_API) {
return true;
}
}
}
}
}
return false;
}
Aggregations