From eafe204ce415d05c49f687512955bb78e2097cea Mon Sep 17 00:00:00 2001 From: Alexandre Dumont Date: Wed, 18 Jan 2012 00:28:43 +0100 Subject: [PATCH] Implement rotation compensation for landscape devices Retrieve the system property ro.device.screenrotation (value in 0, 90, 180, 270) and adjust the pictures/videos accordingly. Example of use: HTC Chacha, device with always fixed open keyboard and landscape screen. Without the use of that property (ro.device.screenrotation), all pictures and videos taken are rotated 90 degrees. Setting ro.device.screenrotation=90 will correct the issue. Change-Id: I8015318e676e12c6fbf2bce387ce5805186c514b --- src/com/android/camera/Camera.java | 8 +++++++- src/com/android/camera/VideoCamera.java | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/com/android/camera/Camera.java b/src/com/android/camera/Camera.java index d308d3341c..fe39385e2d 100644 --- a/src/com/android/camera/Camera.java +++ b/src/com/android/camera/Camera.java @@ -49,6 +49,7 @@ import android.os.Looper; import android.os.Message; import android.os.MessageQueue; +import android.os.SystemProperties; import android.preference.CheckBoxPreference; import android.provider.MediaStore; import android.provider.Settings; @@ -125,6 +126,11 @@ public class Camera extends BaseCamera implements View.OnClickListener, private static final int ZOOM_START = 1; private static final int ZOOM_STOPPING = 2; + // Property that indicates that the device screen is rotated by default + // Necesary to adjust the rotation of pictures/movies (0, 90, 180, 270) + private static final int mDeviceScreenRotation = + SystemProperties.getInt("ro.device.screenrotation", 0); + private int mZoomState = ZOOM_STOPPED; private boolean mSmoothZoomSupported = false; private int mZoomValue; // The current zoom value. @@ -825,7 +831,7 @@ private void capture() { info.orientation != 90) { rotation = (info.orientation - mOrientation + 360) % 360; } else { // back-facing camera (or acting like it) - rotation = (info.orientation + mOrientation) % 360; + rotation = (info.orientation + mOrientation - mDeviceScreenRotation ) % 360; } } mParameters.setRotation(rotation); diff --git a/src/com/android/camera/VideoCamera.java b/src/com/android/camera/VideoCamera.java index d2b6b84638..cc4eab4838 100644 --- a/src/com/android/camera/VideoCamera.java +++ b/src/com/android/camera/VideoCamera.java @@ -51,6 +51,7 @@ import android.os.Message; import android.os.StatFs; import android.os.SystemClock; +import android.os.SystemProperties; import android.provider.MediaStore; import android.provider.Settings; import android.provider.MediaStore.Video; @@ -124,6 +125,11 @@ public class VideoCamera extends BaseCamera private GestureDetector mGestureDetector; private final ZoomListener mZoomListener = new ZoomListener(); + // Property that indicates that the device screen is rotated by default + // Necesary to adjust the rotation of pictures/movies (0, 90, 180, 270) + private static final int mDeviceScreenRotation = + SystemProperties.getInt("ro.device.screenrotation", 0); + /** * An unpublished intent flag requesting to start recording straight away * and return as soon as recording is stopped. @@ -1119,7 +1125,7 @@ private void initializeRecorder() { if (info.facing == CameraInfo.CAMERA_FACING_FRONT) { rotation = (info.orientation - mOrientation + 360) % 360; } else { // back-facing camera - rotation = (info.orientation + mOrientation) % 360; + rotation = (info.orientation + mOrientation - mDeviceScreenRotation ) % 360; } } mMediaRecorder.setOrientationHint(rotation);