Changing the state UI logic for normal build and quickStep build

> Creating ShareHandlers for managing UI
> In normal build, hotseat is hidden in overview, while in QuickStepBuild, it is visible

Change-Id: I5f8d35c75b861d912d93fce186b5dd74106184c3
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index 75968ae..fa4a1c8 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -339,7 +339,7 @@
 
         mDragController = new DragController(this);
         mAllAppsController = new AllAppsTransitionController(this);
-        mStateManager = new LauncherStateManager(this, mAllAppsController);
+        mStateManager = new LauncherStateManager(this);
 
         mAppWidgetManager = AppWidgetManagerCompat.getInstance(this);
 
@@ -1287,6 +1287,10 @@
         }
     }
 
+    public AllAppsTransitionController getAllAppsController() {
+        return mAllAppsController;
+    }
+
     public DragLayer getDragLayer() {
         return mDragLayer;
     }
diff --git a/src/com/android/launcher3/LauncherState.java b/src/com/android/launcher3/LauncherState.java
index bb09a9f..d6cd8a3 100644
--- a/src/com/android/launcher3/LauncherState.java
+++ b/src/com/android/launcher3/LauncherState.java
@@ -36,9 +36,8 @@
 
     protected static final int FLAG_SHOW_SCRIM = 1 << 0;
     protected static final int FLAG_MULTI_PAGE = 1 << 1;
-    protected static final int FLAG_HIDE_HOTSEAT = 1 << 2;
-    protected static final int FLAG_DISABLE_ACCESSIBILITY = 1 << 3;
-    protected static final int FLAG_DO_NOT_RESTORE = 1 << 4;
+    protected static final int FLAG_DISABLE_ACCESSIBILITY = 1 << 2;
+    protected static final int FLAG_DO_NOT_RESTORE = 1 << 3;
 
     private static final LauncherState[] sAllStates = new LauncherState[4];
 
@@ -80,7 +79,6 @@
      * @see WorkspaceStateTransitionAnimation
      */
     public final boolean hasScrim;
-    public final boolean hideHotseat;
     public final int transitionDuration;
 
     /**
@@ -97,7 +95,6 @@
 
         this.hasScrim = (flags & FLAG_SHOW_SCRIM) != 0;
         this.hasMultipleVisiblePages = (flags & FLAG_MULTI_PAGE) != 0;
-        this.hideHotseat = (flags & FLAG_HIDE_HOTSEAT) != 0;
         this.workspaceAccessibilityFlag = (flags & FLAG_DISABLE_ACCESSIBILITY) != 0
                 ? IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS
                 : IMPORTANT_FOR_ACCESSIBILITY_AUTO;
diff --git a/src/com/android/launcher3/LauncherStateManager.java b/src/com/android/launcher3/LauncherStateManager.java
index b99df71..f016e8d 100644
--- a/src/com/android/launcher3/LauncherStateManager.java
+++ b/src/com/android/launcher3/LauncherStateManager.java
@@ -29,6 +29,7 @@
 import com.android.launcher3.anim.AnimationLayerSet;
 import com.android.launcher3.anim.AnimationSuccessListener;
 import com.android.launcher3.anim.AnimatorPlaybackController;
+import com.android.launcher3.uioverrides.UiFactory;
 
 /**
  * TODO: figure out what kind of tests we can write for this
@@ -78,21 +79,26 @@
     private final AnimationConfig mConfig = new AnimationConfig();
     private final Handler mUiHandler;
     private final Launcher mLauncher;
-    private final AllAppsTransitionController mAllAppsController;
 
+    private StateHandler[] mStateHandlers;
     private LauncherState mState = NORMAL;
 
-    public LauncherStateManager(
-            Launcher l, AllAppsTransitionController allAppsController) {
+    public LauncherStateManager(Launcher l) {
         mUiHandler = new Handler(Looper.getMainLooper());
         mLauncher = l;
-        mAllAppsController = allAppsController;
     }
 
     public LauncherState getState() {
         return mState;
     }
 
+    private StateHandler[] getStateHandlers() {
+        if (mStateHandlers == null) {
+            mStateHandlers = UiFactory.getStateHandler(mLauncher);
+        }
+        return mStateHandlers;
+    }
+
     /**
      * @see #goToState(LauncherState, boolean, Runnable)
      */
