mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-88555
This commit is contained in:
+7
-6
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -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);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
+6
-5
@@ -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> gravity = Gravity.getSides(component);
|
||||
|
||||
+6
-7
@@ -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();
|
||||
|
||||
+4
-4
@@ -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
|
||||
|
||||
+11
-10
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-2
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
-3
@@ -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(',', '.'));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-2
@@ -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<Integer, Integer> widthInfo = ResizeOperation.getDefaultSize(width, bounds.width);
|
||||
Pair<Integer, Integer> heightInfo = ResizeOperation.getDefaultSize(height, bounds.height);
|
||||
|
||||
+7
-4
@@ -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<Integer, Integer> widthInfo = getDefaultSize(width, bounds.width);
|
||||
Pair<Integer, Integer> 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));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
+2
-2
@@ -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
|
||||
|
||||
+11
-10
@@ -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");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+5
-4
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -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());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+10
-9
@@ -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);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
+2
-1
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+8
-8
@@ -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");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
+12
-12
@@ -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");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
+3
-2
@@ -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");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
+2
-1
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -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)) {
|
||||
|
||||
+2
-1
@@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+353
-351
@@ -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<StaticDecorator> decorators, List<RadComponent> 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<RadComponent> 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> 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<RadComponent> 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<Gravity> HORIZONTALS = Arrays.asList(Gravity.left, Gravity.center, Gravity.right, null);
|
||||
private static final List<Gravity> VERTICALS = Arrays.asList(Gravity.top, Gravity.center, Gravity.bottom, null);
|
||||
|
||||
@Override
|
||||
public void addSelectionActions(DesignerEditorPanel designer,
|
||||
DefaultActionGroup actionGroup,
|
||||
JComponent shortcuts,
|
||||
List<RadComponent> 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<Gravity> {
|
||||
private Gravity mySelection;
|
||||
|
||||
public GravityAction(DesignerEditorPanel designer, List<RadComponent> 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<RadComponent> 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<RadComponent> components) {
|
||||
boolean override = false;
|
||||
Iterator<RadComponent> 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<RadComponent> components) {
|
||||
List<RadComponent> 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<RadViewComponent> 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<StaticDecorator> decorators, List<RadComponent> 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<RadComponent> 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> 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<RadComponent> 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<Gravity> HORIZONTALS = Arrays.asList(Gravity.left, Gravity.center, Gravity.right, null);
|
||||
private static final List<Gravity> VERTICALS = Arrays.asList(Gravity.top, Gravity.center, Gravity.bottom, null);
|
||||
|
||||
@Override
|
||||
public void addSelectionActions(DesignerEditorPanel designer,
|
||||
DefaultActionGroup actionGroup,
|
||||
JComponent shortcuts,
|
||||
List<RadComponent> 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<Gravity> {
|
||||
private Gravity mySelection;
|
||||
|
||||
public GravityAction(DesignerEditorPanel designer, List<RadComponent> 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<RadComponent> 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<RadComponent> components) {
|
||||
boolean override = false;
|
||||
Iterator<RadComponent> 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<RadComponent> components) {
|
||||
List<RadComponent> 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<RadViewComponent> 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");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -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));
|
||||
}
|
||||
}
|
||||
+3
-2
@@ -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<Gravity> {
|
||||
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<Gravity> {
|
||||
|
||||
for (RadComponent component : myComponents) {
|
||||
XmlTag tag = ((RadViewComponent)component).getTag();
|
||||
tag.setAttribute("android:layout_gravity", value);
|
||||
tag.setAttribute("layout_gravity", SdkConstants.NS_RESOURCES, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -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);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
+13
-11
@@ -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");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+6
-6
@@ -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<RadViewComponent> 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<RadViewComponent> 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<RadViewComponent> 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<RadViewComponent> 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<RadViewComponent> 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;
|
||||
}
|
||||
}
|
||||
|
||||
+19
-18
@@ -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<String, RadViewComponent> 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);
|
||||
|
||||
+6
-5
@@ -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));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+7
-6
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+8
-7
@@ -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<Gravity, Gravity> 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();
|
||||
|
||||
+7
-6
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-3
@@ -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
|
||||
|
||||
+3
-2
@@ -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();
|
||||
|
||||
+5
-4
@@ -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();
|
||||
|
||||
+10
-9
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -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<RadViewComponent> 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<RadViewComponent> 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
|
||||
|
||||
+4
-3
@@ -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<RadViewComponent> 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<RadViewComponent> implements IPropert
|
||||
}
|
||||
|
||||
protected Set<String> 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<RadViewComponent> implements IPropert
|
||||
}
|
||||
}
|
||||
else {
|
||||
component.getTag().setAttribute("android:" + myDefinition.getName(), StringUtil.join(options, "|"));
|
||||
component.getTag().setAttribute(myDefinition.getName(), SdkConstants.NS_RESOURCES, StringUtil.join(options, "|"));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
+7
-6
@@ -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<RadViewComponent> implements IXml
|
||||
myEditor = editor;
|
||||
myJavadocText = javadocText;
|
||||
setImportant(true);
|
||||
myAttribute = "android:" + name;
|
||||
myAttribute = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -54,7 +55,7 @@ public class FragmentProperty extends Property<RadViewComponent> 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<RadViewComponent> 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<RadViewComponent> 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<RadViewComponent> 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;
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -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, "|"));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user