Adding background protection to icons and apps button.

Change-Id: I650f9135c0ce5bc2a6f7c5f878d470d6a85e9f7e
diff --git a/res/drawable/shortcut_selector.xml b/res/drawable/shortcut_selector.xml
index 884bccf..8059f00 100644
--- a/res/drawable/shortcut_selector.xml
+++ b/res/drawable/shortcut_selector.xml
@@ -19,7 +19,7 @@
 -->
 
 <selector xmlns:android="http://schemas.android.com/apk/res/android">
-    <item android:state_pressed="true" android:drawable="@drawable/pressed_application_background" />
     <item android:state_window_focused="true" android:state_focused="true" android:drawable="@drawable/focused_application_background" />
-    <item android:state_window_focused="false" android:state_focused="true" android:drawable="@android:color/transparent" />
+    <item android:state_pressed="true" android:drawable="@drawable/pressed_application_background" />
+    <item android:drawable="@android:color/transparent" />
 </selector>
diff --git a/res/layout-xlarge-land/application.xml b/res/layout-xlarge-land/application.xml
index ed8fa8c..2598e5a 100644
--- a/res/layout-xlarge-land/application.xml
+++ b/res/layout-xlarge-land/application.xml
@@ -15,4 +15,4 @@
 -->
 
 <com.android.launcher2.BubbleTextView xmlns:android="http://schemas.android.com/apk/res/android"
-   style="@style/WorkspaceIcon.Landscape" />
\ No newline at end of file
+   style="@style/WorkspaceIcon.Landscape" />
diff --git a/res/layout-xlarge-land/launcher.xml b/res/layout-xlarge-land/launcher.xml
index 0fc954b..7b66d7c 100644
--- a/res/layout-xlarge-land/launcher.xml
+++ b/res/layout-xlarge-land/launcher.xml
@@ -125,7 +125,13 @@
             android:layout_toLeftOf="@id/configure_button"
             android:layout_marginLeft="@dimen/toolbar_button_spacing"
             android:layout_marginRight="@dimen/toolbar_button_spacing"
-            android:textSize="18dp"
+            android:textColor="#CCFFFFFF"
+            android:textSize="18sp"
+
+            android:shadowColor="#A0000000"
+            android:shadowDx="0.0"
+            android:shadowDy="0.0"
+            android:shadowRadius="2.0"
 
             android:onClick="onClickAllAppsButton"
             android:focusable="true"
diff --git a/res/layout-xlarge-port/launcher.xml b/res/layout-xlarge-port/launcher.xml
index 088f081..c5691b8 100644
--- a/res/layout-xlarge-port/launcher.xml
+++ b/res/layout-xlarge-port/launcher.xml
@@ -125,8 +125,14 @@
             android:layout_toLeftOf="@id/configure_button"
             android:layout_marginLeft="@dimen/toolbar_button_spacing"
             android:layout_marginRight="@dimen/toolbar_button_spacing"
+            android:textColor="#CCFFFFFF"
             android:textSize="18dp"
 
+            android:shadowColor="#A0000000"
+            android:shadowDx="0.0"
+            android:shadowDy="0.0"
+            android:shadowRadius="2.0"
+
             android:onClick="onClickAllAppsButton"
             android:focusable="true"
             android:clickable="true" />
diff --git a/res/values-xlarge/config.xml b/res/values-xlarge/config.xml
index 3654753..55a96f6 100644
--- a/res/values-xlarge/config.xml
+++ b/res/values-xlarge/config.xml
@@ -26,8 +26,8 @@
     <!-- Duration in milliseconds toolbar fade in and fade out animations.
          NOTE: Fade in and fade out time should together be less the transition
          animations between all apps, customize, & the workspace. -->
-    <integer name="config_toolbarButtonFadeInTime">350</integer>
-    <integer name="config_toolbarButtonFadeOutTime">350</integer>
+    <integer name="config_toolbarButtonFadeInTime">100</integer>
+    <integer name="config_toolbarButtonFadeOutTime">100</integer>
 
     <!-- When dragging items on the workspace, how much bigger (in pixels) the dragged view
          should be, as compared to the original view. If 0, it will not be scaled at all.
diff --git a/res/values-xlarge/styles.xml b/res/values-xlarge/styles.xml
index 5198d30..7208d97 100644
--- a/res/values-xlarge/styles.xml
+++ b/res/values-xlarge/styles.xml
@@ -31,12 +31,13 @@
     </style>
 
     <style name="WorkspaceIcon.Portrait">
-        <item name="android:drawablePadding">0dip</item>
+        <item name="android:drawablePadding">2dip</item>
         <item name="android:paddingTop">0dip</item>
+        <item name="android:includeFontPadding">false</item>
     </style>
 
     <style name="WorkspaceIcon.Landscape">
-        <item name="android:drawablePadding">0dip</item>
+        <item name="android:drawablePadding">2dip</item>
         <item name="android:paddingTop">0dip</item>
         <item name="android:includeFontPadding">false</item>
     </style>
diff --git a/res/values/colors.xml b/res/values/colors.xml
index 3e964c4..57f8bfc 100644
--- a/res/values/colors.xml
+++ b/res/values/colors.xml
@@ -20,7 +20,7 @@
 <resources>
     <color name="window_background">#FF191919</color>
     <color name="grid_dark_background">#EB191919</color>     
-    <color name="bubble_dark_background">#B2191919</color>
+    <color name="bubble_dark_background">#20000000</color>
     <color name="delete_color_filter">#A5FF0000</color>
 
     <color name="appwidget_error_color">#FCCC</color>
diff --git a/res/values/styles.xml b/res/values/styles.xml
index c867d38..3305299 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -38,7 +38,7 @@
         <item name="android:textSize">13dip</item>
         <item name="android:singleLine">true</item>
         <item name="android:ellipsize">marquee</item>
-        <item name="android:shadowColor">#FF000000</item>
+        <item name="android:shadowColor">#B0000000</item>
         <item name="android:shadowRadius">2.0</item>
         <item name="android:textColor">#FFF</item>
         <item name="android:gravity">center_horizontal</item>
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 @@
  * 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 @@
     }
 
     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 @@
             }
         }
 
+        // Draw the hotdog bubble
         final Layout layout = getLayout();
-        final RectF rect = mRect;
-        final int left = getCompoundPaddingLeft();
-        final int top = getExtendedPaddingTop();
+        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);
 
-        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);
+        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 @@
 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 @@
         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 @@
         }
 
         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 @@
         }
         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 @@
         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.