danger.text.span
Class BitmapSpan

java.lang.Object
  extended by danger.text.span.BitmapSpan
All Implemented Interfaces:
AtomicSpan, CharacterHeightAffectingSpan, CharacterSpan, DrawnSpan, MetricAffectingSpan
Direct Known Subclasses:
HTML.Image


public class BitmapSpan
extends Object
implements MetricAffectingSpan, AtomicSpan, DrawnSpan

This implementation of DrawnSpan draws a Bitmap instead of text. You should take care to ensure that the span is exclusive on both ends to guard against it accidentally growing to cover text inserted nearby.

In general you will want to cover exactly one character with a BitmapSpan. You are encouraged to use character FFFC (the Unicode "Object Replacement Character") in the underlying text.

You may instead prefer to place the "alt" text for the image in the buffer and cover that text with the bitmap. This is what happens with the IM smilies. If you do this, be careful not to include any carriage returns or line feeds in the underlying text because it may fool the text rewrapping code into thinking that a new paragraph starts in the middle of your bitmap. Because BitmapSpan is an AtomicSpan, EditText will take care to keep the user from moving the cursor into the middle of your underlying text or making changes to it other than as a unit.


Field Summary
static int ALIGN_ABOVE
          Align with respect to the bottom of the bitmap.
static int ALIGN_BELOW
          Align with respect to the top of the bitmap.
static int ALIGN_CENTER
          Align with respect to the center of the bitmap.
static Class BITMAP_SPAN_TYPE
           
static int RELATIVE_TO_ASCENT
          Align with respect to the top of the ascent of the font.
static int RELATIVE_TO_BASELINE
          Align with respect to the baseline of the font.
static int RELATIVE_TO_BODY_CENTER
          Align with respect to the center of the body of the font.
static int RELATIVE_TO_DESCENT
          Align with respect to the bottom of the descent of the font.
 
Fields inherited from interface danger.text.span.CharacterHeightAffectingSpan
CHARACTER_HEIGHT_AFFECTING_SPAN_TYPE
 
Constructor Summary
BitmapSpan(Bitmap b, int alignment, int relativeTo)
          Create a BitmapSpan with the specified bitmap and alignment.
 
Method Summary
 int drawText(Pen p, CharSequence text, int start, int len, int x, int top, int baseline, int bottom, Object[] spans)
          Claim to be drawing a segment of text but actually draw a Bitmap.
 boolean findLineBreakCandidate(Font f, int wid_avail, CharSequence text, int end, LineBreakerArguments args, Object[] spans)
          Find a line break within this BitmapSpan.
 int getAdvance(Font f, CharSequence text, int offset, int len, Object[] spans)
          Claim that the advance of this text is actually the width of the bitmap.
 int getAlignment()
           
 Bitmap getBitmap()
           
 int getRelativeTo()
           
 int getVerticalDimensions(Font f, CharSequence text, int start, int end, Object[] spans)
          Return the vertical space occupied by this bitmap, taking into account its vertical alignment and what it is aligned relative to.
 int getWidth(Font f, CharSequence text, int start, int len, Object[] spans)
          Claim that the width of this text is actually the width of the bitmap.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BITMAP_SPAN_TYPE

public static final Class BITMAP_SPAN_TYPE

ALIGN_ABOVE

public static final int ALIGN_ABOVE
Align with respect to the bottom of the bitmap.

See Also:
Constant Field Values

ALIGN_CENTER

public static final int ALIGN_CENTER
Align with respect to the center of the bitmap.

See Also:
Constant Field Values

ALIGN_BELOW

public static final int ALIGN_BELOW
Align with respect to the top of the bitmap.

See Also:
Constant Field Values

RELATIVE_TO_ASCENT

public static final int RELATIVE_TO_ASCENT
Align with respect to the top of the ascent of the font.

See Also:
Constant Field Values

RELATIVE_TO_BASELINE

public static final int RELATIVE_TO_BASELINE
Align with respect to the baseline of the font.

See Also:
Constant Field Values

RELATIVE_TO_DESCENT

public static final int RELATIVE_TO_DESCENT
Align with respect to the bottom of the descent of the font.

See Also:
Constant Field Values

RELATIVE_TO_BODY_CENTER

public static final int RELATIVE_TO_BODY_CENTER
Align with respect to the center of the body of the font.

See Also:
Constant Field Values
Constructor Detail

BitmapSpan

public BitmapSpan(Bitmap b,
                  int alignment,
                  int relativeTo)
Create a BitmapSpan with the specified bitmap and alignment.

Method Detail

getBitmap

public Bitmap getBitmap()

getAlignment

public int getAlignment()

getRelativeTo

public int getRelativeTo()

drawText

public int drawText(Pen p,
                    CharSequence text,
                    int start,
                    int len,
                    int x,
                    int top,
                    int baseline,
                    int bottom,
                    Object[] spans)
Claim to be drawing a segment of text but actually draw a Bitmap.

Specified by:
drawText in interface DrawnSpan

getWidth

public int getWidth(Font f,
                    CharSequence text,
                    int start,
                    int len,
                    Object[] spans)
Claim that the width of this text is actually the width of the bitmap.

Specified by:
getWidth in interface DrawnSpan

getAdvance

public int getAdvance(Font f,
                      CharSequence text,
                      int offset,
                      int len,
                      Object[] spans)
Claim that the advance of this text is actually the width of the bitmap.

Specified by:
getAdvance in interface DrawnSpan

getVerticalDimensions

public int getVerticalDimensions(Font f,
                                 CharSequence text,
                                 int start,
                                 int end,
                                 Object[] spans)
Return the vertical space occupied by this bitmap, taking into account its vertical alignment and what it is aligned relative to. The top 16 bits of the return value are the line height; the bottom 16 bits are the descent.

Specified by:
getVerticalDimensions in interface DrawnSpan

findLineBreakCandidate

public boolean findLineBreakCandidate(Font f,
                                      int wid_avail,
                                      CharSequence text,
                                      int end,
                                      LineBreakerArguments args,
                                      Object[] spans)
Find a line break within this BitmapSpan. In fact, if the entire bitmap fits, the whole span fits, otherwise none of it does. A bitmap is never a breakpoint.

Specified by:
findLineBreakCandidate in interface DrawnSpan