From cb49670d051ca2d0d028557d15be9244bbc80d69 Mon Sep 17 00:00:00 2001 From: "dongsug.song" Date: Thu, 10 Mar 2022 11:11:34 +0900 Subject: [PATCH] [DO NOT REVIEW][TEST][NUI] key focus default algorithm test --- src/Tizen.NUI.Components/Controls/Button.cs | 3 + .../Controls/Navigation/Navigator.cs | 93 ++++++++++++++++-- .../Controls/Navigation/Page.cs | 2 + src/Tizen.NUI/src/public/Input/FocusManager.cs | 7 +- .../Tizen.NUI.StyleGuide/Examples/ButtonExample.cs | 6 +- .../ScrollableBaseDirectionExample.cs | 1 - .../ScrollableBase/ScrollableBaseExample.cs | 6 +- test/Tizen.NUI.StyleGuide/Tizen.NUI.StyleGuide.cs | 107 ++++++--------------- 8 files changed, 126 insertions(+), 99 deletions(-) diff --git a/src/Tizen.NUI.Components/Controls/Button.cs b/src/Tizen.NUI.Components/Controls/Button.cs index 70595df..752b52b 100755 --- a/src/Tizen.NUI.Components/Controls/Button.cs +++ b/src/Tizen.NUI.Components/Controls/Button.cs @@ -193,6 +193,7 @@ namespace Tizen.NUI.Components /// 6 public Button() : base() { + Focusable = true; } /// @@ -202,6 +203,7 @@ namespace Tizen.NUI.Components /// 8 public Button(string style) : base(style) { + Focusable = true; } /// @@ -211,6 +213,7 @@ namespace Tizen.NUI.Components /// 8 public Button(ButtonStyle buttonStyle) : base(buttonStyle) { + Focusable = true; } /// diff --git a/src/Tizen.NUI.Components/Controls/Navigation/Navigator.cs b/src/Tizen.NUI.Components/Controls/Navigation/Navigator.cs index a60dc14..6b6b12b 100755 --- a/src/Tizen.NUI.Components/Controls/Navigation/Navigator.cs +++ b/src/Tizen.NUI.Components/Controls/Navigation/Navigator.cs @@ -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); + // } } /// @@ -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> sameTaggedViewPair = new List>(); - 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(currentTopPageView, newTopPageView)); @@ -754,21 +827,21 @@ namespace Tizen.NUI.Components break; } } - if(findPair) + if (findPair) { taggedViewsInNewTopPage.Remove(sameTaggedViewPair[sameTaggedViewPair.Count - 1].Value); } } - foreach(KeyValuePair pair in sameTaggedViewPair) + foreach (KeyValuePair pair in sameTaggedViewPair) { taggedViewsInCurrentTopPage.Remove(pair.Key); } TransitionSet newTransitionSet = new TransitionSet(); - foreach(KeyValuePair pair in sameTaggedViewPair) + foreach (KeyValuePair 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(); } diff --git a/src/Tizen.NUI.Components/Controls/Navigation/Page.cs b/src/Tizen.NUI.Components/Controls/Navigation/Page.cs index fba9475..e2d7197 100755 --- a/src/Tizen.NUI.Components/Controls/Navigation/Page.cs +++ b/src/Tizen.NUI.Components/Controls/Navigation/Page.cs @@ -94,6 +94,8 @@ namespace Tizen.NUI.Components return instance.InternalDisappearingTransition; }); + internal BaseComponents.View LastFocusedView = null; + private Navigator navigator = null; // Default transition is Fade. diff --git a/src/Tizen.NUI/src/public/Input/FocusManager.cs b/src/Tizen.NUI/src/public/Input/FocusManager.cs index 204d898..cc27082 100755 --- a/src/Tizen.NUI/src/public/Input/FocusManager.cs +++ b/src/Tizen.NUI/src/public/Input/FocusManager.cs @@ -72,6 +72,8 @@ namespace Tizen.NUI [UnmanagedFunctionPointer(CallingConvention.StdCall)] private delegate void FocusedViewEnterKeyEventCallback2(IntPtr view); + private View internalFocusIndicator = null; + /// /// PreFocusChange will be triggered before the focus is going to be changed.
/// The FocusManager makes the best guess for which view to focus towards the given direction, but applications might want to change that.
@@ -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(cPtr); - return ret; + internalFocusIndicator = this.GetInstanceSafely(cPtr); + return internalFocusIndicator; } internal PreFocusChangeSignal PreFocusChangeSignal() diff --git a/test/Tizen.NUI.StyleGuide/Examples/ButtonExample.cs b/test/Tizen.NUI.StyleGuide/Examples/ButtonExample.cs index a73ffd8..38b4e5a 100644 --- a/test/Tizen.NUI.StyleGuide/Examples/ButtonExample.cs +++ b/test/Tizen.NUI.StyleGuide/Examples/ButtonExample.cs @@ -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"); diff --git a/test/Tizen.NUI.StyleGuide/Examples/ScrollableBase/ScrollableBaseDirectionExample.cs b/test/Tizen.NUI.StyleGuide/Examples/ScrollableBase/ScrollableBaseDirectionExample.cs index 2ab5934..610d0ab 100644 --- a/test/Tizen.NUI.StyleGuide/Examples/ScrollableBase/ScrollableBaseDirectionExample.cs +++ b/test/Tizen.NUI.StyleGuide/Examples/ScrollableBase/ScrollableBaseDirectionExample.cs @@ -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); } diff --git a/test/Tizen.NUI.StyleGuide/Examples/ScrollableBase/ScrollableBaseExample.cs b/test/Tizen.NUI.StyleGuide/Examples/ScrollableBase/ScrollableBaseExample.cs index 6db39d0..1208fd8 100644 --- a/test/Tizen.NUI.StyleGuide/Examples/ScrollableBase/ScrollableBaseExample.cs +++ b/test/Tizen.NUI.StyleGuide/Examples/ScrollableBase/ScrollableBaseExample.cs @@ -31,11 +31,11 @@ namespace Tizen.NUI.StyleGuide private List 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; }; diff --git a/test/Tizen.NUI.StyleGuide/Tizen.NUI.StyleGuide.cs b/test/Tizen.NUI.StyleGuide/Tizen.NUI.StyleGuide.cs index ffa0663..def75a4 100644 --- a/test/Tizen.NUI.StyleGuide/Tizen.NUI.StyleGuide.cs +++ b/test/Tizen.NUI.StyleGuide/Tizen.NUI.StyleGuide.cs @@ -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(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!"); } } -- 2.7.4