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 LibTVRefCommonPortable.Utils;
18 using LibTVRefCommonTizen.Ports;
19 using Tizen.Applications;
20 using Tizen.Xamarin.Forms.Extension.Renderer;
22 namespace TVApps.TizenTV
25 /// TV Apps application main entry point
27 public class Program : Xamarin.Forms.Platform.Tizen.FormsApplication, IAppLifeControl
30 /// The application instance
32 private static Program instance;
35 /// A interface for the platform notification
37 private IPlatformNotification notification;
40 /// A method will be called when application is created
42 protected override void OnCreate()
46 FileSystemPort.AppDataStroagePath = DirectoryInfo.Data;
47 FileSystemPort.PlatformShareStroagePath = "/opt/usr/home/owner/share/";
49 var app = new App(MainWindow.ScreenSize.Width,
50 MainWindow.ScreenSize.Height,
51 MainWindow.ScreenDpi.X,
52 ElmSharp.Elementary.GetScale());
55 DbgPort.D("-----------------------------------");
56 DbgPort.D("Apps application is being loaded...");
57 DbgPort.D("-----------------------------------");
60 PackageManagerPort.RegisterCallbacks(notification);
61 MainWindow.Alpha = true;
62 MainWindow.KeyUp += KeyUpListener;
64 MainWindow.KeyGrab(ElmSharp.EvasKeyEventArgs.PlatformMenuButtonName, true);
68 /// A method will be called when application receives KeyUp event
71 /// <param name="sender">The source of the event</param>
72 /// <param name="args">A EvasKey event's argument</param>
73 private void KeyUpListener(object sender, ElmSharp.EvasKeyEventArgs args)
75 DebuggingUtils.Dbg("[TVApps.TizenTV.cs] Key Pressed :" + args.KeyName);
76 if (args.KeyName.CompareTo(ElmSharp.EvasKeyEventArgs.PlatformMenuButtonName) == 0)
78 if (notification != null)
80 notification.OnMenuKeyPressed();
86 /// A method will be called when application is terminated
88 protected override void OnTerminate()
93 PackageManagerPort.UnregisterCallbacks();
94 MainWindow.KeyUngrab(ElmSharp.EvasKeyEventArgs.PlatformMenuButtonName);
98 /// A method will be called when application receives AppControl
100 /// <param name="e">AppControl event argument</param>
101 protected override void OnAppControlReceived(AppControlReceivedEventArgs e)
103 DbgPort.D("OnAppControlReceived, " + e.ReceivedAppControl.Operation);
105 if (AppControlPort.AddAppOperation.CompareTo(e.ReceivedAppControl.Operation) == 0)
107 DbgPort.D("Add App Request");
108 notification.OnPinAppRequestReceived();
113 /// The entry point for the application
115 /// <param name="args">A list of command line arguments</param>
116 static void Main(string[] args)
118 instance = new Program();
120 DbgPort.Prefix = "Apps";
122 Xamarin.Forms.DependencyService.Register<DbgPort>();
123 Xamarin.Forms.DependencyService.Register<Program>();
124 Xamarin.Forms.DependencyService.Register<AppControlPort>();
125 Xamarin.Forms.DependencyService.Register<PackageManagerPort>();
126 Xamarin.Forms.DependencyService.Register<FileSystemWatcherPort>();
127 Xamarin.Forms.DependencyService.Register<ApplicationManagerPort>();
128 Xamarin.Forms.DependencyService.Register<FileSystemPort>();
129 Xamarin.Forms.DependencyService.Register<SystemSettingsPort>();
131 Xamarin.Forms.Platform.Tizen.Forms.Init(instance);
132 TizenFormsExtension.Init();
138 /// A method terminates application
140 public void SelfTerminate()