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;
44 /// The default constructor.
46 /// <since_tizen> 3 </since_tizen>
47 public NUIApplication() : base(new NUICoreBackend())
49 Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
53 /// The constructor with window size and position.
55 /// <param name="windowSize">The window size.</param>
56 /// <param name="windowPosition">The window position.</param>
57 /// <since_tizen> 5 </since_tizen>
58 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
59 [EditorBrowsable(EditorBrowsableState.Never)]
60 public NUIApplication(Size2D windowSize, Position2D windowPosition) : base(new NUICoreBackend())
62 Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
63 _windowSize2D = windowSize;
64 _windowPosition2D = windowPosition;
68 /// The constructor with a stylesheet.
70 /// <param name="styleSheet">The styleSheet url.</param>
71 /// <since_tizen> 3 </since_tizen>
72 public NUIApplication(string styleSheet) : base(new NUICoreBackend(styleSheet))
74 Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
78 /// The constructor with a stylesheet, window size, and position.
80 /// <param name="styleSheet">The styleSheet URL.</param>
81 /// <param name="windowSize">The window size.</param>
82 /// <param name="windowPosition">The window position.</param>
83 /// <since_tizen> 5 </since_tizen>
84 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
85 [EditorBrowsable(EditorBrowsableState.Never)]
86 public NUIApplication(string styleSheet, Size2D windowSize, Position2D windowPosition) : base(new NUICoreBackend(styleSheet))
88 Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
89 _windowSize2D = windowSize;
90 _windowPosition2D = windowPosition;
94 /// The constructor with a stylesheet and window mode.
96 /// <param name="styleSheet">The styleSheet url.</param>
97 /// <param name="windowMode">The windowMode.</param>
98 /// <since_tizen> 3 </since_tizen>
99 public NUIApplication(string styleSheet, WindowMode windowMode) : base(new NUICoreBackend(styleSheet, windowMode))
101 Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
105 /// The constructor with a stylesheet, window mode, window size, and position.
107 /// <param name="styleSheet">The styleSheet URL.</param>
108 /// <param name="windowMode">The windowMode.</param>
109 /// <param name="windowSize">The window size.</param>
110 /// <param name="windowPosition">The window position.</param>
111 /// <since_tizen> 5 </since_tizen>
112 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
113 [EditorBrowsable(EditorBrowsableState.Never)]
114 public NUIApplication(string styleSheet, WindowMode windowMode, Size2D windowSize, Position2D windowPosition) : base(new NUICoreBackend(styleSheet, windowMode))
116 Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
117 _windowSize2D = windowSize;
118 _windowPosition2D = windowPosition;
122 /// Internal inhouse constructor with Graphics Backend Type
124 /// <param name="backend"></param>
125 /// <param name="windowMode"></param>
126 /// <param name="windowSize"></param>
127 /// <param name="windowPosition"></param>
128 /// <param name="styleSheet"></param>
129 /// InhouseAPI, this could be opend in NextTizen
130 [Obsolete("Please do not use! This will be deprecated!")]
131 [EditorBrowsable(EditorBrowsableState.Never)]
132 public NUIApplication(Graphics.BackendType backend, WindowMode windowMode = WindowMode.Opaque, Size2D windowSize = null, Position2D windowPosition = null, string styleSheet = "") : base(new NUICoreBackend(styleSheet, windowMode))
134 //windowMode and styleSheet will be added later. currenlty it's not working as expected.
135 Graphics.Backend = backend;
136 Tizen.Log.Error("NUI", "Plaese DO NOT set graphical backend type with this constructor! This will give no effect!");
138 if (windowSize != null) { _windowSize2D = windowSize; }
139 if (windowPosition != null) { _windowPosition2D = windowPosition; }
140 Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
144 /// Occurs whenever the application is resumed.
146 /// <since_tizen> 4 </since_tizen>
147 public event EventHandler Resumed;
150 /// Occurs whenever the application is paused.
152 /// <since_tizen> 4 </since_tizen>
153 public event EventHandler Paused;
156 /// Enumeration for deciding whether a NUI application window is opaque or transparent.
158 /// <since_tizen> 3 </since_tizen>
159 public enum WindowMode
164 /// <since_tizen> 3 </since_tizen>
169 /// <since_tizen> 3 </since_tizen>
174 /// ResourceManager to handle multilingual.
176 /// <since_tizen> 4 </since_tizen>
177 public static System.Resources.ResourceManager MultilingualResourceManager
181 return resourceManager;
185 resourceManager = value;
190 /// Gets the window instance.
192 /// <since_tizen> 3 </since_tizen>
193 [Obsolete("Please do not use! This will be deprecated!")]
194 [EditorBrowsable(EditorBrowsableState.Never)]
199 return Window.Instance;
204 /// Gets the default window.
206 /// <returns>The default Window.</returns>
207 /// <since_tizen> 6 </since_tizen>
208 /// This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
209 [EditorBrowsable(EditorBrowsableState.Never)]
210 public static Window GetDefaultWindow()
212 return Window.Instance;
215 internal Application ApplicationHandle
219 return ((NUICoreBackend)this.Backend).ApplicationHandle;
224 /// Register the assembly to XAML.
226 /// <since_tizen> 5 </since_tizen>
227 public static void RegisterAssembly(Assembly assembly)
229 XamlParser.s_assemblies.Add(assembly);
233 /// Runs the NUIApplication.
235 /// <param name="args">Arguments from commandline.</param>
236 /// <since_tizen> 4 </since_tizen>
237 public override void Run(string[] args)
239 Backend.AddEventHandler(EventType.PreCreated, OnPreCreate);
240 Backend.AddEventHandler(EventType.Resumed, OnResume);
241 Backend.AddEventHandler(EventType.Paused, OnPause);
246 /// Exits the NUIApplication.
248 /// <since_tizen> 4 </since_tizen>
249 public override void Exit()
255 /// Ensures that the function passed in is called from the main loop when it is idle.
257 /// <param name="func">The function to call</param>
258 /// <returns>true if added successfully, false otherwise</returns>
259 /// <since_tizen> 4 </since_tizen>
260 public bool AddIdle(System.Delegate func)
262 return ((NUICoreBackend)this.Backend).AddIdle(func);
266 /// Overrides this method if you want to handle behavior.
268 /// <since_tizen> 3 </since_tizen>
269 protected override void OnLocaleChanged(LocaleChangedEventArgs e)
271 base.OnLocaleChanged(e);
275 /// Overrides this method if you want to handle behavior.
277 /// <since_tizen> 3 </since_tizen>
278 protected override void OnLowBattery(LowBatteryEventArgs e)
280 base.OnLowBattery(e);
284 /// Overrides this method if you want to handle behavior.
286 /// <since_tizen> 3 </since_tizen>
287 protected override void OnLowMemory(LowMemoryEventArgs e)
293 /// Overrides this method if you want to handle behavior.
295 /// <since_tizen> 3 </since_tizen>
296 protected override void OnRegionFormatChanged(RegionFormatChangedEventArgs e)
298 base.OnRegionFormatChanged(e);
302 /// Overrides this method if you want to handle behavior.
304 /// <since_tizen> 3 </since_tizen>
305 protected override void OnTerminate()
311 /// Overrides this method if you want to handle behavior.
313 /// <since_tizen> 3 </since_tizen>
314 protected virtual void OnPause()
316 Paused?.Invoke(this, EventArgs.Empty);
320 /// Overrides this method if you want to handle behavior.
322 /// <since_tizen> 3 </since_tizen>
323 protected virtual void OnResume()
325 Resumed?.Invoke(this, EventArgs.Empty);
329 /// Overrides this method if you want to handle behavior.
331 /// <since_tizen> 3 </since_tizen>
332 protected virtual void OnPreCreate()
337 /// Overrides this method if you want to handle behavior.
339 /// <since_tizen> 3 </since_tizen>
340 protected override void OnAppControlReceived(AppControlReceivedEventArgs e)
344 Log.Info("NUI", "OnAppControlReceived() is called! ApplicationId=" + e.ReceivedAppControl.ApplicationId);
345 Log.Info("NUI", "CallerApplicationId=" + e.ReceivedAppControl.CallerApplicationId + " IsReplyRequest=" + e.ReceivedAppControl.IsReplyRequest);
347 base.OnAppControlReceived(e);
351 /// Overrides this method if you want to handle behavior.
353 /// <since_tizen> 3 </since_tizen>
354 protected override void OnCreate()
357 Device.PlatformServices = new TizenPlatformServices();
362 /// Graphics Backend Type.
364 [EditorBrowsable(EditorBrowsableState.Never)]
365 [Obsolete("Please do not use! This will be deprecated!")]
366 public class Graphics
369 /// Graphics Backend Type.
371 public enum BackendType
374 /// The GLES backend.
378 /// The Vulkan backend.
384 /// The backend used by the NUIApplication.
386 [EditorBrowsable(EditorBrowsableState.Never)]
387 public static BackendType Backend = BackendType.Gles;
389 internal const string GlesCSharpBinder = NDalicPINVOKE.Lib;
390 internal const string VulkanCSharpBinder = "libdali-csharp-binder-vk.so";