2626import android .content .pm .ApplicationInfo ;
2727import android .content .pm .PackageManager ;
2828import android .os .Bundle ;
29+ import android .support .annotation .StringRes ;
2930import android .support .v4 .content .LocalBroadcastManager ;
3031import android .util .Log ;
3132import android .view .View ;
@@ -54,7 +55,7 @@ public class EnableProfileActivity extends Activity implements NavigationBar.Nav
5455 private Button mFinishButton ;
5556 private SetupWizardLayout mSetupWizardLayout ;
5657
57- private boolean mEnableProfileNow ;
58+ private CheckInState mCheckinState ;
5859
5960 public static final String EXTRA_ENABLE_PROFILE_NOW = "enable_profile_now" ;
6061 private static final IntentFilter sIntentFilter =
@@ -64,9 +65,11 @@ public class EnableProfileActivity extends Activity implements NavigationBar.Nav
6465 @ Override
6566 protected void onCreate (Bundle savedInstanceState ) {
6667 super .onCreate (savedInstanceState );
67- mEnableProfileNow = getIntent ().getBooleanExtra (EXTRA_ENABLE_PROFILE_NOW , false );
68+
69+ mCheckinState = new CheckInState (this );
6870 if (savedInstanceState == null ) {
69- if (mEnableProfileNow ) {
71+ if (getIntent ().getBooleanExtra (EXTRA_ENABLE_PROFILE_NOW , false )) {
72+ mCheckinState .setFirstAccountState (CheckInState .FIRST_ACCOUNT_STATE_READY );
7073 ProvisioningUtil .enableProfile (this );
7174 } else {
7275 // Set up an alarm to enable profile in case we do not receive first account ready
@@ -120,8 +123,7 @@ protected void onResume() {
120123 LocalBroadcastManager .getInstance (this ).registerReceiver (mCheckInStateReceiver ,
121124 sIntentFilter );
122125 // In case the broadcast is sent before we register the receiver.
123- CheckInState checkInState = new CheckInState (this );
124- refreshUi (mEnableProfileNow || checkInState .isFirstAccountReady () /* enableFinish */ );
126+ refreshUi ();
125127 }
126128
127129 @ Override
@@ -140,16 +142,30 @@ private boolean isAccountMigrated(String addedAccount) {
140142 return false ;
141143 }
142144
143- private void refreshUi (boolean enableFinish ) {
145+ private void refreshUi () {
146+ boolean enableFinish ;
147+ @ StringRes int headerTextResId ;
148+ switch (mCheckinState .getFirstAccountState ()) {
149+ case CheckInState .FIRST_ACCOUNT_STATE_READY :
150+ enableFinish = true ;
151+ headerTextResId = R .string .finish_setup ;
152+ break ;
153+ case CheckInState .FIRST_ACCOUNT_STATE_TIMEOUT :
154+ enableFinish = true ;
155+ headerTextResId = R .string .finish_setup_account_not_ready ;
156+ break ;
157+ case CheckInState .FIRST_ACCOUNT_STATE_PENDING :
158+ default :
159+ enableFinish = false ;
160+ headerTextResId = R .string .waiting_for_first_account_check_in ;
161+ break ;
162+ }
144163 if (enableFinish ) {
145164 mSetupWizardLayout .hideProgressBar ();
146165 } else {
147166 mSetupWizardLayout .showProgressBar ();
148167 }
149- mSetupWizardLayout .setHeaderText (
150- (enableFinish )
151- ? R .string .finish_setup
152- : R .string .waiting_for_first_account_check_in );
168+ mSetupWizardLayout .setHeaderText (headerTextResId );
153169 mFinishButton .setEnabled (enableFinish );
154170 }
155171
@@ -167,7 +183,7 @@ class CheckInStateReceiver extends BroadcastReceiver {
167183 @ Override
168184 public void onReceive (Context context , Intent intent ) {
169185 // Processed the first check-in broadcast, allow user to tap the finish button.
170- refreshUi (true );
186+ refreshUi ();
171187 }
172188 }
173189}
0 commit comments