From cb539846b2559b40cf96361891265fd47f88d3fb Mon Sep 17 00:00:00 2001 From: Danesh Mondegarian Date: Sat, 8 Jun 2013 13:01:39 -0400 Subject: Utils : Fix tablet orientation logic Tablets have orientations for portrait reversed, this commit addresses it. Add in a few more orientation-aware safety checks to circumvent certain devices whose default orientation does not match their device type. Change-Id: Idc627e687ca61ab29f08433664bf77148424bd6d --- src/com/android/settings/Utils.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/com/android/settings/Utils.java b/src/com/android/settings/Utils.java index 7e92321..aa958d3 100644 --- a/src/com/android/settings/Utils.java +++ b/src/com/android/settings/Utils.java @@ -30,6 +30,7 @@ import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.ResolveInfo; import android.content.pm.UserInfo; +import android.content.res.Configuration; import android.content.res.Resources; import android.content.res.Resources.NotFoundException; import android.database.Cursor; @@ -696,23 +697,23 @@ public class Utils { public static void lockCurrentOrientation(Activity act) { int currentRotation = act.getWindowManager().getDefaultDisplay().getRotation(); int frozenRotation = 0; - boolean isTablet = isTablet(act); + int orientation = act.getResources().getConfiguration().orientation; switch(currentRotation) { case Surface.ROTATION_0: - frozenRotation = isTablet ? ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE : - ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; + frozenRotation = orientation == Configuration.ORIENTATION_LANDSCAPE + ? ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE : ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; break; case Surface.ROTATION_90: - frozenRotation = isTablet ? ActivityInfo.SCREEN_ORIENTATION_PORTRAIT : - ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; + frozenRotation = orientation == Configuration.ORIENTATION_PORTRAIT + ? ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT : ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; break; case Surface.ROTATION_180: - frozenRotation = isTablet ? ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE : - ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT; + frozenRotation = orientation == Configuration.ORIENTATION_LANDSCAPE + ? ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE : ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT; break; case Surface.ROTATION_270: - frozenRotation = isTablet ? ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT : - ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE; + frozenRotation = orientation == Configuration.ORIENTATION_PORTRAIT + ? ActivityInfo.SCREEN_ORIENTATION_PORTRAIT : ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE; break; } act.setRequestedOrientation(frozenRotation); -- cgit v1.1