/* * 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 Tizen.Applications; using LibTVRefCommonPortable.Utils; using LibTVRefCommonTizen.Ports; using Tizen.Xamarin.Forms.Extension.Renderer; using CoreApp; using System; namespace TVHome.TizenTV { /// /// TV Home application main entry point /// class Program : global::Xamarin.Forms.Platform.Tizen.FormsApplication { /// /// An interface for the platform notification /// IPlatformNotification notification; /// /// A port for handling Window APIs /// WindowPort windowPort; /// /// A method will be called when application is created /// protected override void OnCreate() { base.OnCreate(); FileSystemPort.AppDataStroagePath = DirectoryInfo.Data; FileSystemPort.AppResourceStoragePath = DirectoryInfo.Resource; string platformShareStoragePath = "/opt/usr/home/owner/share/"; FileSystemPort.PlatformShareStroagePath = platformShareStoragePath; var app = new App(MainWindow.ScreenSize.Width, MainWindow.ScreenSize.Height, MainWindow.ScreenDpi.X, ElmSharp.Elementary.GetScale()); notification = app; DbgPort.D("-----------------------------------"); DbgPort.D("Home application is being loaded..."); DbgPort.D("-----------------------------------"); LoadApplication(app); PackageManagerPort.RegisterCallbacks(notification); MainWindow.KeyUp += KeyUpListener; MainWindow.Alpha = true; windowPort = new WindowPort(); windowPort.MainWindow = MainWindow; /// Grab key events MainWindow.KeyGrab(ElmSharp.EvasKeyEventArgs.PlatformHomeButtonName, true); MainWindow.KeyGrab(ElmSharp.EvasKeyEventArgs.PlatformMenuButtonName, true); MainWindow.KeyGrab("XF86Info", true); MainWindow.KeyGrab("Up", false); MainWindow.KeyGrab("Down", false); MainWindow.KeyGrab("Left", false); MainWindow.KeyGrab("Right", false); windowPort.SetKeyGrabExclusively(ElmSharp.EvasKeyEventArgs.PlatformHomeButtonName); /// Sniper try { Sniper sniper = new Sniper((IntPtr)MainWindow, platformShareStoragePath, 960, 540); sniper.UpdatedEvent += OnScreenUpdate; sniper.AddRemoveEvent += SniperAddRemoveEvent; sniper.SkipUpdateEvent += SniperSkipUpdateEvent; sniper.StartMonitor(); } catch (SniperException e) { DbgPort.E("Failed to create sniper object : " + e.Message); } } private void SniperSkipUpdateEvent(object sender, Sniper.Event e) { DbgPort.D(" [Sniper SkipUpdateEvent] : " + e.Info); (sender as Sniper).SkipUpdateFlag = true; } private void SniperAddRemoveEvent(object sender, Sniper.Event e) { DbgPort.D(" [Sniper SniperAddRemoveEvent] : " + e.Info); } private void OnScreenUpdate(object sender, Sniper.Event e) { DbgPort.D(" [Sniper OnScreenUpdate] : " + e.Info); } /// /// A method will be called when application receives KeyUp event /// /// The source of the event /// A EvasKey event's argument private void KeyUpListener(object sender, ElmSharp.EvasKeyEventArgs e) { DbgPort.D("Key Pressed :" + e.KeyName); if (e.KeyName.CompareTo(ElmSharp.EvasKeyEventArgs.PlatformHomeButtonName) == 0) { if (notification != null) { notification.OnHomeKeyPressed(); } } else if (e.KeyName.CompareTo(ElmSharp.EvasKeyEventArgs.PlatformMenuButtonName) == 0 || e.KeyName.CompareTo("XF86Info") == 0) { if (notification != null) { notification.OnMenuKeyPressed(); } } else if (e.KeyName.Equals("Up") || e.KeyName.Equals("Down") || e.KeyName.Equals("Left") || e.KeyName.Equals("Right")) { if (notification != null) { notification.OnNavigationKeyPressed(e.KeyName); } } } /// /// A method will be called when application is terminated /// protected override void OnTerminate() { base.OnTerminate(); notification = null; PackageManagerPort.UnregisterCallbacks(); MainWindow.KeyUngrab(ElmSharp.EvasKeyEventArgs.PlatformHomeButtonName); MainWindow.KeyUngrab(ElmSharp.EvasKeyEventArgs.PlatformMenuButtonName); MainWindow.KeyUngrab("XF86Info"); MainWindow.KeyUngrab("Up"); MainWindow.KeyUngrab("Down"); MainWindow.KeyUngrab("Left"); MainWindow.KeyUngrab("Right"); } /// /// A method will be called when application receives app control /// /// AppControl event argument protected override void OnAppControlReceived(AppControlReceivedEventArgs e) { if (AppControlPort.AppAddedNotifyOperation.CompareTo(e.ReceivedAppControl.Operation) == 0) { DbgPort.D("App Added Notification"); string pinnedApp; if (e.ReceivedAppControl.ExtraData.TryGet(AppControlPort.KeyAddedAppID, out pinnedApp)) { notification.OnAppPinnedNotificationReceived(pinnedApp); } else { notification.OnAppPinnedNotificationReceived(""); } } } /// /// The entry point for the application /// /// A list of command line arguments static void Main(string[] args) { var app = new Program(); DbgPort.Prefix = "Home"; global::Xamarin.Forms.DependencyService.Register(); global::Xamarin.Forms.DependencyService.Register(); global::Xamarin.Forms.DependencyService.Register(); global::Xamarin.Forms.DependencyService.Register(); global::Xamarin.Forms.DependencyService.Register(); global::Xamarin.Forms.DependencyService.Register(); global::Xamarin.Forms.DependencyService.Register(); global::Xamarin.Forms.DependencyService.Register(); global::Xamarin.Forms.DependencyService.Register(); TizenFormsExtension.Init(); global::Xamarin.Forms.Platform.Tizen.Forms.Init(app); app.Run(args); } } }