use of org.odk.collect.android.javarosawrapper.FormController in project collect by opendatakit.
the class FormEntryActivity method createView.
/**
* Creates and returns a new view based on the event type passed in. The view returned is
* of type {@link View} if the event passed in represents the end of the form or of type
* {@link ODKView} otherwise.
*
* @param advancingPage -- true if this results from advancing through the form
* @return newly created View
*/
private View createView(int event, boolean advancingPage) {
releaseOdkView();
FormController formController = getFormController();
String formTitle = formController.getFormTitle();
setTitle(formTitle);
if (event != FormEntryController.EVENT_QUESTION) {
formController.getAuditEventLogger().logEvent(AuditEvent.getAuditEventTypeFromFecType(event), formController.getFormIndex(), true, null, System.currentTimeMillis(), null);
}
switch(event) {
case FormEntryController.EVENT_BEGINNING_OF_FORM:
return createViewForFormBeginning(formController);
case FormEntryController.EVENT_END_OF_FORM:
return createViewForFormEnd(formController);
case FormEntryController.EVENT_QUESTION:
case FormEntryController.EVENT_GROUP:
case FormEntryController.EVENT_REPEAT:
// should only be a group here if the event_group is a field-list
try {
AuditUtils.logCurrentScreen(formController, formController.getAuditEventLogger(), System.currentTimeMillis());
FormEntryCaption[] groups = formController.getGroupsForCurrentIndex();
FormEntryPrompt[] prompts = formController.getQuestionPrompts();
odkView = createODKView(advancingPage, prompts, groups);
odkView.setWidgetValueChangedListener(this);
Timber.i("Created view for group %s %s", groups.length > 0 ? groups[groups.length - 1].getLongText() : "[top]", prompts.length > 0 ? prompts[0].getQuestionText() : "[no question]");
} catch (RuntimeException | RepeatsInFieldListException e) {
if (e instanceof RuntimeException) {
Timber.e(e);
}
// this is badness to avoid a crash.
try {
event = formController.stepToNextScreenEvent();
createErrorDialog(e.getMessage(), false);
} catch (JavaRosaException e1) {
Timber.d(e1);
createErrorDialog(e.getMessage() + "\n\n" + e1.getCause().getMessage(), false);
}
return createView(event, advancingPage);
}
if (showNavigationButtons) {
updateNavigationButtonVisibility();
}
return odkView;
case EVENT_PROMPT_NEW_REPEAT:
createRepeatDialog();
return new EmptyView(this);
default:
Timber.e("Attempted to create a view that does not exist.");
// this is badness to avoid a crash.
try {
event = formController.stepToNextScreenEvent();
createErrorDialog(getString(R.string.survey_internal_error), true);
} catch (JavaRosaException e) {
Timber.d(e);
createErrorDialog(e.getCause().getMessage(), true);
}
return createView(event, advancingPage);
}
}
use of org.odk.collect.android.javarosawrapper.FormController in project collect by opendatakit.
the class FormEntryActivity method onPause.
@Override
protected void onPause() {
backgroundLocationViewModel.activityHidden();
FormController formController = getFormController();
// is getting constantly updated
if (!formSaveViewModel.isSaving()) {
if (currentView != null && formController != null && formController.currentPromptIsQuestion()) {
saveAnswersForCurrentScreen(DO_NOT_EVALUATE_CONSTRAINTS);
}
}
super.onPause();
}
use of org.odk.collect.android.javarosawrapper.FormController in project collect by opendatakit.
the class FormHierarchyActivity method isGroupSizeLocked.
/**
* Returns true if the current index is a group that's designated as `noAddRemove`
* (e.g. if `jr:count` is explicitly set).
*/
private boolean isGroupSizeLocked(FormIndex index) {
FormController formController = Collect.getInstance().getFormController();
IFormElement element = formController.getCaptionPrompt(index).getFormElement();
return element instanceof GroupDef && ((GroupDef) element).noAddRemove;
}
use of org.odk.collect.android.javarosawrapper.FormController in project collect by opendatakit.
the class FormHierarchyActivity method updateOptionsMenu.
private void updateOptionsMenu() {
FormController formController = Collect.getInstance().getFormController();
// Not ready yet. Menu will be updated automatically once it's been prepared.
if (optionsMenu == null || formController == null) {
return;
}
boolean isAtBeginning = screenIndex.isBeginningOfFormIndex() && !shouldShowRepeatGroupPicker();
boolean shouldShowPicker = shouldShowRepeatGroupPicker();
boolean isInRepeat = formController.indexContainsRepeatableGroup();
boolean isGroupSizeLocked = shouldShowPicker ? isGroupSizeLocked(repeatGroupPickerIndex) : isGroupSizeLocked(screenIndex);
boolean shouldShowDelete = isInRepeat && !shouldShowPicker && !isGroupSizeLocked;
showDeleteButton(shouldShowDelete);
boolean shouldShowAdd = shouldShowPicker && !isGroupSizeLocked;
showAddButton(shouldShowAdd);
boolean shouldShowGoUp = !isAtBeginning;
showGoUpButton(shouldShowGoUp);
}
use of org.odk.collect.android.javarosawrapper.FormController in project collect by opendatakit.
the class FormHierarchyActivity method createErrorDialog.
/**
* Creates and displays dialog with the given errorMsg.
*/
protected void createErrorDialog(String errorMsg) {
AlertDialog alertDialog = new MaterialAlertDialogBuilder(this).create();
alertDialog.setTitle(getString(R.string.error_occured));
alertDialog.setMessage(errorMsg);
DialogInterface.OnClickListener errorListener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int i) {
switch(i) {
case DialogInterface.BUTTON_POSITIVE:
FormController formController = Collect.getInstance().getFormController();
formController.jumpToIndex(currentIndex);
break;
}
}
};
alertDialog.setCancelable(false);
alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, getString(R.string.ok), errorListener);
alertDialog.show();
}
Aggregations