Home | History | Annotate | Download | only in color
      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.color;
     17 
     18 import static com.android.SdkConstants.ANDROID_NS_NAME;
     19 import static com.android.SdkConstants.ANDROID_URI;
     20 
     21 import com.android.ide.common.api.IAttributeInfo.Format;
     22 import com.android.ide.common.resources.platform.AttributeInfo;
     23 import com.android.ide.common.resources.platform.DeclareStyleableInfo;
     24 import com.android.ide.eclipse.adt.internal.editors.animator.AnimatorDescriptors;
     25 import com.android.ide.eclipse.adt.internal.editors.descriptors.AttributeDescriptor;
     26 import com.android.ide.eclipse.adt.internal.editors.descriptors.ElementDescriptor;
     27 import com.android.ide.eclipse.adt.internal.editors.descriptors.IDescriptorProvider;
     28 import com.android.ide.eclipse.adt.internal.editors.descriptors.ReferenceAttributeDescriptor;
     29 import com.android.ide.eclipse.adt.internal.editors.descriptors.XmlnsAttributeDescriptor;
     30 import com.android.resources.ResourceType;
     31 
     32 import java.util.Map;
     33 
     34 /** Descriptors for /res/color XML files */
     35 public class ColorDescriptors implements IDescriptorProvider {
     36     private static final String SDK_URL =
     37         "http://d.android.com/guide/topics/resources/color-list-resource.html"; //$NON-NLS-1$
     38 
     39     public static final String SELECTOR_TAG = "selector";               //$NON-NLS-1$
     40     public static final String ATTR_COLOR = "color";                    //$NON-NLS-1$
     41 
     42     /** The root element descriptor */
     43     private ElementDescriptor mDescriptor = new ElementDescriptor(
     44             SELECTOR_TAG, "Selector",
     45             "Required. This must be the root element. Contains one or more <item> elements.",
     46             SDK_URL,
     47             new AttributeDescriptor[] {
     48                     new XmlnsAttributeDescriptor(ANDROID_NS_NAME, ANDROID_URI) },
     49             null /*children: added later*/, true /*mandatory*/);
     50 
     51     /** @return the root descriptor. */
     52     @Override
     53     public ElementDescriptor getDescriptor() {
     54         if (mDescriptor == null) {
     55             mDescriptor = new ElementDescriptor("", getRootElementDescriptors()); //$NON-NLS-1$
     56         }
     57 
     58         return mDescriptor;
     59     }
     60 
     61     @Override
     62     public ElementDescriptor[] getRootElementDescriptors() {
     63         return new ElementDescriptor[] { mDescriptor };
     64     }
     65 
     66     public synchronized void updateDescriptors(Map<String, DeclareStyleableInfo> styleMap) {
     67         if (styleMap == null) {
     68             return;
     69         }
     70 
     71         // Selector children
     72         ElementDescriptor selectorItem = AnimatorDescriptors.addElement(null, styleMap,
     73             "item", "Item", "DrawableStates", null, //$NON-NLS-1$ //$NON-NLS-3$
     74             "Defines a drawable to use during certain states, as described by "
     75                  + "its attributes. Must be a child of a <selector> element.",
     76             SDK_URL,
     77             new ReferenceAttributeDescriptor(
     78                     ResourceType.COLOR, ATTR_COLOR,
     79                     ANDROID_URI,
     80                     new AttributeInfo(ATTR_COLOR, Format.COLOR_SET)).setTooltip(
     81                 "Hexadeximal color. Required. The color is specified with an RGB value and "
     82                     + "optional alpha channel.\n"
     83                     + "The value always begins with a pound (#) character and then "
     84                     + "followed by the Alpha-Red-Green-Blue information in one of "
     85                     + "the following formats:\n"
     86                     + "* RGB\n"
     87                     + "* ARGB\n"
     88                     + "* RRGGBB\n"
     89                     + "* AARRGGBB"),
     90             null, /* This is wrong -- we can now embed any above drawable
     91                         (but without xmlns as extra) */
     92             false /*mandatory*/);
     93 
     94         if (selectorItem != null) {
     95             mDescriptor.setChildren(new ElementDescriptor[] { selectorItem });
     96         }
     97     }
     98 }
     99