[DO NOT REVIEW][TEST][NUI] key focus default algorithm test
authordongsug.song <dongsug.song@samsung.com>
Thu, 10 Mar 2022 02:11:34 +0000 (11:11 +0900)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Tue, 15 Mar 2022 08:03:22 +0000 (17:03 +0900)
src/Tizen.NUI.Components/Controls/Button.cs
src/Tizen.NUI.Components/Controls/Navigation/Navigator.cs
src/Tizen.NUI.Components/Controls/Navigation/Page.cs
src/Tizen.NUI/src/public/Input/FocusManager.cs
test/Tizen.NUI.StyleGuide/Examples/ButtonExample.cs
test/Tizen.NUI.StyleGuide/Examples/ScrollableBase/ScrollableBaseDirectionExample.cs
test/Tizen.NUI.StyleGuide/Examples/ScrollableBase/ScrollableBaseExample.cs
test/Tizen.NUI.StyleGuide/Tizen.NUI.StyleGuide.cs

index 70595df..752b52b 100755 (executable)
@@ -193,6 +193,7 @@ namespace Tizen.NUI.Components
         /// <since_tizen> 6 </since_tizen>
         public Button() : base()
         {
+            Focusable = true;
         }
 
         /// <summary>
@@ -202,6 +203,7 @@ namespace Tizen.NUI.Components
         /// <since_tizen> 8 </since_tizen>
         public Button(string style) : base(style)
         {
+            Focusable = true;
         }
 
         /// <summary>
@@ -211,6 +213,7 @@ namespace Tizen.NUI.Components
         /// <since_tizen> 8 </since_tizen>
         public Button(ButtonStyle buttonStyle) : base(buttonStyle)
         {
+            Focusable = true;
         }
 
         /// <summary>
index a60dc14..6b6b12b 100755 (executable)
@@ -228,7 +228,7 @@ namespace Tizen.NUI.Components
             {
                 if (page is DialogPage == false)
                 {
-                   topPage.SetVisible(false);
+                    topPage.SetVisible(false);
                 }
 
                 // Need to update Content of the new page
@@ -338,6 +338,20 @@ namespace Tizen.NUI.Components
             page.InvokeAppearing();
             curTop.InvokeDisappearing();
 
+            //test.
+            // if (FocusManager.Instance.IsDefaultAlgorithmEnabled())
+            // {
+            //     curTop.LastFocusedView = FocusManager.Instance.GetCurrentFocusView();
+            //     if(page.LastFocusedView)
+            //     {
+            //         FocusManager.Instance.SetCurrentFocusView(page.LastFocusedView);
+            //     }
+            //     else
+            //     {
+            //         FocusManager.Instance.ClearFocus();
+            //     }
+            // }
+
             //TODO: The following transition codes will be replaced with view transition.
             InitializeAnimation();
 
@@ -368,6 +382,15 @@ namespace Tizen.NUI.Components
                     //Invoke Page events
                     page.InvokeAppeared();
                     NotifyAccessibilityStatesChangeOfPages(curTop, page);
+
+                    //test.
+                    // if (FocusManager.Instance.IsDefaultAlgorithmEnabled())
+                    // {
+                    //     FocusManager.Instance.ClearFocus();
+                    //     FocusManager.Instance.MoveFocus(View.FocusDirection.Down);
+                    //     //FocusManager.Instance.MoveFocus(View.FocusDirection.Down);
+                    // }
+
                 };
                 newAnimation.Play();
             }
@@ -375,6 +398,14 @@ namespace Tizen.NUI.Components
             {
                 ShowContentOfPage(page);
             }
+
+            //test.
+            // if (FocusManager.Instance.IsDefaultAlgorithmEnabled())
+            // {
+            //     FocusManager.Instance.ClearFocus();
+            //     FocusManager.Instance.MoveFocus(View.FocusDirection.Down);
+            //     FocusManager.Instance.MoveFocus(View.FocusDirection.Down);
+            // }
         }
 
         /// <summary>
@@ -414,6 +445,20 @@ namespace Tizen.NUI.Components
             newTop.InvokeAppearing();
             curTop.InvokeDisappearing();
 
+            //test.
+            // if (FocusManager.Instance.IsDefaultAlgorithmEnabled())
+            // {
+            //     curTop.LastFocusedView = FocusManager.Instance.GetCurrentFocusView();
+            //     if(newTop.LastFocusedView)
+            //     {
+            //         FocusManager.Instance.SetCurrentFocusView(newTop.LastFocusedView);
+            //     }
+            //     else
+            //     {
+            //         FocusManager.Instance.ClearFocus();
+            //     }
+            // }
+
             //TODO: The following transition codes will be replaced with view transition.
             InitializeAnimation();
 
