Resize widget frame now wraps the scaled widget view.

Previous implementation had space between the frame and
the widget ie. letterboxing.

Bug: 32176631
Change-Id: Ie50279f4edb94812120dea492aefa4f18218162f
diff --git a/src/com/android/launcher3/AppWidgetResizeFrame.java b/src/com/android/launcher3/AppWidgetResizeFrame.java
index c45ff7b..54faca3 100644
--- a/src/com/android/launcher3/AppWidgetResizeFrame.java
+++ b/src/com/android/launcher3/AppWidgetResizeFrame.java
@@ -354,19 +354,18 @@
     }
 
     public void snapToWidget(boolean animate) {
-        final DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams();
         DeviceProfile profile = mLauncher.getDeviceProfile();
-        int newWidth = (int) (mWidgetView.getWidth() * profile.appWidgetScale.x)
-                + 2 * mBackgroundPadding - mWidgetPadding.left - mWidgetPadding.right;
-        int newHeight = (int) (mWidgetView.getHeight() * profile.appWidgetScale.y)
-                + 2 * mBackgroundPadding - mWidgetPadding.top - mWidgetPadding.bottom;
+        float scale = Math.min(profile.appWidgetScale.x, profile.appWidgetScale.y);
 
-        mTmpPt[0] = mWidgetView.getLeft();
-        mTmpPt[1] = mWidgetView.getTop();
-        mDragLayer.getDescendantCoordRelativeToSelf(mCellLayout.getShortcutsAndWidgets(), mTmpPt);
+        mDragLayer.getViewRectRelativeToSelf(mWidgetView, sTmpRect);
 
-        int newX = mTmpPt[0] - mBackgroundPadding + mWidgetPadding.left;
-        int newY = mTmpPt[1] - mBackgroundPadding + mWidgetPadding.top;
+        int newWidth = 2 * mBackgroundPadding
+                + (int) (scale * (sTmpRect.width() - mWidgetPadding.left - mWidgetPadding.right));
+        int newHeight = 2 * mBackgroundPadding
+                + (int) (scale * (sTmpRect.height() - mWidgetPadding.top - mWidgetPadding.bottom));
+
+        int newX = (int) (sTmpRect.left - mBackgroundPadding + scale * mWidgetPadding.left);
+        int newY = (int) (sTmpRect.top - mBackgroundPadding + scale * mWidgetPadding.top);
 
         // We need to make sure the frame's touchable regions lie fully within the bounds of the
         // DragLayer. We allow the actual handles to be clipped, but we shift the touch regions
@@ -384,6 +383,7 @@
             mBottomTouchRegionAdjustment = 0;
         }
 
+        final DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams();
         if (!animate) {
             lp.width = newWidth;
             lp.height = newHeight;