Chromium Code Reviews| Index: blimp/client/android/java/src/org/chromium/blimp/BlimpRendererActivity.java |
| diff --git a/blimp/client/android/java/src/org/chromium/blimp/BlimpRendererActivity.java b/blimp/client/android/java/src/org/chromium/blimp/BlimpRendererActivity.java |
| index 7cc4e66f4e51f6a7373124b3f06c1007b531efd0..7d349600e0f3b898da9ffe82f7fe5324fb4ebdfc 100644 |
| --- a/blimp/client/android/java/src/org/chromium/blimp/BlimpRendererActivity.java |
| +++ b/blimp/client/android/java/src/org/chromium/blimp/BlimpRendererActivity.java |
| @@ -5,22 +5,36 @@ |
| package org.chromium.blimp; |
| import android.app.Activity; |
| +import android.content.Intent; |
| import android.os.Bundle; |
| +import android.widget.Toast; |
| import org.chromium.base.Log; |
| import org.chromium.base.library_loader.ProcessInitException; |
| +import org.chromium.blimp.auth.RetryingTokenSource; |
| +import org.chromium.blimp.auth.TokenSource; |
| +import org.chromium.blimp.auth.TokenSourceImpl; |
| /** |
| * The {@link Activity} for rendering the main Blimp client. This loads the Blimp rendering stack |
| * and displays it. |
| */ |
| -public class BlimpRendererActivity extends Activity implements BlimpLibraryLoader.Callback { |
| - private static final String TAG = "cr.Blimp"; |
| +public class BlimpRendererActivity extends Activity implements BlimpLibraryLoader.Callback, |
| + TokenSource.Callback { |
| + |
| + private static final int ACCOUNT_CHOOSER_INTENT_REQUEST_CODE = 100; |
| + private static final String TAG = "cr_Blimp"; |
|
nyquist
2015/09/29 23:38:40
Nit: Just 'Blimp' nowadays apparently.
David Trainor- moved to gerrit
2015/10/05 15:19:07
Done.
|
| + private TokenSource mTokenSource; |
| private BlimpView mBlimpView; |
| @Override |
| protected void onCreate(Bundle savedInstanceState) { |
| super.onCreate(savedInstanceState); |
| + |
| + mTokenSource = new RetryingTokenSource(new TokenSourceImpl(this)); |
| + mTokenSource.setCallback(this); |
| + mTokenSource.getToken(); |
| + |
| try { |
| BlimpLibraryLoader.startAsync(this, this); |
| } catch (ProcessInitException e) { |
| @@ -37,9 +51,28 @@ public class BlimpRendererActivity extends Activity implements BlimpLibraryLoade |
| mBlimpView = null; |
| } |
| + if (mTokenSource != null) { |
| + mTokenSource.destroy(); |
| + mTokenSource = null; |
| + } |
| + |
| super.onDestroy(); |
| } |
| + @Override |
| + protected void onActivityResult(int requestCode, int resultCode, Intent data) { |
| + switch (requestCode) { |
| + case ACCOUNT_CHOOSER_INTENT_REQUEST_CODE: |
| + if (resultCode == RESULT_OK) { |
| + mTokenSource.onAccountSelected(data); |
| + mTokenSource.getToken(); |
| + } else { |
| + onTokenUnavailable(false); |
| + } |
| + break; |
| + } |
| + } |
| + |
| // BlimpLibraryLoader.Callback implementation. |
| @Override |
| public void onStartupComplete(boolean success) { |
| @@ -53,4 +86,24 @@ public class BlimpRendererActivity extends Activity implements BlimpLibraryLoade |
| mBlimpView = (BlimpView) findViewById(R.id.renderer); |
| mBlimpView.initializeRenderer(); |
| } |
| + |
| + // TokenSource.Callback implementation. |
| + @Override |
| + public void onTokenReceived(String token) { |
| + // TODO(dtrainor): Do something with the token and the assigner! |
| + Toast.makeText(this, R.string.signin_get_token_succeeded, Toast.LENGTH_SHORT).show(); |
| + } |
| + |
| + @Override |
| + public void onTokenUnavailable(boolean isTransient) { |
| + // Ignore isTransient here because we're relying on the auto-retry TokenSource. |
| + // TODO(dtrainor): Show a better error dialog/message. |
| + Toast.makeText(this, R.string.signin_get_token_failed, Toast.LENGTH_LONG).show(); |
| + finish(); |
| + } |
| + |
| + @Override |
| + public void onNeedsAccountToBeSelected(Intent suggestedIntent) { |
| + startActivityForResult(suggestedIntent, ACCOUNT_CHOOSER_INTENT_REQUEST_CODE); |
| + } |
| } |