Change ElmShar pAPI to C# API : ElmSharp.Timer -> System.Threading.Timer
authorGeunsun, Lee <gs86.lee@samsung.com>
Wed, 24 May 2017 06:21:43 +0000 (15:21 +0900)
committerGeunSun Lee <gs86.lee@samsung.com>
Wed, 24 May 2017 06:42:18 +0000 (15:42 +0900)
Change-Id: If25b884b47c255beee022cc2991ce9968b5fc84f

TVMediaHub/TVMediaHub.Tizen/Views/ImageViewer.xaml.cs
TVMediaHub/TVMediaHub.Tizen/Views/SimpleImageViewer.xaml.cs
TVMediaHub/TVMediaHub.Tizen/Views/VideoPlayer.xaml.cs

index 8e4e628..e0b854a 100755 (executable)
@@ -15,6 +15,7 @@
  */
 
 using System;
+using System.Threading;
 using System.Windows.Input;
 using Tizen.Xamarin.Forms.Extension;
 using TVMediaHub.Tizen.Controls;
@@ -121,12 +122,13 @@ namespace TVMediaHub.Tizen.Views
         /// <summary>
         /// The timer to handle the control area
         /// </summary>
-        private IntPtr timer = default(IntPtr);
+        Timer timer;
 
         /// <summary>
-        /// The interval of the timer
+        /// The due time of the timer
+        /// 5 second
         /// </summary>
-        private double timerInterval = 5.0;
+        private int timerDueTime = 5000;
 
         /// <summary>
         /// Identifies the SavedRotationCommand bindable property
@@ -222,6 +224,8 @@ namespace TVMediaHub.Tizen.Views
 
             InitializeButtons();
 
+            timer = new Timer(HideControlAreaHandler, null, Timeout.Infinite, Timeout.Infinite);
+
             PropertyChanged += ImageViewerPropertyChanged;
 
             OnBackButtonPressedHandler += async (s, e) =>
@@ -298,18 +302,6 @@ namespace TVMediaHub.Tizen.Views
         }
 
         /// <summary>
-        /// Initialize the timer
-        /// </summary>
-        private void InitializeTimer()
-        {
-            if (timer != default(IntPtr))
-            {
-                ElmSharp.EcoreMainloop.RemoveTimer(timer);
-                timer = default(IntPtr);
-            }
-        }
-
-        /// <summary>
         /// A method for changing control area according to ControlAreaState
         /// </summary>
         /// <param name="state">A current ControlAreaState</param>
@@ -323,7 +315,7 @@ namespace TVMediaHub.Tizen.Views
                         RunShowAnimation();
                     }
 
-                    InitializeTimer();
+                    timer.Change(Timeout.Infinite, Timeout.Infinite);
 
                     break;
                 case ControlAreaState.HIDE:
@@ -332,7 +324,7 @@ namespace TVMediaHub.Tizen.Views
                         RunHideAnimation();
                     }
 
-                    InitializeTimer();
+                    timer.Change(Timeout.Infinite, Timeout.Infinite);
 
                     break;
                 case ControlAreaState.AUTO:
@@ -342,9 +334,7 @@ namespace TVMediaHub.Tizen.Views
                         RunShowAnimation();
                     }
 
-                    InitializeTimer();
-
-                    timer = ElmSharp.EcoreMainloop.AddTimer(timerInterval, HideControlAreaHandler());
+                    timer.Change(timerDueTime, Timeout.Infinite);
 
                     break;
             }
@@ -896,7 +886,7 @@ namespace TVMediaHub.Tizen.Views
             OptionBtn.MediaHubButtonBtn.On<Tizen>().SetNextFocusRightView(OptionBtn.MediaHubButtonBtn);
 
             RunShowAnimation();
-            timer = ElmSharp.EcoreMainloop.AddTimer(timerInterval, HideControlAreaHandler());
+            timer.Change(timerDueTime, Timeout.Infinite);
 
             if (isFirstLaunching)
             {
@@ -920,7 +910,7 @@ namespace TVMediaHub.Tizen.Views
             ControlArea.TranslationY = 93;
             ControlArea.Opacity = 0;
 
-            InitializeTimer();
+            timer.Change(Timeout.Infinite, Timeout.Infinite);
 
             UngrabRemoteKeys();
         }
@@ -928,17 +918,9 @@ namespace TVMediaHub.Tizen.Views
         /// <summary>e
         /// A method for hiding control area when timer is over
         /// </summary>
-        /// <returns>Always returns false</returns>
-        private Func<bool> HideControlAreaHandler()
+        private void HideControlAreaHandler(object state)
         {
-            return delegate()
-            {
-                SetControlAreaState(ControlAreaState.HIDE);
-
-                timer = default(IntPtr);
-
-                return false;
-            };
+            SetControlAreaState(ControlAreaState.HIDE);
         }
 
         /// <summary>
index 6d2cff4..27593f9 100644 (file)
@@ -15,6 +15,7 @@
  */
 
 using System;
