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.toolbar.BlimpToolbar; |
16 import org.chromium.ui.widget.Toast; | 17 import org.chromium.ui.widget.Toast; |
17 | 18 |
18 /** | 19 /** |
19 * The {@link Activity} for rendering the main Blimp client. This loads the Bli
mp rendering stack | 20 * The {@link Activity} for rendering the main Blimp client. This loads the Bli
mp rendering stack |
20 * and displays it. | 21 * and displays it. |
21 */ | 22 */ |
22 public class BlimpRendererActivity extends Activity implements BlimpLibraryLoade
r.Callback, | 23 public class BlimpRendererActivity extends Activity implements BlimpLibraryLoade
r.Callback, |
23 TokenSource.Callback { | 24 TokenSource.Callback { |
24 | 25 |
25 private static final int ACCOUNT_CHOOSER_INTENT_REQUEST_CODE = 100; | 26 private static final int ACCOUNT_CHOOSER_INTENT_REQUEST_CODE = 100; |
26 private static final String TAG = "Blimp"; | 27 private static final String TAG = "Blimp"; |
27 private TokenSource mTokenSource; | 28 private TokenSource mTokenSource; |
28 private BlimpView mBlimpView; | 29 private BlimpView mBlimpView; |
| 30 private BlimpToolbar mBlimpToolbar; |
29 | 31 |
30 @Override | 32 @Override |
31 protected void onCreate(Bundle savedInstanceState) { | 33 protected void onCreate(Bundle savedInstanceState) { |
32 super.onCreate(savedInstanceState); | 34 super.onCreate(savedInstanceState); |
33 | 35 |
34 mTokenSource = new RetryingTokenSource(new TokenSourceImpl(this)); | 36 mTokenSource = new RetryingTokenSource(new TokenSourceImpl(this)); |
35 mTokenSource.setCallback(this); | 37 mTokenSource.setCallback(this); |
36 mTokenSource.getToken(); | 38 mTokenSource.getToken(); |
37 | 39 |
38 try { | 40 try { |
39 BlimpLibraryLoader.startAsync(this, this); | 41 BlimpLibraryLoader.startAsync(this, this); |
40 } catch (ProcessInitException e) { | 42 } catch (ProcessInitException e) { |
41 Log.e(TAG, "Native startup exception", e); | 43 Log.e(TAG, "Native startup exception", e); |
42 System.exit(-1); | 44 System.exit(-1); |
43 return; | 45 return; |
44 } | 46 } |
45 } | 47 } |
46 | 48 |
47 @Override | 49 @Override |
48 protected void onDestroy() { | 50 protected void onDestroy() { |
49 if (mBlimpView != null) { | 51 if (mBlimpView != null) { |
50 mBlimpView.destroyRenderer(); | 52 mBlimpView.destroyRenderer(); |
51 mBlimpView = null; | 53 mBlimpView = null; |
52 } | 54 } |
53 | 55 |
| 56 if (mBlimpToolbar != null) { |
| 57 mBlimpToolbar.destroy(); |
| 58 mBlimpToolbar = null; |
| 59 } |
| 60 |
54 if (mTokenSource != null) { | 61 if (mTokenSource != null) { |
55 mTokenSource.destroy(); | 62 mTokenSource.destroy(); |
56 mTokenSource = null; | 63 mTokenSource = null; |
57 } | 64 } |
58 | 65 |
59 super.onDestroy(); | 66 super.onDestroy(); |
60 } | 67 } |
61 | 68 |
62 @Override | 69 @Override |
63 protected void onActivityResult(int requestCode, int resultCode, Intent data
) { | 70 protected void onActivityResult(int requestCode, int resultCode, Intent data
) { |
64 switch (requestCode) { | 71 switch (requestCode) { |
65 case ACCOUNT_CHOOSER_INTENT_REQUEST_CODE: | 72 case ACCOUNT_CHOOSER_INTENT_REQUEST_CODE: |
66 if (resultCode == RESULT_OK) { | 73 if (resultCode == RESULT_OK) { |
67 mTokenSource.onAccountSelected(data); | 74 mTokenSource.onAccountSelected(data); |
68 mTokenSource.getToken(); | 75 mTokenSource.getToken(); |
69 } else { | 76 } else { |
70 onTokenUnavailable(false); | 77 onTokenUnavailable(false); |
71 } | 78 } |
72 break; | 79 break; |
73 } | 80 } |
74 } | 81 } |
75 | 82 |
| 83 @Override |
| 84 public void onBackPressed() { |
| 85 // Check if the toolbar can handle the back navigation. |
| 86 if (mBlimpToolbar != null && mBlimpToolbar.onBackPressed()) return; |
| 87 |
| 88 // If not, use the default Activity behavior. |
| 89 super.onBackPressed(); |
| 90 } |
| 91 |
76 // BlimpLibraryLoader.Callback implementation. | 92 // BlimpLibraryLoader.Callback implementation. |
77 @Override | 93 @Override |
78 public void onStartupComplete(boolean success) { | 94 public void onStartupComplete(boolean success) { |
79 if (!success) { | 95 if (!success) { |
80 Log.e(TAG, "Native startup failed"); | 96 Log.e(TAG, "Native startup failed"); |
81 finish(); | 97 finish(); |
82 return; | 98 return; |
83 } | 99 } |
84 | 100 |
85 setContentView(R.layout.blimp_main); | 101 setContentView(R.layout.blimp_main); |
| 102 |
86 mBlimpView = (BlimpView) findViewById(R.id.renderer); | 103 mBlimpView = (BlimpView) findViewById(R.id.renderer); |
87 mBlimpView.initializeRenderer(); | 104 mBlimpView.initializeRenderer(); |
| 105 |
| 106 mBlimpToolbar = (BlimpToolbar) findViewById(R.id.toolbar); |
| 107 mBlimpToolbar.initialize(); |
88 } | 108 } |
89 | 109 |
90 // TokenSource.Callback implementation. | 110 // TokenSource.Callback implementation. |
91 @Override | 111 @Override |
92 public void onTokenReceived(String token) { | 112 public void onTokenReceived(String token) { |
93 // TODO(dtrainor): Do something with the token and the assigner! | 113 // TODO(dtrainor): Do something with the token and the assigner! |
94 Toast.makeText(this, R.string.signin_get_token_succeeded, Toast.LENGTH_S
HORT).show(); | 114 Toast.makeText(this, R.string.signin_get_token_succeeded, Toast.LENGTH_S
HORT).show(); |
95 } | 115 } |
96 | 116 |
97 @Override | 117 @Override |
98 public void onTokenUnavailable(boolean isTransient) { | 118 public void onTokenUnavailable(boolean isTransient) { |
99 // Ignore isTransient here because we're relying on the auto-retry Token
Source. | 119 // Ignore isTransient here because we're relying on the auto-retry Token
Source. |
100 // TODO(dtrainor): Show a better error dialog/message. | 120 // TODO(dtrainor): Show a better error dialog/message. |
101 Toast.makeText(this, R.string.signin_get_token_failed, Toast.LENGTH_LONG
).show(); | 121 Toast.makeText(this, R.string.signin_get_token_failed, Toast.LENGTH_LONG
).show(); |
102 finish(); | 122 finish(); |
103 } | 123 } |
104 | 124 |
105 @Override | 125 @Override |
106 public void onNeedsAccountToBeSelected(Intent suggestedIntent) { | 126 public void onNeedsAccountToBeSelected(Intent suggestedIntent) { |
107 startActivityForResult(suggestedIntent, ACCOUNT_CHOOSER_INTENT_REQUEST_C
ODE); | 127 startActivityForResult(suggestedIntent, ACCOUNT_CHOOSER_INTENT_REQUEST_C
ODE); |
108 } | 128 } |
109 } | 129 } |
OLD | NEW |