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;
}
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;
}
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();
}
}
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)));
}
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)));
}
Aggregations