Search in sources :

Example 1 with DomPullParser

use of com.android.tools.idea.rendering.DomPullParser 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)

Aggregations

Configuration (com.android.tools.idea.configurations.Configuration)1 DomPullParser (com.android.tools.idea.rendering.DomPullParser)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 BufferedImage (java.awt.image.BufferedImage)1 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)1 AndroidPlatform (org.jetbrains.android.sdk.AndroidPlatform)1