Smooth handling of Home key event
authorKyuho Jo <kyuho.jo@samsung.com>
Thu, 23 Mar 2017 09:58:26 +0000 (18:58 +0900)
committerChulSeung Kim <charles0.kim@samsung.com>
Thu, 8 Jun 2017 09:34:49 +0000 (18:34 +0900)
1. Add WindowAPIs for providing functions of elm_win. (iconified,
keygrab)
2. Remove the timer which was used to smooth animation of iconifying.
3. Remove the timer for KeyGrab. (Nevertheless it works very well.)

Signed-off-by: Kyuho Jo <kyuho.jo@samsung.com>
Change-Id: I56a175cb9e45335544a1e20160707585e4e95130

LibTVRefCommonPortable/LibTVRefCommonPortable.csproj
LibTVRefCommonPortable/Utils/IWindowAPIs.cs [new file with mode: 0644]
LibTVRefCommonTizen/LibTVRefCommonTizen.csproj
LibTVRefCommonTizen/Ports/ElmPort.cs [deleted file]
LibTVRefCommonTizen/Ports/WindowPort.cs [new file with mode: 0644]
TVHome/TVHome.TizenTV/TVHome.TizenTV.cs
TVHome/TVHome.TizenTV/bin/Debug/TVHome.TizenTV.tpk
TVHome/TVHome/Views/MainPage.xaml.cs

index e686bda..94e680c 100644 (file)
@@ -68,6 +68,7 @@
     <Compile Include="Utils\IAppControl.cs" />
     <Compile Include="Utils\IApplicationManagerAPIs.cs" />
     <Compile Include="Utils\IAppLifeControl.cs" />
+    <Compile Include="Utils\IWindowAPIs.cs" />
     <Compile Include="Utils\IPlatformNotification.cs" />
     <Compile Include="Utils\IBTAPIs.cs" />
     <Compile Include="Utils\IDebuggingAPIs.cs" />
diff --git a/LibTVRefCommonPortable/Utils/IWindowAPIs.cs b/LibTVRefCommonPortable/Utils/IWindowAPIs.cs
new file mode 100644 (file)
index 0000000..1186c79
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace LibTVRefCommonPortable.Utils
+{
+    public interface IWindowAPIs
+    {
+        void SetIconified(bool iconified);
+        bool GetIconified();
+    }
+}
index 83e49b3..ca0c80d 100644 (file)
@@ -49,7 +49,7 @@
     <Compile Include="Ports\ApplicationManagerPort.cs" />
     <Compile Include="Ports\BTModulePort.cs" />
     <Compile Include="Ports\DebuggingPort.cs" />
-    <Compile Include="Ports\ElmPort.cs" />
+    <Compile Include="Ports\WindowPort.cs" />
     <Compile Include="Ports\FileSystemPort.cs" />
     <Compile Include="Ports\FileSystemWatcherPort.cs" />
     <Compile Include="Ports\PackageManagerPort.cs" />
