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