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