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