@@ -148,8 +154,9 @@
 
         if (!animated) {
             setState(state);
-            mAllAppsController.setFinalProgress(state.verticalProgress);
-            mLauncher.getWorkspace().setState(state);
+            for (StateHandler handler : getStateHandlers()) {
+                handler.setState(state);
+            }
             mLauncher.getUserEventDispatcher().resetElapsedContainerMillis();
 
             // Run any queued runnable
@@ -190,14 +197,12 @@
 
     protected AnimatorSet createAnimationToNewWorkspaceInternal(final LauncherState state,
             final Runnable onCompleteRunnable) {
-
         final AnimatorSet animation = LauncherAnimUtils.createAnimatorSet();
         final AnimationLayerSet layerViews = new AnimationLayerSet();
 
-        mAllAppsController.animateToFinalProgress(state.verticalProgress, animation, mConfig);
-        mLauncher.getWorkspace().setStateWithAnimation(state,
-                layerViews, animation, mConfig);
-
+        for (StateHandler handler : getStateHandlers()) {
+            handler.setStateWithAnimation(state, layerViews, animation, mConfig);
+        }
         animation.addListener(layerViews);
         animation.addListener(new AnimationSuccessListener() {
 
@@ -285,4 +290,18 @@
             mCurrentAnimation.addListener(this);
         }
     }
+
+    public interface StateHandler {
+
+        /**
+         * Updates the UI to {@param state} without any animations
+         */
+        void setState(LauncherState state);
+
+        /**
+         * Sets the UI to {@param state} by animating any changes.
+         */
+        void setStateWithAnimation(LauncherState toState, AnimationLayerSet layerViews,
+                AnimatorSet anim, AnimationConfig config);
+    }
 }
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java
index daa9bd0..685dcee 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -105,7 +105,7 @@
 public class Workspace extends PagedView
         implements DropTarget, DragSource, View.OnTouchListener,
         DragController.DragListener, ViewGroup.OnHierarchyChangeListener,
-        Insettable {
+        Insettable, LauncherStateManager.StateHandler {
     private static final String TAG = "Launcher.Workspace";
 
     /** The value that {@link #mTransitionProgress} must be greater than for
@@ -1558,6 +1558,7 @@
     /**
      * Sets the current workspace {@link LauncherState} and updates the UI without any animations
      */
+    @Override
     public void setState(LauncherState toState) {
         onStartStateTransition(toState);
         mStateTransitionAnimation.setState(toState);
@@ -1567,6 +1568,7 @@
     /**
      * Sets the current workspace {@link LauncherState}, then animates the UI
      */
+    @Override
     public void setStateWithAnimation(LauncherState toState, AnimationLayerSet layerViews,
             AnimatorSet anim, AnimationConfig config) {
         StateTransitionListener listener = new StateTransitionListener(toState);
diff --git a/src/com/android/launcher3/WorkspaceStateTransitionAnimation.java b/src/com/android/launcher3/WorkspaceStateTransitionAnimation.java
index e14461e..8edec40 100644
--- a/src/com/android/launcher3/WorkspaceStateTransitionAnimation.java
+++ b/src/com/android/launcher3/WorkspaceStateTransitionAnimation.java
@@ -90,7 +90,7 @@
  */
 public class WorkspaceStateTransitionAnimation {
 
-    private static final PropertySetter NO_ANIM_PROPERTY_SETTER = new PropertySetter();
+    public static final PropertySetter NO_ANIM_PROPERTY_SETTER = new PropertySetter();
 
     public final int mWorkspaceScrimAlpha;
 
@@ -141,14 +141,6 @@
                     propertySetter);
         }
 
-        float finalHotseatAlpha = state.hideHotseat ? 0f : 1f;
-
-        // This is true when transitioning between:
-        // - Overview <-> Workspace
-        propertySetter.setViewAlpha(null, mLauncher.getOverviewPanel(), 1 - finalHotseatAlpha);
-        propertySetter.setViewAlpha(mWorkspace.createHotseatAlphaAnimator(finalHotseatAlpha),
-                mLauncher.getHotseat(), finalHotseatAlpha);
-
         propertySetter.setFloat(mWorkspace, SCALE_PROPERTY, mNewScale, Interpolators.ZOOM_IN);
         propertySetter.setFloat(mWorkspace, View.TRANSLATION_Y,
                 finalWorkspaceTranslationY, Interpolators.ZOOM_IN);
@@ -176,7 +168,7 @@
         }
     }
 
-    private static class PropertySetter {
+    public static class PropertySetter {
 
         public void setViewAlpha(Animator anim, View view, float alpha) {
             if (anim != null) {
@@ -204,13 +196,14 @@
         }
     }
 
-    private static class AnimatedPropertySetter extends PropertySetter {
+    public static class AnimatedPropertySetter extends PropertySetter {
 
         private final long mDuration;
         private final AnimationLayerSet mLayerViews;
         private final AnimatorSet mStateAnimator;
 
-        AnimatedPropertySetter(long duration, AnimationLayerSet layerView, AnimatorSet anim) {
+        public AnimatedPropertySetter(
+                long duration, AnimationLayerSet layerView, AnimatorSet anim) {
             mDuration = duration;
             mLayerViews = layerView;
             mStateAnimator = anim;
diff --git a/src/com/android/launcher3/allapps/AllAppsTransitionController.java b/src/com/android/launcher3/allapps/AllAppsTransitionController.java
index 9b64043..eb26704 100644
--- a/src/com/android/launcher3/allapps/AllAppsTransitionController.java
+++ b/src/com/android/launcher3/allapps/AllAppsTransitionController.java
@@ -15,10 +15,12 @@
 import com.android.launcher3.Hotseat;
 import com.android.launcher3.Launcher;
 import com.android.launcher3.LauncherState;
+import com.android.launcher3.LauncherStateManager;
 import com.android.launcher3.LauncherStateManager.AnimationConfig;
 import com.android.launcher3.R;
 import com.android.launcher3.Utilities;
 import com.android.launcher3.Workspace;
+import com.android.launcher3.anim.AnimationLayerSet;
 import com.android.launcher3.anim.AnimationSuccessListener;
 import com.android.launcher3.anim.Interpolators;
 import com.android.launcher3.graphics.GradientView;
@@ -35,7 +37,8 @@
  * If release velocity < THRES1, snap according to either top or bottom depending on whether it's
  * closer to top or closer to the page indicator.
  */
-public class AllAppsTransitionController implements SearchUiManager.OnScrollRangeChangeListener {
+public class AllAppsTransitionController
+        implements SearchUiManager.OnScrollRangeChangeListener, LauncherStateManager.StateHandler {
 
     private static final Property<AllAppsTransitionController, Float> PROGRESS =
             new Property<AllAppsTransitionController, Float>(Float.class, "progress") {
@@ -122,8 +125,8 @@
      *
      * @param progress value between 0 and 1, 0 shows all apps and 1 shows workspace
      *
-     * @see #setFinalProgress(float)
-     * @see #animateToFinalProgress(float, AnimatorSet, AnimationConfig)
+     * @see #setState(LauncherState)
+     * @see #setStateWithAnimation(LauncherState, AnimationLayerSet, AnimatorSet, AnimationConfig)
      */
     public void setProgress(float progress) {
         mProgress = progress;
@@ -161,33 +164,32 @@
     }
 
     /**
-     * Sets the vertical transition progress to {@param progress} and updates all the dependent UI
+     * Sets the vertical transition progress to {@param state} and updates all the dependent UI
      * accordingly.
      */
-    public void setFinalProgress(float progress) {
-        setProgress(progress);
+    @Override
+    public void setState(LauncherState state) {
+        setProgress(state.verticalProgress);
         onProgressAnimationEnd();
     }
 
     /**
      * Creates an animation which updates the vertical transition progress and updates all the
      * dependent UI using various animation events
-     *
-     * @param progress the final vertical progress at the end of the animation
-     * @param animationOut the target AnimatorSet where this animation should be added
-     * @param outConfig an in/out configuration which can be shared with other animations
      */
-    public void animateToFinalProgress(
-            float progress, AnimatorSet animationOut, AnimationConfig outConfig) {
-        if (Float.compare(mProgress, progress) == 0) {
+    @Override
+    public void setStateWithAnimation(LauncherState toState, AnimationLayerSet layerViews,
+            AnimatorSet animationOut, AnimationConfig config) {
+        if (Float.compare(mProgress, toState.verticalProgress) == 0) {
             // Fail fast
             onProgressAnimationEnd();
             return;
         }
 
-        Interpolator interpolator = outConfig.userControlled ? LINEAR : FAST_OUT_SLOW_IN;
-        ObjectAnimator anim = ObjectAnimator.ofFloat(this, PROGRESS, mProgress, progress);
-        anim.setDuration(outConfig.duration);
+        Interpolator interpolator = config.userControlled ? LINEAR : FAST_OUT_SLOW_IN;
+        ObjectAnimator anim = ObjectAnimator.ofFloat(
+                this, PROGRESS, mProgress, toState.verticalProgress);
+        anim.setDuration(config.duration);
         anim.setInterpolator(interpolator);
         anim.addListener(new AnimationSuccessListener() {
             @Override