• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
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.rendering.api;
18 
19 import com.android.resources.ResourceType;
20 
21 /**
22  * A class containing all the resources needed to do a rendering.
23  * <p/>
24  * This contains both the project specific resources and the framework resources, and provide
25  * convenience methods to resolve resource and theme references.
26  */
27 public class RenderResources {
28 
29     public final static String REFERENCE_NULL = "@null";
30 
31     public static class FrameworkResourceIdProvider {
getId(ResourceType resType, String resName)32         public Integer getId(ResourceType resType, String resName) {
33             return null;
34         }
35     }
36 
setFrameworkResourceIdProvider(FrameworkResourceIdProvider provider)37     public void setFrameworkResourceIdProvider(FrameworkResourceIdProvider provider) {
38     }
39 
setLogger(LayoutLog logger)40     public void setLogger(LayoutLog logger) {
41     }
42 
43     /**
44      * Returns the {@link StyleResourceValue} representing the current theme.
45      * @return the theme or null if there is no current theme.
46      */
getCurrentTheme()47     public StyleResourceValue getCurrentTheme() {
48         return null;
49     }
50 
51     /**
52      * Returns a theme by its name.
53      *
54      * @param name the name of the theme
55      * @param frameworkTheme whether the theme is a framework theme.
56      * @return the theme or null if there's no match
57      */
getTheme(String name, boolean frameworkTheme)58     public StyleResourceValue getTheme(String name, boolean frameworkTheme) {
59         return null;
60     }
61 
62     /**
63      * Returns whether a theme is a parent of a given theme.
64      * @param parentTheme the parent theme
65      * @param childTheme the child theme.
66      * @return true if the parent theme is indeed a parent theme of the child theme.
67      */
themeIsParentOf(StyleResourceValue parentTheme, StyleResourceValue childTheme)68     public boolean themeIsParentOf(StyleResourceValue parentTheme, StyleResourceValue childTheme) {
69         return false;
70     }
71 
72     /**
73      * Returns a framework resource by type and name. The returned resource is resolved.
74      * @param resourceType the type of the resource
75      * @param resourceName the name of the resource
76      */
getFrameworkResource(ResourceType resourceType, String resourceName)77     public ResourceValue getFrameworkResource(ResourceType resourceType, String resourceName) {
78         return null;
79     }
80 
81     /**
82      * Returns a project resource by type and name. The returned resource is resolved.
83      * @param resourceType the type of the resource
84      * @param resourceName the name of the resource
85      */
getProjectResource(ResourceType resourceType, String resourceName)86     public ResourceValue getProjectResource(ResourceType resourceType, String resourceName) {
87         return null;
88     }
89 
90     /**
91      * Returns the {@link ResourceValue} matching a given name in the current theme. If the
92      * item is not directly available in the theme, the method looks in its parent theme.
93      *
94      * @param itemName the name of the item to search for.
95      * @return the {@link ResourceValue} object or <code>null</code>
96      *
97      * @deprecated Use {@link #findItemInTheme(String, boolean)}
98      */
99     @Deprecated
findItemInTheme(String itemName)100     public ResourceValue findItemInTheme(String itemName) {
101         StyleResourceValue currentTheme = getCurrentTheme();
102         if (currentTheme != null) {
103             return findItemInStyle(currentTheme, itemName);
104         }
105 
106         return null;
107     }
108 
109     /**
110      * Returns the {@link ResourceValue} matching a given attribute in the current theme. If the
111      * item is not directly available in the theme, the method looks in its parent theme.
112      *
113      * @param attrName the name of the attribute to search for.
114      * @param isFrameworkAttr whether the attribute is a framework attribute
115      * @return the {@link ResourceValue} object or <code>null</code>
116      */
findItemInTheme(String attrName, boolean isFrameworkAttr)117     public ResourceValue findItemInTheme(String attrName, boolean isFrameworkAttr) {
118         StyleResourceValue currentTheme = getCurrentTheme();
119         if (currentTheme != null) {
120             return findItemInStyle(currentTheme, attrName, isFrameworkAttr);
121         }
122 
123         return null;
124     }
125 
126     /**
127      * Returns the {@link ResourceValue} matching a given name in a given style. If the
128      * item is not directly available in the style, the method looks in its parent style.
129      *
130      * This version of doesn't support providing the namespace of the attribute so it'll search
131      * in both the project's namespace and then in the android namespace.
132      *
133      * @param style the style to search in
134      * @param attrName the name of the attribute to search for.
135      * @return the {@link ResourceValue} object or <code>null</code>
136      *
137      * @Deprecated Use {@link #findItemInStyle(StyleResourceValue, String, boolean)} since this
138      * method doesn't know the item namespace.
139      */
140     @Deprecated
findItemInStyle(StyleResourceValue style, String attrName)141     public ResourceValue findItemInStyle(StyleResourceValue style, String attrName) {
142         return null;
143     }
144 
145     /**
146      * Returns the {@link ResourceValue} matching a given attribute in a given style. If the
147      * item is not directly available in the style, the method looks in its parent style.
148      *
149      * @param style the style to search in
150      * @param attrName the name of the attribute to search for.
151      * @param isFrameworkAttr whether the attribute is a framework attribute
152      * @return the {@link ResourceValue} object or <code>null</code>
153      */
findItemInStyle(StyleResourceValue style, String attrName, boolean isFrameworkAttr)154     public ResourceValue findItemInStyle(StyleResourceValue style, String attrName,
155             boolean isFrameworkAttr) {
156         return null;
157     }
158 
159     /**
160      * Searches for, and returns a {@link ResourceValue} by its reference.
161      * <p/>
162      * The reference format can be:
163      * <pre>@resType/resName</pre>
164      * <pre>@android:resType/resName</pre>
165      * <pre>@resType/android:resName</pre>
166      * <pre>?resType/resName</pre>
167      * <pre>?android:resType/resName</pre>
168      * <pre>?resType/android:resName</pre>
169      * Any other string format will return <code>null</code>.
170      * <p/>
171      * The actual format of a reference is <pre>@[namespace:]resType/resName</pre> but this method
172      * only support the android namespace.
173      *
174      * @param reference the resource reference to search for.
175      * @param forceFrameworkOnly if true all references are considered to be toward framework
176      *      resource even if the reference does not include the android: prefix.
177      * @return a {@link ResourceValue} or <code>null</code>.
178      */
findResValue(String reference, boolean forceFrameworkOnly)179     public ResourceValue findResValue(String reference, boolean forceFrameworkOnly) {
180         return null;
181     }
182 
183     /**
184      * Resolves the value of a resource, if the value references a theme or resource value.
185      * <p/>
186      * This method ensures that it returns a {@link ResourceValue} object that does not
187      * reference another resource.
188      * If the resource cannot be resolved, it returns <code>null</code>.
189      * <p/>
190      * If a value that does not need to be resolved is given, the method will return a new
191      * instance of {@link ResourceValue} that contains the input value.
192      *
193      * @param type the type of the resource
194      * @param name the name of the attribute containing this value.
195      * @param value the resource value, or reference to resolve
196      * @param isFrameworkValue whether the value is a framework value.
197      *
198      * @return the resolved resource value or <code>null</code> if it failed to resolve it.
199      */
resolveValue(ResourceType type, String name, String value, boolean isFrameworkValue)200     public ResourceValue resolveValue(ResourceType type, String name, String value,
201             boolean isFrameworkValue) {
202         return null;
203     }
204 
205     /**
206      * Returns the {@link ResourceValue} referenced by the value of <var>value</var>.
207      * <p/>
208      * This method ensures that it returns a {@link ResourceValue} object that does not
209      * reference another resource.
210      * If the resource cannot be resolved, it returns <code>null</code>.
211      * <p/>
212      * If a value that does not need to be resolved is given, the method will return the input
213      * value.
214      *
215      * @param value the value containing the reference to resolve.
216      * @return a {@link ResourceValue} object or <code>null</code>
217      */
resolveResValue(ResourceValue value)218     public ResourceValue resolveResValue(ResourceValue value) {
219         return null;
220     }
221 }
222