package org.mazhuang.android.geoquiz;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class CheatActivity extends Activity {

	public static final String EXTRA_ANSWER_IS_TRUE = "org.mazhuang.android.geoquiz.answer_is_true";
	public static final String EXTRA_ANSWER_SHOWN = "org.mazhuang.android.geoquiz.answer_shown";
	private boolean mAnswerIsTrue;
	
	private TextView mAnswerTextView;
	private Button mShowAnswer;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_cheat);
		
		setAnswerShownResult(false);
		
		mAnswerIsTrue = getIntent().getBooleanExtra(EXTRA_ANSWER_IS_TRUE, false);
		
		mAnswerTextView = (TextView)findViewById(R.id.answerTextView);
		
		mShowAnswer = (Button)findViewById(R.id.showAnswerButton);
		mShowAnswer.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				if (mAnswerIsTrue) {
					mAnswerTextView.setText(R.string.true_button);
				} else {
					mAnswerTextView.setText(R.string.false_button);
				}
				setAnswerShownResult(true);
			}
		});
	}
	
	private void setAnswerShownResult(boolean isAnswerShown) {
		Intent data = new Intent();
		data.putExtra(EXTRA_ANSWER_SHOWN, isAnswerShown);
		setResult(RESULT_OK, data);
	}
}

@@ -446,16 +446,112 @@
 shown%22;%0A
+%09private static final String KEY_IS_CHEATER = %22isCheater%22;%0A%09private boolean mIsCheater = false;%0A
 %09private
@@ -574,16 +574,16 @@
 IsTrue;%0A
-
 %09%0A%09priva
@@ -745,16 +745,132 @@
 State);%0A
+%09%09%0A%09%09if (savedInstanceState != null) %7B%0A%09%09%09mIsCheater = savedInstanceState.getBoolean(KEY_IS_CHEATER, false);%0A%09%09%7D%0A%09%09%0A
 %09%09setCon
@@ -930,21 +930,26 @@
 nResult(
-false
+mIsCheater
 );%0A%09%09%0A%09%09
@@ -1262,24 +1262,47 @@
 k(View v) %7B%0A
+%09%09%09%09mIsCheater = true;%0A
 %09%09%09%09if (mAns
@@ -1463,20 +1463,26 @@
 nResult(
-true
+mIsCheater
 );%0A%09%09%09%7D%0A
@@ -1634,16 +1634,16 @@
 Shown);%0A
-
 %09%09setRes
@@ -1667,10 +1667,171 @@
 ta);%0A%09%7D%0A
+%09%0A%09@Override%0A%09protected void onSaveInstanceState(Bundle outState) %7B%0A%09%09super.onSaveInstanceState(outState);%0A%09%09outState.putBoolean(KEY_IS_CHEATER, mIsCheater);%0A%09%7D%0A
 %7D%0A

解决旋转子Activity丢失状态的问题,P190