Fix misaligned drop targets in the all apps CAB
diff --git a/res/layout-xlarge/launcher.xml b/res/layout-xlarge/launcher.xml
index c6acec3..9ed2dc5 100644
--- a/res/layout-xlarge/launcher.xml
+++ b/res/layout-xlarge/launcher.xml
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2007 The Android Open Source Project
+<!-- Copyright (C) 2010 The Android Open Source Project
 
      Licensed under the Apache License, Version 2.0 (the "License");
      you may not use this file except in compliance with the License.
diff --git a/src/com/android/launcher2/AllAppsPagedView.java b/src/com/android/launcher2/AllAppsPagedView.java
index a9e4dfe..a2a3793 100644
--- a/src/com/android/launcher2/AllAppsPagedView.java
+++ b/src/com/android/launcher2/AllAppsPagedView.java
@@ -21,14 +21,13 @@
 import android.content.ComponentName;
 import android.content.Context;
 import android.content.res.TypedArray;
-import android.graphics.Rect;
 import android.util.AttributeSet;
-import android.util.Log;
 import android.view.ActionMode;
 import android.view.LayoutInflater;
 import android.view.Menu;
 import android.view.MenuItem;
 import android.view.View;
+import android.view.ViewGroup;
 import android.view.animation.AnimationUtils;
 import android.widget.Checkable;
 import android.widget.TextView;
@@ -72,6 +71,12 @@
 
     private final LayoutInflater mInflater;
 
+    private ViewGroup mOrigInfoButtonParent;
+    private LayoutParams mOrigInfoButtonLayoutParams;
+
+    private ViewGroup mOrigDeleteZoneParent;
+    private LayoutParams mOrigDeleteZoneLayoutParams;
+
     public AllAppsPagedView(Context context) {
         this(context, null);
     }
@@ -400,10 +405,28 @@
     public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
         mode.setTitle(R.string.cab_selection_text);
 
-        menu.add(0, MENU_APP_INFO, 0, R.string.cab_menu_app_info)
-                .setIcon(R.drawable.info_button);
-        menu.add(0, MENU_DELETE_APP, 0, R.string.cab_menu_delete_app)
-                .setIcon(R.drawable.delete_zone_selector);
+        // Until the workspace has a selection mode and the CAB supports drag-and-drop, we
+        // take a hybrid approach: grab the views from the workspace and stuff them into the CAB.
+        // When the action mode is done, restore the views to their original place in the toolbar.
+
+        ApplicationInfoDropTarget infoButton =
+                (ApplicationInfoDropTarget) mLauncher.findViewById(R.id.info_button);
+        mOrigInfoButtonParent = (ViewGroup) infoButton.getParent();
+        mOrigInfoButtonLayoutParams = infoButton.getLayoutParams();
+        mOrigInfoButtonParent.removeView(infoButton);
+        infoButton.setManageVisibility(false);
+        infoButton.setVisibility(View.VISIBLE);
+
+        DeleteZone deleteZone = (DeleteZone) mLauncher.findViewById(R.id.delete_zone);
+        mOrigDeleteZoneParent = (ViewGroup) deleteZone.getParent();
+        mOrigDeleteZoneLayoutParams = deleteZone.getLayoutParams();
+        mOrigDeleteZoneParent.removeView(deleteZone);
+        deleteZone.setManageVisibility(false);
+        deleteZone.setVisibility(View.VISIBLE);
+
+        menu.add(0, MENU_APP_INFO, 0, R.string.cab_menu_app_info).setActionView(infoButton);
+        menu.add(0, MENU_DELETE_APP, 0, R.string.cab_menu_delete_app).setActionView(deleteZone);
+
         return true;
     }
 
@@ -415,6 +438,20 @@
 
     @Override
     public void onDestroyActionMode(ActionMode mode) {
+        // Re-parent the drop targets into the toolbar, and restore their layout params
+        ApplicationInfoDropTarget infoButton =
+                (ApplicationInfoDropTarget) mLauncher.findViewById(R.id.info_button);
+        ((ViewGroup) infoButton.getParent()).removeView(infoButton);
+        mOrigInfoButtonParent.addView(infoButton, mOrigInfoButtonLayoutParams);
+        infoButton.setVisibility(View.GONE);
+        infoButton.setManageVisibility(true);
+
+        DeleteZone deleteZone = (DeleteZone) mLauncher.findViewById(R.id.delete_zone);
+        ((ViewGroup) deleteZone.getParent()).removeView(deleteZone);
+        mOrigDeleteZoneParent.addView(deleteZone, mOrigDeleteZoneLayoutParams);
+        deleteZone.setVisibility(View.GONE);
+        deleteZone.setManageVisibility(true);
+
         mDragController.removeDropTarget(this);
         endChoiceMode();
     }
diff --git a/src/com/android/launcher2/ApplicationInfoDropTarget.java b/src/com/android/launcher2/ApplicationInfoDropTarget.java
index 99a5258..0e342a7 100644
--- a/src/com/android/launcher2/ApplicationInfoDropTarget.java
+++ b/src/com/android/launcher2/ApplicationInfoDropTarget.java
@@ -21,7 +21,6 @@
 import android.graphics.Paint;
 import android.graphics.PorterDuff;
 import android.graphics.PorterDuffColorFilter;
-import android.graphics.Rect;
 import android.util.AttributeSet;
 import android.view.View;
 import android.widget.ImageView;
@@ -32,10 +31,17 @@
  */
 public class ApplicationInfoDropTarget extends ImageView implements DropTarget, DragController.DragListener {
     private Launcher mLauncher;
-    private DragController mDragController;
     private boolean mActive = false;
 
-    private View mHandle;
+    /**
+     * If true, this View responsible for managing its own visibility, and that of its handle.
+     * This is generally the case, but it will be set to false when this is part of the
+     * Contextual Action Bar.
+     */
+    private boolean mManageVisibility = true;
+
+    /** The view that this view should appear in the place of. */
+    private View mHandle = null;
 
     private final Paint mPaint = new Paint();
 
@@ -47,11 +53,6 @@
         super(context, attrs, defStyle);
     }
 
