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