Esempio n. 1
0
 private static void TryInitializeHingeAngleSensor(HingeAngleSensor owner)
 {
     if (_hingeAngleSensor != null)
     {
         return;
     }
     lock (_syncLock)
     {
         if (_hingeAngleSensor == null && !ApiExtensibility.CreateInstance(owner, out _hingeAngleSensor))
         {
             owner.Log().Warn("You need to reference Uno.UI.DualScreen NuGet package from your project to use this feature.");
         }
     }
 }
Esempio n. 2
0
 public static IAsyncOperation <HingeAngleSensor> GetDefaultAsync()
 {
     // avoid locking if possible
     if (!_initializationAttempted)
     {
         lock (_syncLock)
         {
             if (!_initializationAttempted)                     //double-check for race conditions
             {
                 // we need to create a dummy instance to give IUnoHingeAngleSensor an owner
                 var sensor = new HingeAngleSensor();
                 TryInitializeHingeAngleSensor(sensor);
                 if (_hingeAngleSensor?.DeviceHasHinge == true)
                 {
                     _instance = sensor;
                 }
                 _initializationAttempted = true;
             }
         }
     }
     return(Task.FromResult(_instance).AsAsyncOperation());
 }
Esempio n. 3
0
        async void ProcessHingeAngleSubscriberCount(int newCount)
        {
            try
            {
                if (_angleSensor == null)
                {
                    _angleSensor = await Windows.Devices.Sensors.HingeAngleSensor.GetDefaultAsync();
                }

                if (_angleSensor == null)
                {
                    return;
                }

                lock (hingeAngleLock)
                {
                    if (newCount == 1)
                    {
                        _angleSensor.ReadingChanged += OnReadingChanged;
                    }
                    else if (newCount == 0)
                    {
                        _angleSensor.ReadingChanged -= OnReadingChanged;
                    }
                }
            }
            catch (Exception e)
            {
                Internals.Log.Warning(nameof(DualScreenInfo), $"Failed to retrieve Hinge Angle Sensor {e}");
            }

            void OnReadingChanged(HingeAngleSensor sender, HingeAngleSensorReadingChangedEventArgs args)
            {
                Device.BeginInvokeOnMainThread(() =>
                {
                    _hingeAngleChanged?.Invoke(this, new HingeAngleChangedEventArgs(args.Reading.AngleInDegrees));
                });
            }
        }