From 96a962a981772466e9d7b3fd8d0227693dbc38ec Mon Sep 17 00:00:00 2001 From: Eino-Ville Talvala Date: Mon, 8 Sep 2014 17:04:13 -0700 Subject: TestingCamera: Fix orientation setting. It's not actually possible to skip this call, even for an app that's forced landscape. Bug: 17393631 Change-Id: Icf992117e5d45f1a1737f6b20dff73c7f36201a9 --- .../com/android/testingcamera/TestingCamera.java | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'apps') diff --git a/apps/TestingCamera/src/com/android/testingcamera/TestingCamera.java b/apps/TestingCamera/src/com/android/testingcamera/TestingCamera.java index f28ec34..70e8835 100644 --- a/apps/TestingCamera/src/com/android/testingcamera/TestingCamera.java +++ b/apps/TestingCamera/src/com/android/testingcamera/TestingCamera.java @@ -33,6 +33,7 @@ import android.os.Environment; import android.os.Handler; import android.os.SystemClock; import android.view.View; +import android.view.Surface; import android.view.SurfaceHolder; import android.view.SurfaceView; import android.view.View.OnClickListener; @@ -404,6 +405,35 @@ public class TestingCamera extends Activity mPreviewHolder = null; } + public void setCameraDisplayOrientation() { + android.hardware.Camera.CameraInfo info = + new android.hardware.Camera.CameraInfo(); + android.hardware.Camera.getCameraInfo(mCameraId, info); + int rotation = getWindowManager().getDefaultDisplay() + .getRotation(); + int degrees = 0; + switch (rotation) { + case Surface.ROTATION_0: degrees = 0; break; + case Surface.ROTATION_90: degrees = 90; break; + case Surface.ROTATION_180: degrees = 180; break; + case Surface.ROTATION_270: degrees = 270; break; + } + + int result; + if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { + result = (info.orientation + degrees) % 360; + result = (360 - result) % 360; // compensate the mirror + } else { // back-facing + result = (info.orientation - degrees + 360) % 360; + } + log(String.format( + "Camera sensor orientation %d, UI rotation %d, facing %s. Final orientation %d", + info.orientation, rotation, + info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT ? "FRONT" : "BACK", + result)); + mCamera.setDisplayOrientation(result); + } + /** UI controls enable/disable for all open-only controls */ private void enableOpenOnlyControls(boolean enabled) { for (View v : mOpenOnlyControls) { @@ -903,6 +933,8 @@ public class TestingCamera extends Activity } mCamera.setErrorCallback(this); + + setCameraDisplayOrientation(); mParams = mCamera.getParameters(); // Set up preview size selection -- cgit v1.2.3