• 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 
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 DeclareStyleableInfo {
26     /** The style name, never null. */
27     private String mStyleName;
28     /** Attributes for this view or view group. Can be empty but never null. */
29     private AttributeInfo[] mAttributes;
30     /** Short javadoc. Can be null. */
31     private String mJavaDoc;
32     /** Optional name of the parents stylable. Can be null. */
33     private String[] mParents;
34 
35     public static class AttributeInfo {
36         /** XML Name of the attribute */
37         private String mName;
38 
39         public enum Format {
40             STRING,
41             BOOLEAN,
42             INTEGER,
43             FLOAT,
44             REFERENCE,
45             COLOR,
46             DIMENSION,
47             FRACTION,
48             ENUM,
49             FLAG,
50         }
51 
52         /** Formats of the attribute. Cannot be null. Should have at least one format. */
53         private Format[] mFormats;
54         /** Values for enum. null for other types. */
55         private String[] mEnumValues;
56         /** Values for flag. null for other types. */
57         private String[] mFlagValues;
58         /** Short javadoc (i.e. the first sentence). */
59         private String mJavaDoc;
60         /** Documentation for deprecated attributes. Null if not deprecated. */
61         private String mDeprecatedDoc;
62 
63         /**
64          * @param name The XML Name of the attribute
65          * @param formats The formats of the attribute. Cannot be null.
66          *                Should have at least one format.
67          */
AttributeInfo(String name, Format[] formats)68         public AttributeInfo(String name, Format[] formats) {
69             mName = name;
70             mFormats = formats;
71         }
72 
73         /**
74          * @param name The XML Name of the attribute
75          * @param formats The formats of the attribute. Cannot be null.
76          *                Should have at least one format.
77          * @param javadoc Short javadoc (i.e. the first sentence).
78          */
AttributeInfo(String name, Format[] formats, String javadoc)79         public AttributeInfo(String name, Format[] formats, String javadoc) {
80             mName = name;
81             mFormats = formats;
82             mJavaDoc = javadoc;
83         }
84 
AttributeInfo(AttributeInfo info)85         public AttributeInfo(AttributeInfo info) {
86             mName = info.mName;
87             mFormats = info.mFormats;
88             mEnumValues = info.mEnumValues;
89             mFlagValues = info.mFlagValues;
90             mJavaDoc = info.mJavaDoc;
91             mDeprecatedDoc = info.mDeprecatedDoc;
92         }
93 
94         /** Returns the XML Name of the attribute */
getName()95         public String getName() {
96             return mName;
97         }
98         /** Returns the formats of the attribute. Cannot be null.
99          *  Should have at least one format. */
getFormats()100         public Format[] getFormats() {
101             return mFormats;
102         }
103         /** Returns the values for enums. null for other types. */
getEnumValues()104         public String[] getEnumValues() {
105             return mEnumValues;
106         }
107         /** Returns the values for flags. null for other types. */
getFlagValues()108         public String[] getFlagValues() {
109             return mFlagValues;
110         }
111         /** Returns a short javadoc, .i.e. the first sentence. */
getJavaDoc()112         public String getJavaDoc() {
113             return mJavaDoc;
114         }
115         /** Returns the documentation for deprecated attributes. Null if not deprecated. */
getDeprecatedDoc()116         public String getDeprecatedDoc() {
117             return mDeprecatedDoc;
118         }
119 
120         /** Sets the values for enums. null for other types. */
setEnumValues(String[] values)121         public void setEnumValues(String[] values) {
122             mEnumValues = values;
123         }
124         /** Sets the values for flags. null for other types. */
setFlagValues(String[] values)125         public void setFlagValues(String[] values) {
126             mFlagValues = values;
127         }
128         /** Sets a short javadoc, .i.e. the first sentence. */
setJavaDoc(String javaDoc)129         public void setJavaDoc(String javaDoc) {
130             mJavaDoc = javaDoc;
131         }
132         /** Sets the documentation for deprecated attributes. Null if not deprecated. */
setDeprecatedDoc(String deprecatedDoc)133         public void setDeprecatedDoc(String deprecatedDoc) {
134             mDeprecatedDoc = deprecatedDoc;
135         }
136 
137     }
138 
139     // --------
140 
141     /**
142      * Creates a new {@link DeclareStyleableInfo}.
143      *
144      * @param styleName The name of the style. Should not be empty nor null.
145      * @param attributes The initial list of attributes. Can be null.
146      */
DeclareStyleableInfo(String styleName, AttributeInfo[] attributes)147     public DeclareStyleableInfo(String styleName, AttributeInfo[] attributes) {
148         mStyleName = styleName;
149         mAttributes = attributes == null ? new AttributeInfo[0] : attributes;
150     }
151 
152     /** Returns style name */
getStyleName()153     public String getStyleName() {
154         return mStyleName;
155     }
156 
157     /** Returns the attributes for this view or view group. Maybe empty but not null. */
getAttributes()158     public AttributeInfo[] getAttributes() {
159         return mAttributes;
160     }
161 
162     /** Sets the list of attributes for this View or ViewGroup. */
setAttributes(AttributeInfo[] attributes)163     public void setAttributes(AttributeInfo[] attributes) {
164         mAttributes = attributes;
165     }
166 
167     /** Returns a short javadoc */
getJavaDoc()168     public String getJavaDoc() {
169         return mJavaDoc;
170     }
171 
172     /** Sets the javadoc. */
setJavaDoc(String javaDoc)173     public void setJavaDoc(String javaDoc) {
174         mJavaDoc = javaDoc;
175     }
176 
177     /** Sets the name of the parents styleable. Can be null. */
setParents(String[] parents)178     public void setParents(String[] parents) {
179         mParents = parents;
180     }
181 
182     /** Returns the name of the parents styleable. Can be null. */
getParents()183     public String[] getParents() {
184         return mParents;
185     }
186 }
187