diff options
author | Xavier Ducrohet <xav@android.com> | 2010-12-15 19:20:08 -0800 |
---|---|---|
committer | Xavier Ducrohet <xav@android.com> | 2010-12-21 10:43:17 -0800 |
commit | 19a021038f2f4683dddef651543d7298f5bd7218 (patch) | |
tree | 358449cfa97dffe26183d672f92aae8101a1e624 /tools | |
parent | 34884643b66d2560273b7c29d3eacb59560ab231 (diff) | |
download | frameworks_base-19a021038f2f4683dddef651543d7298f5bd7218.zip frameworks_base-19a021038f2f4683dddef651543d7298f5bd7218.tar.gz frameworks_base-19a021038f2f4683dddef651543d7298f5bd7218.tar.bz2 |
LayoutLib: Update layoutlib with revised API.
Change-Id: I78929df621f48e85d9cbefe1f5590f9ce99bbaff
Diffstat (limited to 'tools')
15 files changed, 204 insertions, 194 deletions
diff --git a/tools/layoutlib/bridge/src/android/app/Fragment_Delegate.java b/tools/layoutlib/bridge/src/android/app/Fragment_Delegate.java index b46d95c..60ad645 100644 --- a/tools/layoutlib/bridge/src/android/app/Fragment_Delegate.java +++ b/tools/layoutlib/bridge/src/android/app/Fragment_Delegate.java @@ -16,7 +16,7 @@ package android.app; -import com.android.layoutlib.api.IProjectCallback; +import com.android.ide.common.rendering.api.IProjectCallback; import android.content.Context; import android.os.Bundle; diff --git a/tools/layoutlib/bridge/src/android/graphics/BitmapFactory.java b/tools/layoutlib/bridge/src/android/graphics/BitmapFactory.java index 626f878..c57aef6 100644 --- a/tools/layoutlib/bridge/src/android/graphics/BitmapFactory.java +++ b/tools/layoutlib/bridge/src/android/graphics/BitmapFactory.java @@ -16,7 +16,7 @@ package android.graphics; -import com.android.layoutlib.api.ResourceDensity; +import com.android.ide.common.rendering.api.ResourceDensity; import com.android.layoutlib.bridge.Bridge; import android.content.res.AssetManager; diff --git a/tools/layoutlib/bridge/src/android/graphics/Bitmap_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Bitmap_Delegate.java index fe201c1..d69abc9 100644 --- a/tools/layoutlib/bridge/src/android/graphics/Bitmap_Delegate.java +++ b/tools/layoutlib/bridge/src/android/graphics/Bitmap_Delegate.java @@ -16,7 +16,7 @@ package android.graphics; -import com.android.layoutlib.api.ResourceDensity; +import com.android.ide.common.rendering.api.ResourceDensity; import com.android.layoutlib.bridge.impl.DelegateManager; import android.graphics.Bitmap.Config; diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java index c30e8e4..5f40854 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java @@ -16,15 +16,17 @@ package com.android.layoutlib.bridge; -import com.android.layoutlib.api.Capability; -import com.android.layoutlib.api.LayoutBridge; -import com.android.layoutlib.api.LayoutLog; -import com.android.layoutlib.api.SceneParams; -import com.android.layoutlib.api.SceneResult; -import com.android.layoutlib.api.SceneResult.SceneStatus; +import static com.android.ide.common.rendering.api.Result.Status.ERROR_UNKNOWN; +import static com.android.ide.common.rendering.api.Result.Status.SUCCESS; + +import com.android.ide.common.rendering.api.Capability; +import com.android.ide.common.rendering.api.LayoutLog; +import com.android.ide.common.rendering.api.Params; +import com.android.ide.common.rendering.api.RenderSession; +import com.android.ide.common.rendering.api.Result; import com.android.layoutlib.bridge.android.BridgeAssetManager; import com.android.layoutlib.bridge.impl.FontLoader; -import com.android.layoutlib.bridge.impl.LayoutSceneImpl; +import com.android.layoutlib.bridge.impl.RenderSessionImpl; import com.android.ninepatch.NinePatchChunk; import com.android.tools.layoutlib.create.MethodAdapter; import com.android.tools.layoutlib.create.OverrideMethod; @@ -33,6 +35,7 @@ import android.graphics.Bitmap; import android.graphics.Typeface_Delegate; import android.os.Looper; +import java.io.File; import java.lang.ref.SoftReference; import java.lang.reflect.Field; import java.lang.reflect.Modifier; @@ -47,7 +50,7 @@ import java.util.concurrent.locks.ReentrantLock; * <p/>To use this bridge, simply instantiate an object of type {@link Bridge} and call * {@link #createScene(SceneParams)} */ -public final class Bridge extends LayoutBridge { +public final class Bridge extends com.android.ide.common.rendering.api.Bridge { public static class StaticMethodNotImplementedException extends RuntimeException { private static final long serialVersionUID = 1L; @@ -169,7 +172,7 @@ public final class Bridge extends LayoutBridge { @Override public int getApiLevel() { - return LayoutBridge.API_CURRENT; + return com.android.ide.common.rendering.api.Bridge.API_CURRENT; } @Override @@ -179,10 +182,10 @@ public final class Bridge extends LayoutBridge { /* * (non-Javadoc) - * @see com.android.layoutlib.api.ILayoutLibBridge#init(java.lang.String, java.util.Map) + * @see com.android.layoutlib.api.ILayoutLibBridge#init(java.io.File, java.util.Map) */ @Override - public boolean init(String fontOsLocation, Map<String, Map<String, Integer>> enumValueMap) { + public boolean init(File fontLocation, Map<String, Map<String, Integer>> enumValueMap) { sEnumValueMap = enumValueMap; // don't use EnumSet.allOf(), because the bridge doesn't come with its specific version @@ -229,7 +232,7 @@ public final class Bridge extends LayoutBridge { } // load the fonts. - FontLoader fontLoader = FontLoader.create(fontOsLocation); + FontLoader fontLoader = FontLoader.create(fontLocation.getAbsolutePath()); if (fontLoader != null) { Typeface_Delegate.init(fontLoader); } else { @@ -299,10 +302,10 @@ public final class Bridge extends LayoutBridge { * @since 5 */ @Override - public BridgeLayoutScene createScene(SceneParams params) { + public RenderSession createSession(Params params) { try { - SceneResult lastResult = SceneStatus.SUCCESS.createResult(); - LayoutSceneImpl scene = new LayoutSceneImpl(params); + Result lastResult = SUCCESS.createResult(); + RenderSessionImpl scene = new RenderSessionImpl(params); try { prepareThread(); lastResult = scene.init(params.getTimeout()); @@ -317,15 +320,15 @@ public final class Bridge extends LayoutBridge { cleanupThread(); } - return new BridgeLayoutScene(scene, lastResult); + return new BridgeRenderSession(scene, lastResult); } catch (Throwable t) { // get the real cause of the exception. Throwable t2 = t; while (t2.getCause() != null) { t2 = t.getCause(); } - return new BridgeLayoutScene(null, - SceneStatus.ERROR_UNKNOWN.createResult(t2.getMessage(), t2)); + return new BridgeRenderSession(null, + ERROR_UNKNOWN.createResult(t2.getMessage(), t2)); } } diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeLayoutScene.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeRenderSession.java index f43559f..a09524c 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeLayoutScene.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeRenderSession.java @@ -16,12 +16,13 @@ package com.android.layoutlib.bridge; -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.ViewInfo; -import com.android.layoutlib.bridge.impl.LayoutSceneImpl; +import com.android.ide.common.rendering.api.IAnimationListener; +import com.android.ide.common.rendering.api.ILayoutPullParser; +import com.android.ide.common.rendering.api.Params; +import com.android.ide.common.rendering.api.RenderSession; +import com.android.ide.common.rendering.api.Result; +import com.android.ide.common.rendering.api.ViewInfo; +import com.android.layoutlib.bridge.impl.RenderSessionImpl; import android.view.View; import android.view.ViewGroup; @@ -30,47 +31,47 @@ import java.awt.image.BufferedImage; import java.util.Map; /** - * An implementation of {@link LayoutScene}. + * An implementation of {@link RenderSession}. * * This is a pretty basic class that does almost nothing. All of the work is done in - * {@link LayoutSceneImpl}. + * {@link RenderSessionImpl}. * */ -public class BridgeLayoutScene extends LayoutScene { +public class BridgeRenderSession extends RenderSession { - private final LayoutSceneImpl mScene; - private SceneResult mLastResult; + private final RenderSessionImpl mSession; + private Result mLastResult; @Override - public SceneResult getResult() { + public Result getResult() { return mLastResult; } @Override public BufferedImage getImage() { - return mScene.getImage(); + return mSession.getImage(); } @Override public ViewInfo getRootView() { - return mScene.getViewInfo(); + return mSession.getViewInfo(); } @Override - public Map<String, String> getDefaultViewPropertyValues(Object viewObject) { - return mScene.getDefaultViewPropertyValues(viewObject); + public Map<String, String> getDefaultProperties(Object viewObject) { + return mSession.getDefaultProperties(viewObject); } @Override - public SceneResult render(long timeout) { + public Result render(long timeout) { try { Bridge.prepareThread(); - mLastResult = mScene.acquire(timeout); + mLastResult = mSession.acquire(timeout); if (mLastResult.isSuccess()) { - mLastResult = mScene.render(); + mLastResult = mSession.render(); } } finally { - mScene.release(); + mSession.release(); Bridge.cleanupThread(); } @@ -78,17 +79,17 @@ public class BridgeLayoutScene extends LayoutScene { } @Override - public SceneResult animate(Object targetObject, String animationName, + public Result animate(Object targetObject, String animationName, boolean isFrameworkAnimation, IAnimationListener listener) { try { Bridge.prepareThread(); - mLastResult = mScene.acquire(SceneParams.DEFAULT_TIMEOUT); + mLastResult = mSession.acquire(Params.DEFAULT_TIMEOUT); if (mLastResult.isSuccess()) { - mLastResult = mScene.animate(targetObject, animationName, isFrameworkAnimation, + mLastResult = mSession.animate(targetObject, animationName, isFrameworkAnimation, listener); } } finally { - mScene.release(); + mSession.release(); Bridge.cleanupThread(); } @@ -96,7 +97,7 @@ public class BridgeLayoutScene extends LayoutScene { } @Override - public SceneResult insertChild(Object parentView, IXmlPullParser childXml, int index, + public Result insertChild(Object parentView, ILayoutPullParser childXml, int index, IAnimationListener listener) { if (parentView instanceof ViewGroup == false) { throw new IllegalArgumentException("parentView is not a ViewGroup"); @@ -104,12 +105,12 @@ public class BridgeLayoutScene extends LayoutScene { try { Bridge.prepareThread(); - mLastResult = mScene.acquire(SceneParams.DEFAULT_TIMEOUT); + mLastResult = mSession.acquire(Params.DEFAULT_TIMEOUT); if (mLastResult.isSuccess()) { - mLastResult = mScene.insertChild((ViewGroup) parentView, childXml, index, listener); + mLastResult = mSession.insertChild((ViewGroup) parentView, childXml, index, listener); } } finally { - mScene.release(); + mSession.release(); Bridge.cleanupThread(); } @@ -118,7 +119,7 @@ public class BridgeLayoutScene extends LayoutScene { @Override - public SceneResult moveChild(Object parentView, Object childView, int index, + public Result moveChild(Object parentView, Object childView, int index, Map<String, String> layoutParams, IAnimationListener listener) { if (parentView instanceof ViewGroup == false) { throw new IllegalArgumentException("parentView is not a ViewGroup"); @@ -129,13 +130,13 @@ public class BridgeLayoutScene extends LayoutScene { try { Bridge.prepareThread(); - mLastResult = mScene.acquire(SceneParams.DEFAULT_TIMEOUT); + mLastResult = mSession.acquire(Params.DEFAULT_TIMEOUT); if (mLastResult.isSuccess()) { - mLastResult = mScene.moveChild((ViewGroup) parentView, (View) childView, index, + mLastResult = mSession.moveChild((ViewGroup) parentView, (View) childView, index, layoutParams, listener); } } finally { - mScene.release(); + mSession.release(); Bridge.cleanupThread(); } @@ -143,19 +144,19 @@ public class BridgeLayoutScene extends LayoutScene { } @Override - public SceneResult removeChild(Object childView, IAnimationListener listener) { + public Result removeChild(Object childView, IAnimationListener listener) { if (childView instanceof View == false) { throw new IllegalArgumentException("childView is not a View"); } try { Bridge.prepareThread(); - mLastResult = mScene.acquire(SceneParams.DEFAULT_TIMEOUT); + mLastResult = mSession.acquire(Params.DEFAULT_TIMEOUT); if (mLastResult.isSuccess()) { - mLastResult = mScene.removeChild((View) childView, listener); + mLastResult = mSession.removeChild((View) childView, listener); } } finally { - mScene.release(); + mSession.release(); Bridge.cleanupThread(); } @@ -166,9 +167,9 @@ public class BridgeLayoutScene extends LayoutScene { public void dispose() { } - /*package*/ BridgeLayoutScene(LayoutSceneImpl scene, SceneResult lastResult) { - mScene = scene; - mScene.setScene(this); + /*package*/ BridgeRenderSession(RenderSessionImpl scene, Result lastResult) { + mSession = scene; + mSession.setScene(this); mLastResult = lastResult; } } diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java index f484e7a..7269227 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java @@ -16,9 +16,9 @@ package com.android.layoutlib.bridge.android; -import com.android.layoutlib.api.IProjectCallback; -import com.android.layoutlib.api.ResourceValue; -import com.android.layoutlib.api.StyleResourceValue; +import com.android.ide.common.rendering.api.IProjectCallback; +import com.android.ide.common.rendering.api.ResourceValue; +import com.android.ide.common.rendering.api.StyleResourceValue; import com.android.layoutlib.bridge.Bridge; import com.android.layoutlib.bridge.BridgeConstants; import com.android.layoutlib.bridge.impl.Stack; @@ -105,11 +105,11 @@ public final class BridgeContext extends Activity { * @param themeName The name of the theme to use. * @param projectResources the resources of the project. The map contains (String, map) pairs * where the string is the type of the resource reference used in the layout file, and the - * map contains (String, {@link IResourceValue}) pairs where the key is the resource name, + * map contains (String, {@link }) pairs where the key is the resource name, * and the value is the resource value. * @param frameworkResources the framework resources. The map contains (String, map) pairs * where the string is the type of the resource reference used in the layout file, and the map - * contains (String, {@link IResourceValue}) pairs where the key is the resource name, and the + * contains (String, {@link ResourceValue}) pairs where the key is the resource name, and the * value is the resource value. * @param styleInheritanceMap * @param projectCallback @@ -321,7 +321,7 @@ public final class BridgeContext extends Activity { isPlatformFile = parser.isPlatformFile(); - Object key = parser.getViewKey(); + Object key = parser.getViewCookie(); if (key != null) { defaultPropMap = mDefaultPropMaps.get(key); if (defaultPropMap == null) { diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeInflater.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeInflater.java index dbf83e7..1b59621 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeInflater.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeInflater.java @@ -16,8 +16,8 @@ package com.android.layoutlib.bridge.android; -import com.android.layoutlib.api.IProjectCallback; -import com.android.layoutlib.api.ResourceValue; +import com.android.ide.common.rendering.api.IProjectCallback; +import com.android.ide.common.rendering.api.ResourceValue; import com.android.layoutlib.bridge.Bridge; import com.android.layoutlib.bridge.BridgeConstants; @@ -217,14 +217,14 @@ public final class BridgeInflater extends LayoutInflater { BridgeXmlBlockParser parser = (BridgeXmlBlockParser) attrs; // get the view key - Object viewKey = parser.getViewKey(); + Object viewKey = parser.getViewCookie(); // if there's no view key and the depth is 1 (ie this is the first tag), // look for a previous parser in the context, and check if this one has a viewkey. if (viewKey == null && parser.getDepth() == 1) { BridgeXmlBlockParser previousParser = bc.getPreviousParser(); if (previousParser != null) { - viewKey = previousParser.getViewKey(); + viewKey = previousParser.getViewCookie(); } } diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeResources.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeResources.java index c1e2046..2ea5281 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeResources.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeResources.java @@ -16,8 +16,8 @@ package com.android.layoutlib.bridge.android; -import com.android.layoutlib.api.IProjectCallback; -import com.android.layoutlib.api.ResourceValue; +import com.android.ide.common.rendering.api.IProjectCallback; +import com.android.ide.common.rendering.api.ResourceValue; import com.android.layoutlib.bridge.Bridge; import com.android.layoutlib.bridge.BridgeConstants; import com.android.layoutlib.bridge.impl.ResourceHelper; diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeTypedArray.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeTypedArray.java index fcbf5fa..6ae7e03 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeTypedArray.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeTypedArray.java @@ -16,9 +16,9 @@ package com.android.layoutlib.bridge.android; +import com.android.ide.common.rendering.api.ResourceValue; +import com.android.ide.common.rendering.api.StyleResourceValue; import com.android.internal.util.XmlUtils; -import com.android.layoutlib.api.ResourceValue; -import com.android.layoutlib.api.StyleResourceValue; import com.android.layoutlib.bridge.Bridge; import com.android.layoutlib.bridge.BridgeConstants; import com.android.layoutlib.bridge.impl.ResourceHelper; @@ -66,7 +66,7 @@ public final class BridgeTypedArray extends TypedArray { } /** - * Seals the array after all calls to {@link #bridgeSetValue(int, String, IResourceValue)} have + * Seals the array after all calls to {@link #bridgeSetValue(int, String, ResourceValue)} have * been done. * <p/>This allows to compute the list of non default values, permitting * {@link #getIndexCount()} to return the proper value. diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeXmlBlockParser.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeXmlBlockParser.java index 73bee96..38800da 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeXmlBlockParser.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeXmlBlockParser.java @@ -16,7 +16,8 @@ package com.android.layoutlib.bridge.android; -import com.android.layoutlib.api.IXmlPullParser; + +import com.android.ide.common.rendering.api.ILayoutPullParser; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; @@ -65,17 +66,17 @@ public class BridgeXmlBlockParser implements XmlResourceParser { return mPlatformFile; } - public IXmlPullParser getParser(String layoutName) { - if (mParser instanceof IXmlPullParser) { - return ((IXmlPullParser)mParser).getParser(layoutName); + public ILayoutPullParser getParser(String layoutName) { + if (mParser instanceof ILayoutPullParser) { + return ((ILayoutPullParser)mParser).getParser(layoutName); } return null; } - public Object getViewKey() { - if (mParser instanceof IXmlPullParser) { - return ((IXmlPullParser)mParser).getViewKey(); + public Object getViewCookie() { + if (mParser instanceof ILayoutPullParser) { + return ((ILayoutPullParser)mParser).getViewCookie(); } return null; diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeXmlPullAttributes.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeXmlPullAttributes.java index 92b98e5..ba45217 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeXmlPullAttributes.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeXmlPullAttributes.java @@ -16,7 +16,7 @@ package com.android.layoutlib.bridge.android; -import com.android.layoutlib.api.ResourceValue; +import com.android.ide.common.rendering.api.ResourceValue; import com.android.layoutlib.bridge.Bridge; import com.android.layoutlib.bridge.BridgeConstants; diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/AnimationThread.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/AnimationThread.java index 4ee813c..1651d6a 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/AnimationThread.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/AnimationThread.java @@ -16,10 +16,10 @@ package com.android.layoutlib.bridge.impl; -import com.android.layoutlib.api.LayoutScene; -import com.android.layoutlib.api.SceneResult; -import com.android.layoutlib.api.LayoutScene.IAnimationListener; -import com.android.layoutlib.api.SceneResult.SceneStatus; +import com.android.ide.common.rendering.api.IAnimationListener; +import com.android.ide.common.rendering.api.RenderSession; +import com.android.ide.common.rendering.api.Result; +import com.android.ide.common.rendering.api.Result.Status; import com.android.layoutlib.bridge.Bridge; import android.animation.ValueAnimator; @@ -57,18 +57,19 @@ public abstract class AnimationThread extends Thread { } } - private final LayoutSceneImpl mScene; + private final RenderSessionImpl mSession; Queue<MessageBundle> mQueue = new LinkedList<MessageBundle>(); private final IAnimationListener mListener; - public AnimationThread(LayoutSceneImpl scene, String threadName, IAnimationListener listener) { + public AnimationThread(RenderSessionImpl scene, String threadName, + IAnimationListener listener) { super(threadName); - mScene = scene; + mSession = scene; mListener = listener; } - public abstract SceneResult preAnimation(); + public abstract Result preAnimation(); public abstract void postAnimation(); @Override @@ -87,13 +88,13 @@ public abstract class AnimationThread extends Thread { }); // call out to the pre-animation work, which should start an animation or more. - SceneResult result = preAnimation(); + Result result = preAnimation(); if (result.isSuccess() == false) { mListener.done(result); } // loop the animation - LayoutScene scene = mScene.getScene(); + RenderSession session = mSession.getSession(); do { // check early. if (mListener.isCanceled()) { @@ -123,7 +124,7 @@ public abstract class AnimationThread extends Thread { } // ready to do the work, acquire the scene. - result = mScene.acquire(250); + result = mSession.acquire(250); if (result.isSuccess() == false) { mListener.done(result); return; @@ -138,15 +139,15 @@ public abstract class AnimationThread extends Thread { } bundle.mTarget.handleMessage(bundle.mMessage); - if (mScene.render().isSuccess()) { - mListener.onNewFrame(scene); + if (mSession.render().isSuccess()) { + mListener.onNewFrame(session); } } finally { - mScene.release(); + mSession.release(); } } while (mListener.isCanceled() == false && mQueue.size() > 0); - mListener.done(SceneStatus.SUCCESS.createResult()); + mListener.done(Status.SUCCESS.createResult()); } finally { postAnimation(); Handler_Delegate.setCallback(null); diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/PlayAnimationThread.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/PlayAnimationThread.java index 2e2c5f4..35e5987 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/PlayAnimationThread.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/PlayAnimationThread.java @@ -16,9 +16,9 @@ package com.android.layoutlib.bridge.impl; -import com.android.layoutlib.api.SceneResult; -import com.android.layoutlib.api.LayoutScene.IAnimationListener; -import com.android.layoutlib.api.SceneResult.SceneStatus; +import com.android.ide.common.rendering.api.IAnimationListener; +import com.android.ide.common.rendering.api.Result; +import com.android.ide.common.rendering.api.Result.Status; import android.animation.Animator; @@ -26,19 +26,19 @@ public class PlayAnimationThread extends AnimationThread { private final Animator mAnimator; - public PlayAnimationThread(Animator animator, LayoutSceneImpl scene, String animName, + public PlayAnimationThread(Animator animator, RenderSessionImpl scene, String animName, IAnimationListener listener) { super(scene, animName, listener); mAnimator = animator; } @Override - public SceneResult preAnimation() { + public Result preAnimation() { // start the animation. This will send a message to the handler right away, so // the queue is filled when this method returns. mAnimator.start(); - return SceneStatus.SUCCESS.createResult(); + return Status.SUCCESS.createResult(); } @Override diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/LayoutSceneImpl.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java index 24cf380..5f86c92 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/LayoutSceneImpl.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java @@ -16,24 +16,28 @@ package com.android.layoutlib.bridge.impl; -import static com.android.layoutlib.api.SceneResult.SceneStatus.ERROR_LOCK_INTERRUPTED; -import static com.android.layoutlib.api.SceneResult.SceneStatus.ERROR_TIMEOUT; -import static com.android.layoutlib.api.SceneResult.SceneStatus.SUCCESS; - +import static com.android.ide.common.rendering.api.Result.Status.ERROR_ANIM_NOT_FOUND; +import static com.android.ide.common.rendering.api.Result.Status.ERROR_INFLATION; +import static com.android.ide.common.rendering.api.Result.Status.ERROR_LOCK_INTERRUPTED; +import static com.android.ide.common.rendering.api.Result.Status.ERROR_NOT_INFLATED; +import static com.android.ide.common.rendering.api.Result.Status.ERROR_TIMEOUT; +import static com.android.ide.common.rendering.api.Result.Status.ERROR_UNKNOWN; +import static com.android.ide.common.rendering.api.Result.Status.ERROR_VIEWGROUP_NO_CHILDREN; +import static com.android.ide.common.rendering.api.Result.Status.SUCCESS; + +import com.android.ide.common.rendering.api.IAnimationListener; +import com.android.ide.common.rendering.api.ILayoutPullParser; +import com.android.ide.common.rendering.api.IProjectCallback; +import com.android.ide.common.rendering.api.Params; +import com.android.ide.common.rendering.api.RenderSession; +import com.android.ide.common.rendering.api.ResourceDensity; +import com.android.ide.common.rendering.api.ResourceValue; +import com.android.ide.common.rendering.api.Result; +import com.android.ide.common.rendering.api.StyleResourceValue; +import com.android.ide.common.rendering.api.ViewInfo; +import com.android.ide.common.rendering.api.Params.RenderingMode; +import com.android.ide.common.rendering.api.Result.Status; import com.android.internal.util.XmlUtils; -import com.android.layoutlib.api.IProjectCallback; -import com.android.layoutlib.api.IXmlPullParser; -import com.android.layoutlib.api.LayoutBridge; -import com.android.layoutlib.api.LayoutScene; -import com.android.layoutlib.api.ResourceDensity; -import com.android.layoutlib.api.ResourceValue; -import com.android.layoutlib.api.SceneParams; -import com.android.layoutlib.api.SceneResult; -import com.android.layoutlib.api.StyleResourceValue; -import com.android.layoutlib.api.ViewInfo; -import com.android.layoutlib.api.LayoutScene.IAnimationListener; -import com.android.layoutlib.api.SceneParams.RenderingMode; -import com.android.layoutlib.api.SceneResult.SceneStatus; import com.android.layoutlib.bridge.Bridge; import com.android.layoutlib.bridge.BridgeConstants; import com.android.layoutlib.bridge.android.BridgeContext; @@ -75,14 +79,14 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.ReentrantLock; /** - * Class managing a layout "scene". + * Class implementing the render session. * - * A scene is a stateful representation of a layout file. It is initialized with data coming through - * the {@link LayoutBridge} API to inflate the layout. Further actions and rendering can then + * A session is a stateful representation of a layout file. It is initialized with data coming + * through the {@link Bridge} API to inflate the layout. Further actions and rendering can then * be done on the layout. * */ -public class LayoutSceneImpl { +public class RenderSessionImpl { private static final int DEFAULT_TITLE_BAR_HEIGHT = 25; private static final int DEFAULT_STATUS_BAR_HEIGHT = 25; @@ -93,10 +97,10 @@ public class LayoutSceneImpl { */ private static BridgeContext sCurrentContext = null; - private final SceneParams mParams; + private final Params mParams; // scene state - private LayoutScene mScene; + private RenderSession mScene; private BridgeContext mContext; private BridgeXmlBlockParser mBlockParser; private BridgeInflater mInflater; @@ -123,14 +127,14 @@ public class LayoutSceneImpl { /** * Creates a layout scene with all the information coming from the layout bridge API. * <p> - * This <b>must</b> be followed by a call to {@link LayoutSceneImpl#init()}, which act as a - * call to {@link LayoutSceneImpl#acquire(long)} + * This <b>must</b> be followed by a call to {@link RenderSessionImpl#init()}, which act as a + * call to {@link RenderSessionImpl#acquire(long)} * * @see LayoutBridge#createScene(com.android.layoutlib.api.SceneParams) */ - public LayoutSceneImpl(SceneParams params) { + public RenderSessionImpl(Params params) { // copy the params. - mParams = new SceneParams(params); + mParams = new Params(params); } /** @@ -144,10 +148,10 @@ public class LayoutSceneImpl { * @see #acquire(long) * @see #release() */ - public SceneResult init(long timeout) { + public Result init(long timeout) { // acquire the lock. if the result is null, lock was just acquired, otherwise, return // the result. - SceneResult result = acquireLock(timeout); + Result result = acquireLock(timeout); if (result != null) { return result; } @@ -168,7 +172,7 @@ public class LayoutSceneImpl { Map<StyleResourceValue, StyleResourceValue> styleParentMap = new HashMap<StyleResourceValue, StyleResourceValue>(); - mCurrentTheme = computeStyleMaps(mParams.getThemeName(), mParams.getIsProjectTheme(), + mCurrentTheme = computeStyleMaps(mParams.getThemeName(), mParams.isProjectTheme(), mParams.getProjectResources().get(BridgeConstants.RES_STYLE), mParams.getFrameworkResources().get(BridgeConstants.RES_STYLE), styleParentMap); @@ -187,7 +191,7 @@ public class LayoutSceneImpl { // get the screen offset and window-background resource mWindowBackground = null; mScreenOffset = 0; - if (mCurrentTheme != null && mParams.isCustomBackgroundEnabled() == false) { + if (mCurrentTheme != null && mParams.isBgColorOverridden() == false) { mWindowBackground = mContext.findItemInStyle(mCurrentTheme, "windowBackground"); mWindowBackground = mContext.resolveResValue(mWindowBackground); @@ -203,7 +207,7 @@ public class LayoutSceneImpl { mBlockParser = new BridgeXmlBlockParser(mParams.getLayoutDescription(), mContext, false /* platformResourceFlag */); - return SceneStatus.SUCCESS.createResult(); + return SUCCESS.createResult(); } /** @@ -215,7 +219,7 @@ public class LayoutSceneImpl { * The preparation can fail if another rendering took too long and the timeout was elapsed. * * More than one call to this from the same thread will have no effect and will return - * {@link SceneResult#SUCCESS}. + * {@link Result#SUCCESS}. * * After scene actions have taken place, only one call to {@link #release()} must be * done. @@ -228,14 +232,14 @@ public class LayoutSceneImpl { * * @throws IllegalStateException if {@link #init(long)} was never called. */ - public SceneResult acquire(long timeout) { + public Result acquire(long timeout) { if (mContext == null) { throw new IllegalStateException("After scene creation, #init() must be called"); } // acquire the lock. if the result is null, lock was just acquired, otherwise, return // the result. - SceneResult result = acquireLock(timeout); + Result result = acquireLock(timeout); if (result != null) { return result; } @@ -253,8 +257,8 @@ public class LayoutSceneImpl { * Acquire the lock so that the scene can be acted upon. * <p> * This returns null if the lock was just acquired, otherwise it returns - * {@link SceneResult#SUCCESS} if the lock already belonged to that thread, or another - * instance (see {@link SceneResult#getStatus()}) if an error occurred. + * {@link Result#SUCCESS} if the lock already belonged to that thread, or another + * instance (see {@link Result#getStatus()}) if an error occurred. * * @param timeout the time to wait if another rendering is happening. * @return null if the lock was just acquire or another result depending on the state. @@ -262,7 +266,7 @@ public class LayoutSceneImpl { * @throws IllegalStateException if the current context is different than the one owned by * the scene. */ - private SceneResult acquireLock(long timeout) { + private Result acquireLock(long timeout) { ReentrantLock lock = Bridge.getLock(); if (lock.isHeldByCurrentThread() == false) { try { @@ -314,7 +318,7 @@ public class LayoutSceneImpl { * @throws IllegalStateException if the current context is different than the one owned by * the scene, or if {@link #init(long)} was not called. */ - public SceneResult inflate() { + public Result inflate() { checkLock(); try { @@ -347,9 +351,9 @@ public class LayoutSceneImpl { mViewRoot.setBackgroundDrawable(d); } - return SceneStatus.SUCCESS.createResult(); + return SUCCESS.createResult(); } catch (PostInflateException e) { - return SceneStatus.ERROR_INFLATION.createResult(e.getMessage(), e); + return ERROR_INFLATION.createResult(e.getMessage(), e); } catch (Throwable e) { // get the real cause of the exception. Throwable t = e; @@ -360,7 +364,7 @@ public class LayoutSceneImpl { // log it mParams.getLog().error("Scene inflate failed", t); - return SceneStatus.ERROR_INFLATION.createResult(t.getMessage(), t); + return ERROR_INFLATION.createResult(t.getMessage(), t); } } @@ -375,12 +379,12 @@ public class LayoutSceneImpl { * @see SceneParams#getRenderingMode() * @see LayoutScene#render(long) */ - public SceneResult render() { + public Result render() { checkLock(); try { if (mViewRoot == null) { - return SceneStatus.ERROR_NOT_INFLATED.createResult(); + return ERROR_NOT_INFLATED.createResult(); } // measure the views int w_spec, h_spec; @@ -443,9 +447,9 @@ public class LayoutSceneImpl { mMeasuredScreenHeight - mScreenOffset, BufferedImage.TYPE_INT_ARGB); } - if (mParams.isCustomBackgroundEnabled()) { + if (mParams.isBgColorOverridden()) { Graphics2D gc = mImage.createGraphics(); - gc.setColor(new Color(mParams.getCustomBackgroundColor(), true)); + gc.setColor(new Color(mParams.getOverrideBgColor(), true)); gc.fillRect(0, 0, mMeasuredScreenWidth, mMeasuredScreenHeight - mScreenOffset); gc.dispose(); } @@ -465,7 +469,7 @@ public class LayoutSceneImpl { mViewInfo = visit(((ViewGroup)mViewRoot).getChildAt(0), mContext); // success! - return SceneStatus.SUCCESS.createResult(); + return SUCCESS.createResult(); } catch (Throwable e) { // get the real cause of the exception. Throwable t = e; @@ -476,7 +480,7 @@ public class LayoutSceneImpl { // log it mParams.getLog().error("Scene Render failed", t); - return SceneStatus.ERROR_UNKNOWN.createResult(t.getMessage(), t); + return ERROR_UNKNOWN.createResult(t.getMessage(), t); } } @@ -490,7 +494,7 @@ public class LayoutSceneImpl { * * @see LayoutScene#animate(Object, String, boolean, IAnimationListener) */ - public SceneResult animate(Object targetObject, String animationName, + public Result animate(Object targetObject, String animationName, boolean isFrameworkAnimation, IAnimationListener listener) { checkLock(); @@ -517,7 +521,7 @@ public class LayoutSceneImpl { new PlayAnimationThread(anim, this, animationName, listener).start(); - return SceneStatus.SUCCESS.createResult(); + return SUCCESS.createResult(); } } catch (Exception e) { // get the real cause of the exception. @@ -526,11 +530,11 @@ public class LayoutSceneImpl { t = t.getCause(); } - return SceneStatus.ERROR_UNKNOWN.createResult(t.getMessage(), t); + return ERROR_UNKNOWN.createResult(t.getMessage(), t); } } - return SceneStatus.ERROR_ANIM_NOT_FOUND.createResult(); + return ERROR_ANIM_NOT_FOUND.createResult(); } /** @@ -541,9 +545,9 @@ public class LayoutSceneImpl { * @throws IllegalStateException if the current context is different than the one owned by * the scene, or if {@link #acquire(long)} was not called. * - * @see LayoutScene#insertChild(Object, IXmlPullParser, int, IAnimationListener) + * @see LayoutScene#insertChild(Object, ILayoutPullParser, int, IAnimationListener) */ - public SceneResult insertChild(final ViewGroup parentView, IXmlPullParser childXml, + public Result insertChild(final ViewGroup parentView, ILayoutPullParser childXml, final int index, IAnimationListener listener) { checkLock(); @@ -562,7 +566,7 @@ public class LayoutSceneImpl { new AnimationThread(this, "insertChild", listener) { @Override - public SceneResult preAnimation() { + public Result preAnimation() { parentView.setLayoutTransition(new LayoutTransition()); return addView(parentView, child, index); } @@ -574,11 +578,11 @@ public class LayoutSceneImpl { }.start(); // always return success since the real status will come through the listener. - return SceneStatus.SUCCESS.createResult(child); + return SUCCESS.createResult(child); } // add it to the parentView in the correct location - SceneResult result = addView(parentView, child, index); + Result result = addView(parentView, child, index); if (result.isSuccess() == false) { return result; } @@ -598,17 +602,17 @@ public class LayoutSceneImpl { * @param view the view to add to the parent * @param index the index where to do the add. * - * @return a SceneResult with {@link SceneStatus#SUCCESS} or - * {@link SceneStatus#ERROR_VIEWGROUP_NO_CHILDREN} if the given parent doesn't support + * @return a Result with {@link Status#SUCCESS} or + * {@link Status#ERROR_VIEWGROUP_NO_CHILDREN} if the given parent doesn't support * adding views. */ - private SceneResult addView(ViewGroup parent, View view, int index) { + private Result addView(ViewGroup parent, View view, int index) { try { parent.addView(view, index); - return SceneStatus.SUCCESS.createResult(); + return SUCCESS.createResult(); } catch (UnsupportedOperationException e) { // looks like this is a view class that doesn't support children manipulation! - return SceneStatus.ERROR_VIEWGROUP_NO_CHILDREN.createResult(); + return ERROR_VIEWGROUP_NO_CHILDREN.createResult(); } } @@ -622,7 +626,7 @@ public class LayoutSceneImpl { * * @see LayoutScene#moveChild(Object, Object, int, Map, IAnimationListener) */ - public SceneResult moveChild(final ViewGroup parentView, final View childView, final int index, + public Result moveChild(final ViewGroup parentView, final View childView, final int index, Map<String, String> layoutParamsMap, IAnimationListener listener) { checkLock(); @@ -640,7 +644,7 @@ public class LayoutSceneImpl { new AnimationThread(this, "moveChild", listener) { @Override - public SceneResult preAnimation() { + public Result preAnimation() { parentView.setLayoutTransition(new LayoutTransition()); return moveView(parentView, childView, index, params); } @@ -652,10 +656,10 @@ public class LayoutSceneImpl { }.start(); // always return success since the real status will come through the listener. - return SceneStatus.SUCCESS.createResult(layoutParams); + return SUCCESS.createResult(layoutParams); } - SceneResult result = moveView(parentView, childView, index, layoutParams); + Result result = moveView(parentView, childView, index, layoutParams); if (result.isSuccess() == false) { return result; } @@ -677,11 +681,11 @@ public class LayoutSceneImpl { * @param index the new location in the new parent * @param params an option (can be null) {@link LayoutParams} instance. * - * @return a SceneResult with {@link SceneStatus#SUCCESS} or - * {@link SceneStatus#ERROR_VIEWGROUP_NO_CHILDREN} if the given parent doesn't support + * @return a Result with {@link Status#SUCCESS} or + * {@link Status#ERROR_VIEWGROUP_NO_CHILDREN} if the given parent doesn't support * adding views. */ - private SceneResult moveView(ViewGroup parent, View view, int index, LayoutParams params) { + private Result moveView(ViewGroup parent, View view, int index, LayoutParams params) { try { ViewGroup previousParent = (ViewGroup) view.getParent(); previousParent.removeView(view); @@ -694,10 +698,10 @@ public class LayoutSceneImpl { parent.addView(view, index); } - return SceneStatus.SUCCESS.createResult(); + return SUCCESS.createResult(); } catch (UnsupportedOperationException e) { // looks like this is a view class that doesn't support children manipulation! - return SceneStatus.ERROR_VIEWGROUP_NO_CHILDREN.createResult(); + return ERROR_VIEWGROUP_NO_CHILDREN.createResult(); } } @@ -711,7 +715,7 @@ public class LayoutSceneImpl { * * @see LayoutScene#removeChild(Object, IAnimationListener) */ - public SceneResult removeChild(final View childView, IAnimationListener listener) { + public Result removeChild(final View childView, IAnimationListener listener) { checkLock(); invalidateRenderingSize(); @@ -722,7 +726,7 @@ public class LayoutSceneImpl { new AnimationThread(this, "moveChild", listener) { @Override - public SceneResult preAnimation() { + public Result preAnimation() { parent.setLayoutTransition(new LayoutTransition()); return removeView(parent, childView); } @@ -734,10 +738,10 @@ public class LayoutSceneImpl { }.start(); // always return success since the real status will come through the listener. - return SceneStatus.SUCCESS.createResult(); + return SUCCESS.createResult(); } - SceneResult result = removeView(parent, childView); + Result result = removeView(parent, childView); if (result.isSuccess() == false) { return result; } @@ -750,17 +754,17 @@ public class LayoutSceneImpl { * * @param view the view to remove from its parent * - * @return a SceneResult with {@link SceneStatus#SUCCESS} or - * {@link SceneStatus#ERROR_VIEWGROUP_NO_CHILDREN} if the given parent doesn't support + * @return a Result with {@link Status#SUCCESS} or + * {@link Status#ERROR_VIEWGROUP_NO_CHILDREN} if the given parent doesn't support * adding views. */ - private SceneResult removeView(ViewGroup parent, View view) { + private Result removeView(ViewGroup parent, View view) { try { parent.removeView(view); - return SceneStatus.SUCCESS.createResult(); + return SUCCESS.createResult(); } catch (UnsupportedOperationException e) { // looks like this is a view class that doesn't support children manipulation! - return SceneStatus.ERROR_VIEWGROUP_NO_CHILDREN.createResult(); + return ERROR_VIEWGROUP_NO_CHILDREN.createResult(); } } @@ -791,7 +795,7 @@ public class LayoutSceneImpl { * @param inProjectStyleMap the project style map * @param inFrameworkStyleMap the framework style map * @param outInheritanceMap the map of style inheritance. This is filled by the method - * @return the {@link IStyleResourceValue} matching <var>themeName</var> + * @return the {@link StyleResourceValue} matching <var>themeName</var> */ private StyleResourceValue computeStyleMaps( String themeName, boolean isProjectTheme, Map<String, @@ -865,7 +869,7 @@ public class LayoutSceneImpl { } /** - * Searches for and returns the {@link IStyleResourceValue} from a given name. + * Searches for and returns the {@link StyleResourceValue} from a given name. * <p/>The format of the name can be: * <ul> * <li>[android:]<name></li> @@ -875,7 +879,7 @@ public class LayoutSceneImpl { * @param parentName the name of the style. * @param inProjectStyleMap the project style map. Can be <code>null</code> * @param inFrameworkStyleMap the framework style map. - * @return The matching {@link IStyleResourceValue} object or <code>null</code> if not found. + * @return The matching {@link StyleResourceValue} object or <code>null</code> if not found. */ private StyleResourceValue getStyle(String parentName, Map<String, ResourceValue> inProjectStyleMap, @@ -1143,15 +1147,15 @@ public class LayoutSceneImpl { return mViewInfo; } - public Map<String, String> getDefaultViewPropertyValues(Object viewObject) { + public Map<String, String> getDefaultProperties(Object viewObject) { return mContext.getDefaultPropMap(viewObject); } - public void setScene(LayoutScene scene) { - mScene = scene; + public void setScene(RenderSession session) { + mScene = session; } - public LayoutScene getScene() { + public RenderSession getSession() { return mScene; } } diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/ResourceHelper.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/ResourceHelper.java index f03931f..5427f142 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/ResourceHelper.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/ResourceHelper.java @@ -16,9 +16,9 @@ package com.android.layoutlib.bridge.impl; -import com.android.layoutlib.api.DensityBasedResourceValue; -import com.android.layoutlib.api.ResourceDensity; -import com.android.layoutlib.api.ResourceValue; +import com.android.ide.common.rendering.api.DensityBasedResourceValue; +import com.android.ide.common.rendering.api.ResourceDensity; +import com.android.ide.common.rendering.api.ResourceValue; import com.android.layoutlib.bridge.Bridge; import com.android.layoutlib.bridge.android.BridgeContext; import com.android.layoutlib.bridge.android.BridgeXmlBlockParser; |