2 * Copyright(c) 2017 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.
22 using System.Collections.Generic;
23 using System.Collections.ObjectModel;
24 using System.ComponentModel;
25 using System.Runtime.InteropServices;
26 using System.Threading;
27 using System.Threading.Tasks;
28 using Tizen.NUI.Binding;
29 using Tizen.NUI.Binding.Internals;
32 * @brief Event arguments that passed via NUIApplicationInit signal
35 internal class NUIApplicationInitEventArgs : EventArgs
37 private Application _application;
40 * @brief Application - is the application that is being initialized
43 public Application Application
57 * @brief Event arguments that passed via NUIApplicationTerminate signal
60 internal class NUIApplicationTerminatingEventArgs : EventArgs
62 private Application _application;
64 * @brief Application - is the application that is being Terminated
67 public Application Application
81 * @brief Event arguments that passed via NUIApplicationPause signal
84 internal class NUIApplicationPausedEventArgs : EventArgs
86 private Application _application;
88 * @brief Application - is the application that is being Paused
91 public Application Application
105 * @brief Event arguments that passed via NUIApplicationResume signal
108 internal class NUIApplicationResumedEventArgs : EventArgs
110 private Application _application;
112 * @brief Application - is the application that is being Resumed
115 public Application Application
123 _application = value;
129 * @brief Event arguments that passed via NUIApplicationReset signal
132 internal class NUIApplicationResetEventArgs : EventArgs
134 private Application _application;
136 * @brief Application - is the application that is being Reset
139 public Application Application
147 _application = value;
153 * @brief Event arguments that passed via NUIApplicationResize signal
156 internal class NUIApplicationResizedEventArgs : EventArgs
158 private Application _application;
160 * @brief Application - is the application that is being Resized
163 public Application Application
171 _application = value;
177 * @brief Event arguments that passed via NUIApplicationLanguageChanged signal
180 internal class NUIApplicationLanguageChangedEventArgs : EventArgs
182 private Application _application;
184 * @brief Application - is the application that is being affected with Device's language change
187 public Application Application
195 _application = value;
201 * @brief Event arguments that passed via NUIApplicationRegionChanged signal
204 internal class NUIApplicationRegionChangedEventArgs : EventArgs
206 private Application _application;
208 * @brief Application - is the application that is being affected with Device's region change
211 public Application Application
219 _application = value;
225 * @brief Event arguments that passed via NUIApplicationBatteryLow signal
228 internal class NUIApplicationBatteryLowEventArgs : EventArgs
230 private Application.BatteryStatus _status;
232 * @brief Application - is the application that is being affected when the battery level of the device is low
235 public Application.BatteryStatus BatteryStatus
249 * @brief Event arguments that passed via NUIApplicationMemoryLow signal
252 internal class NUIApplicationMemoryLowEventArgs : EventArgs
254 private Application.MemoryStatus _status;
256 * @brief Application - is the application that is being affected when the memory level of the device is low
259 public Application.MemoryStatus MemoryStatus
273 * @brief Event arguments that passed via NUIApplicationAppControl signal
276 internal class NUIApplicationAppControlEventArgs : EventArgs
278 private Application _application;
279 private IntPtr _voidp;
281 * @brief Application - is the application that is receiving the launch request from another application
284 public Application Application
292 _application = value;
296 * @brief VoidP - contains the information about why the application is launched
312 public class GetResourcesProvider
314 static public IResourcesProvider Get()
316 return Tizen.NUI.Application.Current;
320 internal class Application : BaseHandle, IResourcesProvider, IApplicationController, IElementConfiguration<Application>
322 static Application s_current;
323 Task<IDictionary<string, object>> _propertiesTask;
324 readonly Lazy<PlatformConfigurationRegistry<Application>> _platformConfigurationRegistry;
326 IAppIndexingProvider _appIndexProvider;
328 ReadOnlyCollection<Element> _logicalChildren;
332 static SemaphoreSlim SaveSemaphore = new SemaphoreSlim(1, 1);
334 public IAppLinks AppLinks
338 if (_appIndexProvider == null)
339 throw new ArgumentException("No IAppIndexingProvider was provided");
340 if (_appIndexProvider.AppLinks == null)
341 throw new ArgumentException("No AppLinks implementation was found, if in Android make sure you installed the Xamarin.Forms.AppLinks");
342 return _appIndexProvider.AppLinks;
346 [EditorBrowsable(EditorBrowsableState.Never)]
347 public static void SetCurrentApplication(Application value) => Current = value;
349 public static Application Current
351 get { return s_current; }
354 if (s_current == value)
357 s_current = null; //Allow to reset current for unittesting
364 get { return _mainPage; }
368 throw new ArgumentNullException("value");
370 if (_mainPage == value)
373 OnPropertyChanging();
374 if (_mainPage != null)
376 InternalChildren.Remove(_mainPage);
377 _mainPage.Parent = null;
382 if (_mainPage != null)
384 _mainPage.Parent = this;
385 _mainPage.NavigationProxy.Inner = NavigationProxy;
386 InternalChildren.Add(_mainPage);
392 public IDictionary<string, object> Properties
396 if (_propertiesTask == null)
398 _propertiesTask = GetPropertiesAsync();
401 return _propertiesTask.Result;
405 internal override ReadOnlyCollection<Element> LogicalChildrenInternal
407 get { return _logicalChildren ?? (_logicalChildren = new ReadOnlyCollection<Element>(InternalChildren)); }
410 [EditorBrowsable(EditorBrowsableState.Never)]
411 public NavigationProxy NavigationProxy { get; }
413 [EditorBrowsable(EditorBrowsableState.Never)]
414 public int PanGestureId { get; set; }
416 internal IResourceDictionary SystemResources { get; }
418 ObservableCollection<Element> InternalChildren { get; } = new ObservableCollection<Element>();
420 [EditorBrowsable(EditorBrowsableState.Never)]
421 public void SetAppIndexingProvider(IAppIndexingProvider provider)
423 _appIndexProvider = provider;
426 ResourceDictionary _resources;
427 public bool IsResourcesCreated => _resources != null;
429 public delegate void resChangeCb (object sender, ResourcesChangedEventArgs e);
431 static private Dictionary<object, Dictionary<resChangeCb, int>> resourceChangeCallbackDict = new Dictionary<object, Dictionary<resChangeCb, int>>();
432 static public void AddResourceChangedCallback(object handle, resChangeCb cb)
434 Dictionary<resChangeCb, int> cbDict;
435 resourceChangeCallbackDict.TryGetValue(handle, out cbDict);
439 cbDict = new Dictionary<resChangeCb, int>();
440 resourceChangeCallbackDict.Add(handle, cbDict);
443 if (false == cbDict.ContainsKey(cb))
449 internal override void OnResourcesChanged(object sender, ResourcesChangedEventArgs e)
451 base.OnResourcesChanged(sender, e);
453 foreach (KeyValuePair<object, Dictionary<resChangeCb, int>> resourcePair in resourceChangeCallbackDict)
455 foreach (KeyValuePair<resChangeCb, int> cbPair in resourcePair.Value)
457 cbPair.Key(sender, e);
462 public ResourceDictionary XamlResources
466 if (_resources != null)
469 _resources = new ResourceDictionary();
470 int hashCode = _resources.GetHashCode();
471 ((IResourceDictionary)_resources).ValuesChanged += OnResourcesChanged;
476 if (_resources == value)
478 OnPropertyChanging();
480 if (_resources != null)
481 ((IResourceDictionary)_resources).ValuesChanged -= OnResourcesChanged;
483 OnResourcesChanged(value);
484 if (_resources != null)
485 ((IResourceDictionary)_resources).ValuesChanged += OnResourcesChanged;
491 public event EventHandler<ModalPoppedEventArgs> ModalPopped;
493 public event EventHandler<ModalPoppingEventArgs> ModalPopping;
495 public event EventHandler<ModalPushedEventArgs> ModalPushed;
497 public event EventHandler<ModalPushingEventArgs> ModalPushing;
499 public event EventHandler<Page> PageAppearing;
501 public event EventHandler<Page> PageDisappearing;
504 async void SaveProperties()
508 await SetPropertiesAsync();
510 catch (Exception exc)
512 Console.WriteLine(nameof(Application), $"Exception while saving Application Properties: {exc}");
516 public async Task SavePropertiesAsync()
518 if (Device.IsInvokeRequired)
520 Device.BeginInvokeOnMainThread(SaveProperties);
524 await SetPropertiesAsync();
528 // Don't use this unless there really is no better option
529 internal void SavePropertiesAsFireAndForget()
531 if (Device.IsInvokeRequired)
533 Device.BeginInvokeOnMainThread(SaveProperties);
541 public IPlatformElementConfiguration<T, Application> On<T>() where T : IConfigPlatform
543 return _platformConfigurationRegistry.Value.On<T>();
546 protected virtual void OnAppLinkRequestReceived(Uri uri)
550 protected override void OnParentSet()
552 throw new InvalidOperationException("Setting a Parent on Application is invalid.");
555 protected virtual void OnResume()
559 protected virtual void OnSleep()
563 protected virtual void OnStart()
567 [EditorBrowsable(EditorBrowsableState.Never)]
568 public static void ClearCurrent()
573 [EditorBrowsable(EditorBrowsableState.Never)]
574 public static bool IsApplicationOrNull(Element element)
576 return element == null || element is Application;
579 internal override void OnParentResourcesChanged(IEnumerable<KeyValuePair<string, object>> values)
581 if (!((IResourcesProvider)this).IsResourcesCreated || XamlResources.Count == 0)
583 base.OnParentResourcesChanged(values);
587 var innerKeys = new HashSet<string>();
588 var changedResources = new List<KeyValuePair<string, object>>();
589 foreach (KeyValuePair<string, object> c in XamlResources)
590 innerKeys.Add(c.Key);
591 foreach (KeyValuePair<string, object> value in values)
593 if (innerKeys.Add(value.Key))
594 changedResources.Add(value);
596 OnResourcesChanged(changedResources);
599 internal event EventHandler PopCanceled;
601 [EditorBrowsable(EditorBrowsableState.Never)]
602 public void SendOnAppLinkRequestReceived(Uri uri)
604 OnAppLinkRequestReceived(uri);
607 [EditorBrowsable(EditorBrowsableState.Never)]
608 public void SendResume()
614 [EditorBrowsable(EditorBrowsableState.Never)]
615 public void SendSleep()
618 SavePropertiesAsFireAndForget();
621 [EditorBrowsable(EditorBrowsableState.Never)]
622 public Task SendSleepAsync()
625 return SavePropertiesAsync();
628 [EditorBrowsable(EditorBrowsableState.Never)]
629 public void SendStart()
634 async Task<IDictionary<string, object>> GetPropertiesAsync()
636 var deserializer = DependencyService.Get<IDeserializer>();
637 if (deserializer == null)
639 Console.WriteLine("Startup", "No IDeserialzier was found registered");
640 return new Dictionary<string, object>(4);
643 IDictionary<string, object> properties = await deserializer.DeserializePropertiesAsync().ConfigureAwait(false);
644 if (properties == null)
645 properties = new Dictionary<string, object>(4);
650 internal void OnPageAppearing(Page page)
651 => PageAppearing?.Invoke(this, page);
653 internal void OnPageDisappearing(Page page)
654 => PageDisappearing?.Invoke(this, page);
656 void OnModalPopped(Page modalPage)
657 => ModalPopped?.Invoke(this, new ModalPoppedEventArgs(modalPage));
659 bool OnModalPopping(Page modalPage)
661 var args = new ModalPoppingEventArgs(modalPage);
662 ModalPopping?.Invoke(this, args);
666 void OnModalPushed(Page modalPage)
667 => ModalPushed?.Invoke(this, new ModalPushedEventArgs(modalPage));
669 void OnModalPushing(Page modalPage)
670 => ModalPushing?.Invoke(this, new ModalPushingEventArgs(modalPage));
673 => PopCanceled?.Invoke(this, EventArgs.Empty);
675 async Task SetPropertiesAsync()
677 await SaveSemaphore.WaitAsync();
680 await DependencyService.Get<IDeserializer>().SerializePropertiesAsync(Properties);
684 SaveSemaphore.Release();
689 class NavigationImpl : NavigationProxy
691 readonly Application _owner;
693 public NavigationImpl(Application owner)
698 protected override async Task<Page> OnPopModal(bool animated)
700 Page modal = ModalStack[ModalStack.Count - 1];
701 if (_owner.OnModalPopping(modal))
703 _owner.OnPopCanceled();
706 Page result = await base.OnPopModal(animated);
707 result.Parent = null;
708 _owner.OnModalPopped(result);
712 protected override async Task OnPushModal(Page modal, bool animated)
714 _owner.OnModalPushing(modal);
716 modal.Parent = _owner;
718 if (modal.NavigationProxy.ModalStack.Count == 0)
720 modal.NavigationProxy.Inner = this;
721 await base.OnPushModal(modal, animated);
725 await base.OnPushModal(modal, animated);
726 modal.NavigationProxy.Inner = this;
729 _owner.OnModalPushed(modal);
733 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
735 internal Application(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.Application_SWIGUpcast(cPtr), cMemoryOwn)
737 NavigationProxy = new NavigationImpl(this);
738 SetCurrentApplication(this);
740 _platformConfigurationRegistry = new Lazy<PlatformConfigurationRegistry<Application>>(() => new PlatformConfigurationRegistry<Application>(this));
741 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
746 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Application obj)
748 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
751 protected override void Dispose(DisposeTypes type)
758 if (type == DisposeTypes.Explicit)
761 //Release your own managed resources here.
762 //You should release all of your own disposable objects here.
766 //Release your own unmanaged resources here.
767 //You should not access any managed member here except static instance.
768 //because the execution order of Finalizes is non-deterministic.
770 if (_applicationInitEventCallbackDelegate != null)
772 this.InitSignal().Disconnect(_applicationInitEventCallbackDelegate);
775 if (_applicationTerminateEventCallbackDelegate != null)
777 this.TerminateSignal().Disconnect(_applicationTerminateEventCallbackDelegate);
780 if (_applicationPauseEventCallbackDelegate != null)
782 this.PauseSignal().Disconnect(_applicationPauseEventCallbackDelegate);
785 if (_applicationResumeEventCallbackDelegate != null)
787 this.ResumeSignal().Disconnect(_applicationResumeEventCallbackDelegate);
790 if (_applicationResetEventCallbackDelegate != null)
792 this.ResetSignal().Disconnect(_applicationResetEventCallbackDelegate);
795 if (_applicationResizeEventCallbackDelegate != null)
797 this.ResizeSignal().Disconnect(_applicationResizeEventCallbackDelegate);
800 if (_applicationLanguageChangedEventCallbackDelegate != null)
802 this.LanguageChangedSignal().Disconnect(_applicationLanguageChangedEventCallbackDelegate);
805 if (_applicationRegionChangedEventCallbackDelegate != null)
807 this.RegionChangedSignal().Disconnect(_applicationRegionChangedEventCallbackDelegate);
810 if (_applicationBatteryLowEventCallbackDelegate != null)
812 this.BatteryLowSignal().Disconnect(_applicationBatteryLowEventCallbackDelegate);
815 if (_applicationMemoryLowEventCallbackDelegate != null)
817 this.MemoryLowSignal().Disconnect(_applicationMemoryLowEventCallbackDelegate);
820 if (_applicationAppControlEventCallbackDelegate != null)
822 this.AppControlSignal().Disconnect(_applicationAppControlEventCallbackDelegate);
825 if (swigCPtr.Handle != global::System.IntPtr.Zero)
830 NDalicPINVOKE.delete_Application(swigCPtr);
832 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
838 /// <since_tizen> 4 </since_tizen>
839 public enum BatteryStatus
846 /// <since_tizen> 4 </since_tizen>
847 public enum MemoryStatus
854 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
855 private delegate void NUIApplicationInitEventCallbackDelegate(IntPtr application);
856 private DaliEventHandler<object, NUIApplicationInitEventArgs> _applicationInitEventHandler;
857 private NUIApplicationInitEventCallbackDelegate _applicationInitEventCallbackDelegate;
860 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
861 private delegate void NUIApplicationTerminateEventCallbackDelegate(IntPtr application);
862 private DaliEventHandler<object, NUIApplicationTerminatingEventArgs> _applicationTerminateEventHandler;
863 private NUIApplicationTerminateEventCallbackDelegate _applicationTerminateEventCallbackDelegate;
866 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
867 private delegate void NUIApplicationPauseEventCallbackDelegate(IntPtr application);
868 private DaliEventHandler<object, NUIApplicationPausedEventArgs> _applicationPauseEventHandler;
869 private NUIApplicationPauseEventCallbackDelegate _applicationPauseEventCallbackDelegate;
871 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
872 private delegate void NUIApplicationResumeEventCallbackDelegate(IntPtr application);
873 private DaliEventHandler<object, NUIApplicationResumedEventArgs> _applicationResumeEventHandler;
874 private NUIApplicationResumeEventCallbackDelegate _applicationResumeEventCallbackDelegate;
876 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
877 private delegate void NUIApplicationResetEventCallbackDelegate(IntPtr application);
878 private DaliEventHandler<object, NUIApplicationResetEventArgs> _applicationResetEventHandler;
879 private NUIApplicationResetEventCallbackDelegate _applicationResetEventCallbackDelegate;
881 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
882 private delegate void NUIApplicationResizeEventCallbackDelegate(IntPtr application);
883 private DaliEventHandler<object, NUIApplicationResizedEventArgs> _applicationResizeEventHandler;
884 private NUIApplicationResizeEventCallbackDelegate _applicationResizeEventCallbackDelegate;
886 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
887 private delegate void NUIApplicationLanguageChangedEventCallbackDelegate(IntPtr application);
888 private DaliEventHandler<object, NUIApplicationLanguageChangedEventArgs> _applicationLanguageChangedEventHandler;
889 private NUIApplicationLanguageChangedEventCallbackDelegate _applicationLanguageChangedEventCallbackDelegate;
892 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
893 private delegate void NUIApplicationRegionChangedEventCallbackDelegate(IntPtr application);
894 private DaliEventHandler<object, NUIApplicationRegionChangedEventArgs> _applicationRegionChangedEventHandler;
895 private NUIApplicationRegionChangedEventCallbackDelegate _applicationRegionChangedEventCallbackDelegate;
897 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
898 private delegate void NUIApplicationBatteryLowEventCallbackDelegate(BatteryStatus status);
899 private DaliEventHandler<object, NUIApplicationBatteryLowEventArgs> _applicationBatteryLowEventHandler;
900 private NUIApplicationBatteryLowEventCallbackDelegate _applicationBatteryLowEventCallbackDelegate;
902 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
903 private delegate void NUIApplicationMemoryLowEventCallbackDelegate(MemoryStatus status);
904 private DaliEventHandler<object, NUIApplicationMemoryLowEventArgs> _applicationMemoryLowEventHandler;
905 private NUIApplicationMemoryLowEventCallbackDelegate _applicationMemoryLowEventCallbackDelegate;
907 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
908 private delegate void NUIApplicationAppControlEventCallbackDelegate(IntPtr application, IntPtr voidp);
909 private DaliEventHandler<object, NUIApplicationAppControlEventArgs> _applicationAppControlEventHandler;
910 private NUIApplicationAppControlEventCallbackDelegate _applicationAppControlEventCallbackDelegate;
913 * @brief Event for Initialized signal which can be used to subscribe/unsubscribe the event handler
914 * provided by the user. Initialized signal is emitted when application is initialised
916 public event DaliEventHandler<object, NUIApplicationInitEventArgs> Initialized
922 // Restricted to only one listener
923 if (_applicationInitEventHandler == null)
925 _applicationInitEventHandler += value;
927 _applicationInitEventCallbackDelegate = new NUIApplicationInitEventCallbackDelegate(OnApplicationInit);
928 this.InitSignal().Connect(_applicationInitEventCallbackDelegate);
937 if (_applicationInitEventHandler != null)
939 this.InitSignal().Disconnect(_applicationInitEventCallbackDelegate);
942 _applicationInitEventHandler -= value;
947 // Callback for Application InitSignal
948 private void OnApplicationInit(IntPtr data)
950 // Initialize DisposeQueue Singleton class. This is also required to create DisposeQueue on main thread.
951 DisposeQueue.Instance.Initialize();
953 if(_applicationInitEventHandler != null)
955 NUIApplicationInitEventArgs e = new NUIApplicationInitEventArgs();
956 e.Application = this;
957 _applicationInitEventHandler.Invoke(this, e);
962 * @brief Event for Terminated signal which can be used to subscribe/unsubscribe the event handler
963 * provided by the user. Terminated signal is emitted when application is terminating
965 public event DaliEventHandler<object, NUIApplicationTerminatingEventArgs> Terminating
971 // Restricted to only one listener
972 if (_applicationTerminateEventHandler == null)
974 _applicationTerminateEventHandler += value;
976 _applicationTerminateEventCallbackDelegate = new NUIApplicationTerminateEventCallbackDelegate(OnNUIApplicationTerminate);
977 this.TerminateSignal().Connect(_applicationTerminateEventCallbackDelegate);
986 if (_applicationTerminateEventHandler != null)
988 this.TerminateSignal().Disconnect(_applicationTerminateEventCallbackDelegate);
991 _applicationTerminateEventHandler -= value;
996 // Callback for Application TerminateSignal
997 private void OnNUIApplicationTerminate(IntPtr data)
999 if(_applicationTerminateEventHandler != null)
1001 NUIApplicationTerminatingEventArgs e = new NUIApplicationTerminatingEventArgs();
1002 e.Application = this;
1003 _applicationTerminateEventHandler.Invoke(this, e);
1006 Window.Instance.DisconnectNativeSignals();
1010 * @brief Event for Paused signal which can be used to subscribe/unsubscribe the event handler
1011 * provided by the user. Paused signal is emitted when application is paused
1013 public event DaliEventHandler<object, NUIApplicationPausedEventArgs> Paused
1019 // Restricted to only one listener
1020 if (_applicationPauseEventHandler == null)
1022 _applicationPauseEventHandler += value;
1024 _applicationPauseEventCallbackDelegate = new NUIApplicationPauseEventCallbackDelegate(OnNUIApplicationPause);
1025 this.PauseSignal().Connect(_applicationPauseEventCallbackDelegate);
1034 if (_applicationPauseEventHandler != null)
1036 this.PauseSignal().Disconnect(_applicationPauseEventCallbackDelegate);
1039 _applicationPauseEventHandler -= value;
1044 // Callback for Application PauseSignal
1045 private void OnNUIApplicationPause(IntPtr data)
1047 if(_applicationPauseEventHandler != null)
1049 NUIApplicationPausedEventArgs e = new NUIApplicationPausedEventArgs();
1050 e.Application = this;
1051 _applicationPauseEventHandler.Invoke(this, e);
1056 * @brief Event for Resumed signal which can be used to subscribe/unsubscribe the event handler
1057 * provided by the user. Resumed signal is emitted when application is resumed
1059 public event DaliEventHandler<object, NUIApplicationResumedEventArgs> Resumed
1065 // Restricted to only one listener
1066 if (_applicationResumeEventHandler == null)
1068 _applicationResumeEventHandler += value;
1070 _applicationResumeEventCallbackDelegate = new NUIApplicationResumeEventCallbackDelegate(OnNUIApplicationResume);
1071 this.ResumeSignal().Connect(_applicationResumeEventCallbackDelegate);
1080 if (_applicationResumeEventHandler != null)
1082 this.ResumeSignal().Disconnect(_applicationResumeEventCallbackDelegate);
1085 _applicationResumeEventHandler -= value;
1090 // Callback for Application ResumeSignal
1091 private void OnNUIApplicationResume(IntPtr data)
1093 if(_applicationResumeEventHandler != null)
1095 NUIApplicationResumedEventArgs e = new NUIApplicationResumedEventArgs();
1096 e.Application = this;
1097 _applicationResumeEventHandler.Invoke(this, e);
1102 * @brief Event for Reset signal which can be used to subscribe/unsubscribe the event handler
1103 * provided by the user. Reset signal is emitted when application is reset
1105 public new event DaliEventHandler<object, NUIApplicationResetEventArgs> Reset
1111 // Restricted to only one listener
1112 if (_applicationResetEventHandler == null)
1114 _applicationResetEventHandler += value;
1116 _applicationResetEventCallbackDelegate = new NUIApplicationResetEventCallbackDelegate(OnNUIApplicationReset);
1117 this.ResetSignal().Connect(_applicationResetEventCallbackDelegate);
1126 if (_applicationResetEventHandler != null)
1128 this.ResetSignal().Disconnect(_applicationResetEventCallbackDelegate);
1131 _applicationResetEventHandler -= value;
1136 // Callback for Application ResetSignal
1137 private void OnNUIApplicationReset(IntPtr data)
1139 if(_applicationResetEventHandler != null)
1141 NUIApplicationResetEventArgs e = new NUIApplicationResetEventArgs();
1142 e.Application = this;
1143 _applicationResetEventHandler.Invoke(this, e);
1148 * @brief Event for Resized signal which can be used to subscribe/unsubscribe the event handler
1149 * provided by the user. Resized signal is emitted when application is resized
1151 public event DaliEventHandler<object, NUIApplicationResizedEventArgs> Resized
1157 // Restricted to only one listener
1158 if (_applicationResizeEventHandler == null)
1160 _applicationResizeEventHandler += value;
1162 _applicationResizeEventCallbackDelegate = new NUIApplicationResizeEventCallbackDelegate(OnNUIApplicationResize);
1163 this.ResizeSignal().Connect(_applicationResizeEventCallbackDelegate);
1172 if (_applicationResizeEventHandler != null)
1174 this.ResizeSignal().Disconnect(_applicationResizeEventCallbackDelegate);
1177 _applicationResizeEventHandler -= value;
1182 // Callback for Application ResizeSignal
1183 private void OnNUIApplicationResize(IntPtr data)
1185 if(_applicationResizeEventHandler != null)
1187 NUIApplicationResizedEventArgs e = new NUIApplicationResizedEventArgs();
1188 e.Application = this;
1189 _applicationResizeEventHandler.Invoke(this, e);
1194 * @brief Event for LanguageChanged signal which can be used to subscribe/unsubscribe the event handler
1195 * provided by the user. LanguageChanged signal is emitted when the region of the device is changed.
1197 public event DaliEventHandler<object, NUIApplicationLanguageChangedEventArgs> LanguageChanged
1203 // Restricted to only one listener
1204 if (_applicationLanguageChangedEventHandler == null)
1206 _applicationLanguageChangedEventHandler += value;
1208 _applicationLanguageChangedEventCallbackDelegate = new NUIApplicationLanguageChangedEventCallbackDelegate(OnNUIApplicationLanguageChanged);
1209 this.LanguageChangedSignal().Connect(_applicationLanguageChangedEventCallbackDelegate);
1218 if (_applicationLanguageChangedEventHandler != null)
1220 this.LanguageChangedSignal().Disconnect(_applicationLanguageChangedEventCallbackDelegate);
1223 _applicationLanguageChangedEventHandler -= value;
1228 // Callback for Application LanguageChangedSignal
1229 private void OnNUIApplicationLanguageChanged(IntPtr data)
1231 if(_applicationLanguageChangedEventHandler != null)
1233 NUIApplicationLanguageChangedEventArgs e = new NUIApplicationLanguageChangedEventArgs();
1234 e.Application = this;
1235 _applicationLanguageChangedEventHandler.Invoke(this, e);
1240 * @brief Event for RegionChanged signal which can be used to subscribe/unsubscribe the event handler
1241 * provided by the user. RegionChanged signal is emitted when the region of the device is changed.
1243 public event DaliEventHandler<object, NUIApplicationRegionChangedEventArgs> RegionChanged
1249 // Restricted to only one listener
1250 if (_applicationRegionChangedEventHandler == null)
1252 _applicationRegionChangedEventHandler += value;
1254 _applicationRegionChangedEventCallbackDelegate = new NUIApplicationRegionChangedEventCallbackDelegate(OnNUIApplicationRegionChanged);
1255 this.RegionChangedSignal().Connect(_applicationRegionChangedEventCallbackDelegate);
1264 if (_applicationRegionChangedEventHandler != null)
1266 this.RegionChangedSignal().Disconnect(_applicationRegionChangedEventCallbackDelegate);
1269 _applicationRegionChangedEventHandler -= value;
1274 // Callback for Application RegionChangedSignal
1275 private void OnNUIApplicationRegionChanged(IntPtr data)
1277 if(_applicationRegionChangedEventHandler != null)
1279 NUIApplicationRegionChangedEventArgs e = new NUIApplicationRegionChangedEventArgs();
1280 e.Application = this;
1281 _applicationRegionChangedEventHandler.Invoke(this, e);
1286 * @brief Event for BatteryLow signal which can be used to subscribe/unsubscribe the event handler
1287 * provided by the user. BatteryLow signal is emitted when the battery level of the device is low.
1289 public event DaliEventHandler<object, NUIApplicationBatteryLowEventArgs> BatteryLow
1295 // Restricted to only one listener
1296 if (_applicationBatteryLowEventHandler == null)
1298 _applicationBatteryLowEventHandler += value;
1300 _applicationBatteryLowEventCallbackDelegate = new NUIApplicationBatteryLowEventCallbackDelegate(OnNUIApplicationBatteryLow);
1301 this.BatteryLowSignal().Connect(_applicationBatteryLowEventCallbackDelegate);
1310 if (_applicationBatteryLowEventHandler != null)
1312 this.BatteryLowSignal().Disconnect(_applicationBatteryLowEventCallbackDelegate);
1315 _applicationBatteryLowEventHandler -= value;
1320 // Callback for Application BatteryLowSignal
1321 private void OnNUIApplicationBatteryLow(BatteryStatus status)
1325 NUIApplicationBatteryLowEventArgs e = new NUIApplicationBatteryLowEventArgs();
1327 // Populate all members of "e" (NUIApplicationBatteryLowEventArgs) with real data
1328 e.BatteryStatus = status;
1329 _applicationBatteryLowEventHandler?.Invoke(this, e);
1334 * @brief Event for MemoryLow signal which can be used to subscribe/unsubscribe the event handler
1335 * provided by the user. MemoryLow signal is emitted when the memory level of the device is low.
1337 public event DaliEventHandler<object, NUIApplicationMemoryLowEventArgs> MemoryLow
1343 // Restricted to only one listener
1344 if (_applicationMemoryLowEventHandler == null)
1346 _applicationMemoryLowEventHandler += value;
1348 _applicationMemoryLowEventCallbackDelegate = new NUIApplicationMemoryLowEventCallbackDelegate(OnNUIApplicationMemoryLow);
1349 this.MemoryLowSignal().Connect(_applicationMemoryLowEventCallbackDelegate);
1358 if (_applicationMemoryLowEventHandler != null)
1360 this.MemoryLowSignal().Disconnect(_applicationMemoryLowEventCallbackDelegate);
1363 _applicationMemoryLowEventHandler -= value;
1368 // Callback for Application MemoryLowSignal
1369 private void OnNUIApplicationMemoryLow(MemoryStatus status)
1373 NUIApplicationMemoryLowEventArgs e = new NUIApplicationMemoryLowEventArgs();
1375 // Populate all members of "e" (NUIApplicationMemoryLowEventArgs) with real data
1376 e.MemoryStatus = status;
1377 _applicationMemoryLowEventHandler?.Invoke(this, e);
1382 * @brief Event for AppControl signal which can be used to subscribe/unsubscribe the event handler
1383 * provided by the user. AppControl signal is emitted when another application sends a launch request to the application.
1385 public event DaliEventHandler<object, NUIApplicationAppControlEventArgs> AppControl
1391 // Restricted to only one listener
1392 if (_applicationAppControlEventHandler == null)
1394 _applicationAppControlEventHandler += value;
1396 _applicationAppControlEventCallbackDelegate = new NUIApplicationAppControlEventCallbackDelegate(OnNUIApplicationAppControl);
1397 this.AppControlSignal().Connect(_applicationAppControlEventCallbackDelegate);
1406 if (_applicationAppControlEventHandler != null)
1408 this.AppControlSignal().Disconnect(_applicationAppControlEventCallbackDelegate);
1411 _applicationAppControlEventHandler -= value;
1416 // Callback for Application AppControlSignal
1417 private void OnNUIApplicationAppControl(IntPtr application, IntPtr voidp)
1419 if(_applicationAppControlEventHandler != null)
1421 NUIApplicationAppControlEventArgs e = new NUIApplicationAppControlEventArgs();
1423 e.Application = this;
1424 _applicationAppControlEventHandler.Invoke(this, e);
1428 private static Application _instance; // singleton
1430 public static Application Instance
1438 public static Application GetApplicationFromPtr(global::System.IntPtr cPtr)
1440 if (cPtr == global::System.IntPtr.Zero)
1445 Application ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Application;
1446 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1450 public static Application NewApplication()
1452 return NewApplication("", Application.WindowMode.Opaque);
1455 public static Application NewApplication(string stylesheet)
1457 return NewApplication(stylesheet, Application.WindowMode.Opaque);
1460 public static Application NewApplication(string stylesheet, Application.WindowMode windowMode)
1462 // register all Views with the type registry, so that can be created / styled via JSON
1463 //ViewRegistryHelper.Initialize(); //moved to Application side.
1465 Application ret = New(1, stylesheet, windowMode);
1466 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1468 // set the singleton
1474 public static Application NewApplication(string[] args, string stylesheet, Application.WindowMode windowMode)
1476 Application ret = New(args, stylesheet, (Application.WindowMode)windowMode);
1477 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1479 // set the singleton
1485 /// Ensures that the function passed in is called from the main loop when it is idle.
1487 /// <param name="func">The function to call</param>
1488 /// <returns>true if added successfully, false otherwise</returns>
1489 public bool AddIdle(System.Delegate func)
1491 System.IntPtr ip = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate<System.Delegate>(func);
1492 System.IntPtr ip2 = NDalicManualPINVOKE.MakeCallback(new System.Runtime.InteropServices.HandleRef(this, ip));
1494 bool ret = NDalicPINVOKE.Application_AddIdle(swigCPtr, new System.Runtime.InteropServices.HandleRef(this, ip2));
1496 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1501 * Outer::outer_method(int)
1503 public static Application New()
1505 Application ret = new Application(NDalicPINVOKE.Application_New__SWIG_0(), true);
1506 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1510 public static Application New(int argc)
1512 Application ret = new Application(NDalicPINVOKE.Application_New__SWIG_1(argc), true);
1513 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1517 public static Application New(int argc, string stylesheet)
1519 Application ret = new Application(NDalicPINVOKE.Application_New__SWIG_2(argc, stylesheet), true);
1520 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1524 public static Application New(int argc, string stylesheet, Application.WindowMode windowMode)
1526 Application ret = new Application(NDalicPINVOKE.Application_New__SWIG_3(argc, stylesheet, (int)windowMode), true);
1527 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1532 public static Application New(string[] args, string stylesheet, Application.WindowMode windowMode)
1534 int argc = args.Length;
1535 string argvStr = string.Join(" ", args);
1537 Application ret = new Application(NDalicPINVOKE.Application_New__MANUAL_4(argc, argvStr, stylesheet, (int)windowMode), true);
1538 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1542 public static Application New(int argc, string stylesheet, Application.WindowMode windowMode, Rectangle positionSize)
1544 Application ret = new Application(NDalicPINVOKE.Application_New__SWIG_4(argc, stylesheet, (int)windowMode, Rectangle.getCPtr(positionSize)), true);
1545 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1549 public Application() : this(NDalicPINVOKE.new_Application__SWIG_0(), true)
1551 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1554 public Application(Application application) : this(NDalicPINVOKE.new_Application__SWIG_1(Application.getCPtr(application)), true)
1556 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1559 public Application Assign(Application application)
1561 Application ret = new Application(NDalicPINVOKE.Application_Assign(swigCPtr, Application.getCPtr(application)), false);
1562 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1566 public void MainLoop()
1568 NDalicPINVOKE.Application_MainLoop__SWIG_0(swigCPtr);
1569 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1572 internal void MainLoop(SWIGTYPE_p_Configuration__ContextLoss configuration)
1574 NDalicPINVOKE.Application_MainLoop__SWIG_1(swigCPtr, SWIGTYPE_p_Configuration__ContextLoss.getCPtr(configuration));
1575 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1580 NDalicPINVOKE.Application_Lower(swigCPtr);
1581 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1586 NDalicPINVOKE.Application_Quit(swigCPtr);
1587 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1590 internal bool AddIdle(SWIGTYPE_p_Dali__CallbackBase callback)
1592 bool ret = NDalicPINVOKE.Application_AddIdle(swigCPtr, SWIGTYPE_p_Dali__CallbackBase.getCPtr(callback));
1593 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1597 public Window GetWindow()
1599 Window ret = new Window(NDalicPINVOKE.Application_GetWindow(swigCPtr), true);
1600 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1604 public void ReplaceWindow(Rectangle windowPosition, string name)
1606 NDalicPINVOKE.Application_ReplaceWindow(swigCPtr, Rectangle.getCPtr(windowPosition), name);
1607 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1610 public static string GetResourcePath()
1612 string ret = NDalicPINVOKE.Application_GetResourcePath();
1613 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1617 internal void SetViewMode(ViewMode viewMode)
1619 NDalicPINVOKE.Application_SetViewMode(swigCPtr, (int)viewMode);
1620 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1623 internal ViewMode GetViewMode()
1625 ViewMode ret = (ViewMode)NDalicPINVOKE.Application_GetViewMode(swigCPtr);
1626 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1630 public void SetStereoBase(float stereoBase)
1632 NDalicPINVOKE.Application_SetStereoBase(swigCPtr, stereoBase);
1633 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1636 public float GetStereoBase()
1638 float ret = NDalicPINVOKE.Application_GetStereoBase(swigCPtr);
1639 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1643 public string GetLanguage()
1645 string ret = NDalicPINVOKE.Application_GetLanguage(swigCPtr);
1646 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1650 public string GetRegion()
1652 string ret = NDalicPINVOKE.Application_GetRegion(swigCPtr);
1653 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1658 internal ApplicationSignal InitSignal()
1660 ApplicationSignal ret = new ApplicationSignal(NDalicPINVOKE.Application_InitSignal(swigCPtr), false);
1661 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1665 internal ApplicationSignal TerminateSignal()
1667 ApplicationSignal ret = new ApplicationSignal(NDalicPINVOKE.Application_TerminateSignal(swigCPtr), false);
1668 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1672 internal ApplicationSignal PauseSignal()
1674 ApplicationSignal ret = new ApplicationSignal(NDalicPINVOKE.Application_PauseSignal(swigCPtr), false);
1675 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1679 internal ApplicationSignal ResumeSignal()
1681 ApplicationSignal ret = new ApplicationSignal(NDalicPINVOKE.Application_ResumeSignal(swigCPtr), false);
1682 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1686 internal ApplicationSignal ResetSignal()
1688 ApplicationSignal ret = new ApplicationSignal(NDalicPINVOKE.Application_ResetSignal(swigCPtr), false);
1689 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1693 internal ApplicationSignal ResizeSignal()
1695 ApplicationSignal ret = new ApplicationSignal(NDalicPINVOKE.Application_ResizeSignal(swigCPtr), false);
1696 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1700 internal ApplicationControlSignal AppControlSignal()
1702 ApplicationControlSignal ret = new ApplicationControlSignal(NDalicPINVOKE.Application_AppControlSignal(swigCPtr), false);
1703 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1707 internal ApplicationSignal LanguageChangedSignal()
1709 ApplicationSignal ret = new ApplicationSignal(NDalicPINVOKE.Application_LanguageChangedSignal(swigCPtr), false);
1710 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1714 internal ApplicationSignal RegionChangedSignal()
1716 ApplicationSignal ret = new ApplicationSignal(NDalicPINVOKE.Application_RegionChangedSignal(swigCPtr), false);
1717 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1721 internal LowBatterySignalType BatteryLowSignal()
1723 LowBatterySignalType ret = new LowBatterySignalType(NDalicPINVOKE.Application_LowBatterySignal(swigCPtr), false);
1724 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1728 internal LowMemorySignalType MemoryLowSignal()
1730 LowMemorySignalType ret = new LowMemorySignalType(NDalicPINVOKE.Application_LowMemorySignal(swigCPtr), false);
1731 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1735 /// <since_tizen> 3 </since_tizen>
1736 public enum WindowMode