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

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: Use Java enum for state/error codes 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
« no previous file with comments | « no previous file | remoting/android/java/src/org/chromium/chromoting/jni/JniInterface.java » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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(JniInterface.ConnectionListener.State state,
368 JniInterface.ConnectionListener.Error error) {
369 String stateText = getResources().getStringArray(R.array.protoc_states)[ state.value()];
370 boolean dismissProgress = false;
371 switch (state) {
372 case INITIALIZING:
373 case CONNECTING:
374 case AUTHENTICATED:
375 // The connection is still being established, so we'll report th e current progress.
376 if (mProgressIndicator == null) {
377 mProgressIndicator = ProgressDialog.show(this,
378 getString(R.string.progress_title), stateText, true, true,
379 new DialogInterface.OnCancelListener() {
380 @Override
381 public void onCancel(DialogInterface dialog) {
382 JniInterface.disconnectFromHost();
383 }
384 });
385 } else {
386 mProgressIndicator.setMessage(stateText);
387 }
388 break;
389
390 case CONNECTED:
391 dismissProgress = true;
392 Toast.makeText(this, stateText, Toast.LENGTH_SHORT).show();
393
394 // Display the remote desktop.
395 startActivityForResult(new Intent(this, Desktop.class), 0);
396 break;
397
398 case FAILED:
399 dismissProgress = true;
400 Toast.makeText(this, stateText + ": "
401 + getResources().getStringArray(R.array.protoc_errors)[e rror.value()],
402 Toast.LENGTH_LONG).show();
403
404 // Close the Desktop view, if it is currently running.
405 finishActivity(0);
406 break;
407
408 case CLOSED:
409 // No need to show toast in this case. Either the connection wil l have failed
410 // because of an error, which will trigger toast already. Or the disconnection will
411 // have been initiated by the user.
412 dismissProgress = true;
413 finishActivity(0);
414 break;
415 }
frankf 2014/01/10 18:31:05 fidnbugs step on FYI bot is complaining about defa
phoglund_chromium 2014/01/13 16:19:49 +1: please fix.
416
417 if (dismissProgress && mProgressIndicator != null) {
418 mProgressIndicator.dismiss();
419 mProgressIndicator = null;
420 }
421 }
366 } 422 }
OLDNEW
« no previous file with comments | « no previous file | remoting/android/java/src/org/chromium/chromoting/jni/JniInterface.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698