AllAppsSearch interface change Version 3

Change-Id: I79f635582075a1e33e970e4f4eb6ec653572fefe
diff --git a/src/com/android/launcher3/allapps/AllAppsTransitionController.java b/src/com/android/launcher3/allapps/AllAppsTransitionController.java
index f057036..aa9edda 100644
--- a/src/com/android/launcher3/allapps/AllAppsTransitionController.java
+++ b/src/com/android/launcher3/allapps/AllAppsTransitionController.java
@@ -1,6 +1,5 @@
 package com.android.launcher3.allapps;
 
-import static com.android.launcher3.LauncherState.ALL_APPS;
 import static com.android.launcher3.LauncherState.ALL_APPS_CONTENT;
 import static com.android.launcher3.LauncherState.ALL_APPS_HEADER_EXTRA;
 import static com.android.launcher3.LauncherState.APPS_VIEW_ITEM_MASK;
@@ -23,6 +22,7 @@
 import android.view.View;
 import android.view.ViewGroup;
 import android.view.animation.Interpolator;
+import android.widget.EditText;
 
 import com.android.launcher3.DeviceProfile;
 import com.android.launcher3.DeviceProfile.OnDeviceProfileChangeListener;
@@ -87,6 +87,7 @@
 
     private float mScrollRangeDelta = 0;
 
+    // plugin related variables
     private AllAppsSearchPlugin mPlugin;
     private View mPluginContent;
 
@@ -131,7 +132,6 @@
         float shiftCurrent = progress * mShiftRange;
 
         mAppsView.setTranslationY(shiftCurrent);
-
         if (mPlugin != null) {
             mPlugin.setProgress(progress);
         }
@@ -160,7 +160,6 @@
         setProgress(state.getVerticalProgress(mLauncher));
         setAlphas(state, new StateAnimationConfig(), NO_ANIM_PROPERTY_SETTER);
         onProgressAnimationEnd();
-        updatePlugin(state);
     }
 
     /**
@@ -194,20 +193,6 @@
         builder.add(anim);
 
         setAlphas(toState, config, builder);
-
-        updatePlugin(toState);
-    }
-
-    private void updatePlugin(LauncherState toState) {
-        if (mPlugin == null) return;
-        if (toState == ALL_APPS) {
-            // TODO: change this from toggle event to continuous transition event.
-            mPlugin.setEditText(mAppsView.getSearchUiManager().setTextSearchEnabled(true));
-        } else {
-            mPlugin.setEditText(null);
-            mAppsView.getSearchUiManager().setTextSearchEnabled(false);
-        }
-
     }
 
     public Animator createSpringAnimation(float... progressValues) {
@@ -276,6 +261,7 @@
         if (Float.compare(mProgress, 1f) == 0) {
             mAppsView.reset(false /* animate */);
         }
+        updatePluginAnimationEnd();
     }
 
     @Override
@@ -285,7 +271,7 @@
                 R.layout.all_apps_content_layout, mAppsView, false);
         mAppsView.addView(mPluginContent);
         mPluginContent.setAlpha(0f);
-        mPlugin.setup((ViewGroup) mPluginContent, mLauncher);
+        mPlugin.setup((ViewGroup) mPluginContent, mLauncher, mShiftRange);
     }
 
     @Override
@@ -297,4 +283,25 @@
     public void onActivityDestroyed() {
         PluginManagerWrapper.INSTANCE.get(mLauncher).removePluginListener(this);
     }
+
+    /** Used for the plugin to signal when drag starts happens
+     * @param toAllApps*/
+    public void onDragStart(boolean toAllApps) {
+        if (mPlugin == null) return;
+
+        if (toAllApps) {
+            EditText editText = mAppsView.getSearchUiManager().setTextSearchEnabled(true);
+            mPlugin.setEditText(editText);
+        }
+        mPlugin.onDragStart(toAllApps ? 1f : 0f);
+    }
+
+    private void updatePluginAnimationEnd() {
+        if (mPlugin == null) return;
+        mPlugin.onAnimationEnd(mProgress);
+        if (Float.compare(mProgress, 1f) == 0) {
+            mAppsView.getSearchUiManager().setTextSearchEnabled(false);
+            mPlugin.setEditText(null);
+        }
+    }
 }
diff --git a/src/com/android/launcher3/touch/AbstractStateChangeTouchController.java b/src/com/android/launcher3/touch/AbstractStateChangeTouchController.java
index 2e63ccf..2c21609 100644
--- a/src/com/android/launcher3/touch/AbstractStateChangeTouchController.java
+++ b/src/com/android/launcher3/touch/AbstractStateChangeTouchController.java
@@ -242,6 +242,7 @@
     public void onDragStart(boolean start, float startDisplacement) {
         mStartState = mLauncher.getStateManager().getState();
         mIsLogContainerSet = false;
+
         if (mCurrentAnimation == null) {
             mFromState = mStartState;
             mToState = null;
@@ -259,6 +260,10 @@
         }
         mCanBlockFling = mFromState == NORMAL;
         mFlingBlockCheck.unblockFling();
+        // Must be called after all the animation controllers have been paused
+        if (mToState == ALL_APPS || mToState == NORMAL) {
+            mLauncher.getAllAppsController().onDragStart(mToState == ALL_APPS);
+        }
     }
 
     @Override
diff --git a/src_plugins/com/android/systemui/plugins/AllAppsSearchPlugin.java b/src_plugins/com/android/systemui/plugins/AllAppsSearchPlugin.java
index d458fc4..c57f07d 100644
--- a/src_plugins/com/android/systemui/plugins/AllAppsSearchPlugin.java
+++ b/src_plugins/com/android/systemui/plugins/AllAppsSearchPlugin.java
@@ -19,17 +19,32 @@
 import android.app.Activity;
 import android.view.ViewGroup;
 import android.widget.EditText;
+
 import com.android.systemui.plugins.annotations.ProvidesInterface;
 
 /**
- * Implement this plugin interface to add a row of views to the top of the all apps drawer.
+ * Implement this plugin interface to replace the all apps recycler view of the all apps drawer.
  */
 @ProvidesInterface(action = AllAppsSearchPlugin.ACTION, version = AllAppsSearchPlugin.VERSION)
 public interface AllAppsSearchPlugin extends Plugin {
     String ACTION = "com.android.systemui.action.PLUGIN_ALL_APPS_SEARCH_ACTIONS";
-    int VERSION = 2;
+    int VERSION = 3;
 
-    void setup(ViewGroup parent, Activity activity);
-    void setEditText(EditText editText);
+    /** Following are the order that these methods should be called. */
+    void setup(ViewGroup parent, Activity activity, float allAppsContainerHeight);
+
+    /**
+     * When drag starts, pass window inset related fields and the progress to indicate
+     * whether user is swiping down or swiping up
+     */
+    void onDragStart(float progress);
+
+    /** progress is between [0, 1] 1: down, 0: up */
     void setProgress(float progress);
+
+    /** Called when container animation stops, so that plugin can perform cleanups */
+    void onAnimationEnd(float progress);
+
+    /** pass over the search box object */
+    void setEditText(EditText editText);
 }