[NUI] Rollback split-nui (#887)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / internal / Application.cs
index b7167d8..d518199 100755 (executable)
@@ -1,24 +1,32 @@
-/** Copyright (c) 2017 Samsung Electronics Co., Ltd.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*
-*/
+/*
+ * Copyright(c) 2018 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
 
 namespace Tizen.NUI
 {
 
     using System;
+    using System.Collections.Generic;
+    using System.Collections.ObjectModel;
+    using System.ComponentModel;
     using System.Runtime.InteropServices;
+    using System.Threading;
+    using System.Threading.Tasks;
+    using Tizen.NUI.Binding;
+    using Tizen.NUI.Binding.Internals;
 
     /**
       * @brief Event arguments that passed via NUIApplicationInit signal
@@ -219,20 +227,20 @@ namespace Tizen.NUI
       */
     internal class NUIApplicationBatteryLowEventArgs : EventArgs
     {
-        private Application _application;
+        private Application.BatteryStatus _status;
         /**
           * @brief Application - is the application that is being affected when the battery level of the device is low
           *
           */
-        public Application Application
+        public Application.BatteryStatus BatteryStatus
         {
             get
             {
-                return _application;
+                return _status;
             }
             set
             {
-                _application = value;
+                _status = value;
             }
         }
     }
@@ -243,20 +251,20 @@ namespace Tizen.NUI
       */
     internal class NUIApplicationMemoryLowEventArgs : EventArgs
     {
-        private Application _application;
+        private Application.MemoryStatus _status;
         /**
           * @brief Application - is the application that is being affected when the memory level of the device is low
           *
           */
-        public Application Application
+        public Application.MemoryStatus MemoryStatus
         {
             get
             {
-                return _application;
+                return _status;
             }
             set
             {
-                _application = value;
+                _status = value;
             }
         }
     }
@@ -301,13 +309,445 @@ namespace Tizen.NUI
         }
     }
 
