2 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
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;
31 /// Represents an application that have a UI screen. The NUIApplication class has a default stage.
33 /// <since_tizen> 3 </since_tizen>
34 public class NUIApplication : CoreApplication
37 /// The instance of ResourceManager.
39 private static System.Resources.ResourceManager resourceManager = null;
40 private Size2D _windowSize2D = null;
41 private Position2D _windowPosition2D = null;
42 private TransitionOptions transitionOptions;
46 /// The default constructor.
48 /// <since_tizen> 3 </since_tizen>
49 public NUIApplication() : base(new NUICoreBackend())
51 Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
55 /// The constructor with window size and position.
57 /// <param name="windowSize">The window size.</param>
58 /// <param name="windowPosition">The window position.</param>
59 /// <since_tizen> 5 </since_tizen>
60 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
61 [EditorBrowsable(EditorBrowsableState.Never)]
62 public NUIApplication(Size2D windowSize, Position2D windowPosition) : base(new NUICoreBackend("", WindowMode.Opaque, windowSize, windowPosition))
64 Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
65 _windowSize2D = windowSize;
66 _windowPosition2D = windowPosition;
70 /// The constructor with a stylesheet.
72 /// <param name="styleSheet">The styleSheet url.</param>
73 /// <since_tizen> 3 </since_tizen>
74 public NUIApplication(string styleSheet) : base(new NUICoreBackend(styleSheet))
76 Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
80 /// The constructor with a stylesheet, window size, and position.
82 /// <param name="styleSheet">The styleSheet URL.</param>
83 /// <param name="windowSize">The window size.</param>
84 /// <param name="windowPosition">The window position.</param>
85 /// <since_tizen> 5 </since_tizen>
86 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
87 [EditorBrowsable(EditorBrowsableState.Never)]
88 public NUIApplication(string styleSheet, Size2D windowSize, Position2D windowPosition) : base(new NUICoreBackend(styleSheet, WindowMode.Opaque, windowSize, windowPosition))
90 Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
91 _windowSize2D = windowSize;
92 _windowPosition2D = windowPosition;
96 /// The constructor with a stylesheet and window mode.
98 /// <param name="styleSheet">The styleSheet url.</param>
99 /// <param name="windowMode">The windowMode.</param>
100 /// <since_tizen> 3 </since_tizen>
101 public NUIApplication(string styleSheet, WindowMode windowMode) : base(new NUICoreBackend(styleSheet, windowMode))
103 Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
107 /// The constructor with a stylesheet, window mode, window size, and position.
109 /// <param name="styleSheet">The styleSheet URL.</param>
110 /// <param name="windowMode">The windowMode.</param>
111 /// <param name="windowSize">The window size.</param>
112 /// <param name="windowPosition">The window position.</param>
113 /// <since_tizen> 5 </since_tizen>
114 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
115 [EditorBrowsable(EditorBrowsableState.Never)]
116 public NUIApplication(string styleSheet, WindowMode windowMode, Size2D windowSize, Position2D windowPosition) : base(new NUICoreBackend(styleSheet, windowMode, windowSize, windowPosition))
118 Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
119 _windowSize2D = windowSize;
120 _windowPosition2D = windowPosition;
124 /// Internal inhouse constructor with Graphics Backend Type
126 /// <param name="backend"></param>
127 /// <param name="windowMode"></param>
128 /// <param name="windowSize"></param>
129 /// <param name="windowPosition"></param>
130 /// <param name="styleSheet"></param>
131 /// InhouseAPI, this could be opend in NextTizen
132 [Obsolete("Please do not use! This will be deprecated!")]
133 [EditorBrowsable(EditorBrowsableState.Never)]
134 public NUIApplication(Graphics.BackendType backend, WindowMode windowMode = WindowMode.Opaque, Size2D windowSize = null, Position2D windowPosition = null, string styleSheet = "") : base(new NUICoreBackend(styleSheet, windowMode, windowSize, windowPosition))
136 //windowMode and styleSheet will be added later. currenlty it's not working as expected.
137 Graphics.Backend = backend;
138 Tizen.Log.Error("NUI", "Plaese DO NOT set graphical backend type with this constructor! This will give no effect!");
140 if (windowSize != null) { _windowSize2D = windowSize; }
141 if (windowPosition != null) { _windowPosition2D = windowPosition; }
142 Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
146 /// Occurs whenever the application is resumed.
148 /// <since_tizen> 4 </since_tizen>
149 public event EventHandler Resumed;
152 /// Occurs whenever the application is paused.
154 /// <since_tizen> 4 </since_tizen>
155 public event EventHandler Paused;
158 /// Enumeration for deciding whether a NUI application window is opaque or transparent.
160 /// <since_tizen> 3 </since_tizen>
161 public enum WindowMode
166 /// <since_tizen> 3 </since_tizen>
171 /// <since_tizen> 3 </since_tizen>
176 /// ResourceManager to handle multilingual.
178 /// <since_tizen> 4 </since_tizen>
179 public static System.Resources.ResourceManager MultilingualResourceManager
183 return resourceManager;
187 resourceManager = value;
192 /// Gets the window instance.
194 /// <since_tizen> 3 </since_tizen>
195 [Obsolete("Please do not use! This will be deprecated!")]
196 [EditorBrowsable(EditorBrowsableState.Never)]
201 return GetDefaultWindow();
206 /// Gets the default window.
208 /// <returns>The default Window.</returns>
209 /// <since_tizen> 6 </since_tizen>
210 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
211 [EditorBrowsable(EditorBrowsableState.Never)]
212 public static Window GetDefaultWindow()
214 return Window.Instance;
217 internal Application ApplicationHandle
221 return ((NUICoreBackend)this.Backend).ApplicationHandle;
226 /// Register the assembly to XAML.
228 /// <since_tizen> 5 </since_tizen>
229 public static void RegisterAssembly(Assembly assembly)
231 XamlParser.s_assemblies.Add(assembly);
235 /// Runs the NUIApplication.
237 /// <param name="args">Arguments from commandline.</param>
238 /// <since_tizen> 4 </since_tizen>
239 public override void Run(string[] args)
241 Backend.AddEventHandler(EventType.PreCreated, OnPreCreate);
242 Backend.AddEventHandler(EventType.Resumed, OnResume);
243 Backend.AddEventHandler(EventType.Paused, OnPause);
248 /// Exits the NUIApplication.
250 /// <since_tizen> 4 </since_tizen>
251 public override void Exit()
257 /// Ensures that the function passed in is called from the main loop when it is idle.
259 /// <param name="func">The function to call</param>
260 /// <returns>true if added successfully, false otherwise</returns>
261 /// <since_tizen> 4 </since_tizen>
262 public bool AddIdle(System.Delegate func)
264 return ((NUICoreBackend)this.Backend).AddIdle(func);
268 /// Sets the number of frames per render.
270 /// <param name="numberOfVSyncsPerRender">The number of vsyncs between successive renders.</param>
272 /// Suggest this is a power of two:
273 /// 1 - render each vsync frame.
274 /// 2 - render every other vsync frame.
275 /// 4 - render every fourth vsync frame.
276 /// 8 - render every eighth vsync frame. <br />
277 /// For example, if an application runs on 60 FPS and SetRenderRefreshRate(2) is called, the frames per second will be changed to 30.
279 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
280 [EditorBrowsable(EditorBrowsableState.Never)]
281 public static void SetRenderRefreshRate(uint numberOfVSyncsPerRender)
283 Adaptor.Instance.SetRenderRefreshRate(numberOfVSyncsPerRender);
287 /// Overrides this method if you want to handle behavior.
289 /// <since_tizen> 3 </since_tizen>
290 protected override void OnLocaleChanged(LocaleChangedEventArgs e)
292 base.OnLocaleChanged(e);
296 /// Overrides this method if you want to handle behavior.
298 /// <since_tizen> 3 </since_tizen>
299 protected override void OnLowBattery(LowBatteryEventArgs e)
301 base.OnLowBattery(e);
305 /// Overrides this method if you want to handle behavior.
307 /// <since_tizen> 3 </since_tizen>
308 protected override void OnLowMemory(LowMemoryEventArgs e)
314 /// Overrides this method if you want to handle behavior.
316 /// <since_tizen> 3 </since_tizen>
317 protected override void OnRegionFormatChanged(RegionFormatChangedEventArgs e)
319 base.OnRegionFormatChanged(e);
323 /// Overrides this method if you want to handle behavior.
325 /// <since_tizen> 3 </since_tizen>
326 protected override void OnTerminate()
332 /// Overrides this method if you want to handle behavior.
334 /// <since_tizen> 3 </since_tizen>
335 protected virtual void OnPause()
337 Paused?.Invoke(this, EventArgs.Empty);
341 /// Overrides this method if you want to handle behavior.
343 /// <since_tizen> 3 </since_tizen>
344 protected virtual void OnResume()
346 Resumed?.Invoke(this, EventArgs.Empty);
350 /// Overrides this method if you want to handle behavior.
352 /// <since_tizen> 3 </since_tizen>
353 protected virtual void OnPreCreate()
358 /// Overrides this method if you want to handle behavior.
360 /// <since_tizen> 3 </since_tizen>
361 protected override void OnAppControlReceived(AppControlReceivedEventArgs e)
365 Log.Info("NUI", "OnAppControlReceived() is called! ApplicationId=" + e.ReceivedAppControl.ApplicationId);
366 Log.Info("NUI", "CallerApplicationId=" + e.ReceivedAppControl.CallerApplicationId + " IsReplyRequest=" + e.ReceivedAppControl.IsReplyRequest);
368 base.OnAppControlReceived(e);
372 /// Overrides this method if you want to handle behavior.
374 /// <since_tizen> 3 </since_tizen>
375 protected override void OnCreate()
381 /// This is used to improve application launch performance.
383 [EditorBrowsable(EditorBrowsableState.Never)]
384 static public void PreLoad()
386 Interop.Application.Application_PreInitialize();
390 /// This is used to improve application launch performance.
392 [EditorBrowsable(EditorBrowsableState.Never)]
393 public void SendLaunchRequest(AppControl appControl)
395 transitionOptions.SendLaunchRequest(appControl);
399 /// This is used to improve application launch performance.
401 [EditorBrowsable(EditorBrowsableState.Never)]
402 public TransitionOptions TransitionOptions
406 return transitionOptions;
410 transitionOptions = value;
416 /// Graphics Backend Type.
418 [EditorBrowsable(EditorBrowsableState.Never)]
419 [Obsolete("Please do not use! This will be deprecated!")]
420 public class Graphics
423 /// Graphics Backend Type.
425 public enum BackendType
428 /// The GLES backend.
432 /// The Vulkan backend.
438 /// The backend used by the NUIApplication.
440 [EditorBrowsable(EditorBrowsableState.Never)]
441 public static BackendType Backend = BackendType.Gles;
443 internal const string GlesCSharpBinder = NDalicPINVOKE.Lib;
444 internal const string VulkanCSharpBinder = "libdali-csharp-binder-vk.so";