• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 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.resources;
18 
19 import com.android.ide.eclipse.adt.internal.resources.DeclareStyleableInfo.AttributeInfo;
20 
21 /**
22  * Information needed to represent a View or ViewGroup (aka Layout) item
23  * in the layout hierarchy, as extracted from the main android.jar and the
24  * associated attrs.xml.
25  */
26 public class ViewClassInfo {
27     /** Is this a layout class (i.e. ViewGroup) or just a view? */
28     private boolean mIsLayout;
29     /** FQCN e.g. android.view.View, never null. */
30     private String mCanonicalClassName;
31     /** Short class name, e.g. View, never null. */
32     private String mShortClassName;
33     /** Super class. Can be null. */
34     private ViewClassInfo mSuperClass;
35     /** Short javadoc. Can be null. */
36     private String mJavaDoc;
37     /** Attributes for this view or view group. Can be empty but never null. */
38     private AttributeInfo[] mAttributes;
39 
40     public static class LayoutParamsInfo {
41         /** Short class name, e.g. LayoutData, never null. */
42         private String mShortClassName;
43         /** ViewLayout class info owning this layout data */
44         private ViewClassInfo mViewLayoutClass;
45         /** Super class. Can be null. */
46         private LayoutParamsInfo mSuperClass;
47         /** Layout Data Attributes for layout classes. Can be empty but not null. */
48         private AttributeInfo[] mAttributes;
49 
LayoutParamsInfo(ViewClassInfo enclosingViewClassInfo, String shortClassName, LayoutParamsInfo superClassInfo)50         public LayoutParamsInfo(ViewClassInfo enclosingViewClassInfo,
51                 String shortClassName, LayoutParamsInfo superClassInfo) {
52             mShortClassName = shortClassName;
53             mViewLayoutClass = enclosingViewClassInfo;
54             mSuperClass = superClassInfo;
55             mAttributes = new AttributeInfo[0];
56         }
57 
58         /** Returns short class name, e.g. "LayoutData" */
getShortClassName()59         public String getShortClassName() {
60             return mShortClassName;
61         }
62         /** Returns the ViewLayout class info enclosing this layout data. Cannot null. */
getViewLayoutClass()63         public ViewClassInfo getViewLayoutClass() {
64             return mViewLayoutClass;
65         }
66         /** Returns the super class info. Can be null. */
getSuperClass()67         public LayoutParamsInfo getSuperClass() {
68             return mSuperClass;
69         }
70         /** Returns the LayoutData attributes. Can be empty but not null. */
getAttributes()71         public AttributeInfo[] getAttributes() {
72             return mAttributes;
73         }
74         /** Sets the LayoutData attributes. Can be empty but not null. */
setAttributes(AttributeInfo[] attributes)75         public void setAttributes(AttributeInfo[] attributes) {
76             mAttributes = attributes;
77         }
78     }
79 
80     /** Layout data info for a layout class. Null for all non-layout classes and always
81      *  non-null for a layout class. */
82     public LayoutParamsInfo mLayoutData;
83 
84     // --------
85 
ViewClassInfo(boolean isLayout, String canonicalClassName, String shortClassName)86     public ViewClassInfo(boolean isLayout, String canonicalClassName, String shortClassName) {
87         mIsLayout = isLayout;
88         mCanonicalClassName = canonicalClassName;
89         mShortClassName = shortClassName;
90         mAttributes = new AttributeInfo[0];
91     }
92 
93     /** Returns whether this is a layout class (i.e. ViewGroup) or just a View */
isLayout()94     public boolean isLayout() {
95         return mIsLayout;
96     }
97 
98     /** Returns FQCN e.g. "android.view.View" */
getCanonicalClassName()99     public String getCanonicalClassName() {
100         return mCanonicalClassName;
101     }
102 
103     /** Returns short class name, e.g. "View" */
getShortClassName()104     public String getShortClassName() {
105         return mShortClassName;
106     }
107 
108     /** Returns the super class. Can be null. */
getSuperClass()109     public ViewClassInfo getSuperClass() {
110         return mSuperClass;
111     }
112 
113     /** Returns a short javadoc */
getJavaDoc()114     public String getJavaDoc() {
115         return mJavaDoc;
116     }
117 
118     /** Returns the attributes for this view or view group. Maybe empty but not null. */
getAttributes()119     public AttributeInfo[] getAttributes() {
120         return mAttributes;
121     }
122 
123     /** Returns the LayoutData info for layout classes. Null for non-layout view classes. */
getLayoutData()124     public LayoutParamsInfo getLayoutData() {
125         return mLayoutData;
126     }
127 
128     /**
129      * Sets a link on the info of the super class of this View or ViewGroup.
130      * <p/>
131      * The super class info must be of the same kind (i.e. group to group or view to view)
132      * except for the top ViewGroup which links to the View info.
133      * <p/>
134      * The super class cannot be null except for the top View info.
135      */
setSuperClass(ViewClassInfo superClass)136     public void setSuperClass(ViewClassInfo superClass) {
137         mSuperClass = superClass;
138     }
139 
140     /** Sets the javadoc for this View or ViewGroup. */
setJavaDoc(String javaDoc)141     public void setJavaDoc(String javaDoc) {
142         mJavaDoc = javaDoc;
143     }
144 
145     /** Sets the list of attributes for this View or ViewGroup. */
setAttributes(AttributeInfo[] attributes)146     public void setAttributes(AttributeInfo[] attributes) {
147         mAttributes = attributes;
148     }
149 
150     /**
151      * Sets the {@link LayoutParamsInfo} for layout classes.
152      * Does nothing for non-layout view classes.
153      */
setLayoutParams(LayoutParamsInfo layoutData)154     public void setLayoutParams(LayoutParamsInfo layoutData) {
155         if (mIsLayout) {
156             mLayoutData = layoutData;
157         }
158     }
159 }
160