{
private WiFiDirect mWifiDirect;
private PeerSource mPeerSource;
+ private CollectionView mScanList;
public override string ProvideTitle() => Resources.IDS_WIFI_BODY_WI_FI_DIRECT_ABB;
protected override void OnCustomizationUpdate(IEnumerable<MenuCustomizationItem> items)
}
Resources.SetPath(GetResourcePath(""));
+ StartScan();
}
protected override View OnCreate()
{
+ Debug("+");
base.OnCreate();
- try
- {
- List<Peer> peerList = mWifiDirect.GetScanResult();
- mPeerSource.AddFoundPeers(peerList);
- }
- catch (Exception e)
- {
- Debug("Exception " + e.Message);
- }
return CreateComponents();
}
internal View CreateComponents()
{
- Debug("CreateComponents");
+ Debug("+");
View mainView = new View()
{
Layout = new LinearLayout()
var header = GetHeader();
- var mScanList = new CollectionView()
+ mScanList = new CollectionView()
{
ItemsSource = mPeerSource,
ItemsLayouter = new LinearLayouter(),
HeightSpecification = LayoutParamPolicies.MatchParent,
SelectionMode = ItemSelectionMode.Single,
};
+ mWifiDirect.WFDStateChanged += OnWFDStateChanged;
+
+ mScanList.Relayout += (s, e) =>
+ {
+ foreach (var child in mScanList.Children)
+ {
+ child.SizeWidth = mScanList.SizeWidth;
+ }
+ };
+
mainView.Add(header);
mainView.Add(mScanList);
return mainView;
}
+ private void OnWFDStateChanged(Object sender, WFDStateChangedEventArgs e)
+ {
+ Debug("+");
+ UpdateDeviceList();
+ }
private Selector<Color> GetDefaultColorSelector()
{
return icon;
}
-
private DataTemplate CreateItemTemplate()
{
+ Debug("+");
return new DataTemplate(() =>
{
DefaultLinearItem item = new DefaultLinearItem()
//item.Icon = GetApIconImageView();
//item.Extra = GetInfoButton();
item.IsSelectable = false;
-
+ item.SizeWidth = mScanList.SizeWidth;
return item;
});
}
+ private void StartScan()
+ {
+ Debug("+");
+ mWifiDirect.StartDiscovery();
+ Debug("-");
+ }
+
+ private void UpdateDeviceList()
+ {
+ Debug("+");
+ try
+ {
+ List<Peer> peerList = mWifiDirect.GetScanResult();
+ mPeerSource.AddFoundPeers(peerList);
+ }
+ catch (Exception e)
+ {
+ Debug("Exception " + e.Message);
+ }
+ }
+
private TextLabel GetHeader()
{
+ Debug("+");
string label = string.Format(Resources.IDS_WIFI_BODY_YOUR_DEVICE_HPS_IS_CURRENTLY_VISIBLE_TO_NEARBY_DEVICES, mWifiDirect.getDeviceName());
TextLabel header = new TextLabel(label);
{
// Following values are tentative, may be changed later.
internal const string PeerDeviceName = "TizenRPI4_WFD";
- internal const int DiscoveryTime = 30;
+ internal const int DiscoveryTime = 10;
internal const int DelayTime = 2000;
internal const int DiscoverDelayTime = 1000;
internal const int StartDiscoveryDelayTime = 10000;
using System;
using System.Collections.Generic;
-using System.Text;
using System.Threading.Tasks;
using Tizen.Network.WiFiDirect;
using static SettingWiFiDirect.Logger;
{
IEnumerable<WiFiDirectPeer> mFoundDeviceList = new List<WiFiDirectPeer>();
IEnumerable<WiFiDirectPeer> mConnectedDeviceList = new List<WiFiDirectPeer>();
- // IEnumerable<WiFiDirectPeer> specificAPList = new List<WiFiDirectPeer>();
+ private event EventHandler<WFDStateChangedEventArgs> mWifiDirectStateChanged = null;
bool _isInitialized = false;
+
internal void Initialize()
{
if (WiFiDirectManager.IsInitialized)
_isInitialized = true;
}
}
+
public async Task Activate()
{
}
catch (Exception e)
{
- Debug("Fail to activate WiFi Direct " + e.ToString());
+ Debug("Fail to activate WiFi-Direct " + e.ToString());
}
}
WiFiDirectManager.Deactivate();
}
+ internal event EventHandler<WFDStateChangedEventArgs> WFDStateChanged
+ {
+ add
+ {
+ if (mWifiDirectStateChanged == null)
+ {
+ WiFiDirectManager.StateChanged += OnWiFiDirectStateChanged;
+ }
+ mWifiDirectStateChanged += value;
+ }
+ remove
+ {
+ mWifiDirectStateChanged -= value;
+ if (mWifiDirectStateChanged == null)
+ {
+ WiFiDirectManager.StateChanged -= OnWiFiDirectStateChanged;
+ }
+ }
+ }
+
+ private void OnWiFiDirectStateChanged(Object sender, StateChangedEventArgs e)
+ {
+ Debug("+");
+ WFDState state = ConvertWFDState(e.State);
+ mWifiDirectStateChanged.Invoke(null, new WFDStateChangedEventArgs(state));
+ }
+
+ private WFDState ConvertWFDState(WiFiDirectState state)
+ {
+ //TODO: update logic based on state
+ return WFDState.Activated;
+ }
+
public void StartDiscovery()
{
+ Debug("+");
WiFiDirectManager.StartDiscovery(false, WifiDirectConfig.DiscoveryTime);
}
+
public bool IsDiscoverable()
{
- Debug("WiFiDiect.IsDiscoverable");
+ Debug("+");
if (WiFiDirectManager.IsDiscoverable)
{
return true;
public List<Peer> GetScanResult()
{
- Debug("WiFi.GetScanResult");
+ Debug("+");
try
{
mFoundDeviceList = WiFiDirectManager.GetDiscoveredPeers();
return null;
}
+
public List<Peer> GetPeerList()
{
- Debug("WiFi.GetAPList");
+ Debug("+");
List<Peer> peerList = new List<Peer>();
foreach (var item in mFoundDeviceList)
{
private Peer CreatePeer(WiFiDirectPeer wifiDirectPeer)
{
- Debug("CreatePeer");
+ Debug("+");
Peer peer = new Peer(wifiDirectPeer);
return peer;
}
}
}
+
+ internal class WFDStateChangedEventArgs
+ {
+ internal WFDStateChangedEventArgs(WFDState state)
+ {
+ State = state;
+ }
+
+ internal WFDState State
+ {
+ get;
+ set;
+ }
+ }
}
using System;
using System.ComponentModel;
-using System.Collections.Generic;
-using System.Text;
using Tizen.Network.WiFiDirect;
using static SettingWiFiDirect.Logger;
public Peer(WiFiDirectPeer peer)
{
mWfdPeer = peer;
- mPeerName = peer.Name;
- mAddress = peer.MacAddress;
+ Name = peer.Name;
+ Address = peer.MacAddress;
mRssi = peer.Rssi;
}
+
private void OnPropertyChanged(string propertyName)
{
Debug("OnPropertyChanged " + propertyName);
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
- internal string Name
+ public string Name
{
get
{
return mPeerName;
}
+ set
+ {
+ mPeerName = value;
+ OnPropertyChanged("Name");
+ }
}
- internal string Address
+ public string Address
{
get
{
return mAddress;
}
+ set
+ {
+ mAddress = value;
+ OnPropertyChanged("Address"); //TODO: to be revisited
+ }
}
- internal int Rssi
+
+ public int Rssi
{
get
{
{
// TODO
}
+
+ public enum WFDState
+ {
+ //TODO :add more states if needed
+ Deactivated = 0,
+ Activated = 1,
+ Discovering = 2,
+ Connected = 3
+ }
}
public PeerSource()
{
+ Debug("+");
mAvailable = new DeviceCollection(Resources.IDS_WIFI_HEADER_AVAILABLE_DEVICES_ABB);
- // mPaired = new DeviceCollection("Paired devices");
this.Add(mAvailable);
}