Release 4.0.0-preview1-00051
[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             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         /// Exit NUIApplication.
178         /// </summary>
179         public override void Exit()
180         {
181             base.Exit();
182         }
183
184         /// <summary>
185         /// Enumeration for deciding whether a NUI application window is opaque or transparent.
186         /// </summary>
187         public enum WindowMode
188         {
189             Opaque = 0,
190             Transparent = 1
191         }
192
193
194         internal Application ApplicationHandle
195         {
196             get
197             {
198                 return ((NUICoreBackend)this.Backend).ApplicationHandle;
199             }
200         }
201
202         /// <summary>
203         /// ResourceManager to handle multilingual
204         /// </summary>
205         public static System.Resources.ResourceManager MultilingualResourceManager
206         {
207             get
208             {
209                 return resourceManager;
210             }
211             set
212             {
213                 resourceManager = value;
214             }
215         }
216
217         /// <summary>
218         /// Get the window instance.
219         /// </summary>
220         [Obsolete("Please do not use! this will be deprecated")]
221         public Window Window
222         {
223             get
224             {
225                 return Window.Instance;
226             }
227         }
228     }
229 }