Code drop from //branches/cupcake/...@124589

This commit is contained in:
The Android Open Source Project committed 2008-12-17 18:05:58 -08:00
1 parent c8f00b61c6
commit d097a1880f
47 files changed
+2521 -453

No files matched your search

+51 -4
View File
@@ -22,7 +22,7 @@ import android.util.AttributeSet;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.text.Layout;
/**
@@ -38,6 +38,9 @@ public class BubbleTextView extends TextView {
private final RectF mRect = new RectF();
private Paint mPaint;
private boolean mBackgroundSizeChanged;
private Drawable mBackground;
public BubbleTextView(Context context) {
super(context);
init();
@@ -55,13 +58,57 @@ public class BubbleTextView extends TextView {
private void init() {
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));
}
@Override
public void onDraw(Canvas canvas) {
protected boolean setFrame(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);
}
@Override
protected boolean verifyDrawable(Drawable who) {
return who == mBackground || super.verifyDrawable(who);
}
@Override
protected void drawableStateChanged() {
Drawable d = mBackground;
if (d != null && d.isStateful()) {
d.setState(getDrawableState());
}
super.drawableStateChanged();
}
@Override
public void draw(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();
@@ -69,10 +116,10 @@ public class BubbleTextView extends TextView {
rect.set(left + layout.getLineLeft(0) - PADDING_H,
top + layout.getLineTop(0) - PADDING_V,
left + layout.getLineRight(0) + PADDING_H,
Math.min(left + layout.getLineRight(0) + PADDING_H, mScrollX + mRight - mLeft),
top + layout.getLineBottom(0) + PADDING_V);
canvas.drawRoundRect(rect, CORNER_RADIUS, CORNER_RADIUS, mPaint);
super.onDraw(canvas);
super.draw(canvas);
}
}