Fixes to all apps pull up work
am: 74b5af3529

Change-Id: I0e98279c3a77ec5503962bc1d220e8b001aa6e9d
diff --git a/src/com/android/launcher3/LauncherStateTransitionAnimation.java b/src/com/android/launcher3/LauncherStateTransitionAnimation.java
index 6cba2cb..d62c629 100644
--- a/src/com/android/launcher3/LauncherStateTransitionAnimation.java
+++ b/src/com/android/launcher3/LauncherStateTransitionAnimation.java
@@ -248,13 +248,12 @@
         // Cancel the current animation
         cancelAnimation();
 
-        if (!FeatureFlags.LAUNCHER3_ALL_APPS_PULL_UP) {
-            playCommonTransitionAnimations(toWorkspaceState, fromView, toView,
-                    animated, initialized, animation, revealDuration, layerViews);
-        }
         final View contentView = toView.getContentView();
 
         if (!animated || !initialized) {
+            playCommonTransitionAnimations(toWorkspaceState, fromView, toView,
+                    animated, initialized, animation, revealDuration, layerViews);
+
             toView.setTranslationX(0.0f);
             toView.setTranslationY(0.0f);
             toView.setScaleX(1.0f);
@@ -277,6 +276,9 @@
             return null;
         }
         if (animType == CIRCULAR_REVEAL) {
+            playCommonTransitionAnimations(toWorkspaceState, fromView, toView,
+                    animated, initialized, animation, revealDuration, layerViews);
+
             // Setup the reveal view animation
             final View revealView = toView.getRevealView();
 
@@ -421,9 +423,10 @@
                       cleanupAnimation();
                       pCb.onTransitionComplete();
                   }
-
             });
-            mAllAppsController.animateToAllApps(animation);
+            mAllAppsController.animateToAllApps(animation, revealDuration);
+            playCommonTransitionAnimations(toWorkspaceState, fromView, toView,
+                    animated, initialized, animation, revealDuration, layerViews);
 
             dispatchOnLauncherTransitionPrepare(fromView, animated, false);
             dispatchOnLauncherTransitionPrepare(toView, animated, false);
@@ -672,11 +675,9 @@
 
         boolean multiplePagesVisible = toWorkspaceState.hasMultipleVisiblePages;
 
-        if (!FeatureFlags.LAUNCHER3_ALL_APPS_PULL_UP) {
+        if (!animated || !initialized) {
             playCommonTransitionAnimations(toWorkspaceState, fromView, toView,
                     animated, initialized, animation, revealDuration, layerViews);
-        }
-        if (!animated || !initialized) {
             if (FeatureFlags.LAUNCHER3_ALL_APPS_PULL_UP) {
                 mAllAppsController.finishPullDown();
             }
@@ -697,6 +698,8 @@
             return null;
         }
         if (animType == CIRCULAR_REVEAL) {
+            playCommonTransitionAnimations(toWorkspaceState, fromView, toView,
+                    animated, initialized, animation, revealDuration, layerViews);
             final View revealView = fromView.getRevealView();
             final View contentView = fromView.getContentView();
 
@@ -876,7 +879,9 @@
                 }
 
             });
-            mAllAppsController.animateToWorkspace(animation);
+            mAllAppsController.animateToWorkspace(animation, revealDuration);
+            playCommonTransitionAnimations(toWorkspaceState, fromView, toView,
+                    animated, initialized, animation, revealDuration, layerViews);
 
             // Dispatch the prepare transition signal
             dispatchOnLauncherTransitionPrepare(fromView, animated, false);
diff --git a/src/com/android/launcher3/PagedView.java b/src/com/android/launcher3/PagedView.java
index bf9a421..9266793 100644
--- a/src/com/android/launcher3/PagedView.java
+++ b/src/com/android/launcher3/PagedView.java
@@ -1971,7 +1971,7 @@
         snapToPage(getPageNearestToCenterOfScreen(), PAGE_SNAP_ANIMATION_DURATION);
     }
 
-    private static class ScrollInterpolator implements Interpolator {
+    public static class ScrollInterpolator implements Interpolator {
         public ScrollInterpolator() {
         }
 
diff --git a/src/com/android/launcher3/allapps/AllAppsContainerView.java b/src/com/android/launcher3/allapps/AllAppsContainerView.java
index 779bd05..2c9f810 100644
--- a/src/com/android/launcher3/allapps/AllAppsContainerView.java
+++ b/src/com/android/launcher3/allapps/AllAppsContainerView.java
@@ -18,6 +18,7 @@
 import android.annotation.SuppressLint;
 import android.content.Context;
 import android.content.res.Resources;
+import android.graphics.Color;
 import android.graphics.Point;
 import android.graphics.Rect;
 import android.support.v7.widget.LinearLayoutManager;
@@ -450,6 +451,7 @@
             mSearchInput.setLayoutParams(llp);
 
             lp.height = height;
+            mSearchContainer.setBackground(null);
         }
         mSearchContainer.setLayoutParams(lp);
     }
