Adding scanning images
authork.stepaniuk <k.stepaniuk@samsung.com>
Sat, 21 Mar 2020 16:52:33 +0000 (17:52 +0100)
committerLukasz Stanislawski/IoT & UI Sample (PLT) /SRPOL/Engineer/Samsung Electronics <l.stanislaws@samsung.com>
Mon, 23 Mar 2020 08:04:53 +0000 (09:04 +0100)
Handling scan logic

Signed-off-by: k.stepaniuk <k.stepaniuk@samsung.com>
Oobe/OobeCommon/Styles/ButtonStyles.cs
Oobe/OobeWifi/Controls/Wifi/WifiState.cs
Oobe/OobeWifi/Controls/Wifi/WifiView.cs
Oobe/OobeWifi/OobeWifi.csproj
Oobe/OobeWifi/res/12_icon_addnetwork_pressed.png [new file with mode: 0644]
Oobe/OobeWifi/res/12_icon_scan_disabled.png [new file with mode: 0644]
Oobe/OobeWifi/res/12_icon_scan_pressed.png [new file with mode: 0644]
Oobe/OobeWifi/res/12_icon_scanning.png [new file with mode: 0644]

index 1f0f19d27046f69955219701e2703fd929fdd0f0..ec2b11d4e10d2d5250ef154097381a82bbb0ed35 100644 (file)
@@ -32,6 +32,8 @@ namespace Oobe.Common.Styles
             BackgroundImage = new Selector<string>
             {
                 Normal = NUIApplication.Current.DirectoryInfo.Resource + "12_icon_scan.png",
+                Pressed = NUIApplication.Current.DirectoryInfo.Resource + "12_icon_scan_pressed.png",
+                Disabled = NUIApplication.Current.DirectoryInfo.Resource + "12_icon_scan_disabled.png",
             },
             Size2D = new Size2D(72, 32),
         };
@@ -40,6 +42,7 @@ namespace Oobe.Common.Styles
             BackgroundImage = new Selector<string>
             {
                 Normal = NUIApplication.Current.DirectoryInfo.Resource + "12_icon_addnetwork.png",
+                Pressed = NUIApplication.Current.DirectoryInfo.Resource + "12_icon_addnetwork_pressed.png",
             },
             Size2D = new Size2D(42, 42),
         };
index 410257de6dc59d14e0f25dd3aaa56ce2bc344738..4c22a6ce2b9e01179349912c2b1365182a1be1cc 100644 (file)
@@ -6,8 +6,9 @@ using System.Threading.Tasks;
 
 namespace Oobe.Wifi.Controls.Wifi
 {
-    struct WifiInfo
+    public struct WifiInfo
     {
+        public string Essid { get; set; }
     }
 
     internal class WifiState
@@ -15,6 +16,8 @@ namespace Oobe.Wifi.Controls.Wifi
         public event Action OnTurningOnFailed;
         public event Action OnTurnedOn;
         public event Action OnTurnedOff;
+        public event Action OnScanStarted;
+        public event Action OnScanFinished;
         public bool IsTurnedOn { get; private set; } = true;
 
         private int counter = 1; //for verify
@@ -43,9 +46,17 @@ namespace Oobe.Wifi.Controls.Wifi
             }
         }
 
-        async Task<IEnumerable<WifiInfo>> Scan()
+        //asyncEnumerable is useless here while tizen api doesn't support it
+        public async IAsyncEnumerable<WifiInfo> Scan()
         {
-            return await Task.FromResult<IEnumerable<WifiInfo>>(null);
+            OnScanStarted?.Invoke();
+            foreach (var item in Enumerable.Range(1, 6))
+            {
+                await Task.Delay(1_000);
+                yield return new WifiInfo { Essid = $"Wi-Fi_{item}" };
+            }
+            await Tizen.Network.WiFi.WiFiManager.ScanAsync();
+            OnScanFinished?.Invoke();
         }
     }
 }
index 5cc176b58b679953afb5d744fee1fc75963add0e..82fc92098b3c15b52fd73504cc34fafe242ce6f9 100644 (file)
@@ -15,18 +15,11 @@ namespace Oobe.Wifi.Controls.Wifi
         private View view = null;
         private ObservableCollection<View> items;
         private int counter = 0;
