Search in sources :

Example 1 with AlphaPickerQuiz

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

the class TopekaDatabaseHelper method createQuizDueToType.

/**
     * Creates a quiz corresponding to the projection provided from a cursor row.
     * Currently only {@link QuizTable#PROJECTION} is supported.
     *
     * @param cursor The Cursor containing the data.
     * @return The created quiz.
     */
private static Quiz createQuizDueToType(Cursor cursor) {
    // "magic numbers" based on QuizTable#PROJECTION
    final String type = cursor.getString(2);
    final String question = cursor.getString(3);
    final String answer = cursor.getString(4);
    final String options = cursor.getString(5);
    final int min = cursor.getInt(6);
    final int max = cursor.getInt(7);
    final int step = cursor.getInt(8);
    final boolean solved = getBooleanFromDatabase(cursor.getString(11));
    switch(type) {
        case JsonAttributes.QuizType.ALPHA_PICKER:
            {
                return new AlphaPickerQuiz(question, answer, solved);
            }
        case JsonAttributes.QuizType.FILL_BLANK:
            {
                return createFillBlankQuiz(cursor, question, answer, solved);
            }
        case JsonAttributes.QuizType.FILL_TWO_BLANKS:
            {
                return createFillTwoBlanksQuiz(question, answer, solved);
            }
        case JsonAttributes.QuizType.FOUR_QUARTER:
            {
                return createFourQuarterQuiz(question, answer, options, solved);
            }
        case JsonAttributes.QuizType.MULTI_SELECT:
            {
                return createMultiSelectQuiz(question, answer, options, solved);
            }
        case JsonAttributes.QuizType.PICKER:
            {
                return new PickerQuiz(question, Integer.valueOf(answer), min, max, step, solved);
            }
        case JsonAttributes.QuizType.SINGLE_SELECT:
        //fall-through intended
        case JsonAttributes.QuizType.SINGLE_SELECT_ITEM:
            {
                return createSelectItemQuiz(question, answer, options, solved);
            }
        case JsonAttributes.QuizType.TOGGLE_TRANSLATE:
            {
                return createToggleTranslateQuiz(question, answer, options, solved);
            }
        case JsonAttributes.QuizType.TRUE_FALSE:
            {
                return createTrueFalseQuiz(question, answer, solved);
            }
        default:
            {
                throw new IllegalArgumentException("Quiz type " + type + " is not supported");
            }
    }
}
Also used : AlphaPickerQuiz(com.google.samples.apps.topeka.model.quiz.AlphaPickerQuiz) AlphaPickerQuiz(com.google.samples.apps.topeka.model.quiz.AlphaPickerQuiz) PickerQuiz(com.google.samples.apps.topeka.model.quiz.PickerQuiz)

Aggregations

AlphaPickerQuiz (com.google.samples.apps.topeka.model.quiz.AlphaPickerQuiz)1 PickerQuiz (com.google.samples.apps.topeka.model.quiz.PickerQuiz)1