FileDocCategorySizeDatePackage
ImageSpan.javaAPI DocAndroid 5.1 API5225Thu Mar 12 22:22:10 GMT 2015android.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)

deprecated
Use {@link #ImageSpan(Context, Bitmap)} instead.

        this(null, b, 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);
    
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)

deprecated
Use {@link #ImageSpan(Context, Bitmap, int) instead.

        this(null, b, verticalAlignment);
    
public ImageSpan(android.content.Context context, android.graphics.Bitmap b)

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

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

        super(verticalAlignment);
        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); 
    
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);
    
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(mContext.getResources(), 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.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;