Search in sources :

Example 11 with ModelBuilder

use of com.android.tools.idea.uibuilder.fixtures.ModelBuilder 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)

Example 12 with ModelBuilder

use of com.android.tools.idea.uibuilder.fixtures.ModelBuilder in project android by JetBrains.

the class NlComponentTreeTest method createModelWithAppBar.

@NotNull
private NlModel createModelWithAppBar() {
    ModelBuilder builder = model("coordinator.xml", component(COORDINATOR_LAYOUT).withBounds(0, 0, 1000, 1000).matchParentWidth().matchParentHeight().children(component(APP_BAR_LAYOUT).withBounds(0, 0, 1000, 192).matchParentWidth().height("192dp").children(component(COLLAPSING_TOOLBAR_LAYOUT).withBounds(0, 0, 1000, 192).matchParentHeight().matchParentWidth().children(component(IMAGE_VIEW).withBounds(0, 0, 1000, 192).matchParentWidth().matchParentHeight(), component("android.support.v7.widget.Toolbar").withBounds(0, 0, 1000, 18).height("?attr/actionBarSize").matchParentWidth())), component(CLASS_NESTED_SCROLL_VIEW).withBounds(0, 192, 1000, 808).matchParentWidth().matchParentHeight().withAttribute(AUTO_URI, "layout_behavior", "android.support.design.widget.AppBarLayout$ScrollingViewBehavior").children(component(TEXT_VIEW).withBounds(0, 192, 1000, 808).matchParentWidth().wrapContentHeight().text("@string/stuff"))));
    final NlModel model = builder.build();
    assertEquals(1, model.getComponents().size());
    assertEquals("NlComponent{tag=<android.support.design.widget.CoordinatorLayout>, bounds=[0,0:1000x1000}\n" + "    NlComponent{tag=<android.support.design.widget.AppBarLayout>, bounds=[0,0:1000x192}\n" + "        NlComponent{tag=<android.support.design.widget.CollapsingToolbarLayout>, bounds=[0,0:1000x192}\n" + "            NlComponent{tag=<ImageView>, bounds=[0,0:1000x192}\n" + "            NlComponent{tag=<android.support.v7.widget.Toolbar>, bounds=[0,0:1000x18}\n" + "    NlComponent{tag=<android.support.v4.widget.NestedScrollView>, bounds=[0,192:1000x808}\n" + "        NlComponent{tag=<TextView>, bounds=[0,192:1000x808}", NlTreeDumper.dumpTree(model.getComponents()));
    return model;
}
Also used : ModelBuilder(com.android.tools.idea.uibuilder.fixtures.ModelBuilder) NlModel(com.android.tools.idea.uibuilder.model.NlModel) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with ModelBuilder

use of com.android.tools.idea.uibuilder.fixtures.ModelBuilder in project android by JetBrains.

the class IdAnalyzerTest method testButton1And2.

public void testButton1And2() {
    ModelBuilder modelBuilder = createRelativeLayout();
    NlModel model = modelBuilder.build();
    NlComponent button1 = findById(model, "button1");
    NlComponent button2 = findById(model, "button2");
    NlProperty accessibility = new NlPropertyItem(ImmutableList.of(button1, button2), ANDROID_URI, new AttributeDefinition(ATTR_ACCESSIBILITY_TRAVERSAL_BEFORE));
    IdAnalyzer analyzer = new IdAnalyzer(accessibility);
    List<String> ids = analyzer.findIds();
    assertEquals(ImmutableList.of("button3", "button4", "button5", "group1", "radio_button1", "radio_button2", "radio_button3", "text_view1"), ids);
}
Also used : ModelBuilder(com.android.tools.idea.uibuilder.fixtures.ModelBuilder) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) NlProperty(com.android.tools.idea.uibuilder.property.NlProperty) NlModel(com.android.tools.idea.uibuilder.model.NlModel) AttributeDefinition(org.jetbrains.android.dom.attrs.AttributeDefinition) NlPropertyItem(com.android.tools.idea.uibuilder.property.NlPropertyItem)

Example 14 with ModelBuilder

use of com.android.tools.idea.uibuilder.fixtures.ModelBuilder in project android by JetBrains.

the class IdAnalyzerTest method testRadioGroup.

