]> Pileus Git - ~andy/freeotp/commitdiff
Fix camera orientation issue
authorNathaniel McCallum <npmccallum@redhat.com>
Fri, 10 Jan 2014 21:38:50 +0000 (16:38 -0500)
committerNathaniel McCallum <npmccallum@redhat.com>
Fri, 10 Jan 2014 21:38:50 +0000 (16:38 -0500)
src/org/fedorahosted/freeotp/CameraDialogFragment.java

index 80c6c9bc6eb24ee0fac4bdba6838017a0ba7dfca..dfc8eb65b47ae746dd59e9d4dd42eb0ab35cc080 100644 (file)
@@ -114,6 +114,9 @@ public class CameraDialogFragment extends BaseAlertDialogFragment
                if (mCamera == null)
                        return;
 
+               // The code in this section comes from the developer docs. See:
+               //    http://developer.android.com/reference/android/hardware/Camera.html#setDisplayOrientation(int)
+
                int rotation = 0;
                switch (getActivity().getWindowManager().getDefaultDisplay().getRotation()) {
                case Surface.ROTATION_0:
@@ -130,7 +133,19 @@ public class CameraDialogFragment extends BaseAlertDialogFragment
                        break;
                }
 
-               mCamera.setDisplayOrientation((mCameraInfo.orientation - rotation + 360) % 360);
+               int result = 0;
+               switch (mCameraInfo.facing) {
+               case Camera.CameraInfo.CAMERA_FACING_FRONT:
+                       result = (mCameraInfo.orientation + rotation) % 360;
+                       result = (360 - result) % 360; // compensate the mirror
+                       break;
+
+               case Camera.CameraInfo.CAMERA_FACING_BACK:
+                       result = (mCameraInfo.orientation - rotation + 360) % 360;
+                       break;
+               }
+
+               mCamera.setDisplayOrientation(result);
                mCamera.startPreview();
 
                if (mHandler != null)