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")));
}
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;
}
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);
}
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);
}
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());
}
Aggregations