Created
October 6, 2015 08:08
-
-
Save peanutwolf/2287c46aa796c38f22e5 to your computer and use it in GitHub Desktop.
Locking orientation on Android
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void lockOrientation(){ | |
int orientation; | |
int rotation = ((WindowManager) getActivity().getSystemService( | |
Context.WINDOW_SERVICE)).getDefaultDisplay().getRotation(); | |
switch (rotation) { | |
case Surface.ROTATION_0: | |
orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; | |
break; | |
case Surface.ROTATION_90: | |
orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; | |
break; | |
case Surface.ROTATION_180: | |
orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT; | |
break; | |
default: | |
orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE; | |
break; | |
} | |
getActivity().setRequestedOrientation(orientation); | |
} | |
private void unlockOrientation(){ | |
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment