Code drop from //branches/cupcake/...@124589
diff --git a/src/com/android/launcher/BubbleTextView.java b/src/com/android/launcher/BubbleTextView.java
index 730e08e..f2c31e9 100644
--- a/src/com/android/launcher/BubbleTextView.java
+++ b/src/com/android/launcher/BubbleTextView.java
@@ -22,7 +22,7 @@
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 @@
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 @@
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 @@
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);
}
}