use of com.android.tools.idea.uibuilder.model.NlModel 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.model.NlModel in project android by JetBrains.
the class NlComponentTreeTest method testTreeStructureOfAppBar.
public void testTreeStructureOfAppBar() {
NlModel model = createModelWithAppBar();
when(myScreen.getModel()).thenReturn(model);
when(myScreen.getSelectionModel()).thenReturn(model.getSelectionModel());
myTree.setDesignSurface(mySurface);
UIUtil.dispatchAllInvocationEvents();
assertEquals("<android.support.design.widget.CoordinatorLayout> [expanded]\n" + " <android.support.design.widget.AppBarLayout> [expanded]\n" + " <android.support.design.widget.CollapsingToolbarLayout> [expanded]\n" + " <ImageView>\n" + " <android.support.v7.widget.Toolbar>\n" + " <android.support.v4.widget.NestedScrollView> [expanded]\n" + " <TextView>\n", toTree());
}
use of com.android.tools.idea.uibuilder.model.NlModel in project android by JetBrains.
the class WidgetConstraintPanel method setAttribute.
private void setAttribute(String nameSpace, String attribute, String value) {
if (mConfiguringUI) {
return;
}
NlModel model = mComponent.getModel();
AttributesTransaction transaction = mComponent.startAttributeTransaction();
transaction.setAttribute(nameSpace, attribute, value);
transaction.apply();
model.requestLayout(false);
myTimer.setRepeats(false);
Project project = model.getProject();
XmlFile file = model.getFile();
String label = "Change Widget";
myWriteAction = new WriteCommandAction(project, label, file) {
@Override
protected void run(@NotNull Result result) throws Throwable {
AttributesTransaction transaction = mComponent.startAttributeTransaction();
transaction.setAttribute(nameSpace, attribute, value);
transaction.commit();
}
};
myTimer.restart();
}
use of com.android.tools.idea.uibuilder.model.NlModel in project android by JetBrains.
the class ConstraintComponentUtilities method clearAttributes.
public static void clearAttributes(SceneComponent component) {
AttributesTransaction transaction = component.getNlComponent().startAttributeTransaction();
clearAllAttributes(component, transaction);
transaction.apply();
NlModel nlModel = component.getNlComponent().getModel();
Project project = nlModel.getProject();
XmlFile file = nlModel.getFile();
String label = "Cleared all constraints";
WriteCommandAction action = new WriteCommandAction(project, label, file) {
@Override
protected void run(@NotNull Result result) throws Throwable {
transaction.commit();
}
};
action.execute();
}
use of com.android.tools.idea.uibuilder.model.NlModel in project android by JetBrains.
the class ConstraintComponentUtilities method updateOnDelete.
public static void updateOnDelete(NlComponent component, String targetId) {
AttributesTransaction transaction = null;
transaction = updateOnDelete(component, ourLeftAttributes, transaction, targetId);
transaction = updateOnDelete(component, ourTopAttributes, transaction, targetId);
transaction = updateOnDelete(component, ourRightAttributes, transaction, targetId);
transaction = updateOnDelete(component, ourBottomAttributes, transaction, targetId);
transaction = updateOnDelete(component, ourBaselineAttributes, transaction, targetId);
if (transaction != null) {
transaction.apply();
NlModel nlModel = component.getModel();
Project project = nlModel.getProject();
XmlFile file = nlModel.getFile();
String label = "Remove constraints pointing to a deleted component";
AttributesTransaction finalTransaction = transaction;
WriteCommandAction action = new WriteCommandAction(project, label, file) {
@Override
protected void run(@NotNull Result result) throws Throwable {
finalTransaction.commit();
}
};
action.execute();
}
}
Aggregations