26
26
import android .content .pm .ApplicationInfo ;
27
27
import android .content .pm .PackageManager ;
28
28
import android .os .Bundle ;
29
+ import android .support .annotation .StringRes ;
29
30
import android .support .v4 .content .LocalBroadcastManager ;
30
31
import android .util .Log ;
31
32
import android .view .View ;
@@ -54,7 +55,7 @@ public class EnableProfileActivity extends Activity implements NavigationBar.Nav
54
55
private Button mFinishButton ;
55
56
private SetupWizardLayout mSetupWizardLayout ;
56
57
57
- private boolean mEnableProfileNow ;
58
+ private CheckInState mCheckinState ;
58
59
59
60
public static final String EXTRA_ENABLE_PROFILE_NOW = "enable_profile_now" ;
60
61
private static final IntentFilter sIntentFilter =
@@ -64,9 +65,11 @@ public class EnableProfileActivity extends Activity implements NavigationBar.Nav
64
65
@ Override
65
66
protected void onCreate (Bundle savedInstanceState ) {
66
67
super .onCreate (savedInstanceState );
67
- mEnableProfileNow = getIntent ().getBooleanExtra (EXTRA_ENABLE_PROFILE_NOW , false );
68
+
69
+ mCheckinState = new CheckInState (this );
68
70
if (savedInstanceState == null ) {
69
- if (mEnableProfileNow ) {
71
+ if (getIntent ().getBooleanExtra (EXTRA_ENABLE_PROFILE_NOW , false )) {
72
+ mCheckinState .setFirstAccountState (CheckInState .FIRST_ACCOUNT_STATE_READY );
70
73
ProvisioningUtil .enableProfile (this );
71
74
} else {
72
75
// Set up an alarm to enable profile in case we do not receive first account ready
@@ -120,8 +123,7 @@ protected void onResume() {
120
123
LocalBroadcastManager .getInstance (this ).registerReceiver (mCheckInStateReceiver ,
121
124
sIntentFilter );
122
125
// 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 ();
125
127
}
126
128
127
129
@ Override
@@ -140,16 +142,30 @@ private boolean isAccountMigrated(String addedAccount) {
140
142
return false ;
141
143
}
142
144
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
+ }
144
163
if (enableFinish ) {
145
164
mSetupWizardLayout .hideProgressBar ();
146
165
} else {
147
166
mSetupWizardLayout .showProgressBar ();
148
167
}
149
- mSetupWizardLayout .setHeaderText (
150
- (enableFinish )
151
- ? R .string .finish_setup
152
- : R .string .waiting_for_first_account_check_in );
168
+ mSetupWizardLayout .setHeaderText (headerTextResId );
153
169
mFinishButton .setEnabled (enableFinish );
154
170
}
155
171
@@ -167,7 +183,7 @@ class CheckInStateReceiver extends BroadcastReceiver {
167
183
@ Override
168
184
public void onReceive (Context context , Intent intent ) {
169
185
// Processed the first check-in broadcast, allow user to tap the finish button.
170
- refreshUi (true );
186
+ refreshUi ();
171
187
}
172
188
}
173
189
}
0 commit comments