From 8302b34beeefd6cbc1aff18633c5b279a274c9f1 Mon Sep 17 00:00:00 2001 From: "k.stepaniuk" Date: Sat, 21 Mar 2020 17:52:33 +0100 Subject: [PATCH] Adding scanning images Handling scan logic Signed-off-by: k.stepaniuk --- Oobe/OobeCommon/Styles/ButtonStyles.cs | 3 + Oobe/OobeWifi/Controls/Wifi/WifiState.cs | 17 ++- Oobe/OobeWifi/Controls/Wifi/WifiView.cs | 129 +++++++++++++++-------- Oobe/OobeWifi/OobeWifi.csproj | 1 + Oobe/OobeWifi/res/12_icon_addnetwork_pressed.png | Bin 0 -> 1153 bytes Oobe/OobeWifi/res/12_icon_scan_disabled.png | Bin 0 -> 1639 bytes Oobe/OobeWifi/res/12_icon_scan_pressed.png | Bin 0 -> 1627 bytes Oobe/OobeWifi/res/12_icon_scanning.png | Bin 0 -> 625 bytes 8 files changed, 104 insertions(+), 46 deletions(-) create mode 100644 Oobe/OobeWifi/res/12_icon_addnetwork_pressed.png create mode 100644 Oobe/OobeWifi/res/12_icon_scan_disabled.png create mode 100644 Oobe/OobeWifi/res/12_icon_scan_pressed.png create mode 100644 Oobe/OobeWifi/res/12_icon_scanning.png diff --git a/Oobe/OobeCommon/Styles/ButtonStyles.cs b/Oobe/OobeCommon/Styles/ButtonStyles.cs index 1f0f19d..ec2b11d 100644 --- a/Oobe/OobeCommon/Styles/ButtonStyles.cs +++ b/Oobe/OobeCommon/Styles/ButtonStyles.cs @@ -32,6 +32,8 @@ namespace Oobe.Common.Styles BackgroundImage = new Selector { 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 { Normal = NUIApplication.Current.DirectoryInfo.Resource + "12_icon_addnetwork.png", + Pressed = NUIApplication.Current.DirectoryInfo.Resource + "12_icon_addnetwork_pressed.png", }, Size2D = new Size2D(42, 42), }; diff --git a/Oobe/OobeWifi/Controls/Wifi/WifiState.cs b/Oobe/OobeWifi/Controls/Wifi/WifiState.cs index 410257d..4c22a6c 100644 --- a/Oobe/OobeWifi/Controls/Wifi/WifiState.cs +++ b/Oobe/OobeWifi/Controls/Wifi/WifiState.cs @@ -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> Scan() + //asyncEnumerable is useless here while tizen api doesn't support it + public async IAsyncEnumerable Scan() { - return await Task.FromResult>(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(); } } } diff --git a/Oobe/OobeWifi/Controls/Wifi/WifiView.cs b/Oobe/OobeWifi/Controls/Wifi/WifiView.cs index 5cc176b..82fc920 100644 --- a/Oobe/OobeWifi/Controls/Wifi/WifiView.cs +++ b/Oobe/OobeWifi/Controls/Wifi/WifiView.cs @@ -15,18 +15,11 @@ namespace Oobe.Wifi.Controls.Wifi private View view = null; private ObservableCollection 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 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(CreateViews($"{counter} ")); + items = new ObservableCollection(); + 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; diff --git a/Oobe/OobeWifi/OobeWifi.csproj b/Oobe/OobeWifi/OobeWifi.csproj index c95a791..244aee8 100644 --- a/Oobe/OobeWifi/OobeWifi.csproj +++ b/Oobe/OobeWifi/OobeWifi.csproj @@ -3,6 +3,7 @@ Library tizen80 + 8.0 Tizen diff --git a/Oobe/OobeWifi/res/12_icon_addnetwork_pressed.png b/Oobe/OobeWifi/res/12_icon_addnetwork_pressed.png new file mode 100644 index 0000000000000000000000000000000000000000..e5cb65875099e64132db86d313fd019cc16ad82b GIT binary patch literal 1153 zcmV-{1b+L8P)TPt zS5S8aO;2dXS2ZEvCKX;nulWR{-}(-Qb2C|IJj|dM7K=p;=9xemB5NL39)xxhIX8?9{hK>Qq1*~#TfsZ%*G-q#!_02u8 zwH4=d!7~@AGRinHibGb*Io6v8Wy3XZ(HJoI0eYN{VT?f7pSSr!pxV$`u2`N4$30pW zBAfR?6dnM0cQZ#7+g=ga8K7~vzXu6O27e=hXIrIZ0ZSHPhEJe7n&L*-*zD%hAOkd? zlL{oLXPb*%bVe@|;}e>6x5eUlU2;-T;k4xtsVX1fL71qkk_mpM4)(j$eUfROs0BNLedE zG#;dE!0d~5XJ5`$Kxf=;?4;}hM!vD$>_j-7tqSuc*S^oEUko$~CG8|6EIlDB#(=GF8@S?2Ee({7SCWlU5OW1@!AD57X&M!a`Y~D+mAalzr$lPSg9Fqk!m1464YHX@b z9w&2`v5e_N%Fw`)&<9c2XYhg1<Eg z1n6V^<|=YI_LVXhKLg>odsT8Z0h)x&)<$4niKGJ9?kKHm<(IqkP+;`uk@-CEr7m~6 z5xD)=WuyC%!q+3+2hNpPY(u(`iefFwl#nij<7R}pLP>{z{utg|19+muD@)_*}n zFiuhlNlKX;o4X4o9mA`6iABCzxge3x$wd;%Yitx%6#mX^K@|8w{ev1JhKH$jXSzIQ1Uo}O2}lB@AwlCS zF~I~M{P9JjQH%s_MKQ!g3^5TCh#{B|#8(Vzm??#s0=qM%NCFB3sr*5LpcL4hWA1Ec zyIZzpySo$?_fM0~z2~0u-E+S4-8(}l@W;&5;X(=qxY zl64FzMq*Q$V?;E9fpvx|ue_RH{Q}gwuVZ{FmE6jpEmg@;tEW#NbKzxopK2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S`}_>TeqB{wDP_@0nJY2} z%r(8ixuV3f1F~%IB?iAph%{8nP2fN`Bp_s;wgS8+yR5F7LE(Vi@n6R#FJBUG9=}Nr zk2KG$tvx?bCvL>?Lg(P@#YP6r@rfEjLeA%Fp&u{2!9*_*@Glr~mN+hf;zKzSFUK{> zwFFUITU?@4%okszFeVX5ysa3*pml|uKMMjV3}DyZ_HilpW0H>;6U7*aRmSHph!b<% lm$08e@%kyzqlJF{@*nS8P%_fS*{}cr002ovPDHLkV1nM~?vwxk literal 0 HcmV?d00001 diff --git a/Oobe/OobeWifi/res/12_icon_scan_pressed.png b/Oobe/OobeWifi/res/12_icon_scan_pressed.png new file mode 100644 index 0000000000000000000000000000000000000000..548ff10893f49147b24d27a2fcdd27d844a74f84 GIT binary patch literal 1627 zcmV-h2Bi6kP)%U2GIp6#mZa(uRlu#hod1hVEXtAX_y&s4%m2rloUN0|Zc-(mCeN z?yN(*wA1cdS)8|>Irsd0_x#?ygqROAll6Pw0%EigC=2*)0NMa*ipk1mqqU=xJC7iDb%288o?wY93 zdZf2JXB$A-jHWLissAW|BsdAio)*n`zaEX9tj@ORdl=w{OjU1>^0*8j8CD?W#{Y}w zj0Ds2+&2^j{ppmxJ^WS%C`ibl!x>dyIN4pe7S`FGW1%70Zr(5_FYPGd{iDdHr zYc(Oq-8{>4ZzaNBQ`Kc#Py|T!IZzbeOf|m}mr*4;yWngE(<%lx5ojhedI{(wqIc73 z^E=h>p31eBa5pKy#k8t#CfOm|qHkcD%IRwQ9NTmDf#?Bd9t0?C9;XvQ4UA)Dg{jT` zVk!-ttSlkKj0+h2)l`i+bh6+sB*rHhRlj+%4COk@b1s5#kvOp?3PfJ?J;Lm_o0{=p zHT;&)nYR&;qFfWAIk9B0{Ca6%Ed8oB#kXx zmf=N&jpOmMh1121jYQOV8J`lsVYo)W1-wCfO-+A1d@p4J_&LmZ;d^F?jHU;`Pxi?R z_XS^WjxC(efy7QzoqJ@m%u0zq$U!9@Jz#tnHKuHo*WbY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