From 1502ebb0e659824b25f3bc9da7b41232376eb723 Mon Sep 17 00:00:00 2001 From: Kyuho Jo Date: Wed, 22 Mar 2017 15:48:50 +0900 Subject: [PATCH] Home key event handling 1. Grab Key Event 2. Iconified app Signed-off-by: Kyuho Jo Change-Id: I27d12fae5102fca99e3561c9b585c20685289038 --- .../LibTVRefCommonTizen.csproj | 1 + .../LibTVRefCommonTizen.project.json | 2 +- LibTVRefCommonTizen/Ports/ElmPort.cs | 55 +++++++++++++++++++ TVHome/TVHome.TizenTV/TVHome.TizenTV.cs | 26 +++++++-- .../TVHome.TizenTV.project.json | 52 +++++++++--------- .../Controls/SubPanelThumbnailButton.xaml | 2 +- TVHome/TVHome/Views/MainPage.xaml.cs | 13 ++--- 7 files changed, 111 insertions(+), 40 deletions(-) create mode 100644 LibTVRefCommonTizen/Ports/ElmPort.cs diff --git a/LibTVRefCommonTizen/LibTVRefCommonTizen.csproj b/LibTVRefCommonTizen/LibTVRefCommonTizen.csproj index 565835c..c102a36 100644 --- a/LibTVRefCommonTizen/LibTVRefCommonTizen.csproj +++ b/LibTVRefCommonTizen/LibTVRefCommonTizen.csproj @@ -50,6 +50,7 @@ + diff --git a/LibTVRefCommonTizen/LibTVRefCommonTizen.project.json b/LibTVRefCommonTizen/LibTVRefCommonTizen.project.json index 41d478f..497ae2f 100644 --- a/LibTVRefCommonTizen/LibTVRefCommonTizen.project.json +++ b/LibTVRefCommonTizen/LibTVRefCommonTizen.project.json @@ -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 index 0000000..d1b5510 --- /dev/null +++ b/LibTVRefCommonTizen/Ports/ElmPort.cs @@ -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); + } + } +} diff --git a/TVHome/TVHome.TizenTV/TVHome.TizenTV.cs b/TVHome/TVHome.TizenTV/TVHome.TizenTV.cs index a2c9b6a..702821e 100755 --- a/TVHome/TVHome.TizenTV/TVHome.TizenTV.cs +++ b/TVHome/TVHome.TizenTV/TVHome.TizenTV.cs @@ -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) diff --git a/TVHome/TVHome.TizenTV/TVHome.TizenTV.project.json b/TVHome/TVHome.TizenTV/TVHome.TizenTV.project.json index eab0202..507598a 100644 --- a/TVHome/TVHome.TizenTV/TVHome.TizenTV.project.json +++ b/TVHome/TVHome.TizenTV/TVHome.TizenTV.project.json @@ -1,27 +1,27 @@ -{ - "buildOptions": { - "emitEntryPoint": true, - "debugType": "portable", - "platform": "AnyCPU", - "preserveCompilationContext": true - }, - "dependencies": { - "ElmSharp": "1.1.0-beta-014", - "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" - ] - } - } +{ + "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 diff --git a/TVHome/TVHome/Controls/SubPanelThumbnailButton.xaml b/TVHome/TVHome/Controls/SubPanelThumbnailButton.xaml index b38148a..f75e70e 100644 --- a/TVHome/TVHome/Controls/SubPanelThumbnailButton.xaml +++ b/TVHome/TVHome/Controls/SubPanelThumbnailButton.xaml @@ -6,7 +6,7 @@ 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. -- 2.34.1