Revert "Decrease jank in all apps physics."

This change created an issue where some items appear to not have springs when the device does not have that many apps.

This reverts commit 9d7f2b9e0d2b40414951f3dba461c6cabc9c7cbf.

Change-Id: I8e79cf3f86972fde8184debb6ab4d0f32283a8bd
diff --git a/src/com/android/launcher3/allapps/AllAppsGridAdapter.java b/src/com/android/launcher3/allapps/AllAppsGridAdapter.java
index 83c1370..d3d23ca 100644
--- a/src/com/android/launcher3/allapps/AllAppsGridAdapter.java
+++ b/src/com/android/launcher3/allapps/AllAppsGridAdapter.java
@@ -102,12 +102,7 @@
         private SpringAnimation spring;
 
         public ViewHolder(View v) {
-            this(v, null);
-        }
-
-        public ViewHolder(View v, SpringAnimation spring) {
             super(v);
-            this.spring = spring;
         }
     }
 
@@ -290,7 +285,6 @@
 
     @Override
     public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
-        ViewHolder viewHolder;
         switch (viewType) {
             case VIEW_TYPE_ICON:
             case VIEW_TYPE_PREDICTION_ICON:
@@ -304,19 +298,16 @@
 
                 // Ensure the all apps icon height matches the workspace icons
                 icon.getLayoutParams().height = getCellSize().y;
-                viewHolder = new ViewHolder(icon);
-                break;
+                return new ViewHolder(icon);
             case VIEW_TYPE_DISCOVERY_ITEM:
                 AppDiscoveryItemView appDiscoveryItemView = (AppDiscoveryItemView) mLayoutInflater
                         .inflate(R.layout.all_apps_discovery_item, parent, false);
                 appDiscoveryItemView.init(mIconClickListener, mLauncher.getAccessibilityDelegate(),
                         mIconLongClickListener);
-                viewHolder = new ViewHolder(appDiscoveryItemView);
-                break;
+                return new ViewHolder(appDiscoveryItemView);
             case VIEW_TYPE_EMPTY_SEARCH:
-                viewHolder = new ViewHolder(mLayoutInflater.inflate(R.layout.all_apps_empty_search,
+                return new ViewHolder(mLayoutInflater.inflate(R.layout.all_apps_empty_search,
                         parent, false));
-                break;
             case VIEW_TYPE_SEARCH_MARKET:
                 View searchMarketView = mLayoutInflater.inflate(R.layout.all_apps_search_market,
                         parent, false);
@@ -326,30 +317,21 @@
                         mLauncher.startActivitySafely(v, mMarketSearchIntent, null);
                     }
                 });
-                viewHolder = new ViewHolder(searchMarketView);
-                break;
+                return new ViewHolder(searchMarketView);
             case VIEW_TYPE_SEARCH_DIVIDER:
-                viewHolder = new ViewHolder(mLayoutInflater.inflate(
+                return new ViewHolder(mLayoutInflater.inflate(
                         R.layout.all_apps_search_divider, parent, false));
-                break;
             case VIEW_TYPE_APPS_LOADING_DIVIDER:
                 View loadingDividerView = mLayoutInflater.inflate(
                         R.layout.all_apps_discovery_loading_divider, parent, false);
-                viewHolder = new ViewHolder(loadingDividerView);
-                break;
+                return new ViewHolder(loadingDividerView);
             case VIEW_TYPE_PREDICTION_DIVIDER:
             case VIEW_TYPE_SEARCH_MARKET_DIVIDER:
-                viewHolder = new ViewHolder(mLayoutInflater.inflate(
+                return new ViewHolder(mLayoutInflater.inflate(
                         R.layout.all_apps_divider, parent, false));
-                break;
             default:
                 throw new RuntimeException("Unexpected view type");
         }
-
-        if (FeatureFlags.LAUNCHER3_PHYSICS && isViewType(viewType, VIEW_TYPE_MASK_HAS_SPRINGS)) {
-            viewHolder.spring = mSpringAnimationHandler.createSpringAnimation(viewHolder.itemView);
-        }
-        return viewHolder;
     }
 
     private Point getCellSize() {
@@ -358,8 +340,7 @@
 
     @Override
     public void onBindViewHolder(ViewHolder holder, int position) {
-        int viewType = holder.getItemViewType();
-        switch (viewType) {
+        switch (holder.getItemViewType()) {
             case VIEW_TYPE_ICON:
             case VIEW_TYPE_PREDICTION_ICON:
                 AppInfo info = mApps.getAdapterItems().get(position).appInfo;
@@ -396,16 +377,21 @@
                 // nothing to do
                 break;
         }
-        if (FeatureFlags.LAUNCHER3_PHYSICS && isViewType(viewType, VIEW_TYPE_MASK_HAS_SPRINGS)) {
-            holder.spring = mSpringAnimationHandler.add(holder.itemView, position, mApps,
-                    mAppsPerRow, holder.spring);
-        }
         if (mBindViewCallback != null) {
             mBindViewCallback.onBindView(holder);
         }
     }
 
     @Override
+    public void onViewAttachedToWindow(ViewHolder holder) {
+        int type = holder.getItemViewType();
+        if (FeatureFlags.LAUNCHER3_PHYSICS && isViewType(type, VIEW_TYPE_MASK_HAS_SPRINGS)) {
+            holder.spring = mSpringAnimationHandler.add(holder.itemView,
+                    holder.getAdapterPosition(), mApps, mAppsPerRow, holder.spring);
+        }
+    }
+
+    @Override
     public void onViewDetachedFromWindow(ViewHolder holder) {
         int type = holder.getItemViewType();
         if (FeatureFlags.LAUNCHER3_PHYSICS && isViewType(type, VIEW_TYPE_MASK_HAS_SPRINGS)) {
diff --git a/src/com/android/launcher3/anim/SpringAnimationHandler.java b/src/com/android/launcher3/anim/SpringAnimationHandler.java
index 92acfb8..488657c 100644
--- a/src/com/android/launcher3/anim/SpringAnimationHandler.java
+++ b/src/com/android/launcher3/anim/SpringAnimationHandler.java
@@ -178,7 +178,7 @@
         return mDirection == Y_DIRECTION;
     }
 
-    public SpringAnimation createSpringAnimation(View view) {
+    private SpringAnimation createSpringAnimation(View view) {
         DynamicAnimation.ViewProperty property = isVerticalDirection()
                 ? DynamicAnimation.TRANSLATION_Y
                 : DynamicAnimation.TRANSLATION_X;