Implement connection request pop up 48/320048/8
authorSaksham Grover <s.grover@partner.samsung.com>
Fri, 21 Feb 2025 03:59:18 +0000 (09:29 +0530)
committerSaksham Grover <s.grover@partner.samsung.com>
Tue, 25 Mar 2025 11:34:19 +0000 (17:04 +0530)
Change-Id: If944fe399b7d99606fe951b3e99e5993ed506c1e
Signed-off-by: Saksham Grover <s.grover@partner.samsung.com>
SettingWiFiDirect/SettingWiFiDirect/SettingWiFiDirect.cs
SettingWiFiDirect/SettingWiFiDirect/TextResources/Resources.Designer.cs
SettingWiFiDirect/SettingWiFiDirect/TextResources/Resources.en-US.resx
SettingWiFiDirect/SettingWiFiDirect/TextResources/Resources.ko-KR.resx
SettingWiFiDirect/SettingWiFiDirect/TextResources/Resources.resx
SettingWiFiDirect/SettingWiFiDirect/WiFiDirectConfig.cs
SettingWiFiDirect/SettingWiFiDirect/controller/WiFiDirect.cs
SettingWiFiDirect/SettingWiFiDirect/view/ConnectionPopup.cs [new file with mode: 0644]

index 63022a80a65e5e743067d78535a6b925371a7525..2bd8967250bf1172c4500a4e5861aacaed24bd42 100644 (file)
@@ -1,7 +1,6 @@
 using System;
 using System.Linq;
 using System.Collections.Generic;
-using Tizen;
 using Tizen.NUI;
 using Tizen.NUI.BaseComponents;
 using Tizen.NUI.Binding;
@@ -9,13 +8,12 @@ using Tizen.NUI.Components;
 using SettingCore;
 using static SettingWiFiDirect.Logger;
 using SettingWiFiDirect.TextResources;
