Microsoft.Xna.Framework.AndroidCompatibility.GetAbsoluteOrientation C# (CSharp) Method

GetAbsoluteOrientation() public static method

Get the absolute orientation of the device, accounting for platform differences.
public static GetAbsoluteOrientation ( ) : DisplayOrientation
return DisplayOrientation
        public static DisplayOrientation GetAbsoluteOrientation()
        {
            var orientation = Game.Activity.WindowManager.DefaultDisplay.Rotation;

            // Landscape degrees (provided by the OrientationListener) are swapped by default
            // Since we use the code used by OrientationListener, we have to swap manually
            int degrees;
            switch (orientation)
            {
                case SurfaceOrientation.Rotation90:
                    degrees = 270;
                    break;
                case SurfaceOrientation.Rotation180:
                    degrees = 180;
                    break;
                case SurfaceOrientation.Rotation270:
                    degrees = 90;
                    break;
                default:
                    degrees = 0;
                    break;
            }

            return GetAbsoluteOrientation(degrees);
        }
    }

Same methods

AndroidCompatibility::GetAbsoluteOrientation ( int orientation ) : DisplayOrientation

Usage Example

        public override void BeforeInitialize()
        {
            var currentOrientation = AndroidCompatibility.GetAbsoluteOrientation();

            switch (Game.Activity.Resources.Configuration.Orientation)
            {
            case Android.Content.Res.Orientation.Portrait:
                this._gameWindow.SetOrientation(currentOrientation == DisplayOrientation.PortraitDown ? DisplayOrientation.PortraitDown : DisplayOrientation.Portrait, false);
                break;

            default:
                this._gameWindow.SetOrientation(currentOrientation == DisplayOrientation.LandscapeRight ? DisplayOrientation.LandscapeRight : DisplayOrientation.LandscapeLeft, false);
                break;
            }
            base.BeforeInitialize();
            _gameWindow.GameView.TouchEnabled = true;
        }
All Usage Examples Of Microsoft.Xna.Framework.AndroidCompatibility::GetAbsoluteOrientation