Search in sources :

Example 1 with FormEntryPrompt

use of org.javarosa.form.api.FormEntryPrompt in project collect by opendatakit.

the class ODKView method getAnswers.

/**
 * @return a HashMap of answers entered by the user for this set of widgets
 */
public HashMap<FormIndex, IAnswerData> getAnswers() {
    HashMap<FormIndex, IAnswerData> answers = new LinkedHashMap<>();
    for (QuestionWidget q : widgets) {
        /*
             * The FormEntryPrompt has the FormIndex, which is where the answer gets stored. The
             * QuestionWidget has the answer the user has entered.
             */
        FormEntryPrompt p = q.getFormEntryPrompt();
        answers.put(p.getIndex(), q.getAnswer());
    }
    return answers;
}
Also used : IAnswerData(org.javarosa.core.model.data.IAnswerData) FormEntryPrompt(org.javarosa.form.api.FormEntryPrompt) FormIndex(org.javarosa.core.model.FormIndex) QuestionWidget(org.odk.collect.android.widgets.QuestionWidget) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with FormEntryPrompt

use of org.javarosa.form.api.FormEntryPrompt in project collect by opendatakit.

the class FormController method getQuestionPrompts.

/**
 * Returns an array of question promps.
 */
public FormEntryPrompt[] getQuestionPrompts() throws RuntimeException {
    // For questions, there is only one.
    // For groups, there could be many, but we set that below
    FormEntryPrompt[] questions = new FormEntryPrompt[1];
    IFormElement element = formEntryController.getModel().getForm().getChild(getFormIndex());
    if (element instanceof GroupDef) {
        GroupDef gd = (GroupDef) element;
        // we only display relevant questions
        List<FormEntryPrompt> questionList = new ArrayList<>();
        for (FormIndex index : getIndicesForGroup(gd)) {
            if (getEvent(index) != FormEntryController.EVENT_QUESTION) {
                String errorMsg = "Only questions and regular groups are allowed in 'field-list'.  Bad node is: " + index.getReference().toString(false);
                RuntimeException e = new RuntimeException(errorMsg);
                Timber.w(errorMsg);
                throw e;
            }
            // we only display relevant questions
            if (formEntryController.getModel().isIndexRelevant(index)) {
                questionList.add(getQuestionPrompt(index));
            }
            questions = new FormEntryPrompt[questionList.size()];
            questionList.toArray(questions);
        }
    } else {
        // We have a question, so just get the one prompt
        questions[0] = getQuestionPrompt();
    }
    return questions;
}
Also used : IFormElement(org.javarosa.core.model.IFormElement) FormEntryPrompt(org.javarosa.form.api.FormEntryPrompt) ArrayList(java.util.ArrayList) FormIndex(org.javarosa.core.model.FormIndex) GroupDef(org.javarosa.core.model.GroupDef)

Example 3 with FormEntryPrompt

use of org.javarosa.form.api.FormEntryPrompt in project javarosa by opendatakit.

the class QuestionDefTest method testReferences.

@Test
public void testReferences() {
    QuestionDef q = fpi.getFirstQuestionDef();
    FormEntryPrompt fep = fpi.getFormEntryModel().getQuestionPrompt();
    Localizer l = fpi.getFormDef().getLocalizer();
    l.setDefaultLocale(l.getAvailableLocales()[0]);
    l.setLocale(l.getAvailableLocales()[0]);
    String audioURI = fep.getAudioText();
    String ref;
    ReferenceManager.instance().addReferenceFactory(new ResourceReferenceFactory());
    ReferenceManager.instance().addRootTranslator(new RootTranslator("jr://audio/", "jr://resource/"));
    try {
        Reference r = ReferenceManager.instance().DeriveReference(audioURI);
        ref = r.getURI();
        if (!ref.equals("jr://resource/hah.mp3")) {
            fail("Root translation failed.");
        }
    } catch (InvalidReferenceException ire) {
        fail("There was an Invalid Reference Exception:" + ire.getMessage());
        ire.printStackTrace();
    }
    ReferenceManager.instance().addRootTranslator(new RootTranslator("jr://images/", "jr://resource/"));
    q = fpi.getNextQuestion();
    fep = fpi.getFormEntryModel().getQuestionPrompt();
    String imURI = fep.getImageText();
    try {
        Reference r = ReferenceManager.instance().DeriveReference(imURI);
        ref = r.getURI();
        if (!ref.equals("jr://resource/four.gif")) {
            fail("Root translation failed.");
        }
    } catch (InvalidReferenceException ire) {
        fail("There was an Invalid Reference Exception:" + ire.getMessage());
        ire.printStackTrace();
    }
}
Also used : ResourceReferenceFactory(org.javarosa.core.reference.ResourceReferenceFactory) FormEntryPrompt(org.javarosa.form.api.FormEntryPrompt) Reference(org.javarosa.core.reference.Reference) IDataReference(org.javarosa.core.model.IDataReference) QuestionDef(org.javarosa.core.model.QuestionDef) Localizer(org.javarosa.core.services.locale.Localizer) RootTranslator(org.javarosa.core.reference.RootTranslator) InvalidReferenceException(org.javarosa.core.reference.InvalidReferenceException) Test(org.junit.Test)

