aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXavier Ducrohet <xav@android.com>2010-12-02 11:53:05 -0800
committerXavier Ducrohet <xav@android.com>2010-12-02 12:09:22 -0800
commit6d62f10bf1158488089f432b9975a857b806a231 (patch)
tree7c6b1877a22f33b29fbef1b15b17c81895608fa7
parenta09caf06bde2da9e45d57dda5d64b7244ada5f70 (diff)
downloadsdk-6d62f10bf1158488089f432b9975a857b806a231.zip
sdk-6d62f10bf1158488089f432b9975a857b806a231.tar.gz
sdk-6d62f10bf1158488089f432b9975a857b806a231.tar.bz2
LayoutLib API: move add/moveChild API back to using index.
Also add an optional data bundle to SceneResult. Change-Id: I9f9d4ca1f1f05d536a87a005a7939a6d42d0d8a4
-rwxr-xr-xeclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/GraphicalEditorPart.java8
-rwxr-xr-xeclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/PaletteComposite.java3
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/ViewHierarchy.java3
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/tests/functests/layoutRendering/ApiDemosRenderingTest.java3
-rw-r--r--ide_common/src/com/android/ide/common/layoutlib/LayoutBridgeWrapper.java5
-rw-r--r--layoutlib_api/src/com/android/layoutlib/api/LayoutScene.java27
-rw-r--r--layoutlib_api/src/com/android/layoutlib/api/SceneResult.java72
7 files changed, 59 insertions, 62 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/GraphicalEditorPart.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/GraphicalEditorPart.java
index 1e51994..a493b56 100755
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/GraphicalEditorPart.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/GraphicalEditorPart.java
@@ -53,8 +53,8 @@ import com.android.layoutlib.api.IXmlPullParser;
import com.android.layoutlib.api.LayoutBridge;
import com.android.layoutlib.api.LayoutScene;
import com.android.layoutlib.api.SceneParams;
-import com.android.layoutlib.api.SceneResult;
import com.android.layoutlib.api.SceneParams.RenderingMode;
+import com.android.layoutlib.api.SceneResult.SceneStatus;
import com.android.sdklib.IAndroidTarget;
import com.android.sdklib.SdkConstants;
import com.android.sdkuilib.internal.widgets.ResolutionChooserDialog;
@@ -1018,8 +1018,8 @@ public class GraphicalEditorPart extends EditorPart
// no root view yet indicates success and then update the canvas with it.
mCanvasViewer.getCanvas().setResult(
- new BasicLayoutScene(SceneResult.SUCCESS, null /*rootViewInfo*/,
- null /*image*/),
+ new BasicLayoutScene(SceneStatus.SUCCESS.getResult(),
+ null /*rootViewInfo*/, null /*image*/),
null /*explodeNodes*/);
return;
}
@@ -1274,7 +1274,7 @@ public class GraphicalEditorPart extends EditorPart
canvas.setResult(scene, explodeNodes);
// update the UiElementNode with the layout info.
- if (scene.getResult() != SceneResult.SUCCESS) {
+ if (scene.getResult().isSuccess() == false) {
// An error was generated. Print it.
displayError(scene.getResult().getErrorMessage());
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/PaletteComposite.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/PaletteComposite.java
index fc4d5d1..2bc9f34 100755
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/PaletteComposite.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/PaletteComposite.java
@@ -39,7 +39,6 @@ import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode;
import com.android.ide.eclipse.adt.internal.sdk.AndroidTargetData;
import com.android.layoutlib.api.LayoutBridge;
import com.android.layoutlib.api.LayoutScene;
-import com.android.layoutlib.api.SceneResult;
import com.android.layoutlib.api.ViewInfo;
import com.android.sdklib.SdkConstants;
@@ -751,7 +750,7 @@ public class PaletteComposite extends Composite {
}
if (scene != null) {
- if (scene.getResult() == SceneResult.SUCCESS) {
+ if (scene.getResult().isSuccess()) {
BufferedImage image = scene.getImage();
if (image != null) {
BufferedImage cropped;
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/ViewHierarchy.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/ViewHierarchy.java
index 686b0ba..2278cfd 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/ViewHierarchy.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/ViewHierarchy.java
@@ -21,7 +21,6 @@ import com.android.ide.eclipse.adt.internal.editors.layout.gre.NodeProxy;
import com.android.ide.eclipse.adt.internal.editors.layout.uimodel.UiViewElementNode;
import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode;
import com.android.layoutlib.api.LayoutScene;
-import com.android.layoutlib.api.SceneResult;
import com.android.layoutlib.api.ViewInfo;
import org.eclipse.swt.graphics.Rectangle;
@@ -130,7 +129,7 @@ public class ViewHierarchy {
}
mScene = scene;
- mIsResultValid = (scene != null && scene.getResult() == SceneResult.SUCCESS);
+ mIsResultValid = (scene != null && scene.getResult().isSuccess());
mExplodedParents = false;
if (mIsResultValid && scene != null) {
diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/tests/functests/layoutRendering/ApiDemosRenderingTest.java b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/tests/functests/layoutRendering/ApiDemosRenderingTest.java
index 024e9e3..53a36fb 100644
--- a/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/tests/functests/layoutRendering/ApiDemosRenderingTest.java
+++ b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/tests/functests/layoutRendering/ApiDemosRenderingTest.java
@@ -37,7 +37,6 @@ import com.android.layoutlib.api.IResourceValue;
import com.android.layoutlib.api.IXmlPullParser;
import com.android.layoutlib.api.LayoutScene;
import com.android.layoutlib.api.SceneParams;
-import com.android.layoutlib.api.SceneResult;
import com.android.layoutlib.api.SceneParams.RenderingMode;
import com.android.sdklib.IAndroidTarget;
import com.android.sdklib.SdkConstants;
@@ -217,7 +216,7 @@ public class ApiDemosRenderingTest extends SdkTestCase {
null //logger
));
- if (scene.getResult() != SceneResult.SUCCESS) {
+ if (scene.getResult().isSuccess() == false) {
if (projectCallBack.mCustomViewAttempt == false) {
System.out.println("FAILED");
fail(String.format("Rendering %1$s: %2$s", layout.getName(),
diff --git a/ide_common/src/com/android/ide/common/layoutlib/LayoutBridgeWrapper.java b/ide_common/src/com/android/ide/common/layoutlib/LayoutBridgeWrapper.java
index e1b8241..f773a5a 100644
--- a/ide_common/src/com/android/ide/common/layoutlib/LayoutBridgeWrapper.java
+++ b/ide_common/src/com/android/ide/common/layoutlib/LayoutBridgeWrapper.java
@@ -25,6 +25,7 @@ import com.android.layoutlib.api.SceneResult;
import com.android.layoutlib.api.ViewInfo;
import com.android.layoutlib.api.ILayoutResult.ILayoutViewInfo;
import com.android.layoutlib.api.SceneParams.RenderingMode;
+import com.android.layoutlib.api.SceneResult.SceneStatus;
import java.lang.reflect.Field;
import java.util.ArrayList;
@@ -146,10 +147,10 @@ class LayoutBridgeWrapper extends LayoutBridge {
ViewInfo rootViewInfo;
if (result.getSuccess() == ILayoutResult.SUCCESS) {
- sceneResult = SceneResult.SUCCESS;
+ sceneResult = SceneStatus.SUCCESS.getResult();
rootViewInfo = convertToViewInfo(result.getRootView());
} else {
- sceneResult = new SceneResult(result.getErrorMessage());
+ sceneResult = new SceneResult(SceneStatus.ERROR_UNKNOWN, result.getErrorMessage());
rootViewInfo = null;
}
diff --git a/layoutlib_api/src/com/android/layoutlib/api/LayoutScene.java b/layoutlib_api/src/com/android/layoutlib/api/LayoutScene.java
index 8c3d954..871661e 100644
--- a/layoutlib_api/src/com/android/layoutlib/api/LayoutScene.java
+++ b/layoutlib_api/src/com/android/layoutlib/api/LayoutScene.java
@@ -158,8 +158,8 @@ public class LayoutScene {
/**
* Inserts a new child in a ViewGroup object, and renders the result.
* <p/>
- * The child is first inflated and then added to its parent, before the given sibling.
- * If the sibling is <code>null</code>, then it is added at the end of the ViewGroup.
+ * The child is first inflated and then added to its new parent, at the given <var>index<var>
+ * position. If the <var>index</var> is -1 then the child is added at the end of the parent.
* <p/>
* If an animation listener is passed then the rendering is done asynchronously and the
* result is sent to the listener.
@@ -168,15 +168,18 @@ public class LayoutScene {
* The child stays in the view hierarchy after the rendering is done. To remove it call
* {@link #removeChild(Object, int)}.
*
+ * The returned {@link SceneResult} object will contain the android.view.View object for
+ * the newly inflated child. It is accessible through {@link SceneResult#getData()}.
+ *
* @param parentView the parent View object to receive the new child.
* @param childXml an {@link IXmlPullParser} containing the content of the new child.
- * @param beforeSibling the object in <var>parentView</var> to insert before. If
- * <code>null</code>, insert at the end.
+ * @param index the index at which position to add the new child into the parent. -1 means at
+ * the end.
* @param listener an optional {@link IAnimationListener}.
*
* @return a {@link SceneResult} indicating the status of the action.
*/
- public SceneResult insertChild(Object parentView, IXmlPullParser childXml, Object beforeSibling,
+ public SceneResult insertChild(Object parentView, IXmlPullParser childXml, int index,
IAnimationListener listener) {
return NOT_IMPLEMENTED.getResult();
}
@@ -184,9 +187,11 @@ public class LayoutScene {
/**
* Move a new child to a different ViewGroup object.
* <p/>
- * The child is first removed from its current parent, and then added to its new parent, before
- * the given sibling. If the sibling is <code>null</code>, then it is added at the end
- * of the ViewGroup.
+ * The child is first removed from its current parent, and then added to its new parent, at the
+ * given <var>index<var> position. In case the <var>parentView</var> is the current parent of
+ * <var>childView</var> then the index must be the value with the <var>childView</var> removed
+ * from its parent. If the <var>index</var> is -1 then the child is added at the end of
+ * the parent.
* <p/>
* If an animation listener is passed then the rendering is done asynchronously and the
* result is sent to the listener.
@@ -198,13 +203,13 @@ public class LayoutScene {
* @param parentView the parent View object to receive the child. Can be the current parent
* already.
* @param childView the view to move.
- * @param beforeSibling the object in <var>parentView</var> to insert before. If
- * <code>null</code>, insert at the end.
+ * @param index the index at which position to add the new child into the parent. -1 means at
+ * the end.
* @param listener an optional {@link IAnimationListener}.
*
* @return a {@link SceneResult} indicating the status of the action.
*/
- public SceneResult moveChild(Object parentView, Object childView, Object beforeSibling,
+ public SceneResult moveChild(Object parentView, Object childView, int index,
IAnimationListener listener) {
return NOT_IMPLEMENTED.getResult();
}
diff --git a/layoutlib_api/src/com/android/layoutlib/api/SceneResult.java b/layoutlib_api/src/com/android/layoutlib/api/SceneResult.java
index f72c97f..8fada80 100644
--- a/layoutlib_api/src/com/android/layoutlib/api/SceneResult.java
+++ b/layoutlib_api/src/com/android/layoutlib/api/SceneResult.java
@@ -24,6 +24,7 @@ public class SceneResult {
private final SceneStatus mStatus;
private final String mErrorMessage;
private final Throwable mThrowable;
+ private Object mData;
public enum SceneStatus {
SUCCESS,
@@ -45,43 +46,25 @@ public class SceneResult {
// don't want to get generic error that way.
assert this != ERROR_UNKNOWN;
- if (this == SUCCESS) {
- return SceneResult.SUCCESS;
- }
-
return new SceneResult(this);
}
}
/**
- * Singleton SUCCESS {@link SceneResult} object.
- */
- public static final SceneResult SUCCESS = new SceneResult(SceneStatus.SUCCESS);
-
- /**
- * Creates a {@link SceneResult} object, with {@link SceneStatus#ERROR_UNKNOWN} status, and
- * the given message.
- */
- public SceneResult(String errorMessage) {
- this(SceneStatus.ERROR_UNKNOWN, errorMessage, null);
- }
-
- /**
- * Creates a {@link SceneResult} object, with {@link SceneStatus#ERROR_UNKNOWN} status, and
- * the given message and {@link Throwable}
+ * Creates a {@link SceneResult} object with the given SceneStatus.
+ *
+ * @param status the status. Must not be null.
*/
- public SceneResult(String errorMessage, Throwable t) {
- this(SceneStatus.ERROR_UNKNOWN, errorMessage, t);
+ public SceneResult(SceneStatus status) {
+ this(status, null, null);
}
/**
* Creates a {@link SceneResult} object with the given SceneStatus, and the given message
* and {@link Throwable}.
- * <p>
- * This should not be used to create {@link SceneResult} object with
- * {@link SceneStatus#SUCCESS}. Use {@link SceneResult#SUCCESS} instead.
*
- * @param status the status
+ * @param status the status. Must not be null.
+ * @param errorMessage an optional error message.
*/
public SceneResult(SceneStatus status, String errorMessage) {
this(status, errorMessage, null);
@@ -90,31 +73,26 @@ public class SceneResult {
/**
* Creates a {@link SceneResult} object with the given SceneStatus, and the given message
* and {@link Throwable}
- * <p>
- * This should not be used to create {@link SceneResult} object with
- * {@link SceneStatus#SUCCESS}. Use {@link SceneResult#SUCCESS} instead.
*
- * @param status the status
+ * @param status the status. Must not be null.
+ * @param errorMessage an optional error message.
+ * @param t an optional exception.
*/
public SceneResult(SceneStatus status, String errorMessage, Throwable t) {
- assert status != SceneStatus.SUCCESS;
+ assert status != null;
mStatus = status;
mErrorMessage = errorMessage;
mThrowable = t;
}
/**
- * Creates a {@link SceneResult} object with the given SceneStatus.
+ * Returns whether the status is successful.
* <p>
- * This should not be used to create {@link SceneResult} object with
- * {@link SceneStatus#SUCCESS}. Use {@link SceneResult#SUCCESS} instead.
- *
- * @param status the status
+ * This is the same as calling <code>getStatus() == SceneStatus.SUCCESS</code>
+ * @return <code>true</code> if the status is successful.
*/
- public SceneResult(SceneStatus status) {
- mStatus = status;
- mErrorMessage = null;
- mThrowable = null;
+ public boolean isSuccess() {
+ return mStatus == SceneStatus.SUCCESS;
}
/**
@@ -139,4 +117,20 @@ public class SceneResult {
public Throwable getException() {
return mThrowable;
}
+
+ /**
+ * Sets an optional data bundle in the result object.
+ * @param data the data bundle
+ */
+ public void SetData(Object data) {
+ mData = data;
+ }
+
+ /**
+ * Returns the optional data bundle stored in the result object.
+ * @return the data bundle or <code>null</code> if none have been set.
+ */
+ public Object getData() {
+ return mData;
+ }
}