From: Nathaniel McCallum Date: Fri, 10 Jan 2014 21:38:50 +0000 (-0500) Subject: Fix camera orientation issue X-Git-Url: http://pileus.org/git/?p=~andy%2Ffreeotp;a=commitdiff_plain;h=897fea8dac2cca113f826a2d131e0320f94ace53 Fix camera orientation issue --- diff --git a/src/org/fedorahosted/freeotp/CameraDialogFragment.java b/src/org/fedorahosted/freeotp/CameraDialogFragment.java index 80c6c9b..dfc8eb6 100644 --- a/src/org/fedorahosted/freeotp/CameraDialogFragment.java +++ b/src/org/fedorahosted/freeotp/CameraDialogFragment.java @@ -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)