Example 4 with FormEntryPrompt

use of org.javarosa.form.api.FormEntryPrompt in project collect by opendatakit.

the class GuidanceHintFormTest method guidanceHint_ShouldBeDisplayedAfterClickWhenSettingSetToYesCollapsed.

@Test
public void guidanceHint_ShouldBeDisplayedAfterClickWhenSettingSetToYesCollapsed() {
    TestSettingsProvider.getUnprotectedSettings().save(ProjectKeys.KEY_GUIDANCE_HINT, GuidanceHint.YES_COLLAPSED.toString());
    // jump to force recreation of the view after the settings change
    onView(withId(R.id.menu_goto)).perform(click());
    onView(withId(R.id.jumpBeginningButton)).perform(click());
    FormEntryPrompt prompt = Collect.getInstance().getFormController().getQuestionPrompt();
    String guidance = prompt.getSpecialFormQuestionText(prompt.getQuestion().getHelpTextID(), "guidance");
    assertFalse(TextUtils.isEmpty(guidance));
    onView(withId(R.id.guidance_text_view)).check(matches(not(isDisplayed())));
    onView(withId(R.id.help_icon)).perform(click());
    onView(withId(R.id.guidance_text_view)).check(matches(withText(guidance)));
}
Also used : FormEntryPrompt(org.javarosa.form.api.FormEntryPrompt) Test(org.junit.Test)

Example 5 with FormEntryPrompt

use of org.javarosa.form.api.FormEntryPrompt in project collect by opendatakit.

the class GuidanceHintFormTest method guidanceHint_ShouldBeDisplayedWhenSettingSetToYes.

@Test
public void guidanceHint_ShouldBeDisplayedWhenSettingSetToYes() {
    TestSettingsProvider.getUnprotectedSettings().save(ProjectKeys.KEY_GUIDANCE_HINT, GuidanceHint.YES.toString());
    // jump to force recreation of the view after the settings change
    onView(withId(R.id.menu_goto)).perform(click());
    onView(withId(R.id.jumpBeginningButton)).perform(click());
    FormEntryPrompt prompt = Collect.getInstance().getFormController().getQuestionPrompt();
    String guidance = prompt.getSpecialFormQuestionText(prompt.getQuestion().getHelpTextID(), "guidance");
    assertFalse(TextUtils.isEmpty(guidance));
    Screengrab.screenshot("guidance_hint");
    onView(withId(R.id.guidance_text_view)).check(matches(withText(guidance)));
}
Also used : FormEntryPrompt(org.javarosa.form.api.FormEntryPrompt) Test(org.junit.Test)

Aggregations

FormEntryPrompt (org.javarosa.form.api.FormEntryPrompt)114 Test (org.junit.Test)92 MockFormEntryPromptBuilder (org.odk.collect.android.support.MockFormEntryPromptBuilder)45 Clip (org.odk.collect.audioclips.Clip)13 FormIndex (org.javarosa.core.model.FormIndex)10 File (java.io.File)9 SelectChoice (org.javarosa.core.model.SelectChoice)7 StringData (org.javarosa.core.model.data.StringData)7 IFormElement (org.javarosa.core.model.IFormElement)5 QuestionDef (org.javarosa.core.model.QuestionDef)5 FormController (org.odk.collect.android.javarosawrapper.FormController)5 GroupDef (org.javarosa.core.model.GroupDef)4 QuestionDetails (org.odk.collect.android.formentry.questions.QuestionDetails)4 DatePickerDetails (org.odk.collect.android.logic.DatePickerDetails)4 ArrayList (java.util.ArrayList)3 DateData (org.javarosa.core.model.data.DateData)3 IAnswerData (org.javarosa.core.model.data.IAnswerData)3 TreeReference (org.javarosa.core.model.instance.TreeReference)3 LocalDateTime (org.joda.time.LocalDateTime)3 AudioControllerView (org.odk.collect.android.audio.AudioControllerView)3