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.Diagnostics.CodeAnalysis;
21 using System.Threading;
22 using System.Reflection;
23 using Tizen.Applications;
24 using Tizen.Applications.CoreBackend;
25 using Tizen.NUI.Binding;
32 /// Represents an application that have a UI screen. The NUIApplication class has a default stage.
34 /// <since_tizen> 3 </since_tizen>
35 public class NUIApplication : CoreApplication
38 /// The instance of ResourceManager.
40 private static System.Resources.ResourceManager resourceManager = null;
41 private Size2D _windowSize2D = null;
42 private Position2D _windowPosition2D = null;
43 private TransitionOptions transitionOptions;
45 private static bool isPreLoad = false;
48 /// The default constructor.
50 /// <since_tizen> 3 </since_tizen>
51 public NUIApplication() : base(new NUICoreBackend())
53 Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
57 /// The constructor with window size and position.
59 /// <param name="windowSize">The window size.</param>
60 /// <param name="windowPosition">The window position.</param>
61 /// <since_tizen> 5 </since_tizen>
62 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
63 [EditorBrowsable(EditorBrowsableState.Never)]
64 public NUIApplication(Size2D windowSize, Position2D windowPosition) : base(new NUICoreBackend("", WindowMode.Opaque, windowSize, windowPosition))
66 Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
67 _windowSize2D = windowSize;
68 _windowPosition2D = windowPosition;
72 /// The constructor with a stylesheet.
74 /// <param name="styleSheet">The styleSheet url.</param>
75 /// <since_tizen> 3 </since_tizen>
76 public NUIApplication(string styleSheet) : base(new NUICoreBackend(styleSheet))
78 Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
82 /// The constructor with a stylesheet, window size, and position.
84 /// <param name="styleSheet">The styleSheet URL.</param>
85 /// <param name="windowSize">The window size.</param>
86 /// <param name="windowPosition">The window position.</param>
87 /// <since_tizen> 5 </since_tizen>
88 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
89 [EditorBrowsable(EditorBrowsableState.Never)]
90 public NUIApplication(string styleSheet, Size2D windowSize, Position2D windowPosition) : base(new NUICoreBackend(styleSheet, WindowMode.Opaque, windowSize, windowPosition))
92 Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
93 _windowSize2D = windowSize;
94 _windowPosition2D = windowPosition;
98 /// The constructor with a stylesheet and window mode.
100 /// <param name="styleSheet">The styleSheet url.</param>
101 /// <param name="windowMode">The windowMode.</param>
102 /// <since_tizen> 3 </since_tizen>
103 public NUIApplication(string styleSheet, WindowMode windowMode) : base(new NUICoreBackend(styleSheet, windowMode))
105 Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
109 /// The constructor with a stylesheet, window mode, window size, and position.
111 /// <param name="styleSheet">The styleSheet URL.</param>
112 /// <param name="windowMode">The windowMode.</param>
113 /// <param name="windowSize">The window size.</param>
114 /// <param name="windowPosition">The window position.</param>
115 /// <since_tizen> 5 </since_tizen>
116 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
117 [EditorBrowsable(EditorBrowsableState.Never)]
118 public NUIApplication(string styleSheet, WindowMode windowMode, Size2D windowSize, Position2D windowPosition) : base(new NUICoreBackend(styleSheet, windowMode, windowSize, windowPosition))
120 Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
121 _windowSize2D = windowSize;
122 _windowPosition2D = windowPosition;
126 /// Internal inhouse constructor with Graphics Backend Type
128 /// <param name="backend"></param>
129 /// <param name="windowMode"></param>
130 /// <param name="windowSize"></param>
131 /// <param name="windowPosition"></param>
132 /// <param name="styleSheet"></param>
133 /// InhouseAPI, this could be opend in NextTizen
134 [Obsolete("Please do not use! This will be deprecated!")]
135 [EditorBrowsable(EditorBrowsableState.Never)]
136 public NUIApplication(Graphics.BackendType backend, WindowMode windowMode = WindowMode.Opaque, Size2D windowSize = null, Position2D windowPosition = null, string styleSheet = "") : base(new NUICoreBackend(styleSheet, windowMode, windowSize, windowPosition))
138 //windowMode and styleSheet will be added later. currenlty it's not working as expected.
139 Graphics.Backend = backend;
140 Tizen.Log.Error("NUI", "Plaese DO NOT set graphical backend type with this constructor! This will give no effect!");
142 if (windowSize != null) { _windowSize2D = windowSize; }
143 if (windowPosition != null) { _windowPosition2D = windowPosition; }
144 Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
148 /// Occurs whenever the application is resumed.
150 /// <since_tizen> 4 </since_tizen>
151 public event EventHandler Resumed;
154 /// Occurs whenever the application is paused.
156 /// <since_tizen> 4 </since_tizen>
157 public event EventHandler Paused;
160 /// Enumeration for deciding whether a NUI application window is opaque or transparent.
162 /// <since_tizen> 3 </since_tizen>
163 public enum WindowMode
168 /// <since_tizen> 3 </since_tizen>
173 /// <since_tizen> 3 </since_tizen>
178 /// ResourceManager to handle multilingual.
180 /// <since_tizen> 4 </since_tizen>
181 public static System.Resources.ResourceManager MultilingualResourceManager
185 return resourceManager;
189 resourceManager = value;
194 /// Gets the window instance.
196 /// <since_tizen> 3 </since_tizen>
197 [Obsolete("Please do not use! This will be deprecated!")]
198 [EditorBrowsable(EditorBrowsableState.Never)]
203 return GetDefaultWindow();
208 /// Gets the default window.
210 /// <returns>The default Window.</returns>
211 /// <since_tizen> 6 </since_tizen>
212 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
213 [EditorBrowsable(EditorBrowsableState.Never)]
214 public static Window GetDefaultWindow()
216 return Window.Instance;
219 internal Application ApplicationHandle
223 return ((NUICoreBackend)this.Backend).ApplicationHandle;
228 /// Register the assembly to XAML.
230 /// <since_tizen> 5 </since_tizen>
231 public static void RegisterAssembly(Assembly assembly)
233 XamlParser.s_assemblies.Add(assembly);
237 /// Runs the NUIApplication.
239 /// <param name="args">Arguments from commandline.</param>
240 /// <since_tizen> 4 </since_tizen>
241 public override void Run(string[] args)
243 Backend.AddEventHandler(EventType.PreCreated, OnPreCreate);
244 Backend.AddEventHandler(EventType.Resumed, OnResume);
245 Backend.AddEventHandler(EventType.Paused, OnPause);
250 /// Exits the NUIApplication.
252 /// <since_tizen> 4 </since_tizen>
253 public override void Exit()
259 /// Ensures that the function passed in is called from the main loop when it is idle.
261 /// <param name="func">The function to call</param>
262 /// <returns>true if added successfully, false otherwise</returns>
263 /// <since_tizen> 4 </since_tizen>
264 public bool AddIdle(System.Delegate func)
266 return ((NUICoreBackend)this.Backend).AddIdle(func);
270 /// Sets the number of frames per render.
272 /// <param name="numberOfVSyncsPerRender">The number of vsyncs between successive renders.</param>
274 /// Suggest this is a power of two:
275 /// 1 - render each vsync frame.
276 /// 2 - render every other vsync frame.
277 /// 4 - render every fourth vsync frame.
278 /// 8 - render every eighth vsync frame. <br />
279 /// For example, if an application runs on 60 FPS and SetRenderRefreshRate(2) is called, the frames per second will be changed to 30.
281 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
282 [EditorBrowsable(EditorBrowsableState.Never)]
283 public static void SetRenderRefreshRate(uint numberOfVSyncsPerRender)
285 Adaptor.Instance.SetRenderRefreshRate(numberOfVSyncsPerRender);
289 /// Overrides this method if you want to handle behavior.
291 /// <since_tizen> 3 </since_tizen>
292 protected override void OnLocaleChanged(LocaleChangedEventArgs e)
294 base.OnLocaleChanged(e);
298 /// Overrides this method if you want to handle behavior.
300 /// <since_tizen> 3 </since_tizen>
301 protected override void OnLowBattery(LowBatteryEventArgs e)
303 base.OnLowBattery(e);
307 /// Overrides this method if you want to handle behavior.
309 /// <since_tizen> 3 </since_tizen>
310 protected override void OnLowMemory(LowMemoryEventArgs e)
316 /// Overrides this method if you want to handle behavior.
318 /// <since_tizen> 3 </since_tizen>
319 protected override void OnRegionFormatChanged(RegionFormatChangedEventArgs e)
321 base.OnRegionFormatChanged(e);
325 /// Overrides this method if you want to handle behavior.
327 /// <since_tizen> 3 </since_tizen>
328 protected override void OnTerminate()
334 /// Overrides this method if you want to handle behavior.
336 /// <since_tizen> 3 </since_tizen>
337 protected virtual void OnPause()
339 Paused?.Invoke(this, EventArgs.Empty);
343 /// Overrides this method if you want to handle behavior.
345 /// <since_tizen> 3 </since_tizen>
346 protected virtual void OnResume()
348 Resumed?.Invoke(this, EventArgs.Empty);
352 /// Overrides this method if you want to handle behavior.
354 /// <since_tizen> 3 </since_tizen>
355 protected virtual void OnPreCreate()
360 /// Overrides this method if you want to handle behavior.
362 /// <since_tizen> 3 </since_tizen>
363 protected override void OnAppControlReceived(AppControlReceivedEventArgs e)
367 Log.Info("NUI", "OnAppControlReceived() is called! ApplicationId=" + e.ReceivedAppControl.ApplicationId);
368 Log.Info("NUI", "CallerApplicationId=" + e.ReceivedAppControl.CallerApplicationId + " IsReplyRequest=" + e.ReceivedAppControl.IsReplyRequest);
370 base.OnAppControlReceived(e);
374 /// Overrides this method if you want to handle behavior.
376 /// <since_tizen> 3 </since_tizen>
377 protected override void OnCreate()
383 /// This is used to improve application launch performance.
385 [EditorBrowsable(EditorBrowsableState.Never)]
386 static public void PreLoad()
388 Interop.Application.PreInitialize();
393 /// This is used to improve application launch performance.
395 [EditorBrowsable(EditorBrowsableState.Never)]
396 public void SendLaunchRequest(AppControl appControl)
398 transitionOptions.SendLaunchRequest(appControl);
402 /// This is used to improve application launch performance.
404 [EditorBrowsable(EditorBrowsableState.Never)]
405 public TransitionOptions TransitionOptions
409 return transitionOptions;
413 transitionOptions = value;
418 /// Check if it is loaded as dotnet-loader-nui.
420 static internal bool IsPreLoad
430 /// Graphics Backend Type.
432 [SuppressMessage("Microsoft.Design", "CA1052:StaticHolderTypesShouldBeStaticOrNotInheritable")]
433 [EditorBrowsable(EditorBrowsableState.Never)]
434 [Obsolete("Please do not use! This will be deprecated!")]
435 public class Graphics
438 /// Graphics Backend Type.
440 public enum BackendType
443 /// The GLES backend.
447 /// The Vulkan backend.
453 /// The backend used by the NUIApplication.
455 [EditorBrowsable(EditorBrowsableState.Never)]
456 internal static BackendType Backend = BackendType.Gles;
458 internal const string GlesCSharpBinder = NDalicPINVOKE.Lib;
459 internal const string VulkanCSharpBinder = "libdali-csharp-binder-vk.so";