diff --git a/src/com/android/launcher3/allapps/AllAppsTransitionController.java b/src/com/android/launcher3/allapps/AllAppsTransitionController.java
index 1428c2f..53a517c 100644
--- a/src/com/android/launcher3/allapps/AllAppsTransitionController.java
+++ b/src/com/android/launcher3/allapps/AllAppsTransitionController.java
@@ -8,12 +8,16 @@
 import android.util.Log;
 import android.view.MotionEvent;
 import android.view.View;
+import android.view.animation.AccelerateInterpolator;
 import android.view.animation.DecelerateInterpolator;
 import android.view.animation.Interpolator;
+import android.view.animation.LinearInterpolator;
 
+import com.android.launcher3.CellLayout;
 import com.android.launcher3.Hotseat;
 import com.android.launcher3.Launcher;
 import com.android.launcher3.LauncherAnimUtils;
+import com.android.launcher3.PagedView;
 import com.android.launcher3.util.TouchController;
 
 /**
@@ -31,7 +35,10 @@
     private static final String TAG = "AllAppsTrans";
     private static final boolean DBG = false;
 
-    private static final float ANIMATION_DURATION = 500;
+     private final Interpolator mAccelInterpolator = new AccelerateInterpolator(1f);
+
+    private static final float ANIMATION_DURATION = 2000;
+    private static final float FINAL_ALPHA = .6f;
 
     private AllAppsContainerView mAppsView;
     private Hotseat mHotseat;
@@ -48,7 +55,7 @@
     private float mProgressTransY;   // numerator
     private float mTranslation = -1; // denominator
 
-    private float mAnimationDuration;
+    private long mAnimationDuration;
     private float mCurY;
 
     private AnimatorSet mCurrentAnimation;
@@ -84,8 +91,6 @@
         }
         mAppsView = mLauncher.getAppsView();
         mHotseat = mLauncher.getHotseat();
-        mWorkspaceCurPage = mLauncher.getWorkspace().getChildAt(
-                mLauncher.getWorkspace().getCurrentPage());
 
         if (mHotseatBackground == null) {
             mHotseatBackground = mHotseat.getBackground();
@@ -97,21 +102,27 @@
     public void onScrollStart(boolean start) {
         cancelAnimation();
         mCurrentAnimation = LauncherAnimUtils.createAnimatorSet();
-        mCurY = mAppsView.getTranslationY();
         preparePull(start);
-
+        mCurY = mAppsView.getTranslationY();
     }
 
     /**
      * @param start {@code true} if start of new drag.
      */
     public void preparePull(boolean start) {
+        // TODO: create a method inside workspace to fetch this easily.
+        mWorkspaceCurPage = mLauncher.getWorkspace().getChildAt(
+                mLauncher.getWorkspace().getNextPage());
+        mHotseat.setVisibility(View.VISIBLE);
+        mHotseat.bringToFront();
         if (start) {
             if (!mLauncher.isAllAppsVisible()) {
                 mHotseat.setBackground(null);
                 mAppsView.setVisibility(View.VISIBLE);
                 mAppsView.getContentView().setVisibility(View.VISIBLE);
-                mAppsView.setAlpha(mHotseatAlpha);
+                mAppsView.getContentView().setBackground(null);
+                mAppsView.getRevealView().setVisibility(View.VISIBLE);
+                mAppsView.getRevealView().setAlpha(mHotseatAlpha);
                 mAppsView.setSearchBarVisible(false);
 
                 if (mTranslation < 0) {
@@ -119,16 +130,14 @@
                     setProgress(mTranslation);
                 }
             } else {
-                mLauncher.getWorkspace().setVisibility(View.VISIBLE);
-                mLauncher.getWorkspace().setAlpha(1f);
                 mLauncher.getWorkspace().onLauncherTransitionPrepare(mLauncher, false, false);
                 mWorkspaceCurPage.setVisibility(View.VISIBLE);
+                ((CellLayout) mWorkspaceCurPage).getShortcutsAndWidgets().setVisibility(View.VISIBLE);
+                ((CellLayout) mWorkspaceCurPage).getShortcutsAndWidgets().setAlpha(1f);
                 mAppsView.setSearchBarVisible(false);
                 setLightStatusBar(false);
             }
         }
-        mHotseat.setVisibility(View.VISIBLE);
-        mHotseat.bringToFront();
     }
 
     private void setLightStatusBar(boolean enable) {
@@ -144,8 +153,6 @@
         }
     }
 