-    internal class Application : BaseHandle
+    /// <summary>
+    /// A class to get resources in current application.
+    /// </summary>
+    public class GetResourcesProvider
     {
+        /// <summary>
+        /// Get resources in current application.
+        /// </summary>
+        static public IResourcesProvider Get()
+        {
+            return Tizen.NUI.Application.Current;
+        }
+    }
+
+    internal class Application : BaseHandle, IResourcesProvider, IApplicationController, IElementConfiguration<Application>
+    {
+
+        static Application s_current;
+        Task<IDictionary<string, object>> _propertiesTask;
+        readonly Lazy<PlatformConfigurationRegistry<Application>> _platformConfigurationRegistry;
+
+        IAppIndexingProvider _appIndexProvider;
+
+        ReadOnlyCollection<Element> _logicalChildren;
+
+        Page _mainPage;
+
+        static SemaphoreSlim SaveSemaphore = new SemaphoreSlim(1, 1);
+
+        public IAppLinks AppLinks
+        {
+            get
+            {
+                if (_appIndexProvider == null)
+                    throw new ArgumentException("No IAppIndexingProvider was provided");
+                if (_appIndexProvider.AppLinks == null)
+                    throw new ArgumentException("No AppLinks implementation was found, if in Android make sure you installed the Xamarin.Forms.AppLinks");
+                return _appIndexProvider.AppLinks;
+            }
+        }
+
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static void SetCurrentApplication(Application value) => Current = value;
+
+        public static Application Current
+        {
+            get { return s_current; }
+            set
+            {
+                if (s_current == value)
+                    return;
+                if (value == null)
+                    s_current = null; //Allow to reset current for unittesting
+                s_current = value;
+            }
+        }
+
+        public Page MainPage
+        {
+            get { return _mainPage; }
+            set
+            {
+                if (value == null)
+                    throw new ArgumentNullException("value");
+
+                if (_mainPage == value)
+                    return;
+
+                OnPropertyChanging();
+                if (_mainPage != null)
+                {
+                    InternalChildren.Remove(_mainPage);
+                    _mainPage.Parent = null;
+                }
+
+                _mainPage = value;
+
+                if (_mainPage != null)
+                {
+                    _mainPage.Parent = this;
+                    _mainPage.NavigationProxy.Inner = NavigationProxy;
+                    InternalChildren.Add(_mainPage);
+                }
+                OnPropertyChanged();
+            }
+        }
+
+        public IDictionary<string, object> Properties
+        {
+            get
+            {
+                if (_propertiesTask == null)
+                {
+                    _propertiesTask = GetPropertiesAsync();
+                }
+
+                return _propertiesTask.Result;
+            }
+        }
+
+        internal override ReadOnlyCollection<Element> LogicalChildrenInternal
+        {
+            get { return _logicalChildren ?? (_logicalChildren = new ReadOnlyCollection<Element>(InternalChildren)); }
+        }
+
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public new NavigationProxy NavigationProxy { get; }
+
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public int PanGestureId { get; set; }
+
+        internal IResourceDictionary SystemResources { get; }
+
+        ObservableCollection<Element> InternalChildren { get; } = new ObservableCollection<Element>();
+
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void SetAppIndexingProvider(IAppIndexingProvider provider)
+        {
+            _appIndexProvider = provider;
+        }
+
+        ResourceDictionary _resources;
+        public bool IsResourcesCreated => _resources != null;
+
+        public delegate void resChangeCb(object sender, ResourcesChangedEventArgs e);
+
+        static private Dictionary<object, Dictionary<resChangeCb, int>> resourceChangeCallbackDict = new Dictionary<object, Dictionary<resChangeCb, int>>();
+        static public void AddResourceChangedCallback(object handle, resChangeCb cb)
+        {
+            Dictionary<resChangeCb, int> cbDict;
+            resourceChangeCallbackDict.TryGetValue(handle, out cbDict);
+
+            if (null == cbDict)
+            {
+                cbDict = new Dictionary<resChangeCb, int>();
+                resourceChangeCallbackDict.Add(handle, cbDict);
+            }
+
+            if (false == cbDict.ContainsKey(cb))
+            {
+                cbDict.Add(cb, 0);
+            }
+        }
+
+        internal override void OnResourcesChanged(object sender, ResourcesChangedEventArgs e)
+        {
+            base.OnResourcesChanged(sender, e);
+
+            foreach (KeyValuePair<object, Dictionary<resChangeCb, int>> resourcePair in resourceChangeCallbackDict)
+            {
+                foreach (KeyValuePair<resChangeCb, int> cbPair in resourcePair.Value)
+                {
+                    cbPair.Key(sender, e);
+                }
+            }
+        }
+
+        public ResourceDictionary XamlResources
+        {
+            get
+            {
+                if (_resources != null)
+                    return _resources;
+
+                _resources = new ResourceDictionary();
+                int hashCode = _resources.GetHashCode();
+                ((IResourceDictionary)_resources).ValuesChanged += OnResourcesChanged;
+                return _resources;
+            }
+            set
+            {
+                if (_resources == value)
+                    return;
+                OnPropertyChanging();
+
+                if (_resources != null)
+                    ((IResourceDictionary)_resources).ValuesChanged -= OnResourcesChanged;
+                _resources = value;
+                OnResourcesChanged(value);
+                if (_resources != null)
+                    ((IResourceDictionary)_resources).ValuesChanged += OnResourcesChanged;
+
+                OnPropertyChanged();
+            }
+        }
+
+        public event EventHandler<ModalPoppedEventArgs> ModalPopped;
+
+        public event EventHandler<ModalPoppingEventArgs> ModalPopping;
+
+        public event EventHandler<ModalPushedEventArgs> ModalPushed;
+
+        public event EventHandler<ModalPushingEventArgs> ModalPushing;
+
+        public event EventHandler<Page> PageAppearing;
+
+        public event EventHandler<Page> PageDisappearing;
+
+
+        async void SaveProperties()
+        {
+            try
+            {
+                await SetPropertiesAsync();
+            }
+            catch (Exception exc)
+            {
+                Console.WriteLine(nameof(Application), $"Exception while saving Application Properties: {exc}");
+            }
+        }
+
+        public async Task SavePropertiesAsync()
+        {
+            if (Device.IsInvokeRequired)
+            {
+                Device.BeginInvokeOnMainThread(SaveProperties);
+            }
+            else
+            {
+                await SetPropertiesAsync();
+            }
+        }
+
+        // Don't use this unless there really is no better option
+        internal void SavePropertiesAsFireAndForget()
+        {
+            if (Device.IsInvokeRequired)
+            {
+                Device.BeginInvokeOnMainThread(SaveProperties);
+            }
+            else
+            {
+                SaveProperties();
+            }
+        }
+
+        public IPlatformElementConfiguration<T, Application> On<T>() where T : IConfigPlatform
+        {
+            return _platformConfigurationRegistry.Value.On<T>();
+        }
+
+        protected virtual void OnAppLinkRequestReceived(Uri uri)
+        {
+        }
+
+        protected override void OnParentSet()
+        {
+            throw new InvalidOperationException("Setting a Parent on Application is invalid.");
+        }
+
+        protected virtual void OnResume()
+        {
+        }
+
+        protected virtual void OnSleep()
+        {
+        }
+
+        protected virtual void OnStart()
+        {
+        }
+
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static void ClearCurrent()
+        {
+            s_current = null;
+        }
+
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static bool IsApplicationOrNull(Element element)
+        {
+            return element == null || element is Application;
+        }
+
+        internal override void OnParentResourcesChanged(IEnumerable<KeyValuePair<string, object>> values)
+        {
+            if (!((IResourcesProvider)this).IsResourcesCreated || XamlResources.Count == 0)
+            {
+                base.OnParentResourcesChanged(values);
+                return;
+            }
+
+            var innerKeys = new HashSet<string>();
+            var changedResources = new List<KeyValuePair<string, object>>();
+            foreach (KeyValuePair<string, object> c in XamlResources)
+                innerKeys.Add(c.Key);
+            foreach (KeyValuePair<string, object> value in values)
+            {
+                if (innerKeys.Add(value.Key))
+                    changedResources.Add(value);
+            }
+            OnResourcesChanged(changedResources);
+        }
+
+        internal event EventHandler PopCanceled;
+
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void SendOnAppLinkRequestReceived(Uri uri)
+        {
+            OnAppLinkRequestReceived(uri);
+        }
+
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void SendResume()
+        {
+            s_current = this;
+            OnResume();
+        }
+
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void SendSleep()
+        {
+            OnSleep();
+            SavePropertiesAsFireAndForget();
+        }
+
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public Task SendSleepAsync()
+        {
+            OnSleep();
+            return SavePropertiesAsync();
+        }
+
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void SendStart()
+        {
+            OnStart();
+        }
+
+        async Task<IDictionary<string, object>> GetPropertiesAsync()
+        {
+            var deserializer = DependencyService.Get<IDeserializer>();
+            if (deserializer == null)
+            {
+                Console.WriteLine("Startup", "No IDeserialzier was found registered");
+                return new Dictionary<string, object>(4);
+            }
+
+            IDictionary<string, object> properties = await deserializer.DeserializePropertiesAsync().ConfigureAwait(false);
+            if (properties == null)
+                properties = new Dictionary<string, object>(4);
+
+            return properties;
+        }
+
+        internal void OnPageAppearing(Page page)
+            => PageAppearing?.Invoke(this, page);
+
+        internal void OnPageDisappearing(Page page)
+            => PageDisappearing?.Invoke(this, page);
+
+        void OnModalPopped(Page modalPage)
+            => ModalPopped?.Invoke(this, new ModalPoppedEventArgs(modalPage));
+
+        bool OnModalPopping(Page modalPage)
+        {
+            var args = new ModalPoppingEventArgs(modalPage);
+            ModalPopping?.Invoke(this, args);
+            return args.Cancel;
+        }
+
+        void OnModalPushed(Page modalPage)
+            => ModalPushed?.Invoke(this, new ModalPushedEventArgs(modalPage));
+
+        void OnModalPushing(Page modalPage)
+            => ModalPushing?.Invoke(this, new ModalPushingEventArgs(modalPage));
+
+        void OnPopCanceled()
+            => PopCanceled?.Invoke(this, EventArgs.Empty);
+
+        async Task SetPropertiesAsync()
+        {
+            await SaveSemaphore.WaitAsync();
+            try
+            {
+                await DependencyService.Get<IDeserializer>()?.SerializePropertiesAsync(Properties);
+            }
+            finally
+            {
+                SaveSemaphore.Release();
+            }
+
+        }
+
+        class NavigationImpl : NavigationProxy
+        {
+            readonly Application _owner;
+
+            public NavigationImpl(Application owner)
+            {
+                _owner = owner;
+            }
+
+            protected override async Task<Page> OnPopModal(bool animated)
+            {
+                Page modal = ModalStack[ModalStack.Count - 1];
+                if (_owner.OnModalPopping(modal))
+                {
+                    _owner.OnPopCanceled();
+                    return null;
+                }
+                Page result = await base.OnPopModal(animated);
+                result.Parent = null;
+                _owner.OnModalPopped(result);
+                return result;
+            }
+
+            protected override async Task OnPushModal(Page modal, bool animated)
+            {
+                _owner.OnModalPushing(modal);
+
+                modal.Parent = _owner;
+
+                if (modal.NavigationProxy.ModalStack.Count == 0)
+                {
+                    modal.NavigationProxy.Inner = this;
+                    await base.OnPushModal(modal, animated);
+                }
+                else
+                {
+                    await base.OnPushModal(modal, animated);
+                    modal.NavigationProxy.Inner = this;
+                }
+
+                _owner.OnModalPushed(modal);
+            }
+        }
+
         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
 
         internal Application(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.Application_SWIGUpcast(cPtr), cMemoryOwn)
         {
+            NavigationProxy = new NavigationImpl(this);
+            SetCurrentApplication(this);
+
+            _platformConfigurationRegistry = new Lazy<PlatformConfigurationRegistry<Application>>(() => new PlatformConfigurationRegistry<Application>(this));
             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
+
+            SendResume();
         }
 
         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Application obj)
