Merge "Fix glitchy animation in Settings" into sc-dev am: 686eff64e3 am: 2f1179b589

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/WallpaperPicker2/+/14928657

Change-Id: I4066f9fb85fe9952f0b8d4eafccf4045b79fb369
diff --git a/src/com/android/wallpaper/model/CustomizationSectionController.java b/src/com/android/wallpaper/model/CustomizationSectionController.java
index bfa3ec3..b01f098 100644
--- a/src/com/android/wallpaper/model/CustomizationSectionController.java
+++ b/src/com/android/wallpaper/model/CustomizationSectionController.java
@@ -51,4 +51,7 @@
 
     /** Releases the controller. */
     default void release() {}
+
+    /** Gets called when the section gets transitioned out. */
+    default void onTransitionOut() {}
 }
diff --git a/src/com/android/wallpaper/model/WallpaperSectionController.java b/src/com/android/wallpaper/model/WallpaperSectionController.java
index 7c43baa..7346cc3 100644
--- a/src/com/android/wallpaper/model/WallpaperSectionController.java
+++ b/src/com/android/wallpaper/model/WallpaperSectionController.java
@@ -531,4 +531,23 @@
             mLockPreviewContainer.setVisibility(visibility);
         }
     }
+
+    @Override
+    public void onTransitionOut() {
+        if (mHomeWallpaperSurface != null) {
+            mHomeWallpaperSurface.setUseAlpha();
+            mHomeWallpaperSurface.setAlpha(0f);
+        }
+        if (mLockWallpaperSurface != null) {
+            mLockWallpaperSurface.setUseAlpha();
+            mLockWallpaperSurface.setAlpha(0f);
+        }
+        if (mWorkspaceSurface != null) {
+            mWorkspaceSurface.setUseAlpha();
+            mWorkspaceSurface.setAlpha(0f);
+        }
+        if (mLockPreviewContainer != null) {
+            mLockPreviewContainer.setAlpha(0f);
+        }
+    }
 }
diff --git a/src/com/android/wallpaper/picker/CustomizationPickerFragment.java b/src/com/android/wallpaper/picker/CustomizationPickerFragment.java
index 176ee1c..75f1b46 100644
--- a/src/com/android/wallpaper/picker/CustomizationPickerFragment.java
+++ b/src/com/android/wallpaper/picker/CustomizationPickerFragment.java
@@ -116,6 +116,15 @@
     }
 
     @Override
+    public boolean onBackPressed() {
+        // TODO(b/191120122) Improve glitchy animation in Settings.
+        if (ActivityUtils.isLaunchedFromSettingsSearch(getActivity().getIntent())) {
+            mSectionControllers.forEach(CustomizationSectionController::onTransitionOut);
+        }
+        return super.onBackPressed();
+    }
+
+    @Override
     public void onDestroyView() {
         mSectionControllers.forEach(CustomizationSectionController::release);
         mSectionControllers.clear();
diff --git a/src/com/android/wallpaper/util/ActivityUtils.java b/src/com/android/wallpaper/util/ActivityUtils.java
index c4d49f8..eb2adb2 100755
--- a/src/com/android/wallpaper/util/ActivityUtils.java
+++ b/src/com/android/wallpaper/util/ActivityUtils.java
@@ -83,7 +83,7 @@
      *
      * @param intent activity intent.
      */
-    private static boolean isLaunchedFromSettingsSearch(Intent intent) {
+    public static boolean isLaunchedFromSettingsSearch(Intent intent) {
         return (intent != null && intent.hasExtra(LAUNCH_SETTINGS_SEARCH));
     }