add BackKey support. 10/244710/3
authorLukasz Stanislawski <lukasz.stanislawski@gmail.com>
Wed, 23 Sep 2020 10:13:14 +0000 (12:13 +0200)
committerLukasz Stanislawski <lukasz.stanislawski@gmail.com>
Fri, 9 Oct 2020 07:39:13 +0000 (09:39 +0200)
Handle BackKey with BackKeyPressed event. Refactor MainView
to be a NUI View for easy event handling.

For closing popup use similar approach as BackKey events
should be passed only to top level objects.

Change-Id: I994d333bab9bfdaeda96fe03c3a6125053d78ee3

Oobe/Oobe.Common/Utils/Popup.cs
Oobe/Oobe/Managers/ProcessManager.cs
Oobe/Oobe/Views/MainView.cs

index 76779cf4498c2ebcfb5e25d1850c4da99a9bf35b..8a68d715a21fc2a4bf55033130354493da7052b2 100644 (file)
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 
+using System;
 using Tizen.NUI;
 using Tizen.NUI.BaseComponents;
 using Tizen.NUI.Components;
@@ -64,6 +65,7 @@ namespace Oobe.Common.Utils
         {
             if (layer != null)
             {
+                view.BackKeyPressed -= OnBackKeyPressed;
                 Window.Instance.RemoveLayer(layer);
                 layer.Dispose();
                 layer = null;
@@ -77,9 +79,15 @@ namespace Oobe.Common.Utils
             layer.Add(CreateGray());
             layer.Add(view);
             view.TouchEvent += (s, e) => false; // prevent gray view reacting
+            view.BackKeyPressed += OnBackKeyPressed;
             Window.Instance.AddLayer(layer);
         }
 
+        private void OnBackKeyPressed(object sender, EventArgs args)
+        {
+            Dismiss();
+        }
+
         private Control CreateGray()
         {
             var gray = new Tizen.NUI.Components.Control()
index e4d2a856035a4dd96a1f77ac9ed56d545b2b5fe5..de53e60aa2a1468fe5f66e2a7e7b7335d2998ab3 100644 (file)
@@ -79,8 +79,13 @@ namespace Oobe
             current = steps.First;
             current.Value.Value.Initialize();
             ui.Push(current.Value.Value.CreateView(new NavigationController(this, current.Value.Value)));
+            ui.BackKeyPressed += (obj, args) =>
+            {
+                Previous();
+            };
             current.Next?.Value.Value.Initialize();
 
+            Window.Instance.Add(ui);
             started = true;
         }
 
index 7e7441bc3363d9f134918e5f2f63a76eb997cbf0..a19ec804afc70c3d65624cdd40f54fe2d4cd841c 100644 (file)
@@ -25,7 +25,7 @@ namespace Oobe.Views
     /// <summary>
     /// Implementation of OOBE GUI Guideline for IoT Headed
     /// </summary>
-    public class MainView : IDisposable
+    public class MainView : View
     {
         private const int TransitionTime = 750;
         private readonly Extents stackMargin = new Extents(48, 48, 48, 48);
@@ -33,14 +33,9 @@ namespace Oobe.Views
         private Pagination pagination;
 
         public MainView(Window win)
+            : base()
         {
-            View backImage = new View
-            {
-                BackgroundImage = NUIApplication.Current.DirectoryInfo.Resource + "0_BG_dark.png",
-                PositionUsesPivotPoint = true,
-                PivotPoint = new Position(0.5f, 0.5f),
-                ParentOrigin = new Position(0.5f, 0.5f),
-            };
+            BackgroundImage = NUIApplication.Current.DirectoryInfo.Resource + "0_BG_dark.png";
 
             Size2D stackSize = new Size2D(
                     win.WindowSize.Width - stackMargin.Start - stackMargin.End,
@@ -74,9 +69,8 @@ namespace Oobe.Views
             };
             pagination.IndicatorSpacing = 12;
 
-            win.GetDefaultLayer().Add(backImage);
-            win.GetDefaultLayer().Add(stack);
-            win.GetDefaultLayer().Add(pagination);
+            Add(stack);
+            Add(pagination);
         }
 
         public int PagesCount
@@ -116,10 +110,20 @@ namespace Oobe.Views
             stack.Pop();
         }
 
-        public void Dispose()
+        protected override void Dispose(DisposeTypes type)
         {
-            stack.Dispose();
-            pagination.Dispose();
+            if (disposed)
+            {
+                return;
+            }
+
+            if (type == DisposeTypes.Explicit)
+            {
+                stack.Dispose();
+                pagination.Dispose();
+            }
+
+            base.Dispose(type);
         }
     }
 }