diff --git a/LibTVRefCommonTizen/Ports/ElmPort.cs b/LibTVRefCommonTizen/Ports/ElmPort.cs
deleted file mode 100644 (file)
index 46eb65e..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-using System;
-using System.Runtime.InteropServices;
-
-namespace LibTVRefCommonTizen.Ports
-{
-    public class ElmPort
-    {
-        internal class Elm
-        {
-            internal delegate bool EcoreEventHanlderCallback(IntPtr data, int type, IntPtr ei);
-
-            [DllImport("libelementary.so.1", EntryPoint = "elm_win_keygrab_set", CallingConvention = CallingConvention.Cdecl)]
-            internal static extern IntPtr Elm_win_keygrab_set(IntPtr obj, string key, ulong modifiers, ulong not_modifiers, int proirity, int grab_mode);
-
-            [DllImport("libelementary.so.1", EntryPoint = "elm_win_iconified_set", CallingConvention = CallingConvention.Cdecl)]
-            internal static extern void Elm_win_iconified_set(IntPtr obj, bool iconified);
-
-            [DllImport("libelementary.so.1", EntryPoint = "elm_win_iconified_get", CallingConvention = CallingConvention.Cdecl)]
-            internal static extern bool Elm_win_iconified_get(IntPtr obj);
-        }
-
-        public static void SetKeyGrabExclusively(IntPtr window, string key)
-        {
-            DebuggingPort.D("Grab Key Event for :" + key);
-            Elm.Elm_win_keygrab_set(window, key, 0, 0, 0, 1024);
-        }
-
-        public static void SetIconified(IntPtr window, bool iconified)
-        {
-            DebuggingPort.D("Iconified :" + iconified);
-            Elm.Elm_win_iconified_set(window, iconified);
-        }
-
-        public static bool GetIconified(IntPtr window)
-        {
-            return Elm.Elm_win_iconified_get(window);
-        }
-    }
-}
diff --git a/LibTVRefCommonTizen/Ports/WindowPort.cs b/LibTVRefCommonTizen/Ports/WindowPort.cs
new file mode 100644 (file)
index 0000000..32c7636
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using System.Runtime.InteropServices;
+using LibTVRefCommonPortable.Utils;
+using Xamarin.Forms.Platform.Tizen.Native;
+
+namespace LibTVRefCommonTizen.Ports
+{
+    public class WindowPort : IWindowAPIs
+    {
+        internal class ElmWindow
+        {
+            [DllImport("libelementary.so.1", EntryPoint = "elm_win_keygrab_set", CallingConvention = CallingConvention.Cdecl)]
+            internal static extern IntPtr elm_win_keygrab_set(IntPtr obj, string key, ulong modifiers, ulong  not_modifiers, int proirity, int grab_mode);
+
+            [DllImport("libelementary.so.1", EntryPoint = "elm_win_iconified_set", CallingConvention = CallingConvention.Cdecl)]
+            internal static extern void elm_win_iconified_set(IntPtr obj, bool iconified);
+
+            [DllImport("libelementary.so.1", EntryPoint = "elm_win_iconified_get", CallingConvention = CallingConvention.Cdecl)]
+            internal static extern bool elm_win_iconified_get(IntPtr obj);
+        }
+
+        static private Window mainWindow;
+
+        public Window MainWindow
+        {
+            set
+            {
+                mainWindow = value;
+            }
+        }
+
+        public void SetKeyGrabExclusively(string key)
+        {
+            if (mainWindow != null)
+                ElmWindow.elm_win_keygrab_set((IntPtr)mainWindow, key, 0, 0, 0, 1024);
+        }
+
+        public void SetIconified(bool iconified)
+        {
+            if (mainWindow != null)
+                ElmWindow.elm_win_iconified_set((IntPtr)mainWindow, iconified);
+        }
+
+        public bool GetIconified()
+        {
+            if (mainWindow != null)
+                return ElmWindow.elm_win_iconified_get((IntPtr)mainWindow);
+            else
+                return false;
+        }
+
+        public void Active()
+        {
+            if (mainWindow != null)
+                mainWindow.Active();
+        }
+    }
+}
index 561ba7a..d6b23bb 100755 (executable)
@@ -27,8 +27,7 @@ namespace TVHome.TizenTV
     class Program : global::Xamarin.Forms.Platform.Tizen.FormsApplication
     {
         IPlatformNotification notification;
-        private Timer timerForKeyGrab;
-        private Timer timerForIconified;
+        WindowPort windowPort;
 
         public static string AppResourcePath
         {
@@ -42,23 +41,6 @@ namespace TVHome.TizenTV
             private set;
         }
 
-        private void CallbackForKeyGrab(Object state)
-        {
-            MainWindow.KeyGrab(ElmSharp.EvasKeyEventArgs.PlatformHomeButtonName, true);
-            MainWindow.KeyGrab(ElmSharp.EvasKeyEventArgs.PlatformMenuButtonName, true);
-            ElmPort.SetKeyGrabExclusively((IntPtr)(MainWindow), ElmSharp.EvasKeyEventArgs.PlatformHomeButtonName);
-            timerForKeyGrab.Dispose();
-            timerForKeyGrab = null;
-            DebuggingPort.D("KeyGrab finished");
-        }
-
-        private void CallbackForIconified(Object state)
-        {
-            ElmPort.SetIconified((IntPtr)MainWindow, true);
-            timerForIconified.Dispose();
-            timerForIconified = null;
-        }
-
         protected override void OnCreate()
         {
             base.OnCreate();
@@ -76,8 +58,13 @@ namespace TVHome.TizenTV
             MainWindow.KeyUp += KeyUpListener;
             MainWindow.Alpha = true;
 
-            TimerCallback timerDelegate = new TimerCallback(CallbackForKeyGrab);
-            timerForKeyGrab = new Timer(timerDelegate, null, 3000, 0);
+            windowPort = new WindowPort();
+            windowPort.MainWindow = MainWindow;
+
+            // Grab key events
+            MainWindow.KeyGrab(ElmSharp.EvasKeyEventArgs.PlatformHomeButtonName, true);
+            MainWindow.KeyGrab(ElmSharp.EvasKeyEventArgs.PlatformMenuButtonName, true);
+            windowPort.SetKeyGrabExclusively(ElmSharp.EvasKeyEventArgs.PlatformHomeButtonName);
         }
 
         private void KeyUpListener(object sender, ElmSharp.EvasKeyEventArgs e)
@@ -85,17 +72,9 @@ namespace TVHome.TizenTV
             DebuggingPort.D("Key Pressed :" + e.KeyName);
             if (e.KeyName.CompareTo(ElmSharp.EvasKeyEventArgs.PlatformHomeButtonName) == 0)
             {
-                if (ElmPort.GetIconified((IntPtr)MainWindow) == true)
-                {
-                    ElmPort.SetIconified((IntPtr)MainWindow, false);
-                    MainWindow.Active();
-                    notification.OnHomeKeyPressed();
-                }
-                else
+                if (notification != null)
                 {
                     notification.OnHomeKeyPressed();
-                    TimerCallback timerDelegate = new TimerCallback(CallbackForIconified);
-                    timerForIconified = new Timer(timerDelegate, null, 200, 0);
                 }
             }
             else if (e.KeyName.CompareTo(ElmSharp.EvasKeyEventArgs.PlatformMenuButtonName) == 0)
@@ -149,6 +128,7 @@ namespace TVHome.TizenTV
             global::Xamarin.Forms.DependencyService.Register<FileSystemWatcherPort>();
             global::Xamarin.Forms.DependencyService.Register<ApplicationManagerPort>();
             global::Xamarin.Forms.DependencyService.Register<FileSystemPort>();
+            global::Xamarin.Forms.DependencyService.Register<WindowPort>();
             global::Xamarin.Forms.Platform.Tizen.Forms.Init(app);
             app.Run(args);
         }
