Search in sources :

Example 26 with FormController

use of org.odk.collect.android.javarosawrapper.FormController in project collect by opendatakit.

the class SelectOneWidget method clearFollowingItemsetWidgets.

/**
 * If there are "fast external itemset" selects right after this select, assume that they are linked to the current question and clear them.
 */
private void clearFollowingItemsetWidgets() {
    FormController formController = Collect.getInstance().getFormController();
    if (formController == null) {
        return;
    }
    if (formController.currentCaptionPromptIsQuestion()) {
        try {
            FormIndex startFormIndex = formController.getQuestionPrompt().getIndex();
            formController.stepToNextScreenEvent();
            while (formController.currentCaptionPromptIsQuestion() && formController.getQuestionPrompt().getFormElement().getAdditionalAttribute(null, "query") != null) {
                formController.saveAnswer(formController.getQuestionPrompt().getIndex(), null);
                formController.stepToNextScreenEvent();
            }
            formController.jumpToIndex(startFormIndex);
        } catch (JavaRosaException e) {
            Timber.d(e);
        }
    }
}
Also used : FormController(org.odk.collect.android.javarosawrapper.FormController) FormIndex(org.javarosa.core.model.FormIndex) JavaRosaException(org.odk.collect.android.exception.JavaRosaException)

Example 27 with FormController

use of org.odk.collect.android.javarosawrapper.FormController in project collect by opendatakit.

the class FormSaveViewModelTest method setup.

@Before
public void setup() {
    // Useful given some methods will execute AsyncTasks
    Robolectric.getBackgroundThreadScheduler().pause();
    formController = mock(FormController.class);
    logger = mock(AuditEventLogger.class);
    mediaUtils = mock(MediaUtils.class);
    Analytics analytics = mock(Analytics.class);
    when(formController.getAuditEventLogger()).thenReturn(logger);
    when(logger.isChangeReasonRequired()).thenReturn(false);
    audioRecorder = mock(AudioRecorder.class);
    currentProjectProvider = mock(CurrentProjectProvider.class);
    when(currentProjectProvider.getCurrentProject()).thenReturn(Project.Companion.getDEMO_PROJECT());
    viewModel = new FormSaveViewModel(savedStateHandle, () -> CURRENT_TIME, formSaver, mediaUtils, analytics, scheduler, audioRecorder, currentProjectProvider);
    viewModel.formLoaded(formController);
}
Also used : FormController(org.odk.collect.android.javarosawrapper.FormController) CurrentProjectProvider(org.odk.collect.android.projects.CurrentProjectProvider) FormSaveViewModel(org.odk.collect.android.formentry.saving.FormSaveViewModel) MediaUtils(org.odk.collect.android.utilities.MediaUtils) AudioRecorder(org.odk.collect.audiorecorder.recording.AudioRecorder) Analytics(org.odk.collect.analytics.Analytics) Before(org.junit.Before)

Example 28 with FormController

use of org.odk.collect.android.javarosawrapper.FormController in project collect by opendatakit.

the class BackgroundAudioViewModelTest method setBackgroundRecordingEnabled_whenTrue_logsEventToAuditLog.

@Test
public void setBackgroundRecordingEnabled_whenTrue_logsEventToAuditLog() {
    FormController formController = mock(FormController.class);
    AuditEventLogger auditEventLogger = mock(AuditEventLogger.class);
    when(formController.getAuditEventLogger()).thenReturn(auditEventLogger);
    viewModel.formLoaded(formController);
    when(clock.get()).thenReturn(1234L);
    viewModel.setBackgroundRecordingEnabled(true);
    verify(auditEventLogger).logEvent(AuditEvent.AuditEventType.BACKGROUND_AUDIO_ENABLED, true, 1234L);
}
Also used : FormController(org.odk.collect.android.javarosawrapper.FormController) AuditEventLogger(org.odk.collect.android.formentry.audit.AuditEventLogger) Test(org.junit.Test)

Example 29 with FormController

use of org.odk.collect.android.javarosawrapper.FormController in project collect by opendatakit.

the class FormEntryViewModelTest method setup.

@Before
public void setup() {
    formController = mock(FormController.class);
    startingIndex = new FormIndex(null, 0, 0, new TreeReference());
    when(formController.getFormIndex()).thenReturn(startingIndex);
    when(formController.getFormDef()).thenReturn(new FormDef());
    AuditEventLogger auditEventLogger = mock(AuditEventLogger.class);
    when(formController.getAuditEventLogger()).thenReturn(auditEventLogger);
    viewModel = new FormEntryViewModel(mock(Supplier.class));
    viewModel.formLoaded(formController);
}
Also used : FormController(org.odk.collect.android.javarosawrapper.FormController) AuditEventLogger(org.odk.collect.android.formentry.audit.AuditEventLogger) TreeReference(org.javarosa.core.model.instance.TreeReference) FormDef(org.javarosa.core.model.FormDef) FormIndex(org.javarosa.core.model.FormIndex) Before(org.junit.Before)

Example 30 with FormController

use of org.odk.collect.android.javarosawrapper.FormController in project collect by opendatakit.

the class OSMWidgetTest method setUp.

@Before
public void setUp() {
    widgetActivity = widgetTestActivity();
    shadowActivity = shadowOf(widgetActivity);
    intentLauncher = IntentLauncherImpl.INSTANCE;
    formController = mock(FormController.class);
    FormDef formDef = mock(FormDef.class);
    questionDef = mock(QuestionDef.class);
    when(formController.getInstanceFile()).thenReturn(instancePath);
    when(formController.getMediaFolder()).thenReturn(mediaFolder);
    when(formController.getSubmissionMetadata()).thenReturn(new FormController.InstanceMetadata("instanceId", "instanceTesTName", null));
    when(formController.getFormDef()).thenReturn(formDef);
    when(formDef.getID()).thenReturn(0);
}
Also used : FormController(org.odk.collect.android.javarosawrapper.FormController) FormDef(org.javarosa.core.model.FormDef) QuestionDef(org.javarosa.core.model.QuestionDef) Before(org.junit.Before)

Aggregations

FormController (org.odk.collect.android.javarosawrapper.FormController)53 FormIndex (org.javarosa.core.model.FormIndex)11 File (java.io.File)9 JavaRosaException (org.odk.collect.android.exception.JavaRosaException)9 FormDef (org.javarosa.core.model.FormDef)4 FormEntryPrompt (org.javarosa.form.api.FormEntryPrompt)4 Collect (org.odk.collect.android.application.Collect)4 RepeatsInFieldListException (org.odk.collect.android.javarosawrapper.RepeatsInFieldListException)4 LocalizedApplicationKt.getLocalizedString (org.odk.collect.strings.localization.LocalizedApplicationKt.getLocalizedString)4 TextView (android.widget.TextView)3 ArrayList (java.util.ArrayList)3 FormInstance (org.javarosa.core.model.instance.FormInstance)3 TreeReference (org.javarosa.core.model.instance.TreeReference)3 FormEntryCaption (org.javarosa.form.api.FormEntryCaption)3 Before (org.junit.Before)3 Test (org.junit.Test)3 Form (org.odk.collect.forms.Form)3 Intent (android.content.Intent)2 View (android.view.View)2 WebView (android.webkit.WebView)2