Search in sources :

Example 1 with FillTwoBlanksQuiz

use of com.google.samples.apps.topeka.model.quiz.FillTwoBlanksQuiz in project android-topeka by googlesamples.

the class SolveQuizUtil method solveQuiz.

/**
     * Solves a given quiz.
     *
     * @param quiz Quiz to solve.
     */
public static void solveQuiz(Quiz quiz) {
    switch(quiz.getType()) {
        case ALPHA_PICKER:
            setAlphaPickerProgress((AlphaPickerQuiz) quiz);
            break;
        case PICKER:
            setPickerProgress((PickerQuiz) quiz);
            break;
        case FILL_BLANK:
            FillBlankQuiz fillBlankQuiz = (FillBlankQuiz) quiz;
            String siblingText = fillBlankQuiz.getStart();
            if (TextUtils.isEmpty(siblingText)) {
                siblingText = fillBlankQuiz.getEnd();
            }
            int viewId = R.id.quiz_edit_text;
            if (TextUtils.isEmpty(siblingText)) {
                siblingText = quiz.getQuestion();
                viewId = R.id.quiz_content;
            }
            typeAndCloseOnView(fillBlankQuiz.getAnswer(), siblingText, viewId);
            break;
        case FILL_TWO_BLANKS:
            FillTwoBlanksQuiz fillTwoBlanksQuiz = (FillTwoBlanksQuiz) quiz;
            typeAndCloseOnView(fillTwoBlanksQuiz.getAnswer()[0], R.id.quiz_edit_text);
            typeAndCloseOnView(fillTwoBlanksQuiz.getAnswer()[1], R.id.quiz_edit_text_two);
            break;
        case FOUR_QUARTER:
            testOptionsQuizWithType(quiz, GridView.class);
            break;
        case SINGLE_SELECT:
        case SINGLE_SELECT_ITEM:
        case MULTI_SELECT:
            testOptionsQuizWithType(quiz, ListView.class);
            break;
        case TOGGLE_TRANSLATE:
            ToggleTranslateQuiz toggleTranslateQuiz = (ToggleTranslateQuiz) quiz;
            for (int i : toggleTranslateQuiz.getAnswer()) {
                onData(equalTo(toggleTranslateQuiz.getReadableOptions()[i])).inAdapterView(allOf(instanceOf(AdapterView.class), withId(R.id.quiz_content), hasSiblingWith(quiz.getQuestion()))).perform(click());
            }
            break;
        case TRUE_FALSE:
            TrueFalseQuiz trueFalseQuiz = (TrueFalseQuiz) quiz;
            onView(allOf(isDescendantOfA(hasSibling(withText(quiz.getQuestion()))), withText(trueFalseQuiz.getAnswer() ? R.string.btn_true : R.string.btn_false))).perform(click());
            break;
    }
}
Also used : FillBlankQuiz(com.google.samples.apps.topeka.model.quiz.FillBlankQuiz) AdapterView(android.widget.AdapterView) ToggleTranslateQuiz(com.google.samples.apps.topeka.model.quiz.ToggleTranslateQuiz) FillTwoBlanksQuiz(com.google.samples.apps.topeka.model.quiz.FillTwoBlanksQuiz) TrueFalseQuiz(com.google.samples.apps.topeka.model.quiz.TrueFalseQuiz)

Aggregations

AdapterView (android.widget.AdapterView)1 FillBlankQuiz (com.google.samples.apps.topeka.model.quiz.FillBlankQuiz)1 FillTwoBlanksQuiz (com.google.samples.apps.topeka.model.quiz.FillTwoBlanksQuiz)1 ToggleTranslateQuiz (com.google.samples.apps.topeka.model.quiz.ToggleTranslateQuiz)1 TrueFalseQuiz (com.google.samples.apps.topeka.model.quiz.TrueFalseQuiz)1