use of org.odk.collect.android.javarosawrapper.RepeatsInFieldListException 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.RepeatsInFieldListException in project collect by opendatakit.
the class AuditUtils method logCurrentScreen.
public static void logCurrentScreen(FormController formController, AuditEventLogger auditEventLogger, long currentTime) {
if (formController.getEvent() == EVENT_QUESTION || formController.getEvent() == EVENT_GROUP || formController.getEvent() == EVENT_REPEAT) {
try {
FormEntryPrompt[] prompts = formController.getQuestionPrompts();
for (FormEntryPrompt question : prompts) {
String answer = question.getAnswerValue() != null ? question.getAnswerValue().getDisplayText() : null;
auditEventLogger.logEvent(AuditEvent.AuditEventType.QUESTION, question.getIndex(), true, answer, currentTime, null);
}
} catch (RepeatsInFieldListException e) {
throw new RuntimeException(e.getMessage(), e);
}
}
}
use of org.odk.collect.android.javarosawrapper.RepeatsInFieldListException in project collect by opendatakit.
the class FormEntryActivity method widgetValueChanged.
@Override
public void widgetValueChanged(QuestionWidget changedWidget) {
FormController formController = getFormController();
if (formController == null) {
// TODO: As usual, no idea if/how this is possible.
return;
}
if (formController.indexIsInFieldList()) {
// Some widgets may call widgetValueChanged from a non-main thread but odkView can only be modified from the main thread
runOnUiThread(new Runnable() {
@Override
public void run() {
try {
updateFieldListQuestions(changedWidget.getFormEntryPrompt().getIndex());
odkView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
@Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
if (!odkView.isDisplayed(changedWidget)) {
odkView.scrollTo(changedWidget);
}
odkView.removeOnLayoutChangeListener(this);
}
});
} catch (RepeatsInFieldListException e) {
createErrorDialog(e.getMessage(), false);
} catch (Exception | Error e) {
Timber.e(e);
createErrorDialog(getString(R.string.update_widgets_error), true);
}
}
});
}
}
use of org.odk.collect.android.javarosawrapper.RepeatsInFieldListException in project collect by opendatakit.
the class FormEntryActivity method showView.
/**
* Displays the View specified by the parameter 'next', animating both the
* current view and next appropriately given the AnimationType. Also updates
* the progress bar.
*/
public void showView(View next, AnimationType from) {
invalidateOptionsMenu();
// disable notifications...
if (inAnimation != null) {
inAnimation.setAnimationListener(null);
}
if (outAnimation != null) {
outAnimation.setAnimationListener(null);
}
// by createView()
switch(from) {
case RIGHT:
inAnimation = loadAnimation(this, R.anim.push_left_in);
outAnimation = loadAnimation(this, R.anim.push_left_out);
// if animation is left or right then it was a swipe, and we want to re-save on
// entry
autoSaved = false;
break;
case LEFT:
inAnimation = loadAnimation(this, R.anim.push_right_in);
outAnimation = loadAnimation(this, R.anim.push_right_out);
autoSaved = false;
break;
case FADE:
inAnimation = loadAnimation(this, R.anim.fade_in);
outAnimation = loadAnimation(this, R.anim.fade_out);
break;
}
// complete setup for animations...
inAnimation.setAnimationListener(this);
outAnimation.setAnimationListener(this);
if (!areAnimationsEnabled(this)) {
inAnimation.setDuration(0);
outAnimation.setDuration(0);
}
// drop keyboard before transition...
if (currentView != null) {
softKeyboardController.hideSoftKeyboard(currentView);
}
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
// adjust which view is in the layout container...
View staleView = currentView;
currentView = next;
swipeHandler.setOdkView(getCurrentViewIfODKView());
questionHolder.addView(currentView, lp);
animationCompletionSet = 0;
if (staleView != null) {
// start OutAnimation for transition...
staleView.startAnimation(outAnimation);
// and remove the old view (MUST occur after start of animation!!!)
questionHolder.removeView(staleView);
} else {
animationCompletionSet = 2;
}
// start InAnimation for transition...
currentView.startAnimation(inAnimation);
FormController formController = getFormController();
if (formController.getEvent() == FormEntryController.EVENT_QUESTION || formController.getEvent() == FormEntryController.EVENT_GROUP || formController.getEvent() == FormEntryController.EVENT_REPEAT) {
try {
FormEntryPrompt[] prompts = getFormController().getQuestionPrompts();
for (FormEntryPrompt p : prompts) {
List<TreeElement> attrs = p.getBindAttributes();
for (int i = 0; i < attrs.size(); i++) {
if (!autoSaved && "saveIncomplete".equals(attrs.get(i).getName())) {
analytics.logEvent(SAVE_INCOMPLETE, "saveIncomplete", AnalyticsUtils.getFormHash(Collect.getInstance().getFormController()));
saveForm(false, false, null, false);
autoSaved = true;
}
}
}
} catch (RepeatsInFieldListException e) {
createErrorDialog(e.getMessage(), false);
}
}
}
Aggregations