@@ -448,6 +493,17 @@ namespace Tizen.NUI.Components
 
                     //Invoke Page events
                     newTop.InvokeAppeared();
+
+
+                    //test.
+                    // if (FocusManager.Instance.IsDefaultAlgorithmEnabled())
+                    // {
+                    //     FocusManager.Instance.ClearFocus();
+                    //     FocusManager.Instance.MoveFocus(View.FocusDirection.Down);
+                    //     //FocusManager.Instance.MoveFocus(View.FocusDirection.Down);
+                    // }
+
+
                 };
                 newAnimation.Play();
             }
@@ -456,6 +512,23 @@ namespace Tizen.NUI.Components
                 Remove(curTop);
             }
 
+            //test.
+            // if (FocusManager.Instance.IsDefaultAlgorithmEnabled())
+            // {
+            //     if(newTop.LastFocusedView)
+            //     {
+            //         FocusManager.Instance.SetCurrentFocusView(newTop.LastFocusedView);
+            //     }
+            // }
+
+            // //test.
+            // if (FocusManager.Instance.IsDefaultAlgorithmEnabled())
+            // {
+            //     FocusManager.Instance.ClearFocus();
+            //     FocusManager.Instance.MoveFocus(View.FocusDirection.Down);
+            //     FocusManager.Instance.MoveFocus(View.FocusDirection.Down);
+            // }
+
             return curTop;
         }
 
@@ -741,12 +814,12 @@ namespace Tizen.NUI.Components
             RetrieveTaggedViews(taggedViewsInCurrentTopPage, currentTopPage, true);
 
             List<KeyValuePair<View, View>> sameTaggedViewPair = new List<KeyValuePair<View, View>>();
