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