Skip to content

Instantly share code, notes, and snippets.

@esabook
Created May 15, 2019 15:16
Show Gist options
  • Save esabook/3f2da22d02f18b3a8a77b41ba7dbca2c to your computer and use it in GitHub Desktop.
Save esabook/3f2da22d02f18b3a8a77b41ba7dbca2c to your computer and use it in GitHub Desktop.
get current android orientation
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