Search in sources :

Example 6 with FormEntryCaption

use of org.javarosa.form.api.FormEntryCaption 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();
}
Also used : FormEntryCaption(org.javarosa.form.api.FormEntryCaption) FormIndex(org.javarosa.core.model.FormIndex)

Example 7 with FormEntryCaption

use of org.javarosa.form.api.FormEntryCaption in project javarosa by opendatakit.

the class FormParseInit method printStuff.

/*
     * Makes an 'extremely basic' print out of the xform model.
     */
public String printStuff() {
    String stuff = "";
    // go to the beginning of the form
    fec.jumpToIndex(FormIndex.createBeginningOfFormIndex());
    do {
        FormEntryCaption fep = femodel.getCaptionPrompt();
        boolean choiceFlag = false;
        if (fep.getFormElement() instanceof QuestionDef) {
            stuff += "\t[Type:QuestionDef, ";
            List<SelectChoice> s = ((QuestionDef) fep.getFormElement()).getChoices();
            stuff += "ContainsChoices: " + ((s != null && s.size() > 0) ? "true " : "false") + ", ";
            if (s != null && s.size() > 0)
                choiceFlag = true;
        } else if (fep.getFormElement() instanceof FormDef) {
            stuff += "\t[Type:FormDef, ";
        } else if (fep.getFormElement() instanceof GroupDef) {
            stuff += "\t[Type:GroupDef, ";
        } else {
            stuff += "\t[Type:Unknown]\n";
            continue;
        }
        stuff += "ID:" + fep.getFormElement().getID() + ", TextID:" + fep.getFormElement().getTextID() + ",InnerText:" + fep.getFormElement().getLabelInnerText();
        if (choiceFlag) {
            stuff += "] \n\t\t---Choices:" + ((QuestionDef) fep.getFormElement()).getChoices().toString() + "\n";
        } else {
            stuff += "]\n";
        }
    } while (fec.stepToNextEvent() != fec.EVENT_END_OF_FORM);
    return stuff;
}
Also used : SelectChoice(org.javarosa.core.model.SelectChoice) FormDef(org.javarosa.core.model.FormDef) FormEntryCaption(org.javarosa.form.api.FormEntryCaption) QuestionDef(org.javarosa.core.model.QuestionDef) GroupDef(org.javarosa.core.model.GroupDef)

Aggregations

FormEntryCaption (org.javarosa.form.api.FormEntryCaption)7 FormIndex (org.javarosa.core.model.FormIndex)4 GroupDef (org.javarosa.core.model.GroupDef)3 FormController (org.odk.collect.android.logic.FormController)3 FormEntryPrompt (org.javarosa.form.api.FormEntryPrompt)2 JavaRosaException (org.odk.collect.android.exception.JavaRosaException)2 SuppressLint (android.annotation.SuppressLint)1 Cursor (android.database.Cursor)1 Uri (android.net.Uri)1 NonNull (android.support.annotation.NonNull)1 Editable (android.text.Editable)1 InputFilter (android.text.InputFilter)1 Spanned (android.text.Spanned)1 TextWatcher (android.text.TextWatcher)1 View (android.view.View)1 OnClickListener (android.view.View.OnClickListener)1 AdapterView (android.widget.AdapterView)1 CheckBox (android.widget.CheckBox)1 EditText (android.widget.EditText)1 ListView (android.widget.ListView)1