Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 19a02103 authored by Xavier Ducrohet's avatar Xavier Ducrohet
Browse files

LayoutLib: Update layoutlib with revised API.

Change-Id: I78929df621f48e85d9cbefe1f5590f9ce99bbaff
parent 34884643
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@

package android.app;

import com.android.layoutlib.api.IProjectCallback;
import com.android.ide.common.rendering.api.IProjectCallback;

import android.content.Context;
import android.os.Bundle;
+1 −1
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@

package android.graphics;

import com.android.layoutlib.api.ResourceDensity;
import com.android.ide.common.rendering.api.ResourceDensity;
import com.android.layoutlib.bridge.Bridge;

import android.content.res.AssetManager;
+1 −1
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@

package android.graphics;

import com.android.layoutlib.api.ResourceDensity;
import com.android.ide.common.rendering.api.ResourceDensity;
import com.android.layoutlib.bridge.impl.DelegateManager;

import android.graphics.Bitmap.Config;
+21 −18
Original line number Diff line number Diff line
@@ -16,15 +16,17 @@

package com.android.layoutlib.bridge;

import com.android.layoutlib.api.Capability;
import com.android.layoutlib.api.LayoutBridge;
import com.android.layoutlib.api.LayoutLog;
import com.android.layoutlib.api.SceneParams;
import com.android.layoutlib.api.SceneResult;
import com.android.layoutlib.api.SceneResult.SceneStatus;
import static com.android.ide.common.rendering.api.Result.Status.ERROR_UNKNOWN;
import static com.android.ide.common.rendering.api.Result.Status.SUCCESS;

import com.android.ide.common.rendering.api.Capability;
import com.android.ide.common.rendering.api.LayoutLog;
import com.android.ide.common.rendering.api.Params;
import com.android.ide.common.rendering.api.RenderSession;
import com.android.ide.common.rendering.api.Result;
import com.android.layoutlib.bridge.android.BridgeAssetManager;
import com.android.layoutlib.bridge.impl.FontLoader;
import com.android.layoutlib.bridge.impl.LayoutSceneImpl;
import com.android.layoutlib.bridge.impl.RenderSessionImpl;
import com.android.ninepatch.NinePatchChunk;
import com.android.tools.layoutlib.create.MethodAdapter;
import com.android.tools.layoutlib.create.OverrideMethod;
@@ -33,6 +35,7 @@ import android.graphics.Bitmap;
import android.graphics.Typeface_Delegate;
import android.os.Looper;

