From e80f4d4d2ac48db8d94b6071e296a8acba32a09a Mon Sep 17 00:00:00 2001 From: Xavier Ducrohet Date: Mon, 29 Nov 2010 11:45:47 -0800 Subject: [PATCH] ADT: more animation stuff. Change-Id: I020342a4fe205161328f22e9dabb0b03343677b5 --- .../internal/editors/layout/gle2/LayoutCanvas.java | 45 +++++++++++++++++----- .../editors/layout/gle2/ViewHierarchy.java | 11 ++++++ .../src/com/android/layoutlib/api/LayoutScene.java | 24 +++++++++--- 3 files changed, 66 insertions(+), 14 deletions(-) diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutCanvas.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutCanvas.java index 4782204d1..ff5d3c49c 100755 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutCanvas.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/LayoutCanvas.java @@ -346,6 +346,8 @@ class LayoutCanvas extends Canvas { mImageOverlay.dispose(); mImageOverlay = null; } + + mViewHierarchy.dispose(); } /** Returns the Rules Engine, associated with the current project. */ @@ -1004,7 +1006,8 @@ class LayoutCanvas extends Canvas { // Add test action // Don't add it at the top above (by the cut action) because the // dynamic context menu makes some assumptions about where things are - manager.add(new Action("Run My Test", IAction.AS_PUSH_BUTTON) { + // FIXME remove test. + manager.add(new Action("Play anim test", IAction.AS_PUSH_BUTTON) { @Override public void run() { List selection = mSelectionManager.getSelections(); @@ -1017,14 +1020,21 @@ class LayoutCanvas extends Canvas { scene.animate(viewObject, "testanim", false /*isFrameworkAnimation*/, new IAnimationListener() { - - public void onNewFrame(final BufferedImage image) { - getDisplay().asyncExec(new Runnable() { - public void run() { - mImageOverlay.setImage(image); - redraw(); - } - }); + private int mCount = 0; + private BufferedImage mImage; + private boolean mPendingDrawing = false; + public synchronized void onNewFrame(final BufferedImage image) { + mCount++; + mImage = image; + if (mPendingDrawing == false) { + getDisplay().asyncExec(new Runnable() { + public void run() { + drawImage(); + } + }); + + mPendingDrawing = true; + } } public boolean isCanceled() { @@ -1032,6 +1042,23 @@ class LayoutCanvas extends Canvas { } public void done(SceneResult result) { + System.out.println("Animation count: " + mCount); + } + + /** + * this is called from the UI thread from the asyncRunnable. + */ + public void drawImage() { + // get last image + BufferedImage image; + synchronized (this) { + image = mImage; + mImage = null; + mPendingDrawing = false; + } + + mImageOverlay.setImage(image); + redraw(); } }); } diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/ViewHierarchy.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/ViewHierarchy.java index 58e3d1ab5..686b0bada 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/ViewHierarchy.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/ViewHierarchy.java @@ -98,6 +98,17 @@ public class ViewHierarchy { private LayoutScene mScene; /** + * Disposes the view hierarchy content. + */ + public void dispose() { + if (mScene != null) { + mScene.dispose(); + mScene = null; + } + } + + + /** * Sets the result of the layout rendering. The result object indicates if the layout * rendering succeeded. If it did, it contains a bitmap and the objects rectangles. * diff --git a/layoutlib_api/src/com/android/layoutlib/api/LayoutScene.java b/layoutlib_api/src/com/android/layoutlib/api/LayoutScene.java index 899fd498e..3429367c2 100644 --- a/layoutlib_api/src/com/android/layoutlib/api/LayoutScene.java +++ b/layoutlib_api/src/com/android/layoutlib/api/LayoutScene.java @@ -116,7 +116,7 @@ public class LayoutScene { * 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 + * {@link SceneStatus#ERROR_TIMEOUT}. * * @param timeout timeout for the rendering, in milliseconds. * @@ -134,13 +134,13 @@ public class LayoutScene { *

* Any amount of actions can be taken on the scene before {@link #render()} is called. * - * @param object + * @param objectView * @param propertyName * @param propertyValue * * @return a {@link SceneResult} indicating the status of the action. */ - public SceneResult setProperty(int object, String propertyName, String propertyValue) { + public SceneResult setProperty(Object objectView, String propertyName, String propertyValue) { return NOT_IMPLEMENTED.getResult(); } @@ -154,7 +154,21 @@ public class LayoutScene { * * @return a {@link SceneResult} indicating the status of the action. */ - public SceneResult insertChild() { + public SceneResult insertChild(Object parentView, IXmlPullParser childXml, int index) { + return NOT_IMPLEMENTED.getResult(); + } + + /** + * Inserts a new child in a ViewGroup object. + *

+ * This does nothing more than change the layouy. To render the scene in its new state, a + * call to {@link #render()} is required. + *

+ * Any amount of actions can be taken on the scene before {@link #render()} is called. + * + * @return a {@link SceneResult} indicating the status of the action. + */ + public SceneResult moveChild(Object parentView, IXmlPullParser layoutParamsXml, int index) { return NOT_IMPLEMENTED.getResult(); } @@ -168,7 +182,7 @@ public class LayoutScene { * * @return a {@link SceneResult} indicating the status of the action. */ - public SceneResult removeChild() { + public SceneResult removeChild(Object parentView, int index) { return NOT_IMPLEMENTED.getResult(); } -- 2.11.0