From: Wootak Jung Date: Wed, 5 Oct 2022 07:09:36 +0000 (+0900) Subject: Add paired device view X-Git-Tag: accepted/tizen/unified/20221005.144506^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fheads%2Ftizen_7.0;p=profile%2Fiot%2Fapps%2Fdotnet%2Fsetting-bluetooth.git Add paired device view add operation state changed logic add device changed logic add detail button Change-Id: I3214eb0513c2b4983ccfdd51d028778cd424f3ff Signed-off-by: Wootak Jung --- diff --git a/SettingBluetooth/SettingBluetooth/Controller/AdapterController.cs b/SettingBluetooth/SettingBluetooth/Controller/AdapterController.cs index 9e7dea7..fce381c 100644 --- a/SettingBluetooth/SettingBluetooth/Controller/AdapterController.cs +++ b/SettingBluetooth/SettingBluetooth/Controller/AdapterController.cs @@ -11,69 +11,38 @@ namespace SettingBluetooth.Controller { 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(); } } } diff --git a/SettingBluetooth/SettingBluetooth/Controller/DeviceController.cs b/SettingBluetooth/SettingBluetooth/Controller/DeviceController.cs index 28ef44a..7508ea4 100644 --- a/SettingBluetooth/SettingBluetooth/Controller/DeviceController.cs +++ b/SettingBluetooth/SettingBluetooth/Controller/DeviceController.cs @@ -1,10 +1,37 @@ 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; + } + } + } } } diff --git a/SettingBluetooth/SettingBluetooth/Model/BtDevice.cs b/SettingBluetooth/SettingBluetooth/Model/BtDevice.cs new file mode 100644 index 0000000..7f4d7cb --- /dev/null +++ b/SettingBluetooth/SettingBluetooth/Model/BtDevice.cs @@ -0,0 +1,78 @@ +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) + } + } +} diff --git a/SettingBluetooth/SettingBluetooth/Model/BtEnumerations.cs b/SettingBluetooth/SettingBluetooth/Model/BtEnumerations.cs new file mode 100644 index 0000000..03cb74d --- /dev/null +++ b/SettingBluetooth/SettingBluetooth/Model/BtEnumerations.cs @@ -0,0 +1,30 @@ +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, + } +} diff --git a/SettingBluetooth/SettingBluetooth/Model/BtEventArgs.cs b/SettingBluetooth/SettingBluetooth/Model/BtEventArgs.cs new file mode 100644 index 0000000..ae58c37 --- /dev/null +++ b/SettingBluetooth/SettingBluetooth/Model/BtEventArgs.cs @@ -0,0 +1,28 @@ +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; + } + } +} diff --git a/SettingBluetooth/SettingBluetooth/Model/BtModel.cs b/SettingBluetooth/SettingBluetooth/Model/BtModel.cs index 5a98d40..37316d6 100644 --- a/SettingBluetooth/SettingBluetooth/Model/BtModel.cs +++ b/SettingBluetooth/SettingBluetooth/Model/BtModel.cs @@ -17,6 +17,14 @@ namespace SettingBluetooth.Model } } + internal static bool IsScanning + { + get + { + return BtModelImpl.Instance.IsScanning; + } + } + internal static void Enable() { BtModelImpl.Instance.Enable(); @@ -31,28 +39,32 @@ namespace SettingBluetooth.Model { BtModelImpl.Instance.StartDiscovery(); } + internal static void StopDiscovery() + { + BtModelImpl.Instance.StopDiscovery(); + } - internal static event EventHandler StateChanged + internal static event EventHandler OperationStateChanged { add { - BtModelImpl.Instance.StateChanged += value; + BtModelImpl.Instance.OperationStateChanged += value; } remove { - BtModelImpl.Instance.StateChanged -= value; + BtModelImpl.Instance.OperationStateChanged -= value; } } - internal static event EventHandler DiscoveryStateChanged + internal static event EventHandler DeviceChanged { add { - BtModelImpl.Instance.DiscoveryStateChanged += value; + BtModelImpl.Instance.DeviceChanged += value; } remove { - BtModelImpl.Instance.DiscoveryStateChanged -= value; + BtModelImpl.Instance.DeviceChanged -= value; } } } diff --git a/SettingBluetooth/SettingBluetooth/Model/BtModelDevice.cs b/SettingBluetooth/SettingBluetooth/Model/BtModelDevice.cs deleted file mode 100644 index 5141813..0000000 --- a/SettingBluetooth/SettingBluetooth/Model/BtModelDevice.cs +++ /dev/null @@ -1,77 +0,0 @@ -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) - } - } -} diff --git a/SettingBluetooth/SettingBluetooth/Model/BtModelEnumerations.cs b/SettingBluetooth/SettingBluetooth/Model/BtModelEnumerations.cs deleted file mode 100644 index d7e6811..0000000 --- a/SettingBluetooth/SettingBluetooth/Model/BtModelEnumerations.cs +++ /dev/null @@ -1,37 +0,0 @@ -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, - } -} diff --git a/SettingBluetooth/SettingBluetooth/Model/BtModelEventArgs.cs b/SettingBluetooth/SettingBluetooth/Model/BtModelEventArgs.cs deleted file mode 100644 index 2570e20..0000000 --- a/SettingBluetooth/SettingBluetooth/Model/BtModelEventArgs.cs +++ /dev/null @@ -1,29 +0,0 @@ -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; - } - } -} diff --git a/SettingBluetooth/SettingBluetooth/Model/BtModelImpl.cs b/SettingBluetooth/SettingBluetooth/Model/BtModelImpl.cs index 190d708..c2a8234 100644 --- a/SettingBluetooth/SettingBluetooth/Model/BtModelImpl.cs +++ b/SettingBluetooth/SettingBluetooth/Model/BtModelImpl.cs @@ -9,8 +9,9 @@ namespace SettingBluetooth.Model internal class BtModelImpl { static readonly BtModelImpl instance = new BtModelImpl(); - static event EventHandler stateChanged = null; - static event EventHandler discoveryStateChanged = null; + static bool isScanning = false; + static event EventHandler operationStateChanged = null; + static event EventHandler deviceChanged = null; internal bool IsEnabled { @@ -20,68 +21,97 @@ namespace SettingBluetooth.Model } } + 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 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 OperationStateChanged + { + add { - BtModelDevice device = new BtModelDevice(ev.DeviceFound.Address); - args.DiscoveredDevice = device; + operationStateChanged += value; + } + remove + { + operationStateChanged -= value; } - - discoveryStateChanged?.Invoke(null, args); } - internal event EventHandler DiscoveryStateChanged + internal event EventHandler DeviceChanged { add { - discoveryStateChanged += value; + deviceChanged += value; } remove { - discoveryStateChanged -= value; + deviceChanged -= value; } } diff --git a/SettingBluetooth/SettingBluetooth/View/BtDeviceView.cs b/SettingBluetooth/SettingBluetooth/View/BtDeviceView.cs index 905a23d..7c639b9 100644 --- a/SettingBluetooth/SettingBluetooth/View/BtDeviceView.cs +++ b/SettingBluetooth/SettingBluetooth/View/BtDeviceView.cs @@ -32,7 +32,7 @@ namespace SettingBluetooth registered = reg; } - public Device(string deviceName) + public Device(string deviceName) // BtDevice { Log.Debug(Program.LogTag, "Device added. deviceName: " + deviceName); name = deviceName; @@ -111,6 +111,19 @@ namespace SettingBluetooth { 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 @@ -120,7 +133,7 @@ namespace SettingBluetooth 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); } @@ -129,9 +142,27 @@ namespace SettingBluetooth 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; + } } } diff --git a/SettingBluetooth/SettingBluetooth/View/BtMainView.cs b/SettingBluetooth/SettingBluetooth/View/BtMainView.cs index 65a24d1..7ba8be0 100644 --- a/SettingBluetooth/SettingBluetooth/View/BtMainView.cs +++ b/SettingBluetooth/SettingBluetooth/View/BtMainView.cs @@ -18,42 +18,22 @@ namespace SettingBluetooth { 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(() => { @@ -66,6 +46,19 @@ namespace SettingBluetooth 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; }), @@ -84,66 +77,138 @@ namespace SettingBluetooth 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, @@ -175,6 +240,9 @@ namespace SettingBluetooth onOffItem.Extra = onOffSwitch; mainView.Add(onOffItem); + BtModel.OperationStateChanged += BtModelOperationStateChanged; + BtModel.DeviceChanged += BtModelDeviceChanged; + mainPage = new ContentPage() { AppBar = appBar, diff --git a/SettingBluetooth/SettingView/SettingView.cs b/SettingBluetooth/SettingView/SettingView.cs index 06dee62..a8f7d79 100644 --- a/SettingBluetooth/SettingView/SettingView.cs +++ b/SettingBluetooth/SettingView/SettingView.cs @@ -44,7 +44,8 @@ namespace SettingView 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); } diff --git a/packaging/org.tizen.cssetting-bluetooth-1.0.0.tpk b/packaging/org.tizen.cssetting-bluetooth-1.0.0.tpk index f24c624..2013b84 100644 Binary files a/packaging/org.tizen.cssetting-bluetooth-1.0.0.tpk and b/packaging/org.tizen.cssetting-bluetooth-1.0.0.tpk differ