Search in sources :

Example 81 with NlComponent

use of com.android.tools.idea.uibuilder.model.NlComponent in project android by JetBrains.

the class IdInspectorProviderTest method testUpdateProperties.

public void testUpdateProperties() {
    List<NlComponent> components = ImmutableList.of(myTextView);
    Map<String, NlProperty> properties = getPropertyMap(components);
    assertThat(myProvider.isApplicable(components, properties, myPropertiesManager)).isTrue();
    IdInspectorComponent inspector = myProvider.createCustomInspector(components, properties, myPropertiesManager);
    inspector.updateProperties(ImmutableList.of(), properties, myPropertiesManager);
    components = ImmutableList.of(myButtonInConstraintLayout);
    properties = getPropertyMap(components);
    inspector.updateProperties(components, properties, myPropertiesManager);
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) NlProperty(com.android.tools.idea.uibuilder.property.NlProperty) Matchers.anyString(org.mockito.Matchers.anyString) IdInspectorComponent(com.android.tools.idea.uibuilder.property.inspector.IdInspectorProvider.IdInspectorComponent)

Example 82 with NlComponent

use of com.android.tools.idea.uibuilder.model.NlComponent in project android by JetBrains.

the class SceneBasicConnectionsTest method testConnectTop.

public void testConnectTop() {
    myInteraction.select("button", true);
    NlComponent button = myScene.getSceneComponent("button").getNlComponent();
    assertEquals(1, myScreen.getScreen().getSelectionModel().getSelection().size());
    assertEquals(button, myScreen.getScreen().getSelectionModel().getPrimary());
    myInteraction.mouseDown("button", AnchorTarget.Type.TOP);
    myInteraction.mouseRelease("root", AnchorTarget.Type.TOP);
    myScreen.get("@id/button").expectXml("<TextView\n" + "    android:id=\"@id/button\"\n" + "    android:layout_width=\"100dp\"\n" + "    android:layout_height=\"20dp\"\n" + "    tools:layout_editor_absoluteX=\"100dp\"\n" + "      app:layout_constraintTop_toTopOf=\"parent\"\n" + "      android:layout_marginTop=\"8dp\" />");
    assertEquals(button, myScreen.getScreen().getSelectionModel().getPrimary());
    assertEquals(1, myScreen.getScreen().getSelectionModel().getSelection().size());
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent)

Example 83 with NlComponent

use of com.android.tools.idea.uibuilder.model.NlComponent in project android by JetBrains.

the class SceneCreationTest method testBasicScene.

public void testBasicScene() {
    myScreen.get("@id/button").expectXml("<TextView\n" + "    android:id=\"@id/button\"\n" + "    android:layout_width=\"100dp\"\n" + "    android:layout_height=\"20dp\"\n" + "    tools:layout_editor_absoluteX=\"100dp\"\n" + "    tools:layout_editor_absoluteY=\"200dp\"/>");
    assertTrue(myInteraction.getDisplayList().getCommands().size() > 0);
    SceneComponent component = myScene.getSceneComponent("button");
    assertEquals(component.getScene(), myScene);
    NlComponent nlComponent = component.getNlComponent();
    assertEquals(component, myScene.getSceneComponent(nlComponent));
    assertEquals(myScene.pxToDp(myScene.dpToPx(100)), 100);
    myScene.setDpiFactorOverride(3.5f);
    assertEquals(myScene.pxToDp(myScene.dpToPx(100)), 100);
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent)

Example 84 with NlComponent

use of com.android.tools.idea.uibuilder.model.NlComponent in project android by JetBrains.

the class SceneDeleteWidgetBaselineTest method testDelete.

public void testDelete() {
    SceneComponent layout = myScene.getSceneComponent("root");
    NlComponent layoutComponent = layout.getNlComponent();
    ViewGroupHandler handler = (ViewGroupHandler) layoutComponent.getViewHandler();
    ArrayList<NlComponent> deleted = new ArrayList<>();
    deleted.add(myScene.getSceneComponent("button2").getNlComponent());
    handler.deleteChildren(layoutComponent, deleted);
    myScreen.get("@id/button").expectXml("<TextView\n" + "    android:id=\"@id/button\"\n" + "    android:layout_width=\"100dp\"\n" + "    android:layout_height=\"50dp\"\n" + "      app:layout_constraintLeft_toLeftOf=\"parent\"\n" + "    android:layout_marginLeft=\"8dp\"\n" + "      tools:layout_editor_absoluteY=\"83dp\" />");
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) ArrayList(java.util.ArrayList) ViewGroupHandler(com.android.tools.idea.uibuilder.api.ViewGroupHandler)

