[NUI] Fix FocusIndicator default value
authordongsug.song <dongsug.song@samsung.com>
Thu, 28 Apr 2022 00:04:51 +0000 (09:04 +0900)
committerSangHyeon Jade Lee <dltkdgus1764@gmail.com>
Tue, 10 May 2022 06:09:58 +0000 (15:09 +0900)
src/Tizen.NUI/res/keyboard_focus.9.png [new file with mode: 0644]
src/Tizen.NUI/src/internal/Application/Application.cs
src/Tizen.NUI/src/public/Input/FocusManager.cs
test/Tizen.NUI.StyleGuide/Examples/DialogAndAlertDialogExample.cs
test/Tizen.NUI.StyleGuide/Examples/FocusIndicatorTest.cs [new file with mode: 0644]
test/Tizen.NUI.StyleGuide/Tizen.NUI.StyleGuide.cs
test/Tizen.NUI.StyleGuide/Tizen.NUI.StyleGuide.csproj

diff --git a/src/Tizen.NUI/res/keyboard_focus.9.png b/src/Tizen.NUI/res/keyboard_focus.9.png
new file mode 100644 (file)
index 0000000..5590f15
Binary files /dev/null and b/src/Tizen.NUI/res/keyboard_focus.9.png differ
index b434edb..effb0d8 100755 (executable)
@@ -587,6 +587,7 @@ namespace Tizen.NUI
             // Initialize DisposeQueue Singleton class. This is also required to create DisposeQueue on main thread.
             DisposeQueue.Instance.Initialize();
             Window.Instance = GetWindow();
+            _ = FocusManager.Instance;
 
             // Notify that the window is displayed to the app core.
             if (NUIApplication.IsPreload)
index bcd6624..cdfa12c 100755 (executable)
@@ -73,6 +73,7 @@ namespace Tizen.NUI
         private delegate void FocusedViewEnterKeyEventCallback2(IntPtr view);
 
         private View internalFocusIndicator = null;
+        private View nullFocusIndicator = null;
 
         /// <summary>
         /// PreFocusChange will be triggered before the focus is going to be changed.<br />
@@ -264,11 +265,23 @@ namespace Tizen.NUI
         {
             set
             {
-                SetFocusIndicatorView(value);
+                internalFocusIndicator = value;
+                if (internalFocusIndicator == null)
+                {
+                    if (nullFocusIndicator == null)
+                    {
+                        nullFocusIndicator = new View();
+                    }
+                    SetFocusIndicatorView(nullFocusIndicator);
+                }
+                else
+                {
+                    SetFocusIndicatorView(internalFocusIndicator);
+                }
             }
             get
             {
-                return GetFocusIndicatorView();
+                return internalFocusIndicator;
             }
         }
 
@@ -476,10 +489,49 @@ namespace Tizen.NUI
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
+        /// <summary>
+        /// Get a default focus indicator
+        /// </summary>
+        /// <remarks>
+        /// The type actually <see cref="Tizen.NUI.BaseComponents.ImageView"/> of blue border squred png image, so it would be difficult to modify itself.
+        /// To change focus indicator, creating new indicator and assigning it to FocusIndicator are recommended.
+        /// For example,
+        /// <code>
+        /// FocusManager.Instance.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),
+        /// };
+        /// </code>
+        /// </remarks>
+        /// <returns>instance of default focus indicator</returns>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public View GetDefaultFocusIndicator()
+        {
+            ImageView ret = new ImageView(FrameworkInformation.ResourcePath + "keyboard_focus.9.png")
+            {
+                Name = "DefaultFocusIndicatorCreatedByNUI",
+                PositionUsesAnchorPoint = true,
+                ParentOrigin = ParentOrigin.Center,
+                PivotPoint = ParentOrigin.Center,
+                Position2D = new Position2D(0, 0),
+            };
+            ret.SetResizePolicy(ResizePolicyType.FillToParent, DimensionType.AllDimensions);
+            return ret;
+        }
+
         internal static FocusManager Get()
         {
             FocusManager ret = new FocusManager(Interop.FocusManager.Get(), true);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+
+            ret.FocusIndicator = ret.GetDefaultFocusIndicator();
             return ret;
         }
 
@@ -500,15 +552,13 @@ 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);
-            internalFocusIndicator = this.GetInstanceSafely<View>(cPtr);
-            return internalFocusIndicator;
+            return this.GetInstanceSafely<View>(cPtr);
         }
 
         internal PreFocusChangeSignal PreFocusChangeSignal()
index 7be53af..6f00a9a 100644 (file)
@@ -78,7 +78,7 @@ namespace Tizen.NUI.StyleGuide
                     Text = "OK",
                 };
 
-                button.Clicked += (object s, ClickedEventArgs a) =>
+                button.Clicked += (object sender, ClickedEventArgs args) =>
                 {
                     Navigator?.Pop();
                 };
@@ -101,7 +101,7 @@ namespace Tizen.NUI.StyleGuide
                     Text = "Cancel",
                 };
 
-                button.Clicked += (object s, ClickedEventArgs a) =>
+                button.Clicked += (object sender, ClickedEventArgs args) =>
                 {
                     Navigator?.Pop();
                 };
@@ -111,7 +111,7 @@ namespace Tizen.NUI.StyleGuide
                     Text = "OK",
                 };
 
-                button2.Clicked += (object s, ClickedEventArgs a) =>
+                button2.Clicked += (object sender, ClickedEventArgs args) =>
                 {
                     Navigator?.Pop();
                 };
