2 * Copyright (c) 2016 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;
63 /// The constructor with a stylesheet.
65 /// <param name="styleSheet">The styleSheet url.</param>
66 /// <since_tizen> 3 </since_tizen>
67 public NUIApplication(string styleSheet) : base(new NUICoreBackend(styleSheet))
69 Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
73 /// The constructor with a stylesheet and window mode.
75 /// <param name="styleSheet">The styleSheet url.</param>
76 /// <param name="windowMode">The windowMode.</param>
77 /// <since_tizen> 3 </since_tizen>
78 public NUIApplication(string styleSheet, WindowMode windowMode) : base(new NUICoreBackend(styleSheet, windowMode))
80 Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
84 /// Overrides this method if you want to handle behavior.
86 /// <since_tizen> 3 </since_tizen>
87 protected override void OnLocaleChanged(LocaleChangedEventArgs e)
89 base.OnLocaleChanged(e);
93 /// Overrides this method if you want to handle behavior.
95 /// <since_tizen> 3 </since_tizen>
96 protected override void OnLowBattery(LowBatteryEventArgs e)
102 /// Overrides this method if you want to handle behavior.
104 /// <since_tizen> 3 </since_tizen>
105 protected override void OnLowMemory(LowMemoryEventArgs e)
111 /// Overrides this method if you want to handle behavior.
113 /// <since_tizen> 3 </since_tizen>
114 protected override void OnRegionFormatChanged(RegionFormatChangedEventArgs e)
116 base.OnRegionFormatChanged(e);
120 /// Overrides this method if you want to handle behavior.
122 /// <since_tizen> 3 </since_tizen>
123 protected override void OnTerminate()
129 /// Overrides this method if you want to handle behavior.
131 /// <since_tizen> 3 </since_tizen>
132 protected virtual void OnPause()
134 Paused?.Invoke(this, EventArgs.Empty);
138 /// Overrides this method if you want to handle behavior.
140 /// <since_tizen> 3 </since_tizen>
141 protected virtual void OnResume()
143 Resumed?.Invoke(this, EventArgs.Empty);
147 /// Overrides this method if you want to handle behavior.
149 /// <since_tizen> 3 </since_tizen>
150 protected virtual void OnPreCreate()
155 /// Overrides this method if you want to handle behavior.
157 /// <since_tizen> 3 </since_tizen>
158 protected override void OnAppControlReceived(AppControlReceivedEventArgs e)
162 Log.Info("NUI", "OnAppControlReceived() is called! ApplicationId=" + e.ReceivedAppControl.ApplicationId);
163 Log.Info("NUI", "CallerApplicationId=" + e.ReceivedAppControl.CallerApplicationId + " IsReplyRequest=" + e.ReceivedAppControl.IsReplyRequest);
165 base.OnAppControlReceived(e);
169 /// Overrides this method if you want to handle behavior.
171 /// <since_tizen> 3 </since_tizen>
172 protected override void OnCreate()
175 Device.PlatformServices = new TizenPlatformServices();
179 /// Runs the NUIApplication.
181 /// <param name="args">Arguments from commandline.</param>
182 /// <since_tizen> 4 </since_tizen>
183 public override void Run(string[] args)
185 Backend.AddEventHandler(EventType.PreCreated, OnPreCreate);
186 Backend.AddEventHandler(EventType.Resumed, OnResume);
187 Backend.AddEventHandler(EventType.Paused, OnPause);
192 /// Exits the NUIApplication.
194 /// <since_tizen> 4 </since_tizen>
195 public override void Exit()
201 /// Ensures that the function passed in is called from the main loop when it is idle.
203 /// <param name="func">The function to call</param>
204 /// <returns>true if added successfully, false otherwise</returns>
205 /// <since_tizen> 4 </since_tizen>
206 public bool AddIdle(System.Delegate func)
208 return ((NUICoreBackend)this.Backend).AddIdle(func);
212 /// Enumeration for deciding whether a NUI application window is opaque or transparent.
214 /// <since_tizen> 3 </since_tizen>
215 public enum WindowMode
220 /// <since_tizen> 3 </since_tizen>
225 /// <since_tizen> 3 </since_tizen>
230 internal Application ApplicationHandle
234 return ((NUICoreBackend)this.Backend).ApplicationHandle;
239 /// ResourceManager to handle multilingual.
241 /// <since_tizen> 4 </since_tizen>
242 public static System.Resources.ResourceManager MultilingualResourceManager
246 return resourceManager;
250 resourceManager = value;
255 /// Register the assembly to XAML.
257 /// <since_tizen> 5 </since_tizen>
258 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
259 [EditorBrowsable(EditorBrowsableState.Never)]
260 public static void RegisterAssembly(Assembly assembly)
262 XamlParser.s_assemblies.Add(assembly);
266 /// Gets the window instance.
268 /// <since_tizen> 3 </since_tizen>
269 [Obsolete("Please do not use! This will be deprecated!")]
270 [EditorBrowsable(EditorBrowsableState.Never)]
275 return Window.Instance;