Skip to content

Commit

Permalink
Fixes systers#154:Timer doesn't stops in rapidfire
Browse files Browse the repository at this point in the history
  • Loading branch information
HimanshuS01 committed Jan 11, 2017
1 parent 1d242e1 commit 01cd547
Showing 1 changed file with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.peacecorps.malaria.activities;

import android.annotation.TargetApi;
import android.app.Activity;
import android.app.Dialog;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.preference.PreferenceManager;
Expand Down Expand Up @@ -34,6 +36,7 @@ public class RapidFireGame extends Activity{
private String resultString;
private int quesNo;
private int gameScore;
private long millisLeft;
private SharedPreferences sharedPreferences;
private SharedPreferences.Editor editor;
private long timercount;
Expand Down Expand Up @@ -72,6 +75,7 @@ void initializeGame(){
scoreTv.setText("Score : " + gameScore);
askQuestion(quesNo);
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
void askQuestion(int i){
opt1.setBackground(getResources().getDrawable(R.drawable.info_hub_button));
opt2.setBackground(getResources().getDrawable(R.drawable.info_hub_button));
Expand All @@ -94,6 +98,7 @@ void askQuestion(int i){
}
public View.OnClickListener optionOneClick() {
return new View.OnClickListener() {
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override
public void onClick(View view) {
counter.cancel();
Expand Down Expand Up @@ -238,20 +243,33 @@ public RapidFireTimeCounter(long millisInFuture, long countDownInterval) {

@Override
public void onTick(long l) {
timercount=l;
timer.setText(""+ l/1000);

timer.setText(""+l/1000);
millisLeft=l;
}

@Override
public void onFinish() {
counter.cancel();
prepNextQues();
}
}


@Override
protected void onPause() {
counter.cancel();
counter= null;
super.onPause();
}

@Override
protected void onResume() {
if(counter==null){
counter= new RapidFireTimeCounter(millisLeft,1000);
counter.start();
}
super.onResume();
}
public void showDialog(){
final Dialog alertDialog = new Dialog(RapidFireGame.this,android.R.style.Theme_DeviceDefault_Dialog_NoActionBar);
alertDialog.setContentView(R.layout.game_over_dialog);
Expand Down

0 comments on commit 01cd547

Please sign in to comment.