+        private const int listItemWidth = 460;
+        private const int listItemHeight = 89;
 
         private WifiState State { get; set; } = new WifiState();
 
-        private static IEnumerable<View> CreateViews(string pattern)
-        {
-            yield return CreateManualWifiView(460, 89);
-            foreach (var item in Enumerable.Range(1, 10))
-            {
-                yield return CreateWifiView(460, 89, $"Wi-Fi_{item}");
-            }
-        }
-
         public View View
         {
             get
@@ -52,32 +45,16 @@ namespace Oobe.Wifi.Controls.Wifi
                     });
 
                     view.Add(CreateListViewPlaceHolder());
-
-                    ForVerify();
                 }
                 return view;
             }
         }
 
-        private async void ForVerify()
-        {
-            counter++;
-            if (counter > 4)
-                return;
-            if (view != null)
-            {
-                await Task.Delay(2000);
-                items.RemoveAt(1);
-                //items.Insert(1, CreateViewAbsolute($"s{counter}"));
-                ForVerify();
-            }
-        }
-
-        private static View CreateManualWifiView(int width, int height)
+        private static View CreateManualWifiView()
         {
             var manualWifi = new View()
             {
-                Size = new Size(width, height),
+                Size = new Size(listItemWidth, listItemHeight),
                 Layout = new AbsoluteLayout(),
             };
 
@@ -98,11 +75,11 @@ namespace Oobe.Wifi.Controls.Wifi
             return manualWifi;
         }
 
-        private static View CreateWifiView(int width, int height, string name)
+        private static View CreateWifiView(WifiInfo wifiInfo)
         {
             var wifi = new View()
             {
-                Size = new Size(width, height),
+                Size = new Size(listItemWidth, listItemHeight),
                 Layout = new AbsoluteLayout(),
             };
 
@@ -113,7 +90,7 @@ namespace Oobe.Wifi.Controls.Wifi
                 BackgroundImage = System.IO.Path.Combine(NUIApplication.Current.DirectoryInfo.Resource, "12_icon_wifi.svg"),
             });
 
