[Tizen] Add NUIWidgetApplication and NUIWidgetCoreBackend
authorminho.sun <minho.sun@samsung.com>
Tue, 29 Aug 2017 02:41:57 +0000 (11:41 +0900)
committerMinho Sun <minho.sun@samsung.com>
Thu, 31 Aug 2017 04:18:28 +0000 (04:18 +0000)
Change-Id: I9ddc54cb5517289af6bbe0b3dfb4baa41b8c3c8e
Signed-off-by: minho.sun <minho.sun@samsung.com>
src/Tizen.NUI/src/internal/NUIWidgetCoreBackend.cs [new file with mode: 0755]
src/Tizen.NUI/src/public/NUIWidgetApplication.cs [new file with mode: 0755]

diff --git a/src/Tizen.NUI/src/internal/NUIWidgetCoreBackend.cs b/src/Tizen.NUI/src/internal/NUIWidgetCoreBackend.cs
new file mode 100755 (executable)
index 0000000..ec05e43
--- /dev/null
@@ -0,0 +1,208 @@
+/*
+ * 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.
+ *
+ */
+
+using System;
+using System.Collections.Generic;
+
+using Tizen.Applications.CoreBackend;
+using Tizen.Applications;
+
+namespace Tizen.NUI
+{
+    class NUIWidgetCoreBackend : ICoreBackend
+    {
+        /// <summary>
+        /// Application instance to connect event.
+        /// </summary>
+        protected WidgetApplication _application;
+        private string _stylesheet = "";
+
+        /// <summary>
+        /// Dictionary to contain each type of event callback.
+        /// </summary>
+        protected IDictionary<EventType, object> Handlers = new Dictionary<EventType, object>();
+
+        /// <summary>
+        /// The default Constructor.
+        /// </summary>
+        public NUIWidgetCoreBackend()
+        {
+            //Tizen.Log.Fatal("NUI", "### NUIWidgetCoreBackend called");
+            //_application = WidgetApplication.NewWidgetApplication();
+        }
+
+        /// <summary>
+        /// The constructor with stylesheet.
+        /// </summary>
+        public NUIWidgetCoreBackend(string stylesheet)
+        {
+            _stylesheet = stylesheet;
+            //_application = WidgetApplication.NewWidgetApplication(stylesheet);
+        }
+
+        /// <summary>
+        /// Add NUIWidgetApplication event to Application.
+        /// Put each type of event callback in Dictionary.
+        /// </summary>
+        /// <param name="evType">Type of event</param>
+        /// <param name="handler">Event callback</param>
+        public void AddEventHandler(EventType evType, Action handler)
+        {
+            Handlers.Add(evType, handler);
+        }
+
+        /// <summary>
+        /// Add NUIWidgetApplication event to Application.
+        /// Put each type of event callback in Dictionary.
+        /// </summary>
+        /// <typeparam name="TEventArgs">Argument type for the event</typeparam>
+        /// <param name="evType">Type of event</param>
+        /// <param name="handler">Event callback</param>
+        public void AddEventHandler<TEventArgs>(EventType evType, Action<TEventArgs> handler) where TEventArgs : EventArgs
+        {
+            Handlers.Add(evType, handler);
+        }
+
+
+        /// <summary>
+        /// Dispose function.
+        /// </summary>
+        public void Dispose()
+        {
+            Tizen.Log.Fatal("NUI", "### NUIWidgetCoreBackend Dispose called");
+            if (_application != null)
+            {
+                _application.Dispose();
+            }
+        }
+
+        /// <summary>
+        /// Exit Application.
+        /// </summary>
+        public void Exit()
+        {
+            Tizen.Log.Fatal("NUI", "### NUIWidgetCoreBackend Exit called");
+            if (_application != null)
+            {
+                _application.Quit();
+            }
+        }
+
+        /// <summary>
+        /// Run Application.
+        /// </summary>
+        /// <param name="args">Arguments from commandline.</param>
+        public void Run(string[] args)
+        {
+            args[0] = Tizen.Applications.Application.Current.ApplicationInfo.ExecutablePath;
+            _application = WidgetApplication.NewWidgetApplication(args, _stylesheet);
+
+            TizenSynchronizationContext.Initialize();
+            _application.BatteryLow += OnBatteryLow;
+            _application.LanguageChanged += OnLanguageChanged;
+            _application.MemoryLow += OnMemoryLow;
+            _application.RegionChanged += OnRegionChanged; ;
+
+            _application.Init += OnInit;
+            _application.Terminate += OnTerminate;
+
+            _application.MainLoop();
+        }
+
+        private void OnInit(object sender, WidgetApplication.WidgetApplicationEventArgs e)
+        {
+            Log.Fatal("NUI", "NUIWidgetApplication OnPreCreated Called");
+            var preCreateHandler = Handlers[EventType.PreCreated] as Action;
+            preCreateHandler?.Invoke();
+
+            Log.Fatal("NUI", "NUIWidgetApplication OnCreate Called");
+            var createHandler = Handlers[EventType.Created] as Action;
+            createHandler?.Invoke();
+
+        }
+
+        private void OnTerminate(object sender, WidgetApplication.WidgetApplicationEventArgs e)
+        {
+            Log.Fatal("NUI", "NUIWidgetApplication OnTerminated Called");
+            var handler = Handlers[EventType.Terminated] as Action;
+            handler?.Invoke();
+        }
+
+        /// <summary>
+        /// Region changed event callback function.
+        /// </summary>
+        /// <param name="source">Application instance</param>
+        /// <param name="e">Event argument for RegionChanged</param>
+        private void OnRegionChanged(object sender, WidgetApplication.WidgetApplicationEventArgs e)
+        {
+            Log.Fatal("NUI", "NUIWidgetApplication OnRegionChanged Called");
+            var handler = Handlers[EventType.RegionFormatChanged] as Action<RegionFormatChangedEventArgs>;
+            // Need to make new signal return in native to return right value.
+            handler?.Invoke(new RegionFormatChangedEventArgs(""));
+        }
+
+        /// <summary>
+        /// Memory Low event callback function.
+        /// </summary>
+        /// <param name="source">Application instance</param>
+        /// <param name="e">Event argument for MemoryLow</param>
+        private void OnMemoryLow(object sender, WidgetApplication.WidgetApplicationEventArgs e)
+        {
+            Log.Fatal("NUI", "NUIWidgetApplication OnMemoryLow Called");
+            var handler = Handlers[EventType.LowMemory] as Action<LowMemoryEventArgs>;
+            // Need to make new signal return in native to return right value.
+            handler?.Invoke(new LowMemoryEventArgs(LowMemoryStatus.None));
+        }
+
+        /// <summary>
+        /// Language changed event callback function.
+        /// </summary>
+        /// <param name="source">Application instance</param>
+        /// <param name="e">Event argument for LanguageChanged</param>
+        private void OnLanguageChanged(object sender, WidgetApplication.WidgetApplicationEventArgs e)
+        {
+
+            Log.Fatal("NUI", "NUIWidgetApplication OnLanguageChanged Called");
+            var handler = Handlers[EventType.LocaleChanged] as Action<LocaleChangedEventArgs>;
+            // Need to make new signal return in native to return right value.
+            handler?.Invoke(new LocaleChangedEventArgs(""));
+
+        }
+
+        /// <summary>
+        /// Battery low event callback function.
+        /// </summary>
+        /// <param name="source">Application instance</param>
+        /// <param name="e">Event argument for BatteryLow</param>
+        private void OnBatteryLow(object sender, WidgetApplication.WidgetApplicationEventArgs e)
+        {
+            Log.Fatal("NUI", "NUIWidgetApplication OnBatteryLow Called");
+            var handler = Handlers[EventType.LowBattery] as Action<LowBatteryEventArgs>;
+            // Need to make new signal return in native to return right value.
+            handler?.Invoke(new LowBatteryEventArgs(LowBatteryStatus.None));
+
+        }
+
+        internal WidgetApplication WidgetApplicationHandle
+        {
+            get
+            {
+                return _application;
+            }
+        }
+    }
+}
diff --git a/src/Tizen.NUI/src/public/NUIWidgetApplication.cs b/src/Tizen.NUI/src/public/NUIWidgetApplication.cs
new file mode 100755 (executable)
index 0000000..c0de24c
--- /dev/null
@@ -0,0 +1,152 @@
+/*
+ * Copyright (c) 2016 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.
+ *
+ */
+
+using System;
+using Tizen.Applications;
+using Tizen.Applications.CoreBackend;
+using Tizen.NUI;
+
+namespace Tizen.NUI
+{
+
+    /// <summary>
+    /// Represents an application that have UI screen. The NUIWidgetApplication class has a default stage.
+    /// </summary>
+    public class NUIWidgetApplication : CoreApplication
+    {
+
+        /// <summary>
+        /// The default constructor.
+        /// </summary>
+        public NUIWidgetApplication() : base(new NUIWidgetCoreBackend())
+        {
+            Tizen.Log.Fatal("NUI", "### NUIWidgetApplication called");
+        }
+
+        /// <summary>
+        /// The constructor with stylesheet.
+        /// </summary>
+        public NUIWidgetApplication(string stylesheet) : base(new NUIWidgetCoreBackend(stylesheet))
+        {
+            Tizen.Log.Fatal("NUI", "### NUIWidgetApplication(string) called");
+        }
+
+        /// <summary>
+        /// Overrides this method if want to handle behavior.
+        /// </summary>
+        protected override void OnLocaleChanged(LocaleChangedEventArgs e)
+        {
+            Log.Fatal("NUI", "OnLocaleChanged() is called!");
+            base.OnLocaleChanged(e);
+        }
+
+        /// <summary>
+        /// Overrides this method if want to handle behavior.
+        /// </summary>
+        protected override void OnLowBattery(LowBatteryEventArgs e)
+        {
+            Log.Fatal("NUI", "OnLowBattery() is called!");
+            base.OnLowBattery(e);
+        }
+
+        /// <summary>
+        /// Overrides this method if want to handle behavior.
+        /// </summary>
+        protected override void OnLowMemory(LowMemoryEventArgs e)
+        {
+            Log.Fatal("NUI", "OnLowMemory() is called!");
+            base.OnLowMemory(e);
+        }
+
+        /// <summary>
+        /// Overrides this method if want to handle behavior.
+        /// </summary>
+        protected override void OnRegionFormatChanged(RegionFormatChangedEventArgs e)
+        {
+            Log.Fatal("NUI", "OnRegionFormatChanged() is called!");
+            base.OnRegionFormatChanged(e);
+        }
+
+        /// <summary>
+        /// Overrides this method if want to handle behavior.
+        /// </summary>
+        protected override void OnTerminate()
+        {
+            Log.Fatal("NUI", "OnTerminate() is called!");
+            base.OnTerminate();
+        }
+
+        /// <summary>
+        /// Overrides this method if want to handle behavior.
+        /// </summary>
+        protected virtual void OnPreCreate()
+        {
+            Log.Fatal("NUI", "OnPreCreate() is called!");
+        }
+
+        /// <summary>
+        /// Overrides this method if want to handle behavior.
+        /// </summary>
+        protected override void OnCreate()
+        {
+            // This is also required to create DisposeQueue on main thread.
+            DisposeQueue disposeQ = DisposeQueue.Instance;
+            disposeQ.Initialize();
+            Log.Fatal("NUI","OnCreate() is called!");
+            base.OnCreate();
+        }
+
+        /// <summary>
+        /// Run NUIWidgetApplication.
+        /// </summary>
+        /// <param name="args">Arguments from commandline.</param>
+        public override void Run(string[] args)
+        {
+            Backend.AddEventHandler(EventType.PreCreated, OnPreCreate);
+            base.Run(args);
+        }
+
+        /// <summary>
+        /// Exit NUIWidgetApplication.
+        /// </summary>
+        public override void Exit()
+        {
+            Tizen.Log.Fatal("NUI", "### NUIWidgetApplication Exit called");
+            base.Exit();
+        }
+
+        internal WidgetApplication ApplicationHandle
+        {
+            get
+            {
+                return ((NUIWidgetCoreBackend)this.Backend).WidgetApplicationHandle;
+            }
+        }
+
+        /// <summary>
+        /// Get the window instance.
+        /// </summary>
+        public Window Window
+        {
+            get
+            {
+                //return Window.Instance;
+                return ApplicationHandle.GetWindow();
+            }
+        }
+    }
+}