Merge "Use global color extraction in widgets for wallpaper preview" into sc-v2-dev
diff --git a/quickstep/src/com/android/launcher3/appprediction/PredictionRowView.java b/quickstep/src/com/android/launcher3/appprediction/PredictionRowView.java
index de04082..6afbf9a 100644
--- a/quickstep/src/com/android/launcher3/appprediction/PredictionRowView.java
+++ b/quickstep/src/com/android/launcher3/appprediction/PredictionRowView.java
@@ -96,6 +96,13 @@
 
     private void updateVisibility() {
         setVisibility(mPredictionsEnabled ? VISIBLE : GONE);
+        if (mLauncher.getAppsView() != null) {
+            if (mPredictionsEnabled) {
+                mLauncher.getAppsView().getAppsStore().registerIconContainer(this);
+            } else {
+                mLauncher.getAppsView().getAppsStore().unregisterIconContainer(this);
+            }
+        }
     }
 
     @Override
diff --git a/quickstep/src/com/android/quickstep/views/RecentsView.java b/quickstep/src/com/android/quickstep/views/RecentsView.java
index 6844f9f..9dd4cf0 100644
--- a/quickstep/src/com/android/quickstep/views/RecentsView.java
+++ b/quickstep/src/com/android/quickstep/views/RecentsView.java
@@ -2599,6 +2599,7 @@
     }
 
     protected void onDismissAnimationEnds() {
+        AccessibilityManagerCompat.sendDismissAnimationEndsEventToTest(getContext());
     }
 
     public PendingAnimation createAllTasksDismissAnimation(long duration) {
diff --git a/src/com/android/launcher3/allapps/AllAppsStore.java b/src/com/android/launcher3/allapps/AllAppsStore.java
index 2443b83..7bc3eec 100644
--- a/src/com/android/launcher3/allapps/AllAppsStore.java
+++ b/src/com/android/launcher3/allapps/AllAppsStore.java
@@ -132,7 +132,7 @@
     }
 
     public void registerIconContainer(ViewGroup container) {
-        if (container != null) {
+        if (container != null && !mIconContainers.contains(container)) {
             mIconContainers.add(container);
         }
     }
diff --git a/src/com/android/launcher3/allapps/DiscoveryBounce.java b/src/com/android/launcher3/allapps/DiscoveryBounce.java
index d8ef18e..be261f7 100644
--- a/src/com/android/launcher3/allapps/DiscoveryBounce.java
+++ b/src/com/android/launcher3/allapps/DiscoveryBounce.java
@@ -20,16 +20,17 @@
 
 import android.animation.Animator;
 import android.animation.AnimatorInflater;
-import android.animation.AnimatorListenerAdapter;
 import android.os.Handler;
 import android.os.UserManager;
 import android.view.MotionEvent;
+import android.view.View;
 
 import com.android.launcher3.AbstractFloatingView;
 import com.android.launcher3.Launcher;
 import com.android.launcher3.LauncherState;
 import com.android.launcher3.R;
 import com.android.launcher3.Utilities;
+import com.android.launcher3.anim.AnimatorListeners;
 import com.android.launcher3.statemanager.StateManager.StateListener;
 import com.android.launcher3.util.OnboardingPrefs;
 
@@ -53,21 +54,15 @@
         public void onStateTransitionComplete(LauncherState finalState) {}
     };
 
-    public DiscoveryBounce(Launcher launcher, float delta) {
+    public DiscoveryBounce(Launcher launcher) {
         super(launcher, null);
         mLauncher = launcher;
-        AllAppsTransitionController controller = mLauncher.getAllAppsController();
 
         mDiscoBounceAnimation =
                 AnimatorInflater.loadAnimator(launcher, R.animator.discovery_bounce);
-        mDiscoBounceAnimation.setTarget(new VerticalProgressWrapper(controller, delta));
-        mDiscoBounceAnimation.addListener(new AnimatorListenerAdapter() {
-            @Override
-            public void onAnimationEnd(Animator animation) {
-                handleClose(false);
-            }
-        });
-        mDiscoBounceAnimation.addListener(controller.getProgressAnimatorListener());
+        mDiscoBounceAnimation.setTarget(new VerticalProgressWrapper(
+                launcher.getHotseat(), mLauncher.getDragLayer().getHeight()));
+        mDiscoBounceAnimation.addListener(AnimatorListeners.forEndCallback(this::handleClose));
         launcher.getStateManager().addStateListener(mStateListener);
     }
 
@@ -104,9 +99,9 @@
         if (mIsOpen) {
             mIsOpen = false;
             mLauncher.getDragLayer().removeView(this);
-            // Reset the all-apps progress to what ever it was previously.
-            mLauncher.getAllAppsController().setProgress(mLauncher.getStateManager()
-                    .getState().getVerticalProgress(mLauncher));
+            // Reset the translation to what ever it was previously.
+            mLauncher.getHotseat().setTranslationY(mLauncher.getStateManager().getState()
+                    .getHotseatScaleAndTranslation(mLauncher).translationY);
             mLauncher.getStateManager().removeStateListener(mStateListener);
         }
     }
@@ -141,29 +136,28 @@
             return;
         }
         onboardingPrefs.incrementEventCount(OnboardingPrefs.HOME_BOUNCE_COUNT);
