Search in sources :

Example 6 with ViewHandler

use of com.android.tools.idea.uibuilder.api.ViewHandler in project android by JetBrains.

the class Scene method addTargets.

/**
   * Add targets to the given component (by asking the associated
   * {@linkplain ViewGroupHandler} to do it)
   *
   * @param component
   */
void addTargets(@NotNull SceneComponent component) {
    SceneComponent parent = component.getParent();
    if (parent != null) {
        component = parent;
    } else {
        component = myRoot;
    }
    ViewHandler handler = component.getNlComponent().getViewHandler();
    if (handler instanceof ViewGroupHandler) {
        ViewGroupHandler viewGroupHandler = (ViewGroupHandler) handler;
        if (component.getViewGroupHandler() != viewGroupHandler) {
            component.setViewGroupHandler(viewGroupHandler, true);
        }
        int childCount = component.getChildCount();
        for (int i = 0; i < childCount; i++) {
            SceneComponent child = component.getChild(i);
            if (child.getViewGroupHandler() != viewGroupHandler) {
                child.setViewGroupHandler(viewGroupHandler, false);
            }
        }
    }
    needsRebuildList();
}
Also used : ViewHandler(com.android.tools.idea.uibuilder.api.ViewHandler) ViewGroupHandler(com.android.tools.idea.uibuilder.api.ViewGroupHandler)

Example 7 with ViewHandler

use of com.android.tools.idea.uibuilder.api.ViewHandler in project android by JetBrains.

the class SceneMergeTest method testBasicScene.

public void testBasicScene() {
    myScreen.get("@+id/root").expectXml("<merge xmlns:android=\"http://schemas.android.com/apk/res/android\"\n" + "      xmlns:tools=\"http://schemas.android.com/tools\"\n" + "  android:id=\"@+id/root\"\n" + "  android:layout_width=\"1000dp\"\n" + "  android:layout_height=\"1000dp\"\n" + "  tools:parentTag=\"android.support.constraint.ConstraintLayout\"/>");
    SceneComponent component = myScene.getSceneComponent("root");
    assertTrue(component.getDecorator() instanceof ConstraintLayoutDecorator);
    Project project = component.getNlComponent().getModel().getProject();
    ViewHandler viewGroupHandler = ViewHandlerManager.get(project).getHandler(component.getNlComponent());
    assertTrue(viewGroupHandler instanceof ConstraintLayoutHandler);
}
Also used : Project(com.intellij.openapi.project.Project) ConstraintLayoutHandler(com.android.tools.idea.uibuilder.handlers.constraint.ConstraintLayoutHandler) ViewHandler(com.android.tools.idea.uibuilder.api.ViewHandler) ConstraintLayoutDecorator(com.android.tools.idea.uibuilder.scene.decorator.ConstraintLayoutDecorator)

Example 8 with ViewHandler

use of com.android.tools.idea.uibuilder.api.ViewHandler in project android by JetBrains.

the class ConstraintsLayer method drawComponent.

/**
   * Draw the given component and its children
   *
   * @param gc the graphics context
   * @param component the component we want to draw
   * @param parentHandlesPainting the parent of the component already handled the painting
   *
   * @return true if the component needs a repaint (for example when running an application)
   */
private boolean drawComponent(@NotNull Graphics2D gc, @NotNull NlComponent component, boolean parentHandlesPainting) {
    if (component.viewInfo != null) {
        ViewHandler handler = component.getViewHandler();
        boolean handlesPainting = false;
        // Check if the view handler handles the painting
        if (handler != null && handler instanceof ViewGroupHandler) {
            ViewGroupHandler viewGroupHandler = (ViewGroupHandler) handler;
            if (viewGroupHandler.handlesPainting()) {
                viewGroupHandler.drawGroup(gc, myScreenView, component);
                handlesPainting = true;
            }
        }
        if (handler != null) {
            handler.paintConstraints(myScreenView, gc, component);
        }
    }
    boolean needsRepaint = false;
    // Draw the children of the component...
    for (NlComponent child : component.getChildren()) {
        needsRepaint |= drawComponent(gc, child, parentHandlesPainting);
    }
    return needsRepaint;
}
Also used : NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) ViewHandler(com.android.tools.idea.uibuilder.api.ViewHandler) ViewGroupHandler(com.android.tools.idea.uibuilder.api.ViewGroupHandler)

Example 9 with ViewHandler

use of com.android.tools.idea.uibuilder.api.ViewHandler in project android by JetBrains.

the class DesignSurfaceActionHandler method pasteOperation.

