aboutsummaryrefslogtreecommitdiff
path: root/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/color/ColorDescriptors.java
blob: 16add3ec94322ee73584ca98066e2a3e54002a96 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
 * Copyright (C) 2011 The Android Open Source Project
 *
 * Licensed under the Eclipse Public License, Version 1.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.eclipse.org/org/documents/epl-v10.php
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.ide.eclipse.adt.internal.editors.color;

import static com.android.SdkConstants.ANDROID_NS_NAME;
import static com.android.SdkConstants.ANDROID_URI;

import com.android.ide.common.api.IAttributeInfo.Format;
import com.android.ide.common.resources.platform.AttributeInfo;
import com.android.ide.common.resources.platform.DeclareStyleableInfo;
import com.android.ide.eclipse.adt.internal.editors.animator.AnimatorDescriptors;
import com.android.ide.eclipse.adt.internal.editors.descriptors.AttributeDescriptor;
import com.android.ide.eclipse.adt.internal.editors.descriptors.ElementDescriptor;
import com.android.ide.eclipse.adt.internal.editors.descriptors.IDescriptorProvider;
import com.android.ide.eclipse.adt.internal.editors.descriptors.ReferenceAttributeDescriptor;
import com.android.ide.eclipse.adt.internal.editors.descriptors.XmlnsAttributeDescriptor;
import com.android.resources.ResourceType;

import java.util.Map;

/** Descriptors for /res/color XML files */
public class ColorDescriptors implements IDescriptorProvider {
    private static final String SDK_URL =
        "http://d.android.com/guide/topics/resources/color-list-resource.html"; //$NON-NLS-1$

    public static final String SELECTOR_TAG = "selector";               //$NON-NLS-1$
    public static final String ATTR_COLOR = "color";                    //$NON-NLS-1$

    /** The root element descriptor */
    private ElementDescriptor mDescriptor = new ElementDescriptor(
            SELECTOR_TAG, "Selector",
            "Required. This must be the root element. Contains one or more <item> elements.",
            SDK_URL,
            new AttributeDescriptor[] {
                    new XmlnsAttributeDescriptor(ANDROID_NS_NAME, ANDROID_URI) },
            null /*children: added later*/, true /*mandatory*/);

    /** @return the root descriptor. */
    @Override
    public ElementDescriptor getDescriptor() {
        if (mDescriptor == null) {
            mDescriptor = new ElementDescriptor("", getRootElementDescriptors()); //$NON-NLS-1$
        }

        return mDescriptor;
    }

    @Override
    public ElementDescriptor[] getRootElementDescriptors() {
        return new ElementDescriptor[] { mDescriptor };
    }

    public synchronized void updateDescriptors(Map<String, DeclareStyleableInfo> styleMap) {
        if (styleMap == null) {
            return;
        }

        // Selector children
        ElementDescriptor selectorItem = AnimatorDescriptors.addElement(null, styleMap,
            "item", "Item", "DrawableStates", null, //$NON-NLS-1$ //$NON-NLS-3$
            "Defines a drawable to use during certain states, as described by "
                 + "its attributes. Must be a child of a <selector> element.",
            SDK_URL,
            new ReferenceAttributeDescriptor(
                    ResourceType.COLOR, ATTR_COLOR,
                    ANDROID_URI,
                    new AttributeInfo(ATTR_COLOR, Format.COLOR_SET)).setTooltip(
                "Hexadeximal color. Required. The color is specified with an RGB value and "
                    + "optional alpha channel.\n"
                    + "The value always begins with a pound (#) character and then "
                    + "followed by the Alpha-Red-Green-Blue information in one of "
                    + "the following formats:\n"
                    + "* RGB\n"
                    + "* ARGB\n"
                    + "* RRGGBB\n"
                    + "* AARRGGBB"),
            null, /* This is wrong -- we can now embed any above drawable
                        (but without xmlns as extra) */
            false /*mandatory*/);

        if (selectorItem != null) {
            mDescriptor.setChildren(new ElementDescriptor[] { selectorItem });
        }
    }
}