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