Home | History | Annotate | Download | only in animator
      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     public ElementDescriptor getDescriptor() {
     41         if (mDescriptor == null) {
     42             mDescriptor = new ElementDescriptor("", getRootElementDescriptors()); //$NON-NLS-1$
     43         }
     44 
     45         return mDescriptor;
     46     }
     47 
     48     public ElementDescriptor[] getRootElementDescriptors() {
     49         return mRootDescriptors;
     50     }
     51 
     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 
     67     public synchronized void updateDescriptors(Map<String, DeclareStyleableInfo> styleMap) {
     68         if (styleMap == null) {
     69             return;
     70         }
     71 
     72         XmlnsAttributeDescriptor xmlns = new XmlnsAttributeDescriptor(ANDROID_NS_NAME,
     73                 SdkConstants.NS_RESOURCES);
     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