|
@@ -29,10 +29,11 @@ import de.tudarmstadt.informatik.hostage.sync.SyncMessage;
|
|
|
|
|
|
public class BluetoothSync extends Activity{
|
|
|
|
|
|
- public static final int CONNECTION_ESTABLISHED = 0x0;
|
|
|
- public static final int CONNECTION_FAILED = 0x1;
|
|
|
- public static final int SYNC_SUCCESSFUL = 0x2;
|
|
|
- public static final int SYNC_FAILED = 0x3;
|
|
|
+ public static final int CONNECTING = 0x0;
|
|
|
+ public static final int CONNECTION_ESTABLISHED = 0x1;
|
|
|
+ public static final int CONNECTION_FAILED = 0x2;
|
|
|
+ public static final int SYNC_SUCCESSFUL = 0x3;
|
|
|
+ public static final int SYNC_FAILED = 0x4;
|
|
|
|
|
|
public static UUID serviceUUID;
|
|
|
|
|
@@ -111,14 +112,10 @@ public class BluetoothSync extends Activity{
|
|
|
}
|
|
|
|
|
|
|
|
|
- private void manageConnectedSocket(BluetoothSocket socket) {
|
|
|
+ protected void manageConnectedSocket(BluetoothSocket socket) {
|
|
|
mBluetoothAdapter.cancelDiscovery();
|
|
|
unregisterBroadcastReceiver();
|
|
|
|
|
|
- layout.removeView(listView);
|
|
|
- String deviceName = socket.getRemoteDevice().getName();
|
|
|
- mInfoText.setText("Synchronizing with " + deviceName + "...");
|
|
|
-
|
|
|
HostageDBOpenHelper dbh = new HostageDBOpenHelper(this);
|
|
|
commThread = new CommunicationThread(this, socket, mHandler);
|
|
|
commThread.start();
|
|
@@ -180,6 +177,8 @@ public class BluetoothSync extends Activity{
|
|
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
|
|
String deviceInfo = arrayAdapter.getItem(position);
|
|
|
String mac = deviceInfo.substring(deviceInfo.indexOf("\n") + 1);
|
|
|
+ String name = deviceInfo.substring(0, deviceInfo.indexOf("\n"));
|
|
|
+ mHandler.obtainMessage(CONNECTING, name).sendToTarget();
|
|
|
clientThread = new ClientThread(mBluetoothAdapter.getRemoteDevice(mac), mHandler);
|
|
|
clientThread.start();
|
|
|
}
|
|
@@ -191,11 +190,19 @@ public class BluetoothSync extends Activity{
|
|
|
@Override
|
|
|
public void handleMessage(Message msg) {
|
|
|
switch(msg.what){
|
|
|
+ case CONNECTING:
|
|
|
+ layout.removeView(listView);
|
|
|
+ mInfoText.setText("Connecting to " + (String)msg.obj + "!");
|
|
|
+ break;
|
|
|
case CONNECTION_ESTABLISHED:
|
|
|
- manageConnectedSocket((BluetoothSocket) msg.obj);
|
|
|
+ BluetoothSocket socket = (BluetoothSocket) msg.obj;
|
|
|
+ layout.removeView(listView);
|
|
|
+ String deviceName = socket.getRemoteDevice().getName();
|
|
|
+ mInfoText.setText("Synchronizing with " + deviceName + "...");
|
|
|
+ manageConnectedSocket(socket);
|
|
|
break;
|
|
|
case CONNECTION_FAILED:
|
|
|
- mInfoText.setText("Synchronization failed!");
|
|
|
+ mInfoText.setText("Failed to connect to device!");
|
|
|
break;
|
|
|
case SYNC_SUCCESSFUL:
|
|
|
mInfoText.setText("Synchronization successfull!");
|