use of com.android.tools.idea.rendering.AttributeSnapshot in project android by JetBrains.
the class NlDropListener method morphReceiverIntoViewGroup.
/**
* Morph the receiver into a constraint layout and add the dragged component to it.
*
* @param model {@link NlComponentTree#getDesignerModel()}
*/
private void morphReceiverIntoViewGroup(@NotNull NlModel model) {
final AttributesTransaction transaction = myDragReceiver.startAttributeTransaction();
for (AttributeSnapshot attribute : myDragReceiver.getAttributes()) {
if (!TOOLS_PREFIX.equals(attribute.prefix) && !ourCopyableAttributes.contains(attribute.name) && attribute.namespace != null) {
transaction.removeAttribute(attribute.namespace, attribute.name);
}
}
new WriteCommandAction(model.getProject(), model.getFile()) {
@Override
protected void run(@NotNull Result result) throws Throwable {
final XmlTag tag = myDragReceiver.getTag();
tag.setName(CONSTRAINT_LAYOUT);
myDragReceiver.setTag(tag);
transaction.commit();
}
}.execute();
}
use of com.android.tools.idea.rendering.AttributeSnapshot in project android by JetBrains.
the class NlPropertiesSorter method getModifiedAttributes.
@NotNull
public static Set<String> getModifiedAttributes(@NotNull List<NlComponent> components) {
List<AttributeSnapshot> attrs = components.get(0).getAttributes();
Set<String> modifiedAttrs = Sets.newHashSetWithExpectedSize(attrs.size());
for (NlComponent component : components) {
attrs = component.getAttributes();
for (AttributeSnapshot snapshot : attrs) {
modifiedAttrs.add(snapshot.name);
}
}
return modifiedAttrs;
}
use of com.android.tools.idea.rendering.AttributeSnapshot in project android by JetBrains.
the class GenerateLayoutTestSkeletonAction method appendComponent.
private static void appendComponent(@NotNull NlComponent component, int indent, @NotNull StringBuilder builder) {
builder.append(StringUtil.repeat(" ", indent)).append("component(").append(getTagSymbol(component.getTagName())).append(")\n").append(StringUtil.repeat(" ", indent + 2)).append(makeBounds(component)).append("\n");
for (AttributeSnapshot attribute : component.getAttributes()) {
appendAttribute(attribute, indent + 4, builder);
}
if (component.getChildCount() > 0) {
builder.append(StringUtil.repeat(" ", indent + 2)).append(".children(\n");
for (NlComponent child : component.getChildren()) {
appendComponent(child, indent + 4, builder);
// Replace last \n with a comma separator:
builder.replace(builder.length() - 1, builder.length(), ",\n\n");
}
// Replace last comma separator with end paren
builder.replace(builder.length() - 3, builder.length(), ")\n");
}
}
Aggregations