-            foreach(View currentTopPageView in taggedViewsInCurrentTopPage)
+            foreach (View currentTopPageView in taggedViewsInCurrentTopPage)
             {
                 bool findPair = false;
-                foreach(View newTopPageView in taggedViewsInNewTopPage)
+                foreach (View newTopPageView in taggedViewsInNewTopPage)
                 {
-                    if((currentTopPageView.TransitionOptions != null) && (newTopPageView.TransitionOptions != null) &&
+                    if ((currentTopPageView.TransitionOptions != null) && (newTopPageView.TransitionOptions != null) &&
                         currentTopPageView.TransitionOptions?.TransitionTag == newTopPageView.TransitionOptions?.TransitionTag)
                     {
                         sameTaggedViewPair.Add(new KeyValuePair<View, View>(currentTopPageView, newTopPageView));
@@ -754,21 +827,21 @@ namespace Tizen.NUI.Components
                         break;
                     }
                 }
-                if(findPair)
+                if (findPair)
                 {
                     taggedViewsInNewTopPage.Remove(sameTaggedViewPair[sameTaggedViewPair.Count - 1].Value);
                 }
             }
-            foreach(KeyValuePair<View, View> pair in sameTaggedViewPair)
+            foreach (KeyValuePair<View, View> pair in sameTaggedViewPair)
             {
                 taggedViewsInCurrentTopPage.Remove(pair.Key);
             }
 
             TransitionSet newTransitionSet = new TransitionSet();
-            foreach(KeyValuePair<View, View> pair in sameTaggedViewPair)
+            foreach (KeyValuePair<View, View> pair in sameTaggedViewPair)
             {
                 TransitionItem pairTransition = transition.CreateTransition(pair.Key, pair.Value, pushTransition);
-                if(pair.Value.TransitionOptions?.TransitionWithChild ?? false)
+                if (pair.Value.TransitionOptions?.TransitionWithChild ?? false)
                 {
                     pairTransition.TransitionWithChild = true;
                 }
@@ -777,11 +850,11 @@ namespace Tizen.NUI.Components
 
             newTransitionSet.Finished += (object sender, EventArgs e) =>
             {
-                if(newTopPage.Layout != null)
+                if (newTopPage.Layout != null)
                 {
                     newTopPage.Layout.RequestLayout();
                 }
-                if(currentTopPage.Layout != null)
+                if (currentTopPage.Layout != null)
                 {
                     currentTopPage.Layout.RequestLayout();
                 }
index fba9475..e2d7197 100755 (executable)
@@ -94,6 +94,8 @@ namespace Tizen.NUI.Components
             return instance.InternalDisappearingTransition;
         });
 
+        internal BaseComponents.View LastFocusedView = null;
+
         private Navigator navigator = null;
 
         // Default transition is Fade.
index 204d898..cc27082 100755 (executable)
@@ -72,6 +72,8 @@ namespace Tizen.NUI
         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
         private delegate void FocusedViewEnterKeyEventCallback2(IntPtr view);
 
+        private View internalFocusIndicator = null;
+
         /// <summary>
         /// PreFocusChange will be triggered before the focus is going to be changed.<br />
         /// The FocusManager makes the best guess for which view to focus towards the given direction, but applications might want to change that.<br />
@@ -474,14 +476,15 @@ namespace Tizen.NUI
         {
             Interop.FocusManager.SetFocusIndicatorActor(SwigCPtr, View.getCPtr(indicator));
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            internalFocusIndicator = indicator;
         }
 
         internal View GetFocusIndicatorView()
         {
             //to fix memory leak issue, match the handle count with native side.
             IntPtr cPtr = Interop.FocusManager.GetFocusIndicatorActor(SwigCPtr);
-            View ret = this.GetInstanceSafely<View>(cPtr);
-            return ret;
+            internalFocusIndicator = this.GetInstanceSafely<View>(cPtr);
+            return internalFocusIndicator;
         }
 
         internal PreFocusChangeSignal PreFocusChangeSignal()
index a73ffd8..38b4e5a 100644 (file)
@@ -28,11 +28,11 @@ namespace Tizen.NUI.StyleGuide
         private Window window;
         public void Activate()
         {
-           Log.Info(this.GetType().Name, $"@@@ this.GetType().Name={this.GetType().Name}, Activate()\n");
+           Log.Info(this.GetType().Name, $"this.GetType().Name={this.GetType().Name}, Activate()\n");
         }
         public void Deactivate()
         {
-            Log.Info(this.GetType().Name, $"@@@ this.GetType().Name={this.GetType().Name}, Deactivate()\n");
+            Log.Info(this.GetType().Name, $"this.GetType().Name={this.GetType().Name}, Deactivate()\n");
             window = null;
         }
 
@@ -71,7 +71,6 @@ namespace Tizen.NUI.StyleGuide
             {
                 Text = "Enabled"
             };
-            enabledButton.EnableFocus();
             enabledButton.Clicked += (object obj, ClickedEventArgs ev) =>
             {
                 Log.Info(this.GetType().Name, "Enabled Button Clicked\n");
@@ -96,7 +95,6 @@ namespace Tizen.NUI.StyleGuide
                 Text = "Unselected",
                 IsSelectable = true,
             };
-            selectableButton.EnableFocus();
             selectableButton.Clicked += (object obj, ClickedEventArgs ev) =>
             {
                 Log.Info(this.GetType().Name, "Selected Button Clicked\n");
index 2ab5934..610d0ab 100644 (file)
@@ -81,7 +81,6 @@ namespace Tizen.NUI.StyleGuide
                 colorView.WidthSpecification = (isHorizontal? 200 : LayoutParamPolicies.MatchParent);
                 colorView.HeightSpecification = (isHorizontal? LayoutParamPolicies.MatchParent : 200);
                 colorView.BackgroundColor = new Color((float)rnd.Next(256)/256f, (float)rnd.Next(256)/256f, (float)rnd.Next(256)/256f, 1);
-                colorView.EnableFocus();
                 scrollView.Add(colorView);
             }
 
index 6db39d0..1208fd8 100644 (file)
@@ -31,11 +31,11 @@ namespace Tizen.NUI.StyleGuide
         private List<DirectionOption> directionMenu;
         public void Activate()
         {
-            Log.Info(this.GetType().Name, $"@@@ this.GetType().Name={this.GetType().Name}, Activate()\n");
+            Log.Info(this.GetType().Name, $"this.GetType().Name={this.GetType().Name}, Activate()\n");
         }
         public void Deactivate()
         {
-            Log.Info(this.GetType().Name, $"@@@ this.GetType().Name={this.GetType().Name}, Deactivate()\n");
+            Log.Info(this.GetType().Name, $"this.GetType().Name={this.GetType().Name}, Deactivate()\n");
             window = null;
             directionMenu = null;
         }
@@ -73,7 +73,6 @@ namespace Tizen.NUI.StyleGuide
                     };
                     item.Label.SetBinding(TextLabel.TextProperty, "Direction");
                     item.Label.HorizontalAlignment = HorizontalAlignment.Begin;
