1 /* 2 * Copyright (C) 2016 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;import com.android.ide.common.rendering.api.RenderSession; 18 import com.android.ide.common.rendering.api.Result; 19 import com.android.ide.common.rendering.api.Result.Status; 20 import com.android.ide.common.rendering.api.SessionParams; 21 22 import java.awt.Graphics2D; 23 import java.awt.image.BufferedImage; 24 25 /** 26 * Legacy Bridge used in the SDK version of layoutlib 27 */ 28 public final class Bridge extends com.android.ide.common.rendering.api.Bridge { 29 private static final String SDK_NOT_SUPPORTED = "The SDK layoutlib version is not supported"; 30 private static final Result NOT_SUPPORTED_RESULT = 31 Status.NOT_IMPLEMENTED.createResult(SDK_NOT_SUPPORTED); 32 private static BufferedImage sImage; 33 34 private static class BridgeRenderSession extends RenderSession { 35 36 @Override getImage()37 public synchronized BufferedImage getImage() { 38 if (sImage == null) { 39 sImage = new BufferedImage(500, 500, BufferedImage.TYPE_INT_ARGB); 40 Graphics2D g = sImage.createGraphics(); 41 g.clearRect(0, 0, 500, 500); 42 g.drawString(SDK_NOT_SUPPORTED, 20, 20); 43 g.dispose(); 44 } 45 46 return sImage; 47 } 48 49 @Override render(long timeout, boolean forceMeasure)50 public Result render(long timeout, boolean forceMeasure) { 51 return NOT_SUPPORTED_RESULT; 52 } 53 54 @Override measure(long timeout)55 public Result measure(long timeout) { 56 return NOT_SUPPORTED_RESULT; 57 } 58 59 @Override getResult()60 public Result getResult() { 61 return NOT_SUPPORTED_RESULT; 62 } 63 } 64 65 66 @Override createSession(SessionParams params)67 public RenderSession createSession(SessionParams params) { 68 return new BridgeRenderSession(); 69 } 70 71 @Override getApiLevel()72 public int getApiLevel() { 73 return 0; 74 } 75 } 76