1 /* 2 * Copyright (C) 2017 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.layout.remote.api; 18 19 import com.android.ide.common.rendering.api.Bridge; 20 import com.android.ide.common.rendering.api.LayoutLog; 21 import com.android.ide.common.rendering.api.RenderSession; 22 import com.android.ide.common.rendering.api.Result; 23 import com.android.tools.layoutlib.annotations.NotNull; 24 import com.android.tools.layoutlib.annotations.Nullable; 25 26 import java.io.File; 27 import java.rmi.Remote; 28 import java.rmi.RemoteException; 29 import java.util.Map; 30 31 /** 32 * Interface that defines the operations available in the remote bridge. This is a remote version of 33 * the local {@link Bridge} API. Most of the methods are mapped 1:1 with the {@link Bridge} API 34 * unless there is a need for a method to be adapted for remote use. 35 */ 36 public interface RemoteBridge extends Remote { 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 will 41 * appear. <p>All Layout libraries based on {@link Bridge} return at minimum an API level of 5. 42 */ getApiLevel()43 int getApiLevel() throws RemoteException; 44 45 /** 46 * Returns the revision of the library inside a given (layoutlib) API level. The true revision 47 * number of the library is {@link #getApiLevel()}.{@link #getRevision()} 48 */ 49 @SuppressWarnings("JavaDoc") 50 // javadoc pointing to itself. getRevision()51 int getRevision() throws RemoteException; 52 53 /** 54 * Returns true if the layout library supports the given feature. 55 * 56 * @see com.android.ide.common.rendering.api.Features 57 */ supports(int feature)58 boolean supports(int feature) throws RemoteException; 59 60 /** 61 * Initializes the Bridge object. 62 * 63 * @param platformProperties The build properties for the platform. 64 * @param fontLocation the location of the fonts. 65 * @param icuDataPath the location of the ICU data used natively. 66 * @param enumValueMap map attrName ⇒ { map enumFlagName ⇒ Integer value }. This is typically 67 * read from attrs.xml in the SDK target. 68 * @param log a {@link LayoutLog} object. Can be null. 69 * 70 * @return true if success. 71 */ init(@otNull Map<String, String> platformProperties, File fontLocation, String icuDataPath, @NotNull Map<String, Map<String, Integer>> enumValueMap, @Nullable RemoteLayoutLog log)72 boolean init(@NotNull Map<String, String> platformProperties, File fontLocation, 73 String icuDataPath, @NotNull Map<String, Map<String, Integer>> enumValueMap, 74 @Nullable RemoteLayoutLog log) throws RemoteException; 75 76 /** 77 * Prepares the layoutlib to be unloaded. 78 */ dispose()79 boolean dispose() throws RemoteException; 80 81 /** 82 * Starts a layout session by inflating and rendering it. The method returns a {@link 83 * RenderSession} on which further actions can be taken. 84 * 85 * @return a new {@link RenderSession} object that contains the result of the scene creation and 86 * first rendering. 87 */ 88 @NotNull createSession(@otNull RemoteSessionParams params)89 RemoteRenderSession createSession(@NotNull RemoteSessionParams params) throws RemoteException; 90 91 /** 92 * Renders a Drawable. If the rendering is successful, the result image is accessible through 93 * {@link Result#getData()}. It is of type {@link BufferedImage} 94 * 95 * @param params the rendering parameters. 96 * 97 * @return the result of the action. 98 */ 99 @NotNull renderDrawable(@otNull RemoteDrawableParams params)100 Result renderDrawable(@NotNull RemoteDrawableParams params) throws RemoteException; 101 102 /** 103 * Clears the resource cache for a specific project. 104 * <p>This cache contains bitmaps and nine patches that are loaded from the disk and reused 105 * until this method is called. 106 * <p>The cache is not configuration dependent and should only be cleared when a 107 * resource changes (at this time only bitmaps and 9 patches go into the cache). 108 * <p> 109 * The project key provided must be similar to the one passed in {@link RenderParams}. 110 * 111 * @param projectKey the key for the project. 112 */ clearCaches(String projectKey)113 void clearCaches(String projectKey) throws RemoteException; 114 115 /** 116 * Returns true if the character orientation of the locale is right to left. 117 * 118 * @param locale The locale formatted as language-region 119 * 120 * @return true if the locale is right to left. 121 */ isRtl(String locale)122 boolean isRtl(String locale) throws RemoteException; 123 } 124