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 * @param style the style to search in 131 * @param itemName the name of the item to search for. 132 * @return the {@link ResourceValue} object or <code>null</code> 133 * 134 * @Deprecated Use {@link #findItemInStyle(StyleResourceValue, String, boolean)} 135 */ 136 @Deprecated findItemInStyle(StyleResourceValue style, String itemName)137 public ResourceValue findItemInStyle(StyleResourceValue style, String itemName) { 138 return null; 139 } 140 141 /** 142 * Returns the {@link ResourceValue} matching a given attribute in a given style. If the 143 * item is not directly available in the style, the method looks in its parent style. 144 * 145 * @param style the style to search in 146 * @param attrName the name of the attribute to search for. 147 * @param isFrameworkAttr whether the attribute is a framework attribute 148 * @return the {@link ResourceValue} object or <code>null</code> 149 */ findItemInStyle(StyleResourceValue style, String attrName, boolean isFrameworkAttr)150 public ResourceValue findItemInStyle(StyleResourceValue style, String attrName, 151 boolean isFrameworkAttr) { 152 return null; 153 } 154 155 /** 156 * Searches for, and returns a {@link ResourceValue} by its reference. 157 * <p/> 158 * The reference format can be: 159 * <pre>@resType/resName</pre> 160 * <pre>@android:resType/resName</pre> 161 * <pre>@resType/android:resName</pre> 162 * <pre>?resType/resName</pre> 163 * <pre>?android:resType/resName</pre> 164 * <pre>?resType/android:resName</pre> 165 * Any other string format will return <code>null</code>. 166 * <p/> 167 * The actual format of a reference is <pre>@[namespace:]resType/resName</pre> but this method 168 * only support the android namespace. 169 * 170 * @param reference the resource reference to search for. 171 * @param forceFrameworkOnly if true all references are considered to be toward framework 172 * resource even if the reference does not include the android: prefix. 173 * @return a {@link ResourceValue} or <code>null</code>. 174 */ findResValue(String reference, boolean forceFrameworkOnly)175 public ResourceValue findResValue(String reference, boolean forceFrameworkOnly) { 176 return null; 177 } 178 179 /** 180 * Resolves the value of a resource, if the value references a theme or resource value. 181 * <p/> 182 * This method ensures that it returns a {@link ResourceValue} object that does not 183 * reference another resource. 184 * If the resource cannot be resolved, it returns <code>null</code>. 185 * <p/> 186 * If a value that does not need to be resolved is given, the method will return a new 187 * instance of {@link ResourceValue} that contains the input value. 188 * 189 * @param type the type of the resource 190 * @param name the name of the attribute containing this value. 191 * @param value the resource value, or reference to resolve 192 * @param isFrameworkValue whether the value is a framework value. 193 * 194 * @return the resolved resource value or <code>null</code> if it failed to resolve it. 195 */ resolveValue(ResourceType type, String name, String value, boolean isFrameworkValue)196 public ResourceValue resolveValue(ResourceType type, String name, String value, 197 boolean isFrameworkValue) { 198 return null; 199 } 200 201 /** 202 * Returns the {@link ResourceValue} referenced by the value of <var>value</var>. 203 * <p/> 204 * This method ensures that it returns a {@link ResourceValue} object that does not 205 * reference another resource. 206 * If the resource cannot be resolved, it returns <code>null</code>. 207 * <p/> 208 * If a value that does not need to be resolved is given, the method will return the input 209 * value. 210 * 211 * @param value the value containing the reference to resolve. 212 * @return a {@link ResourceValue} object or <code>null</code> 213 */ resolveResValue(ResourceValue value)214 public ResourceValue resolveResValue(ResourceValue value) { 215 return null; 216 } 217 } 218