[NUI] Clean code releated to application
authorhuiyu.eun <huiyu.eun@samsung.com>
Tue, 16 Feb 2021 04:10:25 +0000 (13:10 +0900)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Thu, 25 Feb 2021 08:24:58 +0000 (17:24 +0900)
- Delete Application.WindowMode
- Delete state of NewApplication without args in Run().
- Delete unused code & variable
- Change to follow NUI coding rule
- Resolve build warnings

Signed-off-by: huiyu.eun <huiyu.eun@samsung.com>
src/Tizen.NUI/src/internal/Application/Application.cs
src/Tizen.NUI/src/internal/Application/NUICoreBackend.cs
src/Tizen.NUI/src/public/Application/NUIApplication.cs
src/Tizen.NUI/src/public/Widget/WidgetViewManager.cs
src/Tizen.NUI/src/public/XamlBinding/IRegisterable.cs [deleted file]
src/Tizen.NUI/src/public/XamlBinding/Registrar.cs

index 8fa349c..c6312d1 100755 (executable)
@@ -1078,15 +1078,15 @@ namespace Tizen.NUI
 
         public static Application NewApplication()
         {
-            return NewApplication("", Application.WindowMode.Opaque);
+            return NewApplication("", NUIApplication.WindowMode.Opaque);
         }
 
         public static Application NewApplication(string stylesheet)
         {
-            return NewApplication(stylesheet, Application.WindowMode.Opaque);
+            return NewApplication(stylesheet, NUIApplication.WindowMode.Opaque);
         }
 
-        public static Application NewApplication(string stylesheet, Application.WindowMode windowMode)
+        public static Application NewApplication(string stylesheet, NUIApplication.WindowMode windowMode)
         {
             // register all Views with the type registry, so that can be created / styled via JSON
             //ViewRegistryHelper.Initialize(); //moved to Application side.
@@ -1103,7 +1103,7 @@ namespace Tizen.NUI
             return ret;
         }
 
-        public static Application NewApplication(string stylesheet, Application.WindowMode windowMode, Rectangle positionSize)
+        public static Application NewApplication(string stylesheet, NUIApplication.WindowMode windowMode, Rectangle positionSize)
         {
             if (_instance)
             {
@@ -1117,13 +1117,13 @@ namespace Tizen.NUI
             return ret;
         }
 
-        public static Application NewApplication(string[] args, string stylesheet, Application.WindowMode windowMode)
+        public static Application NewApplication(string[] args, string stylesheet, NUIApplication.WindowMode windowMode)
         {
             if (_instance)
             {
                 return _instance;
             }
-            Application ret = New(args, stylesheet, (Application.WindowMode)windowMode);
+            Application ret = New(args, stylesheet, windowMode);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
 
             // set the singleton
@@ -1131,13 +1131,13 @@ namespace Tizen.NUI
             return _instance;
         }
 
-        public static Application NewApplication(string[] args, string stylesheet, Application.WindowMode windowMode, Rectangle positionSize)
+        public static Application NewApplication(string[] args, string stylesheet, NUIApplication.WindowMode windowMode, Rectangle positionSize)
         {
             if (_instance)
             {
                 return _instance;
             }
-            Application ret = New(args, stylesheet, (Application.WindowMode)windowMode, positionSize);
+            Application ret = New(args, stylesheet, windowMode, positionSize);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
 
             // set the singleton
@@ -1185,7 +1185,7 @@ namespace Tizen.NUI
             return ret;
         }
 
-        public static Application New(int argc, string stylesheet, Application.WindowMode windowMode)
+        public static Application New(int argc, string stylesheet, NUIApplication.WindowMode windowMode)
         {
             Application ret = new Application(Interop.Application.New(argc, stylesheet, (int)windowMode), true);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
@@ -1193,7 +1193,7 @@ namespace Tizen.NUI
             return ret;
         }
 
-        public static Application New(string[] args, string stylesheet, Application.WindowMode windowMode)
+        public static Application New(string[] args, string stylesheet, NUIApplication.WindowMode windowMode)
         {
             Application ret = null;
             int argc = 0;
@@ -1217,14 +1217,14 @@ namespace Tizen.NUI
             return ret;
         }
 
-        public static Application New(int argc, string stylesheet, Application.WindowMode windowMode, Rectangle positionSize)
+        public static Application New(int argc, string stylesheet, NUIApplication.WindowMode windowMode, Rectangle positionSize)
         {
             Application ret = new Application(Interop.Application.New(argc, stylesheet, (int)windowMode, Rectangle.getCPtr(positionSize)), true);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
         }
 
-        public static Application New(string[] args, string stylesheet, Application.WindowMode windowMode, Rectangle positionSize)
+        public static Application New(string[] args, string stylesheet, NUIApplication.WindowMode windowMode, Rectangle positionSize)
         {
             Application ret = null;
             int argc = 0;
@@ -1411,11 +1411,5 @@ namespace Tizen.NUI
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
         }
-
-        public enum WindowMode
-        {
-            Opaque = 0,
-            Transparent = 1
-        }
     }
 }
