|
@@ -8,7 +8,6 @@ import android.content.DialogInterface;
|
|
import android.content.Intent;
|
|
import android.content.Intent;
|
|
import android.net.wifi.p2p.WifiP2pDevice;
|
|
import android.net.wifi.p2p.WifiP2pDevice;
|
|
import android.net.wifi.p2p.WifiP2pInfo;
|
|
import android.net.wifi.p2p.WifiP2pInfo;
|
|
-import android.os.AsyncTask;
|
|
|
|
import android.os.Bundle;
|
|
import android.os.Bundle;
|
|
import android.provider.Settings;
|
|
import android.provider.Settings;
|
|
import android.util.Log;
|
|
import android.util.Log;
|
|
@@ -50,8 +49,9 @@ public class WiFiP2pSyncActivity extends Activity implements AdapterView.OnItemC
|
|
public static String PERFORMING_TASK_AS_CLIENT = MainActivity.getContext().getString(R.string.PERFORMING_TASK_AS_CLIENT);//"Acting as Client.";
|
|
public static String PERFORMING_TASK_AS_CLIENT = MainActivity.getContext().getString(R.string.PERFORMING_TASK_AS_CLIENT);//"Acting as Client.";
|
|
|
|
|
|
public static String ACTIONBAR_TITLE =MainActivity.getContext().getString(R.string.ACTIONBAR_TITLE);// "WifiDirect Synchronization";
|
|
public static String ACTIONBAR_TITLE =MainActivity.getContext().getString(R.string.ACTIONBAR_TITLE);// "WifiDirect Synchronization";
|
|
- public static String PROGRESS_TITLE_LOADING =MainActivity.getContext().getString(R.string.PROGRESS_TITLE_LOADING);// "Loading...";
|
|
|
|
- public static String PROGRESS_TITLE_CONNECTING = MainActivity.getContext().getString(R.string.PROGRESS_TITLE_CONNECTING);//"Connecting...";
|
|
|
|
|
|
+ public static String PROGRESS_MESSAGE_LOADING =MainActivity.getContext().getString(R.string.PROGRESS_TITLE_LOADING);// "Loading...";
|
|
|
|
+ public static String PROGRESS_MESSAGE_CONNECTING = MainActivity.getContext().getString(R.string.PROGRESS_TITLE_CONNECTING);//"Connecting...";
|
|
|
|
+ public static String PROGRESS_TITLE_SYNC = MainActivity.getContext().getString(R.string.PROGRESS_TITLE_SYNC);//"Connecting...";
|
|
|
|
|
|
public static String DEVICE_STATUS_AVAILABLE =MainActivity.getContext().getString(R.string.DEVICE_STATUS_AVAILABLE);// "Available";
|
|
public static String DEVICE_STATUS_AVAILABLE =MainActivity.getContext().getString(R.string.DEVICE_STATUS_AVAILABLE);// "Available";
|
|
public static String DEVICE_STATUS_INVITED =MainActivity.getContext().getString(R.string.DEVICE_STATUS_INVITED);// "Invited";
|
|
public static String DEVICE_STATUS_INVITED =MainActivity.getContext().getString(R.string.DEVICE_STATUS_INVITED);// "Invited";
|
|
@@ -109,6 +109,11 @@ public class WiFiP2pSyncActivity extends Activity implements AdapterView.OnItemC
|
|
|
|
|
|
this.wifiEventHandler();
|
|
this.wifiEventHandler();
|
|
|
|
|
|
|
|
+ this.progressDialog = new ProgressDialog(this);
|
|
|
|
+ this.progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
|
|
|
|
+ this.progressDialog.setIndeterminate(true);
|
|
|
|
+ this.progressDialog.setTitle(PROGRESS_TITLE_SYNC);
|
|
|
|
+
|
|
setContentView(R.layout.activity_p2_psync);
|
|
setContentView(R.layout.activity_p2_psync);
|
|
|
|
|
|
assert getActionBar() != null;
|
|
assert getActionBar() != null;
|
|
@@ -206,12 +211,10 @@ public class WiFiP2pSyncActivity extends Activity implements AdapterView.OnItemC
|
|
public void didConnect(boolean isHost, WifiP2pInfo connectionInfo) {
|
|
public void didConnect(boolean isHost, WifiP2pInfo connectionInfo) {
|
|
Log.d("DEBUG_WiFiP2pSyncActivity", "Did connect");
|
|
Log.d("DEBUG_WiFiP2pSyncActivity", "Did connect");
|
|
|
|
|
|
- String progressTitle = PROGRESS_TITLE_LOADING;
|
|
|
|
- if (this.activity.progressDialog != null){
|
|
|
|
- this.activity.progressDialog.dismiss();
|
|
|
|
|
|
+ this.activity.progressDialog.setMessage(PROGRESS_MESSAGE_LOADING);
|
|
|
|
+ if (!this.activity.progressDialog.isShowing()){
|
|
|
|
+ this.activity.progressDialog.show();
|
|
}
|
|
}
|
|
- this.activity.progressDialog = ProgressDialog.show(activity, "", progressTitle);
|
|
|
|
-
|
|
|
|
|
|
|
|
this.activity.setHost(isHost);
|
|
this.activity.setHost(isHost);
|
|
if (isHost){
|
|
if (isHost){
|
|
@@ -245,7 +248,12 @@ public class WiFiP2pSyncActivity extends Activity implements AdapterView.OnItemC
|
|
Log.d("DEBUG_WiFiP2pSyncActivity", "Failed to disconnect");
|
|
Log.d("DEBUG_WiFiP2pSyncActivity", "Failed to disconnect");
|
|
//Toast.makeText(this.activity, "Could not disconnect with device. Retry.", Toast.LENGTH_LONG).show();
|
|
//Toast.makeText(this.activity, "Could not disconnect with device. Retry.", Toast.LENGTH_LONG).show();
|
|
// Other device did disconnect a while before.
|
|
// Other device did disconnect a while before.
|
|
- if (this.activity.progressDialog != null){
|
|
|
|
|
|
+ if (this.activity.progressDialog != null &&
|
|
|
|
+ ((this.activity.hostTask == null && this.activity.clientTask == null) ||
|
|
|
|
+ (this.activity.clientTask != null && this.activity.clientTask.isInterrupted()) ||
|
|
|
|
+ (this.activity.hostTask != null && this.activity.hostTask.isInterrupted()) ||
|
|
|
|
+ (this.activity.ownDevice == null && this.activity.ownDevice.status != WifiP2pDevice.CONNECTED)
|
|
|
|
+ )){
|
|
this.activity.progressDialog.dismiss();
|
|
this.activity.progressDialog.dismiss();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -306,14 +314,16 @@ public class WiFiP2pSyncActivity extends Activity implements AdapterView.OnItemC
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public void didFail() {
|
|
|
|
- Toast.makeText(this.activity, SYNCHRONIZATION_FAILED_MESSAGE, Toast.LENGTH_LONG).show();
|
|
|
|
|
|
+ public void didFail(String e) {
|
|
|
|
+ boolean hasMessage = ((e != null) && (e.length() > 0));
|
|
|
|
+ String message = hasMessage ? e : SYNCHRONIZATION_FAILED_MESSAGE;
|
|
|
|
+
|
|
|
|
+ Toast.makeText(this.activity, message, Toast.LENGTH_LONG).show();
|
|
this.activity.wifiEventHandler().disconnect();
|
|
this.activity.wifiEventHandler().disconnect();
|
|
if (this.activity.hostTask != null){
|
|
if (this.activity.hostTask != null){
|
|
this.activity.hostTask.setInterrupted(true);
|
|
this.activity.hostTask.setInterrupted(true);
|
|
this.activity.hostTask = null;
|
|
this.activity.hostTask = null;
|
|
}
|
|
}
|
|
- //this.activity.clientTask = null;
|
|
|
|
}
|
|
}
|
|
}.init(this);
|
|
}.init(this);
|
|
}
|
|
}
|
|
@@ -392,27 +402,10 @@ public class WiFiP2pSyncActivity extends Activity implements AdapterView.OnItemC
|
|
* @param device
|
|
* @param device
|
|
*/
|
|
*/
|
|
private void connectTo(WifiP2pDevice device){
|
|
private void connectTo(WifiP2pDevice device){
|
|
- String connectionTitle = PROGRESS_TITLE_CONNECTING;
|
|
|
|
if (device != null){
|
|
if (device != null){
|
|
- if (progressDialog == null){
|
|
|
|
- this.progressDialog = ProgressDialog.show(this, "", PROGRESS_TITLE_CONNECTING);
|
|
|
|
- } else {
|
|
|
|
- this.progressDialog.setTitle(PROGRESS_TITLE_CONNECTING);
|
|
|
|
- }
|
|
|
|
- new Thread()
|
|
|
|
- {
|
|
|
|
- public void run()
|
|
|
|
- {
|
|
|
|
- try
|
|
|
|
- {
|
|
|
|
- sleep(20);
|
|
|
|
- }
|
|
|
|
- catch (Exception e)
|
|
|
|
- {
|
|
|
|
- }
|
|
|
|
- progressDialog.setTitle(PROGRESS_TITLE_CONNECTING);
|
|
|
|
- }
|
|
|
|
- }.start();
|
|
|
|
|
|
+ this.progressDialog.setMessage(PROGRESS_MESSAGE_CONNECTING);
|
|
|
|
+ this.progressDialog.show();
|
|
|
|
+
|
|
mOtherDevice = device;
|
|
mOtherDevice = device;
|
|
this.wifiEventHandler().connect(device);
|
|
this.wifiEventHandler().connect(device);
|
|
|
|
|