Search in sources :

Example 16 with ConfigurationManager

use of com.android.tools.idea.configurations.ConfigurationManager in project android by JetBrains.

the class RenderErrorContributorTest method getRenderOutput.

private List<RenderErrorModel.Issue> getRenderOutput(@NotNull VirtualFile file, @Nullable LogOperation logOperation) {
    assertNotNull(file);
    AndroidFacet facet = AndroidFacet.getInstance(myModule);
    PsiFile psiFile = PsiManager.getInstance(getProject()).findFile(file);
    assertNotNull(psiFile);
    assertNotNull(facet);
    ConfigurationManager configurationManager = facet.getConfigurationManager();
    assertNotNull(configurationManager);
    IAndroidTarget target = getTestTarget(configurationManager);
    assertNotNull(target);
    configurationManager.setTarget(target);
    Configuration configuration = configurationManager.getConfiguration(file);
    assertSame(target, configuration.getRealTarget());
    if (!LayoutLibraryLoader.USE_SDK_LAYOUTLIB) {
        // TODO: Remove this after http://b.android.com/203392 is released
        // If we are using the embedded layoutlib, use a recent theme to avoid missing styles errors.
        configuration.setTheme("android:Theme.Material");
    }
    RenderService renderService = RenderService.get(facet);
    RenderLogger logger = renderService.createLogger();
    final RenderTask task = renderService.createTask(psiFile, configuration, logger, null);
    assertNotNull(task);
    task.disableSecurityManager();
    RenderResult render = RenderTestBase.renderOnSeparateThread(task);
    assertNotNull(render);
    if (logOperation != null) {
        logOperation.addErrors(logger, render);
    }
    return RenderErrorModelFactory.createErrorModel(render, null).getIssues().stream().sorted().collect(Collectors.toList());
}
Also used : Configuration(com.android.tools.idea.configurations.Configuration) PsiFile(com.intellij.psi.PsiFile) IAndroidTarget(com.android.sdklib.IAndroidTarget) ConfigurationManager(com.android.tools.idea.configurations.ConfigurationManager) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 17 with ConfigurationManager

use of com.android.tools.idea.configurations.ConfigurationManager in project android by JetBrains.

the class IncludeReferenceTest method testGetSet.

public void testGetSet() {
    VirtualFile included = myFixture.copyFileToProject("designer/included.xml", "res/layout/included.xml");
    assertNotNull(included);
    VirtualFile includer = myFixture.copyFileToProject("designer/included.xml", "res/layout/includer.xml");
    assertNotNull(includer);
    XmlFile psiFile = (XmlFile) PsiManager.getInstance(getProject()).findFile(included);
    assertNotNull(psiFile);
    assertEquals("@layout/includer", IncludeReference.getIncludingLayout(psiFile));
    ConfigurationManager manager = myFacet.getConfigurationManager();
    Configuration configuration = manager.getConfiguration(included);
    ResourceResolver resourceResolver = configuration.getResourceResolver();
    assertNotNull(resourceResolver);
    IncludeReference reference = IncludeReference.get(myModule, psiFile, resourceResolver);
    assertEquals("includer.xml", reference.getFromDisplayName());
    assertEquals("includer", reference.getFromResourceName());
    assertEquals("@layout/includer", reference.getFromResourceUrl());
    assertEquals(reference.getFromFile(), includer);
    assertEquals(reference.getToFile(), included);
    IncludeReference.setIncludingLayout(getProject(), psiFile, null);
    assertEquals(IncludeReference.NONE, IncludeReference.get(myModule, psiFile, resourceResolver));
    VirtualFile other = myFixture.copyFileToProject("xmlpull/designtime.xml", "res/layout-land/designtime.xml");
    assertNotNull(other);
    IncludeReference.setIncludingLayout(getProject(), psiFile, "@layout/designtime");
    assertEquals("@layout/designtime", IncludeReference.getIncludingLayout(psiFile));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) XmlFile(com.intellij.psi.xml.XmlFile) Configuration(com.android.tools.idea.configurations.Configuration) ResourceResolver(com.android.ide.common.resources.ResourceResolver) ConfigurationManager(com.android.tools.idea.configurations.ConfigurationManager)

