Merge "Ensuring that snapToPage is completely aborted / cleaned up upon setCurrentPage (issue 11003904)" into jb-ub-now-indigo-rose
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index 62e05e8..7ae429d 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -900,6 +900,9 @@
         // Process any items that were added while Launcher was away.
         InstallShortcutReceiver.disableAndFlushInstallQueue(this);
 
+        // Update the voice search button proxy
+        updateVoiceButtonProxyVisible(false);
+
         // Again, as with the above scenario, it's possible that one or more of the global icons
         // were updated in the wrong orientation.
         updateGlobalIcons();
@@ -3338,7 +3341,7 @@
             if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
             if (searchButton != null) searchButton.setVisibility(View.GONE);
             if (voiceButton != null) voiceButton.setVisibility(View.GONE);
-            setVoiceButtonProxyVisible(false);
+            updateVoiceButtonProxyVisible(false);
             return false;
         }
     }
@@ -3385,13 +3388,13 @@
             }
             if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE);
             voiceButton.setVisibility(View.VISIBLE);
-            setVoiceButtonProxyVisible(true);
+            updateVoiceButtonProxyVisible(false);
             invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
             return true;
         } else {
             if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE);
             if (voiceButton != null) voiceButton.setVisibility(View.GONE);
-            setVoiceButtonProxyVisible(false);
+            updateVoiceButtonProxyVisible(false);
             return false;
         }
     }
@@ -3403,12 +3406,23 @@
         invalidatePressedFocusedStates(voiceButtonContainer, voiceButton);
     }
 
-    public void setVoiceButtonProxyVisible(boolean visible) {
+    public void updateVoiceButtonProxyVisible(boolean forceDisableVoiceButtonProxy) {
         final View voiceButtonProxy = findViewById(R.id.voice_button_proxy);
         if (voiceButtonProxy != null) {
+            boolean visible = !forceDisableVoiceButtonProxy &&
+                    mWorkspace.shouldVoiceButtonProxyBeVisible();
             voiceButtonProxy.setVisibility(visible ? View.VISIBLE : View.GONE);
+            voiceButtonProxy.bringToFront();
         }
     }
+
+    /**
+     * This is an overrid eot disable the voice button proxy.  If disabled is true, then the voice button proxy
+     * will be hidden regardless of what shouldVoiceButtonProxyBeVisible() returns.
+     */
+    public void disableVoiceButtonProxy(boolean disabled) {
+        updateVoiceButtonProxyVisible(disabled);
+    }
     /**
      * Sets the app market icon
      */
diff --git a/src/com/android/launcher3/ThirdPartyWallpaperPickerListAdapter.java b/src/com/android/launcher3/ThirdPartyWallpaperPickerListAdapter.java
index 7ed1c1b..70ef7c3 100644
--- a/src/com/android/launcher3/ThirdPartyWallpaperPickerListAdapter.java
+++ b/src/com/android/launcher3/ThirdPartyWallpaperPickerListAdapter.java
@@ -39,7 +39,8 @@
     private final LayoutInflater mInflater;
     private final PackageManager mPackageManager;
 
-    private List<ResolveInfo> mThirdPartyWallpaperPickers = new ArrayList<ResolveInfo>();
+    private List<ThirdPartyWallpaperTile> mThirdPartyWallpaperPickers =
+            new ArrayList<ThirdPartyWallpaperTile>();
 
     public static class ThirdPartyWallpaperTile extends WallpaperPickerActivity.WallpaperTileInfo {
         private ResolveInfo mResolveInfo;
@@ -96,7 +97,7 @@
                     continue outerLoop;
                 }
             }
-            mThirdPartyWallpaperPickers.add(info);
+            mThirdPartyWallpaperPickers.add(new ThirdPartyWallpaperTile(info));
         }
     }
 
@@ -104,7 +105,7 @@
         return mThirdPartyWallpaperPickers.size();
     }
 
