SetOrientation() private method

Updates the screen orientation. Filters out requests for unsupported orientations.
private SetOrientation ( DisplayOrientation newOrientation, bool applyGraphicsChanges ) : void
newOrientation DisplayOrientation
applyGraphicsChanges bool
return void
Esempio n. 1
0
        public override void BeforeInitialize()
        {
            // TODO: Determine whether device natural orientation is Portrait or Landscape for OrientationListener
            //SurfaceOrientation currentOrient = Game.Activity.WindowManager.DefaultDisplay.Rotation;

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

            case Android.Content.Res.Orientation.Landscape:
                _gameWindow.SetOrientation(DisplayOrientation.LandscapeLeft, false);
                break;

            default:
                _gameWindow.SetOrientation(DisplayOrientation.LandscapeLeft, false);
                break;
            }
            base.BeforeInitialize();
            _gameWindow.GameView.TouchEnabled = true;
        }
Esempio n. 2
0
        public override void OnOrientationChanged(int orientation)
        {
            if (orientation == OrientationEventListener.OrientationUnknown)
            {
                return;
            }

            // Avoid changing orientation whilst the screen is locked
            if (ScreenReceiver.ScreenLocked)
            {
                return;
            }

            if (_naturalOrientation.Value == Orientation.Landscape)
            {
                orientation += 270;
            }

            // Round orientation into one of 4 positions, either 0, 90, 180, 270.
            int ort = ((orientation + 45) / 90 * 90) % 360;

            var disporientation = DisplayOrientation.Unknown;

            switch (ort)
            {
            case 90: disporientation = AndroidCompatibility.FlipLandscape ? DisplayOrientation.LandscapeLeft : DisplayOrientation.LandscapeRight;
                break;

            case 270: disporientation = AndroidCompatibility.FlipLandscape ? DisplayOrientation.LandscapeRight : DisplayOrientation.LandscapeLeft;
                break;

            case 0: disporientation = DisplayOrientation.Portrait;
                break;

            case 180: disporientation = DisplayOrientation.PortraitDown;
                break;

            default:
                disporientation = DisplayOrientation.LandscapeLeft;
                break;
            }

            // Only auto-rotate if target orientation is supported and not current
            AndroidGameWindow gameWindow = (AndroidGameWindow)Game.Instance.Window;

            if ((gameWindow.GetEffectiveSupportedOrientations() & disporientation) != 0 &&
                disporientation != gameWindow.CurrentOrientation)
            {
                gameWindow.SetOrientation(disporientation, true);
            }
        }
Esempio n. 3
0
        public override void OnOrientationChanged(int orientation)
        {
            if (orientation == OrientationEventListener.OrientationUnknown)
            {
                return;
            }

            // Avoid changing orientation whilst the screen is locked
            if (ScreenReceiver.ScreenLocked)
            {
                return;
            }

            // Check if screen orientation is locked by user: if it's locked, do not change orientation.
            try
            {
                if (Settings.System.GetInt(Application.Context.ContentResolver, "accelerometer_rotation") == 0)
                {
                    return;
                }
            }
            catch (Settings.SettingNotFoundException)
            {
                // Do nothing (or log warning?). In case android API or Xamarin do not support this Android system property.
            }

            var disporientation = AndroidCompatibility.GetAbsoluteOrientation(orientation);

            // Only auto-rotate if target orientation is supported and not current
            AndroidGameWindow gameWindow = (AndroidGameWindow)Game.Instance.Window;

            if ((gameWindow.GetEffectiveSupportedOrientations() & disporientation) != 0 &&
                disporientation != gameWindow.CurrentOrientation)
            {
                gameWindow.SetOrientation(disporientation, true);
            }
        }
Esempio n. 4
0
        public override void OnOrientationChanged(int orientation)
        {
            if (orientation == OrientationEventListener.OrientationUnknown)
            {
                return;
            }

            // Avoid changing orientation whilst the screen is locked
            if (ScreenReceiver.ScreenLocked)
            {
                return;
            }

            var disporientation = AndroidCompatibility.GetAbsoluteOrientation(orientation);

            // Only auto-rotate if target orientation is supported and not current
            AndroidGameWindow gameWindow = (AndroidGameWindow)Game.Instance.Window;

            if ((gameWindow.GetEffectiveSupportedOrientations() & disporientation) != 0 &&
                disporientation != gameWindow.CurrentOrientation)
            {
                gameWindow.SetOrientation(disporientation, true);
            }
        }