Refactor drag and drop to work for entire Dialer layout

Add a drag listener to the main dialer layout and manipulate
drag events correctly in DragDropController so that drag and
drop works throughout the main Dialer layout, rather than just the
speed dial fragment.

Also shift the remove view into dialtacts_mainlayout so that it can
continue receiving drag events.

Bug: 14393052

Change-Id: I90c26fee4fe681d0e237aa490185e850628e4cd0
diff --git a/src/com/android/dialer/DialtactsActivity.java b/src/com/android/dialer/DialtactsActivity.java
index ce71245..b965530 100644
--- a/src/com/android/dialer/DialtactsActivity.java
+++ b/src/com/android/dialer/DialtactsActivity.java
@@ -44,10 +44,12 @@
 import android.text.TextUtils;
 import android.text.TextWatcher;
 import android.util.Log;
+import android.view.DragEvent;
 import android.view.Menu;
 import android.view.MenuInflater;
 import android.view.MenuItem;
 import android.view.View;
+import android.view.View.OnDragListener;
 import android.view.animation.AccelerateInterpolator;
 import android.view.animation.DecelerateInterpolator;
 import android.view.animation.Interpolator;
@@ -56,7 +58,6 @@
 import android.widget.EditText;
 import android.widget.PopupMenu;
 import android.widget.RelativeLayout;
-import android.widget.SearchView;
 import android.widget.Toast;
 
 import com.android.contacts.common.CallUtil;
@@ -185,9 +186,6 @@
      */
     private String mPendingSearchViewQuery;
 
-    // This view points to the Framelayout that houses both the search view and remove view
-    // containers.
-    private View mSearchAndRemoveViewContainer;
     private EditText mSearchView;
     private View mSearchViewCloseButton;
     private View mVoiceSearchButton;
@@ -196,13 +194,14 @@
      * If the user releases a contact when hovering on top of this, the contact is unfavorited and
      * removed from the speed dial list.
      */
-    private RemoveView mRemoveViewContainer;
+    private View mRemoveViewContainer;
 
     final Interpolator hideActionBarInterpolator = new AccelerateInterpolator(1.5f);
     final Interpolator showActionBarInterpolator = new DecelerateInterpolator(1.5f);
     private String mSearchQuery;
 
     private DialerDatabaseHelper mDialerDatabaseHelper;
+    private DragDropController mDragDropController;
 
     private class OverflowPopupMenu extends PopupMenu {
         public OverflowPopupMenu(Context context, View anchor) {
@@ -220,6 +219,21 @@
     }
 
     /**
+     * Listener that listens to drag events and sends their x and y coordinates to a
+     * {@link DragDropController}.
+     */
+    private class LayoutOnDragListener implements OnDragListener {
+        @Override
+        public boolean onDrag(View v, DragEvent event) {
+            if (event.getAction() == DragEvent.ACTION_DRAG_LOCATION) {
+                mDragDropController.handleDragHovered(v, (int) event.getX(),
+                        (int) event.getY());
+            }
+            return true;
+        }
+    }
+
+    /**
      * Listener used when one of phone numbers in search UI is selected. This will initiate a
      * phone call using the phone number.
      */
@@ -363,11 +377,12 @@
         mDialpadButton = findViewById(R.id.dialpad_button);
         mDialpadButton.setOnClickListener(this);
 
-        mRemoveViewContainer = (RemoveView) findViewById(R.id.remove_view_container);
-        mSearchAndRemoveViewContainer = findViewById(R.id.search_and_remove_view_container);
+        mRemoveViewContainer = findViewById(R.id.remove_view_container);
 
         mDialerDatabaseHelper = DatabaseHelperManager.getDatabaseHelper(this);
         SmartDialPrefix.initializeNanpSettings(this);
+
+        findViewById(R.id.dialtacts_mainlayout).setOnDragListener(new LayoutOnDragListener());
     }
 
     @Override
@@ -574,13 +589,6 @@
         ft.commit();
     }
 
-    final AnimatorListener mHideListener = new AnimatorListenerAdapter() {
-        @Override
-        public void onAnimationEnd(Animator animation) {
-            mSearchAndRemoveViewContainer.setVisibility(View.GONE);
-        }
-    };
-
     private boolean getInSearchUi() {
         return mInDialpadSearch || mInRegularSearch;
     }
@@ -936,11 +944,12 @@
     @Override
     public void onDragStarted(int x, int y, PhoneFavoriteSquareTileView view) {
         getActionBar().hide();
-        mSearchAndRemoveViewContainer.setVisibility(View.VISIBLE);
+        mRemoveViewContainer.setVisibility(View.VISIBLE);
     }
 
     @Override
-    public void onDragHovered(int x, int y, PhoneFavoriteSquareTileView view) {}
+    public void onDragHovered(int x, int y, PhoneFavoriteSquareTileView view) {
+    }
 
     /**
      * Called when the user has released a contact tile after long-pressing it.
@@ -948,7 +957,7 @@
     @Override
     public void onDragFinished(int x, int y) {
         getActionBar().show();
-        mSearchAndRemoveViewContainer.setVisibility(View.GONE);
+        mRemoveViewContainer.setVisibility(View.GONE);
     }
 
     @Override
@@ -960,7 +969,9 @@
      */
     @Override
     public void setDragDropController(DragDropController dragController) {
-        mRemoveViewContainer.setDragDropController(dragController);
+        mDragDropController = dragController;
+        ((RemoveView) findViewById(R.id.remove_view))
+                .setDragDropController(dragController);
     }
 
     @Override