@@ -134,7 +134,7 @@ namespace Tizen.NUI.StyleGuide
                     Text = "Cancel",
                 };
 
-                button.Clicked += (object s, ClickedEventArgs a) =>
+                button.Clicked += (object sender, ClickedEventArgs args) =>
                 {
                     Navigator?.Pop();
                 };
@@ -144,7 +144,7 @@ namespace Tizen.NUI.StyleGuide
                     Text = "OK",
                 };
 
-                button2.Clicked += (object s, ClickedEventArgs a) =>
+                button2.Clicked += (object sender, ClickedEventArgs args) =>
                 {
                     Navigator?.Pop();
                 };
@@ -167,7 +167,7 @@ namespace Tizen.NUI.StyleGuide
                     Text = "Cancel",
                 };
 
-                button.Clicked += (object s, ClickedEventArgs a) =>
+                button.Clicked += (object sender, ClickedEventArgs args) =>
                 {
                     Navigator?.Pop();
                 };
@@ -177,7 +177,7 @@ namespace Tizen.NUI.StyleGuide
                     Text = "OK",
                 };
 
-                button2.Clicked += (object s, ClickedEventArgs a) =>
+                button2.Clicked += (object sender, ClickedEventArgs args) =>
                 {
                     Navigator?.Pop();
                 };
diff --git a/test/Tizen.NUI.StyleGuide/Examples/FocusIndicatorTest.cs b/test/Tizen.NUI.StyleGuide/Examples/FocusIndicatorTest.cs
new file mode 100644 (file)
index 0000000..34ce3af
--- /dev/null
@@ -0,0 +1,119 @@
+/*
+ * Copyright(c) 2022 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.ComponentModel;
+using Tizen.NUI;
+using Tizen.NUI.BaseComponents;
+using Tizen.NUI.Components;
+
+namespace Tizen.NUI.StyleGuide
+{
+    // IExample inehrited class will be automatically added in the main examples list.
+    internal class FocusIndicatorTest : ContentPage, IExample
+    {
+        private View rootContent;
+        private Button buttonSetNewIndi, buttonRestoreIndi, buttonSetNull;
+        private FocusManager focusmanager;
+        
+
+        public void Activate()
+        {
+        }
+        public void Deactivate()
+        {
+        }
+
+        /// Modify this method for adding other examples.
+        public FocusIndicatorTest() : base()
+        {
+            focusmanager = FocusManager.Instance;
+
+            WidthSpecification = LayoutParamPolicies.MatchParent;
+            HeightSpecification = LayoutParamPolicies.MatchParent;
+
+            // Navigator bar title is added here.
+            AppBar = new AppBar()
+            {
+                Title = "Focus Indicator Test",
+            };
+
+            // Example root content view.
+            // you can decorate, add children on this view.
+            rootContent = new View()
+            {
+                WidthSpecification = LayoutParamPolicies.MatchParent,
+                HeightSpecification = LayoutParamPolicies.MatchParent,
+
+                Layout = new LinearLayout()
+                {
+                    LinearOrientation = LinearLayout.Orientation.Vertical,
+                    HorizontalAlignment = HorizontalAlignment.Center,
+                    VerticalAlignment = VerticalAlignment.Center,
+                    CellPadding = new Size2D(10, 20),
+                },
+            };
+
+            buttonSetNewIndi = new Button
+            {
+                WidthSpecification = LayoutParamPolicies.MatchParent,
+                Text = "Set New Focus Indicator",
+            };
+            rootContent.Add(buttonSetNewIndi);
+
+            buttonSetNewIndi.Clicked += (s, e) =>
+            {
+                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),
+                };
+            };
+
+            buttonSetNull = new Button
+            {
+                WidthSpecification = LayoutParamPolicies.MatchParent,
+                Text = "Set null Focus Indicator",
+            };
+            rootContent.Add(buttonSetNull);
+
+            buttonSetNull.Clicked += (s, e) =>
+            {
+                focusmanager.FocusIndicator = null;
+            };
+
+            buttonRestoreIndi = new Button
+            {
+                WidthSpecification = LayoutParamPolicies.MatchParent,
+                Text = "Restore default Focus Indicator",
+            };
+            rootContent.Add(buttonRestoreIndi);
+
+            buttonRestoreIndi.Clicked += (s, e) =>
+            {
+                focusmanager.FocusIndicator = focusmanager.GetDefaultFocusIndicator();
+            };
+
+            Content = rootContent;
+        }
+    }
+}
index def75a4..c520827 100644 (file)
@@ -174,7 +174,6 @@ namespace Tizen.NUI.StyleGuide
         private ContentPage page;
         private SearchField field;
         private List<ControlMenu> testSource;
-        private FocusManager focusManager;
 
         public void OnKeyEvent(object sender, Window.KeyEventArgs e)
         {
@@ -216,26 +215,8 @@ namespace Tizen.NUI.StyleGuide
             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);
+            FocusManager.Instance.EnableDefaultAlgorithm(true);
         }
         private void Initialize()
         {
index 1aab636..c9187b0 100755 (executable)
@@ -20,6 +20,7 @@
     <ItemGroup>
         <ProjectReference Include="../../src/Tizen.NUI.Components/Tizen.NUI.Components.csproj" />
         <ProjectReference Include="../../src/Tizen.NUI/Tizen.NUI.csproj" />
+        <PackageReference Include="Tizen.NET.Sdk" Version="1.0.9" />
     </ItemGroup>
 
 </Project>