Merge "Improving error messages when swiping up to home" into ub-launcher3-master
diff --git a/Android.bp b/Android.bp
index 4c38205..fc99880 100644
--- a/Android.bp
+++ b/Android.bp
@@ -30,3 +30,19 @@
     manifest: "tests/tapl/AndroidManifest.xml",
     platform_apis: true,
 }
+
+java_library_static {
+    name: "launcher-log-protos-lite",
+    srcs: [
+        "protos/*.proto",
+        "proto_overrides/*.proto",
+    ],
+    sdk_version: "current",
+    proto: {
+        type: "lite",
+        local_include_dirs:[
+            "protos",
+            "proto_overrides",
+        ],
+    },
+}
diff --git a/quickstep/recents_ui_overrides/src/com/android/launcher3/uioverrides/touchcontrollers/NoButtonQuickSwitchTouchController.java b/quickstep/recents_ui_overrides/src/com/android/launcher3/uioverrides/touchcontrollers/NoButtonQuickSwitchTouchController.java
index 54d165f..9ad0638 100644
--- a/quickstep/recents_ui_overrides/src/com/android/launcher3/uioverrides/touchcontrollers/NoButtonQuickSwitchTouchController.java
+++ b/quickstep/recents_ui_overrides/src/com/android/launcher3/uioverrides/touchcontrollers/NoButtonQuickSwitchTouchController.java
@@ -395,8 +395,8 @@
             updateNonOverviewAnim(targetState, new AnimatorSetBuilder(), 0 /* animComponents */);
             nonOverviewAnim = mNonOverviewAnim.getAnimationPlayer();
 
-            new StaggeredWorkspaceAnim(mLauncher, null, velocity.y,
-                    false /* animateOverviewScrim */).start();
+            new StaggeredWorkspaceAnim(mLauncher, velocity.y, false /* animateOverviewScrim */)
+                    .start();
         } else {
             boolean canceled = targetState == NORMAL;
             if (canceled) {
diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/LauncherActivityInterface.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/LauncherActivityInterface.java
index 5b6f7fe..28fc3da 100644
--- a/quickstep/recents_ui_overrides/src/com/android/quickstep/LauncherActivityInterface.java
+++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/LauncherActivityInterface.java
@@ -191,8 +191,8 @@
 
             @Override
             public void playAtomicAnimation(float velocity) {
-                new StaggeredWorkspaceAnim(launcher, workspaceView, velocity,
-                        true /* animateOverviewScrim */).start();
+                new StaggeredWorkspaceAnim(launcher, velocity, true /* animateOverviewScrim */)
+                        .start();
             }
         };
     }
diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/util/StaggeredWorkspaceAnim.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/util/StaggeredWorkspaceAnim.java
index 3dbe1ad..babf13e 100644
--- a/quickstep/recents_ui_overrides/src/com/android/quickstep/util/StaggeredWorkspaceAnim.java
+++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/util/StaggeredWorkspaceAnim.java
@@ -28,8 +28,6 @@
 import android.view.View;
 import android.view.ViewGroup;
 
-import androidx.annotation.Nullable;
-
 import com.android.launcher3.CellLayout;
 import com.android.launcher3.DeviceProfile;
 import com.android.launcher3.Launcher;
@@ -43,7 +41,6 @@
 import com.android.launcher3.anim.PropertySetter;
 import com.android.launcher3.anim.SpringAnimationBuilder;
 import com.android.launcher3.graphics.OverviewScrim;
