diff options
-rw-r--r-- | src/com/android/settings/Utils.java | 31 | ||||
-rw-r--r-- | src/com/android/settings/cyanogenmod/NavBar.java | 6 |
2 files changed, 36 insertions, 1 deletions
diff --git a/src/com/android/settings/Utils.java b/src/com/android/settings/Utils.java index 49d2af3..7e92321 100644 --- a/src/com/android/settings/Utils.java +++ b/src/com/android/settings/Utils.java @@ -24,6 +24,7 @@ import android.content.ContentResolver; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; +import android.content.pm.ActivityInfo; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; @@ -59,6 +60,7 @@ import android.text.TextUtils; import android.util.DisplayMetrics; import android.util.Log; import android.view.DisplayInfo; +import android.view.Surface; import android.view.View; import android.view.ViewGroup; import android.view.WindowManager; @@ -686,4 +688,33 @@ public class Utils { public static boolean hasVolumeRocker(Context con) { return con.getResources().getBoolean(R.bool.has_volume_rocker); } + + /** + * Locks the activity orientation to the current device orientation + * @param act + */ + public static void lockCurrentOrientation(Activity act) { + int currentRotation = act.getWindowManager().getDefaultDisplay().getRotation(); + int frozenRotation = 0; + boolean isTablet = isTablet(act); + switch(currentRotation) { + case Surface.ROTATION_0: + frozenRotation = isTablet ? ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE : + ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; + break; + case Surface.ROTATION_90: + frozenRotation = isTablet ? ActivityInfo.SCREEN_ORIENTATION_PORTRAIT : + ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; + break; + case Surface.ROTATION_180: + frozenRotation = isTablet ? 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; + break; + } + act.setRequestedOrientation(frozenRotation); + } } diff --git a/src/com/android/settings/cyanogenmod/NavBar.java b/src/com/android/settings/cyanogenmod/NavBar.java index 9fc56af..b26d7fa 100644 --- a/src/com/android/settings/cyanogenmod/NavBar.java +++ b/src/com/android/settings/cyanogenmod/NavBar.java @@ -50,7 +50,6 @@ public class NavBar extends Fragment { public void onAttach(Activity activity) { super.onAttach(activity); mActivity = activity; - mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } @Override @@ -148,5 +147,10 @@ public class NavBar extends Fragment { mEditMenu.setTitle(on ? R.string.navigation_bar_menu_editable : R.string.navigation_bar_menu_locked) .setIcon(on ? R.drawable.stat_navbar_edit_on : R.drawable.stat_navbar_edit_off); } + if (on) { + Utils.lockCurrentOrientation(mActivity); + } else { + mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); + } } } |