in designer/src/com/android/tools/idea/uibuilder/handlers/constraint/ConstraintComponentUtilities.java [1001:1120]
public static void cleanup(@NotNull NlAttributesHolder transaction, @NotNull NlComponent component) {
boolean hasLeft = hasLeft(transaction);
boolean hasRight = hasRight(transaction);
boolean hasTop = hasTop(transaction);
boolean hasBottom = hasBottom(transaction);
boolean hasBaseline = transaction.getAttribute(SHERPA_URI, ATTR_LAYOUT_BASELINE_TO_BASELINE_OF) != null;
boolean hasStart = hasStart(transaction);
boolean hasEnd = hasEnd(transaction);
boolean inFlow = isInFlow(component);
String margin;
// Horizontal attributes
// cleanup needs to be sdk range specific
//
AndroidModuleInfo moduleInfo = StudioAndroidModuleInfo.getInstance(component.getModel().getFacet());
boolean remove_left_right = moduleInfo.getMinSdkVersion().isAtLeast(17);
margin = transaction.getAttribute(ANDROID_URI, ATTR_LAYOUT_MARGIN_LEFT);
if (margin != null && margin.equalsIgnoreCase(VALUE_ZERO_DP)) {
transaction.setAttribute(ANDROID_URI, ATTR_LAYOUT_MARGIN_LEFT, null);
}
margin = transaction.getAttribute(ANDROID_URI, ATTR_LAYOUT_MARGIN_RIGHT);
if (margin != null && margin.equalsIgnoreCase(VALUE_ZERO_DP)) {
transaction.setAttribute(ANDROID_URI, ATTR_LAYOUT_MARGIN_RIGHT, null);
}
if (!hasStart) {
transaction.setAttribute(ANDROID_URI, ATTR_LAYOUT_MARGIN_START, null);
if (!hasLeft) {
transaction.setAttribute(ANDROID_URI, ATTR_LAYOUT_MARGIN_LEFT, null);
}
}
else {
margin = transaction.getAttribute(ANDROID_URI, ATTR_LAYOUT_MARGIN_START);
if (margin != null && margin.equalsIgnoreCase(VALUE_ZERO_DP)) {
transaction.setAttribute(ANDROID_URI, ATTR_LAYOUT_MARGIN_START, null);
transaction.setAttribute(ANDROID_URI, ATTR_LAYOUT_MARGIN_LEFT, null);
}
}
if (!hasEnd) {
transaction.setAttribute(ANDROID_URI, ATTR_LAYOUT_MARGIN_END, null);
if (!hasRight) {
transaction.setAttribute(ANDROID_URI, ATTR_LAYOUT_MARGIN_RIGHT, null);
}
}
else {
margin = transaction.getAttribute(ANDROID_URI, ATTR_LAYOUT_MARGIN_END);
if (margin != null && margin.equalsIgnoreCase(VALUE_ZERO_DP)) {
transaction.setAttribute(ANDROID_URI, ATTR_LAYOUT_MARGIN_END, null);
transaction.setAttribute(ANDROID_URI, ATTR_LAYOUT_MARGIN_RIGHT, null);
}
}
if (!(hasLeft && hasRight) && !(hasStart && hasEnd)) {
transaction.setAttribute(SHERPA_URI, ATTR_LAYOUT_HORIZONTAL_BIAS, null);
}
if (!hasLeft && !hasRight && !hasStart && !hasEnd) {
if (transaction.getAttribute(TOOLS_URI, ATTR_LAYOUT_EDITOR_ABSOLUTE_X) == null && !inFlow) {
setDpAttribute(TOOLS_URI, ATTR_LAYOUT_EDITOR_ABSOLUTE_X, transaction, pixelToDP(component, getXfromParent(component)));
transaction.setAttribute(SHERPA_URI, ATTR_LAYOUT_HORIZONTAL_CHAIN_STYLE, null);
}
}
else {
transaction.setAttribute(TOOLS_URI, ATTR_LAYOUT_EDITOR_ABSOLUTE_X, null);
}
// Vertical attributes
if (!hasTop) {
transaction.setAttribute(ANDROID_URI, ATTR_LAYOUT_MARGIN_TOP, null);
transaction.setAttribute(SHERPA_URI, ATTR_LAYOUT_VERTICAL_BIAS, null);
}
else {
margin = transaction.getAttribute(ANDROID_URI, ATTR_LAYOUT_MARGIN_TOP);
if (margin != null && margin.equalsIgnoreCase(VALUE_ZERO_DP)) {
transaction.setAttribute(ANDROID_URI, ATTR_LAYOUT_MARGIN_TOP, null);
}
}
if (!hasBottom) {
transaction.setAttribute(ANDROID_URI, ATTR_LAYOUT_MARGIN_BOTTOM, null);
transaction.setAttribute(SHERPA_URI, ATTR_LAYOUT_VERTICAL_BIAS, null);
}
else {
margin = transaction.getAttribute(ANDROID_URI, ATTR_LAYOUT_MARGIN_BOTTOM);
if (margin != null && margin.equalsIgnoreCase(VALUE_ZERO_DP)) {
transaction.setAttribute(ANDROID_URI, ATTR_LAYOUT_MARGIN_BOTTOM, null);
}
}
if (!hasTop && !hasBottom && !hasBaseline) {
if (transaction.getAttribute(TOOLS_URI, ATTR_LAYOUT_EDITOR_ABSOLUTE_Y) == null && !inFlow) {
setDpAttribute(TOOLS_URI, ATTR_LAYOUT_EDITOR_ABSOLUTE_Y, transaction, pixelToDP(component, getYfromParent(component)));
transaction.setAttribute(SHERPA_URI, ATTR_LAYOUT_VERTICAL_CHAIN_STYLE, null);
}
}
else {
transaction.setAttribute(TOOLS_URI, ATTR_LAYOUT_EDITOR_ABSOLUTE_Y, null);
}
if (isGuideLine(component) || isBarrier(component) || isGroup(component)) {
transaction.setAttribute(TOOLS_URI, ATTR_LAYOUT_EDITOR_ABSOLUTE_X, null);
transaction.setAttribute(TOOLS_URI, ATTR_LAYOUT_EDITOR_ABSOLUTE_Y, null);
}
if (remove_left_right) {
boolean start = null != transaction.getAttribute(ANDROID_URI, ATTR_LAYOUT_MARGIN_START);
if (start) {
boolean left = null != transaction.getAttribute(ANDROID_URI, ATTR_LAYOUT_MARGIN_LEFT);
if (left) {
transaction.removeAttribute(ANDROID_URI, ATTR_LAYOUT_MARGIN_LEFT);
}
}
boolean end = null != transaction.getAttribute(ANDROID_URI, ATTR_LAYOUT_MARGIN_END);
if (end) {
boolean right = null != transaction.getAttribute(ANDROID_URI, ATTR_LAYOUT_MARGIN_RIGHT);
if (right) {
transaction.removeAttribute(ANDROID_URI, ATTR_LAYOUT_MARGIN_RIGHT);
}
}
}
}