-import com.android.launcher3.views.IconLabelDotView;
 import com.android.quickstep.views.RecentsView;
 
 /**
@@ -64,20 +61,12 @@
     private final float mVelocity;
     private final float mSpringTransY;
 
-    // The original view of the {@link FloatingIconView}.
-    private final View mOriginalView;
-
     private final AnimatorSet mAnimators = new AnimatorSet();
 
-    /**
-     * @param floatingViewOriginalView The FloatingIconView's original view.
-     */
-    public StaggeredWorkspaceAnim(Launcher launcher, @Nullable View floatingViewOriginalView,
-            float velocity, boolean animateOverviewScrim) {
+    public StaggeredWorkspaceAnim(Launcher launcher, float velocity, boolean animateOverviewScrim) {
         prepareToAnimate(launcher);
 
         mVelocity = velocity;
-        mOriginalView = floatingViewOriginalView;
 
         // Scale the translationY based on the initial velocity to better sync the workspace items
         // with the floating view.
@@ -198,35 +187,12 @@
         springTransY.setStartDelay(startDelay);
         mAnimators.play(springTransY);
 
-        ObjectAnimator alpha = getAlphaAnimator(v, startDelay);
-        if (v == mOriginalView) {
-            // For IconLabelDotViews, we just want the label to fade in.
-            // Icon, badge, and dots will animate in separately (controlled via FloatingIconView)
-            if (v instanceof IconLabelDotView) {
-                alpha.addListener(new AnimatorListenerAdapter() {
-                    @Override
-                    public void onAnimationStart(Animator animation) {
-                        IconLabelDotView view = (IconLabelDotView) v;
-                        view.setIconVisible(false);
-                        view.setForceHideDot(true);
-                    }
-                });
-            } else {
-                return;
-            }
-        }
-
         v.setAlpha(0);
-        mAnimators.play(alpha);
-    }
-
-    private ObjectAnimator getAlphaAnimator(View v, long startDelay) {
         ObjectAnimator alpha = ObjectAnimator.ofFloat(v, View.ALPHA, 0f, 1f);
         alpha.setInterpolator(LINEAR);
         alpha.setDuration(ALPHA_DURATION_MS);
         alpha.setStartDelay(startDelay);
-        return alpha;
-
+        mAnimators.play(alpha);
     }
 
     private void addScrimAnimationForState(Launcher launcher, LauncherState state, long duration) {
diff --git a/src/com/android/launcher3/views/FloatingIconView.java b/src/com/android/launcher3/views/FloatingIconView.java
index c63d745..0c9a28b 100644
--- a/src/com/android/launcher3/views/FloatingIconView.java
+++ b/src/com/android/launcher3/views/FloatingIconView.java
@@ -560,7 +560,7 @@
      * Checks if the icon result is loaded. If true, we set the icon immediately. Else, we add a
      * callback to set the icon once the icon result is loaded.
      */
-    private void checkIconResult(View originalView, boolean isOpening) {
+    private void checkIconResult(View originalView) {
         CancellationSignal cancellationSignal = new CancellationSignal();
 
         if (mIconLoadResult == null) {
@@ -572,9 +572,7 @@
             if (mIconLoadResult.isIconLoaded) {
                 setIcon(originalView, mIconLoadResult.drawable, mIconLoadResult.badge,
                         mIconLoadResult.iconOffset);
-                if (isOpening) {
-                    hideOriginalView(originalView);
-                }
+                hideOriginalView(originalView);
             } else {
                 mIconLoadResult.onIconLoaded = () -> {
                     if (cancellationSignal.isCanceled()) {
@@ -585,10 +583,7 @@
                             mIconLoadResult.iconOffset);
 
                     setVisibility(VISIBLE);
-                    if (isOpening) {
-                        // Delay swapping views until the icon is loaded to prevent a flash.
-                        hideOriginalView(originalView);
-                    }
+                    hideOriginalView(originalView);
                 };
                 mLoadIconSignal = cancellationSignal;
             }
@@ -596,9 +591,9 @@
     }
 
     private void hideOriginalView(View originalView) {
-        if (originalView instanceof BubbleTextView) {
-            ((BubbleTextView) originalView).setIconVisible(false);
-            ((BubbleTextView) originalView).setForceHideDot(true);
+        if (originalView instanceof IconLabelDotView) {
+            ((IconLabelDotView) originalView).setIconVisible(false);
+            ((IconLabelDotView) originalView).setForceHideDot(true);
         } else {
             originalView.setVisibility(INVISIBLE);
         }
@@ -674,6 +669,9 @@
     }
 
     public void fastFinish() {
+        if (mLoadIconSignal != null) {
+            mLoadIconSignal.cancel();
+        }
         if (mEndRunnable != null) {
             mEndRunnable.run();
             mEndRunnable = null;
@@ -689,6 +687,10 @@
         if (mIconLoadResult != null && mIconLoadResult.isIconLoaded) {
             setVisibility(View.VISIBLE);
         }
+        if (!mIsOpening) {
+            // When closing an app, we want the item on the workspace to be invisible immediately
+            hideOriginalView(mOriginalIcon);
+        }
     }
 
     @Override
@@ -798,7 +800,7 @@
         // Must be called after the fastFinish listener and end runnable is created so that
         // the icon is not left in a hidden state.
         if (shouldLoadIcon) {
-            view.checkIconResult(originalView, isOpening);
+            view.checkIconResult(originalView);
         }
 
         return view;
@@ -842,6 +844,7 @@
                 @Override
                 public void onAnimationStart(Animator animation) {
                     btv.setIconVisible(true);
+                    btv.setForceHideDot(true);
                 }
             });
             fade.play(ObjectAnimator.ofInt(btv.getIcon(), DRAWABLE_ALPHA, 0, 255));
diff --git a/tests/Android.mk b/tests/Android.mk
index 31a9960..83fdddc 100644
--- a/tests/Android.mk
+++ b/tests/Android.mk
@@ -50,7 +50,8 @@
     androidx.test.runner \
     androidx.test.rules \
     androidx.test.uiautomator_uiautomator \
-    mockito-target-minus-junit4
+    mockito-target-minus-junit4 \
+    launcher-log-protos-lite
 
 ifneq (,$(wildcard frameworks/base))
     LOCAL_PRIVATE_PLATFORM_APIS := true
diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
index 2037e30..ccf98ae 100644
--- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
+++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
@@ -875,12 +875,17 @@
         final Point start = new Point(startX, startY);
         final Point end = new Point(endX, endY);
         sendPointer(downTime, downTime, MotionEvent.ACTION_DOWN, start);
+        final long endTime = movePointer(start, end, steps, downTime, slowDown);
+        sendPointer(downTime, endTime, MotionEvent.ACTION_UP, end);
+    }
+
+    long movePointer(Point start, Point end, int steps, long downTime, boolean slowDown) {
         long endTime = movePointer(downTime, downTime, steps * GESTURE_STEP_MS, start, end);
         if (slowDown) {
             endTime = movePointer(downTime, endTime + GESTURE_STEP_MS, 5 * GESTURE_STEP_MS, end,
                     end);
         }
-        sendPointer(downTime, endTime, MotionEvent.ACTION_UP, end);
+        return endTime;
     }
 
     void waitForIdle() {
diff --git a/tests/tapl/com/android/launcher3/tapl/Workspace.java b/tests/tapl/com/android/launcher3/tapl/Workspace.java
index 3301dd8..81d343d 100644
--- a/tests/tapl/com/android/launcher3/tapl/Workspace.java
+++ b/tests/tapl/com/android/launcher3/tapl/Workspace.java
@@ -39,7 +39,6 @@
  * Operations on the workspace screen.
  */
 public final class Workspace extends Home {
-    private static final int DRAG_DURATION = 500;
     private static final int FLING_STEPS = 10;
     private final UiObject2 mHotseat;
 
@@ -170,8 +169,7 @@
         LauncherInstrumentation.log("dragIconToWorkspace: sent down");
         launcher.waitForLauncherObject(longPressIndicator);
         LauncherInstrumentation.log("dragIconToWorkspace: indicator");
-        launcher.movePointer(
-                downTime, SystemClock.uptimeMillis(), DRAG_DURATION, launchableCenter, dest);
+        launcher.movePointer(launchableCenter, dest, 10, downTime, true);
         LauncherInstrumentation.log("dragIconToWorkspace: moved pointer");
         launcher.sendPointer(
                 downTime, SystemClock.uptimeMillis(), MotionEvent.ACTION_UP, dest);