From 48861254283b6953c1f71a2822d8f6909b8df825 Mon Sep 17 00:00:00 2001 From: H Malik Date: Mon, 5 Jun 2017 15:50:18 +0100 Subject: [PATCH] Initial commit --- .gitignore | 9 + .idea/compiler.xml | 22 ++ .idea/copyright/profiles_settings.xml | 3 + .idea/gradle.xml | 18 + .idea/misc.xml | 46 +++ .idea/modules.xml | 9 + .idea/runConfigurations.xml | 12 + app/.gitignore | 1 + app/build.gradle | 29 ++ app/proguard-rules.pro | 17 + .../quizapp/ExampleInstrumentedTest.java | 26 ++ app/src/main/AndroidManifest.xml | 20 ++ .../example/h_mal/quizapp/MainActivity.java | 312 ++++++++++++++++ app/src/main/res/layout/activity_main.xml | 338 ++++++++++++++++++ app/src/main/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 3418 bytes app/src/main/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 2206 bytes app/src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 4842 bytes .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 7718 bytes .../main/res/mipmap-xxxhdpi/ic_launcher.png | Bin 0 -> 10486 bytes app/src/main/res/values-w820dp/dimens.xml | 6 + app/src/main/res/values/colors.xml | 6 + app/src/main/res/values/dimens.xml | 5 + app/src/main/res/values/strings.xml | 3 + app/src/main/res/values/styles.xml | 38 ++ .../h_mal/quizapp/ExampleUnitTest.java | 17 + build.gradle | 23 ++ gradle.properties | 17 + gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 53636 bytes gradle/wrapper/gradle-wrapper.properties | 6 + gradlew | 160 +++++++++ gradlew.bat | 90 +++++ settings.gradle | 1 + 32 files changed, 1234 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/compiler.xml create mode 100644 .idea/copyright/profiles_settings.xml create mode 100644 .idea/gradle.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/runConfigurations.xml create mode 100644 app/.gitignore create mode 100644 app/build.gradle create mode 100644 app/proguard-rules.pro create mode 100644 app/src/androidTest/java/com/example/h_mal/quizapp/ExampleInstrumentedTest.java create mode 100644 app/src/main/AndroidManifest.xml create mode 100644 app/src/main/java/com/example/h_mal/quizapp/MainActivity.java create mode 100644 app/src/main/res/layout/activity_main.xml create mode 100644 app/src/main/res/mipmap-hdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-mdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-xhdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-xxhdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-xxxhdpi/ic_launcher.png create mode 100644 app/src/main/res/values-w820dp/dimens.xml create mode 100644 app/src/main/res/values/colors.xml create mode 100644 app/src/main/res/values/dimens.xml create mode 100644 app/src/main/res/values/strings.xml create mode 100644 app/src/main/res/values/styles.xml create mode 100644 app/src/test/java/com/example/h_mal/quizapp/ExampleUnitTest.java create mode 100644 build.gradle create mode 100644 gradle.properties create mode 100644 gradle/wrapper/gradle-wrapper.jar create mode 100644 gradle/wrapper/gradle-wrapper.properties create mode 100644 gradlew create mode 100644 gradlew.bat create mode 100644 settings.gradle diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..39fb081 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +*.iml +.gradle +/local.properties +/.idea/workspace.xml +/.idea/libraries +.DS_Store +/build +/captures +.externalNativeBuild diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..96cc43e --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml new file mode 100644 index 0000000..e7bedf3 --- /dev/null +++ b/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..7ac24c7 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,18 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..5d19981 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..8160fd1 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..7f68460 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..69755ef --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,29 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 24 + buildToolsVersion "25.0.0" + defaultConfig { + applicationId "com.example.h_mal.quizapp" + minSdkVersion 15 + targetSdkVersion 24 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { + exclude group: 'com.android.support', module: 'support-annotations' + }) + compile 'com.android.support:appcompat-v7:24.2.1' + testCompile 'junit:junit:4.12' +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..05e856b --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,17 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in C:\Users\h_mal\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/app/src/androidTest/java/com/example/h_mal/quizapp/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/example/h_mal/quizapp/ExampleInstrumentedTest.java new file mode 100644 index 0000000..5e1caa7 --- /dev/null +++ b/app/src/androidTest/java/com/example/h_mal/quizapp/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.example.h_mal.quizapp; + +import android.content.Context; +import android.support.test.InstrumentationRegistry; +import android.support.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumentation test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() throws Exception { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getTargetContext(); + + assertEquals("com.example.h_mal.quizapp", appContext.getPackageName()); + } +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..6fbf6c0 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/example/h_mal/quizapp/MainActivity.java b/app/src/main/java/com/example/h_mal/quizapp/MainActivity.java new file mode 100644 index 0000000..7fc9873 --- /dev/null +++ b/app/src/main/java/com/example/h_mal/quizapp/MainActivity.java @@ -0,0 +1,312 @@ +package com.example.h_mal.quizapp; + +import android.content.Intent; +import android.net.Uri; +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import android.view.View; +import android.widget.CheckBox; +import android.widget.EditText; +import android.widget.RadioButton; +import android.widget.RadioGroup; +import android.widget.Toast; + +public class MainActivity extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + } + + /** + * Initial score quantity set as public + */ + int quantity = 0; + boolean isCorrectQ1, isCorrectQ2, isCorrectQ3, isCorrectQ4, isCorrectQ5, isCorrectQ6, isCorrectQ7, isCorrectQ8, isCorrectQ9; + + /** + * Radioboxes controls defined + */ + public void QOne(View view) { + boolean checked = ((RadioButton) view).isChecked(); + switch (view.getId()) { + case R.id.QOneYes: + if (checked) { + isCorrectQ1 = true; + Toast.makeText(MainActivity.this, "Correct", + Toast.LENGTH_LONG).show(); + } + break; + case R.id.QOneNo: + if (checked) { + isCorrectQ1 = false; + RadioGroup questionOneRG = (RadioGroup) findViewById(R.id.QOneGroup); + questionOneRG.clearCheck(); + Toast.makeText(MainActivity.this, "INCORRECT", + Toast.LENGTH_LONG).show(); + } + break; + } + } + + public void QTwo(View view) { + boolean checked = ((RadioButton) view).isChecked(); + switch (view.getId()) { + case R.id.QTwoYes: + if (checked) { + isCorrectQ2 = false; + RadioGroup questionOneRG = (RadioGroup) findViewById(R.id.QTwoGroup); + questionOneRG.clearCheck(); + Toast.makeText(MainActivity.this, "INCORRECT", + Toast.LENGTH_LONG).show(); + } + break; + case R.id.QTwoNo: + if (checked) { + isCorrectQ2 = true; + Toast.makeText(MainActivity.this, "Correct", + Toast.LENGTH_LONG).show(); + } + break; + } + } + + public void QThree(View view) { + boolean checked = ((RadioButton) view).isChecked(); + switch (view.getId()) { + case R.id.QThreeYes: + if (checked) { + isCorrectQ3 = true; + Toast.makeText(MainActivity.this, "Correct", + Toast.LENGTH_LONG).show(); + } + break; + case R.id.QThreeNo: + if (checked) { + isCorrectQ3 = false; + RadioGroup questionOneRG = (RadioGroup) findViewById(R.id.QThreeGroup); + questionOneRG.clearCheck(); + Toast.makeText(MainActivity.this, "INCORRECT", + Toast.LENGTH_LONG).show(); + } + break; + } + } + + public void QFour(View view) { + boolean checked = ((RadioButton) view).isChecked(); + switch (view.getId()) { + case R.id.QFourYes: + if (checked) { + isCorrectQ4 = false; + RadioGroup questionOneRG = (RadioGroup) findViewById(R.id.QFourGroup); + questionOneRG.clearCheck(); + Toast.makeText(MainActivity.this, "INCORRECT", + Toast.LENGTH_LONG).show(); + } + break; + case R.id.QFourNo:{ + isCorrectQ4 = true; + Toast.makeText(MainActivity.this, "Correct", + Toast.LENGTH_LONG).show(); + } + break; + } + } + + public void QFive(View view) { + boolean checked = ((RadioButton) view).isChecked(); + switch (view.getId()) { + case R.id.QFiveYes: + if (checked) { + isCorrectQ5 = true; + Toast.makeText(MainActivity.this, "Correct", + Toast.LENGTH_LONG).show(); + } + break; + case R.id.QFiveNo: + if (checked) { + isCorrectQ5 = false; + RadioGroup questionOneRG = (RadioGroup) findViewById(R.id.QFiveGroup); + questionOneRG.clearCheck(); + Toast.makeText(MainActivity.this, "INCORRECT", + Toast.LENGTH_LONG).show(); + } + break; + } + } + + public void QSix(View view) { + boolean checked = ((RadioButton) view).isChecked(); + switch (view.getId()) { + case R.id.QSixYes: + if (checked) { + isCorrectQ6 = false; + RadioGroup questionOneRG = (RadioGroup) findViewById(R.id.QSixGroup); + questionOneRG.clearCheck(); + Toast.makeText(MainActivity.this, "INCORRECT", + Toast.LENGTH_LONG).show(); + } + break; + case R.id.QSixNo: + if (checked) { + isCorrectQ6 = true; + Toast.makeText(MainActivity.this, "Correct", + Toast.LENGTH_LONG).show(); + } + break; + } + } + + public void QSeven(View view) { + boolean checked = ((RadioButton) view).isChecked(); + switch (view.getId()) { + case R.id.QSevenYes: + if (checked) { + isCorrectQ7 = true; + Toast.makeText(MainActivity.this, "Correct", + Toast.LENGTH_LONG).show(); + } + break; + case R.id.QSevenNo: + if (checked) { + isCorrectQ7 = false; + RadioGroup questionOneRG = (RadioGroup) findViewById(R.id.QSevenGroup); + questionOneRG.clearCheck(); + Toast.makeText(MainActivity.this, "INCORRECT", + Toast.LENGTH_LONG).show(); + } + break; + } + } + + public void QEight (View view) { + EditText answerEight = (EditText) findViewById(R.id.QuestionEightAnswer); + String QEightAnswer = answerEight.getText().toString(); + if (QEightAnswer.equals("Continent")) { + Toast.makeText(MainActivity.this, "Correct", + Toast.LENGTH_LONG).show(); + isCorrectQ8 = true; + }else{ Toast.makeText(MainActivity.this, "INCORRECT", + Toast.LENGTH_LONG).show(); + isCorrectQ8 = true; + answerEight.setText("");} + } + + public void QNine (View view){ + CheckBox checkboxA = (CheckBox) findViewById(R.id.checkboxA); + boolean boxA = checkboxA.isChecked(); + + CheckBox checkboxB = (CheckBox) findViewById(R.id.checkboxB); + boolean boxB = checkboxB.isChecked(); + + CheckBox checkboxC = (CheckBox) findViewById(R.id.checkboxC); + boolean boxC = checkboxC.isChecked(); + + CheckBox checkboxD = (CheckBox) findViewById(R.id.checkboxD); + boolean boxD = checkboxD.isChecked(); + + if (boxA & boxB & !boxC & !boxD) {Toast.makeText(MainActivity.this, "Correct", + Toast.LENGTH_LONG).show(); + isCorrectQ9= true; + + + } else { + Toast.makeText(MainActivity.this, "INCORRECT", + Toast.LENGTH_LONG).show(); + isCorrectQ9= false; + CheckBox answerA = (CheckBox) findViewById(R.id.checkboxA); + answerA.setChecked(false); + CheckBox answerB = (CheckBox) findViewById(R.id.checkboxB); + answerB.setChecked(false); + CheckBox answerC = (CheckBox) findViewById(R.id.checkboxC); + answerC.setChecked(false); + CheckBox answerD = (CheckBox) findViewById(R.id.checkboxD); + answerD.setChecked(false); + } + + } + + public void submitScore(View view) { + String review = createReviewSummary(); + Toast.makeText(MainActivity.this, review, + Toast.LENGTH_LONG).show(); + /** + Resetting score and checkboxes + */ + quantity = 0; + isCorrectQ1 = false; + isCorrectQ2 = false; + isCorrectQ3 = false; + isCorrectQ4 = false; + isCorrectQ5 = false; + isCorrectQ6 = false; + isCorrectQ7 = false; + isCorrectQ8 = false; + isCorrectQ9 = false; + + RadioGroup questionOneRG = (RadioGroup) findViewById(R.id.QOneGroup); + questionOneRG.clearCheck(); + RadioGroup questionTwoRG = (RadioGroup) findViewById(R.id.QTwoGroup); + questionTwoRG.clearCheck(); + RadioGroup questionThreeRG = (RadioGroup) findViewById(R.id.QThreeGroup); + questionThreeRG.clearCheck(); + RadioGroup questionFourRG = (RadioGroup) findViewById(R.id.QFourGroup); + questionFourRG.clearCheck(); + RadioGroup questionFiveRG = (RadioGroup) findViewById(R.id.QFiveGroup); + questionFiveRG.clearCheck(); + RadioGroup questionSixRG = (RadioGroup) findViewById(R.id.QSixGroup); + questionSixRG.clearCheck(); + RadioGroup questionSevenRG = (RadioGroup) findViewById(R.id.QSevenGroup); + questionSevenRG.clearCheck(); + EditText answerEight = (EditText) findViewById(R.id.QuestionEightAnswer); + answerEight.setText(""); + CheckBox answerA = (CheckBox) findViewById(R.id.checkboxA); + answerA.setChecked(false); + CheckBox answerB = (CheckBox) findViewById(R.id.checkboxB); + answerB.setChecked(false); + CheckBox answerC = (CheckBox) findViewById(R.id.checkboxC); + answerC.setChecked(false); + CheckBox answerD = (CheckBox) findViewById(R.id.checkboxD); + answerD.setChecked(false); + } + + + private String createReviewSummary() { + if(isCorrectQ1){quantity++;} + if(isCorrectQ2){quantity++;} + if(isCorrectQ3){quantity++;} + if(isCorrectQ4){quantity++;} + if(isCorrectQ5){quantity++;} + if(isCorrectQ6){quantity++;} + if(isCorrectQ7){quantity++;} + if(isCorrectQ8){quantity++;} + if(isCorrectQ9){quantity++;} + String review = "Score = " + quantity + "/" + "9"; + return review; + } + + private String createEmailContent() { + EditText nameField = (EditText) findViewById(R.id.name_field); + String name = nameField.getText().toString(); + String email = "I Just completed the Quiz on H's Quizapp \n \nYou should try it out yourself \nfrom " + name; + return email; + } + + public void shareEmail(View view) { + String email = createEmailContent(); + Intent intent = new Intent(Intent.ACTION_SENDTO); + intent.setData(Uri.parse("mailto:")); // only email apps should handle this + intent.putExtra(Intent.EXTRA_SUBJECT, "Quizapp"); + intent.putExtra(Intent.EXTRA_TEXT, email); + if (intent.resolveActivity(getPackageManager()) != null) { + startActivity(intent); + } + } +} + + + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..0086345 --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,338 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +