• 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 DeclareStyleableInfo {
26     /** The style name, never null. */
27     private final String mStyleName;
28     /** Attributes for this view or view group. Can be empty but never null. */
29     private final AttributeInfo[] mAttributes;
30     /** Short javadoc. Can be null. */
31     private String mJavaDoc;
32     /** Optional name of the parents styleable. Can be null. */
33     private String[] mParents;
34 
35     /**
36      * Creates a new {@link DeclareStyleableInfo}.
37      *
38      * @param styleName The name of the style. Should not be empty nor null.
39      * @param attributes The initial list of attributes. Can be null.
40      */
DeclareStyleableInfo(String styleName, AttributeInfo[] attributes)41     public DeclareStyleableInfo(String styleName, AttributeInfo[] attributes) {
42         mStyleName = styleName;
43         mAttributes = attributes == null ? new AttributeInfo[0] : attributes;
44     }
45 
46     /**
47      * Creates a new {@link DeclareStyleableInfo} that has the same attributes
48      * as an existing one and only differs by name.
49      *
50      * @param styleName The name of the style. Should not be empty nor null.
51      * @param existing The existing {@link DeclareStyleableInfo} to mirror.
52      */
DeclareStyleableInfo(String styleName, DeclareStyleableInfo existing)53     public DeclareStyleableInfo(String styleName, DeclareStyleableInfo existing) {
54         mStyleName = styleName;
55 
56         mJavaDoc = existing.getJavaDoc();
57 
58         String[] parents = existing.getParents();
59         if (parents != null) {
60             mParents = new String[parents.length];
61             System.arraycopy(parents, 0, mParents, 0, parents.length);
62         }
63 
64         AttributeInfo[] attrs = existing.getAttributes();
65         if (attrs == null || attrs.length == 0) {
66             mAttributes = new AttributeInfo[0];
67         } else {
68             mAttributes = new AttributeInfo[attrs.length];
69             System.arraycopy(attrs, 0, mAttributes, 0, attrs.length);
70         }
71     }
72 
73     /** Returns style name */
getStyleName()74     public String getStyleName() {
75         return mStyleName;
76     }
77 
78     /** Returns the attributes for this view or view group. Maybe empty but not null. */
getAttributes()79     public AttributeInfo[] getAttributes() {
80         return mAttributes;
81     }
82 
83     /** Returns a short javadoc */
getJavaDoc()84     public String getJavaDoc() {
85         return mJavaDoc;
86     }
87 
88     /** Sets the javadoc. */
setJavaDoc(String javaDoc)89     public void setJavaDoc(String javaDoc) {
90         mJavaDoc = javaDoc;
91     }
92 
93     /** Sets the name of the parents styleable. Can be null. */
setParents(String[] parents)94     public void setParents(String[] parents) {
95         mParents = parents;
96     }
97 
98     /** Returns the name of the parents styleable. Can be null. */
getParents()99     public String[] getParents() {
100         return mParents;
101     }
102 }
103