Fix the overview tutorial step success animation

- Tapping the screen after a successful overview gesture, but before the delayed success feedbck created a janky experience
- Immediately setting the gesture as successful

Flag: ENABLE_NEW_GESTURE_NAV_TUTORIAL
Fixes: 281742006
Test: tapped the screen quickly after successfully completing the overview gesture
Change-Id: I166060191753d6b95bc223e2be08df2bb4b4ecfd
diff --git a/quickstep/src/com/android/quickstep/interaction/OverviewGestureTutorialController.java b/quickstep/src/com/android/quickstep/interaction/OverviewGestureTutorialController.java
index dfbcf4d..ea721bc 100644
--- a/quickstep/src/com/android/quickstep/interaction/OverviewGestureTutorialController.java
+++ b/quickstep/src/com/android/quickstep/interaction/OverviewGestureTutorialController.java
@@ -21,7 +21,6 @@
 import android.animation.Animator;
 import android.animation.AnimatorListenerAdapter;
 import android.animation.AnimatorSet;
-import android.annotation.Nullable;
 import android.annotation.TargetApi;
 import android.graphics.PointF;
 import android.os.Build;
@@ -145,30 +144,11 @@
                         showFeedback(R.string.overview_gesture_feedback_swipe_too_far_from_edge);
                         break;
                     case OVERVIEW_GESTURE_COMPLETED:
+                        setGestureCompleted();
                         mTutorialFragment.releaseFeedbackAnimation();
-                        if (ENABLE_NEW_GESTURE_NAV_TUTORIAL.get()) {
-                            onMotionPaused(true /*arbitrary value*/);
-                            animateTaskViewToOverview(() -> {
-                                mFakeTaskView.setVisibility(View.INVISIBLE);
-                                if(!mTutorialFragment.isLargeScreen()){
-                                    mFakePreviousTaskView.animateToFillScreen(() -> {
-                                        mFakeLauncherView.setBackgroundColor(
-                                                mContext.getColor(
-                                                        R.color.gesture_overview_tutorial_swipe_rect
-                                                ));
-                                        showSuccessFeedback();
-                                    });
-                                } else {
-                                    mFakeLauncherView.setBackgroundColor(
-                                            mContext.getColor(
-                                                    R.color.gesture_overview_tutorial_swipe_rect
-                                            ));
-                                    showSuccessFeedback();
-                                }
-                            });
-                        } else {
-                            animateTaskViewToOverview(null);
-                            onMotionPaused(true /*arbitrary value*/);
+                        animateTaskViewToOverview(ENABLE_NEW_GESTURE_NAV_TUTORIAL.get());
+                        onMotionPaused(true /*arbitrary value*/);
+                        if (!ENABLE_NEW_GESTURE_NAV_TUTORIAL.get()) {
                             showSuccessFeedback();
                         }
                         break;
@@ -189,21 +169,28 @@
 
     /**
      * runnable executed with slight delay to ease the swipe animation after landing on overview
-     * @param runnable
      */
-    public void animateTaskViewToOverview(@Nullable Runnable runnable) {
+    public void animateTaskViewToOverview(boolean animateDelayedSuccessFeedback) {
         PendingAnimation anim = new PendingAnimation(TASK_VIEW_END_ANIMATION_DURATION_MILLIS);
         anim.setFloat(mTaskViewSwipeUpAnimation
                 .getCurrentShift(), AnimatedFloat.VALUE, 1, ACCEL);
 
-        anim.addListener(new AnimatorListenerAdapter() {
-            @Override
-            public void onAnimationEnd(Animator animator) {
-                if (runnable != null) {
-                    new Handler().postDelayed(runnable, 300);
+        if (animateDelayedSuccessFeedback) {
+            anim.addListener(new AnimatorListenerAdapter() {
+                @Override
+                public void onAnimationEnd(Animator animator) {
+                    new Handler().postDelayed(() -> {
+                        mFakeTaskView.setVisibility(View.INVISIBLE);
+                        if (!mTutorialFragment.isLargeScreen()) {
+                            mFakePreviousTaskView.animateToFillScreen(
+                                    () -> onSuccessAnimationComplete());
+                        } else {
+                            onSuccessAnimationComplete();
+                        }
+                    }, TASK_VIEW_FILL_SCREEN_ANIMATION_DELAY_MILLIS);
                 }
-            }
-        });
+            });
+        }
 
         ArrayList<Animator> animators = new ArrayList<>();
 
@@ -222,4 +209,9 @@
         animset.start();
         mRunningWindowAnim = SwipeUpAnimationLogic.RunningWindowAnim.wrap(animset);
     }
+
+    private void onSuccessAnimationComplete() {
+        setLauncherViewColor(R.color.gesture_overview_tutorial_swipe_rect);
+        showSuccessFeedback();
+    }
 }
diff --git a/quickstep/src/com/android/quickstep/interaction/OverviewGestureTutorialFragment.java b/quickstep/src/com/android/quickstep/interaction/OverviewGestureTutorialFragment.java
index c471a13..01074dd 100644
--- a/quickstep/src/com/android/quickstep/interaction/OverviewGestureTutorialFragment.java
+++ b/quickstep/src/com/android/quickstep/interaction/OverviewGestureTutorialFragment.java
@@ -73,7 +73,7 @@
             @Override
             public void onAnimationStart(Animator animation) {
                 super.onAnimationStart(animation);
-                controller.animateTaskViewToOverview(null);
+                controller.animateTaskViewToOverview(false);
             }
         });
 
