コード例 #1
0
  private void showFeedback(String msg) {
    AlertDialog.Builder builder = new AlertDialog.Builder(super.getActivity());
    builder.setTitle(super.getActivity().getString(R.string.feedback));
    builder.setMessage(msg);
    try {
      if (this.quiz.getCurrentQuestion().getScoreAsPercent() >= Quiz.QUIZ_QUESTION_PASS_THRESHOLD) {
        builder.setIcon(R.drawable.quiz_tick);
      } else {
        builder.setIcon(R.drawable.quiz_cross);
      }
    } catch (InvalidQuizException e) {
      e.printStackTrace();
    }
    builder.setPositiveButton(
        R.string.ok,
        new DialogInterface.OnClickListener() {

          public void onClick(DialogInterface arg0, int arg1) {
            if (QuizWidget.this.quiz.hasNext()) {
              QuizWidget.this.quiz.moveNext();
              QuizWidget.this.showQuestion();
            } else {
              QuizWidget.this.showResults();
            }
          }
        });
    builder.show();
    try {
      this.quiz.getCurrentQuestion().setFeedbackDisplayed(true);
    } catch (InvalidQuizException e) {
      e.printStackTrace();
    }
  }
コード例 #2
0
 @Override
 public String getContentToRead() {
   // Get the current question text
   String toRead = "";
   try {
     toRead =
         quiz.getCurrentQuestion()
             .getTitle(
                 prefs.getString(PrefsActivity.PREF_LANGUAGE, Locale.getDefault().getLanguage()));
   } catch (InvalidQuizException e) {
     e.printStackTrace();
   }
   return toRead;
 }
コード例 #3
0
 private boolean saveAnswer() {
   try {
     List<String> answers =
         qw.getQuestionResponses(quiz.getCurrentQuestion().getResponseOptions());
     if (answers != null) {
       quiz.getCurrentQuestion().setUserResponses(answers);
       return true;
     }
     if (!quiz.getCurrentQuestion().responseExpected()) {
       return true;
     }
   } catch (InvalidQuizException e) {
     e.printStackTrace();
   }
   return false;
 }
コード例 #4
0
 private void setProgress() {
   TextView progress = (TextView) getView().findViewById(R.id.quiz_progress);
   try {
     if (quiz.getCurrentQuestion().responseExpected()) {
       progress.setText(
           super.getActivity()
               .getString(
                   R.string.widget_quiz_progress,
                   quiz.getCurrentQuestionNo(),
                   quiz.getTotalNoQuestions()));
     } else {
       progress.setText("");
     }
   } catch (InvalidQuizException e) {
     e.printStackTrace();
   }
 }
コード例 #5
0
  public void showQuestion() {
    QuizQuestion q;
    try {
      q = this.quiz.getCurrentQuestion();
    } catch (InvalidQuizException e) {
      Toast.makeText(
              super.getActivity(),
              super.getActivity().getString(R.string.error_quiz_no_questions),
              Toast.LENGTH_LONG)
          .show();
      e.printStackTrace();
      return;
    }
    qText.setVisibility(View.VISIBLE);
    // convert in case has any html special chars
    qText.setText(
        Html.fromHtml(
                q.getTitle(
                    prefs.getString(
                        PrefsActivity.PREF_LANGUAGE, Locale.getDefault().getLanguage())))
            .toString());

    if (q.getProp("image") == null) {
      questionImage.setVisibility(View.GONE);
    } else {
      String fileUrl = course.getLocation() + q.getProp("image");
      // File file = new File(fileUrl);
      Bitmap myBitmap = BitmapFactory.decodeFile(fileUrl);
      File file = new File(fileUrl);
      ImageView iv = (ImageView) getView().findViewById(R.id.question_image_image);
      iv.setImageBitmap(myBitmap);
      iv.setTag(file);
      if (q.getProp("media") == null) {
        OnImageClickListener oicl = new OnImageClickListener(super.getActivity(), "image/*");
        iv.setOnClickListener(oicl);
        TextView tv = (TextView) getView().findViewById(R.id.question_image_caption);
        tv.setText(R.string.widget_quiz_image_caption);
        questionImage.setVisibility(View.VISIBLE);
      } else {
        TextView tv = (TextView) getView().findViewById(R.id.question_image_caption);
        tv.setText(R.string.widget_quiz_media_caption);
        OnMediaClickListener omcl = new OnMediaClickListener(q.getProp("media"));
        iv.setOnClickListener(omcl);
        questionImage.setVisibility(View.VISIBLE);
      }
    }

    if (q instanceof MultiChoice) {
      qw = new MultiChoiceWidget(super.getActivity(), getView(), container);
    } else if (q instanceof MultiSelect) {
      qw = new MultiSelectWidget(super.getActivity(), getView(), container);
    } else if (q instanceof ShortAnswer) {
      qw = new ShortAnswerWidget(super.getActivity(), getView(), container);
    } else if (q instanceof Matching) {
      qw = new MatchingWidget(super.getActivity(), getView(), container);
    } else if (q instanceof Numerical) {
      qw = new NumericalWidget(super.getActivity(), getView(), container);
    } else if (q instanceof Description) {
      qw = new DescriptionWidget(super.getActivity(), getView(), container);
    } else {
      return;
    }
    qw.setQuestionResponses(q.getResponseOptions(), q.getUserResponses());
    this.setProgress();
    this.setNav();
  }