aboutsummaryrefslogtreecommitdiffstats
path: root/layoutlib_api/src
diff options
context:
space:
mode:
Diffstat (limited to 'layoutlib_api/src')
-rw-r--r--layoutlib_api/src/com/android/layoutlib/api/LayoutScene.java51
-rw-r--r--layoutlib_api/src/com/android/layoutlib/api/SceneParams.java14
-rw-r--r--layoutlib_api/src/com/android/layoutlib/api/SceneResult.java55
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;