public static Orientation getOrientation ( @ NonNull final Context context ) { Condition . INSTANCE . ensureNotNull ( context , "The context may not be null" ) ; int orientation = context . getResources ( ) . getConfiguration ( ) . orientation ; if ( orientation == Configuration . ORIENTATION_UNDEFINED ) { int width = getDisplayWidth ( context ) ; int height = getDisplayHeight ( context ) ; if ( width > height ) { return Orientation . LANDSCAPE ; } else if ( width < height ) { return Orientation . PORTRAIT ; } else { return Orientation . SQUARE ; } } else if ( orientation == Configuration . ORIENTATION_LANDSCAPE ) { return Orientation . LANDSCAPE ; } else if ( orientation == Configuration . ORIENTATION_PORTRAIT ) { return Orientation . PORTRAIT ; } else { return Orientation . SQUARE ; } }
Returns the orientation of the device .