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;
44 private string appId = null;
45 internal static NUIApplication me;
47 private static bool isPreLoad = false;
50 /// The default constructor.
52 /// <since_tizen> 3 </since_tizen>
53 public NUIApplication() : base(new NUICoreBackend())
55 Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
60 /// The constructor with window size and position.
62 /// <param name="windowSize">The window size.</param>
63 /// <param name="windowPosition">The window position.</param>
64 /// <since_tizen> 5 </since_tizen>
65 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
66 [EditorBrowsable(EditorBrowsableState.Never)]
67 public NUIApplication(Size2D windowSize, Position2D windowPosition) : base(new NUICoreBackend("", WindowMode.Opaque, windowSize, windowPosition))
69 Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
70 _windowSize2D = windowSize;
71 _windowPosition2D = windowPosition;
76 /// The constructor with a stylesheet.
78 /// <param name="styleSheet">The styleSheet url.</param>
79 /// <since_tizen> 3 </since_tizen>
80 public NUIApplication(string styleSheet) : base(new NUICoreBackend(styleSheet))
82 Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
87 /// The constructor with a stylesheet, window size, and position.
89 /// <param name="styleSheet">The styleSheet URL.</param>
90 /// <param name="windowSize">The window size.</param>
91 /// <param name="windowPosition">The window position.</param>
92 /// <since_tizen> 5 </since_tizen>
93 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
94 [EditorBrowsable(EditorBrowsableState.Never)]
95 public NUIApplication(string styleSheet, Size2D windowSize, Position2D windowPosition) : base(new NUICoreBackend(styleSheet, WindowMode.Opaque, windowSize, windowPosition))
97 Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
98 _windowSize2D = windowSize;
99 _windowPosition2D = windowPosition;
104 /// The constructor with a stylesheet and window mode.
106 /// <param name="styleSheet">The styleSheet url.</param>
107 /// <param name="windowMode">The windowMode.</param>
108 /// <since_tizen> 3 </since_tizen>
109 public NUIApplication(string styleSheet, WindowMode windowMode) : base(new NUICoreBackend(styleSheet, windowMode))
111 Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
116 /// The constructor with a stylesheet, window mode, window size, and position.
118 /// <param name="styleSheet">The styleSheet URL.</param>
119 /// <param name="windowMode">The windowMode.</param>
120 /// <param name="windowSize">The window size.</param>
121 /// <param name="windowPosition">The window position.</param>
122 /// <since_tizen> 5 </since_tizen>
123 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
124 [EditorBrowsable(EditorBrowsableState.Never)]
125 public NUIApplication(string styleSheet, WindowMode windowMode, Size2D windowSize, Position2D windowPosition) : base(new NUICoreBackend(styleSheet, windowMode, windowSize, windowPosition))
127 Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
128 _windowSize2D = windowSize;
129 _windowPosition2D = windowPosition;
134 /// Internal inhouse constructor with Graphics Backend Type
136 /// <param name="backend"></param>
137 /// <param name="windowMode"></param>
138 /// <param name="windowSize"></param>
139 /// <param name="windowPosition"></param>
140 /// <param name="styleSheet"></param>
141 /// InhouseAPI, this could be opend in NextTizen
142 [Obsolete("Please do not use! This will be deprecated!")]
143 [EditorBrowsable(EditorBrowsableState.Never)]
144 public NUIApplication(Graphics.BackendType backend, WindowMode windowMode = WindowMode.Opaque, Size2D windowSize = null, Position2D windowPosition = null, string styleSheet = "") : base(new NUICoreBackend(styleSheet, windowMode, windowSize, windowPosition))
146 //windowMode and styleSheet will be added later. currenlty it's not working as expected.
147 Graphics.Backend = backend;
148 Tizen.Log.Error("NUI", "Plaese DO NOT set graphical backend type with this constructor! This will give no effect!");
150 if (windowSize != null) { _windowSize2D = windowSize; }
151 if (windowPosition != null) { _windowPosition2D = windowPosition; }
152 Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
157 /// Occurs whenever the application is resumed.
159 /// <since_tizen> 4 </since_tizen>
160 public event EventHandler Resumed;
163 /// Occurs whenever the application is paused.
165 /// <since_tizen> 4 </since_tizen>
166 public event EventHandler Paused;
169 /// Enumeration for deciding whether a NUI application window is opaque or transparent.
171 /// <since_tizen> 3 </since_tizen>
172 public enum WindowMode
177 /// <since_tizen> 3 </since_tizen>
182 /// <since_tizen> 3 </since_tizen>
187 /// ResourceManager to handle multilingual.
189 /// <since_tizen> 4 </since_tizen>
190 public static System.Resources.ResourceManager MultilingualResourceManager
194 return resourceManager;
198 resourceManager = value;
203 /// Gets the window instance.
205 /// <since_tizen> 3 </since_tizen>
206 [Obsolete("Please do not use! This will be deprecated!")]
207 [EditorBrowsable(EditorBrowsableState.Never)]
212 return GetDefaultWindow();
217 /// Gets the Application Id.
219 /// <since_tizen> 6 </since_tizen>
220 [EditorBrowsable(EditorBrowsableState.Never)]
230 /// Gets the default window.
232 /// <returns>The default Window.</returns>
233 /// <since_tizen> 6 </since_tizen>
234 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
235 [EditorBrowsable(EditorBrowsableState.Never)]
236 public static Window GetDefaultWindow()
238 return Window.Instance;
241 internal Application ApplicationHandle
245 return ((NUICoreBackend)this.Backend).ApplicationHandle;
250 /// Register the assembly to XAML.
252 /// <since_tizen> 5 </since_tizen>
253 public static void RegisterAssembly(Assembly assembly)
255 XamlParser.s_assemblies.Add(assembly);
259 /// Runs the NUIApplication.
261 /// <param name="args">Arguments from commandline.</param>
262 /// <since_tizen> 4 </since_tizen>
263 public override void Run(string[] args)
265 Backend.AddEventHandler(EventType.PreCreated, OnPreCreate);
266 Backend.AddEventHandler(EventType.Resumed, OnResume);
267 Backend.AddEventHandler(EventType.Paused, OnPause);
272 /// Exits the NUIApplication.
274 /// <since_tizen> 4 </since_tizen>
275 public override void Exit()
281 /// Ensures that the function passed in is called from the main loop when it is idle.
283 /// <param name="func">The function to call</param>
284 /// <returns>true if added successfully, false otherwise</returns>
285 /// <since_tizen> 4 </since_tizen>
286 public bool AddIdle(System.Delegate func)
288 return ((NUICoreBackend)this.Backend).AddIdle(func);
292 /// Sets the number of frames per render.
294 /// <param name="numberOfVSyncsPerRender">The number of vsyncs between successive renders.</param>
296 /// Suggest this is a power of two:
297 /// 1 - render each vsync frame.
298 /// 2 - render every other vsync frame.
299 /// 4 - render every fourth vsync frame.
300 /// 8 - render every eighth vsync frame. <br />
301 /// For example, if an application runs on 60 FPS and SetRenderRefreshRate(2) is called, the frames per second will be changed to 30.
303 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
304 [EditorBrowsable(EditorBrowsableState.Never)]
305 public static void SetRenderRefreshRate(uint numberOfVSyncsPerRender)
307 Adaptor.Instance.SetRenderRefreshRate(numberOfVSyncsPerRender);
311 /// Overrides this method if you want to handle behavior.
313 /// <since_tizen> 3 </since_tizen>
314 protected override void OnLocaleChanged(LocaleChangedEventArgs e)
316 base.OnLocaleChanged(e);
320 /// Overrides this method if you want to handle behavior.
322 /// <since_tizen> 3 </since_tizen>
323 protected override void OnLowBattery(LowBatteryEventArgs e)
325 base.OnLowBattery(e);
329 /// Overrides this method if you want to handle behavior.
331 /// <since_tizen> 3 </since_tizen>
332 protected override void OnLowMemory(LowMemoryEventArgs e)
338 /// Overrides this method if you want to handle behavior.
340 /// <since_tizen> 3 </since_tizen>
341 protected override void OnRegionFormatChanged(RegionFormatChangedEventArgs e)
343 base.OnRegionFormatChanged(e);
347 /// Overrides this method if you want to handle behavior.
349 /// <since_tizen> 3 </since_tizen>
350 protected override void OnTerminate()
356 /// Overrides this method if you want to handle behavior.
358 /// <since_tizen> 3 </since_tizen>
359 protected virtual void OnPause()
361 Paused?.Invoke(this, EventArgs.Empty);
365 /// Overrides this method if you want to handle behavior.
367 /// <since_tizen> 3 </since_tizen>
368 protected virtual void OnResume()
370 Resumed?.Invoke(this, EventArgs.Empty);
374 /// Overrides this method if you want to handle behavior.
376 /// <since_tizen> 3 </since_tizen>
377 protected virtual void OnPreCreate()
382 /// Overrides this method if you want to handle behavior.
384 /// <since_tizen> 3 </since_tizen>
385 protected override void OnAppControlReceived(AppControlReceivedEventArgs e)
389 Log.Info("NUI", "OnAppControlReceived() is called! ApplicationId=" + e.ReceivedAppControl.ApplicationId);
390 Log.Info("NUI", "CallerApplicationId=" + e.ReceivedAppControl.CallerApplicationId + " IsReplyRequest=" + e.ReceivedAppControl.IsReplyRequest);
392 base.OnAppControlReceived(e);
396 /// Overrides this method if you want to handle behavior.
398 /// <since_tizen> 3 </since_tizen>
399 protected override void OnCreate()
402 appId = Tizen.Applications.Application.Current.ApplicationInfo.ApplicationId;
406 /// This is used to improve application launch performance.
408 [EditorBrowsable(EditorBrowsableState.Never)]
409 static public void PreLoad()
411 Interop.Application.PreInitialize();
416 /// This is used to improve application launch performance.
418 [EditorBrowsable(EditorBrowsableState.Never)]
419 public void SendLaunchRequest(AppControl appControl)
421 transitionOptions.SendLaunchRequest(appControl);
425 /// This is used to improve application launch performance.
427 [EditorBrowsable(EditorBrowsableState.Never)]
428 public TransitionOptions TransitionOptions
432 return transitionOptions;
436 transitionOptions = value;
441 /// Check if it is loaded as dotnet-loader-nui.
443 static internal bool IsPreLoad
453 /// Graphics Backend Type.
455 [SuppressMessage("Microsoft.Design", "CA1052:StaticHolderTypesShouldBeStaticOrNotInheritable")]
456 [EditorBrowsable(EditorBrowsableState.Never)]
457 [Obsolete("Please do not use! This will be deprecated!")]
458 public class Graphics
461 /// Graphics Backend Type.
463 public enum BackendType
466 /// The GLES backend.
470 /// The Vulkan backend.
476 /// The backend used by the NUIApplication.
478 [EditorBrowsable(EditorBrowsableState.Never)]
479 internal static BackendType Backend = BackendType.Gles;
481 internal const string GlesCSharpBinder = NDalicPINVOKE.Lib;
482 internal const string VulkanCSharpBinder = "libdali-csharp-binder-vk.so";