2 * Copyright (c) 2018 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 /// Occurs whenever the application is resumed.
39 /// <since_tizen> 4 </since_tizen>
40 public event EventHandler Resumed;
43 /// Occurs whenever the application is paused.
45 /// <since_tizen> 4 </since_tizen>
46 public event EventHandler Paused;
49 /// The instance of ResourceManager.
51 private static System.Resources.ResourceManager resourceManager = null;
54 /// The default constructor.
56 /// <since_tizen> 3 </since_tizen>
57 public NUIApplication() : base(new NUICoreBackend())
59 Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
62 private Size2D _windowSize2D = null;
63 private Position2D _windowPosition2D = null;
65 /// The constructor with window size and position.
67 /// <param name="windowSize">The window size.</param>
68 /// <param name="windowPosition">The window position.</param>
69 /// <since_tizen> 5 </since_tizen>
70 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
71 [EditorBrowsable(EditorBrowsableState.Never)]
72 public NUIApplication(Size2D windowSize, Position2D windowPosition) : base(new NUICoreBackend())
74 Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
75 _windowSize2D = windowSize;
76 _windowPosition2D = windowPosition;
80 /// The constructor with a stylesheet.
82 /// <param name="styleSheet">The styleSheet url.</param>
83 /// <since_tizen> 3 </since_tizen>
84 public NUIApplication(string styleSheet) : base(new NUICoreBackend(styleSheet))
86 Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
90 /// The constructor with a stylesheet, window size, and position.
92 /// <param name="styleSheet">The styleSheet URL.</param>
93 /// <param name="windowSize">The window size.</param>
94 /// <param name="windowPosition">The window position.</param>
95 /// <since_tizen> 5 </since_tizen>
96 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
97 [EditorBrowsable(EditorBrowsableState.Never)]
98 public NUIApplication(string styleSheet, Size2D windowSize, Position2D windowPosition) : base(new NUICoreBackend(styleSheet))
100 Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
101 _windowSize2D = windowSize;
102 _windowPosition2D = windowPosition;
106 /// The constructor with a stylesheet and window mode.
108 /// <param name="styleSheet">The styleSheet url.</param>
109 /// <param name="windowMode">The windowMode.</param>
110 /// <since_tizen> 3 </since_tizen>
111 public NUIApplication(string styleSheet, WindowMode windowMode) : base(new NUICoreBackend(styleSheet, windowMode))
113 Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
117 /// The constructor with a stylesheet, window mode, window size, and position.
119 /// <param name="styleSheet">The styleSheet URL.</param>
120 /// <param name="windowMode">The windowMode.</param>
121 /// <param name="windowSize">The window size.</param>
122 /// <param name="windowPosition">The window position.</param>
123 /// <since_tizen> 5 </since_tizen>
124 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
125 [EditorBrowsable(EditorBrowsableState.Never)]
126 public NUIApplication(string styleSheet, WindowMode windowMode, Size2D windowSize, Position2D windowPosition) : base(new NUICoreBackend(styleSheet, windowMode))
128 Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
129 _windowSize2D = windowSize;
130 _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 [EditorBrowsable(EditorBrowsableState.Never)]
143 public NUIApplication(Graphics.BackendType backend, WindowMode windowMode = WindowMode.Opaque, Size2D windowSize = null, Position2D windowPosition = null, string styleSheet = "") : base(new NUICoreBackend(styleSheet, windowMode))
145 //windowMode and styleSheet will be added later. currenlty it's not working as expected.
146 Graphics.Backend = backend;
147 if (windowSize != null) { _windowSize2D = windowSize; }
148 if (windowPosition != null) { _windowPosition2D = windowPosition; }
149 Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
153 /// Overrides this method if you want to handle behavior.
155 /// <since_tizen> 3 </since_tizen>
156 protected override void OnLocaleChanged(LocaleChangedEventArgs e)
158 base.OnLocaleChanged(e);
162 /// Overrides this method if you want to handle behavior.
164 /// <since_tizen> 3 </since_tizen>
165 protected override void OnLowBattery(LowBatteryEventArgs e)
167 base.OnLowBattery(e);
171 /// Overrides this method if you want to handle behavior.
173 /// <since_tizen> 3 </since_tizen>
174 protected override void OnLowMemory(LowMemoryEventArgs e)
180 /// Overrides this method if you want to handle behavior.
182 /// <since_tizen> 3 </since_tizen>
183 protected override void OnRegionFormatChanged(RegionFormatChangedEventArgs e)
185 base.OnRegionFormatChanged(e);
189 /// Overrides this method if you want to handle behavior.
191 /// <since_tizen> 3 </since_tizen>
192 protected override void OnTerminate()
198 /// Overrides this method if you want to handle behavior.
200 /// <since_tizen> 3 </since_tizen>
201 protected virtual void OnPause()
203 Paused?.Invoke(this, EventArgs.Empty);
207 /// Overrides this method if you want to handle behavior.
209 /// <since_tizen> 3 </since_tizen>
210 protected virtual void OnResume()
212 Resumed?.Invoke(this, EventArgs.Empty);
216 /// Overrides this method if you want to handle behavior.
218 /// <since_tizen> 3 </since_tizen>
219 protected virtual void OnPreCreate()
221 if (_windowSize2D != null)
223 Window.Instance.WindowSize = _windowSize2D;
225 if (_windowPosition2D != null)
227 Window.Instance.WindowPosition = _windowPosition2D;
232 /// Overrides this method if you want to handle behavior.
234 /// <since_tizen> 3 </since_tizen>
235 protected override void OnAppControlReceived(AppControlReceivedEventArgs e)
239 Log.Info("NUI", "OnAppControlReceived() is called! ApplicationId=" + e.ReceivedAppControl.ApplicationId);
240 Log.Info("NUI", "CallerApplicationId=" + e.ReceivedAppControl.CallerApplicationId + " IsReplyRequest=" + e.ReceivedAppControl.IsReplyRequest);
242 base.OnAppControlReceived(e);
246 /// Overrides this method if you want to handle behavior.
248 /// <since_tizen> 3 </since_tizen>
249 protected override void OnCreate()
252 Device.PlatformServices = new TizenPlatformServices();
256 /// Runs the NUIApplication.
258 /// <param name="args">Arguments from commandline.</param>
259 /// <since_tizen> 4 </since_tizen>
260 public override void Run(string[] args)
262 Backend.AddEventHandler(EventType.PreCreated, OnPreCreate);
263 Backend.AddEventHandler(EventType.Resumed, OnResume);
264 Backend.AddEventHandler(EventType.Paused, OnPause);
269 /// Exits the NUIApplication.
271 /// <since_tizen> 4 </since_tizen>
272 public override void Exit()
278 /// Ensures that the function passed in is called from the main loop when it is idle.
280 /// <param name="func">The function to call</param>
281 /// <returns>true if added successfully, false otherwise</returns>
282 /// <since_tizen> 4 </since_tizen>
283 public bool AddIdle(System.Delegate func)
285 return ((NUICoreBackend)this.Backend).AddIdle(func);
289 /// Enumeration for deciding whether a NUI application window is opaque or transparent.
291 /// <since_tizen> 3 </since_tizen>
292 public enum WindowMode
297 /// <since_tizen> 3 </since_tizen>
302 /// <since_tizen> 3 </since_tizen>
307 internal Application ApplicationHandle
311 return ((NUICoreBackend)this.Backend).ApplicationHandle;
316 /// ResourceManager to handle multilingual.
318 /// <since_tizen> 4 </since_tizen>
319 public static System.Resources.ResourceManager MultilingualResourceManager
323 return resourceManager;
327 resourceManager = value;
332 /// Register the assembly to XAML.
334 /// <since_tizen> 5 </since_tizen>
335 public static void RegisterAssembly(Assembly assembly)
337 XamlParser.s_assemblies.Add(assembly);
341 /// Gets the window instance.
343 /// <since_tizen> 3 </since_tizen>
344 [Obsolete("Please do not use! This will be deprecated!")]
345 [EditorBrowsable(EditorBrowsableState.Never)]
350 return Window.Instance;
356 /// Graphics BackendType
358 /// InhouseAPI, this could be opend in NextTizen
359 [EditorBrowsable(EditorBrowsableState.Never)]
360 public class Graphics
362 public enum BackendType
367 public static BackendType Backend = BackendType.Gles;
368 internal const string GlesCSharpBinder = "libdali-csharp-binder.so";
369 internal const string VulkanCSharpBinder = "libdali-csharp-binder-vk.so";