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

Side by Side 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, 11 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chromoting; 5 package org.chromium.chromoting;
6 6
7 import android.accounts.Account; 7 import android.accounts.Account;
8 import android.accounts.AccountManager; 8 import android.accounts.AccountManager;
9 import android.accounts.AccountManagerCallback; 9 import android.accounts.AccountManagerCallback;
10 import android.accounts.AccountManagerFuture; 10 import android.accounts.AccountManagerFuture;
11 import android.accounts.AuthenticatorException; 11 import android.accounts.AuthenticatorException;
12 import android.accounts.OperationCanceledException; 12 import android.accounts.OperationCanceledException;
13 import android.app.Activity; 13 import android.app.Activity;
14 import android.app.ProgressDialog;
15 import android.content.DialogInterface;
14 import android.content.Intent; 16 import android.content.Intent;
15 import android.content.SharedPreferences; 17 import android.content.SharedPreferences;
16 import android.os.Bundle; 18 import android.os.Bundle;
17 import android.os.Handler; 19 import android.os.Handler;
18 import android.os.HandlerThread; 20 import android.os.HandlerThread;
19 import android.util.Log; 21 import android.util.Log;
20 import android.view.Menu; 22 import android.view.Menu;
21 import android.view.MenuItem; 23 import android.view.MenuItem;
22 import android.widget.ArrayAdapter; 24 import android.widget.ArrayAdapter;
23 import android.widget.ListView; 25 import android.widget.ListView;
24 import android.widget.TextView; 26 import android.widget.TextView;
25 import android.widget.Toast; 27 import android.widget.Toast;
26 28
27 import org.chromium.chromoting.jni.JniInterface; 29 import org.chromium.chromoting.jni.JniInterface;
28 import org.json.JSONArray; 30 import org.json.JSONArray;
29 import org.json.JSONException; 31 import org.json.JSONException;
30 import org.json.JSONObject; 32 import org.json.JSONObject;
31 33
32 import java.io.IOException; 34 import java.io.IOException;
33 import java.net.URL; 35 import java.net.URL;
34 import java.net.URLConnection; 36 import java.net.URLConnection;
35 import java.util.Scanner; 37 import java.util.Scanner;
36 38
37 /** 39 /**
38 * The user interface for querying and displaying a user's host list from the di rectory server. It 40 * The user interface for querying and displaying a user's host list from the di rectory server. It
39 * also requests and renews authentication tokens using the system account manag er. 41 * also requests and renews authentication tokens using the system account manag er.
40 */ 42 */
41 public class Chromoting extends Activity { 43 public class Chromoting extends Activity implements JniInterface.ConnectionListe ner {
42 /** Only accounts of this type will be selectable for authentication. */ 44 /** Only accounts of this type will be selectable for authentication. */
43 private static final String ACCOUNT_TYPE = "com.google"; 45 private static final String ACCOUNT_TYPE = "com.google";
44 46
45 /** Scopes at which the authentication token we request will be valid. */ 47 /** Scopes at which the authentication token we request will be valid. */
46 private static final String TOKEN_SCOPE = "oauth2:https://www.googleapis.com /auth/chromoting " + 48 private static final String TOKEN_SCOPE = "oauth2:https://www.googleapis.com /auth/chromoting " +
47 "https://www.googleapis.com/auth/googletalk"; 49 "https://www.googleapis.com/auth/googletalk";
48 50
49 /** Path from which to download a user's host list JSON object. */ 51 /** Path from which to download a user's host list JSON object. */
50 private static final String HOST_LIST_PATH = 52 private static final String HOST_LIST_PATH =
51 "https://www.googleapis.com/chromoting/v1/@me/hosts?key="; 53 "https://www.googleapis.com/chromoting/v1/@me/hosts?key=";
(...skipping 19 matching lines...) Expand all
71 73
72 /** Greeting at the top of the displayed list. */ 74 /** Greeting at the top of the displayed list. */
73 private TextView mGreeting; 75 private TextView mGreeting;
74 76
75 /** Host list as it appears to the user. */ 77 /** Host list as it appears to the user. */
76 private ListView mList; 78 private ListView mList;
77 79
78 /** Callback handler to be used for network operations. */ 80 /** Callback handler to be used for network operations. */
79 private Handler mNetwork; 81 private Handler mNetwork;
80 82
83 /** Dialog for reporting connection progress. */
84 private ProgressDialog mProgressIndicator;
85
81 /** 86 /**
82 * Called when the activity is first created. Loads the native library and r equests an 87 * Called when the activity is first created. Loads the native library and r equests an
83 * authentication token from the system. 88 * authentication token from the system.
84 */ 89 */
85 @Override 90 @Override
86 public void onCreate(Bundle savedInstanceState) { 91 public void onCreate(Bundle savedInstanceState) {
87 super.onCreate(savedInstanceState); 92 super.onCreate(savedInstanceState);
88 setContentView(R.layout.main); 93 setContentView(R.layout.main);
89 94
90 // Get ahold of our view widgets. 95 // Get ahold of our view widgets.
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 } 185 }
181 186
182 return true; 187 return true;
183 } 188 }
184 189
185 /** Called when the user taps on a host entry. */ 190 /** Called when the user taps on a host entry. */
186 public void connectToHost(JSONObject host) { 191 public void connectToHost(JSONObject host) {
187 try { 192 try {
188 synchronized (mLock) { 193 synchronized (mLock) {
189 JniInterface.connectToHost(mAccount.name, mToken, host.getString ("jabberId"), 194 JniInterface.connectToHost(mAccount.name, mToken, host.getString ("jabberId"),
190 host.getString("hostId"), host.getString("publicKey"), 195 host.getString("hostId"), host.getString("publicKey"), t his);
191 new Runnable() {
192 @Override
193 public void run() {
194 startActivity(new Intent(Chromoting.this, De sktop.class));
195 }
196 });
197 } 196 }
198 } catch (JSONException ex) { 197 } catch (JSONException ex) {
199 Log.w("host", ex); 198 Log.w("host", ex);
200 Toast.makeText(this, getString(R.string.error_reading_host), 199 Toast.makeText(this, getString(R.string.error_reading_host),
201 Toast.LENGTH_LONG).show(); 200 Toast.LENGTH_LONG).show();
202 // Close the application. 201 // Close the application.
203 finish(); 202 finish();
204 } 203 }
205 } 204 }
206 205
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 mList.setAdapter(displayer); 355 mList.setAdapter(displayer);
357 } catch (JSONException ex) { 356 } catch (JSONException ex) {
358 Log.w("hostlist", ex); 357 Log.w("hostlist", ex);
359 Toast.makeText(this, getString(R.string.error_cataloging_hosts), 358 Toast.makeText(this, getString(R.string.error_cataloging_hosts),
360 Toast.LENGTH_LONG).show(); 359 Toast.LENGTH_LONG).show();
361 360
362 // Close the application. 361 // Close the application.
363 finish(); 362 finish();
364 } 363 }
365 } 364 }
365
366 @Override
367 public void onConnectionState(int state, int error) {
368 String stateText = getResources().getStringArray(R.array.protoc_states)[ state];
369 boolean dismissProgress = false;
370 switch (state) {
371 case JniInterface.ConnectionListener.STATE_INITIALIZING:
372 case JniInterface.ConnectionListener.STATE_CONNECTING:
373 case JniInterface.ConnectionListener.STATE_AUTHENTICATED:
374 // The connection is still being established, so we'll report th e current progress.
375 if (mProgressIndicator == null) {
376 mProgressIndicator = ProgressDialog.show(this,
377 getString(R.string.progress_title), stateText, true, true,
378 new DialogInterface.OnCancelListener() {
379 @Override
380 public void onCancel(DialogInterface dialog) {
381 JniInterface.disconnectFromHost();
382 }
383 });
384 } else {
385 mProgressIndicator.setMessage(stateText);
386 }
387 break;
388
389 case JniInterface.ConnectionListener.STATE_CONNECTED:
390 dismissProgress = true;
391 Toast.makeText(this, stateText, Toast.LENGTH_SHORT).show();
392
393 // Display the remote desktop.
394 startActivityForResult(new Intent(this, Desktop.class), 0);
395 break;
396
397 case JniInterface.ConnectionListener.STATE_FAILED:
398 dismissProgress = true;
399 Toast.makeText(this, stateText + ": "
Sergey Ulanov 2014/01/08 20:30:45 Appending localized string is wrong - it may not w
400 + getResources().getStringArray(R.array.protoc_errors)[e rror],
401 Toast.LENGTH_LONG).show();
402
403 // Close the Desktop view, if it is currently running.
404 finishActivity(0);
405 break;
406
407 case JniInterface.ConnectionListener.STATE_CLOSED:
408 // No need to show toast in this case. Either the connection wil l have failed
409 // because of an error, which will trigger toast already. Or the disconnection will
410 // have been initiated by the user.
411 dismissProgress = true;
412 finishActivity(0);
413 break;
414
415 default:
416 Log.e("connection", "Unexpected connection state.");
417 break;
418 }
419
420 if (dismissProgress && mProgressIndicator != null) {
421 mProgressIndicator.dismiss();
422 mProgressIndicator = null;
423 }
424 }
366 } 425 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698