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;
203 internal Application ApplicationHandle
207 return ((NUICoreBackend)this.Backend).ApplicationHandle;
212 /// Register the assembly to XAML.
214 /// <since_tizen> 5 </since_tizen>
215 public static void RegisterAssembly(Assembly assembly)
217 XamlParser.s_assemblies.Add(assembly);
221 /// Runs the NUIApplication.
223 /// <param name="args">Arguments from commandline.</param>
224 /// <since_tizen> 4 </since_tizen>
225 public override void Run(string[] args)
227 Backend.AddEventHandler(EventType.PreCreated, OnPreCreate);
228 Backend.AddEventHandler(EventType.Resumed, OnResume);
229 Backend.AddEventHandler(EventType.Paused, OnPause);
234 /// Exits the NUIApplication.
236 /// <since_tizen> 4 </since_tizen>
237 public override void Exit()
243 /// Ensures that the function passed in is called from the main loop when it is idle.
245 /// <param name="func">The function to call</param>
246 /// <returns>true if added successfully, false otherwise</returns>
247 /// <since_tizen> 4 </since_tizen>
248 public bool AddIdle(System.Delegate func)
250 return ((NUICoreBackend)this.Backend).AddIdle(func);
254 /// Overrides this method if you want to handle behavior.
256 /// <since_tizen> 3 </since_tizen>
257 protected override void OnLocaleChanged(LocaleChangedEventArgs e)
259 base.OnLocaleChanged(e);
263 /// Overrides this method if you want to handle behavior.
265 /// <since_tizen> 3 </since_tizen>
266 protected override void OnLowBattery(LowBatteryEventArgs e)
268 base.OnLowBattery(e);
272 /// Overrides this method if you want to handle behavior.
274 /// <since_tizen> 3 </since_tizen>
275 protected override void OnLowMemory(LowMemoryEventArgs e)
281 /// Overrides this method if you want to handle behavior.
283 /// <since_tizen> 3 </since_tizen>
284 protected override void OnRegionFormatChanged(RegionFormatChangedEventArgs e)
286 base.OnRegionFormatChanged(e);
290 /// Overrides this method if you want to handle behavior.
292 /// <since_tizen> 3 </since_tizen>
293 protected override void OnTerminate()
299 /// Overrides this method if you want to handle behavior.
301 /// <since_tizen> 3 </since_tizen>
302 protected virtual void OnPause()
304 Paused?.Invoke(this, EventArgs.Empty);
308 /// Overrides this method if you want to handle behavior.
310 /// <since_tizen> 3 </since_tizen>
311 protected virtual void OnResume()
313 Resumed?.Invoke(this, EventArgs.Empty);
317 /// Overrides this method if you want to handle behavior.
319 /// <since_tizen> 3 </since_tizen>
320 protected virtual void OnPreCreate()
322 if (_windowSize2D != null)
324 Window.Instance.WindowSize = _windowSize2D;
326 if (_windowPosition2D != null)
328 Window.Instance.WindowPosition = _windowPosition2D;
333 /// Overrides this method if you want to handle behavior.
335 /// <since_tizen> 3 </since_tizen>
336 protected override void OnAppControlReceived(AppControlReceivedEventArgs e)
340 Log.Info("NUI", "OnAppControlReceived() is called! ApplicationId=" + e.ReceivedAppControl.ApplicationId);
341 Log.Info("NUI", "CallerApplicationId=" + e.ReceivedAppControl.CallerApplicationId + " IsReplyRequest=" + e.ReceivedAppControl.IsReplyRequest);
343 base.OnAppControlReceived(e);
347 /// Overrides this method if you want to handle behavior.
349 /// <since_tizen> 3 </since_tizen>
350 protected override void OnCreate()
353 Device.PlatformServices = new TizenPlatformServices();
358 /// Graphics Backend Type.
360 [EditorBrowsable(EditorBrowsableState.Never)]
361 [Obsolete("Please do not use! This will be deprecated!")]
362 public class Graphics
365 /// Graphics Backend Type.
367 public enum BackendType
370 /// The GLES backend.
374 /// The Vulkan backend.
380 /// The backend used by the NUIApplication.
382 [EditorBrowsable(EditorBrowsableState.Never)]
383 public static BackendType Backend = BackendType.Gles;
385 internal const string GlesCSharpBinder = "libdali-csharp-binder.so";
386 internal const string VulkanCSharpBinder = "libdali-csharp-binder-vk.so";