@@ -394,7 +834,7 @@ namespace Tizen.NUI
                 if (swigCMemOwn)
                 {
                     swigCMemOwn = false;
-                    NDalicPINVOKE.delete_Application(swigCPtr);
+                    Interop.Application.delete_Application(swigCPtr);
                 }
                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
             }
@@ -402,6 +842,22 @@ namespace Tizen.NUI
             base.Dispose(type);
         }
 
+        /// <since_tizen> 4 </since_tizen>
+        public enum BatteryStatus
+        {
+            Normal,
+            CriticallyLow,
+            PowerOff
+        };
+
+        /// <since_tizen> 4 </since_tizen>
+        public enum MemoryStatus
+        {
+            Normal,
+            Low,
+            CriticallyLow
+        };
+
         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
         private delegate void NUIApplicationInitEventCallbackDelegate(IntPtr application);
         private DaliEventHandler<object, NUIApplicationInitEventArgs> _applicationInitEventHandler;
@@ -446,12 +902,12 @@ namespace Tizen.NUI
         private NUIApplicationRegionChangedEventCallbackDelegate _applicationRegionChangedEventCallbackDelegate;
 
         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
-        private delegate void NUIApplicationBatteryLowEventCallbackDelegate(IntPtr application);
+        private delegate void NUIApplicationBatteryLowEventCallbackDelegate(BatteryStatus status);
         private DaliEventHandler<object, NUIApplicationBatteryLowEventArgs> _applicationBatteryLowEventHandler;
         private NUIApplicationBatteryLowEventCallbackDelegate _applicationBatteryLowEventCallbackDelegate;
 
         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
-        private delegate void NUIApplicationMemoryLowEventCallbackDelegate(IntPtr application);
+        private delegate void NUIApplicationMemoryLowEventCallbackDelegate(MemoryStatus status);
         private DaliEventHandler<object, NUIApplicationMemoryLowEventArgs> _applicationMemoryLowEventHandler;
         private NUIApplicationMemoryLowEventCallbackDelegate _applicationMemoryLowEventCallbackDelegate;
 
@@ -462,7 +918,6 @@ namespace Tizen.NUI
 
         /**
           * @brief Event for Initialized signal which can be used to subscribe/unsubscribe the event handler
-          * (in the type of NUIApplicationInitEventHandler - DaliEventHandler<object,NUIApplicationInitEventArgs>)
           *  provided by the user. Initialized signal is emitted when application is initialised
           */
         public event DaliEventHandler<object, NUIApplicationInitEventArgs> Initialized
@@ -501,21 +956,18 @@ namespace Tizen.NUI
         {
             // Initialize DisposeQueue Singleton class. This is also required to create DisposeQueue on main thread.
             DisposeQueue.Instance.Initialize();
-            NUIApplicationInitEventArgs e = new NUIApplicationInitEventArgs();
-
-            // Populate all members of "e" (NUIApplicationInitEventArgs) with real data
-            e.Application = Application.GetApplicationFromPtr(data);
 
             if (_applicationInitEventHandler != null)
             {
-                //here we send all data to user event handlers
-                _applicationInitEventHandler(this, e);
+                NUIApplicationInitEventArgs e = new NUIApplicationInitEventArgs();
+                e.Application = this;
+                _applicationInitEventHandler.Invoke(this, e);
             }
+
         }
 
         /**
           * @brief Event for Terminated signal which can be used to subscribe/unsubscribe the event handler
-          * (in the type of NUIApplicationTerminateEventHandler-DaliEventHandler<object,NUIApplicationTerminateEventArgs>)
           *  provided by the user. Terminated signal is emitted when application is terminating
           */
         public event DaliEventHandler<object, NUIApplicationTerminatingEventArgs> Terminating
@@ -552,21 +1004,20 @@ namespace Tizen.NUI
         // Callback for Application TerminateSignal
         private void OnNUIApplicationTerminate(IntPtr data)
         {
-            NUIApplicationTerminatingEventArgs e = new NUIApplicationTerminatingEventArgs();
-
-            // Populate all members of "e" (NUIApplicationTerminateEventArgs) with real data
-            e.Application = Application.GetApplicationFromPtr(data);
-
             if (_applicationTerminateEventHandler != null)
             {
-                //here we send all data to user event handlers
-                _applicationTerminateEventHandler(this, e);
+                NUIApplicationTerminatingEventArgs e = new NUIApplicationTerminatingEventArgs();
+                e.Application = this;
+                _applicationTerminateEventHandler.Invoke(this, e);
+            }
+            if (Window.Instance)
+            {
+                Window.Instance.DisconnectNativeSignals();
             }
         }
 
         /**
           * @brief Event for Paused signal which can be used to subscribe/unsubscribe the event handler
-          * (in the type of NUIApplicationPauseEventHandler-DaliEventHandler<object,NUIApplicationPauseEventArgs>)
           * provided by the user. Paused signal is emitted when application is paused
           */
         public event DaliEventHandler<object, NUIApplicationPausedEventArgs> Paused
@@ -603,21 +1054,16 @@ namespace Tizen.NUI
         // Callback for Application PauseSignal
         private void OnNUIApplicationPause(IntPtr data)
         {
-            NUIApplicationPausedEventArgs e = new NUIApplicationPausedEventArgs();
-
-            // Populate all members of "e" (NUIApplicationPauseEventArgs) with real data
-            e.Application = Application.GetApplicationFromPtr(data);
-
             if (_applicationPauseEventHandler != null)
             {
-                //here we send all data to user event handlers
-                _applicationPauseEventHandler(this, e);
+                NUIApplicationPausedEventArgs e = new NUIApplicationPausedEventArgs();
+                e.Application = this;
+                _applicationPauseEventHandler.Invoke(this, e);
             }
         }
 
         /**
           * @brief Event for Resumed signal which can be used to subscribe/unsubscribe the event handler
-          * (in the type of NUIApplicationResumeEventHandler-DaliEventHandler<object,NUIApplicationResumeEventArgs>)
           *  provided by the user. Resumed signal is emitted when application is resumed
           */
         public event DaliEventHandler<object, NUIApplicationResumedEventArgs> Resumed
@@ -654,21 +1100,16 @@ namespace Tizen.NUI
         // Callback for Application ResumeSignal
         private void OnNUIApplicationResume(IntPtr data)
         {
-            NUIApplicationResumedEventArgs e = new NUIApplicationResumedEventArgs();
-
-            // Populate all members of "e" (NUIApplicationResumeEventArgs) with real data
-            e.Application = Application.GetApplicationFromPtr(data);
-
             if (_applicationResumeEventHandler != null)
             {
-                //here we send all data to user event handlers
-                _applicationResumeEventHandler(this, e);
+                NUIApplicationResumedEventArgs e = new NUIApplicationResumedEventArgs();
+                e.Application = this;
+                _applicationResumeEventHandler.Invoke(this, e);
             }
         }
 
         /**
           * @brief Event for Reset signal which can be used to subscribe/unsubscribe the event handler
-          * (in the type of NUIApplicationResetEventHandler-DaliEventHandler<object,NUIApplicationResetEventArgs>)
           *  provided by the user. Reset signal is emitted when application is reset
           */
         public new event DaliEventHandler<object, NUIApplicationResetEventArgs> Reset
@@ -705,21 +1146,16 @@ namespace Tizen.NUI
         // Callback for Application ResetSignal
         private void OnNUIApplicationReset(IntPtr data)
         {
-            NUIApplicationResetEventArgs e = new NUIApplicationResetEventArgs();
-
-            // Populate all members of "e" (NUIApplicationResetEventArgs) with real data
-            e.Application = Application.GetApplicationFromPtr(data);
-
             if (_applicationResetEventHandler != null)
             {
-                //here we send all data to user event handlers
-                _applicationResetEventHandler(this, e);
+                NUIApplicationResetEventArgs e = new NUIApplicationResetEventArgs();
+                e.Application = this;
+                _applicationResetEventHandler.Invoke(this, e);
             }
         }
 
         /**
           * @brief Event for Resized signal which can be used to subscribe/unsubscribe the event handler
-          * (in the type of NUIApplicationResizeEventHandler-DaliEventHandler<object,NUIApplicationResizeEventArgs>)
           *  provided by the user. Resized signal is emitted when application is resized
           */
         public event DaliEventHandler<object, NUIApplicationResizedEventArgs> Resized
@@ -756,21 +1192,16 @@ namespace Tizen.NUI
         // Callback for Application ResizeSignal
         private void OnNUIApplicationResize(IntPtr data)
         {
-            NUIApplicationResizedEventArgs e = new NUIApplicationResizedEventArgs();
-
-            // Populate all members of "e" (NUIApplicationResizeEventArgs) with real data
-            e.Application = Application.GetApplicationFromPtr(data);
-
             if (_applicationResizeEventHandler != null)
             {
-                //here we send all data to user event handlers
-                _applicationResizeEventHandler(this, e);
+                NUIApplicationResizedEventArgs e = new NUIApplicationResizedEventArgs();
+                e.Application = this;
+                _applicationResizeEventHandler.Invoke(this, e);
             }
         }
 
         /**
           * @brief Event for LanguageChanged signal which can be used to subscribe/unsubscribe the event handler
-          * (in the type of NUIApplicationLanguageChangedEventHandler-DaliEventHandler<object,NUIApplicationLanguageChangedEventArgs>)
           *  provided by the user. LanguageChanged signal is emitted when the region of the device is changed.
           */
         public event DaliEventHandler<object, NUIApplicationLanguageChangedEventArgs> LanguageChanged
@@ -807,21 +1238,16 @@ namespace Tizen.NUI
         // Callback for Application LanguageChangedSignal
         private void OnNUIApplicationLanguageChanged(IntPtr data)
         {
-            NUIApplicationLanguageChangedEventArgs e = new NUIApplicationLanguageChangedEventArgs();
-
-            // Populate all members of "e" (NUIApplicationLanguageChangedEventArgs) with real data
-            e.Application = Application.GetApplicationFromPtr(data);
-
             if (_applicationLanguageChangedEventHandler != null)
             {
-                //here we send all data to user event handlers
-                _applicationLanguageChangedEventHandler(this, e);
+                NUIApplicationLanguageChangedEventArgs e = new NUIApplicationLanguageChangedEventArgs();
+                e.Application = this;
+                _applicationLanguageChangedEventHandler.Invoke(this, e);
             }
         }
 
         /**
           * @brief Event for RegionChanged signal which can be used to subscribe/unsubscribe the event handler
-          * (in the type of NUIApplicationRegionChangedEventHandler-DaliEventHandler<object,NUIApplicationRegionChangedEventArgs>)
           *  provided by the user. RegionChanged signal is emitted when the region of the device is changed.
           */
         public event DaliEventHandler<object, NUIApplicationRegionChangedEventArgs> RegionChanged
