From 8a80a8555238cc564f445f902aff5231993a8f96 Mon Sep 17 00:00:00 2001 From: Xavier Ducrohet Date: Wed, 9 Feb 2011 19:39:52 -0800 Subject: [PATCH] LayoutLib: remove some exceptions. We need to move away from throwing anything and instead log errors/warnings. Change-Id: Ib1af71a90c06e8565fbd0c061ba56f4d19baa3df --- .../src/android/graphics/Bitmap_Delegate.java | 6 +- .../src/android/graphics/Canvas_Delegate.java | 59 +++++++++++-------- .../src/android/graphics/Paint_Delegate.java | 36 +++++++---- .../src/android/graphics/Path_Delegate.java | 21 ++++--- .../bridge/android/BridgeTypedArray.java | 7 ++- 5 files changed, 83 insertions(+), 46 deletions(-) diff --git a/tools/layoutlib/bridge/src/android/graphics/Bitmap_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Bitmap_Delegate.java index 9da8c1a81b18a..0c87766286461 100644 --- a/tools/layoutlib/bridge/src/android/graphics/Bitmap_Delegate.java +++ b/tools/layoutlib/bridge/src/android/graphics/Bitmap_Delegate.java @@ -383,13 +383,15 @@ public final class Bitmap_Delegate { @LayoutlibDelegate /*package*/ static void nativeCopyPixelsToBuffer(int nativeBitmap, Buffer dst) { // FIXME implement native delegate - throw new UnsupportedOperationException("Native delegate needed for Bitmap.nativeCopyPixelsToBuffer"); + Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED, + "Bitmap.copyPixelsToBuffer is not supported.", null, null /*data*/); } @LayoutlibDelegate /*package*/ static void nativeCopyPixelsFromBuffer(int nb, Buffer src) { // FIXME implement native delegate - throw new UnsupportedOperationException("Native delegate needed for Bitmap.nativeCopyPixelsFromBuffer"); + Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED, + "Bitmap.copyPixelsFromBuffer is not supported.", null, null /*data*/); } @LayoutlibDelegate diff --git a/tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java index bb98843e0094c..e8a99b5d67115 100644 --- a/tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java +++ b/tools/layoutlib/bridge/src/android/graphics/Canvas_Delegate.java @@ -273,13 +273,15 @@ public final class Canvas_Delegate { /*package*/ static void drawPoints(Canvas thisCanvas, float[] pts, int offset, int count, Paint paint) { // FIXME - throw new UnsupportedOperationException(); + Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED, + "Canvas.drawPoint is not supported.", null, null /*data*/); } @LayoutlibDelegate /*package*/ static void drawPoint(Canvas thisCanvas, float x, float y, Paint paint) { // FIXME - throw new UnsupportedOperationException(); + Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED, + "Canvas.drawPoint is not supported.", null, null /*data*/); } @LayoutlibDelegate @@ -645,7 +647,8 @@ public final class Canvas_Delegate { @LayoutlibDelegate /*package*/ static void native_drawPaint(int nativeCanvas, int paint) { // FIXME - throw new UnsupportedOperationException(); + Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED, + "Canvas.drawPaint is not supported.", null, null /*data*/); } @LayoutlibDelegate @@ -718,20 +721,19 @@ public final class Canvas_Delegate { } @LayoutlibDelegate - /*package*/ static void native_drawCircle(int nativeCanvas, float cx, - float cy, float radius, - int paint) { + /*package*/ static void native_drawCircle(int nativeCanvas, + float cx, float cy, float radius, int paint) { native_drawOval(nativeCanvas, new RectF(cx - radius, cy - radius, radius*2, radius*2), paint); } @LayoutlibDelegate - /*package*/ static void native_drawArc(int nativeCanvas, RectF oval, - float startAngle, float sweep, - boolean useCenter, int paint) { + /*package*/ static void native_drawArc(int nativeCanvas, + RectF oval, float startAngle, float sweep, boolean useCenter, int paint) { // FIXME - throw new UnsupportedOperationException(); + Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED, + "Canvas.drawArc is not supported.", null, null /*data*/); } @LayoutlibDelegate @@ -764,8 +766,7 @@ public final class Canvas_Delegate { } @LayoutlibDelegate - /*package*/ static void native_drawPath(int nativeCanvas, int path, - int paint) { + /*package*/ static void native_drawPath(int nativeCanvas, int path, int paint) { final Path_Delegate pathDelegate = Path_Delegate.getDelegate(path); if (pathDelegate == null) { return; @@ -929,20 +930,23 @@ public final class Canvas_Delegate { @LayoutlibDelegate /*package*/ static void nativeDrawBitmapMesh(int nCanvas, int nBitmap, - int meshWidth, int meshHeight, - float[] verts, int vertOffset, - int[] colors, int colorOffset, int nPaint) { + int meshWidth, int meshHeight, float[] verts, int vertOffset, int[] colors, + int colorOffset, int nPaint) { // FIXME - throw new UnsupportedOperationException(); + Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED, + "Canvas.drawBitmapMesh is not supported.", null, null /*data*/); } @LayoutlibDelegate /*package*/ static void nativeDrawVertices(int nCanvas, int mode, int n, - float[] verts, int vertOffset, float[] texs, int texOffset, - int[] colors, int colorOffset, short[] indices, - int indexOffset, int indexCount, int nPaint) { + float[] verts, int vertOffset, + float[] texs, int texOffset, + int[] colors, int colorOffset, + short[] indices, int indexOffset, + int indexCount, int nPaint) { // FIXME - throw new UnsupportedOperationException(); + Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED, + "Canvas.drawVertices is not supported.", null, null /*data*/); } @LayoutlibDelegate @@ -1080,7 +1084,8 @@ public final class Canvas_Delegate { int count, float[] pos, int paint) { // FIXME - throw new UnsupportedOperationException(); + Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED, + "Canvas.drawPosText is not supported.", null, null /*data*/); } @LayoutlibDelegate @@ -1088,7 +1093,8 @@ public final class Canvas_Delegate { String text, float[] pos, int paint) { // FIXME - throw new UnsupportedOperationException(); + Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED, + "Canvas.drawPosText is not supported.", null, null /*data*/); } @LayoutlibDelegate @@ -1099,7 +1105,8 @@ public final class Canvas_Delegate { float vOffset, int bidiFlags, int paint) { // FIXME - throw new UnsupportedOperationException(); + Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED, + "Canvas.drawTextOnPath is not supported.", null, null /*data*/); } @LayoutlibDelegate @@ -1109,14 +1116,16 @@ public final class Canvas_Delegate { float vOffset, int flags, int paint) { // FIXME - throw new UnsupportedOperationException(); + Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED, + "Canvas.drawTextOnPath is not supported.", null, null /*data*/); } @LayoutlibDelegate /*package*/ static void native_drawPicture(int nativeCanvas, int nativePicture) { // FIXME - throw new UnsupportedOperationException(); + Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED, + "Canvas.drawPicture is not supported.", null, null /*data*/); } @LayoutlibDelegate diff --git a/tools/layoutlib/bridge/src/android/graphics/Paint_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Paint_Delegate.java index 39c8a370bdde7..f5d2547799d80 100644 --- a/tools/layoutlib/bridge/src/android/graphics/Paint_Delegate.java +++ b/tools/layoutlib/bridge/src/android/graphics/Paint_Delegate.java @@ -568,14 +568,18 @@ public class Paint_Delegate { /*package*/ static int native_breakText(Paint thisPaint, char[] text, int index, int count, float maxWidth, float[] measuredWidth) { // FIXME - throw new UnsupportedOperationException(); + Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED, + "Paint.native_breakText is not supported.", null, null /*data*/); + return 0; } @LayoutlibDelegate /*package*/ static int native_breakText(Paint thisPaint, String text, boolean measureForwards, float maxWidth, float[] measuredWidth) { // FIXME - throw new UnsupportedOperationException(); + Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED, + "Paint.native_breakText is not supported.", null, null /*data*/); + return 0; } @LayoutlibDelegate @@ -859,14 +863,18 @@ public class Paint_Delegate { /*package*/ static int native_getTextWidths(int native_object, char[] text, int index, int count, float[] widths) { // FIXME - throw new UnsupportedOperationException(); + Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED, + "Paint.getTextWidths is not supported.", null, null /*data*/); + return 0; } @LayoutlibDelegate /*package*/ static int native_getTextWidths(int native_object, String text, int start, int end, float[] widths) { // FIXME - throw new UnsupportedOperationException(); + Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED, + "Paint.getTextWidths is not supported.", null, null /*data*/); + return 0; } @LayoutlibDelegate @@ -930,42 +938,50 @@ public class Paint_Delegate { /*package*/ static int native_getTextRunCursor(Paint thisPaint, int native_object, char[] text, int contextStart, int contextLength, int flags, int offset, int cursorOpt) { // FIXME - throw new UnsupportedOperationException(); + Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED, + "Paint.getTextRunCursor is not supported.", null, null /*data*/); + return 0; } @LayoutlibDelegate /*package*/ static int native_getTextRunCursor(Paint thisPaint, int native_object, String text, int contextStart, int contextEnd, int flags, int offset, int cursorOpt) { // FIXME - throw new UnsupportedOperationException(); + Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED, + "Paint.getTextRunCursor is not supported.", null, null /*data*/); + return 0; } @LayoutlibDelegate /*package*/ static void native_getTextPath(int native_object, int bidiFlags, char[] text, int index, int count, float x, float y, int path) { // FIXME - throw new UnsupportedOperationException(); + Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED, + "Paint.getTextPath is not supported.", null, null /*data*/); } @LayoutlibDelegate /*package*/ static void native_getTextPath(int native_object, int bidiFlags, String text, int start, int end, float x, float y, int path) { // FIXME - throw new UnsupportedOperationException(); + Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED, + "Paint.getTextPath is not supported.", null, null /*data*/); } @LayoutlibDelegate /*package*/ static void nativeGetStringBounds(int nativePaint, String text, int start, int end, Rect bounds) { // FIXME - throw new UnsupportedOperationException(); + Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED, + "Paint.getStringBounds is not supported.", null, null /*data*/); } @LayoutlibDelegate /*package*/ static void nativeGetCharArrayBounds(int nativePaint, char[] text, int index, int count, Rect bounds) { // FIXME - throw new UnsupportedOperationException(); + Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED, + "Paint.getCharArrayBounds is not supported.", null, null /*data*/); } @LayoutlibDelegate diff --git a/tools/layoutlib/bridge/src/android/graphics/Path_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Path_Delegate.java index 6c15a1a221a71..9510ce00e2141 100644 --- a/tools/layoutlib/bridge/src/android/graphics/Path_Delegate.java +++ b/tools/layoutlib/bridge/src/android/graphics/Path_Delegate.java @@ -332,39 +332,45 @@ public final class Path_Delegate { @LayoutlibDelegate /*package*/ static void native_addOval(int nPath, RectF oval, int dir) { // FIXME - throw new UnsupportedOperationException(); + Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED, + "Path.addOval is not supported.", null, null /*data*/); } @LayoutlibDelegate /*package*/ static void native_addCircle(int nPath, float x, float y, float radius, int dir) { // FIXME - throw new UnsupportedOperationException(); + Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED, + "Path.addCircle is not supported.", null, null /*data*/); } @LayoutlibDelegate /*package*/ static void native_addArc(int nPath, RectF oval, float startAngle, float sweepAngle) { // FIXME - throw new UnsupportedOperationException(); + Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED, + "Path.addArc is not supported.", null, null /*data*/); } @LayoutlibDelegate /*package*/ static void native_addRoundRect(int nPath, RectF rect, float rx, float ry, int dir) { // FIXME - throw new UnsupportedOperationException(); + Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED, + "Path.addRoundRect is not supported.", null, null /*data*/); } @LayoutlibDelegate /*package*/ static void native_addRoundRect(int nPath, RectF r, float[] radii, int dir) { // FIXME - throw new UnsupportedOperationException(); + Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED, + "Path.addRoundRect is not supported.", null, null /*data*/); } @LayoutlibDelegate /*package*/ static void native_addPath(int nPath, int src, float dx, float dy) { // FIXME - throw new UnsupportedOperationException(); + Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED, + "Path.addPath is not supported.", null, null /*data*/); } @LayoutlibDelegate @@ -375,7 +381,8 @@ public final class Path_Delegate { @LayoutlibDelegate /*package*/ static void native_addPath(int nPath, int src, int matrix) { // FIXME - throw new UnsupportedOperationException(); + Bridge.getLog().fidelityWarning(LayoutLog.TAG_UNSUPPORTED, + "Path.addPath is not supported.", null, null /*data*/); } @LayoutlibDelegate diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeTypedArray.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeTypedArray.java index 15c4f4422a3cf..ff2b91e15f205 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeTypedArray.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeTypedArray.java @@ -485,8 +485,11 @@ public final class BridgeTypedArray extends TypedArray { if (f == 0) return 0; if (f > 0) return 1; - throw new UnsupportedOperationException("Can't convert to dimension: " + - Integer.toString(index)); + Bridge.getLog().error(LayoutLog.TAG_RESOURCES_FORMAT, + "Can't convert to dimension: " + Integer.toString(index), + null, null /*data*/); + + return defValue; } /**