diff options
author | Eino-Ville Talvala <etalvala@google.com> | 2014-09-10 01:56:40 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2014-09-10 01:56:40 +0000 |
commit | ceb1cbf6be4768bc2dbcc9daa796146f96c0e430 (patch) | |
tree | 3d20ac044f180678e4f3467347f492c0ca5af7c3 /apps | |
parent | c0e7bda74eedf36b09a22032af106fa840f58330 (diff) | |
parent | 96a962a981772466e9d7b3fd8d0227693dbc38ec (diff) | |
download | pdk-ceb1cbf6be4768bc2dbcc9daa796146f96c0e430.tar.gz |
Merge "TestingCamera: Fix orientation setting." into lmp-dev
Diffstat (limited to 'apps')
-rw-r--r-- | apps/TestingCamera/src/com/android/testingcamera/TestingCamera.java | 32 |
1 files changed, 32 insertions, 0 deletions
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 |