Merge branch 'master' into honeycomb-release
diff --git a/src/com/android/launcher2/Launcher.java b/src/com/android/launcher2/Launcher.java
index 2a2d364..1a486d7 100644
--- a/src/com/android/launcher2/Launcher.java
+++ b/src/com/android/launcher2/Launcher.java
@@ -259,6 +259,11 @@
     private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance =
         new HashMap<View, AppWidgetProviderInfo>();
 
+    // External icons saved in case of resource changes, orientation, etc.
+    private static Drawable sGlobalSearchIcon;
+    private static Drawable sVoiceSearchIcon;
+    private static Drawable sAppMarketIcon;
+
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
@@ -374,6 +379,19 @@
 
         IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
         registerReceiver(mCloseSystemDialogsReceiver, filter);
+
+        // If we have a saved version of these external icons, we load them up immediately
+        if (LauncherApplication.isScreenXLarge()) {
+            if (sGlobalSearchIcon != null) {
+                updateGlobalSearchIcon(sGlobalSearchIcon);
+            }
+            if (sVoiceSearchIcon != null) {
+                updateVoiceSearchIcon(sVoiceSearchIcon);
+            }
+            if (sAppMarketIcon != null) {
+                updateAppMarketIcon(sAppMarketIcon);
+            }
+        }
     }
 
     private void checkForLocaleChange() {
@@ -2880,7 +2898,8 @@
         showWorkspace(true, layout);
     }
 
