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.
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
313 /// A class to get resources in current application.
315 public class GetResourcesProvider
318 /// Get resources in current application.
320 static public IResourcesProvider Get()
322 return Tizen.NUI.Application.Current;
326 internal class Application : BaseHandle, IResourcesProvider, IApplicationController, IElementConfiguration<Application>
328 static Application s_current;
329 Task<IDictionary<string, object>> _propertiesTask;
330 readonly Lazy<PlatformConfigurationRegistry<Application>> _platformConfigurationRegistry;
332 IAppIndexingProvider _appIndexProvider;
334 ReadOnlyCollection<Element> _logicalChildren;
338 static SemaphoreSlim SaveSemaphore = new SemaphoreSlim(1, 1);
340 public IAppLinks AppLinks
344 if (_appIndexProvider == null)
345 throw new ArgumentException("No IAppIndexingProvider was provided");
346 if (_appIndexProvider.AppLinks == null)
347 throw new ArgumentException("No AppLinks implementation was found, if in Android make sure you installed the Xamarin.Forms.AppLinks");
348 return _appIndexProvider.AppLinks;
352 [EditorBrowsable(EditorBrowsableState.Never)]
353 public static void SetCurrentApplication(Application value) => Current = value;
355 public static Application Current
357 get { return s_current; }
360 if (s_current == value)
363 s_current = null; //Allow to reset current for unittesting
370 get { return _mainPage; }
374 throw new ArgumentNullException("value");
376 if (_mainPage == value)
379 OnPropertyChanging();
380 if (_mainPage != null)
382 InternalChildren.Remove(_mainPage);
383 _mainPage.Parent = null;
388 if (_mainPage != null)
390 _mainPage.Parent = this;
391 _mainPage.NavigationProxy.Inner = NavigationProxy;
392 InternalChildren.Add(_mainPage);
398 public IDictionary<string, object> Properties
402 if (_propertiesTask == null)
404 _propertiesTask = GetPropertiesAsync();
407 return _propertiesTask.Result;
411 internal override ReadOnlyCollection<Element> LogicalChildrenInternal
413 get { return _logicalChildren ?? (_logicalChildren = new ReadOnlyCollection<Element>(InternalChildren)); }
416 [EditorBrowsable(EditorBrowsableState.Never)]
417 public new NavigationProxy NavigationProxy { get; }
419 [EditorBrowsable(EditorBrowsableState.Never)]
420 public int PanGestureId { get; set; }
422 internal IResourceDictionary SystemResources { get; }
424 ObservableCollection<Element> InternalChildren { get; } = new ObservableCollection<Element>();
426 [EditorBrowsable(EditorBrowsableState.Never)]
427 public void SetAppIndexingProvider(IAppIndexingProvider provider)
429 _appIndexProvider = provider;
432 ResourceDictionary _resources;
433 public bool IsResourcesCreated => _resources != null;
435 public delegate void resChangeCb(object sender, ResourcesChangedEventArgs e);
437 static private Dictionary<object, Dictionary<resChangeCb, int>> resourceChangeCallbackDict = new Dictionary<object, Dictionary<resChangeCb, int>>();
438 static public void AddResourceChangedCallback(object handle, resChangeCb cb)
440 Dictionary<resChangeCb, int> cbDict;
441 resourceChangeCallbackDict.TryGetValue(handle, out cbDict);
445 cbDict = new Dictionary<resChangeCb, int>();
446 resourceChangeCallbackDict.Add(handle, cbDict);
449 if (false == cbDict.ContainsKey(cb))
455 internal override void OnResourcesChanged(object sender, ResourcesChangedEventArgs e)
457 base.OnResourcesChanged(sender, e);
459 foreach (KeyValuePair<object, Dictionary<resChangeCb, int>> resourcePair in resourceChangeCallbackDict)
461 foreach (KeyValuePair<resChangeCb, int> cbPair in resourcePair.Value)
463 cbPair.Key(sender, e);
468 public ResourceDictionary XamlResources
472 if (_resources != null)
475 _resources = new ResourceDictionary();
476 int hashCode = _resources.GetHashCode();
477 ((IResourceDictionary)_resources).ValuesChanged += OnResourcesChanged;
482 if (_resources == value)
484 OnPropertyChanging();
486 if (_resources != null)
487 ((IResourceDictionary)_resources).ValuesChanged -= OnResourcesChanged;
489 OnResourcesChanged(value);
490 if (_resources != null)
491 ((IResourceDictionary)_resources).ValuesChanged += OnResourcesChanged;
497 public event EventHandler<ModalPoppedEventArgs> ModalPopped;
499 public event EventHandler<ModalPoppingEventArgs> ModalPopping;
501 public event EventHandler<ModalPushedEventArgs> ModalPushed;
503 public event EventHandler<ModalPushingEventArgs> ModalPushing;
505 public event EventHandler<Page> PageAppearing;
507 public event EventHandler<Page> PageDisappearing;
510 async void SaveProperties()
514 await SetPropertiesAsync();
516 catch (Exception exc)
518 Console.WriteLine(nameof(Application), $"Exception while saving Application Properties: {exc}");
522 public async Task SavePropertiesAsync()
524 if (Device.IsInvokeRequired)
526 Device.BeginInvokeOnMainThread(SaveProperties);
530 await SetPropertiesAsync();
534 // Don't use this unless there really is no better option
535 internal void SavePropertiesAsFireAndForget()
537 if (Device.IsInvokeRequired)
539 Device.BeginInvokeOnMainThread(SaveProperties);
547 public IPlatformElementConfiguration<T, Application> On<T>() where T : IConfigPlatform
549 return _platformConfigurationRegistry.Value.On<T>();
552 protected virtual void OnAppLinkRequestReceived(Uri uri)
556 protected override void OnParentSet()
558 throw new InvalidOperationException("Setting a Parent on Application is invalid.");
561 protected virtual void OnResume()
565 protected virtual void OnSleep()
569 protected virtual void OnStart()
573 [EditorBrowsable(EditorBrowsableState.Never)]
574 public static void ClearCurrent()
579 [EditorBrowsable(EditorBrowsableState.Never)]
580 public static bool IsApplicationOrNull(Element element)
582 return element == null || element is Application;
585 internal override void OnParentResourcesChanged(IEnumerable<KeyValuePair<string, object>> values)
587 if (!((IResourcesProvider)this).IsResourcesCreated || XamlResources.Count == 0)
589 base.OnParentResourcesChanged(values);
593 var innerKeys = new HashSet<string>();
594 var changedResources = new List<KeyValuePair<string, object>>();
595 foreach (KeyValuePair<string, object> c in XamlResources)
596 innerKeys.Add(c.Key);
597 foreach (KeyValuePair<string, object> value in values)
599 if (innerKeys.Add(value.Key))
600 changedResources.Add(value);
602 OnResourcesChanged(changedResources);
605 internal event EventHandler PopCanceled;
607 [EditorBrowsable(EditorBrowsableState.Never)]
608 public void SendOnAppLinkRequestReceived(Uri uri)
610 OnAppLinkRequestReceived(uri);
613 [EditorBrowsable(EditorBrowsableState.Never)]
614 public void SendResume()
620 [EditorBrowsable(EditorBrowsableState.Never)]
621 public void SendSleep()
624 SavePropertiesAsFireAndForget();
627 [EditorBrowsable(EditorBrowsableState.Never)]
628 public Task SendSleepAsync()
631 return SavePropertiesAsync();
634 [EditorBrowsable(EditorBrowsableState.Never)]
635 public void SendStart()
640 async Task<IDictionary<string, object>> GetPropertiesAsync()
642 var deserializer = DependencyService.Get<IDeserializer>();
643 if (deserializer == null)
645 Console.WriteLine("Startup", "No IDeserialzier was found registered");
646 return new Dictionary<string, object>(4);
649 IDictionary<string, object> properties = await deserializer.DeserializePropertiesAsync().ConfigureAwait(false);
650 if (properties == null)
651 properties = new Dictionary<string, object>(4);
656 internal void OnPageAppearing(Page page)
657 => PageAppearing?.Invoke(this, page);
659 internal void OnPageDisappearing(Page page)
660 => PageDisappearing?.Invoke(this, page);
662 void OnModalPopped(Page modalPage)
663 => ModalPopped?.Invoke(this, new ModalPoppedEventArgs(modalPage));
665 bool OnModalPopping(Page modalPage)
667 var args = new ModalPoppingEventArgs(modalPage);
668 ModalPopping?.Invoke(this, args);
672 void OnModalPushed(Page modalPage)
673 => ModalPushed?.Invoke(this, new ModalPushedEventArgs(modalPage));
675 void OnModalPushing(Page modalPage)
676 => ModalPushing?.Invoke(this, new ModalPushingEventArgs(modalPage));
679 => PopCanceled?.Invoke(this, EventArgs.Empty);
681 async Task SetPropertiesAsync()
683 await SaveSemaphore.WaitAsync();
686 await DependencyService.Get<IDeserializer>()?.SerializePropertiesAsync(Properties);
690 SaveSemaphore.Release();
695 class NavigationImpl : NavigationProxy
697 readonly Application _owner;
699 public NavigationImpl(Application owner)
704 protected override async Task<Page> OnPopModal(bool animated)
706 Page modal = ModalStack[ModalStack.Count - 1];
707 if (_owner.OnModalPopping(modal))
709 _owner.OnPopCanceled();
712 Page result = await base.OnPopModal(animated);
713 result.Parent = null;
714 _owner.OnModalPopped(result);
718 protected override async Task OnPushModal(Page modal, bool animated)
720 _owner.OnModalPushing(modal);
722 modal.Parent = _owner;
724 if (modal.NavigationProxy.ModalStack.Count == 0)
726 modal.NavigationProxy.Inner = this;
727 await base.OnPushModal(modal, animated);
731 await base.OnPushModal(modal, animated);
732 modal.NavigationProxy.Inner = this;
735 _owner.OnModalPushed(modal);
739 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
741 internal Application(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.Application_SWIGUpcast(cPtr), cMemoryOwn)
743 NavigationProxy = new NavigationImpl(this);
744 SetCurrentApplication(this);
746 _platformConfigurationRegistry = new Lazy<PlatformConfigurationRegistry<Application>>(() => new PlatformConfigurationRegistry<Application>(this));
747 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
752 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Application obj)
754 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
757 protected override void Dispose(DisposeTypes type)
764 if (type == DisposeTypes.Explicit)
767 //Release your own managed resources here.
768 //You should release all of your own disposable objects here.
772 //Release your own unmanaged resources here.
773 //You should not access any managed member here except static instance.
774 //because the execution order of Finalizes is non-deterministic.
776 if (_applicationInitEventCallbackDelegate != null)
778 this.InitSignal().Disconnect(_applicationInitEventCallbackDelegate);
781 if (_applicationTerminateEventCallbackDelegate != null)
783 this.TerminateSignal().Disconnect(_applicationTerminateEventCallbackDelegate);
786 if (_applicationPauseEventCallbackDelegate != null)
788 this.PauseSignal().Disconnect(_applicationPauseEventCallbackDelegate);
791 if (_applicationResumeEventCallbackDelegate != null)
793 this.ResumeSignal().Disconnect(_applicationResumeEventCallbackDelegate);
796 if (_applicationResetEventCallbackDelegate != null)
798 this.ResetSignal().Disconnect(_applicationResetEventCallbackDelegate);
801 if (_applicationResizeEventCallbackDelegate != null)
803 this.ResizeSignal().Disconnect(_applicationResizeEventCallbackDelegate);
806 if (_applicationLanguageChangedEventCallbackDelegate != null)
808 this.LanguageChangedSignal().Disconnect(_applicationLanguageChangedEventCallbackDelegate);
811 if (_applicationRegionChangedEventCallbackDelegate != null)
813 this.RegionChangedSignal().Disconnect(_applicationRegionChangedEventCallbackDelegate);
816 if (_applicationBatteryLowEventCallbackDelegate != null)
818 this.BatteryLowSignal().Disconnect(_applicationBatteryLowEventCallbackDelegate);
821 if (_applicationMemoryLowEventCallbackDelegate != null)
823 this.MemoryLowSignal().Disconnect(_applicationMemoryLowEventCallbackDelegate);
826 if (_applicationAppControlEventCallbackDelegate != null)
828 this.AppControlSignal().Disconnect(_applicationAppControlEventCallbackDelegate);
831 if (swigCPtr.Handle != global::System.IntPtr.Zero)
836 NDalicPINVOKE.delete_Application(swigCPtr);
838 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
844 /// <since_tizen> 4 </since_tizen>
845 public enum BatteryStatus
852 /// <since_tizen> 4 </since_tizen>
853 public enum MemoryStatus
860 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
861 private delegate void NUIApplicationInitEventCallbackDelegate(IntPtr application);
862 private DaliEventHandler<object, NUIApplicationInitEventArgs> _applicationInitEventHandler;
863 private NUIApplicationInitEventCallbackDelegate _applicationInitEventCallbackDelegate;
866 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
867 private delegate void NUIApplicationTerminateEventCallbackDelegate(IntPtr application);
868 private DaliEventHandler<object, NUIApplicationTerminatingEventArgs> _applicationTerminateEventHandler;
869 private NUIApplicationTerminateEventCallbackDelegate _applicationTerminateEventCallbackDelegate;
872 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
873 private delegate void NUIApplicationPauseEventCallbackDelegate(IntPtr application);
874 private DaliEventHandler<object, NUIApplicationPausedEventArgs> _applicationPauseEventHandler;
875 private NUIApplicationPauseEventCallbackDelegate _applicationPauseEventCallbackDelegate;
877 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
878 private delegate void NUIApplicationResumeEventCallbackDelegate(IntPtr application);
879 private DaliEventHandler<object, NUIApplicationResumedEventArgs> _applicationResumeEventHandler;
880 private NUIApplicationResumeEventCallbackDelegate _applicationResumeEventCallbackDelegate;
882 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
883 private delegate void NUIApplicationResetEventCallbackDelegate(IntPtr application);
884 private DaliEventHandler<object, NUIApplicationResetEventArgs> _applicationResetEventHandler;
885 private NUIApplicationResetEventCallbackDelegate _applicationResetEventCallbackDelegate;
887 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
888 private delegate void NUIApplicationResizeEventCallbackDelegate(IntPtr application);
889 private DaliEventHandler<object, NUIApplicationResizedEventArgs> _applicationResizeEventHandler;
890 private NUIApplicationResizeEventCallbackDelegate _applicationResizeEventCallbackDelegate;
892 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
893 private delegate void NUIApplicationLanguageChangedEventCallbackDelegate(IntPtr application);
894 private DaliEventHandler<object, NUIApplicationLanguageChangedEventArgs> _applicationLanguageChangedEventHandler;
895 private NUIApplicationLanguageChangedEventCallbackDelegate _applicationLanguageChangedEventCallbackDelegate;
898 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
899 private delegate void NUIApplicationRegionChangedEventCallbackDelegate(IntPtr application);
900 private DaliEventHandler<object, NUIApplicationRegionChangedEventArgs> _applicationRegionChangedEventHandler;
901 private NUIApplicationRegionChangedEventCallbackDelegate _applicationRegionChangedEventCallbackDelegate;
903 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
904 private delegate void NUIApplicationBatteryLowEventCallbackDelegate(BatteryStatus status);
905 private DaliEventHandler<object, NUIApplicationBatteryLowEventArgs> _applicationBatteryLowEventHandler;
906 private NUIApplicationBatteryLowEventCallbackDelegate _applicationBatteryLowEventCallbackDelegate;
908 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
909 private delegate void NUIApplicationMemoryLowEventCallbackDelegate(MemoryStatus status);
910 private DaliEventHandler<object, NUIApplicationMemoryLowEventArgs> _applicationMemoryLowEventHandler;
911 private NUIApplicationMemoryLowEventCallbackDelegate _applicationMemoryLowEventCallbackDelegate;
913 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
914 private delegate void NUIApplicationAppControlEventCallbackDelegate(IntPtr application, IntPtr voidp);
915 private DaliEventHandler<object, NUIApplicationAppControlEventArgs> _applicationAppControlEventHandler;
916 private NUIApplicationAppControlEventCallbackDelegate _applicationAppControlEventCallbackDelegate;
919 * @brief Event for Initialized signal which can be used to subscribe/unsubscribe the event handler
920 * provided by the user. Initialized signal is emitted when application is initialised
922 public event DaliEventHandler<object, NUIApplicationInitEventArgs> Initialized
928 // Restricted to only one listener
929 if (_applicationInitEventHandler == null)
931 _applicationInitEventHandler += value;
933 _applicationInitEventCallbackDelegate = new NUIApplicationInitEventCallbackDelegate(OnApplicationInit);
934 this.InitSignal().Connect(_applicationInitEventCallbackDelegate);
943 if (_applicationInitEventHandler != null)
945 this.InitSignal().Disconnect(_applicationInitEventCallbackDelegate);
948 _applicationInitEventHandler -= value;
953 // Callback for Application InitSignal
954 private void OnApplicationInit(IntPtr data)
956 // Initialize DisposeQueue Singleton class. This is also required to create DisposeQueue on main thread.
957 DisposeQueue.Instance.Initialize();
959 if (_applicationInitEventHandler != null)
961 NUIApplicationInitEventArgs e = new NUIApplicationInitEventArgs();
962 e.Application = this;
963 _applicationInitEventHandler.Invoke(this, e);
969 * @brief Event for Terminated signal which can be used to subscribe/unsubscribe the event handler
970 * provided by the user. Terminated signal is emitted when application is terminating
972 public event DaliEventHandler<object, NUIApplicationTerminatingEventArgs> Terminating
978 // Restricted to only one listener
979 if (_applicationTerminateEventHandler == null)
981 _applicationTerminateEventHandler += value;
983 _applicationTerminateEventCallbackDelegate = new NUIApplicationTerminateEventCallbackDelegate(OnNUIApplicationTerminate);
984 this.TerminateSignal().Connect(_applicationTerminateEventCallbackDelegate);
993 if (_applicationTerminateEventHandler != null)
995 this.TerminateSignal().Disconnect(_applicationTerminateEventCallbackDelegate);
998 _applicationTerminateEventHandler -= value;
1003 // Callback for Application TerminateSignal
1004 private void OnNUIApplicationTerminate(IntPtr data)
1006 if (_applicationTerminateEventHandler != null)
1008 NUIApplicationTerminatingEventArgs e = new NUIApplicationTerminatingEventArgs();
1009 e.Application = this;
1010 _applicationTerminateEventHandler.Invoke(this, e);
1013 Window.Instance.DisconnectNativeSignals();
1017 * @brief Event for Paused signal which can be used to subscribe/unsubscribe the event handler
1018 * provided by the user. Paused signal is emitted when application is paused
1020 public event DaliEventHandler<object, NUIApplicationPausedEventArgs> Paused
1026 // Restricted to only one listener
1027 if (_applicationPauseEventHandler == null)
1029 _applicationPauseEventHandler += value;
1031 _applicationPauseEventCallbackDelegate = new NUIApplicationPauseEventCallbackDelegate(OnNUIApplicationPause);
1032 this.PauseSignal().Connect(_applicationPauseEventCallbackDelegate);
1041 if (_applicationPauseEventHandler != null)
1043 this.PauseSignal().Disconnect(_applicationPauseEventCallbackDelegate);
1046 _applicationPauseEventHandler -= value;
1051 // Callback for Application PauseSignal
1052 private void OnNUIApplicationPause(IntPtr data)
1054 if (_applicationPauseEventHandler != null)
1056 NUIApplicationPausedEventArgs e = new NUIApplicationPausedEventArgs();
1057 e.Application = this;
1058 _applicationPauseEventHandler.Invoke(this, e);
1063 * @brief Event for Resumed signal which can be used to subscribe/unsubscribe the event handler
1064 * provided by the user. Resumed signal is emitted when application is resumed
1066 public event DaliEventHandler<object, NUIApplicationResumedEventArgs> Resumed
1072 // Restricted to only one listener
1073 if (_applicationResumeEventHandler == null)
1075 _applicationResumeEventHandler += value;
1077 _applicationResumeEventCallbackDelegate = new NUIApplicationResumeEventCallbackDelegate(OnNUIApplicationResume);
1078 this.ResumeSignal().Connect(_applicationResumeEventCallbackDelegate);
1087 if (_applicationResumeEventHandler != null)
1089 this.ResumeSignal().Disconnect(_applicationResumeEventCallbackDelegate);
1092 _applicationResumeEventHandler -= value;
1097 // Callback for Application ResumeSignal
1098 private void OnNUIApplicationResume(IntPtr data)
1100 if (_applicationResumeEventHandler != null)
1102 NUIApplicationResumedEventArgs e = new NUIApplicationResumedEventArgs();
1103 e.Application = this;
1104 _applicationResumeEventHandler.Invoke(this, e);
1109 * @brief Event for Reset signal which can be used to subscribe/unsubscribe the event handler
1110 * provided by the user. Reset signal is emitted when application is reset
1112 public new event DaliEventHandler<object, NUIApplicationResetEventArgs> Reset
1118 // Restricted to only one listener
1119 if (_applicationResetEventHandler == null)
1121 _applicationResetEventHandler += value;
1123 _applicationResetEventCallbackDelegate = new NUIApplicationResetEventCallbackDelegate(OnNUIApplicationReset);
1124 this.ResetSignal().Connect(_applicationResetEventCallbackDelegate);
1133 if (_applicationResetEventHandler != null)
1135 this.ResetSignal().Disconnect(_applicationResetEventCallbackDelegate);
1138 _applicationResetEventHandler -= value;
1143 // Callback for Application ResetSignal
1144 private void OnNUIApplicationReset(IntPtr data)
1146 if (_applicationResetEventHandler != null)
1148 NUIApplicationResetEventArgs e = new NUIApplicationResetEventArgs();
1149 e.Application = this;
1150 _applicationResetEventHandler.Invoke(this, e);
1155 * @brief Event for Resized signal which can be used to subscribe/unsubscribe the event handler
1156 * provided by the user. Resized signal is emitted when application is resized
1158 public event DaliEventHandler<object, NUIApplicationResizedEventArgs> Resized
1164 // Restricted to only one listener
1165 if (_applicationResizeEventHandler == null)
1167 _applicationResizeEventHandler += value;
1169 _applicationResizeEventCallbackDelegate = new NUIApplicationResizeEventCallbackDelegate(OnNUIApplicationResize);
1170 this.ResizeSignal().Connect(_applicationResizeEventCallbackDelegate);
1179 if (_applicationResizeEventHandler != null)
1181 this.ResizeSignal().Disconnect(_applicationResizeEventCallbackDelegate);
1184 _applicationResizeEventHandler -= value;
1189 // Callback for Application ResizeSignal
1190 private void OnNUIApplicationResize(IntPtr data)
1192 if (_applicationResizeEventHandler != null)
1194 NUIApplicationResizedEventArgs e = new NUIApplicationResizedEventArgs();
1195 e.Application = this;
1196 _applicationResizeEventHandler.Invoke(this, e);
1201 * @brief Event for LanguageChanged signal which can be used to subscribe/unsubscribe the event handler
1202 * provided by the user. LanguageChanged signal is emitted when the region of the device is changed.
1204 public event DaliEventHandler<object, NUIApplicationLanguageChangedEventArgs> LanguageChanged
1210 // Restricted to only one listener
1211 if (_applicationLanguageChangedEventHandler == null)
1213 _applicationLanguageChangedEventHandler += value;
1215 _applicationLanguageChangedEventCallbackDelegate = new NUIApplicationLanguageChangedEventCallbackDelegate(OnNUIApplicationLanguageChanged);
1216 this.LanguageChangedSignal().Connect(_applicationLanguageChangedEventCallbackDelegate);
1225 if (_applicationLanguageChangedEventHandler != null)
1227 this.LanguageChangedSignal().Disconnect(_applicationLanguageChangedEventCallbackDelegate);
1230 _applicationLanguageChangedEventHandler -= value;
1235 // Callback for Application LanguageChangedSignal
1236 private void OnNUIApplicationLanguageChanged(IntPtr data)
1238 if (_applicationLanguageChangedEventHandler != null)
1240 NUIApplicationLanguageChangedEventArgs e = new NUIApplicationLanguageChangedEventArgs();
1241 e.Application = this;
1242 _applicationLanguageChangedEventHandler.Invoke(this, e);
1247 * @brief Event for RegionChanged signal which can be used to subscribe/unsubscribe the event handler
1248 * provided by the user. RegionChanged signal is emitted when the region of the device is changed.
1250 public event DaliEventHandler<object, NUIApplicationRegionChangedEventArgs> RegionChanged
1256 // Restricted to only one listener
1257 if (_applicationRegionChangedEventHandler == null)
1259 _applicationRegionChangedEventHandler += value;
1261 _applicationRegionChangedEventCallbackDelegate = new NUIApplicationRegionChangedEventCallbackDelegate(OnNUIApplicationRegionChanged);
1262 this.RegionChangedSignal().Connect(_applicationRegionChangedEventCallbackDelegate);
1271 if (_applicationRegionChangedEventHandler != null)
1273 this.RegionChangedSignal().Disconnect(_applicationRegionChangedEventCallbackDelegate);
1276 _applicationRegionChangedEventHandler -= value;
1281 // Callback for Application RegionChangedSignal
1282 private void OnNUIApplicationRegionChanged(IntPtr data)
1284 if (_applicationRegionChangedEventHandler != null)
1286 NUIApplicationRegionChangedEventArgs e = new NUIApplicationRegionChangedEventArgs();
1287 e.Application = this;
1288 _applicationRegionChangedEventHandler.Invoke(this, e);
1293 * @brief Event for BatteryLow signal which can be used to subscribe/unsubscribe the event handler
1294 * provided by the user. BatteryLow signal is emitted when the battery level of the device is low.
1296 public event DaliEventHandler<object, NUIApplicationBatteryLowEventArgs> BatteryLow
1302 // Restricted to only one listener
1303 if (_applicationBatteryLowEventHandler == null)
1305 _applicationBatteryLowEventHandler += value;
1307 _applicationBatteryLowEventCallbackDelegate = new NUIApplicationBatteryLowEventCallbackDelegate(OnNUIApplicationBatteryLow);
1308 this.BatteryLowSignal().Connect(_applicationBatteryLowEventCallbackDelegate);
1317 if (_applicationBatteryLowEventHandler != null)
1319 this.BatteryLowSignal().Disconnect(_applicationBatteryLowEventCallbackDelegate);
1322 _applicationBatteryLowEventHandler -= value;
1327 // Callback for Application BatteryLowSignal
1328 private void OnNUIApplicationBatteryLow(BatteryStatus status)
1332 NUIApplicationBatteryLowEventArgs e = new NUIApplicationBatteryLowEventArgs();
1334 // Populate all members of "e" (NUIApplicationBatteryLowEventArgs) with real data
1335 e.BatteryStatus = status;
1336 _applicationBatteryLowEventHandler?.Invoke(this, e);
1341 * @brief Event for MemoryLow signal which can be used to subscribe/unsubscribe the event handler
1342 * provided by the user. MemoryLow signal is emitted when the memory level of the device is low.
1344 public event DaliEventHandler<object, NUIApplicationMemoryLowEventArgs> MemoryLow
1350 // Restricted to only one listener
1351 if (_applicationMemoryLowEventHandler == null)
1353 _applicationMemoryLowEventHandler += value;
1355 _applicationMemoryLowEventCallbackDelegate = new NUIApplicationMemoryLowEventCallbackDelegate(OnNUIApplicationMemoryLow);
1356 this.MemoryLowSignal().Connect(_applicationMemoryLowEventCallbackDelegate);
1365 if (_applicationMemoryLowEventHandler != null)
1367 this.MemoryLowSignal().Disconnect(_applicationMemoryLowEventCallbackDelegate);
1370 _applicationMemoryLowEventHandler -= value;
1375 // Callback for Application MemoryLowSignal
1376 private void OnNUIApplicationMemoryLow(MemoryStatus status)
1380 NUIApplicationMemoryLowEventArgs e = new NUIApplicationMemoryLowEventArgs();
1382 // Populate all members of "e" (NUIApplicationMemoryLowEventArgs) with real data
1383 e.MemoryStatus = status;
1384 _applicationMemoryLowEventHandler?.Invoke(this, e);
1389 * @brief Event for AppControl signal which can be used to subscribe/unsubscribe the event handler
1390 * provided by the user. AppControl signal is emitted when another application sends a launch request to the application.
1392 public event DaliEventHandler<object, NUIApplicationAppControlEventArgs> AppControl
1398 // Restricted to only one listener
1399 if (_applicationAppControlEventHandler == null)
1401 _applicationAppControlEventHandler += value;
1403 _applicationAppControlEventCallbackDelegate = new NUIApplicationAppControlEventCallbackDelegate(OnNUIApplicationAppControl);
1404 this.AppControlSignal().Connect(_applicationAppControlEventCallbackDelegate);
1413 if (_applicationAppControlEventHandler != null)
1415 this.AppControlSignal().Disconnect(_applicationAppControlEventCallbackDelegate);
1418 _applicationAppControlEventHandler -= value;
1423 // Callback for Application AppControlSignal
1424 private void OnNUIApplicationAppControl(IntPtr application, IntPtr voidp)
1426 if (_applicationAppControlEventHandler != null)
1428 NUIApplicationAppControlEventArgs e = new NUIApplicationAppControlEventArgs();
1430 e.Application = this;
1431 _applicationAppControlEventHandler.Invoke(this, e);
1435 private static Application _instance; // singleton
1437 public static Application Instance
1445 public static Application GetApplicationFromPtr(global::System.IntPtr cPtr)
1447 if (cPtr == global::System.IntPtr.Zero)
1452 Application ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Application;
1453 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1457 public static Application NewApplication()
1459 return NewApplication("", Application.WindowMode.Opaque);
1462 public static Application NewApplication(string stylesheet)
1464 return NewApplication(stylesheet, Application.WindowMode.Opaque);
1467 public static Application NewApplication(string stylesheet, Application.WindowMode windowMode)
1469 // register all Views with the type registry, so that can be created / styled via JSON
1470 //ViewRegistryHelper.Initialize(); //moved to Application side.
1472 Application ret = New(1, stylesheet, windowMode);
1473 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1475 // set the singleton
1481 public static Application NewApplication(string[] args, string stylesheet, Application.WindowMode windowMode)
1483 Application ret = New(args, stylesheet, (Application.WindowMode)windowMode);
1484 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1486 // set the singleton
1492 /// Ensures that the function passed in is called from the main loop when it is idle.
1494 /// <param name="func">The function to call</param>
1495 /// <returns>true if added successfully, false otherwise</returns>
1496 public bool AddIdle(System.Delegate func)
1498 System.IntPtr ip = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate<System.Delegate>(func);
1499 System.IntPtr ip2 = NDalicManualPINVOKE.MakeCallback(new System.Runtime.InteropServices.HandleRef(this, ip));
1501 bool ret = NDalicPINVOKE.Application_AddIdle(swigCPtr, new System.Runtime.InteropServices.HandleRef(this, ip2));
1503 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1508 * Outer::outer_method(int)
1510 public static Application New()
1512 Application ret = new Application(NDalicPINVOKE.Application_New__SWIG_0(), true);
1513 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1517 public static Application New(int argc)
1519 Application ret = new Application(NDalicPINVOKE.Application_New__SWIG_1(argc), true);
1520 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1524 public static Application New(int argc, string stylesheet)
1526 Application ret = new Application(NDalicPINVOKE.Application_New__SWIG_2(argc, stylesheet), true);
1527 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1531 public static Application New(int argc, string stylesheet, Application.WindowMode windowMode)
1533 Application ret = new Application(NDalicPINVOKE.Application_New__SWIG_3(argc, stylesheet, (int)windowMode), true);
1534 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1539 public static Application New(string[] args, string stylesheet, Application.WindowMode windowMode)
1541 int argc = args.Length;
1542 string argvStr = string.Join(" ", args);
1544 Application ret = new Application(NDalicPINVOKE.Application_New__MANUAL_4(argc, argvStr, stylesheet, (int)windowMode), true);
1545 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1549 public static Application New(int argc, string stylesheet, Application.WindowMode windowMode, Rectangle positionSize)
1551 Application ret = new Application(NDalicPINVOKE.Application_New__SWIG_4(argc, stylesheet, (int)windowMode, Rectangle.getCPtr(positionSize)), true);
1552 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1556 public Application() : this(NDalicPINVOKE.new_Application__SWIG_0(), true)
1558 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1561 public Application(Application application) : this(NDalicPINVOKE.new_Application__SWIG_1(Application.getCPtr(application)), true)
1563 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1566 public Application Assign(Application application)
1568 Application ret = new Application(NDalicPINVOKE.Application_Assign(swigCPtr, Application.getCPtr(application)), false);
1569 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1573 public void MainLoop()
1575 NDalicPINVOKE.Application_MainLoop__SWIG_0(swigCPtr);
1576 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1579 internal void MainLoop(SWIGTYPE_p_Configuration__ContextLoss configuration)
1581 NDalicPINVOKE.Application_MainLoop__SWIG_1(swigCPtr, SWIGTYPE_p_Configuration__ContextLoss.getCPtr(configuration));
1582 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1587 NDalicPINVOKE.Application_Lower(swigCPtr);
1588 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1593 NDalicPINVOKE.Application_Quit(swigCPtr);
1594 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1597 internal bool AddIdle(SWIGTYPE_p_Dali__CallbackBase callback)
1599 bool ret = NDalicPINVOKE.Application_AddIdle(swigCPtr, SWIGTYPE_p_Dali__CallbackBase.getCPtr(callback));
1600 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1604 public Window GetWindow()
1606 Window ret = new Window(NDalicPINVOKE.Application_GetWindow(swigCPtr), true);
1607 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1611 public void ReplaceWindow(Rectangle windowPosition, string name)
1613 NDalicPINVOKE.Application_ReplaceWindow(swigCPtr, Rectangle.getCPtr(windowPosition), name);
1614 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1617 public static string GetResourcePath()
1619 string ret = NDalicPINVOKE.Application_GetResourcePath();
1620 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1624 public string GetLanguage()
1626 string ret = NDalicPINVOKE.Application_GetLanguage(swigCPtr);
1627 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1631 public string GetRegion()
1633 string ret = NDalicPINVOKE.Application_GetRegion(swigCPtr);
1634 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1639 internal ApplicationSignal InitSignal()
1641 ApplicationSignal ret = new ApplicationSignal(NDalicPINVOKE.Application_InitSignal(swigCPtr), false);
1642 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1646 internal ApplicationSignal TerminateSignal()
1648 ApplicationSignal ret = new ApplicationSignal(NDalicPINVOKE.Application_TerminateSignal(swigCPtr), false);
1649 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1653 internal ApplicationSignal PauseSignal()
1655 ApplicationSignal ret = new ApplicationSignal(NDalicPINVOKE.Application_PauseSignal(swigCPtr), false);
1656 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1660 internal ApplicationSignal ResumeSignal()
1662 ApplicationSignal ret = new ApplicationSignal(NDalicPINVOKE.Application_ResumeSignal(swigCPtr), false);
1663 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1667 internal ApplicationSignal ResetSignal()
1669 ApplicationSignal ret = new ApplicationSignal(NDalicPINVOKE.Application_ResetSignal(swigCPtr), false);
1670 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1674 internal ApplicationSignal ResizeSignal()
1676 ApplicationSignal ret = new ApplicationSignal(NDalicPINVOKE.Application_ResizeSignal(swigCPtr), false);
1677 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1681 internal ApplicationControlSignal AppControlSignal()
1683 ApplicationControlSignal ret = new ApplicationControlSignal(NDalicPINVOKE.Application_AppControlSignal(swigCPtr), false);
1684 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1688 internal ApplicationSignal LanguageChangedSignal()
1690 ApplicationSignal ret = new ApplicationSignal(NDalicPINVOKE.Application_LanguageChangedSignal(swigCPtr), false);
1691 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1695 internal ApplicationSignal RegionChangedSignal()
1697 ApplicationSignal ret = new ApplicationSignal(NDalicPINVOKE.Application_RegionChangedSignal(swigCPtr), false);
1698 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1702 internal LowBatterySignalType BatteryLowSignal()
1704 LowBatterySignalType ret = new LowBatterySignalType(NDalicPINVOKE.Application_LowBatterySignal(swigCPtr), false);
1705 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1709 internal LowMemorySignalType MemoryLowSignal()
1711 LowMemorySignalType ret = new LowMemorySignalType(NDalicPINVOKE.Application_LowMemorySignal(swigCPtr), false);
1712 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1716 /// <since_tizen> 3 </since_tizen>
1717 public enum WindowMode