Search in sources :

Example 11 with NlComponent

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

the class HorizontalScrollViewHandler method onCreate.

@Override
public boolean onCreate(@NotNull ViewEditor editor, @Nullable NlComponent parent, @NotNull NlComponent node, @NotNull InsertType insertType) {
    if (insertType.isCreate()) {
        // Insert a default linear layout (which will in turn be registered as
        // a child of this node and the create child method above will set its
        // fill parent attributes, its id, etc.
        NlComponent linear = node.createChild(editor, FQCN_LINEAR_LAYOUT, null, InsertType.VIEW_HANDLER);
        linear.setAttribute(ANDROID_URI, ATTR_ORIENTATION, VALUE_VERTICAL);
    }
    return true;
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent)

Example 12 with NlComponent

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

the class ScrollViewHandler method onCreate.

@Override
public boolean onCreate(@NotNull ViewEditor editor, @Nullable NlComponent parent, @NotNull NlComponent node, @NotNull InsertType insertType) {
    if (insertType.isCreate()) {
        // Insert a default linear layout (which will in turn be registered as
        // a child of this node and the create child method above will set its
        // fill parent attributes, its id, etc.
        NlComponent linear = node.createChild(editor, FQCN_LINEAR_LAYOUT, null, InsertType.VIEW_HANDLER);
        linear.setAttribute(ANDROID_URI, ATTR_ORIENTATION, VALUE_VERTICAL);
    }
    return true;
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent)

Example 13 with NlComponent

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

the class ScrollViewHandler method createScrollHandler.

@Nullable
@Override
public ScrollHandler createScrollHandler(@NotNull ViewEditor editor, @NotNull NlComponent component) {
    int maxScrollableHeight = 0;
    for (NlComponent child : component.getChildren()) {
        maxScrollableHeight += child.h;
    }
    // Subtract the viewport height from the scrollable size
    maxScrollableHeight -= component.h;
    if (maxScrollableHeight > 0) {
        // There is something to scroll
        return new ScrollViewScrollHandler(component, maxScrollableHeight, 10);
    }
    return null;
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) Nullable(org.jetbrains.annotations.Nullable)

Example 14 with NlComponent

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

the class TabLayoutHandler method onCreate.

@Override
public boolean onCreate(@NotNull ViewEditor editor, @Nullable NlComponent parent, @NotNull NlComponent node, @NotNull InsertType insertType) {
    if (insertType.isCreate()) {
        // Insert a couple of TabItems:
        NlComponent tab1 = node.createChild(editor, CLASS_TAB_ITEM, null, InsertType.VIEW_HANDLER);
        NlComponent tab2 = node.createChild(editor, CLASS_TAB_ITEM, null, InsertType.VIEW_HANDLER);
        NlComponent tab3 = node.createChild(editor, CLASS_TAB_ITEM, null, InsertType.VIEW_HANDLER);
        tab1.setAndroidAttribute(ATTR_TEXT, "Left");
        tab2.setAndroidAttribute(ATTR_TEXT, "Center");
        tab3.setAndroidAttribute(ATTR_TEXT, "Right");
    }
    return true;
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent)

Example 15 with NlComponent

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

the class TextViewDecorator method addContent.

@Override
public void addContent(@NotNull DisplayList list, long time, @NotNull SceneContext sceneContext, @NotNull SceneComponent component) {
    Rectangle rect = new Rectangle();
    component.fillDrawRect(time, rect);
    int l = sceneContext.getSwingX(rect.x);
    int t = sceneContext.getSwingY(rect.y);
    int w = sceneContext.getSwingDimension(rect.width);
    int h = sceneContext.getSwingDimension(rect.height);
    String text = ConstraintUtilities.getResolvedText(component.getNlComponent());
    NlComponent nlc = component.getNlComponent();
    Configuration configuration = nlc.getModel().getConfiguration();
    ResourceResolver resourceResolver = configuration.getResourceResolver();
    Integer size = null;
    if (resourceResolver != null) {
        String textSize = nlc.getAttribute(SdkConstants.ANDROID_URI, SdkConstants.ATTR_TEXT_SIZE);
        if (textSize != null) {
            size = ViewEditor.resolveDimensionPixelSize(resourceResolver, textSize, configuration);
        }
    }
    if (size == null) {
        // With the specified string, this method cannot return null
        //noinspection ConstantConditions
        size = ViewEditor.resolveDimensionPixelSize(resourceResolver, DEFAULT_DIM, configuration);
        // temporary
        size = (int) (0.8 * size);
    }
    String alignment = nlc.getAttribute(SdkConstants.ANDROID_URI, SdkConstants.ATTR_TEXT_ALIGNMENT);
    int align = ConstraintUtilities.getAlignment(alignment);
    String single = nlc.getAttribute(SdkConstants.ANDROID_URI, SdkConstants.ATTR_SINGLE_LINE);
    boolean singleLine = Boolean.parseBoolean(single);
    int baseLineOffset = sceneContext.getSwingDimension(component.getBaseline());
    int scaleSize = sceneContext.getSwingDimension(size);
    list.add(new DrawTextRegion(l, t, w, h, baseLineOffset, text, singleLine, false, align, DrawTextRegion.TEXT_ALIGNMENT_VIEW_START, scaleSize));
}
Also used : DrawTextRegion(com.android.tools.idea.uibuilder.scene.draw.DrawTextRegion) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) Configuration(com.android.tools.idea.configurations.Configuration) ResourceResolver(com.android.ide.common.resources.ResourceResolver)

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