Fix folder close animation.

Closing a folder at the same time as the keyboard closes causes the
folder close animation to jump. Fixed the animation.

Test: manual
Change-Id: I0785260f280ffc2932cd92d40073009a8c032b1d
diff --git a/src/com/android/launcher3/folder/Folder.java b/src/com/android/launcher3/folder/Folder.java
index c841b7b..281598a 100644
--- a/src/com/android/launcher3/folder/Folder.java
+++ b/src/com/android/launcher3/folder/Folder.java
@@ -58,6 +58,7 @@
 import android.widget.TextView;
 
 import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
 import androidx.annotation.RequiresApi;
 
 import com.android.launcher3.AbstractFloatingView;
@@ -216,6 +217,8 @@
 
     private StatsLogManager mStatsLogManager;
 
+    @Nullable private FolderWindowInsetsAnimationCallback mFolderWindowInsetsAnimationCallback;
+
     /**
      * Used to inflate the Workspace from XML.
      *
@@ -262,10 +265,10 @@
         mFooterHeight = mFooter.getMeasuredHeight();
 
         if (Utilities.ATLEAST_R) {
-            WindowInsetsAnimation.Callback cb = new FolderWindowInsetsAnimationCallback(
-                    DISPATCH_MODE_STOP, this);
+            mFolderWindowInsetsAnimationCallback =
+                    new FolderWindowInsetsAnimationCallback(DISPATCH_MODE_STOP, this);
 
-            setWindowInsetsAnimationCallback(cb);
+            setWindowInsetsAnimationCallback(mFolderWindowInsetsAnimationCallback);
         }
     }
 
@@ -755,11 +758,17 @@
         a.addListener(new AnimatorListenerAdapter() {
             @Override
             public void onAnimationStart(Animator animation) {
+                if (Utilities.ATLEAST_R) {
+                    setWindowInsetsAnimationCallback(null);
+                }
                 mIsAnimatingClosed = true;
             }
 
             @Override
             public void onAnimationEnd(Animator animation) {
+                if (Utilities.ATLEAST_R && mFolderWindowInsetsAnimationCallback != null) {
+                    setWindowInsetsAnimationCallback(mFolderWindowInsetsAnimationCallback);
+                }
                 closeComplete(true);
                 announceAccessibilityChanges();
                 mIsAnimatingClosed = false;