Merge "Fetching assist data only if required by overlay" into ub-launcher3-edmonton-polish
diff --git a/quickstep/src/com/android/launcher3/LauncherAppTransitionManagerImpl.java b/quickstep/src/com/android/launcher3/LauncherAppTransitionManagerImpl.java
index 4108cd2..252e3ea 100644
--- a/quickstep/src/com/android/launcher3/LauncherAppTransitionManagerImpl.java
+++ b/quickstep/src/com/android/launcher3/LauncherAppTransitionManagerImpl.java
@@ -57,6 +57,7 @@
 import android.os.Handler;
 import android.os.Looper;
 import android.util.Pair;
+import android.util.Property;
 import android.view.View;
 import android.view.ViewGroup;
 
@@ -804,25 +805,9 @@
                 float shiftRange = allAppsController.getShiftRange();
                 float slideStart = shiftRange / (shiftRange - mStartSlideTransY);
                 float oscillateStart = shiftRange / (shiftRange - mEndSlideTransY);
-                // Ensures a clean hand-off between slide and oscillate.
-                float slideEnd = Utilities.mapToRange(0, 0, 1f, oscillateStart, 1, OSCILLATE);
 
-                allAppsController.setProgress(slideStart);
-                Animator slideIn = ObjectAnimator.ofFloat(allAppsController, ALL_APPS_PROGRESS,
-                        slideStart, slideEnd);
-                slideIn.setDuration(SPRING_SLIDE_DURATION);
-                slideIn.setInterpolator(DEACCEL);
-
-                Animator oscillate = ObjectAnimator.ofFloat(allAppsController, ALL_APPS_PROGRESS,
-                        oscillateStart, 1f);
-                oscillate.setDuration(SPRING_OSCILLATE_DURATION);
-                oscillate.setInterpolator(OSCILLATE);
-
-                Animator settle = ObjectAnimator.ofFloat(allAppsController, ALL_APPS_PROGRESS, 1f);
-                settle.setDuration(SPRING_SETTLE_DURATION);
-                settle.setInterpolator(LINEAR);
-
-                workspaceAnimator.playSequentially(slideIn, oscillate, settle);
+                buildSpringAnimation(workspaceAnimator, allAppsController, ALL_APPS_PROGRESS,
+                        0 /* startDelay */, slideStart, oscillateStart, 1f /* finalPosition */);
             }
 
             mDragLayer.getScrim().hideSysUiScrim(true);
@@ -852,28 +837,13 @@
         v.setAlpha(0);
         ObjectAnimator alpha = ObjectAnimator.ofFloat(v, View.ALPHA, 1f);
         alpha.setInterpolator(LINEAR);
-        alpha.setDuration(SPRING_SLIDE_DURATION);
+        alpha.setDuration(SPRING_SLIDE_DURATION + SPRING_OSCILLATE_DURATION);
         alpha.setStartDelay(startDelay);
         outAnimator.play(alpha);
 
-        // Ensures a clean hand-off between slide and oscillate.
-        float slideEnd = Utilities.mapToRange(0, 0, 1f, mEndSlideTransY, 0, OSCILLATE);
-        v.setTranslationY(mStartSlideTransY);
-        ObjectAnimator slideIn = ObjectAnimator.ofFloat(v, TRANSLATION_Y, mStartSlideTransY,
-                slideEnd);
-        slideIn.setInterpolator(DEACCEL);
-        slideIn.setStartDelay(startDelay);
-        slideIn.setDuration(SPRING_SLIDE_DURATION);
+        buildSpringAnimation(outAnimator, v, TRANSLATION_Y, startDelay, mStartSlideTransY,
+                mEndSlideTransY, 0f /* finalPosition */);
 
-        ObjectAnimator oscillate = ObjectAnimator.ofFloat(v, TRANSLATION_Y, mEndSlideTransY, 0);
-        oscillate.setInterpolator(OSCILLATE);
-        oscillate.setDuration(SPRING_OSCILLATE_DURATION);
-
-        ObjectAnimator settle = ObjectAnimator.ofFloat(v, TRANSLATION_Y, 0);
-        settle.setInterpolator(LINEAR);
-        settle.setDuration(SPRING_SETTLE_DURATION);
-
-        outAnimator.playSequentially(slideIn, oscillate, settle);
         outAnimator.addListener(new AnimatorListenerAdapter() {
             @Override
             public void onAnimationEnd(Animator animation) {
@@ -883,6 +853,36 @@
         });
     }
 
