Move TransformingTouchDelegate logic to BaseContainerView.

In ag/1460444 we used TransformingTouchDelegate to extend the
touch target for the widgets list. Now both WidgetsContainerView
and AllAppsContainerView will use the same TransformingTouchDelegate logic
to extend the touch target for their respective lists.

This is part of a larger refactor where in a follow up CL, we will
handle the logic for dismissing WCV and AACV when touching outside
of its content in BaseContainerView. (currently broken in WCV).

Change-Id: I7fddb456bba34a6533f8824da0481d308a8b715e
diff --git a/src/com/android/launcher3/BaseContainerView.java b/src/com/android/launcher3/BaseContainerView.java
index 96942ee..fe95106 100644
--- a/src/com/android/launcher3/BaseContainerView.java
+++ b/src/com/android/launcher3/BaseContainerView.java
@@ -18,6 +18,7 @@
 
 import android.content.Context;
 import android.content.res.TypedArray;
+import android.graphics.Rect;
 import android.graphics.drawable.ColorDrawable;
 import android.graphics.drawable.Drawable;
 import android.graphics.drawable.InsetDrawable;
@@ -27,6 +28,7 @@
 
 import com.android.launcher3.allapps.AllAppsContainerView;
 import com.android.launcher3.config.FeatureFlags;
+import com.android.launcher3.util.TransformingTouchDelegate;
 
 /**
  * A base container view, which supports resizing.
@@ -39,12 +41,14 @@
     protected int mContainerPaddingTop;
     protected int mContainerPaddingBottom;
 
-    private InsetDrawable mRevealDrawable;
     protected final Drawable mBaseDrawable;
+    private final Rect mBgPaddingRect = new Rect();
 
     private View mRevealView;
     private View mContent;
 
+    private TransformingTouchDelegate mTouchDelegate;
+
     public BaseContainerView(Context context) {
         this(context, null);
     }
@@ -72,6 +76,12 @@
 
         DeviceProfile grid = Launcher.getLauncher(getContext()).getDeviceProfile();
         grid.addLauncherLayoutChangedListener(this);
+
+        View touchDelegateTargetView = getTouchDelegateTargetView();
+        if (touchDelegateTargetView != null) {
+            mTouchDelegate = new TransformingTouchDelegate(touchDelegateTargetView);
+            ((View) touchDelegateTargetView.getParent()).setTouchDelegate(mTouchDelegate);
+        }
     }
 
     @Override
@@ -93,6 +103,21 @@
     }
 
     @Override
+    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
+        super.onLayout(changed, left, top, right, bottom);
+        getRevealView().getBackground().getPadding(mBgPaddingRect);
+
+        View touchDelegateTargetView = getTouchDelegateTargetView();
+        if (touchDelegateTargetView != null) {
+            mTouchDelegate.setBounds(
+                    touchDelegateTargetView.getLeft() - mBgPaddingRect.left,
+                    touchDelegateTargetView.getTop() - mBgPaddingRect.top,
+                    touchDelegateTargetView.getRight() + mBgPaddingRect.right,
+                    touchDelegateTargetView.getBottom() + mBgPaddingRect.bottom);
+        }
+    }
+
+    @Override
     public void onLauncherLayoutChanged() {
         updatePaddings();
     }
@@ -130,14 +155,12 @@
             }
         }
 
-        mRevealDrawable = new InsetDrawable(mBaseDrawable,
+        InsetDrawable revealDrawable = new InsetDrawable(mBaseDrawable,
                 mContainerPaddingLeft, mContainerPaddingTop, mContainerPaddingRight,
                 mContainerPaddingBottom);
-        mRevealView.setBackground(mRevealDrawable);
-        if (FeatureFlags.LAUNCHER3_ALL_APPS_PULL_UP && this instanceof AllAppsContainerView) {
-            // Skip updating the content background
-        } else {
-            mContent.setBackground(mRevealDrawable);
-        }
+        mRevealView.setBackground(revealDrawable);
+        mContent.setBackground(revealDrawable);
     }
+
+    public abstract View getTouchDelegateTargetView();
 }