using System.Threading.Tasks;\r
using Tizen;\r
using Tizen.Network.WiFi;\r
+using Tizen.Network.Connection;\r
using SettingWiFi.res.locale;\r
using static SettingWiFi.Logger;\r
+using System.Net;\r
\r
namespace SettingWiFi\r
{\r
\r
//bool isPassphraseRequired = item.SecurityInformation.IsPassphraseRequired;\r
\r
- var securityType = item.SecurityInformation.SecurityType;\r
- bool isWpsSupported = item.SecurityInformation.IsWpsSupported;\r
+ var ap = CreateAp(item);\r
\r
+ Debug("AP Info. IPv4[" + ap.IPv4 + "] IPv6[" + ap.IPv6 + "] Mac[" + ap.Bssid + "] "\r
+ + "ProxyAddress[" + ap.ProxyAddress + "] ProxyPort[" + ap.ProxyPort + "]");\r
\r
- WiFiState state = convertWiFiState(item.NetworkInformation.ConnectionState);\r
+ apInfoList.Add(ap);\r
+ }\r
\r
- var networkInfo = item.NetworkInformation;\r
- var ap = new AP(item, networkInfo.Essid,\r
- state, securityType, isWpsSupported,\r
- networkInfo.Bssid, networkInfo.RssiLevel);\r
+ return apInfoList;\r
+ }\r
\r
- ap.IPv4 = networkInfo.IPv4Setting.IP.ToString();\r
- ap.IPv6 = networkInfo.IPv6Setting.IP.ToString();\r
- var proxy = networkInfo.ProxyAddress;\r
- if (proxy.Contains(':'))\r
+ private AP CreateAp(WiFiAP wifiAp)\r
+ {\r
+ var securityType = wifiAp.SecurityInformation.SecurityType;\r
+ bool isWpsSupported = wifiAp.SecurityInformation.IsWpsSupported;\r
+ WiFiState state = convertWiFiState(wifiAp.NetworkInformation.ConnectionState);\r
+ var networkInfo = wifiAp.NetworkInformation;\r
+\r
+ var ap = new AP(wifiAp, networkInfo.Essid,\r
+ state, securityType, isWpsSupported,\r
+ networkInfo.Bssid, networkInfo.RssiLevel);\r
+\r
+ ap.IPv4 = networkInfo.IPv4Setting.IP.ToString();\r
+ ap.IPv6 = networkInfo.IPv6Setting.IP.ToString();\r
+ var proxy = networkInfo.ProxyAddress;\r
+ if (proxy.Contains(':'))\r
+ {\r
+ var result = proxy.Split(":");\r
+ ap.ProxyAddress = result[0];\r
+ int port = 0;\r
+ if (Int32.TryParse(result[1], out port))\r
{\r
- var result = proxy.Split(":");\r
- ap.ProxyAddress = result[0];\r
- int port = 0;\r
- if (Int32.TryParse(result[1], out port))\r
- {\r
- ap.ProxyPort = port;\r
- }\r
- else\r
- {\r
- ap.ProxyPort = -1;\r
- }\r
+ ap.ProxyPort = port;\r
}\r
+ else\r
+ {\r
+ ap.ProxyPort = -1;\r
+ }\r
+ }\r
\r
- Debug("AP Info. IPv4[" + ap.IPv4 + "] IPv6[" + ap.IPv6 + "] Mac[" + ap.Bssid + "] "\r
- + "ProxyAddress[" + ap.ProxyAddress + "] ProxyPort[" + ap.ProxyPort + "]");\r
+ ap.StaticIPConfig = (networkInfo.IPv4Setting.IPConfigType == IPConfigType.Static);\r
\r
- apInfoList.Add(ap);\r
- }\r
+ return ap;\r
+ }\r
\r
- return apInfoList;\r
+ public void UpdateApInfo(AP ap)\r
+ {\r
+ ap.ApHandle.Update();\r
}\r
\r
public List<AP> GetSpecificAPList()\r
\r
return wpsPin;\r
}\r
+\r
+ public void UpateIpConfigMethod(AP ap, bool isStaticIpConfig)\r
+ {\r
+ if (isStaticIpConfig)\r
+ {\r
+ ap.ApHandle.NetworkInformation.IPv4Setting.IPConfigType = IPConfigType.Static;\r
+ ap.ApHandle.NetworkInformation.IPv6Setting.IPConfigType = IPConfigType.Static;\r
+ }\r
+ else\r
+ {\r
+ ap.ApHandle.NetworkInformation.IPv4Setting.IPConfigType = IPConfigType.Dynamic;\r
+ ap.ApHandle.NetworkInformation.IPv6Setting.IPConfigType = IPConfigType.Dynamic;\r
+ }\r
+ }\r
+\r
+ public bool UpdateIPAddress(AP ap, string ip)\r
+ {\r
+ IPAddress ipAddress;\r
+ if (IPAddress.TryParse(ip, out ipAddress) == false)\r
+ {\r
+ Error("IP address parsing error");\r
+ return false;\r
+ }\r
+\r
+ ap.ApHandle.NetworkInformation.IPv4Setting.IP = ipAddress;\r
+ return true;\r
+ }\r
+\r
+ public bool UpdateSubnetMask(AP ap, string mask)\r
+ {\r
+ IPAddress ipAddress;\r
+ if (IPAddress.TryParse(mask, out ipAddress) == false)\r
+ {\r
+ Error("IP address parsing error");\r
+ return false;\r
+ }\r
+\r
+ ap.ApHandle.NetworkInformation.IPv4Setting.SubnetMask = ipAddress;\r
+ return true;\r
+ }\r
+\r
+ public bool UpdateGatewayAddress(AP ap, string address)\r
+ {\r
+ IPAddress ipAddress;\r
+ if (IPAddress.TryParse(address, out ipAddress) == false)\r
+ {\r
+ Error("IP address parsing error");\r
+ return false;\r
+ }\r
+\r
+ ap.ApHandle.NetworkInformation.IPv4Setting.Gateway = ipAddress;\r
+ return true;\r
+ }\r
+\r
+ public bool UpdateDns1(AP ap, string address)\r
+ {\r
+ IPAddress ipAddress;\r
+ if (IPAddress.TryParse(address, out ipAddress) == false)\r
+ {\r
+ Error("IP address parsing error");\r
+ return false;\r
+ }\r
+\r
+ ap.ApHandle.NetworkInformation.IPv4Setting.Dns1 = ipAddress;\r
+ return true;\r
+ }\r
+\r
+ public bool UpdateDns2(AP ap, string address)\r
+ {\r
+ IPAddress ipAddress;\r
+ if (IPAddress.TryParse(address, out ipAddress) == false)\r
+ {\r
+ Error("IP address parsing error");\r
+ return false;\r
+ }\r
+\r
+ ap.ApHandle.NetworkInformation.IPv4Setting.Dns2 = ipAddress;\r
+ return true;\r
+ }\r
+\r
+ public bool UpdateProxy(AP ap, string proxy)\r
+ {\r
+ ap.ApHandle.NetworkInformation.ProxyAddress = proxy;\r
+ return true;\r
+ }\r
}\r
\r
internal class WiFiStateChangedEventArgs\r
get;\r
set;\r
}\r
+\r
+ public bool StaticIPConfig\r
+ {\r
+ get;\r
+ set;\r
+ }\r
+\r
+ public string SubnetMask\r
+ {\r
+ get;\r
+ set;\r
+ }\r
+\r
+ public string GatewayAddress\r
+ {\r
+ get;\r
+ set;\r
+ }\r
+\r
+ public string Dns1\r
+ {\r
+ get;\r
+ set;\r
+ }\r
+\r
+ public string Dns2\r
+ {\r
+ get;\r
+ set;\r
+ }\r
};\r
}\r
+using System;
+using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
+using SettingWiFi.res.locale;
using static SettingWiFi.Logger;
namespace SettingWiFi
{
public class ApInfoSource : ObservableCollection<ApInfoText>
{
- public ApInfoSource()
+ private WiFi mWifi;
+ private AP mAp;
+
+ private string mProxyAddress = "";
+
+ public ApInfoSource(WiFi wifi, AP ap)
{
+ mWifi = wifi;
+ mAp = ap;
}
- internal void initialize(string ipv4, string ipv6, string bssid, string proxy, int proxyPort)
+ internal void ShowInfo(bool isStaticIpConfig, bool isConfigChanged)
{
- this.Add(new ApInfoText("IPv4", ipv4));
- if (ipv6?.Length > 0)
+ if (isStaticIpConfig)
+ {
+ ShowStaticInfo(isConfigChanged);
+ }
+ else
+ {
+ ShowDynamicInfo(isConfigChanged);
+ }
+ }
+
+ private void ShowDynamicInfo(bool isConfigChanged)
+ {
+ Add(new ApInfoText(Resources.IDS_ST_BODY_IPV4, mAp.IPv4, null));
+ if (mAp.IPv6?.Length > 0)
+ {
+ Add(new ApInfoText(Resources.IDS_ST_BODY_IPV6, mAp.IPv6, null));
+ }
+ Add(new ApInfoText(Resources.IDS_WIFI_BODY_MAC_ADDRESS, mAp.Bssid, null));
+ if (mAp.ProxyAddress?.Length > 0)
{
- this.Add(new ApInfoText("IPv6", ipv6));
+ Add(new ApInfoText(Resources.IDS_ST_SBODY_PROXY_ADDRESS, mAp.ProxyAddress, null));
}
- this.Add(new ApInfoText("MAC address", bssid));
- if (proxy?.Length > 0)
+ if (mAp.ProxyPort >= 0)
{
- this.Add(new ApInfoText("Proxy address", proxy));
+ Add(new ApInfoText(Resources.IDS_ST_SBODY_PROXY_PORT, "" + mAp.ProxyPort, null));
}
- if (proxyPort >= 0)
+ }
+
+ private void ShowStaticInfo(bool isConfigChanged)
+ {
+ if (isConfigChanged)
+ {
+ mAp.IPv4 = "";
+ mAp.SubnetMask = "";
+ mAp.GatewayAddress = "";
+ mAp.Dns1 = "";
+ mAp.Dns2 = "";
+ mAp.ProxyAddress = "";
+ mAp.ProxyPort = 0;
+ }
+
+ Add(new ApInfoText(Resources.IDS_WIFI_BODY_IP_ADDRESS, mAp.IPv4, UpdateIPAddress));
+ Add(new ApInfoText(Resources.IDS_WIFI_BODY_SUBNET_MASK, mAp.SubnetMask, UpdateSubnetMask));
+ Add(new ApInfoText(Resources.IDS_WIFI_BODY_GATEWAY_ADDRESS, mAp.GatewayAddress, UpdateGatewayAddress));
+ Add(new ApInfoText(Resources.IDS_WIFI_BODY_DNS_1, mAp.Dns1, UpdateDns1));
+ Add(new ApInfoText(Resources.IDS_WIFI_BODY_DNS_2, mAp.Dns2, UpdateDns2));
+ Add(new ApInfoText(Resources.IDS_WIFI_BODY_MAC_ADDRESS, mAp.Bssid, null));
+ Add(new ApInfoText(Resources.IDS_ST_SBODY_PROXY_ADDRESS, mAp.ProxyAddress, UpdateProxyAddress));
+ Add(new ApInfoText(Resources.IDS_ST_SBODY_PROXY_PORT, "" + mAp.ProxyPort, UpdateProxyPort));
+ }
+
+ internal IList<ApInfoText> GetItemList()
+ {
+ return this.Items;
+ }
+
+ public bool UpdateIPAddress(string ip)
+ {
+ return mWifi.UpdateIPAddress(mAp, ip);
+ }
+
+ public bool UpdateSubnetMask(string mask)
+ {
+ return mWifi.UpdateSubnetMask(mAp, mask);
+ }
+
+ public bool UpdateGatewayAddress(string address)
+ {
+ return mWifi.UpdateGatewayAddress(mAp, address);
+ }
+
+ public bool UpdateDns1(string address)
+ {
+ return mWifi.UpdateDns1(mAp, address);
+ }
+
+ public bool UpdateDns2(string address)
+ {
+ return mWifi.UpdateDns2(mAp, address);
+ }
+
+ public bool UpdateProxyAddress(string address)
+ {
+ mProxyAddress = address;
+ return true;
+ }
+
+ public bool UpdateProxyPort(string port)
+ {
+ int portNum;
+ if (Int32.TryParse(port, out portNum) == false)
{
- this.Add(new ApInfoText("Proxy port", "" + proxyPort));
+ Error("port parsing error");
+ return false;
}
+ mProxyAddress += ":" + port;
+ return UpdateProxyAddress(mProxyAddress);
}
}
public class ApInfoText : INotifyPropertyChanged
{
- private string infoTitle;
- private string infoValue;
+ private string mInfoTitle;
+ private string mInfoValue;
+ public Predicate<string> mUpdater;
public event PropertyChangedEventHandler PropertyChanged;
- public ApInfoText(string title, string value)
+
+ public ApInfoText(string title, string value, Predicate<string> updater)
{
InfoTitle = title;
InfoValue = value;
+ mUpdater = updater;
}
private void OnPropertyChanged(string propertyName)
{
get
{
- return infoTitle;
+ return mInfoTitle;
}
set
{
- infoTitle = value;
+ mInfoTitle = value;
OnPropertyChanged("InfoTitle");
}
}
{
get
{
- return infoValue;
+ return mInfoValue;
}
set
{
- infoValue = value;
+ mInfoValue = value;
OnPropertyChanged("InfoValue");
}
}
{
internal class InfoPage : ContentPage
{
+ Switch mOnOffSwitch;
+ CollectionView mApInfoListView;
+
private AP mAp;
private WiFi mWifi;
ApInfoSource mApInfoSource;
+ bool mIsOriginOnOffSwitchSelected;
+
internal InfoPage(WiFi wifi)
{
mWifi = wifi;
HeightSpecification = LayoutParamPolicies.MatchParent,
};
- mApInfoSource = new ApInfoSource();
- mApInfoSource.initialize(ap.IPv4, ap.IPv6, ap.Bssid, ap.ProxyAddress, ap.ProxyPort);
+ mApInfoSource = new ApInfoSource(mWifi, mAp);
- CollectionView apInfoListView = new CollectionView()
+ mApInfoListView = new CollectionView()
{
ItemsSource = mApInfoSource,
ItemsLayouter = new LinearLayouter(),
ScrollingDirection = ScrollableBase.Direction.Vertical,
WidthSpecification = LayoutParamPolicies.MatchParent,
HeightSpecification = LayoutParamPolicies.MatchParent,
- SelectionMode = ItemSelectionMode.Single,
+ SelectionMode = mAp.StaticIPConfig ? ItemSelectionMode.Single : ItemSelectionMode.None,
};
- apInfoListView.SelectionChanged += OnInfoListViewSelected;
+ if (mAp.StaticIPConfig)
+ {
+ mApInfoListView.SelectionChanged += OnInfoListViewSelected;
+ }
var header = GetHeader();
forgetButton.Clicked += OnForgetClicked;
infoView.Add(header);
- infoView.Add(apInfoListView);
+ infoView.Add(mApInfoListView);
infoView.Add(forgetButton);
AppBar = appBar;
Content = infoView;
+
+ mApInfoSource.ShowInfo(mOnOffSwitch.IsSelected, false);
}
private void OnInfoListViewSelected(object sender, SelectionChangedEventArgs e)
};
toggle.Label.HorizontalAlignment = HorizontalAlignment.Begin;
- var onOffSwitch = new Switch()
+ mIsOriginOnOffSwitchSelected = mAp.StaticIPConfig;
+ mOnOffSwitch = new Switch()
{
- IsSelected = false,
+ IsSelected = mAp.StaticIPConfig,
};
+ mOnOffSwitch.SelectedChanged += OnSwitchClicked;
- toggle.Extra = onOffSwitch;
+ toggle.Extra = mOnOffSwitch;
header.Add(toggle);
return header;
}
+ private void OnSwitchClicked(object sender, SelectedChangedEventArgs e)
+ {
+ if (e.IsSelected)
+ {
+ mApInfoListView.SelectionMode = ItemSelectionMode.Single;
+ mApInfoListView.SelectionChanged += OnInfoListViewSelected;
+ }
+ else
+ {
+ mApInfoListView.SelectionMode = ItemSelectionMode.None;
+ mApInfoListView.SelectionChanged -= OnInfoListViewSelected;
+ }
+
+ mApInfoSource.Clear();
+ mApInfoSource.ShowInfo(e.IsSelected, true);
+
+
+ }
+
private ContentPage CreateForgetPage()
{
var forgetView = new View()
private void OnBackClicked(object source, ClickedEventArgs args)
{
+ if (mIsOriginOnOffSwitchSelected != mOnOffSwitch.IsSelected)
+ {
+ UpdateApInfo(mOnOffSwitch.IsSelected);
+ }
Navigator.Pop();
}
+ private void UpdateApInfo(bool isStaticIpConfig)
+ {
+ mWifi.UpateIpConfigMethod(mAp, isStaticIpConfig);
+ if (isStaticIpConfig)
+ {
+ GetStaticIpInfo();
+ }
+ mWifi.UpdateApInfo(mAp);
+ }
+
+ private void GetStaticIpInfo()
+ {
+ Debug("GetStaticIpInfo from mApInfoSource");
+ var list = mApInfoSource.GetItemList();
+ foreach (var info in list)
+ {
+ if (info.mUpdater != null)
+ info.mUpdater(info.InfoValue);
+ }
+ }
+
private void OnForgetClicked(object source, ClickedEventArgs args)
{
Debug("Forget " + mAp.Essid);