Merge "Created include filters for jacoco" into ub-launcher3-calgary
diff --git a/res/layout/widgets_list_row_view.xml b/res/layout/widgets_list_row_view.xml
index 4687b38..30a34d4 100644
--- a/res/layout/widgets_list_row_view.xml
+++ b/res/layout/widgets_list_row_view.xml
@@ -59,8 +59,8 @@
             android:id="@+id/widgets_cell_list"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
-            android:layout_marginStart="@dimen/widget_row_padding"
-            android:layout_marginLeft="@dimen/widget_row_padding"
+            android:paddingStart="@dimen/widget_row_padding"
+            android:paddingEnd="0dp"
             android:orientation="horizontal"
             android:divider="@drawable/widgets_row_divider"
             android:showDividers="middle"/>
diff --git a/src/com/android/launcher3/util/TransformingTouchDelegate.java b/src/com/android/launcher3/util/TransformingTouchDelegate.java
index da1de5e..3197ba9 100644
--- a/src/com/android/launcher3/util/TransformingTouchDelegate.java
+++ b/src/com/android/launcher3/util/TransformingTouchDelegate.java
@@ -33,6 +33,10 @@
 
     private final RectF mBounds;
 
+    private final RectF mTouchCheckBounds;
+    private float mTouchExtension;
+    private boolean mWasTouchOutsideBounds;
+
     private View mDelegateView;
     private boolean mDelegateTargeted;
 
@@ -41,10 +45,22 @@
 
         mDelegateView = delegateView;
         mBounds = new RectF();
+        mTouchCheckBounds = new RectF();
     }
 
     public void setBounds(int left, int top, int right, int bottom) {
         mBounds.set(left, top, right, bottom);
+        updateTouchBounds();
+    }
+
+    public void extendTouchBounds(float extension) {
+        mTouchExtension = extension;
+        updateTouchBounds();
+    }
+
+    private void updateTouchBounds() {
+        mTouchCheckBounds.set(mBounds);
+        mTouchCheckBounds.inset(-mTouchExtension, -mTouchExtension);
     }
 
     public void setDelegateView(View view) {
@@ -62,8 +78,9 @@
         boolean sendToDelegate = false;
         switch (event.getAction()) {
             case MotionEvent.ACTION_DOWN:
-                mDelegateTargeted = mBounds.contains(event.getX(), event.getY());
+                mDelegateTargeted = mTouchCheckBounds.contains(event.getX(), event.getY());
                 if (mDelegateTargeted) {
+                    mWasTouchOutsideBounds = !mBounds.contains(event.getX(), event.getY());
                     sendToDelegate = true;
                 }
                 break;
@@ -78,9 +95,15 @@
         }
         boolean handled = false;
         if (sendToDelegate) {
-            event.offsetLocation(-mBounds.left, -mBounds.top);
+            float x = event.getX();
+            float y = event.getY();
+            if (mWasTouchOutsideBounds) {
+                event.setLocation(mBounds.centerX(), mBounds.centerY());
+            } else {
+                event.offsetLocation(-mBounds.left, -mBounds.top);
+            }
             handled = mDelegateView.dispatchTouchEvent(event);
-            event.offsetLocation(mBounds.left, mBounds.top);
+            event.setLocation(x, y);
         }
         return handled;
     }
diff --git a/src/com/android/launcher3/widget/WidgetsContainerView.java b/src/com/android/launcher3/widget/WidgetsContainerView.java
index 538d4c9..083103c 100644
--- a/src/com/android/launcher3/widget/WidgetsContainerView.java
+++ b/src/com/android/launcher3/widget/WidgetsContainerView.java
@@ -48,6 +48,7 @@
 import com.android.launcher3.userevent.nano.LauncherLogProto;
 import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
 import com.android.launcher3.util.Thunk;
+import com.android.launcher3.util.TransformingTouchDelegate;
 
 /**
  * The widgets list view container.
@@ -63,11 +64,11 @@
     private IconCache mIconCache;
 
     private final Rect mTmpBgPaddingRect = new Rect();
-    private final Rect mTmpRect = new Rect();
 
     /* Recycler view related member variables */
     private WidgetsRecyclerView mRecyclerView;
     private WidgetsListAdapter mAdapter;
+    private TransformingTouchDelegate mRecyclerViewTouchDelegate;
 
     /* Touch handling related member variables. */
     private Toast mWidgetInstructionToast;
@@ -95,29 +96,29 @@
     }
 
     @Override
+    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
+        super.onLayout(changed, left, top, right, bottom);
+        getRevealView().getBackground().getPadding(mTmpBgPaddingRect);
+        mRecyclerViewTouchDelegate.setBounds(
+                mRecyclerView.getLeft() - mTmpBgPaddingRect.left,
+                mRecyclerView.getTop() - mTmpBgPaddingRect.top,
+                mRecyclerView.getRight() + mTmpBgPaddingRect.right,
+                mRecyclerView.getBottom() + mTmpBgPaddingRect.bottom);
+    }
+
+    @Override
     protected void onFinishInflate() {
         super.onFinishInflate();
         mRecyclerView = (WidgetsRecyclerView) getContentView().findViewById(R.id.widgets_list_view);
         mRecyclerView.setAdapter(mAdapter);
         mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
+        mRecyclerViewTouchDelegate = new TransformingTouchDelegate(mRecyclerView);
     }
 
     @Override
-    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
-        getRevealView().getBackground().getPadding(mTmpBgPaddingRect);
-        if (Utilities.isRtl(getResources())) {
-            getContentView().setPadding(0, mTmpBgPaddingRect.top, mTmpBgPaddingRect.right,
-                    mTmpBgPaddingRect.bottom);
-            mTmpRect.set(mTmpBgPaddingRect.left, 0, 0, 0);
-            mRecyclerView.updateBackgroundPadding(mTmpRect);
-        } else {
-            getContentView().setPadding(mTmpBgPaddingRect.left, mTmpBgPaddingRect.top, 0,
-                    mTmpBgPaddingRect.bottom);
-            mTmpRect.set(0, 0, mTmpBgPaddingRect.right, 0);
-            mRecyclerView.updateBackgroundPadding(mTmpRect);
-        }
-
-        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
+    protected void onAttachedToWindow() {
+        super.onAttachedToWindow();
+        ((View) mRecyclerView.getParent()).setTouchDelegate(mRecyclerViewTouchDelegate);
     }
 
     //