• 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      */
findItemInTheme(String itemName)97     public ResourceValue findItemInTheme(String itemName) {
98         StyleResourceValue currentTheme = getCurrentTheme();
99         if (currentTheme != null) {
100             return findItemInStyle(currentTheme, itemName);
101         }
102 
103         return null;
104     }
105 
106     /**
107      * Returns the {@link ResourceValue} matching a given name in a given style. If the
108      * item is not directly available in the style, the method looks in its parent style.
109      *
110      * @param style the style to search in
111      * @param itemName the name of the item to search for.
112      * @return the {@link ResourceValue} object or <code>null</code>
113      */
findItemInStyle(StyleResourceValue style, String itemName)114     public ResourceValue findItemInStyle(StyleResourceValue style, String itemName) {
115         return null;
116     }
117 
118     /**
119      * Searches for, and returns a {@link ResourceValue} by its reference.
120      * <p/>
121      * The reference format can be:
122      * <pre>@resType/resName</pre>
123      * <pre>@android:resType/resName</pre>
124      * <pre>@resType/android:resName</pre>
125      * <pre>?resType/resName</pre>
126      * <pre>?android:resType/resName</pre>
127      * <pre>?resType/android:resName</pre>
128      * Any other string format will return <code>null</code>.
129      * <p/>
130      * The actual format of a reference is <pre>@[namespace:]resType/resName</pre> but this method
131      * only support the android namespace.
132      *
133      * @param reference the resource reference to search for.
134      * @param forceFrameworkOnly if true all references are considered to be toward framework
135      *      resource even if the reference does not include the android: prefix.
136      * @return a {@link ResourceValue} or <code>null</code>.
137      */
findResValue(String reference, boolean forceFrameworkOnly)138     public ResourceValue findResValue(String reference, boolean forceFrameworkOnly) {
139         return null;
140     }
141 
142     /**
143      * Resolves the value of a resource, if the value references a theme or resource value.
144      * <p/>
145      * This method ensures that it returns a {@link ResourceValue} object that does not
146      * reference another resource.
147      * If the resource cannot be resolved, it returns <code>null</code>.
148      * <p/>
149      * If a value that does not need to be resolved is given, the method will return a new
150      * instance of {@link ResourceValue} that contains the input value.
151      *
152      * @param type the type of the resource
153      * @param name the name of the attribute containing this value.
154      * @param value the resource value, or reference to resolve
155      * @param isFrameworkValue whether the value is a framework value.
156      *
157      * @return the resolved resource value or <code>null</code> if it failed to resolve it.
158      */
resolveValue(ResourceType type, String name, String value, boolean isFrameworkValue)159     public ResourceValue resolveValue(ResourceType type, String name, String value,
160             boolean isFrameworkValue) {
161         return null;
162     }
163 
164     /**
165      * Returns the {@link ResourceValue} referenced by the value of <var>value</var>.
166      * <p/>
167      * This method ensures that it returns a {@link ResourceValue} object that does not
168      * reference another resource.
169      * If the resource cannot be resolved, it returns <code>null</code>.
170      * <p/>
171      * If a value that does not need to be resolved is given, the method will return the input
172      * value.
173      *
174      * @param value the value containing the reference to resolve.
175      * @return a {@link ResourceValue} object or <code>null</code>
176      */
resolveResValue(ResourceValue value)177     public ResourceValue resolveResValue(ResourceValue value) {
178         return null;
179     }
180 }
181