partial void Initialize()
        {
            _sensorManager = (SensorManager)Application.Context.GetSystemService(Context.SensorService);
            var gravitySensor = _sensorManager.GetDefaultSensor(_gravitySensorType);

            // Gravity sensor support seems to have been added in Nougat (Android 7), but not entirely functional.
            // Therefore, only use it in Oreo+
            var useGravitySensor = Build.VERSION.SdkInt >= BuildVersionCodes.O;

            // If the the device has a gyroscope we will use the SensorType.Gravity, if not we will use single angle orientation calculations instead
            if (gravitySensor != null && useGravitySensor)
            {
                _sensorManager.RegisterListener(this, _sensorManager.GetDefaultSensor(_gravitySensorType), SensorDelay.Normal);
            }
            else
            {
                _orientationListener = new SimpleOrientationEventListener(orientation => OnOrientationChanged(orientation));
                _contentObserver     = new SettingsContentObserver(new Handler(Looper.MainLooper), () => OnIsAccelerometerRotationEnabledChanged(IsAccelerometerRotationEnabled));

                ContextHelper.Current.ContentResolver.RegisterContentObserver(Settings.System.GetUriFor(Settings.System.AccelerometerRotation), true, _contentObserver);
                if (_orientationListener.CanDetectOrientation() && IsAccelerometerRotationEnabled)
                {
                    _orientationListener.Enable();
                }
            }
        }
Ejemplo n.º 2
0
        partial void Initialize()
        {
            _orientationListener = new SimpleOrientationEventListener(orientation => OnOrientationChanged(orientation));
            _contentObserver     = new SettingsContentObserver(new Handler(Looper.MainLooper), () => OnIsAccelerometerRotationEnabledChanged(IsAccelerometerRotationEnabled));

            ContextHelper.Current.ContentResolver.RegisterContentObserver(Settings.System.GetUriFor(Settings.System.AccelerometerRotation), true, _contentObserver);
            if (_orientationListener.CanDetectOrientation() && IsAccelerometerRotationEnabled)
            {
                _orientationListener.Enable();
            }
        }
Ejemplo n.º 3
0
        partial void Initialize()
        {
            _sensorManager = (SensorManager)Application.Context.GetSystemService(Context.SensorService);
            var gravitySensor = _sensorManager.GetDefaultSensor(_gravitySensorType);

            // If the the device has a gyroscope we will use the SensorType.Gravity, if not we will use single angle orientation calculations instead
            if (gravitySensor != null)
            {
                _sensorManager.RegisterListener(this, _sensorManager.GetDefaultSensor(_gravitySensorType), SensorDelay.Normal);
            }
            else
            {
                _orientationListener = new SimpleOrientationEventListener(orientation => OnOrientationChanged(orientation));
                _contentObserver     = new SettingsContentObserver(new Handler(Looper.MainLooper), () => OnIsAccelerometerRotationEnabledChanged(IsAccelerometerRotationEnabled));

                ContextHelper.Current.ContentResolver.RegisterContentObserver(Settings.System.GetUriFor(Settings.System.AccelerometerRotation), true, _contentObserver);
                if (_orientationListener.CanDetectOrientation() && IsAccelerometerRotationEnabled)
                {
                    _orientationListener.Enable();
                }
            }
        }