2 * Copyright (c) 2017 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.1 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://floralicense.org/license/
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 using Tizen.Applications;
18 using LibTVRefCommonPortable.Utils;
19 using LibTVRefCommonTizen.Ports;
20 using Tizen.Xamarin.Forms.Extension.Renderer;
24 namespace TVHome.TizenTV
27 /// TV Home application main entry point
29 class Program : global::Xamarin.Forms.Platform.Tizen.FormsApplication
32 /// An interface for the platform notification
34 IPlatformNotification notification;
36 /// A port for handling Window APIs
38 WindowPort windowPort;
41 /// A method will be called when application is created
43 protected override void OnCreate()
47 FileSystemPort.AppDataStroagePath = DirectoryInfo.Data;
48 FileSystemPort.AppResourceStoragePath = DirectoryInfo.Resource;
49 string platformShareStoragePath = "/opt/usr/home/owner/share/";
50 FileSystemPort.PlatformShareStroagePath = platformShareStoragePath;
52 var app = new App(MainWindow.ScreenSize.Width,
53 MainWindow.ScreenSize.Height,
54 MainWindow.ScreenDpi.X,
55 ElmSharp.Elementary.GetScale());
59 DbgPort.D("-----------------------------------");
60 DbgPort.D("Home application is being loaded...");
61 DbgPort.D("-----------------------------------");
64 PackageManagerPort.RegisterCallbacks(notification);
66 MainWindow.KeyUp += KeyUpListener;
67 MainWindow.Alpha = true;
69 windowPort = new WindowPort();
70 windowPort.MainWindow = MainWindow;
73 MainWindow.KeyGrab(ElmSharp.EvasKeyEventArgs.PlatformHomeButtonName, true);
74 MainWindow.KeyGrab(ElmSharp.EvasKeyEventArgs.PlatformMenuButtonName, true);
75 MainWindow.KeyGrab("XF86Info", true);
76 MainWindow.KeyGrab("Up", false);
77 MainWindow.KeyGrab("Down", false);
78 MainWindow.KeyGrab("Left", false);
79 MainWindow.KeyGrab("Right", false);
80 windowPort.SetKeyGrabExclusively(ElmSharp.EvasKeyEventArgs.PlatformHomeButtonName);
85 Sniper sniper = new Sniper((IntPtr)MainWindow, platformShareStoragePath, 960, 540);
86 sniper.UpdatedEvent += OnScreenUpdate;
87 sniper.AddRemoveEvent += SniperAddRemoveEvent;
88 sniper.SkipUpdateEvent += SniperSkipUpdateEvent;
89 sniper.StartMonitor();
91 catch (SniperException e)
93 DbgPort.E("Failed to create sniper object : " + e.Message);
97 private void SniperSkipUpdateEvent(object sender, Sniper.Event e)
99 DbgPort.D(" [Sniper SkipUpdateEvent] : " + e.Info);
100 (sender as Sniper).SkipUpdateFlag = true;
103 private void SniperAddRemoveEvent(object sender, Sniper.Event e)
105 DbgPort.D(" [Sniper SniperAddRemoveEvent] : " + e.Info);
108 private void OnScreenUpdate(object sender, Sniper.Event e)
110 DbgPort.D(" [Sniper OnScreenUpdate] : " + e.Info);
114 /// A method will be called when application receives KeyUp event
116 /// <param name="sender">The source of the event</param>
117 /// <param name="e">A EvasKey event's argument</param>
118 private void KeyUpListener(object sender, ElmSharp.EvasKeyEventArgs e)
120 DbgPort.D("Key Pressed :" + e.KeyName);
121 if (e.KeyName.CompareTo(ElmSharp.EvasKeyEventArgs.PlatformHomeButtonName) == 0)
123 if (notification != null)
125 notification.OnHomeKeyPressed();
128 else if (e.KeyName.CompareTo(ElmSharp.EvasKeyEventArgs.PlatformMenuButtonName) == 0 ||
129 e.KeyName.CompareTo("XF86Info") == 0)
131 if (notification != null)
133 notification.OnMenuKeyPressed();
136 else if (e.KeyName.Equals("Up") || e.KeyName.Equals("Down") || e.KeyName.Equals("Left") || e.KeyName.Equals("Right"))
138 if (notification != null)
140 notification.OnNavigationKeyPressed(e.KeyName);
146 /// A method will be called when application is terminated
148 protected override void OnTerminate()
153 PackageManagerPort.UnregisterCallbacks();
154 MainWindow.KeyUngrab(ElmSharp.EvasKeyEventArgs.PlatformHomeButtonName);
155 MainWindow.KeyUngrab(ElmSharp.EvasKeyEventArgs.PlatformMenuButtonName);
156 MainWindow.KeyUngrab("XF86Info");
157 MainWindow.KeyUngrab("Up");
158 MainWindow.KeyUngrab("Down");
159 MainWindow.KeyUngrab("Left");
160 MainWindow.KeyUngrab("Right");
164 /// A method will be called when application receives app control
166 /// <param name="e">AppControl event argument</param>
167 protected override void OnAppControlReceived(AppControlReceivedEventArgs e)
169 if (AppControlPort.AppAddedNotifyOperation.CompareTo(e.ReceivedAppControl.Operation) == 0)
171 DbgPort.D("App Added Notification");
173 if (e.ReceivedAppControl.ExtraData.TryGet(AppControlPort.KeyAddedAppID, out pinnedApp))
175 notification.OnAppPinnedNotificationReceived(pinnedApp);
179 notification.OnAppPinnedNotificationReceived("");
185 /// The entry point for the application
187 /// <param name="args">A list of command line arguments</param>
188 static void Main(string[] args)
190 var app = new Program();
192 DbgPort.Prefix = "Home";
194 global::Xamarin.Forms.DependencyService.Register<DbgPort>();
195 global::Xamarin.Forms.DependencyService.Register<AppControlPort>();
196 global::Xamarin.Forms.DependencyService.Register<PackageManagerPort>();
197 global::Xamarin.Forms.DependencyService.Register<FileSystemWatcherPort>();
198 global::Xamarin.Forms.DependencyService.Register<ApplicationManagerPort>();
199 global::Xamarin.Forms.DependencyService.Register<FileSystemPort>();
200 global::Xamarin.Forms.DependencyService.Register<WindowPort>();
201 global::Xamarin.Forms.DependencyService.Register<SystemSettingsPort>();
202 global::Xamarin.Forms.DependencyService.Register<MediaContentPort>();
203 TizenFormsExtension.Init();
204 global::Xamarin.Forms.Platform.Tizen.Forms.Init(app);