use of com.android.tools.idea.uibuilder.model.NlModel in project android by JetBrains.
the class ConstraintTarget method cycleChainStyle.
protected void cycleChainStyle(SceneComponent chainHeadComponent, String orientationStyle) {
NlComponent chainHead = chainHeadComponent.getNlComponent();
String chainStyle = chainHead.getLiveAttribute(SdkConstants.SHERPA_URI, orientationStyle);
if (chainStyle != null) {
if (chainStyle.equalsIgnoreCase(SdkConstants.ATTR_LAYOUT_CHAIN_SPREAD)) {
chainStyle = SdkConstants.ATTR_LAYOUT_CHAIN_SPREAD_INSIDE;
} else if (chainStyle.equalsIgnoreCase(SdkConstants.ATTR_LAYOUT_CHAIN_SPREAD_INSIDE)) {
chainStyle = SdkConstants.ATTR_LAYOUT_CHAIN_PACKED;
} else if (chainStyle.equalsIgnoreCase(SdkConstants.ATTR_LAYOUT_CHAIN_PACKED)) {
chainStyle = SdkConstants.ATTR_LAYOUT_CHAIN_SPREAD;
}
} else {
chainStyle = SdkConstants.ATTR_LAYOUT_CHAIN_SPREAD;
}
AttributesTransaction transaction = chainHead.startAttributeTransaction();
transaction.setAttribute(SdkConstants.SHERPA_URI, orientationStyle, chainStyle);
transaction.apply();
NlModel nlModel = chainHead.getModel();
Project project = nlModel.getProject();
XmlFile file = nlModel.getFile();
String label = "Cycle chain style";
WriteCommandAction action = new WriteCommandAction(project, label, file) {
@Override
protected void run(@NotNull Result result) throws Throwable {
transaction.commit();
}
};
action.execute();
myComponent.getScene().needsRebuildList();
}
use of com.android.tools.idea.uibuilder.model.NlModel in project android by JetBrains.
the class SceneCreationTest method testSceneReparenting.
public void testSceneReparenting() {
ModelBuilder builder = createModel();
NlModel model = builder.build();
Scene scene = Scene.createScene(model, myScreen.getScreen());
scene.setDpiFactorOverride(1);
scene.setAnimate(false);
assertEquals(scene.getRoot().getChildren().size(), 1);
ComponentDescriptor parent = builder.findByPath(CONSTRAINT_LAYOUT);
parent.addChild(component(CONSTRAINT_LAYOUT).id("@id/layout").withBounds(200, 300, 200, 200).width("200dp").height("200dp"), null);
builder.updateModel(model, false);
scene.updateFrom(model);
assertEquals(2, scene.getRoot().getChildren().size());
NlComponent textView = scene.getRoot().getChild(0).getNlComponent();
NlComponent container = scene.getRoot().getChild(1).getNlComponent();
scene.getRoot().getNlComponent().removeChild(textView);
container.addChild(textView);
scene.updateFrom(model);
assertEquals(1, scene.getRoot().getChildCount());
SceneComponent layout = scene.getSceneComponent("layout");
assertEquals(1, layout.getChildCount());
}
use of com.android.tools.idea.uibuilder.model.NlModel in project android by JetBrains.
the class IdAnalyzerTest method testConstraintLayout.
public void testConstraintLayout() {
ModelBuilder modelBuilder = createConstraintLayout();
NlModel model = modelBuilder.build();
NlComponent button2 = findById(model, "button3");
NlProperty property = new NlPropertyItem(ImmutableList.of(button2), AUTO_URI, new AttributeDefinition(ATTR_LAYOUT_TOP_TO_TOP_OF));
IdAnalyzer analyzer = new IdAnalyzer(property);
List<String> ids = analyzer.findIds();
assertEquals(ImmutableList.of("button4", "button5"), ids);
}
use of com.android.tools.idea.uibuilder.model.NlModel in project android by JetBrains.
the class IdAnalyzerTest method testRelativeLayout.
public void testRelativeLayout() {
ModelBuilder modelBuilder = createRelativeLayout();
NlModel model = modelBuilder.build();
NlComponent button2 = findById(model, "button3");
NlProperty property = new NlPropertyItem(ImmutableList.of(button2), ANDROID_URI, new AttributeDefinition(ATTR_LAYOUT_ALIGN_START));
IdAnalyzer analyzer = new IdAnalyzer(property);
List<String> ids = analyzer.findIds();
assertEquals(ImmutableList.of("button4", "button5", "group1"), ids);
}
use of com.android.tools.idea.uibuilder.model.NlModel in project android by JetBrains.
the class IdAnalyzerTest method testButton1.
public void testButton1() {
ModelBuilder modelBuilder = createRelativeLayout();
NlModel model = modelBuilder.build();
NlComponent button1 = findById(model, "button1");
NlProperty labelFor = new NlPropertyItem(ImmutableList.of(button1), ANDROID_URI, new AttributeDefinition(ATTR_LABEL_FOR));
IdAnalyzer analyzer = new IdAnalyzer(labelFor);
List<String> ids = analyzer.findIds();
assertEquals(ImmutableList.of("button2", "button3", "button4", "button5", "group1", "radio_button1", "radio_button2", "radio_button3", "text_view1"), ids);
}
Aggregations