{
internal class BtDevice
{
- private string address;
- private string name;
- private bool isPaired;
- private BtDeviceState deviceState;
- private BluetoothDevice bluetoothDevice;
+ private string mAddress;
+ private string mName;
+ private bool mIsPaired;
+ private BtDeviceState mDeviceState;
+ private BluetoothDevice mBluetoothDevice;
// TODO
internal BtDevice(BluetoothDevice device, BtDeviceState state)
{
- bluetoothDevice = device;
- address = bluetoothDevice.Address;
- name = bluetoothDevice.Name;
- isPaired = bluetoothDevice.IsPaired;
- deviceState = state;
+ mAddress = device.Address;
+ mName = device.Name;
+ mIsPaired = device.IsPaired;
+ mDeviceState = state;
+ mBluetoothDevice = device;
}
// for dummy instance (No devices found, Paired device)
- internal BtDevice(string addr)
+ internal BtDevice(string address)
{
- address = addr;
- name = addr;
+ mAddress = address;
+ mName = address;
}
internal string Address
{
get
{
- return address;
+ return mAddress;
}
}
{
get
{
- return name;
+ return mName;
}
}
{
get
{
- return isPaired;
+ return mIsPaired;
}
}
{
get
{
- return deviceState;
+ return mDeviceState;
}
}
Log.Info(Program.LogTag, "BluetoothDeviceBondCreated. Address: " + ev.Device.Address + ", IsPaired: " + ev.Device.IsPaired);
if (ev.Device.IsPaired)
{
- isPaired = true;
- deviceState = BtDeviceState.Paired;
+ mIsPaired = true;
+ mDeviceState = BtDeviceState.Paired;
BtModel.NotifyDeviceChanged(this);
//BtModel.NotifyOperationStateChanged(BtOperationState.Activated);
}
- bluetoothDevice.BondCreated -= BluetoothDeviceBondCreated;
+ mBluetoothDevice.BondCreated -= BluetoothDeviceBondCreated;
}
// TODO
// 5. Set BT Operation state as Activated
internal void Pair()
{
- bluetoothDevice.BondCreated += BluetoothDeviceBondCreated;
- bluetoothDevice.CreateBond();
- deviceState = BtDeviceState.Pairing;
+ mBluetoothDevice.BondCreated += BluetoothDeviceBondCreated;
+ mBluetoothDevice.CreateBond();
+ mDeviceState = BtDeviceState.Pairing;
BtModel.NotifyDeviceChanged(this);
BtModel.NotifyOperationStateChanged(BtOperationState.Pairing);
}
Log.Info(Program.LogTag, "BluetoothDeviceBondDestroyed. Address: " + ev.DeviceAddress + ", Result: " + ev.Result);
if (ev.Result == BluetoothError.None)
{
- isPaired = false;
- deviceState = BtDeviceState.Unpaired;
+ mIsPaired = false;
+ mDeviceState = BtDeviceState.Unpaired;
BtModel.NotifyDeviceChanged(this);
//BtModel.NotifyOperationStateChanged(BtOperationState.Activated);
}
- bluetoothDevice.BondDestroyed -= BluetoothDeviceBondDestroyed;
+ mBluetoothDevice.BondDestroyed -= BluetoothDeviceBondDestroyed;
}
// TODO
// 5. Set BT Operation state as Activated
internal void Unpair()
{
- bluetoothDevice.BondDestroyed += BluetoothDeviceBondDestroyed;
- bluetoothDevice.DestroyBond();
- deviceState = BtDeviceState.Unpairing;
+ mBluetoothDevice.BondDestroyed += BluetoothDeviceBondDestroyed;
+ mBluetoothDevice.DestroyBond();
+ mDeviceState = BtDeviceState.Unpairing;
BtModel.NotifyDeviceChanged(this);
BtModel.NotifyOperationStateChanged(BtOperationState.Pairing);
}
{
internal class BtOperationStateChangedEventArgs : EventArgs
{
- private BtOperationState operationState;
+ private BtOperationState mOperationState;
internal BtOperationStateChangedEventArgs(BtOperationState state)
{
- operationState = state;
+ mOperationState = state;
}
internal BtOperationState OperationState
{
get
{
- return operationState;
+ return mOperationState;
}
}
}
internal class BtDeviceChangedEventArgs : EventArgs
{
- private BtDevice btDevice;
+ private BtDevice mBtDevice;
internal BtDeviceChangedEventArgs(BtDevice device)
{
- btDevice = device;
+ mBtDevice = device;
}
internal BtDevice BtDevice
{
get
{
- return btDevice;
+ return mBtDevice;
}
}
}
{
internal class BtModelImpl
{
- static readonly BtModelImpl instance = new BtModelImpl();
- static bool isScanning = false;
- static event EventHandler<BtOperationStateChangedEventArgs> operationStateChanged = null;
- static event EventHandler<BtDeviceChangedEventArgs> deviceChanged = null;
+ static readonly BtModelImpl mInstance = new BtModelImpl();
+ static bool mIsScanning = false;
+ static event EventHandler<BtOperationStateChangedEventArgs> mOperationStateChanged = null;
+ static event EventHandler<BtDeviceChangedEventArgs> mDeviceChanged = null;
internal bool IsEnabled
{
{
get
{
- return isScanning;
+ return mIsScanning;
}
}
internal void Enable()
{
BluetoothAdapter.Enable();
- operationStateChanged?.Invoke(null, new BtOperationStateChangedEventArgs(BtOperationState.Activating));
+ mOperationStateChanged?.Invoke(null, new BtOperationStateChangedEventArgs(BtOperationState.Activating));
}
internal void Disable()
{
BluetoothAdapter.Disable();
- operationStateChanged?.Invoke(null, new BtOperationStateChangedEventArgs(BtOperationState.Deactivating));
+ mOperationStateChanged?.Invoke(null, new BtOperationStateChangedEventArgs(BtOperationState.Deactivating));
}
internal void StartDiscovery()
{
BluetoothAdapter.StartDiscovery();
- isScanning = true;
- operationStateChanged?.Invoke(null, new BtOperationStateChangedEventArgs(BtOperationState.Searching));
+ mIsScanning = true;
+ mOperationStateChanged?.Invoke(null, new BtOperationStateChangedEventArgs(BtOperationState.Searching));
}
internal void StopDiscovery()
{
BluetoothAdapter.StopDiscovery();
- isScanning = false;
- operationStateChanged?.Invoke(null, new BtOperationStateChangedEventArgs(BtOperationState.Searched));
+ mIsScanning = false;
+ mOperationStateChanged?.Invoke(null, new BtOperationStateChangedEventArgs(BtOperationState.Searched));
}
private void AdapterStateChanged(object obj, StateChangedEventArgs ev)
{
if (ev.BTState == BluetoothState.Enabled)
{
- operationStateChanged?.Invoke(null, new BtOperationStateChangedEventArgs(BtOperationState.Activated));
+ mOperationStateChanged?.Invoke(null, new BtOperationStateChangedEventArgs(BtOperationState.Activated));
}
else
{
- operationStateChanged?.Invoke(null, new BtOperationStateChangedEventArgs(BtOperationState.Deactivated));
+ mOperationStateChanged?.Invoke(null, new BtOperationStateChangedEventArgs(BtOperationState.Deactivated));
}
}
}
BtDeviceChangedEventArgs args = new BtDeviceChangedEventArgs(btDevice);
- deviceChanged?.Invoke(null, args);
+ mDeviceChanged?.Invoke(null, args);
}
else if (ev.DiscoveryState == BluetoothDeviceDiscoveryState.Finished)
{
- isScanning = false;
- operationStateChanged?.Invoke(null, new BtOperationStateChangedEventArgs(BtOperationState.Searched));
+ mIsScanning = false;
+ mOperationStateChanged?.Invoke(null, new BtOperationStateChangedEventArgs(BtOperationState.Searched));
}
}
{
add
{
- operationStateChanged += value;
+ mOperationStateChanged += value;
}
remove
{
- operationStateChanged -= value;
+ mOperationStateChanged -= value;
}
}
{
add
{
- deviceChanged += value;
+ mDeviceChanged += value;
}
remove
{
- deviceChanged -= value;
+ mDeviceChanged -= value;
}
}
internal void NotifyOperationStateChanged(BtOperationState state)
{
- operationStateChanged?.Invoke(null, new BtOperationStateChangedEventArgs(state));
+ mOperationStateChanged?.Invoke(null, new BtOperationStateChangedEventArgs(state));
}
internal void NotifyDeviceChanged(BtDevice btDevice)
{
- deviceChanged?.Invoke(null, new BtDeviceChangedEventArgs(btDevice));
+ mDeviceChanged?.Invoke(null, new BtDeviceChangedEventArgs(btDevice));
}
private void Initialize()
{
get
{
- return instance;
+ return mInstance;
}
}
{
public class Device : INotifyPropertyChanged
{
- string iconDir = Tizen.Applications.Application.Current.DirectoryInfo.Resource + "icon.png";
- private string address;
- private string name;
+ string mIconDir = Tizen.Applications.Application.Current.DirectoryInfo.Resource + "icon.png";
+ private string mAddress;
+ private string mName;
//private bool connected;
//private bool registered;
public event PropertyChangedEventHandler PropertyChanged;
- BtDevice btItem;
+ BtDevice mBtItem;
private void OnPropertyChanged(string propertyName)
{
public Device(string deviceName, bool con, bool reg)
{
- name = deviceName;
+ mName = deviceName;
//connected = con;
//registered = reg;
}
internal Device(BtDevice btDevice)
{
- address = btDevice.Address;
- name = btDevice.Name;
- btItem = btDevice;
+ mAddress = btDevice.Address;
+ mName = btDevice.Name;
+ mBtItem = btDevice;
}
internal BtDevice BtItem
{
get
{
- return btItem;
+ return mBtItem;
}
}
{
get
{
- return address;
+ return mAddress;
}
}
{
get
{
- return name;
+ return mName;
}
set
{
- name = value;
+ mName = value;
OnPropertyChanged("Name");
}
}
{
get
{
- return iconDir;
+ return mIconDir;
}
}
{
class BtMainView : Widget
{
- static ContentPage mainPage;
- static View mainView;
- static CollectionView pairedDeviceView = null;
- static CollectionView searchedDeviceView = null;
- static Button scanButton = null;
- static DeviceSource searchedDevice = null;
- static DeviceSource pairedDevice = null;
+ static ContentPage mMainPage;
+ static View mMainView;
+ static CollectionView mPairedDeviceView = null;
+ static CollectionView mSearchedDeviceView = null;
+ static Button mScanButton = null;
+ static DeviceSource mSearchedDevice = null;
+ static DeviceSource mPairedDevice = null;
public BtMainView() : base()
{
private static void AddPairedDeviceView()
{
- pairedDevice = new DeviceSource();
- pairedDeviceView = CreateCollectionView(pairedDevice, false);
- pairedDevice.AddDevice(new BtDevice("dummy paired device")); // temporary device
- pairedDevice.UpdateTitle(Resources.IDS_BT_BODY_PAIRED_DEVICES);
- mainView.Add(pairedDeviceView);
+ mPairedDevice = new DeviceSource();
+ mPairedDeviceView = CreateCollectionView(mPairedDevice, false);
+ mPairedDevice.AddDevice(new BtDevice("dummy paired device")); // temporary device
+ mPairedDevice.UpdateTitle(Resources.IDS_BT_BODY_PAIRED_DEVICES);
+ mMainView.Add(mPairedDeviceView);
}
private static void AddSearchedDeviceView()
{
- searchedDevice = new DeviceSource();
- searchedDeviceView = CreateCollectionView(searchedDevice);
- searchedDevice.AddDevice(new BtDevice("dummy searched device")); // temporary device
- mainView.Add(searchedDeviceView);
+ mSearchedDevice = new DeviceSource();
+ mSearchedDeviceView = CreateCollectionView(mSearchedDevice);
+ mSearchedDevice.AddDevice(new BtDevice("dummy searched device")); // temporary device
+ mMainView.Add(mSearchedDeviceView);
- scanButton = new Button
+ mScanButton = new Button
{
Text = Resources.IDS_BT_SK_SCAN,
};
- scanButton.Clicked += AdapterController.ScanButtonClicked;
- mainView.Add(scanButton);
+ mScanButton.Clicked += AdapterController.ScanButtonClicked;
+ mMainView.Add(mScanButton);
}
//internal static void AddDeviceView()
private static void UpdateSearchedViewTitle(string title)
{
- searchedDevice.UpdateTitle(title);
+ mSearchedDevice.UpdateTitle(title);
}
private static void UpdateScanButtonText(string text)
{
- scanButton.Text = text;
+ mScanButton.Text = text;
}
private static void RemoveSearchedDeviceView()
{
- if (searchedDeviceView)
+ if (mSearchedDeviceView)
{
- mainView.Remove(searchedDeviceView);
- searchedDeviceView = null;
+ mMainView.Remove(mSearchedDeviceView);
+ mSearchedDeviceView = null;
}
- if (scanButton)
+ if (mScanButton)
{
- mainView.Remove(scanButton);
- scanButton = null;
+ mMainView.Remove(mScanButton);
+ mScanButton = null;
}
}
{
RemoveSearchedDeviceView();
- if (pairedDeviceView)
+ if (mPairedDeviceView)
{
- mainView.Remove(pairedDeviceView);
- pairedDeviceView = null;
+ mMainView.Remove(mPairedDeviceView);
+ mPairedDeviceView = null;
}
}
case BtOperationState.Deactivating:
break;
case BtOperationState.Activated:
- if (pairedDeviceView == null && searchedDeviceView == null)
+ if (mPairedDeviceView == null && mSearchedDeviceView == null)
{
Log.Info(Program.LogTag, "Add initial view");
AddPairedDeviceView();
switch (ev.BtDevice.DeviceState)
{
case BtDeviceState.Idle:
- //if (searchedDevice.FindDevice("dummy searched device") != null)
+ //if (mSearchedDevice.FindDevice("dummy searched device") != null)
//{
- // searchedDevice.RemoveDevice("dummy searched device");
+ // mSearchedDevice.RemoveDevice("dummy searched device");
//}
if (ev.BtDevice.IsPaired)
{
- pairedDevice.AddDevice(ev.BtDevice);
+ mPairedDevice.AddDevice(ev.BtDevice);
}
else
{
- searchedDevice.AddDevice(ev.BtDevice);
+ mSearchedDevice.AddDevice(ev.BtDevice);
}
break;
case BtDeviceState.Pairing:
break;
case BtDeviceState.Unpairing:
- //pairedDevice.RemoveDevice(ev.BtDevice.Address);
+ //mPairedDevice.RemoveDevice(ev.BtDevice.Address);
break;
case BtDeviceState.Paired:
- //if (pairedDevice.FindDevice("dummy paired device") != null)
+ //if (mPairedDevice.FindDevice("dummy paired device") != null)
//{
- // pairedDevice.RemoveDevice("dummy paired device");
+ // mPairedDevice.RemoveDevice("dummy paired device");
//}
- if (searchedDevice.FindDevice(ev.BtDevice.Address) != null)
+ if (mSearchedDevice.FindDevice(ev.BtDevice.Address) != null)
{
- searchedDevice.RemoveDevice(ev.BtDevice.Address);
+ mSearchedDevice.RemoveDevice(ev.BtDevice.Address);
}
- if (pairedDevice.FindDevice(ev.BtDevice.Address) == null)
+ if (mPairedDevice.FindDevice(ev.BtDevice.Address) == null)
{
- pairedDevice.AddDevice(ev.BtDevice);
+ mPairedDevice.AddDevice(ev.BtDevice);
}
break;
case BtDeviceState.Unpaired:
- if (searchedDevice.FindDevice(ev.BtDevice.Address) == null)
+ if (mSearchedDevice.FindDevice(ev.BtDevice.Address) == null)
{
- searchedDevice.AddDevice(ev.BtDevice);
+ mSearchedDevice.AddDevice(ev.BtDevice);
}
- if (pairedDevice.FindDevice(ev.BtDevice.Address) != null)
+ if (mPairedDevice.FindDevice(ev.BtDevice.Address) != null)
{
- pairedDevice.RemoveDevice(ev.BtDevice.Address);
+ mPairedDevice.RemoveDevice(ev.BtDevice.Address);
}
break;
case BtDeviceState.Connecting:
Title = Resources.IDS_BT_BODY_BLUETOOTH,
};
- mainView = new View()
+ mMainView = new View()
{
Layout = new LinearLayout()
{
};
onOffSwitch.SelectedChanged += AdapterController.OnOffSwitchSelectedChanged;
onOffItem.Extra = onOffSwitch;
- mainView.Add(onOffItem);
+ mMainView.Add(onOffItem);
BtModel.OperationStateChanged += BtModelOperationStateChanged;
BtModel.DeviceChanged += BtModelDeviceChanged;
- mainPage = new ContentPage()
+ mMainPage = new ContentPage()
{
AppBar = appBar,
- Content = mainView,
+ Content = mMainView,
};
- window.GetDefaultNavigator().Push(mainPage);
+ window.GetDefaultNavigator().Push(mMainPage);
}
}
}