index 615cc1c..0cc935c 100755 (executable)
@@ -27,11 +27,10 @@ namespace Tizen.NUI
         /// <summary>
         /// The Application instance to connect event.
         /// </summary>
-        protected Application _application;
-        private string _stylesheet = "";
-        private NUIApplication.WindowMode _windowMode = NUIApplication.WindowMode.Opaque;
-        private Size2D _windowSize = null;
-        private Position2D _windowPosition = null;
+        protected Application application;
+        private string stylesheet = "";
+        private NUIApplication.WindowMode windowMode = NUIApplication.WindowMode.Opaque;
+        private Rectangle windowRectangle = null;
 
         /// <summary>
         /// The Dictionary to contain each type of event callback.
@@ -50,7 +49,7 @@ namespace Tizen.NUI
         /// </summary>
         public NUICoreBackend(string stylesheet)
         {
-            _stylesheet = stylesheet;
+            this.stylesheet = stylesheet;
         }
 
         /// <summary>
@@ -58,8 +57,8 @@ namespace Tizen.NUI
         /// </summary>
         public NUICoreBackend(string stylesheet, NUIApplication.WindowMode windowMode)
         {
-            _stylesheet = stylesheet;
-            _windowMode = windowMode;
+            this.stylesheet = stylesheet;
+            this.windowMode = windowMode;
         }
 
         /// <summary>
@@ -67,10 +66,12 @@ namespace Tizen.NUI
         /// </summary>
         public NUICoreBackend(string stylesheet, NUIApplication.WindowMode windowMode, Size2D windowSize, Position2D windowPosition)
         {
-            _stylesheet = stylesheet;
-            _windowMode = windowMode;
-            _windowSize = windowSize;
-            _windowPosition = windowPosition;
+            this.stylesheet = stylesheet;
+            this.windowMode = windowMode;
+            if (windowSize != null && windowPosition != null)
+            {
+                this.windowRectangle = new Rectangle(windowPosition.X, windowPosition.Y, windowSize.Width, windowSize.Height);
+            }
         }
 
         /// <summary>
@@ -101,17 +102,13 @@ namespace Tizen.NUI
         /// </summary>
         public void Dispose()
         {
-            if (_application != null)
-            {
-                _application.Dispose();
-            }
-            if (_windowSize != null)
+            if (application != null)
             {
-                _windowSize.Dispose();
+                application.Dispose();
             }
-            if (_windowPosition != null)
+            if (windowRectangle != null)
             {
-                _windowPosition.Dispose();
+                windowRectangle.Dispose();
             }
         }
 
@@ -120,9 +117,9 @@ namespace Tizen.NUI
         /// </summary>
         public void Exit()
         {
-            if (_application != null)
+            if (application != null)
             {
-                _application.Quit();
+                application.Quit();
             }
         }
 
@@ -133,7 +130,7 @@ namespace Tizen.NUI
         /// <returns>true if added successfully, false otherwise</returns>
         public bool AddIdle(System.Delegate func)
         {
-            return _application.AddIdle(func);
+            return application.AddIdle(func);
         }
 
         /// <summary>
@@ -150,42 +147,28 @@ namespace Tizen.NUI
                 args[0] = this.GetType().Assembly.FullName;
             }
 
