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;
}
}
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);
}
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());
}
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);
}
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);
}
Aggregations