Home key event handling
authorKyuho Jo <kyuho.jo@samsung.com>
Wed, 22 Mar 2017 06:48:50 +0000 (15:48 +0900)
committerChulSeung Kim <charles0.kim@samsung.com>
Thu, 8 Jun 2017 09:34:48 +0000 (18:34 +0900)
1. Grab Key Event
2. Iconified app

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

LibTVRefCommonTizen/LibTVRefCommonTizen.csproj
LibTVRefCommonTizen/LibTVRefCommonTizen.project.json
LibTVRefCommonTizen/Ports/ElmPort.cs [new file with mode: 0644]
TVHome/TVHome.TizenTV/TVHome.TizenTV.cs
TVHome/TVHome.TizenTV/TVHome.TizenTV.project.json
TVHome/TVHome/Controls/SubPanelThumbnailButton.xaml
TVHome/TVHome/Views/MainPage.xaml.cs

index 565835c..c102a36 100644 (file)
@@ -50,6 +50,7 @@
     <Compile Include="Ports\BTModulePort.cs" />
     <Compile Include="Ports\DBPort.cs" />
     <Compile Include="Ports\DebuggingPort.cs" />
+    <Compile Include="Ports\ElmPort.cs" />
     <Compile Include="Ports\FileSystemPort.cs" />
     <Compile Include="Ports\FileSystemWatcherPort.cs" />
     <Compile Include="Ports\PackageManagerPort.cs" />
index 41d478f..497ae2f 100644 (file)
@@ -1,6 +1,6 @@
 {
   "dependencies": {
-    "ElmSharp": "1.1.0-beta-014",
+    "ElmSharp": "1.1.0-beta-015",
     "Microsoft.NETCore.App": "1.1.0",
     "Tizen.Library": "1.0.0-pre2",
     "Xamarin.Forms": "2.3.3.193",
diff --git a/LibTVRefCommonTizen/Ports/ElmPort.cs b/LibTVRefCommonTizen/Ports/ElmPort.cs
new file mode 100644 (file)
index 0000000..d1b5510
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * 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);
+        }
+    }
+}
index a2c9b6a..702821e 100755 (executable)
@@ -19,6 +19,7 @@ using System.Threading;
 using LibTVRefCommonPortable.Utils;
 using LibTVRefCommonTizen.Ports;
 using Tizen.Applications;
+using ElmSharp;
 
 
 namespace TVHome.TizenTV
@@ -27,6 +28,7 @@ namespace TVHome.TizenTV
     {
         IPlatformNotification notification;
         private Timer timerForKeyGrab;
+        private Timer timerForIconified;
 
         public static string AppResourcePath
         {
@@ -44,11 +46,19 @@ namespace TVHome.TizenTV
         {
             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();
@@ -63,12 +73,11 @@ namespace TVHome.TizenTV
 
             PackageManagerPort.RegisterCallbacks(notification);
 
-           MainWindow.KeyUp += KeyUpListener;
+            MainWindow.KeyUp += KeyUpListener;
             MainWindow.Alpha = true;
 
             TimerCallback timerDelegate = new TimerCallback(CallbackForKeyGrab);
-            timerForKeyGrab = new Timer(timerDelegate, MainWindow, 3000, 0);
-
+            timerForKeyGrab = new Timer(timerDelegate, null, 3000, 0);
         }
 
         private void KeyUpListener(object sender, ElmSharp.EvasKeyEventArgs e)
@@ -76,10 +85,17 @@ namespace TVHome.TizenTV
             DebuggingPort.D("Key Pressed :" + e.KeyName);
             if (e.KeyName.CompareTo(ElmSharp.EvasKeyEventArgs.PlatformHomeButtonName) == 0)
             {
-                MainWindow.Active();
-                if (notification != null)
+                if (ElmPort.GetIconified((IntPtr)MainWindow) == true)
+                {
+                    ElmPort.SetIconified((IntPtr)MainWindow, false);
+                    MainWindow.Active();
+                    notification.OnHomeKeyPressed();
+                }
+                else
                 {
                     notification.OnHomeKeyPressed();
+                    TimerCallback timerDelegate = new TimerCallback(CallbackForIconified);
+                    timerForIconified = new Timer(timerDelegate, null, 200, 0);
                 }
             }
             else if (e.KeyName.CompareTo(ElmSharp.EvasKeyEventArgs.PlatformMenuButtonName) == 0)
index eab0202..507598a 100644 (file)
@@ -1,27 +1,27 @@
-{\r
-  "buildOptions": {\r
-    "emitEntryPoint": true,\r
-    "debugType": "portable",\r
-    "platform": "AnyCPU",\r
-    "preserveCompilationContext": true\r
-  },\r
-  "dependencies": {\r
-    "ElmSharp": "1.1.0-beta-014",\r
-    "Microsoft.NETCore.App": "1.1.0",\r
-    "Tizen.Library": "1.0.0-pre2",\r
-    "Xamarin.Forms": "2.3.3.193",\r
-    "Xamarin.Forms.Platform.Tizen": "2.3.4-r192-001"\r
-  },\r
-  "runtimes": {\r
-    "win": {},\r
-    "linux": {}\r
-  },\r
-  "frameworks": {\r
-    "netcoreapp1.0": {\r
-      "imports": [\r
-        "portable-net45+wp80+win81+wpa81",\r
-        "netstandard1.6"\r
-      ]\r
-    }\r
-  }\r
+{
+  "buildOptions": {
+    "emitEntryPoint": true,
+    "debugType": "portable",
+    "platform": "AnyCPU",
+    "preserveCompilationContext": true
+  },
+  "dependencies": {
+    "ElmSharp": "1.1.0-beta-015",
+    "Microsoft.NETCore.App": "1.1.0",
+    "Tizen.Library": "1.0.0-pre2",
+    "Xamarin.Forms": "2.3.3.193",
+    "Xamarin.Forms.Platform.Tizen": "2.3.4-r192-001"
+  },
+  "runtimes": {
+    "win": {},
+    "linux": {}
+  },
+  "frameworks": {
+    "netcoreapp1.0": {
+      "imports": [
+        "portable-net45+wp80+win81+wpa81",
+        "netstandard1.6"
+      ]
+    }
+  }
 }
\ No newline at end of file
index b38148a..f75e70e 100644 (file)
@@ -6,7 +6,7 @@
     <RelativeLayout Opacity="0.99">
         <BoxView x:Name="ButtonBox"
                 WidthRequest="320"
-                HeightRequest="160"
+                HeightRequest="180"
                 Opacity="0"/>
         <Image x:Name="ThumbnailImage"
                 RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToView, ElementName=ButtonBox, Property=Width, Factor=1}"
index c825638..62e30d3 100755 (executable)
@@ -32,6 +32,7 @@ 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
         {
@@ -71,18 +72,16 @@ namespace TVHome.Views
 
             App.SetHomeKeyListener((e, arg) =>
             {
-                DebuggingUtils.Dbg("FIRED!!");
-                if (IsVisible)
+                if (Iconified == true)
                 {
-                    PlayHideAnimation();
-                    IsVisible = !IsVisible;
+                    PageMainPanel.InitialFocusing();
+                    PlayShowAnimation();
                 }
                 else
                 {
-                    IsVisible = !IsVisible;
-                    PageMainPanel.InitialFocusing();
-                    PlayShowAnimation();
+                    PlayHideAnimation();
                 }
+                Iconified = !Iconified;
             });
 
             // TODO : this is for the unpin test.