use of org.javarosa.core.model.FormIndex in project collect by opendatakit.
the class FormEntryActivity method saveAnswersForCurrentScreen.
// The method saves questions one by one in order to support calculations in field-list groups
private void saveAnswersForCurrentScreen(FormEntryPrompt[] mutableQuestionsBeforeSave, List<ImmutableDisplayableQuestion> immutableQuestionsBeforeSave) {
FormController formController = getFormController();
ODKView currentView = getCurrentViewIfODKView();
if (formController == null || currentView == null) {
return;
}
int index = 0;
for (Map.Entry<FormIndex, IAnswerData> answer : currentView.getAnswers().entrySet()) {
// Questions with calculates will have their answers updated as the questions they depend on are saved
if (!isQuestionRecalculated(mutableQuestionsBeforeSave[index], immutableQuestionsBeforeSave.get(index))) {
try {
formController.saveOneScreenAnswer(answer.getKey(), answer.getValue(), false);
} catch (JavaRosaException e) {
Timber.e(e);
}
}
index++;
}
}
use of org.javarosa.core.model.FormIndex 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.core.model.FormIndex in project collect by opendatakit.
the class AuditEventCSVLine method toCSVLine.
public static String toCSVLine(AuditEvent auditEvent, boolean isTrackingLocationsEnabled, boolean isTrackingChangesEnabled, boolean isTrackingChangesReasonEnabled) {
FormIndex formIndex = auditEvent.getFormIndex();
AuditEvent.AuditEventType auditEventType = auditEvent.getAuditEventType();
long start = auditEvent.getStart();
long end = auditEvent.getEnd();
String latitude = auditEvent.getLatitude();
String longitude = auditEvent.getLongitude();
String accuracy = auditEvent.getAccuracy();
String oldValue = auditEvent.getOldValue();
String newValue = auditEvent.getNewValue();
String user = auditEvent.getUser();
String changeReason = auditEvent.getChangeReason();
String node = formIndex == null || formIndex.getReference() == null ? "" : getXPathPath(formIndex);
String string = String.format("%s,%s,%s,%s", auditEventType.getValue(), node, start, end != 0 ? end : "");
if (isTrackingLocationsEnabled) {
string += String.format(",%s,%s,%s", latitude, longitude, accuracy);
}
if (isTrackingChangesEnabled) {
string += String.format(",%s,%s", getEscapedValueForCsv(oldValue), getEscapedValueForCsv(newValue));
}
if (user != null) {
string += String.format(",%s", getEscapedValueForCsv(user));
}
if (isTrackingChangesReasonEnabled) {
if (changeReason != null) {
string += String.format(",%s", getEscapedValueForCsv(changeReason));
} else {
string += ",";
}
}
return string;
}
use of org.javarosa.core.model.FormIndex in project collect by opendatakit.
the class FormController method getQuestionPrompts.
/**
* Returns an array of question prompts corresponding to the current {@link FormIndex}. These
* are the prompts that should be displayed to the user and don't include any non-relevant
* questions.
* <p>
* The array has a single element if there is a question at this {@link FormIndex} or multiple
* elements if there is a group.
*
* @throws RepeatsInFieldListException if there is a group at this {@link FormIndex} and it contains
* elements that are not questions or regular (non-repeat) groups.
*/
public FormEntryPrompt[] getQuestionPrompts() throws RepeatsInFieldListException {
// For questions, there is only one.
// For groups, there could be many, but we set that below
FormEntryPrompt[] questions = new FormEntryPrompt[0];
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) {
throw new RepeatsInFieldListException("Repeats in 'field-list' groups " + "are not supported. Please update the form design to remove the " + "following repeat from a field list: " + index.getReference().toString(false));
}
// 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 = new FormEntryPrompt[1];
questions[0] = getQuestionPrompt();
}
return questions;
}
use of org.javarosa.core.model.FormIndex in project collect by opendatakit.
the class FormController method jumpToNewRepeatPrompt.
/**
* Jumps to the next prompt for a repeated instance of the group referenced by the current FormIndex.
*/
public void jumpToNewRepeatPrompt() {
FormIndex repeatGroupIndex = getRepeatGroupIndex(getFormIndex(), getFormDef());
Integer depth = repeatGroupIndex.getDepth();
Integer promptDepth = null;
while (!depth.equals(promptDepth)) {
stepToNextEventType(FormEntryController.EVENT_PROMPT_NEW_REPEAT);
promptDepth = getFormIndex().getDepth();
}
}
Aggregations