Merge "Fixed drag to remove favorite contacts on a few devices."
diff --git a/java/com/android/dialer/main/impl/OldMainActivityPeer.java b/java/com/android/dialer/main/impl/OldMainActivityPeer.java
index 70444bd..9e8bd1a 100644
--- a/java/com/android/dialer/main/impl/OldMainActivityPeer.java
+++ b/java/com/android/dialer/main/impl/OldMainActivityPeer.java
@@ -43,6 +43,7 @@
 import android.telecom.PhoneAccountHandle;
 import android.telephony.TelephonyManager;
 import android.text.TextUtils;
+import android.view.DragEvent;
 import android.view.View;
 import android.widget.ImageView;
 import com.android.contacts.common.list.OnPhoneNumberPickerActionListener;
@@ -246,6 +247,7 @@
     oldSpeedDialFragmentHost =
         new MainOldSpeedDialFragmentHost(
             activity,
+            activity.findViewById(R.id.root_layout),
             bottomNav,
             activity.findViewById(R.id.contact_tile_drag_shadow_overlay),
             activity.findViewById(R.id.remove_view),
@@ -1024,34 +1026,42 @@
       implements OldSpeedDialFragment.HostInterface, OnDragDropListener {
 
     private final Context context;
+    private final View rootLayout;
     private final BottomNavBar bottomNavBar;
     private final ImageView dragShadowOverlay;
     private final RemoveView removeView;
+    private final View removeViewContent;
     private final View searchViewContainer;
     private final MainToolbar toolbar;
 
-    // TODO(calderwoodra): Use this for drag and drop
-    @SuppressWarnings("unused")
-    private DragDropController dragDropController;
-
     MainOldSpeedDialFragmentHost(
         Context context,
+        View rootLayout,
         BottomNavBar bottomNavBar,
         ImageView dragShadowOverlay,
         RemoveView removeView,
         View searchViewContainer,
         MainToolbar toolbar) {
       this.context = context;
+      this.rootLayout = rootLayout;
       this.bottomNavBar = bottomNavBar;
       this.dragShadowOverlay = dragShadowOverlay;
       this.removeView = removeView;
       this.searchViewContainer = searchViewContainer;
       this.toolbar = toolbar;
+      removeViewContent = removeView.findViewById(R.id.remove_view_content);
     }
 
     @Override
     public void setDragDropController(DragDropController dragDropController) {
       removeView.setDragDropController(dragDropController);
+      rootLayout.setOnDragListener(
+          (v, event) -> {
+            if (event.getAction() == DragEvent.ACTION_DRAG_LOCATION) {
+              dragDropController.handleDragHovered(v, (int) event.getX(), (int) event.getY());
+            }
+            return true;
+          });
     }
 
     @Override
@@ -1088,9 +1098,9 @@
 
     private void showRemoveView(boolean show) {
       if (show) {
-        AnimUtils.crossFadeViews(removeView, searchViewContainer, 300);
+        AnimUtils.crossFadeViews(removeViewContent, searchViewContainer, 300);
       } else {
-        AnimUtils.crossFadeViews(searchViewContainer, removeView, 300);
+        AnimUtils.crossFadeViews(searchViewContainer, removeViewContent, 300);
       }
     }
   }
diff --git a/java/com/android/dialer/main/impl/res/layout/stub_fragment.xml b/java/com/android/dialer/main/impl/res/layout/stub_fragment.xml
deleted file mode 100644
index 3bb744f..0000000
--- a/java/com/android/dialer/main/impl/res/layout/stub_fragment.xml
+++ /dev/null
@@ -1,27 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-  ~ Copyright (C) 2017 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.
-  ~ You may obtain a copy of the License at
-  ~
-  ~      http://www.apache.org/licenses/LICENSE-2.0
-  ~
-  ~ Unless required by applicable law or agreed to in writing, software
-  ~ distributed under the License is distributed on an "AS IS" BASIS,
-  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  ~ See the License for the specific language governing permissions and
-  ~ limitations under the License
-  -->
-<FrameLayout
-    xmlns:android="http://schemas.android.com/apk/res/android"
-    android:layout_width="match_parent"
-    android:layout_height="match_parent">
-
-  <TextView
-      android:text="hello world!"
-      android:layout_width="wrap_content"
-      android:layout_height="wrap_content"
-      android:layout_gravity="center"/>
-</FrameLayout>
\ No newline at end of file
diff --git a/java/com/android/dialer/main/impl/toolbar/res/layout/toolbar_layout.xml b/java/com/android/dialer/main/impl/toolbar/res/layout/toolbar_layout.xml
index 3ab20c1..c7c37d0 100644
--- a/java/com/android/dialer/main/impl/toolbar/res/layout/toolbar_layout.xml
+++ b/java/com/android/dialer/main/impl/toolbar/res/layout/toolbar_layout.xml
@@ -100,16 +100,18 @@
       android:layout_gravity="center_vertical"
       android:layout_margin="@dimen/search_bar_margin"
       android:contentDescription="@string/main_remove_contact"
-      android:visibility="gone"
       android:importantForAccessibility="no">
 
+    <!-- We set this view's visibility to gone instead of the parent because if we hide remove
+    view, it won't receive drag and accessibility events. -->
     <LinearLayout
         android:id="@+id/remove_view_content"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:background="@color/dialer_theme_color"
         android:gravity="center"
-        android:orientation="horizontal">
+        android:orientation="horizontal"
+        android:visibility="gone">
 
       <ImageView
           android:id="@+id/remove_view_icon"