-
+using Tizen.Network.WiFiDirect;
 
 namespace SettingWiFiDirect
 {
     public class MainPage : SettingCore.MenuGadget
     {
-        private WiFiDirect mWifiDirect;
         private PeerSource mPeerSource;
         private CollectionView mScanList;
         bool mNeedScanning;
@@ -30,13 +28,11 @@ namespace SettingWiFiDirect
         public MainPage()
         {
             Debug("+");
-            mWifiDirect = new WiFiDirect();
             mNeedScanning = true;
-            mWifiDirect.WFDStateChanged += OnWFDStateChanged;
-            mWifiDirect.Activate();
+            WiFiDirect.Activate();
             try
             {
-                bool flag = mWifiDirect.IsDiscoverable();
+                bool flag = WiFiDirect.IsDiscoverable();
 
                 if (flag)
                 {
@@ -53,11 +49,14 @@ namespace SettingWiFiDirect
             }
 
             Resources.SetPath(GetResourcePath(""));
-            StartScan();
+
         }
 
         protected override View OnCreate()
         {
+            WiFiDirect.WFDStateChanged += OnWFDStateChanged;
+            WiFiDirect.WFDStatusChanged += OnConnectionStatusChanged;
+
             Debug("MainPage: " + this.GetHashCode());
             base.OnCreate();
             ResourceManager.TextResourceManager = this;
@@ -69,6 +68,8 @@ namespace SettingWiFiDirect
         protected override void OnDestroy()
         {
             Debug("+");
+            WiFiDirect.WFDStateChanged -= OnWFDStateChanged;
+            WiFiDirect.WFDStatusChanged -= OnConnectionStatusChanged;
             base.OnDestroy();
         }
 
@@ -165,12 +166,53 @@ namespace SettingWiFiDirect
                     }
                     break;
                 case WFDState.Connected:
+                    ChangeScanningState(false);
                     ShowConnectedDevice();
                     break;
                 case WFDState.Disconnecting:
                     mNeedScanning = true;
                     break;
                 //TODO: update for further states.
+
+            }
+        }
+
+        private void OnConnectionStatusChanged(object sender, ConnectionStatusChangedEventArgs e)
+        {
+            Debug("State : " + e.ConnectionState);
+
+            switch (e.ConnectionState)
+            {
+                case WiFiDirectConnectionState.ConnectionRequest:
+
+                    OnConnectionRequest();
+                    break;
+
+                default:
+                    break;
+            }
+
+        }
+
+        private void OnConnectionRequest()
+        {
+            try
+            {
+                ConnectionPopup connectionPopup = new ConnectionPopup();
+                var page = connectionPopup.ConnectionPopupPage();
+                if (page != null)
+                {
+                    NUIApplication.GetDefaultWindow().GetDefaultNavigator().Add(page);
+                    connectionPopup.SetPopupPage(page);
+                }
+                else
+                {
+                    Debug("Page is NULL");
+                }
+            }
+            catch (Exception e)
+            {
+                Debug("An error occurred: " + e.Message);
             }
         }
 
@@ -222,8 +264,6 @@ namespace SettingWiFiDirect
                 item.SubLabel.SetBinding(TextLabel.TextProperty, "StateInfo");
                 item.SubLabel.HorizontalAlignment = HorizontalAlignment.Begin;
 
-                //item.Icon = GetApIconImageView();
-                //item.Extra = GetInfoButton();
                 item.IsSelectable = false;
                 item.SizeWidth = mScanList.SizeWidth;
 
@@ -235,8 +275,7 @@ namespace SettingWiFiDirect
         private void StartScan()
         {
             Debug("+");
-
-            bool discoveryStarted = mWifiDirect.StartDiscovery();
+            bool discoveryStarted = WiFiDirect.StartDiscovery();
             if (discoveryStarted)
             {
                 Debug("Discovery started");
@@ -251,7 +290,7 @@ namespace SettingWiFiDirect
             Debug("+");
             try
             {
-                List<Peer> peerList = mWifiDirect.GetScanResult();
+                List<Peer> peerList = WiFiDirect.GetScanResult();
                 mPeerSource.ShowDiscoveredPeers(peerList);
             }
             catch (Exception e)
@@ -263,16 +302,16 @@ namespace SettingWiFiDirect
         private void ShowConnectedDevice()
         {
             Debug("+");
-            List<Peer> peerList = mWifiDirect.GetConnectedDevices();
+            List<Peer> peerList = WiFiDirect.GetConnectedDevices();
             mPeerSource.ShowConnectedPeer(peerList);
         }
 
         private TextLabel GetHeader()
         {
             Debug("+");
-            string headerString = NUIGadgetResourceManager.GetString(nameof(Resources.IDS_WIFI_BODY_YOUR_DEVICE_HPS_IS_CURRENTLY_VISIBLE_TO_NEARBY_DEVICES));
-            string label = string.Format(headerString, mWifiDirect.getDeviceName());
-
+            string headerString = NUIGadgetResourceManager.GetString(
+                nameof(Resources.IDS_WIFI_BODY_YOUR_DEVICE_HPS_IS_CURRENTLY_VISIBLE_TO_NEARBY_DEVICES));
+            string label = string.Format(headerString, WiFiDirect.getDeviceName());
             TextLabel header = new TextLabel(label);
 
             return header;
@@ -283,6 +322,7 @@ namespace SettingWiFiDirect
             Debug("this: " + this.GetHashCode());
             DefaultLinearItem listItem = (DefaultLinearItem)sender;
             var peer = listItem.BindingContext as Peer;
+
             Info("Name: " + peer.Name + " Address: " + peer.Address);
             if(!peer.IsConnected())
             {
index a2ff4944a2c6a9607a84246dd15a6f3f96f7b261..5133c514d60d7b51d7addf65a8f10f0a0445a160 100644 (file)
@@ -162,6 +162,24 @@ namespace SettingWiFiDirect.TextResources {
             }
         }
         
+        /// <summary>
+        ///   Looks up a localized string similar to wifi direct connection.
+        /// </summary>
+        public static string IDS_WIFI_HEADER_WI_FI_DIRECT_CONNECTION_ABB {
+            get {
+                return ResourceManager.GetString("IDS_WIFI_HEADER_WI_FI_DIRECT_CONNECTION_ABB", resourceCulture);
+            }
+        }
+        
+        /// <summary>
+        ///   Looks up a localized string similar to Connect to ({0}) in ({1}) seconds..
+        /// </summary>
+        public static string IDS_WIFI_POP_CONNECT_TO_PS_IN_PD_SECONDS {
+            get {
+                return ResourceManager.GetString("IDS_WIFI_POP_CONNECT_TO_PS_IN_PD_SECONDS", resourceCulture);
+            }
+        }
+        
         /// <summary>
         ///   Looks up a localized string similar to Cancel.
         /// </summary>
@@ -179,5 +197,14 @@ namespace SettingWiFiDirect.TextResources {
                 return ResourceManager.GetString("IDS_WIFI_SK_DISCONNECT", resourceCulture);
             }
         }
+        
+        /// <summary>
+        ///   Looks up a localized string similar to ok.
+        /// </summary>
+        public static string IDS_WIFI_SK2_OK {
+            get {
+                return ResourceManager.GetString("IDS_WIFI_SK2_OK", resourceCulture);
+            }
+        }
     }
 }
index b61b83d5218fb5812916ea95644fe008eaac9dd8..5013c0209b33aefe7494c6d75398e49ef9e3c719 100644 (file)
   <data name="IDS_WIFI_HEADER_AVAILABLE_DEVICES_ABB" xml:space="preserve">
     <value>Available devices</value>
   </data>
+  <data name="IDS_WIFI_HEADER_WI_FI_DIRECT_CONNECTION_ABB" xml:space="preserve">
+    <value>Wi-Fi Direct connection</value>
+  </data>
+  <data name="IDS_WIFI_POP_CONNECT_TO_PS_IN_PD_SECONDS" xml:space="preserve">
+    <value>Connect to ({0}) in ({1}) seconds.
+</value>
+  </data>
+  <data name="IDS_WIFI_SK2_OK" xml:space="preserve">
+    <value>OK</value>
+  </data>
   <data name="IDS_WIFI_SK_CANCEL" xml:space="preserve">
     <value>Cancel</value>
   </data>
index 100a8c645573a016fe15ecc8b8f3afa33f17d037..18870255aabc65dbbeb8db224cff1ed542a64c9f 100644 (file)
   <data name="IDS_WIFI_HEADER_AVAILABLE_DEVICES_ABB" xml:space="preserve">
     <value>사용 가능한 디바이스</value>
   </data>
+  <data name="IDS_WIFI_HEADER_WI_FI_DIRECT_CONNECTION_ABB" xml:space="preserve">
+    <value>Wi-Fi 다이렉트 연결</value>
+  </data>
+  <data name="IDS_WIFI_POP_CONNECT_TO_PS_IN_PD_SECONDS" xml:space="preserve">
+    <value>({1})에 ({0})초 이내에 연결됩니다.</value>
+  </data>
+  <data name="IDS_WIFI_SK2_OK" xml:space="preserve">
+    <value>확인</value>
+  </data>
   <data name="IDS_WIFI_SK_CANCEL" xml:space="preserve">
     <value>취소</value>
   </data>
index b61b83d5218fb5812916ea95644fe008eaac9dd8..fd8e4fede7fee0e900c3a2f613685e1f516a8a9c 100644 (file)
   <data name="IDS_WIFI_HEADER_AVAILABLE_DEVICES_ABB" xml:space="preserve">
     <value>Available devices</value>
   </data>
+  <data name="IDS_WIFI_HEADER_WI_FI_DIRECT_CONNECTION_ABB" xml:space="preserve">
+    <value>wifi direct connection</value>
+  </data>
+  <data name="IDS_WIFI_POP_CONNECT_TO_PS_IN_PD_SECONDS" xml:space="preserve">
+    <value>Connect to ({0}) in ({1}) seconds.</value>
+  </data>
+  <data name="IDS_WIFI_SK2_OK" xml:space="preserve">
+    <value>ok</value>
+  </data>
   <data name="IDS_WIFI_SK_CANCEL" xml:space="preserve">
     <value>Cancel</value>
   </data>
index 130aa01a2f718f40586cf49b9ca66cc3af4e967c..af001d81d5aedb61608b5545082551c8509277a0 100644 (file)
@@ -5,8 +5,8 @@ namespace SettingWiFiDirect
     internal static class WifiDirectConfig
     {
         // Following values are tentative, may be changed later.
-        internal const string PeerDeviceName = "TizenRPI4_WFD";
-        internal const int DiscoveryTime = 10;
+        internal const string PeerDeviceName = "RpiNui";
+        internal const int DiscoveryTime = 60;
         internal const int DelayTime = 2000;
         internal const int DiscoverDelayTime = 1000;
         internal const int StartDiscoveryDelayTime = 10000;
index 63b51468cd77b9845496518b90072f4af769b457..0535cbf3febd4f51b56092b80493bf5be247b4b6 100644 (file)
@@ -6,14 +6,14 @@ using static SettingWiFiDirect.Logger;
 
 namespace SettingWiFiDirect
 {
-    class WiFiDirect
+    static class WiFiDirect
     {
-        IEnumerable<WiFiDirectPeer> mFoundDeviceList = new List<WiFiDirectPeer>();
-        IEnumerable<WiFiDirectPeer> mConnectedDeviceList = new List<WiFiDirectPeer>();
-        private event EventHandler<WFDStateChangedEventArgs> mWifiDirectStateChanged = null;
-        bool _isInitialized = false;
+        static private IEnumerable<WiFiDirectPeer> mFoundDeviceList = new List<WiFiDirectPeer>();
+        static private IEnumerable<WiFiDirectPeer> mConnectedDeviceList = new List<WiFiDirectPeer>();
+        static private event EventHandler<WFDStateChangedEventArgs> mWifiDirectStateChanged = null;
+        static bool _isInitialized = false;
 
-        internal void Initialize()
+        static internal void Initialize()
         {
             if (WiFiDirectManager.IsInitialized)
             {
@@ -32,15 +32,22 @@ namespace SettingWiFiDirect
             }
         }
 
-        public async Task Activate()
+        static public async Task Activate()
         {
+            Debug("WiFiDirect.Activate");
+            Initialize();
+            if (WiFiDirectManager.State >= WiFiDirectState.Activated)
+            {
+                Debug("Already activated");
+                return;
+            }
+
             WiFiDirectManager.DeviceStateChanged += (Object sender, DeviceStateChangedEventArgs e) =>
             {
                 Debug("DeviceState: " + e.DeviceState);
+                StartDiscovery();
             };
 
-            Debug("WiFiDirect.Activate");
-            Initialize();
             if (!_isInitialized)
             {
                 return;
@@ -55,13 +62,13 @@ namespace SettingWiFiDirect
             }
         }
 
-        public void Deactivate()
+        static public void Deactivate()
         {
             Debug("WiFiDirect.Deactivate");
             WiFiDirectManager.Deactivate();
         }
 
-        internal event EventHandler<WFDStateChangedEventArgs> WFDStateChanged
+        static internal event EventHandler<WFDStateChangedEventArgs> WFDStateChanged
         {
             add
             {
@@ -81,14 +88,26 @@ namespace SettingWiFiDirect
             }
         }
 
-        private void OnWiFiDirectStateChanged(Object sender, StateChangedEventArgs e)
+        static private void OnWiFiDirectStateChanged(Object sender, StateChangedEventArgs e)
         {
             Debug("+");
             WFDState state = ConvertWFDState(e.State);
             mWifiDirectStateChanged.Invoke(null, new WFDStateChangedEventArgs(state));
         }
 
-        private WFDState ConvertWFDState(WiFiDirectState state)
+        static internal event EventHandler<ConnectionStatusChangedEventArgs> WFDStatusChanged
+        {
+            add
+            {
+                WiFiDirectManager.ConnectionStatusChanged += value;
+            }
+            remove
+            {
+                WiFiDirectManager.ConnectionStatusChanged -= value;
+            }
+        }
+
+        static private WFDState ConvertWFDState(WiFiDirectState state)
         {
             switch (state)
             {
@@ -113,7 +132,7 @@ namespace SettingWiFiDirect
             }
         }
 
-        public bool StartDiscovery()
+        static public bool StartDiscovery()
         {
             Debug("+");
             try
@@ -128,7 +147,7 @@ namespace SettingWiFiDirect
             return true;
         }
 
-        public bool IsDiscoverable()
+        static public bool IsDiscoverable()
         {
             Debug("+");
             if (WiFiDirectManager.IsDiscoverable)
@@ -139,7 +158,7 @@ namespace SettingWiFiDirect
             return false;
         }
 
-        public List<Peer> GetScanResult()
+        static public List<Peer> GetScanResult()
         {
             Debug("+");
             try
@@ -155,7 +174,7 @@ namespace SettingWiFiDirect
             return null;
         }
 
-        public List<Peer> GetConnectedDevices()
+        static public List<Peer> GetConnectedDevices()
         {
             Debug("+");
             try
@@ -171,7 +190,7 @@ namespace SettingWiFiDirect
             return null;
         }
 
-        public List<Peer> GetPeerList()
+        static public List<Peer> GetPeerList()
         {
             Debug("+");
             List<Peer> peerList = new List<Peer>();
@@ -185,14 +204,14 @@ namespace SettingWiFiDirect
             return peerList;
         }
 
-        private Peer CreatePeer(WiFiDirectPeer wifiDirectPeer)
+        static private Peer CreatePeer(WiFiDirectPeer wifiDirectPeer)
         {
             Debug("+");
             Peer peer = new Peer(wifiDirectPeer);
             return peer;
         }
 
-        public string getDeviceName()
+        static public string getDeviceName()
         {
             return WiFiDirectManager.Name;
         }
diff --git a/SettingWiFiDirect/SettingWiFiDirect/view/ConnectionPopup.cs b/SettingWiFiDirect/SettingWiFiDirect/view/ConnectionPopup.cs
new file mode 100644 (file)
index 0000000..a88e66e
--- /dev/null
@@ -0,0 +1,150 @@
+using Tizen.NUI.BaseComponents;
+using Tizen.NUI;
+using Tizen.NUI.Components;
+using SettingWiFiDirect.TextResources;
+using static SettingWiFiDirect.Logger;
+
+namespace SettingWiFiDirect
+{
+    internal class ConnectionPopup:ContentPage
+    {
+        private Timer mTimer;
+        private Progress mProgress;
+        private ContentPage mContentPage = null;
+        private const int MaxDuration = 120;
+
+        internal ContentPage ConnectionPopupPage()
+        {
+            var connectionRequestView = new View()
+            {
+                Layout = new LinearLayout()
+                {
+                    LinearOrientation = LinearLayout.Orientation.Vertical,
+                    HorizontalAlignment = HorizontalAlignment.Center,
+                },
+                WidthSpecification = 200,
+                HeightSpecification = 100,
+            };
+
+            var item = new DefaultLinearItem();
+            connectionRequestView.Add(item);
+
+            int timeout = 120;
+            string message = ResourceManager.TextResourceManager.NUIGadgetResourceManager.GetString(
+                nameof(Resources.IDS_WIFI_POP_CONNECT_TO_PS_IN_PD_SECONDS));
+            string label = string.Format(message, WiFiDirect.getDeviceName(), timeout);
+
+            var messageItem = new TextLabel(label)
+            {
+                HorizontalAlignment = HorizontalAlignment.Center,
+            };
+
+            CreateProgressBar();
+
+            connectionRequestView.Add(messageItem);
+            connectionRequestView.Add(mProgress);
+
+            var cancelButton = CreateCancelButton();
+            var okButton = CreateOkButton();
+
+            ContentPage page = new ContentPage()
+            {
+                Content = new AlertDialog()
+                {
+                    Title = ResourceManager.TextResourceManager.NUIGadgetResourceManager.GetString(
+                        nameof(Resources.IDS_WIFI_HEADER_WI_FI_DIRECT_CONNECTION_ABB)),
+                    Content = connectionRequestView,
+                    Actions = new View[] { cancelButton, okButton },
+                },
+            };
+
+            return page;
+        }
+
+        private bool OnTimerTick()
+        {
+            mProgress.CurrentValue++;
+
+            if (mProgress.CurrentValue == MaxDuration)
+            {
+                if (mContentPage != null)
+                {
+                    NUIApplication.GetDefaultWindow().GetDefaultNavigator().Remove(mContentPage);
+                }
+                return false;
+            }
+
+            return true;
+        }
+
+        private void OnCancelButtonClicked(object sender, ClickedEventArgs e)
+        {
+            Debug("+");
+            mTimer.Stop();
+            if (mContentPage != null)
+            {
+                NUIApplication.GetDefaultWindow().GetDefaultNavigator().Remove(mContentPage);
+            }
+        }
+
+        private Button CreateOkButton()
+        {
+            var okButton = new Button()
+            {
+                Text = ResourceManager.TextResourceManager.NUIGadgetResourceManager.GetString(
+                    nameof(Resources.IDS_WIFI_SK2_OK)),
+                WidthSpecification = 300,
+                HeightSpecification = 80,
+            };
+            okButton.Clicked += OnOkConfirmed;
+            return okButton;
+        }
+
+        private Button CreateCancelButton()
+        {
+            var cancelButton = new Button()
+            {
+                Text = ResourceManager.TextResourceManager.NUIGadgetResourceManager.GetString(
+                    nameof(Resources.IDS_WIFI_SK_CANCEL)),
+                WidthSpecification = 300,
+                HeightSpecification = 80,
+            };
+            cancelButton.Clicked += OnCancelButtonClicked;
+            return cancelButton;
+        }
+
+        private void CreateProgressBar()
+        {
+            var customColor = new Color("#FF6200");
+            mProgress = new Progress()
+            {
+                MinValue = 0,
+                MaxValue = 120,
+                CurrentValue = 0,
+                TrackColor = Color.LightGrey,
+                ProgressColor = customColor,
+            };
+
+            mTimer = new Timer(1000);
+
+            mTimer.Tick += (o, e) => OnTimerTick();
+            mTimer.Start();
+        }
+
+        private void OnOkConfirmed(object source, ClickedEventArgs args)
+        {
+            Debug("+");
+            if (mContentPage != null)
+            {
+                NUIApplication.GetDefaultWindow().GetDefaultNavigator().Remove(mContentPage);
+            }  //TODO
+        }
+
+        public void SetPopupPage(ContentPage page)
+        {
+            Debug("+");
+            mContentPage = page;
+        }
+
+    }
+}