a79785e2e3fff17db2f8632f2eb5d503c3fcf398
[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 System.ComponentModel;
20 using System.Threading;
21 using Tizen.Applications;
22 using Tizen.Applications.CoreBackend;
23
24 namespace Tizen.NUI
25 {
26
27     /// <summary>
28     /// Represents an application that have a UI screen. The NUIApplication class has a default stage.
29     /// </summary>
30     /// <since_tizen> 3 </since_tizen>
31     public class NUIApplication : CoreApplication
32     {
33         /// <summary>
34         /// Occurs whenever the application is resumed.
35         /// </summary>
36         /// <since_tizen> 4 </since_tizen>
37         public event EventHandler Resumed;
38
39         /// <summary>
40         /// Occurs whenever the application is paused.
41         /// </summary>
42         /// <since_tizen> 4 </since_tizen>
43         public event EventHandler Paused;
44
45         /// <summary>
46         /// The instance of ResourceManager.
47         /// </summary>
48         private static System.Resources.ResourceManager resourceManager = null;
49
50         /// <summary>
51         /// The default constructor.
52         /// </summary>
53         /// <since_tizen> 3 </since_tizen>
54         public NUIApplication() : base(new NUICoreBackend())
55         {
56             Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
57         }
58
59         /// <summary>
60         /// The constructor with a stylesheet.
61         /// </summary>
62         /// <param name="styleSheet">The styleSheet url.</param>
63         /// <since_tizen> 3 </since_tizen>
64         public NUIApplication(string styleSheet) : base(new NUICoreBackend(styleSheet))
65         {
66             Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
67         }
68
69         /// <summary>
70         /// The constructor with a stylesheet and window mode.
71         /// </summary>
72         /// <param name="styleSheet">The styleSheet url.</param>
73         /// <param name="windowMode">The windowMode.</param>
74         /// <since_tizen> 3 </since_tizen>
75         public NUIApplication(string styleSheet, WindowMode windowMode) : base(new NUICoreBackend(styleSheet, windowMode))
76         {
77             Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
78         }
79
80         /// <summary>
81         /// Overrides this method if you want to handle behavior.
82         /// </summary>
83         /// <since_tizen> 3 </since_tizen>
84         protected override void OnLocaleChanged(LocaleChangedEventArgs e)
85         {
86             base.OnLocaleChanged(e);
87         }
88
89         /// <summary>
90         /// Overrides this method if you want to handle behavior.
91         /// </summary>
92         /// <since_tizen> 3 </since_tizen>
93         protected override void OnLowBattery(LowBatteryEventArgs e)
94         {
95             base.OnLowBattery(e);
96         }
97
98         /// <summary>
99         /// Overrides this method if you want to handle behavior.
100         /// </summary>
101         /// <since_tizen> 3 </since_tizen>
102         protected override void OnLowMemory(LowMemoryEventArgs e)
103         {
104             base.OnLowMemory(e);
105         }
106
107         /// <summary>
108         /// Overrides this method if you want to handle behavior.
109         /// </summary>
110         /// <since_tizen> 3 </since_tizen>
111         protected override void OnRegionFormatChanged(RegionFormatChangedEventArgs e)
112         {
113             base.OnRegionFormatChanged(e);
114         }
115
116         /// <summary>
117         /// Overrides this method if you want to handle behavior.
118         /// </summary>
119         /// <since_tizen> 3 </since_tizen>
120         protected override void OnTerminate()
121         {
122             base.OnTerminate();
123         }
124
125         /// <summary>
126         /// Overrides this method if you want to handle behavior.
127         /// </summary>
128         /// <since_tizen> 3 </since_tizen>
129         protected virtual void OnPause()
130         {
131             Paused?.Invoke(this, EventArgs.Empty);
132         }
133
134         /// <summary>
135         /// Overrides this method if you want to handle behavior.
136         /// </summary>
137         /// <since_tizen> 3 </since_tizen>
138         protected virtual void OnResume()
139         {
140             Resumed?.Invoke(this, EventArgs.Empty);
141         }
142
143         /// <summary>
144         /// Overrides this method if you want to handle behavior.
145         /// </summary>
146         /// <since_tizen> 3 </since_tizen>
147         protected virtual void OnPreCreate()
148         {
149         }
150
151         /// <summary>
152         /// Overrides this method if you want to handle behavior.
153         /// </summary>
154         /// <since_tizen> 3 </since_tizen>
155         protected override void OnAppControlReceived(AppControlReceivedEventArgs e)
156         {
157             if (e != null)
158             {
159                 Log.Info("NUI", "OnAppControlReceived() is called! ApplicationId=" + e.ReceivedAppControl.ApplicationId);
160                 Log.Info("NUI", "CallerApplicationId=" + e.ReceivedAppControl.CallerApplicationId + "   IsReplyRequest=" + e.ReceivedAppControl.IsReplyRequest);
161             }
162             base.OnAppControlReceived(e);
163         }
164
165         /// <summary>
166         /// Overrides this method if you want to handle behavior.
167         /// </summary>
168         /// <since_tizen> 3 </since_tizen>
169         protected override void OnCreate()
170         {
171             // This is also required to create DisposeQueue on main thread.
172             DisposeQueue disposeQ = DisposeQueue.Instance;
173             disposeQ.Initialize();
174             base.OnCreate();
175         }
176
177         /// <summary>
178         /// Runs the NUIApplication.
179         /// </summary>
180         /// <param name="args">Arguments from commandline.</param>
181         /// <since_tizen> 4 </since_tizen>
182         public override void Run(string[] args)
183         {
184             Backend.AddEventHandler(EventType.PreCreated, OnPreCreate);
185             Backend.AddEventHandler(EventType.Resumed, OnResume);
186             Backend.AddEventHandler(EventType.Paused, OnPause);
187             base.Run(args);
188         }
189
190         /// <summary>
191         /// Exits the NUIApplication.
192         /// </summary>
193         /// <since_tizen> 4 </since_tizen>
194         public override void Exit()
195         {
196             base.Exit();
197         }
198
199         /// <summary>
200         /// Ensures that the function passed in is called from the main loop when it is idle.
201         /// </summary>
202         /// <param name="func">The function to call</param>
203         /// <returns>true if added successfully, false otherwise</returns>
204         /// <since_tizen> 4 </since_tizen>
205         public bool AddIdle(System.Delegate func)
206         {
207             return ((NUICoreBackend)this.Backend).AddIdle(func);
208         }
209
210         /// <summary>
211         /// Enumeration for deciding whether a NUI application window is opaque or transparent.
212         /// </summary>
213         /// <since_tizen> 3 </since_tizen>
214         public enum WindowMode
215         {
216             /// <summary>
217             /// Opaque
218             /// </summary>
219             /// <since_tizen> 3 </since_tizen>
220             Opaque = 0,
221             /// <summary>
222             /// Transparent
223             /// </summary>
224             /// <since_tizen> 3 </since_tizen>
225             Transparent = 1
226         }
227
228
229         internal Application ApplicationHandle
230         {
231             get
232             {
233                 return ((NUICoreBackend)this.Backend).ApplicationHandle;
234             }
235         }
236
237         /// <summary>
238         /// ResourceManager to handle multilingual.
239         /// </summary>
240         /// <since_tizen> 4 </since_tizen>
241         public static System.Resources.ResourceManager MultilingualResourceManager
242         {
243             get
244             {
245                 return resourceManager;
246             }
247             set
248             {
249                 resourceManager = value;
250             }
251         }
252
253         /// <summary>
254         /// Gets the window instance.
255         /// </summary>
256         /// <since_tizen> 3 </since_tizen>
257         [Obsolete("Please do not use! This will be deprecated!")]
258         [EditorBrowsable(EditorBrowsableState.Never)]
259         public Window Window
260         {
261             get
262             {
263                 return Window.Instance;
264             }
265         }
266     }
267 }