OSDN Git Service

Fix portrait orientation on landscape devices
authorJohn Reck <jreck@google.com>
Thu, 11 Oct 2012 16:40:18 +0000 (09:40 -0700)
committerJohn Reck <jreck@google.com>
Thu, 11 Oct 2012 16:45:05 +0000 (09:45 -0700)
 Bug: 7328349

Change-Id: I0f871ea56e6afb5ba0b54cac15c18f79db07f4f9

src/com/android/gallery3d/app/OrientationManager.java

index a8ef99a..0e033eb 100644 (file)
@@ -98,8 +98,9 @@ public class OrientationManager implements OrientationSource {
     public void lockOrientation() {
         if (mOrientationLocked) return;
         mOrientationLocked = true;
+        int displayRotation = getDisplayRotation();
         // Display rotation >= 180 means we need to use the REVERSE landscape/portrait
-        boolean standard = getDisplayRotation() < 180;
+        boolean standard = displayRotation < 180;
         if (mActivity.getResources().getConfiguration().orientation
                 == Configuration.ORIENTATION_LANDSCAPE) {
             Log.d(TAG, "lock orientation to landscape");
@@ -107,6 +108,13 @@ public class OrientationManager implements OrientationSource {
                     ? ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
                     : ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
         } else {
+            if (displayRotation == 90 || displayRotation == 270) {
+                // If displayRotation = 90 or 270 then we are on a landscape
+                // device. On landscape devices, portrait is a 90 degree
+                // clockwise rotation from landscape, so we need
+                // to flip which portrait we pick as display rotation is counter clockwise
+                standard = !standard;
+            }
             Log.d(TAG, "lock orientation to portrait");
             mActivity.setRequestedOrientation(standard
                     ? ActivityInfo.SCREEN_ORIENTATION_PORTRAIT