Index: remoting/android/java/src/org/chromium/chromoting/Chromoting.java |
diff --git a/remoting/android/java/src/org/chromium/chromoting/Chromoting.java b/remoting/android/java/src/org/chromium/chromoting/Chromoting.java |
index 264d8a2eab9e55ecc6636b4da0897c5ddec2d0aa..820d33d25ece911e1c9d10e658aca402e078b70b 100644 |
--- a/remoting/android/java/src/org/chromium/chromoting/Chromoting.java |
+++ b/remoting/android/java/src/org/chromium/chromoting/Chromoting.java |
@@ -11,6 +11,8 @@ import android.accounts.AccountManagerFuture; |
import android.accounts.AuthenticatorException; |
import android.accounts.OperationCanceledException; |
import android.app.Activity; |
+import android.app.ProgressDialog; |
+import android.content.DialogInterface; |
import android.content.Intent; |
import android.content.SharedPreferences; |
import android.os.Bundle; |
@@ -38,7 +40,7 @@ import java.util.Scanner; |
* The user interface for querying and displaying a user's host list from the directory server. It |
* also requests and renews authentication tokens using the system account manager. |
*/ |
-public class Chromoting extends Activity { |
+public class Chromoting extends Activity implements JniInterface.ConnectionListener { |
/** Only accounts of this type will be selectable for authentication. */ |
private static final String ACCOUNT_TYPE = "com.google"; |
@@ -78,6 +80,9 @@ public class Chromoting extends Activity { |
/** Callback handler to be used for network operations. */ |
private Handler mNetwork; |
+ /** Dialog for reporting connection progress. */ |
+ private ProgressDialog mProgressIndicator; |
+ |
/** |
* Called when the activity is first created. Loads the native library and requests an |
* authentication token from the system. |
@@ -187,13 +192,7 @@ public class Chromoting extends Activity { |
try { |
synchronized (mLock) { |
JniInterface.connectToHost(mAccount.name, mToken, host.getString("jabberId"), |
- host.getString("hostId"), host.getString("publicKey"), |
- new Runnable() { |
- @Override |
- public void run() { |
- startActivity(new Intent(Chromoting.this, Desktop.class)); |
- } |
- }); |
+ host.getString("hostId"), host.getString("publicKey"), this); |
} |
} catch (JSONException ex) { |
Log.w("host", ex); |
@@ -360,4 +359,46 @@ public class Chromoting extends Activity { |
finish(); |
} |
} |
+ |
+ @Override |
+ public void onConnectionState(int state, int error) { |
+ if (state < SUCCESSFUL_CONNECTION && error == 0) { |
Sergey Ulanov
2014/01/03 00:01:51
error is meaningful only when state==FAILED, so ch
Lambros
2014/01/04 01:59:46
Done.
|
+ // The connection is still being established, so we'll report the current progress. |
+ if (mProgressIndicator == null) { |
+ mProgressIndicator = ProgressDialog.show(this, getString(R.string.progress_title), |
+ getResources().getStringArray(R.array.protoc_states)[state], true, true, |
+ new DialogInterface.OnCancelListener() { |
+ @Override |
+ public void onCancel(DialogInterface dialog) { |
+ JniInterface.disconnectFromHost(); |
+ } |
+ }); |
+ } else { |
+ mProgressIndicator.setMessage( |
+ getResources().getStringArray(R.array.protoc_states)[state]); |
+ } |
+ } else { |
+ // The connection is complete or has failed, so we can lose the progress indicator. |
+ if (mProgressIndicator != null) { |
+ mProgressIndicator.dismiss(); |
+ mProgressIndicator = null; |
+ } |
+ |
+ if (state == SUCCESSFUL_CONNECTION) { |
+ Toast.makeText(this, getResources().getStringArray(R.array.protoc_states)[state], |
+ Toast.LENGTH_SHORT).show(); |
+ |
+ // Display the remote desktop. |
+ startActivityForResult(new Intent(this, Desktop.class), 0); |
+ } else { |
+ Toast.makeText(this, getResources().getStringArray(R.array.protoc_states)[state] |
+ + (error == 0 ? "" : ": " |
Sergey Ulanov
2014/01/03 00:01:51
no need to check error==0 here. error shouldn't be
Lambros
2014/01/04 01:59:46
Done.
|
+ + getResources().getStringArray(R.array.protoc_errors)[error]), |
+ Toast.LENGTH_LONG).show(); |
+ |
+ // Close the Desktop view, if it is currently running. |
+ finishActivity(0); |
+ } |
+ } |
+ } |
} |