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