• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 The Android Open Source Project
3  *
4  * Licensed under the Eclipse Public License, Version 1.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.eclipse.org/org/documents/epl-v10.php
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.android.ide.eclipse.adt.internal.editors.animator;
17 
18 import com.android.SdkConstants;
19 import com.android.ide.common.resources.platform.DeclareStyleableInfo;
20 import com.android.ide.eclipse.adt.internal.editors.descriptors.ElementDescriptor;
21 import com.android.ide.eclipse.adt.internal.editors.descriptors.IDescriptorProvider;
22 import com.android.ide.eclipse.adt.internal.editors.descriptors.XmlnsAttributeDescriptor;
23 
24 import java.util.ArrayList;
25 import java.util.HashMap;
26 import java.util.List;
27 import java.util.Map;
28 
29 /** Descriptors for the res/anim resources */
30 public class AnimDescriptors implements IDescriptorProvider {
31     /** The root element descriptor */
32     private ElementDescriptor mDescriptor;
33     /** The root element descriptors */
34     private ElementDescriptor[] mRootDescriptors;
35     private Map<String, ElementDescriptor> nameToDescriptor;
36 
37     /** @return the root descriptor. */
38     @Override
getDescriptor()39     public ElementDescriptor getDescriptor() {
40         if (mDescriptor == null) {
41             mDescriptor = new ElementDescriptor("", getRootElementDescriptors()); //$NON-NLS-1$
42         }
43 
44         return mDescriptor;
45     }
46 
47     @Override
getRootElementDescriptors()48     public ElementDescriptor[] getRootElementDescriptors() {
49         return mRootDescriptors;
50     }
51 
getElementDescriptor(String mRootTag)52     public ElementDescriptor getElementDescriptor(String mRootTag) {
53         if (nameToDescriptor == null) {
54             nameToDescriptor = new HashMap<String, ElementDescriptor>();
55             for (ElementDescriptor descriptor : getRootElementDescriptors()) {
56                 nameToDescriptor.put(descriptor.getXmlName(), descriptor);
57             }
58         }
59 
60         ElementDescriptor descriptor = nameToDescriptor.get(mRootTag);
61         if (descriptor == null) {
62             descriptor = getDescriptor();
63         }
64         return descriptor;
65     }
66 
updateDescriptors(Map<String, DeclareStyleableInfo> styleMap)67     public synchronized void updateDescriptors(Map<String, DeclareStyleableInfo> styleMap) {
68         if (styleMap == null) {
69             return;
70         }
71 
72         XmlnsAttributeDescriptor xmlns = new XmlnsAttributeDescriptor(SdkConstants.ANDROID_NS_NAME,
73                 SdkConstants.ANDROID_URI);
74 
75         List<ElementDescriptor> descriptors = new ArrayList<ElementDescriptor>();
76 
77         String sdkUrl =
78             "http://developer.android.com/guide/topics/graphics/view-animation.html"; //$NON-NLS-1$
79         ElementDescriptor set = AnimatorDescriptors.addElement(descriptors, styleMap,
80                 "set", "Set", "AnimationSet", "Animation", //$NON-NLS-1$ //$NON-NLS-3$ //$NON-NLS-4$
81                 "A container that holds other animation elements (<alpha>, <scale>, "
82                     + "<translate>, <rotate>) or other <set> elements. ",
83                 sdkUrl,
84                 xmlns, null, true /*mandatory*/);
85 
86         AnimatorDescriptors.addElement(descriptors, styleMap,
87                 "alpha", "Alpha", "AlphaAnimation", "Animation", //$NON-NLS-1$ //$NON-NLS-3$ //$NON-NLS-4$
88                 "A fade-in or fade-out animation.",
89                 sdkUrl,
90                 xmlns, null, true /*mandatory*/);
91 
92         AnimatorDescriptors.addElement(descriptors, styleMap,
93                 "scale", "Scale", "ScaleAnimation", "Animation", //$NON-NLS-1$ //$NON-NLS-3$ //$NON-NLS-4$
94                 "A resizing animation. You can specify the center point of the image from "
95                     + "which it grows outward (or inward) by specifying pivotX and pivotY. "
96                     + "For example, if these values are 0, 0 (top-left corner), all growth "
97                     + "will be down and to the right.",
98                 sdkUrl,
99                 xmlns, null, true /*mandatory*/);
100 
101         AnimatorDescriptors.addElement(descriptors, styleMap,
102                 "rotate", "Rotate", "RotateAnimation", "Animation", //$NON-NLS-1$ //$NON-NLS-3$ //$NON-NLS-4$
103                 "A rotation animation.",
104                 sdkUrl,
105                 xmlns, null, true /*mandatory*/);
106 
107         AnimatorDescriptors.addElement(descriptors, styleMap,
108                 "translate", "Translate", "TranslateAnimation", "Animation", //$NON-NLS-1$ //$NON-NLS-3$ //$NON-NLS-4$
109                 "A vertical and/or horizontal motion. Supports the following attributes in "
110                     + "any of the following three formats: values from -100 to 100 ending "
111                     + "with \"%\", indicating a percentage relative to itself; values from "
112                     + "-100 to 100 ending in \"%p\", indicating a percentage relative to its "
113                     + "parent; a float value with no suffix, indicating an absolute value.",
114                 sdkUrl,
115                 xmlns, null, true /*mandatory*/);
116 
117         mRootDescriptors = descriptors.toArray(new ElementDescriptor[descriptors.size()]);
118 
119         // Allow <set> to nest the others (and other sets)
120         if (set != null) {
121             set.setChildren(mRootDescriptors);
122         }
123     }
124 }
125