Change Wifi Security Types to clickable
authorKrzysztof Wieclaw/IoT & UI Sample (PLT) /SRPOL/Engineer/Samsung Electronics <k.wieclaw@samsung.com>
Fri, 8 Oct 2021 19:12:01 +0000 (21:12 +0200)
committerKrzysztof Wieclaw/IoT & UI Sample (PLT) /SRPOL/Engineer/Samsung Electronics <k.wieclaw@samsung.com>
Thu, 14 Oct 2021 17:11:16 +0000 (19:11 +0200)
Change-Id: I6d4b1eca9e734e6600ebe1fbd69e62b4bee495fa
Signed-off-by: Krzysztof Wieclaw/IoT & UI Sample (PLT) /SRPOL/Engineer/Samsung Electronics <k.wieclaw@samsung.com>
Oobe/Oobe.Wifi/Controls/Wifi/ChangeSecurityTypePopup.cs
Oobe/Oobe.Wifi/Controls/Wifi/SecurityTypeView.cs

index e3c43ad..e872fd6 100644 (file)
@@ -107,6 +107,9 @@ namespace Oobe.Wifi.Controls.Wifi
                 Items = choiceViews,
             };
             listView.View.Position = DpUtils.ToPixels(new Position(0, 82));
+
+            (radioButtonGroup.GetItem(0) as SecurityTypeView.SecurityRadioButton)?.SetSelectionProgramatically(true);
+
             this.Add(listView.View);
         }
 
@@ -119,7 +122,7 @@ namespace Oobe.Wifi.Controls.Wifi
             }
 
             radioButtonGroup.Add(view.Button);
-            view.Button.Clicked += (s, e) => this.WifiUISecurityType = view.WifiUISecurityType;
+            view.Activated += () => this.WifiUISecurityType = view.WifiUISecurityType;
             return view;
         }
     }
index f1e58df..0666e02 100644 (file)
@@ -28,6 +28,8 @@ namespace Oobe.Wifi.Controls.Wifi
     {
         private TextLabel descriptionTextLabel = null;
 
+        private TapGestureDetector detector;
+
         public SecurityTypeView(WifiUISecurityType wifiUISecurityType)
         {
             Size = DpUtils.ToPixels(new Size(768, 64));
@@ -37,13 +39,15 @@ namespace Oobe.Wifi.Controls.Wifi
             InitializeSubelements();
         }
 
+        public event Action Activated;
+
         public WifiUISecurityType WifiUISecurityType { get; set; }
 
-        public RadioButton Button { get; set; }
+        public SecurityRadioButton Button { get; set; }
 
         private void InitializeSubelements()
         {
-            Button = new RadioButton
+            Button = new SecurityRadioButton
             {
                 IsSelected = false,
                 Position = DpUtils.ToPixels(new Position(40, 20)),
@@ -66,6 +70,47 @@ namespace Oobe.Wifi.Controls.Wifi
                 VerticalAlignment = VerticalAlignment.Center,
             };
             this.Add(descriptionTextLabel);
+
+            detector = new TapGestureDetector();
+            detector.Detected += OnClicked;
+            detector.Attach(this);
+        }
+
+        private void OnClicked(object sender, TapGestureDetector.DetectedEventArgs args)
+        {
+            var selectedIndex = Button.ItemGroup.SelectedIndex;
+            Tizen.Log.Debug("oobe", $"Selected index {selectedIndex}");
+            if (Button.ItemGroup.GetItem(selectedIndex) is SecurityRadioButton selectedView)
+            {
+                selectedView.SetSelectionProgramatically(false);
+                Button.SetSelectionProgramatically(true);
+                Activated?.Invoke();
+            }
+        }
+
+        public class SecurityRadioButton : RadioButton
+        {
+            public void SetSelectionProgramatically(bool isSelected)
+            {
+                IsSelected = isSelected;
+                Tizen.Log.Debug("oobe", $"Button{this.ItemGroup.SelectedIndex}, isSelected={isSelected}");
+                // Unfortunatelly RadioButtonGroup has no public method to activate/deactivate its items
+                // Below sequence is a workaround way of informing manager (RadioButtonGroup) about change
+                // It is an equivalent of raising SelectedChanged event (this could be done by reflection)
+                OnKey(new Key()
+                {
+                    State = Tizen.NUI.Key.StateType.Up,
+                    KeyPressedName = "Return",
+                });
+                if (isSelected)
+                {
+                    OnControlStateChanged(new ControlStateChangedEventArgs(ControlState.Normal, ControlState.Selected));
+                }
+                else
+                {
+                    OnControlStateChanged(new ControlStateChangedEventArgs(ControlState.Selected, ControlState.Normal));
+                }
+            }
         }
     }
 }