Search in sources :

Example 81 with Configuration

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

the class ThemeResolverTest method testFrameworkThemeRead.

/*
   * The test SDK only includes some resources. It only includes a few incomplete styles.
   */
public void testFrameworkThemeRead() {
    VirtualFile myLayout = myFixture.copyFileToProject("xmlpull/layout.xml", "res/layout/layout1.xml");
    Configuration configuration = myFacet.getConfigurationManager().getConfiguration(myLayout);
    ThemeResolver themeResolver = new ThemeResolver(configuration);
    // It's system theme and we're not specifying namespace so it will fail.
    assertNull(themeResolver.getTheme("Theme.Holo.Light"));
    ConfiguredThemeEditorStyle theme = themeResolver.getTheme("android:Theme.Holo.Light");
    assertEquals("Theme.Holo.Light", theme.getName());
    // Only framework themes.
    assertEquals(themeResolver.getThemesCount(), themeResolver.getFrameworkThemes().size());
    assertEmpty(themeResolver.getLocalThemes());
    assertNull("Theme resolver shouldn't resolve styles", themeResolver.getTheme("android:TextAppearance"));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Configuration(com.android.tools.idea.configurations.Configuration) ConfiguredThemeEditorStyle(com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle)

Example 82 with Configuration

use of com.android.tools.idea.configurations.Configuration 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 83 with Configuration

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

the class NewStyleDialogTest method testGetStyleParentName.

public void testGetStyleParentName() {
    VirtualFile myFile = myFixture.copyFileToProject("themeEditor/styles_1.xml", "res/values/styles.xml");
    myFixture.copyFileToProject("themeEditor/attrs.xml", "res/values/attrs.xml");
    Configuration configuration = myFacet.getConfigurationManager().getConfiguration(myFile);
    ThemeEditorContext context = new ThemeEditorContext(configuration);
    String styleName = "android:TextAppearance.Medium";
    NewStyleDialog dialog = new NewStyleDialog(false, context, styleName, "textAppearance", null);
    assertEquals(styleName, dialog.getStyleParentName());
    assertEquals("TextAppearance.Medium.textAppearance", dialog.getStyleName());
    // Calling .doCancelAction to dispose dialog object and avoid memory leaks
    dialog.doCancelAction();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Configuration(com.android.tools.idea.configurations.Configuration)

Example 84 with Configuration

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

the class FileChooserActionListener method openDeviceChoiceDialog.

/**
   * Open a dialog asking to choose a device whose dimensions match those of the image
   */
private static void openDeviceChoiceDialog(VirtualFile virtualFile, @NotNull NlProperty fileProperty, @Nullable NlProperty cropProperty) {
    if (virtualFile.exists() && !virtualFile.isDirectory()) {
        try {
            final Image probe = PixelProbe.probe(virtualFile.getInputStream());
            final BufferedImage image = probe.getMergedImage();
            if (image == null) {
                return;
            }
            final NlModel model = fileProperty.getModel();
            final Configuration configuration = model.getConfiguration();
            final Device device = configuration.getDevice();
            if (device == null) {
                return;
            }
            ApplicationManager.getApplication().invokeLater(() -> {
                final DeviceSelectionPopup deviceSelectionPopup = new DeviceSelectionPopup(model.getProject(), configuration, image);
                if (deviceSelectionPopup.showAndGet()) {
                    saveMockupFile(virtualFile, fileProperty, cropProperty);
                }
            });
        } catch (IOException e1) {
            LOGGER.warn("Unable to open this file\n" + e1.getMessage());
        }
    }
}
Also used : Configuration(com.android.tools.idea.configurations.Configuration) Device(com.android.sdklib.devices.Device) NlModel(com.android.tools.idea.uibuilder.model.NlModel) IOException(java.io.IOException) BufferedImage(java.awt.image.BufferedImage) Image(com.android.tools.pixelprobe.Image) BufferedImage(java.awt.image.BufferedImage)

Example 85 with Configuration

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

the class MockupTest method testGetBounds_Normal_Position.

public void testGetBounds_Normal_Position() {
    final NlModel model = createModel1Mockup(MOCKUP_PSD, "0 0 -1 -1 10 10 120 50");
    DesignSurface mockSurface = mock(DesignSurface.class);
    when(mockSurface.getScale()).thenReturn(1.0);
    Configuration configuration = mock(Configuration.class);
    when(configuration.getDensity()).thenReturn(Density.DPI_280);
    ScreenView screenView = mock(ScreenView.class);
    when(screenView.getX()).thenReturn(0);
    when(screenView.getY()).thenReturn(0);
    when(screenView.getSize()).thenReturn(new Dimension(1000, 2000));
    when(screenView.getSize(anyObject())).thenReturn(new Dimension(1000, 2000));
    when(screenView.getScale()).thenReturn(2.);
    when(screenView.getConfiguration()).thenReturn(configuration);
    final Mockup mockup = Mockup.create(model.getComponents().get(0));
    assertNotNull(mockup);
    assertEquals(new Rectangle(10, 10, 120, 50), mockup.getBounds());
    final Rectangle swingBounds = mockup.getScreenBounds(screenView);
    assertEquals(Coordinates.getSwingXDip(screenView, 10), swingBounds.x, 2.);
    assertEquals(Coordinates.getSwingXDip(screenView, 10), swingBounds.y, 2.);
    assertEquals(Coordinates.getSwingDimensionDip(screenView, 110), swingBounds.width, 2.);
    assertEquals(Coordinates.getSwingDimensionDip(screenView, 40), swingBounds.height, 2.);
}
Also used : DesignSurface(com.android.tools.idea.uibuilder.surface.DesignSurface) ScreenView(com.android.tools.idea.uibuilder.surface.ScreenView) Configuration(com.android.tools.idea.configurations.Configuration) NlModel(com.android.tools.idea.uibuilder.model.NlModel)

Aggregations

Configuration (com.android.tools.idea.configurations.Configuration)95 VirtualFile (com.intellij.openapi.vfs.VirtualFile)38 FolderConfiguration (com.android.ide.common.resources.configuration.FolderConfiguration)23 ConfiguredThemeEditorStyle (com.android.tools.idea.editors.theme.datamodels.ConfiguredThemeEditorStyle)21 ResourceResolver (com.android.ide.common.resources.ResourceResolver)16 ConfigurationManager (com.android.tools.idea.configurations.ConfigurationManager)14 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)10 Module (com.intellij.openapi.module.Module)9 ItemResourceValue (com.android.ide.common.rendering.api.ItemResourceValue)8 IAndroidTarget (com.android.sdklib.IAndroidTarget)7 Device (com.android.sdklib.devices.Device)7 State (com.android.sdklib.devices.State)7 NotNull (org.jetbrains.annotations.NotNull)7 ResourceValue (com.android.ide.common.rendering.api.ResourceValue)6 EditedStyleItem (com.android.tools.idea.editors.theme.datamodels.EditedStyleItem)5 CompatibilityRenderTarget (com.android.tools.idea.rendering.multi.CompatibilityRenderTarget)5 NlModel (com.android.tools.idea.uibuilder.model.NlModel)4 DesignSurface (com.android.tools.idea.uibuilder.surface.DesignSurface)4 PsiFile (com.intellij.psi.PsiFile)4 ResourceFolderType (com.android.resources.ResourceFolderType)3