Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
f73d94b0ec
|
@ -1,28 +1,78 @@
|
|||
package com.example.alzapp;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.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;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_quick_quiz_start);
|
||||
|
||||
textViewHighScore = findViewById(R.id.quiz_highScore);
|
||||
loadHighScore();
|
||||
|
||||
quiz_start = findViewById(R.id.start_quiz);
|
||||
quiz_start.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,12 +8,13 @@ import android.database.sqlite.SQLiteOpenHelper;
|
|||
|
||||
import com.example.alzapp.QuizContract.* ;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class QuizDbHelper extends SQLiteOpenHelper {
|
||||
|
||||
private static final String DATABASE_NAME = "Quiz.db";
|
||||
public class QuizDbHelper extends SQLiteOpenHelper {
|
||||
private static final String DATABASE_NAME = "MyAwesomeQuiz.db";
|
||||
private static final int DATABASE_VERSION = 1;
|
||||
|
||||
private SQLiteDatabase db;
|
||||
|
@ -24,7 +25,6 @@ public class QuizDbHelper extends SQLiteOpenHelper {
|
|||
|
||||
@Override
|
||||
public void onCreate(SQLiteDatabase db) {
|
||||
|
||||
this.db = db;
|
||||
|
||||
final String SQL_CREATE_QUESTIONS_TABLE = "CREATE TABLE " +
|
||||
|
@ -38,9 +38,7 @@ public class QuizDbHelper extends SQLiteOpenHelper {
|
|||
")";
|
||||
|
||||
db.execSQL(SQL_CREATE_QUESTIONS_TABLE);
|
||||
|
||||
fillQuestionsTable();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -50,20 +48,26 @@ public class QuizDbHelper extends SQLiteOpenHelper {
|
|||
}
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
|
@ -71,16 +75,12 @@ public class QuizDbHelper extends SQLiteOpenHelper {
|
|||
ContentValues cv = new ContentValues();
|
||||
cv.put(QuestionsTable.COLUMN_QUESTION, question.getQuestion());
|
||||
cv.put(QuestionsTable.COLUMN_OPTION1, question.getOption1());
|
||||
cv.put(QuestionsTable.COLUMN_OPTION1, question.getOption1());
|
||||
cv.put(QuestionsTable.COLUMN_OPTION2, question.getOption2());
|
||||
cv.put(QuestionsTable.COLUMN_OPTION3, question.getOption3());
|
||||
cv.put(QuestionsTable.COLUMN_ANSWER_NR, question.getAnswerNr());
|
||||
|
||||
db.insert(QuestionsTable.TABLE_NAME, null, cv);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public List<Question> getAllQuestions() {
|
||||
List<Question> questionList = new ArrayList<>();
|
||||
db = getReadableDatabase();
|
||||
|
@ -94,6 +94,7 @@ public class QuizDbHelper extends SQLiteOpenHelper {
|
|||
question.setOption2(c.getString(c.getColumnIndex(QuestionsTable.COLUMN_OPTION2)));
|
||||
question.setOption3(c.getString(c.getColumnIndex(QuestionsTable.COLUMN_OPTION3)));
|
||||
question.setAnswerNr(c.getInt(c.getColumnIndex(QuestionsTable.COLUMN_ANSWER_NR)));
|
||||
questionList.add(question);
|
||||
} while (c.moveToNext());
|
||||
}
|
||||
|
||||
|
|
|
@ -1,19 +1,27 @@
|
|||
package com.example.alzapp;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.os.CountDownTimer;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.RadioGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import android.widget.Toast;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
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 textViewScore;
|
||||
private TextView textViewQuestionCount;
|
||||
|
@ -25,7 +33,10 @@ public class QuizQuestionPage extends AppCompatActivity {
|
|||
private Button buttonConfirmNext;
|
||||
|
||||
private ColorStateList textColorDefaultRb;
|
||||
private ColorStateList textColorDefaultCd;
|
||||
|
||||
private CountDownTimer countDownTimer;
|
||||
private long timeLeftInMillis;
|
||||
|
||||
private List<Question> questionList;
|
||||
private int questionCounter;
|
||||
|
@ -35,6 +46,8 @@ public class QuizQuestionPage extends AppCompatActivity {
|
|||
private int score;
|
||||
private boolean answered;
|
||||
|
||||
private long backPressedTime;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
@ -50,6 +63,10 @@ public class QuizQuestionPage extends AppCompatActivity {
|
|||
rb3 = findViewById(R.id.radioButton32);
|
||||
buttonConfirmNext = findViewById(R.id.quiz_confirm_next);
|
||||
|
||||
|
||||
textColorDefaultRb = rb1.getTextColors();
|
||||
textColorDefaultCd = textViewCountDown.getTextColors();
|
||||
|
||||
QuizDbHelper dbHelper = new QuizDbHelper(this);
|
||||
questionList = dbHelper.getAllQuestions();
|
||||
questionCountTotal = questionList.size();
|
||||
|
@ -57,6 +74,20 @@ public class QuizQuestionPage extends AppCompatActivity {
|
|||
|
||||
showNextQuestion();
|
||||
|
||||
buttonConfirmNext.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (!answered) {
|
||||
if (rb1.isChecked() || rb2.isChecked() || rb3.isChecked()) {
|
||||
checkAnswer();
|
||||
} else {
|
||||
Toast.makeText(QuizQuestionPage.this, "Please select an answer", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
} else {
|
||||
showNextQuestion();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void showNextQuestion() {
|
||||
|
@ -77,10 +108,117 @@ public class QuizQuestionPage extends AppCompatActivity {
|
|||
textViewQuestionCount.setText("Question: " + questionCounter + "/" + questionCountTotal);
|
||||
answered = false;
|
||||
buttonConfirmNext.setText("Confirm");
|
||||
|
||||
timeLeftInMillis = COUNT_DOWN_MILLIS;
|
||||
startCountdown();
|
||||
|
||||
} else {
|
||||
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() {
|
||||
answered = true;
|
||||
|
||||
countDownTimer.cancel();
|
||||
|
||||
RadioButton rbSelected = findViewById(rbGroup.getCheckedRadioButtonId());
|
||||
int answerNr = rbGroup.indexOfChild(rbSelected) + 1;
|
||||
|
||||
if (answerNr == currentQuestion.getAnswerNr()) {
|
||||
score++;
|
||||
textViewScore.setText("Score: " + score);
|
||||
}
|
||||
|
||||
showSolution();
|
||||
}
|
||||
|
||||
private void showSolution() {
|
||||
/** rb1.setTextColor(Color.RED);
|
||||
rb2.setTextColor(Color.RED);
|
||||
rb3.setTextColor(Color.RED); **/
|
||||
|
||||
switch (currentQuestion.getAnswerNr()) {
|
||||
case 1:
|
||||
// rb1.setTextColor(Color.GREEN);
|
||||
textViewQuestion.setText("Answer 1 is correct");
|
||||
break;
|
||||
case 2:
|
||||
// rb2.setTextColor(Color.GREEN);
|
||||
textViewQuestion.setText("Answer 2 is correct");
|
||||
break;
|
||||
case 3:
|
||||
// rb3.setTextColor(Color.GREEN);
|
||||
textViewQuestion.setText("Answer 3 is correct");
|
||||
break;
|
||||
}
|
||||
|
||||
if (questionCounter < questionCountTotal) {
|
||||
buttonConfirmNext.setText("Next");
|
||||
} else {
|
||||
buttonConfirmNext.setText("Finish");
|
||||
}
|
||||
}
|
||||
|
||||
private void finishQuiz() {
|
||||
Intent resultIntent = new Intent();
|
||||
resultIntent.putExtra(EXTRA_SCORE,score);
|
||||
setResult(RESULT_OK,resultIntent);
|
||||
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.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.Chronometer;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
|
@ -38,7 +39,8 @@ public class TileMatchingActivity extends AppCompatActivity {
|
|||
img201,img202,img203,img204,img205,img206,img207,img208,
|
||||
firstCard,secondCard,clickedFirst,clickedSecond,cardNumber=1,playerMoves=0;
|
||||
|
||||
|
||||
private Chronometer chronometer;
|
||||
public boolean running;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -46,6 +48,9 @@ public class TileMatchingActivity extends AppCompatActivity {
|
|||
setContentView(R.layout.activity_tile_matching);
|
||||
counter=(TextView) findViewById(R.id.counter1);
|
||||
|
||||
chronometer = findViewById(R.id.tileMatching_chronometer);
|
||||
|
||||
|
||||
i11=(ImageView) findViewById(R.id.i11);
|
||||
i12=(ImageView) findViewById(R.id.i12);
|
||||
i13=(ImageView) findViewById(R.id.i13);
|
||||
|
@ -222,8 +227,6 @@ public class TileMatchingActivity extends AppCompatActivity {
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
Button back = (Button) findViewById(R.id.back);
|
||||
|
||||
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){
|
||||
if(cardsArray[card]==101){
|
||||
img.setImageResource(img101);
|
||||
|
@ -495,9 +505,14 @@ public class TileMatchingActivity extends AppCompatActivity {
|
|||
i44.getVisibility()==View.INVISIBLE
|
||||
){
|
||||
AlertDialog.Builder message= new AlertDialog.Builder(TileMatchingActivity.this);
|
||||
message.setMessage("GAME OVER!!\nMOVES= "+counter)
|
||||
.setCancelable(false)
|
||||
.setPositiveButton("NEXT", new DialogInterface.OnClickListener() {
|
||||
message.setMessage("GAME OVER!!\nMOVES= "+counter);
|
||||
/** Timer end **/
|
||||
if(running){
|
||||
chronometer.stop();
|
||||
running = false;
|
||||
}
|
||||
message.setCancelable(false);
|
||||
message.setPositiveButton("NEXT", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
finish();
|
||||
|
|
|
@ -15,9 +15,10 @@
|
|||
android:textColor="@android:color/black" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/quiz_highScore"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="High Score"
|
||||
android:text="Highscore : 0"
|
||||
android:textSize="20dp"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginTop="160dp"
|
||||
|
|
|
@ -83,7 +83,7 @@
|
|||
android:id="@+id/quiz_confirm_next"
|
||||
android:layout_width="160dp"
|
||||
android:layout_height="50dp"
|
||||
android:text="next"
|
||||
android:text="confirm"
|
||||
android:background="@drawable/button_menu"
|
||||
android:layout_below="@id/quiz_radio_group"
|
||||
android:layout_marginTop="50dp"
|
||||
|
|
|
@ -43,6 +43,15 @@
|
|||
android:text="MOVES= 0"
|
||||
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>
|
Loading…
Reference in New Issue