-            if (args.Length == 1)
+            if (windowRectangle != null)
             {
-                if (_windowSize != null)
-                {
-                    _application = Application.NewApplication(_stylesheet, (Application.WindowMode)_windowMode, new Rectangle(_windowPosition.X, _windowPosition.Y, _windowSize.Width, _windowSize.Height));
-                }
-                else
-                {
-                    _application = Application.NewApplication(_stylesheet, (Application.WindowMode)_windowMode);
-                }
+                application = Application.NewApplication(args, stylesheet, windowMode, windowRectangle);
             }
-            else if (args.Length > 1)
+            else
             {
-                if (_windowSize != null)
-                {
-                    _application = Application.NewApplication(args, _stylesheet, (Application.WindowMode)_windowMode, new Rectangle(_windowPosition.X, _windowPosition.Y, _windowSize.Width, _windowSize.Height));
-                }
-                else
-                {
-                    _application = Application.NewApplication(args, _stylesheet, (Application.WindowMode)_windowMode);
-                }
+                application = Application.NewApplication(args, stylesheet, windowMode);
             }
 
-            _application.BatteryLow += OnBatteryLow;
-            _application.LanguageChanged += OnLanguageChanged;
-            _application.MemoryLow += OnMemoryLow;
-            _application.RegionChanged += OnRegionChanged;
+            application.BatteryLow += OnBatteryLow;
+            application.LanguageChanged += OnLanguageChanged;
+            application.MemoryLow += OnMemoryLow;
+            application.RegionChanged += OnRegionChanged;
 
-            _application.Initialized += OnInitialized;
-            _application.Resumed += OnResumed;
-            _application.Terminating += OnTerminated;
-            _application.Paused += OnPaused;
-            _application.AppControl += OnAppControl;
+            application.Initialized += OnInitialized;
+            application.Resumed += OnResumed;
+            application.Terminating += OnTerminated;
+            application.Paused += OnPaused;
+            application.AppControl += OnAppControl;
 
-            _application.MainLoop();
-            _application.Dispose();
+            application.MainLoop();
+            application.Dispose();
         }
 
         /// <summary>
@@ -340,7 +323,7 @@ namespace Tizen.NUI
         {
             get
             {
-                return _application;
+                return application;
             }
         }
     }
index 90e3aab..56c553f 100755 (executable)
@@ -39,28 +39,24 @@ namespace Tizen.NUI
         /// The instance of ResourceManager.
         /// </summary>
         private static System.Resources.ResourceManager resourceManager = null;
-        private Size2D _windowSize2D = null;
-        private Position2D _windowPosition2D = null;
-        private TransitionOptions transitionOptions;
-        private string appId = null;
-        internal static NUIApplication me;
-
-        private static bool isPreload = false;
 
         // TODO Enable this after tizen-theme-manager is released.
         // private readonly ThemeLoader themeLoader = new ThemeLoader();
 
+        static NUIApplication()
+        {
+            Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
+            // TODO Enable this after tizen-theme-manager is released.
+            // themeLoader.ThemeChanged += TizenThemeChanged;
+        }
+
         /// <summary>
         /// The default constructor.
         /// </summary>
         /// <since_tizen> 3 </since_tizen>
+        [SuppressMessage("Microsoft.Design", "CA2000: Dispose objects before losing scope", Justification = "NUICoreBackend is disposed in the base class when the application is terminated")]
         public NUIApplication() : base(new NUICoreBackend())
         {
-            Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
-            me = this;
-
-            // TODO Enable this after tizen-theme-manager is released.
-            // themeLoader.ThemeChanged += TizenThemeChanged;
         }
 
         /// <summary>
@@ -70,15 +66,10 @@ namespace Tizen.NUI
         /// <param name="windowPosition">The window position.</param>
         /// <since_tizen> 5 </since_tizen>
         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+        [SuppressMessage("Microsoft.Design", "CA2000: Dispose objects before losing scope", Justification = "NUICoreBackend is disposed in the base class when the application is terminated")]
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public NUIApplication(Size2D windowSize, Position2D windowPosition) : base(new NUICoreBackend("", WindowMode.Opaque, windowSize, windowPosition))
+        public NUIApplication(Size2D windowSize, Position2D windowPosition) : base(new NUICoreBackend("", NUIApplication.WindowMode.Opaque, windowSize, windowPosition))
         {
-            Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
-            // TODO Enable this after tizen-theme-manager is released.
-            // themeLoader.ThemeChanged += TizenThemeChanged;
-            _windowSize2D = windowSize;
-            _windowPosition2D = windowPosition;
-            me = this;
         }
 
         /// <summary>
