Fixing a crash on APPS->WORKSPACE transition when animation is automated without dragging.
b/29424335

Change-Id: I2b109423b5a4cfc94fcda75fdea936785373968f
diff --git a/src/com/android/launcher3/Hotseat.java b/src/com/android/launcher3/Hotseat.java
index 9f86a0b..5245509 100644
--- a/src/com/android/launcher3/Hotseat.java
+++ b/src/com/android/launcher3/Hotseat.java
@@ -218,4 +218,13 @@
             mBackgroundColor = color;
         }
     }
+
+    public void setBackgroundTransparent(boolean enable) {
+        // This causes re-layout. Should replace the logic with simply setting the background alpha
+        if (enable) {
+            setBackground(null);
+        } else {
+            setBackground(mBackground);
+        }
+    }
 }
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index 156c1b0..f30d6c5 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -1395,6 +1395,8 @@
         mDragController.addDropTarget(mWorkspace);
         mDropTargetBar.setup(mDragController);
 
+        mAllAppsController.setupViews(mAppsView, mHotseat, mWorkspace);
+
         if (TestingUtils.MEMORY_DUMP_ENABLED) {
             TestingUtils.addWeightWatcher(this);
         }
diff --git a/src/com/android/launcher3/allapps/AllAppsTransitionController.java b/src/com/android/launcher3/allapps/AllAppsTransitionController.java
index c443b1e..4bdd9f4 100644
--- a/src/com/android/launcher3/allapps/AllAppsTransitionController.java
+++ b/src/com/android/launcher3/allapps/AllAppsTransitionController.java
@@ -4,11 +4,9 @@
 import android.animation.AnimatorListenerAdapter;
 import android.animation.AnimatorSet;
 import android.animation.ObjectAnimator;
-import android.graphics.drawable.Drawable;
 import android.util.Log;
 import android.view.MotionEvent;
 import android.view.View;
-import android.view.animation.AccelerateDecelerateInterpolator;
 import android.view.animation.AccelerateInterpolator;
 import android.view.animation.DecelerateInterpolator;
 import android.view.animation.Interpolator;
@@ -39,7 +37,6 @@
 
     private final Interpolator mAccelInterpolator = new AccelerateInterpolator(2f);
     private final Interpolator mDecelInterpolator = new DecelerateInterpolator(1f);
-    private final Interpolator mAccelDecelInterpolator = new AccelerateDecelerateInterpolator();
 
     private static final float ANIMATION_DURATION = 2000;
     public static final float ALL_APPS_FINAL_ALPHA = .8f;
@@ -49,8 +46,8 @@
     private AllAppsContainerView mAppsView;
     private Workspace mWorkspace;
     private Hotseat mHotseat;
-    private Drawable mHotseatBackground;
-    private float mHotseatAlpha;
+    private float mHotseatBackgroundAlpha;
+
     private float mStatusBarHeight;
 
     private final Launcher mLauncher;
@@ -87,7 +84,6 @@
 
     @Override
     public boolean onInterceptTouchEvent(MotionEvent ev) {
-        init();
         if (ev.getAction() == MotionEvent.ACTION_DOWN) {
             mNoIntercept = false;
             if (mLauncher.getWorkspace().isInOverviewMode() || mLauncher.isWidgetsViewVisible()) {
@@ -138,45 +134,32 @@
         return mProgressTransY / mTranslation > 1 - RECATCH_REJECTION_FRACTION;
     }
 
-    private void init() {
-        if (mAppsView != null) {
-            return;
-        }
-        mAppsView = mLauncher.getAppsView();
-        mHotseat = mLauncher.getHotseat();
-        mWorkspace = mLauncher.getWorkspace();
-
-        mStatusBarHeight = mLauncher.getDragLayer().getInsets().height();
-        if (mHotseatBackground == null) {
-            mHotseatBackground = mHotseat.getBackground();
-            mHotseatAlpha = mHotseatBackground.getAlpha() / 255f;
-        }
-    }
-
     @Override
     public void onScrollStart(boolean start) {
-        init();
         cancelAnimation();
         mCurrentAnimation = LauncherAnimUtils.createAnimatorSet();
         preparePull(start);
-        mCurY = mAppsView.getTranslationY();
     }
 
     /**
      * @param start {@code true} if start of new drag.
      */
     public void preparePull(boolean start) {
+        // Initialize values that should not change until #onScrollEnd
+        mCurY = mAppsView.getTranslationY();
+        mStatusBarHeight = mLauncher.getDragLayer().getInsets().top;
         mHotseat.setVisibility(View.VISIBLE);
         mHotseat.bringToFront();
         if (start) {
             if (!mLauncher.isAllAppsVisible()) {
                 mLauncher.tryAndUpdatePredictedApps();
-                mHotseat.setBackground(null);
+                mHotseatBackgroundAlpha = mHotseat.getBackground().getAlpha() / 255f;
+                mHotseat.setBackgroundTransparent(true /* transparent */);
                 mAppsView.setVisibility(View.VISIBLE);
                 mAppsView.getContentView().setVisibility(View.VISIBLE);
                 mAppsView.getContentView().setBackground(null);
                 mAppsView.getRevealView().setVisibility(View.VISIBLE);
-                mAppsView.getRevealView().setAlpha(mHotseatAlpha);
+                mAppsView.getRevealView().setAlpha(mHotseatBackgroundAlpha);
 
                 DeviceProfile grid= mLauncher.getDeviceProfile();
                 if (!grid.isLandscape) {
@@ -235,7 +218,7 @@
         float alpha = calcAlphaAllApps(progress);
         float workspaceHotseatAlpha = 1 - alpha;
 
-        mAppsView.getRevealView().setAlpha(Math.min(ALL_APPS_FINAL_ALPHA, Math.max(mHotseatAlpha,
+        mAppsView.getRevealView().setAlpha(Math.min(ALL_APPS_FINAL_ALPHA, Math.max(mHotseatBackgroundAlpha,
                 mDecelInterpolator.getInterpolation(alpha))));
         mAppsView.getContentView().setAlpha(alpha);
         mAppsView.setTranslationY(progress);
@@ -292,7 +275,7 @@
     }
 
     public void animateToAllApps(AnimatorSet animationOut, long duration) {
-        if ((mAppsView = mLauncher.getAppsView()) == null || animationOut == null){
+        if (animationOut == null){
             return;
         }
         if (mDetector.isRestingState()) {
@@ -330,7 +313,7 @@
     }
 
     public void animateToWorkspace(AnimatorSet animationOut, long duration) {
-        if ((mAppsView = mLauncher.getAppsView()) == null || animationOut == null){
+        if (animationOut == null){
             return;
         }
         if(mDetector.isRestingState()) {
@@ -382,7 +365,7 @@
             return;
         }
         mAppsView.setVisibility(View.INVISIBLE);
-        mHotseat.setBackground(mHotseatBackground);
+        mHotseat.setBackgroundTransparent(false /* transparent */);
         mHotseat.setVisibility(View.VISIBLE);
         setProgress(mTranslation);
         if (!mStateAlreadyChanged) {
@@ -401,4 +384,10 @@
     private void cleanUpAnimation() {
         mCurrentAnimation = null;
     }
+
+    public void setupViews(AllAppsContainerView appsView, Hotseat hotseat, Workspace workspace) {
+        mAppsView = appsView;
+        mHotseat = hotseat;
+        mWorkspace = workspace;
+    }
 }