Fixing a couple small issues with reordering (issue 7064138), (issue 7064337)

Change-Id: Iaaeb37f630a71f8fd54a6064602ddd10d4d4ab91
diff --git a/src/com/android/launcher2/AppWidgetResizeFrame.java b/src/com/android/launcher2/AppWidgetResizeFrame.java
index 2070eb6..eb60054 100644
--- a/src/com/android/launcher2/AppWidgetResizeFrame.java
+++ b/src/com/android/launcher2/AppWidgetResizeFrame.java
@@ -57,6 +57,7 @@
     private int mBottomTouchRegionAdjustment = 0;
 
     int[] mDirectionVector = new int[2];
+    int[] mLastDirectionVector = new int[2];
 
     final int SNAP_DURATION = 150;
     final int BACKGROUND_PADDING = 24;
@@ -293,17 +294,31 @@
         if (mLeftBorderActive || mRightBorderActive) {
             spanX += hSpanInc;
             cellX += cellXInc;
-            mDirectionVector[0] = mLeftBorderActive ? -1 : 1;
+            if (hSpanDelta != 0) {
+                mDirectionVector[0] = mLeftBorderActive ? -1 : 1;
+            }
         }
 
         if (mTopBorderActive || mBottomBorderActive) {
             spanY += vSpanInc;
             cellY += cellYInc;
-            mDirectionVector[1] = mTopBorderActive ? -1 : 1;
+            if (vSpanDelta != 0) {
+                mDirectionVector[1] = mTopBorderActive ? -1 : 1;
+            }
         }
 
         if (!onDismiss && vSpanDelta == 0 && hSpanDelta == 0) return;
 
+        // We always want the final commit to match the feedback, so we make sure to use the
+        // last used direction vector when committing the resize / reorder.
+        if (onDismiss) {
+            mDirectionVector[0] = mLastDirectionVector[0];
+            mDirectionVector[1] = mLastDirectionVector[1];
+        } else {
+            mLastDirectionVector[0] = mDirectionVector[0];
+            mLastDirectionVector[1] = mDirectionVector[1];
+        }
+
         if (mCellLayout.createAreaForResize(cellX, cellY, spanX, spanY, mWidgetView,
                 mDirectionVector, onDismiss)) {
             lp.tmpCellX = cellX;