+using System.Threading;
 using System.Windows.Input;
 using Tizen.Xamarin.Forms.Extension;
 using TVMediaHub.Tizen.Controls;
@@ -86,12 +87,13 @@ namespace TVMediaHub.Tizen.Views
         /// <summary>
         /// The timer to handle the control area
         /// </summary>
-        private IntPtr timer = default(IntPtr);
+        private Timer timer;
 
         /// <summary>
-        /// The interval of the timer
+        /// The due time of the timer
+        /// 5 second
         /// </summary>
-        private double timerInterval = 5.0;
+        private int timerDueTime = 5000;
 
         /// <summary>
         /// Identifies the SavedRotationCommand bindable property
@@ -180,6 +182,8 @@ namespace TVMediaHub.Tizen.Views
 
             InitializeButtons();
 
+            timer = new Timer(HideControlAreaHandler, null, Timeout.Infinite, Timeout.Infinite);
+
             PropertyChanged += ImageViewerPropertyChanged;
             OnBackButtonPressedHandler += async (s, e) =>
             {
@@ -267,11 +271,7 @@ namespace TVMediaHub.Tizen.Views
                         RunShowAnimation();
                     }
 
-                    if (timer != default(IntPtr))
-                    {
-                        ElmSharp.EcoreMainloop.RemoveTimer(timer);
-                        timer = default(IntPtr);
-                    }
+                    timer.Change(Timeout.Infinite, Timeout.Infinite);
 
                     break;
                 case ControlAreaState.HIDE:
@@ -280,11 +280,7 @@ namespace TVMediaHub.Tizen.Views
                         RunHideAnimation();
                     }
 
-                    if (timer != default(IntPtr))
-                    {
-                        ElmSharp.EcoreMainloop.RemoveTimer(timer);
-                        timer = default(IntPtr);
-                    }
+                    timer.Change(Timeout.Infinite, Timeout.Infinite);
 
                     break;
                 case ControlAreaState.AUTO:
@@ -294,13 +290,7 @@ namespace TVMediaHub.Tizen.Views
                         RunShowAnimation();
                     }
 
-                    if (timer != default(IntPtr))
-                    {
-                        ElmSharp.EcoreMainloop.RemoveTimer(timer);
-                        timer = default(IntPtr);
-                    }
-
-                    timer = ElmSharp.EcoreMainloop.AddTimer(timerInterval, HideControlAreaHandler());
+                    timer.Change(timerDueTime, Timeout.Infinite);
 
                     break;
             }
@@ -711,7 +701,7 @@ namespace TVMediaHub.Tizen.Views
             OptionBtn.MediaHubButtonBtn.On<Tizen>().SetNextFocusRightView(OptionBtn.MediaHubButtonBtn);
 
             RunShowAnimation();
-            timer = ElmSharp.EcoreMainloop.AddTimer(timerInterval, HideControlAreaHandler());
+            timer.Change(timerDueTime, Timeout.Infinite);
 
             RotateBtn.MediaHubButtonBtn.Focus();
 
@@ -721,27 +711,20 @@ namespace TVMediaHub.Tizen.Views
         /// <summary>e
         /// A method for hiding control area when timer is over
         /// </summary>
-        /// <returns>Always returns false</returns>
-        private Func<bool> HideControlAreaHandler()
+        private void HideControlAreaHandler(object state)
         {
-            return delegate()
-            {
-                SetControlAreaState(ControlAreaState.HIDE);
-
-                timer = default(IntPtr);
-
-                return false;
-            };
+            SetControlAreaState(ControlAreaState.HIDE);
         }
 
         /// <summary>
         /// A method for finalizing page when the page is disappeared
-        /// Ungrabs move keys of the remote controller
-        /// Releases resources of the minimap
+        /// Ungrabs keys of the remote controller
         /// </summary>
         protected override void FinalizePage()
         {
             UngrabRemoteKeys();
+
+            timer.Change(Timeout.Infinite, Timeout.Infinite);
         }
 
         /// <summary>
index 59b9546..58b951d 100755 (executable)
@@ -23,6 +23,7 @@ using TVMediaHub.Tizen.Controls;
 using Xamarin.Forms;
 using Extension = Tizen.Xamarin.Forms.Extension;
 using Xamarin.Forms.PlatformConfiguration.TizenSpecific;
