diff options
author | Xavier Ducrohet <xav@android.com> | 2010-12-02 11:53:05 -0800 |
---|---|---|
committer | Xavier Ducrohet <xav@android.com> | 2010-12-02 12:09:22 -0800 |
commit | 6d62f10bf1158488089f432b9975a857b806a231 (patch) | |
tree | 7c6b1877a22f33b29fbef1b15b17c81895608fa7 /layoutlib_api/src | |
parent | a09caf06bde2da9e45d57dda5d64b7244ada5f70 (diff) | |
download | sdk-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
Diffstat (limited to 'layoutlib_api/src')
-rw-r--r-- | layoutlib_api/src/com/android/layoutlib/api/LayoutScene.java | 27 | ||||
-rw-r--r-- | layoutlib_api/src/com/android/layoutlib/api/SceneResult.java | 72 |
2 files changed, 49 insertions, 50 deletions
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; + } } |