-                    item.EnableFocus();
                     return item;
                 }),
                 ScrollingDirection = ScrollableBase.Direction.Vertical,
@@ -88,7 +87,6 @@ namespace Tizen.NUI.StyleGuide
                     Page scrollDirPage = new ScrollableBaseDirectionExample(directionItem.Direction);
                     window = NUIApplication.GetDefaultWindow();
                     window.GetDefaultNavigator().Push(scrollDirPage);
-                    FocusableExtension.SetFocusOnPage(scrollDirPage);
                 }
                 directionListView.SelectedItem = null;
             };
index ffa0663..def75a4 100644 (file)
@@ -26,67 +26,6 @@ using System.Reflection;
 
 namespace Tizen.NUI.StyleGuide
 {
-
-    /// Helder static extension class for Focusable.
-    /// NUI default behavior is unfocusable in key or touch,
-    /// this class help to setting focusable features easily.
-    public static class FocusableExtension
-    {
-        public static FocusManager FocusManager;
-        public static void EnableFocus(this View view)
-        {
-            view.Focusable = true;
-            view.FocusableInTouch = true;
-        }
-
-        public static void EnableAutoFocusable()
-        {
-            FocusManager = FocusManager.Instance;
-            FocusManager.EnableDefaultAlgorithm(true);
-            FocusManager.FocusIndicator = new View()
-            {
-                PositionUsesPivotPoint = true,
-                PivotPoint = new Position(0, 0, 0),
-                WidthResizePolicy = ResizePolicyType.FillToParent,
-                HeightResizePolicy = ResizePolicyType.FillToParent,
-                BorderlineColor = Color.Orange,
-                BorderlineWidth = 4.0f,
-                BorderlineOffset = -1f,
-                BackgroundColor = new Color(0.2f, 0.2f, 0.2f, 0.2f),
-            };
-        }
-
-        public static void SetFocusOnPage(Page page)
-        {
-            View focusCandidate = null;
-            if (page == null) return;
-
-            if (page is ContentPage contentPage)
-            {
-                focusCandidate = contentPage.AppBar?.NavigationContent;
-                focusCandidate.Focusable = true;
-            }
-
-            if (focusCandidate == null)
-            {
-                foreach (View child in page.Children)
-                {
-                    if (child.Focusable)
-                    {
-                        focusCandidate = child;
-                    }
-                }
-            }
-
-            Log.Info("FocusableExtension", $"Focus candidate {focusCandidate}\n");
-
-            if (focusCandidate != null)
-            {
-                FocusManager.SetCurrentFocusView(focusCandidate);
-            }
-        }
-    }
-
     public class SearchField : View
     {
         public TextField SearchTextField;
@@ -108,14 +47,12 @@ namespace Tizen.NUI.StyleGuide
 
             var searchTextBox = CreateSearchText();
             SearchTextField = CreateTextField();
-            SearchTextField.EnableFocus();
             var underline = CreateUnderline();
 
             searchTextBox.Add(SearchTextField);
             searchTextBox.Add(underline);
 
             SearchButton = CreateSearchButton();
-            SearchButton.EnableFocus();
 
             Add(searchTextBox);
             Add(SearchButton);
@@ -143,6 +80,7 @@ namespace Tizen.NUI.StyleGuide
                 WidthSpecification = LayoutParamPolicies.MatchParent,
                 HeightSpecification = LayoutParamPolicies.WrapContent,
                 MinimumSize = new Size2D(0, 40),
+                Focusable = true, //BaseComponents' Focusable is false as a default value, true should be set to navigate key focus and edit text.
             };
         }
 
@@ -218,7 +156,7 @@ namespace Tizen.NUI.StyleGuide
 
             foreach (Type type in assembly.GetTypes())
             {
-                Console.WriteLine($"@@@ type.Name={type.Name}, type.FullName={type.FullName}");
+                Console.WriteLine($"type.Name={type.Name}, type.FullName={type.FullName}");
                 if (exampleType.IsAssignableFrom(type) && type.Name != "SampleMain" && this.GetType() != type && type.IsClass)
                 {
                     NamePool.Add(new Tuple<string, string>(type.Name, type.FullName));
@@ -252,7 +190,7 @@ namespace Tizen.NUI.StyleGuide
 
                     if (navigator.PageCount == 0)
                     {
-                         Exit();
+                        Exit();
                     }
                 }
             }
