diff options
author | Winson Chung <winsonc@google.com> | 2010-11-29 17:15:47 -0800 |
---|---|---|
committer | Winson Chung <winsonc@google.com> | 2010-12-01 21:55:26 -0800 |
commit | 656d11c882296d732e6bdab30ec26f84b99eba19 (patch) | |
tree | 71307ef1efb0655cbb1c3b3973cafbbe5e6e478c /src/com/android/launcher2/BubbleTextView.java | |
parent | f28958bc003177cc98ed9bde62f412811784ec14 (diff) | |
download | android_packages_apps_Trebuchet-656d11c882296d732e6bdab30ec26f84b99eba19.tar.gz android_packages_apps_Trebuchet-656d11c882296d732e6bdab30ec26f84b99eba19.tar.bz2 android_packages_apps_Trebuchet-656d11c882296d732e6bdab30ec26f84b99eba19.zip |
Adding background protection to icons and apps button.
Change-Id: I650f9135c0ce5bc2a6f7c5f878d470d6a85e9f7e
Diffstat (limited to 'src/com/android/launcher2/BubbleTextView.java')
-rw-r--r-- | src/com/android/launcher2/BubbleTextView.java | 74 |
1 files changed, 52 insertions, 22 deletions
diff --git a/src/com/android/launcher2/BubbleTextView.java b/src/com/android/launcher2/BubbleTextView.java index 603930792..89a6303b4 100644 --- a/src/com/android/launcher2/BubbleTextView.java +++ b/src/com/android/launcher2/BubbleTextView.java @@ -16,15 +16,17 @@ package com.android.launcher2; -import android.widget.TextView; import android.content.Context; -import android.util.AttributeSet; +import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.Canvas; +import android.graphics.Color; import android.graphics.Paint; import android.graphics.RectF; import android.graphics.drawable.Drawable; import android.text.Layout; +import android.util.AttributeSet; +import android.view.View.MeasureSpec; import com.android.launcher.R; @@ -34,12 +36,15 @@ import com.android.launcher.R; * too aggressive. */ public class BubbleTextView extends CacheableTextView { - static final float CORNER_RADIUS = 8.0f; - static final float PADDING_H = 5.0f; - static final float PADDING_V = 1.0f; + static final float CORNER_RADIUS = 4.0f; + static final float PADDING_H = 8.0f; + static final float PADDING_V = 3.0f; + + private int mAppCellWidth; private final RectF mRect = new RectF(); private Paint mPaint; + private float mBubbleColorAlpha; private int mPrevAlpha = -1; private boolean mBackgroundSizeChanged; @@ -64,20 +69,31 @@ public class BubbleTextView extends CacheableTextView { } private void init() { - setFocusable(true); mBackground = getBackground(); + setFocusable(true); setBackgroundDrawable(null); + final Resources res = getContext().getResources(); + int bubbleColor = res.getColor(R.color.bubble_dark_background); mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); - mPaint.setColor(getContext().getResources().getColor(R.color.bubble_dark_background)); + mPaint.setColor(bubbleColor); + mBubbleColorAlpha = Color.alpha(bubbleColor) / 255.0f; + mAppCellWidth = (int) res.getDimension(R.dimen.app_icon_size); - final float scale = getContext().getResources().getDisplayMetrics().density; + final float scale = res.getDisplayMetrics().density; mCornerRadius = CORNER_RADIUS * scale; mPaddingH = PADDING_H * scale; //noinspection PointlessArithmeticExpression mPaddingV = PADDING_V * scale; } + protected int getVerticalPadding() { + return (int) PADDING_V; + } + protected int getHorizontalPadding() { + return (int) PADDING_H; + } + public void applyFromShortcutInfo(ShortcutInfo info, IconCache iconCache) { Bitmap b = info.getIcon(iconCache); @@ -133,39 +149,53 @@ public class BubbleTextView extends CacheableTextView { } } + // Draw the hotdog bubble 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); - // TEMPORARILY DISABLE DRAWING ROUND RECT -- re-enable this when we tweak CacheableTextView - // to support padding so we can capture the "rounded" edges - //canvas.drawRoundRect(rect, mCornerRadius, mCornerRadius, mPaint); + final int offset = getExtendedPaddingTop(); + final int paddingLeft = getPaddingLeft(); + final int paddingRight = getPaddingRight(); + final float left = layout.getLineLeft(0) + paddingLeft; + final float right = Math.min(layout.getLineRight(0) + paddingRight, + left + getWidth() - paddingLeft - paddingRight); + mRect.set(left - mPaddingH, offset + (int) layout.getLineTop(0) - mPaddingV, + right + mPaddingH, offset + (int) layout.getLineBottom(0) + mPaddingV); + + canvas.drawRoundRect(mRect, mCornerRadius, mCornerRadius, mPaint); super.draw(canvas); } @Override + protected void onSizeChanged(int w, int h, int oldw, int oldh) { + if (w > 0 && h > 0) { + // Temporary Workaround: We need to set padding to compress the text so that we can draw + // a hotdog around it. Currently, the background images prevent us from applying the + // padding in XML, so we are doing this programmatically + int d = w - mAppCellWidth; + int pL = d - (d / 2); + int pR = d - pL; + setPadding(pL, getPaddingTop(), pR, getPaddingBottom()); + } + super.onSizeChanged(w, h, oldw, oldh); + } + + @Override protected void onAttachedToWindow() { super.onAttachedToWindow(); - mBackground.setCallback(this); + if (mBackground != null) mBackground.setCallback(this); } @Override protected void onDetachedFromWindow() { super.onDetachedFromWindow(); - mBackground.setCallback(null); + if (mBackground != null) mBackground.setCallback(null); } @Override protected boolean onSetAlpha(int alpha) { if (mPrevAlpha != alpha) { mPrevAlpha = alpha; - mPaint.setAlpha(alpha); + mPaint.setAlpha((int) (alpha * mBubbleColorAlpha)); super.onSetAlpha(alpha); } return true; |