Add paired device view 36/282536/2 accepted/tizen_7.0_unified accepted/tizen_7.0_unified_hotfix tizen_7.0 tizen_7.0_hotfix accepted/tizen/7.0/unified/20221110.060618 accepted/tizen/7.0/unified/hotfix/20221116.111648 accepted/tizen/unified/20221005.144506 tizen_7.0_m2_release
authorWootak Jung <wootak.jung@samsung.com>
Wed, 5 Oct 2022 07:09:36 +0000 (16:09 +0900)
committerWootak Jung <wootak.jung@samsung.com>
Wed, 5 Oct 2022 07:16:54 +0000 (16:16 +0900)
add operation state changed logic
add device changed logic
add detail button

Change-Id: I3214eb0513c2b4983ccfdd51d028778cd424f3ff
Signed-off-by: Wootak Jung <wootak.jung@samsung.com>
14 files changed:
SettingBluetooth/SettingBluetooth/Controller/AdapterController.cs
SettingBluetooth/SettingBluetooth/Controller/DeviceController.cs
SettingBluetooth/SettingBluetooth/Model/BtDevice.cs [new file with mode: 0644]
SettingBluetooth/SettingBluetooth/Model/BtEnumerations.cs [new file with mode: 0644]
SettingBluetooth/SettingBluetooth/Model/BtEventArgs.cs [new file with mode: 0644]
SettingBluetooth/SettingBluetooth/Model/BtModel.cs
SettingBluetooth/SettingBluetooth/Model/BtModelDevice.cs [deleted file]
SettingBluetooth/SettingBluetooth/Model/BtModelEnumerations.cs [deleted file]
SettingBluetooth/SettingBluetooth/Model/BtModelEventArgs.cs [deleted file]
SettingBluetooth/SettingBluetooth/Model/BtModelImpl.cs
SettingBluetooth/SettingBluetooth/View/BtDeviceView.cs
SettingBluetooth/SettingBluetooth/View/BtMainView.cs
SettingBluetooth/SettingView/SettingView.cs
packaging/org.tizen.cssetting-bluetooth-1.0.0.tpk

index 9e7dea726be2f9736b872fcaea16f6e39cf9fde8..fce381cad3a22baa9ead0136b0c321b4e318fafc 100644 (file)
@@ -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();
             }
         }
     }
index 28ef44a779824d1ada132a3b3eb2f50c2b567805..7508ea48779356ba289582727d423f9bbff64c96 100644 (file)
@@ -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 (file)
index 0000000..7f4d7cb
--- /dev/null
@@ -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 (file)
index 0000000..03cb74d
--- /dev/null
@@ -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 (file)
index 0000000..ae58c37
--- /dev/null
@@ -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;
+        }
+    }
+}
index 5a98d4074b078a117973ccaa5cc1d28a30299741..37316d6141dbe838e2320c9472f0fa3a4df5f61e 100644 (file)
@@ -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<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;
             }
         }
     }
diff --git a/SettingBluetooth/SettingBluetooth/Model/BtModelDevice.cs b/SettingBluetooth/SettingBluetooth/Model/BtModelDevice.cs
deleted file mode 100644 (file)
index 5141813..0000000
+++ /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 (file)
index d7e6811..0000000
+++ /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 (file)
index 2570e20..0000000
+++ /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;
-        }
-    }
-}
index 190d708c2649c301ac7294e9e7b8260a4f8efa3a..c2a8234f1aea8cd22c76fc5c0852aec5df173f99 100644 (file)
@@ -9,8 +9,9 @@ namespace SettingBluetooth.Model
     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
         {
@@ -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<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;
             }
         }
 
index 905a23d525069b38452dcab544b1f50d63f0e6a4..7c639b90a00495ff15087b914f88e67247f2e34c 100644 (file)
@@ -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<DeviceCollection>
@@ -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;
+        }
     }
 }
index 65a24d13f0358450c524892a8964d9c8d3e5f77e..7ba8be0bf41ff606b4bb15f8fb0df05bb91dcf68 100644 (file)
@@ -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,
index 06dee624a579ea32857ef43f7bdfbc6e478a06d1..a8f7d79f312a6c98421d6cc385d11b86db24e280 100644 (file)
@@ -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);
         }
index f24c62472069bd8e6751d903fefcb46779055f63..2013b84c42959fb4df500847922fa9eb3ad7e180 100644 (file)
Binary files a/packaging/org.tizen.cssetting-bluetooth-1.0.0.tpk and b/packaging/org.tizen.cssetting-bluetooth-1.0.0.tpk differ