-
-        new DiscoveryBounce(launcher, 0).show();
+        new DiscoveryBounce(launcher).show();
     }
 
     /**
-     * A wrapper around {@link AllAppsTransitionController} allowing a fixed shift in the value.
+     * A wrapper around hotseat animator allowing a fixed shift in the value.
      */
     public static class VerticalProgressWrapper {
 
-        private final float mDelta;
-        private final AllAppsTransitionController mController;
+        private final View mView;
+        private final float mLimit;
 
-        private VerticalProgressWrapper(AllAppsTransitionController controller, float delta) {
-            mController = controller;
-            mDelta = delta;
+        private VerticalProgressWrapper(View view, float limit) {
+            mView = view;
+            mLimit = limit;
         }
 
         public float getProgress() {
-            return mController.getProgress() + mDelta;
+            return 1 + mView.getTranslationY() / mLimit;
         }
 
         public void setProgress(float progress) {
-            mController.setProgress(progress - mDelta);
+            mView.setTranslationY(mLimit * (progress - 1));
         }
     }
 }
diff --git a/src/com/android/launcher3/compat/AccessibilityManagerCompat.java b/src/com/android/launcher3/compat/AccessibilityManagerCompat.java
index 92bc19a..97052b2 100644
--- a/src/com/android/launcher3/compat/AccessibilityManagerCompat.java
+++ b/src/com/android/launcher3/compat/AccessibilityManagerCompat.java
@@ -87,7 +87,14 @@
         if (accessibilityManager == null) return;
 
         sendEventToTest(accessibilityManager, context, TestProtocol.PAUSE_DETECTED_MESSAGE, null);
-        Log.d(TestProtocol.HOME_TO_OVERVIEW_FLAKY, "sendPauseDetectedEventToTest");
+    }
+
+    public static void sendDismissAnimationEndsEventToTest(Context context) {
+        final AccessibilityManager accessibilityManager = getAccessibilityManagerForTest(context);
+        if (accessibilityManager == null) return;
+
+        sendEventToTest(accessibilityManager, context, TestProtocol.DISMISS_ANIMATION_ENDS_MESSAGE,
+                null);
     }
 
     private static void sendEventToTest(
diff --git a/src/com/android/launcher3/testing/TestProtocol.java b/src/com/android/launcher3/testing/TestProtocol.java
index a9d3998..65bec25 100644
--- a/src/com/android/launcher3/testing/TestProtocol.java
+++ b/src/com/android/launcher3/testing/TestProtocol.java
@@ -24,6 +24,7 @@
     public static final String SWITCHED_TO_STATE_MESSAGE = "TAPL_SWITCHED_TO_STATE";
     public static final String SCROLL_FINISHED_MESSAGE = "TAPL_SCROLL_FINISHED";
     public static final String PAUSE_DETECTED_MESSAGE = "TAPL_PAUSE_DETECTED";
+    public static final String DISMISS_ANIMATION_ENDS_MESSAGE = "TAPL_DISMISS_ANIMATION_ENDS";
     public static final int NORMAL_STATE_ORDINAL = 0;
     public static final int SPRING_LOADED_STATE_ORDINAL = 1;
     public static final int OVERVIEW_STATE_ORDINAL = 2;
@@ -111,5 +112,4 @@
     public static final String PERMANENT_DIAG_TAG = "TaplTarget";
     public static final String WORK_PROFILE_REMOVED = "b/159671700";
     public static final String FALLBACK_ACTIVITY_NO_SET = "b/181019015";
-    public static final String HOME_TO_OVERVIEW_FLAKY = "b/193440212";
 }
diff --git a/src/com/android/launcher3/views/FloatingIconView.java b/src/com/android/launcher3/views/FloatingIconView.java
index 3027db6..872adec 100644
--- a/src/com/android/launcher3/views/FloatingIconView.java
+++ b/src/com/android/launcher3/views/FloatingIconView.java
@@ -580,11 +580,6 @@
                     if (originalView instanceof IconLabelDotView) {
                         setIconAndDotVisible(originalView, true);
                     }
-                    if (originalView instanceof BubbleTextView) {
-                        BubbleTextView btv = (BubbleTextView) originalView;
-                        btv.setIconVisible(true);
-                        btv.setForceHideDot(true);
-                    }
                     view.finish(dragLayer);
                 }
             } else {
diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
index ef809d5..1e7f8a5 100644
--- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
+++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
@@ -207,6 +207,11 @@
     public LauncherInstrumentation(Instrumentation instrumentation) {
         mInstrumentation = instrumentation;
         mDevice = UiDevice.getInstance(instrumentation);
+        try {
+            mDevice.executeShellCommand("am wait-for-broadcast-idle");
+        } catch (IOException e) {
+            log("Failed to wait for broadcast idle");
+        }
 
         // Launcher should run in test harness so that custom accessibility protocol between
         // Launcher and TAPL is enabled. In-process tests enable this protocol with a direct call
diff --git a/tests/tapl/com/android/launcher3/tapl/OverviewTask.java b/tests/tapl/com/android/launcher3/tapl/OverviewTask.java
index 657b74d..71c0abb 100644
--- a/tests/tapl/com/android/launcher3/tapl/OverviewTask.java
+++ b/tests/tapl/com/android/launcher3/tapl/OverviewTask.java
@@ -59,9 +59,14 @@
             final Rect taskBounds = mLauncher.getVisibleBounds(mTask);
             final int centerX = taskBounds.centerX();
             final int centerY = taskBounds.centerY();
-            mLauncher.linearGesture(centerX, centerY, centerX, 0, 10, false,
-                    LauncherInstrumentation.GestureScope.INSIDE);
-            mLauncher.waitForIdle();
+            mLauncher.executeAndWaitForLauncherEvent(
+                    () -> mLauncher.linearGesture(centerX, centerY, centerX, 0, 10, false,
+                            LauncherInstrumentation.GestureScope.INSIDE),
+                    event -> TestProtocol.DISMISS_ANIMATION_ENDS_MESSAGE.equals(
+                            event.getClassName()),
+                    () -> "Didn't receive a dismiss animation ends message: " + centerX + ", "
+                            + centerY,
+                    "swiping to dismiss");
         }
     }