Search in sources :

Example 51 with IAndroidTarget

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);
}
Also used : AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) IAndroidTarget(com.android.sdklib.IAndroidTarget)

Example 52 with IAndroidTarget

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?
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) Device(com.android.sdklib.devices.Device) State(com.android.sdklib.devices.State) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) IAndroidTarget(com.android.sdklib.IAndroidTarget) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 53 with IAndroidTarget

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);
}
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 54 with IAndroidTarget

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));
}
Also used : MockPlatformTarget(com.android.sdklib.internal.androidTarget.MockPlatformTarget) IAndroidTarget(com.android.sdklib.IAndroidTarget) AndroidVersion(com.android.sdklib.AndroidVersion)

Example 55 with IAndroidTarget

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;
}
Also used : AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) IAndroidTarget(com.android.sdklib.IAndroidTarget) Module(com.intellij.openapi.module.Module) AndroidVersion(com.android.sdklib.AndroidVersion)

Aggregations

IAndroidTarget (com.android.sdklib.IAndroidTarget)105 Nullable (org.jetbrains.annotations.Nullable)24 VirtualFile (com.intellij.openapi.vfs.VirtualFile)19 Module (com.intellij.openapi.module.Module)17 NotNull (org.jetbrains.annotations.NotNull)16 AndroidSdkData (org.jetbrains.android.sdk.AndroidSdkData)15 Sdk (com.intellij.openapi.projectRoots.Sdk)14 File (java.io.File)13 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)13 AndroidPlatform (org.jetbrains.android.sdk.AndroidPlatform)13 AndroidVersion (com.android.sdklib.AndroidVersion)11 Device (com.android.sdklib.devices.Device)11 FolderConfiguration (com.android.ide.common.resources.configuration.FolderConfiguration)9 State (com.android.sdklib.devices.State)8 AndroidSdkAdditionalData (org.jetbrains.android.sdk.AndroidSdkAdditionalData)8 AndroidTargetData (org.jetbrains.android.sdk.AndroidTargetData)8 Configuration (com.android.tools.idea.configurations.Configuration)7 CompatibilityRenderTarget (com.android.tools.idea.rendering.multi.CompatibilityRenderTarget)7 CompilerMessage (org.jetbrains.jps.incremental.messages.CompilerMessage)7 ConfigurationManager (com.android.tools.idea.configurations.ConfigurationManager)6