6c34da6582f89331b9e6138e828fe5ad044a62ac
[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     /// <summary>
26     /// Represents an application that have UI screen. The NUIApplication class has a default stage.
27     /// </summary>
28     public class NUIApplication : CoreUIApplication
29     {
30         /// <summary>
31         /// The instance of the Application.
32         /// </summary>
33         /// <remarks>
34         /// This application is created before OnCreate() or created event. And the NUIApplication will be terminated when this application is closed.
35         /// </remarks>
36         private Application _application;
37
38         /// <summary>
39         /// The instance of the Dali Application extension.
40         /// </summary>
41         private ApplicationExtensions _applicationExt;
42
43         /// <summary>
44         /// Store the stylesheet value.
45         /// </summary>
46         private string _stylesheet;
47
48         /// <summary>
49         /// Store the window mode value.
50         /// </summary>
51         private Application.WindowMode _windowMode;
52
53         /// <summary>
54         /// Store the app mode value.
55         /// </summary>
56         private AppMode _appMode;
57
58         /// <summary>
59         /// The instance of the Dali Stage.
60         /// </summary>
61         private Window _window;
62
63         /// <summary>
64         /// The default constructor.
65         /// </summary>
66         public NUIApplication() : base()
67         {
68             _appMode = AppMode.Default;
69         }
70
71         /// <summary>
72         /// The constructor with stylesheet.
73         /// </summary>
74         public NUIApplication(string stylesheet) : base()
75         {
76             //handle the stylesheet
77             _appMode = AppMode.StyleSheetOnly;
78             _stylesheet = stylesheet;
79         }
80
81         /// <summary>
82         /// The constructor with stylesheet and window mode.
83         /// </summary>
84         public NUIApplication(string stylesheet, WindowMode windowMode) : base()
85         {
86             //handle the stylesheet and windowMode
87             _appMode = AppMode.StyleSheetWithWindowMode;
88             _stylesheet = stylesheet;
89             _windowMode = (Application.WindowMode)windowMode;
90         }
91
92         /// <summary>
93         /// Overrides this method if want to handle behavior.
94         /// </summary>
95         protected override void OnPause()
96         {
97             base.OnPause();
98             _applicationExt.Pause();
99             NUILog.Debug("OnPause() is called!");
100         }
101
102         /// <summary>
103         /// Overrides this method if want to handle behavior before calling OnCreate().<br>
104         /// stage property is initialized in this overrided method.<br>
105         /// </summary>
106         protected override void OnPreCreate()
107         {
108             // Initialize DisposeQueue Singleton class.
109             DisposeQueue disposeQ = DisposeQueue.Instance;
110             NUILog.Debug("##### 1) DisposeQueue.Instance.Initialize()!");
111             switch (_appMode)
112             {
113                 case AppMode.Default:
114                     _application = Tizen.NUI.Application.NewApplication();
115                     break;
116                 case AppMode.StyleSheetOnly:
117                     _application = Tizen.NUI.Application.NewApplication(_stylesheet);
118                     break;
119                 case AppMode.StyleSheetWithWindowMode:
120                     _application = Tizen.NUI.Application.NewApplication(_stylesheet, _windowMode);
121                     break;
122                 default:
123                     break;
124             }
125             _applicationExt = new ApplicationExtensions(_application);
126             _applicationExt.Init();
127             _applicationExt.Start();
128
129             // This is also required to create DisposeQueue on main thread.
130             disposeQ.Initialize();
131             NUILog.Debug("##### 2) DisposeQueue.Instance.Initialize()!");
132             _window = Window.Instance;
133             _window.SetBackgroundColor(Color.White);
134             NUILog.Debug("OnPreCreate() is called!");
135         }
136
137         /// <summary>
138         /// Overrides this method if want to handle behavior.
139         /// </summary>
140         protected override void OnResume()
141         {
142             base.OnResume();
143             _applicationExt.Resume();
144             NUILog.Debug("OnResume() is called!");
145         }
146
147         /// <summary>
148         /// Overrides this method if want to handle behavior.
149         /// </summary>
150         protected override void OnAppControlReceived(AppControlReceivedEventArgs e)
151         {
152             base.OnAppControlReceived(e);
153             NUILog.Debug("OnAppControlReceived() is called!");
154             if (e != null)
155             {
156                 NUILog.Debug("OnAppControlReceived() is called! ApplicationId=" + e.ReceivedAppControl.ApplicationId);
157                 NUILog.Debug("CallerApplicationId=" + e.ReceivedAppControl.CallerApplicationId + "   IsReplyRequest=" + e.ReceivedAppControl.IsReplyRequest);
158             }
159         }
160
161         /// <summary>
162         /// Overrides this method if want to handle behavior.
163         /// </summary>
164         protected override void OnCreate()
165         {
166             base.OnCreate();
167             NUILog.Debug("OnCreate() is called!");
168         }
169
170         /// <summary>
171         /// Overrides this method if want to handle behavior.
172         /// </summary>
173         protected override void OnLocaleChanged(LocaleChangedEventArgs e)
174         {
175             base.OnLocaleChanged(e);
176             _applicationExt.LanguageChange();
177             NUILog.Debug("OnLocaleChanged() is called!");
178         }
179
180         /// <summary>
181         /// Overrides this method if want to handle behavior.
182         /// </summary>
183         protected override void OnLowBattery(LowBatteryEventArgs e)
184         {
185             base.OnLowBattery(e);
186             NUILog.Debug("OnLowBattery() is called!");
187         }
188
189         /// <summary>
190         /// Overrides this method if want to handle behavior.
191         /// </summary>
192         protected override void OnLowMemory(LowMemoryEventArgs e)
193         {
194             base.OnLowMemory(e);
195             NUILog.Debug("OnLowMemory() is called!");
196         }
197
198         /// <summary>
199         /// Overrides this method if want to handle behavior.
200         /// </summary>
201         protected override void OnRegionFormatChanged(RegionFormatChangedEventArgs e)
202         {
203             base.OnRegionFormatChanged(e);
204             NUILog.Debug("OnRegionFormatChanged() is called!");
205         }
206
207         /// <summary>
208         /// Overrides this method if want to handle behavior.
209         /// </summary>
210         protected override void OnTerminate()
211         {
212             base.OnTerminate();
213             _applicationExt.Terminate();
214             NUILog.Debug("OnTerminate() is called!");
215         }
216
217         /// <summary>
218         /// The mode of creating NUI application.
219         /// </summary>
220         private enum AppMode
221         {
222             Default = 0,
223             StyleSheetOnly = 1,
224             StyleSheetWithWindowMode = 2
225         }
226
227         /// <summary>
228         /// Enumeration for deciding whether a NUI application window is opaque or transparent.
229         /// </summary>
230         public enum WindowMode
231         {
232             Opaque = 0,
233             Transparent = 1
234         }
235
236         /// <summary>
237         /// Get the window instance.
238         /// </summary>
239         public Window Window
240         {
241             get
242             {
243                 return _application.GetWindow();
244             }
245         }
246     }
247 }