Merge "Fix SRI orientation on manta" into gb-ub-photos-carlsbad
diff --git a/src/com/android/camera/WideAnglePanoramaController.java b/src/com/android/camera/WideAnglePanoramaController.java
index 6ac7c51..d711c09 100644
--- a/src/com/android/camera/WideAnglePanoramaController.java
+++ b/src/com/android/camera/WideAnglePanoramaController.java
@@ -30,4 +30,6 @@
     public void onShutterButtonClick();
 
     public void onPreviewUILayoutChange(int l, int t, int r, int b);
+
+    public int getCameraOrientation();
 }
diff --git a/src/com/android/camera/WideAnglePanoramaModule.java b/src/com/android/camera/WideAnglePanoramaModule.java
index db4e59d..320b960 100644
--- a/src/com/android/camera/WideAnglePanoramaModule.java
+++ b/src/com/android/camera/WideAnglePanoramaModule.java
@@ -647,6 +647,13 @@
         return orientation;
     }
 
+    /** The orientation of the camera image. The value is the angle that the camera
+     *  image needs to be rotated clockwise so it shows correctly on the display
+     *  in its natural orientation. It should be 0, 90, 180, or 270.*/
+    public int getCameraOrientation() {
+        return mCameraOrientation;
+    }
+
     public void saveHighResMosaic() {
         runBackgroundThread(new Thread() {
             @Override
diff --git a/src/com/android/camera/WideAnglePanoramaUI.java b/src/com/android/camera/WideAnglePanoramaUI.java
index b0f3de4..1546958 100644
--- a/src/com/android/camera/WideAnglePanoramaUI.java
+++ b/src/com/android/camera/WideAnglePanoramaUI.java
@@ -434,8 +434,13 @@
     }
 
     public void flipPreviewIfNeeded() {
-        if (CameraUtil.getDisplayRotation(mActivity) >= 180) {
-            // In either reverse landscape or reverse portrait
+        // Rotation needed to display image correctly clockwise
+        int cameraOrientation = mController.getCameraOrientation();
+        // Display rotated counter-clockwise
+        int displayRotation = CameraUtil.getDisplayRotation(mActivity);
+        // Rotation needed to display image correctly on current display
+        int rotation = (cameraOrientation - displayRotation + 360) % 360;
+        if (rotation >= 180) {
             mTextureView.setRotation(180);
         } else {
             mTextureView.setRotation(0);