Using state to update voice button proxy visibility instead of view flags. (Bug 10915381)

Change-Id: I72feb506cbc1b03e2b99d36bc4a9d7bda27101be
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index ba34c13..71b98dd 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -895,6 +895,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();
@@ -3301,7 +3304,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;
         }
     }
@@ -3348,13 +3351,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;
         }
     }
@@ -3366,12 +3369,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/Workspace.java b/src/com/android/launcher3/Workspace.java
index 132f42d..68d2414 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);
             }
         }
     };
@@ -1823,6 +1823,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 +1985,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