├── .gitattributes ├── .gitignore ├── .idea ├── codeStyles │ └── Project.xml ├── encodings.xml ├── gradle.xml ├── misc.xml ├── runConfigurations.xml └── vcs.xml ├── Certificate.jpg ├── Project Report-CST Science Quiz Android app.pdf ├── README.md ├── app ├── .gitignore ├── build.gradle ├── google-services.json ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── shashwatsupreme │ │ └── sciencequiz │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── assets │ │ └── databases │ │ │ └── ScienceQuizDB.db │ ├── java │ │ └── com │ │ │ └── shashwatsupreme │ │ │ └── sciencequiz │ │ │ ├── Adapter │ │ │ ├── AnswerSheetAdapter.java │ │ │ ├── AnswerSheetHelperAdapter.java │ │ │ ├── CategoryAdapter.java │ │ │ ├── QuestionFragmentAdapter.java │ │ │ └── ResultGridAdapter.java │ │ │ ├── Common │ │ │ ├── Common.java │ │ │ └── SpaceDecoration.java │ │ │ ├── DBHelper │ │ │ ├── DBHelper.java │ │ │ └── OnlineDBHelper.java │ │ │ ├── Interface │ │ │ ├── HighScore.java │ │ │ ├── IQuestion.java │ │ │ ├── IRecyclerHelperClick.java │ │ │ └── MyCallback.java │ │ │ ├── MainActivity.java │ │ │ ├── MainLoginActivity.java │ │ │ ├── Misc │ │ │ └── CustomViewPager.java │ │ │ ├── QuestionActivity.java │ │ │ ├── QuestionFragment.java │ │ │ ├── ResultActivity.java │ │ │ └── model │ │ │ ├── Category.java │ │ │ ├── CurrentQuestion.java │ │ │ ├── Question.java │ │ │ └── UserData.java │ └── res │ │ ├── drawable-v24 │ │ ├── ic_launcher_foreground.xml │ │ └── science_clip_art.jpg │ │ ├── drawable │ │ ├── border_bg.xml │ │ ├── grid_question_no_answer.xml │ │ ├── grid_question_right_answer.xml │ │ ├── grid_question_wrong_answer.xml │ │ ├── ic_access_time_black_24dp.xml │ │ ├── ic_check_black_24dp.xml │ │ ├── ic_check_white_24dp.xml │ │ ├── ic_clear_black_24dp.xml │ │ ├── ic_clear_white_24dp.xml │ │ ├── ic_error_outline_black_24dp.xml │ │ ├── ic_error_outline_white_24dp.xml │ │ ├── ic_format_align_justify_black_24dp.xml │ │ ├── ic_launcher_background.xml │ │ ├── ic_menu_camera.xml │ │ ├── ic_menu_gallery.xml │ │ ├── ic_menu_manage.xml │ │ ├── ic_menu_send.xml │ │ ├── ic_menu_share.xml │ │ ├── ic_menu_slideshow.xml │ │ ├── ic_mood_black_24dp.xml │ │ ├── ic_mood_white_24dp.xml │ │ ├── ic_sentiment_very_dissatisfied_black_24dp.xml │ │ ├── ic_settings_white_24dp.xml │ │ ├── ic_timer_black_24dp.xml │ │ ├── side_nav_bar.xml │ │ └── text_view_bg.xml │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── activity_main_login.xml │ │ ├── activity_question.xml │ │ ├── activity_result.xml │ │ ├── app_bar_question.xml │ │ ├── content_question.xml │ │ ├── fragment_question.xml │ │ ├── layout_answer_sheet_helper.xml │ │ ├── layout_category_item.xml │ │ ├── layout_grid_answer_sheet_item.xml │ │ ├── layout_result_item.xml │ │ ├── nav_header_question.xml │ │ ├── rectangle_text_view.xml │ │ └── settings_layout.xml │ │ ├── menu │ │ ├── activity_question_drawer.xml │ │ ├── category_menu.xml │ │ ├── question.xml │ │ └── result_menu.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── values-v21 │ │ └── styles.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── shashwatsupreme │ └── sciencequiz │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── images ├── 1.jpg ├── 10.jpg ├── 11.jpg ├── 12.jpg ├── 13.jpg ├── 14.jpg ├── 15.jpg ├── 16.jpg ├── 17.jpg ├── 18.jpg ├── 19.jpg ├── 2.jpg ├── 20.jpg ├── 21.jpg ├── 22.jpg ├── 3.jpg ├── 4.jpg ├── 5.jpg ├── 6.jpg ├── 7.jpg ├── 8.jpg ├── 9.jpg └── a.txt └── settings.gradle /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | /.idea/navEditor.xml 9 | /.idea/assetWizardSettings.xml 10 | .DS_Store 11 | /build 12 | /captures 13 | .externalNativeBuild 14 | -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | xmlns:android 14 | 15 | ^$ 16 | 17 | 18 | 19 |
20 |
21 | 22 | 23 | 24 | xmlns:.* 25 | 26 | ^$ 27 | 28 | 29 | BY_NAME 30 | 31 |
32 |
33 | 34 | 35 | 36 | .*:id 37 | 38 | http://schemas.android.com/apk/res/android 39 | 40 | 41 | 42 |
43 |
44 | 45 | 46 | 47 | .*:name 48 | 49 | http://schemas.android.com/apk/res/android 50 | 51 | 52 | 53 |
54 |
55 | 56 | 57 | 58 | name 59 | 60 | ^$ 61 | 62 | 63 | 64 |
65 |
66 | 67 | 68 | 69 | style 70 | 71 | ^$ 72 | 73 | 74 | 75 |
76 |
77 | 78 | 79 | 80 | .* 81 | 82 | ^$ 83 | 84 | 85 | BY_NAME 86 | 87 |
88 |
89 | 90 | 91 | 92 | .* 93 | 94 | http://schemas.android.com/apk/res/android 95 | 96 | 97 | ANDROID_ATTRIBUTE_ORDER 98 | 99 |
100 |
101 | 102 | 103 | 104 | .* 105 | 106 | .* 107 | 108 | 109 | BY_NAME 110 | 111 |
112 |
113 |
114 |
115 |
116 |
-------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 19 | 20 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Certificate.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shshwtkhr/ScienceQuiz-Android-App/ed9d1405af3bfac5f92e9db025cecd88ea1714d6/Certificate.jpg -------------------------------------------------------------------------------- /Project Report-CST Science Quiz Android app.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shshwtkhr/ScienceQuiz-Android-App/ed9d1405af3bfac5f92e9db025cecd88ea1714d6/Project Report-CST Science Quiz Android app.pdf -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ScienceQuiz-Android-App 2 | Please read the pdf file titled 'Project Report-CST Science Quiz Android app' to gain understanding of this project repository. 3 | 4 | ![](images/2.jpg) 5 | 6 | ![](images/7.jpg) 7 | 8 | ![](images/8.jpg) 9 | 10 | ![](images/9.jpg) 11 | 12 | ![](images/10.jpg) 13 | 14 | ![](images/11.jpg) 15 | 16 | ![](images/12.jpg) 17 | 18 | ![](images/13.jpg) 19 | 20 | ![](images/14.jpg) 21 | 22 | ![](images/15.jpg) 23 | 24 | ![](images/16.jpg) 25 | 26 | ![](images/17.jpg) 27 | 28 | ![](images/18.jpg) 29 | 30 | ![](images/19.jpg) 31 | 32 | ![](images/20.jpg) 33 | 34 | ![](images/21.jpg) 35 | 36 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'com.google.gms.google-services' 3 | 4 | android { 5 | compileSdkVersion 28 6 | defaultConfig { 7 | applicationId "com.shashwatsupreme.sciencequiz" 8 | minSdkVersion 21 9 | targetSdkVersion 28 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | implementation fileTree(dir: 'libs', include: ['*.jar']) 24 | implementation 'com.android.support:appcompat-v7:28.0.0' 25 | implementation 'com.android.support:exifinterface:28.0.0' 26 | implementation 'com.android.support:design:28.0.0' 27 | implementation 'com.android.support.constraint:constraint-layout:1.1.3' 28 | implementation 'com.android.support:support-annotations:28.0.0' 29 | implementation 'android.arch.lifecycle:extensions:1.1.1' 30 | implementation 'com.google.firebase:firebase-database:17.0.0' 31 | testImplementation 'junit:junit:4.12' 32 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 33 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 34 | 35 | implementation 'com.squareup.picasso:picasso:2.71828' 36 | implementation 'com.readystatesoftware.sqliteasset:sqliteassethelper:+' 37 | implementation 'com.github.javiersantos:MaterialStyledDialogs:2.1' 38 | implementation 'com.google.code.gson:gson:2.8.5' 39 | 40 | implementation 'com.google.firebase:firebase-auth:17.0.0' 41 | 42 | implementation 'com.firebaseui:firebase-ui-auth:4.3.1' 43 | implementation 'com.google.android.gms:play-services-auth:16.0.1' 44 | implementation 'com.facebook.android:facebook-android-sdk:[5,6)' 45 | 46 | implementation 'com.github.d-max:spots-dialog:1.1@aar' 47 | implementation 'io.paperdb:paperdb:2.6' 48 | 49 | 50 | // Required only if Twitter login support is required 51 | // Find the latest Twitter SDK releases here: https://goo.gl/E5wZvQ 52 | // implementation 'com.twitter.sdk.android:twitter-core:3.x' 53 | } 54 | -------------------------------------------------------------------------------- /app/google-services.json: -------------------------------------------------------------------------------- 1 | { 2 | "project_info": { 3 | "project_number": "304877824800", 4 | "firebase_url": "https://sciencequiz-3b7a7.firebaseio.com", 5 | "project_id": "sciencequiz-3b7a7", 6 | "storage_bucket": "sciencequiz-3b7a7.appspot.com" 7 | }, 8 | "client": [ 9 | { 10 | "client_info": { 11 | "mobilesdk_app_id": "1:304877824800:android:8a5043ef603ba87a", 12 | "android_client_info": { 13 | "package_name": "com.shashwatsupreme.sciencequiz" 14 | } 15 | }, 16 | "oauth_client": [ 17 | { 18 | "client_id": "304877824800-69koe3nipn4sms7ufc6uuvrbagssqh0l.apps.googleusercontent.com", 19 | "client_type": 1, 20 | "android_info": { 21 | "package_name": "com.shashwatsupreme.sciencequiz", 22 | "certificate_hash": "b0f4b106cb79418a326e231b5e0f658e9640875a" 23 | } 24 | }, 25 | { 26 | "client_id": "304877824800-onfrrb4jolggjqckkbhf0eg3abt0fugl.apps.googleusercontent.com", 27 | "client_type": 3 28 | } 29 | ], 30 | "api_key": [ 31 | { 32 | "current_key": "AIzaSyCvlzT_7SCfJxLAZDGDLoLLl7pihiC6Tl8" 33 | } 34 | ], 35 | "services": { 36 | "appinvite_service": { 37 | "other_platform_oauth_client": [ 38 | { 39 | "client_id": "304877824800-onfrrb4jolggjqckkbhf0eg3abt0fugl.apps.googleusercontent.com", 40 | "client_type": 3 41 | } 42 | ] 43 | } 44 | } 45 | } 46 | ], 47 | "configuration_version": "1" 48 | } -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/shashwatsupreme/sciencequiz/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.shashwatsupreme.sciencequiz; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest 19 | { 20 | @Test 21 | public void useAppContext() 22 | { 23 | // Context of the app under test. 24 | Context appContext = InstrumentationRegistry.getTargetContext(); 25 | 26 | assertEquals("com.shashwatsupreme.sciencequiz", appContext.getPackageName()); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 14 | 15 | 16 | 17 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /app/src/main/assets/databases/ScienceQuizDB.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shshwtkhr/ScienceQuiz-Android-App/ed9d1405af3bfac5f92e9db025cecd88ea1714d6/app/src/main/assets/databases/ScienceQuizDB.db -------------------------------------------------------------------------------- /app/src/main/java/com/shashwatsupreme/sciencequiz/Adapter/AnswerSheetAdapter.java: -------------------------------------------------------------------------------- 1 | package com.shashwatsupreme.sciencequiz.Adapter; 2 | 3 | import android.content.Context; 4 | import android.database.Cursor; 5 | import android.support.annotation.NonNull; 6 | import android.support.v7.widget.RecyclerView; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | 11 | import com.shashwatsupreme.sciencequiz.Common.Common; 12 | import com.shashwatsupreme.sciencequiz.R; 13 | import com.shashwatsupreme.sciencequiz.model.CurrentQuestion; 14 | 15 | import java.util.List; 16 | 17 | public class AnswerSheetAdapter extends RecyclerView.Adapter 18 | { 19 | Context context; 20 | List currentQuestionList; 21 | 22 | public AnswerSheetAdapter(Context context, List currentQuestionList) 23 | { 24 | this.context = context; 25 | this.currentQuestionList = currentQuestionList; 26 | } 27 | 28 | @NonNull 29 | @Override 30 | public MyViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) 31 | { 32 | View itemView = LayoutInflater.from(context).inflate(R.layout.layout_grid_answer_sheet_item, viewGroup, false); 33 | return new MyViewHolder(itemView); 34 | } 35 | 36 | @Override 37 | public void onBindViewHolder(@NonNull MyViewHolder myViewHolder, int i) 38 | { 39 | if((currentQuestionList.get(i)!=null)&&(myViewHolder.question_item!=null)) 40 | { 41 | if (currentQuestionList.get(i).getType() == Common.ANSWER_TYPE.RIGHT_ANSWER) 42 | myViewHolder.question_item.setBackgroundResource(R.drawable.grid_question_right_answer); 43 | else if (currentQuestionList.get(i).getType() == Common.ANSWER_TYPE.WRONG_ANSWER) 44 | myViewHolder.question_item.setBackgroundResource(R.drawable.grid_question_wrong_answer); 45 | else 46 | myViewHolder.question_item.setBackgroundResource(R.drawable.grid_question_no_answer); 47 | } 48 | 49 | } 50 | 51 | @Override 52 | public int getItemCount() 53 | { 54 | return currentQuestionList.size(); 55 | } 56 | 57 | public class MyViewHolder extends RecyclerView.ViewHolder 58 | { 59 | View question_item; 60 | public MyViewHolder(@NonNull View itemView) 61 | { 62 | super(itemView); 63 | 64 | question_item = itemView.findViewById(R.id.question_item); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /app/src/main/java/com/shashwatsupreme/sciencequiz/Adapter/AnswerSheetHelperAdapter.java: -------------------------------------------------------------------------------- 1 | package com.shashwatsupreme.sciencequiz.Adapter; 2 | 3 | 4 | import android.content.Context; 5 | import android.content.Intent; 6 | import android.support.annotation.NonNull; 7 | import android.support.v4.content.LocalBroadcastManager; 8 | import android.support.v7.widget.RecyclerView; 9 | import android.view.LayoutInflater; 10 | import android.view.View; 11 | import android.view.ViewGroup; 12 | import android.widget.LinearLayout; 13 | import android.widget.TextView; 14 | 15 | import com.shashwatsupreme.sciencequiz.Common.Common; 16 | import com.shashwatsupreme.sciencequiz.Interface.IRecyclerHelperClick; 17 | import com.shashwatsupreme.sciencequiz.R; 18 | import com.shashwatsupreme.sciencequiz.model.CurrentQuestion; 19 | 20 | import java.util.List; 21 | 22 | 23 | 24 | public class AnswerSheetHelperAdapter extends RecyclerView.Adapter { 25 | 26 | Context context; 27 | List currentQuestionList; 28 | 29 | public AnswerSheetHelperAdapter(Context context, List currentQuestionList) { 30 | this.context = context; 31 | this.currentQuestionList = currentQuestionList; 32 | } 33 | 34 | @NonNull 35 | @Override 36 | public MyViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) { 37 | View itemView = LayoutInflater.from(context).inflate(R.layout.layout_answer_sheet_helper,viewGroup,false); 38 | return new MyViewHolder(itemView); 39 | } 40 | 41 | @Override 42 | public void onBindViewHolder(@NonNull MyViewHolder myViewHolder, int i) { 43 | 44 | myViewHolder.txt_question_num.setText(String.valueOf(i+1)); // Show question number 45 | if(currentQuestionList.get(i).getType() == Common.ANSWER_TYPE.RIGHT_ANSWER) 46 | myViewHolder.layout_wrapper.setBackgroundResource(R.drawable.grid_question_right_answer); 47 | else if(currentQuestionList.get(i).getType() == Common.ANSWER_TYPE.WRONG_ANSWER) 48 | myViewHolder.layout_wrapper.setBackgroundResource(R.drawable.grid_question_wrong_answer); 49 | else 50 | myViewHolder.layout_wrapper.setBackgroundResource(R.drawable.grid_question_no_answer); 51 | myViewHolder.setiRecyclerHelperClick(new IRecyclerHelperClick() { 52 | @Override 53 | public void onClick(View view, int position) { 54 | //When user click to item , navigate to this question on Question Activity 55 | LocalBroadcastManager.getInstance(context) 56 | .sendBroadcast(new Intent( 57 | Common.KEY_GO_TO_QUESTION 58 | ).putExtra(Common.KEY_GO_TO_QUESTION,position)); 59 | } 60 | }); 61 | } 62 | 63 | @Override 64 | public int getItemCount() { 65 | return currentQuestionList.size(); 66 | } 67 | 68 | public class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener { 69 | TextView txt_question_num; 70 | LinearLayout layout_wrapper; 71 | IRecyclerHelperClick iRecyclerHelperClick; 72 | 73 | public void setiRecyclerHelperClick(IRecyclerHelperClick iRecyclerHelperClick) { 74 | this.iRecyclerHelperClick = iRecyclerHelperClick; 75 | } 76 | 77 | public MyViewHolder(@NonNull View itemView) { 78 | super(itemView); 79 | txt_question_num = (TextView)itemView.findViewById(R.id.txt_question_num); 80 | layout_wrapper = (LinearLayout) itemView.findViewById(R.id.layout_wrapper); 81 | itemView.setOnClickListener(this); 82 | } 83 | 84 | @Override 85 | public void onClick(View view) { 86 | iRecyclerHelperClick.onClick(view,getAdapterPosition()); 87 | } 88 | } 89 | } -------------------------------------------------------------------------------- /app/src/main/java/com/shashwatsupreme/sciencequiz/Adapter/CategoryAdapter.java: -------------------------------------------------------------------------------- 1 | package com.shashwatsupreme.sciencequiz.Adapter; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.support.annotation.NonNull; 6 | import android.support.v7.widget.CardView; 7 | import android.support.v7.widget.RecyclerView; 8 | import android.view.LayoutInflater; 9 | import android.view.View; 10 | import android.view.ViewGroup; 11 | import android.widget.RadioButton; 12 | import android.widget.RadioGroup; 13 | import android.widget.TextView; 14 | import android.widget.Toast; 15 | 16 | import com.shashwatsupreme.sciencequiz.Common.Common; 17 | import com.shashwatsupreme.sciencequiz.QuestionActivity; 18 | import com.shashwatsupreme.sciencequiz.R; 19 | import com.shashwatsupreme.sciencequiz.model.Category; 20 | 21 | import java.util.List; 22 | 23 | public class CategoryAdapter extends RecyclerView.Adapter 24 | { 25 | Context context; 26 | List categories; 27 | 28 | public CategoryAdapter(Context context, List categories) 29 | { 30 | this.context = context; 31 | this.categories = categories; 32 | } 33 | 34 | @NonNull 35 | @Override 36 | public MyViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) 37 | { 38 | View itemView = LayoutInflater.from(context).inflate(R.layout.layout_category_item, viewGroup, false); 39 | return new MyViewHolder(itemView); 40 | } 41 | 42 | @Override 43 | public void onBindViewHolder(@NonNull MyViewHolder myViewHolder, int i) 44 | { 45 | myViewHolder.text_category_name.setText(categories.get(i).getName()); 46 | } 47 | 48 | 49 | 50 | @Override 51 | public int getItemCount() 52 | { 53 | return categories.size(); 54 | } 55 | 56 | public class MyViewHolder extends RecyclerView.ViewHolder 57 | { 58 | CardView card_category; 59 | TextView text_category_name; 60 | RadioGroup radio_card_category_class; 61 | RadioButton rdo_class_selected; 62 | 63 | 64 | public MyViewHolder(@NonNull final View itemView) 65 | { 66 | super(itemView); 67 | card_category = (CardView) itemView.findViewById(R.id.card_category); 68 | text_category_name = itemView.findViewById(R.id.text_category_name); 69 | card_category.setOnClickListener(new View.OnClickListener() 70 | { 71 | @Override 72 | public void onClick(View v) 73 | { 74 | 75 | radio_card_category_class = itemView.findViewById(R.id.radio_class); 76 | int selectedId = radio_card_category_class.getCheckedRadioButtonId(); 77 | rdo_class_selected = itemView.findViewById(selectedId); 78 | 79 | 80 | if(selectedId!=-1) 81 | { 82 | Common.selectedCategory = categories.get(getAdapterPosition()); // Assign current category 83 | Common.selectedCategory.setClassId(Integer.parseInt(rdo_class_selected.getText().toString())); 84 | Intent intent = new Intent(context, QuestionActivity.class); 85 | context.startActivity(intent); 86 | 87 | } 88 | else 89 | { 90 | Toast.makeText(context, "First select a class!", Toast.LENGTH_SHORT).show(); 91 | } 92 | //Add the code(using MaterialStyledDialog.Builder to ask for class of the user here 93 | 94 | 95 | } 96 | }); 97 | } 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /app/src/main/java/com/shashwatsupreme/sciencequiz/Adapter/QuestionFragmentAdapter.java: -------------------------------------------------------------------------------- 1 | package com.shashwatsupreme.sciencequiz.Adapter; 2 | 3 | import android.content.Context; 4 | import android.support.annotation.Nullable; 5 | import android.support.v4.app.Fragment; 6 | import android.support.v4.app.FragmentManager; 7 | import android.support.v4.app.FragmentPagerAdapter; 8 | 9 | import com.shashwatsupreme.sciencequiz.QuestionFragment; 10 | 11 | import java.util.List; 12 | 13 | public class QuestionFragmentAdapter extends FragmentPagerAdapter 14 | { 15 | Context context; 16 | List fragmentList; 17 | 18 | public QuestionFragmentAdapter(FragmentManager fm, Context context, List fragmentList) 19 | { 20 | super(fm); 21 | this.context = context; 22 | this.fragmentList = fragmentList; 23 | } 24 | 25 | @Override 26 | public Fragment getItem(int i) 27 | { 28 | return fragmentList.get(i); 29 | } 30 | 31 | @Override 32 | public int getCount() 33 | { 34 | return fragmentList.size(); 35 | } 36 | 37 | @Nullable 38 | @Override 39 | public CharSequence getPageTitle(int position) 40 | { 41 | return new StringBuilder("Question ").append(position+1).toString(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /app/src/main/java/com/shashwatsupreme/sciencequiz/Adapter/ResultGridAdapter.java: -------------------------------------------------------------------------------- 1 | package com.shashwatsupreme.sciencequiz.Adapter; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.graphics.Color; 6 | import android.graphics.drawable.Drawable; 7 | import android.support.annotation.NonNull; 8 | import android.support.v4.content.LocalBroadcastManager; 9 | import android.support.v7.widget.RecyclerView; 10 | import android.view.LayoutInflater; 11 | import android.view.View; 12 | import android.view.ViewGroup; 13 | import android.widget.Button; 14 | 15 | import com.shashwatsupreme.sciencequiz.Common.Common; 16 | import com.shashwatsupreme.sciencequiz.R; 17 | import com.shashwatsupreme.sciencequiz.model.CurrentQuestion; 18 | 19 | import java.util.List; 20 | 21 | public class ResultGridAdapter extends RecyclerView.Adapter 22 | { 23 | Context context; 24 | List currentQuestionList; 25 | 26 | public ResultGridAdapter(Context context, List currentQuestionList) 27 | { 28 | this.context = context; 29 | this.currentQuestionList = currentQuestionList; 30 | } 31 | 32 | @NonNull 33 | @Override 34 | public MyViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) 35 | { 36 | View itemView = LayoutInflater.from(context).inflate(R.layout.layout_result_item, viewGroup, false); 37 | 38 | 39 | return new MyViewHolder(itemView); 40 | } 41 | 42 | @Override 43 | public void onBindViewHolder(@NonNull MyViewHolder myViewHolder, int i) 44 | { 45 | Drawable img; 46 | 47 | //Change color base on result 48 | if(currentQuestionList.get(i)!=null) 49 | myViewHolder.btn_question.setText(new StringBuilder("Question ").append(currentQuestionList.get(i) 50 | .getQuestionIndex()+1)); 51 | 52 | if(currentQuestionList.get(i).getType() == Common.ANSWER_TYPE.RIGHT_ANSWER) 53 | { 54 | myViewHolder.btn_question.setBackgroundColor(Color.parseColor("#ff99cc00")); 55 | img = context.getResources().getDrawable(R.drawable.ic_check_white_24dp); 56 | myViewHolder.btn_question.setCompoundDrawablesWithIntrinsicBounds(null, null, null, img); 57 | } 58 | else if(currentQuestionList.get(i).getType() == Common.ANSWER_TYPE.WRONG_ANSWER) 59 | { 60 | myViewHolder.btn_question.setBackgroundColor(Color.parseColor("#ffcc0000")); 61 | img = context.getResources().getDrawable(R.drawable.ic_clear_white_24dp); 62 | myViewHolder.btn_question.setCompoundDrawablesWithIntrinsicBounds(null, null, null, img); 63 | } 64 | else 65 | { 66 | img = context.getResources().getDrawable(R.drawable.ic_error_outline_white_24dp); 67 | myViewHolder.btn_question.setCompoundDrawablesWithIntrinsicBounds(null, null, null, img); 68 | } 69 | 70 | 71 | 72 | } 73 | 74 | @Override 75 | public int getItemCount() 76 | { 77 | return currentQuestionList.size(); 78 | } 79 | 80 | public class MyViewHolder extends RecyclerView.ViewHolder 81 | { 82 | Button btn_question; 83 | public MyViewHolder(@NonNull View itemView) 84 | { 85 | super(itemView); 86 | 87 | btn_question = itemView.findViewById(R.id.btn_question); 88 | btn_question.setOnClickListener(new View.OnClickListener() 89 | { 90 | @Override 91 | public void onClick(View v) 92 | { 93 | //When user clicks on the Question button, we will get back to the question activity to show question 94 | LocalBroadcastManager.getInstance(context) 95 | .sendBroadcast(new Intent(Common.KEY_BACK_FROM_RESULT).putExtra(Common.KEY_BACK_FROM_RESULT, 96 | currentQuestionList.get(getAdapterPosition()).getQuestionIndex())); 97 | } 98 | }); 99 | } 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /app/src/main/java/com/shashwatsupreme/sciencequiz/Common/Common.java: -------------------------------------------------------------------------------- 1 | package com.shashwatsupreme.sciencequiz.Common; 2 | 3 | import android.content.Intent; 4 | import android.net.Uri; 5 | import android.os.CountDownTimer; 6 | 7 | import com.shashwatsupreme.sciencequiz.QuestionFragment; 8 | import com.shashwatsupreme.sciencequiz.model.Category; 9 | import com.shashwatsupreme.sciencequiz.model.CurrentQuestion; 10 | import com.shashwatsupreme.sciencequiz.model.Question; 11 | import com.shashwatsupreme.sciencequiz.model.UserData; 12 | 13 | import java.util.ArrayList; 14 | import java.util.List; 15 | import java.util.TreeSet; 16 | 17 | public class Common 18 | { 19 | public static int TOTAL_TIME = 60*1000 ; // 60 sec 20 | public static final String KEY_GO_TO_QUESTION = "GO_TO_QUESTION"; 21 | public static final String KEY_BACK_FROM_RESULT = "BACK_FROM_RESULT"; 22 | public static final String KEY_SAVE_ONLINE_MODE = "ONLINE_MODE"; 23 | public static final String KEY_CLASS_MODE = "CLASS MODE"; 24 | public static List questionList = new ArrayList<>(); 25 | public static List answerSheetList = new ArrayList(); 26 | public static List answerSheetListFiltered = new ArrayList(); 27 | 28 | public static Category selectedCategory = new Category(); 29 | 30 | public static CountDownTimer countDownTimer; 31 | 32 | public static int timer = 0; 33 | public static int right_answer_count = 0; 34 | public static int wrong_answer_count = 0; 35 | public static int no_answer_count = 0; 36 | public static StringBuilder data_question = new StringBuilder(); 37 | public static ArrayList fragmentsList = new ArrayList<>(); 38 | public static TreeSet selected_values = new TreeSet<>(); 39 | public static boolean isOnlineMode = false; 40 | public static int classMode; 41 | 42 | 43 | public static String user_id = null; 44 | public static String user_Phone_No = null; 45 | public static UserData userData; 46 | public static String name; 47 | public static String email; 48 | public static Uri photo_url; 49 | public static String name_provider; 50 | public static String email_provider; 51 | public static Uri photo_url_provider; 52 | 53 | 54 | 55 | public enum ANSWER_TYPE 56 | { 57 | NO_ANSWER, 58 | WRONG_ANSWER, 59 | RIGHT_ANSWER 60 | } 61 | public enum SwipeDirection 62 | { 63 | all, left, right, none ; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /app/src/main/java/com/shashwatsupreme/sciencequiz/Common/SpaceDecoration.java: -------------------------------------------------------------------------------- 1 | package com.shashwatsupreme.sciencequiz.Common; 2 | 3 | import android.graphics.Rect; 4 | import android.support.annotation.NonNull; 5 | import android.support.v7.widget.RecyclerView; 6 | import android.view.View; 7 | 8 | public class SpaceDecoration extends RecyclerView.ItemDecoration 9 | { 10 | private int space; 11 | 12 | public SpaceDecoration(int space) 13 | { 14 | this.space = space; 15 | } 16 | 17 | @Override 18 | public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) 19 | { 20 | outRect.left=outRect.right=outRect.bottom=outRect.top=space; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /app/src/main/java/com/shashwatsupreme/sciencequiz/DBHelper/DBHelper.java: -------------------------------------------------------------------------------- 1 | package com.shashwatsupreme.sciencequiz.DBHelper; 2 | 3 | import android.content.Context; 4 | import android.database.Cursor; 5 | import android.database.sqlite.SQLiteDatabase; 6 | 7 | import com.readystatesoftware.sqliteasset.SQLiteAssetHelper; 8 | import com.shashwatsupreme.sciencequiz.Common.Common; 9 | import com.shashwatsupreme.sciencequiz.model.Category; 10 | import com.shashwatsupreme.sciencequiz.model.Question; 11 | 12 | import java.util.ArrayList; 13 | import java.util.List; 14 | 15 | public class DBHelper extends SQLiteAssetHelper 16 | { 17 | private static final String DB_NAME = "ScienceQuizDB.db"; 18 | private static final int DB_VER=1; 19 | 20 | private static DBHelper instance; 21 | 22 | public static synchronized DBHelper getInstance(Context context) 23 | { 24 | if(instance==null) 25 | { 26 | instance=new DBHelper(context); 27 | } 28 | return instance; 29 | } 30 | 31 | public DBHelper(Context context) 32 | { 33 | super(context, DB_NAME, null, DB_VER); 34 | } 35 | 36 | /* Getting all categories from the database*/ 37 | 38 | public List getAllCategories() 39 | { 40 | SQLiteDatabase db = instance.getWritableDatabase(); 41 | 42 | Cursor cursor = db.rawQuery("SELECT * FROM Category;", null); 43 | List categories = new ArrayList<>(); 44 | if(cursor.moveToFirst()) 45 | { 46 | while (!cursor.isAfterLast()) 47 | { 48 | Category category = new Category(cursor.getInt(cursor.getColumnIndex("ID")), 49 | cursor.getString(cursor.getColumnIndex("Name")), 50 | cursor.getString(cursor.getColumnIndex("Image")), 51 | Common.selectedCategory.getClassId()); 52 | categories.add(category); 53 | cursor.moveToNext(); 54 | } 55 | } 56 | cursor.close(); 57 | db.close(); 58 | 59 | return categories; 60 | } 61 | 62 | // Get 30 question from db by category 63 | 64 | public List getQuestionByCategory(int category, int classId) 65 | { 66 | SQLiteDatabase db = instance.getWritableDatabase();//?getting 67 | 68 | Cursor cursor = db.rawQuery(String.format("SELECT * FROM Question WHERE CategoryID = %d AND ClassID = %d ORDER BY RANDOM() LIMIT 30", category, classId), null); 69 | List questions = new ArrayList<>(); 70 | if(cursor.moveToFirst()) 71 | { 72 | while (!cursor.isAfterLast()) 73 | { 74 | Question question = new Question(cursor.getInt(cursor.getColumnIndex("ID")), 75 | cursor.getString(cursor.getColumnIndex("QuestionText")), 76 | cursor.getString(cursor.getColumnIndex("QuestionImage")), 77 | cursor.getString(cursor.getColumnIndex("AnswerA")), 78 | cursor.getString(cursor.getColumnIndex("AnswerB")), 79 | cursor.getString(cursor.getColumnIndex("AnswerC")), 80 | cursor.getString(cursor.getColumnIndex("AnswerD")), 81 | cursor.getString(cursor.getColumnIndex("CorrectAnswer")), 82 | cursor.getInt(cursor.getColumnIndex("IsImageQuestion"))==0?Boolean.FALSE:Boolean.TRUE, 83 | cursor.getInt(cursor.getColumnIndex("CategoryID")), 84 | cursor.getInt(cursor.getColumnIndex("ClassID"))); 85 | questions.add(question); 86 | cursor.moveToNext(); 87 | } 88 | } 89 | cursor.close(); 90 | db.close(); 91 | 92 | return questions; 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /app/src/main/java/com/shashwatsupreme/sciencequiz/DBHelper/OnlineDBHelper.java: -------------------------------------------------------------------------------- 1 | package com.shashwatsupreme.sciencequiz.DBHelper; 2 | 3 | import android.app.AlertDialog; 4 | import android.content.Context; 5 | import android.support.annotation.NonNull; 6 | import android.widget.Toast; 7 | 8 | import com.google.firebase.database.DataSnapshot; 9 | import com.google.firebase.database.DatabaseError; 10 | import com.google.firebase.database.DatabaseReference; 11 | import com.google.firebase.database.FirebaseDatabase; 12 | import com.google.firebase.database.ValueEventListener; 13 | import com.shashwatsupreme.sciencequiz.Common.Common; 14 | import com.shashwatsupreme.sciencequiz.Interface.HighScore; 15 | import com.shashwatsupreme.sciencequiz.Interface.MyCallback; 16 | import com.shashwatsupreme.sciencequiz.model.Question; 17 | import com.shashwatsupreme.sciencequiz.model.UserData; 18 | 19 | import java.util.ArrayList; 20 | import java.util.Collection; 21 | import java.util.HashMap; 22 | import java.util.List; 23 | import java.util.Map; 24 | import java.util.Set; 25 | 26 | import dmax.dialog.SpotsDialog; 27 | 28 | public class OnlineDBHelper 29 | { 30 | FirebaseDatabase firebaseDatabase; 31 | Context context; 32 | 33 | DatabaseReference reference; 34 | 35 | public OnlineDBHelper(Context context, FirebaseDatabase firebaseDatabase) 36 | { 37 | this.firebaseDatabase = firebaseDatabase; 38 | this.context = context; 39 | reference = this.firebaseDatabase.getReference("ScienceQuiz"); 40 | } 41 | 42 | private static OnlineDBHelper instance; 43 | 44 | public static synchronized OnlineDBHelper getInstance(Context context, FirebaseDatabase firebaseDatabase) 45 | { 46 | if(instance == null) 47 | { 48 | instance = new OnlineDBHelper(context, firebaseDatabase); 49 | } 50 | return instance; 51 | } 52 | 53 | public void readData(final MyCallback myCallback, String category, String classId) 54 | { 55 | final AlertDialog dialog = new SpotsDialog.Builder() 56 | .setContext(context) 57 | .setCancelable(false) 58 | .build(); 59 | 60 | if(!dialog.isShowing()) 61 | dialog.show(); 62 | 63 | reference.child(category) 64 | .child("question") 65 | .child(classId) 66 | .addListenerForSingleValueEvent(new ValueEventListener() 67 | { 68 | @Override 69 | public void onDataChange(@NonNull DataSnapshot dataSnapshot) 70 | { 71 | List questionList = new ArrayList<>(); 72 | for(DataSnapshot questionSnapshot:dataSnapshot.getChildren()) 73 | questionList.add(questionSnapshot.getValue(Question.class)); 74 | myCallback.setQuestionList(questionList); 75 | 76 | if(dialog.isShowing()) 77 | dialog.dismiss(); 78 | } 79 | 80 | @Override 81 | public void onCancelled(@NonNull DatabaseError databaseError) 82 | { 83 | Toast.makeText(context, ""+databaseError.getMessage(), Toast.LENGTH_SHORT).show(); 84 | } 85 | }); 86 | } 87 | UserData userData = new UserData(); 88 | public UserData readUserData(String category, String uid, String subject, String classid) 89 | { 90 | 91 | String path = Common.email; 92 | path = path.replace(".", "dot"); 93 | path = path.replace("@", "attherateof"); 94 | path = path.replace("_", "underscore"); 95 | path = path.replace("#", "hashtag"); 96 | path = path.replace("*", "asterisk"); 97 | path = path.replace("-", "dash"); 98 | 99 | reference.child(category) 100 | .child(path) 101 | .addListenerForSingleValueEvent(new ValueEventListener() 102 | { 103 | @Override 104 | public void onDataChange(@NonNull DataSnapshot dataSnapshot) 105 | { 106 | userData = dataSnapshot.getValue(UserData.class); 107 | Common.userData = userData; 108 | } 109 | 110 | @Override 111 | public void onCancelled(@NonNull DatabaseError databaseError) 112 | { 113 | Toast.makeText(context, ""+databaseError.getMessage(), Toast.LENGTH_SHORT).show(); 114 | } 115 | }); 116 | return userData; 117 | } 118 | public void writeUserData(String category, String uid, String subject, String classid, int newhighscore, boolean new_user) 119 | { 120 | String path = Common.email; 121 | path = path.replace(".", "dot"); 122 | path = path.replace("@", "attherateof"); 123 | path = path.replace("_", "underscore"); 124 | path = path.replace("#", "hashtag"); 125 | path = path.replace("*", "asterisk"); 126 | path = path.replace("-", "dash"); 127 | 128 | UserData newuser = new UserData(); 129 | 130 | if(!new_user) 131 | { 132 | reference.child(category) 133 | .child(path) 134 | .child(subject.toLowerCase() + classid + "high") 135 | .setValue(newhighscore); 136 | 137 | switch (Common.selectedCategory.getClassId()) 138 | { 139 | case 6: 140 | if(Common.selectedCategory.getName().equalsIgnoreCase("physics")) 141 | newuser = new UserData(newhighscore, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, Common.email, Common.name); 142 | if(Common.selectedCategory.getName().equalsIgnoreCase("chemistry")) 143 | newuser = new UserData(0, 0, 0, newhighscore, 0, 0, 0, 0, 0, 0, 0, 0, Common.email, Common.name); 144 | if(Common.selectedCategory.getName().equalsIgnoreCase("biology")) 145 | newuser = new UserData(0, 0, 0, 0, 0, 0, newhighscore, 0, 0, 0, 0, 0, Common.email, Common.name); 146 | if(Common.selectedCategory.getName().equalsIgnoreCase("mixed")) 147 | newuser = new UserData(0, 0, 0, 0, 0, 0, 0, 0, newhighscore, 0, 0, 0, Common.email, Common.name); 148 | break; 149 | case 7: 150 | if(Common.selectedCategory.getName().equalsIgnoreCase("physics")) 151 | newuser = new UserData(0, newhighscore, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, Common.email, Common.name); 152 | if(Common.selectedCategory.getName().equalsIgnoreCase("chemistry")) 153 | newuser = new UserData(0, 0, 0, 0, newhighscore, 0, 0, 0, 0, 0, 0, 0, Common.email, Common.name); 154 | if(Common.selectedCategory.getName().equalsIgnoreCase("biology")) 155 | newuser = new UserData(0, 0, 0, 0, 0, 0, 0, newhighscore, 0, 0, 0, 0, Common.email, Common.name); 156 | if(Common.selectedCategory.getName().equalsIgnoreCase("mixed")) 157 | newuser = new UserData(newhighscore, 0, 0, 0, 0, 0, 0, 0, 0, 0, newhighscore, 0, Common.email, Common.name); 158 | break; 159 | case 8: 160 | if(Common.selectedCategory.getName().equalsIgnoreCase("physics")) 161 | newuser = new UserData(0, 0, newhighscore, 0, 0, 0, 0, 0, 0, 0, 0, 0, Common.email, Common.name); 162 | if(Common.selectedCategory.getName().equalsIgnoreCase("chemistry")) 163 | newuser = new UserData(0, 0, 0, 0, 0, newhighscore, 0, 0, 0, 0, 0, 0, Common.email, Common.name); 164 | if(Common.selectedCategory.getName().equalsIgnoreCase("biology")) 165 | newuser = new UserData(0, 0, 0, 0, 0, 0, 0, 0, newhighscore, 0, 0, 0, Common.email, Common.name); 166 | if(Common.selectedCategory.getName().equalsIgnoreCase("mixed")) 167 | newuser = new UserData(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, newhighscore, Common.email, Common.name); 168 | break; 169 | 170 | } 171 | } 172 | 173 | else 174 | { 175 | 176 | switch (Common.selectedCategory.getClassId()) 177 | { 178 | case 6: 179 | if(Common.selectedCategory.getName().equalsIgnoreCase("physics")) 180 | newuser = new UserData(newhighscore, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, Common.email, Common.name); 181 | if(Common.selectedCategory.getName().equalsIgnoreCase("chemistry")) 182 | newuser = new UserData(0, 0, 0, newhighscore, 0, 0, 0, 0, 0, 0, 0, 0, Common.email, Common.name); 183 | if(Common.selectedCategory.getName().equalsIgnoreCase("biology")) 184 | newuser = new UserData(0, 0, 0, 0, 0, 0, newhighscore, 0, 0, 0, 0, 0, Common.email, Common.name); 185 | if(Common.selectedCategory.getName().equalsIgnoreCase("mixed")) 186 | newuser = new UserData(0, 0, 0, 0, 0, 0, 0, 0, newhighscore, 0, 0, 0, Common.email, Common.name); 187 | break; 188 | case 7: 189 | if(Common.selectedCategory.getName().equalsIgnoreCase("physics")) 190 | newuser = new UserData(0, newhighscore, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, Common.email, Common.name); 191 | if(Common.selectedCategory.getName().equalsIgnoreCase("chemistry")) 192 | newuser = new UserData(0, 0, 0, 0, newhighscore, 0, 0, 0, 0, 0, 0, 0, Common.email, Common.name); 193 | if(Common.selectedCategory.getName().equalsIgnoreCase("biology")) 194 | newuser = new UserData(0, 0, 0, 0, 0, 0, 0, newhighscore, 0, 0, 0, 0, Common.email, Common.name); 195 | if(Common.selectedCategory.getName().equalsIgnoreCase("mixed")) 196 | newuser = new UserData(newhighscore, 0, 0, 0, 0, 0, 0, 0, 0, 0, newhighscore, 0, Common.email, Common.name); 197 | break; 198 | case 8: 199 | if(Common.selectedCategory.getName().equalsIgnoreCase("physics")) 200 | newuser = new UserData(0, 0, newhighscore, 0, 0, 0, 0, 0, 0, 0, 0, 0, Common.email, Common.name); 201 | if(Common.selectedCategory.getName().equalsIgnoreCase("chemistry")) 202 | newuser = new UserData(0, 0, 0, 0, 0, newhighscore, 0, 0, 0, 0, 0, 0, Common.email, Common.name); 203 | if(Common.selectedCategory.getName().equalsIgnoreCase("biology")) 204 | newuser = new UserData(0, 0, 0, 0, 0, 0, 0, 0, newhighscore, 0, 0, 0, Common.email, Common.name); 205 | if(Common.selectedCategory.getName().equalsIgnoreCase("mixed")) 206 | newuser = new UserData(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, newhighscore, Common.email, Common.name); 207 | break; 208 | 209 | } 210 | Common.userData = newuser; 211 | // Map uid_map = new HashMap<>(); 212 | // uid_map.put("/Users/", path); 213 | // reference.push().updateChildren(uid_map); 214 | 215 | 216 | 217 | Map userDataMap = newuser.toMap(); 218 | Map finalUserDataMap = new HashMap<>(); 219 | finalUserDataMap.put("/Users/"+path, userDataMap); 220 | reference.updateChildren(finalUserDataMap); 221 | 222 | 223 | } 224 | } 225 | 226 | 227 | 228 | } 229 | -------------------------------------------------------------------------------- /app/src/main/java/com/shashwatsupreme/sciencequiz/Interface/HighScore.java: -------------------------------------------------------------------------------- 1 | package com.shashwatsupreme.sciencequiz.Interface; 2 | 3 | import com.shashwatsupreme.sciencequiz.model.UserData; 4 | 5 | public interface HighScore 6 | { 7 | void setUserDataList(UserData userData); 8 | } 9 | -------------------------------------------------------------------------------- /app/src/main/java/com/shashwatsupreme/sciencequiz/Interface/IQuestion.java: -------------------------------------------------------------------------------- 1 | package com.shashwatsupreme.sciencequiz.Interface; 2 | 3 | import com.shashwatsupreme.sciencequiz.model.CurrentQuestion; 4 | 5 | public interface IQuestion 6 | { 7 | CurrentQuestion getSelectedAnswer(); //Get selected answer from user select 8 | void showCorrectAnswer(); //Bold correct answer text 9 | void disableAnswer(); //Disable all check boxes 10 | void resetQuestion(); //Reset all function on question 11 | } 12 | -------------------------------------------------------------------------------- /app/src/main/java/com/shashwatsupreme/sciencequiz/Interface/IRecyclerHelperClick.java: -------------------------------------------------------------------------------- 1 | package com.shashwatsupreme.sciencequiz.Interface; 2 | 3 | import android.view.View; 4 | 5 | public interface IRecyclerHelperClick { 6 | void onClick(View view, int position); 7 | } 8 | -------------------------------------------------------------------------------- /app/src/main/java/com/shashwatsupreme/sciencequiz/Interface/MyCallback.java: -------------------------------------------------------------------------------- 1 | package com.shashwatsupreme.sciencequiz.Interface; 2 | 3 | import com.shashwatsupreme.sciencequiz.model.Question; 4 | 5 | import java.util.List; 6 | 7 | public interface MyCallback 8 | { 9 | void setQuestionList(List questionList); 10 | } 11 | -------------------------------------------------------------------------------- /app/src/main/java/com/shashwatsupreme/sciencequiz/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.shashwatsupreme.sciencequiz; 2 | 3 | import android.content.Intent; 4 | import android.os.Build; 5 | import android.support.annotation.NonNull; 6 | import android.support.annotation.RequiresApi; 7 | import android.support.v7.app.AppCompatActivity; 8 | import android.os.Bundle; 9 | import android.support.v7.widget.GridLayoutManager; 10 | import android.support.v7.widget.RecyclerView; 11 | import android.util.DisplayMetrics; 12 | //import android.widget.Toolbar; 13 | import android.support.v7.widget.Toolbar; 14 | import android.view.LayoutInflater; 15 | import android.view.Menu; 16 | import android.view.MenuItem; 17 | import android.view.View; 18 | import android.widget.Button; 19 | import android.widget.CheckBox; 20 | import android.widget.Toast; 21 | 22 | import com.afollestad.materialdialogs.DialogAction; 23 | import com.afollestad.materialdialogs.MaterialDialog; 24 | import com.firebase.ui.auth.AuthUI; 25 | import com.firebase.ui.auth.IdpResponse; 26 | import com.github.javiersantos.materialstyleddialogs.MaterialStyledDialog; 27 | import com.google.android.gms.tasks.OnCompleteListener; 28 | import com.google.android.gms.tasks.OnFailureListener; 29 | import com.google.android.gms.tasks.Task; 30 | import com.google.firebase.auth.FirebaseAuth; 31 | import com.google.firebase.auth.FirebaseUser; 32 | import com.shashwatsupreme.sciencequiz.Adapter.CategoryAdapter; 33 | import com.shashwatsupreme.sciencequiz.Common.Common; 34 | import com.shashwatsupreme.sciencequiz.Common.SpaceDecoration; 35 | import com.shashwatsupreme.sciencequiz.DBHelper.DBHelper; 36 | 37 | import java.util.Arrays; 38 | import java.util.List; 39 | 40 | import io.paperdb.Paper; 41 | 42 | public class MainActivity extends AppCompatActivity 43 | { 44 | 45 | Toolbar toolbar; 46 | RecyclerView recycler_category; 47 | 48 | private static final int MY_REQUEST_CODE = 7117; 49 | List providers; 50 | Button btn_sign_out; 51 | 52 | 53 | @Override 54 | protected void onCreate(Bundle savedInstanceState) 55 | { 56 | super.onCreate(savedInstanceState); 57 | setContentView(R.layout.activity_main); 58 | 59 | //Init Paper 60 | Paper.init(this); 61 | 62 | //Get value online mode 63 | Common.isOnlineMode = Paper.book().read(Common.KEY_SAVE_ONLINE_MODE, false); //Default false 64 | 65 | toolbar = findViewById(R.id.toolbar); 66 | toolbar.setTitle("Science Quiz"); 67 | toolbar.setTextAlignment(View.TEXT_ALIGNMENT_CENTER); 68 | setSupportActionBar(toolbar); 69 | 70 | recycler_category = findViewById(R.id.recyler_category); 71 | recycler_category.setHasFixedSize(true); 72 | recycler_category.setLayoutManager(new GridLayoutManager(this, 1)); 73 | 74 | //Get Screen Height 75 | // DisplayMetrics displayMetrics = new DisplayMetrics(); 76 | // getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); 77 | // int height = displayMetrics.heightPixels / 8;//Max size of item in Category 78 | CategoryAdapter adapter = new CategoryAdapter(MainActivity.this, DBHelper.getInstance(this).getAllCategories()); 79 | int spaceInPixel = 4; 80 | recycler_category.addItemDecoration(new SpaceDecoration(spaceInPixel)); 81 | recycler_category.setAdapter(adapter); 82 | 83 | // btn_sign_out = findViewById(R.id.btn_sign_out); 84 | // btn_sign_out.setOnClickListener(new View.OnClickListener() 85 | // { 86 | // @Override 87 | // public void onClick(View v) 88 | // { 89 | // // Sign out 90 | // AuthUI.getInstance() 91 | // .signOut(MainActivity.this) 92 | // .addOnCompleteListener(new OnCompleteListener() 93 | // { 94 | // public void onComplete(@NonNull Task task) 95 | // { 96 | // btn_sign_out.setEnabled(false); 97 | // showSignInOptions(); 98 | // } 99 | // }).addOnFailureListener(new OnFailureListener() 100 | // { 101 | // @Override 102 | // public void onFailure(@NonNull Exception e) 103 | // { 104 | // Toast.makeText(MainActivity.this, ""+e.getMessage(), Toast.LENGTH_SHORT).show(); 105 | // } 106 | // }); 107 | // // [END auth_fui_signout] 108 | // } 109 | // }); 110 | 111 | providers = Arrays.asList( 112 | new AuthUI.IdpConfig.EmailBuilder().build(), 113 | new AuthUI.IdpConfig.PhoneBuilder().build(), 114 | new AuthUI.IdpConfig.GoogleBuilder().build(), 115 | new AuthUI.IdpConfig.FacebookBuilder().build()); 116 | 117 | showSignInOptions(); 118 | 119 | } 120 | 121 | @Override 122 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { 123 | super.onActivityResult(requestCode, resultCode, data); 124 | 125 | if (requestCode == MY_REQUEST_CODE) 126 | { 127 | IdpResponse response = IdpResponse.fromResultIntent(data); 128 | 129 | if (resultCode == RESULT_OK) { 130 | // Successfully signed in, now get user 131 | FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser(); 132 | Toast.makeText(this, "Signed in as: "+((user.getEmail()!=null)?user.getEmail():user.getPhoneNumber()), Toast.LENGTH_SHORT).show(); 133 | // ... 134 | // btn_sign_out.setEnabled(true); 135 | } else { 136 | // Sign in failed. If response is null the user canceled the 137 | // sign-in flow using the back button. Otherwise check 138 | // response.getError().getErrorCode() and handle the error. 139 | // ... 140 | Toast.makeText(this, ""+response.getError().getMessage(), Toast.LENGTH_SHORT).show(); 141 | } 142 | } 143 | } 144 | 145 | private void showSignInOptions() 146 | { 147 | startActivityForResult( 148 | AuthUI.getInstance() 149 | .createSignInIntentBuilder() 150 | .setAvailableProviders(providers) 151 | .setTheme(R.style.Mytheme) 152 | .build(),MY_REQUEST_CODE 153 | ); 154 | } 155 | 156 | @Override 157 | public boolean onCreateOptionsMenu(Menu menu) 158 | { 159 | getMenuInflater().inflate(R.menu.category_menu, menu); 160 | return true; 161 | } 162 | 163 | @Override 164 | public boolean onOptionsItemSelected(MenuItem item) 165 | { 166 | if(item.getItemId() == R.id.menu_settings) 167 | { 168 | showSettings(); 169 | } 170 | if(item.getItemId() == R.id.btn_sign_out) 171 | { 172 | AuthUI.getInstance() 173 | .signOut(MainActivity.this) 174 | .addOnCompleteListener(new OnCompleteListener() 175 | { 176 | public void onComplete(@NonNull Task task) 177 | { 178 | // btn_sign_out.setEnabled(false); 179 | Intent intent = getIntent(); 180 | finish(); 181 | startActivity(intent); 182 | } 183 | }).addOnFailureListener(new OnFailureListener() 184 | { 185 | @Override 186 | public void onFailure(@NonNull Exception e) 187 | { 188 | Toast.makeText(MainActivity.this, ""+e.getMessage(), Toast.LENGTH_SHORT).show(); 189 | } 190 | }); 191 | } 192 | 193 | return true; 194 | } 195 | 196 | private void showSettings() 197 | { 198 | View setting_layout = LayoutInflater.from(this).inflate(R.layout.settings_layout, null); 199 | final CheckBox ckb_online_mode = setting_layout.findViewById(R.id.ckb_online_mode); 200 | 201 | //Load data from paper, if not available just init default false 202 | ckb_online_mode.setChecked(Paper.book().read(Common.KEY_SAVE_ONLINE_MODE, false)); 203 | 204 | //Show Dialog 205 | new MaterialStyledDialog.Builder(MainActivity.this) 206 | .setIcon(R.drawable.ic_settings_white_24dp) 207 | .setTitle("Settings") 208 | .setDescription("Please choose action") 209 | .setCustomView(setting_layout) 210 | .setNegativeText("DISMISS") 211 | .onNegative(new MaterialDialog.SingleButtonCallback() 212 | { 213 | @Override 214 | public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) 215 | { 216 | dialog.dismiss(); 217 | } 218 | }) 219 | .setPositiveText("SAVE") 220 | .onPositive(new MaterialDialog.SingleButtonCallback() 221 | { 222 | @Override 223 | public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) 224 | { 225 | if(ckb_online_mode.isChecked()) 226 | { 227 | Common.isOnlineMode = true; 228 | } 229 | else 230 | { 231 | Common.isOnlineMode = false; 232 | } 233 | 234 | //Save 235 | Paper.book().write(Common.KEY_SAVE_ONLINE_MODE, ckb_online_mode.isChecked()); 236 | } 237 | }).show(); 238 | } 239 | } 240 | -------------------------------------------------------------------------------- /app/src/main/java/com/shashwatsupreme/sciencequiz/MainLoginActivity.java: -------------------------------------------------------------------------------- 1 | package com.shashwatsupreme.sciencequiz; 2 | 3 | import android.content.Intent; 4 | import android.support.annotation.NonNull; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.os.Bundle; 7 | import android.view.View; 8 | import android.widget.Button; 9 | import android.widget.Toast; 10 | 11 | import com.firebase.ui.auth.AuthUI; 12 | import com.firebase.ui.auth.IdpResponse; 13 | import com.google.android.gms.tasks.OnCompleteListener; 14 | import com.google.android.gms.tasks.OnFailureListener; 15 | import com.google.android.gms.tasks.Task; 16 | import com.google.firebase.auth.FirebaseAuth; 17 | import com.google.firebase.auth.FirebaseUser; 18 | 19 | import java.util.Arrays; 20 | import java.util.List; 21 | 22 | public class MainLoginActivity extends AppCompatActivity 23 | { 24 | 25 | private static final int MY_REQUEST_CODE = 7117; 26 | List providers; 27 | Button btn_sign_out; 28 | 29 | @Override 30 | protected void onCreate(Bundle savedInstanceState) 31 | { 32 | super.onCreate(savedInstanceState); 33 | setContentView(R.layout.activity_main_login); 34 | 35 | // btn_sign_out = findViewById(R.id.btn_sign_out); 36 | // btn_sign_out.setOnClickListener(new View.OnClickListener() 37 | // { 38 | // @Override 39 | // public void onClick(View v) 40 | // { 41 | // // Sign out 42 | // AuthUI.getInstance() 43 | // .signOut(MainLoginActivity.this) 44 | // .addOnCompleteListener(new OnCompleteListener() 45 | // { 46 | // public void onComplete(@NonNull Task task) 47 | // { 48 | // btn_sign_out.setEnabled(false); 49 | // showSignInOptions(); 50 | // } 51 | // }).addOnFailureListener(new OnFailureListener() 52 | // { 53 | // @Override 54 | // public void onFailure(@NonNull Exception e) 55 | // { 56 | // Toast.makeText(MainLoginActivity.this, ""+e.getMessage(), Toast.LENGTH_SHORT).show(); 57 | // } 58 | // }); 59 | // // [END auth_fui_signout] 60 | // } 61 | // }); 62 | 63 | providers = Arrays.asList( 64 | new AuthUI.IdpConfig.EmailBuilder().build(), 65 | new AuthUI.IdpConfig.PhoneBuilder().build(), 66 | new AuthUI.IdpConfig.GoogleBuilder().build(), 67 | new AuthUI.IdpConfig.FacebookBuilder().build()); 68 | 69 | showSignInOptions(); 70 | 71 | } 72 | 73 | private void showSignInOptions() 74 | { 75 | startActivityForResult( 76 | AuthUI.getInstance() 77 | .createSignInIntentBuilder() 78 | .setAvailableProviders(providers) 79 | .setTheme(R.style.Mytheme) 80 | .build(),MY_REQUEST_CODE 81 | ); 82 | } 83 | 84 | @Override 85 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { 86 | super.onActivityResult(requestCode, resultCode, data); 87 | 88 | if (requestCode == MY_REQUEST_CODE) 89 | { 90 | IdpResponse response = IdpResponse.fromResultIntent(data); 91 | 92 | if (resultCode == RESULT_OK) { 93 | // Successfully signed in, now get user 94 | FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser(); 95 | Toast.makeText(this, "Signed in as: "+user.getEmail(), Toast.LENGTH_SHORT).show(); 96 | // ... 97 | // btn_sign_out.setEnabled(true); 98 | } else { 99 | // Sign in failed. If response is null the user canceled the 100 | // sign-in flow using the back button. Otherwise check 101 | // response.getError().getErrorCode() and handle the error. 102 | // ... 103 | Toast.makeText(this, ""+response.getError().getMessage(), Toast.LENGTH_SHORT).show(); 104 | } 105 | } 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /app/src/main/java/com/shashwatsupreme/sciencequiz/Misc/CustomViewPager.java: -------------------------------------------------------------------------------- 1 | package com.shashwatsupreme.sciencequiz.Misc; 2 | 3 | import android.content.Context; 4 | import android.support.v4.view.ViewPager; 5 | import android.util.AttributeSet; 6 | import android.view.MotionEvent; 7 | 8 | import com.shashwatsupreme.sciencequiz.Common.Common; 9 | 10 | public class CustomViewPager extends ViewPager 11 | { 12 | 13 | // private boolean isPagingEnabled = true; 14 | 15 | private float initialXValue; 16 | private Common.SwipeDirection direction; 17 | 18 | public CustomViewPager(Context context) 19 | { 20 | super(context); 21 | } 22 | 23 | public CustomViewPager(Context context, AttributeSet attrs) 24 | { 25 | super(context, attrs); 26 | this.direction = Common.SwipeDirection.all; 27 | 28 | } 29 | 30 | @Override 31 | public boolean onTouchEvent(MotionEvent event) 32 | { 33 | if (this.IsSwipeAllowed(event)) { 34 | return super.onTouchEvent(event); 35 | } 36 | 37 | return false; 38 | } 39 | 40 | @Override 41 | public boolean onInterceptTouchEvent(MotionEvent event) 42 | { 43 | if (this.IsSwipeAllowed(event)) { 44 | return super.onInterceptTouchEvent(event); 45 | } 46 | 47 | return false; 48 | } 49 | 50 | // public void setPagingEnabled(boolean b) 51 | // { 52 | // this.isPagingEnabled = b; 53 | // } 54 | 55 | private boolean IsSwipeAllowed(MotionEvent event) 56 | { 57 | if(this.direction == Common.SwipeDirection.all) return true; 58 | 59 | if(direction == Common.SwipeDirection.none )//disable any swipe 60 | return false; 61 | 62 | if(event.getAction()==MotionEvent.ACTION_DOWN) 63 | { 64 | initialXValue = event.getX(); 65 | return true; 66 | } 67 | 68 | if(event.getAction()==MotionEvent.ACTION_MOVE) 69 | { 70 | try 71 | { 72 | float diffX = event.getX() - initialXValue; 73 | if (diffX > 0 && direction == Common.SwipeDirection.right ) 74 | { 75 | // swipe from left to right detected 76 | return false; 77 | }else if (diffX < 0 && direction == Common.SwipeDirection.left ) 78 | { 79 | // swipe from right to left detected 80 | return false; 81 | } 82 | } catch (Exception exception) 83 | { 84 | exception.printStackTrace(); 85 | } 86 | } 87 | 88 | return true; 89 | } 90 | 91 | public void setAllowedSwipeDirection(Common.SwipeDirection direction) 92 | { 93 | this.direction = direction; 94 | } 95 | } -------------------------------------------------------------------------------- /app/src/main/java/com/shashwatsupreme/sciencequiz/QuestionFragment.java: -------------------------------------------------------------------------------- 1 | package com.shashwatsupreme.sciencequiz; 2 | 3 | 4 | import android.app.Activity; 5 | import android.content.Context; 6 | import android.graphics.Color; 7 | import android.graphics.Typeface; 8 | import android.os.Bundle; 9 | import android.support.v4.app.Fragment; 10 | import android.text.TextUtils; 11 | import android.view.LayoutInflater; 12 | import android.view.View; 13 | import android.view.ViewGroup; 14 | import android.widget.CheckBox; 15 | import android.widget.CompoundButton; 16 | import android.widget.FrameLayout; 17 | import android.widget.ImageView; 18 | import android.widget.ProgressBar; 19 | import android.widget.TextView; 20 | import android.widget.Toast; 21 | 22 | import com.shashwatsupreme.sciencequiz.Common.Common; 23 | import com.shashwatsupreme.sciencequiz.Interface.IQuestion; 24 | import com.shashwatsupreme.sciencequiz.model.CurrentQuestion; 25 | import com.shashwatsupreme.sciencequiz.model.Question; 26 | import com.squareup.picasso.Callback; 27 | import com.squareup.picasso.Picasso; 28 | 29 | 30 | /** 31 | * A simple {@link Fragment} subclass. 32 | */ 33 | public class QuestionFragment extends Fragment implements IQuestion 34 | { 35 | 36 | TextView txt_question_text; 37 | CheckBox ckbA, ckbB, ckbC, ckbD; 38 | FrameLayout layout_image; 39 | ProgressBar progressBar; 40 | 41 | Context context; 42 | Question question; 43 | int questionIndex=-1; 44 | 45 | public QuestionFragment() 46 | { 47 | // Required empty public constructor 48 | } 49 | 50 | 51 | 52 | 53 | @Override 54 | public View onCreateView(LayoutInflater inflater, ViewGroup container, 55 | Bundle savedInstanceState) 56 | { 57 | // Inflate the layout for this fragment 58 | View itemView = inflater.inflate(R.layout.fragment_question, container, false); 59 | 60 | //Get question 61 | questionIndex = getArguments().getInt("index", -1); 62 | if(Common.questionList.size() > 0) 63 | { 64 | question = Common.questionList.get(questionIndex); 65 | // Toast.makeText(getActivity(), "questionIndex="+questionIndex, Toast.LENGTH_SHORT).show(); 66 | } 67 | 68 | if(question != null) 69 | { 70 | layout_image = itemView.findViewById(R.id.layout_image); 71 | progressBar = itemView.findViewById(R.id.progress_bar); 72 | if(question.isImageQuestion()) 73 | { 74 | ImageView img_question = itemView.findViewById(R.id.img_question); 75 | Picasso.get().load(question.getQuestionImage()).into(img_question, new Callback() 76 | { 77 | @Override 78 | public void onSuccess() 79 | { 80 | progressBar.setVisibility(View.GONE); 81 | } 82 | 83 | @Override 84 | public void onError(Exception e) 85 | { 86 | Toast.makeText(getContext(), ""+e.getMessage(), Toast.LENGTH_SHORT).show(); 87 | } 88 | }); 89 | } 90 | else 91 | layout_image.setVisibility(View.GONE); 92 | //View 93 | txt_question_text = itemView.findViewById(R.id.txt_question_text); 94 | txt_question_text.setText(question.getQuestionText()); 95 | 96 | ckbA = itemView.findViewById(R.id.ckbA); 97 | ckbA.setText(question.getAnswerA()); 98 | ckbA.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() 99 | { 100 | @Override 101 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) 102 | { 103 | if(isChecked) 104 | Common.selected_values.add(ckbA.getText().toString()); 105 | else 106 | Common.selected_values.remove(ckbA.getText().toString()); 107 | 108 | } 109 | }); 110 | 111 | ckbB = itemView.findViewById(R.id.ckbB); 112 | ckbB.setText(question.getAnswerB()); 113 | ckbB.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() 114 | { 115 | @Override 116 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) 117 | { 118 | if(isChecked) 119 | Common.selected_values.add(ckbB.getText().toString()); 120 | else 121 | Common.selected_values.remove(ckbB.getText().toString()); 122 | 123 | } 124 | }); 125 | 126 | ckbC = itemView.findViewById(R.id.ckbC); 127 | ckbC.setText(question.getAnswerC()); 128 | ckbC.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() 129 | { 130 | @Override 131 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) 132 | { 133 | if(isChecked) 134 | Common.selected_values.add(ckbC.getText().toString()); 135 | else 136 | Common.selected_values.remove(ckbC.getText().toString()); 137 | 138 | } 139 | }); 140 | 141 | ckbD = itemView.findViewById(R.id.ckbD); 142 | ckbD.setText(question.getAnswerD()); 143 | ckbD.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() 144 | { 145 | @Override 146 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) 147 | { 148 | if(isChecked) 149 | Common.selected_values.add(ckbD.getText().toString()); 150 | else 151 | Common.selected_values.remove(ckbD.getText().toString()); 152 | 153 | } 154 | }); 155 | 156 | 157 | 158 | } 159 | 160 | 161 | return itemView; 162 | } 163 | 164 | @Override 165 | public CurrentQuestion getSelectedAnswer() 166 | { 167 | //This function will return state of the answer 168 | //Right, wrong or normal 169 | CurrentQuestion currentQuestion = new CurrentQuestion(questionIndex, Common.ANSWER_TYPE.NO_ANSWER); //Default no answer 170 | StringBuilder result = new StringBuilder(); 171 | if(Common.selected_values.size() > 1) 172 | { 173 | //If multichoice 174 | //Split answer to array 175 | //Ex. arr[0] = A, New York 176 | //Ex. arr[1] = B, Paris 177 | Object[] answerArray = Common.selected_values.toArray(); 178 | for(int i=0; i 0) 222 | // { 223 | // question = Common.questionList.get(questionIndex); 224 | //// Toast.makeText(getActivity(), "questionIndex="+questionIndex, Toast.LENGTH_SHORT).show(); 225 | // } 226 | 227 | 228 | 229 | String[] correctAnswer = question.getCorrectAnswer().split(","); 230 | // Toast.makeText(getActivity(), ""+question.getCorrectAnswer(), Toast.LENGTH_SHORT).show(); 231 | 232 | // View itemView = inflater.inflate(R.layout.fragment_question, container, false); 233 | // if(question != null) 234 | // { 235 | // layout_image = itemView.findViewById(R.id.layout_image); 236 | // progressBar = itemView.findViewById(R.id.progress_bar); 237 | // if(question.isImageQuestion()) 238 | // { 239 | // ImageView img_question = itemView.findViewById(R.id.img_question); 240 | // Picasso.get().load(question.getQuestionImage()).into(img_question, new Callback() 241 | // { 242 | // @Override 243 | // public void onSuccess() 244 | // { 245 | // progressBar.setVisibility(View.GONE); 246 | // } 247 | // 248 | // @Override 249 | // public void onError(Exception e) 250 | // { 251 | // Toast.makeText(getContext(), ""+e.getMessage(), Toast.LENGTH_SHORT).show(); 252 | // } 253 | // }); 254 | // } 255 | // else 256 | // layout_image.setVisibility(View.GONE); 257 | // //View 258 | // txt_question_text = itemView.findViewById(R.id.txt_question_text); 259 | // txt_question_text.setText(question.getQuestionText()); 260 | // 261 | // ckbA = itemView.findViewById(R.id.ckbA); 262 | // ckbA.setText(question.getAnswerA()); 263 | // 264 | // ckbB = itemView.findViewById(R.id.ckbB); 265 | // ckbB.setText(question.getAnswerB()); 266 | // 267 | // 268 | // ckbC = itemView.findViewById(R.id.ckbC); 269 | // ckbC.setText(question.getAnswerC()); 270 | // 271 | // 272 | // ckbD = itemView.findViewById(R.id.ckbD); 273 | // ckbD.setText(question.getAnswerD()); 274 | // 275 | // 276 | // 277 | // 278 | // } 279 | // 280 | for(String answer:correctAnswer) 281 | { 282 | if(answer.equalsIgnoreCase("A")) 283 | { 284 | ckbA.setTypeface(null, Typeface.BOLD); 285 | ckbA.setTextColor(Color.GREEN); 286 | } 287 | else if(answer.equalsIgnoreCase("B")) 288 | { 289 | ckbB.setTypeface(null, Typeface.BOLD); 290 | ckbB.setTextColor(Color.GREEN); 291 | } 292 | else if(answer.equalsIgnoreCase("C")) 293 | { 294 | ckbC.setTypeface(null, Typeface.BOLD); 295 | ckbC.setTextColor(Color.GREEN); 296 | } 297 | else if(answer.equalsIgnoreCase("D")) 298 | { 299 | ckbD.setTypeface(null, Typeface.BOLD); 300 | ckbD.setTextColor(Color.GREEN); 301 | } 302 | } 303 | 304 | } 305 | 306 | @Override 307 | public void disableAnswer() 308 | { 309 | ckbA.setEnabled(false); 310 | ckbB.setEnabled(false); 311 | ckbC.setEnabled(false); 312 | ckbD.setEnabled(false); 313 | } 314 | 315 | @Override 316 | public void resetQuestion() 317 | { 318 | //Enable Checkbox 319 | ckbA.setEnabled(true); 320 | ckbB.setEnabled(true); 321 | ckbC.setEnabled(true); 322 | ckbD.setEnabled(true); 323 | 324 | //Remove all selected 325 | ckbA.setChecked(false); 326 | ckbB.setChecked(false); 327 | ckbC.setChecked(false); 328 | ckbD.setChecked(false); 329 | 330 | //Remove all bold on text 331 | ckbA.setTypeface(null, Typeface.NORMAL); 332 | ckbA.setTextColor(Color.BLACK); 333 | ckbB.setTypeface(null, Typeface.NORMAL); 334 | ckbB.setTextColor(Color.BLACK); 335 | ckbC.setTypeface(null, Typeface.NORMAL); 336 | ckbC.setTextColor(Color.BLACK); 337 | ckbD.setTypeface(null, Typeface.NORMAL); 338 | ckbD.setTextColor(Color.BLACK); 339 | 340 | 341 | } 342 | } 343 | -------------------------------------------------------------------------------- /app/src/main/java/com/shashwatsupreme/sciencequiz/ResultActivity.java: -------------------------------------------------------------------------------- 1 | package com.shashwatsupreme.sciencequiz; 2 | 3 | import android.app.Activity; 4 | import android.content.BroadcastReceiver; 5 | import android.content.Context; 6 | import android.content.Intent; 7 | import android.content.IntentFilter; 8 | import android.net.Uri; 9 | import android.support.annotation.NonNull; 10 | import android.support.v4.content.LocalBroadcastManager; 11 | import android.support.v7.app.AppCompatActivity; 12 | import android.os.Bundle; 13 | import android.support.v7.widget.GridLayoutManager; 14 | import android.support.v7.widget.RecyclerView; 15 | import android.support.v7.widget.Toolbar; 16 | import android.util.Log; 17 | import android.view.Gravity; 18 | import android.view.Menu; 19 | import android.view.MenuItem; 20 | import android.view.View; 21 | import android.widget.Button; 22 | import android.widget.TextView; 23 | import android.widget.Toast; 24 | 25 | import com.afollestad.materialdialogs.DialogAction; 26 | import com.afollestad.materialdialogs.MaterialDialog; 27 | import com.firebase.ui.auth.AuthUI; 28 | import com.github.javiersantos.materialstyleddialogs.MaterialStyledDialog; 29 | import com.google.android.gms.tasks.OnCompleteListener; 30 | import com.google.android.gms.tasks.OnFailureListener; 31 | import com.google.android.gms.tasks.Task; 32 | import com.google.firebase.auth.FirebaseAuth; 33 | import com.google.firebase.auth.FirebaseUser; 34 | import com.google.firebase.auth.UserInfo; 35 | import com.google.firebase.database.DataSnapshot; 36 | import com.google.firebase.database.DatabaseError; 37 | import com.google.firebase.database.DatabaseReference; 38 | import com.google.firebase.database.FirebaseDatabase; 39 | import com.google.firebase.database.ValueEventListener; 40 | import com.shashwatsupreme.sciencequiz.Adapter.ResultGridAdapter; 41 | import com.shashwatsupreme.sciencequiz.Common.Common; 42 | import com.shashwatsupreme.sciencequiz.Common.SpaceDecoration; 43 | import com.shashwatsupreme.sciencequiz.DBHelper.OnlineDBHelper; 44 | 45 | import java.util.List; 46 | import java.util.concurrent.TimeUnit; 47 | 48 | 49 | public class ResultActivity extends AppCompatActivity 50 | { 51 | Toolbar toolbar; 52 | TextView txt_timer, txt_result, txt_right_answer, txt_percent; 53 | Button btn_filter_total, btn_filter_right, btn_filter_wrong, btn_filter_no_answer; 54 | RecyclerView recycler_result; 55 | String name = null; 56 | int highscoretodisplay = 0; 57 | ResultGridAdapter adapter, filtered_adapter; 58 | 59 | //personal modifications 60 | Button btn_sign_out; 61 | 62 | 63 | BroadcastReceiver backToQuestion = new BroadcastReceiver() 64 | { 65 | @Override 66 | public void onReceive(Context context, Intent intent) 67 | { 68 | if(intent.getAction().toString().equals(Common.KEY_BACK_FROM_RESULT)) 69 | { 70 | int question = intent.getIntExtra(Common.KEY_BACK_FROM_RESULT, -1); 71 | goBackActivityWithQuestion(question); 72 | 73 | } 74 | } 75 | }; 76 | 77 | private void goBackActivityWithQuestion(int question) 78 | { 79 | Intent returnIntent = new Intent(); 80 | returnIntent.putExtra(Common.KEY_BACK_FROM_RESULT, question); 81 | setResult(Activity.RESULT_OK, returnIntent); 82 | finish(); 83 | } 84 | 85 | @Override 86 | protected void onCreate(Bundle savedInstanceState) 87 | { 88 | super.onCreate(savedInstanceState); 89 | setContentView(R.layout.activity_result); 90 | 91 | LocalBroadcastManager.getInstance(this) 92 | .registerReceiver(backToQuestion, new IntentFilter(Common.KEY_BACK_FROM_RESULT)); 93 | 94 | 95 | toolbar = (Toolbar)findViewById(R.id.toolbar); 96 | toolbar.setTitle("RESULT"); 97 | setSupportActionBar(toolbar); 98 | 99 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); 100 | getSupportActionBar().setDisplayShowHomeEnabled(true); 101 | 102 | txt_result = findViewById(R.id.txt_result); 103 | txt_right_answer = findViewById(R.id.txt_right_answer); 104 | txt_timer = findViewById(R.id.txt_time); 105 | 106 | btn_filter_no_answer = findViewById(R.id.btn_filter_no_answer); 107 | btn_filter_right = findViewById(R.id.btn_filter_right_answer); 108 | btn_filter_wrong = findViewById(R.id.btn_filter_wrong_answer); 109 | btn_filter_total = findViewById(R.id.btn_filter_total); 110 | 111 | recycler_result = findViewById(R.id.recycler_result); 112 | recycler_result.setHasFixedSize(true); 113 | recycler_result.setLayoutManager( new GridLayoutManager(this, 3)); 114 | 115 | //Set Adapter 116 | adapter = new ResultGridAdapter(this, Common.answerSheetList); 117 | recycler_result.addItemDecoration(new SpaceDecoration(4)); 118 | recycler_result.setAdapter(adapter); 119 | 120 | txt_timer.setText(String.format("%02d:%02d", 121 | TimeUnit.MILLISECONDS.toMinutes(Common.timer), 122 | TimeUnit.MILLISECONDS.toSeconds(Common.timer) - 123 | TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(Common.timer)))); 124 | txt_right_answer.setText(new StringBuilder("").append(Common.right_answer_count).append("/") 125 | .append(Common.questionList.size())); 126 | 127 | btn_filter_total.setText(new StringBuilder("").append(Common.questionList.size())); 128 | btn_filter_right.setText(new StringBuilder("").append(Common.right_answer_count)); 129 | btn_filter_wrong.setText(new StringBuilder("").append(Common.wrong_answer_count)); 130 | btn_filter_no_answer.setText(new StringBuilder("").append(Common.no_answer_count)); 131 | 132 | //Calculate result 133 | // if(Common.questionList.size() != 0) 134 | final int percent = ((Common.right_answer_count * 100) / Common.questionList.size()); 135 | if(percent > 85) 136 | txt_result.setText("EXCELLENT"); 137 | else if(percent > 75) 138 | txt_result.setText("GOOD"); 139 | else if(percent > 60) 140 | txt_result.setText("FAIR"); 141 | else if(percent > 50) 142 | txt_result.setText("SATISFACTORY"); 143 | else if(percent > 40) 144 | txt_result.setText("POOR"); 145 | else 146 | txt_result.setText("FAILED"); 147 | 148 | txt_percent = findViewById(R.id.txt_percent); 149 | txt_percent.setText(percent+"%"); 150 | 151 | //Event filter 152 | btn_filter_total.setOnClickListener(new View.OnClickListener() 153 | { 154 | @Override 155 | public void onClick(View v) 156 | { 157 | if(adapter == null) 158 | { 159 | adapter = new ResultGridAdapter(ResultActivity.this, Common.answerSheetList); 160 | recycler_result.setAdapter(adapter); 161 | } 162 | else 163 | recycler_result.setAdapter(adapter); 164 | } 165 | }); 166 | 167 | btn_filter_no_answer.setOnClickListener(new View.OnClickListener() 168 | { 169 | @Override 170 | public void onClick(View v) 171 | { 172 | Common.answerSheetListFiltered.clear(); 173 | for(int i = 0; i < Common.answerSheetList.size(); i++) 174 | { 175 | if((Common.answerSheetList.get(i) != null)&&(Common.answerSheetList.get(i).getType() == Common.ANSWER_TYPE.NO_ANSWER)) 176 | Common.answerSheetListFiltered.add(Common.answerSheetList.get(i)); 177 | } 178 | filtered_adapter = new ResultGridAdapter(ResultActivity.this, Common.answerSheetListFiltered); 179 | recycler_result.setAdapter(filtered_adapter); 180 | } 181 | }); 182 | btn_filter_wrong.setOnClickListener(new View.OnClickListener() 183 | { 184 | @Override 185 | public void onClick(View v) 186 | { 187 | Common.answerSheetListFiltered.clear(); 188 | for(int i = 0; i < Common.answerSheetList.size(); i++) 189 | { 190 | if((Common.answerSheetList.get(i) != null)&&(Common.answerSheetList.get(i).getType() == Common.ANSWER_TYPE.WRONG_ANSWER)) 191 | Common.answerSheetListFiltered.add(Common.answerSheetList.get(i)); 192 | } 193 | filtered_adapter = new ResultGridAdapter(ResultActivity.this, Common.answerSheetListFiltered); 194 | recycler_result.setAdapter(filtered_adapter); 195 | } 196 | }); 197 | btn_filter_right.setOnClickListener(new View.OnClickListener() 198 | { 199 | @Override 200 | public void onClick(View v) 201 | { 202 | Common.answerSheetListFiltered.clear(); 203 | for(int i = 0; i < Common.answerSheetList.size(); i++) 204 | { 205 | if((Common.answerSheetList.get(i) != null)&&(Common.answerSheetList.get(i).getType() == Common.ANSWER_TYPE.RIGHT_ANSWER)) 206 | Common.answerSheetListFiltered.add(Common.answerSheetList.get(i)); 207 | } 208 | filtered_adapter = new ResultGridAdapter(ResultActivity.this, Common.answerSheetListFiltered); 209 | recycler_result.setAdapter(filtered_adapter); 210 | 211 | } 212 | }); 213 | 214 | 215 | FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser(); 216 | final String useruid = user.getUid(); 217 | String email; 218 | Uri photoUrl, photoUrl_provider; 219 | String providerId, name_provider, email_provider; 220 | 221 | 222 | if (user != null) 223 | { 224 | // Name, email address, and profile photo Url 225 | name = user.getDisplayName(); 226 | email = user.getEmail(); 227 | photoUrl = user.getPhotoUrl(); 228 | 229 | Common.name = name; 230 | Common.email = email; 231 | Common.photo_url = photoUrl; 232 | 233 | // The user's ID, unique to the Firebase project. Do NOT use this value to 234 | // authenticate with your backend server, if you have one. Use 235 | // FirebaseUser.getIdToken() instead. 236 | 237 | 238 | Common.user_id = useruid; 239 | 240 | for (UserInfo profile : user.getProviderData()) 241 | { 242 | // Id of the provider (ex: google.com) 243 | providerId = profile.getProviderId(); 244 | 245 | // Name, email address, and profile photo Url 246 | name_provider = profile.getDisplayName(); 247 | email_provider = profile.getEmail(); 248 | photoUrl_provider = profile.getPhotoUrl(); 249 | 250 | Common.name_provider = name_provider; 251 | Common.email_provider = email_provider; 252 | Common.photo_url_provider = photoUrl_provider; 253 | } 254 | 255 | } 256 | else 257 | { 258 | Common.user_Phone_No = user.getPhoneNumber(); 259 | } 260 | 261 | DatabaseReference reference = FirebaseDatabase.getInstance().getReference("ScienceQuiz"); 262 | 263 | final OnlineDBHelper onlineDBHelper = OnlineDBHelper.getInstance(this, FirebaseDatabase.getInstance()); 264 | 265 | 266 | reference.addListenerForSingleValueEvent(new ValueEventListener() 267 | { 268 | @Override 269 | public void onDataChange(@NonNull DataSnapshot dataSnapshot) 270 | { 271 | String path = Common.email; 272 | path = path.replace(".", "dot"); 273 | path = path.replace("@", "attherateof"); 274 | path = path.replace("_", "underscore"); 275 | path = path.replace("#", "hashtag"); 276 | path = path.replace("*", "asterisk"); 277 | path = path.replace("-", "dash"); 278 | if(dataSnapshot.child("/Users/").hasChild(path)) 279 | { 280 | 281 | 282 | // Toast.makeText(ResultActivity.this, "read", Toast.LENGTH_SHORT).show(); 283 | Common.userData = onlineDBHelper.readUserData("Users", useruid, Common.selectedCategory.getName(), String.valueOf(Common.selectedCategory.getClassId())); 284 | switch (Common.selectedCategory.getClassId()) 285 | { 286 | case 6: 287 | if(Common.selectedCategory.getName().equalsIgnoreCase("physics")) 288 | { 289 | highscoretodisplay = onlineDBHelper.readUserData("Users", useruid, Common.selectedCategory.getName(), String.valueOf(Common.selectedCategory.getClassId())).getPhysics6high(); 290 | if(percent > highscoretodisplay) 291 | highscoretodisplay = percent; 292 | } 293 | if(Common.selectedCategory.getName().equalsIgnoreCase("chemistry")) 294 | { 295 | highscoretodisplay = onlineDBHelper.readUserData("Users", useruid, Common.selectedCategory.getName(), String.valueOf(Common.selectedCategory.getClassId())).getChemistry6high(); 296 | if(percent > highscoretodisplay) 297 | highscoretodisplay = percent; 298 | } 299 | if(Common.selectedCategory.getName().equalsIgnoreCase("biology")) 300 | { 301 | highscoretodisplay = onlineDBHelper.readUserData("Users", useruid, Common.selectedCategory.getName(), String.valueOf(Common.selectedCategory.getClassId())).getBiology6high(); 302 | if(percent > highscoretodisplay) 303 | highscoretodisplay = percent; 304 | } 305 | if(Common.selectedCategory.getName().equalsIgnoreCase("mixed")) 306 | { 307 | highscoretodisplay = onlineDBHelper.readUserData("Users", useruid, Common.selectedCategory.getName(), String.valueOf(Common.selectedCategory.getClassId())).getMixed6high(); 308 | if(percent > highscoretodisplay) 309 | highscoretodisplay = percent; 310 | } 311 | break; 312 | case 7: 313 | if(Common.selectedCategory.getName().equalsIgnoreCase("physics")) 314 | { 315 | highscoretodisplay = onlineDBHelper.readUserData("Users", useruid, Common.selectedCategory.getName(), String.valueOf(Common.selectedCategory.getClassId())).getPhysics7high(); 316 | if(percent > highscoretodisplay) 317 | highscoretodisplay = percent; 318 | } 319 | if(Common.selectedCategory.getName().equalsIgnoreCase("chemistry")) 320 | { 321 | highscoretodisplay = onlineDBHelper.readUserData("Users", useruid, Common.selectedCategory.getName(), String.valueOf(Common.selectedCategory.getClassId())).getChemistry7high(); 322 | if(percent > highscoretodisplay) 323 | highscoretodisplay = percent; 324 | } 325 | if(Common.selectedCategory.getName().equalsIgnoreCase("biology")) 326 | { 327 | highscoretodisplay = onlineDBHelper.readUserData("Users", useruid, Common.selectedCategory.getName(), String.valueOf(Common.selectedCategory.getClassId())).getBiology7high(); 328 | if(percent > highscoretodisplay) 329 | highscoretodisplay = percent; 330 | } 331 | if(Common.selectedCategory.getName().equalsIgnoreCase("mixed")) 332 | { 333 | highscoretodisplay = onlineDBHelper.readUserData("Users", useruid, Common.selectedCategory.getName(), String.valueOf(Common.selectedCategory.getClassId())).getMixed7high(); 334 | if(percent > highscoretodisplay) 335 | highscoretodisplay = percent; 336 | } 337 | break; 338 | case 8: 339 | if(Common.selectedCategory.getName().equalsIgnoreCase("physics")) 340 | { 341 | highscoretodisplay = onlineDBHelper.readUserData("Users", useruid, Common.selectedCategory.getName(), String.valueOf(Common.selectedCategory.getClassId())).getPhysics8high(); 342 | if(percent > highscoretodisplay) 343 | highscoretodisplay = percent; 344 | } 345 | if(Common.selectedCategory.getName().equalsIgnoreCase("chemistry")) 346 | { 347 | highscoretodisplay = onlineDBHelper.readUserData("Users", useruid, Common.selectedCategory.getName(), String.valueOf(Common.selectedCategory.getClassId())).getChemistry8high(); 348 | if(percent > highscoretodisplay) 349 | highscoretodisplay = percent; 350 | } 351 | if(Common.selectedCategory.getName().equalsIgnoreCase("biology")) 352 | { 353 | highscoretodisplay = onlineDBHelper.readUserData("Users", useruid, Common.selectedCategory.getName(), String.valueOf(Common.selectedCategory.getClassId())).getBiology8high(); 354 | if(percent > highscoretodisplay) 355 | highscoretodisplay = percent; 356 | } 357 | if(Common.selectedCategory.getName().equalsIgnoreCase("mixed")) 358 | { 359 | highscoretodisplay = onlineDBHelper.readUserData("Users", useruid, Common.selectedCategory.getName(), String.valueOf(Common.selectedCategory.getClassId())).getMixed8high(); 360 | if(percent > highscoretodisplay) 361 | highscoretodisplay = percent; 362 | } 363 | break; 364 | 365 | } 366 | 367 | onlineDBHelper.writeUserData("Users", useruid, Common.selectedCategory.getName(), String.valueOf(Common.selectedCategory.getClassId()), highscoretodisplay, false); 368 | 369 | 370 | } 371 | else 372 | { 373 | // Toast.makeText(ResultActivity.this, "write", Toast.LENGTH_SHORT).show(); 374 | onlineDBHelper.writeUserData("Users", useruid, Common.selectedCategory.getName(), String.valueOf(Common.selectedCategory.getClassId()), percent, true); 375 | highscoretodisplay = percent; 376 | } 377 | } 378 | 379 | @Override 380 | public void onCancelled(@NonNull DatabaseError databaseError) 381 | { 382 | Toast.makeText(ResultActivity.this, ""+databaseError.getMessage(), Toast.LENGTH_SHORT).show(); 383 | 384 | } 385 | }); 386 | 387 | 388 | 389 | 390 | 391 | } 392 | 393 | @Override 394 | public boolean onCreateOptionsMenu(Menu menu) 395 | { 396 | getMenuInflater().inflate(R.menu.result_menu, menu); 397 | return true; 398 | } 399 | 400 | @Override 401 | public boolean onOptionsItemSelected(MenuItem item) 402 | { 403 | // Log.d("1", "There 1"); 404 | // Toast.makeText(ResultActivity.this, "There 1", Toast.LENGTH_SHORT).show(); 405 | switch (item.getItemId()) 406 | { 407 | 408 | case R.id.menu_do_quiz_again: 409 | // Log.d("2", "There 2"); 410 | // Toast.makeText(ResultActivity.this, "There 2", Toast.LENGTH_SHORT).show(); 411 | doQuizAgain(); 412 | break; 413 | case R.id.menu_view_answer: 414 | // Log.d("3", "There 3"); 415 | // Toast.makeText(ResultActivity.this, "There 3", Toast.LENGTH_SHORT).show(); 416 | viewQuizAnswer(); 417 | break; 418 | case R.id.menu_high_score: 419 | if(OnlineDBHelper.getInstance(this, FirebaseDatabase.getInstance()) != null) 420 | { 421 | new MaterialStyledDialog.Builder(ResultActivity.this) 422 | .setTitle("Hi "+name) 423 | .setIcon(R.drawable.ic_mood_white_24dp) 424 | .setDescription("Your current high score in class "+Common.selectedCategory.getClassId()+" of "+Common.selectedCategory.getName()+" category is "+highscoretodisplay+"%") 425 | .setPositiveText("OK") 426 | .onPositive(new MaterialDialog.SingleButtonCallback() 427 | { 428 | @Override 429 | public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) 430 | { 431 | dialog.dismiss(); 432 | } 433 | }).show(); 434 | } 435 | break; 436 | case R.id.btn_sign_out: 437 | AuthUI.getInstance() 438 | .signOut(ResultActivity.this) 439 | .addOnCompleteListener(new OnCompleteListener() 440 | { 441 | public void onComplete(@NonNull Task task) 442 | { 443 | // btn_sign_out.setEnabled(false); 444 | startActivity(new Intent(ResultActivity.this, MainActivity.class)); 445 | 446 | } 447 | }).addOnFailureListener(new OnFailureListener() 448 | { 449 | @Override 450 | public void onFailure(@NonNull Exception e) 451 | { 452 | Toast.makeText(ResultActivity.this, ""+e.getMessage(), Toast.LENGTH_SHORT).show(); 453 | } 454 | }); 455 | break; 456 | case android.R.id.home: 457 | // Log.d("4", "There 4"); 458 | // Toast.makeText(ResultActivity.this, "There 4", Toast.LENGTH_SHORT).show(); 459 | Intent intent = new Intent(getApplicationContext(), MainActivity.class); 460 | intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); //Delete all activity 461 | startActivity(intent); 462 | break; 463 | } 464 | return true; 465 | } 466 | 467 | private void viewQuizAnswer() 468 | { 469 | // Log.d("5", "There 5"); 470 | // Toast.makeText(ResultActivity.this, "There 5", Toast.LENGTH_SHORT).show(); 471 | Intent returnIntent = new Intent(); 472 | returnIntent.putExtra("action", "viewquizanswer"); 473 | setResult(Activity.RESULT_OK, returnIntent); 474 | finish(); 475 | } 476 | 477 | private void doQuizAgain() 478 | { 479 | new MaterialStyledDialog.Builder(ResultActivity.this) 480 | .setTitle("Do quiz again?") 481 | .setIcon(R.drawable.ic_mood_black_24dp) 482 | .setDescription("Do you really want to delete this data?") 483 | .setNegativeText("No") 484 | .onNegative(new MaterialDialog.SingleButtonCallback() 485 | { 486 | @Override 487 | public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) 488 | { 489 | dialog.dismiss(); 490 | } 491 | }) 492 | .setPositiveText("Yes") 493 | .onPositive(new MaterialDialog.SingleButtonCallback() 494 | { 495 | @Override 496 | public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) 497 | { 498 | dialog.dismiss(); 499 | Intent returnIntent = new Intent(); 500 | returnIntent.putExtra("action", "doitagain"); 501 | setResult(Activity.RESULT_OK, returnIntent); 502 | // Log.d("6", "There 6"); 503 | // Toast.makeText(ResultActivity.this, "There 6", Toast.LENGTH_SHORT).show(); 504 | finish(); 505 | } 506 | }).show(); 507 | } 508 | } 509 | -------------------------------------------------------------------------------- /app/src/main/java/com/shashwatsupreme/sciencequiz/model/Category.java: -------------------------------------------------------------------------------- 1 | package com.shashwatsupreme.sciencequiz.model; 2 | 3 | public class Category 4 | { 5 | private int id; 6 | private String name,image; 7 | private int classId; 8 | 9 | public Category() 10 | { 11 | } 12 | 13 | public Category(int id, String name, String image, int classId) 14 | { 15 | this.id = id; 16 | this.name = name; 17 | this.image = image; 18 | this.classId = classId; 19 | } 20 | 21 | public int getClassId() 22 | { 23 | return classId; 24 | } 25 | 26 | public void setClassId(int classId) 27 | { 28 | this.classId = classId; 29 | } 30 | 31 | public int getId() 32 | { 33 | return id; 34 | } 35 | 36 | public void setId(int id) 37 | { 38 | this.id = id; 39 | } 40 | 41 | public String getName() 42 | { 43 | return name; 44 | } 45 | 46 | public void setName(String name) 47 | { 48 | this.name = name; 49 | } 50 | 51 | public String getImage() 52 | { 53 | return image; 54 | } 55 | 56 | public void setImage(String image) 57 | { 58 | this.image = image; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /app/src/main/java/com/shashwatsupreme/sciencequiz/model/CurrentQuestion.java: -------------------------------------------------------------------------------- 1 | package com.shashwatsupreme.sciencequiz.model; 2 | 3 | import com.shashwatsupreme.sciencequiz.Common.Common; 4 | 5 | public class CurrentQuestion 6 | { 7 | private int questionIndex; 8 | private Common.ANSWER_TYPE type; 9 | 10 | public CurrentQuestion(int questionIndex, Common.ANSWER_TYPE type) 11 | { 12 | this.questionIndex = questionIndex; 13 | this.type = type; 14 | } 15 | 16 | public int getQuestionIndex() 17 | { 18 | return questionIndex; 19 | } 20 | 21 | public void setQuestionIndex(int questionIndex) 22 | { 23 | this.questionIndex = questionIndex; 24 | } 25 | 26 | public Common.ANSWER_TYPE getType() 27 | { 28 | return type; 29 | } 30 | 31 | public void setType(Common.ANSWER_TYPE type) 32 | { 33 | this.type = type; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /app/src/main/java/com/shashwatsupreme/sciencequiz/model/Question.java: -------------------------------------------------------------------------------- 1 | package com.shashwatsupreme.sciencequiz.model; 2 | 3 | public class Question 4 | { 5 | private int ID; 6 | private String QuestionText, QuestionImage, AnswerA, AnswerB, AnswerC, AnswerD, CorrectAnswer; 7 | private boolean IsImageQuestion; 8 | private int CategoryID; 9 | private int ClassID; 10 | 11 | 12 | 13 | public Question() 14 | { 15 | } 16 | 17 | public Question(int ID, String questionText, String questionImage, String answerA, String answerB, String answerC, String answerD, String correctAnswer, boolean isImageQuestion, int categoryID, int classID) 18 | { 19 | this.ID = ID; 20 | this.QuestionText = questionText; 21 | this.QuestionImage = questionImage; 22 | this.AnswerA = answerA; 23 | this.AnswerB = answerB; 24 | this.AnswerC = answerC; 25 | this.AnswerD = answerD; 26 | this.CorrectAnswer = correctAnswer; 27 | this.IsImageQuestion = isImageQuestion; 28 | this.CategoryID = categoryID; 29 | this.ClassID = classID; 30 | } 31 | 32 | // public Question(int id, String QuestionText, String QuestionImage, String AnswerA, String AnswerB, String AnswerC, String AnswerD, String CorrectAnswer, boolean IsImageQuestion, int CategoryID) 33 | // { 34 | // this.id = id; 35 | // this.QuestionText = QuestionText; 36 | // this.QuestionImage = QuestionImage; 37 | // this.AnswerA = AnswerA; 38 | // this.AnswerB = AnswerB; 39 | // this.AnswerC = AnswerC; 40 | // this.AnswerD = AnswerD; 41 | // this.CorrectAnswer = CorrectAnswer; 42 | // this.IsImageQuestion = IsImageQuestion; 43 | // this.CategoryID = CategoryID; 44 | // } 45 | 46 | public int getID() 47 | { 48 | return ID; 49 | } 50 | 51 | public void setID(int ID) 52 | { 53 | this.ID = ID; 54 | } 55 | 56 | public int getClassID() 57 | { 58 | return ClassID; 59 | } 60 | 61 | public void setClassID(int classID) 62 | { 63 | this.ClassID = classID; 64 | } 65 | 66 | public String getQuestionText() 67 | { 68 | return QuestionText; 69 | } 70 | 71 | public void setQuestionText(String questionText) 72 | { 73 | this.QuestionText = questionText; 74 | } 75 | 76 | public String getQuestionImage() 77 | { 78 | return QuestionImage; 79 | } 80 | 81 | public void setQuestionImage(String questionImage) 82 | { 83 | this.QuestionImage = questionImage; 84 | } 85 | 86 | public String getAnswerA() 87 | { 88 | return AnswerA; 89 | } 90 | 91 | public void setAnswerA(String answerA) 92 | { 93 | this.AnswerA = answerA; 94 | } 95 | 96 | public String getAnswerB() 97 | { 98 | return AnswerB; 99 | } 100 | 101 | public void setAnswerB(String answerB) 102 | { 103 | this.AnswerB = answerB; 104 | } 105 | 106 | public String getAnswerC() 107 | { 108 | return AnswerC; 109 | } 110 | 111 | public void setAnswerC(String answerC) 112 | { 113 | this.AnswerC = answerC; 114 | } 115 | 116 | public String getAnswerD() 117 | { 118 | return AnswerD; 119 | } 120 | 121 | public void setAnswerD(String answerD) 122 | { 123 | this.AnswerD = answerD; 124 | } 125 | 126 | public String getCorrectAnswer() 127 | { 128 | return CorrectAnswer; 129 | } 130 | 131 | public void setCorrectAnswer(String correctAnswer) 132 | { 133 | this.CorrectAnswer = correctAnswer; 134 | } 135 | 136 | public boolean isImageQuestion() 137 | { 138 | return IsImageQuestion; 139 | } 140 | 141 | public void setImageQuestion(boolean imageQuestion) 142 | { 143 | IsImageQuestion = imageQuestion; 144 | } 145 | 146 | public int getCategoryID() 147 | { 148 | return CategoryID; 149 | } 150 | 151 | public void setCategoryID(int categoryID) 152 | { 153 | this.CategoryID = categoryID; 154 | } 155 | } 156 | -------------------------------------------------------------------------------- /app/src/main/java/com/shashwatsupreme/sciencequiz/model/UserData.java: -------------------------------------------------------------------------------- 1 | package com.shashwatsupreme.sciencequiz.model; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | public class UserData 7 | { 8 | private int physics6high; 9 | private int physics7high; 10 | private int physics8high; 11 | private int chemistry6high; 12 | private int chemistry7high; 13 | private int chemistry8high; 14 | private int biology6high; 15 | private int biology7high; 16 | private int biology8high; 17 | private int mixed6high; 18 | private int mixed7high; 19 | private int mixed8high; 20 | 21 | private String emailid; 22 | private String name; 23 | 24 | public UserData() 25 | { 26 | } 27 | 28 | public UserData(int physics6high, int physics7high, int physics8high, int chemistry6high, int chemistry7high, int chemistry8high, int biology6high, int biology7high, int biology8high, int mixed6high, int mixed7high, int mixed8high, String emailid, String name) 29 | { 30 | this.physics6high = physics6high; 31 | this.physics7high = physics7high; 32 | this.physics8high = physics8high; 33 | this.chemistry6high = chemistry6high; 34 | this.chemistry7high = chemistry7high; 35 | this.chemistry8high = chemistry8high; 36 | this.biology6high = biology6high; 37 | this.biology7high = biology7high; 38 | this.biology8high = biology8high; 39 | this.mixed6high = mixed6high; 40 | this.mixed7high = mixed7high; 41 | this.mixed8high = mixed8high; 42 | this.emailid = emailid; 43 | this.name = name; 44 | } 45 | 46 | public int getPhysics6high() 47 | { 48 | return physics6high; 49 | } 50 | 51 | public void setPhysics6high(int physics6high) 52 | { 53 | this.physics6high = physics6high; 54 | } 55 | 56 | public int getPhysics7high() 57 | { 58 | return physics7high; 59 | } 60 | 61 | public void setPhysics7high(int physics7high) 62 | { 63 | this.physics7high = physics7high; 64 | } 65 | 66 | public int getPhysics8high() 67 | { 68 | return physics8high; 69 | } 70 | 71 | public void setPhysics8high(int physics8high) 72 | { 73 | this.physics8high = physics8high; 74 | } 75 | 76 | public int getChemistry6high() 77 | { 78 | return chemistry6high; 79 | } 80 | 81 | public void setChemistry6high(int chemistry6high) 82 | { 83 | this.chemistry6high = chemistry6high; 84 | } 85 | 86 | public int getChemistry7high() 87 | { 88 | return chemistry7high; 89 | } 90 | 91 | public void setChemistry7high(int chemistry7high) 92 | { 93 | this.chemistry7high = chemistry7high; 94 | } 95 | 96 | public int getChemistry8high() 97 | { 98 | return chemistry8high; 99 | } 100 | 101 | public void setChemistry8high(int chemistry8high) 102 | { 103 | this.chemistry8high = chemistry8high; 104 | } 105 | 106 | public int getBiology6high() 107 | { 108 | return biology6high; 109 | } 110 | 111 | public void setBiology6high(int biology6high) 112 | { 113 | this.biology6high = biology6high; 114 | } 115 | 116 | public int getBiology7high() 117 | { 118 | return biology7high; 119 | } 120 | 121 | public void setBiology7high(int biology7high) 122 | { 123 | this.biology7high = biology7high; 124 | } 125 | 126 | public int getBiology8high() 127 | { 128 | return biology8high; 129 | } 130 | 131 | public void setBiology8high(int biology8high) 132 | { 133 | this.biology8high = biology8high; 134 | } 135 | 136 | public int getMixed6high() 137 | { 138 | return mixed6high; 139 | } 140 | 141 | public void setMixed6high(int mixed6high) 142 | { 143 | this.mixed6high = mixed6high; 144 | } 145 | 146 | public int getMixed7high() 147 | { 148 | return mixed7high; 149 | } 150 | 151 | public void setMixed7high(int mixed7high) 152 | { 153 | this.mixed7high = mixed7high; 154 | } 155 | 156 | public int getMixed8high() 157 | { 158 | return mixed8high; 159 | } 160 | 161 | public void setMixed8high(int mixed8high) 162 | { 163 | this.mixed8high = mixed8high; 164 | } 165 | 166 | public String getEmailid() 167 | { 168 | return emailid; 169 | } 170 | 171 | public void setEmailid(String emailid) 172 | { 173 | this.emailid = emailid; 174 | } 175 | 176 | public String getName() 177 | { 178 | return name; 179 | } 180 | 181 | public void setName(String name) 182 | { 183 | this.name = name; 184 | } 185 | 186 | public Map toMap() 187 | { 188 | HashMap userMap = new HashMap<>(); 189 | userMap.put("name", name); 190 | userMap.put("email", emailid); 191 | userMap.put("physics6high", physics6high); 192 | userMap.put("physics7high", physics7high); 193 | userMap.put("physics8high", physics8high); 194 | userMap.put("chemistry6high", chemistry6high); 195 | userMap.put("chemistry7high", chemistry7high); 196 | userMap.put("chemistry8high", chemistry8high); 197 | userMap.put("biology6high", biology6high); 198 | userMap.put("biology7high", biology7high); 199 | userMap.put("biology8high", chemistry8high); 200 | userMap.put("mixed6high", mixed6high); 201 | userMap.put("mixed7high", mixed7high); 202 | userMap.put("mixed8high", mixed8high); 203 | 204 | 205 | return userMap; 206 | } 207 | } -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/science_clip_art.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shshwtkhr/ScienceQuiz-Android-App/ed9d1405af3bfac5f92e9db025cecd88ea1714d6/app/src/main/res/drawable-v24/science_clip_art.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable/border_bg.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/grid_question_no_answer.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/grid_question_right_answer.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/grid_question_wrong_answer.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_access_time_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_check_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_check_white_24dp.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_clear_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_clear_white_24dp.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_error_outline_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_error_outline_white_24dp.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_format_align_justify_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_menu_camera.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_menu_gallery.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_menu_manage.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_menu_send.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_menu_share.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_menu_slideshow.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_mood_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_mood_white_24dp.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_sentiment_very_dissatisfied_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_settings_white_24dp.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_timer_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/side_nav_bar.xml: -------------------------------------------------------------------------------- 1 | 3 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/text_view_bg.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 24 | 25 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main_login.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_question.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 15 | 16 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_result.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 15 | 16 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 41 | 42 | 47 | 48 | 53 | 54 | 60 | 61 | 62 | 63 | 68 | 69 | 79 | 89 | 90 | 91 | 92 | 98 | 99 | 107 | 108 | 109 | 110 | 111 | 112 | 117 | 118 | -------------------------------------------------------------------------------- /app/src/main/res/layout/nav_header_question.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 13 | 14 | 15 |