Search in sources :

Example 51 with FormIndex

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

the class FormEntryActivity method onSaveInstanceState.

@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putString(KEY_FORMPATH, formPath);
    FormController formController = getFormController();
    if (formController != null) {
        if (formController.getInstanceFile() != null) {
            outState.putString(KEY_INSTANCEPATH, getAbsoluteInstancePath());
        }
        outState.putString(KEY_XPATH, formController.getXPath(formController.getFormIndex()));
        FormIndex waiting = formController.getIndexWaitingForData();
        if (waiting != null) {
            outState.putString(KEY_XPATH_WAITING_FOR_DATA, formController.getXPath(waiting));
        }
        // save the instance to a temp path...
        nonblockingCreateSavePointData();
    }
    outState.putBoolean(NEWFORM, false);
    outState.putString(KEY_ERROR, errorMessage);
    outState.putString(KEY_SAVE_NAME, saveName);
    outState.putBoolean(KEY_AUTO_SAVED, autoSaved);
    outState.putBoolean(KEY_READ_PHONE_STATE_PERMISSION_REQUEST_NEEDED, readPhoneStatePermissionRequestNeeded);
    outState.putBoolean(KEY_LOCATION_PERMISSIONS_GRANTED, locationPermissionsPreviouslyGranted);
}
Also used : FormController(org.odk.collect.android.javarosawrapper.FormController) FormIndex(org.javarosa.core.model.FormIndex)

Example 52 with FormIndex

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

the class FormHierarchyActivity method jumpToHierarchyStartIndex.

/**
 * Goes to the start of the hierarchy view based on where the user came from.
 * Backs out until the index is at the beginning of a repeat group or the beginning of the form.
 */
private void jumpToHierarchyStartIndex() {
    FormController formController = Collect.getInstance().getFormController();
    FormIndex startIndex = formController.getFormIndex();
    // If we're not at the first level, we're inside a repeated group so we want to only
    // display everything enclosed within that group.
    contextGroupRef = null;
    // Save the index to the screen itself, before potentially moving into it.
    screenIndex = startIndex;
    // node to display.
    if (formController.isDisplayableGroup(startIndex)) {
        contextGroupRef = formController.getFormIndex().getReference();
        formController.stepToNextEvent(FormController.STEP_INTO_GROUP);
    } else {
        FormIndex potentialStartIndex = getPreviousLevel(startIndex);
        // Step back until we hit a displayable group or the beginning.
        while (!isScreenEvent(formController, potentialStartIndex)) {
            potentialStartIndex = getPreviousLevel(potentialStartIndex);
        }
        screenIndex = potentialStartIndex;
        // Otherwise we're at a displayable group.
        if (screenIndex == null) {
            screenIndex = FormIndex.createBeginningOfFormIndex();
        }
        formController.jumpToIndex(screenIndex);
        // Now test again. This should be true at this point or we're at the beginning.
        if (formController.isDisplayableGroup(formController.getFormIndex())) {
            contextGroupRef = formController.getFormIndex().getReference();
            formController.stepToNextEvent(FormController.STEP_INTO_GROUP);
        } else {
        // Let contextGroupRef be null.
        }
    }
}
Also used : FormController(org.odk.collect.android.javarosawrapper.FormController) FormIndex(org.javarosa.core.model.FormIndex)

Example 53 with FormIndex

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

the class FormHierarchyActivity method onElementClick.

/**
 * Handles clicks on a specific row in the hierarchy view.
 */
public void onElementClick(HierarchyElement element) {
    FormIndex index = element.getFormIndex();
    switch(element.getType()) {
        case QUESTION:
            onQuestionClicked(index);
            break;
        case REPEATABLE_GROUP:
            // Show the picker.
            repeatGroupPickerIndex = index;
            refreshView();
            break;
        case VISIBLE_GROUP:
        case REPEAT_INSTANCE:
            // Hide the picker.
            repeatGroupPickerIndex = null;
            Collect.getInstance().getFormController().jumpToIndex(index);
            setResult(RESULT_OK);
            refreshView();
            break;
    }
}
Also used : FormIndex(org.javarosa.core.model.FormIndex)

Example 54 with FormIndex

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

the class FormController method deleteRepeat.

/**
 * If the current FormIndex is within a repeated group, will find the innermost repeat, delete
 * it, and jump the FormEntryController to the previous valid index. That is, if you have
 * group1
 * (2) > group2 (3) and you call deleteRepeat, it will delete the 3rd instance of group2.
 */
public void deleteRepeat() {
    FormIndex fi = formEntryController.deleteRepeat();
    formEntryController.jumpToIndex(fi);
}
Also used : FormIndex(org.javarosa.core.model.FormIndex)

Example 55 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 displayable group
 * (that is, a repeatable group or a visible group),
 * or to the start of the form.
 */
public int stepToOuterScreenEvent() {
    FormIndex index = getFormIndex();
    // Step out once to begin with if we're coming from a question.
    if (getEvent() == FormEntryController.EVENT_QUESTION) {
        index = getPreviousLevel(index);
    }
    // Save where we started from.
    FormIndex startIndex = index;
    // Step out once more no matter what.
    index = getPreviousLevel(index);
    // Step out of any group indexes that are present, unless they're visible.
    while (index != null && getEvent(index) == FormEntryController.EVENT_GROUP && !isDisplayableGroup(index)) {
        index = getPreviousLevel(index);
    }
    if (index == null) {
        jumpToIndex(FormIndex.createBeginningOfFormIndex());
    } else {
        if (isDisplayableGroup(startIndex)) {
            // We were at a displayable group, so stepping back brought us to the previous level
            jumpToIndex(index);
        } else {
            // We were at a question, so stepping back brought us to either:
            // The beginning, or the start of a displayable group. So we need to step
            // out again to go past the group.
            index = getPreviousLevel(index);
            if (index == null) {
                jumpToIndex(FormIndex.createBeginningOfFormIndex());
            } else {
                jumpToIndex(index);
            }
        }
    }
    return getEvent();
}
Also used : FormIndex(org.javarosa.core.model.FormIndex)

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