Search in sources :

Example 1 with ABSOLUTE_LAYOUT

use of com.android.SdkConstants.ABSOLUTE_LAYOUT in project android by JetBrains.

the class DesignSurfaceTest method testRenderWhileBuilding.

public void testRenderWhileBuilding() {
    ModelBuilder modelBuilder = model("absolute.xml", component(ABSOLUTE_LAYOUT).withBounds(0, 0, 1000, 1000).matchParentWidth().matchParentHeight().children(component("custom.view.not.present.yet").withBounds(100, 100, 100, 100).matchParentWidth().matchParentHeight()));
    NlModel model = modelBuilder.build();
    // Simulate that we are in the middle of a build
    BuildSettings.getInstance(getProject()).setBuildMode(BuildMode.SOURCE_GEN);
    // Avoid rendering any other components (nav bar and similar) so we do not have dependencies on the Material theme
    model.getConfiguration().setTheme("android:Theme.NoTitleBar.Fullscreen");
    mySurface.setModel(model);
    assertNull(model.getRenderResult());
    mySurface.requestRender();
    assertEquals(1, mySurface.getErrorModel().getIssues().size());
    assertEquals("The project is still building", mySurface.getErrorModel().getIssues().get(0).getSummary());
    // Now finish the build, and try to build again. The "project is still building" should be gone.
    BuildSettings.getInstance(getProject()).setBuildMode(null);
    model = modelBuilder.build();
    model.getConfiguration().setTheme("android:Theme.NoTitleBar.Fullscreen");
    mySurface.setModel(model);
    mySurface.requestRender();
    // Because there is a missing view, some other extra errors will be generated about missing styles. This is caused by
    // MockView (which is based on TextView) that depends on some Material styles.
    // We only care about the missing class error.
    assertTrue(mySurface.getErrorModel().getIssues().stream().anyMatch(issue -> issue.getSummary().startsWith("Missing classes")));
    assertFalse(mySurface.getErrorModel().getIssues().stream().anyMatch(issue -> issue.getSummary().startsWith("The project is still building")));
}
Also used : IdeEventQueue(com.intellij.ide.IdeEventQueue) ABSOLUTE_LAYOUT(com.android.SdkConstants.ABSOLUTE_LAYOUT) ModelBuilder(com.android.tools.idea.uibuilder.fixtures.ModelBuilder) BuildMode(com.android.tools.idea.gradle.util.BuildMode) Disposer(com.intellij.openapi.util.Disposer) NlModel(com.android.tools.idea.uibuilder.model.NlModel) BuildSettings(com.android.tools.idea.gradle.project.BuildSettings) LayoutTestCase(com.android.tools.idea.uibuilder.LayoutTestCase) ModelBuilder(com.android.tools.idea.uibuilder.fixtures.ModelBuilder) NlModel(com.android.tools.idea.uibuilder.model.NlModel)

Aggregations

ABSOLUTE_LAYOUT (com.android.SdkConstants.ABSOLUTE_LAYOUT)1 BuildSettings (com.android.tools.idea.gradle.project.BuildSettings)1 BuildMode (com.android.tools.idea.gradle.util.BuildMode)1 LayoutTestCase (com.android.tools.idea.uibuilder.LayoutTestCase)1 ModelBuilder (com.android.tools.idea.uibuilder.fixtures.ModelBuilder)1 NlModel (com.android.tools.idea.uibuilder.model.NlModel)1 IdeEventQueue (com.intellij.ide.IdeEventQueue)1 Disposer (com.intellij.openapi.util.Disposer)1