Improve image size change handling.

- When the camera relative frame is set, we delay the change for camera
rectange until the next setImageSize call. This avoids the unwanted
intermediate state if we change them separately.

- Don't draw other screennails when the camera is in full screen. This
avoids showing other screennails when the image size changes.

- When the aspect ratio of the image changes, we assume the view angle
of the longer side doesn't change (so the aspect ratio change is because
the view angle of the shorter side changes). This matches what camera
preview does.

Bug: 6566612

Change-Id: I7603416f31c96ba77c96cdc2a3d0b79f8921c491
diff --git a/src/com/android/gallery3d/ui/PositionController.java b/src/com/android/gallery3d/ui/PositionController.java
index db77b99..cf41d3a 100644
--- a/src/com/android/gallery3d/ui/PositionController.java
+++ b/src/com/android/gallery3d/ui/PositionController.java
@@ -218,28 +218,34 @@
         }
     }
 
-    public void setConstrainedFrame(Rect f) {
-        if (mConstrainedFrame.equals(f)) return;
-        mConstrainedFrame.set(f);
+    public void setConstrainedFrame(Rect cFrame) {
+        if (mConstrainedFrame.equals(cFrame)) return;
+        mConstrainedFrame.set(cFrame);
         mPlatform.updateDefaultXY();
         updateScaleAndGapLimit();
         snapAndRedraw();
     }
 
-    public void setImageSize(int index, int width, int height, boolean force) {
-        if (force) {
-            Box b = mBoxes.get(index);
-            b.mImageW = width;
-            b.mImageH = height;
-            return;
-        }
+    public void forceImageSize(int index, int width, int height) {
+        if (width == 0 || height == 0) return;
+        Box b = mBoxes.get(index);
+        b.mImageW = width;
+        b.mImageH = height;
+        return;
+    }
 
-        if (width == 0 || height == 0) {
-            initBox(index);
-        } else if (!setBoxSize(index, width, height, false)) {
-            return;
-        }
+    public void setImageSize(int index, int width, int height, Rect cFrame) {
+        if (width == 0 || height == 0) return;
 
+        boolean needUpdate = false;
+        if (cFrame != null && !mConstrainedFrame.equals(cFrame)) {
+            mConstrainedFrame.set(cFrame);
+            mPlatform.updateDefaultXY();
+            needUpdate = true;
+        }
+        needUpdate |= setBoxSize(index, width, height, false);
+
+        if (!needUpdate) return;
         updateScaleAndGapLimit();
         snapAndRedraw();
     }
@@ -259,8 +265,15 @@
         }
 
         // The ratio of the old size and the new size.
-        float ratio = Math.min(
-                (float) b.mImageW / width, (float) b.mImageH / height);
+        //
+        // If the aspect ratio changes, we don't know if it is because one side
+        // grows or the other side shrinks. Currently we just assume the view
+        // angle of the longer side doesn't change (so the aspect ratio change
+        // is because the view angle of the shorter side changes). This matches
+        // what camera preview does.
+        float ratio = (width > height)
+                ? (float) b.mImageW / width
+                : (float) b.mImageH / height;
 
         b.mImageW = width;
         b.mImageH = height;