Search in sources :

Example 1 with FormIndex

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

the class QuestionWidget method isWaitingForData.

@Override
public final boolean isWaitingForData() {
    Collect collect = Collect.getInstance();
    if (collect == null) {
        throw new IllegalStateException("Collect application instance is null.");
    }
    FormController formController = collect.getFormController();
    if (formController == null) {
        return false;
    }
    FormIndex index = getFormEntryPrompt().getIndex();
    return index.equals(formController.getIndexWaitingForData());
}
Also used : FormController(org.odk.collect.android.logic.FormController) Collect(org.odk.collect.android.application.Collect) FormIndex(org.javarosa.core.model.FormIndex)

Example 2 with FormIndex

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;
}
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 3 with FormIndex

use of org.javarosa.core.model.FormIndex 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 4 with FormIndex

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

the class FormController method stepToOuterScreenEvent.

/**
 * Move the current form index to the index of the first enclosing repeat
 * or to the start of the form.
 */
public int stepToOuterScreenEvent() {
    FormIndex index = stepIndexOut(getFormIndex());
    int currentEvent = getEvent();
    // Step out of any group indexes that are present.
    while (index != null && getEvent(index) == FormEntryController.EVENT_GROUP) {
        index = stepIndexOut(index);
    }
    if (index == null) {
        jumpToIndex(FormIndex.createBeginningOfFormIndex());
    } else {
        if (currentEvent == FormEntryController.EVENT_REPEAT) {
            // We were at a repeat, so stepping back brought us to then previous level
            jumpToIndex(index);
        } else {
            // We were at a question, so stepping back brought us to either:
            // The beginning. or The start of a repeat. So we need to step
            // out again to go passed the repeat.
            index = stepIndexOut(index);
            if (index == null) {
                jumpToIndex(FormIndex.createBeginningOfFormIndex());
            } else {
                jumpToIndex(index);
            }
        }
    }
    return getEvent();
}
Also used : FormIndex(org.javarosa.core.model.FormIndex)

Example 5 with FormIndex

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;
}
Also used : FormIndex(org.javarosa.core.model.FormIndex) JavaRosaException(org.odk.collect.android.exception.JavaRosaException)

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