-    private void updateButtonWithIconFromExternalActivity(
+    // if successful in getting icon, return it; otherwise, set button to use default drawable
+    private Drawable updateButtonWithIconFromExternalActivity(
             int buttonId, ComponentName activityName, int fallbackDrawableId) {
         ImageView button = (ImageView) findViewById(buttonId);
         Drawable toolbarIcon = null;
@@ -2902,18 +2921,25 @@
         // If we were unable to find the icon via the meta-data, use a generic one
         if (toolbarIcon == null) {
             button.setImageResource(fallbackDrawableId);
+            return null;
         } else {
             button.setImageDrawable(toolbarIcon);
+            return toolbarIcon;
         }
     }
 
+    private void updateButtonWithDrawable(int buttonId, Drawable d) {
+        ImageView button = (ImageView) findViewById(buttonId);
+        button.setImageDrawable(d);
+    }
+
     private void updateGlobalSearchIcon() {
         if (LauncherApplication.isScreenXLarge()) {
             final SearchManager searchManager =
                     (SearchManager) getSystemService(Context.SEARCH_SERVICE);
             ComponentName activityName = searchManager.getGlobalSearchActivity();
             if (activityName != null) {
-                updateButtonWithIconFromExternalActivity(
+                sGlobalSearchIcon = updateButtonWithIconFromExternalActivity(
                         R.id.search_button, activityName, R.drawable.search_button_generic);
             } else {
                 findViewById(R.id.search_button).setVisibility(View.GONE);
@@ -2921,12 +2947,16 @@
         }
     }
 
+    private void updateGlobalSearchIcon(Drawable d) {
+        updateButtonWithDrawable(R.id.search_button, d);
+    }
+
     private void updateVoiceSearchIcon() {
         if (LauncherApplication.isScreenXLarge()) {
             Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
             ComponentName activityName = intent.resolveActivity(getPackageManager());
             if (activityName != null) {
-                updateButtonWithIconFromExternalActivity(
+                sVoiceSearchIcon = updateButtonWithIconFromExternalActivity(
                         R.id.voice_button, activityName, R.drawable.ic_voice_search);
             } else {
                 findViewById(R.id.voice_button).setVisibility(View.GONE);
@@ -2934,6 +2964,10 @@
         }
     }
 
+    private void updateVoiceSearchIcon(Drawable d) {
+        updateButtonWithDrawable(R.id.voice_button, d);
+    }
+
     /**
      * Sets the app market icon (shown when all apps is visible on x-large screens)
      */
@@ -2945,12 +2979,16 @@
             ComponentName activityName = intent.resolveActivity(getPackageManager());
             if (activityName != null) {
                 mAppMarketIntent = intent;
-                updateButtonWithIconFromExternalActivity(
+                sAppMarketIcon = updateButtonWithIconFromExternalActivity(
                         R.id.market_button, activityName, R.drawable.app_market_generic);
             }
         }
     }
 
+    private void updateAppMarketIcon(Drawable d) {
+        updateButtonWithDrawable(R.id.market_button, d);
+    }
+
     /**
      * Displays the shortcut creation dialog and launches, if necessary, the
      * appropriate activity.
diff --git a/src/com/android/launcher2/Workspace.java b/src/com/android/launcher2/Workspace.java
index 0a3f915..f866b22 100644
--- a/src/com/android/launcher2/Workspace.java
+++ b/src/com/android/launcher2/Workspace.java
@@ -107,6 +107,8 @@
     private ObjectAnimator mBackgroundFadeInAnimation;
     private ObjectAnimator mBackgroundFadeOutAnimation;
     private Drawable mBackground;
+    private Drawable mCustomizeTrayBackground;
+    private boolean mDrawCustomizeTrayBackground;
     private float mBackgroundAlpha = 0;
     private float mOverScrollMaxBackgroundAlpha = 0.0f;
     private int mOverScrollPageIndex = -1;
@@ -249,6 +251,7 @@
         try {
             final Resources res = getResources();
             mBackground = res.getDrawable(R.drawable.all_apps_bg_gradient);
+            mCustomizeTrayBackground = res.getDrawable(R.drawable.customize_bg_gradient);
         } catch (Resources.NotFoundException e) {
             // In this case, we will skip drawing background protection
         }
@@ -261,6 +264,7 @@
             @Override
             public void onAnimationEndOrCancel(Animator animation) {
                 mIsInUnshrinkAnimation = false;
+                mDrawCustomizeTrayBackground = false;
             }
         };
         mSnapVelocity = 600;
@@ -588,7 +592,12 @@
         return mChildrenOutlineAlpha;
     }
 
-    public void showBackgroundGradient() {
+    private void showBackgroundGradientForCustomizeTray() {
+        showBackgroundGradient();
+        mDrawCustomizeTrayBackground = true;
+    }
+
+    private void showBackgroundGradient() {
         if (mBackground == null) return;
         if (mBackgroundFadeOutAnimation != null) mBackgroundFadeOutAnimation.cancel();
         if (mBackgroundFadeInAnimation != null) mBackgroundFadeInAnimation.cancel();
@@ -598,7 +607,7 @@
         mBackgroundFadeInAnimation.start();
     }
 
-    public void hideBackgroundGradient() {
+    private void hideBackgroundGradient() {
         if (mBackground == null) return;
         if (mBackgroundFadeInAnimation != null) mBackgroundFadeInAnimation.cancel();
         if (mBackgroundFadeOutAnimation != null) mBackgroundFadeOutAnimation.cancel();
@@ -731,9 +740,16 @@
     protected void onDraw(Canvas canvas) {
         // Draw the background gradient if necessary
         if (mBackground != null && mBackgroundAlpha > 0.0f) {
-            mBackground.setAlpha((int) (mBackgroundAlpha * 255));
+            int alpha = (int) (mBackgroundAlpha * 255);
+            mBackground.setAlpha(alpha);
             mBackground.setBounds(mScrollX, 0, mScrollX + getMeasuredWidth(), getMeasuredHeight());
             mBackground.draw(canvas);
+            if (mDrawCustomizeTrayBackground) {
+                mCustomizeTrayBackground.setAlpha(alpha);
+                mCustomizeTrayBackground.setBounds(mScrollX, 0, mScrollX + getMeasuredWidth(),
+                        getMeasuredHeight());
+                mCustomizeTrayBackground.draw(canvas);
+            }
         }
 
         super.onDraw(canvas);
@@ -918,7 +934,6 @@
 
     // we use this to shrink the workspace for the all apps view and the customize view
     private void shrink(ShrinkPosition shrinkPosition, boolean animated) {
-        showBackgroundGradient();
 
         if (mFirstLayout) {
             // (mFirstLayout == "first layout has not happened yet")
@@ -1039,6 +1054,12 @@
             mAnimator.start();
         }
         setChildrenDrawnWithCacheEnabled(true);
+
+        if (shrinkPosition == ShrinkPosition.SHRINK_TO_TOP) {
+            showBackgroundGradientForCustomizeTray();
+        } else {
+            showBackgroundGradient();
+        }
     }
 
     /*
@@ -1191,8 +1212,6 @@
     }
 
     void unshrink(boolean animated) {
-        hideBackgroundGradient();
-
         if (mIsSmall) {
             mIsSmall = false;
             if (mAnimator != null) {
@@ -1246,6 +1265,8 @@
                 mAnimator.start();
             }
         }
+
+        hideBackgroundGradient();
     }
 
     /**