Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
kabirwdwww committed Aug 17, 2022
0 parents commit 2c1b9cb
Show file tree
Hide file tree
Showing 47 changed files with 1,172 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
38 changes: 38 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
plugins {
id 'com.android.application'
}

android {
compileSdk 32

defaultConfig {
applicationId "com.example.quizapp"
minSdk 21
targetSdk 32
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {

implementation 'androidx.appcompat:appcompat:1.5.0'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
21 changes: 21 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# 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 *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.example.quizapp;

import android.content.Context;

import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
assertEquals("com.example.quizapp", appContext.getPackageName());
}
}
27 changes: 27 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.quizapp">

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.QuizApp"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
196 changes: 196 additions & 0 deletions app/src/main/java/com/example/quizapp/MainActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
package com.example.quizapp;


import android.annotation.SuppressLint;
import android.os.Build;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;

import saniandkd.questions;

public class MainActivity extends AppCompatActivity
implements View.OnClickListener {
// setting up things
private Button falseButton;
private Button trueButton;
private ImageButton nextButton;
private ImageButton prevButton;
private ImageView Image;
private TextView questionTextView;
private int correct = 0;
// to keep current question track
private int currentQuestionIndex = 0;

private final questions[] questionBank = new questions[] {
// array of objects of class Question
// providing questions from string
// resource and the correct ans
new questions()(R.string.a, true),
new void questions()(R.string.b, false),
new void questions(R.string.c, true),
new void Question(R.string.d, true),
new void Question(R.string.e, true),
new void Question(R.string.f, false),

@Override
public void onClick(View v) {

}
};

protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// setting up the buttons
// associated with id
falseButton = findViewById(R.id.false_button);
trueButton = findViewById(R.id.true_button);
nextButton = findViewById(R.id.next_button);
prevButton = findViewById(R.id.prev_button);
// register our buttons to listen to
// click events
questionTextView
= findViewById(R.id.answer_text_view);
Image = findViewById(R.id.myimage);
falseButton.setOnClickListener(this);
trueButton.setOnClickListener(this);
nextButton.setOnClickListener(this);
prevButton.setOnClickListener(this);
}

@SuppressLint("SetTextI18n")
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
public void onClick(View v)
{
// checking which button is
// clicked by user
// in this case user choose false
switch (v.getId()) {
case R.id.false_button:
checkAnswer(false);
break;

case R.id.true_button:
checkAnswer(true);
break;

case R.id.next_button:
// go to next question
// limiting question bank range
if (currentQuestionIndex < 7) {
currentQuestionIndex
= currentQuestionIndex + 1;
// we are safe now!
// last question reached
// making buttons
// invisible
if (currentQuestionIndex == 6) {
questionTextView.setText(getString(
R.string.correct, correct));
nextButton.setVisibility(
View.INVISIBLE);
prevButton.setVisibility(
View.INVISIBLE);
trueButton.setVisibility(
View.INVISIBLE);
falseButton.setVisibility(
View.INVISIBLE);
if (correct > 3)

questionTextView.setText(
"CORRECTNESS IS " + correct
+ " "
+ "OUT OF 6");
// showing correctness
else
Image.setImageResource(
R.drawable.resu);
// if correctness<3 showing sad emoji
}
else {
updateQuestion();
}
}

break;
case R.id.prev_button:
if (currentQuestionIndex > 0) {
currentQuestionIndex
= (currentQuestionIndex - 1)
% questionBank.length;
updateQuestion();
}
}
}

@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private void updateQuestion()
{
Log.d("Current",
"onClick: " + currentQuestionIndex);

questionTextView.setText(
questionBank[currentQuestionIndex]
.getAnswerResId());
// setting the textview with new question
switch (currentQuestionIndex) {
case 1:
// setting up image for each
// question
Image.setImageResource(R.drawable.f2);
break;
case 2:
Image.setImageResource(R.drawable.f3);
break;
case 3:
Image.setImageResource(R.drawable.f4);
break;
case 4:
Image.setImageResource(R.drawable.f5);
break;
case 5:
Image.setImageResource(R.drawable.f6);
break;
case 6:
Image.setImageResource(R.drawable.f7);
break;
case 7:
Image.setImageResource(R.drawable.f1);
break;
}
}
private void checkAnswer(boolean userChooseCorrect)
{
boolean answerIsTrue
= questionBank[currentQuestionIndex]
.isAnswerTrue();
// getting correct ans of current question
int toastMessageId;
// if ans matches with the
// button clicked

if (userChooseCorrect == answerIsTrue) {
toastMessageId = R.string.correct_answer;
correct++;
}
else {
// showing toast
// message correct
toastMessageId = R.string.wrong_answer;
}

Toast
.makeText(MainActivity.this, toastMessageId,
Toast.LENGTH_SHORT)
.show();
}
}

Loading

0 comments on commit 2c1b9cb

Please sign in to comment.