OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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.blimp; | 5 package org.chromium.blimp; |
6 | 6 |
7 import android.app.Activity; | 7 import android.app.Activity; |
8 import android.content.Intent; | 8 import android.content.Intent; |
9 import android.os.Bundle; | 9 import android.os.Bundle; |
10 | 10 |
11 import org.chromium.base.Log; | 11 import org.chromium.base.Log; |
12 import org.chromium.base.library_loader.ProcessInitException; | 12 import org.chromium.base.library_loader.ProcessInitException; |
13 import org.chromium.blimp.auth.RetryingTokenSource; | 13 import org.chromium.blimp.auth.RetryingTokenSource; |
14 import org.chromium.blimp.auth.TokenSource; | 14 import org.chromium.blimp.auth.TokenSource; |
15 import org.chromium.blimp.auth.TokenSourceImpl; | 15 import org.chromium.blimp.auth.TokenSourceImpl; |
16 import org.chromium.blimp.session.BlimpClientSession; | 16 import org.chromium.blimp.session.BlimpClientSession; |
17 import org.chromium.blimp.session.TabControlFeature; | 17 import org.chromium.blimp.session.TabControlFeature; |
18 import org.chromium.blimp.toolbar.Toolbar; | 18 import org.chromium.blimp.toolbar.Toolbar; |
19 import org.chromium.ui.widget.Toast; | 19 import org.chromium.ui.widget.Toast; |
20 | 20 |
21 /** | 21 /** |
22 * The {@link Activity} for rendering the main Blimp client. This loads the Bli mp rendering stack | 22 * The {@link Activity} for rendering the main Blimp client. This loads the Bli mp rendering stack |
23 * and displays it. | 23 * and displays it. |
24 */ | 24 */ |
25 public class BlimpRendererActivity extends Activity implements BlimpLibraryLoade r.Callback, | 25 public class BlimpRendererActivity extends Activity |
26 TokenSource.Callback { | 26 implements BlimpLibraryLoader.Callback, TokenSource.Callback, BlimpClien tSession.Callback { |
27 | |
28 private static final int ACCOUNT_CHOOSER_INTENT_REQUEST_CODE = 100; | 27 private static final int ACCOUNT_CHOOSER_INTENT_REQUEST_CODE = 100; |
29 private static final String TAG = "Blimp"; | 28 private static final String TAG = "Blimp"; |
30 private TokenSource mTokenSource; | 29 private TokenSource mTokenSource; |
Kevin M
2016/02/12 19:45:26
Could you document tokenSource?
David Trainor- moved to gerrit
2016/02/17 21:09:47
Done.
| |
31 private BlimpView mBlimpView; | 30 private BlimpView mBlimpView; |
32 private Toolbar mToolbar; | 31 private Toolbar mToolbar; |
33 private BlimpClientSession mBlimpClientSession; | 32 private BlimpClientSession mBlimpClientSession; |
34 private TabControlFeature mTabControlFeature; | 33 private TabControlFeature mTabControlFeature; |
35 | 34 |
36 @Override | 35 @Override |
37 protected void onCreate(Bundle savedInstanceState) { | 36 protected void onCreate(Bundle savedInstanceState) { |
38 super.onCreate(savedInstanceState); | 37 super.onCreate(savedInstanceState); |
39 | 38 |
40 mTokenSource = new RetryingTokenSource(new TokenSourceImpl(this)); | 39 mTokenSource = new RetryingTokenSource(new TokenSourceImpl(this)); |
Kevin M
2016/02/12 19:45:26
Brief comment for this block to educate the non-Cl
David Trainor- moved to gerrit
2016/02/17 21:09:47
Done.
| |
41 mTokenSource.setCallback(this); | 40 mTokenSource.setCallback(this); |
42 mTokenSource.getToken(); | 41 mTokenSource.getToken(); |
43 | 42 |
44 try { | 43 try { |
45 BlimpLibraryLoader.startAsync(this, this); | 44 BlimpLibraryLoader.startAsync(this, this); |
46 } catch (ProcessInitException e) { | 45 } catch (ProcessInitException e) { |
47 Log.e(TAG, "Native startup exception", e); | 46 Log.e(TAG, "Native startup exception", e); |
48 System.exit(-1); | 47 System.exit(-1); |
49 return; | 48 return; |
50 } | 49 } |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
108 @Override | 107 @Override |
109 public void onStartupComplete(boolean success) { | 108 public void onStartupComplete(boolean success) { |
110 if (!success) { | 109 if (!success) { |
111 Log.e(TAG, "Native startup failed"); | 110 Log.e(TAG, "Native startup failed"); |
112 finish(); | 111 finish(); |
113 return; | 112 return; |
114 } | 113 } |
115 | 114 |
116 setContentView(R.layout.blimp_main); | 115 setContentView(R.layout.blimp_main); |
117 | 116 |
118 mBlimpClientSession = new BlimpClientSession(); | 117 mBlimpClientSession = new BlimpClientSession(this); |
119 mBlimpClientSession.connect(); | |
120 | 118 |
121 mBlimpView = (BlimpView) findViewById(R.id.renderer); | 119 mBlimpView = (BlimpView) findViewById(R.id.renderer); |
122 mBlimpView.initializeRenderer(mBlimpClientSession); | 120 mBlimpView.initializeRenderer(mBlimpClientSession); |
123 | 121 |
124 mToolbar = (Toolbar) findViewById(R.id.toolbar); | 122 mToolbar = (Toolbar) findViewById(R.id.toolbar); |
125 mToolbar.initialize(mBlimpClientSession); | 123 mToolbar.initialize(mBlimpClientSession); |
126 | 124 |
127 mTabControlFeature = new TabControlFeature(mBlimpClientSession, mBlimpVi ew); | 125 mTabControlFeature = new TabControlFeature(mBlimpClientSession, mBlimpVi ew); |
128 mToolbar.loadUrl("http://www.google.com/"); | 126 mToolbar.loadUrl("http://www.google.com/"); |
129 } | 127 } |
130 | 128 |
131 // TokenSource.Callback implementation. | 129 // TokenSource.Callback implementation. |
132 @Override | 130 @Override |
133 public void onTokenReceived(String token) { | 131 public void onTokenReceived(String token) { |
134 // TODO(dtrainor): Do something with the token and the assigner! | 132 if (mBlimpClientSession != null) mBlimpClientSession.connect(token); |
135 Toast.makeText(this, R.string.signin_get_token_succeeded, Toast.LENGTH_S HORT).show(); | |
136 } | 133 } |
137 | 134 |
138 @Override | 135 @Override |
139 public void onTokenUnavailable(boolean isTransient) { | 136 public void onTokenUnavailable(boolean isTransient) { |
140 // Ignore isTransient here because we're relying on the auto-retry Token Source. | 137 // Ignore isTransient here because we're relying on the auto-retry Token Source. |
141 // TODO(dtrainor): Show a better error dialog/message. | 138 // TODO(dtrainor): Show a better error dialog/message. |
142 Toast.makeText(this, R.string.signin_get_token_failed, Toast.LENGTH_LONG ).show(); | 139 Toast.makeText(this, R.string.signin_get_token_failed, Toast.LENGTH_LONG ).show(); |
143 finish(); | |
144 } | 140 } |
145 | 141 |
146 @Override | 142 @Override |
147 public void onNeedsAccountToBeSelected(Intent suggestedIntent) { | 143 public void onNeedsAccountToBeSelected(Intent suggestedIntent) { |
148 startActivityForResult(suggestedIntent, ACCOUNT_CHOOSER_INTENT_REQUEST_C ODE); | 144 startActivityForResult(suggestedIntent, ACCOUNT_CHOOSER_INTENT_REQUEST_C ODE); |
149 } | 145 } |
146 | |
147 // BlimpClientSession.Callback implementation. | |
148 @Override | |
149 public void onAssignmentReceived(int result, int suggestedMessageResourceId) { | |
150 if (result != AssignmentSourceResult.OKAY) { | |
151 Toast.makeText(this, suggestedMessageResourceId, Toast.LENGTH_LONG). show(); | |
152 } | |
153 } | |
150 } | 154 } |
OLD | NEW |