import java.io.File;
import java.lang.ref.SoftReference;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
@@ -47,7 +50,7 @@ import java.util.concurrent.locks.ReentrantLock;
 * <p/>To use this bridge, simply instantiate an object of type {@link Bridge} and call
 * {@link #createScene(SceneParams)}
 */
public final class Bridge extends LayoutBridge {
public final class Bridge extends com.android.ide.common.rendering.api.Bridge {

    public static class StaticMethodNotImplementedException extends RuntimeException {
        private static final long serialVersionUID = 1L;
@@ -169,7 +172,7 @@ public final class Bridge extends LayoutBridge {

    @Override
    public int getApiLevel() {
        return LayoutBridge.API_CURRENT;
        return com.android.ide.common.rendering.api.Bridge.API_CURRENT;
    }

    @Override
@@ -179,10 +182,10 @@ public final class Bridge extends LayoutBridge {

    /*
     * (non-Javadoc)
     * @see com.android.layoutlib.api.ILayoutLibBridge#init(java.lang.String, java.util.Map)
     * @see com.android.layoutlib.api.ILayoutLibBridge#init(java.io.File, java.util.Map)
     */
    @Override
    public boolean init(String fontOsLocation, Map<String, Map<String, Integer>> enumValueMap) {
    public boolean init(File fontLocation, Map<String, Map<String, Integer>> enumValueMap) {
        sEnumValueMap = enumValueMap;

        // don't use EnumSet.allOf(), because the bridge doesn't come with its specific version
@@ -229,7 +232,7 @@ public final class Bridge extends LayoutBridge {
        }

        // load the fonts.
        FontLoader fontLoader = FontLoader.create(fontOsLocation);
        FontLoader fontLoader = FontLoader.create(fontLocation.getAbsolutePath());
        if (fontLoader != null) {
            Typeface_Delegate.init(fontLoader);
        } else {
@@ -299,10 +302,10 @@ public final class Bridge extends LayoutBridge {
     * @since 5
     */
    @Override
    public BridgeLayoutScene createScene(SceneParams params) {
    public RenderSession createSession(Params params) {
        try {
            SceneResult lastResult = SceneStatus.SUCCESS.createResult();
            LayoutSceneImpl scene = new LayoutSceneImpl(params);
            Result lastResult = SUCCESS.createResult();
            RenderSessionImpl scene = new RenderSessionImpl(params);
            try {
                prepareThread();
                lastResult = scene.init(params.getTimeout());
@@ -317,15 +320,15 @@ public final class Bridge extends LayoutBridge {
                cleanupThread();
            }

            return new BridgeLayoutScene(scene, lastResult);
            return new BridgeRenderSession(scene, lastResult);
        } catch (Throwable t) {
            // get the real cause of the exception.
            Throwable t2 = t;
            while (t2.getCause() != null) {
                t2 = t.getCause();
            }
            return new BridgeLayoutScene(null,
                    SceneStatus.ERROR_UNKNOWN.createResult(t2.getMessage(), t2));
            return new BridgeRenderSession(null,
                    ERROR_UNKNOWN.createResult(t2.getMessage(), t2));
        }
    }

+40 −39
Original line number Diff line number Diff line
@@ -16,12 +16,13 @@

package com.android.layoutlib.bridge;

import com.android.layoutlib.api.IXmlPullParser;
import com.android.layoutlib.api.LayoutScene;
import com.android.layoutlib.api.SceneParams;
import com.android.layoutlib.api.SceneResult;
import com.android.layoutlib.api.ViewInfo;
import com.android.layoutlib.bridge.impl.LayoutSceneImpl;
import com.android.ide.common.rendering.api.IAnimationListener;
import com.android.ide.common.rendering.api.ILayoutPullParser;
import com.android.ide.common.rendering.api.Params;
import com.android.ide.common.rendering.api.RenderSession;
import com.android.ide.common.rendering.api.Result;
import com.android.ide.common.rendering.api.ViewInfo;
import com.android.layoutlib.bridge.impl.RenderSessionImpl;

import android.view.View;
import android.view.ViewGroup;
@@ -30,47 +31,47 @@ import java.awt.image.BufferedImage;
import java.util.Map;

/**
 * An implementation of {@link LayoutScene}.
 * An implementation of {@link RenderSession}.
 *
 * This is a pretty basic class that does almost nothing. All of the work is done in
 * {@link LayoutSceneImpl}.
 * {@link RenderSessionImpl}.
 *
 */
public class BridgeLayoutScene extends LayoutScene {
public class BridgeRenderSession extends RenderSession {

    private final LayoutSceneImpl mScene;
    private SceneResult mLastResult;
    private final RenderSessionImpl mSession;
    private Result mLastResult;

    @Override
    public SceneResult getResult() {
    public Result getResult() {
        return mLastResult;
    }

    @Override
    public BufferedImage getImage() {
        return mScene.getImage();
        return mSession.getImage();
    }

    @Override
    public ViewInfo getRootView() {
        return mScene.getViewInfo();
        return mSession.getViewInfo();
    }

    @Override
    public Map<String, String> getDefaultViewPropertyValues(Object viewObject) {
        return mScene.getDefaultViewPropertyValues(viewObject);
    public Map<String, String> getDefaultProperties(Object viewObject) {
        return mSession.getDefaultProperties(viewObject);
    }

    @Override
    public SceneResult render(long timeout) {
    public Result render(long timeout) {
        try {
            Bridge.prepareThread();
            mLastResult = mScene.acquire(timeout);
            mLastResult = mSession.acquire(timeout);
            if (mLastResult.isSuccess()) {
                mLastResult = mScene.render();
                mLastResult = mSession.render();
            }
        } finally {
            mScene.release();
            mSession.release();
            Bridge.cleanupThread();
        }

@@ -78,17 +79,17 @@ public class BridgeLayoutScene extends LayoutScene {
    }

    @Override
    public SceneResult animate(Object targetObject, String animationName,
    public Result animate(Object targetObject, String animationName,
            boolean isFrameworkAnimation, IAnimationListener listener) {
        try {
            Bridge.prepareThread();
            mLastResult = mScene.acquire(SceneParams.DEFAULT_TIMEOUT);
            mLastResult = mSession.acquire(Params.DEFAULT_TIMEOUT);
            if (mLastResult.isSuccess()) {
                mLastResult = mScene.animate(targetObject, animationName, isFrameworkAnimation,
                mLastResult = mSession.animate(targetObject, animationName, isFrameworkAnimation,
                        listener);
            }
        } finally {
            mScene.release();
            mSession.release();
            Bridge.cleanupThread();
        }

@@ -96,7 +97,7 @@ public class BridgeLayoutScene extends LayoutScene {
    }

    @Override
    public SceneResult insertChild(Object parentView, IXmlPullParser childXml, int index,
    public Result insertChild(Object parentView, ILayoutPullParser childXml, int index,
            IAnimationListener listener) {
        if (parentView instanceof ViewGroup == false) {
            throw new IllegalArgumentException("parentView is not a ViewGroup");
@@ -104,12 +105,12 @@ public class BridgeLayoutScene extends LayoutScene {

        try {
            Bridge.prepareThread();
            mLastResult = mScene.acquire(SceneParams.DEFAULT_TIMEOUT);
            mLastResult = mSession.acquire(Params.DEFAULT_TIMEOUT);
            if (mLastResult.isSuccess()) {
                mLastResult = mScene.insertChild((ViewGroup) parentView, childXml, index, listener);
                mLastResult = mSession.insertChild((ViewGroup) parentView, childXml, index, listener);
            }
        } finally {
            mScene.release();
            mSession.release();
            Bridge.cleanupThread();
        }

@@ -118,7 +119,7 @@ public class BridgeLayoutScene extends LayoutScene {


    @Override
    public SceneResult moveChild(Object parentView, Object childView, int index,
    public Result moveChild(Object parentView, Object childView, int index,
            Map<String, String> layoutParams, IAnimationListener listener) {
        if (parentView instanceof ViewGroup == false) {
            throw new IllegalArgumentException("parentView is not a ViewGroup");
@@ -129,13 +130,13 @@ public class BridgeLayoutScene extends LayoutScene {

        try {
            Bridge.prepareThread();
            mLastResult = mScene.acquire(SceneParams.DEFAULT_TIMEOUT);
            mLastResult = mSession.acquire(Params.DEFAULT_TIMEOUT);
            if (mLastResult.isSuccess()) {
                mLastResult = mScene.moveChild((ViewGroup) parentView, (View) childView, index,
                mLastResult = mSession.moveChild((ViewGroup) parentView, (View) childView, index,
                        layoutParams, listener);
            }
        } finally {
            mScene.release();
            mSession.release();
            Bridge.cleanupThread();
        }

@@ -143,19 +144,19 @@ public class BridgeLayoutScene extends LayoutScene {
    }

    @Override
    public SceneResult removeChild(Object childView, IAnimationListener listener) {
    public Result removeChild(Object childView, IAnimationListener listener) {
        if (childView instanceof View == false) {
            throw new IllegalArgumentException("childView is not a View");
        }

        try {
            Bridge.prepareThread();
            mLastResult = mScene.acquire(SceneParams.DEFAULT_TIMEOUT);
            mLastResult = mSession.acquire(Params.DEFAULT_TIMEOUT);
            if (mLastResult.isSuccess()) {
                mLastResult = mScene.removeChild((View) childView, listener);
                mLastResult = mSession.removeChild((View) childView, listener);
            }
        } finally {
            mScene.release();
            mSession.release();
            Bridge.cleanupThread();
        }

@@ -166,9 +167,9 @@ public class BridgeLayoutScene extends LayoutScene {
    public void dispose() {
    }

    /*package*/ BridgeLayoutScene(LayoutSceneImpl scene, SceneResult lastResult) {
        mScene = scene;
        mScene.setScene(this);
    /*package*/ BridgeRenderSession(RenderSessionImpl scene, Result lastResult) {
        mSession = scene;
        mSession.setScene(this);
        mLastResult = lastResult;
    }
}
Loading