-    private final Interpolator mAlphaInterpolator = new DecelerateInterpolator(.5f);
-
     @Override
     public boolean onScroll(float displacement, float velocity) {
         if (mAppsView == null) {
@@ -163,9 +170,12 @@
     public void setProgress(float progress) {
         mProgressTransY = progress;
         float alpha = calcAlphaAllApps(progress);
-        float workspaceHotseatAlpha = Math.max(mHotseatAlpha, 1 - alpha);
-        setTransAndAlpha(mAppsView, progress, Math.max(mHotseatAlpha, alpha));
-        setTransAndAlpha(mWorkspaceCurPage, -mTranslation + progress, workspaceHotseatAlpha);
+        float workspaceHotseatAlpha = 1 - alpha;
+
+        mAppsView.getRevealView().setAlpha(Math.min(FINAL_ALPHA, Math.max(mHotseatAlpha, alpha)));
+        mAppsView.getContentView().setAlpha(alpha);
+        mAppsView.setTranslationY(progress);
+        setTransAndAlpha(mWorkspaceCurPage, -mTranslation + progress, mAccelInterpolator.getInterpolation(workspaceHotseatAlpha));
         setTransAndAlpha(mHotseat, -mTranslation + progress, workspaceHotseatAlpha);
     }
 
@@ -174,7 +184,7 @@
     }
 
     private float calcAlphaAllApps(float progress) {
-        return mAlphaInterpolator.getInterpolation((mTranslation - progress)/mTranslation);
+        return ((mTranslation - progress)/mTranslation);
     }
 
     private void setTransAndAlpha(View v, float transY, float alpha) {
@@ -212,11 +222,11 @@
 
     private void calculateDuration(float velocity, float disp) {
         // TODO: make these values constants after tuning.
-        float velocityDivisor = Math.max(1, 0.75f * velocity);
+        float velocityDivisor = Math.max(1.5f, Math.abs(0.25f * velocity));
         float travelDistance = Math.max(0.2f, disp / mTranslation);
-        mAnimationDuration = Math.max(100, ANIMATION_DURATION / velocityDivisor * travelDistance);
-        if (true) { // MERONG
-            Log.d(TAG, String.format("calculateDuration=%f, v=%f, d=%f", mAnimationDuration, velocity, disp));
+        mAnimationDuration = (long) Math.max(100, ANIMATION_DURATION / velocityDivisor * travelDistance);
+        if (DBG) {
+            Log.d(TAG, String.format("calculateDuration=%d, v=%f, d=%f", mAnimationDuration, velocity, disp));
         }
     }
 
@@ -227,7 +237,7 @@
      */
     private void showAppsView() {
         if (mLauncher.isAllAppsVisible()) {
-            animateToAllApps(mCurrentAnimation);
+            animateToAllApps(mCurrentAnimation, mAnimationDuration);
             mCurrentAnimation.start();
         } else {
             mLauncher.showAppsView(true /* animated */, true /* resetListToTop */,
@@ -244,17 +254,18 @@
         if (mLauncher.isAllAppsVisible()) {
             mLauncher.showWorkspace(true /* animated */);
         } else {
-            animateToWorkspace(mCurrentAnimation);
+            animateToWorkspace(mCurrentAnimation, mAnimationDuration);
             mCurrentAnimation.start();
         }
     }
 
-    public void animateToAllApps(AnimatorSet animationOut) {
+    public void animateToAllApps(AnimatorSet animationOut, long duration) {
         if ((mAppsView = mLauncher.getAppsView()) == null || animationOut == null){
             return;
         }
         if (!mDetector.mScrolling) {
             preparePull(true);
+            mAnimationDuration = duration;
         }
         mCurY = mAppsView.getTranslationY();
         final float fromAllAppsTop = mAppsView.getTranslationY();
@@ -262,7 +273,8 @@
 
         ObjectAnimator driftAndAlpha = ObjectAnimator.ofFloat(this, "progress",
                 fromAllAppsTop, toAllAppsTop);
-        driftAndAlpha.setDuration((long) mAnimationDuration);
+        driftAndAlpha.setDuration(mAnimationDuration);
+        driftAndAlpha.setInterpolator(new PagedView.ScrollInterpolator());
         animationOut.play(driftAndAlpha);
 
         animationOut.addListener(new AnimatorListenerAdapter() {
@@ -291,19 +303,21 @@
         setLightStatusBar(true);
     }
 
-    public void animateToWorkspace(AnimatorSet animationOut) {
+    public void animateToWorkspace(AnimatorSet animationOut, long duration) {
         if ((mAppsView = mLauncher.getAppsView()) == null || animationOut == null){
             return;
         }
         if(!mDetector.mScrolling) {
             preparePull(true);
+            mAnimationDuration = duration;
         }
         final float fromAllAppsTop = mAppsView.getTranslationY();
         final float toAllAppsTop = mTranslation;
 
         ObjectAnimator driftAndAlpha = ObjectAnimator.ofFloat(this, "progress",
                 fromAllAppsTop, toAllAppsTop);
-        driftAndAlpha.setDuration((long) mAnimationDuration);
+        driftAndAlpha.setDuration(mAnimationDuration);
+        driftAndAlpha.setInterpolator(new PagedView.ScrollInterpolator());
         animationOut.play(driftAndAlpha);
 
         animationOut.addListener(new AnimatorListenerAdapter() {
diff --git a/src/com/android/launcher3/allapps/VerticalPullDetector.java b/src/com/android/launcher3/allapps/VerticalPullDetector.java
index 4cc921c..12d414e 100644
--- a/src/com/android/launcher3/allapps/VerticalPullDetector.java
+++ b/src/com/android/launcher3/allapps/VerticalPullDetector.java
@@ -21,7 +21,7 @@
     /**
      * The minimum release velocity in pixels per millisecond that triggers fling..
      */
-    private static final float RELEASE_VELOCITY_PX_MS = 1.7f;
+    private static final float RELEASE_VELOCITY_PX_MS = 1.0f;
 
     /**
      * The time constant used to calculate dampening in the low-pass filter of scroll velocity.
@@ -32,7 +32,7 @@
     /* Scroll state, this is set to true during dragging and animation. */
     boolean mScrolling;
 
-
+    float mDownX;
     float mDownY;
     float mDownMillis;
 
@@ -41,7 +41,8 @@
 
     float mVelocity;
     float mLastDisplacement;
-    float mDisplacement;
+    float mDisplacementY;
+    float mDisplacementX;
 
     /* scroll started during previous animation */
     boolean mSubtractSlop = true;
@@ -72,11 +73,17 @@
     }
 
     private boolean shouldScrollStart() {
-        if (mAllAppsVisible && mDisplacement > mTouchSlop && mAllAppsScrollAtTop) {
-            return true;
+        float deltaY = Math.abs(mDisplacementY);
+        float deltaX = Math.max(Math.abs(mDisplacementX), 1);
+        if (mAllAppsVisible && mDisplacementY > mTouchSlop && mAllAppsScrollAtTop) {
+            if (deltaY > deltaX) {
+                return true;
+            }
         }
-        if (!mAllAppsVisible && mDisplacement < -mTouchSlop) {
-            return true;
+        if (!mAllAppsVisible && mDisplacementY < -mTouchSlop) {
+            if (deltaY > deltaX) {
+                return true;
+            }
         }
         return false;
     }
@@ -85,6 +92,7 @@
         switch (ev.getAction()) {
             case MotionEvent.ACTION_DOWN:
                 mDownMillis = ev.getDownTime();
+                mDownX = ev.getX();
                 mDownY = ev.getY();
                 mLastDisplacement = 0;
                 mVelocity = 0;
@@ -94,7 +102,8 @@
                 }
                 break;
             case MotionEvent.ACTION_MOVE:
-                mDisplacement = computeDisplacement(ev);
+                mDisplacementX = ev.getX() - mDownX;
+                mDisplacementY = ev.getY() - mDownY;
                 mVelocity = computeVelocity(ev, mVelocity);
 
                 if (!mScrolling && shouldScrollStart()) {
@@ -117,7 +126,7 @@
                 break;
         }
         // Do house keeping.
-        mLastDisplacement = mDisplacement;
+        mLastDisplacement = mDisplacementY;
 
         mLastY = ev.getY();
         mLastMillis = ev.getEventTime();
@@ -138,13 +147,17 @@
     }
 
     private boolean reportScroll() {
-        float delta = mDisplacement - mLastDisplacement;
+        float delta = mDisplacementY - mLastDisplacement;
         if (delta != 0) {
             if (DBG) {
                 Log.d(TAG, String.format("onScroll disp=%.1f, velocity=%.1f",
-                        mDisplacement, mVelocity));
+                        mDisplacementY, mVelocity));
             }
-            return mListener.onScroll(mDisplacement - (mSubtractSlop? mTouchSlop : 0), mVelocity);
+            if (mDisplacementY > 0) {
+                return mListener.onScroll(mDisplacementY - mTouchSlop, mVelocity);
+            } else {
+                return mListener.onScroll(mDisplacementY + mTouchSlop, mVelocity);
+            }
         }
         return true;
     }
@@ -152,7 +165,7 @@
     private void reportScrollEnd() {
         if (DBG) {
             Log.d(TAG, String.format("onScrolEnd disp=%.1f, velocity=%.1f",
-                    mDisplacement, mVelocity));
+                    mDisplacementY, mVelocity));
         }
         mListener.onScrollEnd(mVelocity, Math.abs(mVelocity) > RELEASE_VELOCITY_PX_MS);
     }