diff options
author | Danesh Mondegarian <daneshm90@gmail.com> | 2013-05-14 17:14:21 -0400 |
---|---|---|
committer | Danesh Mondegarian <daneshm90@gmail.com> | 2013-05-20 12:18:40 -0400 |
commit | bbbc8f7f16120b9886cd6c63b007fd58e1a2a645 (patch) | |
tree | f0c342ad1758fbc9d64825d9553862d6564c7e48 | |
parent | 701558adb7392b96d2b28eea1f94410c90bfe85f (diff) | |
download | packages_apps_settings-bbbc8f7f16120b9886cd6c63b007fd58e1a2a645.zip packages_apps_settings-bbbc8f7f16120b9886cd6c63b007fd58e1a2a645.tar.gz packages_apps_settings-bbbc8f7f16120b9886cd6c63b007fd58e1a2a645.tar.bz2 |
Navbar : Lock current orientation in edit mode
Freeze current orientation during edit mode.
Jira : https://jira.cyanogenmod.org/browse/CYAN-1117
Change-Id: I61a852855b70011291a242f3068f67336ba61131
-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); + } } } |