2 * Copyright(c) 2021 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.
18 using System.Collections.Generic;
19 using System.Collections.ObjectModel;
20 using System.ComponentModel;
21 using System.Diagnostics;
22 using System.Runtime.InteropServices;
23 using Tizen.NUI.Binding;
28 * @brief Event arguments that passed via NUIApplicationInit signal
30 internal class NUIApplicationInitEventArgs : EventArgs
32 private Application application;
35 * @brief Application - is the application that is being initialized
37 public Application Application
51 * @brief Event arguments that passed via NUIApplicationTerminate signal
53 internal class NUIApplicationTerminatingEventArgs : EventArgs
55 private Application application;
57 * @brief Application - is the application that is being Terminated
59 public Application Application
73 * @brief Event arguments that passed via NUIApplicationPause signal
75 internal class NUIApplicationPausedEventArgs : EventArgs
77 private Application application;
79 * @brief Application - is the application that is being Paused
81 public Application Application
95 * @brief Event arguments that passed via NUIApplicationResume signal
97 internal class NUIApplicationResumedEventArgs : EventArgs
99 private Application application;
101 * @brief Application - is the application that is being Resumed
103 public Application Application
117 * @brief Event arguments that passed via NUIApplicationReset signal
119 internal class NUIApplicationResetEventArgs : EventArgs
121 private Application application;
123 * @brief Application - is the application that is being Reset
125 public Application Application
139 * @brief Event arguments that passed via NUIApplicationLanguageChanged signal
141 internal class NUIApplicationLanguageChangedEventArgs : EventArgs
143 private Application application;
145 * @brief Application - is the application that is being affected with Device's language change
147 public Application Application
161 * @brief Event arguments that passed via NUIApplicationRegionChanged signal
163 internal class NUIApplicationRegionChangedEventArgs : EventArgs
165 private Application application;
167 * @brief Application - is the application that is being affected with Device's region change
169 public Application Application
183 * @brief Event arguments that passed via NUIApplicationBatteryLow signal
185 internal class NUIApplicationBatteryLowEventArgs : EventArgs
187 private Application.BatteryStatus status;
189 * @brief Application - is the application that is being affected when the battery level of the device is low
191 public Application.BatteryStatus BatteryStatus
205 * @brief Event arguments that passed via NUIApplicationMemoryLow signal
207 internal class NUIApplicationMemoryLowEventArgs : EventArgs
209 private Application.MemoryStatus status;
211 * @brief Application - is the application that is being affected when the memory level of the device is low
213 public Application.MemoryStatus MemoryStatus
227 * @brief Event arguments that passed via NUIApplicationAppControl signal
229 internal class NUIApplicationAppControlEventArgs : EventArgs
231 private Application application;
232 private IntPtr voidp;
234 * @brief Application - is the application that is receiving the launch request from another application
236 public Application Application
248 * @brief VoidP - contains the information about why the application is launched
264 /// A class to get resources in current application.
266 public sealed class GetResourcesProvider
269 /// Get resources in current application.
271 static public IResourcesProvider Get()
273 return Tizen.NUI.Application.Current;
277 internal class Application : BaseHandle, IResourcesProvider, IElementConfiguration<Application>
279 static Application s_current;
281 ReadOnlyCollection<Element> logicalChildren;
283 [EditorBrowsable(EditorBrowsableState.Never)]
284 public static void SetCurrentApplication(Application value) => Current = value;
286 public static Application Current
288 get { return s_current; }
291 if (s_current == value)
297 internal override ReadOnlyCollection<Element> LogicalChildrenInternal
299 get { return logicalChildren ?? (logicalChildren = new ReadOnlyCollection<Element>(InternalChildren)); }
302 internal IResourceDictionary SystemResources { get; }
304 ObservableCollection<Element> InternalChildren { get; } = new ObservableCollection<Element>();
306 ResourceDictionary resources;
307 public bool IsResourcesCreated => resources != null;
309 public delegate void resChangeCb(object sender, ResourcesChangedEventArgs e);
311 static private Dictionary<object, Dictionary<resChangeCb, int>> resourceChangeCallbackDict = new Dictionary<object, Dictionary<resChangeCb, int>>();
312 static public void AddResourceChangedCallback(object handle, resChangeCb cb)
314 Dictionary<resChangeCb, int> cbDict;
315 resourceChangeCallbackDict.TryGetValue(handle, out cbDict);
319 cbDict = new Dictionary<resChangeCb, int>();
320 resourceChangeCallbackDict.Add(handle, cbDict);
323 if (false == cbDict.ContainsKey(cb))
329 internal override void OnResourcesChanged(object sender, ResourcesChangedEventArgs e)
331 base.OnResourcesChanged(sender, e);
333 foreach (KeyValuePair<object, Dictionary<resChangeCb, int>> resourcePair in resourceChangeCallbackDict)
335 foreach (KeyValuePair<resChangeCb, int> cbPair in resourcePair.Value)
337 cbPair.Key(sender, e);
342 public ResourceDictionary XamlResources
346 if (resources == null)
348 resources = new ResourceDictionary();
349 int hashCode = resources.GetHashCode();
350 ((IResourceDictionary)resources).ValuesChanged += OnResourcesChanged;
356 if (resources == value)
358 OnPropertyChanging();
360 if (resources != null)
361 ((IResourceDictionary)resources).ValuesChanged -= OnResourcesChanged;
363 OnResourcesChanged(value);
364 if (resources != null)
365 ((IResourceDictionary)resources).ValuesChanged += OnResourcesChanged;
371 protected override void OnParentSet()
373 throw new InvalidOperationException("Setting a Parent on Application is invalid.");
376 [EditorBrowsable(EditorBrowsableState.Never)]
377 public static bool IsApplicationOrNull(Element element)
379 return element == null || element is Application;
382 internal override void OnParentResourcesChanged(IEnumerable<KeyValuePair<string, object>> values)
384 if (!((IResourcesProvider)this).IsResourcesCreated || XamlResources.Count == 0)
386 base.OnParentResourcesChanged(values);
390 var innerKeys = new HashSet<string>();
391 var changedResources = new List<KeyValuePair<string, object>>();
392 foreach (KeyValuePair<string, object> c in XamlResources)
393 innerKeys.Add(c.Key);
394 foreach (KeyValuePair<string, object> value in values)
396 if (innerKeys.Add(value.Key))
397 changedResources.Add(value);
399 OnResourcesChanged(changedResources);
402 internal Application(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
404 SetCurrentApplication(this);
408 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Application obj)
410 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.SwigCPtr;
413 protected override void Dispose(DisposeTypes type)
420 //Release your own unmanaged resources here.
421 //You should not access any managed member here except static instance.
422 //because the execution order of Finalizes is non-deterministic.
423 if (applicationInitEventCallbackDelegate != null)
425 initSignal?.Disconnect(applicationInitEventCallbackDelegate);
426 initSignal?.Dispose();
430 if (applicationTerminateEventCallbackDelegate != null)
432 terminateSignal?.Disconnect(applicationTerminateEventCallbackDelegate);
433 terminateSignal?.Dispose();
434 terminateSignal = null;
437 if (applicationPauseEventCallbackDelegate != null)
439 pauseSignal?.Disconnect(applicationPauseEventCallbackDelegate);
440 pauseSignal?.Dispose();
444 if (applicationResumeEventCallbackDelegate != null)
446 resumeSignal?.Disconnect(applicationResumeEventCallbackDelegate);
447 resumeSignal?.Dispose();
451 if (applicationResetEventCallbackDelegate != null)
453 resetSignal?.Disconnect(applicationResetEventCallbackDelegate);
454 resetSignal?.Dispose();
458 if (applicationLanguageChangedEventCallbackDelegate != null)
460 languageChangedSignal?.Disconnect(applicationLanguageChangedEventCallbackDelegate);
461 languageChangedSignal?.Dispose();
462 languageChangedSignal = null;
465 if (applicationRegionChangedEventCallbackDelegate != null)
467 regionChangedSignal?.Disconnect(applicationRegionChangedEventCallbackDelegate);
468 regionChangedSignal?.Dispose();
469 regionChangedSignal = null;
472 if (applicationBatteryLowEventCallbackDelegate != null)
474 batteryLowSignal?.Disconnect(applicationBatteryLowEventCallbackDelegate);
475 batteryLowSignal?.Dispose();
476 batteryLowSignal = null;
479 if (applicationMemoryLowEventCallbackDelegate != null)
481 memoryLowSignal?.Disconnect(applicationMemoryLowEventCallbackDelegate);
482 memoryLowSignal?.Dispose();
483 memoryLowSignal = null;
486 if (applicationAppControlEventCallbackDelegate != null)
488 appControlSignal?.Disconnect(applicationAppControlEventCallbackDelegate);
489 appControlSignal?.Dispose();
490 appControlSignal = null;
498 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
500 Interop.Application.DeleteApplication(swigCPtr);
503 public enum BatteryStatus
510 public enum MemoryStatus
517 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
518 private delegate void NUIApplicationInitEventCallbackDelegate(IntPtr application);
519 private DaliEventHandler<object, NUIApplicationInitEventArgs> applicationInitEventHandler;
520 private NUIApplicationInitEventCallbackDelegate applicationInitEventCallbackDelegate;
521 private ApplicationSignal initSignal;
523 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
524 private delegate void NUIApplicationTerminateEventCallbackDelegate(IntPtr application);
525 private DaliEventHandler<object, NUIApplicationTerminatingEventArgs> applicationTerminateEventHandler;
526 private NUIApplicationTerminateEventCallbackDelegate applicationTerminateEventCallbackDelegate;
527 private ApplicationSignal terminateSignal;
529 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
530 private delegate void NUIApplicationPauseEventCallbackDelegate(IntPtr application);
531 private DaliEventHandler<object, NUIApplicationPausedEventArgs> applicationPauseEventHandler;
532 private NUIApplicationPauseEventCallbackDelegate applicationPauseEventCallbackDelegate;
533 private ApplicationSignal pauseSignal;
535 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
536 private delegate void NUIApplicationResumeEventCallbackDelegate(IntPtr application);
537 private DaliEventHandler<object, NUIApplicationResumedEventArgs> applicationResumeEventHandler;
538 private NUIApplicationResumeEventCallbackDelegate applicationResumeEventCallbackDelegate;
539 private ApplicationSignal resumeSignal;
541 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
542 private delegate void NUIApplicationResetEventCallbackDelegate(IntPtr application);
543 private DaliEventHandler<object, NUIApplicationResetEventArgs> applicationResetEventHandler;
544 private NUIApplicationResetEventCallbackDelegate applicationResetEventCallbackDelegate;
545 private ApplicationSignal resetSignal;
547 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
548 private delegate void NUIApplicationLanguageChangedEventCallbackDelegate(IntPtr application);
549 private DaliEventHandler<object, NUIApplicationLanguageChangedEventArgs> applicationLanguageChangedEventHandler;
550 private NUIApplicationLanguageChangedEventCallbackDelegate applicationLanguageChangedEventCallbackDelegate;
551 private ApplicationSignal languageChangedSignal;
554 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
555 private delegate void NUIApplicationRegionChangedEventCallbackDelegate(IntPtr application);
556 private DaliEventHandler<object, NUIApplicationRegionChangedEventArgs> applicationRegionChangedEventHandler;
557 private NUIApplicationRegionChangedEventCallbackDelegate applicationRegionChangedEventCallbackDelegate;
558 private ApplicationSignal regionChangedSignal;
560 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
561 private delegate void NUIApplicationBatteryLowEventCallbackDelegate(BatteryStatus status);
562 private DaliEventHandler<object, NUIApplicationBatteryLowEventArgs> applicationBatteryLowEventHandler;
563 private NUIApplicationBatteryLowEventCallbackDelegate applicationBatteryLowEventCallbackDelegate;
564 private LowBatterySignalType batteryLowSignal;
566 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
567 private delegate void NUIApplicationMemoryLowEventCallbackDelegate(MemoryStatus status);
568 private DaliEventHandler<object, NUIApplicationMemoryLowEventArgs> applicationMemoryLowEventHandler;
569 private NUIApplicationMemoryLowEventCallbackDelegate applicationMemoryLowEventCallbackDelegate;
570 private LowMemorySignalType memoryLowSignal;
572 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
573 private delegate void NUIApplicationAppControlEventCallbackDelegate(IntPtr application, IntPtr voidp);
574 private DaliEventHandler<object, NUIApplicationAppControlEventArgs> applicationAppControlEventHandler;
575 private NUIApplicationAppControlEventCallbackDelegate applicationAppControlEventCallbackDelegate;
576 private ApplicationControlSignal appControlSignal;
578 private Window window;
581 * @brief Event for Initialized signal which can be used to subscribe/unsubscribe the event handler
582 * provided by the user. Initialized signal is emitted when application is initialized
584 public event DaliEventHandler<object, NUIApplicationInitEventArgs> Initialized
588 // Restricted to only one listener
589 if (applicationInitEventHandler == null)
591 applicationInitEventHandler += value;
592 applicationInitEventCallbackDelegate = new NUIApplicationInitEventCallbackDelegate(OnApplicationInit);
593 initSignal = this.InitSignal();
594 initSignal?.Connect(applicationInitEventCallbackDelegate);
600 if (applicationInitEventHandler != null)
602 initSignal?.Disconnect(applicationInitEventCallbackDelegate);
603 initSignal?.Dispose();
607 applicationInitEventHandler -= value;
611 // Callback for Application InitSignal
612 private void OnApplicationInit(IntPtr data)
614 // Initialize DisposeQueue Singleton class. This is also required to create DisposeQueue on main thread.
615 DisposeQueue.Instance.Initialize();
616 Window.Instance = GetWindow();
618 // Notify that the window is displayed to the app core.
619 if (NUIApplication.IsPreload)
621 Window.Instance.Show();
624 if (applicationInitEventHandler != null)
626 NUIApplicationInitEventArgs e = new NUIApplicationInitEventArgs();
627 e.Application = this;
628 applicationInitEventHandler.Invoke(this, e);
634 * @brief Event for Terminated signal which can be used to subscribe/unsubscribe the event handler
635 * provided by the user. Terminated signal is emitted when application is terminating
637 public event DaliEventHandler<object, NUIApplicationTerminatingEventArgs> Terminating
641 // Restricted to only one listener
642 if (applicationTerminateEventHandler == null)
644 applicationTerminateEventHandler += value;
646 applicationTerminateEventCallbackDelegate = new NUIApplicationTerminateEventCallbackDelegate(OnNUIApplicationTerminate);
647 terminateSignal = this.TerminateSignal();
648 terminateSignal?.Connect(applicationTerminateEventCallbackDelegate);
654 if (applicationTerminateEventHandler != null)
656 terminateSignal?.Disconnect(applicationTerminateEventCallbackDelegate);
657 terminateSignal?.Dispose();
658 terminateSignal = null;
661 applicationTerminateEventHandler -= value;
665 // Callback for Application TerminateSignal
666 private void OnNUIApplicationTerminate(IntPtr data)
668 if (applicationTerminateEventHandler != null)
670 NUIApplicationTerminatingEventArgs e = new NUIApplicationTerminatingEventArgs();
671 e.Application = this;
672 applicationTerminateEventHandler.Invoke(this, e);
675 List<Window> windows = GetWindowList();
676 foreach (Window window in windows)
678 window?.DisconnectNativeSignals();
683 * @brief Event for Paused signal which can be used to subscribe/unsubscribe the event handler
684 * provided by the user. Paused signal is emitted when application is paused
686 public event DaliEventHandler<object, NUIApplicationPausedEventArgs> Paused
690 // Restricted to only one listener
691 if (applicationPauseEventHandler == null)
693 applicationPauseEventHandler += value;
695 applicationPauseEventCallbackDelegate = new NUIApplicationPauseEventCallbackDelegate(OnNUIApplicationPause);
696 pauseSignal = this.PauseSignal();
697 pauseSignal?.Connect(applicationPauseEventCallbackDelegate);
703 if (applicationPauseEventHandler != null)
705 pauseSignal?.Disconnect(applicationPauseEventCallbackDelegate);
706 pauseSignal?.Dispose();
710 applicationPauseEventHandler -= value;
714 // Callback for Application PauseSignal
715 private void OnNUIApplicationPause(IntPtr data)
717 if (applicationPauseEventHandler != null)
719 NUIApplicationPausedEventArgs e = new NUIApplicationPausedEventArgs();
720 e.Application = this;
721 applicationPauseEventHandler.Invoke(this, e);
726 * @brief Event for Resumed signal which can be used to subscribe/unsubscribe the event handler
727 * provided by the user. Resumed signal is emitted when application is resumed
729 public event DaliEventHandler<object, NUIApplicationResumedEventArgs> Resumed
733 // Restricted to only one listener
734 if (applicationResumeEventHandler == null)
736 applicationResumeEventHandler += value;
738 applicationResumeEventCallbackDelegate = new NUIApplicationResumeEventCallbackDelegate(OnNUIApplicationResume);
739 resumeSignal = this.ResumeSignal();
740 resumeSignal?.Connect(applicationResumeEventCallbackDelegate);
746 if (applicationResumeEventHandler != null)
748 resumeSignal?.Disconnect(applicationResumeEventCallbackDelegate);
749 resumeSignal?.Dispose();
753 applicationResumeEventHandler -= value;
757 // Callback for Application ResumeSignal
758 private void OnNUIApplicationResume(IntPtr data)
760 if (applicationResumeEventHandler != null)
762 NUIApplicationResumedEventArgs e = new NUIApplicationResumedEventArgs();
763 e.Application = this;
764 applicationResumeEventHandler.Invoke(this, e);
769 * @brief Event for Reset signal which can be used to subscribe/unsubscribe the event handler
770 * provided by the user. Reset signal is emitted when application is reset
772 public new event DaliEventHandler<object, NUIApplicationResetEventArgs> Reset
776 // Restricted to only one listener
777 if (applicationResetEventHandler == null)
779 applicationResetEventHandler += value;
781 applicationResetEventCallbackDelegate = new NUIApplicationResetEventCallbackDelegate(OnNUIApplicationReset);
782 resetSignal = this.ResetSignal();
783 resetSignal?.Connect(applicationResetEventCallbackDelegate);
789 if (applicationResetEventHandler != null)
791 resetSignal?.Disconnect(applicationResetEventCallbackDelegate);
792 resetSignal?.Dispose();
796 applicationResetEventHandler -= value;
800 // Callback for Application ResetSignal
801 private void OnNUIApplicationReset(IntPtr data)
803 if (applicationResetEventHandler != null)
805 NUIApplicationResetEventArgs e = new NUIApplicationResetEventArgs();
806 e.Application = this;
807 applicationResetEventHandler.Invoke(this, e);
812 * @brief Event for LanguageChanged signal which can be used to subscribe/unsubscribe the event handler
813 * provided by the user. LanguageChanged signal is emitted when the region of the device is changed.
815 public event DaliEventHandler<object, NUIApplicationLanguageChangedEventArgs> LanguageChanged
819 // Restricted to only one listener
820 if (applicationLanguageChangedEventHandler == null)
822 applicationLanguageChangedEventHandler += value;
824 applicationLanguageChangedEventCallbackDelegate = new NUIApplicationLanguageChangedEventCallbackDelegate(OnNUIApplicationLanguageChanged);
825 languageChangedSignal = this.LanguageChangedSignal();
826 languageChangedSignal?.Connect(applicationLanguageChangedEventCallbackDelegate);
832 if (applicationLanguageChangedEventHandler != null)
834 languageChangedSignal?.Disconnect(applicationLanguageChangedEventCallbackDelegate);
835 languageChangedSignal?.Dispose();
836 languageChangedSignal = null;
839 applicationLanguageChangedEventHandler -= value;
843 // Callback for Application LanguageChangedSignal
844 private void OnNUIApplicationLanguageChanged(IntPtr data)
846 if (applicationLanguageChangedEventHandler != null)
848 NUIApplicationLanguageChangedEventArgs e = new NUIApplicationLanguageChangedEventArgs();
849 e.Application = this;
850 applicationLanguageChangedEventHandler.Invoke(this, e);
855 * @brief Event for RegionChanged signal which can be used to subscribe/unsubscribe the event handler
856 * provided by the user. RegionChanged signal is emitted when the region of the device is changed.
858 public event DaliEventHandler<object, NUIApplicationRegionChangedEventArgs> RegionChanged
862 // Restricted to only one listener
863 if (applicationRegionChangedEventHandler == null)
865 applicationRegionChangedEventHandler += value;
867 applicationRegionChangedEventCallbackDelegate = new NUIApplicationRegionChangedEventCallbackDelegate(OnNUIApplicationRegionChanged);
868 regionChangedSignal = this.RegionChangedSignal();
869 regionChangedSignal?.Connect(applicationRegionChangedEventCallbackDelegate);
875 if (applicationRegionChangedEventHandler != null)
877 regionChangedSignal?.Disconnect(applicationRegionChangedEventCallbackDelegate);
878 regionChangedSignal?.Dispose();
879 regionChangedSignal = null;
882 applicationRegionChangedEventHandler -= value;
886 // Callback for Application RegionChangedSignal
887 private void OnNUIApplicationRegionChanged(IntPtr data)
889 if (applicationRegionChangedEventHandler != null)
891 NUIApplicationRegionChangedEventArgs e = new NUIApplicationRegionChangedEventArgs();
892 e.Application = this;
893 applicationRegionChangedEventHandler.Invoke(this, e);
898 * @brief Event for BatteryLow signal which can be used to subscribe/unsubscribe the event handler
899 * provided by the user. BatteryLow signal is emitted when the battery level of the device is low.
901 public event DaliEventHandler<object, NUIApplicationBatteryLowEventArgs> BatteryLow
905 // Restricted to only one listener
906 if (applicationBatteryLowEventHandler == null)
908 applicationBatteryLowEventHandler += value;
910 applicationBatteryLowEventCallbackDelegate = new NUIApplicationBatteryLowEventCallbackDelegate(OnNUIApplicationBatteryLow);
911 batteryLowSignal = this.BatteryLowSignal();
912 batteryLowSignal?.Connect(applicationBatteryLowEventCallbackDelegate);
918 if (applicationBatteryLowEventHandler != null)
920 batteryLowSignal?.Disconnect(applicationBatteryLowEventCallbackDelegate);
921 batteryLowSignal?.Dispose();
922 batteryLowSignal = null;
925 applicationBatteryLowEventHandler -= value;
929 // Callback for Application BatteryLowSignal
930 private void OnNUIApplicationBatteryLow(BatteryStatus status)
932 NUIApplicationBatteryLowEventArgs e = new NUIApplicationBatteryLowEventArgs();
934 // Populate all members of "e" (NUIApplicationBatteryLowEventArgs) with real data
935 e.BatteryStatus = status;
936 applicationBatteryLowEventHandler?.Invoke(this, e);
940 * @brief Event for MemoryLow signal which can be used to subscribe/unsubscribe the event handler
941 * provided by the user. MemoryLow signal is emitted when the memory level of the device is low.
943 public event DaliEventHandler<object, NUIApplicationMemoryLowEventArgs> MemoryLow
947 // Restricted to only one listener
948 if (applicationMemoryLowEventHandler == null)
950 applicationMemoryLowEventHandler += value;
952 applicationMemoryLowEventCallbackDelegate = new NUIApplicationMemoryLowEventCallbackDelegate(OnNUIApplicationMemoryLow);
953 memoryLowSignal = this.MemoryLowSignal();
954 memoryLowSignal?.Connect(applicationMemoryLowEventCallbackDelegate);
960 if (applicationMemoryLowEventHandler != null)
962 memoryLowSignal?.Disconnect(applicationMemoryLowEventCallbackDelegate);
963 memoryLowSignal?.Dispose();
964 memoryLowSignal = null;
967 applicationMemoryLowEventHandler -= value;
971 // Callback for Application MemoryLowSignal
972 private void OnNUIApplicationMemoryLow(MemoryStatus status)
974 NUIApplicationMemoryLowEventArgs e = new NUIApplicationMemoryLowEventArgs();
976 // Populate all members of "e" (NUIApplicationMemoryLowEventArgs) with real data
977 e.MemoryStatus = status;
978 applicationMemoryLowEventHandler?.Invoke(this, e);
982 * @brief Event for AppControl signal which can be used to subscribe/unsubscribe the event handler
983 * provided by the user. AppControl signal is emitted when another application sends a launch request to the application.
985 public event DaliEventHandler<object, NUIApplicationAppControlEventArgs> AppControl
989 // Restricted to only one listener
990 if (applicationAppControlEventHandler == null)
992 applicationAppControlEventHandler += value;
994 applicationAppControlEventCallbackDelegate = new NUIApplicationAppControlEventCallbackDelegate(OnNUIApplicationAppControl);
995 appControlSignal = this.AppControlSignal();
996 appControlSignal?.Connect(applicationAppControlEventCallbackDelegate);
1002 if (applicationAppControlEventHandler != null)
1004 appControlSignal?.Disconnect(applicationAppControlEventCallbackDelegate);
1005 appControlSignal?.Dispose();
1006 appControlSignal = null;
1009 applicationAppControlEventHandler -= value;
1013 // Callback for Application AppControlSignal
1014 private void OnNUIApplicationAppControl(IntPtr application, IntPtr voidp)
1016 if (applicationAppControlEventHandler != null)
1018 NUIApplicationAppControlEventArgs e = new NUIApplicationAppControlEventArgs();
1020 e.Application = this;
1021 applicationAppControlEventHandler.Invoke(this, e);
1025 protected static Application instance; // singleton
1027 public static Application Instance
1035 public static Application GetApplicationFromPtr(global::System.IntPtr cPtr)
1037 if (cPtr == global::System.IntPtr.Zero)
1042 Application ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Application;
1043 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1047 public static Application NewApplication()
1049 return NewApplication("", NUIApplication.WindowMode.Opaque);
1052 public static Application NewApplication(string stylesheet)
1054 return NewApplication(stylesheet, NUIApplication.WindowMode.Opaque);
1057 public static Application NewApplication(string stylesheet, NUIApplication.WindowMode windowMode)
1059 // register all Views with the type registry, so that can be created / styled via JSON
1060 //ViewRegistryHelper.Initialize(); //moved to Application side.
1066 Application ret = New(1, stylesheet, windowMode);
1067 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1069 // set the singleton
1074 public static Application NewApplication(string stylesheet, NUIApplication.WindowMode windowMode, Rectangle positionSize)
1080 Application ret = New(1, stylesheet, windowMode, positionSize);
1081 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1083 // set the singleton
1088 public static Application NewApplication(string[] args, string stylesheet, NUIApplication.WindowMode windowMode)
1094 Application ret = New(args, stylesheet, windowMode);
1095 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1097 // set the singleton
1102 public static Application NewApplication(string[] args, string stylesheet, NUIApplication.WindowMode windowMode, Rectangle positionSize)
1108 Application ret = New(args, stylesheet, windowMode, positionSize);
1109 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1111 // set the singleton
1117 /// Ensures that the function passed in is called from the main loop when it is idle.
1119 /// <param name="func">The function to call</param>
1120 /// <returns>true if added successfully, false otherwise</returns>
1121 public bool AddIdle(System.Delegate func)
1123 System.IntPtr ip = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate<System.Delegate>(func);
1124 System.IntPtr ip2 = Interop.Application.MakeCallback(new System.Runtime.InteropServices.HandleRef(this, ip));
1126 bool ret = Interop.Application.AddIdle(SwigCPtr, new System.Runtime.InteropServices.HandleRef(this, ip2));
1128 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1133 * Outer::outer_method(int)
1135 public static Application New()
1137 Application ret = new Application(Interop.Application.New(), true);
1138 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1142 public static Application New(int argc)
1144 Application ret = new Application(Interop.Application.New(argc), true);
1145 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1149 public static Application New(int argc, string stylesheet)
1151 Application ret = new Application(Interop.Application.New(argc, stylesheet), true);
1152 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1156 public static Application New(int argc, string stylesheet, NUIApplication.WindowMode windowMode)
1158 Application ret = new Application(Interop.Application.New(argc, stylesheet, (int)windowMode), true);
1159 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1164 public static Application New(string[] args, string stylesheet, NUIApplication.WindowMode windowMode)
1166 Application ret = null;
1168 string argvStr = "";
1172 argvStr = string.Join(" ", args);
1174 catch (Exception exception)
1176 Tizen.Log.Fatal("NUI", "[Error] got exception during Application New(), this should not occur, message : " + exception.Message);
1177 Tizen.Log.Fatal("NUI", "[Error] error line number : " + new StackTrace(exception, true).GetFrame(0).GetFileLineNumber());
1178 Tizen.Log.Fatal("NUI", "[Error] Stack Trace : " + exception.StackTrace);
1182 ret = new Application(NDalicPINVOKE.ApplicationNewManual4(argc, argvStr, stylesheet, (int)windowMode), true);
1183 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1188 public static Application New(int argc, string stylesheet, NUIApplication.WindowMode windowMode, Rectangle positionSize)
1190 Application ret = new Application(Interop.Application.New(argc, stylesheet, (int)windowMode, Rectangle.getCPtr(positionSize)), true);
1191 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1195 public static Application New(string[] args, string stylesheet, NUIApplication.WindowMode windowMode, Rectangle positionSize)
1197 Application ret = null;
1199 string argvStr = "";
1203 argvStr = string.Join(" ", args);
1205 catch (Exception exception)
1207 Tizen.Log.Fatal("NUI", "[Error] got exception during Application New(), this should not occur, message : " + exception.Message);
1208 Tizen.Log.Fatal("NUI", "[Error] error line number : " + new StackTrace(exception, true).GetFrame(0).GetFileLineNumber());
1209 Tizen.Log.Fatal("NUI", "[Error] Stack Trace : " + exception.StackTrace);
1213 ret = new Application(NDalicPINVOKE.ApplicationNewWithWindowSizePosition(argc, argvStr, stylesheet, (int)windowMode, Rectangle.getCPtr(positionSize)), true);
1214 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1219 public Application() : this(Interop.Application.NewApplication(), true)
1221 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1224 public Application(Application application) : this(Interop.Application.NewApplication(Application.getCPtr(application)), true)
1226 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1229 public Application Assign(Application application)
1231 Application ret = new Application(Interop.Application.Assign(SwigCPtr, Application.getCPtr(application)), false);
1232 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1236 public void MainLoop()
1238 NDalicPINVOKE.ApplicationMainLoop(SwigCPtr);
1239 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1244 Interop.Application.Lower(SwigCPtr);
1245 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1250 Interop.Application.Quit(SwigCPtr);
1251 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1254 internal bool AddIdle(SWIGTYPE_p_Dali__CallbackBase callback)
1256 bool ret = Interop.Application.AddIdle(SwigCPtr, SWIGTYPE_p_Dali__CallbackBase.getCPtr(callback));
1257 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1261 public Window GetWindow()
1268 window = (Registry.GetManagedBaseHandleFromNativePtr(Interop.Application.GetWindow(SwigCPtr)) as Window) ?? new Window(Interop.Application.GetWindow(SwigCPtr), true);
1270 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1274 public static string GetResourcePath()
1276 string ret = Interop.Application.GetResourcePath();
1277 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1281 public string GetLanguage()
1283 string ret = Interop.Application.GetLanguage(SwigCPtr);
1284 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1288 public string GetRegion()
1290 string ret = Interop.Application.GetRegion(SwigCPtr);
1291 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1295 [EditorBrowsable(EditorBrowsableState.Never)]
1296 public static List<Window> GetWindowList()
1298 uint ListSize = Interop.Application.GetWindowsListSize();
1299 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1301 List<Window> WindowList = new List<Window>();
1302 for (uint i = 0; i < ListSize; ++i)
1304 Window currWin = Registry.GetManagedBaseHandleFromNativePtr(Interop.Application.GetWindowsFromList(i)) as Window;
1305 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1308 WindowList.Add(currWin);
1314 internal ApplicationSignal InitSignal()
1316 ApplicationSignal ret = new ApplicationSignal(NDalicPINVOKE.ApplicationInitSignal(SwigCPtr), false);
1317 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1321 internal ApplicationSignal TerminateSignal()
1323 ApplicationSignal ret = new ApplicationSignal(NDalicPINVOKE.ApplicationTerminateSignal(SwigCPtr), false);
1324 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1328 internal ApplicationSignal PauseSignal()
1330 ApplicationSignal ret = new ApplicationSignal(NDalicPINVOKE.ApplicationPauseSignal(SwigCPtr), false);
1331 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1335 internal ApplicationSignal ResumeSignal()
1337 ApplicationSignal ret = new ApplicationSignal(NDalicPINVOKE.ApplicationResumeSignal(SwigCPtr), false);
1338 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1342 internal ApplicationSignal ResetSignal()
1344 ApplicationSignal ret = new ApplicationSignal(NDalicPINVOKE.ApplicationResetSignal(SwigCPtr), false);
1345 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1349 internal ApplicationControlSignal AppControlSignal()
1351 ApplicationControlSignal ret = new ApplicationControlSignal(NDalicPINVOKE.ApplicationAppControlSignal(SwigCPtr), false);
1352 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1356 internal ApplicationSignal LanguageChangedSignal()
1358 ApplicationSignal ret = new ApplicationSignal(NDalicPINVOKE.ApplicationLanguageChangedSignal(SwigCPtr), false);
1359 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1363 internal ApplicationSignal RegionChangedSignal()
1365 ApplicationSignal ret = new ApplicationSignal(NDalicPINVOKE.ApplicationRegionChangedSignal(SwigCPtr), false);
1366 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1370 internal LowBatterySignalType BatteryLowSignal()
1372 LowBatterySignalType ret = new LowBatterySignalType(NDalicPINVOKE.ApplicationLowBatterySignal(SwigCPtr), false);
1373 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1377 internal LowMemorySignalType MemoryLowSignal()
1379 LowMemorySignalType ret = new LowMemorySignalType(NDalicPINVOKE.ApplicationLowMemorySignal(SwigCPtr), false);
1380 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();