Skip to content

Commit

Permalink
Restore instructional text on retry
Browse files Browse the repository at this point in the history
Added slight delay that made the instructional text reappear after
telling the user they got an answer incorrect, and giving them the
chance to retry. Also moved multiplying the score by 100 to the percent
formatter, rather than handling it in my own code. Finally a lot of
other code had been reorganized and refactored.
  • Loading branch information
theblackwidower committed Mar 13, 2017
1 parent 1240b25 commit 02caec2
Showing 1 changed file with 31 additions and 13 deletions.
44 changes: 31 additions & 13 deletions app/src/main/java/com/noprestige/kanaquiz/MainQuiz.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class MainQuiz extends AppCompatActivity
private Button btnSubmit;

private int oldTextColour;
private static final DecimalFormat PERCENT_FORMATTER = new DecimalFormat("#0.0");
private static final DecimalFormat PERCENT_FORMATTER = new DecimalFormat("#0.0%");

private Handler delayHandler = new Handler();

Expand Down Expand Up @@ -95,22 +95,19 @@ private void setQuestion()
{
questionBank.newQuestion();
lblDisplayKana.setText(Character.toString(questionBank.getCurrentKana()));
lblResponse.setText(R.string.request_answer);
txtAnswer.setEnabled(true);
btnSubmit.setEnabled(true);
txtAnswer.requestFocus();
// txtAnswer.setEnabled(true);
isRetrying = false;
ReadyForAnswer();
}
catch (NoQuestionsException ex)
{
lblDisplayKana.setText("");
lblResponse.setText(R.string.no_questions);
txtAnswer.setEnabled(false);
btnSubmit.setEnabled(false);
lblResponse.setTextColor(oldTextColour); //kludge for reverting text colours
txtAnswer.setText("");
}
lblResponse.setTextColor(oldTextColour); //kludge for reverting text colours

txtAnswer.setText("");
}

private void displayScore()
Expand All @@ -122,9 +119,9 @@ private void displayScore()
lblScore.setText(R.string.score_label);
lblScore.append(": ");

lblScore.append(PERCENT_FORMATTER.format(((float)totalCorrect / (float)totalQuestions) * 100));
lblScore.append(PERCENT_FORMATTER.format((float)totalCorrect / (float)totalQuestions));

lblScore.append("%\n");
lblScore.append(System.getProperty("line.separator"));
lblScore.append(Integer.toString(totalCorrect));
lblScore.append(" / ");
lblScore.append(Integer.toString(totalQuestions));
Expand All @@ -136,6 +133,7 @@ private void displayScore()
private void checkAnswer()
{
boolean isNewQuestion = true;
btnSubmit.setEnabled(false);

if (questionBank.checkCurrentAnswer(txtAnswer.getText().toString()))
{
Expand All @@ -162,17 +160,28 @@ private void checkAnswer()
lblResponse.append(getResources().getText(R.string.try_again));
isRetrying = true;
isNewQuestion = false;

delayHandler.postDelayed(
new Runnable()
{
public void run()
{
ReadyForAnswer();
}
}, 1000
);
}
}

if (isNewQuestion)
{
totalQuestions++;
//txtAnswer.setEnabled(false); //TODO: Find a way to disable a textbox without closing the touch keyboard
btnSubmit.setEnabled(false);
delayHandler.postDelayed(
new Runnable() {
public void run() {
new Runnable()
{
public void run()
{
displayScore();
setQuestion();
}
Expand All @@ -181,6 +190,15 @@ public void run() {
}
}

private void ReadyForAnswer()
{
lblResponse.setText(R.string.request_answer);
btnSubmit.setEnabled(true);
txtAnswer.requestFocus();
lblResponse.setTextColor(oldTextColour); //kludge for reverting text colours
txtAnswer.setText("");
}

public void submitAnswer(View view)
{
submitAnswer();
Expand Down

0 comments on commit 02caec2

Please sign in to comment.