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.ILayoutLog; 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 * Initializes the Bridge object. 39 * 40 * @param platformProperties The build properties for the platform. 41 * @param fontLocation the location of the fonts. 42 * @param nativeLibPath the absolute path of the JNI library for layoutlib. 43 * @param icuDataPath the location of the ICU data used natively. 44 * @param enumValueMap map attrName ⇒ { map enumFlagName ⇒ Integer value }. This is typically 45 * read from attrs.xml in the SDK target. 46 * @param log a {@link ILayoutLog} object. Can be null. 47 * 48 * @return true if success. 49 */ init(@otNull Map<String, String> platformProperties, File fontLocation, @Nullable String nativeLibPath, @Nullable String icuDataPath, @NotNull Map<String, Map<String, Integer>> enumValueMap, @Nullable RemoteLayoutLog log)50 boolean init(@NotNull Map<String, String> platformProperties, File fontLocation, 51 @Nullable String nativeLibPath, @Nullable String icuDataPath, 52 @NotNull Map<String, Map<String, Integer>> enumValueMap, 53 @Nullable RemoteLayoutLog log) throws RemoteException; 54 55 /** 56 * Prepares the layoutlib to be unloaded. 57 */ dispose()58 boolean dispose() throws RemoteException; 59 60 /** 61 * Starts a layout session by inflating and rendering it. The method returns a {@link 62 * RenderSession} on which further actions can be taken. 63 * 64 * @return a new {@link RenderSession} object that contains the result of the scene creation and 65 * first rendering. 66 */ 67 @NotNull createSession(@otNull RemoteSessionParams params)68 RemoteRenderSession createSession(@NotNull RemoteSessionParams params) throws RemoteException; 69 70 /** 71 * Renders a Drawable. If the rendering is successful, the result image is accessible through 72 * {@link Result#getData()}. It is of type {@link BufferedImage} 73 * 74 * @param params the rendering parameters. 75 * 76 * @return the result of the action. 77 */ 78 @NotNull renderDrawable(@otNull RemoteDrawableParams params)79 Result renderDrawable(@NotNull RemoteDrawableParams params) throws RemoteException; 80 81 /** 82 * Clears the resource cache for a specific project. 83 * 84 * <p>This cache contains bitmaps and nine patches that are loaded from the disk and reused 85 * until this method is called. 86 * 87 * <p>The cache is not configuration dependent and should only be cleared when a resource 88 * changes (at this time only bitmaps and 9 patches go into the cache). 89 * 90 * <p>The project key provided must be similar to the one passed in {@link RenderParams}. 91 * 92 * @param projectKey the key for the project. 93 */ clearResourceCaches(String projectKey)94 void clearResourceCaches(String projectKey) throws RemoteException; 95 96 /** 97 * Returns true if the character orientation of the locale is right to left. 98 * 99 * @param locale The locale formatted as language-region 100 * 101 * @return true if the locale is right to left. 102 */ isRtl(String locale)103 boolean isRtl(String locale) throws RemoteException; 104 } 105