@@ -858,21 +1284,16 @@ namespace Tizen.NUI
         // Callback for Application RegionChangedSignal
         private void OnNUIApplicationRegionChanged(IntPtr data)
         {
-            NUIApplicationRegionChangedEventArgs e = new NUIApplicationRegionChangedEventArgs();
-
-            // Populate all members of "e" (NUIApplicationRegionChangedEventArgs) with real data
-            e.Application = Application.GetApplicationFromPtr(data);
-
             if (_applicationRegionChangedEventHandler != null)
             {
-                //here we send all data to user event handlers
-                _applicationRegionChangedEventHandler(this, e);
+                NUIApplicationRegionChangedEventArgs e = new NUIApplicationRegionChangedEventArgs();
+                e.Application = this;
+                _applicationRegionChangedEventHandler.Invoke(this, e);
             }
         }
 
         /**
           * @brief Event for BatteryLow signal which can be used to subscribe/unsubscribe the event handler
-          * (in the type of NUIApplicationBatteryLowEventHandler-DaliEventHandler<object,NUIApplicationBatteryLowEventArgs>)
           * provided by the user. BatteryLow signal is emitted when the battery level of the device is low.
           */
         public event DaliEventHandler<object, NUIApplicationBatteryLowEventArgs> BatteryLow
@@ -907,23 +1328,20 @@ namespace Tizen.NUI
         }
 
         // Callback for Application BatteryLowSignal
-        private void OnNUIApplicationBatteryLow(IntPtr data)
+        private void OnNUIApplicationBatteryLow(BatteryStatus status)
         {
-            NUIApplicationBatteryLowEventArgs e = new NUIApplicationBatteryLowEventArgs();
-
-            // Populate all members of "e" (NUIApplicationBatteryLowEventArgs) with real data
-            e.Application = Application.GetApplicationFromPtr(data);
-
-            if (_applicationBatteryLowEventHandler != null)
+            lock (this)
             {
-                //here we send all data to user event handlers
-                _applicationBatteryLowEventHandler(this, e);
+                NUIApplicationBatteryLowEventArgs e = new NUIApplicationBatteryLowEventArgs();
+
+                // Populate all members of "e" (NUIApplicationBatteryLowEventArgs) with real data
+                e.BatteryStatus = status;
+                _applicationBatteryLowEventHandler?.Invoke(this, e);
             }
         }
 
         /**
           * @brief Event for MemoryLow signal which can be used to subscribe/unsubscribe the event handler
-          * (in the type of NUIApplicationMemoryLowEventHandler-DaliEventHandler<object,NUIApplicationMemoryLowEventArgs>)
           *  provided by the user. MemoryLow signal is emitted when the memory level of the device is low.
           */
         public event DaliEventHandler<object, NUIApplicationMemoryLowEventArgs> MemoryLow
@@ -958,23 +1376,20 @@ namespace Tizen.NUI
         }
 
         // Callback for Application MemoryLowSignal
-        private void OnNUIApplicationMemoryLow(IntPtr data)
+        private void OnNUIApplicationMemoryLow(MemoryStatus status)
         {
-            NUIApplicationMemoryLowEventArgs e = new NUIApplicationMemoryLowEventArgs();
-
-            // Populate all members of "e" (NUIApplicationMemoryLowEventArgs) with real data
-            e.Application = Application.GetApplicationFromPtr(data);
-
-            if (_applicationMemoryLowEventHandler != null)
+            lock (this)
             {
-                //here we send all data to user event handlers
-                _applicationMemoryLowEventHandler(this, e);
+                NUIApplicationMemoryLowEventArgs e = new NUIApplicationMemoryLowEventArgs();
+
+                // Populate all members of "e" (NUIApplicationMemoryLowEventArgs) with real data
+                e.MemoryStatus = status;
+                _applicationMemoryLowEventHandler?.Invoke(this, e);
             }
         }
 
         /**
           * @brief Event for AppControl signal which can be used to subscribe/unsubscribe the event handler
-          * (in the type of NUIApplicationAppControlEventHandler-DaliEventHandler<object,NUIApplicationAppControlEventArgs>)
           *  provided by the user. AppControl signal is emitted when another application sends a launch request to the application.
           */
         public event DaliEventHandler<object, NUIApplicationAppControlEventArgs> AppControl
