Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Unified Diff: remoting/android/java/src/org/chromium/chromoting/Chromoting.java

Issue 105943010: Android Chromoting - Close the Desktop view on disconnection (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add enum constants to Java Created 6 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 520690d89d11f898185ca8553252b57496d9ae07..40b5253704806b896de1e4b605eba6973e08802b 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);
@@ -363,4 +362,64 @@ public class Chromoting extends Activity {
finish();
}
}
+
+ @Override
+ public void onConnectionState(int state, int error) {
+ String stateText = getResources().getStringArray(R.array.protoc_states)[state];
+ boolean dismissProgress = false;
+ switch (state) {
+ case JniInterface.ConnectionListener.STATE_INITIALIZING:
+ case JniInterface.ConnectionListener.STATE_CONNECTING:
+ case JniInterface.ConnectionListener.STATE_AUTHENTICATED:
+ // 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), stateText, true, true,
+ new DialogInterface.OnCancelListener() {
+ @Override
+ public void onCancel(DialogInterface dialog) {
+ JniInterface.disconnectFromHost();
+ }
+ });
+ } else {
+ mProgressIndicator.setMessage(stateText);
+ }
+ break;
+
+ case JniInterface.ConnectionListener.STATE_CONNECTED:
+ dismissProgress = true;
+ Toast.makeText(this, stateText, Toast.LENGTH_SHORT).show();
+
+ // Display the remote desktop.
+ startActivityForResult(new Intent(this, Desktop.class), 0);
+ break;
+
+ case JniInterface.ConnectionListener.STATE_FAILED:
+ dismissProgress = true;
+ Toast.makeText(this, stateText + ": "
Sergey Ulanov 2014/01/08 20:30:45 Appending localized string is wrong - it may not w
+ + getResources().getStringArray(R.array.protoc_errors)[error],
+ Toast.LENGTH_LONG).show();
+
+ // Close the Desktop view, if it is currently running.
+ finishActivity(0);
+ break;
+
+ case JniInterface.ConnectionListener.STATE_CLOSED:
+ // No need to show toast in this case. Either the connection will have failed
+ // because of an error, which will trigger toast already. Or the disconnection will
+ // have been initiated by the user.
+ dismissProgress = true;
+ finishActivity(0);
+ break;
+
+ default:
+ Log.e("connection", "Unexpected connection state.");
+ break;
+ }
+
+ if (dismissProgress && mProgressIndicator != null) {
+ mProgressIndicator.dismiss();
+ mProgressIndicator = null;
+ }
+ }
}

Powered by Google App Engine
This is Rietveld 408576698