1 /* 2 * Copyright (C) 2007 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 17 package com.android.ide.eclipse.adt.internal.editors.values.descriptors; 18 19 import static com.android.SdkConstants.ATTR_NAME; 20 import static com.android.SdkConstants.ATTR_TYPE; 21 import static com.android.SdkConstants.TAG_COLOR; 22 import static com.android.SdkConstants.TAG_DIMEN; 23 import static com.android.SdkConstants.TAG_DRAWABLE; 24 import static com.android.SdkConstants.TAG_INTEGER_ARRAY; 25 import static com.android.SdkConstants.TAG_ITEM; 26 import static com.android.SdkConstants.TAG_PLURALS; 27 import static com.android.SdkConstants.TAG_RESOURCES; 28 import static com.android.SdkConstants.TAG_STRING; 29 import static com.android.SdkConstants.TAG_STRING_ARRAY; 30 import static com.android.SdkConstants.TAG_STYLE; 31 32 import com.android.ide.common.api.IAttributeInfo.Format; 33 import com.android.ide.common.resources.platform.AttributeInfo; 34 import com.android.ide.eclipse.adt.internal.editors.descriptors.AttributeDescriptor; 35 import com.android.ide.eclipse.adt.internal.editors.descriptors.ElementDescriptor; 36 import com.android.ide.eclipse.adt.internal.editors.descriptors.EnumAttributeDescriptor; 37 import com.android.ide.eclipse.adt.internal.editors.descriptors.FlagAttributeDescriptor; 38 import com.android.ide.eclipse.adt.internal.editors.descriptors.IDescriptorProvider; 39 import com.android.ide.eclipse.adt.internal.editors.descriptors.ListAttributeDescriptor; 40 import com.android.ide.eclipse.adt.internal.editors.descriptors.TextAttributeDescriptor; 41 import com.android.ide.eclipse.adt.internal.editors.descriptors.TextValueDescriptor; 42 import com.android.resources.ResourceType; 43 44 import java.util.EnumSet; 45 46 47 /** 48 * Complete description of the structure for resources XML files (under res/values/) 49 */ 50 public final class ValuesDescriptors implements IDescriptorProvider { 51 private static final ValuesDescriptors sThis = new ValuesDescriptors(); 52 53 /** The {@link ElementDescriptor} for the root Resources element. */ 54 public final ElementDescriptor mResourcesElement; 55 56 public static ValuesDescriptors getInstance() { 57 return sThis; 58 } 59 60 /* 61 * @see com.android.ide.eclipse.editors.descriptors.IDescriptorProvider#getRootElementDescriptors() 62 */ 63 @Override 64 public ElementDescriptor[] getRootElementDescriptors() { 65 return new ElementDescriptor[] { mResourcesElement }; 66 } 67 68 @Override 69 public ElementDescriptor getDescriptor() { 70 return mResourcesElement; 71 } 72 73 public ElementDescriptor getElementDescriptor() { 74 return mResourcesElement; 75 } 76 77 private ValuesDescriptors() { 78 79 // Common attributes used in many placed 80 81 // Elements 82 83 AttributeInfo nameAttrInfo = new AttributeInfo(ATTR_NAME, Format.STRING_SET); 84 85 ElementDescriptor color_element = new ElementDescriptor( 86 TAG_COLOR, 87 "Color", 88 "A @color@ value specifies an RGB value with an alpha channel, which can be used in various places such as specifying a solid color for a Drawable or the color to use for text. It always begins with a # character and then is followed by the alpha-red-green-blue information in one of the following formats: #RGB, #ARGB, #RRGGBB or #AARRGGBB.", 89 "http://code.google.com/android/reference/available-resources.html#colorvals", //$NON-NLS-1$ 90 new AttributeDescriptor[] { 91 new TextAttributeDescriptor(ATTR_NAME, 92 null /* nsUri */, 93 nameAttrInfo), 94 new ColorValueDescriptor( 95 "Value*", 96 "A mandatory color value.") 97 .setTooltip("The mandatory name used in referring to this color.") 98 }, 99 null, // no child nodes 100 false /* not mandatory */); 101 102 ElementDescriptor string_element = new ElementDescriptor( 103 TAG_STRING, 104 "String", 105 "@Strings@, with optional simple formatting, can be stored and retrieved as resources. You can add formatting to your string by using three standard HTML tags: b, i, and u. If you use an apostrophe or a quote in your string, you must either escape it or enclose the whole string in the other kind of enclosing quotes.", 106 "http://code.google.com/android/reference/available-resources.html#stringresources", //$NON-NLS-1$ 107 new AttributeDescriptor[] { 108 new TextAttributeDescriptor(ATTR_NAME, 109 null /* nsUri */, 110 nameAttrInfo) 111 .setTooltip("The mandatory name used in referring to this string."), 112 new TextValueDescriptor( 113 "Value*", 114 "A mandatory string value.") 115 }, 116 null, // no child nodes 117 false /* not mandatory */); 118 119 ElementDescriptor item_element = new ItemElementDescriptor( 120 TAG_ITEM, 121 "Item", 122 null, // TODO find javadoc 123 null, // TODO find link to javadoc 124 new AttributeDescriptor[] { 125 new TextAttributeDescriptor(ATTR_NAME, 126 null /* nsUri */, 127 nameAttrInfo) 128 .setTooltip("The mandatory name used in referring to this resource."), 129 new ListAttributeDescriptor(ATTR_TYPE, 130 null /* nsUri */, 131 new AttributeInfo(ATTR_TYPE, 132 EnumSet.of(Format.STRING, Format.ENUM) 133 ).setEnumValues(ResourceType.getNames()) 134 ).setTooltip("The mandatory type of this resource."), 135 new FlagAttributeDescriptor("format", //$NON-NLS-1$ 136 null /* nsUri */, 137 new AttributeInfo("format", 138 EnumSet.of(Format.STRING, Format.FLAG) 139 ).setFlagValues( 140 new String[] { 141 "boolean", //$NON-NLS-1$ 142 TAG_COLOR, 143 "dimension", //$NON-NLS-1$ 144 "float", //$NON-NLS-1$ 145 "fraction", //$NON-NLS-1$ 146 "integer", //$NON-NLS-1$ 147 "reference", //$NON-NLS-1$ 148 "string" //$NON-NLS-1$ 149 } ) 150 ).setTooltip("The optional format of this resource."), 151 new TextValueDescriptor( 152 "Value", 153 "A standard string, hex color value, or reference to any other resource type.") 154 }, 155 null, // no child nodes 156 false /* not mandatory */); 157 158 ElementDescriptor drawable_element = new ElementDescriptor( 159 TAG_DRAWABLE, 160 "Drawable", 161 "A @drawable@ defines a rectangle of color. Android accepts color values written in various web-style formats -- a hexadecimal constant in any of the following forms: #RGB, #ARGB, #RRGGBB, #AARRGGBB. Zero in the alpha channel means transparent. The default value is opaque.", 162 "http://code.google.com/android/reference/available-resources.html#colordrawableresources", //$NON-NLS-1$ 163 new AttributeDescriptor[] { 164 new TextAttributeDescriptor(ATTR_NAME, 165 null /* nsUri */, 166 nameAttrInfo) 167 .setTooltip("The mandatory name used in referring to this drawable."), 168 new TextValueDescriptor( 169 "Value*", 170 "A mandatory color value in the form #RGB, #ARGB, #RRGGBB or #AARRGGBB.") 171 }, 172 null, // no child nodes 173 false /* not mandatory */); 174 175 ElementDescriptor dimen_element = new ElementDescriptor( 176 TAG_DIMEN, 177 "Dimension", 178 "You can create common dimensions to use for various screen elements by defining @dimension@ values in XML. A dimension resource is a number followed by a unit of measurement. Supported units are px (pixels), in (inches), mm (millimeters), pt (points at 72 DPI), dp (density-independent pixels) and sp (scale-independent pixels)", 179 "http://code.google.com/android/reference/available-resources.html#dimension", //$NON-NLS-1$ 180 new AttributeDescriptor[] { 181 new TextAttributeDescriptor(ATTR_NAME, 182 null /* nsUri */, 183 nameAttrInfo) 184 .setTooltip("The mandatory name used in referring to this dimension."), 185 new TextValueDescriptor( 186 "Value*", 187 "A mandatory dimension value is a number followed by a unit of measurement. For example: 10px, 2in, 5sp.") 188 }, 189 null, // no child nodes 190 false /* not mandatory */); 191 192 ElementDescriptor style_element = new ElementDescriptor( 193 TAG_STYLE, 194 "Style/Theme", 195 "Both @styles and themes@ are defined in a style block containing one or more string or numerical values (typically color values), or references to other resources (drawables and so on).", 196 "http://code.google.com/android/reference/available-resources.html#stylesandthemes", //$NON-NLS-1$ 197 new AttributeDescriptor[] { 198 new TextAttributeDescriptor(ATTR_NAME, 199 null /* nsUri */, 200 nameAttrInfo) 201 .setTooltip("The mandatory name used in referring to this theme."), 202 new TextAttributeDescriptor("parent", //$NON-NLS-1$ 203 null /* nsUri */, 204 new AttributeInfo("parent", //$NON-NLS-1$ 205 Format.STRING_SET)) 206 .setTooltip("An optional parent theme. All values from the specified theme will be inherited into this theme. Any values with identical names that you specify will override inherited values."), 207 }, 208 new ElementDescriptor[] { 209 new ElementDescriptor( 210 TAG_ITEM, 211 "Item", 212 "A value to use in this @theme@. It can be a standard string, a hex color value, or a reference to any other resource type.", 213 "http://code.google.com/android/reference/available-resources.html#stylesandthemes", //$NON-NLS-1$ 214 new AttributeDescriptor[] { 215 new TextAttributeDescriptor(ATTR_NAME, 216 null /* nsUri */, 217 nameAttrInfo) 218 .setTooltip("The mandatory name used in referring to this item."), 219 new TextValueDescriptor( 220 "Value*", 221 "A mandatory standard string, hex color value, or reference to any other resource type.") 222 }, 223 null, // no child nodes 224 false /* not mandatory */) 225 }, 226 false /* not mandatory */); 227 228 ElementDescriptor string_array_element = new ElementDescriptor( 229 TAG_STRING_ARRAY, 230 "String Array", 231 "An array of strings. Strings are added as underlying item elements to the array.", 232 null, // tooltips 233 new AttributeDescriptor[] { 234 new TextAttributeDescriptor(ATTR_NAME, 235 null /* nsUri */, 236 nameAttrInfo) 237 .setTooltip("The mandatory name used in referring to this string array."), 238 }, 239 new ElementDescriptor[] { 240 new ElementDescriptor( 241 TAG_ITEM, 242 "Item", 243 "A string value to use in this string array.", 244 null, // tooltip 245 new AttributeDescriptor[] { 246 new TextValueDescriptor( 247 "Value*", 248 "A mandatory string.") 249 }, 250 null, // no child nodes 251 false /* not mandatory */) 252 }, 253 false /* not mandatory */); 254 255 ElementDescriptor plurals_element = new ElementDescriptor( 256 TAG_PLURALS, 257 "Quantity Strings (Plurals)", 258 "A quantity string", 259 null, // tooltips 260 new AttributeDescriptor[] { 261 new TextAttributeDescriptor(ATTR_NAME, 262 null /* nsUri */, 263 nameAttrInfo) 264 .setTooltip("A name for the pair of strings. This name will be used as the resource ID."), 265 }, 266 new ElementDescriptor[] { 267 new ElementDescriptor( 268 TAG_ITEM, 269 "Item", 270 "A plural or singular string", 271 null, // tooltip 272 new AttributeDescriptor[] { 273 new EnumAttributeDescriptor( 274 "quantity", "Quantity", null, 275 "A keyword value indicating when this string should be used", 276 new AttributeInfo("quantity", Format.ENUM_SET) 277 .setEnumValues(new String[] { 278 "zero", //$NON-NLS-1$ 279 "one", //$NON-NLS-1$ 280 "two", //$NON-NLS-1$ 281 "few", //$NON-NLS-1$ 282 "many", //$NON-NLS-1$ 283 "other" //$NON-NLS-1$ 284 })) 285 }, 286 null, // no child nodes 287 false /* not mandatory */) 288 }, 289 false /* not mandatory */); 290 291 ElementDescriptor integer_array_element = new ElementDescriptor( 292 TAG_INTEGER_ARRAY, 293 "Integer Array", 294 "An array of integers. Integers are added as underlying item elements to the array.", 295 null, // tooltips 296 new AttributeDescriptor[] { 297 new TextAttributeDescriptor(ATTR_NAME, 298 null /* nsUri */, 299 nameAttrInfo) 300 .setTooltip("The mandatory name used in referring to this integer array.") 301 }, 302 new ElementDescriptor[] { 303 new ElementDescriptor( 304 TAG_ITEM, 305 "Item", 306 "An integer value to use in this integer array.", 307 null, // tooltip 308 new AttributeDescriptor[] { 309 new TextValueDescriptor( 310 "Value*", 311 "A mandatory integer.") 312 }, 313 null, // no child nodes 314 false /* not mandatory */) 315 }, 316 false /* not mandatory */); 317 318 mResourcesElement = new ElementDescriptor( 319 TAG_RESOURCES, 320 "Resources", 321 null, 322 "http://code.google.com/android/reference/available-resources.html", //$NON-NLS-1$ 323 null, // no attributes 324 new ElementDescriptor[] { 325 string_element, 326 color_element, 327 dimen_element, 328 drawable_element, 329 style_element, 330 item_element, 331 string_array_element, 332 integer_array_element, 333 plurals_element, 334 }, 335 true /* mandatory */); 336 } 337 } 338