why did I forget to push this
This commit is contained in:
parent
e2915f99a3
commit
7c6e0d61e9
@ -21,6 +21,7 @@
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
@ -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();
|
||||
}
|
||||
});
|
||||
|
@ -1,9 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent" >
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_height="fill_parent"
|
||||
android:orientation="horizontal">
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
@ -27,6 +28,14 @@
|
||||
android:layout_height="130px"
|
||||
android:gravity="center">
|
||||
|
||||
<Button
|
||||
android:id="@+id/previous_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:drawableLeft="@drawable/arrow_left"
|
||||
android:drawablePadding="4dp"
|
||||
android:text="@string/previous_button" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/true_button"
|
||||
android:layout_width="wrap_content"
|
||||
@ -45,15 +54,6 @@
|
||||
android:layout_height="130px"
|
||||
android:gravity="center">
|
||||
|
||||
<Button
|
||||
android:id="@+id/previous_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/previous_button"
|
||||
android:drawableLeft="@drawable/arrow_left"
|
||||
android:drawablePadding="4dp"
|
||||
/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/next_button"
|
||||
android:layout_width="wrap_content"
|
@ -1,7 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent" >
|
||||
android:layout_height="fill_parent"
|
||||
android:orientation="vertical">
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
|
Loading…
Reference in New Issue
Block a user