private boolean pasteOperation(boolean checkOnly) {
    ScreenView screenView = mySurface.getCurrentScreenView();
    if (screenView == null) {
        return false;
    }
    List<NlComponent> selection = screenView.getSelectionModel().getSelection();
    NlComponent receiver = !selection.isEmpty() ? selection.get(0) : null;
    if (receiver == null) {
        // In the case where there is no selection but we only have a root component, use that one
        List<NlComponent> components = screenView.getModel().getComponents();
        if (components.size() == 1) {
            receiver = components.get(0);
        }
    }
    if (receiver == null) {
        return false;
    }
    NlComponent before;
    NlModel model = screenView.getModel();
    ViewHandlerManager handlerManager = ViewHandlerManager.get(model.getProject());
    ViewHandler handler = handlerManager.getHandler(receiver);
    if (handler instanceof ViewGroupHandler) {
        before = receiver.getChild(0);
    } else {
        before = receiver.getNextSibling();
        receiver = receiver.getParent();
        if (receiver == null) {
            return false;
        }
    }
    DnDTransferItem item = getClipboardData();
    if (item == null) {
        return false;
    }
    InsertType insertType = model.determineInsertType(DragType.PASTE, item, checkOnly);
    List<NlComponent> pasted = model.createComponents(screenView, item, insertType);
    if (!model.canAddComponents(pasted, receiver, before)) {
        return false;
    }
    if (checkOnly) {
        return true;
    }
    model.addComponents(pasted, receiver, before, insertType);
    return true;
}
Also used : ViewHandlerManager(com.android.tools.idea.uibuilder.handlers.ViewHandlerManager) ViewHandler(com.android.tools.idea.uibuilder.api.ViewHandler) ViewGroupHandler(com.android.tools.idea.uibuilder.api.ViewGroupHandler) InsertType(com.android.tools.idea.uibuilder.api.InsertType)

Example 10 with ViewHandler

use of com.android.tools.idea.uibuilder.api.ViewHandler in project android by JetBrains.

the class SelectionLayer method parentHandlingSelection.

/**
   * Utility function that checks if the component is a child of a view group that
   * handles painting
   *
   * @param component          the component we are looking at
   * @return true if the parent container handles painting
   */
private static boolean parentHandlingSelection(@NotNull NlComponent component) {
    NlComponent parent = component.getParent();
    if (parent == null) {
        return false;
    }
    ViewInfo view = parent.viewInfo;
    if (view == null) {
        return false;
    }
    ViewHandler handler = parent.getViewHandler();
    if (handler != null && handler instanceof ViewGroupHandler) {
        ViewGroupHandler viewGroupHandler = (ViewGroupHandler) handler;
        if (viewGroupHandler.handlesPainting()) {
            return true;
        }
    }
    return false;
}
Also used : ViewHandler(com.android.tools.idea.uibuilder.api.ViewHandler) ViewGroupHandler(com.android.tools.idea.uibuilder.api.ViewGroupHandler) ViewInfo(com.android.ide.common.rendering.api.ViewInfo)

Aggregations

ViewHandler (com.android.tools.idea.uibuilder.api.ViewHandler)13 ViewGroupHandler (com.android.tools.idea.uibuilder.api.ViewGroupHandler)6 NlComponent (com.android.tools.idea.uibuilder.model.NlComponent)4 ViewHandlerManager (com.android.tools.idea.uibuilder.handlers.ViewHandlerManager)3 AdViewHandler (com.android.tools.idea.uibuilder.handlers.google.AdViewHandler)2 MapViewHandler (com.android.tools.idea.uibuilder.handlers.google.MapViewHandler)2 Nullable (org.jetbrains.annotations.Nullable)2 ViewInfo (com.android.ide.common.rendering.api.ViewInfo)1 ResourceValueMap (com.android.ide.common.resources.ResourceValueMap)1 InsertType (com.android.tools.idea.uibuilder.api.InsertType)1 ViewEditor (com.android.tools.idea.uibuilder.api.ViewEditor)1 TextViewHandler (com.android.tools.idea.uibuilder.handlers.TextViewHandler)1 ViewEditorImpl (com.android.tools.idea.uibuilder.handlers.ViewEditorImpl)1 ConstraintLayoutHandler (com.android.tools.idea.uibuilder.handlers.constraint.ConstraintLayoutHandler)1 ConstraintLayoutDecorator (com.android.tools.idea.uibuilder.scene.decorator.ConstraintLayoutDecorator)1 ScreenView (com.android.tools.idea.uibuilder.surface.ScreenView)1 Project (com.intellij.openapi.project.Project)1 FontRenderContext (java.awt.font.FontRenderContext)1 Rectangle2D (java.awt.geom.Rectangle2D)1 NotNull (org.jetbrains.annotations.NotNull)1