Merge "LayoutLib: use tags in logs." into honeycomb

This commit is contained in:
Xavier Ducrohet
2011-01-12 18:23:04 -08:00
committed by Android (Google) Code Review
24 changed files with 165 additions and 101 deletions

View File

@@ -18,6 +18,7 @@ package android.graphics;
import com.android.ide.common.rendering.api.ResourceDensity;
import com.android.layoutlib.bridge.Bridge;
import com.android.layoutlib.bridge.BridgeConstants;
import android.content.res.AssetManager;
import android.content.res.Resources;
@@ -351,7 +352,7 @@ public class BitmapFactory {
If the exception happened on open, bm will be null.
If it happened on close, bm is still valid.
*/
Bridge.getLog().error(null,
Bridge.getLog().error(BridgeConstants.TAG_RESOURCES_READ,
String.format("Error decoding bitmap of id 0x%x", id), e);
} finally {
try {
@@ -451,7 +452,7 @@ public class BitmapFactory {
Bitmap bm;
if (is instanceof AssetManager.AssetInputStream) {
Bridge.getLog().error(null,
Bridge.getLog().error(BridgeConstants.TAG_UNSUPPORTED,
"Bitmap.decodeStream: " +
"InputStream is unsupported (AssetManager.AssetInputStream)");
return null;

View File

@@ -17,6 +17,7 @@
package android.graphics;
import com.android.layoutlib.bridge.Bridge;
import com.android.layoutlib.bridge.BridgeConstants;
import com.android.layoutlib.bridge.impl.DelegateManager;
import android.graphics.Shader.TileMode;
@@ -112,7 +113,8 @@ public class BitmapShader_Delegate extends Shader_Delegate {
try {
canvasMatrix = xform.createInverse();
} catch (java.awt.geom.NoninvertibleTransformException e) {
Bridge.getLog().error(null, "Unable to inverse matrix in BitmapShader", e);
Bridge.getLog().fidelityWarning(BridgeConstants.TAG_MATRIX,
"Unable to inverse matrix in BitmapShader", e);
canvasMatrix = new java.awt.geom.AffineTransform();
}
@@ -120,7 +122,8 @@ public class BitmapShader_Delegate extends Shader_Delegate {
try {
localMatrix = localMatrix.createInverse();
} catch (java.awt.geom.NoninvertibleTransformException e) {
Bridge.getLog().error(null, "Unable to inverse matrix in BitmapShader", e);
Bridge.getLog().fidelityWarning(BridgeConstants.TAG_MATRIX,
"Unable to inverse matrix in BitmapShader", e);
localMatrix = new java.awt.geom.AffineTransform();
}

View File

@@ -18,6 +18,7 @@ package android.graphics;
import com.android.ide.common.rendering.api.ResourceDensity;
import com.android.layoutlib.bridge.Bridge;
import com.android.layoutlib.bridge.BridgeConstants;
import com.android.layoutlib.bridge.impl.DelegateManager;
import android.graphics.Bitmap.Config;
@@ -248,7 +249,8 @@ public final class Bitmap_Delegate {
/*package*/ static boolean nativeCompress(int nativeBitmap, int format, int quality,
OutputStream stream, byte[] tempStorage) {
Bridge.getLog().error(null, "Bitmap.compress() is not supported");
Bridge.getLog().error(BridgeConstants.TAG_UNSUPPORTED,
"Bitmap.compress() is not supported");
return true;
}
@@ -383,7 +385,7 @@ public final class Bitmap_Delegate {
/*package*/ static Bitmap nativeCreateFromParcel(Parcel p) {
// This is only called by Bitmap.CREATOR (Parcelable.Creator<Bitmap>), which is only
// used during aidl call so really this should not be called.
Bridge.getLog().error(null,
Bridge.getLog().error(BridgeConstants.TAG_UNSUPPORTED,
"AIDL is not suppored, and therefore Bitmaps cannot be created from parcels.");
return null;
}
@@ -392,7 +394,7 @@ public final class Bitmap_Delegate {
int density, Parcel p) {
// This is only called when sending a bitmap through aidl, so really this should not
// be called.
Bridge.getLog().error(null,
Bridge.getLog().error(BridgeConstants.TAG_UNSUPPORTED,
"AIDL is not suppored, and therefore Bitmaps cannot be written to parcels.");
return false;
}
@@ -408,7 +410,7 @@ public final class Bitmap_Delegate {
Paint_Delegate paint = Paint_Delegate.getDelegate(nativePaint);
if (paint != null && paint.getMaskFilter() != null) {
Bridge.getLog().fidelityWarning(null,
Bridge.getLog().fidelityWarning(BridgeConstants.TAG_MASKFILTER,
"MaskFilter not supported in Bitmap.extractAlpha",
null);
}

View File

@@ -17,6 +17,7 @@
package android.graphics;
import com.android.layoutlib.bridge.Bridge;
import com.android.layoutlib.bridge.BridgeConstants;
import com.android.layoutlib.bridge.impl.DelegateManager;
import com.android.layoutlib.bridge.impl.GcSnapshot;
@@ -422,7 +423,7 @@ public final class Canvas_Delegate {
if (matrixDelegate.hasPerspective()) {
assert false;
Bridge.getLog().fidelityWarning(null,
Bridge.getLog().fidelityWarning(BridgeConstants.TAG_MATRIX,
"android.graphics.Canvas#setMatrix(android.graphics.Matrix) only " +
"supports affine transformations.", null);
}
@@ -492,7 +493,8 @@ public final class Canvas_Delegate {
}
if (filterDelegate.isSupported() == false) {
Bridge.getLog().fidelityWarning(null, filterDelegate.getSupportMessage(), null);
Bridge.getLog().fidelityWarning(BridgeConstants.TAG_DRAWFILTER,
filterDelegate.getSupportMessage(), null);
}
}

View File

@@ -17,6 +17,7 @@
package android.graphics;
import com.android.layoutlib.bridge.Bridge;
import com.android.layoutlib.bridge.BridgeConstants;
import com.android.layoutlib.bridge.impl.DelegateManager;
import android.graphics.Shader.TileMode;
@@ -135,7 +136,8 @@ public final class LinearGradient_Delegate extends Gradient_Delegate {
try {
canvasMatrix = xform.createInverse();
} catch (java.awt.geom.NoninvertibleTransformException e) {
Bridge.getLog().error(null, "Unable to inverse matrix in LinearGradient", e);
Bridge.getLog().fidelityWarning(BridgeConstants.TAG_MATRIX,
"Unable to inverse matrix in LinearGradient", e);
canvasMatrix = new java.awt.geom.AffineTransform();
}
@@ -143,7 +145,8 @@ public final class LinearGradient_Delegate extends Gradient_Delegate {
try {
localMatrix = localMatrix.createInverse();
} catch (java.awt.geom.NoninvertibleTransformException e) {
Bridge.getLog().error(null, "Unable to inverse matrix in LinearGradient", e);
Bridge.getLog().fidelityWarning(BridgeConstants.TAG_MATRIX,
"Unable to inverse matrix in LinearGradient", e);
localMatrix = new java.awt.geom.AffineTransform();
}

View File

@@ -18,6 +18,7 @@ package android.graphics;
import com.android.layoutlib.bridge.Bridge;
import com.android.layoutlib.bridge.BridgeConstants;
import com.android.layoutlib.bridge.impl.DelegateManager;
import android.graphics.Matrix.ScaleToFit;
@@ -612,7 +613,7 @@ public final class Matrix_Delegate {
/*package*/ static boolean native_setPolyToPoly(int native_object, float[] src, int srcIndex,
float[] dst, int dstIndex, int pointCount) {
// FIXME
Bridge.getLog().fidelityWarning(null,
Bridge.getLog().fidelityWarning(BridgeConstants.TAG_UNSUPPORTED,
"Matrix.setPolyToPoly is not supported.",
null);
return false;

View File

@@ -17,6 +17,7 @@
package android.graphics;
import com.android.layoutlib.bridge.Bridge;
import com.android.layoutlib.bridge.BridgeConstants;
import com.android.layoutlib.bridge.impl.DelegateManager;
import com.android.layoutlib.bridge.impl.GcSnapshot;
import com.android.ninepatch.NinePatchChunk;
@@ -196,10 +197,12 @@ public final class NinePatch_Delegate {
sChunkCache.put(array, new SoftReference<NinePatchChunk>(chunk));
}
} catch (IOException e) {
Bridge.getLog().error(null, "Failed to deserialize NinePatchChunk content.", e);
Bridge.getLog().error(BridgeConstants.TAG_BROKEN,
"Failed to deserialize NinePatchChunk content.", e);
return null;
} catch (ClassNotFoundException e) {
Bridge.getLog().error(null, "Failed to deserialize NinePatchChunk class.", e);
Bridge.getLog().error(BridgeConstants.TAG_BROKEN,
"Failed to deserialize NinePatchChunk class.", e);
return null;
} finally {
if (ois != null) {

View File

@@ -17,6 +17,7 @@
package android.graphics;
import com.android.layoutlib.bridge.Bridge;
import com.android.layoutlib.bridge.BridgeConstants;
import com.android.layoutlib.bridge.impl.DelegateManager;
import android.graphics.Paint.FontMetrics;
@@ -179,7 +180,7 @@ public class Paint_Delegate {
return stroke;
}
} else {
Bridge.getLog().fidelityWarning(null,
Bridge.getLog().fidelityWarning(BridgeConstants.TAG_PATHEFFECT,
effectDelegate.getSupportMessage(),
null);
}
@@ -375,7 +376,8 @@ public class Paint_Delegate {
/*package*/ static void nSetShadowLayer(Paint thisPaint, float radius, float dx, float dy,
int color) {
// FIXME
Bridge.getLog().fidelityWarning(null, "Paint.setShadowLayer is not supported.", null);
Bridge.getLog().fidelityWarning(BridgeConstants.TAG_UNSUPPORTED,
"Paint.setShadowLayer is not supported.", null);
}
/*package*/ static float getTextSize(Paint thisPaint) {
@@ -691,7 +693,8 @@ public class Paint_Delegate {
// since none of those are supported, display a fidelity warning right away
ColorFilter_Delegate filterDelegate = delegate.getColorFilter();
if (filterDelegate != null && filterDelegate.isSupported() == false) {
Bridge.getLog().fidelityWarning(null, filterDelegate.getSupportMessage(), null);
Bridge.getLog().fidelityWarning(BridgeConstants.TAG_COLORFILTER,
filterDelegate.getSupportMessage(), null);
}
return filter;
@@ -729,7 +732,8 @@ public class Paint_Delegate {
// since none of those are supported, display a fidelity warning right away
MaskFilter_Delegate filterDelegate = delegate.getMaskFilter();
if (filterDelegate != null && filterDelegate.isSupported() == false) {
Bridge.getLog().fidelityWarning(null, filterDelegate.getSupportMessage(), null);
Bridge.getLog().fidelityWarning(BridgeConstants.TAG_MASKFILTER,
filterDelegate.getSupportMessage(), null);
}
return maskfilter;
@@ -759,7 +763,8 @@ public class Paint_Delegate {
// since none of those are supported, display a fidelity warning right away
Rasterizer_Delegate rasterizerDelegate = delegate.getRasterizer();
if (rasterizerDelegate != null && rasterizerDelegate.isSupported() == false) {
Bridge.getLog().fidelityWarning(null, rasterizerDelegate.getSupportMessage(), null);
Bridge.getLog().fidelityWarning(BridgeConstants.TAG_RASTERIZER,
rasterizerDelegate.getSupportMessage(), null);
}
return rasterizer;

View File

@@ -17,6 +17,7 @@
package android.graphics;
import com.android.layoutlib.bridge.Bridge;
import com.android.layoutlib.bridge.BridgeConstants;
import com.android.layoutlib.bridge.impl.DelegateManager;
import android.graphics.Path.Direction;
@@ -695,7 +696,7 @@ public final class Path_Delegate {
public void transform(Matrix_Delegate matrix, Path_Delegate dst) {
if (matrix.hasPerspective()) {
assert false;
Bridge.getLog().fidelityWarning(null,
Bridge.getLog().fidelityWarning(BridgeConstants.TAG_MATRIX,
"android.graphics.Path#transform() only " +
"supports affine transformations.", null);
}

View File

@@ -17,6 +17,7 @@
package android.graphics;
import com.android.layoutlib.bridge.Bridge;
import com.android.layoutlib.bridge.BridgeConstants;
import com.android.layoutlib.bridge.impl.DelegateManager;
import java.awt.AlphaComposite;
@@ -72,7 +73,8 @@ public class PorterDuffXfermode_Delegate extends Xfermode_Delegate {
}
}
Bridge.getLog().error(null, String.format("Unknown PorterDuff.Mode: %d", mode));
Bridge.getLog().error(BridgeConstants.TAG_BROKEN,
String.format("Unknown PorterDuff.Mode: %d", mode));
assert false;
return PorterDuff.Mode.SRC_OVER;
}
@@ -114,7 +116,7 @@ public class PorterDuffXfermode_Delegate extends Xfermode_Delegate {
return AlphaComposite.getInstance(AlphaComposite.XOR, falpha);
}
Bridge.getLog().fidelityWarning(null,
Bridge.getLog().fidelityWarning(BridgeConstants.TAG_BROKEN,
String.format("Unsupported PorterDuff Mode: %s", mode.name()),
null);

View File

@@ -17,6 +17,7 @@
package android.graphics;
import com.android.layoutlib.bridge.Bridge;
import com.android.layoutlib.bridge.BridgeConstants;
import com.android.layoutlib.bridge.impl.DelegateManager;
import android.graphics.Shader.TileMode;
@@ -124,7 +125,8 @@ public class RadialGradient_Delegate extends Gradient_Delegate {
try {
canvasMatrix = xform.createInverse();
} catch (java.awt.geom.NoninvertibleTransformException e) {
Bridge.getLog().error(null, "Unable to inverse matrix in RadialGradient", e);
Bridge.getLog().fidelityWarning(BridgeConstants.TAG_MATRIX,
"Unable to inverse matrix in RadialGradient", e);
canvasMatrix = new java.awt.geom.AffineTransform();
}
@@ -132,7 +134,8 @@ public class RadialGradient_Delegate extends Gradient_Delegate {
try {
localMatrix = localMatrix.createInverse();
} catch (java.awt.geom.NoninvertibleTransformException e) {
Bridge.getLog().error(null, "Unable to inverse matrix in RadialGradient", e);
Bridge.getLog().fidelityWarning(BridgeConstants.TAG_MATRIX,
"Unable to inverse matrix in RadialGradient", e);
localMatrix = new java.awt.geom.AffineTransform();
}

View File

@@ -17,6 +17,7 @@
package android.graphics;
import com.android.layoutlib.bridge.Bridge;
import com.android.layoutlib.bridge.BridgeConstants;
import com.android.layoutlib.bridge.impl.DelegateManager;
import android.os.Parcel;
@@ -415,7 +416,7 @@ public class Region_Delegate {
/*package*/ static int nativeCreateFromParcel(Parcel p) {
// This is only called by Region.CREATOR (Parcelable.Creator<Region>), which is only
// used during aidl call so really this should not be called.
Bridge.getLog().error(null,
Bridge.getLog().error(BridgeConstants.TAG_UNSUPPORTED,
"AIDL is not suppored, and therefore Regions cannot be created from parcels.");
return 0;
}
@@ -424,7 +425,7 @@ public class Region_Delegate {
Parcel p) {
// This is only called when sending a region through aidl, so really this should not
// be called.
Bridge.getLog().error(null,
Bridge.getLog().error(BridgeConstants.TAG_UNSUPPORTED,
"AIDL is not suppored, and therefore Regions cannot be written to parcels.");
return false;
}

View File

@@ -17,6 +17,7 @@
package android.graphics;
import com.android.layoutlib.bridge.Bridge;
import com.android.layoutlib.bridge.BridgeConstants;
import com.android.layoutlib.bridge.impl.DelegateManager;
/**
@@ -116,7 +117,8 @@ public class SweepGradient_Delegate extends Gradient_Delegate {
try {
canvasMatrix = xform.createInverse();
} catch (java.awt.geom.NoninvertibleTransformException e) {
Bridge.getLog().error(null, "Unable to inverse matrix in SweepGradient", e);
Bridge.getLog().fidelityWarning(BridgeConstants.TAG_MATRIX,
"Unable to inverse matrix in SweepGradient", e);
canvasMatrix = new java.awt.geom.AffineTransform();
}
@@ -124,7 +126,8 @@ public class SweepGradient_Delegate extends Gradient_Delegate {
try {
localMatrix = localMatrix.createInverse();
} catch (java.awt.geom.NoninvertibleTransformException e) {
Bridge.getLog().error(null, "Unable to inverse matrix in SweepGradient", e);
Bridge.getLog().fidelityWarning(BridgeConstants.TAG_MATRIX,
"Unable to inverse matrix in SweepGradient", e);
localMatrix = new java.awt.geom.AffineTransform();
}

View File

@@ -17,6 +17,7 @@
package android.graphics;
import com.android.layoutlib.bridge.Bridge;
import com.android.layoutlib.bridge.BridgeConstants;
import com.android.layoutlib.bridge.impl.DelegateManager;
import com.android.layoutlib.bridge.impl.FontLoader;
@@ -125,12 +126,14 @@ public final class Typeface_Delegate {
}
/*package*/ static synchronized int nativeCreateFromAsset(AssetManager mgr, String path) {
Bridge.getLog().fidelityWarning(null, "Typeface.createFromAsset() is not supported.", null);
Bridge.getLog().fidelityWarning(BridgeConstants.TAG_UNSUPPORTED,
"Typeface.createFromAsset() is not supported.", null);
return 0;
}
/*package*/ static synchronized int nativeCreateFromFile(String path) {
Bridge.getLog().fidelityWarning(null, "Typeface.createFromFile() is not supported.", null);
Bridge.getLog().fidelityWarning(BridgeConstants.TAG_UNSUPPORTED,
"Typeface.createFromFile() is not supported.", null);
return 0;
}

View File

@@ -262,7 +262,7 @@ public final class Bridge extends com.android.ide.common.rendering.api.Bridge {
}
} catch (Throwable throwable) {
if (log != null) {
log.error(null,
log.error(BridgeConstants.TAG_BROKEN,
"Failed to load com.android.internal.R from the layout library jar",
throwable);
}

View File

@@ -64,4 +64,18 @@ public class BridgeConstants {
public final static String MATCH_PARENT = "match_parent";
public final static String FILL_PARENT = "fill_parent";
public final static String WRAP_CONTENT = "wrap_content";
public final static String TAG_UNSUPPORTED = "unsupported";
public static final String TAG_BROKEN = "broken";
public final static String TAG_RESOURCES_RESOLVE = "resources.resolve";
public final static String TAG_RESOURCES_READ = "resources.read";
public final static String TAG_RESOURCES_FORMAT = "resources.format";
public static final String TAG_MATRIX = "matrix";
public final static String TAG_MASKFILTER = "maskfilter";
public static final String TAG_DRAWFILTER = "drawfilter";
public static final String TAG_PATHEFFECT = "patheffect";
public static final String TAG_COLORFILTER = "colorfilter";
public static final String TAG_RASTERIZER = "rasterizer";
public static final String TAG_SHADER = "shader";
public static final String TAG_XFERMODE = "xfermode";
}

View File

@@ -336,7 +336,8 @@ public final class BridgeContext extends Activity {
isPlatformFile = false;
} else if (set != null) { // null parser is ok
// really this should not be happening since its instantiated in Bridge
Bridge.getLog().error(null, "Parser is not a BridgeXmlBlockParser!");
Bridge.getLog().error(BridgeConstants.TAG_BROKEN,
"Parser is not a BridgeXmlBlockParser!");
return null;
}
@@ -705,7 +706,7 @@ public final class BridgeContext extends Activity {
// This is normal if the resource is an ID that is generated automatically.
// For other resources, we output a warning
if ("+id".equals(resType) == false && "+android:id".equals(resType) == false) { //$NON-NLS-1$ //$NON-NLS-2$
Bridge.getLog().warning("resources", //$NON-NLS-1$
Bridge.getLog().warning(BridgeConstants.TAG_RESOURCES_RESOLVE,
"Couldn't resolve resource @" +
(frameworkOnly ? "android:" : "") + resType + "/" + resName);
}

View File

@@ -178,7 +178,7 @@ public final class BridgeInflater extends LayoutInflater {
return inflate(bridgeParser, root);
} catch (Exception e) {
Bridge.getLog().error(null,
Bridge.getLog().error(BridgeConstants.TAG_RESOURCES_READ,
"Failed to parse file " + f.getAbsolutePath(), e);
return null;

View File

@@ -142,6 +142,7 @@ public final class BridgeResources extends Resources {
try {
return ResourceHelper.getColor(value.getValue());
} catch (NumberFormatException e) {
Bridge.getLog().error(BridgeConstants.TAG_RESOURCES_FORMAT, e.getMessage(), e);
return 0;
}
}
@@ -172,10 +173,15 @@ public final class BridgeResources extends Resources {
return ColorStateList.createFromXml(this,
new BridgeXmlBlockParser(parser, mContext, resValue.isFramework()));
} catch (XmlPullParserException e) {
Bridge.getLog().error(BridgeConstants.TAG_BROKEN,
"Failed to configure parser for " + value, e);
// we'll return null below.
} catch (Exception e) {
// this is an error and not warning since the file existence is checked before
// attempting to parse it.
Bridge.getLog().error(null, "Failed to parse file " + value, e);
Bridge.getLog().error(BridgeConstants.TAG_RESOURCES_READ,
"Failed to parse file " + value, e);
return null;
}
@@ -185,6 +191,8 @@ public final class BridgeResources extends Resources {
int color = ResourceHelper.getColor(value);
return ColorStateList.valueOf(color);
} catch (NumberFormatException e) {
Bridge.getLog().error(BridgeConstants.TAG_RESOURCES_FORMAT,
"Failed to convert " + value + " into a ColorStateList", e);
return null;
}
}
@@ -243,7 +251,7 @@ public final class BridgeResources extends Resources {
return new BridgeXmlBlockParser(parser, mContext, mPlatformResourceFlag[0]);
}
} catch (XmlPullParserException e) {
Bridge.getLog().error(null,
Bridge.getLog().error(BridgeConstants.TAG_BROKEN,
"Failed to configure parser for " + value.getValue(), e);
// we'll return null below.
} catch (FileNotFoundException e) {
@@ -278,7 +286,7 @@ public final class BridgeResources extends Resources {
return new BridgeXmlBlockParser(parser, mContext, mPlatformResourceFlag[0]);
}
} catch (XmlPullParserException e) {
Bridge.getLog().error(null,
Bridge.getLog().error(BridgeConstants.TAG_BROKEN,
"Failed to configure parser for " + value.getValue(), e);
// we'll return null below.
} catch (FileNotFoundException e) {

View File

@@ -25,6 +25,7 @@ import com.android.layoutlib.bridge.impl.ResourceHelper;
import org.kxml2.io.KXmlParser;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import android.content.res.ColorStateList;
import android.content.res.Resources;
@@ -205,9 +206,10 @@ public final class BridgeTypedArray extends TypedArray {
if (i != null) {
result |= i.intValue();
} else {
Bridge.getLog().warning(null, String.format(
"Unknown constant \"%s\" in attribute \"%2$s\"",
keyword, mNames[index]));
Bridge.getLog().warning(BridgeConstants.TAG_RESOURCES_RESOLVE,
String.format(
"Unknown constant \"%s\" in attribute \"%2$s\"",
keyword, mNames[index]));
}
}
return result;
@@ -235,9 +237,10 @@ public final class BridgeTypedArray extends TypedArray {
try {
return Float.parseFloat(s);
} catch (NumberFormatException e) {
Bridge.getLog().warning(null, String.format(
"Unable to convert \"%s\" into a float in attribute \"%2$s\"",
s, mNames[index]));
Bridge.getLog().warning(BridgeConstants.TAG_RESOURCES_RESOLVE,
String.format(
"Unable to convert \"%s\" into a float in attribute \"%2$s\"",
s, mNames[index]));
// we'll return the default value below.
}
@@ -267,9 +270,7 @@ public final class BridgeTypedArray extends TypedArray {
try {
return ResourceHelper.getColor(s);
} catch (NumberFormatException e) {
Bridge.getLog().warning(null, String.format(
"Unable to convert \"%s\" into a color in attribute \"%2$s\"",
s, mNames[index]));
Bridge.getLog().error(BridgeConstants.TAG_RESOURCES_FORMAT, e.getMessage(), e);
// we'll return the default value below.
}
@@ -298,17 +299,10 @@ public final class BridgeTypedArray extends TypedArray {
return null;
}
try {
int color = ResourceHelper.getColor(value);
return ColorStateList.valueOf(color);
} catch (NumberFormatException e) {
// if it's not a color value, we'll attempt to read the xml based color below.
}
// let the framework inflate the ColorStateList from the XML file.
try {
File f = new File(value);
if (f.isFile()) {
File f = new File(value);
if (f.isFile()) {
try {
KXmlParser parser = new KXmlParser();
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
parser.setInput(new FileReader(f));
@@ -318,19 +312,26 @@ public final class BridgeTypedArray extends TypedArray {
// FIXME: we need to know if this resource is platform or not
new BridgeXmlBlockParser(parser, mContext, false));
return colorStateList;
}
} catch (Exception e) {
// this is an error and not warning since the file existence is checked before
// attempting to parse it.
Bridge.getLog().error(null, "Failed to parse file " + value, e);
} catch (XmlPullParserException e) {
Bridge.getLog().error(BridgeConstants.TAG_BROKEN,
"Failed to configure parser for " + value, e);
return null;
} catch (Exception e) {
// this is an error and not warning since the file existence is checked before
// attempting to parse it.
Bridge.getLog().error(BridgeConstants.TAG_RESOURCES_READ,
"Failed to parse file " + value, e);
return null;
return null;
}
}
// looks like were unable to resolve the color value.
Bridge.getLog().warning(null, String.format(
"Unable to resolve color value \"%1$s\" in attribute \"%2$s\"",
value, mNames[index]));
try {
int color = ResourceHelper.getColor(value);
return ColorStateList.valueOf(color);
} catch (NumberFormatException e) {
Bridge.getLog().error(BridgeConstants.TAG_RESOURCES_FORMAT, e.getMessage(), e);
}
assert false;
@@ -358,9 +359,10 @@ public final class BridgeTypedArray extends TypedArray {
try {
return Integer.parseInt(s);
} catch (NumberFormatException e) {
Bridge.getLog().warning(null, String.format(
"Unable to convert \"%s\" into a integer in attribute \"%2$s\"",
s, mNames[index]));
Bridge.getLog().warning(BridgeConstants.TAG_RESOURCES_RESOLVE,
String.format(
"Unable to convert \"%s\" into a integer in attribute \"%2$s\"",
s, mNames[index]));
// The default value is returned below.
}
@@ -407,9 +409,10 @@ public final class BridgeTypedArray extends TypedArray {
}
// looks like we were unable to resolve the dimension value
Bridge.getLog().warning(null, String.format(
"Unable to resolve dimension value \"%1$s\" in attribute \"%2$s\"",
s, mNames[index]));
Bridge.getLog().warning(BridgeConstants.TAG_RESOURCES_RESOLVE,
String.format(
"Unable to resolve dimension value \"%1$s\" in attribute \"%2$s\"",
s, mNames[index]));
assert false;
@@ -538,9 +541,10 @@ public final class BridgeTypedArray extends TypedArray {
}
// looks like we were unable to resolve the fraction value
Bridge.getLog().warning(null, String.format(
"Unable to resolve fraction value \"%1$s\" in attribute \"%2$s\"",
value, mNames[index]));
Bridge.getLog().warning(BridgeConstants.TAG_RESOURCES_RESOLVE,
String.format(
"Unable to resolve fraction value \"%1$s\" in attribute \"%2$s\"",
value, mNames[index]));
assert false;
@@ -649,8 +653,9 @@ public final class BridgeTypedArray extends TypedArray {
return idValue.intValue();
}
Bridge.getLog().warning(null, String.format(
"Unable to resolve id \"%1$s\" for attribute \"%2$s\"", value, mNames[index]));
Bridge.getLog().warning(BridgeConstants.TAG_RESOURCES_RESOLVE,
String.format(
"Unable to resolve id \"%1$s\" for attribute \"%2$s\"", value, mNames[index]));
assert false;
@@ -686,9 +691,10 @@ public final class BridgeTypedArray extends TypedArray {
}
// looks like we were unable to resolve the drawable
Bridge.getLog().warning(null, String.format(
"Unable to resolve drawable \"%1$s\" in attribute \"%2$s\"", stringValue,
mNames[index]));
Bridge.getLog().warning(BridgeConstants.TAG_RESOURCES_RESOLVE,
String.format(
"Unable to resolve drawable \"%1$s\" in attribute \"%2$s\"", stringValue,
mNames[index]));
assert false;
@@ -717,9 +723,10 @@ public final class BridgeTypedArray extends TypedArray {
return new CharSequence[] { value };
}
Bridge.getLog().warning(null, String.format(
String.format("Unknown value for getTextArray(%d) => %s", //DEBUG
index, mResourceData[index].getName())));
Bridge.getLog().warning(BridgeConstants.TAG_RESOURCES_RESOLVE,
String.format(
String.format("Unknown value for getTextArray(%d) => %s", //DEBUG
index, mResourceData[index].getName())));
return null;
}

View File

@@ -159,7 +159,6 @@ public abstract class AnimationThread extends Thread {
} catch (Throwable throwable) {
// can't use Bridge.getLog() as the exception might be thrown outside
// of an acquire/release block.
mSession.getLog().error(null, "Error playing animation", throwable);
mListener.done(Status.ERROR_UNKNOWN.createResult("Error playing animation", throwable));
} finally {

View File

@@ -17,6 +17,7 @@
package com.android.layoutlib.bridge.impl;
import com.android.layoutlib.bridge.Bridge;
import com.android.layoutlib.bridge.BridgeConstants;
import android.graphics.Bitmap_Delegate;
import android.graphics.Canvas;
@@ -728,7 +729,7 @@ public class GcSnapshot {
customShader = true;
}
} else {
Bridge.getLog().fidelityWarning(null,
Bridge.getLog().fidelityWarning(BridgeConstants.TAG_SHADER,
shaderDelegate.getSupportMessage(),
null);
}
@@ -762,7 +763,7 @@ public class GcSnapshot {
customXfermode = true;
}
} else {
Bridge.getLog().fidelityWarning(null,
Bridge.getLog().fidelityWarning(BridgeConstants.TAG_XFERMODE,
xfermodeDelegate.getSupportMessage(),
null);
}

View File

@@ -364,9 +364,6 @@ public class RenderSessionImpl {
t = t.getCause();
}
// log it
mParams.getLog().error(null, "Scene inflate failed", t);
return ERROR_INFLATION.createResult(t.getMessage(), t);
}
}
@@ -480,9 +477,6 @@ public class RenderSessionImpl {
t = t.getCause();
}
// log it
mParams.getLog().error(null, "Scene Render failed", t);
return ERROR_UNKNOWN.createResult(t.getMessage(), t);
}
}
@@ -1051,7 +1045,7 @@ public class RenderSessionImpl {
}
assert false;
mParams.getLog().error(null,
mParams.getLog().error(BridgeConstants.TAG_RESOURCES_RESOLVE,
String.format("Unable to resolve parent style name: %s", parentName));
return null;

View File

@@ -20,6 +20,7 @@ import com.android.ide.common.rendering.api.DensityBasedResourceValue;
import com.android.ide.common.rendering.api.ResourceDensity;
import com.android.ide.common.rendering.api.ResourceValue;
import com.android.layoutlib.bridge.Bridge;
import com.android.layoutlib.bridge.BridgeConstants;
import com.android.layoutlib.bridge.android.BridgeContext;
import com.android.layoutlib.bridge.android.BridgeXmlBlockParser;
import com.android.ninepatch.NinePatch;
@@ -64,14 +65,18 @@ public final class ResourceHelper {
public static int getColor(String value) {
if (value != null) {
if (value.startsWith("#") == false) {
throw new NumberFormatException();
throw new NumberFormatException(
String.format("Color value '%s' must start with #", value));
}
value = value.substring(1);
// make sure it's not longer than 32bit
if (value.length() > 8) {
throw new NumberFormatException();
throw new NumberFormatException(String.format(
"Color value '%s' is too long. Format is either" +
"#AARRGGBB, #RRGGBB, #RGB, or #ARGB",
value));
}
if (value.length() == 3) { // RGB format
@@ -160,7 +165,8 @@ public final class ResourceHelper {
// URL is wrong, we'll return null below
} catch (IOException e) {
// failed to read the file, we'll return null below.
Bridge.getLog().error(null, "Failed lot load " + file.getAbsolutePath(), e);
Bridge.getLog().error(BridgeConstants.TAG_RESOURCES_READ,
"Failed lot load " + file.getAbsolutePath(), e);
}
}
@@ -194,7 +200,7 @@ public final class ResourceHelper {
Bridge.getLog().error(null, "Failed to parse file " + value, e);
}
} else {
Bridge.getLog().error(null,
Bridge.getLog().error(BridgeConstants.TAG_BROKEN,
String.format("File %s does not exist (or is not a file)", stringValue));
}
@@ -221,7 +227,8 @@ public final class ResourceHelper {
return new BitmapDrawable(context.getResources(), bitmap);
} catch (IOException e) {
// we'll return null below
Bridge.getLog().error(null, "Failed lot load " + bmpFile.getAbsolutePath(), e);
Bridge.getLog().error(BridgeConstants.TAG_RESOURCES_READ,
"Failed lot load " + bmpFile.getAbsolutePath(), e);
}
} else {
// attempt to get a color from the value
@@ -230,8 +237,8 @@ public final class ResourceHelper {
return new ColorDrawable(color);
} catch (NumberFormatException e) {
// we'll return null below.
Bridge.getLog().error(null,
"failed to convert " + stringValue + " into a drawable");
Bridge.getLog().error(BridgeConstants.TAG_RESOURCES_FORMAT,
"Failed to convert " + stringValue + " into a drawable", e);
}
}
}