diff options
author | Xavier Ducrohet <xav@android.com> | 2010-11-24 16:41:53 -0800 |
---|---|---|
committer | Xavier Ducrohet <xav@android.com> | 2010-11-29 11:51:58 -0800 |
commit | d9881e4b0ed00c7f7fd529f482cfd08b7d9ec396 (patch) | |
tree | aeec22f6cbc66c69113c7054e34d2e6cd97ec3eb /layoutlib_api/src/com/android/layoutlib | |
parent | a2f6143a565e77b21026aca9bce7da41c350374c (diff) | |
download | sdk-d9881e4b0ed00c7f7fd529f482cfd08b7d9ec396.zip sdk-d9881e4b0ed00c7f7fd529f482cfd08b7d9ec396.tar.gz sdk-d9881e4b0ed00c7f7fd529f482cfd08b7d9ec396.tar.bz2 |
ADT: Animation preparation.
Update layoutlib API to work better with the new scene
locking mechanism (for concurrent renderings), new error
types in SceneResult, and updated Animation listener.
ADT changes to record the view object in CanvasViewInfo,
and the current LayoutScene in ViewHierarchy.
Added a test menu item to start an animation. This
is temporary and will be fixed later.
Change-Id: I67df2d116afdfd23c093e4645d4a0f99695c5d95
Diffstat (limited to 'layoutlib_api/src/com/android/layoutlib')
3 files changed, 95 insertions, 25 deletions
diff --git a/layoutlib_api/src/com/android/layoutlib/api/LayoutScene.java b/layoutlib_api/src/com/android/layoutlib/api/LayoutScene.java index 85c7365..899fd49 100644 --- a/layoutlib_api/src/com/android/layoutlib/api/LayoutScene.java +++ b/layoutlib_api/src/com/android/layoutlib/api/LayoutScene.java @@ -16,7 +16,9 @@ package com.android.layoutlib.api; -import com.android.layoutlib.api.SceneResult.LayoutStatus; +import static com.android.layoutlib.api.SceneResult.SceneStatus.NOT_IMPLEMENTED; + +import com.android.layoutlib.api.SceneResult.SceneStatus; import java.awt.image.BufferedImage; import java.util.Map; @@ -41,19 +43,19 @@ public class LayoutScene { /** * Called when the animation is done playing. */ - void done(); + void done(SceneResult result); /** * Returns true if the animation is canceled. */ - void isCanceled(); + boolean isCanceled(); } /** * Returns the last operation result. */ public SceneResult getResult() { - return new SceneResult(LayoutStatus.NOT_IMPLEMENTED); + return NOT_IMPLEMENTED.getResult(); } /** @@ -61,7 +63,7 @@ public class LayoutScene { * <p> * This is reset to a new instance every time {@link #render()} is called and can be * <code>null</code> if the call failed (and the method returned a {@link SceneResult} with - * {@link LayoutStatus#ERROR} or {@link LayoutStatus#NOT_IMPLEMENTED}. + * {@link SceneStatus#ERROR_UNKNOWN} or {@link SceneStatus#NOT_IMPLEMENTED}. * <p/> * This can be safely modified by the caller. */ @@ -74,7 +76,7 @@ public class LayoutScene { * <p> * This is reset to a new instance every time {@link #render()} is called and can be * <code>null</code> if the call failed (and the method returned a {@link SceneResult} with - * {@link LayoutStatus#ERROR} or {@link LayoutStatus#NOT_IMPLEMENTED}. + * {@link SceneStatus#ERROR_UNKNOWN} or {@link SceneStatus#NOT_IMPLEMENTED}. * <p/> * This can be safely modified by the caller. */ @@ -98,10 +100,30 @@ public class LayoutScene { * In case of success, this should be followed by calls to {@link #getRootView()} and * {@link #getImage()} to access the result of the rendering. * + * This is equivalent to calling <code>render(SceneParams.DEFAULT_TIMEOUT)</code> + * * @return a {@link SceneResult} indicating the status of the action. */ public SceneResult render() { - return new SceneResult(LayoutStatus.NOT_IMPLEMENTED); + return render(SceneParams.DEFAULT_TIMEOUT); + } + + /** + * Re-renders the layout as-is, with a given timeout in case other renderings are being done. + * In case of success, this should be followed by calls to {@link #getRootView()} and + * {@link #getImage()} to access the result of the rendering. + * + * The {@link LayoutBridge} is only able to inflate or render one layout at a time. There + * is an internal lock object whenever such an action occurs. The timeout parameter is used + * when attempting to acquire the lock. If the timeout expires, the method will return + * SceneResult.sdfdsf + * + * @param timeout timeout for the rendering, in milliseconds. + * + * @return a {@link SceneResult} indicating the status of the action. + */ + public SceneResult render(long timeout) { + return NOT_IMPLEMENTED.getResult(); } /** @@ -119,7 +141,7 @@ public class LayoutScene { * @return a {@link SceneResult} indicating the status of the action. */ public SceneResult setProperty(int object, String propertyName, String propertyValue) { - return new SceneResult(LayoutStatus.NOT_IMPLEMENTED); + return NOT_IMPLEMENTED.getResult(); } /** @@ -133,7 +155,7 @@ public class LayoutScene { * @return a {@link SceneResult} indicating the status of the action. */ public SceneResult insertChild() { - return new SceneResult(LayoutStatus.NOT_IMPLEMENTED); + return NOT_IMPLEMENTED.getResult(); } /** @@ -147,7 +169,7 @@ public class LayoutScene { * @return a {@link SceneResult} indicating the status of the action. */ public SceneResult removeChild() { - return new SceneResult(LayoutStatus.NOT_IMPLEMENTED); + return NOT_IMPLEMENTED.getResult(); } /** @@ -156,10 +178,15 @@ public class LayoutScene { * The animation playback is asynchronous and the rendered frame is sent vi the * <var>listener</var>. * + * @param targetObject the view object to animate + * @param animationName the name of the animation (res/anim) to play. + * @param listener the listener callback. + * * @return a {@link SceneResult} indicating the status of the action. */ - public SceneResult animate(int object, int animation, IAnimationListener listener) { - return new SceneResult(LayoutStatus.NOT_IMPLEMENTED); + public SceneResult animate(Object targetObject, String animationName, + boolean isFrameworkAnimation, IAnimationListener listener) { + return NOT_IMPLEMENTED.getResult(); } /** diff --git a/layoutlib_api/src/com/android/layoutlib/api/SceneParams.java b/layoutlib_api/src/com/android/layoutlib/api/SceneParams.java index 36c7a0a..0eb9768 100644 --- a/layoutlib_api/src/com/android/layoutlib/api/SceneParams.java +++ b/layoutlib_api/src/com/android/layoutlib/api/SceneParams.java @@ -20,6 +20,8 @@ import java.util.Map; public class SceneParams { + public final static long DEFAULT_TIMEOUT = 250; //ms + public static enum RenderingMode { NORMAL(false, false), V_SCROLL(false, true), @@ -57,8 +59,10 @@ public class SceneParams { private Map<String, Map<String, IResourceValue>> mFrameworkResources; private IProjectCallback mProjectCallback; private ILayoutLog mLogger; + private boolean mCustomBackgroundEnabled; private int mCustomBackgroundColor; + private long mTimeout; /** * @@ -108,6 +112,7 @@ public class SceneParams { mProjectCallback = projectCallback; mLogger = logger; mCustomBackgroundEnabled = false; + mTimeout = DEFAULT_TIMEOUT; } /** @@ -130,6 +135,7 @@ public class SceneParams { mLogger = params.mLogger; mCustomBackgroundEnabled = params.mCustomBackgroundEnabled; mCustomBackgroundColor = params.mCustomBackgroundColor; + mTimeout = params.mTimeout; } public void setCustomBackgroundColor(int color) { @@ -137,6 +143,10 @@ public class SceneParams { mCustomBackgroundColor = color; } + public void setCustomTimeout(long timeout) { + mTimeout = timeout; + } + public IXmlPullParser getLayoutDescription() { return mLayoutDescription; } @@ -200,4 +210,8 @@ public class SceneParams { public int getCustomBackgroundColor() { return mCustomBackgroundColor; } + + public long getTimeout() { + return mTimeout; + } } diff --git a/layoutlib_api/src/com/android/layoutlib/api/SceneResult.java b/layoutlib_api/src/com/android/layoutlib/api/SceneResult.java index 386eecc..57094ea 100644 --- a/layoutlib_api/src/com/android/layoutlib/api/SceneResult.java +++ b/layoutlib_api/src/com/android/layoutlib/api/SceneResult.java @@ -16,43 +16,70 @@ package com.android.layoutlib.api; - /** * Scene result class. */ public class SceneResult { - private final LayoutStatus mStatus; + private final SceneStatus mStatus; private final String mErrorMessage; private final Throwable mThrowable; - public enum LayoutStatus { SUCCESS, ERROR, NOT_IMPLEMENTED }; + public enum SceneStatus { + SUCCESS, + NOT_IMPLEMENTED, + ERROR_TIMEOUT, + ERROR_LOCK_INTERRUPTED, + ERROR_UNKNOWN; + + /** + * Returns a {@link SceneResult} object with this status. + * @return an instance of SceneResult; + */ + public SceneResult getResult() { + // 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(LayoutStatus.SUCCESS); + public static final SceneResult SUCCESS = new SceneResult(SceneStatus.SUCCESS); /** - * Creates an error {@link SceneResult} object with the given message. + * Creates a {@link SceneResult} object, with {@link SceneStatus#ERROR_UNKNOWN} status, and + * the given message. */ public SceneResult(String errorMessage) { - mStatus = LayoutStatus.ERROR; + mStatus = SceneStatus.ERROR_UNKNOWN; mErrorMessage = errorMessage; mThrowable = null; } /** - * Creates an error {@link SceneResult} object with the given message and {@link Throwable} + * Creates a {@link SceneResult} object, with {@link SceneStatus#ERROR_UNKNOWN} status, and + * the given message and {@link Throwable} */ public SceneResult(String errorMessage, Throwable t) { - mStatus = LayoutStatus.ERROR; + mStatus = SceneStatus.ERROR_UNKNOWN; mErrorMessage = errorMessage; mThrowable = t; } - /*package*/ SceneResult(LayoutStatus status) { - mStatus = LayoutStatus.NOT_IMPLEMENTED; + /** + * Creates a{@link SceneResult} object with the given SceneStatus. + * + * @param status the status + */ + private SceneResult(SceneStatus status) { + mStatus = status; mErrorMessage = null; mThrowable = null; } @@ -60,19 +87,21 @@ public class SceneResult { /** * Returns the status. This is never null. */ - public LayoutStatus getStatus() { + public SceneStatus getStatus() { return mStatus; } /** - * Returns the error message. This can be null if the status is {@link LayoutStatus#SUCCESS}. + * Returns the error message. This is only non-null when {@link #getStatus()} returns + * {@link SceneStatus#ERROR_UNKNOWN} */ public String getErrorMessage() { return mErrorMessage; } /** - * Returns the exception. This can be null. + * Returns the exception. This is only non-null when {@link #getStatus()} returns + * {@link SceneStatus#ERROR_UNKNOWN} */ public Throwable getException() { return mThrowable; |