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" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
@ -21,7 +21,10 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
private TextView mScoreTextView;
|
private TextView mScoreTextView;
|
||||||
private final String TAG = "QuizController";
|
private final String TAG = "QuizController";
|
||||||
private long answersCorrect = 0, answersIncorrect = 0;
|
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_australia, true),
|
||||||
new Question(R.string.question_oceans, 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_africa, false),
|
||||||
new Question(R.string.question_asia, true),
|
new Question(R.string.question_asia, true),
|
||||||
};
|
};
|
||||||
private int mCurrentIndex = 0;
|
private int mCurrentIndex = 0;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onConfigurationChanged(Configuration newConfig) {
|
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
||||||
Log.d(TAG, "onConfigurationChanged() called");
|
// Make sure to call the super method so that the states of our views are saved
|
||||||
super.onConfigurationChanged(newConfig);
|
super.onSaveInstanceState(outState);
|
||||||
|
Log.d(TAG, "onSaveInstanceState() called!");
|
||||||
if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
|
// Save our own state now
|
||||||
setContentView(R.layout.activity_main);
|
outState.putInt(STATE_COUNTER, mCurrentIndex);
|
||||||
}
|
outState.putLong(INCORRECT_ANSWER_STORAGE, answersIncorrect);
|
||||||
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
outState.putLong(CORRECT_ANSWER_STORAGE, answersCorrect);
|
||||||
setContentView(R.layout.activity_main_landscape);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStart() {
|
protected void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
Log.d(TAG,"onStart() called");
|
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
|
@Override
|
||||||
@ -83,13 +78,25 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
Log.d(TAG,"onCreate(Bundle) called");
|
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)
|
mQuestionTextView = (TextView)
|
||||||
findViewById(R.id.question_text_view);
|
findViewById(R.id.question_text_view);
|
||||||
int question =
|
int question =
|
||||||
mQuestionBank[mCurrentIndex].getmTextResId();
|
mQuestionBank[mCurrentIndex].getmTextResId();
|
||||||
//mQuestionTextView.setText(question);
|
//mQuestionTextView.setText(question);
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
mQuestionTextView = findViewById(R.id.question_text_view);
|
mQuestionTextView = findViewById(R.id.question_text_view);
|
||||||
trueButton = findViewById(R.id.true_button);
|
trueButton = findViewById(R.id.true_button);
|
||||||
@ -98,8 +105,20 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
previousButton = findViewById(R.id.previous_button);
|
previousButton = findViewById(R.id.previous_button);
|
||||||
mScoreTextView = findViewById(R.id.score_counter);
|
mScoreTextView = findViewById(R.id.score_counter);
|
||||||
resetButton = findViewById(R.id.reset_score_button);
|
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() {
|
trueButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
@ -138,16 +157,18 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
Log.i(TAG,"Calling nextButton event listener");
|
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) {
|
if(MainActivity.this.mCurrentIndex == mQuestionBank.length - 1) {
|
||||||
MainActivity.this.mCurrentIndex = 0;
|
MainActivity.this.mCurrentIndex = 0;
|
||||||
} else {
|
} else {
|
||||||
MainActivity.this.mCurrentIndex++;
|
MainActivity.this.mCurrentIndex++;
|
||||||
}
|
}
|
||||||
Log.i(TAG, "mCurrentIndex is: " + mCurrentIndex);
|
Log.i(TAG, "mCurrentIndex is: " + mCurrentIndex);
|
||||||
|
Question q = mQuestionBank[MainActivity.this.mCurrentIndex];
|
||||||
|
int idOfQuestion = q.getmTextResId();
|
||||||
MainActivity.this.mQuestionTextView.setText(idOfQuestion);
|
MainActivity.this.mQuestionTextView.setText(idOfQuestion);
|
||||||
|
updateScores();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -159,16 +180,16 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
Log.i(TAG, "Calling previousButton event listener");
|
Log.i(TAG, "Calling previousButton event listener");
|
||||||
updateScores();
|
|
||||||
Question q = mQuestionBank[MainActivity.this.mCurrentIndex];
|
|
||||||
int idOfQuestion = q.getmTextResId();
|
|
||||||
if (MainActivity.this.mCurrentIndex <= 0) {
|
if (MainActivity.this.mCurrentIndex <= 0) {
|
||||||
MainActivity.this.mCurrentIndex = mQuestionBank.length - 1;
|
MainActivity.this.mCurrentIndex = mQuestionBank.length - 1;
|
||||||
} else {
|
} else {
|
||||||
MainActivity.this.mCurrentIndex--;
|
MainActivity.this.mCurrentIndex--;
|
||||||
}
|
}
|
||||||
Log.i(TAG, "mCurrentIndex is: " + mCurrentIndex);
|
Log.i(TAG, "mCurrentIndex is: " + mCurrentIndex);
|
||||||
|
Question q = mQuestionBank[MainActivity.this.mCurrentIndex];
|
||||||
|
int idOfQuestion = q.getmTextResId();
|
||||||
MainActivity.this.mQuestionTextView.setText(idOfQuestion);
|
MainActivity.this.mQuestionTextView.setText(idOfQuestion);
|
||||||
|
updateScores();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -177,6 +198,13 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
Log.i(TAG, "Resetting scores!");
|
Log.i(TAG, "Resetting scores!");
|
||||||
answersCorrect = answersIncorrect = 0;
|
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();
|
updateScores();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="fill_parent" >
|
android:layout_height="fill_parent"
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
android:orientation="horizontal">
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
@ -27,6 +28,14 @@
|
|||||||
android:layout_height="130px"
|
android:layout_height="130px"
|
||||||
android:gravity="center">
|
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
|
<Button
|
||||||
android:id="@+id/true_button"
|
android:id="@+id/true_button"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
@ -45,15 +54,6 @@
|
|||||||
android:layout_height="130px"
|
android:layout_height="130px"
|
||||||
android:gravity="center">
|
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
|
<Button
|
||||||
android:id="@+id/next_button"
|
android:id="@+id/next_button"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
@ -1,7 +1,8 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="fill_parent"
|
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"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
Loading…
Reference in New Issue
Block a user