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 static com.android.ide.common.layout.LayoutConstants.ANDROID_NS_NAME; 19 20 import com.android.ide.common.resources.platform.DeclareStyleableInfo; 21 import com.android.ide.eclipse.adt.internal.editors.descriptors.ElementDescriptor; 22 import com.android.ide.eclipse.adt.internal.editors.descriptors.IDescriptorProvider; 23 import com.android.ide.eclipse.adt.internal.editors.descriptors.XmlnsAttributeDescriptor; 24 import com.android.sdklib.SdkConstants; 25 26 import java.util.ArrayList; 27 import java.util.HashMap; 28 import java.util.List; 29 import java.util.Map; 30 31 /** Descriptors for the res/anim resources */ 32 public class AnimDescriptors implements IDescriptorProvider { 33 /** The root element descriptor */ 34 private ElementDescriptor mDescriptor; 35 /** The root element descriptors */ 36 private ElementDescriptor[] mRootDescriptors; 37 private Map<String, ElementDescriptor> nameToDescriptor; 38 39 /** @return the root descriptor. */ 40 @Override getDescriptor()41 public ElementDescriptor getDescriptor() { 42 if (mDescriptor == null) { 43 mDescriptor = new ElementDescriptor("", getRootElementDescriptors()); //$NON-NLS-1$ 44 } 45 46 return mDescriptor; 47 } 48 49 @Override getRootElementDescriptors()50 public ElementDescriptor[] getRootElementDescriptors() { 51 return mRootDescriptors; 52 } 53 getElementDescriptor(String mRootTag)54 public ElementDescriptor getElementDescriptor(String mRootTag) { 55 if (nameToDescriptor == null) { 56 nameToDescriptor = new HashMap<String, ElementDescriptor>(); 57 for (ElementDescriptor descriptor : getRootElementDescriptors()) { 58 nameToDescriptor.put(descriptor.getXmlName(), descriptor); 59 } 60 } 61 62 ElementDescriptor descriptor = nameToDescriptor.get(mRootTag); 63 if (descriptor == null) { 64 descriptor = getDescriptor(); 65 } 66 return descriptor; 67 } 68 updateDescriptors(Map<String, DeclareStyleableInfo> styleMap)69 public synchronized void updateDescriptors(Map<String, DeclareStyleableInfo> styleMap) { 70 if (styleMap == null) { 71 return; 72 } 73 74 XmlnsAttributeDescriptor xmlns = new XmlnsAttributeDescriptor(ANDROID_NS_NAME, 75 SdkConstants.NS_RESOURCES); 76 77 List<ElementDescriptor> descriptors = new ArrayList<ElementDescriptor>(); 78 79 String sdkUrl = 80 "http://developer.android.com/guide/topics/graphics/view-animation.html"; //$NON-NLS-1$ 81 ElementDescriptor set = AnimatorDescriptors.addElement(descriptors, styleMap, 82 "set", "Set", "AnimationSet", "Animation", //$NON-NLS-1$ //$NON-NLS-3$ //$NON-NLS-4$ 83 "A container that holds other animation elements (<alpha>, <scale>, " 84 + "<translate>, <rotate>) or other <set> elements. ", 85 sdkUrl, 86 xmlns, null, true /*mandatory*/); 87 88 AnimatorDescriptors.addElement(descriptors, styleMap, 89 "alpha", "Alpha", "AlphaAnimation", "Animation", //$NON-NLS-1$ //$NON-NLS-3$ //$NON-NLS-4$ 90 "A fade-in or fade-out animation.", 91 sdkUrl, 92 xmlns, null, true /*mandatory*/); 93 94 AnimatorDescriptors.addElement(descriptors, styleMap, 95 "scale", "Scale", "ScaleAnimation", "Animation", //$NON-NLS-1$ //$NON-NLS-3$ //$NON-NLS-4$ 96 "A resizing animation. You can specify the center point of the image from " 97 + "which it grows outward (or inward) by specifying pivotX and pivotY. " 98 + "For example, if these values are 0, 0 (top-left corner), all growth " 99 + "will be down and to the right.", 100 sdkUrl, 101 xmlns, null, true /*mandatory*/); 102 103 AnimatorDescriptors.addElement(descriptors, styleMap, 104 "rotate", "Rotate", "RotateAnimation", "Animation", //$NON-NLS-1$ //$NON-NLS-3$ //$NON-NLS-4$ 105 "A rotation animation.", 106 sdkUrl, 107 xmlns, null, true /*mandatory*/); 108 109 AnimatorDescriptors.addElement(descriptors, styleMap, 110 "translate", "Translate", "TranslateAnimation", "Animation", //$NON-NLS-1$ //$NON-NLS-3$ //$NON-NLS-4$ 111 "A vertical and/or horizontal motion. Supports the following attributes in " 112 + "any of the following three formats: values from -100 to 100 ending " 113 + "with \"%\", indicating a percentage relative to itself; values from " 114 + "-100 to 100 ending in \"%p\", indicating a percentage relative to its " 115 + "parent; a float value with no suffix, indicating an absolute value.", 116 sdkUrl, 117 xmlns, null, true /*mandatory*/); 118 119 mRootDescriptors = descriptors.toArray(new ElementDescriptor[descriptors.size()]); 120 121 // Allow <set> to nest the others (and other sets) 122 if (set != null) { 123 set.setChildren(mRootDescriptors); 124 } 125 } 126 } 127