use of org.javarosa.core.model.FormIndex in project collect by opendatakit.
the class QuestionWidget method isWaitingForData.
@Override
public final boolean isWaitingForData() {
Collect collect = Collect.getInstance();
if (collect == null) {
throw new IllegalStateException("Collect application instance is null.");
}
FormController formController = collect.getFormController();
if (formController == null) {
return false;
}
FormIndex index = getFormEntryPrompt().getIndex();
return index.equals(formController.getIndexWaitingForData());
}
use of org.javarosa.core.model.FormIndex in project collect by opendatakit.
the class ODKView method getAnswers.
/**
* @return a HashMap of answers entered by the user for this set of widgets
*/
public HashMap<FormIndex, IAnswerData> getAnswers() {
HashMap<FormIndex, IAnswerData> answers = new LinkedHashMap<>();
for (QuestionWidget q : widgets) {
/*
* The FormEntryPrompt has the FormIndex, which is where the answer gets stored. The
* QuestionWidget has the answer the user has entered.
*/
FormEntryPrompt p = q.getFormEntryPrompt();
answers.put(p.getIndex(), q.getAnswer());
}
return answers;
}
use of org.javarosa.core.model.FormIndex in project collect by opendatakit.
the class FormController method getQuestionPrompts.
/**
* Returns an array of question promps.
*/
public FormEntryPrompt[] getQuestionPrompts() throws RuntimeException {
// For questions, there is only one.
// For groups, there could be many, but we set that below
FormEntryPrompt[] questions = new FormEntryPrompt[1];
IFormElement element = formEntryController.getModel().getForm().getChild(getFormIndex());
if (element instanceof GroupDef) {
GroupDef gd = (GroupDef) element;
// we only display relevant questions
List<FormEntryPrompt> questionList = new ArrayList<>();
for (FormIndex index : getIndicesForGroup(gd)) {
if (getEvent(index) != FormEntryController.EVENT_QUESTION) {
String errorMsg = "Only questions and regular groups are allowed in 'field-list'. Bad node is: " + index.getReference().toString(false);
RuntimeException e = new RuntimeException(errorMsg);
Timber.w(errorMsg);
throw e;
}
// we only display relevant questions
if (formEntryController.getModel().isIndexRelevant(index)) {
questionList.add(getQuestionPrompt(index));
}
questions = new FormEntryPrompt[questionList.size()];
questionList.toArray(questions);
}
} else {
// We have a question, so just get the one prompt
questions[0] = getQuestionPrompt();
}
return questions;
}
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 enclosing repeat
* or to the start of the form.
*/
public int stepToOuterScreenEvent() {
FormIndex index = stepIndexOut(getFormIndex());
int currentEvent = getEvent();
// Step out of any group indexes that are present.
while (index != null && getEvent(index) == FormEntryController.EVENT_GROUP) {
index = stepIndexOut(index);
}
if (index == null) {
jumpToIndex(FormIndex.createBeginningOfFormIndex());
} else {
if (currentEvent == FormEntryController.EVENT_REPEAT) {
// We were at a repeat, so stepping back brought us to then previous level
jumpToIndex(index);
} else {
// We were at a question, so stepping back brought us to either:
// The beginning. or The start of a repeat. So we need to step
// out again to go passed the repeat.
index = stepIndexOut(index);
if (index == null) {
jumpToIndex(FormIndex.createBeginningOfFormIndex());
} else {
jumpToIndex(index);
}
}
}
return getEvent();
}
use of org.javarosa.core.model.FormIndex in project collect by opendatakit.
the class FormController method isCurrentQuestionFirstInForm.
public boolean isCurrentQuestionFirstInForm() {
boolean isFirstQuestion = true;
FormIndex originalFormIndex = getFormIndex();
try {
isFirstQuestion = stepToPreviousScreenEvent() == FormEntryController.EVENT_BEGINNING_OF_FORM && stepToNextScreenEvent() != FormEntryController.EVENT_PROMPT_NEW_REPEAT;
} catch (JavaRosaException e) {
Timber.d(e);
}
jumpToIndex(originalFormIndex);
return isFirstQuestion;
}
Aggregations