aboutsummaryrefslogtreecommitdiff
path: root/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/resources/platform/DeclareStyleableInfo.java
blob: 40111e24e9db2d25303b9427c3d7b172c5ad48f1 (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
99
100
101
102
/*
 * Copyright (C) 2008 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.common.resources.platform;


/**
 * Information needed to represent a View or ViewGroup (aka Layout) item
 * in the layout hierarchy, as extracted from the main android.jar and the
 * associated attrs.xml.
 */
public class DeclareStyleableInfo {
    /** The style name, never null. */
    private final String mStyleName;
    /** Attributes for this view or view group. Can be empty but never null. */
    private final AttributeInfo[] mAttributes;
    /** Short javadoc. Can be null. */
    private String mJavaDoc;
    /** Optional name of the parents styleable. Can be null. */
    private String[] mParents;

    /**
     * Creates a new {@link DeclareStyleableInfo}.
     *
     * @param styleName The name of the style. Should not be empty nor null.
     * @param attributes The initial list of attributes. Can be null.
     */
    public DeclareStyleableInfo(String styleName, AttributeInfo[] attributes) {
        mStyleName = styleName;
        mAttributes = attributes == null ? new AttributeInfo[0] : attributes;
    }

    /**
     * Creates a new {@link DeclareStyleableInfo} that has the same attributes
     * as an existing one and only differs by name.
     *
     * @param styleName The name of the style. Should not be empty nor null.
     * @param existing The existing {@link DeclareStyleableInfo} to mirror.
     */
    public DeclareStyleableInfo(String styleName, DeclareStyleableInfo existing) {
        mStyleName = styleName;

        mJavaDoc = existing.getJavaDoc();

        String[] parents = existing.getParents();
        if (parents != null) {
            mParents = new String[parents.length];
            System.arraycopy(parents, 0, mParents, 0, parents.length);
        }

        AttributeInfo[] attrs = existing.getAttributes();
        if (attrs == null || attrs.length == 0) {
            mAttributes = new AttributeInfo[0];
        } else {
            mAttributes = new AttributeInfo[attrs.length];
            System.arraycopy(attrs, 0, mAttributes, 0, attrs.length);
        }
    }

    /** Returns style name */
    public String getStyleName() {
        return mStyleName;
    }

    /** Returns the attributes for this view or view group. Maybe empty but not null. */
    public AttributeInfo[] getAttributes() {
        return mAttributes;
    }

    /** Returns a short javadoc */
    public String getJavaDoc() {
        return mJavaDoc;
    }

    /** Sets the javadoc. */
    public void setJavaDoc(String javaDoc) {
        mJavaDoc = javaDoc;
    }

    /** Sets the name of the parents styleable. Can be null. */
    public void setParents(String[] parents) {
        mParents = parents;
    }

    /** Returns the name of the parents styleable. Can be null. */
    public String[] getParents() {
        return mParents;
    }
}