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