{
internal static class AdapterController
{
- static bool deviceViewInit = false;
- static DeviceSource deviceSource;
-
- internal static void BtModelDiscoveryStateChanged(object obj, BtModelDiscoveryStateChangedEventArgs ev)
+ internal static void OnOffSwitchSelectedChanged(object obj, SelectedChangedEventArgs ev)
{
- if (ev.DiscoveryState == BtModelDiscoveryState.Started)
+ Log.Debug(Program.LogTag, "OnOffSwitchSelectedChanged. IsSelected: " + ev.IsSelected + ", isEnabled: " + BtModel.IsEnabled);
+ if (ev.IsSelected == true && BtModel.IsEnabled == false)
{
- Log.Debug(Program.LogTag, "Device discovery started");
+ Log.Info(Program.LogTag, "Enable BT");
+ BtModel.Enable();
}
- else if (ev.DiscoveryState == BtModelDiscoveryState.Found)
+ else if (ev.IsSelected == false && BtModel.IsEnabled == true)
{
- if (deviceViewInit == false)
- {
- deviceSource = new DeviceSource();
- BtMainView.AddDeviceView(deviceSource);
- BtMainView.AddScanButton();
- deviceViewInit = true;
- }
-
- Log.Debug(Program.LogTag, "Device found. Address: " + ev.DiscoveredDevice.RemoteDeviceAddress);
- deviceSource.AddDevice(ev.DiscoveredDevice.RemoteDeviceAddress);
+ Log.Info(Program.LogTag, "Disable BT");
+ BtModel.Disable();
}
else
{
- Log.Debug(Program.LogTag, "Device discovery finished");
- deviceSource.UpdateTitle(Resources.IDS_BT_BODY_AVAILABLE_DEVICES);
- BtMainView.UpdateScanButton(Resources.IDS_BT_SK_SCAN);
+ Log.Error(Program.LogTag, "Invalid state");
}
}
- internal static void BtModelStateChanged(object obj, BtModelStateChangedEventArgs ev)
+ internal static void ScanButtonClicked(object obj, ClickedEventArgs ev)
{
- if (ev.IsEnabled)
- {
- Log.Debug(Program.LogTag, "BT enabled. Start discovery");
- BtModel.DiscoveryStateChanged += BtModelDiscoveryStateChanged;
- BtModel.StartDiscovery();
- }
- else
- {
- Log.Debug(Program.LogTag, "BT disabled");
- BtMainView.RemoveDeviceView();
- BtMainView.RemoveScanButton();
- }
- }
+ Log.Debug(Program.LogTag, "OnOffSwitchSelectedChanged. IsScanning: " + BtModel.IsScanning);
- internal static void OnOffSwitchSelectedChanged(object obj, SelectedChangedEventArgs ev)
- {
- Log.Debug(Program.LogTag, "btOnOffSwitch clicked. IsSelected: " + ev.IsSelected + ", isEnabled: " + BtModel.IsEnabled);
- if (ev.IsSelected == true && BtModel.IsEnabled == false)
- {
- Log.Info(Program.LogTag, "Enable BT");
- BtModel.StateChanged += BtModelStateChanged;
- BtModel.Enable();
- }
- else if (ev.IsSelected == false && BtModel.IsEnabled == true)
+ if (BtModel.IsScanning)
{
- Log.Info(Program.LogTag, "Disable BT");
- BtModel.Disable();
+ Log.Info(Program.LogTag, "Stop discovery");
+ BtModel.StopDiscovery();
}
else
{
- Log.Error(Program.LogTag, "Invalid state");
+ Log.Info(Program.LogTag, "Start discovery");
+ BtModel.StartDiscovery();
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
+using Tizen.NUI.Components;
+using Tizen;
namespace SettingBluetooth.Controller
{
- class DeviceController
+ internal static class DeviceController
{
+ internal static void DeviceViewSelectionChanged(object obj, SelectionChangedEventArgs ev)
+ {
+ Log.Debug(Program.LogTag, "DeviceViewSelectionChanged");
+
+ //SingleSelection Only have 1 or nil object in the list.
+ foreach (object item in ev.PreviousSelection)
+ {
+ if (item == null) break;
+ if (item is Device device)
+ {
+ device.Connected = false;
+ }
+ }
+ foreach (object item in ev.CurrentSelection)
+ {
+ if (item == null) break;
+ if (item is Device device)
+ {
+ Log.Debug(Program.LogTag, "Name: " + device.Name);
+ device.Connected = true;
+ //device.btDevice.Pair();
+ device.Registered = true;
+ }
+ }
+ }
}
}
--- /dev/null
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace SettingBluetooth.Model
+{
+ public class BtDevice
+ {
+ internal string RemoteDeviceAddress;
+ internal BtDeviceState DeviceState;
+ // TODO
+
+ internal BtDevice(string address) // TODO
+ {
+ RemoteDeviceAddress = address;
+ }
+
+ internal static void Pair()
+ {
+ // TODO
+ // 1. Call CreateBond API
+ // 2. Set BT Operation state as Pairing
+ // 3. Set Device state as Pairing
+ // 4. Bonding Created
+ // --> Remove device into searched list
+ // --> Add device into paired list
+ // --> Invoke Remove Searched Device event to View
+ // --> Invoke New Paired Device event to View
+ // 5. Set BT Operation state as Activated
+ }
+
+ internal static void Unpair()
+ {
+ // TODO
+ // 1. Call DestroyBond API
+ // 2. Set BT Operation state as Pairing
+ // 3. Set Device state as Unpairing
+ // 4. Bonding Destroyed
+ // --> Remove device into paired list
+ // --> Invoke Remove Paired Device event to View
+ // 5. Set BT Operation state as Activated
+ }
+
+ internal static void ConnectAudio()
+ {
+ // TODO
+ // 1. Call Connect API (Audio)
+ // 2. Set BT Operation state as Connecting
+ // 3. Set Device state as Connecting
+ // 4. Audio Connection Callback
+ // --> Update Device State (Success -> Connected, Fail -> Paired)
+ // --> Update Device Connected info (Connected Profile info - HFP / A2DP)
+ // 5. Set BT Operation state as Activated
+ }
+
+ internal static void DisConnectAudio()
+ {
+ // TODO
+ // 1. Call Disconnect API (Audio)
+ // 2. Set BT Operation state as Connecting
+ // 3. Set Device state as Disonnecting
+ // 4. Audio Disconnection Callback
+ // --> Update Device State (Success -> Paired, Fail -> Connected)
+ // --> Update Device Connected info (Connected Profile info - HFP / A2DP)
+ // 5. Set BT Operation state as Activated
+ }
+
+ internal static void ConnectHid()
+ {
+ // TODO (Same with audio)
+ }
+
+ internal static void DisConnectHid()
+ {
+ // TODO (Same with audio)
+ }
+ }
+}
--- /dev/null
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace SettingBluetooth.Model
+{
+ public enum BtOperationState
+ {
+ Deactivated,
+ Deactivating,
+ Activated,
+ Activating,
+ Searching,
+ Searched,
+ Pairing,
+ Connecting,
+ }
+
+ public enum BtDeviceState
+ {
+ Idle,
+ Pairing,
+ Unpairing,
+ Paired,
+ Connecting,
+ Connected,
+ Disconnecting,
+ ServiceSearching,
+ }
+}
--- /dev/null
+using System;
+using System.Collections.Generic;
+using System.Text;
+using Tizen.Network.Bluetooth;
+using Tizen;
+
+namespace SettingBluetooth.Model
+{
+ internal class BtOperationStateChangedEventArgs : EventArgs
+ {
+ internal BtOperationState OperationState;
+
+ internal BtOperationStateChangedEventArgs(BtOperationState state)
+ {
+ OperationState = state;
+ }
+ }
+
+ internal class BtDeviceChangedEventArgs : EventArgs
+ {
+ internal BtDevice btDevice;
+
+ internal BtDeviceChangedEventArgs(BtDevice device)
+ {
+ btDevice = device;
+ }
+ }
+}
}
}
+ internal static bool IsScanning
+ {
+ get
+ {
+ return BtModelImpl.Instance.IsScanning;
+ }
+ }
+
internal static void Enable()
{
BtModelImpl.Instance.Enable();
{
BtModelImpl.Instance.StartDiscovery();
}
+ internal static void StopDiscovery()
+ {
+ BtModelImpl.Instance.StopDiscovery();
+ }
- internal static event EventHandler<BtModelStateChangedEventArgs> StateChanged
+ internal static event EventHandler<BtOperationStateChangedEventArgs> OperationStateChanged
{
add
{
- BtModelImpl.Instance.StateChanged += value;
+ BtModelImpl.Instance.OperationStateChanged += value;
}
remove
{
- BtModelImpl.Instance.StateChanged -= value;
+ BtModelImpl.Instance.OperationStateChanged -= value;
}
}
- internal static event EventHandler<BtModelDiscoveryStateChangedEventArgs> DiscoveryStateChanged
+ internal static event EventHandler<BtDeviceChangedEventArgs> DeviceChanged
{
add
{
- BtModelImpl.Instance.DiscoveryStateChanged += value;
+ BtModelImpl.Instance.DeviceChanged += value;
}
remove
{
- BtModelImpl.Instance.DiscoveryStateChanged -= value;
+ BtModelImpl.Instance.DeviceChanged -= value;
}
}
}
+++ /dev/null
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace SettingBluetooth.Model
-{
- public class BtModelDevice
- {
- internal string RemoteDeviceAddress;
- // TODO
-
- internal BtModelDevice(string address) // TODO
- {
- RemoteDeviceAddress = address;
- }
-
- internal static void Pair()
- {
- // TODO
- // 1. Call CreateBond API
- // 2. Set BT Operation state as Pairing
- // 3. Set Device state as Pairing
- // 4. Bonding Created
- // --> Remove device into searched list
- // --> Add device into paired list
- // --> Invoke Remove Searched Device event to View
- // --> Invoke New Paired Device event to View
- // 5. Set BT Operation state as Activated
- }
-
- internal static void Unpair()
- {
- // TODO
- // 1. Call DestroyBond API
- // 2. Set BT Operation state as Pairing
- // 3. Set Device state as Unpairing
- // 4. Bonding Destroyed
- // --> Remove device into paired list
- // --> Invoke Remove Paired Device event to View
- // 5. Set BT Operation state as Activated
- }
-
- internal static void ConnectAudio()
- {
- // TODO
- // 1. Call Connect API (Audio)
- // 2. Set BT Operation state as Connecting
- // 3. Set Device state as Connecting
- // 4. Audio Connection Callback
- // --> Update Device State (Success -> Connected, Fail -> Paired)
- // --> Update Device Connected info (Connected Profile info - HFP / A2DP)
- // 5. Set BT Operation state as Activated
- }
-
- internal static void DisConnectAudio()
- {
- // TODO
- // 1. Call Disconnect API (Audio)
- // 2. Set BT Operation state as Connecting
- // 3. Set Device state as Disonnecting
- // 4. Audio Disconnection Callback
- // --> Update Device State (Success -> Paired, Fail -> Connected)
- // --> Update Device Connected info (Connected Profile info - HFP / A2DP)
- // 5. Set BT Operation state as Activated
- }
-
- internal static void ConnectHid()
- {
- // TODO (Same with audio)
- }
-
- internal static void DisConnectHid()
- {
- // TODO (Same with audio)
- }
- }
-}
+++ /dev/null
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace SettingBluetooth.Model
-{
- /* Removable - We can use BtOperationState and BtDeviceState */
- public enum BtModelDiscoveryState
- {
- Started,
- Finished,
- Found
- }
-
- public enum BtOperationState
- {
- Deactivated,
- Deactivating,
- Activated,
- Activating,
- Searching,
- Pairing,
- Connecting,
- }
-
- public enum BtDeviceState
- {
- Idle,
- Pairing,
- Unpairing,
- Paired,
- Connecting,
- Connected,
- Disconnecting,
- ServiceSearching,
- }
-}
+++ /dev/null
-using System;
-using System.Collections.Generic;
-using System.Text;
-using Tizen.Network.Bluetooth;
-using Tizen;
-
-namespace SettingBluetooth.Model
-{
- internal class BtModelStateChangedEventArgs : EventArgs
- {
- internal bool IsEnabled;
-
- internal BtModelStateChangedEventArgs(StateChangedEventArgs args)
- {
- IsEnabled = args.BTState == BluetoothState.Enabled;
- }
- }
-
- internal class BtModelDiscoveryStateChangedEventArgs : EventArgs
- {
- internal BtModelDiscoveryState DiscoveryState;
- internal BtModelDevice DiscoveredDevice;
-
- internal BtModelDiscoveryStateChangedEventArgs(BluetoothDeviceDiscoveryState state)
- {
- DiscoveryState = (BtModelDiscoveryState)state;
- }
- }
-}
internal class BtModelImpl
{
static readonly BtModelImpl instance = new BtModelImpl();
- static event EventHandler<BtModelStateChangedEventArgs> stateChanged = null;
- static event EventHandler<BtModelDiscoveryStateChangedEventArgs> discoveryStateChanged = null;
+ static bool isScanning = false;
+ static event EventHandler<BtOperationStateChangedEventArgs> operationStateChanged = null;
+ static event EventHandler<BtDeviceChangedEventArgs> deviceChanged = null;
internal bool IsEnabled
{
}
}
+ internal bool IsScanning
+ {
+ get
+ {
+ return isScanning;
+ }
+ }
+
internal void Enable()
{
BluetoothAdapter.Enable();
+ operationStateChanged?.Invoke(null, new BtOperationStateChangedEventArgs(BtOperationState.Activating));
}
internal void Disable()
{
BluetoothAdapter.Disable();
+ operationStateChanged?.Invoke(null, new BtOperationStateChangedEventArgs(BtOperationState.Deactivating));
}
internal void StartDiscovery()
{
BluetoothAdapter.StartDiscovery();
+ isScanning = true;
+ operationStateChanged?.Invoke(null, new BtOperationStateChangedEventArgs(BtOperationState.Searching));
}
- private static void AdapterStateChanged(object obj, StateChangedEventArgs ev)
+ internal void StopDiscovery()
{
- stateChanged?.Invoke(null, new BtModelStateChangedEventArgs(ev));
+ BluetoothAdapter.StopDiscovery();
+ isScanning = false;
+ operationStateChanged?.Invoke(null, new BtOperationStateChangedEventArgs(BtOperationState.Searched));
}
- internal event EventHandler<BtModelStateChangedEventArgs> StateChanged
+ private void AdapterStateChanged(object obj, StateChangedEventArgs ev)
{
- add
+ if (ev.BTState == BluetoothState.Enabled)
{
- stateChanged += value;
+ operationStateChanged?.Invoke(null, new BtOperationStateChangedEventArgs(BtOperationState.Activated));
}
- remove
+ else
{
- stateChanged -= value;
+ operationStateChanged?.Invoke(null, new BtOperationStateChangedEventArgs(BtOperationState.Deactivated));
}
}
- private static void AdapterDiscoveryChanged(object obj, DiscoveryStateChangedEventArgs ev)
+ private void AdapterDiscoveryChanged(object obj, DiscoveryStateChangedEventArgs ev)
{
- BtModelDiscoveryStateChangedEventArgs args = new BtModelDiscoveryStateChangedEventArgs(ev.DiscoveryState);
-
- if (ev.DiscoveryState == BluetoothDeviceDiscoveryState.Started)
+ if (ev.DiscoveryState == BluetoothDeviceDiscoveryState.Found)
{
- discoveryStateChanged?.Invoke(null, args);
+ BtDevice btDevice = new BtDevice(ev.DeviceFound.Address);
+ if (ev.DeviceFound.IsPaired)
+ {
+ btDevice.DeviceState = BtDeviceState.Paired;
+ }
+ else
+ {
+ btDevice.DeviceState = BtDeviceState.Idle;
+ }
+
+ BtDeviceChangedEventArgs args = new BtDeviceChangedEventArgs(btDevice);
+ deviceChanged?.Invoke(null, args);
}
else if (ev.DiscoveryState == BluetoothDeviceDiscoveryState.Finished)
{
- discoveryStateChanged?.Invoke(null, args);
+ isScanning = false;
+ operationStateChanged?.Invoke(null, new BtOperationStateChangedEventArgs(BtOperationState.Searched));
}
- else
+ }
+
+ internal event EventHandler<BtOperationStateChangedEventArgs> OperationStateChanged
+ {
+ add
{
- BtModelDevice device = new BtModelDevice(ev.DeviceFound.Address);
- args.DiscoveredDevice = device;
+ operationStateChanged += value;
+ }
+ remove
+ {
+ operationStateChanged -= value;
}
-
- discoveryStateChanged?.Invoke(null, args);
}
- internal event EventHandler<BtModelDiscoveryStateChangedEventArgs> DiscoveryStateChanged
+ internal event EventHandler<BtDeviceChangedEventArgs> DeviceChanged
{
add
{
- discoveryStateChanged += value;
+ deviceChanged += value;
}
remove
{
- discoveryStateChanged -= value;
+ deviceChanged -= value;
}
}
registered = reg;
}
- public Device(string deviceName)
+ public Device(string deviceName) // BtDevice
{
Log.Debug(Program.LogTag, "Device added. deviceName: " + deviceName);
name = deviceName;
{
this.Add(new Device(deviceName));
}
+
+ public void RemoveDevice(string deviceName)
+ {
+ foreach (Device device in this)
+ {
+ if (device.Name == deviceName)
+ {
+ this.Remove(device);
+ Log.Info(Program.LogTag, "device(" + deviceName + ") removed");
+ break;
+ }
+ }
+ }
}
public class DeviceSource : ObservableCollection<DeviceCollection>
public DeviceSource()
{
Log.Info(Program.LogTag, "DeviceSource created");
- collection = new DeviceCollection(Resources.IDS_BT_BODY_SCANNING_FOR_DEVICES_ING);
+ collection = new DeviceCollection(Resources.IDS_BT_BODY_AVAILABLE_DEVICES);
this.Add(collection);
}
collection.Title = title;
}
- public void AddDevice(string deviceName)
+ public void AddDevice(string deviceName) // BtDevice
{
collection.AddDevice(deviceName);
}
+
+ public void RemoveDevice(string deviceName)
+ {
+ collection.RemoveDevice(deviceName);
+ }
+
+ public Device FindDevice(string deviceName)
+ {
+ foreach (Device device in collection)
+ {
+ if (device.Name == deviceName)
+ {
+ Log.Info(Program.LogTag, "Device(" + deviceName + ") found");
+ return device;
+ }
+ }
+ return null;
+ }
}
}
{
static ContentPage mainPage;
static View mainView;
- static CollectionView deviceView = null;
+ static CollectionView pairedDeviceView = null;
+ static CollectionView searchedDeviceView = null;
static Button scanButton = null;
+ static BtOperationState operationState;
+ static DeviceSource searchedDevice;
+ static DeviceSource pairedDevice;
public BtMainView() : base()
{
}
- public static void DeviceSelectionChanged(object obj, SelectionChangedEventArgs ev)
+ private static CollectionView CreateCollectionView(DeviceSource source, bool fixHeight = true)
{
- Log.Debug(Program.LogTag, "DeviceSelectionChanged called");
-
- //SingleSelection Only have 1 or nil object in the list.
- foreach (object item in ev.PreviousSelection)
- {
- if (item == null) break;
- if (item is Device device)
- {
- device.Connected = false;
- }
- }
- foreach (object item in ev.CurrentSelection)
+ var view = new CollectionView()
{
- if (item == null) break;
- if (item is Device device)
- {
- device.Connected = true;
- device.Registered = true;
- }
- }
- }
-
- internal static void AddDeviceView(DeviceSource deviceSource)
- {
- deviceView = new CollectionView()
- {
- ItemsSource = deviceSource,
+ ItemsSource = source,
ItemsLayouter = new LinearLayouter(),
ItemTemplate = new DataTemplate(() =>
{
item.Icon.SetBinding(ImageView.ResourceUrlProperty, "ImageUrl");
item.Icon.WidthSpecification = 40;
item.Icon.HeightSpecification = 40;
+ var detailButton = new Button // TODO: need to use other type instead of Button
+ {
+ Text = "i"
+ };
+ detailButton.WidthSpecification = 40;
+ detailButton.Clicked += (obj, ev) =>
+ {
+ Button button = (Button)obj;
+ var device = button.BindingContext as Device;
+ Log.Debug(Program.LogTag, "Button clicked. Name: " + device.Name);
+ // TODO: add BtDetailView with device
+ };
+ item.Extra = detailButton;
return item;
}),
IsGrouped = true,
ScrollingDirection = ScrollableBase.Direction.Vertical,
WidthSpecification = LayoutParamPolicies.MatchParent,
- HeightSpecification = LayoutParamPolicies.MatchParent,
+ //HeightSpecification = LayoutParamPolicies.MatchParent,
SelectionMode = ItemSelectionMode.Single,
};
- deviceView.SelectionChanged += DeviceSelectionChanged;
- mainView.Add(deviceView);
+ if (fixHeight) // for searched view
+ {
+ view.HeightSpecification = LayoutParamPolicies.MatchParent;
+ }
+ view.SelectionChanged += DeviceController.DeviceViewSelectionChanged;
+
+ return view;
+ }
+
+ internal static void AddPairedDeviceView()
+ {
+ pairedDevice = new DeviceSource();
+ pairedDeviceView = CreateCollectionView(pairedDevice, false);
+ pairedDevice.AddDevice("Paired device"); // temporary device
+ pairedDevice.UpdateTitle(Resources.IDS_BT_BODY_PAIRED_DEVICES);
+ mainView.Add(pairedDeviceView);
}
- internal static void AddScanButton()
+ internal static void AddSearchedDeviceView()
{
+ searchedDevice = new DeviceSource();
+ searchedDeviceView = CreateCollectionView(searchedDevice);
+ searchedDevice.AddDevice("No devices found"); // temporary device
+ mainView.Add(searchedDeviceView);
+
scanButton = new Button
{
- Text = Resources.IDS_BT_SK_STOP,
- //WidthSpecification = 300,
- //HeightSpecification = 80,
- };
- scanButton.Clicked += (object obj, ClickedEventArgs ev) =>
- {
- //Log.Debug(Program.LogTag, "scanButton clicked. isScanning: " + isScanning);
- // check isScanning
- // scan stop
- //if (isScanning == true)
- //{
- // BluetoothAdapter.StopDiscovery();
- //}
- //else
- //{
- // BluetoothAdapter.StartDiscovery();
- //}
+ Text = Resources.IDS_BT_SK_SCAN,
};
-
+ scanButton.Clicked += AdapterController.ScanButtonClicked;
mainView.Add(scanButton);
}
- internal static void UpdateScanButton(string text)
+ //internal static void AddDeviceView()
+ //{
+ // AddPairedDeviceView();
+ // AddSearchedDeviceView();
+ //}
+
+ internal static void UpdateSearchedViewTitle(string title)
+ {
+ searchedDevice.UpdateTitle(title);
+ }
+
+ internal static void UpdateScanButtonText(string text)
{
scanButton.Text = text;
}
- internal static void RemoveDeviceView()
+ internal static void RemoveSearchedDeviceView()
{
- if (deviceView)
+ if (searchedDeviceView)
{
- mainView.Remove(deviceView);
+ mainView.Remove(searchedDeviceView);
}
- }
- internal static void RemoveScanButton()
- {
if (scanButton)
{
mainView.Remove(scanButton);
}
}
- protected override void OnCreate(string contentInfo, Window window)
+ internal static void RemoveAllView()
+ {
+ RemoveSearchedDeviceView();
+
+ if (pairedDeviceView)
+ {
+ mainView.Remove(pairedDeviceView);
+ }
+ }
+
+ private static void BtModelOperationStateChanged(object obj, BtOperationStateChangedEventArgs ev)
+ {
+ Log.Debug(Program.LogTag, "BtModelOperationStateChanged. OperationState: " + ev.OperationState);
+ switch (ev.OperationState)
+ {
+ case BtOperationState.Deactivated:
+ RemoveAllView();
+ break;
+ case BtOperationState.Deactivating:
+ break;
+ case BtOperationState.Activated:
+ AddPairedDeviceView();
+ AddSearchedDeviceView();
+ break;
+ case BtOperationState.Activating:
+ break;
+ case BtOperationState.Searching:
+ RemoveSearchedDeviceView();
+ AddSearchedDeviceView();
+ UpdateSearchedViewTitle(Resources.IDS_BT_BODY_SCANNING_FOR_DEVICES_ING);
+ UpdateScanButtonText(Resources.IDS_BT_SK_STOP);
+ break;
+ case BtOperationState.Searched:
+ UpdateSearchedViewTitle(Resources.IDS_BT_BODY_AVAILABLE_DEVICES);
+ UpdateScanButtonText(Resources.IDS_BT_SK_SCAN);
+ break;
+ case BtOperationState.Pairing:
+ break;
+ case BtOperationState.Connecting:
+ break;
+ }
+ }
+
+ private static void BtModelDeviceChanged(object obj, BtDeviceChangedEventArgs ev)
{
- //window = NUIApplication.GetDefaultWindow();
- //window.BackgroundColor = Color.White;
+ Log.Debug(Program.LogTag, "BtModelDeviceChanged. Address: " + ev.btDevice.RemoteDeviceAddress + ", State: " + ev.btDevice.DeviceState);
+ if (ev.btDevice.DeviceState == BtDeviceState.Paired)
+ {
+ if (pairedDevice.FindDevice("Paired device") != null)
+ {
+ pairedDevice.RemoveDevice("Paired device");
+ }
+ pairedDevice.AddDevice(ev.btDevice.RemoteDeviceAddress);
+ }
+ else if (ev.btDevice.DeviceState == BtDeviceState.Idle)
+ {
+ if (searchedDevice.FindDevice("No devices found") != null)
+ {
+ searchedDevice.RemoveDevice("No devices found");
+ }
+ searchedDevice.AddDevice(ev.btDevice.RemoteDeviceAddress);
+ }
+ }
+ protected override void OnCreate(string contentInfo, Window window)
+ {
var appBar = new AppBar()
{
Title = Resources.IDS_BT_BODY_BLUETOOTH,
onOffItem.Extra = onOffSwitch;
mainView.Add(onOffItem);
+ BtModel.OperationStateChanged += BtModelOperationStateChanged;
+ BtModel.DeviceChanged += BtModelDeviceChanged;
+
mainPage = new ContentPage()
{
AppBar = appBar,
static void Main(string[] args)
{
var appCustomBorder = new SettingViewBorder();
- var app = new Program("", new Size2D(800, 400), new Position2D(300, 100), appCustomBorder);
+ //var app = new Program("", new Size2D(800, 400), new Position2D(300, 100), appCustomBorder);
+ var app = new Program("", new Size2D(1200, 800), new Position2D(300, 100), appCustomBorder);
app.Run(args);
}