From 0cd6376fa14089cee42991f751962ffd7f455797 Mon Sep 17 00:00:00 2001 From: Dianne Hackborn Date: Wed, 29 Jul 2009 17:36:27 -0700 Subject: [PATCH] Fix issue #2018454: NullPointerException in ImageSpan constructor --- api/current.xml | 26 ++++++++++++++++++++++++++ core/java/android/text/style/ImageSpan.java | 23 ++++++++++++++++++++--- 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/api/current.xml b/api/current.xml index e0ea9668ee32..4df50bc7cfc3 100644 --- a/api/current.xml +++ b/api/current.xml @@ -130442,9 +130442,33 @@ type="android.text.style.ImageSpan" static="false" final="false" + deprecated="deprecated" + visibility="public" +> + + + + + + + + + + + + @@ -130455,6 +130479,8 @@ deprecated="not deprecated" visibility="public" > + + diff --git a/core/java/android/text/style/ImageSpan.java b/core/java/android/text/style/ImageSpan.java index 911a23c9631c..86ef5f68bc7c 100644 --- a/core/java/android/text/style/ImageSpan.java +++ b/core/java/android/text/style/ImageSpan.java @@ -33,17 +33,34 @@ public class ImageSpan extends DynamicDrawableSpan { private Context mContext; private String mSource; + /** + * @deprecated Use {@link #ImageSpan(Context, Bitmap)} instead. + */ public ImageSpan(Bitmap b) { - this(b, ALIGN_BOTTOM); + this(null, b, ALIGN_BOTTOM); + } + + /** + * @deprecated Use {@link #ImageSpan(Context, Bitmap, int) instead. + */ + public ImageSpan(Bitmap b, int verticalAlignment) { + this(null, b, verticalAlignment); + } + + public ImageSpan(Context context, Bitmap b) { + this(context, b, ALIGN_BOTTOM); } /** * @param verticalAlignment one of {@link DynamicDrawableSpan#ALIGN_BOTTOM} or * {@link DynamicDrawableSpan#ALIGN_BASELINE}. */ - public ImageSpan(Bitmap b, int verticalAlignment) { + public ImageSpan(Context context, Bitmap b, int verticalAlignment) { super(verticalAlignment); - mDrawable = new BitmapDrawable(mContext.getResources(), b); + mContext = context; + mDrawable = context != null + ? new BitmapDrawable(context.getResources(), b) + : new BitmapDrawable(b); int width = mDrawable.getIntrinsicWidth(); int height = mDrawable.getIntrinsicHeight(); mDrawable.setBounds(0, 0, width > 0 ? width : 0, height > 0 ? height : 0); -- 2.11.0