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

Commit 5b44aece authored by Xavier Ducrohet's avatar Xavier Ducrohet Committed by Android (Google) Code Review
Browse files

Merge "LayoutLib: Fix logging."

parents d752b66a 168677c9
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.graphics;

import com.android.layoutlib.api.IDensityBasedResourceValue.Density;
import com.android.layoutlib.bridge.Bridge;

import android.content.res.AssetManager;
import android.content.res.Resources;
@@ -448,7 +449,9 @@ public class BitmapFactory {
        Bitmap  bm;

        if (is instanceof AssetManager.AssetInputStream) {
            // FIXME: log this.
            Bridge.getLog().error(null,
                    "Bitmap.decodeStream: " +
                    "InputStream is unsupported (AssetManager.AssetInputStream)");
            return null;
        } else {
            // pass some temp storage down to the native code. 1024 is made up,
+14 −22
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@

package android.graphics;

import com.android.layoutlib.api.ILayoutLog;
import com.android.layoutlib.bridge.Bridge;
import com.android.layoutlib.bridge.impl.DelegateManager;
import com.android.layoutlib.bridge.impl.Stack;

@@ -59,7 +59,6 @@ public class Canvas_Delegate {
    // ---- delegate data ----
    private BufferedImage mBufferedImage;
    private final Stack<Graphics2D> mGraphicsStack = new Stack<Graphics2D>();
    private ILayoutLog mLogger;

    // ---- Public Helper methods ----

@@ -77,14 +76,6 @@ public class Canvas_Delegate {
        return sManager.getDelegate(native_canvas);
    }

    /**
     * Sets the layoutlib logger into the canvas.
     * @param logger
     */
    public void setLogger(ILayoutLog logger) {
        mLogger = logger;
    }

    /**
     * Returns the current {@link Graphics2D} used to draw.
     */
@@ -408,10 +399,11 @@ public class Canvas_Delegate {
        // give it to the graphics2D as a new matrix replacing all previous transform
        g.setTransform(matrixTx);

        // FIXME: log
//        if (mLogger != null && matrixDelegate.hasPerspective()) {
//            mLogger.warning("android.graphics.Canvas#setMatrix(android.graphics.Matrix) only supports affine transformations in the Layout Editor.");
//        }
        if (matrixDelegate.hasPerspective()) {
            Bridge.getLog().warning(null,
                    "android.graphics.Canvas#setMatrix(android.graphics.Matrix) only " +
                    "supports affine transformations in the Layout Preview.");
        }
    }

    /*package*/ static boolean native_clipRect(int nCanvas,
@@ -1042,13 +1034,12 @@ public class Canvas_Delegate {
                g.setPaint(shaderPaint);
                useColorPaint = false;
            } else {
                if (mLogger != null) {
                    mLogger.warning(String.format(
                            "Shader '%1$s' is not supported in the Layout Editor.",
                Bridge.getLog().warning(null,
                        String.format(
                            "Shader '%1$s' is not supported in the Layout Preview.",
                            shaderDelegate.getClass().getCanonicalName()));
            }
        }
        }

        if (useColorPaint) {
            g.setColor(new Color(paint.getColor(), true /*hasAlpha*/));
@@ -1089,9 +1080,10 @@ public class Canvas_Delegate {
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER));

            // if xfermode wasn't null, then it's something we don't support. log it.
            if (mLogger != null && xfermodeDelegate != null) {
                mLogger.warning(String.format(
                        "Xfermode '%1$s' is not supported in the Layout Editor.",
            if (xfermodeDelegate != null) {
                Bridge.getLog().warning(null,
                        String.format(
                            "Xfermode '%1$s' is not supported in the Layout Preview.",
                            xfermodeDelegate.getClass().getCanonicalName()));
            }
        }
+4 −3
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.graphics;

import com.android.layoutlib.bridge.Bridge;
import com.android.layoutlib.bridge.impl.DelegateManager;
import com.android.ninepatch.NinePatchChunk;

@@ -71,7 +72,7 @@ public class NinePatch_Delegate {
            oos = new ObjectOutputStream(baos);
            oos.writeObject(chunk);
        } catch (IOException e) {
            //FIXME log this.
            Bridge.getLog().error("Failed to serialize NinePatchChunk.", e);
            return null;
        } finally {
            if (oos != null) {
@@ -205,10 +206,10 @@ public class NinePatch_Delegate {
                    sChunkCache.put(array, new SoftReference<NinePatchChunk>(chunk));
                }
            } catch (IOException e) {
                // FIXME: log this
                Bridge.getLog().error("Failed to deserialize NinePatchChunk content.", e);
                return null;
            } catch (ClassNotFoundException e) {
                // FIXME: log this
                Bridge.getLog().error("Failed to deserialize NinePatchChunk class.", e);
                return null;
            } finally {
                if (ois != null) {
+40 −10
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@
package com.android.layoutlib.bridge;

import com.android.layoutlib.api.Capabilities;
import com.android.layoutlib.api.ILayoutLog;
import com.android.layoutlib.api.LayoutLog;
import com.android.layoutlib.api.IProjectCallback;
import com.android.layoutlib.api.IResourceValue;
import com.android.layoutlib.api.IXmlPullParser;
@@ -133,14 +133,16 @@ public final class Bridge extends LayoutBridge {
    private final static IntArray sIntArrayWrapper = new IntArray();

    /**
     * A default logger than prints to stdout/stderr.
     * A default log than prints to stdout/stderr.
     */
    private final static ILayoutLog sDefaultLogger = new ILayoutLog() {
        public void error(String message) {
    private final static LayoutLog sDefaultLog = new LayoutLog() {
        @Override
        public void error(String tag, String message) {
            System.err.println(message);
        }

        public void error(Throwable t) {
        @Override
        public void error(String tag, Throwable t) {
            String message = t.getMessage();
            if (message == null) {
                message = t.getClass().getName();
@@ -149,11 +151,23 @@ public final class Bridge extends LayoutBridge {
            System.err.println(message);
        }

        public void warning(String message) {
        @Override
        public void error(String tag, String message, Throwable throwable) {
            System.err.println(message);
        }

        @Override
        public void warning(String tag, String message) {
            System.out.println(message);
        }
    };

    /**
     * Current log.
     */
    private static LayoutLog sCurrentLog = sDefaultLog;


    private EnumSet<Capabilities> mCapabilities;


@@ -203,7 +217,7 @@ public final class Bridge extends LayoutBridge {
            OverrideMethod.setDefaultListener(new MethodAdapter() {
                @Override
                public void onInvokeV(String signature, boolean isNative, Object caller) {
                    sDefaultLogger.error("Missing Stub: " + signature +
                    sDefaultLog.error(null, "Missing Stub: " + signature +
                            (isNative ? " (native)" : ""));

                    if (debug.equalsIgnoreCase("throw")) {
@@ -311,7 +325,7 @@ public final class Bridge extends LayoutBridge {
    @Override
    public BridgeLayoutScene createScene(SceneParams params) {
        try {
            SceneResult lastResult = SceneStatus.SUCCESS.getResult();
            SceneResult lastResult = SceneStatus.SUCCESS.createResult();
            LayoutSceneImpl scene = new LayoutSceneImpl(params);
            try {
                prepareThread();
@@ -335,7 +349,7 @@ public final class Bridge extends LayoutBridge {
                t2 = t.getCause();
            }
            return new BridgeLayoutScene(null,
                    SceneStatus.ERROR_UNKNOWN.getResult(t2.getMessage(), t2));
                    SceneStatus.ERROR_UNKNOWN.createResult(t2.getMessage(), t2));
        }
    }

@@ -383,6 +397,23 @@ public final class Bridge extends LayoutBridge {
        Looper.sThreadLocal.remove();
    }

    public static LayoutLog getLog() {
        return sCurrentLog;
    }

    public static void setLog(LayoutLog log) {
        // check only the thread currently owning the lock can do this.
        if (sLock.isHeldByCurrentThread() == false) {
            throw new IllegalStateException("scene must be acquired first. see #acquire(long)");
        }

        if (log != null) {
            sCurrentLog = log;
        } else {
            sCurrentLog = sDefaultLog;
        }
    }

    /**
     * Returns details of a framework resource from its integer value.
     * @param value the integer value
@@ -391,7 +422,6 @@ public final class Bridge extends LayoutBridge {
     */
    public static String[] resolveResourceValue(int value) {
        return sRMap.get(value);

    }

    /**
+2 −9
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

package com.android.layoutlib.bridge.android;

import com.android.layoutlib.api.ILayoutLog;
import com.android.layoutlib.api.IProjectCallback;
import com.android.layoutlib.api.IResourceValue;
import com.android.layoutlib.api.IStyleResourceValue;
@@ -97,7 +96,6 @@ public final class BridgeContext extends Activity {
    private BridgeInflater mInflater;

    private final IProjectCallback mProjectCallback;
    private final ILayoutLog mLogger;
    private BridgeContentResolver mContentResolver;

    private final Stack<BridgeXmlBlockParser> mParserStack = new Stack<BridgeXmlBlockParser>();
@@ -122,11 +120,10 @@ public final class BridgeContext extends Activity {
            Map<String, Map<String, IResourceValue>> projectResources,
            Map<String, Map<String, IResourceValue>> frameworkResources,
            Map<IStyleResourceValue, IStyleResourceValue> styleInheritanceMap,
            IProjectCallback projectCallback, ILayoutLog logger) {
            IProjectCallback projectCallback) {
        mProjectKey = projectKey;
        mMetrics = metrics;
        mProjectCallback = projectCallback;
        mLogger = logger;

        mThemeValues = currentTheme;
        mProjectResources = projectResources;
@@ -183,10 +180,6 @@ public final class BridgeContext extends Activity {
        return mProjectCallback;
    }

    public ILayoutLog getLogger() {
        return mLogger;
    }

    public Map<String, String> getDefaultPropMap(Object key) {
        return mDefaultPropMaps.get(key);
    }
@@ -340,7 +333,7 @@ public final class BridgeContext extends Activity {
            // good, nothing to do.
        } else if (set != null) { // null parser is ok
            // really this should not be happening since its instantiated in Bridge
            mLogger.error("Parser is not a BridgeXmlBlockParser!");
            Bridge.getLog().error(null, "Parser is not a BridgeXmlBlockParser!");
            return null;
        }

Loading