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 /eclipse | |
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 'eclipse')
4 files changed, 69 insertions, 4 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/CanvasViewInfo.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/CanvasViewInfo.java index cc2c489..29f4874 100755 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/CanvasViewInfo.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/CanvasViewInfo.java @@ -61,6 +61,7 @@ public class CanvasViewInfo implements IPropertySource { private final Rectangle mAbsRect; private final Rectangle mSelectionRect; private final String mName; + private final Object mViewObject; private final UiViewElementNode mUiViewNode; private final CanvasViewInfo mParent; private final ArrayList<CanvasViewInfo> mChildren = new ArrayList<CanvasViewInfo>(); @@ -86,6 +87,7 @@ public class CanvasViewInfo implements IPropertySource { int parentX, int parentY) { mParent = parent; mName = viewInfo.getClassName(); + mViewObject = viewInfo.getViewObject(); // The ViewInfo#getViewKey() method returns a cookie uniquely identifying the object // they represent on this side of the API. @@ -210,6 +212,14 @@ public class CanvasViewInfo implements IPropertySource { return mName; } + /** + * Returns the View object associated with the {@link CanvasViewInfo}. + * @return the view object or null. + */ + public Object getViewObject() { + return mViewObject; + } + // ---- Implementation of IPropertySource public Object getEditableValue() { diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/GraphicalEditorPart.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/GraphicalEditorPart.java index 0243764..8cb13e6 100755 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/GraphicalEditorPart.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/GraphicalEditorPart.java @@ -1290,10 +1290,6 @@ public class GraphicalEditorPart extends EditorPart } } - // at the moment we don't keep the scene around for future actions, - // so we must dispose it asap. - scene.dispose(); - model.refreshUi(); } 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 8f5f048..89eb9a4 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 @@ -29,6 +29,8 @@ import com.android.ide.eclipse.adt.internal.editors.layout.uimodel.UiViewElement import com.android.ide.eclipse.adt.internal.editors.uimodel.UiDocumentNode; import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode; import com.android.layoutlib.api.LayoutScene; +import com.android.layoutlib.api.SceneResult; +import com.android.layoutlib.api.LayoutScene.IAnimationListener; import com.android.sdklib.SdkConstants; import org.eclipse.core.filesystem.EFS; @@ -83,6 +85,7 @@ import org.eclipse.ui.internal.ide.IDEWorkbenchMessages; import org.eclipse.ui.views.contentoutline.IContentOutlinePage; import org.w3c.dom.Node; +import java.awt.image.BufferedImage; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.HashSet; @@ -998,6 +1001,46 @@ class LayoutCanvas extends Canvas { manager.add(new Separator()); + // 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) { + @Override + public void run() { + List<CanvasSelection> selection = mSelectionManager.getSelections(); + CanvasSelection canvasSelection = selection.get(0); + CanvasViewInfo info = canvasSelection.getViewInfo(); + + Object viewObject = info.getViewObject(); + if (viewObject != null) { + LayoutScene scene = mViewHierarchy.getScene(); + + 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(); + } + }); + } + + public boolean isCanceled() { + return false; + } + + public void done(SceneResult result) { + } + }); + } + } + }); + + + manager.add(new Separator()); + manager.add(mDeleteAction); manager.add(mSelectAllAction); 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 c737fc4..58e3d1a 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 @@ -95,6 +95,8 @@ public class ViewHierarchy { */ private boolean mExplodedParents; + private LayoutScene mScene; + /** * 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. @@ -111,6 +113,12 @@ public class ViewHierarchy { * nodes are padded during certain interactions. */ /* package */ void setResult(LayoutScene scene, Set<UiElementNode> explodedNodes) { + // replace the previous scene, so the previous scene must be disposed. + if (mScene != null) { + mScene.dispose(); + } + + mScene = scene; mIsResultValid = (scene != null && scene.getResult() == SceneResult.SUCCESS); mExplodedParents = false; @@ -202,6 +210,14 @@ public class ViewHierarchy { } /** + * Returns the current {@link LayoutScene}. + * @return the scene or null if none have been set. + */ + public LayoutScene getScene() { + return mScene; + } + + /** * Returns true when the last {@link #setResult} provided a valid * {@link LayoutScene}. * <p/> |