More work to ensure that the wallpaper is visible before transitions take place. (Bug 6445085)

Change-Id: Ic8435ba946949674a986aa4eaa879d33044c7884
diff --git a/src/com/android/launcher2/Launcher.java b/src/com/android/launcher2/Launcher.java
index 0bb119b..74ec6f3 100644
--- a/src/com/android/launcher2/Launcher.java
+++ b/src/com/android/launcher2/Launcher.java
@@ -1204,12 +1204,7 @@
                         mWorkspace.post(new Runnable() {
                             @Override
                             public void run() {
-                                if (mState == State.APPS_CUSTOMIZE) {
-                                    if (mAppsCustomizeTabHost != null &&
-                                            !mAppsCustomizeTabHost.isTransitioning()) {
-                                        updateWallpaperVisibility(false);
-                                    }
-                                }
+                                disableWallpaperIfInAllApps();
                             }
                         });
 
@@ -2191,6 +2186,16 @@
         view.setPivotY(view.getHeight() / 2.0f);
     }
 
+    void disableWallpaperIfInAllApps() {
+        // Only disable it if we are in all apps
+        if (mState == State.APPS_CUSTOMIZE) {
+            if (mAppsCustomizeTabHost != null &&
+                    !mAppsCustomizeTabHost.isTransitioning()) {
+                updateWallpaperVisibility(false);
+            }
+        }
+    }
+
     void updateWallpaperVisibility(boolean visible) {
         int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
         int curflags = getWindow().getAttributes().flags
@@ -2534,6 +2539,18 @@
         }
     }
 
+    @Override
+    public void onWindowFocusChanged(boolean hasFocus) {
+        if (!hasFocus) {
+            // When another window occludes launcher (like the notification shade, or recents),
+            // ensure that we enable the wallpaper flag so that transitions are done correctly.
+            updateWallpaperVisibility(true);
+        } else {
+            // When launcher has focus again, disable the wallpaper if we are in AllApps
+            disableWallpaperIfInAllApps();
+        }
+    }
+
     void showWorkspace(boolean animated) {
         showWorkspace(animated, null);
     }