Play common transition animations from a common method.

There are 3 animations that 3 different transitions use; to prevent
future problems, let's put them all in one place. For instance,
ag/781127 added dispatchOnLauncherTransitionStepAnim() to the two
transitions that existed in burnaby-polish, but not to a third,
startAnimationToNewWorkspaceState(), that was added in master. If a
common method existed in polish, the new animation would have merged
into master automatically instead of forcing us to remember to add it.

Change-Id: I7775aaa43a08ae8b8241b0eeb77b6c84167c5ff0
diff --git a/src/com/android/launcher3/LauncherStateTransitionAnimation.java b/src/com/android/launcher3/LauncherStateTransitionAnimation.java
index aa56f9d..17dd6f3 100644
--- a/src/com/android/launcher3/LauncherStateTransitionAnimation.java
+++ b/src/com/android/launcher3/LauncherStateTransitionAnimation.java
@@ -226,16 +226,8 @@
         // Cancel the current animation
         cancelAnimation();
 
-        // Create the workspace animation.
-        // NOTE: this call apparently also sets the state for the workspace if !animated
-        Animator workspaceAnim = mLauncher.startWorkspaceStateChangeAnimation(toWorkspaceState,
-                animated, layerViews);
-
-        // Animate the search bar
-        startWorkspaceSearchBarAnimation(animation, fromWorkspaceState, toWorkspaceState,
-                animated ? revealDuration : 0, overlaySearchBarView);
-
-        Animator updateTransitionStepAnim = dispatchOnLauncherTransitionStepAnim(fromView, toView);
+        playCommonTransitionAnimations(fromWorkspaceState, toWorkspaceState, fromView, toView,
+                overlaySearchBarView, animated, initialized, animation, revealDuration, layerViews);
 
         if (animated && initialized) {
             // Setup the reveal view animation
@@ -345,13 +337,6 @@
 
             });
 
-            // Play the workspace animation
-            if (workspaceAnim != null) {
-                animation.play(workspaceAnim);
-            }
-
-            animation.play(updateTransitionStepAnim);
-
             // Dispatch the prepare transition signal
             dispatchOnLauncherTransitionPrepare(fromView, animated, false);
             dispatchOnLauncherTransitionPrepare(toView, animated, false);
@@ -411,6 +396,32 @@
     }
 
     /**
+     * Plays animations used by various transitions.
+     */
+    private void playCommonTransitionAnimations(Workspace.State fromWorkspaceState,
+            Workspace.State toWorkspaceState, View fromView, View toView, View overlaySearchBarView,
+            boolean animated, boolean initialized, AnimatorSet animation, int revealDuration,
+            HashMap<View, Integer> layerViews) {
+        // Create the workspace animation.
+        // NOTE: this call apparently also sets the state for the workspace if !animated
+        Animator workspaceAnim = mLauncher.startWorkspaceStateChangeAnimation(toWorkspaceState,
+                animated, layerViews);
+
+        // Animate the search bar
+        startWorkspaceSearchBarAnimation(animation, fromWorkspaceState, toWorkspaceState,
+                animated ? revealDuration : 0, overlaySearchBarView);
+
+        if (animated && initialized) {
+            // Play the workspace animation
+            if (workspaceAnim != null) {
+                animation.play(workspaceAnim);
+            }
+            // Dispatch onLauncherTransitionStep() as the animation interpolates.
+            animation.play(dispatchOnLauncherTransitionStepAnim(fromView, toView));
+        }
+    }
+
+    /**
      * Returns an Animator that calls {@link #dispatchOnLauncherTransitionStep(View, float)} on
      * {@param fromView} and {@param toView} as the animation interpolates.
      *
@@ -517,18 +528,10 @@
         // Cancel the current animation
         cancelAnimation();
 
-        // Create the workspace animation.
-        // NOTE: this call apparently also sets the state for the workspace if !animated
-        Animator workspaceAnim = mLauncher.startWorkspaceStateChangeAnimation(toWorkspaceState,
-                animated, layerViews);
-
-        startWorkspaceSearchBarAnimation(animation, fromWorkspaceState, toWorkspaceState,
-                animated ? revealDuration : 0, null);
+        playCommonTransitionAnimations(fromWorkspaceState, toWorkspaceState, fromWorkspace, null,
+                null, animated, animated, animation, revealDuration, layerViews);
 
         if (animated) {
-            if (workspaceAnim != null) {
-                animation.play(workspaceAnim);
-            }
             dispatchOnLauncherTransitionPrepare(fromWorkspace, animated, true);
 
             final AnimatorSet stateAnimation = animation;
@@ -616,25 +619,10 @@
         // Cancel the current animation
         cancelAnimation();
 
-        // Create the workspace animation.
-        // NOTE: this call apparently also sets the state for the workspace if !animated
-        Animator workspaceAnim = mLauncher.startWorkspaceStateChangeAnimation(toWorkspaceState,
-                animated, layerViews);
-
-        // Animate the search bar
-        startWorkspaceSearchBarAnimation(animation, fromWorkspaceState, toWorkspaceState,
-                animated ? revealDuration : 0, overlaySearchBarView);
-
-        Animator updateTransitionStepAnim = dispatchOnLauncherTransitionStepAnim(fromView, toView);
+        playCommonTransitionAnimations(fromWorkspaceState, toWorkspaceState, fromView, toView,
+                overlaySearchBarView, animated, initialized, animation, revealDuration, layerViews);
 
         if (animated && initialized) {
-            // Play the workspace animation
-            if (workspaceAnim != null) {
-                animation.play(workspaceAnim);
-            }
-
-            animation.play(updateTransitionStepAnim);
-
             // hideAppsCustomizeHelper is called in some cases when it is already hidden
             // don't perform all these no-op animations. In particularly, this was causing
             // the all-apps button to pop in and out.