aboutsummaryrefslogtreecommitdiffstats
path: root/layoutlib_api/src/com/android/layoutlib
diff options
context:
space:
mode:
authorXavier Ducrohet <xav@android.com>2010-12-03 10:48:32 -0800
committerXavier Ducrohet <xav@android.com>2010-12-03 11:26:38 -0800
commit9eadd4e557ebf420d7773e168abd6df9233a042a (patch)
treeb0a7e522b30d3206ee90af64cca237488c478fd8 /layoutlib_api/src/com/android/layoutlib
parent55da58bc9cff4800a9832a1e46f2701d5f4fa02d (diff)
downloadsdk-9eadd4e557ebf420d7773e168abd6df9233a042a.zip
sdk-9eadd4e557ebf420d7773e168abd6df9233a042a.tar.gz
sdk-9eadd4e557ebf420d7773e168abd6df9233a042a.tar.bz2
LayoutLib API: SceneResult API clean up.
Change-Id: I1cb80da55f9ff16d0422eb6c4767448a4691b74b
Diffstat (limited to 'layoutlib_api/src/com/android/layoutlib')
-rw-r--r--layoutlib_api/src/com/android/layoutlib/api/SceneResult.java97
1 files changed, 74 insertions, 23 deletions
diff --git a/layoutlib_api/src/com/android/layoutlib/api/SceneResult.java b/layoutlib_api/src/com/android/layoutlib/api/SceneResult.java
index 20081a1..1a46167 100644
--- a/layoutlib_api/src/com/android/layoutlib/api/SceneResult.java
+++ b/layoutlib_api/src/com/android/layoutlib/api/SceneResult.java
@@ -17,7 +17,13 @@
package com.android.layoutlib.api;
/**
- * Scene result class.
+ * Scene result class. This is an immutable class.
+ * <p/>
+ * This cannot be allocated directly, instead use
+ * {@link SceneStatus#getResult()},
+ * {@link SceneStatus#getResult(String, Throwable)},
+ * {@link SceneStatus#getResult(String)}
+ * {@link SceneStatus#getResult(Object)}
*/
public class SceneResult {
@@ -26,6 +32,10 @@ public class SceneResult {
private final Throwable mThrowable;
private Object mData;
+ /**
+ * Scene Status enum.
+ * <p/>This indicates the status of all scene actions.
+ */
public enum SceneStatus {
SUCCESS,
NOT_IMPLEMENTED,
@@ -38,6 +48,8 @@ public class SceneResult {
ERROR_ANIM_NOT_FOUND,
ERROR_UNKNOWN;
+ private SceneResult mResult;
+
/**
* Returns a {@link SceneResult} object with this status.
* @return an instance of SceneResult;
@@ -46,7 +58,46 @@ public class SceneResult {
// don't want to get generic error that way.
assert this != ERROR_UNKNOWN;
- return new SceneResult(this);
+ if (mResult == null) {
+ mResult = new SceneResult(this);
+ }
+
+ return mResult;
+ }
+
+ /**
+ * Returns a {@link SceneResult} object with this status, and the given data.
+ * @return an instance of SceneResult;
+ *
+ * @see SceneResult#getData()
+ */
+ public SceneResult getResult(Object data) {
+ SceneResult res = getResult();
+
+ if (data != null) {
+ res = res.getCopyWithData(data);
+ }
+
+ return res;
+ }
+
+ /**
+ * Returns a {@link #ERROR_UNKNOWN} result with the given message and throwable
+ * @param errorMessage the error message
+ * @param throwable the throwable
+ * @return an instance of SceneResult.
+ */
+ public SceneResult getResult(String errorMessage, Throwable throwable) {
+ return new SceneResult(this, errorMessage, throwable);
+ }
+
+ /**
+ * Returns a {@link #ERROR_UNKNOWN} result with the given message
+ * @param errorMessage the error message
+ * @return an instance of SceneResult.
+ */
+ public SceneResult getResult(String errorMessage) {
+ return new SceneResult(this, errorMessage, null /*throwable*/);
}
}
@@ -55,36 +106,44 @@ public class SceneResult {
*
* @param status the status. Must not be null.
*/
- public SceneResult(SceneStatus status) {
+ private SceneResult(SceneStatus status) {
this(status, null, null);
}
/**
* Creates a {@link SceneResult} object with the given SceneStatus, and the given message
- * and {@link Throwable}.
- *
- * @param status the status. Must not be null.
- * @param errorMessage an optional error message.
- */
- public SceneResult(SceneStatus status, String errorMessage) {
- this(status, errorMessage, null);
- }
-
- /**
- * Creates a {@link SceneResult} object with the given SceneStatus, and the given message
* and {@link Throwable}
*
* @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) {
+ private SceneResult(SceneStatus status, String errorMessage, Throwable t) {
assert status != null;
mStatus = status;
mErrorMessage = errorMessage;
mThrowable = t;
}
+ private SceneResult(SceneResult result) {
+ mStatus = result.mStatus;
+ mErrorMessage = result.mErrorMessage;
+ mThrowable = result.mThrowable;
+ }
+
+ /**
+ * Returns a copy of the current result with the added (or replaced) given data
+ * @param data the data bundle
+ *
+ * @return returns a new SceneResult instance.
+ */
+ public SceneResult getCopyWithData(Object data) {
+ SceneResult r = new SceneResult(this);
+ r.mData = data;
+ return r;
+ }
+
+
/**
* Returns whether the status is successful.
* <p>
@@ -119,14 +178,6 @@ public class SceneResult {
}
/**
- * 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.
*/