public void showResults() { // log the activity as complete isOnResultsPage = true; quiz.mark(prefs.getString(PrefsActivity.PREF_LANGUAGE, Locale.getDefault().getLanguage())); // save results ready to send back to the quiz server String data = quiz.getResultObject().toString(); Log.d(TAG, data); DbHelper db = DbHelper.getInstance(super.getActivity()); long userId = db.getUserId(SessionManager.getUsername(getActivity())); QuizAttempt qa = new QuizAttempt(); qa.setCourseId(course.getCourseId()); qa.setUserId(userId); qa.setData(data); qa.setActivityDigest(activity.getDigest()); qa.setScore(quiz.getUserscore()); qa.setMaxscore(quiz.getMaxscore()); qa.setPassed(this.getActivityCompleted()); qa.setSent(false); db.insertQuizAttempt(qa); // Check if quiz results layout is already loaded View quizResultsLayout = getView().findViewById(R.id.widget_quiz_results); if (quizResultsLayout == null) { // load new layout View C = getView().findViewById(R.id.quiz_progress); ViewGroup parent = (ViewGroup) C.getParent(); int index = parent.indexOfChild(C); parent.removeView(C); C = super.getActivity() .getLayoutInflater() .inflate(R.layout.widget_quiz_results, parent, false); parent.addView(C, index); } TextView title = (TextView) getView().findViewById(R.id.quiz_results_score); title.setText( super.getActivity().getString(R.string.widget_quiz_results_score, this.getPercent())); if (this.isBaseline) { TextView baselineExtro = (TextView) getView().findViewById(R.id.quiz_results_baseline); baselineExtro.setVisibility(View.VISIBLE); baselineExtro.setText(super.getActivity().getString(R.string.widget_quiz_baseline_completed)); } // TODO add TextView here to give overall feedback if it's in the quiz // Show the detail of which questions were right/wrong if (quiz.getShowFeedback() == Quiz.SHOW_FEEDBACK_ALWAYS || quiz.getShowFeedback() == Quiz.SHOW_FEEDBACK_ATEND) { ListView questionFeedbackLV = (ListView) getView().findViewById(R.id.quiz_results_feedback); ArrayList<QuizFeedback> quizFeedback = new ArrayList<QuizFeedback>(); List<QuizQuestion> questions = this.quiz.getQuestions(); for (QuizQuestion q : questions) { if (!(q instanceof Description)) { QuizFeedback qf = new QuizFeedback(); qf.setScore(q.getScoreAsPercent()); qf.setQuestionText( q.getTitle( prefs.getString(PrefsActivity.PREF_LANGUAGE, Locale.getDefault().getLanguage()))); qf.setUserResponse(q.getUserResponses()); qf.setFeedbackText( q.getFeedback( prefs.getString(PrefsActivity.PREF_LANGUAGE, Locale.getDefault().getLanguage()))); quizFeedback.add(qf); } } QuizFeedbackAdapter qfa = new QuizFeedbackAdapter(super.getActivity(), quizFeedback); questionFeedbackLV.setAdapter(qfa); } // Show restart or continue button Button restartBtn = (Button) getView().findViewById(R.id.quiz_results_button); if (this.isBaseline) { restartBtn.setText(super.getActivity().getString(R.string.widget_quiz_baseline_goto_course)); restartBtn.setOnClickListener( new View.OnClickListener() { public void onClick(View v) { QuizWidget.this.getActivity().finish(); } }); } else { restartBtn.setText(super.getActivity().getString(R.string.widget_quiz_results_restart)); restartBtn.setOnClickListener( new View.OnClickListener() { public void onClick(View v) { QuizWidget.this.restart(); } }); } }
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(); }