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 Tizen.Applications;
22 using Tizen.Applications.CoreBackend;
28 /// Represents an application that have a UI screen. The NUIApplication class has a default stage.
30 /// <since_tizen> 3 </since_tizen>
31 public class NUIApplication : CoreApplication
34 /// Occurs whenever the application is resumed.
36 /// <since_tizen> 4 </since_tizen>
37 public event EventHandler Resumed;
40 /// Occurs whenever the application is paused.
42 /// <since_tizen> 4 </since_tizen>
43 public event EventHandler Paused;
46 /// The instance of ResourceManager.
48 private static System.Resources.ResourceManager resourceManager = null;
51 /// The default constructor.
53 /// <since_tizen> 3 </since_tizen>
54 public NUIApplication() : base(new NUICoreBackend())
56 Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
60 /// The constructor with a stylesheet.
62 /// <param name="styleSheet">The styleSheet url.</param>
63 /// <since_tizen> 3 </since_tizen>
64 public NUIApplication(string styleSheet) : base(new NUICoreBackend(styleSheet))
66 Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
70 /// The constructor with a stylesheet and window mode.
72 /// <param name="styleSheet">The styleSheet url.</param>
73 /// <param name="windowMode">The windowMode.</param>
74 /// <since_tizen> 3 </since_tizen>
75 public NUIApplication(string styleSheet, WindowMode windowMode) : base(new NUICoreBackend(styleSheet, windowMode))
77 Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
81 /// Overrides this method if you want to handle behavior.
83 /// <since_tizen> 3 </since_tizen>
84 protected override void OnLocaleChanged(LocaleChangedEventArgs e)
86 base.OnLocaleChanged(e);
90 /// Overrides this method if you want to handle behavior.
92 /// <since_tizen> 3 </since_tizen>
93 protected override void OnLowBattery(LowBatteryEventArgs e)
99 /// Overrides this method if you want to handle behavior.
101 /// <since_tizen> 3 </since_tizen>
102 protected override void OnLowMemory(LowMemoryEventArgs e)
108 /// Overrides this method if you want to handle behavior.
110 /// <since_tizen> 3 </since_tizen>
111 protected override void OnRegionFormatChanged(RegionFormatChangedEventArgs e)
113 base.OnRegionFormatChanged(e);
117 /// Overrides this method if you want to handle behavior.
119 /// <since_tizen> 3 </since_tizen>
120 protected override void OnTerminate()
126 /// Overrides this method if you want to handle behavior.
128 /// <since_tizen> 3 </since_tizen>
129 protected virtual void OnPause()
131 Paused?.Invoke(this, EventArgs.Empty);
135 /// Overrides this method if you want to handle behavior.
137 /// <since_tizen> 3 </since_tizen>
138 protected virtual void OnResume()
140 Resumed?.Invoke(this, EventArgs.Empty);
144 /// Overrides this method if you want to handle behavior.
146 /// <since_tizen> 3 </since_tizen>
147 protected virtual void OnPreCreate()
152 /// Overrides this method if you want to handle behavior.
154 /// <since_tizen> 3 </since_tizen>
155 protected override void OnAppControlReceived(AppControlReceivedEventArgs e)
159 Log.Info("NUI", "OnAppControlReceived() is called! ApplicationId=" + e.ReceivedAppControl.ApplicationId);
160 Log.Info("NUI", "CallerApplicationId=" + e.ReceivedAppControl.CallerApplicationId + " IsReplyRequest=" + e.ReceivedAppControl.IsReplyRequest);
162 base.OnAppControlReceived(e);
166 /// Overrides this method if you want to handle behavior.
168 /// <since_tizen> 3 </since_tizen>
169 protected override void OnCreate()
171 // This is also required to create DisposeQueue on main thread.
172 DisposeQueue disposeQ = DisposeQueue.Instance;
173 disposeQ.Initialize();
176 // Dali's default layer is default center origin. need to change as top left.
177 // NUI's Layer is like a transparent film which covers entire window. (Layer is not an actor of Dali)
178 // otherwise, this makes ScreenPosition as wrong value.
179 Layer defaultLayer = Window.GetDefaultLayer();
180 defaultLayer.SetParentOrigin(Tizen.NUI.ParentOrigin.TopLeft);
181 defaultLayer.SetAnchorPoint(Tizen.NUI.PivotPoint.TopLeft);
185 /// Runs the NUIApplication.
187 /// <param name="args">Arguments from commandline.</param>
188 /// <since_tizen> 4 </since_tizen>
189 public override void Run(string[] args)
191 Backend.AddEventHandler(EventType.PreCreated, OnPreCreate);
192 Backend.AddEventHandler(EventType.Resumed, OnResume);
193 Backend.AddEventHandler(EventType.Paused, OnPause);
198 /// Exits the NUIApplication.
200 /// <since_tizen> 4 </since_tizen>
201 public override void Exit()
207 /// Ensures that the function passed in is called from the main loop when it is idle.
209 /// <param name="func">The function to call</param>
210 /// <returns>true if added successfully, false otherwise</returns>
211 /// <since_tizen> 4 </since_tizen>
212 public bool AddIdle(System.Delegate func)
214 return ((NUICoreBackend)this.Backend).AddIdle(func);
218 /// Enumeration for deciding whether a NUI application window is opaque or transparent.
220 /// <since_tizen> 3 </since_tizen>
221 public enum WindowMode
226 /// <since_tizen> 3 </since_tizen>
231 /// <since_tizen> 3 </since_tizen>
236 internal Application ApplicationHandle
240 return ((NUICoreBackend)this.Backend).ApplicationHandle;
245 /// ResourceManager to handle multilingual.
247 /// <since_tizen> 4 </since_tizen>
248 public static System.Resources.ResourceManager MultilingualResourceManager
252 return resourceManager;
256 resourceManager = value;
261 /// Gets the window instance.
263 /// <since_tizen> 3 </since_tizen>
264 [Obsolete("Please do not use! This will be deprecated!")]
265 [EditorBrowsable(EditorBrowsableState.Never)]
270 return Window.Instance;