aboutsummaryrefslogtreecommitdiff
path: root/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/resources/platform/ViewClassInfo.java
blob: 214eb9cb4c142a1a95eaea6557e8839148ff5a6a (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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*
 * 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 ViewClassInfo {
    /** Is this a layout class (i.e. ViewGroup) or just a view? */
    private boolean mIsLayout;
    /** FQCN e.g. android.view.View, never null. */
    private String mFullClassName;
    /** Short class name, e.g. View, never null. */
    private String mShortClassName;
    /** Super class. Can be null. */
    private ViewClassInfo mSuperClass;
    /** Short javadoc. Can be null. */
    private String mJavaDoc;
    /** Attributes for this view or view group. Can be empty but never null. */
    private AttributeInfo[] mAttributes;

    public static class LayoutParamsInfo {
        /** Short class name, e.g. LayoutData, never null. */
        private String mShortClassName;
        /** ViewLayout class info owning this layout data */
        private ViewClassInfo mViewLayoutClass;
        /** Super class. Can be null. */
        private LayoutParamsInfo mSuperClass;
        /** Layout Data Attributes for layout classes. Can be empty but not null. */
        private AttributeInfo[] mAttributes;

        public LayoutParamsInfo(ViewClassInfo enclosingViewClassInfo,
                String shortClassName, LayoutParamsInfo superClassInfo) {
            mShortClassName = shortClassName;
            mViewLayoutClass = enclosingViewClassInfo;
            mSuperClass = superClassInfo;
            mAttributes = new AttributeInfo[0];
        }

        /** Returns short class name, e.g. "LayoutData" */
        public String getShortClassName() {
            return mShortClassName;
        }
        /** Returns the ViewLayout class info enclosing this layout data. Cannot null. */
        public ViewClassInfo getViewLayoutClass() {
            return mViewLayoutClass;
        }
        /** Returns the super class info. Can be null. */
        public LayoutParamsInfo getSuperClass() {
            return mSuperClass;
        }
        /** Returns the LayoutData attributes. Can be empty but not null. */
        public AttributeInfo[] getAttributes() {
            return mAttributes;
        }
        /** Sets the LayoutData attributes. Can be empty but not null. */
        public void setAttributes(AttributeInfo[] attributes) {
            mAttributes = attributes;
        }
    }

    /** Layout data info for a layout class. Null for all non-layout classes and always
     *  non-null for a layout class. */
    public LayoutParamsInfo mLayoutData;

    // --------

    public ViewClassInfo(boolean isLayout, String fullClassName, String shortClassName) {
        mIsLayout = isLayout;
        mFullClassName = fullClassName;
        mShortClassName = shortClassName;
        mAttributes = new AttributeInfo[0];
    }

    /** Returns whether this is a layout class (i.e. ViewGroup) or just a View */
    public boolean isLayout() {
        return mIsLayout;
    }

    /** Returns FQCN e.g. "android.view.View" */
    public String getFullClassName() {
        return mFullClassName;
    }

    /** Returns short class name, e.g. "View" */
    public String getShortClassName() {
        return mShortClassName;
    }

    /** Returns the super class. Can be null. */
    public ViewClassInfo getSuperClass() {
        return mSuperClass;
    }

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

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

    /** Returns the LayoutData info for layout classes. Null for non-layout view classes. */
    public LayoutParamsInfo getLayoutData() {
        return mLayoutData;
    }

    /**
     * Sets a link on the info of the super class of this View or ViewGroup.
     * <p/>
     * The super class info must be of the same kind (i.e. group to group or view to view)
     * except for the top ViewGroup which links to the View info.
     * <p/>
     * The super class cannot be null except for the top View info.
     */
    public void setSuperClass(ViewClassInfo superClass) {
        mSuperClass = superClass;
    }

    /** Sets the javadoc for this View or ViewGroup. */
    public void setJavaDoc(String javaDoc) {
        mJavaDoc = javaDoc;
    }

    /** Sets the list of attributes for this View or ViewGroup. */
    public void setAttributes(AttributeInfo[] attributes) {
        mAttributes = attributes;
    }

    /**
     * Sets the {@link LayoutParamsInfo} for layout classes.
     * Does nothing for non-layout view classes.
     */
    public void setLayoutParams(LayoutParamsInfo layoutData) {
        if (mIsLayout) {
            mLayoutData = layoutData;
        }
    }
}