Implements Apps out VI
[profile/tv/apps/dotnet/home.git] / TVApps / TVApps.TizenTV / TVApps.TizenTV.cs
1 /*
2  * Copyright (c) 2017 Samsung Electronics Co., Ltd
3  *
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
7  *
8  *     http://floralicense.org/license/
9  *
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.
15  */
16
17 using LibTVRefCommonPortable.Utils;
18 using LibTVRefCommonTizen.Ports;
19 using Tizen.Applications;
20 using Tizen.Xamarin.Forms.Extension.Renderer;
21
22 namespace TVApps.TizenTV
23 {
24     /// <summary>
25     /// TV Apps application main entry point
26     /// </summary>
27     public class Program : Xamarin.Forms.Platform.Tizen.FormsApplication, IAppLifeControl
28     {
29         /// <summary>
30         /// The application instance
31         /// </summary>
32         private static Program instance;
33
34         /// <summary>
35         /// A interface for the platform notification
36         /// </summary>
37         private IPlatformNotification notification;
38
39         /// <summary>
40         /// A method will be called when application is created
41         /// </summary>
42         protected override void OnCreate()
43         {
44             base.OnCreate();
45
46             FileSystemPort.AppDataStroagePath = DirectoryInfo.Data;
47             FileSystemPort.PlatformShareStroagePath = "/opt/usr/home/owner/share/";
48
49             var app = new App(MainWindow.ScreenSize.Width,
50                 MainWindow.ScreenSize.Height,
51                 MainWindow.ScreenDpi.X,
52                 ElmSharp.Elementary.GetScale());
53             notification = app;
54
55             DbgPort.D("-----------------------------------");
56             DbgPort.D("Apps application is being loaded...");
57             DbgPort.D("-----------------------------------");
58             LoadApplication(app);
59
60             PackageManagerPort.RegisterCallbacks(notification);
61             MainWindow.Alpha = true;
62             MainWindow.KeyUp += KeyUpListener;
63
64             MainWindow.KeyGrab(ElmSharp.EvasKeyEventArgs.PlatformMenuButtonName, true);
65         }
66
67         /// <summary>
68         /// A method will be called when application receives KeyUp event
69         /// </summary>
70
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)
74         {
75             DebuggingUtils.Dbg("[TVApps.TizenTV.cs] Key Pressed :" + args.KeyName);
76             if (args.KeyName.CompareTo(ElmSharp.EvasKeyEventArgs.PlatformMenuButtonName) == 0)
77             {
78                 if (notification != null)
79                 {
80                     notification.OnMenuKeyPressed();
81                 }
82             }
83         }
84
85         /// <summary>
86         /// A method will be called when application is terminated
87         /// </summary>
88         protected override void OnTerminate()
89         {
90             base.OnTerminate();
91
92             notification = null;
93             PackageManagerPort.UnregisterCallbacks();
94             MainWindow.KeyUngrab(ElmSharp.EvasKeyEventArgs.PlatformMenuButtonName);
95         }
96
97         /// <summary>
98         /// A method will be called when application receives AppControl
99         /// </summary>
100         /// <param name="e">AppControl event argument</param>
101         protected override void OnAppControlReceived(AppControlReceivedEventArgs e)
102         {
103             DbgPort.D("OnAppControlReceived, " + e.ReceivedAppControl.Operation);
104
105             if (AppControlPort.AddAppOperation.CompareTo(e.ReceivedAppControl.Operation) == 0)
106             {
107                 DbgPort.D("Add App Request");
108                 notification.OnPinAppRequestReceived();
109             }
110         }
111
112         /// <summary>
113         /// The entry point for the application
114         /// </summary>
115         /// <param name="args">A list of command line arguments</param>
116         static void Main(string[] args)
117         {
118             instance = new Program();
119
120             DbgPort.Prefix = "Apps";
121
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>();
130
131             Xamarin.Forms.Platform.Tizen.Forms.Init(instance);
132             TizenFormsExtension.Init();
133
134             instance.Run(args);
135         }
136
137         /// <summary>
138         /// A method terminates application
139         /// </summary>
140         public void SelfTerminate()
141         {
142             instance.Exit();
143         }
144     }
145 }