-    public ResolveInfo getItem(int position) {
+    public ThirdPartyWallpaperTile getItem(int position) {
         return mThirdPartyWallpaperPickers.get(position);
     }
 
@@ -123,7 +124,7 @@
 
         WallpaperPickerActivity.setWallpaperItemPaddingToZero((FrameLayout) view);
 
-        ResolveInfo info = mThirdPartyWallpaperPickers.get(position);
+        ResolveInfo info = mThirdPartyWallpaperPickers.get(position).mResolveInfo;
         TextView label = (TextView) view.findViewById(R.id.wallpaper_item_label);
         label.setText(info.loadLabel(mPackageManager));
         label.setCompoundDrawablesWithIntrinsicBounds(
diff --git a/src/com/android/launcher3/WallpaperCropActivity.java b/src/com/android/launcher3/WallpaperCropActivity.java
index bc8df6c..cdfcd1c 100644
--- a/src/com/android/launcher3/WallpaperCropActivity.java
+++ b/src/com/android/launcher3/WallpaperCropActivity.java
@@ -506,7 +506,9 @@
                             (int) returnRect.height(), Bitmap.Config.ARGB_8888);
                     if (tmp != null) {
                         Canvas c = new Canvas(tmp);
-                        c.drawBitmap(crop, m, new Paint());
+                        Paint p = new Paint();
+                        p.setFilterBitmap(true);
+                        c.drawBitmap(crop, m, p);
                         crop = tmp;
                     }
                 } else if (mRotation > 0) {
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java
index 132f42d..ea348ef 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -1036,14 +1036,14 @@
             if (mCustomContentCallbacks != null) {
                 mCustomContentCallbacks.onShow();
                 mCustomContentShowTime = System.currentTimeMillis();
-                mLauncher.setVoiceButtonProxyVisible(false);
+                mLauncher.updateVoiceButtonProxyVisible(false);
             }
         } else if (hasCustomContent() && getNextPage() != 0 && mCustomContentShowing) {
             mCustomContentShowing = false;
             if (mCustomContentCallbacks != null) {
                 mCustomContentCallbacks.onHide();
                 mLauncher.resetQSBScroll();
-                mLauncher.setVoiceButtonProxyVisible(true);
+                mLauncher.updateVoiceButtonProxyVisible(false);
             }
         }
     };
@@ -1070,7 +1070,6 @@
     class WallpaperOffsetInterpolator implements Choreographer.FrameCallback {
         float mFinalOffset = 0.0f;
         float mCurrentOffset = 0.5f; // to force an initial update
-        //long mLastWallpaperOffsetUpdateTime;
         boolean mWaitingForUpdate;
         Choreographer mChoreographer;
         Interpolator mInterpolator;
@@ -1135,10 +1134,12 @@
             }
 
             // Exclude the leftmost page
-            final int firstIndex = isLayoutRtl() ? getChildCount() - 2 : 1;
+            final int startPage = hasCustomContent() ? 1 : 0;
+            final int firstIndex = isLayoutRtl() ? getChildCount() - 1 - startPage : startPage;
             // Exclude the last extra empty screen (if we have > MIN_PARALLAX_PAGE_SPAN pages)
-            int extra = numExtraScreensToIgnore();
-            final int lastIndex = isLayoutRtl() ? 0 + extra : getChildCount() - 1 - extra;
+            int emptyExtraPages = numExtraScreensToIgnore();
+            final int lastIndex =
+                    isLayoutRtl() ? 0 + emptyExtraPages : getChildCount() - 1 - emptyExtraPages;
 
             int firstPageScrollX = getScrollForPage(firstIndex);
             int scrollRange = getScrollForPage(lastIndex) - firstPageScrollX;
@@ -1166,7 +1167,8 @@
         }
 
         private int getNumScreensExcludingExtraEmptyScreenAndLeftmost() {
-            int numScrollingPages = getChildCount() - 1 - numExtraScreensToIgnore();
+            int numScrollingPages = getChildCount() - numExtraScreensToIgnore();
+            if (hasCustomContent()) numScrollingPages -= 1;
             return numScrollingPages;
         }
 
@@ -1823,6 +1825,16 @@
         return offsetDelta;
     }
 
+    boolean shouldVoiceButtonProxyBeVisible() {
+        if (isOnOrMovingToCustomContent()) {
+            return false;
+        }
+        if (mState != State.NORMAL) {
+            return false;
+        }
+        return true;
+    }
+
     Animator getChangeStateAnimation(final State state, boolean animated, int delay, int snapPage) {
         if (mState == state) {
             return null;
@@ -1975,11 +1987,7 @@
             setScaleY(mNewScale);
             setTranslationY(finalWorkspaceTranslationY);
         }
-        if (finalSearchBarAlpha == 0) {
-            mLauncher.setVoiceButtonProxyVisible(false);
-        } else {
-            mLauncher.setVoiceButtonProxyVisible(true);
-        }
+        mLauncher.updateVoiceButtonProxyVisible(false);
 
         if (stateIsSpringLoaded) {
             // Right now we're covered by Apps Customize