-            wifi.Add(new TextLabel(name)
+            wifi.Add(new TextLabel(wifiInfo.Essid)
             {
                 Position = new Position(78, 28),
                 PixelSize = 20f,
@@ -141,21 +118,26 @@ namespace Oobe.Wifi.Controls.Wifi
                 Layout = new AbsoluteLayout(),
             };
 
-            header.Add(new TextLabel("Wi-Fi")
-            {
-                Size = new Size(49, 24),
-                Position = new Position(40, 43),
-                PixelSize = 19f,
-                TextColor = new Color(0, 14.0f / 255.0f, 47.0f / 255.0f, 1.0f),
-                FontFamily = "BreezeSans",
-                FontStyle = FontsStyles.Regular(),
-            });
+            header.Add(CreateWifiScanningPlaceHolder());
 
-            header.Add(new Button(ButtonStyles.Scan)
+            var scan = new Button(ButtonStyles.Scan)
             {
                 Size = new Size(72, 32),
                 Position = new Position(276, 39),
-            });
+            };
+            scan.ClickEvent += async (s, e) =>
+            {
+                scan.IsEnabled = false;
+                await foreach(var item in State.Scan())
+                {
+                    items.Add(CreateWifiView(item));
+                }
+                scan.IsEnabled = State.IsTurnedOn;
+            };
+            scan.IsEnabled = State.IsTurnedOn;
+            State.OnTurnedOff += () => scan.IsEnabled = State.IsTurnedOn;
+            State.OnTurnedOn += () => scan.IsEnabled = State.IsTurnedOn;
+            header.Add(scan);
 
             header.Add(CreateTurnOnButton());
             return header;
@@ -183,12 +165,12 @@ namespace Oobe.Wifi.Controls.Wifi
         private View CreateListViewPlaceHolder()
         {
             var view = new View();
-            items = new ObservableCollection<View>(CreateViews($"{counter} "));
+            items = new ObservableCollection<View>();
+            items.Add(CreateManualWifiView());
             var listView = new ListView(480, 328)//480, 335
             {
                 Items = items
             }.View;
-            listView.Hide();
             view.Add(listView);
 
             var prompt = new TextLabel()
@@ -222,6 +204,67 @@ namespace Oobe.Wifi.Controls.Wifi
             return view;
         }
 
+        private static View CreateScanningView()
+        {
+            var view = new View()
+            {
+                Layout = new LinearLayout()
+                {
+                    LinearOrientation = LinearLayout.Orientation.Horizontal,
+                }
+            };
+            view.Add(new View()
+            {
+                Margin = new Extents(0, 0, 1, 0),
+                BackgroundImage = System.IO.Path.Combine(NUIApplication.Current.DirectoryInfo.Resource, "12_icon_scanning.png"),
+            });
+            view.Add(new TextLabel("Scanning...")
+            {
+                Margin = new Extents(17, 0, 0, 0),
+                PixelSize = 19f,
+                TextColor = new Color(0, 14.0f / 255.0f, 47.0f / 255.0f, 1.0f),
+                FontFamily = "BreezeSans",
+                FontStyle = FontsStyles.Regular(),
+            });
+            return view;
+        }
+
+        private View CreateWifiScanningPlaceHolder()
+        {
+            var view = new View()
+            {
+                Position = new Position(40, 43),
+            };
+
+            var wifi = new TextLabel("Wi-Fi")
+            {
+                //Size = new Size(49, 24),
+                PixelSize = 19f,
+                TextColor = new Color(0, 14.0f / 255.0f, 47.0f / 255.0f, 1.0f),
+                FontFamily = "BreezeSans",
+                FontStyle = FontsStyles.Regular(),
+            };
+            view.Add(wifi);
+
+            var scanning = CreateScanningView();
+            view.Add(scanning);
+
+            void startScan()
+            {
+                wifi.Hide();
+                scanning.Show();
+            }
+            void finishScan()
+            {
+                scanning.Hide();
+                wifi.Show();
+            }
+            finishScan();
+            State.OnScanStarted += startScan;
+            State.OnScanFinished += finishScan;
+            return view;
+        }
+
         public void Dispose()
         {
             view = null;
index c95a791ffa48dcb6573b7835c37ce84305156bf9..244aee82ab7074d18bfb50b03bf8ba6a5e6fa56d 100644 (file)
@@ -3,6 +3,7 @@
   <PropertyGroup>\r
     <OutputType>Library</OutputType>\r
     <TargetFramework>tizen80</TargetFramework>\r
+    <LangVersion>8.0</LangVersion>\r
     <TargetFrameworkIndentifier>Tizen</TargetFrameworkIndentifier>\r
   </PropertyGroup>\r
 \r
diff --git a/Oobe/OobeWifi/res/12_icon_addnetwork_pressed.png b/Oobe/OobeWifi/res/12_icon_addnetwork_pressed.png
new file mode 100644 (file)
index 0000000..e5cb658
Binary files /dev/null and b/Oobe/OobeWifi/res/12_icon_addnetwork_pressed.png differ
diff --git a/Oobe/OobeWifi/res/12_icon_scan_disabled.png b/Oobe/OobeWifi/res/12_icon_scan_disabled.png
new file mode 100644 (file)
index 0000000..8c15ba5
Binary files /dev/null and b/Oobe/OobeWifi/res/12_icon_scan_disabled.png differ
diff --git a/Oobe/OobeWifi/res/12_icon_scan_pressed.png b/Oobe/OobeWifi/res/12_icon_scan_pressed.png
new file mode 100644 (file)
index 0000000..548ff10
Binary files /dev/null and b/Oobe/OobeWifi/res/12_icon_scan_pressed.png differ
diff --git a/Oobe/OobeWifi/res/12_icon_scanning.png b/Oobe/OobeWifi/res/12_icon_scanning.png
new file mode 100644 (file)
index 0000000..6213c30
Binary files /dev/null and b/Oobe/OobeWifi/res/12_icon_scanning.png differ