index 2f8b0f4..c1eee18 100644 (file)
Binary files a/TVHome/TVHome.TizenTV/bin/Debug/TVHome.TizenTV.tpk and b/TVHome/TVHome.TizenTV/bin/Debug/TVHome.TizenTV.tpk differ
index 755f08b..a344fcf 100755 (executable)
@@ -32,7 +32,6 @@ namespace TVHome.Views
     /// </summary>
     public partial class MainPage : ContentPage
     {
-        private bool Iconified = false;
         public static readonly BindableProperty CurrentStatusProperty = BindableProperty.Create("CurrentStatus", typeof(HomeStatus), typeof(MainPage), default(HomeStatus));
         public HomeStatus CurrentStatus
         {
@@ -49,16 +48,37 @@ namespace TVHome.Views
 
         private Dictionary<HomeMenuItem, Panel> SubPanelDictionary;
 
-        private async void PlayHideAnimation()
+        private async void Iconified()
         {
+#pragma warning disable CS4014
             SubPanelDictionary[SelectedMenuName]?.TranslateTo(0.0, 100, 150);
+            DimmedBgImage.FadeTo(0.0, 150);
+#pragma warning restore CS4014
             await PageMainPanel.ScaleTo(0.0, 150);
+            DependencyService.Get<IWindowAPIs>().SetIconified(true);
         }
 
-        private async void PlayShowAnimation()
+        private async void Uniconified()
         {
+#pragma warning disable CS4014
             SubPanelDictionary[SelectedMenuName]?.TranslateTo(0.0, 0.0, 150);
+            DimmedBgImage.FadeTo(0.5, 150);
+#pragma warning restore CS4014
             await PageMainPanel.ScaleTo(1.0, 150);
+            DependencyService.Get<IWindowAPIs>().SetIconified(false);
+        }
+
+        private void ToggleIconified()
+        {
+            if (DependencyService.Get<IWindowAPIs>().GetIconified() == true)
+            {
+                PageMainPanel.InitialFocusing();
+                Uniconified();
+            }
+            else
+            {
+                Iconified();
+            }
         }
 
         public MainPage()
@@ -72,17 +92,7 @@ namespace TVHome.Views
 
             App.SetHomeKeyListener((e, arg) =>
             {
-                if (Iconified == true)
-                {
-                    PageMainPanel.InitialFocusing();
-                    PlayShowAnimation();
-                }
-                else
-                {
-                    PlayHideAnimation();
-                }
-
-                Iconified = !Iconified;
+                ToggleIconified();
             });
 
             // TODO : this is for the unpin test.
@@ -183,5 +193,11 @@ namespace TVHome.Views
                 UpdatePinnedApps(PinnedApps);
             }
         }
+
+        protected override bool OnBackButtonPressed()
+        {
+            ToggleIconified();
+            return true;
+        }
     }
 }
\ No newline at end of file