@@ -1011,16 +1426,12 @@ namespace Tizen.NUI
         // Callback for Application AppControlSignal
         private void OnNUIApplicationAppControl(IntPtr application, IntPtr voidp)
         {
-            NUIApplicationAppControlEventArgs e = new NUIApplicationAppControlEventArgs();
-
-            // Populate all members of "e" (NUIApplicationAppControlEventArgs) with real data
-            e.Application = Application.GetApplicationFromPtr(application);
-            e.VoidP = voidp;
-
             if (_applicationAppControlEventHandler != null)
             {
-                //here we send all data to user event handlers
-                _applicationAppControlEventHandler(this, e);
+                NUIApplicationAppControlEventArgs e = new NUIApplicationAppControlEventArgs();
+                e.VoidP = voidp;
+                e.Application = this;
+                _applicationAppControlEventHandler.Invoke(this, e);
             }
         }
 
@@ -1036,7 +1447,12 @@ namespace Tizen.NUI
 
         public static Application GetApplicationFromPtr(global::System.IntPtr cPtr)
         {
-            Application ret = new Application(cPtr, false);
+            if (cPtr == global::System.IntPtr.Zero)
+            {
+                return null;
+            }
+
+            Application ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Application;
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
         }
@@ -1067,8 +1483,6 @@ namespace Tizen.NUI
 
         public static Application NewApplication(string[] args, string stylesheet, Application.WindowMode windowMode)
         {
-            NUILog.Debug(" NewApplication(string[] args, string stylesheet, Application.WindowMode windowMode) is called! ");
-
             Application ret = New(args, stylesheet, (Application.WindowMode)windowMode);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
 
@@ -1085,9 +1499,9 @@ namespace Tizen.NUI
         public bool AddIdle(System.Delegate func)
         {
             System.IntPtr ip = System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate<System.Delegate>(func);
-            System.IntPtr ip2 = NDalicManualPINVOKE.MakeCallback(new System.Runtime.InteropServices.HandleRef(this, ip));
+            System.IntPtr ip2 = Interop.Application.MakeCallback(new System.Runtime.InteropServices.HandleRef(this, ip));
 
-            bool ret = NDalicPINVOKE.Application_AddIdle(swigCPtr, new System.Runtime.InteropServices.HandleRef(this, ip2));
+            bool ret = Interop.Application.Application_AddIdle(swigCPtr, new System.Runtime.InteropServices.HandleRef(this, ip2));
 
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
@@ -1098,73 +1512,65 @@ namespace Tizen.NUI
         */
         public static Application New()
         {
-            NUILog.Debug("New() is called!");
-
-            Application ret = new Application(NDalicPINVOKE.Application_New__SWIG_0(), true);
+            Application ret = new Application(Interop.Application.Application_New__SWIG_0(), true);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
         }
 
         public static Application New(int argc)
         {
-            NUILog.Debug("New(int argc) is called!");
-
-            Application ret = new Application(NDalicPINVOKE.Application_New__SWIG_1(argc), true);
+            Application ret = new Application(Interop.Application.Application_New__SWIG_1(argc), true);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
         }
 
         public static Application New(int argc, string stylesheet)
         {
-            NUILog.Debug("New(int argc, string stylesheet) is called!");
-
-            Application ret = new Application(NDalicPINVOKE.Application_New__SWIG_2(argc, stylesheet), true);
+            Application ret = new Application(Interop.Application.Application_New__SWIG_2(argc, stylesheet), true);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
         }
 
         public static Application New(int argc, string stylesheet, Application.WindowMode windowMode)
         {
-            NUILog.Debug("New(int argc, string stylesheet, Application.WindowMode windowMode) is called!");
-
-            Application ret = new Application(NDalicPINVOKE.Application_New__SWIG_3(argc, stylesheet, (int)windowMode), true);
+            Application ret = new Application(Interop.Application.Application_New__SWIG_3(argc, stylesheet, (int)windowMode), true);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            ret.SendResume();
             return ret;
         }
 
         public static Application New(string[] args, string stylesheet, Application.WindowMode windowMode)
         {
-            NUILog.Debug("New(string[] args) is called!");
             int argc = args.Length;
             string argvStr = string.Join(" ", args);
 
             Application ret = new Application(NDalicPINVOKE.Application_New__MANUAL_4(argc, argvStr, stylesheet, (int)windowMode), true);
+
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+
             return ret;
         }
 
         public static Application New(int argc, string stylesheet, Application.WindowMode windowMode, Rectangle positionSize)
         {
-            Application ret = new Application(NDalicPINVOKE.Application_New__SWIG_4(argc, stylesheet, (int)windowMode, Rectangle.getCPtr(positionSize)), true);
+            Application ret = new Application(Interop.Application.Application_New__SWIG_4(argc, stylesheet, (int)windowMode, Rectangle.getCPtr(positionSize)), true);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
         }
 
-        public Application() : this(NDalicPINVOKE.new_Application__SWIG_0(), true)
+        public Application() : this(Interop.Application.new_Application__SWIG_0(), true)
         {
-            NUILog.Debug("Application() is called!");
-
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
-        public Application(Application application) : this(NDalicPINVOKE.new_Application__SWIG_1(Application.getCPtr(application)), true)
+        public Application(Application application) : this(Interop.Application.new_Application__SWIG_1(Application.getCPtr(application)), true)
         {
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
         public Application Assign(Application application)
         {
-            Application ret = new Application(NDalicPINVOKE.Application_Assign(swigCPtr, Application.getCPtr(application)), false);
+            Application ret = new Application(Interop.Application.Application_Assign(swigCPtr, Application.getCPtr(application)), false);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
         }
@@ -1177,75 +1583,64 @@ namespace Tizen.NUI
 
         internal void MainLoop(SWIGTYPE_p_Configuration__ContextLoss configuration)
         {
-            NDalicPINVOKE.Application_MainLoop__SWIG_1(swigCPtr, SWIGTYPE_p_Configuration__ContextLoss.getCPtr(configuration));
+            Interop.Application.Application_MainLoop__SWIG_1(swigCPtr, SWIGTYPE_p_Configuration__ContextLoss.getCPtr(configuration));
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
         public void Lower()
         {
-            NDalicPINVOKE.Application_Lower(swigCPtr);
+            Interop.Application.Application_Lower(swigCPtr);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
         public void Quit()
         {
-            NDalicPINVOKE.Application_Quit(swigCPtr);
+            Interop.Application.Application_Quit(swigCPtr);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
         internal bool AddIdle(SWIGTYPE_p_Dali__CallbackBase callback)
         {
-            bool ret = NDalicPINVOKE.Application_AddIdle(swigCPtr, SWIGTYPE_p_Dali__CallbackBase.getCPtr(callback));
+            bool ret = Interop.Application.Application_AddIdle(swigCPtr, SWIGTYPE_p_Dali__CallbackBase.getCPtr(callback));
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
         }
 
         public Window GetWindow()
         {
-            Window ret = new Window(NDalicPINVOKE.Application_GetWindow(swigCPtr), true);
+            Window ret = new Window(Interop.Application.Application_GetWindow(swigCPtr), true);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
         }
 
         public void ReplaceWindow(Rectangle windowPosition, string name)
         {
-            NDalicPINVOKE.Application_ReplaceWindow(swigCPtr, Rectangle.getCPtr(windowPosition), name);
+            Interop.Application.Application_ReplaceWindow(swigCPtr, Rectangle.getCPtr(windowPosition), name);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
         public static string GetResourcePath()
         {
-            string ret = NDalicPINVOKE.Application_GetResourcePath();
+            string ret = Interop.Application.Application_GetResourcePath();
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
         }
 
-        internal void SetViewMode(ViewMode viewMode)
+        public string GetLanguage()
         {
-            NDalicPINVOKE.Application_SetViewMode(swigCPtr, (int)viewMode);
-            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
-        }
-
-        internal ViewMode GetViewMode()
-        {
-            ViewMode ret = (ViewMode)NDalicPINVOKE.Application_GetViewMode(swigCPtr);
+            string ret = Interop.Application.Application_GetLanguage(swigCPtr);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
         }
 
-        public void SetStereoBase(float stereoBase)
-        {
-            NDalicPINVOKE.Application_SetStereoBase(swigCPtr, stereoBase);
-            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
-        }
-
-        public float GetStereoBase()
+        public string GetRegion()
         {
-            float ret = NDalicPINVOKE.Application_GetStereoBase(swigCPtr);
+            string ret = Interop.Application.Application_GetRegion(swigCPtr);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
         }
 
+
         internal ApplicationSignal InitSignal()
         {
             ApplicationSignal ret = new ApplicationSignal(NDalicPINVOKE.Application_InitSignal(swigCPtr), false);
@@ -1309,20 +1704,21 @@ namespace Tizen.NUI
             return ret;
         }
 
-        internal ApplicationSignal BatteryLowSignal()
+        internal LowBatterySignalType BatteryLowSignal()
         {
-            ApplicationSignal ret = new ApplicationSignal(NDalicPINVOKE.Application_BatteryLowSignal(swigCPtr), false);
+            LowBatterySignalType ret = new LowBatterySignalType(NDalicPINVOKE.Application_LowBatterySignal(swigCPtr), false);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
         }
 
-        internal ApplicationSignal MemoryLowSignal()
+        internal LowMemorySignalType MemoryLowSignal()
         {
-            ApplicationSignal ret = new ApplicationSignal(NDalicPINVOKE.Application_MemoryLowSignal(swigCPtr), false);
+            LowMemorySignalType ret = new LowMemorySignalType(NDalicPINVOKE.Application_LowMemorySignal(swigCPtr), false);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
         }
 
+        /// <since_tizen> 3 </since_tizen>
         public enum WindowMode
         {
             Opaque = 0,