diff options
author | Winson Chung <winsonc@google.com> | 2010-12-01 21:58:09 -0800 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2010-12-01 21:58:09 -0800 |
commit | 60cd600e6bc45fc5b738f0e5dd93201e5bee6d01 (patch) | |
tree | 6ffbbe15e414408d917261110d593bc5192a6f12 /src | |
parent | cdc30d5c07ae1cd13d9ebacad8c8ff1185d87e19 (diff) | |
parent | 656d11c882296d732e6bdab30ec26f84b99eba19 (diff) | |
download | packages_apps_trebuchet-60cd600e6bc45fc5b738f0e5dd93201e5bee6d01.zip packages_apps_trebuchet-60cd600e6bc45fc5b738f0e5dd93201e5bee6d01.tar.gz packages_apps_trebuchet-60cd600e6bc45fc5b738f0e5dd93201e5bee6d01.tar.bz2 |
Merge "Adding background protection to icons and apps button."
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/launcher2/BubbleTextView.java | 74 | ||||
-rw-r--r-- | src/com/android/launcher2/CacheableTextView.java | 34 | ||||
-rw-r--r-- | src/com/android/launcher2/Workspace.java | 9 |
3 files changed, 81 insertions, 36 deletions
diff --git a/src/com/android/launcher2/BubbleTextView.java b/src/com/android/launcher2/BubbleTextView.java index 6039307..89a6303 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; diff --git a/src/com/android/launcher2/CacheableTextView.java b/src/com/android/launcher2/CacheableTextView.java index 26eafa9..084810e 100644 --- a/src/com/android/launcher2/CacheableTextView.java +++ b/src/com/android/launcher2/CacheableTextView.java @@ -34,6 +34,7 @@ import android.widget.TextView; public class CacheableTextView extends TextView { private Bitmap mCache; private final Paint mCachePaint = new Paint(); + private final Canvas mCacheCanvas = new Canvas(); private int mPrevAlpha = -1; private boolean mIsBuildingCache; @@ -57,6 +58,13 @@ public class CacheableTextView extends TextView { super(context, attrs, defStyle); } + protected int getVerticalPadding() { + return 0; + } + protected int getHorizontalPadding() { + return 0; + } + public void buildAndEnableCache() { if (getLayout() == null) { mWaitingToGenerateCache = true; @@ -64,32 +72,34 @@ public class CacheableTextView extends TextView { } final Layout layout = getLayout(); - final int left = getCompoundPaddingLeft(); final int top = getExtendedPaddingTop(); - mTextCacheLeft = layout.getLineLeft(0); - mTextCacheTop = top + layout.getLineTop(0) - mPaddingV; + final float prevAlpha = getAlpha(); + + int vPadding = getVerticalPadding(); + int hPadding = getHorizontalPadding(); + + mTextCacheLeft = layout.getLineLeft(0) - hPadding; + mTextCacheTop = top + layout.getLineTop(0) - mPaddingV - vPadding; mRectLeft = mScrollX + getLeft(); mRectTop = 0; mTextCacheScrollX = mScrollX; final float textCacheRight = - Math.min(left + layout.getLineRight(0) + mPaddingH, mScrollX + mRight - mLeft); - final float textCacheBottom = top + layout.getLineBottom(0) + mPaddingV; + Math.min(left + layout.getLineRight(0) + mPaddingH, mScrollX + mRight - mLeft) + hPadding; + final float textCacheBottom = top + layout.getLineBottom(0) + mPaddingV + vPadding; mCache = Bitmap.createBitmap((int) (textCacheRight - mTextCacheLeft), (int) (textCacheBottom - mTextCacheTop), Config.ARGB_8888); - Canvas c = new Canvas(mCache); - c.translate(-mTextCacheLeft, -mTextCacheTop); + mCacheCanvas.setBitmap(mCache); + mCacheCanvas.translate(-mTextCacheLeft, -mTextCacheTop); mIsBuildingCache = true; - float alpha = getAlpha(); setAlpha(1.0f); - draw(c); - setAlpha(alpha); + draw(mCacheCanvas); + setAlpha(prevAlpha); mIsBuildingCache = false; - mCachePaint.setFilterBitmap(true); // A hack-- we set the text to be one space (we don't make it empty just to avoid any // potential issues with text measurement, like line height, etc.) so that the text view @@ -119,4 +129,4 @@ public class CacheableTextView extends TextView { } return true; } -}
\ No newline at end of file +} diff --git a/src/com/android/launcher2/Workspace.java b/src/com/android/launcher2/Workspace.java index f866b22..b12d357 100644 --- a/src/com/android/launcher2/Workspace.java +++ b/src/com/android/launcher2/Workspace.java @@ -1281,9 +1281,14 @@ public class Workspace extends SmoothPagedView v.getDrawingRect(clipRect); // For a TextView, adjust the clip rect so that we don't include the text label - if (v instanceof TextView) { + if (v instanceof BubbleTextView) { + final BubbleTextView tv = (BubbleTextView) v; + clipRect.bottom = tv.getExtendedPaddingTop() - (int) BubbleTextView.PADDING_V + + tv.getLayout().getLineTop(0); + } else if (v instanceof TextView) { final TextView tv = (TextView) v; - clipRect.bottom = clipRect.top + tv.getCompoundPaddingTop() - 1; + clipRect.bottom = tv.getExtendedPaddingTop() - tv.getCompoundDrawablePadding() + + tv.getLayout().getLineTop(0); } // Draw the View into the bitmap. |