From 22bb23d71d77a0dda49da3433d3432eea12a95fe Mon Sep 17 00:00:00 2001 From: Alexander Lobas Date: Wed, 11 Jul 2012 20:35:03 +0400 Subject: [PATCH] IDEA-88555 --- .../layout/AbsoluteLayoutOperation.java | 13 +- .../layout/FrameLayoutOperation.java | 3 +- .../layout/LinearLayoutOperation.java | 11 +- .../layout/RelativeLayoutOperation.java | 13 +- .../actions/GridLayoutSpanOperation.java | 8 +- .../layout/actions/LayoutMarginOperation.java | 21 +- .../layout/actions/LayoutSpanOperation.java | 5 +- .../layout/actions/LayoutWeightOperation.java | 7 +- .../RelativeLayoutResizeOperation.java | 5 +- .../layout/actions/ResizeOperation.java | 11 +- .../actions/TableLayoutSpanOperation.java | 4 +- .../layout/relative/AutoResizeSnapPoint.java | 21 +- .../layout/relative/AutoSnapPoint.java | 9 +- .../layout/relative/BaselineSnapPoint.java | 3 +- .../layout/relative/ComponentSnapPoint.java | 19 +- .../layout/relative/ContainerSnapPoint.java | 3 +- .../relative/ResizeComponentSnapPoint.java | 16 +- .../relative/ResizeContainerSnapPoint.java | 24 +- .../layout/relative/WrapSizeSnapPoint.java | 5 +- .../android/designer/model/IdManager.java | 3 +- .../android/designer/model/ModelParser.java | 21 +- .../designer/model/RadViewComponent.java | 3 +- .../designer/model/layout/Gravity.java | 3 +- .../designer/model/layout/RadFrameLayout.java | 3 +- .../model/layout/RadLinearLayout.java | 704 +++++++++--------- .../model/layout/RadRadioGroupLayout.java | 3 +- .../layout/actions/AllGravityAction.java | 5 +- .../layout/actions/OrientationAction.java | 3 +- .../layout/grid/RadGridLayoutComponent.java | 24 +- .../model/layout/relative/CenterProperty.java | 12 +- .../relative/RadRelativeLayoutComponent.java | 37 +- .../layout/table/RadTableLayoutComponent.java | 11 +- .../model/morphing/AbsoluteLayout.java | 13 +- .../designer/model/morphing/FrameLayout.java | 15 +- .../designer/model/morphing/GridLayout.java | 13 +- .../designer/model/morphing/LinearLayout.java | 7 +- .../designer/model/morphing/RadioGroup.java | 5 +- .../model/morphing/RelativeLayout.java | 9 +- .../designer/model/morphing/TableLayout.java | 19 +- .../propertyTable/AttributeProperty.java | 5 +- .../designer/propertyTable/FlagProperty.java | 7 +- .../propertyTable/FragmentProperty.java | 13 +- .../propertyTable/GravityProperty.java | 3 +- 43 files changed, 599 insertions(+), 543 deletions(-) diff --git a/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/AbsoluteLayoutOperation.java b/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/AbsoluteLayoutOperation.java index 6943eca67e46..0c12f12932d9 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/AbsoluteLayoutOperation.java +++ b/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/AbsoluteLayoutOperation.java @@ -15,6 +15,7 @@ */ package com.intellij.android.designer.designSurface.layout; +import com.android.sdklib.SdkConstants; import com.intellij.android.designer.designSurface.AbstractEditOperation; import com.intellij.android.designer.model.RadViewComponent; import com.intellij.designer.designSurface.FeedbackLayer; @@ -117,15 +118,15 @@ public class AbsoluteLayoutOperation extends AbstractEditOperation { for (RadComponent component : myComponents) { XmlTag tag = ((RadViewComponent)component).getTag(); - tag.setAttribute("android:layout_x", Integer.toString(location.x - parentBounds.x) + "dp"); - tag.setAttribute("android:layout_y", Integer.toString(location.y - parentBounds.y) + "dp"); + tag.setAttribute("layout_x", SdkConstants.NS_RESOURCES, Integer.toString(location.x - parentBounds.x) + "dp"); + tag.setAttribute("layout_y", SdkConstants.NS_RESOURCES, Integer.toString(location.y - parentBounds.y) + "dp"); if (delta != null && myComponents.size() == 1) { if (delta.width > 0) { - tag.setAttribute("android:layout_width", Integer.toString(myBounds.width) + "dp"); + tag.setAttribute("layout_width", SdkConstants.NS_RESOURCES, Integer.toString(myBounds.width) + "dp"); } if (delta.height > 0) { - tag.setAttribute("android:layout_height", Integer.toString(myBounds.height) + "dp"); + tag.setAttribute("layout_height", SdkConstants.NS_RESOURCES, Integer.toString(myBounds.height) + "dp"); } } } @@ -139,8 +140,8 @@ public class AbsoluteLayoutOperation extends AbstractEditOperation { Point location = component.convertPoint(layer, bounds.x + moveDeltaX, bounds.y + moveDeltaY); XmlTag tag = ((RadViewComponent)component).getTag(); - tag.setAttribute("android:layout_x", Integer.toString(location.x - parentBounds.x) + "dp"); - tag.setAttribute("android:layout_y", Integer.toString(location.y - parentBounds.y) + "dp"); + tag.setAttribute("layout_x", SdkConstants.NS_RESOURCES, Integer.toString(location.x - parentBounds.x) + "dp"); + tag.setAttribute("layout_y", SdkConstants.NS_RESOURCES, Integer.toString(location.y - parentBounds.y) + "dp"); } } } diff --git a/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/FrameLayoutOperation.java b/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/FrameLayoutOperation.java index 146686f8bb13..68265390a49d 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/FrameLayoutOperation.java +++ b/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/FrameLayoutOperation.java @@ -15,6 +15,7 @@ */ package com.intellij.android.designer.designSurface.layout; +import com.android.sdklib.SdkConstants; import com.intellij.android.designer.designSurface.AbstractEditOperation; import com.intellij.android.designer.model.RadViewComponent; import com.intellij.android.designer.model.layout.Gravity; @@ -178,7 +179,7 @@ public class FrameLayoutOperation extends AbstractEditOperation { @Override public void run() { for (RadComponent component : myComponents) { - ((RadViewComponent)component).getTag().setAttribute("android:layout_gravity", myGravity); + ((RadViewComponent)component).getTag().setAttribute("layout_gravity", SdkConstants.NS_RESOURCES, myGravity); } } }); diff --git a/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/LinearLayoutOperation.java b/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/LinearLayoutOperation.java index f943ed3dba1b..34b3a7d7c318 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/LinearLayoutOperation.java +++ b/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/LinearLayoutOperation.java @@ -15,6 +15,7 @@ */ package com.intellij.android.designer.designSurface.layout; +import com.android.sdklib.SdkConstants; import com.intellij.android.designer.designSurface.layout.actions.ResizeOperation; import com.intellij.android.designer.designSurface.layout.flow.FlowBaseOperation; import com.intellij.android.designer.model.ModelParser; @@ -171,8 +172,8 @@ public class LinearLayoutOperation extends FlowBaseOperation { if (gravity == null) { for (RadComponent component : components) { XmlTag tag = ((RadViewComponent)component).getTag(); - ModelParser.deleteAttribute(tag, "android:layout_gravity"); - tag.setAttribute(horizontal ? "android:layout_height" : "android:layout_width", "fill_parent"); + ModelParser.deleteAttribute(tag, "layout_gravity"); + tag.setAttribute(horizontal ? "layout_height" : "layout_width", SdkConstants.NS_RESOURCES, "fill_parent"); } } else { @@ -181,12 +182,12 @@ public class LinearLayoutOperation extends FlowBaseOperation { for (RadComponent component : components) { XmlTag tag = ((RadViewComponent)component).getTag(); - XmlAttribute attribute = tag.getAttribute(horizontal ? "android:layout_height" : "android:layout_width"); + XmlAttribute attribute = tag.getAttribute(horizontal ? "layout_height" : "layout_width", SdkConstants.NS_RESOURCES); if (attribute != null && ("match_parent".equals(attribute.getValue()) || "fill_parent".equals(attribute.getValue()))) { attribute.setValue("wrap_content"); } - tag.setAttribute("android:layout_gravity", gravityValue); + tag.setAttribute("layout_gravity", SdkConstants.NS_RESOURCES, gravityValue); } } } @@ -194,7 +195,7 @@ public class LinearLayoutOperation extends FlowBaseOperation { @Nullable public static Gravity getGravity(boolean horizontal, RadComponent component) { XmlTag tag = ((RadViewComponent)component).getTag(); - String length = tag.getAttributeValue(horizontal ? "android:layout_height" : "android:layout_width"); + String length = tag.getAttributeValue(horizontal ? "layout_height" : "layout_width", SdkConstants.NS_RESOURCES); if (!ResizeOperation.isFill(length)) { Pair gravity = Gravity.getSides(component); diff --git a/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/RelativeLayoutOperation.java b/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/RelativeLayoutOperation.java index 74b67f463e9f..02593e5c40be 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/RelativeLayoutOperation.java +++ b/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/RelativeLayoutOperation.java @@ -276,13 +276,12 @@ public class RelativeLayoutOperation extends AbstractEditOperation { } private static final String[] ATTRIBUTES = - {"android:layout_toLeftOf", "android:layout_toRightOf", "android:layout_above", "android:layout_below", "android:layout_alignBaseline", - "android:layout_alignLeft", "android:layout_alignTop", "android:layout_alignRight", "android:layout_alignBottom", - "android:layout_alignParentLeft", "android:layout_alignParentTop", "android:layout_alignParentRight", - "android:layout_alignParentBottom", "android:layout_centerInParent", "android:layout_centerHorizontal", - "android:layout_centerVertical", "android:layout_margin", "android:layout_marginLeft", "android:layout_marginTop", - "android:layout_marginRight", - "android:layout_marginBottom", "android:layout_marginStart", "android:layout_marginEnd"}; + {"layout_toLeftOf", "layout_toRightOf", "layout_above", "layout_below", "layout_alignBaseline", + "layout_alignLeft", "layout_alignTop", "layout_alignRight", "layout_alignBottom", + "layout_alignParentLeft", "layout_alignParentTop", "layout_alignParentRight", + "layout_alignParentBottom", "layout_centerInParent", "layout_centerHorizontal", + "layout_centerVertical", "layout_margin", "layout_marginLeft", "layout_marginTop", + "layout_marginRight", "layout_marginBottom", "layout_marginStart", "layout_marginEnd"}; private static void clear(RadViewComponent component) { XmlTag tag = component.getTag(); diff --git a/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/actions/GridLayoutSpanOperation.java b/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/actions/GridLayoutSpanOperation.java index 6d57587e6c7a..e3b049fb4145 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/actions/GridLayoutSpanOperation.java +++ b/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/actions/GridLayoutSpanOperation.java @@ -40,22 +40,22 @@ public class GridLayoutSpanOperation extends LayoutSpanOperation { @Override protected String getColumnAttribute(boolean asName) { - return asName ? "layout:column" : "android:layout_column"; + return asName ? "layout:column" : "layout_column"; } @Override protected String getColumnSpanAttribute(boolean asName) { - return asName ? "layout:columnSpan" : "android:layout_columnSpan"; + return asName ? "layout:columnSpan" : "layout_columnSpan"; } @Override protected String getRowAttribute(boolean asName) { - return asName ? "layout:row" : "android:layout_row"; + return asName ? "layout:row" : "layout_row"; } @Override protected String getRowSpanAttribute(boolean asName) { - return asName ? "layout:rowSpan" : "android:layout_rowSpan"; + return asName ? "layout:rowSpan" : "layout_rowSpan"; } @Override diff --git a/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/actions/LayoutMarginOperation.java b/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/actions/LayoutMarginOperation.java index 9153d87e2c51..b27d72cf049d 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/actions/LayoutMarginOperation.java +++ b/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/actions/LayoutMarginOperation.java @@ -15,6 +15,7 @@ */ package com.intellij.android.designer.designSurface.layout.actions; +import com.android.sdklib.SdkConstants; import com.intellij.android.designer.model.ModelParser; import com.intellij.android.designer.model.RadViewComponent; import com.intellij.designer.designSurface.DecorationLayer; @@ -143,16 +144,16 @@ public class LayoutMarginOperation implements EditOperation { public void run() { XmlTag tag = myComponent.getTag(); - XmlAttribute margin = tag.getAttribute("android:layout_margin"); + XmlAttribute margin = tag.getAttribute("layout_margin", SdkConstants.NS_RESOURCES); if (margin != null) { String value = margin.getValue(); margin.delete(); if (!StringUtil.isEmpty(value)) { - tag.setAttribute("android:layout_marginLeft", value); - tag.setAttribute("android:layout_marginRight", value); - tag.setAttribute("android:layout_marginTop", value); - tag.setAttribute("android:layout_marginBottom", value); + tag.setAttribute("layout_marginLeft", SdkConstants.NS_RESOURCES, value); + tag.setAttribute("layout_marginRight", SdkConstants.NS_RESOURCES, value); + tag.setAttribute("layout_marginTop", SdkConstants.NS_RESOURCES, value); + tag.setAttribute("layout_marginBottom", SdkConstants.NS_RESOURCES, value); } } @@ -161,16 +162,16 @@ public class LayoutMarginOperation implements EditOperation { int direction = myContext.getResizeDirection(); if (direction == Position.WEST) { // left - setValue(tag, "android:layout_marginLeft", myMargins.x - moveDelta.x); + setValue(tag, "layout_marginLeft", myMargins.x - moveDelta.x); } else if (direction == Position.EAST) { // right - setValue(tag, "android:layout_marginRight", myMargins.width + sizeDelta.width); + setValue(tag, "layout_marginRight", myMargins.width + sizeDelta.width); } else if (direction == Position.NORTH) { // top - setValue(tag, "android:layout_marginTop", myMargins.y - moveDelta.y); + setValue(tag, "layout_marginTop", myMargins.y - moveDelta.y); } else if (direction == Position.SOUTH) { // bottom - setValue(tag, "android:layout_marginBottom", myMargins.height + sizeDelta.height); + setValue(tag, "layout_marginBottom", myMargins.height + sizeDelta.height); } } }); @@ -181,7 +182,7 @@ public class LayoutMarginOperation implements EditOperation { ModelParser.deleteAttribute(tag, name); } else { - tag.setAttribute(name, Integer.toString(value) + "dp"); + tag.setAttribute(name, SdkConstants.NS_RESOURCES, Integer.toString(value) + "dp"); } } diff --git a/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/actions/LayoutSpanOperation.java b/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/actions/LayoutSpanOperation.java index 45291ad38773..205d4414045d 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/actions/LayoutSpanOperation.java +++ b/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/actions/LayoutSpanOperation.java @@ -15,6 +15,7 @@ */ package com.intellij.android.designer.designSurface.layout.actions; +import com.android.sdklib.SdkConstants; import com.intellij.android.designer.designSurface.layout.grid.GridSelectionDecorator; import com.intellij.android.designer.model.ModelParser; import com.intellij.android.designer.model.RadViewComponent; @@ -409,7 +410,7 @@ public abstract class LayoutSpanOperation implements EditOperation { XmlTag tag = myComponent.getTag(); if (cellFix) { - tag.setAttribute(cell, Integer.toString(myCells[myIndex])); + tag.setAttribute(cell, SdkConstants.NS_RESOURCES, Integer.toString(myCells[myIndex])); } int spanValue = mySpans[myIndex]; @@ -417,7 +418,7 @@ public abstract class LayoutSpanOperation implements EditOperation { ModelParser.deleteAttribute(tag, span); } else { - tag.setAttribute(span, Integer.toString(spanValue)); + tag.setAttribute(span, SdkConstants.NS_RESOURCES, Integer.toString(spanValue)); } } diff --git a/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/actions/LayoutWeightOperation.java b/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/actions/LayoutWeightOperation.java index bd583b0bc88c..913f2e66fcd8 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/actions/LayoutWeightOperation.java +++ b/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/actions/LayoutWeightOperation.java @@ -15,6 +15,7 @@ */ package com.intellij.android.designer.designSurface.layout.actions; +import com.android.sdklib.SdkConstants; import com.intellij.android.designer.model.ModelParser; import com.intellij.designer.designSurface.OperationContext; import com.intellij.designer.designSurface.selection.ResizeSelectionDecorator; @@ -42,7 +43,7 @@ public class LayoutWeightOperation extends LayoutMarginOperation { super.setComponent(component); try { - myWeight = Float.parseFloat(myComponent.getTag().getAttributeValue("android:layout_weight")); + myWeight = Float.parseFloat(myComponent.getTag().getAttributeValue("layout_weight", SdkConstants.NS_RESOURCES)); } catch (Throwable e) { myWeight = 0; @@ -98,10 +99,10 @@ public class LayoutWeightOperation extends LayoutMarginOperation { private void setWeight(int value) { float weight = myWeight + value / 100f; if (weight <= 0) { - ModelParser.deleteAttribute(myComponent, "android:layout_weight"); + ModelParser.deleteAttribute(myComponent, "layout_weight"); } else { - myComponent.getTag().setAttribute("android:layout_weight", FORMAT.format(weight).replace(',', '.')); + myComponent.getTag().setAttribute("layout_weight", SdkConstants.NS_RESOURCES, FORMAT.format(weight).replace(',', '.')); } } diff --git a/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/actions/RelativeLayoutResizeOperation.java b/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/actions/RelativeLayoutResizeOperation.java index 8e0543d25ed8..a6ca3794358d 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/actions/RelativeLayoutResizeOperation.java +++ b/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/actions/RelativeLayoutResizeOperation.java @@ -15,6 +15,7 @@ */ package com.intellij.android.designer.designSurface.layout.actions; +import com.android.sdklib.SdkConstants; import com.intellij.android.designer.designSurface.layout.RelativeLayoutOperation; import com.intellij.android.designer.designSurface.layout.relative.*; import com.intellij.android.designer.model.RadViewComponent; @@ -100,8 +101,8 @@ public class RelativeLayoutResizeOperation implements EditOperation { if (direction == Position.EAST || direction == Position.SOUTH || direction == Position.SOUTH_EAST) { Rectangle bounds = myComponent.getBounds(myContext.getArea().getFeedbackLayer()); - String width = myComponent.getTag().getAttributeValue("android:layout_width"); - String height = myComponent.getTag().getAttributeValue("android:layout_height"); + String width = myComponent.getTag().getAttributeValue("layout_width", SdkConstants.NS_RESOURCES); + String height = myComponent.getTag().getAttributeValue("layout_height", SdkConstants.NS_RESOURCES); Pair widthInfo = ResizeOperation.getDefaultSize(width, bounds.width); Pair heightInfo = ResizeOperation.getDefaultSize(height, bounds.height); diff --git a/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/actions/ResizeOperation.java b/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/actions/ResizeOperation.java index c10c21fae8b6..81fdfbab13b0 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/actions/ResizeOperation.java +++ b/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/actions/ResizeOperation.java @@ -15,6 +15,7 @@ */ package com.intellij.android.designer.designSurface.layout.actions; +import com.android.sdklib.SdkConstants; import com.intellij.android.designer.model.RadViewComponent; import com.intellij.android.designer.propertyTable.renderers.ResourceRenderer; import com.intellij.designer.designSurface.EditOperation; @@ -69,8 +70,8 @@ public class ResizeOperation implements EditOperation { myComponent = (RadViewComponent)component; Rectangle bounds = myComponent.getBounds(myContext.getArea().getFeedbackLayer()); - String width = myComponent.getTag().getAttributeValue("android:layout_width"); - String height = myComponent.getTag().getAttributeValue("android:layout_height"); + String width = myComponent.getTag().getAttributeValue("layout_width", SdkConstants.NS_RESOURCES); + String height = myComponent.getTag().getAttributeValue("layout_height", SdkConstants.NS_RESOURCES); Pair widthInfo = getDefaultSize(width, bounds.width); Pair heightInfo = getDefaultSize(height, bounds.height); @@ -277,10 +278,12 @@ public class ResizeOperation implements EditOperation { int direction = myContext.getResizeDirection(); if ((direction & Position.EAST) != 0) { - myComponent.getTag().setAttribute("android:layout_width", getSize(myBounds.width, myWrapSize.width, myFillSize.width)); + myComponent.getTag() + .setAttribute("layout_width", SdkConstants.NS_RESOURCES, getSize(myBounds.width, myWrapSize.width, myFillSize.width)); } if ((direction & Position.SOUTH) != 0) { - myComponent.getTag().setAttribute("android:layout_height", getSize(myBounds.height, myWrapSize.height, myFillSize.height)); + myComponent.getTag() + .setAttribute("layout_height", SdkConstants.NS_RESOURCES, getSize(myBounds.height, myWrapSize.height, myFillSize.height)); } } }); diff --git a/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/actions/TableLayoutSpanOperation.java b/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/actions/TableLayoutSpanOperation.java index 7a44d4c56ec3..5d3097cb5262 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/actions/TableLayoutSpanOperation.java +++ b/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/actions/TableLayoutSpanOperation.java @@ -41,12 +41,12 @@ public class TableLayoutSpanOperation extends LayoutSpanOperation { @Override protected String getColumnAttribute(boolean asName) { - return asName ? "layout:column" : "android:layout_column"; + return asName ? "layout:column" : "layout_column"; } @Override protected String getColumnSpanAttribute(boolean asName) { - return asName ? "layout:span" : "android:layout_span"; + return asName ? "layout:span" : "layout_span"; } @Override diff --git a/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/relative/AutoResizeSnapPoint.java b/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/relative/AutoResizeSnapPoint.java index 29d18c04e532..82250fbbf647 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/relative/AutoResizeSnapPoint.java +++ b/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/relative/AutoResizeSnapPoint.java @@ -15,6 +15,7 @@ */ package com.intellij.android.designer.designSurface.layout.relative; +import com.android.sdklib.SdkConstants; import com.intellij.android.designer.model.ModelParser; import com.intellij.android.designer.model.RadViewComponent; import com.intellij.designer.designSurface.feedbacks.TextFeedback; @@ -93,30 +94,30 @@ public class AutoResizeSnapPoint extends ResizeSnapPoint { XmlTag tag = ((RadViewComponent)components.get(0)).getTag(); if (myMargin > 0) { String attribute = myHorizontal ? "Left" : "Top"; - tag.setAttribute("android:layout_alignParent" + attribute, "true"); - tag.setAttribute("android:layout_margin" + attribute, Integer.toString(myMargin) + "dp"); - ModelParser.deleteAttribute(tag, "android:layout_align" + attribute); + tag.setAttribute("layout_alignParent" + attribute, SdkConstants.NS_RESOURCES, "true"); + tag.setAttribute("layout_margin" + attribute, SdkConstants.NS_RESOURCES, Integer.toString(myMargin) + "dp"); + ModelParser.deleteAttribute(tag, "layout_align" + attribute); if (myHorizontal) { - ModelParser.deleteAttribute(tag, "android:layout_toRightOf"); + ModelParser.deleteAttribute(tag, "layout_toRightOf"); } else { - ModelParser.deleteAttribute(tag, "android:layout_below"); + ModelParser.deleteAttribute(tag, "layout_below"); } } else { String attribute = myHorizontal ? "Right" : "Bottom"; - ModelParser.deleteAttribute(tag, "android:layout_alignParent" + attribute); - ModelParser.deleteAttribute(tag, "android:layout_align" + attribute); + ModelParser.deleteAttribute(tag, "layout_alignParent" + attribute); + ModelParser.deleteAttribute(tag, "layout_align" + attribute); if (myHorizontal) { - ModelParser.deleteAttribute(tag, "android:layout_toLeftOf"); + ModelParser.deleteAttribute(tag, "layout_toLeftOf"); } else { - ModelParser.deleteAttribute(tag, "android:layout_above"); + ModelParser.deleteAttribute(tag, "layout_above"); } } - tag.setAttribute("android:layout_" + (myHorizontal ? "width" : "height"), Integer.toString(mySize) + "dp"); + tag.setAttribute("layout_" + (myHorizontal ? "width" : "height"), SdkConstants.NS_RESOURCES, Integer.toString(mySize) + "dp"); } }); } diff --git a/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/relative/AutoSnapPoint.java b/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/relative/AutoSnapPoint.java index ef4823af47db..2fbccc0e5868 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/relative/AutoSnapPoint.java +++ b/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/relative/AutoSnapPoint.java @@ -15,6 +15,7 @@ */ package com.intellij.android.designer.designSurface.layout.relative; +import com.android.sdklib.SdkConstants; import com.intellij.android.designer.model.RadViewComponent; import com.intellij.designer.designSurface.feedbacks.TextFeedback; import com.intellij.designer.model.RadComponent; @@ -70,20 +71,20 @@ public class AutoSnapPoint extends SnapPoint { ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { - String attribute = "android:layout_" + getAttribute(); + String attribute = "layout_" + getAttribute(); String marginAttribute = null; String marginValue = null; if (myMargin > 0) { - marginAttribute = myHorizontal ? "android:layout_marginLeft" : "android:layout_marginTop"; + marginAttribute = myHorizontal ? "layout_marginLeft" : "layout_marginTop"; marginValue = Integer.toString(myMargin) + "dp"; } for (RadComponent component : components) { XmlTag tag = ((RadViewComponent)component).getTag(); - tag.setAttribute(attribute, "true"); + tag.setAttribute(attribute, SdkConstants.NS_RESOURCES, "true"); if (marginValue != null) { - tag.setAttribute(marginAttribute, marginValue); + tag.setAttribute(marginAttribute, SdkConstants.NS_RESOURCES, marginValue); } } } diff --git a/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/relative/BaselineSnapPoint.java b/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/relative/BaselineSnapPoint.java index 89f47c3fda78..3329d47c07e6 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/relative/BaselineSnapPoint.java +++ b/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/relative/BaselineSnapPoint.java @@ -15,6 +15,7 @@ */ package com.intellij.android.designer.designSurface.layout.relative; +import com.android.sdklib.SdkConstants; import com.intellij.android.designer.model.RadViewComponent; import com.intellij.designer.componentTree.AttributeWrapper; import com.intellij.designer.designSurface.feedbacks.TextFeedback; @@ -75,7 +76,7 @@ public class BaselineSnapPoint extends SnapPoint { @Override public void run() { XmlTag tag = ((RadViewComponent)components.get(0)).getTag(); - tag.setAttribute("android:layout_alignBaseline", myComponent.ensureId()); + tag.setAttribute("layout_alignBaseline", SdkConstants.NS_RESOURCES, myComponent.ensureId()); } }); } diff --git a/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/relative/ComponentSnapPoint.java b/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/relative/ComponentSnapPoint.java index 39bdce2dcaf7..43b25fe1e2e8 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/relative/ComponentSnapPoint.java +++ b/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/relative/ComponentSnapPoint.java @@ -15,6 +15,7 @@ */ package com.intellij.android.designer.designSurface.layout.relative; +import com.android.sdklib.SdkConstants; import com.intellij.android.designer.model.RadViewComponent; import com.intellij.designer.componentTree.AttributeWrapper; import com.intellij.designer.designSurface.feedbacks.TextFeedback; @@ -192,28 +193,28 @@ public class ComponentSnapPoint extends SnapPoint { final String attribute; if (myBeginSide == Side.top && myEndSide == Side.top) { - attribute = "android:layout_alignTop"; + attribute = "layout_alignTop"; } else if (myBeginSide == Side.bottom && myEndSide == Side.bottom) { - attribute = "android:layout_alignBottom"; + attribute = "layout_alignBottom"; } else if (myBeginSide == Side.top && myEndSide == Side.bottom) { - attribute = "android:layout_below"; + attribute = "layout_below"; } else if (myBeginSide == Side.bottom && myEndSide == Side.top) { - attribute = "android:layout_above"; + attribute = "layout_above"; } else if (myBeginSide == Side.left && myEndSide == Side.left) { - attribute = "android:layout_alignLeft"; + attribute = "layout_alignLeft"; } else if (myBeginSide == Side.right && myEndSide == Side.right) { - attribute = "android:layout_alignRight"; + attribute = "layout_alignRight"; } else if (myBeginSide == Side.left && myEndSide == Side.right) { - attribute = "android:layout_toRightOf"; + attribute = "layout_toRightOf"; } else if (myBeginSide == Side.right && myEndSide == Side.left) { - attribute = "android:layout_toLeftOf"; + attribute = "layout_toLeftOf"; } else { return; @@ -226,7 +227,7 @@ public class ComponentSnapPoint extends SnapPoint { for (RadComponent component : components) { XmlTag tag = ((RadViewComponent)component).getTag(); - tag.setAttribute(attribute, componentId); + tag.setAttribute(attribute, SdkConstants.NS_RESOURCES, componentId); } } }); diff --git a/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/relative/ContainerSnapPoint.java b/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/relative/ContainerSnapPoint.java index d00a7a1cdb9c..0c421b6b8e34 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/relative/ContainerSnapPoint.java +++ b/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/relative/ContainerSnapPoint.java @@ -15,6 +15,7 @@ */ package com.intellij.android.designer.designSurface.layout.relative; +import com.android.sdklib.SdkConstants; import com.intellij.android.designer.model.RadViewComponent; import com.intellij.designer.designSurface.feedbacks.TextFeedback; import com.intellij.designer.model.RadComponent; @@ -186,7 +187,7 @@ public class ContainerSnapPoint extends SnapPoint { if (attribute != null) { for (RadComponent component : components) { XmlTag tag = ((RadViewComponent)component).getTag(); - tag.setAttribute("android:layout_" + attribute, "true"); + tag.setAttribute("layout_" + attribute, SdkConstants.NS_RESOURCES, "true"); } } } diff --git a/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/relative/ResizeComponentSnapPoint.java b/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/relative/ResizeComponentSnapPoint.java index 8ef19310c610..6143b2497b62 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/relative/ResizeComponentSnapPoint.java +++ b/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/relative/ResizeComponentSnapPoint.java @@ -104,20 +104,20 @@ public class ResizeComponentSnapPoint extends ResizeSnapPoint { XmlTag tag = ((RadViewComponent)components.get(0)).getTag(); if (mySide == Side.top) { - ModelParser.deleteAttribute(tag, "android:layout_alignParentTop"); - ModelParser.deleteAttribute(tag, "android:layout_marginTop"); + ModelParser.deleteAttribute(tag, "layout_alignParentTop"); + ModelParser.deleteAttribute(tag, "layout_marginTop"); } else if (mySide == Side.bottom) { - ModelParser.deleteAttribute(tag, "android:layout_alignParentBottom"); - ModelParser.deleteAttribute(tag, "android:layout_marginBottom"); + ModelParser.deleteAttribute(tag, "layout_alignParentBottom"); + ModelParser.deleteAttribute(tag, "layout_marginBottom"); } else if (mySide == Side.left) { - ModelParser.deleteAttribute(tag, "android:layout_alignParentLeft"); - ModelParser.deleteAttribute(tag, "android:layout_marginLeft"); + ModelParser.deleteAttribute(tag, "layout_alignParentLeft"); + ModelParser.deleteAttribute(tag, "layout_marginLeft"); } else if (mySide == Side.right) { - ModelParser.deleteAttribute(tag, "android:layout_alignParentRight"); - ModelParser.deleteAttribute(tag, "android:layout_marginRight"); + ModelParser.deleteAttribute(tag, "layout_alignParentRight"); + ModelParser.deleteAttribute(tag, "layout_marginRight"); } } }); diff --git a/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/relative/ResizeContainerSnapPoint.java b/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/relative/ResizeContainerSnapPoint.java index 324932c2891d..82d5672b6afe 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/relative/ResizeContainerSnapPoint.java +++ b/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/relative/ResizeContainerSnapPoint.java @@ -70,24 +70,24 @@ public class ResizeContainerSnapPoint extends ResizeSnapPoint { XmlTag tag = ((RadViewComponent)components.get(0)).getTag(); if (mySide == Side.top) { - ModelParser.deleteAttribute(tag, "android:layout_alignTop"); - ModelParser.deleteAttribute(tag, "android:layout_below"); - ModelParser.deleteAttribute(tag, "android:layout_marginTop"); + ModelParser.deleteAttribute(tag, "layout_alignTop"); + ModelParser.deleteAttribute(tag, "layout_below"); + ModelParser.deleteAttribute(tag, "layout_marginTop"); } else if (mySide == Side.bottom) { - ModelParser.deleteAttribute(tag, "android:layout_alignBottom"); - ModelParser.deleteAttribute(tag, "android:layout_above"); - ModelParser.deleteAttribute(tag, "android:layout_marginBottom"); + ModelParser.deleteAttribute(tag, "layout_alignBottom"); + ModelParser.deleteAttribute(tag, "layout_above"); + ModelParser.deleteAttribute(tag, "layout_marginBottom"); } else if (mySide == Side.left) { - ModelParser.deleteAttribute(tag, "android:layout_alignLeft"); - ModelParser.deleteAttribute(tag, "android:layout_toRightOf"); - ModelParser.deleteAttribute(tag, "android:layout_marginLeft"); + ModelParser.deleteAttribute(tag, "layout_alignLeft"); + ModelParser.deleteAttribute(tag, "layout_toRightOf"); + ModelParser.deleteAttribute(tag, "layout_marginLeft"); } else if (mySide == Side.right) { - ModelParser.deleteAttribute(tag, "android:layout_alignRight"); - ModelParser.deleteAttribute(tag, "android:layout_toLeftOf"); - ModelParser.deleteAttribute(tag, "android:layout_marginRight"); + ModelParser.deleteAttribute(tag, "layout_alignRight"); + ModelParser.deleteAttribute(tag, "layout_toLeftOf"); + ModelParser.deleteAttribute(tag, "layout_marginRight"); } } }); diff --git a/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/relative/WrapSizeSnapPoint.java b/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/relative/WrapSizeSnapPoint.java index 144efca6a457..ccc59bdab591 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/relative/WrapSizeSnapPoint.java +++ b/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/relative/WrapSizeSnapPoint.java @@ -15,6 +15,7 @@ */ package com.intellij.android.designer.designSurface.layout.relative; +import com.android.sdklib.SdkConstants; import com.intellij.android.designer.model.ModelParser; import com.intellij.android.designer.model.RadViewComponent; import com.intellij.designer.designSurface.feedbacks.TextFeedback; @@ -68,8 +69,8 @@ public class WrapSizeSnapPoint extends ResizeSnapPoint { @Override public void run() { XmlTag tag = ((RadViewComponent)components.get(0)).getTag(); - ModelParser.deleteAttribute(tag, "android:layout_alignParent" + (myHorizontal ? "Right" : "Bottom")); - tag.setAttribute("android:layout_" + (myHorizontal ? "width" : "height"), "wrap_content"); + ModelParser.deleteAttribute(tag, "layout_alignParent" + (myHorizontal ? "Right" : "Bottom")); + tag.setAttribute("layout_" + (myHorizontal ? "width" : "height"), SdkConstants.NS_RESOURCES, "wrap_content"); } }); } diff --git a/plugins/android-designer/src/com/intellij/android/designer/model/IdManager.java b/plugins/android-designer/src/com/intellij/android/designer/model/IdManager.java index 8cc797b8ee94..d669ff5e1442 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/model/IdManager.java +++ b/plugins/android-designer/src/com/intellij/android/designer/model/IdManager.java @@ -15,6 +15,7 @@ */ package com.intellij.android.designer.model; +import com.android.sdklib.SdkConstants; import com.intellij.designer.model.RadComponent; import com.intellij.designer.model.RadComponentVisitor; import com.intellij.openapi.application.ApplicationManager; @@ -78,7 +79,7 @@ public class IdManager { myIdList.add(nextIdValue); String newId = "@+id/" + idValue + (index == 0 ? "" : Integer.toString(index)); - component.getTag().setAttribute("android:id", newId); + component.getTag().setAttribute("id", SdkConstants.NS_RESOURCES, newId); return newId; } diff --git a/plugins/android-designer/src/com/intellij/android/designer/model/ModelParser.java b/plugins/android-designer/src/com/intellij/android/designer/model/ModelParser.java index 19bf7ed3e681..ac1813d70e12 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/model/ModelParser.java +++ b/plugins/android-designer/src/com/intellij/android/designer/model/ModelParser.java @@ -17,6 +17,7 @@ package com.intellij.android.designer.model; import com.android.ide.common.rendering.api.RenderSession; import com.android.ide.common.rendering.api.ViewInfo; +import com.android.sdklib.SdkConstants; import com.intellij.android.designer.designSurface.AndroidPasteFactory; import com.intellij.android.designer.designSurface.RootView; import com.intellij.designer.model.MetaManager; @@ -306,6 +307,11 @@ public class ModelParser extends XmlRecursiveElementVisitor { XmlElementFactory.getInstance(project).createTagFromText("\n" + tagBuilder.compute(), language); if (checkTag(parentTag)) { + String namespacePrefix = parentTag.getPrefixByNamespace(SdkConstants.NS_RESOURCES); + if (!"android".equals(namespacePrefix)) { + convertNamespacePrefix(xmlTag, namespacePrefix); + } + if (nextTag == null) { xmlTag = parentTag.addSubTag(xmlTag, false); } @@ -314,7 +320,7 @@ public class ModelParser extends XmlRecursiveElementVisitor { } } else { - xmlTag.setAttribute("xmlns:android", "http://schemas.android.com/apk/res/android"); + xmlTag.setAttribute("xmlns:android", SdkConstants.NS_RESOURCES); xmlTag = (XmlTag)xmlFile.getDocument().add(xmlTag); XmlUtil.expandTag(xmlTag); @@ -335,12 +341,23 @@ public class ModelParser extends XmlRecursiveElementVisitor { } } + private static void convertNamespacePrefix(XmlTag xmlTag, String namespacePrefix) { + for (XmlAttribute attribute : xmlTag.getAttributes()) { + if ("android".equals(attribute.getNamespacePrefix())) { + attribute.setName(namespacePrefix + ":" + attribute.getLocalName()); + } + } + for (XmlTag subTag : xmlTag.getSubTags()) { + convertNamespacePrefix(subTag, namespacePrefix); + } + } + public static void deleteAttribute(RadComponent component, String name) { deleteAttribute(((RadViewComponent)component).getTag(), name); } public static void deleteAttribute(XmlTag tag, String name) { - XmlAttribute attribute = tag.getAttribute(name); + XmlAttribute attribute = tag.getAttribute(name, SdkConstants.NS_RESOURCES); if (attribute != null) { attribute.delete(); } diff --git a/plugins/android-designer/src/com/intellij/android/designer/model/RadViewComponent.java b/plugins/android-designer/src/com/intellij/android/designer/model/RadViewComponent.java index 4554f6330ddb..fce666c5e4eb 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/model/RadViewComponent.java +++ b/plugins/android-designer/src/com/intellij/android/designer/model/RadViewComponent.java @@ -16,6 +16,7 @@ package com.intellij.android.designer.model; import com.android.ide.common.rendering.api.ViewInfo; +import com.android.sdklib.SdkConstants; import com.intellij.designer.model.MetaModel; import com.intellij.designer.model.RadComponent; import com.intellij.designer.model.RadVisualComponent; @@ -91,7 +92,7 @@ public class RadViewComponent extends RadVisualComponent { } public String getId() { - String idValue = myTag.getAttributeValue("android:id"); + String idValue = myTag.getAttributeValue("id", SdkConstants.NS_RESOURCES); return StringUtil.isEmpty(idValue) ? null : idValue; } diff --git a/plugins/android-designer/src/com/intellij/android/designer/model/layout/Gravity.java b/plugins/android-designer/src/com/intellij/android/designer/model/layout/Gravity.java index 060633782da6..ed5110661539 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/model/layout/Gravity.java +++ b/plugins/android-designer/src/com/intellij/android/designer/model/layout/Gravity.java @@ -15,6 +15,7 @@ */ package com.intellij.android.designer.model.layout; +import com.android.sdklib.SdkConstants; import com.intellij.android.designer.model.RadViewComponent; import com.intellij.designer.model.RadComponent; import com.intellij.openapi.util.IconLoader; @@ -92,7 +93,7 @@ public enum Gravity { } public static int getFlags(RadComponent component) { - String value = ((RadViewComponent)component).getTag().getAttributeValue("android:layout_gravity"); + String value = ((RadViewComponent)component).getTag().getAttributeValue("layout_gravity", SdkConstants.NS_RESOURCES); int flags = NONE; if (!StringUtil.isEmpty(value)) { diff --git a/plugins/android-designer/src/com/intellij/android/designer/model/layout/RadFrameLayout.java b/plugins/android-designer/src/com/intellij/android/designer/model/layout/RadFrameLayout.java index 899357747bb4..ec157eaf0a09 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/model/layout/RadFrameLayout.java +++ b/plugins/android-designer/src/com/intellij/android/designer/model/layout/RadFrameLayout.java @@ -15,6 +15,7 @@ */ package com.intellij.android.designer.model.layout; +import com.android.sdklib.SdkConstants; import com.intellij.android.designer.designSurface.TreeDropToOperation; import com.intellij.android.designer.designSurface.layout.FrameLayoutOperation; import com.intellij.android.designer.designSurface.layout.actions.LayoutMarginOperation; @@ -172,7 +173,7 @@ public class RadFrameLayout extends RadViewLayoutWithData { execute(new Runnable() { @Override public void run() { - ((RadViewComponent)myComponents.get(0)).getTag().setAttribute("android:layout_gravity", gravity); + ((RadViewComponent)myComponents.get(0)).getTag().setAttribute("layout_gravity", SdkConstants.NS_RESOURCES, gravity); } }); } diff --git a/plugins/android-designer/src/com/intellij/android/designer/model/layout/RadLinearLayout.java b/plugins/android-designer/src/com/intellij/android/designer/model/layout/RadLinearLayout.java index 5553f127fe7d..eb2336da5441 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/model/layout/RadLinearLayout.java +++ b/plugins/android-designer/src/com/intellij/android/designer/model/layout/RadLinearLayout.java @@ -1,352 +1,354 @@ -/* - * Copyright 2000-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.android.designer.model.layout; - -import com.intellij.android.designer.designSurface.TreeDropToOperation; -import com.intellij.android.designer.designSurface.layout.LinearLayoutOperation; -import com.intellij.android.designer.designSurface.layout.actions.LayoutMarginOperation; -import com.intellij.android.designer.designSurface.layout.actions.LayoutWeightOperation; -import com.intellij.android.designer.designSurface.layout.actions.ResizeOperation; -import com.intellij.android.designer.designSurface.layout.flow.FlowStaticDecorator; -import com.intellij.android.designer.model.ModelParser; -import com.intellij.android.designer.model.RadViewComponent; -import com.intellij.android.designer.model.RadViewLayoutWithData; -import com.intellij.android.designer.model.layout.actions.AbstractGravityAction; -import com.intellij.android.designer.model.layout.actions.OrientationAction; -import com.intellij.designer.componentTree.TreeEditOperation; -import com.intellij.designer.designSurface.*; -import com.intellij.designer.designSurface.selection.DirectionResizePoint; -import com.intellij.designer.designSurface.selection.ResizePoint; -import com.intellij.designer.designSurface.selection.ResizeSelectionDecorator; -import com.intellij.designer.model.RadComponent; -import com.intellij.designer.utils.Position; -import com.intellij.openapi.actionSystem.DefaultActionGroup; -import com.intellij.openapi.actionSystem.Presentation; -import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.util.Pair; -import org.jetbrains.annotations.NotNull; - -import javax.swing.*; -import java.awt.*; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; - -/** - * @author Alexander Lobas - */ -public class RadLinearLayout extends RadViewLayoutWithData implements ILayoutDecorator { - private static final String[] LAYOUT_PARAMS = {"LinearLayout_Layout", "ViewGroup_MarginLayout"}; - - private ResizeSelectionDecorator mySelectionDecorator; - private FlowStaticDecorator myLineDecorator; - - @Override - @NotNull - public String[] getLayoutParams() { - return LAYOUT_PARAMS; - } - - public boolean isHorizontal() { - return !"vertical".equals(((RadViewComponent)myContainer).getTag().getAttributeValue("android:orientation")); - } - - @Override - public EditOperation processChildOperation(OperationContext context) { - if (context.isCreate() || context.isPaste() || context.isAdd() || context.isMove()) { - if (context.isTree()) { - if (TreeEditOperation.isTarget(myContainer, context)) { - return new TreeDropToOperation(myContainer, context); - } - return null; - } - return new LinearLayoutOperation(myContainer, context, isHorizontal()); - } - if (context.is(ResizeOperation.TYPE)) { - return new ResizeOperation(context); - } - if (context.is(LayoutMarginOperation.TYPE)) { - return new LayoutMarginOperation(context); - } - if (context.is(LayoutWeightOperation.TYPE)) { - return new LayoutWeightOperation(context); - } - return null; - } - - private StaticDecorator getLineDecorator() { - if (myLineDecorator == null) { - myLineDecorator = new FlowStaticDecorator(myContainer) { - @Override - protected boolean isHorizontal() { - return RadLinearLayout.this.isHorizontal(); - } - }; - } - return myLineDecorator; - } - - @Override - public void addStaticDecorators(List decorators, List selection) { - if (selection.contains(myContainer)) { - if (!(myContainer.getParent().getLayout() instanceof ILayoutDecorator)) { - decorators.add(getLineDecorator()); - } - } - else { - for (RadComponent component : selection) { - if (component.getParent() == myContainer) { - decorators.add(getLineDecorator()); - return; - } - } - super.addStaticDecorators(decorators, selection); - } - } - - private static final int POINTS_SIZE = 16; - - @Override - public ComponentDecorator getChildSelectionDecorator(RadComponent component, List selection) { - if (mySelectionDecorator == null) { - mySelectionDecorator = new ResizeSelectionDecorator(Color.red, 1) { - @Override - protected boolean visible(RadComponent component, ResizePoint point) { - if (point.getType() == LayoutMarginOperation.TYPE) { - boolean horizontal = isHorizontal(); - Pair gravity = Gravity.getSides(component); - int direction = ((DirectionResizePoint)point).getDirection(); - Rectangle bounds = component.getBounds(); - boolean goodWidth = bounds.width >= POINTS_SIZE; - boolean goodHeight = bounds.height >= POINTS_SIZE; - - if (direction == Position.WEST) { // left - return (horizontal || gravity.first != Gravity.right) && goodHeight; - } - if (direction == Position.EAST) { // right - return (horizontal || gravity.first != Gravity.left) && goodHeight; - } - if (direction == Position.NORTH) { // top - return (!horizontal || gravity.second != Gravity.bottom) && goodWidth; - } - if (direction == Position.SOUTH) { // bottom - return (!horizontal || gravity.second != Gravity.top) && goodWidth; - } - } - if (point.getType() == LayoutWeightOperation.TYPE) { - int direction = ((DirectionResizePoint)point).getDirection(); - - if (direction == Position.EAST) { // right - return isHorizontal() && component.getBounds().height >= POINTS_SIZE; - } - if (direction == Position.SOUTH) { // bottom - return !isHorizontal() && component.getBounds().width >= POINTS_SIZE; - } - } - return true; - } - }; - } - - mySelectionDecorator.clear(); - if (selection.size() == 1) { - LayoutMarginOperation.points(mySelectionDecorator); - LayoutWeightOperation.point(mySelectionDecorator); - } - ResizeOperation.points(mySelectionDecorator); - - return mySelectionDecorator; - } - - ////////////////////////////////////////////////////////////////////////////////////////// - // - // Actions - // - ////////////////////////////////////////////////////////////////////////////////////////// - - @Override - public void addContainerSelectionActions(DesignerEditorPanel designer, - DefaultActionGroup actionGroup, - JComponent shortcuts, - List selection) { - if (selection.get(selection.size() - 1) != myContainer) { - return; - } - for (RadComponent component : selection) { - if (!(component.getLayout() instanceof RadLinearLayout)) { - return; - } - } - - createOrientationAction(designer, actionGroup, shortcuts, selection); - } - - private static final List HORIZONTALS = Arrays.asList(Gravity.left, Gravity.center, Gravity.right, null); - private static final List VERTICALS = Arrays.asList(Gravity.top, Gravity.center, Gravity.bottom, null); - - @Override - public void addSelectionActions(DesignerEditorPanel designer, - DefaultActionGroup actionGroup, - JComponent shortcuts, - List selection) { - for (RadComponent component : selection) { - if (component.getParent() != myContainer) { - return; - } - } - - createOrientationAction(designer, actionGroup, shortcuts, Arrays.asList(myContainer)); - actionGroup.add(new GravityAction(designer, selection)); - } - - private class GravityAction extends AbstractGravityAction { - private Gravity mySelection; - - public GravityAction(DesignerEditorPanel designer, List components) { - super(designer, components); - } - - @NotNull - @Override - protected DefaultActionGroup createPopupActionGroup(JComponent button) { - boolean horizontal = isHorizontal(); - Gravity unknown = horizontal ? Gravity.left : Gravity.top; - setItems(horizontal ? VERTICALS : HORIZONTALS, unknown); - - Iterator I = myComponents.iterator(); - mySelection = LinearLayoutOperation.getGravity(horizontal, I.next()); - - while (I.hasNext()) { - if (mySelection != LinearLayoutOperation.getGravity(horizontal, I.next())) { - mySelection = unknown; - break; - } - } - - return super.createPopupActionGroup(button); - } - - @Override - protected void update(Gravity item, Presentation presentation, boolean popup) { - if (popup) { - presentation.setIcon(mySelection == item ? CHECKED : null); - presentation.setText(item == null ? "fill" : item.name()); - } - } - - @Override - protected boolean selectionChanged(final Gravity item) { - execute(new Runnable() { - @Override - public void run() { - LinearLayoutOperation.execute(isHorizontal(), item, myComponents); - } - }); - - return false; - } - - @Override - public void update() { - } - } - - private static void createOrientationAction(DesignerEditorPanel designer, - DefaultActionGroup actionGroup, - JComponent shortcuts, - List components) { - boolean override = false; - Iterator I = components.iterator(); - boolean horizontal = ((RadLinearLayout)I.next().getLayout()).isHorizontal(); - - while (I.hasNext()) { - boolean next = ((RadLinearLayout)I.next().getLayout()).isHorizontal(); - if (horizontal != next) { - override = true; - break; - } - } - - actionGroup.add(new OrientationAction(designer, components, horizontal, override)); - } - - @Override - public boolean isWrapIn(List components) { - List children = myContainer.getChildren(); - - int[] indexes = new int[components.size()]; - for (int i = 0; i < indexes.length; i++) { - indexes[i] = children.indexOf(components.get(i)); - } - Arrays.sort(indexes); - - for (int i = 0; i < indexes.length - 1; i++) { - if (indexes[i + 1] - indexes[i] != 1) { - return false; - } - } - - return true; - } - - @Override - public void wrapIn(final RadViewComponent newParent, final List components) throws Exception { - final boolean horizontal = isHorizontal(); - RadViewComponent firstComponent = components.get(0); - boolean single = components.size() == 1; - String layoutWidth = single ? firstComponent.getTag().getAttributeValue("android:layout_width") : "wrap_content"; - String layoutHeight = single ? firstComponent.getTag().getAttributeValue("android:layout_height") : "wrap_content"; - String layoutGravity = firstComponent.getTag().getAttributeValue("android:layout_gravity"); - - if (horizontal) { - for (RadViewComponent component : components.subList(1, components.size())) { - String height = component.getTag().getAttributeValue("android:layout_height"); - if ("fill_parent".equals(height) || "match_parent".equals(height)) { - layoutHeight = "fill_parent"; - layoutGravity = null; - } - if (layoutGravity != null && layoutGravity.equals(component.getTag().getAttributeValue("android:layout_gravity"))) { - - } - } - } - else { - - } - - if (newParent.getLayout() instanceof RadLinearLayout) { - RadLinearLayout layout = (RadLinearLayout)newParent.getLayout(); - if (horizontal != layout.isHorizontal()) { - ApplicationManager.getApplication().runWriteAction(new Runnable() { - @Override - public void run() { - newParent.getTag().setAttribute("android:orientation", horizontal ? "horizontal" : "vertical"); - } - }); - } - } - else { - ApplicationManager.getApplication().runWriteAction(new Runnable() { - @Override - public void run() { - for (RadViewComponent component : components) { - ModelParser.deleteAttribute(component.getTag(), "android:layout_gravity"); - } - } - }); - } - } +/* + * Copyright 2000-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.android.designer.model.layout; + +import com.android.sdklib.SdkConstants; +import com.intellij.android.designer.designSurface.TreeDropToOperation; +import com.intellij.android.designer.designSurface.layout.LinearLayoutOperation; +import com.intellij.android.designer.designSurface.layout.actions.LayoutMarginOperation; +import com.intellij.android.designer.designSurface.layout.actions.LayoutWeightOperation; +import com.intellij.android.designer.designSurface.layout.actions.ResizeOperation; +import com.intellij.android.designer.designSurface.layout.flow.FlowStaticDecorator; +import com.intellij.android.designer.model.ModelParser; +import com.intellij.android.designer.model.RadViewComponent; +import com.intellij.android.designer.model.RadViewLayoutWithData; +import com.intellij.android.designer.model.layout.actions.AbstractGravityAction; +import com.intellij.android.designer.model.layout.actions.OrientationAction; +import com.intellij.designer.componentTree.TreeEditOperation; +import com.intellij.designer.designSurface.*; +import com.intellij.designer.designSurface.selection.DirectionResizePoint; +import com.intellij.designer.designSurface.selection.ResizePoint; +import com.intellij.designer.designSurface.selection.ResizeSelectionDecorator; +import com.intellij.designer.model.RadComponent; +import com.intellij.designer.utils.Position; +import com.intellij.openapi.actionSystem.DefaultActionGroup; +import com.intellij.openapi.actionSystem.Presentation; +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.util.Pair; +import org.jetbrains.annotations.NotNull; + +import javax.swing.*; +import java.awt.*; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; + +/** + * @author Alexander Lobas + */ +public class RadLinearLayout extends RadViewLayoutWithData implements ILayoutDecorator { + private static final String[] LAYOUT_PARAMS = {"LinearLayout_Layout", "ViewGroup_MarginLayout"}; + + private ResizeSelectionDecorator mySelectionDecorator; + private FlowStaticDecorator myLineDecorator; + + @Override + @NotNull + public String[] getLayoutParams() { + return LAYOUT_PARAMS; + } + + public boolean isHorizontal() { + return !"vertical".equals(((RadViewComponent)myContainer).getTag().getAttributeValue("orientation", SdkConstants.NS_RESOURCES)); + } + + @Override + public EditOperation processChildOperation(OperationContext context) { + if (context.isCreate() || context.isPaste() || context.isAdd() || context.isMove()) { + if (context.isTree()) { + if (TreeEditOperation.isTarget(myContainer, context)) { + return new TreeDropToOperation(myContainer, context); + } + return null; + } + return new LinearLayoutOperation(myContainer, context, isHorizontal()); + } + if (context.is(ResizeOperation.TYPE)) { + return new ResizeOperation(context); + } + if (context.is(LayoutMarginOperation.TYPE)) { + return new LayoutMarginOperation(context); + } + if (context.is(LayoutWeightOperation.TYPE)) { + return new LayoutWeightOperation(context); + } + return null; + } + + private StaticDecorator getLineDecorator() { + if (myLineDecorator == null) { + myLineDecorator = new FlowStaticDecorator(myContainer) { + @Override + protected boolean isHorizontal() { + return RadLinearLayout.this.isHorizontal(); + } + }; + } + return myLineDecorator; + } + + @Override + public void addStaticDecorators(List decorators, List selection) { + if (selection.contains(myContainer)) { + if (!(myContainer.getParent().getLayout() instanceof ILayoutDecorator)) { + decorators.add(getLineDecorator()); + } + } + else { + for (RadComponent component : selection) { + if (component.getParent() == myContainer) { + decorators.add(getLineDecorator()); + return; + } + } + super.addStaticDecorators(decorators, selection); + } + } + + private static final int POINTS_SIZE = 16; + + @Override + public ComponentDecorator getChildSelectionDecorator(RadComponent component, List selection) { + if (mySelectionDecorator == null) { + mySelectionDecorator = new ResizeSelectionDecorator(Color.red, 1) { + @Override + protected boolean visible(RadComponent component, ResizePoint point) { + if (point.getType() == LayoutMarginOperation.TYPE) { + boolean horizontal = isHorizontal(); + Pair gravity = Gravity.getSides(component); + int direction = ((DirectionResizePoint)point).getDirection(); + Rectangle bounds = component.getBounds(); + boolean goodWidth = bounds.width >= POINTS_SIZE; + boolean goodHeight = bounds.height >= POINTS_SIZE; + + if (direction == Position.WEST) { // left + return (horizontal || gravity.first != Gravity.right) && goodHeight; + } + if (direction == Position.EAST) { // right + return (horizontal || gravity.first != Gravity.left) && goodHeight; + } + if (direction == Position.NORTH) { // top + return (!horizontal || gravity.second != Gravity.bottom) && goodWidth; + } + if (direction == Position.SOUTH) { // bottom + return (!horizontal || gravity.second != Gravity.top) && goodWidth; + } + } + if (point.getType() == LayoutWeightOperation.TYPE) { + int direction = ((DirectionResizePoint)point).getDirection(); + + if (direction == Position.EAST) { // right + return isHorizontal() && component.getBounds().height >= POINTS_SIZE; + } + if (direction == Position.SOUTH) { // bottom + return !isHorizontal() && component.getBounds().width >= POINTS_SIZE; + } + } + return true; + } + }; + } + + mySelectionDecorator.clear(); + if (selection.size() == 1) { + LayoutMarginOperation.points(mySelectionDecorator); + LayoutWeightOperation.point(mySelectionDecorator); + } + ResizeOperation.points(mySelectionDecorator); + + return mySelectionDecorator; + } + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // Actions + // + ////////////////////////////////////////////////////////////////////////////////////////// + + @Override + public void addContainerSelectionActions(DesignerEditorPanel designer, + DefaultActionGroup actionGroup, + JComponent shortcuts, + List selection) { + if (selection.get(selection.size() - 1) != myContainer) { + return; + } + for (RadComponent component : selection) { + if (!(component.getLayout() instanceof RadLinearLayout)) { + return; + } + } + + createOrientationAction(designer, actionGroup, shortcuts, selection); + } + + private static final List HORIZONTALS = Arrays.asList(Gravity.left, Gravity.center, Gravity.right, null); + private static final List VERTICALS = Arrays.asList(Gravity.top, Gravity.center, Gravity.bottom, null); + + @Override + public void addSelectionActions(DesignerEditorPanel designer, + DefaultActionGroup actionGroup, + JComponent shortcuts, + List selection) { + for (RadComponent component : selection) { + if (component.getParent() != myContainer) { + return; + } + } + + createOrientationAction(designer, actionGroup, shortcuts, Arrays.asList(myContainer)); + actionGroup.add(new GravityAction(designer, selection)); + } + + private class GravityAction extends AbstractGravityAction { + private Gravity mySelection; + + public GravityAction(DesignerEditorPanel designer, List components) { + super(designer, components); + } + + @NotNull + @Override + protected DefaultActionGroup createPopupActionGroup(JComponent button) { + boolean horizontal = isHorizontal(); + Gravity unknown = horizontal ? Gravity.left : Gravity.top; + setItems(horizontal ? VERTICALS : HORIZONTALS, unknown); + + Iterator I = myComponents.iterator(); + mySelection = LinearLayoutOperation.getGravity(horizontal, I.next()); + + while (I.hasNext()) { + if (mySelection != LinearLayoutOperation.getGravity(horizontal, I.next())) { + mySelection = unknown; + break; + } + } + + return super.createPopupActionGroup(button); + } + + @Override + protected void update(Gravity item, Presentation presentation, boolean popup) { + if (popup) { + presentation.setIcon(mySelection == item ? CHECKED : null); + presentation.setText(item == null ? "fill" : item.name()); + } + } + + @Override + protected boolean selectionChanged(final Gravity item) { + execute(new Runnable() { + @Override + public void run() { + LinearLayoutOperation.execute(isHorizontal(), item, myComponents); + } + }); + + return false; + } + + @Override + public void update() { + } + } + + private static void createOrientationAction(DesignerEditorPanel designer, + DefaultActionGroup actionGroup, + JComponent shortcuts, + List components) { + boolean override = false; + Iterator I = components.iterator(); + boolean horizontal = ((RadLinearLayout)I.next().getLayout()).isHorizontal(); + + while (I.hasNext()) { + boolean next = ((RadLinearLayout)I.next().getLayout()).isHorizontal(); + if (horizontal != next) { + override = true; + break; + } + } + + actionGroup.add(new OrientationAction(designer, components, horizontal, override)); + } + + @Override + public boolean isWrapIn(List components) { + List children = myContainer.getChildren(); + + int[] indexes = new int[components.size()]; + for (int i = 0; i < indexes.length; i++) { + indexes[i] = children.indexOf(components.get(i)); + } + Arrays.sort(indexes); + + for (int i = 0; i < indexes.length - 1; i++) { + if (indexes[i + 1] - indexes[i] != 1) { + return false; + } + } + + return true; + } + + @Override + public void wrapIn(final RadViewComponent newParent, final List components) throws Exception { + final boolean horizontal = isHorizontal(); + RadViewComponent firstComponent = components.get(0); + boolean single = components.size() == 1; + String layoutWidth = single ? firstComponent.getTag().getAttributeValue("layout_width", SdkConstants.NS_RESOURCES) : "wrap_content"; + String layoutHeight = single ? firstComponent.getTag().getAttributeValue("layout_height", SdkConstants.NS_RESOURCES) : "wrap_content"; + String layoutGravity = firstComponent.getTag().getAttributeValue("layout_gravity", SdkConstants.NS_RESOURCES); + + if (horizontal) { + for (RadViewComponent component : components.subList(1, components.size())) { + String height = component.getTag().getAttributeValue("layout_height", SdkConstants.NS_RESOURCES); + if ("fill_parent".equals(height) || "match_parent".equals(height)) { + layoutHeight = "fill_parent"; + layoutGravity = null; + } + if (layoutGravity != null && + layoutGravity.equals(component.getTag().getAttributeValue("layout_gravity", SdkConstants.NS_RESOURCES))) { + + } + } + } + else { + + } + + if (newParent.getLayout() instanceof RadLinearLayout) { + RadLinearLayout layout = (RadLinearLayout)newParent.getLayout(); + if (horizontal != layout.isHorizontal()) { + ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override + public void run() { + newParent.getTag().setAttribute("orientation", SdkConstants.NS_RESOURCES, horizontal ? "horizontal" : "vertical"); + } + }); + } + } + else { + ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override + public void run() { + for (RadViewComponent component : components) { + ModelParser.deleteAttribute(component.getTag(), "layout_gravity"); + } + } + }); + } + } } \ No newline at end of file diff --git a/plugins/android-designer/src/com/intellij/android/designer/model/layout/RadRadioGroupLayout.java b/plugins/android-designer/src/com/intellij/android/designer/model/layout/RadRadioGroupLayout.java index 6f6af85b40ab..a0ca35952ab4 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/model/layout/RadRadioGroupLayout.java +++ b/plugins/android-designer/src/com/intellij/android/designer/model/layout/RadRadioGroupLayout.java @@ -15,6 +15,7 @@ */ package com.intellij.android.designer.model.layout; +import com.android.sdklib.SdkConstants; import com.intellij.android.designer.model.RadViewComponent; /** @@ -23,6 +24,6 @@ import com.intellij.android.designer.model.RadViewComponent; public class RadRadioGroupLayout extends RadLinearLayout { @Override public boolean isHorizontal() { - return "horizontal".equals(((RadViewComponent)myContainer).getTag().getAttributeValue("android:orientation")); + return "horizontal".equals(((RadViewComponent)myContainer).getTag().getAttributeValue("orientation", SdkConstants.NS_RESOURCES)); } } \ No newline at end of file diff --git a/plugins/android-designer/src/com/intellij/android/designer/model/layout/actions/AllGravityAction.java b/plugins/android-designer/src/com/intellij/android/designer/model/layout/actions/AllGravityAction.java index db15242f30dc..9d4e1380349f 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/model/layout/actions/AllGravityAction.java +++ b/plugins/android-designer/src/com/intellij/android/designer/model/layout/actions/AllGravityAction.java @@ -15,6 +15,7 @@ */ package com.intellij.android.designer.model.layout.actions; +import com.android.sdklib.SdkConstants; import com.intellij.android.designer.model.ModelParser; import com.intellij.android.designer.model.RadViewComponent; import com.intellij.android.designer.model.layout.Gravity; @@ -81,7 +82,7 @@ public class AllGravityAction extends AbstractGravityAction { public void run() { if (mySelection.isEmpty()) { for (RadComponent component : myComponents) { - ModelParser.deleteAttribute(component, "android:layout_gravity"); + ModelParser.deleteAttribute(component, "layout_gravity"); } } else { @@ -94,7 +95,7 @@ public class AllGravityAction extends AbstractGravityAction { for (RadComponent component : myComponents) { XmlTag tag = ((RadViewComponent)component).getTag(); - tag.setAttribute("android:layout_gravity", value); + tag.setAttribute("layout_gravity", SdkConstants.NS_RESOURCES, value); } } } diff --git a/plugins/android-designer/src/com/intellij/android/designer/model/layout/actions/OrientationAction.java b/plugins/android-designer/src/com/intellij/android/designer/model/layout/actions/OrientationAction.java index fad6cddeb031..0c9b68c209a2 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/model/layout/actions/OrientationAction.java +++ b/plugins/android-designer/src/com/intellij/android/designer/model/layout/actions/OrientationAction.java @@ -15,6 +15,7 @@ */ package com.intellij.android.designer.model.layout.actions; +import com.android.sdklib.SdkConstants; import com.intellij.android.designer.model.RadViewComponent; import com.intellij.designer.designSurface.DesignerEditorPanel; import com.intellij.designer.model.RadComponent; @@ -59,7 +60,7 @@ public class OrientationAction extends AnAction { public void run() { String value = mySelection ? "horizontal" : "vertical"; for (RadComponent component : myComponents) { - ((RadViewComponent)component).getTag().setAttribute("android:orientation", value); + ((RadViewComponent)component).getTag().setAttribute("orientation", SdkConstants.NS_RESOURCES, value); } } }); diff --git a/plugins/android-designer/src/com/intellij/android/designer/model/layout/grid/RadGridLayoutComponent.java b/plugins/android-designer/src/com/intellij/android/designer/model/layout/grid/RadGridLayoutComponent.java index 90c3a7cb9684..4f22fd067559 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/model/layout/grid/RadGridLayoutComponent.java +++ b/plugins/android-designer/src/com/intellij/android/designer/model/layout/grid/RadGridLayoutComponent.java @@ -16,6 +16,7 @@ package com.intellij.android.designer.model.layout.grid; import com.android.ide.common.rendering.api.ViewInfo; +import com.android.sdklib.SdkConstants; import com.intellij.android.designer.model.ModelParser; import com.intellij.android.designer.model.RadViewComponent; import com.intellij.android.designer.model.RadViewContainer; @@ -46,10 +47,10 @@ public class RadGridLayoutComponent extends RadViewContainer implements ICompone XmlTag tag = getTag(); StringBuilder value = new StringBuilder(" ("); - String rowCount = tag.getAttributeValue("android:rowCount"); + String rowCount = tag.getAttributeValue("rowCount", SdkConstants.NS_RESOURCES); value.append(StringUtil.isEmpty(rowCount) ? "?" : rowCount).append(", "); - String columnCount = tag.getAttributeValue("android:columnCount"); + String columnCount = tag.getAttributeValue("columnCount", SdkConstants.NS_RESOURCES); value.append(StringUtil.isEmpty(columnCount) ? "?" : columnCount).append(", "); value.append(isHorizontal() ? "horizontal" : "vertical"); @@ -58,7 +59,7 @@ public class RadGridLayoutComponent extends RadViewContainer implements ICompone } public boolean isHorizontal() { - return !"vertical".equals(getTag().getAttributeValue("android:orientation")); + return !"vertical".equals(getTag().getAttributeValue("orientation", SdkConstants.NS_RESOURCES)); } @Override @@ -249,13 +250,13 @@ public class RadGridLayoutComponent extends RadViewContainer implements ICompone @Override public void run() { XmlTag tag = ((RadViewComponent)component).getTag(); - tag.setAttribute("android:layout_row", Integer.toString(row)); - tag.setAttribute("android:layout_column", Integer.toString(column)); + tag.setAttribute("layout_row", SdkConstants.NS_RESOURCES, Integer.toString(row)); + tag.setAttribute("layout_column", SdkConstants.NS_RESOURCES, Integer.toString(column)); if (clearRowSpan) { - ModelParser.deleteAttribute(tag, "android:layout_rowSpan"); + ModelParser.deleteAttribute(tag, "layout_rowSpan"); } if (clearColumnSpan) { - ModelParser.deleteAttribute(tag, "android:layout_columnSpan"); + ModelParser.deleteAttribute(tag, "layout_columnSpan"); } } }); @@ -263,7 +264,8 @@ public class RadGridLayoutComponent extends RadViewContainer implements ICompone public static int getSpan(RadComponent component, boolean row) { try { - String span = ((RadViewComponent)component).getTag().getAttributeValue(row ? "android:layout_rowSpan" : "android:layout_columnSpan"); + String span = + ((RadViewComponent)component).getTag().getAttributeValue(row ? "layout_rowSpan" : "layout_columnSpan", SdkConstants.NS_RESOURCES); return Integer.parseInt(span); } catch (Throwable e) { @@ -276,7 +278,7 @@ public class RadGridLayoutComponent extends RadViewContainer implements ICompone @Override public void run() { XmlTag tag = ((RadViewComponent)component).getTag(); - tag.setAttribute(row ? "android:layout_rowSpan" : "android:layout_columnSpan", Integer.toString(span)); + tag.setAttribute(row ? "layout_rowSpan" : "layout_columnSpan", SdkConstants.NS_RESOURCES, Integer.toString(span)); } }); } @@ -286,8 +288,8 @@ public class RadGridLayoutComponent extends RadViewContainer implements ICompone @Override public void run() { XmlTag tag = ((RadViewComponent)component).getTag(); - ModelParser.deleteAttribute(tag, "android:layout_rowSpan"); - ModelParser.deleteAttribute(tag, "android:layout_columnSpan"); + ModelParser.deleteAttribute(tag, "layout_rowSpan"); + ModelParser.deleteAttribute(tag, "layout_columnSpan"); } }); } diff --git a/plugins/android-designer/src/com/intellij/android/designer/model/layout/relative/CenterProperty.java b/plugins/android-designer/src/com/intellij/android/designer/model/layout/relative/CenterProperty.java index 1a46899760fd..8b95d525ed2a 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/model/layout/relative/CenterProperty.java +++ b/plugins/android-designer/src/com/intellij/android/designer/model/layout/relative/CenterProperty.java @@ -15,6 +15,7 @@ */ package com.intellij.android.designer.model.layout.relative; +import com.android.sdklib.SdkConstants; import com.intellij.android.designer.model.ModelParser; import com.intellij.android.designer.model.RadViewComponent; import com.intellij.android.designer.propertyTable.IXmlAttributeLocator; @@ -36,8 +37,7 @@ import org.jetbrains.annotations.Nullable; */ public class CenterProperty extends Property implements IXmlAttributeLocator { private static final String[] COMBO_ITEMS = {"horizontal", "vertical", "both"}; - private static final String[] ATTR_ITEMS = - {"android:layout_centerHorizontal", "android:layout_centerVertical", "android:layout_centerInParent"}; + private static final String[] ATTR_ITEMS = {"layout_centerHorizontal", "layout_centerVertical", "layout_centerInParent"}; private static final String JAVA_DOC = JavadocParser.build("layout:centerInParent", "Set centers this child horizontally or vertically within its parent."); @@ -54,7 +54,7 @@ public class CenterProperty extends Property implements IXmlAt XmlTag tag = component.getTag(); boolean[] values = new boolean[3]; for (int i = 0; i < ATTR_ITEMS.length; i++) { - values[i] = "true".equals(tag.getAttributeValue(ATTR_ITEMS[i])); + values[i] = "true".equals(tag.getAttributeValue(ATTR_ITEMS[i], SdkConstants.NS_RESOURCES)); } if (values[2] || (values[0] && values[1])) { return COMBO_ITEMS[2]; @@ -77,7 +77,7 @@ public class CenterProperty extends Property implements IXmlAt XmlTag tag = component.getTag(); for (int i = 0; i < ATTR_ITEMS.length; i++) { if (i == index) { - tag.setAttribute(ATTR_ITEMS[i], "true"); + tag.setAttribute(ATTR_ITEMS[i], SdkConstants.NS_RESOURCES, "true"); } else { ModelParser.deleteAttribute(tag, ATTR_ITEMS[i]); @@ -91,7 +91,7 @@ public class CenterProperty extends Property implements IXmlAt public boolean isDefaultValue(RadViewComponent component) throws Exception { XmlTag tag = component.getTag(); for (String attribute : ATTR_ITEMS) { - if (tag.getAttribute(attribute) != null) { + if (tag.getAttribute(attribute, SdkConstants.NS_RESOURCES) != null) { return false; } } @@ -128,7 +128,7 @@ public class CenterProperty extends Property implements IXmlAt public boolean checkAttribute(RadViewComponent component, XmlAttribute attribute) { XmlTag tag = component.getTag(); for (String name : ATTR_ITEMS) { - if (tag.getAttribute(name) == attribute) { + if (tag.getAttribute(name, SdkConstants.NS_RESOURCES) == attribute) { return true; } } diff --git a/plugins/android-designer/src/com/intellij/android/designer/model/layout/relative/RadRelativeLayoutComponent.java b/plugins/android-designer/src/com/intellij/android/designer/model/layout/relative/RadRelativeLayoutComponent.java index cd3efc8e1d64..8c14680fd324 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/model/layout/relative/RadRelativeLayoutComponent.java +++ b/plugins/android-designer/src/com/intellij/android/designer/model/layout/relative/RadRelativeLayoutComponent.java @@ -16,6 +16,7 @@ package com.intellij.android.designer.model.layout.relative; import com.android.ide.common.rendering.api.ViewInfo; +import com.android.sdklib.SdkConstants; import com.intellij.android.designer.model.RadViewComponent; import com.intellij.android.designer.model.RadViewContainer; import com.intellij.designer.model.RadComponent; @@ -52,25 +53,25 @@ public class RadRelativeLayoutComponent extends RadViewContainer { XmlTag tag = ((RadViewComponent)child).getTag(); - info.alignTop = getComponent(idToComponent, tag, "android:layout_alignTop"); - info.alignBottom = getComponent(idToComponent, tag, "android:layout_alignBottom"); - info.alignLeft = getComponent(idToComponent, tag, "android:layout_alignLeft"); - info.alignRight = getComponent(idToComponent, tag, "android:layout_alignRight"); - info.alignBaseline = getComponent(idToComponent, tag, "android:layout_alignBaseline"); - info.above = getComponent(idToComponent, tag, "android:layout_above"); - info.below = getComponent(idToComponent, tag, "android:layout_below"); - info.toLeftOf = getComponent(idToComponent, tag, "android:layout_toLeftOf"); - info.toRightOf = getComponent(idToComponent, tag, "android:layout_toRightOf"); + info.alignTop = getComponent(idToComponent, tag, "layout_alignTop"); + info.alignBottom = getComponent(idToComponent, tag, "layout_alignBottom"); + info.alignLeft = getComponent(idToComponent, tag, "layout_alignLeft"); + info.alignRight = getComponent(idToComponent, tag, "layout_alignRight"); + info.alignBaseline = getComponent(idToComponent, tag, "layout_alignBaseline"); + info.above = getComponent(idToComponent, tag, "layout_above"); + info.below = getComponent(idToComponent, tag, "layout_below"); + info.toLeftOf = getComponent(idToComponent, tag, "layout_toLeftOf"); + info.toRightOf = getComponent(idToComponent, tag, "layout_toRightOf"); - info.parentTop = "true".equals(tag.getAttributeValue("android:layout_alignParentTop")); - info.parentBottom = "true".equals(tag.getAttributeValue("android:layout_alignParentBottom")); - info.parentLeft = "true".equals(tag.getAttributeValue("android:layout_alignParentLeft")); - info.parentRight = "true".equals(tag.getAttributeValue("android:layout_alignParentRight")); + info.parentTop = "true".equals(tag.getAttributeValue("layout_alignParentTop", SdkConstants.NS_RESOURCES)); + info.parentBottom = "true".equals(tag.getAttributeValue("layout_alignParentBottom", SdkConstants.NS_RESOURCES)); + info.parentLeft = "true".equals(tag.getAttributeValue("layout_alignParentLeft", SdkConstants.NS_RESOURCES)); + info.parentRight = "true".equals(tag.getAttributeValue("layout_alignParentRight", SdkConstants.NS_RESOURCES)); - info.parentCenterHorizontal = "true".equals(tag.getAttributeValue("android:layout_centerHorizontal")); - info.parentCenterVertical = "true".equals(tag.getAttributeValue("android:layout_centerVertical")); + info.parentCenterHorizontal = "true".equals(tag.getAttributeValue("layout_centerHorizontal", SdkConstants.NS_RESOURCES)); + info.parentCenterVertical = "true".equals(tag.getAttributeValue("layout_centerVertical", SdkConstants.NS_RESOURCES)); - String center = tag.getAttributeValue("android:layout_centerInParent"); + String center = tag.getAttributeValue("layout_centerInParent", SdkConstants.NS_RESOURCES); if (!StringUtil.isEmpty(center)) { info.parentCenterHorizontal = info.parentCenterVertical = "true".equals(center); } @@ -79,12 +80,12 @@ public class RadRelativeLayoutComponent extends RadViewContainer { @Nullable private static RadViewComponent getComponent(Map idToComponent, XmlTag tag, String attribute) { - return idToComponent.get(parseIdValue(tag.getAttributeValue(attribute))); + return idToComponent.get(parseIdValue(tag.getAttributeValue(attribute, SdkConstants.NS_RESOURCES))); } private static String parseIdValue(String idValue) { if (!StringUtil.isEmpty(idValue)) { - if (idValue.startsWith("@android:id/")) { + if (idValue.startsWith("@id/")) { return idValue; } return idValue.substring(idValue.indexOf('/') + 1); diff --git a/plugins/android-designer/src/com/intellij/android/designer/model/layout/table/RadTableLayoutComponent.java b/plugins/android-designer/src/com/intellij/android/designer/model/layout/table/RadTableLayoutComponent.java index 7638697ea118..2fd4b30ff0f9 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/model/layout/table/RadTableLayoutComponent.java +++ b/plugins/android-designer/src/com/intellij/android/designer/model/layout/table/RadTableLayoutComponent.java @@ -16,6 +16,7 @@ package com.intellij.android.designer.model.layout.table; import com.android.ide.common.rendering.api.ViewInfo; +import com.android.sdklib.SdkConstants; import com.intellij.android.designer.model.ModelParser; import com.intellij.android.designer.model.RadViewComponent; import com.intellij.android.designer.model.RadViewContainer; @@ -171,7 +172,7 @@ public class RadTableLayoutComponent extends RadViewContainer implements IGridPr public static int getCellIndex(RadComponent component) { try { - String column = ((RadViewComponent)component).getTag().getAttributeValue("android:layout_column"); + String column = ((RadViewComponent)component).getTag().getAttributeValue("layout_column", SdkConstants.NS_RESOURCES); return Integer.parseInt(column); } catch (Throwable e) { @@ -181,7 +182,7 @@ public class RadTableLayoutComponent extends RadViewContainer implements IGridPr public static int getCellSpan(RadComponent component) { try { - String span = ((RadViewComponent)component).getTag().getAttributeValue("android:layout_span"); + String span = ((RadViewComponent)component).getTag().getAttributeValue("layout_span", SdkConstants.NS_RESOURCES); return Integer.parseInt(span); } catch (Throwable e) { @@ -194,8 +195,8 @@ public class RadTableLayoutComponent extends RadViewContainer implements IGridPr @Override public void run() { XmlTag tag = ((RadViewComponent)component).getTag(); - tag.setAttribute("android:layout_column", Integer.toString(column)); - ModelParser.deleteAttribute(tag, "android:layout_span"); + tag.setAttribute("layout_column", SdkConstants.NS_RESOURCES, Integer.toString(column)); + ModelParser.deleteAttribute(tag, "layout_span"); } }); } @@ -205,7 +206,7 @@ public class RadTableLayoutComponent extends RadViewContainer implements IGridPr @Override public void run() { XmlTag tag = ((RadViewComponent)component).getTag(); - tag.setAttribute("android:layout_span", Integer.toString(span)); + tag.setAttribute("layout_span", SdkConstants.NS_RESOURCES, Integer.toString(span)); } }); } diff --git a/plugins/android-designer/src/com/intellij/android/designer/model/morphing/AbsoluteLayout.java b/plugins/android-designer/src/com/intellij/android/designer/model/morphing/AbsoluteLayout.java index 67fc45a1e267..5c6cdb939922 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/model/morphing/AbsoluteLayout.java +++ b/plugins/android-designer/src/com/intellij/android/designer/model/morphing/AbsoluteLayout.java @@ -15,6 +15,7 @@ */ package com.intellij.android.designer.model.morphing; +import com.android.sdklib.SdkConstants; import com.intellij.android.designer.model.ComponentMorphingTool; import com.intellij.android.designer.model.RadViewComponent; import com.intellij.android.designer.model.layout.relative.RadRelativeLayout; @@ -35,16 +36,16 @@ public class AbsoluteLayout { for (RadComponent childComponent : myNewComponent.getChildren()) { XmlTag tag = ((RadViewComponent)childComponent).getTag(); - XmlAttribute xAttribute = tag.getAttribute("android:layout_x"); + XmlAttribute xAttribute = tag.getAttribute("layout_x", SdkConstants.NS_RESOURCES); if (xAttribute != null) { - tag.setAttribute("android:layout_alignParentLeft", "true"); - xAttribute.setName("android:layout_marginLeft"); + tag.setAttribute("layout_alignParentLeft", SdkConstants.NS_RESOURCES, "true"); + xAttribute.setName(xAttribute.getNamespacePrefix() + ":layout_marginLeft"); } - XmlAttribute yAttribute = tag.getAttribute("android:layout_y"); + XmlAttribute yAttribute = tag.getAttribute("layout_y", SdkConstants.NS_RESOURCES); if (yAttribute != null) { - tag.setAttribute("android:layout_alignParentTop", "true"); - yAttribute.setName("android:layout_marginTop"); + tag.setAttribute("layout_alignParentTop", SdkConstants.NS_RESOURCES, "true"); + yAttribute.setName(yAttribute.getNamespacePrefix() + ":layout_marginTop"); } } } diff --git a/plugins/android-designer/src/com/intellij/android/designer/model/morphing/FrameLayout.java b/plugins/android-designer/src/com/intellij/android/designer/model/morphing/FrameLayout.java index 74cda55d4d34..fdf11698f6a1 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/model/morphing/FrameLayout.java +++ b/plugins/android-designer/src/com/intellij/android/designer/model/morphing/FrameLayout.java @@ -15,6 +15,7 @@ */ package com.intellij.android.designer.model.morphing; +import com.android.sdklib.SdkConstants; import com.intellij.android.designer.model.*; import com.intellij.android.designer.model.layout.Gravity; import com.intellij.android.designer.model.layout.grid.RadGridLayout; @@ -89,11 +90,11 @@ public class FrameLayout { for (RadComponent rowComponent : myNewComponent.getChildren()) { for (RadComponent cellComponent : rowComponent.getChildren()) { XmlTag childTag = ((RadViewComponent)cellComponent).getTag(); - ModelParser.deleteAttribute(childTag, "android:layout_gravity"); + ModelParser.deleteAttribute(childTag, "layout_gravity"); Integer column = cellComponent.extractClientProperty(COLUMN_KEY); if (column != null) { - childTag.setAttribute("android:layout_column", column.toString()); + childTag.setAttribute("layout_column", SdkConstants.NS_RESOURCES, column.toString()); } } } @@ -133,15 +134,15 @@ public class FrameLayout { @Override protected void convertTag() { XmlTag tag = myNewComponent.getTag(); - tag.setAttribute("android:rowCount", "3"); - tag.setAttribute("android:columnCount", "3"); + tag.setAttribute("rowCount", SdkConstants.NS_RESOURCES, "3"); + tag.setAttribute("columnCount", SdkConstants.NS_RESOURCES, "3"); for (RadComponent childComponent : myNewComponent.getChildren()) { XmlTag childTag = ((RadViewComponent)childComponent).getTag(); Pair sides = Gravity.getSides(childComponent); - ModelParser.deleteAttribute(childTag, "android:layout_gravity"); - childTag.setAttribute("android:layout_row", getRowIndexValue(sides.second)); - childTag.setAttribute("android:layout_column", getColumnIndexValue(sides.first)); + ModelParser.deleteAttribute(childTag, "layout_gravity"); + childTag.setAttribute("layout_row", SdkConstants.NS_RESOURCES, getRowIndexValue(sides.second)); + childTag.setAttribute("layout_column", SdkConstants.NS_RESOURCES, getColumnIndexValue(sides.first)); } } }.result(); diff --git a/plugins/android-designer/src/com/intellij/android/designer/model/morphing/GridLayout.java b/plugins/android-designer/src/com/intellij/android/designer/model/morphing/GridLayout.java index c21b4664ffcb..ef1484084da9 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/model/morphing/GridLayout.java +++ b/plugins/android-designer/src/com/intellij/android/designer/model/morphing/GridLayout.java @@ -15,6 +15,7 @@ */ package com.intellij.android.designer.model.morphing; +import com.android.sdklib.SdkConstants; import com.intellij.android.designer.model.*; import com.intellij.android.designer.model.grid.GridInfo; import com.intellij.android.designer.model.layout.grid.RadGridLayoutComponent; @@ -57,18 +58,18 @@ public class GridLayout { @Override protected void convertTag() { XmlTag tag = myNewComponent.getTag(); - ModelParser.deleteAttribute(tag, "android:rowCount"); - ModelParser.deleteAttribute(tag, "android:columnCount"); + ModelParser.deleteAttribute(tag, "rowCount"); + ModelParser.deleteAttribute(tag, "columnCount"); for (RadComponent rowComponent : myNewComponent.getChildren()) { for (RadComponent cellComponent : rowComponent.getChildren()) { XmlTag cellTag = ((RadViewComponent)cellComponent).getTag(); - ModelParser.deleteAttribute(cellTag, "android:layout_row"); - ModelParser.deleteAttribute(cellTag, "android:layout_rowSpan"); + ModelParser.deleteAttribute(cellTag, "layout_row"); + ModelParser.deleteAttribute(cellTag, "layout_rowSpan"); - XmlAttribute attribute = cellTag.getAttribute("android:layout_columnSpan"); + XmlAttribute attribute = cellTag.getAttribute("layout_columnSpan", SdkConstants.NS_RESOURCES); if (attribute != null) { - attribute.setName("android:layout_span"); + attribute.setName(attribute.getNamespacePrefix() + ":layout_span"); } } } diff --git a/plugins/android-designer/src/com/intellij/android/designer/model/morphing/LinearLayout.java b/plugins/android-designer/src/com/intellij/android/designer/model/morphing/LinearLayout.java index e1377ab42719..792723f9d146 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/model/morphing/LinearLayout.java +++ b/plugins/android-designer/src/com/intellij/android/designer/model/morphing/LinearLayout.java @@ -15,6 +15,7 @@ */ package com.intellij.android.designer.model.morphing; +import com.android.sdklib.SdkConstants; import com.intellij.android.designer.model.*; import com.intellij.android.designer.model.layout.RadLinearLayout; import com.intellij.android.designer.model.layout.RadRadioGroupLayout; @@ -39,10 +40,10 @@ public class LinearLayout { @Override protected void convertTag() { if (horizontal) { - myNewComponent.getTag().setAttribute("android:orientation", "horizontal"); + myNewComponent.getTag().setAttribute("orientation", SdkConstants.NS_RESOURCES, "horizontal"); } else { - ModelParser.deleteAttribute(myNewComponent, "android:orientation"); + ModelParser.deleteAttribute(myNewComponent, "orientation"); } } }.result(); @@ -84,7 +85,7 @@ public class LinearLayout { @Override protected void convertTag() { - ModelParser.deleteAttribute(myNewComponent, "android:orientation"); + ModelParser.deleteAttribute(myNewComponent, "orientation"); } @Override diff --git a/plugins/android-designer/src/com/intellij/android/designer/model/morphing/RadioGroup.java b/plugins/android-designer/src/com/intellij/android/designer/model/morphing/RadioGroup.java index 67f5d6df92b5..69533bc802c1 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/model/morphing/RadioGroup.java +++ b/plugins/android-designer/src/com/intellij/android/designer/model/morphing/RadioGroup.java @@ -15,6 +15,7 @@ */ package com.intellij.android.designer.model.morphing; +import com.android.sdklib.SdkConstants; import com.intellij.android.designer.model.ComponentMorphingTool; import com.intellij.android.designer.model.ModelParser; import com.intellij.android.designer.model.RadViewComponent; @@ -45,10 +46,10 @@ public class RadioGroup { @Override protected void convertTag() { if (horizontal) { - ModelParser.deleteAttribute(myNewComponent, "android:orientation"); + ModelParser.deleteAttribute(myNewComponent, "orientation"); } else { - myNewComponent.getTag().setAttribute("android:orientation", "vertical"); + myNewComponent.getTag().setAttribute("orientation", SdkConstants.NS_RESOURCES, "vertical"); } } }.result(); diff --git a/plugins/android-designer/src/com/intellij/android/designer/model/morphing/RelativeLayout.java b/plugins/android-designer/src/com/intellij/android/designer/model/morphing/RelativeLayout.java index c3fcb9d3726c..c4128243a8d1 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/model/morphing/RelativeLayout.java +++ b/plugins/android-designer/src/com/intellij/android/designer/model/morphing/RelativeLayout.java @@ -15,6 +15,7 @@ */ package com.intellij.android.designer.model.morphing; +import com.android.sdklib.SdkConstants; import com.intellij.android.designer.model.ComponentMorphingTool; import com.intellij.android.designer.model.RadViewComponent; import com.intellij.android.designer.model.layout.relative.RadRelativeLayout; @@ -38,10 +39,10 @@ public class RelativeLayout { for (RadComponent childComponent : myNewComponent.getChildren()) { Rectangle bounds = childComponent.getBounds(); XmlTag tag = ((RadViewComponent)childComponent).getTag(); - tag.setAttribute("android:layout_alignParentLeft", "true"); - tag.setAttribute("android:layout_marginLeft", Integer.toString(bounds.x - parentBounds.x) + "dp"); - tag.setAttribute("android:layout_alignParentTop", "true"); - tag.setAttribute("android:layout_marginTop", Integer.toString(bounds.y - parentBounds.y) + "dp"); + tag.setAttribute("layout_alignParentLeft", SdkConstants.NS_RESOURCES, "true"); + tag.setAttribute("layout_marginLeft", SdkConstants.NS_RESOURCES, Integer.toString(bounds.x - parentBounds.x) + "dp"); + tag.setAttribute("layout_alignParentTop", SdkConstants.NS_RESOURCES, "true"); + tag.setAttribute("layout_marginTop", SdkConstants.NS_RESOURCES, Integer.toString(bounds.y - parentBounds.y) + "dp"); } } }.result(); diff --git a/plugins/android-designer/src/com/intellij/android/designer/model/morphing/TableLayout.java b/plugins/android-designer/src/com/intellij/android/designer/model/morphing/TableLayout.java index 2f537fe01eca..a3f2ac3a5dee 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/model/morphing/TableLayout.java +++ b/plugins/android-designer/src/com/intellij/android/designer/model/morphing/TableLayout.java @@ -15,6 +15,7 @@ */ package com.intellij.android.designer.model.morphing; +import com.android.sdklib.SdkConstants; import com.intellij.android.designer.model.ComponentMorphingTool; import com.intellij.android.designer.model.ModelParser; import com.intellij.android.designer.model.RadViewComponent; @@ -60,8 +61,8 @@ public class TableLayout { XmlTag tag = myNewComponent.getTag(); if (components.length > 0) { String columnCount = Integer.toString(components[0].length); - tag.setAttribute("android:rowCount", Integer.toString(components.length)); - tag.setAttribute("android:columnCount", columnCount); + tag.setAttribute("rowCount", SdkConstants.NS_RESOURCES, Integer.toString(components.length)); + tag.setAttribute("columnCount", SdkConstants.NS_RESOURCES, columnCount); for (int i = 0; i < components.length; i++) { RadComponent[] rowComponents = components[i]; @@ -69,25 +70,25 @@ public class TableLayout { RadComponent firstCellComponent = rowComponents[0]; if (firstCellComponent != null && firstCellComponent.extractClientProperty(TABLE_ROW_KEY) == Boolean.TRUE) { XmlTag cellTag = ((RadViewComponent)firstCellComponent).getTag(); - ModelParser.deleteAttribute(cellTag, "android:layout_span"); - cellTag.setAttribute("android:layout_column", "0"); - cellTag.setAttribute("android:layout_columnSpan", columnCount); - cellTag.setAttribute("android:layout_gravity", "fill_horizontal"); + ModelParser.deleteAttribute(cellTag, "layout_span"); + cellTag.setAttribute("layout_column", SdkConstants.NS_RESOURCES, "0"); + cellTag.setAttribute("layout_columnSpan", SdkConstants.NS_RESOURCES, columnCount); + cellTag.setAttribute("layout_gravity", SdkConstants.NS_RESOURCES, "fill_horizontal"); } for (RadComponent cellComponent : rowComponents) { if (cellComponent != null) { XmlTag cellTag = ((RadViewComponent)cellComponent).getTag(); - cellTag.setAttribute("android:layout_row", Integer.toString(i)); + cellTag.setAttribute("layout_row", SdkConstants.NS_RESOURCES, Integer.toString(i)); break; } } } for (RadComponent childComponent : myNewComponent.getChildren()) { - XmlAttribute attribute = ((RadViewComponent)childComponent).getTag().getAttribute("android:layout_span"); + XmlAttribute attribute = ((RadViewComponent)childComponent).getTag().getAttribute("layout_span", SdkConstants.NS_RESOURCES); if (attribute != null) { - attribute.setName("android:layout_columnSpan"); + attribute.setName(attribute.getNamespacePrefix() + ":layout_columnSpan"); } } } diff --git a/plugins/android-designer/src/com/intellij/android/designer/propertyTable/AttributeProperty.java b/plugins/android-designer/src/com/intellij/android/designer/propertyTable/AttributeProperty.java index 5c049489bda3..c7c4f733a147 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/propertyTable/AttributeProperty.java +++ b/plugins/android-designer/src/com/intellij/android/designer/propertyTable/AttributeProperty.java @@ -16,6 +16,7 @@ package com.intellij.android.designer.propertyTable; import com.android.resources.ResourceType; +import com.android.sdklib.SdkConstants; import com.intellij.android.designer.model.RadViewComponent; import com.intellij.android.designer.propertyTable.editors.ResourceEditor; import com.intellij.android.designer.propertyTable.editors.StringsComboEditor; @@ -122,7 +123,7 @@ public class AttributeProperty extends Property implements IXm } } else { - component.getTag().setAttribute("android:" + myDefinition.getName(), (String)value); + component.getTag().setAttribute(myDefinition.getName(), SdkConstants.NS_RESOURCES, (String)value); } } }); @@ -142,7 +143,7 @@ public class AttributeProperty extends Property implements IXm @Nullable private XmlAttribute getAttribute(RadViewComponent component) { - return component.getTag().getAttribute("android:" + myDefinition.getName()); + return component.getTag().getAttribute(myDefinition.getName(), SdkConstants.NS_RESOURCES); } @Override diff --git a/plugins/android-designer/src/com/intellij/android/designer/propertyTable/FlagProperty.java b/plugins/android-designer/src/com/intellij/android/designer/propertyTable/FlagProperty.java index cb87f37aa0a0..d1a8d0b35b50 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/propertyTable/FlagProperty.java +++ b/plugins/android-designer/src/com/intellij/android/designer/propertyTable/FlagProperty.java @@ -15,6 +15,7 @@ */ package com.intellij.android.designer.propertyTable; +import com.android.sdklib.SdkConstants; import com.intellij.android.designer.model.RadViewComponent; import com.intellij.designer.model.MetaModel; import com.intellij.designer.propertyTable.IPropertyDecorator; @@ -116,7 +117,7 @@ public class FlagProperty extends Property implements IPropert @Nullable protected XmlAttribute getAttribute(RadViewComponent component) { - return component.getTag().getAttribute("android:" + myDefinition.getName()); + return component.getTag().getAttribute(myDefinition.getName(), SdkConstants.NS_RESOURCES); } @Override @@ -125,7 +126,7 @@ public class FlagProperty extends Property implements IPropert } protected Set getOptions(RadViewComponent component) throws Exception { - String value = component.getTag().getAttributeValue("android:" + myDefinition.getName()); + String value = component.getTag().getAttributeValue(myDefinition.getName(), SdkConstants.NS_RESOURCES); if (value == null) { return Collections.emptySet(); } @@ -161,7 +162,7 @@ public class FlagProperty extends Property implements IPropert } } else { - component.getTag().setAttribute("android:" + myDefinition.getName(), StringUtil.join(options, "|")); + component.getTag().setAttribute(myDefinition.getName(), SdkConstants.NS_RESOURCES, StringUtil.join(options, "|")); } } }); diff --git a/plugins/android-designer/src/com/intellij/android/designer/propertyTable/FragmentProperty.java b/plugins/android-designer/src/com/intellij/android/designer/propertyTable/FragmentProperty.java index 4d9ad12d13e8..644efb550c12 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/propertyTable/FragmentProperty.java +++ b/plugins/android-designer/src/com/intellij/android/designer/propertyTable/FragmentProperty.java @@ -15,6 +15,7 @@ */ package com.intellij.android.designer.propertyTable; +import com.android.sdklib.SdkConstants; import com.intellij.android.designer.model.ModelParser; import com.intellij.android.designer.model.RadViewComponent; import com.intellij.designer.model.RadComponent; @@ -44,7 +45,7 @@ public class FragmentProperty extends Property implements IXml myEditor = editor; myJavadocText = javadocText; setImportant(true); - myAttribute = "android:" + name; + myAttribute = name; } @Override @@ -54,7 +55,7 @@ public class FragmentProperty extends Property implements IXml @Override public Object getValue(RadViewComponent component) throws Exception { - String value = component.getTag().getAttributeValue(myAttribute); + String value = component.getTag().getAttributeValue(myAttribute, SdkConstants.NS_RESOURCES); return value == null ? "" : value; } @@ -67,7 +68,7 @@ public class FragmentProperty extends Property implements IXml ModelParser.deleteAttribute(component, myAttribute); } else { - component.getTag().setAttribute(myAttribute, (String)value); + component.getTag().setAttribute(myAttribute, SdkConstants.NS_RESOURCES, (String)value); } } }); @@ -75,12 +76,12 @@ public class FragmentProperty extends Property implements IXml @Override public boolean isDefaultValue(RadViewComponent component) throws Exception { - return component.getTag().getAttribute(myAttribute) == null; + return component.getTag().getAttribute(myAttribute, SdkConstants.NS_RESOURCES) == null; } @Override public void setDefaultValue(RadViewComponent component) throws Exception { - if (component.getTag().getAttribute(myAttribute) != null) { + if (component.getTag().getAttribute(myAttribute, SdkConstants.NS_RESOURCES) != null) { setValue(component, null); } } @@ -108,6 +109,6 @@ public class FragmentProperty extends Property implements IXml @Override public boolean checkAttribute(RadViewComponent component, XmlAttribute attribute) { - return component.getTag().getAttribute(myAttribute) == attribute; + return component.getTag().getAttribute(myAttribute, SdkConstants.NS_RESOURCES) == attribute; } } \ No newline at end of file diff --git a/plugins/android-designer/src/com/intellij/android/designer/propertyTable/GravityProperty.java b/plugins/android-designer/src/com/intellij/android/designer/propertyTable/GravityProperty.java index da93bdff7794..6bea65dd5dd4 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/propertyTable/GravityProperty.java +++ b/plugins/android-designer/src/com/intellij/android/designer/propertyTable/GravityProperty.java @@ -15,6 +15,7 @@ */ package com.intellij.android.designer.propertyTable; +import com.android.sdklib.SdkConstants; import com.intellij.android.designer.model.RadViewComponent; import com.intellij.android.designer.propertyTable.editors.StringsComboEditor; import com.intellij.designer.propertyTable.Property; @@ -155,7 +156,7 @@ public class GravityProperty extends FlagProperty { } } else { - component.getTag().setAttribute("android:" + myDefinition.getName(), StringUtil.join(options, "|")); + component.getTag().setAttribute(myDefinition.getName(), SdkConstants.NS_RESOURCES, StringUtil.join(options, "|")); } } });