aboutsummaryrefslogtreecommitdiff
path: root/eclipse
diff options
context:
space:
mode:
Diffstat (limited to 'eclipse')
-rwxr-xr-xeclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/FrameLayoutRule.java2
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/HorizontalScrollViewRule.java34
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/LayoutConstants.java1
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/ScrollViewRule.java34
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newxmlfile/NewXmlFileCreationPage.java29
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newxmlfile/NewXmlFileWizard.java11
6 files changed, 105 insertions, 6 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/FrameLayoutRule.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/FrameLayoutRule.java
index 83a93bec1..b8c74086c 100755
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/FrameLayoutRule.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/FrameLayoutRule.java
@@ -62,7 +62,7 @@ public class FrameLayoutRule extends BaseLayoutRule {
});
}
- void drawFeedback(
+ protected void drawFeedback(
IGraphics gc,
INode targetNode,
IDragElement[] elements,
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/HorizontalScrollViewRule.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/HorizontalScrollViewRule.java
index f73c11442..62ea6f9fd 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/HorizontalScrollViewRule.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/HorizontalScrollViewRule.java
@@ -23,9 +23,15 @@ import static com.android.ide.common.layout.LayoutConstants.ATTR_ORIENTATION;
import static com.android.ide.common.layout.LayoutConstants.FQCN_LINEAR_LAYOUT;
import static com.android.ide.common.layout.LayoutConstants.VALUE_HORIZONTAL;
+import com.android.ide.common.api.DrawingStyle;
+import com.android.ide.common.api.DropFeedback;
+import com.android.ide.common.api.IDragElement;
+import com.android.ide.common.api.IGraphics;
import com.android.ide.common.api.INode;
import com.android.ide.common.api.IViewRule;
import com.android.ide.common.api.InsertType;
+import com.android.ide.common.api.Point;
+import com.android.ide.common.api.Rect;
/**
* An {@link IViewRule} for android.widget.HorizontalScrollView.
@@ -55,4 +61,32 @@ public class HorizontalScrollViewRule extends FrameLayoutRule {
}
}
+ @Override
+ public DropFeedback onDropMove(INode targetNode, IDragElement[] elements,
+ DropFeedback feedback, Point p) {
+ DropFeedback f = super.onDropMove(targetNode, elements, feedback, p);
+
+ // HorizontalScrollViews only allow a single child
+ if (targetNode.getChildren().length > 0) {
+ f.invalidTarget = true;
+ }
+ return f;
+ }
+
+ @Override
+ protected void drawFeedback(
+ IGraphics gc,
+ INode targetNode,
+ IDragElement[] elements,
+ DropFeedback feedback) {
+ if (targetNode.getChildren().length > 0) {
+ Rect b = targetNode.getBounds();
+ if (b.isValid()) {
+ gc.useStyle(DrawingStyle.DROP_RECIPIENT);
+ gc.drawRect(b);
+ }
+ } else {
+ super.drawFeedback(gc, targetNode, elements, feedback);
+ }
+ }
}
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/LayoutConstants.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/LayoutConstants.java
index 4116185c6..f88e7ab77 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/LayoutConstants.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/LayoutConstants.java
@@ -52,6 +52,7 @@ public class LayoutConstants {
public static final String RADIO_GROUP = "RadioGroup"; //$NON-NLS-1$
public static final String EXPANDABLE_LIST_VIEW = "ExpandableListView";//$NON-NLS-1$
public static final String GESTURE_OVERLAY_VIEW = "GestureOverlayView";//$NON-NLS-1$
+ public static final String HORIZONTAL_SCROLL_VIEW = "HorizontalScrollView"; //$NON-NLS-1$
public static final String ATTR_TEXT = "text"; //$NON-NLS-1$
public static final String ATTR_HINT = "hint"; //$NON-NLS-1$
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/ScrollViewRule.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/ScrollViewRule.java
index bf57456fb..385dcc5c3 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/ScrollViewRule.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/ScrollViewRule.java
@@ -21,9 +21,15 @@ import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_HEIGHT;
import static com.android.ide.common.layout.LayoutConstants.ATTR_LAYOUT_WIDTH;
import static com.android.ide.common.layout.LayoutConstants.FQCN_LINEAR_LAYOUT;
+import com.android.ide.common.api.DrawingStyle;
+import com.android.ide.common.api.DropFeedback;
+import com.android.ide.common.api.IDragElement;
+import com.android.ide.common.api.IGraphics;
import com.android.ide.common.api.INode;
import com.android.ide.common.api.IViewRule;
import com.android.ide.common.api.InsertType;
+import com.android.ide.common.api.Point;
+import com.android.ide.common.api.Rect;
/**
* An {@link IViewRule} for android.widget.ScrollView.
@@ -52,4 +58,32 @@ public class ScrollViewRule extends FrameLayoutRule {
}
}
+ @Override
+ public DropFeedback onDropMove(INode targetNode, IDragElement[] elements,
+ DropFeedback feedback, Point p) {
+ DropFeedback f = super.onDropMove(targetNode, elements, feedback, p);
+
+ // ScrollViews only allow a single child
+ if (targetNode.getChildren().length > 0) {
+ f.invalidTarget = true;
+ }
+ return f;
+ }
+
+ @Override
+ protected void drawFeedback(
+ IGraphics gc,
+ INode targetNode,
+ IDragElement[] elements,
+ DropFeedback feedback) {
+ if (targetNode.getChildren().length > 0) {
+ Rect b = targetNode.getBounds();
+ if (b.isValid()) {
+ gc.useStyle(DrawingStyle.DROP_RECIPIENT);
+ gc.drawRect(b);
+ }
+ } else {
+ super.drawFeedback(gc, targetNode, elements, feedback);
+ }
+ }
}
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newxmlfile/NewXmlFileCreationPage.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newxmlfile/NewXmlFileCreationPage.java
index a797bd09a..583202ace 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newxmlfile/NewXmlFileCreationPage.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newxmlfile/NewXmlFileCreationPage.java
@@ -17,6 +17,8 @@
package com.android.ide.eclipse.adt.internal.wizards.newxmlfile;
+import static com.android.ide.common.layout.LayoutConstants.HORIZONTAL_SCROLL_VIEW;
+import static com.android.ide.common.layout.LayoutConstants.SCROLL_VIEW;
import static com.android.ide.common.layout.LayoutConstants.VALUE_FILL_PARENT;
import static com.android.ide.common.layout.LayoutConstants.VALUE_MATCH_PARENT;
@@ -208,6 +210,18 @@ class NewXmlFileCreationPage extends WizardPage {
}
/**
+ * When not null, represents an extra string that should be written inside
+ * the element when constructed
+ *
+ * @param project the project to get the child content for
+ * @param root the chosen root element
+ * @return a string to be written inside the root element, or null if nothing
+ */
+ String getChild(IProject project, String root) {
+ return null;
+ }
+
+ /**
* The minimum API level required by the current SDK target to support this feature.
*
* @return the minimum API level
@@ -248,10 +262,21 @@ class NewXmlFileCreationPage extends WizardPage {
return String.format(
"android:orientation=\"vertical\"\n" //$NON-NLS-1$
- + "android:layout_width=\"%1$s\"\n" //$NON-NLS-1$
- + "android:layout_height=\"%1$s\"", //$NON-NLS-1$
+ + "android:layout_width=\"%1$s\"\n" //$NON-NLS-1$
+ + "android:layout_height=\"%1$s\"", //$NON-NLS-1$
fill, fill);
}
+
+ @Override
+ String getChild(IProject project, String root) {
+ // Create vertical linear layouts inside new scroll views
+ if (SCROLL_VIEW.equals(root) || HORIZONTAL_SCROLL_VIEW.equals(root)) {
+ return " <LinearLayout " //$NON-NLS-1$
+ + getDefaultAttrs(project).replace('\n', ' ')
+ + "></LinearLayout>\n"; //$NON-NLS-1$
+ }
+ return null;
+ }
},
new TypeInfo("Values", // UI name
"An XML file with simple values: colors, strings, dimensions, etc.", // tooltip
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newxmlfile/NewXmlFileWizard.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newxmlfile/NewXmlFileWizard.java
index 75527b308..442568f37 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newxmlfile/NewXmlFileWizard.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newxmlfile/NewXmlFileWizard.java
@@ -146,12 +146,13 @@ public class NewXmlFileWizard extends Wizard implements INewWizard {
String attrs = type.getDefaultAttrs(mMainPage.getProject());
- return createXmlFile(file, xmlns, root, attrs);
+ String child = type.getChild(mMainPage.getProject(), root);
+ return createXmlFile(file, xmlns, root, attrs, child);
}
/** Creates a new file using the given root element, namespace and root attributes */
private static Pair<IFile, IRegion> createXmlFile(IFile file, String xmlns,
- String root, String rootAttributes) {
+ String root, String rootAttributes, String child) {
String name = file.getFullPath().toString();
boolean need_delete = false;
@@ -180,6 +181,10 @@ public class NewXmlFileWizard extends Wizard implements INewWizard {
sb.append(">\n"); //$NON-NLS-1$
+ if (child != null) {
+ sb.append(child);
+ }
+
// The insertion line
sb.append(" "); //$NON-NLS-1$
int caretOffset = sb.length();
@@ -239,7 +244,7 @@ public class NewXmlFileWizard extends Wizard implements INewWizard {
root = type.getRootSeed().toString();
}
String attrs = type.getDefaultAttrs(project);
- return createXmlFile(file, xmlns, root, attrs);
+ return createXmlFile(file, xmlns, root, attrs, null);
}
private static boolean createWsParentDirectory(IContainer wsPath) {