Merge "Adds LICENSE file" into tizen
[profile/tv/apps/dotnet/mediahub.git] / TVMediaHub / TVMediaHub.Tizen / TVMediaHub.Tizen.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 Tizen.Applications;
18 using Tizen.Xamarin.Forms.Extension.Renderer;
19 using Xamarin.Forms;
20 using TVMediaHub.Tizen.Views;
21 using TVMediaHub.Tizen.ViewModels;
22
23 namespace TVMediaHub.Tizen
24 {
25     /// <summary>
26     /// TV MediaHub application main entry point
27     /// </summary>
28     class Program : global::Xamarin.Forms.Platform.Tizen.FormsApplication
29     {
30         /// <summary>
31         /// Gets or sets the instance of TV MediaHub
32         /// </summary>
33         public static Program Instance
34         {
35             get;
36             private set;
37         }
38
39         /// <summary>
40         /// Gets or sets the resource directory path of TV MediaHub
41         /// </summary>
42         public static string ResourceDirectoryPath
43         {
44             get;
45             private set;
46         }
47
48         /// <summary>
49         /// An instance of the TV MediaHub application
50         /// </summary>
51         private static App app;
52
53         /// <summary>
54         /// A method will be called when application is created
55         /// </summary>
56         protected override void OnCreate()
57         {
58             base.OnCreate();
59
60             // TODO : due to VD's GBM binary issue.
61             if (DirectoryInfo.Resource == null || DirectoryInfo.Resource.Length < 1)
62             {
63                 ResourceDirectoryPath = "/home/owner/apps_rw/org.tizen.xamediahub/res/";
64             }
65             else
66             {
67                 ResourceDirectoryPath = DirectoryInfo.Resource;
68             }
69
70             app = new App(MainWindow.ScreenSize.Width,
71                 MainWindow.ScreenSize.Height,
72                 MainWindow.ScreenDpi.X,
73                 ElmSharp.Elementary.GetScale(),
74                 MainWindow);
75             LoadApplication(app);
76         }
77
78         /// <summary>
79         /// A method will be called when application receives app control
80         /// </summary>
81         /// <param name="e">AppControl event argument</param>
82         protected override void OnAppControlReceived(AppControlReceivedEventArgs e)
83         {
84             if (e.ReceivedAppControl != null && e.ReceivedAppControl.ExtraData != null)
85             {
86                 string mediaId;
87                 if (e.ReceivedAppControl.ExtraData.TryGet("Media Id", out mediaId) == true)
88                 {
89                     VideoTabViewModelLocator.ViewModel.SetCurrentVideo(mediaId);
90                     Program.TransitionTo(new VideoPlayer());
91                 }
92             }
93         }
94
95         /// <summary>
96         /// A method for pushing a specific page to navigation stack.
97         /// </summary>
98         /// <param name="page">A page to be pushed</param>
99         public static void TransitionTo(ContentPage page)
100         {
101             app.TransitionTo(page);
102         }
103
104         /// <summary>
105         /// A method for setting the root page as MainPage.
106         /// </summary>
107         /// <param name="tabIndex">An index of tab to be set as MainPage. Default value is 0</param>
108         public static void TransitionToMain(int tabIndex = 0)
109         {
110             app.TransitionToMain(tabIndex);
111         }
112
113         /// <summary>
114         /// The entry point for the application
115         /// </summary>
116         /// <param name="args">A list of command line arguments</param>
117         static void Main(string[] args)
118         {
119             Instance = new Program();
120             TizenFormsExtension.Init();
121             global::Xamarin.Forms.Platform.Tizen.Forms.Init(Instance);
122             Instance.Run(args);
123         }
124
125         /// <summary>
126         /// A method terminates application
127         /// </summary>
128         public void SelfTerminate()
129         {
130             Instance.Exit();
131         }
132     }
133 }