@@ -86,12 +77,9 @@ namespace Tizen.NUI
         /// </summary>
         /// <param name="styleSheet">The styleSheet url.</param>
         /// <since_tizen> 3 </since_tizen>
+        [SuppressMessage("Microsoft.Design", "CA2000: Dispose objects before losing scope", Justification = "NUICoreBackend is disposed in the base class when the application is terminated")]
         public NUIApplication(string styleSheet) : base(new NUICoreBackend(styleSheet))
         {
-            Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
-            me = this;
-            // TODO Enable this after tizen-theme-manager is released.
-            // themeLoader.ThemeChanged += TizenThemeChanged;
         }
 
         /// <summary>
@@ -102,15 +90,10 @@ namespace Tizen.NUI
         /// <param name="windowPosition">The window position.</param>
         /// <since_tizen> 5 </since_tizen>
         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+        [SuppressMessage("Microsoft.Design", "CA2000: Dispose objects before losing scope", Justification = "NUICoreBackend is disposed in the base class when the application is terminated")]
         [EditorBrowsable(EditorBrowsableState.Never)]
         public NUIApplication(string styleSheet, Size2D windowSize, Position2D windowPosition) : base(new NUICoreBackend(styleSheet, WindowMode.Opaque, windowSize, windowPosition))
         {
-            Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
-            // TODO Enable this after tizen-theme-manager is released.
-            // themeLoader.ThemeChanged += TizenThemeChanged;
-            _windowSize2D = windowSize;
-            _windowPosition2D = windowPosition;
-            me = this;
         }
 
         /// <summary>
@@ -119,12 +102,9 @@ namespace Tizen.NUI
         /// <param name="styleSheet">The styleSheet url.</param>
         /// <param name="windowMode">The windowMode.</param>
         /// <since_tizen> 3 </since_tizen>
+        [SuppressMessage("Microsoft.Design", "CA2000: Dispose objects before losing scope", Justification = "NUICoreBackend is disposed in the base class when the application is terminated")]
         public NUIApplication(string styleSheet, WindowMode windowMode) : base(new NUICoreBackend(styleSheet, windowMode))
         {
-            Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
-            me = this;
-            // TODO Enable this after tizen-theme-manager is released.
-            // themeLoader.ThemeChanged += TizenThemeChanged;
         }
 
         /// <summary>
@@ -136,15 +116,10 @@ namespace Tizen.NUI
         /// <param name="windowPosition">The window position.</param>
         /// <since_tizen> 5 </since_tizen>
         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
+        [SuppressMessage("Microsoft.Design", "CA2000: Dispose objects before losing scope", Justification = "NUICoreBackend is disposed in the base class when the application is terminated")]
         [EditorBrowsable(EditorBrowsableState.Never)]
         public NUIApplication(string styleSheet, WindowMode windowMode, Size2D windowSize, Position2D windowPosition) : base(new NUICoreBackend(styleSheet, windowMode, windowSize, windowPosition))
         {
-            Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
-            // TODO Enable this after tizen-theme-manager is released.
-            // themeLoader.ThemeChanged += TizenThemeChanged;
-            _windowSize2D = windowSize;
-            _windowPosition2D = windowPosition;
-            me = this;
         }
 
         /// <summary>
@@ -163,13 +138,6 @@ namespace Tizen.NUI
             //windowMode and styleSheet will be added later. currenlty it's not working as expected.
             Graphics.Backend = backend;
             Tizen.Log.Error("NUI", "Plaese DO NOT set graphical backend type with this constructor! This will give no effect!");
