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; |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 HelpActivity.launch(this, HELP_URL); | 217 HelpActivity.launch(this, HELP_URL); |
218 return true; | 218 return true; |
219 | 219 |
220 default: | 220 default: |
221 return super.onOptionsItemSelected(item); | 221 return super.onOptionsItemSelected(item); |
222 } | 222 } |
223 } | 223 } |
224 | 224 |
225 /** Called when the user taps on a host entry. */ | 225 /** Called when the user taps on a host entry. */ |
226 public void connectToHost(HostInfo host) { | 226 public void connectToHost(HostInfo host) { |
| 227 mProgressIndicator = ProgressDialog.show(this, |
| 228 host.name, getString(R.string.footer_connecting), true, true, |
| 229 new DialogInterface.OnCancelListener() { |
| 230 @Override |
| 231 public void onCancel(DialogInterface dialog) { |
| 232 JniInterface.disconnectFromHost(); |
| 233 } |
| 234 }); |
227 SessionConnector connector = new SessionConnector(this, this, mHostListL
oader); | 235 SessionConnector connector = new SessionConnector(this, this, mHostListL
oader); |
228 connector.connectToHost(mAccount.name, mToken, host); | 236 connector.connectToHost(mAccount.name, mToken, host); |
229 } | 237 } |
230 | 238 |
231 private void refreshHostList() { | 239 private void refreshHostList() { |
232 mTriedNewAuthToken = false; | 240 mTriedNewAuthToken = false; |
233 | 241 |
234 // The refresh button simply makes use of the currently-chosen account. | 242 // The refresh button simply makes use of the currently-chosen account. |
235 AccountManager.get(this).getAuthToken(mAccount, TOKEN_SCOPE, null, this,
this, null); | 243 AccountManager.get(this).getAuthToken(mAccount, TOKEN_SCOPE, null, this,
this, null); |
236 } | 244 } |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 mGreeting.setText(getString(R.string.mode_me2me)); | 361 mGreeting.setText(getString(R.string.mode_me2me)); |
354 | 362 |
355 ArrayAdapter<HostInfo> displayer = new HostListAdapter(this, R.layout.ho
st, mHosts); | 363 ArrayAdapter<HostInfo> displayer = new HostListAdapter(this, R.layout.ho
st, mHosts); |
356 Log.i("hostlist", "About to populate host list display"); | 364 Log.i("hostlist", "About to populate host list display"); |
357 mList.setAdapter(displayer); | 365 mList.setAdapter(displayer); |
358 } | 366 } |
359 | 367 |
360 @Override | 368 @Override |
361 public void onConnectionState(JniInterface.ConnectionListener.State state, | 369 public void onConnectionState(JniInterface.ConnectionListener.State state, |
362 JniInterface.ConnectionListener.Error error) { | 370 JniInterface.ConnectionListener.Error error) { |
363 String stateText = getResources().getStringArray(R.array.protoc_states)[
state.value()]; | |
364 boolean dismissProgress = false; | 371 boolean dismissProgress = false; |
365 switch (state) { | 372 switch (state) { |
366 case INITIALIZING: | 373 case INITIALIZING: |
367 case CONNECTING: | 374 case CONNECTING: |
368 case AUTHENTICATED: | 375 case AUTHENTICATED: |
369 // The connection is still being established, so we'll report th
e current progress. | 376 // The connection is still being established. |
370 if (mProgressIndicator == null) { | |
371 mProgressIndicator = ProgressDialog.show(this, | |
372 getString(R.string.footer_connecting), stateText, tr
ue, true, | |
373 new DialogInterface.OnCancelListener() { | |
374 @Override | |
375 public void onCancel(DialogInterface dialog) { | |
376 JniInterface.disconnectFromHost(); | |
377 } | |
378 }); | |
379 } else { | |
380 mProgressIndicator.setMessage(stateText); | |
381 } | |
382 break; | 377 break; |
383 | 378 |
384 case CONNECTED: | 379 case CONNECTED: |
385 dismissProgress = true; | 380 dismissProgress = true; |
386 Toast.makeText(this, stateText, Toast.LENGTH_SHORT).show(); | |
387 | |
388 // Display the remote desktop. | 381 // Display the remote desktop. |
389 startActivityForResult(new Intent(this, Desktop.class), 0); | 382 startActivityForResult(new Intent(this, Desktop.class), 0); |
390 break; | 383 break; |
391 | 384 |
392 case FAILED: | 385 case FAILED: |
393 dismissProgress = true; | 386 dismissProgress = true; |
394 Toast.makeText(this, stateText + ": " | 387 Toast.makeText(this, getString(error.message()), Toast.LENGTH_LO
NG).show(); |
395 + getResources().getStringArray(R.array.protoc_errors)[e
rror.value()], | |
396 Toast.LENGTH_LONG).show(); | |
397 | |
398 // Close the Desktop view, if it is currently running. | 388 // Close the Desktop view, if it is currently running. |
399 finishActivity(0); | 389 finishActivity(0); |
400 break; | 390 break; |
401 | 391 |
402 case CLOSED: | 392 case CLOSED: |
403 // No need to show toast in this case. Either the connection wil
l have failed | 393 // No need to show toast in this case. Either the connection wil
l have failed |
404 // because of an error, which will trigger toast already. Or the
disconnection will | 394 // because of an error, which will trigger toast already. Or the
disconnection will |
405 // have been initiated by the user. | 395 // have been initiated by the user. |
406 dismissProgress = true; | 396 dismissProgress = true; |
407 finishActivity(0); | 397 finishActivity(0); |
408 break; | 398 break; |
409 | 399 |
410 default: | 400 default: |
411 // Unreachable, but required by Google Java style and findbugs. | 401 // Unreachable, but required by Google Java style and findbugs. |
412 assert false : "Unreached"; | 402 assert false : "Unreached"; |
413 } | 403 } |
414 | 404 |
415 if (dismissProgress && mProgressIndicator != null) { | 405 if (dismissProgress && mProgressIndicator != null) { |
416 mProgressIndicator.dismiss(); | 406 mProgressIndicator.dismiss(); |
417 mProgressIndicator = null; | 407 mProgressIndicator = null; |
418 } | 408 } |
419 } | 409 } |
420 } | 410 } |
OLD | NEW |