+using System.Threading;
 
 namespace TVMediaHub.Tizen.Views
 {
@@ -81,12 +82,13 @@ namespace TVMediaHub.Tizen.Views
         /// <summary>
         /// The timer to handle the control area
         /// </summary>
-        private IntPtr timer = default(IntPtr);
+        private Timer timer;
 
         /// <summary>
-        /// The interval of the timer
+        /// The due time of the timer
+        /// 5 second
         /// </summary>
-        private double timerInterval = 5.0;
+        private int timerDueTime = 5000;
 
         /// <summary>
         /// Gets or sets whether play status is back forward or back rewind
@@ -200,26 +202,28 @@ namespace TVMediaHub.Tizen.Views
 
             InitializeButtons();
 
-            OnBackButtonPressedHandler  += async (s, e) =>
-            {
-                try
-                {
-                    playerInstance?.Stop();
-                    playerInstance?.Unprepare();
-                }
-                catch (Exception ex)
-                {
-                    DbgPort.E("Stop Failed : " + ex.Message);
-                }
+            timer = new Timer(HideControlAreaHandler, null, Timeout.Infinite, Timeout.Infinite);
+
+            OnBackButtonPressedHandler += async (s, e) =>
+           {
+               try
+               {
+                   playerInstance?.Stop();
+                   playerInstance?.Unprepare();
+               }
+               catch (Exception ex)
+               {
+                   DbgPort.E("Stop Failed : " + ex.Message);
+               }
 
 #pragma warning disable CS4014
                 GradientDim.FadeTo(0, 667, Easing.CubicInOut);
-                ControlArea.TranslateTo(0, 93, 667, Easing.CubicInOut);
-                ControlArea.FadeTo(0, 667, Easing.CubicInOut);
-                TitleLabel.TranslateTo(0, -50, 667, Easing.CubicInOut);
-                await TitleLabel.FadeTo(0, 667, Easing.CubicInOut);
+               ControlArea.TranslateTo(0, 93, 667, Easing.CubicInOut);
+               ControlArea.FadeTo(0, 667, Easing.CubicInOut);
+               TitleLabel.TranslateTo(0, -50, 667, Easing.CubicInOut);
+               await TitleLabel.FadeTo(0, 667, Easing.CubicInOut);
 
-                App.AppMainPage.Navigation.PopAsync();
+               App.AppMainPage.Navigation.PopAsync();
                 //Program.TransitionToMain(0);
 #pragma warning restore CS4014
             };
@@ -275,11 +279,7 @@ namespace TVMediaHub.Tizen.Views
                         RunShowAnimation();
                     }
 
-                    if (timer != default(IntPtr))
-                    {
-                        ElmSharp.EcoreMainloop.RemoveTimer(timer);
-                        timer = default(IntPtr);
-                    }
+                    timer.Change(Timeout.Infinite, Timeout.Infinite);
 
                     break;
                 case ControlAreaState.HIDE:
@@ -288,11 +288,7 @@ namespace TVMediaHub.Tizen.Views
                         RunHideAnimation();
                     }
 
-                    if (timer != default(IntPtr))
-                    {
-                        ElmSharp.EcoreMainloop.RemoveTimer(timer);
-                        timer = default(IntPtr);
-                    }
+                    timer.Change(Timeout.Infinite, Timeout.Infinite);
 
                     break;
                 case ControlAreaState.AUTO:
@@ -302,13 +298,7 @@ namespace TVMediaHub.Tizen.Views
                         RunShowAnimation();
                     }
 
-                    if (timer != default(IntPtr))
-                    {
-                        ElmSharp.EcoreMainloop.RemoveTimer(timer);
-                        timer = default(IntPtr);
-                    }
-
-                    timer = ElmSharp.EcoreMainloop.AddTimer(timerInterval, HideControlAreaHandler());
+                    timer.Change(timerDueTime, Timeout.Infinite);
 
                     break;
             }
@@ -510,27 +500,19 @@ namespace TVMediaHub.Tizen.Views
             NextBtn.MediaHubButtonBtn.On<Tizen>().SetNextFocusRightView(NextBtn.MediaHubButtonBtn);
 
             RunShowAnimation();
-            timer = ElmSharp.EcoreMainloop.AddTimer(timerInterval, HideControlAreaHandler());
+            timer.Change(timerDueTime, Timeout.Infinite);
 
             PausePlayBtn.MediaHubButtonBtn.Focus();
 
             GrabRemoteKeys();
         }
 
-        /// <summary>
-        /// Hide the control area
+        /// <summary>e
+        /// A method for hiding control area when timer is over
         /// </summary>
-        /// <returns></returns>
-        private Func<bool> HideControlAreaHandler()
+        private void HideControlAreaHandler(object state)
         {
-            return delegate ()
-            {
-                SetControlAreaState(ControlAreaState.HIDE);
-
-                timer = default(IntPtr);
-
-                return false;
-            };
+            SetControlAreaState(ControlAreaState.HIDE);
         }
 
         /// <summary>
@@ -538,15 +520,9 @@ namespace TVMediaHub.Tizen.Views
         /// </summary>
         protected override void FinalizePage()
         {
-            DbgPort.D("Finalize Page");
-
-            if (timer != default(IntPtr))
-            {
-                ElmSharp.EcoreMainloop.RemoveTimer(timer);
-                timer = default(IntPtr);
-            }
-
             UngrabRemoteKeys();
+
+            timer.Change(Timeout.Infinite, Timeout.Infinite);
         }
 
         /// <summary>