Created
May 15, 2019 15:16
-
-
Save esabook/3f2da22d02f18b3a8a77b41ba7dbca2c to your computer and use it in GitHub Desktop.
get current android orientation
This file contains 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 int getCurrentOrientation() { | |
int rotation = getWindowManager().getDefaultDisplay().getRotation(); | |
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { | |
switch (rotation) { | |
case Surface.ROTATION_0: | |
case Surface.ROTATION_90: | |
return ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; | |
default: | |
return ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE; | |
} | |
} else { | |
switch (rotation) { | |
case Surface.ROTATION_0: | |
case Surface.ROTATION_270: | |
return ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; | |
default: | |
return ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment