summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorandralex8 <andralex8@gmail.com>2017-05-28 16:56:39 +0200
committerArne Coucheron <arco68@gmail.com>2017-06-12 19:43:05 +0000
commitd7247ff7c682a46b23bf56a4d8ed4d55a9523f00 (patch)
tree3fd2f94bb134bc2000acc28cdcb16b23cf0c9548
parent78666b57a88587e09178368b82140dc85424745d (diff)
downloadandroid_packages_apps_Snap-d7247ff7c682a46b23bf56a4d8ed4d55a9523f00.zip
android_packages_apps_Snap-d7247ff7c682a46b23bf56a4d8ed4d55a9523f00.tar.gz
android_packages_apps_Snap-d7247ff7c682a46b23bf56a4d8ed4d55a9523f00.tar.bz2
Add orientation correction for landscape devices
Snap does not correctly handle devices with a landscape screen as rotation is 0 when device is in landscape while Snap assume that 0 is portrait. This lead to a rotated gui and a deformed preview. This commit: - Solve the gui rotation for Photo, Video and Panorama modules - Solve the deformed preview for Photo and Video (Panorama preview was ok with gui fix) - Solve the PhotoMenu rotation (all devices, it was also broken on portrait devices) Change-Id: Ic0b95904da6e13946c7e46e2e571b26da498db02
-rw-r--r--src/com/android/camera/PhotoModule.java5
-rw-r--r--src/com/android/camera/PhotoUI.java4
-rw-r--r--src/com/android/camera/VideoModule.java10
-rw-r--r--src/com/android/camera/VideoUI.java3
-rw-r--r--src/com/android/camera/WideAnglePanoramaModule.java7
5 files changed, 23 insertions, 6 deletions
diff --git a/src/com/android/camera/PhotoModule.java b/src/com/android/camera/PhotoModule.java
index c9fe960..2a902e2 100644
--- a/src/com/android/camera/PhotoModule.java
+++ b/src/com/android/camera/PhotoModule.java
@@ -289,6 +289,7 @@ public class PhotoModule extends BaseModule<PhotoUI> implements
private boolean mMirror;
private boolean mFirstTimeInitialized;
private boolean mIsImageCaptureIntent;
+ private int mOrientationOffset;
private int mCameraState = INIT;
private boolean mSnapshotOnIdle = false;
@@ -556,6 +557,7 @@ public class PhotoModule extends BaseModule<PhotoUI> implements
public void init(CameraActivity activity, View parent) {
mActivity = activity;
mRootView = parent;
+ mOrientationOffset = CameraUtil.isDefaultToPortrait(mActivity) ? 0 : 90;
mPreferences = ComboPreferences.get(mActivity);
if (mPreferences == null) {
mPreferences = new ComboPreferences(mActivity);
@@ -1704,7 +1706,7 @@ public class PhotoModule extends BaseModule<PhotoUI> implements
}
// Set rotation and gps data.
- int orientation = mOrientation;
+ int orientation = (mOrientation + mOrientationOffset) % 360;
mJpegRotation = CameraUtil.getJpegRotation(mCameraId, orientation);
String pictureFormat = mParameters.get(KEY_PICTURE_FORMAT);
Location loc = getLocationAccordPictureFormat(pictureFormat);
@@ -2181,6 +2183,7 @@ public class PhotoModule extends BaseModule<PhotoUI> implements
// the camera then point the camera to floor or sky, we still have
// the correct orientation.
if (orientation == OrientationEventListener.ORIENTATION_UNKNOWN) return;
+ orientation = (orientation - mOrientationOffset + 360) % 360;
int oldOrientation = mOrientation;
mOrientation = CameraUtil.roundOrientation(orientation, mOrientation);
if (oldOrientation != mOrientation) {
diff --git a/src/com/android/camera/PhotoUI.java b/src/com/android/camera/PhotoUI.java
index a6d806f..0012dd4 100644
--- a/src/com/android/camera/PhotoUI.java
+++ b/src/com/android/camera/PhotoUI.java
@@ -303,6 +303,9 @@ public class PhotoUI extends BaseUI implements PieListener,
FrameLayout.LayoutParams lp;
float scaledTextureWidth, scaledTextureHeight;
int rotation = CameraUtil.getDisplayRotation(mActivity);
+ if(!CameraUtil.isDefaultToPortrait(mActivity)) {
+ rotation = (rotation - 90) % 360;
+ }
mScreenRatio = CameraUtil.determineRatio(ratio);
if (mScreenRatio == CameraUtil.RATIO_16_9
&& CameraUtil.determinCloseRatio(ratio) == CameraUtil.RATIO_4_3) {
@@ -1189,6 +1192,7 @@ public class PhotoUI extends BaseUI implements PieListener,
RotateImageView v = (RotateImageView) mReviewImage;
v.setOrientation(orientation, animation);
}
+ mOrientation = orientation;
}
public void tryToCloseSubList() {
diff --git a/src/com/android/camera/VideoModule.java b/src/com/android/camera/VideoModule.java
index dd9c9bb..e4f5bc2 100644
--- a/src/com/android/camera/VideoModule.java
+++ b/src/com/android/camera/VideoModule.java
@@ -194,6 +194,7 @@ public class VideoModule extends BaseModule<VideoUI> implements
// true.
private int mDisplayRotation;
private int mCameraDisplayOrientation;
+ private int mOrientationOffset;
private int mDesiredPreviewWidth;
private int mDesiredPreviewHeight;
@@ -543,6 +544,7 @@ public class VideoModule extends BaseModule<VideoUI> implements
@Override
public void init(CameraActivity activity, View root) {
mActivity = activity;
+ mOrientationOffset = CameraUtil.isDefaultToPortrait(mActivity) ? 0 : 90;
mPreferences = ComboPreferences.get(mActivity);
if (mPreferences == null) {
@@ -690,7 +692,8 @@ public class VideoModule extends BaseModule<VideoUI> implements
}
// Set rotation and gps data.
- int rotation = CameraUtil.getJpegRotation(mCameraId, mOrientation);
+ int orientation = (mOrientation + mOrientationOffset) % 360;
+ int rotation = CameraUtil.getJpegRotation(mCameraId, orientation);
mParameters.setRotation(rotation);
Location loc = mLocationManager.getCurrentLocation();
CameraUtil.setGpsParameters(mParameters, loc);
@@ -766,6 +769,7 @@ public class VideoModule extends BaseModule<VideoUI> implements
// the camera then point the camera to floor or sky, we still have
// the correct orientation.
if (orientation == OrientationEventListener.ORIENTATION_UNKNOWN) return;
+ orientation = (orientation - mOrientationOffset + 360) % 360;
int newOrientation = CameraUtil.roundOrientation(orientation, mOrientation);
if (mOrientation != newOrientation) {
@@ -1870,9 +1874,9 @@ public class VideoModule extends BaseModule<VideoUI> implements
if (mOrientation != OrientationEventListener.ORIENTATION_UNKNOWN) {
CameraInfo info = CameraHolder.instance().getCameraInfo()[mCameraId];
if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {
- rotation = (info.orientation - mOrientation + 360) % 360;
+ rotation = (info.orientation - mOrientation - mOrientationOffset + 360) % 360;
} else { // back-facing camera
- rotation = (info.orientation + mOrientation) % 360;
+ rotation = (info.orientation + mOrientation + mOrientationOffset) % 360;
}
}
mMediaRecorder.setOrientationHint(rotation);
diff --git a/src/com/android/camera/VideoUI.java b/src/com/android/camera/VideoUI.java
index 0b51970..fcb1c83 100644
--- a/src/com/android/camera/VideoUI.java
+++ b/src/com/android/camera/VideoUI.java
@@ -334,6 +334,9 @@ public class VideoUI extends BaseUI implements PieRenderer.PieListener,
float scaledTextureWidth = 0.0f, scaledTextureHeight = 0.0f;
int rotation = CameraUtil.getDisplayRotation(mActivity);
+ if(!CameraUtil.isDefaultToPortrait(mActivity)) {
+ rotation = (rotation - 90) % 360;
+ }
mScreenRatio = CameraUtil.determineRatio(ratio);
if (mScreenRatio == CameraUtil.RATIO_16_9
&& CameraUtil.determinCloseRatio(ratio) == CameraUtil.RATIO_4_3) {
diff --git a/src/com/android/camera/WideAnglePanoramaModule.java b/src/com/android/camera/WideAnglePanoramaModule.java
index ec61da4..3ca9c2f 100644
--- a/src/com/android/camera/WideAnglePanoramaModule.java
+++ b/src/com/android/camera/WideAnglePanoramaModule.java
@@ -129,6 +129,7 @@ public class WideAnglePanoramaModule extends BaseModule<WideAnglePanoramaUI> imp
// respectively.
private int mDeviceOrientation;
private int mDeviceOrientationAtCapture;
+ private int mOrientationOffset;
private int mCameraOrientation;
private int mOrientationCompensation;
private boolean mOrientationLocked;
@@ -193,6 +194,7 @@ public class WideAnglePanoramaModule extends BaseModule<WideAnglePanoramaUI> imp
// the camera then point the camera to floor or sky, we still have
// the correct orientation.
if (orientation == ORIENTATION_UNKNOWN) return;
+ orientation = (orientation - mOrientationOffset + 360) % 360;
int oldOrientation = mDeviceOrientation;
mDeviceOrientation = CameraUtil.roundOrientation(orientation, mDeviceOrientation);
// When the screen is unlocked, display rotation may change. Always
@@ -226,6 +228,7 @@ public class WideAnglePanoramaModule extends BaseModule<WideAnglePanoramaUI> imp
public void init(CameraActivity activity, View parent) {
mActivity = activity;
mRootView = parent;
+ mOrientationOffset = CameraUtil.isDefaultToPortrait(mActivity) ? 0 : 90;
mOrientationManager = new OrientationManager(activity);
mCaptureState = CAPTURE_STATE_VIEWFINDER;
@@ -750,9 +753,9 @@ public class WideAnglePanoramaModule extends BaseModule<WideAnglePanoramaUI> imp
if (mUsingFrontCamera) {
// mCameraOrientation is negative with respect to the front facing camera.
// See document of android.hardware.Camera.Parameters.setRotation.
- orientation = (mDeviceOrientationAtCapture - mCameraOrientation - 360) % 360;
+ orientation = (mDeviceOrientationAtCapture - mCameraOrientation - mOrientationOffset + 360) % 360;
} else {
- orientation = (mDeviceOrientationAtCapture + mCameraOrientation) % 360;
+ orientation = (mDeviceOrientationAtCapture + mCameraOrientation + mOrientationOffset) % 360;
}
return orientation;
}