From e0b3fd627e41996f91e4629bf08071344a6a75e3 Mon Sep 17 00:00:00 2001 From: Pawit Pornkitprasan Date: Sat, 28 Dec 2013 13:47:57 +0700 Subject: Camera: fix preview for landscape devices Landscape devices have broken preview because PORTRAIT mode is being abused to check for screen rotation. Use proper rotation check to fix. Ported from cm-10.2 Change-Id: I75588cbce9843e180e4be7591f6a43bcec788506 --- src/com/android/camera/PhotoUI.java | 4 +--- src/com/android/camera/VideoUI.java | 8 ++------ src/com/android/camera/util/CameraUtil.java | 5 +++++ 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/com/android/camera/PhotoUI.java b/src/com/android/camera/PhotoUI.java index 50b5f64fe..9f6cc9833 100755 --- a/src/com/android/camera/PhotoUI.java +++ b/src/com/android/camera/PhotoUI.java @@ -344,9 +344,7 @@ public class PhotoUI implements PieListener, public void setAspectRatio(float ratio) { if (ratio <= 0.0) throw new IllegalArgumentException(); - if (mOrientationResize && - mActivity.getResources().getConfiguration().orientation - != Configuration.ORIENTATION_PORTRAIT) { + if (mOrientationResize && CameraUtil.isScreenRotated(mActivity)) { ratio = 1 / ratio; } diff --git a/src/com/android/camera/VideoUI.java b/src/com/android/camera/VideoUI.java index 75c9ab1db..02db6b390 100755 --- a/src/com/android/camera/VideoUI.java +++ b/src/com/android/camera/VideoUI.java @@ -382,9 +382,7 @@ public class VideoUI implements PieRenderer.PieListener, } else { ratio = (float) height / width; } - if (mOrientationResize && - mActivity.getResources().getConfiguration().orientation - != Configuration.ORIENTATION_PORTRAIT) { + if (mOrientationResize && CameraUtil.isScreenRotated(mActivity)) { ratio = 1 / ratio; } @@ -727,9 +725,7 @@ public class VideoUI implements PieRenderer.PieListener, } public void setAspectRatio(double ratio) { - if (mOrientationResize && - mActivity.getResources().getConfiguration().orientation - != Configuration.ORIENTATION_PORTRAIT) { + if (mOrientationResize && CameraUtil.isScreenRotated(mActivity)) { ratio = 1 / ratio; } diff --git a/src/com/android/camera/util/CameraUtil.java b/src/com/android/camera/util/CameraUtil.java index af15143b6..09c9277e4 100755 --- a/src/com/android/camera/util/CameraUtil.java +++ b/src/com/android/camera/util/CameraUtil.java @@ -474,6 +474,11 @@ public class CameraUtil { return 0; } + public static boolean isScreenRotated(Activity activity) { + int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); + return rotation != Surface.ROTATION_0 && rotation != Surface.ROTATION_180; + } + /** * Calculate the default orientation of the device based on the width and * height of the display when rotation = 0 (i.e. natural width and height) -- cgit v1.2.3