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 @Override getDescriptor()54 public ElementDescriptor getDescriptor() { 55 if (mDescriptor == null) { 56 mDescriptor = new ElementDescriptor("", getRootElementDescriptors()); //$NON-NLS-1$ 57 } 58 59 return mDescriptor; 60 } 61 62 @Override getRootElementDescriptors()63 public ElementDescriptor[] getRootElementDescriptors() { 64 return new ElementDescriptor[] { mDescriptor }; 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 // Selector children 73 ElementDescriptor selectorItem = AnimatorDescriptors.addElement(null, styleMap, 74 "item", "Item", "DrawableStates", null, //$NON-NLS-1$ //$NON-NLS-3$ 75 "Defines a drawable to use during certain states, as described by " 76 + "its attributes. Must be a child of a <selector> element.", 77 SDK_URL, 78 new ReferenceAttributeDescriptor( 79 ResourceType.COLOR, ATTR_COLOR, 80 SdkConstants.NS_RESOURCES, 81 new AttributeInfo(ATTR_COLOR, Format.COLOR_SET)).setTooltip( 82 "Hexadeximal color. Required. The color is specified with an RGB value and " 83 + "optional alpha channel.\n" 84 + "The value always begins with a pound (#) character and then " 85 + "followed by the Alpha-Red-Green-Blue information in one of " 86 + "the following formats:\n" 87 + "* RGB\n" 88 + "* ARGB\n" 89 + "* RRGGBB\n" 90 + "* AARRGGBB"), 91 null, /* This is wrong -- we can now embed any above drawable 92 (but without xmlns as extra) */ 93 false /*mandatory*/); 94 95 if (selectorItem != null) { 96 mDescriptor.setChildren(new ElementDescriptor[] { selectorItem }); 97 } 98 } 99 } 100