}
}
- internal void AddDevice(BtDevice btDevice)
+ internal void AddDevice(BtDevice btDevice) // TODO: need to create AddDeviceFront function to add the device in front of the list for paired and unpaired case
{
if (this.Count == 0)
{
Log.Info(Program.LogTag, "device(" + btDevice.Address + ") added");
}
- internal void RemoveDevice(string address)
+ internal void RemoveDevice(BtDevice btDevice)
{
foreach (Device device in this)
{
- if (device.Address == address)
+ if (device.Address == btDevice.Address)
{
this.Remove(device);
- Log.Info(Program.LogTag, "device(" + address + ") removed");
+ Log.Info(Program.LogTag, "device(" + device.Address + ") removed");
break;
}
}
public class DeviceSource : ObservableCollection<DeviceCollection>
{
- private DeviceCollection collection;
+ private DeviceCollection mSearched;
+ private DeviceCollection mPaired;
public DeviceSource()
{
Log.Info(Program.LogTag, "DeviceSource created");
- collection = new DeviceCollection(Resources.IDS_BT_BODY_AVAILABLE_DEVICES);
- this.Add(collection);
+ mSearched = new DeviceCollection(Resources.IDS_BT_BODY_SCANNING_FOR_DEVICES_ING);
+ mPaired = new DeviceCollection(Resources.IDS_BT_BODY_PAIRED_DEVICES);
+ this.Add(mSearched);
+ }
+
+ internal void UpdateSearchedTitle(string title)
+ {
+ mSearched.Title = title;
+ }
+
+ internal void AddToSearched(BtDevice btDevice)
+ {
+ mSearched.AddDevice(btDevice);
+ UpdateState(btDevice); // TODO: don't need to find device item. let's use return value from above function
+ }
+
+ internal void AddToPaired(BtDevice btDevice)
+ {
+ if (mPaired.Count == 0)
+ {
+ this.Insert(0, mPaired);
+ }
+ mPaired.AddDevice(btDevice); // TODO: need to Add to in front of the list not Insert if paired
+ UpdateState(btDevice); // TODO: don't need to find device item. let's use return value from above function
+ }
+
+ internal void RemoveFromSearched(BtDevice btDevice)
+ {
+ mSearched.RemoveDevice(btDevice);
}
- internal void UpdateTitle(string title)
+ internal void RemoveFromPaired(BtDevice btDevice)
{
- collection.Title = title;
+ mPaired.RemoveDevice(btDevice);
+ if (mPaired.Count == 0)
+ {
+ this.Remove(mPaired);
+ }
}
- internal void AddDevice(BtDevice btDevice)
+ internal void RemoveAllSearchedDevices()
{
- collection.AddDevice(btDevice);
- UpdateState(btDevice);
+ mSearched.Clear();
}
- internal void RemoveDevice(string address)
+ internal Device FindInSearched(BtDevice btDevice)
{
- collection.RemoveDevice(address);
+ foreach (Device device in mSearched)
+ {
+ if (device.Address == btDevice.Address)
+ {
+ //Log.Info(Program.LogTag, "Device(" + device.Address + ") found in searched");
+ return device;
+ }
+ }
+
+ return null;
}
- internal Device FindDevice(BtDevice btDevice)
+ internal Device FindInPaired(BtDevice btDevice)
{
- foreach (Device device in collection)
+ foreach (Device device in mPaired)
{
if (device.Address == btDevice.Address)
{
- //Log.Info(Program.LogTag, "Device(" + address + ") found");
+ //Log.Info(Program.LogTag, "Device(" + device.Address + ") found in paired");
return device;
}
}
- //Log.Info(Program.LogTag, "Device(" + address + ") not found");
+
return null;
}
internal void UpdateState(BtDevice btDevice)
{
- var device = FindDevice(btDevice);
+ var device = FindInSearched(btDevice);
+ if (device == null)
+ {
+ device = FindInPaired(btDevice);
+ }
+
switch (btDevice.DeviceState)
{
case BtDeviceState.Idle:
internal static class BtDeviceView
{
- static CollectionView mPairedDeviceView = null;
- static CollectionView mSearchedDeviceView = null;
+ static CollectionView mDeviceView = null;
static Button mScanButton = null;
- static DeviceSource mSearchedDevice = null;
- static DeviceSource mPairedDevice = null;
+ static DeviceSource mDeviceSource = null;
private static CollectionView CreateCollectionView(DeviceSource source, bool isPairedDeviceView = false)
{
item.Clicked += DeviceController.DeviceItemClicked;
item.IsSelectable = false;
- if (isPairedDeviceView == true)
- {
- var detailButton = new Button // TODO: need to use other type instead of Button
+ //if (isPairedDeviceView == true) // TODO: need to use DataTemplateExtension and DataTemplateSelector
+ //{
+ var detailButton = new Button // TODO: need to use other type instead of Button
{
Text = "i"
};
BtDetailView.CreateDetailView(device);
};
item.Extra = detailButton;
- }
+ //}
return item;
}),
SelectionMode = ItemSelectionMode.Single,
};
- if (isPairedDeviceView == false)
- {
- view.HeightSpecification = LayoutParamPolicies.MatchParent;
- }
+ view.HeightSpecification = LayoutParamPolicies.MatchParent;
//view.SelectionChanged += DeviceController.DeviceViewSelectionChanged;
return view;
}
- internal static void AddPairedDeviceView(View view)
+ internal static void AddDeviceView(View view)
{
- mPairedDevice = new DeviceSource();
- mPairedDeviceView = CreateCollectionView(mPairedDevice, true);
- mPairedDevice.AddDevice(new BtDevice("dummy paired device")); // temporary device
- mPairedDevice.UpdateTitle(Resources.IDS_BT_BODY_PAIRED_DEVICES);
- view.Add(mPairedDeviceView);
- }
+ Log.Info(Program.LogTag, "Add device view");
- internal static void AddSearchedDeviceView(View view)
- {
- mSearchedDevice = new DeviceSource();
- mSearchedDeviceView = CreateCollectionView(mSearchedDevice);
- mSearchedDevice.AddDevice(new BtDevice("dummy searched device")); // temporary device
- view.Add(mSearchedDeviceView);
+ mDeviceSource = new DeviceSource();
+ mDeviceView = CreateCollectionView(mDeviceSource);
+ mDeviceSource.AddToPaired(new BtDevice("dummy paired device", true)); // dummy device
+ mDeviceSource.AddToSearched(new BtDevice("dummy paired device", false)); // dummy device
+ view.Add(mDeviceView);
+ BtModel.GetBondedDevices();
mScanButton = new Button
{
view.Add(mScanButton);
}
- internal static void AddDeviceView(View view)
+ internal static void RemoveDeviceView(View view)
{
- Log.Info(Program.LogTag, "Add device view");
- AddPairedDeviceView(view);
- AddSearchedDeviceView(view);
- BtModel.GetBondedDevices();
- AdapterController.AutoStart();
- }
-
- internal static void RemovePairedDeviceView(View view)
- {
- if (mPairedDeviceView)
- {
- view.Remove(mPairedDeviceView);
- mPairedDeviceView = null;
- }
- }
+ Log.Info(Program.LogTag, "Remove device view");
- internal static void RemoveSearchedDeviceView(View view)
- {
- if (mSearchedDeviceView)
+ if (mDeviceView)
{
- view.Remove(mSearchedDeviceView);
- mSearchedDeviceView = null;
+ view.Remove(mDeviceView);
+ mDeviceView = null;
}
if (mScanButton)
}
}
- internal static void UpdateSearchedViewTitle(string title)
+ internal static void RemoveAllSearchedDevices()
+ {
+ Log.Info(Program.LogTag, "Remove all searched devices");
+ mDeviceSource.RemoveAllSearchedDevices();
+ }
+
+ internal static void UpdateSearchedTitle(string title)
{
- mSearchedDevice.UpdateTitle(title);
+ mDeviceSource.UpdateSearchedTitle(title);
}
internal static void UpdateScanButtonText(string text)
// available cases: added new one, bond/unbond/audio failed
if (ev.BtDevice.IsPaired)
{
- if (mPairedDevice.FindDevice(ev.BtDevice) == null)
+ if (mDeviceSource.FindInPaired(ev.BtDevice) == null)
{
- mPairedDevice.AddDevice(ev.BtDevice);
+ mDeviceSource.AddToPaired(ev.BtDevice);
}
else
{
- mPairedDevice.UpdateState(ev.BtDevice);
+ mDeviceSource.UpdateState(ev.BtDevice);
}
}
else
{
- if (mSearchedDevice.FindDevice(ev.BtDevice) != null) // bond/unbond/audio failed case
+ if (mDeviceSource.FindInSearched(ev.BtDevice) != null) // bond/unbond/audio failed case
{
- mSearchedDevice.UpdateState(ev.BtDevice); // TODO: need to remove SubLabel in this case
+ mDeviceSource.UpdateState(ev.BtDevice); // TODO: need to remove SubLabel in this case
}
else
{
- mSearchedDevice.AddDevice(ev.BtDevice); // added new one
+ mDeviceSource.AddToSearched(ev.BtDevice); // added new one
}
}
break;
case BtDeviceState.Pairing:
- if (mSearchedDevice.FindDevice(ev.BtDevice) != null)
+ if (mDeviceSource.FindInSearched(ev.BtDevice) != null)
{
- mSearchedDevice.UpdateState(ev.BtDevice);
+ mDeviceSource.UpdateState(ev.BtDevice);
}
break;
case BtDeviceState.Unpairing:
break;
case BtDeviceState.Paired:
- if (mSearchedDevice.FindDevice(ev.BtDevice) != null)
+ if (mDeviceSource.FindInSearched(ev.BtDevice) != null)
{
- mSearchedDevice.RemoveDevice(ev.BtDevice.Address);
+ mDeviceSource.RemoveFromSearched(ev.BtDevice);
}
- if (mPairedDevice.FindDevice(ev.BtDevice) == null)
+ if (mDeviceSource.FindInPaired(ev.BtDevice) == null)
{
- mPairedDevice.AddDevice(ev.BtDevice);
+ mDeviceSource.AddToPaired(ev.BtDevice);
if (ev.BtDevice.IsA2dpSupported)
{
DeviceController.ConnectA2dp(ev.BtDevice);
}
else // audio disconnected case
{
- mPairedDevice.UpdateState(ev.BtDevice);
+ mDeviceSource.UpdateState(ev.BtDevice);
}
break;
case BtDeviceState.Unpaired:
- if (mSearchedDevice.FindDevice(ev.BtDevice) == null)
+ if (mDeviceSource.FindInSearched(ev.BtDevice) == null)
{
- mSearchedDevice.AddDevice(ev.BtDevice);
+ mDeviceSource.AddToSearched(ev.BtDevice); // TODO: need to add in front of the list
}
- if (mPairedDevice.FindDevice(ev.BtDevice) != null)
+ if (mDeviceSource.FindInPaired(ev.BtDevice) != null)
{
- mPairedDevice.RemoveDevice(ev.BtDevice.Address);
+ mDeviceSource.RemoveFromPaired(ev.BtDevice);
}
break;
case BtDeviceState.Connecting:
- if (mPairedDevice.FindDevice(ev.BtDevice) != null)
+ if (mDeviceSource.FindInPaired(ev.BtDevice) != null)
{
- mPairedDevice.UpdateState(ev.BtDevice);
+ mDeviceSource.UpdateState(ev.BtDevice);
}
break;
case BtDeviceState.Connected:
- if (mPairedDevice.FindDevice(ev.BtDevice) != null)
+ if (mDeviceSource.FindInPaired(ev.BtDevice) != null)
{
- mPairedDevice.UpdateState(ev.BtDevice);
+ mDeviceSource.UpdateState(ev.BtDevice);
}
break;
case BtDeviceState.Disconnecting:
- if (mPairedDevice.FindDevice(ev.BtDevice) != null)
+ if (mDeviceSource.FindInPaired(ev.BtDevice) != null)
{
- mPairedDevice.UpdateState(ev.BtDevice);
+ mDeviceSource.UpdateState(ev.BtDevice);
}
break;
case BtDeviceState.ServiceSearching: