|
|
|
@ -21,7 +21,10 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
private TextView mScoreTextView;
|
|
|
|
|
private final String TAG = "QuizController";
|
|
|
|
|
private long answersCorrect = 0, answersIncorrect = 0;
|
|
|
|
|
private Question[] mQuestionBank = new Question[]
|
|
|
|
|
private static final String STATE_COUNTER = "counter";
|
|
|
|
|
private static final String INCORRECT_ANSWER_STORAGE = "incorrect answer storage";
|
|
|
|
|
private static final String CORRECT_ANSWER_STORAGE = "correct answer storage";
|
|
|
|
|
private Question[] mQuestionBank = new Question[]
|
|
|
|
|
{
|
|
|
|
|
new Question(R.string.question_australia, true),
|
|
|
|
|
new Question(R.string.question_oceans, true),
|
|
|
|
@ -29,31 +32,23 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
new Question(R.string.question_africa, false),
|
|
|
|
|
new Question(R.string.question_asia, true),
|
|
|
|
|
};
|
|
|
|
|
private int mCurrentIndex = 0;
|
|
|
|
|
private int mCurrentIndex = 0;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onConfigurationChanged(Configuration newConfig) {
|
|
|
|
|
Log.d(TAG, "onConfigurationChanged() called");
|
|
|
|
|
super.onConfigurationChanged(newConfig);
|
|
|
|
|
|
|
|
|
|
if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
|
|
|
|
|
setContentView(R.layout.activity_main);
|
|
|
|
|
}
|
|
|
|
|
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
|
|
|
|
setContentView(R.layout.activity_main_landscape);
|
|
|
|
|
}
|
|
|
|
|
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
|
|
|
|
// Make sure to call the super method so that the states of our views are saved
|
|
|
|
|
super.onSaveInstanceState(outState);
|
|
|
|
|
Log.d(TAG, "onSaveInstanceState() called!");
|
|
|
|
|
// Save our own state now
|
|
|
|
|
outState.putInt(STATE_COUNTER, mCurrentIndex);
|
|
|
|
|
outState.putLong(INCORRECT_ANSWER_STORAGE, answersIncorrect);
|
|
|
|
|
outState.putLong(CORRECT_ANSWER_STORAGE, answersCorrect);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onStart() {
|
|
|
|
|
super.onStart();
|
|
|
|
|
Log.d(TAG,"onStart() called");
|
|
|
|
|
if (this.getRequestedOrientation() == ActivityInfo.CORIENTATION_PORTRAIT) {
|
|
|
|
|
setContentView(R.layout.activity_main);
|
|
|
|
|
}
|
|
|
|
|
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
|
|
|
|
setContentView(R.layout.activity_main_landscape);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -83,13 +78,25 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
@Override
|
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
Log.d(TAG,"onCreate(Bundle) called");
|
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
/*
|
|
|
|
|
if (getResources().getConfiguration().orientation == 1) {
|
|
|
|
|
Log.d(TAG, "setting orientation to portrait");
|
|
|
|
|
setContentView(R.layout.activity_main);
|
|
|
|
|
} else {
|
|
|
|
|
Log.d(TAG, "setting orientation to landscape");
|
|
|
|
|
setContentView(R.layout.activity_main_landscape);
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mQuestionTextView = (TextView)
|
|
|
|
|
findViewById(R.id.question_text_view);
|
|
|
|
|
int question =
|
|
|
|
|
mQuestionBank[mCurrentIndex].getmTextResId();
|
|
|
|
|
//mQuestionTextView.setText(question);
|
|
|
|
|
|
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
|
|
|
|
|
setContentView(R.layout.activity_main);
|
|
|
|
|
mQuestionTextView = findViewById(R.id.question_text_view);
|
|
|
|
|
trueButton = findViewById(R.id.true_button);
|
|
|
|
@ -98,8 +105,20 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
previousButton = findViewById(R.id.previous_button);
|
|
|
|
|
mScoreTextView = findViewById(R.id.score_counter);
|
|
|
|
|
resetButton = findViewById(R.id.reset_score_button);
|
|
|
|
|
updateScores();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// If we have a saved state, restore it
|
|
|
|
|
if (savedInstanceState != null) {
|
|
|
|
|
mCurrentIndex = savedInstanceState.getInt(STATE_COUNTER, 0);
|
|
|
|
|
answersIncorrect = savedInstanceState.getLong(INCORRECT_ANSWER_STORAGE);
|
|
|
|
|
answersCorrect = savedInstanceState.getLong(CORRECT_ANSWER_STORAGE);
|
|
|
|
|
|
|
|
|
|
// Update the question panel so it doesn't display the default text
|
|
|
|
|
Question q = mQuestionBank[MainActivity.this.mCurrentIndex];
|
|
|
|
|
int idOfQuestion = q.getmTextResId();
|
|
|
|
|
MainActivity.this.mQuestionTextView.setText(idOfQuestion);
|
|
|
|
|
}
|
|
|
|
|
updateScores();
|
|
|
|
|
trueButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
@ -138,16 +157,18 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
Log.i(TAG,"Calling nextButton event listener");
|
|
|
|
|
updateScores();
|
|
|
|
|
Question q = mQuestionBank[MainActivity.this.mCurrentIndex];
|
|
|
|
|
int idOfQuestion = q.getmTextResId();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(MainActivity.this.mCurrentIndex == mQuestionBank.length - 1) {
|
|
|
|
|
MainActivity.this.mCurrentIndex = 0;
|
|
|
|
|
} else {
|
|
|
|
|
MainActivity.this.mCurrentIndex++;
|
|
|
|
|
}
|
|
|
|
|
Log.i(TAG, "mCurrentIndex is: " + mCurrentIndex);
|
|
|
|
|
Question q = mQuestionBank[MainActivity.this.mCurrentIndex];
|
|
|
|
|
int idOfQuestion = q.getmTextResId();
|
|
|
|
|
MainActivity.this.mQuestionTextView.setText(idOfQuestion);
|
|
|
|
|
updateScores();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
@ -159,16 +180,16 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View view) {
|
|
|
|
|
Log.i(TAG, "Calling previousButton event listener");
|
|
|
|
|
updateScores();
|
|
|
|
|
Question q = mQuestionBank[MainActivity.this.mCurrentIndex];
|
|
|
|
|
int idOfQuestion = q.getmTextResId();
|
|
|
|
|
if (MainActivity.this.mCurrentIndex <= 0) {
|
|
|
|
|
MainActivity.this.mCurrentIndex = mQuestionBank.length - 1;
|
|
|
|
|
} else {
|
|
|
|
|
MainActivity.this.mCurrentIndex--;
|
|
|
|
|
}
|
|
|
|
|
Log.i(TAG, "mCurrentIndex is: " + mCurrentIndex);
|
|
|
|
|
Question q = mQuestionBank[MainActivity.this.mCurrentIndex];
|
|
|
|
|
int idOfQuestion = q.getmTextResId();
|
|
|
|
|
MainActivity.this.mQuestionTextView.setText(idOfQuestion);
|
|
|
|
|
updateScores();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
@ -177,6 +198,13 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
public void onClick(View view) {
|
|
|
|
|
Log.i(TAG, "Resetting scores!");
|
|
|
|
|
answersCorrect = answersIncorrect = 0;
|
|
|
|
|
|
|
|
|
|
// Reset the question position as well
|
|
|
|
|
MainActivity.this.mCurrentIndex = 0;
|
|
|
|
|
Question q = mQuestionBank[MainActivity.this.mCurrentIndex];
|
|
|
|
|
int idOfQuestion = q.getmTextResId();
|
|
|
|
|
MainActivity.this.mQuestionTextView.setText(idOfQuestion);
|
|
|
|
|
|
|
|
|
|
updateScores();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|