public void testRadioGroup() {
    ModelBuilder modelBuilder = createRelativeLayout();
    NlModel model = modelBuilder.build();
    NlComponent group = findById(model, "group1");
    NlProperty property = new NlPropertyItem(ImmutableList.of(group), ANDROID_URI, new AttributeDefinition(ATTR_CHECKED_BUTTON));
    IdAnalyzer analyzer = new IdAnalyzer(property);
    List<String> ids = analyzer.findIds();
    assertEquals(ImmutableList.of("radio_button1", "radio_button2", "radio_button3"), ids);
}
Also used : ModelBuilder(com.android.tools.idea.uibuilder.fixtures.ModelBuilder) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) NlProperty(com.android.tools.idea.uibuilder.property.NlProperty) NlModel(com.android.tools.idea.uibuilder.model.NlModel) AttributeDefinition(org.jetbrains.android.dom.attrs.AttributeDefinition) NlPropertyItem(com.android.tools.idea.uibuilder.property.NlPropertyItem)

Example 15 with ModelBuilder

use of com.android.tools.idea.uibuilder.fixtures.ModelBuilder in project android by JetBrains.

the class SceneCreationTest method testDeviceChange.

public void testDeviceChange() {
    ModelBuilder builder = createModel();
    NlModel model = builder.build();
    Configuration config = model.getConfiguration();
    config.setDevice(config.getConfigurationManager().getDeviceById("Nexus 6P"), false);
    Scene scene = Scene.createScene(model, myScreen.getScreen());
    scene.setAnimate(false);
    ComponentDescriptor parent = builder.findByPath(CONSTRAINT_LAYOUT);
    ComponentDescriptor textView = builder.findByPath(CONSTRAINT_LAYOUT, TEXT_VIEW);
    SceneComponent sceneTextView = scene.getRoot().getChildren().get(0);
    float dpiFactor = 560 / 160f;
    assertEquals(pxToDp(100, dpiFactor), sceneTextView.getDrawX());
    assertEquals(pxToDp(200, dpiFactor), sceneTextView.getDrawY());
    assertEquals(pxToDp(100, dpiFactor), sceneTextView.getDrawWidth());
    assertEquals(pxToDp(20, dpiFactor), sceneTextView.getDrawHeight());
    config.setDevice(config.getConfigurationManager().getDeviceById("Nexus S"), false);
    dpiFactor = 240 / 160f;
    assertEquals(pxToDp(100, dpiFactor), sceneTextView.getDrawX());
    assertEquals(pxToDp(200, dpiFactor), sceneTextView.getDrawY());
    assertEquals(pxToDp(100, dpiFactor), sceneTextView.getDrawWidth());
    assertEquals(pxToDp(20, dpiFactor), sceneTextView.getDrawHeight());
}
Also used : ModelBuilder(com.android.tools.idea.uibuilder.fixtures.ModelBuilder) Configuration(com.android.tools.idea.configurations.Configuration) ComponentDescriptor(com.android.tools.idea.uibuilder.fixtures.ComponentDescriptor) NlModel(com.android.tools.idea.uibuilder.model.NlModel)

Aggregations

ModelBuilder (com.android.tools.idea.uibuilder.fixtures.ModelBuilder)29 NlModel (com.android.tools.idea.uibuilder.model.NlModel)19 ComponentDescriptor (com.android.tools.idea.uibuilder.fixtures.ComponentDescriptor)12 NlComponent (com.android.tools.idea.uibuilder.model.NlComponent)6 NotNull (org.jetbrains.annotations.NotNull)6 NlProperty (com.android.tools.idea.uibuilder.property.NlProperty)5 NlPropertyItem (com.android.tools.idea.uibuilder.property.NlPropertyItem)5 AttributeDefinition (org.jetbrains.android.dom.attrs.AttributeDefinition)5 ABSOLUTE_LAYOUT (com.android.SdkConstants.ABSOLUTE_LAYOUT)1 ViewInfo (com.android.ide.common.rendering.api.ViewInfo)1 Configuration (com.android.tools.idea.configurations.Configuration)1 BuildSettings (com.android.tools.idea.gradle.project.BuildSettings)1 BuildMode (com.android.tools.idea.gradle.util.BuildMode)1 TagSnapshot (com.android.tools.idea.rendering.TagSnapshot)1 LayoutTestCase (com.android.tools.idea.uibuilder.LayoutTestCase)1 IdeEventQueue (com.intellij.ide.IdeEventQueue)1 Document (com.intellij.openapi.editor.Document)1 Project (com.intellij.openapi.project.Project)1 Disposer (com.intellij.openapi.util.Disposer)1 PsiDocumentManager (com.intellij.psi.PsiDocumentManager)1