OLD | NEW |
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.ActionBar; | 13 import android.app.ActionBar; |
14 import android.app.Activity; | 14 import android.app.Activity; |
15 import android.app.ProgressDialog; | 15 import android.app.ProgressDialog; |
16 import android.content.DialogInterface; | 16 import android.content.DialogInterface; |
17 import android.content.Intent; | 17 import android.content.Intent; |
18 import android.content.SharedPreferences; | 18 import android.content.SharedPreferences; |
19 import android.content.res.Configuration; | 19 import android.content.res.Configuration; |
| 20 import android.net.Uri; |
20 import android.os.Bundle; | 21 import android.os.Bundle; |
21 import android.util.Log; | 22 import android.util.Log; |
22 import android.view.Menu; | 23 import android.view.Menu; |
23 import android.view.MenuItem; | 24 import android.view.MenuItem; |
24 import android.widget.ArrayAdapter; | 25 import android.widget.ArrayAdapter; |
25 import android.widget.ListView; | 26 import android.widget.ListView; |
26 import android.widget.TextView; | 27 import android.widget.TextView; |
27 import android.widget.Toast; | 28 import android.widget.Toast; |
28 | 29 |
29 import org.chromium.chromoting.jni.JniInterface; | 30 import org.chromium.chromoting.jni.JniInterface; |
30 | 31 |
31 import java.io.IOException; | 32 import java.io.IOException; |
32 import java.util.Arrays; | 33 import java.util.Arrays; |
33 | 34 |
34 /** | 35 /** |
35 * The user interface for querying and displaying a user's host list from the di
rectory server. It | 36 * The user interface for querying and displaying a user's host list from the di
rectory server. It |
36 * also requests and renews authentication tokens using the system account manag
er. | 37 * also requests and renews authentication tokens using the system account manag
er. |
37 */ | 38 */ |
38 public class Chromoting extends Activity implements JniInterface.ConnectionListe
ner, | 39 public class Chromoting extends Activity implements JniInterface.ConnectionListe
ner, |
39 AccountManagerCallback<Bundle>, ActionBar.OnNavigationListener, | 40 AccountManagerCallback<Bundle>, ActionBar.OnNavigationListener, |
40 HostListLoader.Callback { | 41 HostListLoader.Callback { |
41 /** Only accounts of this type will be selectable for authentication. */ | 42 /** Only accounts of this type will be selectable for authentication. */ |
42 private static final String ACCOUNT_TYPE = "com.google"; | 43 private static final String ACCOUNT_TYPE = "com.google"; |
43 | 44 |
44 /** Scopes at which the authentication token we request will be valid. */ | 45 /** Scopes at which the authentication token we request will be valid. */ |
45 private static final String TOKEN_SCOPE = "oauth2:https://www.googleapis.com
/auth/chromoting " + | 46 private static final String TOKEN_SCOPE = "oauth2:https://www.googleapis.com
/auth/chromoting " + |
46 "https://www.googleapis.com/auth/googletalk"; | 47 "https://www.googleapis.com/auth/googletalk"; |
47 | 48 |
| 49 /** Web page to be displayed in the Help screen when launched from this acti
vity. */ |
| 50 private static final String HELP_URL = |
| 51 "http://support.google.com/chrome/?p=mobile_crd_hostslist"; |
| 52 |
48 /** User's account details. */ | 53 /** User's account details. */ |
49 private Account mAccount; | 54 private Account mAccount; |
50 | 55 |
51 /** List of accounts on the system. */ | 56 /** List of accounts on the system. */ |
52 private Account[] mAccounts; | 57 private Account[] mAccounts; |
53 | 58 |
54 /** Account auth token. */ | 59 /** Account auth token. */ |
55 private String mToken; | 60 private String mToken; |
56 | 61 |
57 /** Helper for fetching the host list. */ | 62 /** Helper for fetching the host list. */ |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 // If there is no account, don't allow the user to refresh the listi
ng. | 169 // If there is no account, don't allow the user to refresh the listi
ng. |
165 mRefreshButton.setEnabled(false); | 170 mRefreshButton.setEnabled(false); |
166 } | 171 } |
167 | 172 |
168 return super.onCreateOptionsMenu(menu); | 173 return super.onCreateOptionsMenu(menu); |
169 } | 174 } |
170 | 175 |
171 /** Called whenever an action bar button is pressed. */ | 176 /** Called whenever an action bar button is pressed. */ |
172 @Override | 177 @Override |
173 public boolean onOptionsItemSelected(MenuItem item) { | 178 public boolean onOptionsItemSelected(MenuItem item) { |
174 refreshHostList(); | 179 switch (item.getItemId()) { |
175 return true; | 180 case R.id.actionbar_directoryrefresh: |
| 181 refreshHostList(); |
| 182 return true; |
| 183 |
| 184 case R.id.actionbar_help: |
| 185 { |
| 186 Intent intent = new Intent(this, HelpActivity.class); |
| 187 intent.setData(Uri.parse(HELP_URL)); |
| 188 startActivity(intent); |
| 189 } |
| 190 return true; |
| 191 |
| 192 default: |
| 193 return super.onOptionsItemSelected(item); |
| 194 } |
176 } | 195 } |
177 | 196 |
178 /** Called when the user taps on a host entry. */ | 197 /** Called when the user taps on a host entry. */ |
179 public void connectToHost(HostInfo host) { | 198 public void connectToHost(HostInfo host) { |
180 if (host.jabberId.isEmpty() || host.publicKey.isEmpty()) { | 199 if (host.jabberId.isEmpty() || host.publicKey.isEmpty()) { |
181 // TODO(lambroslambrou): If these keys are not present, treat this a
s a connection | 200 // TODO(lambroslambrou): If these keys are not present, treat this a
s a connection |
182 // failure and reload the host list (see crbug.com/304719). | 201 // failure and reload the host list (see crbug.com/304719). |
183 Toast.makeText(this, getString(R.string.error_reading_host), | 202 Toast.makeText(this, getString(R.string.error_reading_host), |
184 Toast.LENGTH_LONG).show(); | 203 Toast.LENGTH_LONG).show(); |
185 return; | 204 return; |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 // Unreachable, but required by Google Java style and findbugs. | 391 // Unreachable, but required by Google Java style and findbugs. |
373 assert false : "Unreached"; | 392 assert false : "Unreached"; |
374 } | 393 } |
375 | 394 |
376 if (dismissProgress && mProgressIndicator != null) { | 395 if (dismissProgress && mProgressIndicator != null) { |
377 mProgressIndicator.dismiss(); | 396 mProgressIndicator.dismiss(); |
378 mProgressIndicator = null; | 397 mProgressIndicator = null; |
379 } | 398 } |
380 } | 399 } |
381 } | 400 } |
OLD | NEW |