use of org.odk.collect.android.javarosawrapper.FormController in project collect by opendatakit.
the class FormEntryActivity method onCreateContextMenu.
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
if (!swipeHandler.beenSwiped()) {
super.onCreateContextMenu(menu, v, menuInfo);
FormController formController = getFormController();
menu.add(0, v.getId(), 0, getString(R.string.clear_answer));
if (formController.indexContainsRepeatableGroup()) {
menu.add(0, DELETE_REPEAT, 0, getString(R.string.delete_repeat));
}
menu.setHeaderTitle(getString(R.string.edit_prompt));
}
}
use of org.odk.collect.android.javarosawrapper.FormController in project collect by opendatakit.
the class FormEntryActivity method onActivityResult.
@Override
protected void onActivityResult(int requestCode, int resultCode, final Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
FormController formController = getFormController();
if (formController == null) {
// try to save this callback data to the FormLoaderTask
if (formLoaderTask != null && formLoaderTask.getStatus() != AsyncTask.Status.FINISHED) {
formLoaderTask.setActivityResult(requestCode, resultCode, intent);
} else {
Timber.e("Got an activityResult without any pending form loader");
}
return;
}
// button or another question to jump to so we need to rebuild the view.
if (requestCode == RequestCodes.HIERARCHY_ACTIVITY || requestCode == RequestCodes.CHANGE_SETTINGS) {
onScreenRefresh();
return;
}
if (resultCode == RESULT_CANCELED) {
waitingForDataRegistry.cancelWaitingForData();
return;
}
// intent is needed for all requestCodes except of DRAW_IMAGE, ANNOTATE_IMAGE, SIGNATURE_CAPTURE, IMAGE_CAPTURE and HIERARCHY_ACTIVITY
if (intent == null && requestCode != RequestCodes.DRAW_IMAGE && requestCode != RequestCodes.ANNOTATE_IMAGE && requestCode != RequestCodes.SIGNATURE_CAPTURE && requestCode != RequestCodes.IMAGE_CAPTURE) {
Timber.d("The intent has a null value for requestCode: %s", requestCode);
showLongToast(this, getString(R.string.null_intent_value));
return;
}
switch(requestCode) {
case RequestCodes.OSM_CAPTURE:
AnalyticsUtils.logFormEvent(OPEN_MAP_KIT_RESPONSE);
setWidgetData(intent.getStringExtra("OSM_FILE_NAME"));
break;
case RequestCodes.EX_ARBITRARY_FILE_CHOOSER:
case RequestCodes.EX_VIDEO_CHOOSER:
case RequestCodes.EX_IMAGE_CHOOSER:
case RequestCodes.EX_AUDIO_CHOOSER:
if (intent.getClipData() != null && intent.getClipData().getItemCount() > 0 && intent.getClipData().getItemAt(0) != null) {
loadFile(intent.getClipData().getItemAt(0).getUri());
} else {
setWidgetData(null);
}
break;
case RequestCodes.EX_GROUP_CAPTURE:
try {
Bundle extras = intent.getExtras();
if (getCurrentViewIfODKView() != null) {
getCurrentViewIfODKView().setDataForFields(extras);
}
} catch (JavaRosaException e) {
Timber.e(e);
createErrorDialog(e.getCause().getMessage(), false);
}
break;
case RequestCodes.DRAW_IMAGE:
case RequestCodes.ANNOTATE_IMAGE:
case RequestCodes.SIGNATURE_CAPTURE:
case RequestCodes.IMAGE_CAPTURE:
loadFile(Uri.fromFile(new File(storagePathProvider.getTmpImageFilePath())));
break;
case RequestCodes.ALIGNED_IMAGE:
case RequestCodes.ARBITRARY_FILE_CHOOSER:
case RequestCodes.AUDIO_CAPTURE:
case RequestCodes.AUDIO_CHOOSER:
case RequestCodes.VIDEO_CAPTURE:
case RequestCodes.VIDEO_CHOOSER:
case RequestCodes.IMAGE_CHOOSER:
loadFile(intent.getData());
break;
case RequestCodes.LOCATION_CAPTURE:
case RequestCodes.GEOSHAPE_CAPTURE:
case RequestCodes.GEOTRACE_CAPTURE:
case RequestCodes.BEARING_CAPTURE:
case RequestCodes.BARCODE_CAPTURE:
case RequestCodes.EX_STRING_CAPTURE:
case RequestCodes.EX_INT_CAPTURE:
case RequestCodes.EX_DECIMAL_CAPTURE:
setWidgetData(ExternalAppUtils.getReturnedSingleValue(intent));
break;
}
}
use of org.odk.collect.android.javarosawrapper.FormController in project collect by opendatakit.
the class FormEntryActivity method onStart.
@Override
protected void onStart() {
super.onStart();
FormController formController = getFormController();
// Register to receive location provider change updates and write them to the audit log
if (formController != null && formController.currentFormAuditsLocation() && new PlayServicesChecker().isGooglePlayServicesAvailable(this)) {
registerReceiver(locationProvidersReceiver, new IntentFilter(LocationManager.PROVIDERS_CHANGED_ACTION));
}
// User may have changed location permissions in Android settings
if (permissionsProvider.areLocationPermissionsGranted() != locationPermissionsPreviouslyGranted) {
backgroundLocationViewModel.locationPermissionChanged();
locationPermissionsPreviouslyGranted = !locationPermissionsPreviouslyGranted;
}
}
use of org.odk.collect.android.javarosawrapper.FormController 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.FormController in project collect by opendatakit.
the class FormEntryActivity method moveScreen.
private boolean moveScreen(Direction direction) {
if (currentView != null) {
currentView.cancelPendingInputEvents();
}
closeContextMenu();
FormController formController = getFormController();
if (formController == null) {
Timber.d("FormController has a null value");
return false;
}
if (audioRecorder.isRecording() && !backgroundAudioViewModel.isBackgroundRecording()) {
// We want the user to stop recording before changing screens
DialogFragmentUtils.showIfNotShowing(RecordingWarningDialogFragment.class, getSupportFragmentManager());
return false;
}
if (direction == FORWARDS) {
if (formController.getEvent() == FormEntryController.EVENT_END_OF_FORM) {
return false;
}
if (!saveBeforeNextView(formController)) {
formEntryViewModel.moveForward();
formIndexAnimationHandler.handle(formController.getFormIndex());
return true;
} else {
return false;
}
} else {
if (formController.isCurrentQuestionFirstInForm() || !allowMovingBackwards) {
return false;
}
// The answer is saved on a back swipe, but question constraints are ignored.
if (formController.currentPromptIsQuestion()) {
saveAnswersForCurrentScreen(DO_NOT_EVALUATE_CONSTRAINTS);
}
formEntryViewModel.moveBackward();
formIndexAnimationHandler.handle(formController.getFormIndex());
return true;
}
}
Aggregations