am a5be033d: Preserve setup wizard step while orientation change

* commit 'a5be033d4a7a141615e7d784f9218a476a10e018':
  Preserve setup wizard step while orientation change
main
Tadashi G. Takaoka 2013-05-02 03:23:59 -07:00 committed by Android Git Automerger
commit a36266dd58
1 changed files with 23 additions and 34 deletions

View File

@ -59,7 +59,7 @@ public final class SetupActivity extends Activity implements View.OnClickListene
private SetupStepGroup mSetupStepGroup; private SetupStepGroup mSetupStepGroup;
private static final String STATE_STEP = "step"; private static final String STATE_STEP = "step";
private int mStepNumber; private int mStepNumber;
private static final int STEP_0 = 0; private static final int STEP_WELCOME = 0;
private static final int STEP_1 = 1; private static final int STEP_1 = 1;
private static final int STEP_2 = 2; private static final int STEP_2 = 2;
private static final int STEP_3 = 3; private static final int STEP_3 = 3;
@ -113,18 +113,20 @@ public final class SetupActivity extends Activity implements View.OnClickListene
if (savedInstanceState == null) { if (savedInstanceState == null) {
mStepNumber = determineSetupStepNumber(); mStepNumber = determineSetupStepNumber();
if (mStepNumber == STEP_1 && !mWasLanguageAndInputSettingsInvoked) {
mStepNumber = STEP_WELCOME;
}
if (mStepNumber == STEP_3) {
// This IME already has been enabled and set as current IME.
// TODO: Implement tutorial.
invokeSettingsOfThisIme();
finish();
return;
}
} else { } else {
mStepNumber = savedInstanceState.getInt(STATE_STEP); mStepNumber = savedInstanceState.getInt(STATE_STEP);
} }
if (mStepNumber == STEP_3) {
// This IME already has been enabled and set as current IME.
// TODO: Implement tutorial.
invokeSettingsOfThisIme();
finish();
return;
}
final String applicationName = getResources().getString(getApplicationInfo().labelRes); final String applicationName = getResources().getString(getApplicationInfo().labelRes);
mWelcomeScreen = findViewById(R.id.setup_welcome_screen); mWelcomeScreen = findViewById(R.id.setup_welcome_screen);
final TextView welcomeTitle = (TextView)findViewById(R.id.setup_welcome_title); final TextView welcomeTitle = (TextView)findViewById(R.id.setup_welcome_title);
@ -230,13 +232,13 @@ public final class SetupActivity extends Activity implements View.OnClickListene
finish(); finish();
return; return;
} }
final int stepState = determineSetupState(); final int currentStep = determineSetupStepNumber();
final int nextStep; final int nextStep;
if (v == mActionStart) { if (v == mActionStart) {
nextStep = STEP_1; nextStep = STEP_1;
} else if (v == mActionNext) { } else if (v == mActionNext) {
nextStep = mStepNumber + 1; nextStep = mStepNumber + 1;
} else if (v == mStep1Bullet && stepState == STEP_2) { } else if (v == mStep1Bullet && currentStep == STEP_2) {
nextStep = STEP_1; nextStep = STEP_1;
} else { } else {
nextStep = mStepNumber; nextStep = mStepNumber;
@ -316,7 +318,7 @@ public final class SetupActivity extends Activity implements View.OnClickListene
return myImi.getId().equals(currentImeId); return myImi.getId().equals(currentImeId);
} }
private int determineSetupState() { private int determineSetupStepNumber() {
mHandler.cancelPollingImeSettings(); mHandler.cancelPollingImeSettings();
if (!isThisImeEnabled(this)) { if (!isThisImeEnabled(this)) {
return STEP_1; return STEP_1;
@ -327,14 +329,6 @@ public final class SetupActivity extends Activity implements View.OnClickListene
return STEP_3; return STEP_3;
} }
private int determineSetupStepNumber() {
final int stepState = determineSetupState();
if (stepState == STEP_1) {
return mWasLanguageAndInputSettingsInvoked ? STEP_1 : STEP_0;
}
return stepState;
}
@Override @Override
protected void onSaveInstanceState(final Bundle outState) { protected void onSaveInstanceState(final Bundle outState) {
super.onSaveInstanceState(outState); super.onSaveInstanceState(outState);
@ -347,16 +341,12 @@ public final class SetupActivity extends Activity implements View.OnClickListene
mStepNumber = savedInstanceState.getInt(STATE_STEP); mStepNumber = savedInstanceState.getInt(STATE_STEP);
} }
@Override
protected void onStart() {
super.onStart();
mStepNumber = determineSetupStepNumber();
}
@Override @Override
protected void onRestart() { protected void onRestart() {
super.onRestart(); super.onRestart();
mStepNumber = determineSetupStepNumber(); if (mStepNumber != STEP_WELCOME) {
mStepNumber = determineSetupStepNumber();
}
} }
@Override @Override
@ -368,7 +358,7 @@ public final class SetupActivity extends Activity implements View.OnClickListene
@Override @Override
public void onBackPressed() { public void onBackPressed() {
if (mStepNumber == STEP_1) { if (mStepNumber == STEP_1) {
mStepNumber = STEP_0; mStepNumber = STEP_WELCOME;
updateSetupStepView(); updateSetupStepView();
return; return;
} }
@ -384,15 +374,14 @@ public final class SetupActivity extends Activity implements View.OnClickListene
@Override @Override
public void onWindowFocusChanged(final boolean hasFocus) { public void onWindowFocusChanged(final boolean hasFocus) {
super.onWindowFocusChanged(hasFocus); super.onWindowFocusChanged(hasFocus);
if (!hasFocus) { if (hasFocus && mStepNumber != STEP_WELCOME) {
return; mStepNumber = determineSetupStepNumber();
updateSetupStepView();
} }
mStepNumber = determineSetupStepNumber();
updateSetupStepView();
} }
private void updateSetupStepView() { private void updateSetupStepView() {
final boolean welcomeScreen = (mStepNumber == STEP_0); final boolean welcomeScreen = (mStepNumber == STEP_WELCOME);
mWelcomeScreen.setVisibility(welcomeScreen ? View.VISIBLE : View.GONE); mWelcomeScreen.setVisibility(welcomeScreen ? View.VISIBLE : View.GONE);
mSetupScreen.setVisibility(welcomeScreen ? View.GONE: View.VISIBLE); mSetupScreen.setVisibility(welcomeScreen ? View.GONE: View.VISIBLE);
if (welcomeScreen) { if (welcomeScreen) {
@ -401,7 +390,7 @@ public final class SetupActivity extends Activity implements View.OnClickListene
return; return;
} }
mWelcomeVideoView.stopPlayback(); mWelcomeVideoView.stopPlayback();
final boolean isStepActionAlreadyDone = mStepNumber < determineSetupState(); final boolean isStepActionAlreadyDone = mStepNumber < determineSetupStepNumber();
mSetupStepGroup.enableStep(mStepNumber, isStepActionAlreadyDone); mSetupStepGroup.enableStep(mStepNumber, isStepActionAlreadyDone);
mActionNext.setVisibility(isStepActionAlreadyDone ? View.VISIBLE : View.GONE); mActionNext.setVisibility(isStepActionAlreadyDone ? View.VISIBLE : View.GONE);
mActionFinish.setVisibility((mStepNumber == STEP_3) ? View.VISIBLE : View.GONE); mActionFinish.setVisibility((mStepNumber == STEP_3) ? View.VISIBLE : View.GONE);