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