parent
11f732361d
commit
26ce59d117
|
@ -1,28 +1,78 @@
|
||||||
package com.example.alzapp;
|
package com.example.alzapp;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
public class QuickQuizStart extends AppCompatActivity {
|
public class QuickQuizStart extends AppCompatActivity {
|
||||||
|
|
||||||
|
private static final int REQUEST_CODE_QUIZ = 1;
|
||||||
|
|
||||||
|
public static final String SHARED_PREFS = "sharedPrefs";
|
||||||
|
public static final String KEY_HIGHSCORE = "keyHighScore";
|
||||||
|
|
||||||
|
private TextView textViewHighScore;
|
||||||
|
private int highScore;
|
||||||
|
|
||||||
private Button quiz_start;
|
private Button quiz_start;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_quick_quiz_start);
|
setContentView(R.layout.activity_quick_quiz_start);
|
||||||
|
|
||||||
|
textViewHighScore = findViewById(R.id.quiz_highScore);
|
||||||
|
loadHighScore();
|
||||||
|
|
||||||
quiz_start = findViewById(R.id.start_quiz);
|
quiz_start = findViewById(R.id.start_quiz);
|
||||||
quiz_start.setOnClickListener(new View.OnClickListener() {
|
quiz_start.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
Intent intent = new Intent(QuickQuizStart.this,QuizQuestionPage.class);
|
Intent intent = new Intent(QuickQuizStart.this,QuizQuestionPage.class);
|
||||||
startActivity(intent);
|
startActivityForResult(intent,REQUEST_CODE_QUIZ);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
|
||||||
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
|
|
||||||
|
if(requestCode == REQUEST_CODE_QUIZ){
|
||||||
|
if(resultCode == RESULT_OK){
|
||||||
|
int score = data.getIntExtra(QuizQuestionPage.EXTRA_SCORE,0);
|
||||||
|
if(score > highScore){
|
||||||
|
updateHighScore(score);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateHighScore(int highScoreNew){
|
||||||
|
highScore = highScoreNew;
|
||||||
|
textViewHighScore.setText("Highscore: "+ highScore);
|
||||||
|
|
||||||
|
SharedPreferences prefs = getSharedPreferences(SHARED_PREFS, MODE_PRIVATE);
|
||||||
|
SharedPreferences.Editor editor = prefs.edit();
|
||||||
|
editor.putInt(KEY_HIGHSCORE, highScore);
|
||||||
|
editor.apply();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void loadHighScore(){
|
||||||
|
SharedPreferences prefs = getSharedPreferences(SHARED_PREFS,MODE_PRIVATE);
|
||||||
|
highScore = prefs.getInt(KEY_HIGHSCORE,0);
|
||||||
|
textViewHighScore.setText("Highscore: "+ highScore);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,16 +48,27 @@ public class QuizDbHelper extends SQLiteOpenHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fillQuestionsTable() {
|
private void fillQuestionsTable() {
|
||||||
Question q1 = new Question("A is correct", "A", "B", "C", 1);
|
Question q1 = new Question("What is 2+2?", "4", "12", "17", 1);
|
||||||
addQuestion(q1);
|
addQuestion(q1);
|
||||||
Question q2 = new Question("B is correct", "A", "B", "C", 2);
|
Question q2 = new Question("Which letter comes after A,B,C,D in the english alphabet series?", "F", "E", "D", 2);
|
||||||
addQuestion(q2);
|
addQuestion(q2);
|
||||||
Question q3 = new Question("C is correct", "A", "B", "C", 3);
|
Question q3 = new Question("How many letters are present in the english alphabet?", "28", "25", "26", 3);
|
||||||
addQuestion(q3);
|
addQuestion(q3);
|
||||||
Question q4 = new Question("A is correct again", "A", "B", "C", 1);
|
Question q4 = new Question("8,16,24, __ Which number should come in the blank space ?", "34", "32", "48", 2);
|
||||||
addQuestion(q4);
|
addQuestion(q4);
|
||||||
Question q5 = new Question("B is correct again", "A", "B", "C", 2);
|
Question q5 = new Question("In tossing of a fair coin, what is the probability of getting a head? ", "50%", "40%", "55%", 1);
|
||||||
addQuestion(q5);
|
addQuestion(q5);
|
||||||
|
Question q6 = new Question("The total number of states present in India is", "27", "28", "29", 2);
|
||||||
|
addQuestion(q6);
|
||||||
|
Question q7 = new Question("The Hindi film industry is better known as ", "Bollywood", "Tollywood", "Sandalwood", 1);
|
||||||
|
addQuestion(q7);
|
||||||
|
Question q8 = new Question("Which city is also known as the Silicon Valley of Asia ?", "Mumbai", "Abu Dhabi", "Bangalore", 3);
|
||||||
|
addQuestion(q8);
|
||||||
|
Question q9 = new Question("Total number of bones present in the human body is ", "204", "205", "206", 3);
|
||||||
|
addQuestion(q9);
|
||||||
|
Question q10 = new Question("Novak Djokovic is a famous player associated with the game of ", "Basketball", "Tennis", "Cricket", 1);
|
||||||
|
addQuestion(q10);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addQuestion(Question question) {
|
private void addQuestion(Question question) {
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
package com.example.alzapp;
|
package com.example.alzapp;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
import android.content.res.ColorStateList;
|
import android.content.res.ColorStateList;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.CountDownTimer;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.RadioButton;
|
import android.widget.RadioButton;
|
||||||
|
@ -13,8 +15,13 @@ import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
public class QuizQuestionPage extends AppCompatActivity {
|
public class QuizQuestionPage extends AppCompatActivity {
|
||||||
|
|
||||||
|
public static final String EXTRA_SCORE = "extraScore";
|
||||||
|
private static final long COUNT_DOWN_MILLIS = 10000;
|
||||||
|
|
||||||
private TextView textViewQuestion;
|
private TextView textViewQuestion;
|
||||||
private TextView textViewScore;
|
private TextView textViewScore;
|
||||||
private TextView textViewQuestionCount;
|
private TextView textViewQuestionCount;
|
||||||
|
@ -26,6 +33,10 @@ public class QuizQuestionPage extends AppCompatActivity {
|
||||||
private Button buttonConfirmNext;
|
private Button buttonConfirmNext;
|
||||||
|
|
||||||
private ColorStateList textColorDefaultRb;
|
private ColorStateList textColorDefaultRb;
|
||||||
|
private ColorStateList textColorDefaultCd;
|
||||||
|
|
||||||
|
private CountDownTimer countDownTimer;
|
||||||
|
private long timeLeftInMillis;
|
||||||
|
|
||||||
private List<Question> questionList;
|
private List<Question> questionList;
|
||||||
private int questionCounter;
|
private int questionCounter;
|
||||||
|
@ -35,6 +46,8 @@ public class QuizQuestionPage extends AppCompatActivity {
|
||||||
private int score;
|
private int score;
|
||||||
private boolean answered;
|
private boolean answered;
|
||||||
|
|
||||||
|
private long backPressedTime;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
@ -52,6 +65,7 @@ public class QuizQuestionPage extends AppCompatActivity {
|
||||||
|
|
||||||
|
|
||||||
textColorDefaultRb = rb1.getTextColors();
|
textColorDefaultRb = rb1.getTextColors();
|
||||||
|
textColorDefaultCd = textViewCountDown.getTextColors();
|
||||||
|
|
||||||
QuizDbHelper dbHelper = new QuizDbHelper(this);
|
QuizDbHelper dbHelper = new QuizDbHelper(this);
|
||||||
questionList = dbHelper.getAllQuestions();
|
questionList = dbHelper.getAllQuestions();
|
||||||
|
@ -94,14 +108,54 @@ public class QuizQuestionPage extends AppCompatActivity {
|
||||||
textViewQuestionCount.setText("Question: " + questionCounter + "/" + questionCountTotal);
|
textViewQuestionCount.setText("Question: " + questionCounter + "/" + questionCountTotal);
|
||||||
answered = false;
|
answered = false;
|
||||||
buttonConfirmNext.setText("Confirm");
|
buttonConfirmNext.setText("Confirm");
|
||||||
|
|
||||||
|
timeLeftInMillis = COUNT_DOWN_MILLIS;
|
||||||
|
startCountdown();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
finishQuiz();
|
finishQuiz();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void startCountdown(){
|
||||||
|
countDownTimer = new CountDownTimer(timeLeftInMillis,1000) {
|
||||||
|
@Override
|
||||||
|
public void onTick(long millisUntilFinished) {
|
||||||
|
timeLeftInMillis = millisUntilFinished;
|
||||||
|
updateCountDownText();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFinish() {
|
||||||
|
timeLeftInMillis = 0;
|
||||||
|
updateCountDownText();
|
||||||
|
checkAnswer();
|
||||||
|
}
|
||||||
|
}.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateCountDownText(){
|
||||||
|
int minutes = (int) (timeLeftInMillis / 1000) /60;
|
||||||
|
int seconds = (int) (timeLeftInMillis / 1000) %60;
|
||||||
|
|
||||||
|
String timeFormatted = String.format(Locale.getDefault(),"%02d:%02d",minutes,seconds);
|
||||||
|
textViewCountDown.setText(timeFormatted);
|
||||||
|
|
||||||
|
|
||||||
|
if(timeLeftInMillis < 5000){
|
||||||
|
textViewCountDown.setTextColor(Color.GREEN);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
textViewCountDown.setTextColor(textColorDefaultCd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void checkAnswer() {
|
private void checkAnswer() {
|
||||||
answered = true;
|
answered = true;
|
||||||
|
|
||||||
|
countDownTimer.cancel();
|
||||||
|
|
||||||
RadioButton rbSelected = findViewById(rbGroup.getCheckedRadioButtonId());
|
RadioButton rbSelected = findViewById(rbGroup.getCheckedRadioButtonId());
|
||||||
int answerNr = rbGroup.indexOfChild(rbSelected) + 1;
|
int answerNr = rbGroup.indexOfChild(rbSelected) + 1;
|
||||||
|
|
||||||
|
@ -114,21 +168,21 @@ public class QuizQuestionPage extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showSolution() {
|
private void showSolution() {
|
||||||
rb1.setTextColor(Color.RED);
|
/** rb1.setTextColor(Color.RED);
|
||||||
rb2.setTextColor(Color.RED);
|
rb2.setTextColor(Color.RED);
|
||||||
rb3.setTextColor(Color.RED);
|
rb3.setTextColor(Color.RED); **/
|
||||||
|
|
||||||
switch (currentQuestion.getAnswerNr()) {
|
switch (currentQuestion.getAnswerNr()) {
|
||||||
case 1:
|
case 1:
|
||||||
rb1.setTextColor(Color.GREEN);
|
// rb1.setTextColor(Color.GREEN);
|
||||||
textViewQuestion.setText("Answer 1 is correct");
|
textViewQuestion.setText("Answer 1 is correct");
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
rb2.setTextColor(Color.GREEN);
|
// rb2.setTextColor(Color.GREEN);
|
||||||
textViewQuestion.setText("Answer 2 is correct");
|
textViewQuestion.setText("Answer 2 is correct");
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
rb3.setTextColor(Color.GREEN);
|
// rb3.setTextColor(Color.GREEN);
|
||||||
textViewQuestion.setText("Answer 3 is correct");
|
textViewQuestion.setText("Answer 3 is correct");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -141,6 +195,30 @@ public class QuizQuestionPage extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void finishQuiz() {
|
private void finishQuiz() {
|
||||||
|
Intent resultIntent = new Intent();
|
||||||
|
resultIntent.putExtra(EXTRA_SCORE,score);
|
||||||
|
setResult(RESULT_OK,resultIntent);
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBackPressed() {
|
||||||
|
if(backPressedTime + 2000 > System.currentTimeMillis()){
|
||||||
|
finishQuiz();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Toast.makeText(this,"Press back again to finish",Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
|
||||||
|
backPressedTime = System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onDestroy() {
|
||||||
|
super.onDestroy();
|
||||||
|
if(countDownTimer != null){
|
||||||
|
countDownTimer.cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
|
import android.widget.Chronometer;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
@ -38,7 +39,8 @@ public class TileMatchingActivity extends AppCompatActivity {
|
||||||
img201,img202,img203,img204,img205,img206,img207,img208,
|
img201,img202,img203,img204,img205,img206,img207,img208,
|
||||||
firstCard,secondCard,clickedFirst,clickedSecond,cardNumber=1,playerMoves=0;
|
firstCard,secondCard,clickedFirst,clickedSecond,cardNumber=1,playerMoves=0;
|
||||||
|
|
||||||
|
private Chronometer chronometer;
|
||||||
|
public boolean running;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
@ -46,6 +48,9 @@ public class TileMatchingActivity extends AppCompatActivity {
|
||||||
setContentView(R.layout.activity_tile_matching);
|
setContentView(R.layout.activity_tile_matching);
|
||||||
counter=(TextView) findViewById(R.id.counter1);
|
counter=(TextView) findViewById(R.id.counter1);
|
||||||
|
|
||||||
|
chronometer = findViewById(R.id.tileMatching_chronometer);
|
||||||
|
|
||||||
|
|
||||||
i11=(ImageView) findViewById(R.id.i11);
|
i11=(ImageView) findViewById(R.id.i11);
|
||||||
i12=(ImageView) findViewById(R.id.i12);
|
i12=(ImageView) findViewById(R.id.i12);
|
||||||
i13=(ImageView) findViewById(R.id.i13);
|
i13=(ImageView) findViewById(R.id.i13);
|
||||||
|
@ -222,8 +227,6 @@ public class TileMatchingActivity extends AppCompatActivity {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Button back = (Button) findViewById(R.id.back);
|
Button back = (Button) findViewById(R.id.back);
|
||||||
|
|
||||||
back.setOnClickListener(new View.OnClickListener() {
|
back.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@ -233,9 +236,16 @@ public class TileMatchingActivity extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/** Game timer **/
|
||||||
|
if(!running){
|
||||||
|
chronometer.start();
|
||||||
|
running = true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void doStuff(ImageView img,int card){
|
private void doStuff(ImageView img,int card){
|
||||||
if(cardsArray[card]==101){
|
if(cardsArray[card]==101){
|
||||||
img.setImageResource(img101);
|
img.setImageResource(img101);
|
||||||
|
@ -495,9 +505,14 @@ public class TileMatchingActivity extends AppCompatActivity {
|
||||||
i44.getVisibility()==View.INVISIBLE
|
i44.getVisibility()==View.INVISIBLE
|
||||||
){
|
){
|
||||||
AlertDialog.Builder message= new AlertDialog.Builder(TileMatchingActivity.this);
|
AlertDialog.Builder message= new AlertDialog.Builder(TileMatchingActivity.this);
|
||||||
message.setMessage("GAME OVER!!\nMOVES= "+counter)
|
message.setMessage("GAME OVER!!\nMOVES= "+counter);
|
||||||
.setCancelable(false)
|
/** Timer end **/
|
||||||
.setPositiveButton("NEXT", new DialogInterface.OnClickListener() {
|
if(running){
|
||||||
|
chronometer.stop();
|
||||||
|
running = false;
|
||||||
|
}
|
||||||
|
message.setCancelable(false);
|
||||||
|
message.setPositiveButton("NEXT", new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
finish();
|
finish();
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
android:textColor="@android:color/black" />
|
android:textColor="@android:color/black" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
android:id="@+id/quiz_highScore"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="Highscore : 0"
|
android:text="Highscore : 0"
|
||||||
|
|
|
@ -43,6 +43,15 @@
|
||||||
android:text="MOVES= 0"
|
android:text="MOVES= 0"
|
||||||
android:textSize="20sp"/>
|
android:textSize="20sp"/>
|
||||||
|
|
||||||
|
<Chronometer
|
||||||
|
android:id="@+id/tileMatching_chronometer"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignParentBottom="true"
|
||||||
|
android:layout_marginLeft="16dp"
|
||||||
|
android:textSize="24sp"/>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
Loading…
Reference in New Issue