use of org.javarosa.core.model.FormIndex in project collect by opendatakit.
the class FormController method stepToPreviousEvent.
/**
* Navigates backward in the form.
*
* @return the event that should be handled by a view.
*/
public int stepToPreviousEvent() {
/*
* Right now this will always skip to the beginning of a group if that group is represented
* as a 'field-list'. Should a need ever arise to step backwards by only one step in a
* 'field-list', this method will have to be updated.
*/
formEntryController.stepToPreviousEvent();
if (indexIsInFieldList() && getEvent() == FormEntryController.EVENT_QUESTION) {
// caption[0..len-1]
// caption[len-1] == the question itself
// caption[len-2] == the first group it is contained in.
FormEntryCaption[] captions = getCaptionHierarchy();
FormEntryCaption grp = captions[captions.length - 2];
int event = formEntryController.jumpToIndex(grp.getIndex());
// and test if this group or at least one of its children is relevant...
FormIndex idx = grp.getIndex();
if (!formEntryController.getModel().isIndexRelevant(idx)) {
return stepToPreviousEvent();
}
idx = formEntryController.getModel().incrementIndex(idx, true);
while (FormIndex.isSubElement(grp.getIndex(), idx)) {
if (formEntryController.getModel().isIndexRelevant(idx)) {
return event;
}
idx = formEntryController.getModel().incrementIndex(idx, true);
}
return stepToPreviousEvent();
} else if (indexIsInFieldList() && getEvent() == FormEntryController.EVENT_GROUP) {
FormIndex grpidx = formEntryController.getModel().getFormIndex();
int event = formEntryController.getModel().getEvent();
// and test if this group or at least one of its children is relevant...
if (!formEntryController.getModel().isIndexRelevant(grpidx)) {
// shouldn't happen?
return stepToPreviousEvent();
}
FormIndex idx = formEntryController.getModel().incrementIndex(grpidx, true);
while (FormIndex.isSubElement(grpidx, idx)) {
if (formEntryController.getModel().isIndexRelevant(idx)) {
return event;
}
idx = formEntryController.getModel().incrementIndex(idx, true);
}
return stepToPreviousEvent();
}
return getEvent();
}
use of org.javarosa.core.model.FormIndex in project collect by opendatakit.
the class FormController method isCurrentQuestionFirstInForm.
public boolean isCurrentQuestionFirstInForm() {
boolean isFirstQuestion = true;
FormIndex originalFormIndex = getFormIndex();
try {
isFirstQuestion = stepToPreviousScreenEvent() == FormEntryController.EVENT_BEGINNING_OF_FORM && stepToNextScreenEvent() != FormEntryController.EVENT_PROMPT_NEW_REPEAT;
} catch (JavaRosaException e) {
Timber.d(e);
}
jumpToIndex(originalFormIndex);
return isFirstQuestion;
}
use of org.javarosa.core.model.FormIndex in project collect by opendatakit.
the class FormController method isGroupRelevant.
/**
* @return true if a group contains at least one relevant question, otherwise false
*/
public boolean isGroupRelevant() {
GroupDef groupDef = (GroupDef) getCaptionPrompt().getFormElement();
FormIndex currentChildIndex = formEntryController.getModel().incrementIndex(getFormIndex(), true);
for (FormIndex index : getIndicesForGroup(groupDef, currentChildIndex, true)) {
if (formEntryController.getModel().isIndexRelevant(index)) {
return true;
}
}
return false;
}
use of org.javarosa.core.model.FormIndex in project collect by opendatakit.
the class FormIndexSavepointTest method saveAndReadFormIndexTest.
@Test
public void saveAndReadFormIndexTest() {
String instanceName = "test.xml";
// for loadFormIndexFromFile
File instancePath = new File(new StoragePathProvider().getOdkDirPath(StorageSubdirectory.INSTANCES) + File.separator + instanceName);
when(formController.getInstanceFile()).thenReturn(instancePath);
Collect.getInstance().setFormController(formController);
FormIndex originalFormIndex = FormIndex.createBeginningOfFormIndex();
File indexFile = SaveFormToDisk.getFormIndexFile(instanceName);
SaveFormIndexTask.exportFormIndexToFile(originalFormIndex, indexFile);
FormIndex readFormIndex = SaveFormIndexTask.loadFormIndexFromFile();
assertEquals(originalFormIndex, readFormIndex);
assertNotNull(readFormIndex);
assertEquals(originalFormIndex.getReference(), readFormIndex.getReference());
}
use of org.javarosa.core.model.FormIndex in project collect by opendatakit.
the class RecordingHandler method handleForegroundRecording.
private void handleForegroundRecording(FormController formController, RecordingSession session, Result<File> result) throws JavaRosaException {
FormIndex formIndex = (FormIndex) session.getId();
questionMediaManager.replaceAnswerFile(formIndex.toString(), result.getOrNull().getAbsolutePath());
formController.answerQuestion(formIndex, new StringData(result.getOrNull().getName()));
session.getFile().delete();
}
Aggregations