OSDN Git Service

Use res/animator rather than res/anim for the Play Animation code
authorTor Norbye <tnorbye@google.com>
Tue, 11 Jan 2011 22:50:59 +0000 (14:50 -0800)
committerTor Norbye <tnorbye@google.com>
Wed, 12 Jan 2011 00:44:43 +0000 (16:44 -0800)
We should be using ResourceType.ANIMATOR rather than ResourceType.ANIM
for the designtime playable animations. Simple tweak to make the
"Create Animation" dialog able to create files into res/animator/,
though this needs to be improved (with proper animator/interpolator
root elements etc).

Change-Id: I70a504fbd946da3ff161f9cf953b878a41886fee

eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/layout/gle2/PlayAnimationMenu.java
eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newxmlfile/NewXmlFileCreationPage.java

index b1bd79f..878c50e 100644 (file)
 package com.android.ide.eclipse.adt.internal.editors.layout.gle2;
 
 import static com.android.ide.eclipse.adt.AndroidConstants.WS_SEP;
-import static com.android.sdklib.SdkConstants.FD_ANIM;
+import static com.android.sdklib.SdkConstants.FD_ANIMATOR;
 import static com.android.sdklib.SdkConstants.FD_RESOURCES;
 
 import com.android.ide.common.rendering.api.Capability;
 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.eclipse.adt.AdtPlugin;
 import com.android.ide.eclipse.adt.internal.editors.layout.LayoutEditor;
 import com.android.ide.eclipse.adt.internal.resources.ResourceType;
 import com.android.ide.eclipse.adt.internal.wizards.newxmlfile.NewXmlFileWizard;
@@ -116,7 +117,7 @@ public class PlayAnimationMenu extends SubmenuAction {
 
             // List of animations
             Collection<String> animationNames = graphicalEditor.getResourceNames(mFramework,
-                    ResourceType.ANIM);
+                    ResourceType.ANIMATOR);
             if (animationNames.size() > 0) {
                 if (!mFramework) {
                     new Separator().fill(menu, -1);
@@ -158,7 +159,7 @@ public class PlayAnimationMenu extends SubmenuAction {
             if (viewObject != null) {
                 ViewHierarchy viewHierarchy = mCanvas.getViewHierarchy();
                 RenderSession session = viewHierarchy.getSession();
-                session.animate(viewObject, mAnimationName, mIsFrameworkAnim,
+                Result r = session.animate(viewObject, mAnimationName, mIsFrameworkAnim,
                         new IAnimationListener() {
                             private boolean mPendingDrawing = false;
 
@@ -211,6 +212,12 @@ public class PlayAnimationMenu extends SubmenuAction {
                                 });
                             }
                         });
+
+                if (!r.isSuccess()) {
+                    if (r.getErrorMessage() != null) {
+                        AdtPlugin.log(r.getException(), r.getErrorMessage());
+                    }
+                }
             }
         }
     }
@@ -231,7 +238,7 @@ public class PlayAnimationMenu extends SubmenuAction {
             LayoutEditor editor = mCanvas.getLayoutEditor();
             IWorkbenchWindow workbenchWindow = editor.getEditorSite().getWorkbenchWindow();
             IWorkbench workbench = workbenchWindow.getWorkbench();
-            String animationDir = FD_RESOURCES + WS_SEP + FD_ANIM;
+            String animationDir = FD_RESOURCES + WS_SEP + FD_ANIMATOR;
             Pair<IProject, String> pair = Pair.of(editor.getProject(), animationDir);
             IStructuredSelection selection = new StructuredSelection(pair);
             wizard.init(workbench, selection);
index fe62e26..b3f34aa 100644 (file)
@@ -1040,6 +1040,19 @@ class NewXmlFileCreationPage extends WizardPage {
                     }
                 }
 
+                // For now, treat a selection of /res/animator as /res/anim/,
+                // though we need to handle this better
+                // TODO: Properly support ANIMATOR templates!
+                if (!selected && folderName.equals(SdkConstants.FD_ANIMATOR)) {
+                    for (TypeInfo type : sTypes) {
+                        if (type.getResFolderType() == ResourceFolderType.ANIM) {
+                            matches.add(type);
+                            selected |= type.getWidget().getSelection();
+                            break;
+                        }
+                    }
+                }
+
                 if (matches.size() == 1) {
                     // If there's only one match, select it if it's not already selected
                     if (!selected) {