Search in sources :

Example 6 with FormIndex

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

the class FormController method getIndexFromXPath.

public FormIndex getIndexFromXPath(String xpath) {
    switch(xpath) {
        case "beginningOfForm":
            return FormIndex.createBeginningOfFormIndex();
        case "endOfForm":
            return FormIndex.createEndOfFormIndex();
        case "unexpected":
            Timber.e("Unexpected string from XPath");
            throw new IllegalArgumentException("unexpected string from XPath");
        default:
            FormIndex returned = null;
            FormIndex saved = getFormIndex();
            // until the XPath of a form entry matches that of the supplied XPath
            try {
                jumpToIndex(FormIndex.createBeginningOfFormIndex());
                int event = stepToNextEvent(true);
                while (event != FormEntryController.EVENT_END_OF_FORM) {
                    String candidateXPath = getXPath(getFormIndex());
                    // Log.i(t, "xpath: " + candidateXPath);
                    if (candidateXPath.equals(xpath)) {
                        returned = getFormIndex();
                        break;
                    }
                    event = stepToNextEvent(true);
                }
            } finally {
                jumpToIndex(saved);
            }
            return returned;
    }
}
Also used : FormIndex(org.javarosa.core.model.FormIndex)

Example 7 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 8 with FormIndex

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(Collect.INSTANCES_PATH + File.separator + instanceName);
    when(formController.getInstanceFile()).thenReturn(instancePath);
    Collect.getInstance().setFormController(formController);
    FormIndex originalFormIndex = FormIndex.createBeginningOfFormIndex();
    File indexFile = SaveToDiskTask.getFormIndexFile(instanceName);
    SaveFormIndexTask.exportFormIndexToFile(originalFormIndex, indexFile);
    FormIndex readFormIndex = SaveFormIndexTask.loadFormIndexFromFile();
    assertEquals(originalFormIndex, readFormIndex);
    assertNotNull(readFormIndex);
    assertEquals(originalFormIndex.getReference(), readFormIndex.getReference());
}
Also used : FormIndex(org.javarosa.core.model.FormIndex) File(java.io.File) Test(org.junit.Test)

Example 9 with FormIndex

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

the class EditFormHierarchyActivity method onItemClick.

@Override
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
    HierarchyElement h = (HierarchyElement) listView.getItemAtPosition(position);
    FormIndex index = h.getFormIndex();
    if (index == null) {
        goUpLevel();
        return;
    }
    switch(h.getType()) {
        case EXPANDED:
            Collect.getInstance().getActivityLogger().logInstanceAction(this, "onListItemClick", "COLLAPSED", h.getFormIndex());
            h.setType(COLLAPSED);
            ArrayList<HierarchyElement> children = h.getChildren();
            for (int i = 0; i < children.size(); i++) {
                formList.remove(position + 1);
            }
            h.setIcon(ContextCompat.getDrawable(getApplicationContext(), R.drawable.expander_ic_minimized));
            break;
        case COLLAPSED:
            Collect.getInstance().getActivityLogger().logInstanceAction(this, "onListItemClick", "EXPANDED", h.getFormIndex());
            h.setType(EXPANDED);
            ArrayList<HierarchyElement> children1 = h.getChildren();
            for (int i = 0; i < children1.size(); i++) {
                Timber.i("adding child: %s", children1.get(i).getFormIndex());
                formList.add(position + 1 + i, children1.get(i));
            }
            h.setIcon(ContextCompat.getDrawable(getApplicationContext(), R.drawable.expander_ic_maximized));
            break;
        case QUESTION:
            Collect.getInstance().getActivityLogger().logInstanceAction(this, "onListItemClick", "QUESTION-JUMP", index);
            Collect.getInstance().getFormController().jumpToIndex(index);
            if (Collect.getInstance().getFormController().indexIsInFieldList()) {
                try {
                    Collect.getInstance().getFormController().stepToPreviousScreenEvent();
                } catch (JavaRosaException e) {
                    Timber.d(e);
                    createErrorDialog(e.getCause().getMessage());
                    return;
                }
            }
            setResult(RESULT_OK);
            finish();
            return;
        case CHILD:
            Collect.getInstance().getActivityLogger().logInstanceAction(this, "onListItemClick", "REPEAT-JUMP", h.getFormIndex());
            Collect.getInstance().getFormController().jumpToIndex(h.getFormIndex());
            setResult(RESULT_OK);
            refreshView();
            return;
    }
    // Should only get here if we've expanded or collapsed a group
    HierarchyListAdapter itla = new HierarchyListAdapter(this);
    itla.setListItems(formList);
    listView.setAdapter(itla);
    listView.setSelection(position);
}
Also used : HierarchyElement(org.odk.collect.android.logic.HierarchyElement) HierarchyListAdapter(org.odk.collect.android.adapters.HierarchyListAdapter) FormIndex(org.javarosa.core.model.FormIndex) JavaRosaException(org.odk.collect.android.exception.JavaRosaException)

Example 10 with FormIndex

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

the class ActivityLogger method logInstanceAction.

public void logInstanceAction(Object t, String context, String action) {
    FormIndex index = null;
    String instancePath = null;
    FormController formController = Collect.getInstance().getFormController();
    if (formController != null) {
        index = formController.getFormIndex();
        instancePath = getInstancePath(formController);
    }
    log(t.getClass().getName(), context, action, instancePath, index, null, null);
}
Also used : FormController(org.odk.collect.android.logic.FormController) 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