@@ -260,13 +198,13 @@ namespace Tizen.NUI.StyleGuide
 
         public void OnSelectionChanged(object sender, SelectionChangedEventArgs ev)
         {
-            Console.WriteLine($"@@@ OnSelectionChanged() {ev.CurrentSelection}");
+            Console.WriteLine($"OnSelectionChanged() {ev.CurrentSelection}");
 
             if (ev.CurrentSelection.Count == 0) return;
 
             if (ev.CurrentSelection[0] is ControlMenu selItem)
             {
-                Console.WriteLine($"@@@ selItem.Name={selItem.Name}, selItem.FullName={selItem.FullName}");
+                Console.WriteLine($"selItem.Name={selItem.Name}, selItem.FullName={selItem.FullName}");
                 RunSample(selItem?.FullName);
             }
             colView.SelectedItem = null;
@@ -277,6 +215,27 @@ namespace Tizen.NUI.StyleGuide
             base.OnCreate();
             Initialize();
             SetMainPage();
+
+            focusManager = FocusManager.Instance;
+
+            //set user customized focus indicator
+            if (!focusManager.FocusIndicator)
+            {
+                focusManager.FocusIndicator = new View()
+                {
+                    PositionUsesPivotPoint = true,
+                    PivotPoint = new Position(0, 0, 0),
+                    WidthResizePolicy = ResizePolicyType.FillToParent,
+                    HeightResizePolicy = ResizePolicyType.FillToParent,
+                    BorderlineColor = Color.Orange,
+                    BorderlineWidth = 4.0f,
+                    BorderlineOffset = -1f,
+                    BackgroundColor = new Color(0.2f, 0.2f, 0.2f, 0.2f),
+                };
+            }
+
+            //enable FocusManger default algorithm
+            focusManager.EnableDefaultAlgorithm(true);
         }
         private void Initialize()
         {
@@ -284,13 +243,10 @@ namespace Tizen.NUI.StyleGuide
             window.Title = "NUI Style Guide";
             window.KeyEvent += OnKeyEvent;
 
-            FocusableExtension.EnableAutoFocusable();
-
             navigator = window.GetDefaultNavigator();
             navigator.Popped += (object obj, PoppedEventArgs ev) =>
             {
                 Page top = navigator.Peek();
-                FocusableExtension.SetFocusOnPage(top);
             };
         }
 
@@ -319,7 +275,6 @@ namespace Tizen.NUI.StyleGuide
             var appBarStyle = ThemeManager.GetStyle("Tizen.NUI.Components.AppBar");
             var moreButton = new Button(((AppBarStyle)appBarStyle).BackButton);
             moreButton.Icon.ResourceUrl = Tizen.Applications.Application.Current.DirectoryInfo.Resource + "menu.png";
-            moreButton.EnableFocus();
             appBar.NavigationContent = moreButton;
 
 
@@ -359,7 +314,7 @@ namespace Tizen.NUI.StyleGuide
                     };
                     item.Label.SetBinding(TextLabel.TextProperty, "ViewLabel");
                     item.Label.HorizontalAlignment = HorizontalAlignment.Begin;
-                    item.EnableFocus();
+                    item.Focusable = true; //BaseComponents' Focusable is false as a default value, true should be set to navigate key focus.
                     return item;
                 }),
                 Header = myTitle,
@@ -378,10 +333,8 @@ namespace Tizen.NUI.StyleGuide
                 AppBar = appBar,
                 Content = pageContent,
             };
-            page.Focusable = true;
 
             navigator.Push(page);
-            FocusableExtension.SetFocusOnPage(page);
         }
 
         private void RunSample(string name)
@@ -389,21 +342,19 @@ namespace Tizen.NUI.StyleGuide
             IExample example = typeof(Program).Assembly?.CreateInstance(name) as IExample;
 
 
-            Console.WriteLine($"@@@ typeof(Program).Assembly={typeof(Program).Assembly}, name={name}");
+            Console.WriteLine($"typeof(Program).Assembly={typeof(Program).Assembly}, name={name}");
 
             if (example != null)
             {
                 example.Activate();
                 if (example is Page examplePage)
                 {
-                    examplePage.Focusable = true;
                     navigator.Push(examplePage);
-                    FocusableExtension.SetFocusOnPage(examplePage);
                 }
             }
             else
             {
-                Console.WriteLine($"@@@ examle is null!");
+                Console.WriteLine($"examle is null!");
             }
         }