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