6ba6408dc4e90bd489be1ae800c9d1c90739770a
[platform/core/csapi/nui.git] / Tizen.NUI / src / public / NUIApplication.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (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://www.apache.org/licenses/LICENSE-2.0
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
18 using System;
19 using Tizen.Applications;
20 using Tizen.NUI;
21
22 namespace Tizen.NUI
23 {
24
25     public class NUIApplication : CoreUIApplication
26     {
27         private void LOG(string _str)
28         {
29             Tizen.Log.Debug("NUI", _str);
30             //Console.WriteLine("[NUI]" + _str);
31         }
32
33         private Application _application;
34         private ApplicationExtensions _applicationExt;
35         private string _stylesheet;
36         private Application.WindowMode _windowMode;
37         private AppMode _appMode;
38         private Stage _stage;
39
40         public NUIApplication() : base()
41         {
42             _appMode = AppMode.Default;
43         }
44
45         public NUIApplication(string stylesheet) : base()
46         {
47             //handle the stylesheet
48             _appMode = AppMode.StyleSheetOnly;
49             _stylesheet = stylesheet;
50         }
51
52         public NUIApplication(string stylesheet, Application.WindowMode windowMode) : base()
53         {
54             //handle the stylesheet and windowMode
55             _appMode = AppMode.StyleSheetWithWindowMode;
56             _stylesheet = stylesheet;
57             _windowMode = windowMode;
58         }
59
60
61         protected override void OnPause()
62         {
63             base.OnPause();
64             _applicationExt.Pause();
65             LOG("OnPause() is called!");
66         }
67
68         protected override void OnPreCreate()
69         {
70             switch (_appMode)
71             {
72                 case AppMode.Default:
73                     _application = Tizen.NUI.Application.NewApplication();
74                     break;
75                 case AppMode.StyleSheetOnly:
76                     _application = Tizen.NUI.Application.NewApplication(_stylesheet);
77                     break;
78                 case AppMode.StyleSheetWithWindowMode:
79                     _application = Tizen.NUI.Application.NewApplication(_stylesheet, _windowMode);
80                     break;
81                 default:
82                     break;
83             }
84             _applicationExt = new ApplicationExtensions(_application);
85             _applicationExt.Init();
86
87             _stage = Stage.Instance;
88             _stage.SetBackgroundColor(Color.White);
89             LOG("OnPreCreate() is called!");
90         }
91
92         protected override void OnResume()
93         {
94             base.OnResume();
95             _applicationExt.Resume();
96             LOG("OnResume() is called!");
97         }
98
99         protected override void OnAppControlReceived(AppControlReceivedEventArgs e)
100         {
101             base.OnAppControlReceived(e);
102             LOG("OnAppControlReceived() is called!");
103             if (e != null)
104             {
105                 LOG("OnAppControlReceived() is called! ApplicationId=" + e.ReceivedAppControl.ApplicationId);
106                 LOG("CallerApplicationId=" + e.ReceivedAppControl.CallerApplicationId + "   IsReplyRequest=" + e.ReceivedAppControl.IsReplyRequest);
107             }
108         }
109
110         protected override void OnCreate()
111         {
112             base.OnCreate();
113             LOG("OnCreate() is called!");
114         }
115
116         protected override void OnLocaleChanged(LocaleChangedEventArgs e)
117         {
118             base.OnLocaleChanged(e);
119             _applicationExt.LanguageChange();
120             LOG("OnLocaleChanged() is called!");
121         }
122
123         protected override void OnLowBattery(LowBatteryEventArgs e)
124         {
125             base.OnLowBattery(e);
126             LOG("OnLowBattery() is called!");
127         }
128
129         protected override void OnLowMemory(LowMemoryEventArgs e)
130         {
131             base.OnLowMemory(e);
132             LOG("OnLowMemory() is called!");
133         }
134
135         protected override void OnRegionFormatChanged(RegionFormatChangedEventArgs e)
136         {
137             base.OnRegionFormatChanged(e);
138             LOG("OnRegionFormatChanged() is called!");
139         }
140
141         protected override void OnTerminate()
142         {
143             base.OnTerminate();
144             _applicationExt.Terminate();
145             LOG("OnTerminate() is called!");
146         }
147
148         private enum AppMode
149         {
150             Default = 0,
151             StyleSheetOnly = 1,
152             StyleSheetWithWindowMode = 2
153         }
154     }
155 }