Example 85 with NlComponent

use of com.android.tools.idea.uibuilder.model.NlComponent in project android by JetBrains.

the class NlLintHighlightingPass method getAnnotations.

@NotNull
private static LintAnnotationsModel getAnnotations(@NotNull NlModel model, @NotNull ProgressIndicator progress) {
    ApplicationManager.getApplication().assertReadAccessAllowed();
    LintAnnotationsModel lintModel = new LintAnnotationsModel();
    XmlFile xmlFile = model.getFile();
    AndroidLintExternalAnnotator annotator = new AndroidLintExternalAnnotator();
    State state = annotator.collectInformation(xmlFile);
    if (state != null) {
        state = annotator.doAnnotate(state);
    }
    if (state == null) {
        return lintModel;
    }
    for (ProblemData problemData : state.getProblems()) {
        if (progress.isCanceled()) {
            break;
        }
        TextRange range = problemData.getTextRange();
        final PsiElement startElement = xmlFile.findElementAt(range.getStartOffset());
        final PsiElement endElement = xmlFile.findElementAt(range.getEndOffset());
        if (startElement == null || endElement == null) {
            continue;
        }
        NlComponent component = model.findViewByPsi(startElement);
        if (component == null) {
            continue;
        }
        Issue issue = problemData.getIssue();
        Pair<AndroidLintInspectionBase, HighlightDisplayLevel> pair = AndroidLintUtil.getHighlighLevelAndInspection(xmlFile.getProject(), issue, xmlFile);
        if (pair == null) {
            continue;
        }
        AndroidLintInspectionBase inspection = pair.getFirst();
        if (inspection == null) {
            continue;
        }
        HighlightDisplayLevel level = pair.getSecond();
        HighlightDisplayKey key = HighlightDisplayKey.find(inspection.getShortName());
        if (key == null) {
            continue;
        }
        lintModel.addIssue(component, issue, problemData.getMessage(), inspection, level, startElement, endElement);
    }
    return lintModel;
}
Also used : Issue(com.android.tools.lint.detector.api.Issue) HighlightDisplayLevel(com.intellij.codeHighlighting.HighlightDisplayLevel) XmlFile(com.intellij.psi.xml.XmlFile) HighlightDisplayKey(com.intellij.codeInsight.daemon.HighlightDisplayKey) TextRange(com.intellij.openapi.util.TextRange) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

NlComponent (com.android.tools.idea.uibuilder.model.NlComponent)184 NlModel (com.android.tools.idea.uibuilder.model.NlModel)34 NotNull (org.jetbrains.annotations.NotNull)34 NlProperty (com.android.tools.idea.uibuilder.property.NlProperty)18 ScreenView (com.android.tools.idea.uibuilder.surface.ScreenView)17 Nullable (org.jetbrains.annotations.Nullable)14 Test (org.junit.Test)12 Matchers.anyString (org.mockito.Matchers.anyString)11 ViewGroupHandler (com.android.tools.idea.uibuilder.api.ViewGroupHandler)9 AttributesTransaction (com.android.tools.idea.uibuilder.model.AttributesTransaction)9 AttributeDefinition (org.jetbrains.android.dom.attrs.AttributeDefinition)8 NlPropertyItem (com.android.tools.idea.uibuilder.property.NlPropertyItem)7 XmlFile (com.intellij.psi.xml.XmlFile)7 XmlTag (com.intellij.psi.xml.XmlTag)7 ArrayList (java.util.ArrayList)7 ModelBuilder (com.android.tools.idea.uibuilder.fixtures.ModelBuilder)6 NlGraphics (com.android.tools.idea.uibuilder.graphics.NlGraphics)6 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)6 Project (com.intellij.openapi.project.Project)6 List (java.util.List)6