Example 18 with ConfigurationManager

use of com.android.tools.idea.configurations.ConfigurationManager in project android by JetBrains.

the class ThemeResolverTest method testConfigurationUpdate.

/** Check that, after a configuration update, the resolver updates the list of themes */
public void testConfigurationUpdate() {
    myFixture.copyFileToProject("themeEditor/attributeResolution/styles-v17.xml", "res/values-v17/styles.xml");
    myFixture.copyFileToProject("themeEditor/attributeResolution/styles-v19.xml", "res/values-v19/styles.xml");
    VirtualFile file = myFixture.copyFileToProject("themeEditor/attributeResolution/styles-v20.xml", "res/values-v20/styles.xml");
    ConfigurationManager configurationManager = myFacet.getConfigurationManager();
    Configuration configuration = configurationManager.getConfiguration(file);
    ThemeEditorContext context = new ThemeEditorContext(configuration);
    ThemeResolver resolver = context.getThemeResolver();
    assertNotNull(resolver.getTheme("V20OnlyTheme"));
    assertNotNull(resolver.getTheme("V19OnlyTheme"));
    assertNotNull(resolver.getTheme("V17OnlyTheme"));
    // Set API level 17 and check that only the V17 theme can be resolved
    //noinspection ConstantConditions
    configuration.setTarget(new CompatibilityRenderTarget(configurationManager.getHighestApiTarget(), 17, null));
    context = new ThemeEditorContext(configuration);
    resolver = context.getThemeResolver();
    assertNull(resolver.getTheme("V20OnlyTheme"));
    assertNull(resolver.getTheme("V19OnlyTheme"));
    assertNotNull(resolver.getTheme("V17OnlyTheme"));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Configuration(com.android.tools.idea.configurations.Configuration) CompatibilityRenderTarget(com.android.tools.idea.rendering.multi.CompatibilityRenderTarget) ConfigurationManager(com.android.tools.idea.configurations.ConfigurationManager)

Example 19 with ConfigurationManager

use of com.android.tools.idea.configurations.ConfigurationManager in project android by JetBrains.

the class DeviceSelectionPopup method initDeviceList.

/**
   * Fill the device combo box by looking first for device matching the same size
   * as the image. If none are found, try to find device with the same aspect ratio.
   * If none are found again, tries to find avd matching size or ratio.
   * Otherwise, use the current selected device as the only item in the combo box
   *
   * @param configuration
   */
private void initDeviceList(Configuration configuration) {
    myNoMatchingDevice = false;
    if (!myMatchingDevices.isEmpty()) {
        myMatchingDevices.clear();
    }
    if (myDevicesComboBox.getItemCount() > 0) {
        myDevicesComboBox.removeAllItems();
    }
    int lastNexusIndex = 0;
    int lastMatchIndex = 0;
    int lastNexusRatioIndex = 0;
    ConfigurationManager configurationManager = configuration.getConfigurationManager();
    List<Device> deviceList = configurationManager.getDevices();
    final double imageRatio = myImageSize.width / (double) myImageSize.height;
    myScreenOrientation = myImageSize.width <= myImageSize.height ? ScreenOrientation.PORTRAIT : ScreenOrientation.LANDSCAPE;
    for (Device device : deviceList) {
        final Dimension screenSize = device.getScreenSize(myScreenOrientation);
        if (screenSize == null) {
            continue;
        }
        if (myImageSize.equals(screenSize)) {
            if (isNexus(device)) {
                myMatchingDevices.add(lastNexusIndex++, device);
            } else if (isGeneric(device)) {
                myMatchingDevices.add(lastNexusIndex + lastMatchIndex++, device);
            }
        } else {
            if (ratioAlmostEqual(imageRatio, screenSize)) {
                if (isNexus(device)) {
                    myMatchingDevices.add(lastNexusIndex + lastMatchIndex + lastNexusRatioIndex++, device);
                } else {
                    myMatchingDevices.add(device);
                }
            }
        }
    }
    // Try to find on in the Avd
    if (myMatchingDevices.isEmpty()) {
        if (findMatchingAvd(configurationManager, imageRatio)) {
            return;
        }
        // If there is still no device matching the size or ratio of the mockup,
        // use the current selected device as best matching device.
        myMatchingDevices.add(configuration.getDevice());
        myNoMatchingDevice = true;
    }
    for (Device device : myMatchingDevices) {
        String deviceLabel;
        if (isNexus(device)) {
            deviceLabel = getNexusLabel(device);
        } else if (isGeneric(device)) {
            deviceLabel = getGenericLabel(device);
        } else {
            deviceLabel = device.getId();
        }
        if (device == myConfiguration.getDevice()) {
            // Set a special label for the current device
            // and display it on top if it matches the image ratio
            deviceLabel = String.format("* %s (current)", deviceLabel);
        }
        myDevicesComboBox.addItem(deviceLabel);
    }
    mySelectedDevice = myMatchingDevices.get(0);
    myDevicesComboBox.setSelectedIndex(0);
    updateDevicePreview();
}
Also used : Device(com.android.sdklib.devices.Device) ConfigurationManager(com.android.tools.idea.configurations.ConfigurationManager)

Example 20 with ConfigurationManager

use of com.android.tools.idea.configurations.ConfigurationManager in project android by JetBrains.

the class ConfiguredThemeEditorStyleTest method testThemeOverride.

/**
   * Test that the main theme will override the one from the library
   */
public void testThemeOverride() {
    VirtualFile virtualFile = myFixture.copyFileToProject("themeEditor/themeEditorStyle/styles.xml", "res/values/styles.xml");
    myFixture.copyFileToProject("themeEditor/themeEditorStyle/styles_1.xml", "additionalModules/moduleA/res/values/styles.xml");
    ConfigurationManager configurationManager = myFacet.getConfigurationManager();
    Configuration configuration = configurationManager.getConfiguration(virtualFile);
    ThemeResolver resolver = new ThemeResolver(configuration);
    ConfiguredThemeEditorStyle theme = resolver.getTheme("AppTheme");
    assertNotNull(theme);
    assertEquals(1, theme.getParentNames().size());
    // We expect only the main app parent to be available
    assertEquals("ATheme", theme.getParentNames().iterator().next().getElement());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) Configuration(com.android.tools.idea.configurations.Configuration) ConfigurationManager(com.android.tools.idea.configurations.ConfigurationManager) ConfiguredThemeEditorStyle(com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle)

Aggregations

ConfigurationManager (com.android.tools.idea.configurations.ConfigurationManager)20 Configuration (com.android.tools.idea.configurations.Configuration)14 VirtualFile (com.intellij.openapi.vfs.VirtualFile)14 FolderConfiguration (com.android.ide.common.resources.configuration.FolderConfiguration)9 ConfiguredThemeEditorStyle (com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle)8 IAndroidTarget (com.android.sdklib.IAndroidTarget)6 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)5 CompatibilityRenderTarget (com.android.tools.idea.rendering.multi.CompatibilityRenderTarget)4 NotNull (org.jetbrains.annotations.NotNull)4 Module (com.intellij.openapi.module.Module)3 ItemResourceValue (com.android.ide.common.rendering.api.ItemResourceValue)2 ResourceResolver (com.android.ide.common.resources.ResourceResolver)2 VersionQualifier (com.android.ide.common.resources.configuration.VersionQualifier)2 ResourceValue (com.android.ide.common.rendering.api.ResourceValue)1 ResourceItem (com.android.ide.common.res2.ResourceItem)1 ResourceItem (com.android.ide.common.resources.ResourceItem)1 ResourceRepository (com.android.ide.common.resources.ResourceRepository)1 Configurable (com.android.ide.common.resources.configuration.Configurable)1 LocaleQualifier (com.android.ide.common.resources.configuration.LocaleQualifier)1 Device (com.android.sdklib.devices.Device)1