//CODEBRIX-CONVERSION-NOTE: Because of some uniqueness with the Android platform, the base class // for our platform configuration class needs to be updated when the configuration changes. // So we need to override OnConfigurationChanged() and pass the newConfig parameter to // AndroidPlatformConfigBase. public override void OnConfigurationChanged(Configuration newConfig) { base.OnConfigurationChanged(newConfig); AndroidPlatformConfigBase.OnConfigurationChanged(newConfig); }
public static void Initialize(AndroidPlatformConfigBase platformConfig) { _platformConfig = platformConfig ?? throw new ArgumentNullException(nameof(platformConfig)); SubscribeToPageScreenSizeNotifications(); try { _orientationListener = new OrientationListener(platformConfig.MainActivityContext, SensorDelay.Normal); if (!_orientationListener.TryEnabling()) { _orientationListener = null; } } catch (Exception) { _orientationListener = null; } if (_orientationListener?.Enabled ?? false) { CodeBrixViewModelBase.DeviceViewOrientationChecker = () => { DeviceViewOrientation orientation = DeviceViewOrientation.Unknown; if (_orientationListener.Enabled && _orientationListener.FirstOrientationSet) { int rotation = _orientationListener.Orientation; switch (rotation) { case 0: orientation = DeviceViewOrientation.PortraitNormal; break; case 90: orientation = DeviceViewOrientation.LandscapeRight; break; case 180: orientation = DeviceViewOrientation.PortraitUpsideDown; break; case 270: orientation = DeviceViewOrientation.LandscapeLeft; break; default: break; } } if (orientation == DeviceViewOrientation.Unknown) { orientation = (_lastKnownOrientation == Orientation.Landscape) ? DeviceViewOrientation.LandscapeLeft : DeviceViewOrientation.PortraitNormal; } return(orientation); }; } SetDeviceOrientation(_platformConfig.Resources.Configuration.Orientation); _initialized = true; }