1 /* 2 * Copyright (C) 2008 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.layoutlib.api; 18 19 import com.android.ide.common.rendering.api.Bridge; 20 21 import java.util.Map; 22 23 /** 24 * Entry point of the Layout Lib. Implementations of this interface provide a method to compute 25 * and render a layout. 26 * <p/> 27 * <p/>{@link #getApiLevel()} gives the ability to know which methods are available. 28 * <p/> 29 * Changes in API level 5: 30 * <ul> 31 * <li>Bridge should extend {@link Bridge} instead of implementing {@link ILayoutBridge}.</li> 32 * </ul> 33 * Changes in API level 4: 34 * <ul> 35 * <li>new render method: {@link #computeLayout(IXmlPullParser, Object, int, int, boolean, int, float, float, String, boolean, Map, Map, IProjectCallback, ILayoutLog)}</li> 36 * <li>deprecated {@link #computeLayout(IXmlPullParser, Object, int, int, int, float, float, String, boolean, Map, Map, IProjectCallback, ILayoutLog)}</li> 37 * </ul> 38 * Changes in API level 3: 39 * <ul> 40 * <li>new render method: {@link #computeLayout(IXmlPullParser, Object, int, int, int, float, float, String, boolean, Map, Map, IProjectCallback, ILayoutLog)}</li> 41 * <li>deprecated {@link #computeLayout(IXmlPullParser, Object, int, int, String, boolean, Map, Map, IProjectCallback, ILayoutLog)}</li> 42 * </ul> 43 * Changes in API level 2: 44 * <ul> 45 * <li>new API Level method: {@link #getApiLevel()}</li> 46 * <li>new render method: {@link #computeLayout(IXmlPullParser, Object, int, int, String, boolean, Map, Map, IProjectCallback, ILayoutLog)}</li> 47 * <li>deprecated {@link #computeLayout(IXmlPullParser, Object, int, int, String, Map, Map, IProjectCallback, ILayoutLog)}</li> 48 * </ul> 49 * @deprecated Extend {@link Bridge} instead. 50 */ 51 @Deprecated 52 public interface ILayoutBridge { 53 54 final int API_CURRENT = 4; 55 56 /** 57 * Returns the API level of the layout library. 58 * While no methods will ever be removed, some may become deprecated, and some new ones 59 * will appear. 60 * <p/>If calling this method throws an {@link AbstractMethodError}, then the API level 61 * should be considered to be 1. 62 */ getApiLevel()63 int getApiLevel(); 64 65 /** 66 * Initializes the Bridge object. 67 * @param fontOsLocation the location of the fonts. 68 * @param enumValueMap map attrName => { map enumFlagName => Integer value }. 69 * @return true if success. 70 * @since 1 71 */ init(String fontOsLocation, Map<String, Map<String, Integer>> enumValueMap)72 boolean init(String fontOsLocation, Map<String, Map<String, Integer>> enumValueMap); 73 74 /** 75 * Prepares the layoutlib to unloaded. 76 */ dispose()77 boolean dispose(); 78 79 /** 80 * Starts a layout session by inflating and rendering it. The method returns a 81 * {@link ILayoutResult} on which further actions can be taken. 82 * 83 * @param layoutDescription the {@link IXmlPullParser} letting the LayoutLib Bridge visit the 84 * layout file. 85 * @param projectKey An Object identifying the project. This is used for the cache mechanism. 86 * @param screenWidth the screen width 87 * @param screenHeight the screen height 88 * @param renderFullSize if true, the rendering will render the full size needed by the 89 * layout. This size is never smaller than <var>screenWidth</var> x <var>screenHeight</var>. 90 * @param density the density factor for the screen. 91 * @param xdpi the screen actual dpi in X 92 * @param ydpi the screen actual dpi in Y 93 * @param themeName The name of the theme to use. 94 * @param isProjectTheme true if the theme is a project theme, false if it is a framework theme. 95 * @param projectResources the resources of the project. The map contains (String, map) pairs 96 * where the string is the type of the resource reference used in the layout file, and the 97 * map contains (String, {@link IResourceValue}) pairs where the key is the resource name, 98 * and the value is the resource value. 99 * @param frameworkResources the framework resources. The map contains (String, map) pairs 100 * where the string is the type of the resource reference used in the layout file, and the map 101 * contains (String, {@link IResourceValue}) pairs where the key is the resource name, and the 102 * value is the resource value. 103 * @param projectCallback The {@link IProjectCallback} object to get information from 104 * the project. 105 * @param logger the object responsible for displaying warning/errors to the user. 106 * @return a new {@link ILayoutResult} object that contains the result of the layout. 107 * @deprecated use {@link Bridge#createScene(SceneParams)} 108 * @since 4 109 */ 110 @Deprecated computeLayout(IXmlPullParser layoutDescription, Object projectKey, int screenWidth, int screenHeight, boolean renderFullSize, int density, float xdpi, float ydpi, String themeName, boolean isProjectTheme, Map<String, Map<String, IResourceValue>> projectResources, Map<String, Map<String, IResourceValue>> frameworkResources, IProjectCallback projectCallback, ILayoutLog logger)111 ILayoutResult computeLayout(IXmlPullParser layoutDescription, 112 Object projectKey, 113 int screenWidth, int screenHeight, boolean renderFullSize, 114 int density, float xdpi, float ydpi, 115 String themeName, boolean isProjectTheme, 116 Map<String, Map<String, IResourceValue>> projectResources, 117 Map<String, Map<String, IResourceValue>> frameworkResources, 118 IProjectCallback projectCallback, ILayoutLog logger); 119 120 /** 121 * Computes and renders a layout 122 * @param layoutDescription the {@link IXmlPullParser} letting the LayoutLib Bridge visit the 123 * layout file. 124 * @param projectKey An Object identifying the project. This is used for the cache mechanism. 125 * @param screenWidth the screen width 126 * @param screenHeight the screen height 127 * @param density the density factor for the screen. 128 * @param xdpi the screen actual dpi in X 129 * @param ydpi the screen actual dpi in Y 130 * @param themeName The name of the theme to use. 131 * @param isProjectTheme true if the theme is a project theme, false if it is a framework theme. 132 * @param projectResources the resources of the project. The map contains (String, map) pairs 133 * where the string is the type of the resource reference used in the layout file, and the 134 * map contains (String, {@link IResourceValue}) pairs where the key is the resource name, 135 * and the value is the resource value. 136 * @param frameworkResources the framework resources. The map contains (String, map) pairs 137 * where the string is the type of the resource reference used in the layout file, and the map 138 * contains (String, {@link IResourceValue}) pairs where the key is the resource name, and the 139 * value is the resource value. 140 * @param projectCallback The {@link IProjectCallback} object to get information from 141 * the project. 142 * @param logger the object responsible for displaying warning/errors to the user. 143 * @return a new {@link ILayoutResult} object that contains the result of the layout. 144 * @deprecated use {@link Bridge#createScene(SceneParams)} 145 * @since 3 146 */ 147 @Deprecated computeLayout(IXmlPullParser layoutDescription, Object projectKey, int screenWidth, int screenHeight, int density, float xdpi, float ydpi, String themeName, boolean isProjectTheme, Map<String, Map<String, IResourceValue>> projectResources, Map<String, Map<String, IResourceValue>> frameworkResources, IProjectCallback projectCallback, ILayoutLog logger)148 ILayoutResult computeLayout(IXmlPullParser layoutDescription, 149 Object projectKey, 150 int screenWidth, int screenHeight, int density, float xdpi, float ydpi, 151 String themeName, boolean isProjectTheme, 152 Map<String, Map<String, IResourceValue>> projectResources, 153 Map<String, Map<String, IResourceValue>> frameworkResources, 154 IProjectCallback projectCallback, ILayoutLog logger); 155 156 /** 157 * Computes and renders a layout 158 * @param layoutDescription the {@link IXmlPullParser} letting the LayoutLib Bridge visit the 159 * layout file. 160 * @param projectKey An Object identifying the project. This is used for the cache mechanism. 161 * @param screenWidth the screen width 162 * @param screenHeight the screen height 163 * @param themeName The name of the theme to use. 164 * @param isProjectTheme true if the theme is a project theme, false if it is a framework theme. 165 * @param projectResources the resources of the project. The map contains (String, map) pairs 166 * where the string is the type of the resource reference used in the layout file, and the 167 * map contains (String, {@link IResourceValue}) pairs where the key is the resource name, 168 * and the value is the resource value. 169 * @param frameworkResources the framework resources. The map contains (String, map) pairs 170 * where the string is the type of the resource reference used in the layout file, and the map 171 * contains (String, {@link IResourceValue}) pairs where the key is the resource name, and the 172 * value is the resource value. 173 * @param projectCallback The {@link IProjectCallback} object to get information from 174 * the project. 175 * @param logger the object responsible for displaying warning/errors to the user. 176 * @return a new {@link ILayoutResult} object that contains the result of the layout. 177 * @deprecated use {@link Bridge#createScene(SceneParams)} 178 * @since 2 179 */ 180 @Deprecated computeLayout(IXmlPullParser layoutDescription, Object projectKey, int screenWidth, int screenHeight, String themeName, boolean isProjectTheme, Map<String, Map<String, IResourceValue>> projectResources, Map<String, Map<String, IResourceValue>> frameworkResources, IProjectCallback projectCallback, ILayoutLog logger)181 ILayoutResult computeLayout(IXmlPullParser layoutDescription, 182 Object projectKey, 183 int screenWidth, int screenHeight, String themeName, boolean isProjectTheme, 184 Map<String, Map<String, IResourceValue>> projectResources, 185 Map<String, Map<String, IResourceValue>> frameworkResources, 186 IProjectCallback projectCallback, ILayoutLog logger); 187 188 /** 189 * Computes and renders a layout 190 * @param layoutDescription the {@link IXmlPullParser} letting the LayoutLib Bridge visit the 191 * layout file. 192 * @param projectKey An Object identifying the project. This is used for the cache mechanism. 193 * @param screenWidth 194 * @param screenHeight 195 * @param themeName The name of the theme to use. In order to differentiate project and platform 196 * themes sharing the same name, all project themes must be prepended with a '*' character. 197 * @param projectResources the resources of the project. The map contains (String, map) pairs 198 * where the string is the type of the resource reference used in the layout file, and the 199 * map contains (String, {@link IResourceValue}) pairs where the key is the resource name, 200 * and the value is the resource value. 201 * @param frameworkResources the framework resources. The map contains (String, map) pairs 202 * where the string is the type of the resource reference used in the layout file, and the map 203 * contains (String, {@link IResourceValue}) pairs where the key is the resource name, and the 204 * value is the resource value. 205 * @param projectCallback The {@link IProjectCallback} object to get information from 206 * the project. 207 * @param logger the object responsible for displaying warning/errors to the user. 208 * @return a new {@link ILayoutResult} object that contains the result of the layout. 209 * @deprecated use {@link Bridge#createScene(SceneParams)} 210 * @since 1 211 */ 212 @Deprecated computeLayout(IXmlPullParser layoutDescription, Object projectKey, int screenWidth, int screenHeight, String themeName, Map<String, Map<String, IResourceValue>> projectResources, Map<String, Map<String, IResourceValue>> frameworkResources, IProjectCallback projectCallback, ILayoutLog logger)213 ILayoutResult computeLayout(IXmlPullParser layoutDescription, 214 Object projectKey, 215 int screenWidth, int screenHeight, String themeName, 216 Map<String, Map<String, IResourceValue>> projectResources, 217 Map<String, Map<String, IResourceValue>> frameworkResources, 218 IProjectCallback projectCallback, ILayoutLog logger); 219 220 /** 221 * Clears the resource cache for a specific project. 222 * <p/>This cache contains bitmaps and nine patches that are loaded from the disk and reused 223 * until this method is called. 224 * <p/>The cache is not configuration dependent and should only be cleared when a 225 * resource changes (at this time only bitmaps and 9 patches go into the cache). 226 * @param projectKey the key for the project. 227 * @since 1 228 */ clearCaches(Object projectKey)229 void clearCaches(Object projectKey); 230 } 231