84c21b5647f4c690103adee23e61c92b75b7c04f
[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 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 stylesheet.
55         /// </summary>
56         public NUIApplication(string stylesheet) : base(new NUICoreBackend(stylesheet))
57         {
58         }
59
60         /// <summary>
61         /// The constructor with 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 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 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 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 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 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 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 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 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 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 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         /// Run NUIApplication.
166         /// </summary>
167         /// <param name="args">Arguments from commandline.</param>
168         public override void Run(string[] args)
169         {
170             string[] argsClone = null;
171
172             if (args == null)
173             {
174                 argsClone = new string[1];
175             }
176             else
177             {
178                 argsClone = new string[args.Length + 1];
179                 args.CopyTo(argsClone, 1);
180             }
181             argsClone[0] = string.Empty;
182
183             Backend.AddEventHandler(EventType.PreCreated, OnPreCreate);
184             Backend.AddEventHandler(EventType.Created, OnCreate);
185             Backend.AddEventHandler<AppControlReceivedEventArgs>(EventType.AppControlReceived, OnAppControlReceived);
186             Backend.AddEventHandler(EventType.Resumed, OnResume);
187             Backend.AddEventHandler(EventType.Paused, OnPause);
188             Backend.AddEventHandler(EventType.Terminated, OnTerminate);
189             Backend.AddEventHandler<RegionFormatChangedEventArgs>(EventType.RegionFormatChanged, OnRegionFormatChanged);
190             Backend.AddEventHandler<LowMemoryEventArgs>(EventType.LowMemory, OnLowMemory);
191             Backend.AddEventHandler<LowBatteryEventArgs>(EventType.LowBattery, OnLowBattery);
192             Backend.AddEventHandler<LocaleChangedEventArgs>(EventType.LocaleChanged, OnLocaleChanged);
193
194             Backend.Run(argsClone);
195         }
196
197         /// <summary>
198         /// Exit NUIApplication.
199         /// </summary>
200         public override void Exit()
201         {
202             Backend.Exit();
203         }
204
205         /// <summary>
206         /// Enumeration for deciding whether a NUI application window is opaque or transparent.
207         /// </summary>
208         public enum WindowMode
209         {
210             Opaque = 0,
211             Transparent = 1
212         }
213
214
215         internal Application ApplicationHandle
216         {
217             get
218             {
219                 return ((NUICoreBackend)this.Backend).ApplicationHandle;
220             }
221         }
222
223         /// <summary>
224         /// ResourceManager to handle multilingual
225         /// </summary>
226         public static System.Resources.ResourceManager MultilingualResourceManager
227         {
228             get
229             {
230                 return resourceManager;
231             }
232             set
233             {
234                 resourceManager = value;
235             }
236         }
237
238         /// <summary>
239         /// Get the window instance.
240         /// </summary>
241         [Obsolete("Please do not use! this will be deprecated")]
242         public Window Window
243         {
244             get
245             {
246                 return Window.Instance;
247             }
248         }
249     }
250 }