FileDocCategorySizeDatePackage
ImageSpan.javaAPI DocAndroid 1.5 API4660Wed May 06 22:41:56 BST 2009android.text.style

ImageSpan

public class ImageSpan extends DynamicDrawableSpan

Fields Summary
private android.graphics.drawable.Drawable
mDrawable
private android.net.Uri
mContentUri
private int
mResourceId
private android.content.Context
mContext
private String
mSource
Constructors Summary
public ImageSpan(android.graphics.Bitmap b)

        this(b, ALIGN_BOTTOM);
    
public ImageSpan(android.content.Context context, int resourceId, int verticalAlignment)

param
verticalAlignment one of {@link DynamicDrawableSpan#ALIGN_BOTTOM} or {@link DynamicDrawableSpan#ALIGN_BASELINE}.

        super(verticalAlignment);
        mContext = context;
        mResourceId = resourceId;
    
public ImageSpan(android.graphics.Bitmap b, int verticalAlignment)

param
verticalAlignment one of {@link DynamicDrawableSpan#ALIGN_BOTTOM} or {@link DynamicDrawableSpan#ALIGN_BASELINE}.

        super(verticalAlignment);
        mDrawable = new BitmapDrawable(b);
        int width = mDrawable.getIntrinsicWidth();
        int height = mDrawable.getIntrinsicHeight();
        mDrawable.setBounds(0, 0, width > 0 ? width : 0, height > 0 ? height : 0); 
    
public ImageSpan(android.graphics.drawable.Drawable d)

        this(d, ALIGN_BOTTOM);
    
public ImageSpan(android.graphics.drawable.Drawable d, int verticalAlignment)

param
verticalAlignment one of {@link DynamicDrawableSpan#ALIGN_BOTTOM} or {@link DynamicDrawableSpan#ALIGN_BASELINE}.

        super(verticalAlignment);
        mDrawable = d;
    
public ImageSpan(android.graphics.drawable.Drawable d, String source)

        this(d, source, ALIGN_BOTTOM);
    
public ImageSpan(android.graphics.drawable.Drawable d, String source, int verticalAlignment)

param
verticalAlignment one of {@link DynamicDrawableSpan#ALIGN_BOTTOM} or {@link DynamicDrawableSpan#ALIGN_BASELINE}.

        super(verticalAlignment);
        mDrawable = d;
        mSource = source;
    
public ImageSpan(android.content.Context context, android.net.Uri uri)

        this(context, uri, ALIGN_BOTTOM);
    
public ImageSpan(android.content.Context context, android.net.Uri uri, int verticalAlignment)

param
verticalAlignment one of {@link DynamicDrawableSpan#ALIGN_BOTTOM} or {@link DynamicDrawableSpan#ALIGN_BASELINE}.

        super(verticalAlignment);
        mContext = context;
        mContentUri = uri;
        mSource = uri.toString();
    
public ImageSpan(android.content.Context context, int resourceId)

        this(context, resourceId, ALIGN_BOTTOM);
    
Methods Summary
public android.graphics.drawable.DrawablegetDrawable()

        Drawable drawable = null;
        
        if (mDrawable != null) {
            drawable = mDrawable;
        } else  if (mContentUri != null) {
            Bitmap bitmap = null;
            try {
                InputStream is = mContext.getContentResolver().openInputStream(
                        mContentUri);
                bitmap = BitmapFactory.decodeStream(is);
                drawable = new BitmapDrawable(bitmap);
                drawable.setBounds(0, 0, drawable.getIntrinsicWidth(),
                        drawable.getIntrinsicHeight());
                is.close();
            } catch (Exception e) {
                Log.e("sms", "Failed to loaded content " + mContentUri, e);
            }
        } else {
            try {
                drawable = mContext.getResources().getDrawable(mResourceId);
                drawable.setBounds(0, 0, drawable.getIntrinsicWidth(),
                        drawable.getIntrinsicHeight());
            } catch (Exception e) {
                Log.e("sms", "Unable to find resource: " + mResourceId);
            }                
        }

        return drawable;
    
public java.lang.StringgetSource()
Returns the source string that was saved during construction.

        return mSource;