Search in sources :

Example 46 with NlModel

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();
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) Project(com.intellij.openapi.project.Project) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) XmlFile(com.intellij.psi.xml.XmlFile) NlModel(com.android.tools.idea.uibuilder.model.NlModel) NotNull(org.jetbrains.annotations.NotNull) AttributesTransaction(com.android.tools.idea.uibuilder.model.AttributesTransaction) Result(com.intellij.openapi.application.Result)

Example 47 with NlModel

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());
}
Also used : ModelBuilder(com.android.tools.idea.uibuilder.fixtures.ModelBuilder) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) ComponentDescriptor(com.android.tools.idea.uibuilder.fixtures.ComponentDescriptor) NlModel(com.android.tools.idea.uibuilder.model.NlModel)

Example 48 with NlModel

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);
}
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 49 with NlModel

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);
}
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 50 with NlModel

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);
}
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)

Aggregations

NlModel (com.android.tools.idea.uibuilder.model.NlModel)71 NlComponent (com.android.tools.idea.uibuilder.model.NlComponent)33 ModelBuilder (com.android.tools.idea.uibuilder.fixtures.ModelBuilder)19 NotNull (org.jetbrains.annotations.NotNull)18 XmlFile (com.intellij.psi.xml.XmlFile)14 Project (com.intellij.openapi.project.Project)12 AttributesTransaction (com.android.tools.idea.uibuilder.model.AttributesTransaction)11 Result (com.intellij.openapi.application.Result)11 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)11 ScreenView (com.android.tools.idea.uibuilder.surface.ScreenView)6 ComponentDescriptor (com.android.tools.idea.uibuilder.fixtures.ComponentDescriptor)5 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 Configuration (com.android.tools.idea.configurations.Configuration)4 DesignSurface (com.android.tools.idea.uibuilder.surface.DesignSurface)3 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)3 SelectionModel (com.android.tools.idea.uibuilder.model.SelectionModel)2 XmlTag (com.intellij.psi.xml.XmlTag)2 BufferedImage (java.awt.image.BufferedImage)2