Search in sources :

Example 91 with Configuration

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

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

the class GraphicsLayoutRendererTest method testInflateAndRender.

public void testInflateAndRender() throws InitializationException, ParserConfigurationException, IOException, SAXException {
    VirtualFile layout = myFixture.copyFileToProject("themeEditor/theme_preview_layout.xml", "res/layout/theme_preview_layout.xml");
    Configuration configuration = myFacet.getConfigurationManager().getConfiguration(layout);
    DomPullParser parser = new DomPullParser(DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(layout.getInputStream()).getDocumentElement());
    AndroidFacet facet = AndroidFacet.getInstance(configuration.getModule());
    assertNotNull(facet);
    AndroidPlatform platform = AndroidPlatform.getInstance(myModule);
    assertNotNull(platform);
    //noinspection UndesirableClassUsage
    BufferedImage image = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
    GraphicsLayoutRenderer renderer = GraphicsLayoutRenderer.create(facet, platform, myModule.getProject(), configuration, parser, Color.BLACK, SessionParams.RenderingMode.V_SCROLL, false);
    // The first render triggers a render (to a NOP Graphics object) so we expect sizes to have been initialized.
    Dimension initialSize = renderer.getPreferredSize();
    assertNotEquals("Expected layout dimensions after create", EMPTY_DIMENSION, initialSize);
    assertTrue(renderer.render((Graphics2D) image.getGraphics()));
    // We haven't changed the layout so, after the render, we expect the same dimensions.
    assertEquals(initialSize, renderer.getPreferredSize());
    renderer.setSize(new Dimension(50, 50));
    assertTrue(renderer.render((Graphics2D) image.getGraphics()));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Configuration(com.android.tools.idea.configurations.Configuration) DomPullParser(com.android.tools.idea.rendering.DomPullParser) AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) BufferedImage(java.awt.image.BufferedImage)

Example 93 with Configuration

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

the class NlPropertiesTest method testSrcCompatIncludedWithRelativeContextName.

public void testSrcCompatIncludedWithRelativeContextName() {
    Configuration configuration = myModel.getConfiguration();
    configuration.setActivity(".MyActivity");
    when(myDependencyManager.dependsOn(myModule, APPCOMPAT_LIB_ARTIFACT)).thenReturn(true);
    addAppCompatActivity();
    addMyActivityAsAppCompatActivity();
    Table<String, String, NlPropertyItem> properties = NlProperties.getInstance().getProperties(myFacet, ImmutableList.of(myImageView), myDependencyManager);
    assertPresent("ImageView", properties, ANDROID_URI, ATTR_SRC);
    assertPresent("ImageView", properties, AUTO_URI, ATTR_SRC_COMPAT);
}
Also used : Configuration(com.android.tools.idea.configurations.Configuration)

Example 94 with Configuration

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

the class NlPalettePanelTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    Configuration configuration = mock(Configuration.class);
    when(configuration.getModule()).thenReturn(myModule);
    DesignSurface surface = mock(DesignSurface.class);
    when(surface.getLayoutType()).thenReturn(NlLayoutType.LAYOUT);
    when(surface.getConfiguration()).thenReturn(configuration);
    myCopyPasteManager = mock(CopyPasteManager.class);
    myPanel = new NlPalettePanel(getProject(), surface, myCopyPasteManager);
}
Also used : DesignSurface(com.android.tools.idea.uibuilder.surface.DesignSurface) Configuration(com.android.tools.idea.configurations.Configuration) CopyPasteManager(com.intellij.openapi.ide.CopyPasteManager)

Example 95 with Configuration

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

the class NlPreviewImagePanelTest method testConfigurationChangesInvalidatesUI.

public void testConfigurationChangesInvalidatesUI() {
    Configuration configuration = mySurface.getConfiguration();
    configuration.updated(CFG_DEVICE);
    verify(myRepaintManager).addDirtyRegion(myPanel, 0, 0, WIDTH, HEIGHT);
}
Also used : Configuration(com.android.tools.idea.configurations.Configuration)

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