diff --git a/quickstep/src/com/android/quickstep/interaction/SwipeUpGestureTutorialController.java b/quickstep/src/com/android/quickstep/interaction/SwipeUpGestureTutorialController.java
index a8af05e..5a2c2cd 100644
--- a/quickstep/src/com/android/quickstep/interaction/SwipeUpGestureTutorialController.java
+++ b/quickstep/src/com/android/quickstep/interaction/SwipeUpGestureTutorialController.java
@@ -64,6 +64,7 @@
     private static final int FAKE_PREVIOUS_TASK_MARGIN = Utilities.dpToPx(12);
 
     protected static final long TASK_VIEW_END_ANIMATION_DURATION_MILLIS = 300;
+    protected static final long TASK_VIEW_FILL_SCREEN_ANIMATION_DELAY_MILLIS = 300;
     private static final long HOME_SWIPE_ANIMATION_DURATION_MILLIS = 625;
     private static final long OVERVIEW_SWIPE_ANIMATION_DURATION_MILLIS = 1000;
 
diff --git a/quickstep/src/com/android/quickstep/interaction/TutorialController.java b/quickstep/src/com/android/quickstep/interaction/TutorialController.java
index d4ff457..198305f 100644
--- a/quickstep/src/com/android/quickstep/interaction/TutorialController.java
+++ b/quickstep/src/com/android/quickstep/interaction/TutorialController.java
@@ -317,6 +317,14 @@
     }
 
     /**
+     * Only use this when a gesture is completed, but the feedback shouldn't be shown immediately.
+     * In that case, call this method immediately instead.
+     */
+    public void setGestureCompleted() {
+        mGestureCompleted = true;
+    }
+
+    /**
      * Show feedback reflecting a successful gesture attempt.
      **/
     void showSuccessFeedback() {
@@ -641,13 +649,17 @@
         }
     }
 
+    void setLauncherViewColor(@ColorRes int backgroundColorRes) {
+        mFakeLauncherView.setBackgroundColor(mContext.getColor(backgroundColorRes));
+    }
+
     private void updateDrawables() {
         if (mContext != null) {
             mTutorialFragment.getRootView().setBackground(AppCompatResources.getDrawable(
                     mContext, getMockWallpaperResId()));
             mTutorialFragment.updateFeedbackAnimation();
-            mFakeLauncherView.setBackgroundColor(
-                    mContext.getColor(R.color.gesture_tutorial_fake_wallpaper_color));
+            setLauncherViewColor(ENABLE_NEW_GESTURE_NAV_TUTORIAL.get()
+                    ? getSwipeActionColorResId() : R.color.gesture_tutorial_fake_wallpaper_color);
             updateFakeViewLayout(mFakeHotseatView, getMockHotseatResId());
             mHotseatIconView = mFakeHotseatView.findViewById(R.id.hotseat_icon_1);
             updateFakeViewLayout(mFakeTaskView, getMockAppTaskLayoutResId());
@@ -657,11 +669,6 @@
                     getMockPreviousAppTaskThumbnailColorResId()));
             mFakeIconView.setBackground(AppCompatResources.getDrawable(
                     mContext, getMockAppIconResId()));
-
-            if (ENABLE_NEW_GESTURE_NAV_TUTORIAL.get()) {
-                mFakeLauncherView.setBackgroundColor(
-                        mContext.getColor(getSwipeActionColorResId()));
-            }
         }
     }