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