Skip to content

Commit

Permalink
Implement rotation compensation for landscape devices
Browse files Browse the repository at this point in the history
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
  • Loading branch information
adumont committed Jan 17, 2012
1 parent 40ebde4 commit eafe204
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/com/android/camera/Camera.java
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 7 additions & 1 deletion src/com/android/camera/VideoCamera.java
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit eafe204

Please sign in to comment.