Search in sources :

Example 41 with FormIndex

use of org.javarosa.core.model.FormIndex in project collect by opendatakit.

the class FormController method stepOverGroup.

/**
 * If using a view like HierarchyView that doesn't support multi-question per screen, step over
 * the group represented by the FormIndex.
 */
private int stepOverGroup() {
    GroupDef gd = (GroupDef) formEntryController.getModel().getForm().getChild(getFormIndex());
    List<FormIndex> indices = getIndicesForGroup(gd);
    // jump to the end of the group
    formEntryController.jumpToIndex(indices.get(indices.size() - 1));
    return stepToNextEvent(STEP_OVER_GROUP);
}
Also used : FormIndex(org.javarosa.core.model.FormIndex) GroupDef(org.javarosa.core.model.GroupDef)

Example 42 with FormIndex

use of org.javarosa.core.model.FormIndex in project collect by opendatakit.

the class QuestionWidget method clearNextLevelsOfCascadingSelect.

/**
 * It's needed only for external choices. Everything works well and
 * out of the box when we use internal choices instead
 */
protected void clearNextLevelsOfCascadingSelect() {
    FormController formController = Collect.getInstance().getFormController();
    if (formController == null) {
        return;
    }
    if (formController.currentCaptionPromptIsQuestion()) {
        try {
            FormIndex startFormIndex = formController.getQuestionPrompt().getIndex();
            formController.stepToNextScreenEvent();
            while (formController.currentCaptionPromptIsQuestion() && formController.getQuestionPrompt().getFormElement().getAdditionalAttribute(null, "query") != null) {
                formController.saveAnswer(formController.getQuestionPrompt().getIndex(), null);
                formController.stepToNextScreenEvent();
            }
            formController.jumpToIndex(startFormIndex);
        } catch (JavaRosaException e) {
            Timber.d(e);
        }
    }
}
Also used : FormController(org.odk.collect.android.logic.FormController) FormIndex(org.javarosa.core.model.FormIndex) JavaRosaException(org.odk.collect.android.exception.JavaRosaException)

Example 43 with FormIndex

use of org.javarosa.core.model.FormIndex in project javarosa by opendatakit.

the class FormEntryModel method getCaptionHierarchy.

/**
 * Returns a hierarchical list of FormEntryCaption objects for the given
 * FormIndex
 *
 * @param index
 * @return list of FormEntryCaptions in hierarchical order
 */
public FormEntryCaption[] getCaptionHierarchy(FormIndex index) {
    List<FormEntryCaption> captions = new ArrayList<FormEntryCaption>();
    FormIndex remaining = index;
    while (remaining != null) {
        remaining = remaining.getNextLevel();
        FormIndex localIndex = index.diff(remaining);
        IFormElement element = form.getChild(localIndex);
        if (element != null) {
            FormEntryCaption caption = null;
            if (element instanceof GroupDef)
                caption = new FormEntryCaption(getForm(), localIndex);
            else if (element instanceof QuestionDef)
                caption = new FormEntryPrompt(getForm(), localIndex);
            if (caption != null) {
                captions.add(caption);
            }
        }
    }
    FormEntryCaption[] captionArray = new FormEntryCaption[captions.size()];
    return captions.toArray(captionArray);
}
Also used : IFormElement(org.javarosa.core.model.IFormElement) ArrayList(java.util.ArrayList) FormIndex(org.javarosa.core.model.FormIndex) QuestionDef(org.javarosa.core.model.QuestionDef) GroupDef(org.javarosa.core.model.GroupDef)

Example 44 with FormIndex

use of org.javarosa.core.model.FormIndex in project javarosa by opendatakit.

the class RecalculateTest method testComputedConstraintText.

@Test
public void testComputedConstraintText() {
    FormIndex nowNoteField = new FormIndex(0, 0, formDef.getMainInstance().getRoot().getChild("now_note", 0).getRef());
    String actualQuestionText = new FormEntryPrompt(formDef, nowNoteField).getQuestionText();
    assertEquals("2018-01-01T10:20:30.400", actualQuestionText);
}
Also used : FormEntryPrompt(org.javarosa.form.api.FormEntryPrompt) FormIndex(org.javarosa.core.model.FormIndex) Test(org.junit.Test)

Example 45 with FormIndex

use of org.javarosa.core.model.FormIndex in project javarosa by opendatakit.

the class FormIndexSerializationTest method testBeginningOfForm.

@Test
public void testBeginningOfForm() throws IOException, ClassNotFoundException {
    FormIndex formIndexToSerialize = FormIndex.createBeginningOfFormIndex();
    byte[] serializedObject = serializeObject(formIndexToSerialize);
    FormIndex formIndexDeserialized = deserializeFormIndex(serializedObject);
    assertFormIndex(formIndexToSerialize, formIndexDeserialized);
}
Also used : FormIndex(org.javarosa.core.model.FormIndex) Test(org.junit.Test)

Aggregations

FormIndex (org.javarosa.core.model.FormIndex)63 GroupDef (org.javarosa.core.model.GroupDef)11 JavaRosaException (org.odk.collect.android.exception.JavaRosaException)11 FormController (org.odk.collect.android.javarosawrapper.FormController)11 ArrayList (java.util.ArrayList)10 FormEntryPrompt (org.javarosa.form.api.FormEntryPrompt)10 Test (org.junit.Test)10 IFormElement (org.javarosa.core.model.IFormElement)6 TreeReference (org.javarosa.core.model.instance.TreeReference)6 FormEntryCaption (org.javarosa.form.api.FormEntryCaption)6 File (java.io.File)5 FormController (org.odk.collect.android.logic.FormController)5 HierarchyElement (org.odk.collect.android.logic.HierarchyElement)5 IAnswerData (org.javarosa.core.model.data.IAnswerData)4 HierarchyListAdapter (org.odk.collect.android.adapters.HierarchyListAdapter)4 FormDef (org.javarosa.core.model.FormDef)3 FormEntryModel (org.javarosa.form.api.FormEntryModel)3 Intent (android.content.Intent)2 ObjectInputStream (java.io.ObjectInputStream)2 HashMap (java.util.HashMap)2