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
17package com.android.layout.remote.api;
18
19import com.android.ide.common.rendering.api.Bridge;
20import com.android.ide.common.rendering.api.LayoutLog;
21import com.android.ide.common.rendering.api.RenderSession;
22import com.android.ide.common.rendering.api.Result;
23import com.android.tools.layoutlib.annotations.NotNull;
24import com.android.tools.layoutlib.annotations.Nullable;
25
26import java.io.File;
27import java.rmi.Remote;
28import java.rmi.RemoteException;
29import 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 */
36public 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     */
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.
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     */
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 enumValueMap map attrName ⇒ { map enumFlagName ⇒ Integer value }. This is typically
66     * read from attrs.xml in the SDK target.
67     * @param log a {@link LayoutLog} object. Can be null.
68     *
69     * @return true if success.
70     */
71    boolean init(@NotNull Map<String, String> platformProperties, File fontLocation,
72            @NotNull Map<String, Map<String, Integer>> enumValueMap, @Nullable RemoteLayoutLog log)
73            throws RemoteException;
74
75    /**
76     * Prepares the layoutlib to be unloaded.
77     */
78    boolean dispose() throws RemoteException;
79
80    /**
81     * Starts a layout session by inflating and rendering it. The method returns a {@link
82     * RenderSession} on which further actions can be taken.
83     *
84     * @return a new {@link RenderSession} object that contains the result of the scene creation and
85     * first rendering.
86     */
87    @NotNull
88    RemoteRenderSession createSession(@NotNull RemoteSessionParams params) throws RemoteException;
89
90    /**
91     * Renders a Drawable. If the rendering is successful, the result image is accessible through
92     * {@link Result#getData()}. It is of type {@link BufferedImage}
93     *
94     * @param params the rendering parameters.
95     *
96     * @return the result of the action.
97     */
98    @NotNull
99    Result renderDrawable(@NotNull RemoteDrawableParams params) throws RemoteException;
100
101    /**
102     * Clears the resource cache for a specific project.
103     * <p>This cache contains bitmaps and nine patches that are loaded from the disk and reused
104     * until this method is called.
105     * <p>The cache is not configuration dependent and should only be cleared when a
106     * resource changes (at this time only bitmaps and 9 patches go into the cache).
107     * <p>
108     * The project key provided must be similar to the one passed in {@link RenderParams}.
109     *
110     * @param projectKey the key for the project.
111     */
112    void clearCaches(String projectKey) throws RemoteException;
113
114    /**
115     * Returns true if the character orientation of the locale is right to left.
116     *
117     * @param locale The locale formatted as language-region
118     *
119     * @return true if the locale is right to left.
120     */
121    boolean isRtl(String locale) throws RemoteException;
122}
123