-
-            if (windowSize != null) { _windowSize2D = windowSize; }
-            if (windowPosition != null) { _windowPosition2D = windowPosition; }
-            Registry.Instance.SavedApplicationThread = Thread.CurrentThread;
-            me = this;
-            // TODO Enable this after tizen-theme-manager is released.
-            // themeLoader.ThemeChanged += TizenThemeChanged;
         }
 
         /// <summary>
@@ -241,7 +209,7 @@ namespace Tizen.NUI
         {
             get
             {
-                return appId;
+                return Tizen.Applications.Application.Current.ApplicationInfo.ApplicationId;
             }
         }
 
@@ -418,7 +386,6 @@ namespace Tizen.NUI
         protected override void OnCreate()
         {
             base.OnCreate();
-            appId = Tizen.Applications.Application.Current.ApplicationInfo.ApplicationId;
         }
 
         /// <summary>
@@ -428,7 +395,7 @@ namespace Tizen.NUI
         static public void Preload()
         {
             Interop.Application.PreInitialize();
-            isPreload = true;
+            IsPreload = true;
         }
 
         /// <summary>
@@ -437,24 +404,14 @@ namespace Tizen.NUI
         [EditorBrowsable(EditorBrowsableState.Never)]
         public void SendLaunchRequest(AppControl appControl)
         {
-            transitionOptions.SendLaunchRequest(appControl);
+            TransitionOptions?.SendLaunchRequest(appControl);
         }
 
         /// <summary>
         /// This is used to improve application launch performance.
         /// </summary>
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public TransitionOptions TransitionOptions
-        {
-            get
-            {
-                return transitionOptions;
-            }
-            set
-            {
-                transitionOptions = value;
-            }
-        }
+        public TransitionOptions TransitionOptions { get; set; }
 
         // TODO Enable this after tizen-theme-manager is released.
         // private void TizenThemeChanged(object sender, ThemeEventArgs e)
@@ -482,13 +439,7 @@ namespace Tizen.NUI
         /// <summary>
         /// Check if it is loaded as dotnet-loader-nui.
         /// </summary>
-        static internal bool IsPreload
-        {
-            get
-            {
-                return isPreload;
-            }
-        }
+        static internal bool IsPreload { get; set; }
     }
 
     /// <summary>
index 885956a..f86cdd4 100755 (executable)
@@ -40,7 +40,7 @@ namespace Tizen.NUI
         /// Creates a new widgetView manager object.
         /// </summary>
         /// <since_tizen> 6 </since_tizen>
-        internal WidgetViewManager() : this(Interop.WidgetViewManager.New(Application.getCPtr(NUIApplication.me?.ApplicationHandle), NUIApplication.me?.AppId), true)
+        internal WidgetViewManager() : this(Interop.WidgetViewManager.New(Application.Instance.SwigCPtr, Applications.Application.Current.ApplicationInfo.ApplicationId), true)
         {
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
@@ -57,9 +57,9 @@ namespace Tizen.NUI
         {
             get
             {
-                if(!instance)
+                if (!instance)
                 {
-                    instance  = new WidgetViewManager();
+                    instance = new WidgetViewManager();
                     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
                 }
                 return instance;
diff --git a/src/Tizen.NUI/src/public/XamlBinding/IRegisterable.cs b/src/Tizen.NUI/src/public/XamlBinding/IRegisterable.cs
deleted file mode 100755 (executable)
index ab41c61..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-using System.ComponentModel;
-
-namespace Tizen.NUI.Binding
-{
-    /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
-    [EditorBrowsable(EditorBrowsableState.Never)]
-    public interface IRegisterable
-    {
-    }
-}
index 42b912c..bf3ce79 100755 (executable)
@@ -212,7 +212,6 @@ namespace Tizen.NUI.Binding.Internals
     {
         static Registrar()
         {
-            Registered = new Registrar<IRegisterable>();
         }
 
         internal static Dictionary<string, Type> Effects { get; } = new Dictionary<string, Type>();
@@ -220,9 +219,5 @@ namespace Tizen.NUI.Binding.Internals
         /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
         [EditorBrowsable(EditorBrowsableState.Never)]
         public static IEnumerable<Assembly> ExtraAssemblies { get; set; }
-
-        /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        public static Registrar<IRegisterable> Registered { get; internal set; }
     }
 }