Debian Codegraph @

layoutlib-api/src/main/java/com/android/ide/common/rendering/api/Bridge.java

raw
1 /*
2 * Copyright (C) 2010 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
20 import static com.android.ide.common.rendering.api.Result.Status.NOT_IMPLEMENTED;
21
22 import com.android.ide.common.rendering.api.Result.Status;
23
24 import java.awt.image.BufferedImage;
25 import java.io.File;
26 import java.util.EnumSet;
27 import java.util.Map;
28
29 /**
30 * Entry point of the Layout Library. Extensions of this class provide a method to compute
31 * and render a layout.
32 */
33 @SuppressWarnings({"MethodMayBeStatic", "UnusedDeclaration"})
34 public abstract class Bridge {
35
36 public static final int API_CURRENT = 17;
37
38 /**
39 * Returns the API level of the layout library.
40 * <p>
41 * While no methods will ever be removed, some may become deprecated, and some new ones
42 * will appear.
43 * <p>All Layout libraries based on {@link Bridge} return at minimum an API level of 5.
44 */
45 public abstract int getApiLevel();
46
47 /**
48 * Returns the revision of the library inside a given (layoutlib) API level.
49 * The true revision number of the library is {@link #getApiLevel()}.{@link #getRevision()}
50 */
51 @SuppressWarnings("JavaDoc") // javadoc pointing to itself.
52 public int getRevision() {
53 return 0;
54 }
55
56 /**
57 * Returns an {@link EnumSet} of the supported {@link Capability}.
58 *
59 * @return an {@link EnumSet} with the supported capabilities.
60 *
61 * @deprecated use {@link #supports(int)}
62 */
63 @Deprecated
64 public EnumSet<Capability> getCapabilities() {
65 return EnumSet.noneOf(Capability.class);
66 }
67
68 /**
69 * Returns true if the layout library supports the given feature.
70 *
71 * @see com.android.ide.common.rendering.api.Features
72 */
73 public boolean supports(int feature) {
74 return false;
75 }
76
77 /**
78 * Initializes the Bridge object.
79 *
80 * @param platformProperties The build properties for the platform.
81 * @param fontLocation the location of the fonts.
82 * @param enumValueMap map attrName ⇒ { map enumFlagName ⇒ Integer value }. This is typically
83 * read from attrs.xml in the SDK target.
84 * @param log a {@link LayoutLog} object. Can be null.
85 * @return true if success.
86 */
87 public boolean init(Map<String, String> platformProperties,
88 File fontLocation,
89 Map<String, Map<String, Integer>> enumValueMap,
90 LayoutLog log) {
91 return false;
92 }
93
94 /**
95 * Prepares the layoutlib to unloaded.
96 */
97 public boolean dispose() {
98 return false;
99 }
100
101 /**
102 * Starts a layout session by inflating and rendering it. The method returns a
103 * {@link RenderSession} on which further actions can be taken.
104 *
105 * @return a new {@link RenderSession} object that contains the result of the scene creation and
106 * first rendering.
107 */
108 public RenderSession createSession(SessionParams params) {
109 return null;
110 }
111
112 /**
113 * Renders a Drawable. If the rendering is successful, the result image is accessible through
114 * {@link Result#getData()}. It is of type {@link BufferedImage}
115 * @param params the rendering parameters.
116 * @return the result of the action.
117 */
118 public Result renderDrawable(DrawableParams params) {
119 return Status.NOT_IMPLEMENTED.createResult();
120 }
121
122 /**
123 * Clears the resource cache for a specific project.
124 * <p>This cache contains bitmaps and nine patches that are loaded from the disk and reused
125 * until this method is called.
126 * <p>The cache is not configuration dependent and should only be cleared when a
127 * resource changes (at this time only bitmaps and 9 patches go into the cache).
128 * <p>
129 * The project key provided must be similar to the one passed in {@link RenderParams}.
130 *
131 * @param projectKey the key for the project.
132 */
133 public void clearCaches(Object projectKey) {
134
135 }
136
137 /**
138 * Utility method returning the parent of a given view object.
139 *
140 * @param viewObject the object for which to return the parent.
141 *
142 * @return a {@link Result} indicating the status of the action, and if success, the parent
143 * object in {@link Result#getData()}
144 */
145 public Result getViewParent(Object viewObject) {
146 return NOT_IMPLEMENTED.createResult();
147 }
148
149 /**
150 * Utility method returning the index of a given view in its parent.
151 * @param viewObject the object for which to return the index.
152 *
153 * @return a {@link Result} indicating the status of the action, and if success, the index in
154 * the parent in {@link Result#getData()}
155 */
156 public Result getViewIndex(Object viewObject) {
157 return NOT_IMPLEMENTED.createResult();
158 }
159
160 /**
161 * Returns true if the character orientation of the locale is right to left.
162 * @param locale The locale formatted as language-region
163 * @return true if the locale is right to left.
164 */
165 public boolean isRtl(String locale) {
166 return false;
167 }
168
169 /**
170 * Utility method returning the baseline value for a given view object. This basically returns
171 * View.getBaseline().
172 *
173 * @param viewObject the object for which to return the index.
174 *
175 * @return the baseline value or -1 if not applicable to the view object or if this layout
176 * library does not implement this method.
177 *
178 * @deprecated use the extended ViewInfo.
179 */
180 @Deprecated
181 public Result getViewBaseline(Object viewObject) {
182 return NOT_IMPLEMENTED.createResult();
183 }
184 }