-    @Override
-    protected void onFinishInflate() {
-        super.onFinishInflate();
-    }
-
     /**
      * Set the color that will be used as a filter over objects dragged over this object.
      */
@@ -92,7 +93,6 @@
 
     public void onDragExit(DragSource source, int x, int y, int xOffset, int yOffset,
             DragView dragView, Object dragInfo) {
-        // TODO: Animate out
         dragView.setPaint(null);
     }
 
@@ -100,22 +100,23 @@
         if (info != null) {
             mActive = true;
 
-            // TODO: Animate these in and out
-
-            // Only show the info icon when an application is selected
-            if (((ItemInfo)info).itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION) {
-                setVisibility(VISIBLE);
+            if (mManageVisibility) {
+                // Only show the info icon when an application is selected
+                if (((ItemInfo)info).itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION) {
+                    setVisibility(VISIBLE);
+                }
+                mHandle.setVisibility(INVISIBLE);
             }
-            mHandle.setVisibility(INVISIBLE);
         }
     }
 
     public void onDragEnd() {
         if (mActive) {
             mActive = false;
-            // TODO: Animate these in and out
-            setVisibility(GONE);
-            mHandle.setVisibility(VISIBLE);
+            if (mManageVisibility) {
+                setVisibility(GONE);
+                mHandle.setVisibility(VISIBLE);
+            }
         }
     }
 
@@ -123,14 +124,14 @@
         mLauncher = launcher;
     }
 
-    void setDragController(DragController dragController) {
-        mDragController = dragController;
-    }
-
     void setHandle(View view) {
         mHandle = view;
     }
 
+    void setManageVisibility(boolean value) {
+        mManageVisibility = value;
+    }
+
     @Override
     public DropTarget getDropTargetDelegate(DragSource source, int x, int y, int xOffset, int yOffset,
             DragView dragView, Object dragInfo) {
diff --git a/src/com/android/launcher2/DeleteZone.java b/src/com/android/launcher2/DeleteZone.java
index 01a20f7..aeaf5a3 100644
--- a/src/com/android/launcher2/DeleteZone.java
+++ b/src/com/android/launcher2/DeleteZone.java
@@ -23,7 +23,6 @@
 import android.graphics.Paint;
 import android.graphics.PorterDuff;
 import android.graphics.PorterDuffColorFilter;
-import android.graphics.Rect;
 import android.graphics.RectF;
 import android.graphics.drawable.TransitionDrawable;
 import android.util.AttributeSet;
@@ -45,6 +44,13 @@
     private Launcher mLauncher;
     private boolean mTrashMode;
 
+    /**
+     * If true, this View responsible for managing its own visibility, and that of its handle.
+     * This is generally the case, but it will be set to false when this is part of the
+     * Contextual Action Bar.
+     */
+    private boolean mManageVisibility = true;
+
     private AnimationSet mInAnimation;
     private AnimationSet mOutAnimation;
     private Animation mHandleInAnimation;
@@ -55,9 +61,11 @@
 
     private final RectF mRegion = new RectF();
     private TransitionDrawable mTransition;
-    private View mHandle;
     private final Paint mTrashPaint = new Paint();
 
+    /** The View that this view will replace. */
+    private View mHandle = null;
+
     public DeleteZone(Context context, AttributeSet attrs) {
         this(context, attrs, 0);
     }
@@ -71,6 +79,7 @@
         TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DeleteZone, defStyle, 0);
         mOrientation = a.getInt(R.styleable.DeleteZone_direction, ORIENTATION_HORIZONTAL);
         a.recycle();
+
     }
 
     @Override
@@ -149,16 +158,21 @@
         final ItemInfo item = (ItemInfo) info;
         if (item != null) {
             mTrashMode = true;
-            createAnimations();
             final int[] location = mLocation;
             getLocationOnScreen(location);
             mRegion.set(location[0], location[1], location[0] + mRight - mLeft,
                     location[1] + mBottom - mTop);
             mDragController.setDeleteRegion(mRegion);
+
+            // Make sure the icon is set to the default drawable, not the hover drawable
             mTransition.resetTransition();
-            startAnimation(mInAnimation);
-            mHandle.startAnimation(mHandleOutAnimation);
-            setVisibility(VISIBLE);
+
+            if (mManageVisibility) {
+                createAnimations();
+                startAnimation(mInAnimation);
+                mHandle.startAnimation(mHandleOutAnimation);
+                setVisibility(VISIBLE);
+            }
         }
     }
 
@@ -166,9 +180,13 @@
         if (mTrashMode) {
             mTrashMode = false;
             mDragController.setDeleteRegion(null);
-            startAnimation(mOutAnimation);
-            mHandle.startAnimation(mHandleInAnimation);
-            setVisibility(GONE);
+
+            if (mOutAnimation != null) startAnimation(mOutAnimation);
+            if (mHandleInAnimation != null) mHandle.startAnimation(mHandleInAnimation);
+
+            if (mManageVisibility) {
+                setVisibility(GONE);
+            }
         }
     }
 
@@ -228,6 +246,10 @@
         mHandle = view;
     }
 
+    void setManageVisibility(boolean value) {
+        mManageVisibility = value;
+    }
+
     private static class FastTranslateAnimation extends TranslateAnimation {
         public FastTranslateAnimation(int fromXType, float fromXValue, int toXType, float toXValue,
                 int fromYType, float fromYValue, int toYType, float toYValue) {