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