Further improvements to connection and feedback.
Change-Id: I04c48ad3d465e132ea9adaf840e9f858a7096794
This commit is contained in:
@@ -25,7 +25,9 @@
|
|||||||
<string name="selector_noservers">Searching for computers…</string>
|
<string name="selector_noservers">Searching for computers…</string>
|
||||||
<string name="selector_delete">Remove server</string>
|
<string name="selector_delete">Remove server</string>
|
||||||
<string name="selector_choose_a_computer">Choose a Computer</string>
|
<string name="selector_choose_a_computer">Choose a Computer</string>
|
||||||
<string name="selector_dialog_connecting">Attempting to connect to {0}...</string>
|
<string name="selector_dialog_connecting">Attempting to connect to {0}…</string>
|
||||||
|
<string name="selector_dialog_connectionfailed">Impress Remote couldn"''"t connect to {0}.</string>
|
||||||
|
<string name="selector_dialog_connectionfailed_ok">OK</string>
|
||||||
<string name="pairing_instructions_1">In Impress, click on the "Slideshow" menu and select "Impress Remote".</string>
|
<string name="pairing_instructions_1">In Impress, click on the "Slideshow" menu and select "Impress Remote".</string>
|
||||||
<string name="pairing_instructions_2_deviceName">Choose \"{0}\" as your device.</string>
|
<string name="pairing_instructions_2_deviceName">Choose \"{0}\" as your device.</string>
|
||||||
<string name="pairing_instructions_3">Then input this PIN:</string>
|
<string name="pairing_instructions_3">Then input this PIN:</string>
|
||||||
|
@@ -10,38 +10,29 @@ package org.libreoffice.impressremote;
|
|||||||
|
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
|
|
||||||
import org.libreoffice.impressremote.communication.CommunicationService;
|
|
||||||
import org.libreoffice.impressremote.communication.CommunicationService.State;
|
|
||||||
|
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.ComponentName;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.content.ServiceConnection;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.IBinder;
|
|
||||||
import android.support.v4.content.LocalBroadcastManager;
|
import android.support.v4.content.LocalBroadcastManager;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.actionbarsherlock.app.SherlockActivity;
|
import com.actionbarsherlock.app.SherlockActivity;
|
||||||
|
|
||||||
public class PairingActivity extends SherlockActivity {
|
public class PairingActivity extends SherlockActivity {
|
||||||
private CommunicationService mCommunicationService;
|
|
||||||
private TextView mPinText;
|
|
||||||
private ActivityChangeBroadcastProcessor mBroadcastProcessor;
|
private ActivityChangeBroadcastProcessor mBroadcastProcessor;
|
||||||
|
|
||||||
/** Called when the activity is first created. */
|
/** Called when the activity is first created. */
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
mBroadcastProcessor = new ActivityChangeBroadcastProcessor(this);
|
|
||||||
bindService(new Intent(this, CommunicationService.class), mConnection,
|
|
||||||
Context.BIND_IMPORTANT);
|
|
||||||
|
|
||||||
IntentFilter aFilter = new IntentFilter(
|
setContentView(R.layout.activity_pairing);
|
||||||
CommunicationService.MSG_PAIRING_STARTED);
|
|
||||||
aFilter.addAction(CommunicationService.MSG_PAIRING_SUCCESSFUL);
|
mBroadcastProcessor = new ActivityChangeBroadcastProcessor(this);
|
||||||
|
|
||||||
|
IntentFilter aFilter = new IntentFilter();
|
||||||
|
|
||||||
mBroadcastProcessor = new ActivityChangeBroadcastProcessor(this);
|
mBroadcastProcessor = new ActivityChangeBroadcastProcessor(this);
|
||||||
mBroadcastProcessor.addToFilter(aFilter);
|
mBroadcastProcessor.addToFilter(aFilter);
|
||||||
@@ -51,66 +42,23 @@ public class PairingActivity extends SherlockActivity {
|
|||||||
|
|
||||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
|
|
||||||
}
|
String aPin = getIntent().getStringExtra("PIN");
|
||||||
|
String aServerName = getIntent().getStringExtra("SERVERNAME");
|
||||||
|
|
||||||
@Override
|
((TextView) findViewById(R.id.pairing_pin)).setText(aPin);
|
||||||
protected void onDestroy() {
|
|
||||||
super.onDestroy();
|
|
||||||
unbindService(mConnection);
|
|
||||||
}
|
|
||||||
|
|
||||||
private ServiceConnection mConnection = new ServiceConnection() {
|
|
||||||
@Override
|
|
||||||
public void onServiceConnected(ComponentName aClassName,
|
|
||||||
IBinder aService) {
|
|
||||||
setContentView(R.layout.activity_pairing);
|
|
||||||
mPinText = (TextView) findViewById(R.id.pairing_pin);
|
|
||||||
mCommunicationService = ((CommunicationService.CBinder) aService)
|
|
||||||
.getService();
|
|
||||||
((TextView) findViewById(R.id.pairing_instruction2_deviceName))
|
((TextView) findViewById(R.id.pairing_instruction2_deviceName))
|
||||||
.setText(MessageFormat
|
.setText(MessageFormat
|
||||||
.format(getResources()
|
.format(getResources()
|
||||||
.getString(R.string.pairing_instructions_2_deviceName),
|
.getString(R.string.pairing_instructions_2_deviceName),
|
||||||
CommunicationService
|
aServerName));
|
||||||
.getDeviceName()));
|
|
||||||
|
|
||||||
if (mCommunicationService.getState() == State.CONNECTING) {
|
getSupportActionBar().setTitle(aServerName);
|
||||||
mPinText.setText(mCommunicationService.getPairingPin());
|
|
||||||
getSupportActionBar().setTitle(
|
|
||||||
mCommunicationService.getPairingDeviceName());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onServiceDisconnected(ComponentName aClassName) {
|
|
||||||
mCommunicationService = null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private BroadcastReceiver mListener = new BroadcastReceiver() {
|
private BroadcastReceiver mListener = new BroadcastReceiver() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context aContext, Intent aIntent) {
|
public void onReceive(Context aContext, Intent aIntent) {
|
||||||
if (mCommunicationService == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (aIntent.getAction().equals(
|
|
||||||
CommunicationService.MSG_PAIRING_STARTED)) {
|
|
||||||
String aPin = aIntent.getStringExtra("PIN");
|
|
||||||
|
|
||||||
mPinText.setText(aPin);
|
|
||||||
if (mCommunicationService != null)
|
|
||||||
getSupportActionBar().setTitle(
|
|
||||||
mCommunicationService
|
|
||||||
.getPairingDeviceName());
|
|
||||||
// refreshLists();
|
|
||||||
} else if (aIntent.getAction().equals(
|
|
||||||
CommunicationService.MSG_PAIRING_SUCCESSFUL)) {
|
|
||||||
Intent nIntent = new Intent(PairingActivity.this,
|
|
||||||
StartPresentationActivity.class);
|
|
||||||
startActivity(nIntent);
|
|
||||||
}
|
|
||||||
mBroadcastProcessor.onReceive(aContext, aIntent);
|
mBroadcastProcessor.onReceive(aContext, aIntent);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@@ -23,6 +23,7 @@ import android.content.BroadcastReceiver;
|
|||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
|
import android.content.DialogInterface.OnCancelListener;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.content.ServiceConnection;
|
import android.content.ServiceConnection;
|
||||||
@@ -63,6 +64,7 @@ public class SelectorActivity extends SherlockActivity {
|
|||||||
|
|
||||||
IntentFilter aFilter = new IntentFilter(
|
IntentFilter aFilter = new IntentFilter(
|
||||||
CommunicationService.MSG_SERVERLIST_CHANGED);
|
CommunicationService.MSG_SERVERLIST_CHANGED);
|
||||||
|
aFilter.addAction(CommunicationService.STATUS_CONNECTION_FAILED);
|
||||||
|
|
||||||
mBroadcastProcessor = new ActivityChangeBroadcastProcessor(this);
|
mBroadcastProcessor = new ActivityChangeBroadcastProcessor(this);
|
||||||
mBroadcastProcessor.addToFilter(aFilter);
|
mBroadcastProcessor.addToFilter(aFilter);
|
||||||
@@ -204,6 +206,32 @@ public class SelectorActivity extends SherlockActivity {
|
|||||||
CommunicationService.MSG_SERVERLIST_CHANGED)) {
|
CommunicationService.MSG_SERVERLIST_CHANGED)) {
|
||||||
refreshLists();
|
refreshLists();
|
||||||
return;
|
return;
|
||||||
|
} else if (aIntent.getAction().equals(
|
||||||
|
CommunicationService.STATUS_CONNECTION_FAILED)) {
|
||||||
|
if (mProgressDialog != null) {
|
||||||
|
mProgressDialog.dismiss();
|
||||||
|
|
||||||
|
String aFormat = getResources().getString(
|
||||||
|
R.string.selector_dialog_connectionfailed);
|
||||||
|
String aDialogText = MessageFormat.format(aFormat,
|
||||||
|
mCommunicationService
|
||||||
|
.getPairingDeviceName());
|
||||||
|
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(
|
||||||
|
SelectorActivity.this);
|
||||||
|
builder.setMessage(aDialogText)
|
||||||
|
.setCancelable(false)
|
||||||
|
.setPositiveButton(
|
||||||
|
R.string.selector_dialog_connectionfailed_ok,
|
||||||
|
new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick(
|
||||||
|
DialogInterface dialog,
|
||||||
|
int id) {
|
||||||
|
dialog.dismiss();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
builder.show();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
mBroadcastProcessor.onReceive(aContext, aIntent);
|
mBroadcastProcessor.onReceive(aContext, aIntent);
|
||||||
|
|
||||||
@@ -318,9 +346,14 @@ public class SelectorActivity extends SherlockActivity {
|
|||||||
|
|
||||||
mProgressDialog = ProgressDialog.show(SelectorActivity.this,
|
mProgressDialog = ProgressDialog.show(SelectorActivity.this,
|
||||||
"", aDialogText, true);
|
"", aDialogText, true);
|
||||||
// Intent aIntent = new Intent(SelectorActivity.this,
|
mProgressDialog.setCancelable(true);
|
||||||
// PairingActivity.class);
|
mProgressDialog.setOnCancelListener(new OnCancelListener() {
|
||||||
// startActivity(aIntent);
|
|
||||||
|
@Override
|
||||||
|
public void onCancel(DialogInterface dialog) {
|
||||||
|
mCommunicationService.disconnect();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -9,6 +9,7 @@
|
|||||||
package org.libreoffice.impressremote.communication;
|
package org.libreoffice.impressremote.communication;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@@ -27,41 +28,33 @@ public class BluetoothClient extends Client {
|
|||||||
|
|
||||||
private boolean mBluetoothWasEnabled;
|
private boolean mBluetoothWasEnabled;
|
||||||
private BluetoothAdapter mAdapter;
|
private BluetoothAdapter mAdapter;
|
||||||
|
private BluetoothSocket mSocket;
|
||||||
|
|
||||||
public BluetoothClient(Server aServer,
|
public BluetoothClient(Server aServer,
|
||||||
CommunicationService aCommunicationService,
|
CommunicationService aCommunicationService,
|
||||||
Receiver aReceiver, boolean aBluetoothWasEnabled) {
|
Receiver aReceiver, boolean aBluetoothWasEnabled)
|
||||||
|
throws IOException {
|
||||||
super(aServer, aCommunicationService, aReceiver);
|
super(aServer, aCommunicationService, aReceiver);
|
||||||
try {
|
|
||||||
mAdapter = BluetoothAdapter.getDefaultAdapter();
|
mAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||||
mBluetoothWasEnabled = aBluetoothWasEnabled;
|
mBluetoothWasEnabled = aBluetoothWasEnabled;
|
||||||
if (!mBluetoothWasEnabled) {
|
if (!mBluetoothWasEnabled) {
|
||||||
mAdapter.enable();
|
mAdapter.enable();
|
||||||
}
|
}
|
||||||
|
|
||||||
BluetoothDevice aDevice = mAdapter.getRemoteDevice(aServer
|
BluetoothDevice aDevice = mAdapter
|
||||||
.getAddress());
|
.getRemoteDevice(aServer.getAddress());
|
||||||
mAdapter.cancelDiscovery();
|
mAdapter.cancelDiscovery();
|
||||||
BluetoothSocket aSocket = aDevice
|
mSocket = aDevice.createRfcommSocketToServiceRecord(UUID
|
||||||
.createRfcommSocketToServiceRecord(UUID
|
|
||||||
.fromString("00001101-0000-1000-8000-00805F9B34FB"));
|
.fromString("00001101-0000-1000-8000-00805F9B34FB"));
|
||||||
aSocket.connect();
|
mSocket.connect();
|
||||||
// mSocket = aSocket;
|
// mSocket = aSocket;
|
||||||
System.out.println("Connected");
|
System.out.println("Connected");
|
||||||
|
|
||||||
mInputStream = aSocket.getInputStream();
|
mInputStream = mSocket.getInputStream();
|
||||||
mReader = new BufferedReader(new InputStreamReader(mInputStream,
|
mReader = new BufferedReader(new InputStreamReader(mInputStream,
|
||||||
CHARSET));
|
CHARSET));
|
||||||
mOutputStream = aSocket.getOutputStream();
|
mOutputStream = mSocket.getOutputStream();
|
||||||
|
|
||||||
// mOutputStream.write(20);
|
|
||||||
// mOutputStream.write(20);
|
|
||||||
// mOutputStream.write(20);
|
|
||||||
// mOutputStream.flush();
|
|
||||||
// System.out.println("reading");
|
|
||||||
// while (true) {
|
|
||||||
// System.out.println(mInputStream.read());
|
|
||||||
// }
|
|
||||||
String aTemp = mReader.readLine();
|
String aTemp = mReader.readLine();
|
||||||
System.out.println("SF:waited");
|
System.out.println("SF:waited");
|
||||||
if (!aTemp.equals("LO_SERVER_SERVER_PAIRED")) {
|
if (!aTemp.equals("LO_SERVER_SERVER_PAIRED")) {
|
||||||
@@ -70,58 +63,22 @@ public class BluetoothClient extends Client {
|
|||||||
while (mReader.readLine().length() != 0) {
|
while (mReader.readLine().length() != 0) {
|
||||||
// Get rid of extra lines
|
// Get rid of extra lines
|
||||||
}
|
}
|
||||||
Intent aIntent = new Intent(
|
Intent aIntent = new Intent(CommunicationService.MSG_PAIRING_SUCCESSFUL);
|
||||||
CommunicationService.MSG_PAIRING_SUCCESSFUL);
|
LocalBroadcastManager.getInstance(mCommunicationService).sendBroadcast(
|
||||||
LocalBroadcastManager.getInstance(mCommunicationService)
|
aIntent);
|
||||||
.sendBroadcast(aIntent);
|
|
||||||
startListening();
|
startListening();
|
||||||
// Pairing.
|
|
||||||
// Random aRandom = new Random();
|
|
||||||
// String aPin = "" + (aRandom.nextInt(9000) + 1000);
|
|
||||||
// while (aPin.length() < 4) {
|
|
||||||
// aPin = "0" + aPin; // Add leading zeros if necessary
|
|
||||||
// }
|
|
||||||
// Intent aIntent = new Intent(
|
|
||||||
// CommunicationService.MSG_PAIRING_STARTED);
|
|
||||||
// aIntent.putExtra("PIN", aPin);
|
|
||||||
// mPin = aPin;
|
|
||||||
// LocalBroadcastManager.getInstance(mContext).sendBroadcast(aIntent);
|
|
||||||
// // Send out
|
|
||||||
// String aName = CommunicationService.getDeviceName(); // TODO: get the proper name
|
|
||||||
// sendCommand("LO_SERVER_CLIENT_PAIR\n" + aName + "\n" + aPin
|
|
||||||
// + "\n\n");
|
|
||||||
//
|
|
||||||
// // Wait until we get the appropriate string back...
|
|
||||||
// System.out.println("SF:waiting");
|
|
||||||
// String aTemp = mReader.readLine();
|
|
||||||
// System.out.println("SF:waited");
|
|
||||||
// if (!aTemp.equals("LO_SERVER_SERVER_PAIRED")) {
|
|
||||||
// return;
|
|
||||||
// } else {
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
// while (mReader.readLine().length() != 0) {
|
|
||||||
// // Get rid of extra lines
|
|
||||||
// System.out.println("SF: empty line");
|
|
||||||
// }
|
|
||||||
// System.out.println("SD: empty");
|
|
||||||
// startListening();
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void closeConnection() {
|
public void closeConnection() {
|
||||||
// try {
|
try {
|
||||||
// if (mSocket != null)
|
if (mSocket != null)
|
||||||
// mSocket.close();
|
mSocket.close();
|
||||||
// } catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// // TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
// e.printStackTrace();
|
e.printStackTrace();
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onDisconnect() {
|
protected void onDisconnect() {
|
||||||
|
@@ -8,6 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.libreoffice.impressremote.communication;
|
package org.libreoffice.impressremote.communication;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -22,6 +23,7 @@ import android.content.SharedPreferences;
|
|||||||
import android.content.SharedPreferences.Editor;
|
import android.content.SharedPreferences.Editor;
|
||||||
import android.os.Binder;
|
import android.os.Binder;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
|
import android.support.v4.content.LocalBroadcastManager;
|
||||||
|
|
||||||
public class CommunicationService extends Service implements Runnable {
|
public class CommunicationService extends Service implements Runnable {
|
||||||
|
|
||||||
@@ -88,17 +90,28 @@ public class CommunicationService extends Service implements Runnable {
|
|||||||
}
|
}
|
||||||
if (mStateDesired == State.CONNECTED) {
|
if (mStateDesired == State.CONNECTED) {
|
||||||
mState = State.CONNECTING;
|
mState = State.CONNECTING;
|
||||||
|
try {
|
||||||
switch (mServerDesired.getProtocol()) {
|
switch (mServerDesired.getProtocol()) {
|
||||||
case NETWORK:
|
case NETWORK:
|
||||||
mClient = new NetworkClient(mServerDesired, this,
|
mClient = new NetworkClient(mServerDesired,
|
||||||
mReceiver);
|
this, mReceiver);
|
||||||
break;
|
break;
|
||||||
case BLUETOOTH:
|
case BLUETOOTH:
|
||||||
mClient = new BluetoothClient(mServerDesired, this,
|
mClient = new BluetoothClient(mServerDesired,
|
||||||
mReceiver,
|
this, mReceiver,
|
||||||
mBluetoothPreviouslyEnabled);
|
mBluetoothPreviouslyEnabled);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
mClient = null;
|
||||||
|
mState = State.DISCONNECTED;
|
||||||
|
Intent aIntent = new Intent(
|
||||||
|
CommunicationService.STATUS_CONNECTION_FAILED);
|
||||||
|
LocalBroadcastManager.getInstance(this)
|
||||||
|
.sendBroadcast(aIntent);
|
||||||
|
return;
|
||||||
|
}
|
||||||
mTransmitter = new Transmitter(mClient);
|
mTransmitter = new Transmitter(mClient);
|
||||||
mState = State.CONNECTED;
|
mState = State.CONNECTED;
|
||||||
}
|
}
|
||||||
@@ -194,6 +207,8 @@ public class CommunicationService extends Service implements Runnable {
|
|||||||
|
|
||||||
public static final String STATUS_PAIRING_PINVALIDATION = "STATUS_PAIRING_PINVALIDATION";
|
public static final String STATUS_PAIRING_PINVALIDATION = "STATUS_PAIRING_PINVALIDATION";
|
||||||
|
|
||||||
|
public static final String STATUS_CONNECTION_FAILED = "STATUS_CONNECTION_FAILED";
|
||||||
|
|
||||||
private Transmitter mTransmitter;
|
private Transmitter mTransmitter;
|
||||||
|
|
||||||
private Client mClient;
|
private Client mClient;
|
||||||
|
@@ -33,9 +33,9 @@ public class NetworkClient extends Client {
|
|||||||
|
|
||||||
public NetworkClient(Server aServer,
|
public NetworkClient(Server aServer,
|
||||||
CommunicationService aCommunicationService,
|
CommunicationService aCommunicationService,
|
||||||
Receiver aReceiver) {
|
Receiver aReceiver) throws UnknownHostException,
|
||||||
|
IOException {
|
||||||
super(aServer, aCommunicationService, aReceiver);
|
super(aServer, aCommunicationService, aReceiver);
|
||||||
try {
|
|
||||||
mName = aServer.getName();
|
mName = aServer.getName();
|
||||||
mSocket = new Socket(aServer.getAddress(), PORT);
|
mSocket = new Socket(aServer.getAddress(), PORT);
|
||||||
mInputStream = mSocket.getInputStream();
|
mInputStream = mSocket.getInputStream();
|
||||||
@@ -44,16 +44,14 @@ public class NetworkClient extends Client {
|
|||||||
mOutputStream = mSocket.getOutputStream();
|
mOutputStream = mSocket.getOutputStream();
|
||||||
// Pairing.
|
// Pairing.
|
||||||
String aPin = setupPin(aServer);
|
String aPin = setupPin(aServer);
|
||||||
Intent aIntent = new Intent(
|
Intent aIntent = new Intent(CommunicationService.MSG_PAIRING_STARTED);
|
||||||
CommunicationService.MSG_PAIRING_STARTED);
|
|
||||||
aIntent.putExtra("PIN", aPin);
|
aIntent.putExtra("PIN", aPin);
|
||||||
mPin = aPin;
|
mPin = aPin;
|
||||||
LocalBroadcastManager.getInstance(mCommunicationService)
|
LocalBroadcastManager.getInstance(mCommunicationService).sendBroadcast(
|
||||||
.sendBroadcast(aIntent);
|
aIntent);
|
||||||
// Send out
|
// Send out
|
||||||
String aName = CommunicationService.getDeviceName(); // TODO: get the proper name
|
String aName = CommunicationService.getDeviceName(); // TODO: get the proper name
|
||||||
sendCommand("LO_SERVER_CLIENT_PAIR\n" + aName + "\n" + aPin
|
sendCommand("LO_SERVER_CLIENT_PAIR\n" + aName + "\n" + aPin + "\n\n");
|
||||||
+ "\n\n");
|
|
||||||
|
|
||||||
// Wait until we get the appropriate string back...
|
// Wait until we get the appropriate string back...
|
||||||
String aTemp = mReader.readLine();
|
String aTemp = mReader.readLine();
|
||||||
@@ -64,6 +62,7 @@ public class NetworkClient extends Client {
|
|||||||
aIntent = new Intent(
|
aIntent = new Intent(
|
||||||
CommunicationService.STATUS_PAIRING_PINVALIDATION);
|
CommunicationService.STATUS_PAIRING_PINVALIDATION);
|
||||||
aIntent.putExtra("PIN", aPin);
|
aIntent.putExtra("PIN", aPin);
|
||||||
|
aIntent.putExtra("SERVERNAME", aServer.getName());
|
||||||
mPin = aPin;
|
mPin = aPin;
|
||||||
LocalBroadcastManager.getInstance(mCommunicationService)
|
LocalBroadcastManager.getInstance(mCommunicationService)
|
||||||
.sendBroadcast(aIntent);
|
.sendBroadcast(aIntent);
|
||||||
@@ -77,8 +76,8 @@ public class NetworkClient extends Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
aIntent = new Intent(CommunicationService.MSG_PAIRING_SUCCESSFUL);
|
aIntent = new Intent(CommunicationService.MSG_PAIRING_SUCCESSFUL);
|
||||||
LocalBroadcastManager.getInstance(mCommunicationService)
|
LocalBroadcastManager.getInstance(mCommunicationService).sendBroadcast(
|
||||||
.sendBroadcast(aIntent);
|
aIntent);
|
||||||
|
|
||||||
while (mReader.readLine().length() != 0) {
|
while (mReader.readLine().length() != 0) {
|
||||||
// Get rid of extra lines
|
// Get rid of extra lines
|
||||||
@@ -86,13 +85,6 @@ public class NetworkClient extends Client {
|
|||||||
}
|
}
|
||||||
System.out.println("SD: empty");
|
System.out.println("SD: empty");
|
||||||
startListening();
|
startListening();
|
||||||
} catch (UnknownHostException e) {
|
|
||||||
// TODO Tell the user we have a problem
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IOException e) {
|
|
||||||
// TODO As above
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user