Substantially improved performance of dragging and drop animations

-> Took DragView drawing out of the window and put it into the DragLayer
-> Added fade-in/out animations to transition between the final view
   and the DragView, after the view animates
-> Enabled hardware layers on Folder items which improves the
   performance Folder reordering

Change-Id: I4d92ca9fba172d1bab9efc215a99abcaadcdf503
diff --git a/src/com/android/launcher2/Folder.java b/src/com/android/launcher2/Folder.java
index 347eba0..8a1b957 100644
--- a/src/com/android/launcher2/Folder.java
+++ b/src/com/android/launcher2/Folder.java
@@ -35,7 +35,6 @@
 import android.view.MenuItem;
 import android.view.MotionEvent;
 import android.view.View;
-import android.view.View.OnClickListener;
 import android.view.animation.AccelerateInterpolator;
 import android.view.animation.DecelerateInterpolator;
 import android.view.inputmethod.EditorInfo;
@@ -43,8 +42,6 @@
 import android.widget.AdapterView;
 import android.widget.LinearLayout;
 import android.widget.TextView;
-import android.widget.AdapterView.OnItemClickListener;
-import android.widget.AdapterView.OnItemLongClickListener;
 
 import com.android.launcher.R;
 import com.android.launcher2.FolderInfo.FolderListener;
@@ -54,9 +51,8 @@
 /**
  * Represents a set of icons chosen by the user or generated by the system.
  */
-public class Folder extends LinearLayout implements DragSource, OnItemLongClickListener,
-        OnItemClickListener, OnClickListener, View.OnLongClickListener, DropTarget, FolderListener,
-        TextView.OnEditorActionListener {
+public class Folder extends LinearLayout implements DragSource, View.OnClickListener,
+        View.OnLongClickListener, DropTarget, FolderListener, TextView.OnEditorActionListener {
 
     protected DragController mDragController;
 
@@ -102,6 +98,7 @@
     private int mFolderNameHeight;
     private Rect mHitRect = new Rect();
     private Rect mTempRect = new Rect();
+    private boolean mFirstOpen = true;
 
     private boolean mIsEditingName = false;
     private InputMethodManager mInputMethodManager;
@@ -135,7 +132,6 @@
         if (sHintText == null) {
             sHintText = res.getString(R.string.folder_hint_text);
         }
-        setLayerType(LAYER_TYPE_HARDWARE, null);
     }
 
     @Override
@@ -177,15 +173,6 @@
         }
     };
 
-    public void onItemClick(AdapterView parent, View v, int position, long id) {
-        ShortcutInfo app = (ShortcutInfo) parent.getItemAtPosition(position);
-        int[] pos = new int[2];
-        v.getLocationOnScreen(pos);
-        app.intent.setSourceBounds(new Rect(pos[0], pos[1],
-                pos[0] + v.getWidth(), pos[1] + v.getHeight()));
-        mLauncher.startActivitySafely(app.intent, app);
-    }
-
     public void onClick(View v) {
         Object tag = v.getTag();
         if (tag instanceof ShortcutInfo) {
@@ -393,6 +380,12 @@
     }
 
     public void animateOpen() {
+        if (mFirstOpen) {
+            setLayerType(LAYER_TYPE_HARDWARE, null);
+            buildLayer();
+            mFirstOpen = false;
+        }
+
         positionAndSizeAsIcon();
 
         if (!(getParent() instanceof DragLayer)) return;
@@ -433,14 +426,25 @@
             @Override
             public void onAnimationEnd(Animator animation) {
                 mState = STATE_OPEN;
+                setLayerType(LAYER_TYPE_NONE, null);
+                enableHardwareLayersForChildren();
             }
         });
         oa.setDuration(mExpandDuration);
         oa.start();
     }
 
+    void enableHardwareLayersForChildren() {
+        ArrayList<View> children = getItemsInReadingOrder();
+        for (View child: children) {
+            child.setLayerType(LAYER_TYPE_HARDWARE, null);
+        }
+    }
+
     public void animateClosed() {
         if (!(getParent() instanceof DragLayer)) return;
+        setLayerType(LAYER_TYPE_HARDWARE, null);
+        buildLayer();
 
         ObjectAnimator oa;
         if (mMode == PARTIAL_GROW) {
@@ -957,4 +961,8 @@
         }
         return mItemsInReadingOrder;
     }
+
+    public void getLocationInDragLayer(int[] loc) {
+        mLauncher.getDragLayer().getLocationInDragLayer(this, loc);
+    }
 }