Skip to content

Instantly share code, notes, and snippets.

@evanca
Last active January 24, 2018 07:45
Show Gist options
  • Save evanca/9ed7a5d252c9ea5a70518147b8517302 to your computer and use it in GitHub Desktop.
Save evanca/9ed7a5d252c9ea5a70518147b8517302 to your computer and use it in GitHub Desktop.
Google Developer Challenge Scholarship - Android Basics / Quiz App
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout
android:id="@+id/main_linear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical">
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:src="@drawable/sitcom" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="@dimen/answer_margin_start_16dp">
<TextView
style="@style/quiz_name"
android:text="@string/friends" />
<EditText
android:id="@+id/name_field"
style="@style/enter_your_name"
android:hint="@string/please_enter_your_name_to_start_quiz" />
<Button
android:id="@+id/start_quiz"
style="@style/main_button"
android:onClick="startQuiz"
android:text="@string/start_quiz" />
<View style="@style/yellow_line" />
<!-- ***** ***** ***** Question nr. 1 ***** ***** ***** -->
<LinearLayout
android:id="@+id/question_1"
style="@style/question_layout">
<Button
style="@style/question_number_blush"
android:text="@string/_1_10" />
<TextView
style="@style/question_text"
android:text="@string/question_1" />
</LinearLayout>
<CheckBox
android:id="@+id/Q1A1"
style="@style/checkbox_answer"
android:text="@string/answer_11" />
<CheckBox
android:id="@+id/Q1A2"
style="@style/checkbox_answer"
android:text="@string/answer_12" />
<CheckBox
android:id="@+id/Q1A3"
style="@style/checkbox_answer"
android:text="@string/answer_13" />
<CheckBox
android:id="@+id/Q1A4"
style="@style/checkbox_answer"
android:text="@string/answer_14" />
<Button
android:id="@+id/button_q1"
style="@style/main_button"
android:onClick="submitAnswer1"
android:text="@string/next" />
<View
android:id="@+id/end_of_1"
style="@style/blue_line" />
<!-- ***** ***** ***** Question nr. 2 ***** ***** ***** -->
<LinearLayout
android:id="@+id/question_2"
style="@style/question_layout">
<Button
style="@style/question_number_yellow"
android:text="@string/_2_10" />
<TextView
style="@style/question_text"
android:text="@string/question_2" />
</LinearLayout>
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<RadioButton
android:id="@+id/Q2A1"
style="@style/checkbox_answer"
android:text="@string/answer_21" />
<RadioButton
android:id="@+id/Q2A2"
style="@style/checkbox_answer"
android:text="@string/answer_22" />
<RadioButton
android:id="@+id/Q2A3"
style="@style/checkbox_answer"
android:text="@string/answer_23" />
<RadioButton
android:id="@+id/Q2A4"
style="@style/checkbox_answer"
android:text="@string/answer_24" />
</RadioGroup>
<Button
android:id="@+id/button_q2"
style="@style/main_button"
android:onClick="submitAnswer2"
android:text="@string/next" />
<View
android:id="@+id/end_of_2"
style="@style/blush_line" />
<!-- ***** ***** ***** Question nr. 3 ***** ***** ***** -->
<LinearLayout
android:id="@+id/question_3"
style="@style/question_layout">
<Button
style="@style/question_number_blue"
android:text="@string/_3_10" />
<TextView
style="@style/question_text"
android:text="@string/question_3" />
</LinearLayout>
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<RadioButton
android:id="@+id/Q3A1"
style="@style/checkbox_answer"
android:text="@string/answer_31" />
<RadioButton
android:id="@+id/Q3A2"
style="@style/checkbox_answer"
android:text="@string/answer_32" />
<RadioButton
android:id="@+id/Q3A3"
style="@style/checkbox_answer"
android:text="@string/answer_33" />
<RadioButton
android:id="@+id/Q3A4"
style="@style/checkbox_answer"
android:text="@string/answer_34" />
</RadioGroup>
<Button
android:id="@+id/button_q3"
style="@style/main_button"
android:onClick="submitAnswer3"
android:text="@string/next" />
<View
android:id="@+id/end_of_3"
style="@style/yellow_line" />
<!-- ***** ***** ***** Question nr. 4 ***** ***** ***** -->
<LinearLayout
android:id="@+id/question_4"
style="@style/question_layout">
<Button
style="@style/question_number_blush"
android:text="@string/_4_10" />
<TextView
style="@style/question_text"
android:text="@string/question_4" />
</LinearLayout>
<CheckBox
android:id="@+id/Q4A1"
style="@style/checkbox_answer"
android:text="@string/answer_41" />
<CheckBox
android:id="@+id/Q4A2"
style="@style/checkbox_answer"
android:text="@string/answer_42" />
<CheckBox
android:id="@+id/Q4A3"
style="@style/checkbox_answer"
android:text="@string/answer_43" />
<CheckBox
android:id="@+id/Q4A4"
style="@style/checkbox_answer"
android:text="@string/answer_44" />
<Button
android:id="@+id/button_q4"
style="@style/main_button"
android:onClick="submitAnswer4"
android:text="@string/next" />
<View
android:id="@+id/end_of_4"
style="@style/blue_line" />
<!-- ***** ***** ***** Question nr. 5 ***** ***** ***** -->
<LinearLayout
android:id="@+id/question_5"
style="@style/question_layout">
<Button
style="@style/question_number_yellow"
android:text="@string/_5_10" />
<TextView
style="@style/question_text"
android:text="@string/question_5" />
</LinearLayout>
<EditText
android:id="@+id/Q5A1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/answer_margin_start_16dp"
android:hint="@string/type_in_the_answer"
android:imeOptions="actionDone"
android:inputType="textCapWords"
android:paddingStart="@dimen/answer_padding_start_24dp"
android:paddingTop="@dimen/answer_padding_start_24dp"
android:textAppearance="?android:textAppearanceMedium" />
<Button
android:id="@+id/button_q5"
style="@style/main_button"
android:onClick="submitAnswer5"
android:text="@string/next" />
<View
android:id="@+id/end_of_5"
style="@style/blush_line" />
<!-- ***** ***** ***** Question nr. 6 ***** ***** ***** -->
<LinearLayout
android:id="@+id/question_6"
style="@style/question_layout">
<Button
style="@style/question_number_blue"
android:text="@string/_6_10" />
<TextView
style="@style/question_text"
android:text="@string/question_6" />
</LinearLayout>
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<RadioButton
android:id="@+id/Q6A1"
style="@style/checkbox_answer"
android:text="@string/answer_61" />
<RadioButton
android:id="@+id/Q6A2"
style="@style/checkbox_answer"
android:text="@string/answer_62" />
<RadioButton
android:id="@+id/Q6A3"
style="@style/checkbox_answer"
android:text="@string/answer_63" />
<RadioButton
android:id="@+id/Q6A4"
style="@style/checkbox_answer"
android:text="@string/answer_64" />
</RadioGroup>
<Button
android:id="@+id/button_q6"
style="@style/main_button"
android:onClick="submitAnswer6"
android:text="@string/next" />
<View
android:id="@+id/end_of_6"
style="@style/yellow_line" />
<!-- ***** ***** ***** Question nr. 7 ***** ***** ***** -->
<LinearLayout
android:id="@+id/question_7"
style="@style/question_layout">
<Button
style="@style/question_number_blush"
android:text="@string/_7_10" />
<TextView
style="@style/question_text"
android:text="@string/question_7" />
</LinearLayout>
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<RadioButton
android:id="@+id/Q7A1"
style="@style/checkbox_answer"
android:text="@string/answer_71" />
<RadioButton
android:id="@+id/Q7A2"
style="@style/checkbox_answer"
android:text="@string/answer_72" />
<RadioButton
android:id="@+id/Q7A3"
style="@style/checkbox_answer"
android:text="@string/answer_73" />
<RadioButton
android:id="@+id/Q7A4"
style="@style/checkbox_answer"
android:text="@string/answer_74" />
</RadioGroup>
<Button
android:id="@+id/button_q7"
style="@style/main_button"
android:onClick="submitAnswer7"
android:text="@string/next" />
<View
android:id="@+id/end_of_7"
style="@style/blue_line" />
<!-- ***** ***** ***** Question nr. 8 ***** ***** ***** -->
<LinearLayout
android:id="@+id/question_8"
style="@style/question_layout">
<Button
style="@style/question_number_yellow"
android:text="@string/_8_10" />
<TextView
style="@style/question_text"
android:text="@string/question_8" />
</LinearLayout>
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<RadioButton
android:id="@+id/Q8A1"
style="@style/checkbox_answer"
android:text="@string/answer_81" />
<RadioButton
android:id="@+id/Q8A2"
style="@style/checkbox_answer"
android:text="@string/answer_82" />
<RadioButton
android:id="@+id/Q8A3"
style="@style/checkbox_answer"
android:text="@string/answer_83" />
<RadioButton
android:id="@+id/Q8A4"
style="@style/checkbox_answer"
android:text="@string/answer_84" />
</RadioGroup>
<Button
android:id="@+id/button_q8"
style="@style/main_button"
android:onClick="submitAnswer8"
android:text="@string/next" />
<View
android:id="@+id/end_of_8"
style="@style/blush_line" />
<!-- ***** ***** ***** Question nr. 9 ***** ***** ***** -->
<LinearLayout
android:id="@+id/question_9"
style="@style/question_layout">
<Button
style="@style/question_number_blue"
android:text="@string/_9_10" />
<TextView
style="@style/question_text"
android:text="@string/question_9" />
</LinearLayout>
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<RadioButton
android:id="@+id/Q9A1"
style="@style/checkbox_answer"
android:text="@string/answer_91" />
<RadioButton
android:id="@+id/Q9A2"
style="@style/checkbox_answer"
android:text="@string/answer_92" />
<RadioButton
android:id="@+id/Q9A3"
style="@style/checkbox_answer"
android:text="@string/answer_93" />
<RadioButton
android:id="@+id/Q9A4"
style="@style/checkbox_answer"
android:text="@string/answer_94" />
</RadioGroup>
<Button
android:id="@+id/button_q9"
style="@style/main_button"
android:onClick="submitAnswer9"
android:text="@string/next" />
<View
android:id="@+id/end_of_9"
style="@style/yellow_line" />
<!-- ***** ***** ***** Question nr. 10 ***** ***** ***** -->
<LinearLayout
android:id="@+id/question_10"
style="@style/question_layout">
<Button
style="@style/question_number_blush"
android:text="@string/_10_10" />
<TextView
style="@style/question_text"
android:text="@string/question_10" />
</LinearLayout>
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<RadioButton
android:id="@+id/Q10A1"
style="@style/checkbox_answer"
android:text="@string/answer_101" />
<RadioButton
android:id="@+id/Q10A2"
style="@style/checkbox_answer"
android:text="@string/answer_102" />
<RadioButton
android:id="@+id/Q10A3"
style="@style/checkbox_answer"
android:text="@string/answer_103" />
<RadioButton
android:id="@+id/Q10A4"
style="@style/checkbox_answer"
android:text="@string/answer_104" />
</RadioGroup>
<Button
android:id="@+id/button_q10"
style="@style/main_button"
android:onClick="submitAnswer10"
android:text="@string/submit" />
<View
android:id="@+id/end_of_10"
style="@style/blue_line" />
<!-- ***** ***** ***** END ***** ***** ***** -->
<TextView
android:id="@+id/show_name"
style="@style/show_your_name" />
<Button
android:id="@+id/button_score"
style="@style/large_button"
android:onClick="buttonScore"
android:text="@string/show_me_score" />
<Button
android:id="@+id/button_reset"
style="@style/large_button"
android:onClick="buttonReset"
android:text="@string/reset_try_again" />
</LinearLayout>
</LinearLayout>
</ScrollView>
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<solid android:color="#7CDAF2"/>
<size android:width="@dimen/circle_diameter" android:height="@dimen/circle_diameter"/>
</shape>
</item>
</selector>
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<solid android:color="#F29596"/>
<size android:width="@dimen/circle_diameter" android:height="@dimen/circle_diameter"/>
</shape>
</item>
</selector>
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<solid android:color="#FFDF70"/>
<size android:width="@dimen/circle_diameter" android:height="@dimen/circle_diameter"/>
</shape>
</item>
</selector>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="smallest">8dp</dimen>
<dimen name="small">16dp</dimen>
<dimen name="medium">24dp</dimen>
<dimen name="normal">36dp</dimen>
<dimen name="next">48dp</dimen>
</resources>
package com.example.android.friendsquiz;
import android.content.Intent;
import android.content.res.Configuration;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
int quizScore = 0;
boolean isSmallestScreenWidthDp600;
boolean isPhonePortrait;
boolean isPhoneLandscape;
ScrollView scrollView;
EditText nameField;
TextView showName;
Button buttonStart;
Button buttonQ1;
Button buttonQ2;
Button buttonQ3;
Button buttonQ4;
Button buttonQ5;
Button buttonQ6;
Button buttonQ7;
Button buttonQ8;
Button buttonQ9;
Button buttonQ10;
View question1;
View question2;
View question3;
View question4;
View question5;
View question6;
View question7;
View question8;
View question9;
View question10;
View endOf1;
View endOf2;
View endOf3;
View endOf4;
View endOf5;
View endOf6;
View endOf7;
View endOf8;
View endOf9;
View endOf10;
CheckBox answerQ1A1;
CheckBox answerQ1A2;
CheckBox answerQ1A3;
CheckBox answerQ1A4;
RadioButton answerQ2A3;
RadioButton answerQ3A4;
CheckBox answerQ4A1;
CheckBox answerQ4A2;
CheckBox answerQ4A3;
CheckBox answerQ4A4;
EditText answerQ5A1;
RadioButton answerQ6A1;
RadioButton answerQ7A4;
RadioButton answerQ8A1;
RadioButton answerQ9A2;
RadioButton answerQ10A4;
View mainLinear;
View bgImage;
View group456;
/**
* "Q" is for Question
* "A" is for Answer
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
scrollView = findViewById(R.id.main_scroll_view);
nameField = findViewById(R.id.name_field);
showName = findViewById(R.id.show_name);
buttonStart = findViewById(R.id.start_quiz);
buttonQ1 = findViewById(R.id.button_q1);
buttonQ2 = findViewById(R.id.button_q2);
buttonQ3 = findViewById(R.id.button_q3);
buttonQ4 = findViewById(R.id.button_q4);
buttonQ5 = findViewById(R.id.button_q5);
buttonQ6 = findViewById(R.id.button_q6);
buttonQ7 = findViewById(R.id.button_q7);
buttonQ8 = findViewById(R.id.button_q8);
buttonQ9 = findViewById(R.id.button_q9);
buttonQ10 = findViewById(R.id.button_q10);
question1 = findViewById(R.id.question_1);
question2 = findViewById(R.id.question_2);
question3 = findViewById(R.id.question_3);
question4 = findViewById(R.id.question_4);
question5 = findViewById(R.id.question_5);
question6 = findViewById(R.id.question_6);
question7 = findViewById(R.id.question_7);
question8 = findViewById(R.id.question_8);
question9 = findViewById(R.id.question_9);
question10 = findViewById(R.id.question_10);
endOf1 = findViewById(R.id.end_of_1);
endOf2 = findViewById(R.id.end_of_2);
endOf3 = findViewById(R.id.end_of_3);
endOf4 = findViewById(R.id.end_of_4);
endOf5 = findViewById(R.id.end_of_5);
endOf6 = findViewById(R.id.end_of_6);
endOf7 = findViewById(R.id.end_of_7);
endOf8 = findViewById(R.id.end_of_8);
endOf9 = findViewById(R.id.end_of_9);
endOf10 = findViewById(R.id.end_of_10);
answerQ1A1 = findViewById(R.id.Q1A1);
answerQ1A2 = findViewById(R.id.Q1A2);
answerQ1A3 = findViewById(R.id.Q1A3);
answerQ1A4 = findViewById(R.id.Q1A4);
answerQ2A3 = findViewById(R.id.Q2A3);
answerQ3A4 = findViewById(R.id.Q3A4);
answerQ4A1 = findViewById(R.id.Q4A1);
answerQ4A2 = findViewById(R.id.Q4A2);
answerQ4A3 = findViewById(R.id.Q4A3);
answerQ4A4 = findViewById(R.id.Q4A4);
answerQ5A1 = findViewById(R.id.Q5A1);
answerQ6A1 = findViewById(R.id.Q6A1);
answerQ7A4 = findViewById(R.id.Q7A4);
answerQ8A1 = findViewById(R.id.Q8A1);
answerQ9A2 = findViewById(R.id.Q9A2);
answerQ10A4 = findViewById(R.id.Q10A4);
mainLinear = findViewById(R.id.main_linear);
bgImage = findViewById(R.id.bg_image);
group456 = findViewById(R.id.group_456);
isSmallestScreenWidthDp600 = getResources().getConfiguration().smallestScreenWidthDp >= 600;
isPhonePortrait = getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT;
isPhoneLandscape = getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
}
public void startQuiz(View view) {
// Get user submitted name to string:
String getNameField = nameField.getText().toString();
// Update the message shown at the end:
showName.setText(getString(R.string.are_you_ready) + " " + getNameField + '?');
// If there is no name, show error & disable first question
if (TextUtils.isEmpty(getNameField)) {
nameField.setError(getString(R.string.name_error));
buttonQ1.setEnabled(false);
// If there is a name, disable the start button & scroll to the first question
} else {
buttonStart.setEnabled(false);
buttonQ1.setEnabled(true);
if (isSmallestScreenWidthDp600)
{
scrollView.postDelayed(new Runnable() {
public void run() {
scrollView.scrollTo(0, bgImage.getBottom());
}
}, 100);
} else {
if (isPhonePortrait)
{
scrollView.postDelayed(new Runnable() {
public void run() {
scrollView.scrollBy(0, question1.getTop());
}
}, 100);
}
// If orientation is horizontal, scroll to the bottom (!) of first question:
else if (isPhoneLandscape)
{
scrollView.postDelayed(new Runnable() {
public void run() {
scrollView.scrollTo(0, endOf1.getTop());
}
}, 100);
}
}
}
}
/**
* ***** ***** ***** Question nr. 1 ***** ***** *****
*/
public void submitAnswer1(View view) {
// Get user submitted answer:
boolean isCheckedQ1A1 = answerQ1A1.isChecked();
boolean isCheckedQ1A2 = answerQ1A2.isChecked();
boolean isCheckedQ1A3 = answerQ1A3.isChecked();
boolean isCheckedQ1A4 = answerQ1A4.isChecked();
// Check if the answer is correct & update the quiz score:
if ((!isCheckedQ1A1) && isCheckedQ1A2 && isCheckedQ1A3 && isCheckedQ1A4) {
quizScore = quizScore + 1;
Log.v("MainActivity", "Score is " + quizScore);
}
// Prevent multiple answer submitting:
buttonQ1.setEnabled(false);
// Finish here & scroll to the next question:
if (isSmallestScreenWidthDp600)
{
scrollView.postDelayed(new Runnable() {
public void run() {
scrollView.scrollTo(0, bgImage.getBottom());
}
}, 100);
} else {
// If orientation is vertical, scroll to the top (!) of next question:
if (isPhonePortrait)
{
scrollView.postDelayed(new Runnable() {
public void run() {
scrollView.scrollTo(0, question2.getTop());
}
}, 100);
}
// If orientation is horizontal, scroll to the bottom (!) of next question:
else if (isPhoneLandscape)
{
scrollView.postDelayed(new Runnable() {
public void run() {
scrollView.scrollTo(0, endOf2.getBottom());
}
}, 100);
}
}
}
/**
* ***** ***** ***** Question nr. 2 ***** ***** *****
*/
public void submitAnswer2(View view) {
boolean isCheckedQ2A3 = answerQ2A3.isChecked();
// Check if the answer is correct & update the quiz score:
if (isCheckedQ2A3) {
quizScore = quizScore + 1;
Log.v("MainActivity", "Score is " + quizScore);
}
// Prevent multiple answer submitting:
buttonQ2.setEnabled(false);
// Finish here & scroll to the next question:
if (isSmallestScreenWidthDp600)
{
scrollView.postDelayed(new Runnable() {
public void run() {
scrollView.scrollTo(0, bgImage.getBottom());
}
}, 100);
} else {
if (isPhonePortrait)
{
scrollView.postDelayed(new Runnable() {
public void run() {
scrollView.scrollTo(0, question3.getTop());
}
}, 100);
} else if (isPhoneLandscape)
{
scrollView.postDelayed(new Runnable() {
public void run() {
scrollView.scrollTo(0, endOf3.getTop());
}
}, 100);
}
}
}
/**
* ***** ***** ***** Question nr. 3 ***** ***** *****
*/
public void submitAnswer3(View view) {
boolean isCheckedQ3A4 = answerQ3A4.isChecked();
// Check if the answer is correct & update the quiz score:
if (isCheckedQ3A4) {
quizScore = quizScore + 1;
Log.v("MainActivity", "Score is " + quizScore);
}
// Prevent multiple answer submitting:
buttonQ3.setEnabled(false);
// Finish here & scroll to the next question:
if (isSmallestScreenWidthDp600)
{
scrollView.postDelayed(new Runnable() {
public void run() {
scrollView.scrollTo(0, group456.getTop());
}
}, 100);
} else {
if (isPhonePortrait)
{
scrollView.postDelayed(new Runnable() {
public void run() {
scrollView.scrollTo(0, question4.getTop());
}
}, 100);
} else if (isPhoneLandscape)
{
scrollView.postDelayed(new Runnable() {
public void run() {
scrollView.scrollTo(0, endOf4.getBottom());
}
}, 100);
}
}
}
/**
* ***** ***** ***** Question nr. 4 ***** ***** *****
*/
public void submitAnswer4(View view) {
// Get user submitted answer:
boolean isCheckedQ4A1 = answerQ4A1.isChecked();
boolean isCheckedQ4A2 = answerQ4A2.isChecked();
boolean isCheckedQ4A3 = answerQ4A3.isChecked();
boolean isCheckedQ4A4 = answerQ4A4.isChecked();
// Check if the answer is correct & update the quiz score:
if (isCheckedQ4A1 && (!isCheckedQ4A2) && isCheckedQ4A3 && isCheckedQ4A4) {
quizScore = quizScore + 1;
Log.v("MainActivity", "Score is " + quizScore);
}
// Prevent multiple answer submitting:
buttonQ4.setEnabled(false);
// Finish here & scroll to the next question:
if (isSmallestScreenWidthDp600)
{
scrollView.postDelayed(new Runnable() {
public void run() {
scrollView.scrollTo(0, group456.getTop());
}
}, 100);
} else {
if (isPhonePortrait)
{
scrollView.postDelayed(new Runnable() {
public void run() {
scrollView.scrollTo(0, question5.getTop());
}
}, 100);
} else if (isPhoneLandscape)
{
scrollView.postDelayed(new Runnable() {
public void run() {
scrollView.scrollTo(0, endOf5.getBottom());
}
}, 100);
}
}
}
/**
* ***** ***** ***** Question nr. 5 ***** ***** *****
*/
public void submitAnswer5(View view) {
// Check if the answer is correct & update the quiz score:
if (answerQ5A1.getText().toString().equals("Gunther")) {
quizScore = quizScore + 1;
Log.v("MainActivity", "Score is " + quizScore);
}
// Prevent multiple answer submitting:
buttonQ5.setEnabled(false);
// Finish here & scroll to the next question:
if (isSmallestScreenWidthDp600)
{
scrollView.postDelayed(new Runnable() {
public void run() {
scrollView.scrollTo(0, group456.getTop());
}
}, 100);
} else {
if (isPhonePortrait)
{
scrollView.postDelayed(new Runnable() {
public void run() {
scrollView.scrollTo(0, question6.getTop());
}
}, 100);
} else if (isPhoneLandscape)
{
scrollView.postDelayed(new Runnable() {
public void run() {
scrollView.scrollTo(0, endOf6.getBottom());
}
}, 100);
}
}
}
/**
* ***** ***** ***** Question nr. 6 ***** ***** *****
*/
public void submitAnswer6(View view) {
boolean isCheckedQ6A1 = answerQ6A1.isChecked();
// Check if the answer is correct & update the quiz score:
if (isCheckedQ6A1) {
quizScore = quizScore + 1;
Log.v("MainActivity", "Score is " + quizScore);
}
// Prevent multiple answer submitting:
buttonQ6.setEnabled(false);
// Finish here & scroll to the next question:
if (isSmallestScreenWidthDp600)
{
scrollView.postDelayed(new Runnable() {
public void run() {
scrollView.scrollTo(0, group456.getBottom());
}
}, 100);
} else {
if (isPhonePortrait)
{
scrollView.postDelayed(new Runnable() {
public void run() {
scrollView.scrollTo(0, question7.getTop());
}
}, 100);
} else if (isPhoneLandscape)
{
scrollView.postDelayed(new Runnable() {
public void run() {
scrollView.scrollTo(0, endOf7.getBottom());
}
}, 100);
}
}
}
/**
* ***** ***** ***** Question nr. 7 ***** ***** *****
*/
public void submitAnswer7(View view) {
boolean isCheckedQ7A4 = answerQ7A4.isChecked();
// Check if the answer is correct & update the quiz score:
if (isCheckedQ7A4) {
quizScore = quizScore + 1;
Log.v("MainActivity", "Score is " + quizScore);
}
// Prevent multiple answer submitting:
buttonQ7.setEnabled(false);
// Finish here & scroll to the next question:
if (isSmallestScreenWidthDp600)
{
scrollView.postDelayed(new Runnable() {
public void run() {
scrollView.scrollTo(0, group456.getBottom());
}
}, 100);
} else {
if (isPhonePortrait)
{
scrollView.postDelayed(new Runnable() {
public void run() {
scrollView.scrollTo(0, question8.getTop());
}
}, 100);
} else if (isPhoneLandscape)
{
scrollView.postDelayed(new Runnable() {
public void run() {
scrollView.scrollTo(0, endOf8.getBottom());
}
}, 100);
}
}
}
/**
* ***** ***** ***** Question nr. 8 ***** ***** *****
*/
public void submitAnswer8(View view) {
boolean isCheckedQ8A1 = answerQ8A1.isChecked();
// Check if the answer is correct & update the quiz score:
if (isCheckedQ8A1) {
quizScore = quizScore + 1;
Log.v("MainActivity", "Score is " + quizScore);
}
// Prevent multiple answer submitting:
buttonQ8.setEnabled(false);
// Finish here & scroll to the next question:
if (isSmallestScreenWidthDp600)
{
scrollView.postDelayed(new Runnable() {
public void run() {
scrollView.scrollTo(0, group456.getBottom());
}
}, 100);
} else {
if (isPhonePortrait)
{
scrollView.postDelayed(new Runnable() {
public void run() {
scrollView.scrollTo(0, question9.getTop());
}
}, 100);
} else if (isPhoneLandscape)
{
scrollView.postDelayed(new Runnable() {
public void run() {
scrollView.scrollTo(0, endOf9.getBottom());
}
}, 100);
}
}
}
/**
* ***** ***** ***** Question nr. 9 ***** ***** *****
*/
public void submitAnswer9(View view) {
boolean isCheckedQ9A2 = answerQ9A2.isChecked();
// Check if the answer is correct & update the quiz score:
if (isCheckedQ9A2) {
quizScore = quizScore + 1;
Log.v("MainActivity", "Score is " + quizScore);
}
// Prevent multiple answer submitting:
buttonQ9.setEnabled(false);
// Finish here & scroll to the next question:
if (isSmallestScreenWidthDp600)
{
scrollView.postDelayed(new Runnable() {
public void run() {
scrollView.scrollTo(0, mainLinear.getBottom());
}
}, 100);
} else {
if (isPhonePortrait)
{
scrollView.postDelayed(new Runnable() {
public void run() {
scrollView.scrollTo(0, question10.getTop());
}
}, 100);
} else if (isPhoneLandscape)
{
scrollView.postDelayed(new Runnable() {
public void run() {
scrollView.scrollTo(0, endOf10.getBottom());
}
}, 100);
}
}
}
/**
* ***** ***** ***** Question nr. 10 ***** ***** *****
*/
public void submitAnswer10(View view) {
boolean isCheckedQ10A4 = answerQ10A4.isChecked();
// Check if the answer is correct & update the quiz score:
if (isCheckedQ10A4) {
quizScore = quizScore + 1;
Log.v("MainActivity", "Score is " + quizScore);
}
// Prevent multiple answer submitting:
buttonQ10.setEnabled(false);
// Finish here & scroll to the end:
if (isSmallestScreenWidthDp600)
{
scrollView.postDelayed(new Runnable() {
public void run() {
scrollView.scrollTo(0, mainLinear.getBottom());
}
}, 100);
} else {
if (isPhonePortrait)
{
scrollView.postDelayed(new Runnable() {
public void run() {
scrollView.scrollTo(0, showName.getTop());
}
}, 100);
} else if (isPhoneLandscape)
{
scrollView.postDelayed(new Runnable() {
public void run() {
scrollView.scrollTo(0, mainLinear.getBottom());
}
}, 100);
}
}
}
/**
* Show the quiz score toast:
*/
public void buttonScore(View view) {
if (quizScore == 10) {
Toast toast = Toast.makeText(getApplicationContext(), getString(R.string.you_scored).toUpperCase() + " " + quizScore + " " + getString(R.string.out_of_10).toUpperCase() + "\n\n\n" + getString(R.string.how_you_doin), Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
}
if (quizScore > 5 && quizScore < 10) {
Toast toast = Toast.makeText(getApplicationContext(), getString(R.string.you_scored).toUpperCase() + " " + quizScore + " " + getString(R.string.out_of_10).toUpperCase() + "\n\n\n" + getString(R.string.they_dont_know), Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
}
if (quizScore <= 5) {
Toast toast = Toast.makeText(getApplicationContext(), getString(R.string.you_scored).toUpperCase() + " " + quizScore + " " + getString(R.string.out_of_10).toUpperCase() + "\n\n\n" + getString(R.string.big_deal), Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
}
}
/**
* ***** ***** ***** Reset quiz: ***** ***** *****
*/
public void buttonReset(View view) {
Intent i = getApplicationContext().getPackageManager()
.getLaunchIntentForPackage(getApplicationContext().getPackageName());
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
}
}
<resources>
<string name="app_name">Friends Quiz</string>
<string name="question_1">Who had a lunch together every day for all 10 years of filming?</string>
<string name="answer_11">David Schwimmer</string>
<string name="answer_12">Jennifer Aniston</string>
<string name="answer_13">Courteney Cox</string>
<string name="answer_14">Lisa Kudrow</string>
<string name="question_2">How many hours average Friends episode took to film?</string>
<string name="answer_21">Nine</string>
<string name="answer_22">Eleven</string>
<string name="answer_23">Five</string>
<string name="answer_24">Two</string>
<string name="question_3">In the first season, each of the main six cast members received $22,000 per episode. How much did they earn by the final season?</string>
<string name="answer_31">$100,000 per episode</string>
<string name="answer_32">$50,000 per episode</string>
<string name="answer_33">$200,000 per episode</string>
<string name="answer_34">$1,000,000 per episode</string>
<string name="question_4">How was the show originally called, before becoming Friends?</string>
<string name="answer_41">Insomnia Cafe</string>
<string name="answer_42">Days of Our Lives</string>
<string name="answer_43">Friends Like Us</string>
<string name="answer_44">Six of One</string>
<string name="question_5">Which character didn\'t have a name until the middle of the second season?</string>
<string name="type_in_the_answer">Type in the answer</string>
<string name="question_6">Which actress producers originally wanted to play Rachel?</string>
<string name="answer_61">Courteney Cox</string>
<string name="answer_62">Monica Bellucci</string>
<string name="answer_63">Lisa Kudrow</string>
<string name="answer_64">Cameron Diaz</string>
<string name="question_7">Ross is __ years old for three years.</string>
<string name="answer_71">30</string>
<string name="answer_72">32</string>
<string name="answer_73">36</string>
<string name="answer_74">29</string>
<string name="question_8">Who directed 10 Friends episodes?</string>
<string name="answer_81">David Schwimmer</string>
<string name="answer_82">Courteney Cox</string>
<string name="answer_83">Matthew Perry</string>
<string name="answer_84">Jennifer Aniston</string>
<string name="question_9">Which actress turned down an offer to play Phoebe?</string>
<string name="answer_91">Cameron Diaz</string>
<string name="answer_92">Ellen DeGeneres</string>
<string name="answer_93">Pamela Anderson</string>
<string name="answer_94">Drew Barrymore</string>
<string name="question_10">What is the name of character Joey plays in a soap opera Days of Our Lives?</string>
<string name="answer_101">Dr. Blake Ramoray</string>
<string name="answer_102">Dr. Blake Memoray</string>
<string name="answer_103">Dr. Drake Lemoray</string>
<string name="answer_104">Dr. Drake Ramoray</string>
<string name="welcome_to_the">Welcome to the</string>
<string name="friends">Friends</string>
<string name="quiz">Quiz</string>
<string name="next"><![CDATA[Submit & Go Next]]></string>
<string name="reset_try_again"><![CDATA[RESET & TRY AGAIN]]></string>
<string name="score">score</string>
<string name="are_you_ready">Are you ready,</string>
<string name="name_error">Please enter your name!</string>
<string name="you_scored">You scored</string>
<string name="out_of_10">out of 10!</string>
<string name="how_you_doin">How YOU doin\'?</string>
<string name="they_dont_know">They don\'t know that we know they know we know!</string>
<string name="big_deal">Just so you know, it\'s not that common, it doesn\'t happen to every guy, and it is a big deal!</string>
<string name="show_me_score">SHOW ME SCORE</string>
<string name="submit">SUBMIT</string>
<string name="_10_10">10/10</string>
<string name="_9_10">9/10</string>
<string name="_8_10">8/10</string>
<string name="_7_10">7/10</string>
<string name="_6_10">6/10</string>
<string name="_5_10">5/10</string>
<string name="_4_10">4/10</string>
<string name="_3_10">3/10</string>
<string name="_2_10">2/10</string>
<string name="_1_10">1/10</string>
<string name="start_quiz">Start Quiz</string>
<string name="please_enter_your_name_to_start_quiz">Please enter your name to start quiz!</string>
</resources>
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:background">#F5F3F3</item>
</style>
<style name="quiz_name">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_gravity">center_horizontal</item>
<item name="android:fontFamily">@font/covered_by_your_grace</item>
<item name="android:gravity">center</item>
<item name="android:textAllCaps">true</item>
<item name="android:textColor">@color/title</item>
<item name="android:textScaleX">1.2</item>
<item name="android:textSize">@dimen/logo_text_size_54sp</item>
</style>
<style name="enter_your_name">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_marginBottom">@dimen/answer_padding_start_24dp</item>
<item name="android:layout_marginTop">@dimen/answer_padding_start_24dp</item>
<item name="android:cursorVisible">false</item>
<item name="android:gravity">center</item>
<item name="android:imeOptions">actionDone</item>
<item name="android:inputType">textCapWords</item>
</style>
<style name="main_button">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_gravity">center</item>
<item name="android:layout_marginTop">@dimen/answer_padding_start_24dp</item>
</style>
<style name="yellow_line">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">1dp</item>
<item name="android:layout_marginTop">@dimen/answer_padding_start_24dp</item>
<item name="android:background">#FFDF70</item>
</style>
<style name="question_layout_old">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:orientation">horizontal</item>
<item name="android:paddingTop">@dimen/answer_padding_start_24dp</item>
</style>
<style name="question_number_blush">
<item name="android:layout_width">@dimen/question_circle_diameter_50dp</item>
<item name="android:layout_height">@dimen/question_circle_diameter_50dp</item>
<item name="android:layout_gravity">center</item>
<item name="android:layout_margin">@dimen/button_margin_text_start_end_8dp</item>
<item name="android:background">@drawable/circle_blush</item>
<item name="android:textColor">@android:color/white</item>
</style>
<style name="question_text">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:paddingBottom">@dimen/button_margin_text_start_end_8dp</item>
<item name="android:paddingEnd">@dimen/button_margin_text_start_end_8dp</item>
<item name="android:paddingLeft">@dimen/button_margin_text_start_end_8dp</item>
<item name="android:paddingStart">@dimen/button_margin_text_start_end_8dp</item>
<item name="android:textAppearance">?android:textAppearanceLarge</item>
</style>
<style name="checkbox_answer">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_marginStart">@dimen/answer_margin_start_16dp</item>
<item name="android:paddingStart">@dimen/answer_padding_start_24dp</item>
<item name="android:textAppearance">?android:textAppearanceMedium</item>
</style>
<style name="question_number_yellow">
<item name="android:layout_width">@dimen/question_circle_diameter_50dp</item>
<item name="android:layout_height">@dimen/question_circle_diameter_50dp</item>
<item name="android:layout_gravity">center</item>
<item name="android:layout_margin">@dimen/button_margin_text_start_end_8dp</item>
<item name="android:background">@drawable/circle_yellow</item>
<item name="android:textColor">@android:color/white</item>
</style>
<style name="blush_line">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">1dp</item>
<item name="android:layout_marginTop">@dimen/answer_padding_start_24dp</item>
<item name="android:background">#F29596</item>
</style>
<style name="question_layout">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:orientation">horizontal</item>
<item name="android:paddingTop">@dimen/question_padding_top_48dp</item>
</style>
<style name="question_number_blue">
<item name="android:layout_width">@dimen/question_circle_diameter_50dp</item>
<item name="android:layout_height">@dimen/question_circle_diameter_50dp</item>
<item name="android:layout_gravity">center</item>
<item name="android:layout_margin">@dimen/button_margin_text_start_end_8dp</item>
<item name="android:background">@drawable/circle_blue</item>
<item name="android:textColor">@android:color/white</item>
</style>
<style name="show_your_name">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_gravity">center_horizontal</item>
<item name="android:gravity">center</item>
<item name="android:padding">@dimen/answer_margin_start_16dp</item>
<item name="android:textColor">@color/name</item>
<item name="android:textSize">@dimen/name_text_size_34sp</item>
</style>
<style name="large_button">
<item name="android:layout_width">@dimen/large_button_width_200dp</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_gravity">center</item>
<item name="android:layout_marginTop">@dimen/answer_padding_start_24dp</item>
</style>
<style name="blue_line">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">1dp</item>
<item name="android:layout_marginTop">@dimen/answer_padding_start_24dp</item>
<item name="android:background">#7CDAF2</item>
</style>
</resources>
@evanca
Copy link
Author

evanca commented Jan 8, 2018

2018-01-08 11_20_25-android emulator - nexus_5x_api_27_5554-horz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment