Fixing issue where PIP did not stay minimized after rotation.

- Ensure that we reapply the minimized offset after applying the snap
  fraction to the rotated bounds
- Fixing small issue where we weren't bottom aligning the PIP when the
  visible IME changes size (but is not made invisible)
- Also fixing an issue where the touch gesture continually allowed
  swiping offscreen even after dragging the PIP a distance. Now, if no
  gesture handles the drag, then the default gesture will disallow
  offscreen dragging once it handles the move.
- Shrinking PIP slightly to fit proportions of screen.

Test: Enable minimization in SysUI tuner, put PIP into minimized state,
      rotate the screen.  This is not final UX and the CTS tests will
      be updated to reflect this behavior once it is final.

Change-Id: I15c851a0bcf5f867289bc5ad50d298f82a103308
diff --git a/packages/SystemUI/src/com/android/systemui/pip/phone/PipTouchState.java b/packages/SystemUI/src/com/android/systemui/pip/phone/PipTouchState.java
index 80af5a6..17d9864 100644
--- a/packages/SystemUI/src/com/android/systemui/pip/phone/PipTouchState.java
+++ b/packages/SystemUI/src/com/android/systemui/pip/phone/PipTouchState.java
@@ -40,6 +40,7 @@
     private final PointF mVelocity = new PointF();
     private boolean mIsDragging = false;
     private boolean mStartedDragging = false;
+    private boolean mAllowDraggingOffscreen = false;
     private int mActivePointerId;
 
     public PipTouchState(ViewConfiguration viewConfig) {
@@ -59,6 +60,7 @@
                 mDownTouch.set(mLastTouch);
                 mIsDragging = false;
                 mStartedDragging = false;
+                mAllowDraggingOffscreen = true;
                 break;
             }
             case MotionEvent.ACTION_MOVE: {
@@ -159,6 +161,20 @@
         return mStartedDragging;
     }
 
+    /**
+     * Disallows dragging offscreen for the duration of the current gesture.
+     */
+    public void setDisallowDraggingOffscreen() {
+        mAllowDraggingOffscreen = false;
+    }
+
+    /**
+     * @return whether dragging offscreen is allowed during this gesture.
+     */
+    public boolean allowDraggingOffscreen() {
+        return mAllowDraggingOffscreen;
+    }
+
     private void initOrResetVelocityTracker() {
         if (mVelocityTracker == null) {
             mVelocityTracker = VelocityTracker.obtain();