FileDocCategorySizeDatePackage
BubbleTextView.javaAPI DocAndroid 1.5 API4394Wed May 06 22:42:46 BST 2009com.android.launcher

BubbleTextView

public class BubbleTextView extends android.widget.TextView
TextView that draws a bubble behind the text. We cannot use a LineBackgroundSpan because we want to make the bubble taller than the text and TextView's clip is too aggressive.

Fields Summary
private static final float
CORNER_RADIUS
private static final float
PADDING_H
private static final float
PADDING_V
private final android.graphics.RectF
mRect
private android.graphics.Paint
mPaint
private boolean
mBackgroundSizeChanged
private android.graphics.drawable.Drawable
mBackground
private float
mCornerRadius
private float
mPaddingH
private float
mPaddingV
Constructors Summary
public BubbleTextView(android.content.Context context)


       
        super(context);
        init();
    
public BubbleTextView(android.content.Context context, android.util.AttributeSet attrs)

        super(context, attrs);
        init();
    
public BubbleTextView(android.content.Context context, android.util.AttributeSet attrs, int defStyle)

        super(context, attrs, defStyle);
        init();
    
Methods Summary
public voiddraw(android.graphics.Canvas canvas)

        final Drawable background = mBackground;
        if (background != null) {
            final int scrollX = mScrollX;
            final int scrollY = mScrollY;

            if (mBackgroundSizeChanged) {
                background.setBounds(0, 0,  mRight - mLeft, mBottom - mTop);
                mBackgroundSizeChanged = false;
            }

            if ((scrollX | scrollY) == 0) {
                background.draw(canvas);
            } else {
                canvas.translate(scrollX, scrollY);
                background.draw(canvas);
                canvas.translate(-scrollX, -scrollY);
            }
        }

        final Layout layout = getLayout();
        final RectF rect = mRect;
        final int left = getCompoundPaddingLeft();
        final int top = getExtendedPaddingTop();

        rect.set(left + layout.getLineLeft(0) - mPaddingH,
                top + layout.getLineTop(0) -  mPaddingV,
                Math.min(left + layout.getLineRight(0) + mPaddingH, mScrollX + mRight - mLeft),
                top + layout.getLineBottom(0) + mPaddingV);
        canvas.drawRoundRect(rect, mCornerRadius, mCornerRadius, mPaint);

        super.draw(canvas);
    
protected voiddrawableStateChanged()

        Drawable d = mBackground;
        if (d != null && d.isStateful()) {
            d.setState(getDrawableState());
        }
        super.drawableStateChanged();
    
private voidinit()

        setFocusable(true);
        mBackground = getBackground();
        setBackgroundDrawable(null);
        mBackground.setCallback(this);

        mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        mPaint.setColor(getContext().getResources().getColor(R.color.bubble_dark_background));

        final float scale = getContext().getResources().getDisplayMetrics().density;
        mCornerRadius = CORNER_RADIUS * scale;
        mPaddingH = PADDING_H * scale;
        //noinspection PointlessArithmeticExpression
        mPaddingV = PADDING_V * scale;
    
protected booleansetFrame(int left, int top, int right, int bottom)

        if (mLeft != left || mRight != right || mTop != top || mBottom != bottom) {
            mBackgroundSizeChanged = true;
        }
        return super.setFrame(left, top, right, bottom);
    
protected booleanverifyDrawable(android.graphics.drawable.Drawable who)

        return who == mBackground || super.verifyDrawable(who);