[OAPSAN-4414] ProcessManager implementation (#2)
authorLukasz Stanislawski/IoT & UI Sample (PLT) /SRPOL/Engineer/Samsung Electronics <l.stanislaws@samsung.com>
Mon, 9 Mar 2020 13:22:53 +0000 (14:22 +0100)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Mon, 9 Mar 2020 13:22:53 +0000 (14:22 +0100)
* ProcessManager implementation

12 files changed:
Oobe/Oobe/Managers/ProcessManager.cs [new file with mode: 0644]
Oobe/Oobe/Oobe.cs
Oobe/Oobe/Views/MainView.cs [new file with mode: 0644]
Oobe/Oobe/Views/OobeViewSwitcher.cs [deleted file]
Oobe/OobeCommon/Interfaces/IProcessNavigation.cs
Oobe/OobeCommon/Interfaces/ProcessInfo.cs [deleted file]
Oobe/OobeCommon/Interfaces/ProcessStep.cs
Oobe/OobeLanguage/LanguageStep.cs
Oobe/OobeLanguage/OobeLanguage.csproj
Oobe/OobeRegion/Class1.cs [deleted file]
Oobe/OobeRegion/OobeRegion.csproj
Oobe/OobeRegion/RegionStep.cs [new file with mode: 0644]

diff --git a/Oobe/Oobe/Managers/ProcessManager.cs b/Oobe/Oobe/Managers/ProcessManager.cs
new file mode 100644 (file)
index 0000000..2de00b5
--- /dev/null
@@ -0,0 +1,77 @@
+using System.Collections.Generic;
+using Oobe.Common.Interfaces;
+using Oobe.Language;
+using Oobe.Views;
+using Tizen.NUI;
+using Oobe.Region;
+using System;
+ namespace Oobe
+ {
+     public class ProcessManager : IProcessNavigation
+     {
+        private MainView ui;
+        private LinkedList<Lazy<ProcessStep>> steps;
+        private LinkedListNode<Lazy<ProcessStep>> current;
+
+        public ProcessManager()
+        {
+            //TODO consider loading this from xaml, xml or something...
+            steps = new LinkedList<Lazy<ProcessStep>>(new List<Lazy<ProcessStep>>{
+                new Lazy<ProcessStep>(() => new LanguageStep()),
+                new Lazy<ProcessStep>(() => new RegionStep())}
+            );
+        }
+
+        public void Start()
+        {
+            ui = new MainView(Window.Instance);
+
+            current = steps.First;
+            current.Value.Value.Initialize();
+            ui.Push(current.Value.Value.CreateView(this));
+            current.Next?.Value.Value.Initialize();
+        }
+
+        /// <summary>
+        /// Next shows next view in the process or finish the process
+        /// </summary>
+        public void Next()
+        {
+            // end process if all steps are done
+            if (current.Next == null)
+            {
+                Exit();
+                return;
+            }
+
+            current = current.Next;
+            ui.Push(current.Value.Value.CreateView(this));
+            current.Next?.Value.Value.Initialize();
+        }
+
+        /// <summary>
+        /// Finishes process and exits application
+        /// </summary>
+        public void Exit()
+        {
+            foreach (Lazy<ProcessStep> step in steps)
+            {
+                step.Value.Shutdown();
+            }
+            NUIApplication.Current.Exit();
+        }
+
+        /// <summary>
+        /// Previous shows previous view in the process
+        /// </summary>
+        public void Previous()
+        {
+            if (current.Previous != null)
+            {
+                current = current.Previous;
+                ui.Pop();
+            }
+        }
+    }
+}
index 1c5899dcc7f5afeb4f6a31385c4fcd49f5200134..3fc8495955a046cf072f632a39f5164f5c2f7338 100644 (file)
@@ -1,15 +1,12 @@
-using System;
-using Tizen.NUI;
-using Tizen.NUI.BaseComponents;
+using Tizen.NUI;
 using Tizen.NUI.Components;
-using Oobe.Controls;
-using Oobe.Views;
+using System;
 
 namespace Oobe
 {
     class Program : NUIApplication
     {
-        private OobeViewSwitcher switcher;
+        private ProcessManager processManager;
 
         protected override void OnCreate()
         {
@@ -17,69 +14,36 @@ namespace Oobe
             Initialize();
         }
 
-        TextLabel makeLabel(string txt, Color color)
-        {
-            TextLabel text2 = new TextLabel(txt);
-            text2.HorizontalAlignment = HorizontalAlignment.Center;
-            text2.VerticalAlignment = VerticalAlignment.Center;
-            text2.TextColor = Color.Black;
-            text2.PointSize = 12.0f;
-            text2.HeightResizePolicy = ResizePolicyType.FillToParent;
-            text2.WidthResizePolicy = ResizePolicyType.FillToParent;
-
-            return text2;
-        }
-
         void Initialize()
         {
-            Window.Instance.KeyEvent += OnKeyEvent;
-
-            switcher = new OobeViewSwitcher(Window.Instance);
+            processManager = new ProcessManager();
+            processManager.Start();
 
             Button button = new Button();
-            button.Text = "Push";
+            button.Text = "Next";
             button.BackgroundColor = Color.Blue;
             button.Size2D = new Size2D(100, 80);
             button.Position2D.X = 48;
             button.Position2D.Y = 720;
-            button.ClickEvent += PushClicked;
+            button.ClickEvent += NextClicked;
             Window.Instance.GetDefaultLayer().Add(button);
-            
+
             button = new Button();
-            button.Text = "Pop";
+            button.Text = "Previous";
             button.Position2D = new Position2D(250, 720);
             button.BackgroundColor = Color.White;
             button.Size2D = new Size2D(100, 80);
-            button.ClickEvent += PopClicked;
+            button.ClickEvent += PrevClicked;
             Window.Instance.GetDefaultLayer().Add(button);
-
         }
-        int current = 0;
-        public static Color[] PossibleColors = new Color[]{
-            Color.White,
-            Color.White,
-            Color.White
-        };
-
-        public void PushClicked(object sender, EventArgs args)
-        {
-            Tizen.Log.Debug("ViewStack", "Push");
-            TextLabel text = makeLabel("More text", PossibleColors[current++ % PossibleColors.Length]);
-            switcher.Push(text);
-        }
-
-        public void PopClicked(object sender, EventArgs args)
+        public void NextClicked(object sender, EventArgs args)
         {
-            Tizen.Log.Debug("ViewStack", "Pop");
-            switcher.Pop();
+            processManager.Next();
         }
 
-        public void OnKeyEvent(object sender, Window.KeyEventArgs e)
+        public void PrevClicked(object sender, EventArgs args)
         {
-            if (e.Key.State == Key.StateType.Down && (e.Key.KeyPressedName == "XF86Back" || e.Key.KeyPressedName == "Escape"))
-            {
-                Exit();
-            }
+            processManager.Previous();
         }
 
         static void Main(string[] args)
diff --git a/Oobe/Oobe/Views/MainView.cs b/Oobe/Oobe/Views/MainView.cs
new file mode 100644 (file)
index 0000000..70e6f48
--- /dev/null
@@ -0,0 +1,95 @@
+using Tizen.NUI.BaseComponents;
+using Tizen.NUI;
+using Oobe.Controls;
+
+namespace Oobe.Views
+{
+    /// <summary>
+    /// Implementation of OOBE GUI Guideline for IoT Headed
+    /// </summary>
+    public class MainView
+    {
+        private ViewStack stack;
+        private Animation dimEffectAnimation;
+        private const int TransitionTime = 750;
+
+        public MainView(Window win)
+        {
+            View backImage = new View();
+            backImage.BackgroundImage = NUIApplication.Current.DirectoryInfo.Resource + "0_BG_dark.svg";
+            backImage.WidthResizePolicy = ResizePolicyType.FillToParent;
+            backImage.HeightResizePolicy = ResizePolicyType.FillToParent;
+
+            stack = new ViewStack();
+            stack.ScrollDuration = TransitionTime;
+            stack.Position2D = new Position2D(48 - 6, 48 - 6); // include shadow
+            stack.Size2D = new Size2D(1184 + 6 + 9, 624 + 6 + 9); // includes surrounding shadow
+            stack.PagesRightPadding = 48;
+            stack.PagesLeftPadding = (int)(0.5f * stack.Size2D.Width);
+            stack.ClippingMode = ClippingModeType.Disabled;
+            dimEffectAnimation = new Animation(TransitionTime);
+
+            win.GetDefaultLayer().Add(backImage);
+            win.GetDefaultLayer().Add(stack);
+        }
+
+        public void Push(View view)
+        {
+            FinishDimAnimation();
+
+            var newView = new Views.Page();
+            newView.HeightResizePolicy = ResizePolicyType.FillToParent;
+            newView.WidthResizePolicy = ResizePolicyType.FillToParent;
+            newView.Content = view;
+            newView.Overlay.Opacity = 0.0f;
+
+            if (stack.Current is Views.Page overlayedView)
+            {
+                StartDimAnimation(overlayedView);
+            }
+
+            stack.Push(newView);
+        }
+
+        public void Pop()
+        {
+            FinishDimAnimation();
+            if (stack.Previous is Views.Page previous)
+            {
+                StartUndimAnimation(previous);
+            }
+            if (stack.Current is Views.Page current)
+            {
+                StartDimAnimation(current);
+            }
+            stack.Pop();
+        }
+
+        private void StartDimAnimation(Views.Page view)
+        {
+            view.Overlay.Opacity = 0.0f;
+            view.Opacity = 1.0f;
+            dimEffectAnimation.AnimateTo(view.Overlay, "Opacity", 0.5f);
+            dimEffectAnimation.AnimateTo(view, "Opacity", 0.0f);
+            dimEffectAnimation.Play();
+        }
+
+        private void StartUndimAnimation(Views.Page view)
+        {
+            view.Overlay.Opacity = 0.5f;
+            view.Opacity = 0.0f;
+            dimEffectAnimation.AnimateTo(view.Overlay, "Opacity", 0.0f);
+            dimEffectAnimation.AnimateTo(view, "Opacity", 1.0f);
+            dimEffectAnimation.Play();
+        }
+
+        private void FinishDimAnimation()
+        {
+            if (dimEffectAnimation.State == Animation.States.Playing)
+            {
+                dimEffectAnimation.Stop(Animation.EndActions.StopFinal);
+            }
+            dimEffectAnimation.Clear();
+        }
+    }
+}
diff --git a/Oobe/Oobe/Views/OobeViewSwitcher.cs b/Oobe/Oobe/Views/OobeViewSwitcher.cs
deleted file mode 100644 (file)
index a9b64c6..0000000
+++ /dev/null
@@ -1,95 +0,0 @@
-using Tizen.NUI.BaseComponents;
-using Tizen.NUI;
-using Oobe.Controls;
-
-namespace Oobe.Views
-{
-    /// <summary>
-    /// Implementation of OOBE GUI Guideline for IoT Headed
-    /// </summary>
-    public class OobeViewSwitcher
-    {
-        private ViewStack stack;
-        private Animation dimEffectAnimation;
-        private const int TransitionTime = 750;
-
-        public OobeViewSwitcher(Window win)
-        {
-            View backImage = new View();
-            backImage.BackgroundImage = NUIApplication.Current.DirectoryInfo.Resource + "0_BG_dark.svg";
-            backImage.WidthResizePolicy = ResizePolicyType.FillToParent;
-            backImage.HeightResizePolicy = ResizePolicyType.FillToParent;
-
-            stack = new ViewStack();
-            stack.ScrollDuration = TransitionTime;
-            stack.Position2D = new Position2D(48 - 6, 48 - 6); // include shadow
-            stack.Size2D = new Size2D(1184 + 6 + 9, 624 + 6 + 9); // includes surrounding shadow
-            stack.PagesRightPadding = 48;
-            stack.PagesLeftPadding = (int)(0.5f * stack.Size2D.Width);
-            stack.ClippingMode = ClippingModeType.Disabled;
-            dimEffectAnimation = new Animation(TransitionTime);
-
-            win.GetDefaultLayer().Add(backImage);
-            win.GetDefaultLayer().Add(stack);
-        }
-
-        public void Push(View view)
-        {
-            FinishDimAnimation();
-
-            var newView = new Views.Page();
-            newView.HeightResizePolicy = ResizePolicyType.FillToParent;
-            newView.WidthResizePolicy = ResizePolicyType.FillToParent;
-            newView.Content = view;
-            newView.Overlay.Opacity = 0.0f;
-
-            if (stack.Current is Views.Page overlayedView)
-            {
-                StartDimAnimation(overlayedView);
-            }
-
-            stack.Push(newView);
-        }
-
-        public void Pop()
-        {
-            FinishDimAnimation();
-            if (stack.Previous is Views.Page previous)
-            {
-                StartUndimAnimation(previous);
-            }
-            if (stack.Current is Views.Page current)
-            {
-                StartDimAnimation(current);
-            }
-            stack.Pop();
-        }
-
-        private void StartDimAnimation(Views.Page view)
-        {
-            view.Overlay.Opacity = 0.0f;
-            view.Opacity = 1.0f;
-            dimEffectAnimation.AnimateTo(view.Overlay, "Opacity", 0.5f);
-            dimEffectAnimation.AnimateTo(view, "Opacity", 0.0f);
-            dimEffectAnimation.Play();
-        }
-
-        private void StartUndimAnimation(Views.Page view)
-        {
-            view.Overlay.Opacity = 0.5f;
-            view.Opacity = 0.0f;
-            dimEffectAnimation.AnimateTo(view.Overlay, "Opacity", 0.0f);
-            dimEffectAnimation.AnimateTo(view, "Opacity", 1.0f);
-            dimEffectAnimation.Play();
-        }
-
-        private void FinishDimAnimation()
-        {
-            if (dimEffectAnimation.State == Animation.States.Playing)
-            {
-                dimEffectAnimation.Stop(Animation.EndActions.StopFinal);
-            }
-            dimEffectAnimation.Clear();
-        }
-    }
-}
index e37350ba1179da270b1be51b7e82621a370b96cb..6ebe9461b936be1db6eae8ebd399c50544ccfe0f 100644 (file)
@@ -4,8 +4,14 @@ namespace Oobe.Common.Interfaces
 {
     public interface IProcessNavigation
     {
+        /// <summary>
+        /// Goto next process step.
+        /// </summary>
         void Next();
+
+        /// <summary>
+        /// Goto previous process step.
+        /// </summary>
         void Previous();
-        ProcessInfo CurrentStep();
     }
 }
\ No newline at end of file
diff --git a/Oobe/OobeCommon/Interfaces/ProcessInfo.cs b/Oobe/OobeCommon/Interfaces/ProcessInfo.cs
deleted file mode 100644 (file)
index 8af119a..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-using System;
-
-
-namespace Oobe.Common.Interfaces
-{
-    public struct ProcessInfo
-    {
-        int CurrentStep;
-        int StepsCount;
-    }
-}
\ No newline at end of file
index 9d9b383442c076ea7af984049ef97a1bb26fe189..e777611e5633cd633ec8e8247f7b3182badf6d85 100644 (file)
@@ -1,25 +1,52 @@
 using System;
 using Tizen.NUI.BaseComponents;
+using Oobe.Common.Interfaces;
 
 namespace Oobe.Common.Interfaces
 {
-    public abstract class ProcessStep
-    {
+     public abstract class ProcessStep
+     {
         protected IProcessNavigation Navigation { get; private set; }
+        private bool initialized;
 
-        protected ProcessStep(IProcessNavigation nav)
+        public void Initialize()
         {
-            Navigation = nav;
+            if (initialized)
+                return;
+
+            this.OnInitialized();
+            initialized = true;
         }
-        public virtual void Initialize()
+
+        public virtual void Shutdown()
         {
+            if (!initialized)
+                return;
+
+            this.OnShutdown();
+            initialized = false;
         }
+
         public virtual void Reset()
         {
+            OnReset();
         }
-        public virtual void Shutdown()
-        {       
+
+        public virtual void OnInitialized()
+        {
+        }
+
+        public virtual void OnShutdown()
+        {
+        }
+
+        public virtual void OnReset()
+        {
+        }
+
+        public virtual View CreateView(IProcessNavigation nav)
+        {
+            return null;
         }
-        public View View => null;
-    }
-}
\ No newline at end of file
+     }
+ }
index a5e8c1e923dfee0d14cf04646d7001393541a4ad..ddbff3cd5ff16a55301ef75acd1fb8aa555a44b5 100644 (file)
@@ -1,12 +1,27 @@
 using System;\r
 using Oobe.Common.Interfaces;\r
+using Tizen.NUI;\r
+using Tizen.NUI.BaseComponents;\r
 \r
 namespace Oobe.Language\r
 {\r
-    public class LanguageStep : ProcessStep\r
-    {\r
-        public LanguageStep(IProcessNavigation navi) : base(navi)\r
+     public class LanguageStep : ProcessStep\r
+     {\r
+        public LanguageStep() : base()\r
         {\r
+\r
         }\r
-    }\r
-}
\ No newline at end of file
+\r
+        public override View CreateView(IProcessNavigation nav)\r
+        {\r
+            TextLabel text2 = new TextLabel("Choose Language");\r
+            text2.HorizontalAlignment = HorizontalAlignment.Center;\r
+            text2.VerticalAlignment = VerticalAlignment.Center;\r
+            text2.TextColor = Color.Black;\r
+            text2.PointSize = 12.0f;\r
+            text2.HeightResizePolicy = ResizePolicyType.FillToParent;\r
+            text2.WidthResizePolicy = ResizePolicyType.FillToParent;\r
+            return text2;\r
+         }\r
+     }\r
+}\r
index 2b5632be81aea8ca300654c2ca33e89c5f93dca7..eb29790921c817468a675d1533eb0de877d876ba 100644 (file)
@@ -12,7 +12,7 @@
     </PackageReference>\r
   </ItemGroup>\r
 \r
-  <ItemGroup>
-    <ProjectReference Include="..\OobeCommon\OobeCommon.csproj" />
+  <ItemGroup>\r
+    <ProjectReference Include="..\OobeCommon\OobeCommon.csproj" />\r
   </ItemGroup>\r
 </Project>\r
diff --git a/Oobe/OobeRegion/Class1.cs b/Oobe/OobeRegion/Class1.cs
deleted file mode 100644 (file)
index 8eda6fe..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-using System;\r
-\r
-namespace OobeRegion\r
-{\r
-    public class Class1\r
-    {\r
-    }\r
-}\r
index ed5548713ce3e099770b4eff3512481113b71d15..c8c933ccb78aaa1a7ee560eefdc691b0455ef634 100644 (file)
@@ -11,4 +11,7 @@
       <ExcludeAssets>Runtime</ExcludeAssets>\r
     </PackageReference>\r
   </ItemGroup>\r
+  <ItemGroup>\r
+    <ProjectReference Include="..\OobeCommon\OobeCommon.csproj" />\r
+  </ItemGroup>\r
 </Project>\r
diff --git a/Oobe/OobeRegion/RegionStep.cs b/Oobe/OobeRegion/RegionStep.cs
new file mode 100644 (file)
index 0000000..a940245
--- /dev/null
@@ -0,0 +1,27 @@
+using System;\r
+using Tizen.NUI;\r
+using Tizen.NUI.BaseComponents;\r
+using Oobe.Common.Interfaces;\r
+\r
+namespace Oobe.Region\r
+{\r
+     public class RegionStep : ProcessStep\r
+     {\r
+        public RegionStep() : base()\r
+        {\r
+\r
+        }\r
+\r
+        public override View CreateView(IProcessNavigation nav)\r
+        {\r
+            TextLabel text2 = new TextLabel("Choose Country");\r
+            text2.HorizontalAlignment = HorizontalAlignment.Center;\r
+            text2.VerticalAlignment = VerticalAlignment.Center;\r
+            text2.TextColor = Color.Black;\r
+            text2.PointSize = 12.0f;\r
+            text2.HeightResizePolicy = ResizePolicyType.FillToParent;\r
+            text2.WidthResizePolicy = ResizePolicyType.FillToParent;\r
+            return text2;\r
+         }\r
+     }\r
+}\r