+    /**
+     * Spring animations consists of three sequential animators: a slide, an oscillation, and
+     * a settle.
+     */
+    private <T> void buildSpringAnimation(AnimatorSet outAnimator, T objectToSpring,
+            Property<T, Float> property, long startDelay, float slideStart, float oscillateStart,
+            float finalPosition) {
+        // Ensures a clean hand-off between slide and oscillate.
+        float slideEnd = Utilities.mapToRange(0, 0, 1f, oscillateStart, finalPosition, OSCILLATE);
+
+        property.set(objectToSpring, slideStart);
+
+        ObjectAnimator slideIn = ObjectAnimator.ofFloat(objectToSpring, property, slideStart,
+                slideEnd);
+        slideIn.setInterpolator(DEACCEL);
+        slideIn.setStartDelay(startDelay);
+        slideIn.setDuration(SPRING_SLIDE_DURATION);
+
+        ObjectAnimator oscillate = ObjectAnimator.ofFloat(objectToSpring, property, oscillateStart,
+                finalPosition);
+        oscillate.setInterpolator(OSCILLATE);
+        oscillate.setDuration(SPRING_OSCILLATE_DURATION);
+
+        ObjectAnimator settle = ObjectAnimator.ofFloat(objectToSpring, property, finalPosition);
+        settle.setInterpolator(LINEAR);
+        settle.setDuration(SPRING_SETTLE_DURATION);
+
+        outAnimator.playSequentially(slideIn, oscillate, settle);
+    }
+
     private void resetContentView() {
         mLauncher.getWorkspace().getPageIndicator().skipAnimationsToEnd();
         mDragLayerAlpha.setValue(1f);
diff --git a/quickstep/src/com/android/quickstep/views/ClearAllButton.java b/quickstep/src/com/android/quickstep/views/ClearAllButton.java
index 3911931..fbecd84 100644
--- a/quickstep/src/com/android/quickstep/views/ClearAllButton.java
+++ b/quickstep/src/com/android/quickstep/views/ClearAllButton.java
@@ -54,7 +54,7 @@
     public void setContentAlpha(float alpha) {
         if (mContentAlpha != alpha) {
             mContentAlpha = alpha;
-            setAlpha(mScrollAlpha * mContentAlpha);
+            updateAlpha();
         }
     }
 
@@ -68,6 +68,12 @@
         float shift = Math.min(scrollState.scrollFromEdge, width);
         setTranslationX(mIsRtl ? (mScrollOffset - shift) : (mScrollOffset + shift));
         mScrollAlpha = 1 - shift / width;
-        setAlpha(mScrollAlpha * mContentAlpha);
+        updateAlpha();
+    }
+
+    private void updateAlpha() {
+        final float alpha = mScrollAlpha * mContentAlpha;
+        setAlpha(alpha);
+        setClickable(alpha == 1);
     }
 }
diff --git a/src/com/android/launcher3/anim/Interpolators.java b/src/com/android/launcher3/anim/Interpolators.java
index efb08a1..8a1abf4 100644
--- a/src/com/android/launcher3/anim/Interpolators.java
+++ b/src/com/android/launcher3/anim/Interpolators.java
@@ -121,7 +121,7 @@
         // Used to scale the oscillations horizontally
         private final float horizontalScale = 1f;
         // Used to shift the oscillations horizontally
-        private final float horizontalShift = 05f;
+        private final float horizontalShift = 0.5f;
         // Used to scale the oscillations vertically
         private final float verticalScale = 1f;
         // Used to shift the oscillations vertically
diff --git a/src/com/android/launcher3/touch/AbstractStateChangeTouchController.java b/src/com/android/launcher3/touch/AbstractStateChangeTouchController.java
index d478d48..55f850c 100644
--- a/src/com/android/launcher3/touch/AbstractStateChangeTouchController.java
+++ b/src/com/android/launcher3/touch/AbstractStateChangeTouchController.java
@@ -283,7 +283,9 @@
     protected void updateProgress(float fraction) {
         mCurrentAnimation.setPlayFraction(fraction);
         if (mAtomicComponentsController != null) {
-            mAtomicComponentsController.setPlayFraction(fraction - mAtomicComponentsStartProgress);
+            // Make sure we don't divide by 0, and have at least a small runway.
+            float start = Math.min(mAtomicComponentsStartProgress, 0.9f);
+            mAtomicComponentsController.setPlayFraction((fraction - start) / (1 - start));
         }
         maybeUpdateAtomicAnim(mFromState, mToState, fraction);
     }
diff --git a/tests/src/com/android/launcher3/ui/widget/BindWidgetTest.java b/tests/src/com/android/launcher3/ui/widget/BindWidgetTest.java
index 6c712f4..b557119 100644
--- a/tests/src/com/android/launcher3/ui/widget/BindWidgetTest.java
+++ b/tests/src/com/android/launcher3/ui/widget/BindWidgetTest.java
@@ -49,6 +49,7 @@
 
 import org.junit.After;
 import org.junit.Before;
+import org.junit.Ignore;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -122,6 +123,7 @@
         setupAndVerifyContents(item, LauncherAppWidgetHostView.class, info.label);
     }
 
+    @Test @Ignore
     public void testUnboundWidget_removed() throws Exception {
         LauncherAppWidgetProviderInfo info = findWidgetProvider(false);
         LauncherAppWidgetInfo item = createWidgetInfo(info, false);
@@ -176,6 +178,7 @@
                         LauncherSettings.Favorites.APPWIDGET_ID))));
     }
 
+    @Test @Ignore
     public void testPendingWidget_notRestored_removed() throws Exception {
         LauncherAppWidgetInfo item = getInvalidWidgetInfo();
         item.restoreStatus = LauncherAppWidgetInfo.FLAG_ID_NOT_VALID