From 2545b47c57e55799623814f3ec126f62d954ad8c Mon Sep 17 00:00:00 2001 From: Praveen Gattu Date: Tue, 24 May 2016 15:45:39 +0530 Subject: [PATCH] [Device] Added Displays and Vibrators property. Change-Id: I74f53b1c3d49504cf1e8cbd8eb3f254e7dba3320 Signed-off-by: Praveen Gattu --- src/Tizen.System/Device/Display.cs | 44 +++++++++++++++------------- src/Tizen.System/Device/Haptic.cs | 59 ++++++++++++++++++++++++-------------- 2 files changed, 61 insertions(+), 42 deletions(-) diff --git a/src/Tizen.System/Device/Display.cs b/src/Tizen.System/Device/Display.cs index ae60a19..321f278 100644 --- a/src/Tizen.System/Device/Display.cs +++ b/src/Tizen.System/Device/Display.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; - namespace Tizen.System { /// @@ -29,8 +28,8 @@ namespace Tizen.System public class Display { private readonly int _displayId; - private static readonly Dictionary s_displays = new Dictionary(); private static readonly object s_lock = new object(); + private static Lazy> _lazyDisplays; private Display(int deviceNumber) { _displayId = deviceNumber; @@ -52,7 +51,30 @@ namespace Tizen.System return number; } } + /// + /// Get all the avaialble vibrators. + /// + public static IReadOnlyList Displays + { + get + { + _lazyDisplays = new Lazy>(() => GetAllDisplayes()); + return _lazyDisplays.Value; + } + } + + private static IReadOnlyList GetAllDisplayes() + { + List displays = new List(); + + for (int i = 0; i < NumberOfDisplays; i++) + { + displays.Add(new Display(i)); + } + return displays; + + } /// /// The maximum brightness value that can be set. /// @@ -96,24 +118,6 @@ namespace Tizen.System } } /// - /// Get the Display instance for the given display index. - /// - /// The index of the display. - /// It can be greater than or equal to 0 and less than the number of display devices - public static Display GetDisplay(int deviceNumber) - { - //TODO: throw an exception for invalid display Id. - if(deviceNumber < 0 || deviceNumber >= NumberOfDisplays) - { - throw DeviceExceptionFactory.CreateException(DeviceError.InvalidParameter, "invalid display number"); - } - if (!s_displays.ContainsKey(deviceNumber)) - { - s_displays.Add(deviceNumber, new Display(deviceNumber)); - } - return s_displays[deviceNumber]; - } - /// /// The current display state. /// public static DisplayState State diff --git a/src/Tizen.System/Device/Haptic.cs b/src/Tizen.System/Device/Haptic.cs index 6af4d7e..4bd431f 100644 --- a/src/Tizen.System/Device/Haptic.cs +++ b/src/Tizen.System/Device/Haptic.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; - namespace Tizen.System { /// @@ -9,9 +8,10 @@ namespace Tizen.System public class Vibrator : IDisposable { private readonly int _vibratorId; - private static readonly Dictionary s_vibrators = new Dictionary(); private IntPtr _hapticHandle; private bool _disposedValue = false; + private static Lazy> _lazyVibrators; + private static int _maxcount = 0; private Vibrator(int id) { _vibratorId = id; @@ -20,39 +20,27 @@ namespace Tizen.System { throw DeviceExceptionFactory.CreateException(res, "unable to create Vibrator for given Id"); } + res = (DeviceError)Interop.Device.DeviceHapticGetCount(out _maxcount); + if (res != DeviceError.None) + { + Log.Warn(DeviceExceptionFactory.LogTag, "unable to get Vibrators count."); + } + } ~Vibrator() { Dispose(false); } - /// - /// Get the Vibrator instance for the given vibrator index. - /// - /// The index of the vibrator. - /// It can be greater than or equal to 0 and less than the number of vibrators. - public static Vibrator GetVibrator(int deviceNumber) - { - if (deviceNumber < 0 || deviceNumber >= NumberOfVibrators) - { - throw DeviceExceptionFactory.CreateException(DeviceError.InvalidParameter, "invalid vibrator number"); - } - if (!s_vibrators.ContainsKey(deviceNumber)) - { - s_vibrators.Add(deviceNumber, new Vibrator(deviceNumber)); - } - return s_vibrators[deviceNumber]; - } - /// - /// Gets the number of vibrators. + /// Get the number of avaialble vibrators. /// public static int NumberOfVibrators { get { int count = 0; - DeviceError res = (DeviceError) Interop.Device.DeviceHapticGetCount(out count); + DeviceError res = (DeviceError)Interop.Device.DeviceHapticGetCount(out count); if (res != DeviceError.None) { Log.Warn(DeviceExceptionFactory.LogTag, "unable to get Vibrators count."); @@ -61,6 +49,33 @@ namespace Tizen.System } } /// + /// Get all the avaialble vibrators. + /// + public static IReadOnlyList Vibrators + { + get + { + _lazyVibrators = new Lazy>(() => GetAllVibrators()); + return _lazyVibrators.Value; + } + } + private static IReadOnlyList GetAllVibrators() + { + int count = 0; + List< Vibrator > vibrators = new List(); + DeviceError res = (DeviceError)Interop.Device.DeviceHapticGetCount(out count); + if (res != DeviceError.None) + { + throw DeviceExceptionFactory.CreateException(res, "unable to get Vibrators count."); + } + for(int i = 0; i< NumberOfVibrators; i++) + { + vibrators.Add(new Vibrator(i)); + } + return vibrators; + + } + /// /// Vibrates during the specified time with a constant intensity. /// This function can be used to start monotonous vibration for the specified time. /// -- 2.7.4