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.layoutlib.bridge.remote.server.adapters;
18 
19 import com.android.ide.common.rendering.api.LayoutLog;
20 import com.android.ide.common.rendering.api.RenderResources;
21 import com.android.ide.common.rendering.api.ResourceReference;
22 import com.android.ide.common.rendering.api.ResourceValue;
23 import com.android.ide.common.rendering.api.StyleResourceValue;
24 import com.android.layout.remote.api.RemoteRenderResources;
25 import com.android.resources.ResourceType;
26 import com.android.tools.layoutlib.annotations.NotNull;
27 
28 import java.rmi.RemoteException;
29 import java.util.List;
30 
31 public class RemoteRenderResourcesAdapter extends RenderResources {
32     private final RemoteRenderResources mDelegate;
33 
RemoteRenderResourcesAdapter(@otNull RemoteRenderResources remoteRenderResources)34     public RemoteRenderResourcesAdapter(@NotNull RemoteRenderResources remoteRenderResources) {
35         mDelegate = remoteRenderResources;
36     }
37 
38     @Override
setFrameworkResourceIdProvider(FrameworkResourceIdProvider provider)39     public void setFrameworkResourceIdProvider(FrameworkResourceIdProvider provider) {
40         // Ignored for remote operations.
41     }
42 
43     @Override
setLogger(LayoutLog logger)44     public void setLogger(LayoutLog logger) {
45         // Ignored for remote operations.
46     }
47 
48     @SuppressWarnings("deprecation")
49     @Override
getCurrentTheme()50     public StyleResourceValue getCurrentTheme() {
51         throw new UnsupportedOperationException();
52     }
53 
54     @Override
getDefaultTheme()55     public StyleResourceValue getDefaultTheme() {
56         try {
57             return mDelegate.getDefaultTheme();
58         } catch (RemoteException e) {
59             throw new RuntimeException(e);
60         }
61     }
62 
63     @Override
applyStyle(StyleResourceValue theme, boolean useAsPrimary)64     public void applyStyle(StyleResourceValue theme, boolean useAsPrimary) {
65         try {
66             mDelegate.applyStyle(theme, useAsPrimary);
67         } catch (RemoteException e) {
68             throw new RuntimeException(e);
69         }
70     }
71 
72     @Override
clearStyles()73     public void clearStyles() {
74         try {
75             mDelegate.clearStyles();
76         } catch (RemoteException e) {
77             throw new RuntimeException(e);
78         }
79     }
80 
81     @Override
getAllThemes()82     public List<StyleResourceValue> getAllThemes() {
83         try {
84             return mDelegate.getAllThemes();
85         } catch (RemoteException e) {
86             throw new RuntimeException(e);
87         }
88     }
89 
90     @Override
getTheme(String name, boolean frameworkTheme)91     public StyleResourceValue getTheme(String name, boolean frameworkTheme) {
92         try {
93             return mDelegate.getTheme(name, frameworkTheme);
94         } catch (RemoteException e) {
95             throw new RuntimeException(e);
96         }
97     }
98 
99     @Override
themeIsParentOf(StyleResourceValue parentTheme, StyleResourceValue childTheme)100     public boolean themeIsParentOf(StyleResourceValue parentTheme, StyleResourceValue childTheme) {
101         try {
102             return mDelegate.themeIsParentOf(parentTheme, childTheme);
103         } catch (RemoteException e) {
104             throw new RuntimeException(e);
105         }
106     }
107 
108     @Override
getFrameworkResource(ResourceType resourceType, String resourceName)109     public ResourceValue getFrameworkResource(ResourceType resourceType, String resourceName) {
110         try {
111             return mDelegate.getFrameworkResource(resourceType, resourceName);
112         } catch (RemoteException e) {
113             throw new RuntimeException(e);
114         }
115     }
116 
117     @Override
getProjectResource(ResourceType resourceType, String resourceName)118     public ResourceValue getProjectResource(ResourceType resourceType, String resourceName) {
119         try {
120             return mDelegate.getProjectResource(resourceType, resourceName);
121         } catch (RemoteException e) {
122             throw new RuntimeException(e);
123         }
124     }
125 
126     @Override
findItemInTheme(ResourceReference attr)127     public ResourceValue findItemInTheme(ResourceReference attr) {
128         try {
129             return mDelegate.findItemInTheme(attr);
130         } catch (RemoteException e) {
131             throw new RuntimeException(e);
132         }
133     }
134 
135     @Override
findItemInStyle(StyleResourceValue style, ResourceReference attr)136     public ResourceValue findItemInStyle(StyleResourceValue style, ResourceReference attr) {
137         try {
138             return mDelegate.findItemInStyle(style, attr);
139         } catch (RemoteException e) {
140             throw new RuntimeException(e);
141         }
142     }
143 
144     @Override
dereference(ResourceValue resourceValue)145     public ResourceValue dereference(ResourceValue resourceValue) {
146         try {
147             return mDelegate.dereference(resourceValue);
148         } catch (RemoteException e) {
149             throw new RuntimeException(e);
150         }
151     }
152 
153     /** Returns a resource by namespace, type and name. The returned resource is unresolved. */
154     @Override
getUnresolvedResource(ResourceReference reference)155     public ResourceValue getUnresolvedResource(ResourceReference reference) {
156         try {
157             return mDelegate.getUnresolvedResource(reference);
158         } catch (RemoteException e) {
159             throw new RuntimeException(e);
160         }
161     }
162 
163     @SuppressWarnings("deprecation")
164     @Override
resolveValue(ResourceType type, String name, String value, boolean isFrameworkValue)165     public ResourceValue resolveValue(ResourceType type, String name, String value,
166             boolean isFrameworkValue) {
167         try {
168             return mDelegate.resolveValue(type, name, value, isFrameworkValue);
169         } catch (RemoteException e) {
170             throw new RuntimeException(e);
171         }
172     }
173 
174     @Override
resolveResValue(ResourceValue value)175     public ResourceValue resolveResValue(ResourceValue value) {
176         try {
177             return mDelegate.resolveValue(value);
178         } catch (RemoteException e) {
179             throw new RuntimeException(e);
180         }
181     }
182 
183     @Override
getParent(StyleResourceValue style)184     public StyleResourceValue getParent(StyleResourceValue style) {
185         try {
186             return mDelegate.getParent(style);
187         } catch (RemoteException e) {
188             throw new RuntimeException(e);
189         }
190     }
191 
192 }
193