use of org.javarosa.core.model.FormIndex in project collect by opendatakit.
the class ViewFormHierarchyActivity 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);
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 javarosa by opendatakit.
the class FormIndexSerializationTest method deserializeFormIndex.
private static FormIndex deserializeFormIndex(byte[] serializedFormIndex) throws IOException, ClassNotFoundException {
ByteArrayInputStream bais = new ByteArrayInputStream(serializedFormIndex);
ObjectInputStream ois = new ObjectInputStream(bais);
Object o = ois.readObject();
return (FormIndex) o;
}
use of org.javarosa.core.model.FormIndex in project javarosa by opendatakit.
the class FormIndexSerializationTest method testEndOfForm.
@Test
public void testEndOfForm() throws IOException, ClassNotFoundException {
FormIndex formIndexToSerialize = FormIndex.createEndOfFormIndex();
byte[] serializedObject = serializeObject(formIndexToSerialize);
FormIndex formIndexDeserialized = deserializeFormIndex(serializedObject);
assertFormIndex(formIndexToSerialize, formIndexDeserialized);
}
use of org.javarosa.core.model.FormIndex in project javarosa by opendatakit.
the class FormIndexSerializationTest method testLocalAndInstanceNullReference.
@Test
public void testLocalAndInstanceNullReference() throws IOException, ClassNotFoundException {
FormIndex formIndexToSerialize = new FormIndex(1, 2, null);
byte[] serializedObject = serializeObject(formIndexToSerialize);
FormIndex formIndexDeserialized = deserializeFormIndex(serializedObject);
assertFormIndex(formIndexToSerialize, formIndexDeserialized);
}
use of org.javarosa.core.model.FormIndex in project javarosa by opendatakit.
the class FormEntryModel method isIndexRelevant.
/**
* Determine if the current FormIndex is relevant. Only relevant indexes
* should be returned when filling out a form.
*
* @param index
* @return true if current element at FormIndex is relevant
*/
public boolean isIndexRelevant(FormIndex index) {
TreeReference ref = form.getChildInstanceRef(index);
boolean isAskNewRepeat = (getEvent(index) == FormEntryController.EVENT_PROMPT_NEW_REPEAT);
boolean isRepeatJuncture = (getEvent(index) == FormEntryController.EVENT_REPEAT_JUNCTURE);
boolean relevant;
if (isAskNewRepeat) {
relevant = form.isRepeatRelevant(ref) && form.canCreateRepeat(ref, index);
// repeat junctures are still relevant if no new repeat can be created; that option
// is simply missing from the menu
} else if (isRepeatJuncture) {
relevant = form.isRepeatRelevant(ref);
} else {
TreeElement node = form.getMainInstance().resolveReference(ref);
// check instance flag first
relevant = node != null && node.isRelevant();
}
if (relevant) {
// if instance flag/condition says relevant, we still
// have to check the <group>/<repeat> hierarchy
FormIndex ancestorIndex = index;
while (!ancestorIndex.isTerminal()) {
// This should be safe now that the TreeReference is contained
// in the ancestor index itself
TreeElement ancestorNode = form.getMainInstance().resolveReference(ancestorIndex.getLocalReference());
if (!ancestorNode.isRelevant()) {
relevant = false;
break;
}
ancestorIndex = ancestorIndex.getNextLevel();
}
}
return relevant;
}
Aggregations