Search in sources :

Example 21 with FormController

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

the class FormEntryActivity method saveAnswersForCurrentScreen.

// The method saves questions one by one in order to support calculations in field-list groups
private void saveAnswersForCurrentScreen(FormEntryPrompt[] mutableQuestionsBeforeSave, List<ImmutableDisplayableQuestion> immutableQuestionsBeforeSave) {
    FormController formController = getFormController();
    ODKView currentView = getCurrentViewIfODKView();
    if (formController == null || currentView == null) {
        return;
    }
    int index = 0;
    for (Map.Entry<FormIndex, IAnswerData> answer : currentView.getAnswers().entrySet()) {
        // Questions with calculates will have their answers updated as the questions they depend on are saved
        if (!isQuestionRecalculated(mutableQuestionsBeforeSave[index], immutableQuestionsBeforeSave.get(index))) {
            try {
                formController.saveOneScreenAnswer(answer.getKey(), answer.getValue(), false);
            } catch (JavaRosaException e) {
                Timber.e(e);
            }
        }
        index++;
    }
}
Also used : FormController(org.odk.collect.android.javarosawrapper.FormController) IAnswerData(org.javarosa.core.model.data.IAnswerData) ODKView(org.odk.collect.android.formentry.ODKView) FormIndex(org.javarosa.core.model.FormIndex) Map(java.util.Map) HashMap(java.util.HashMap) FailedConstraint(org.odk.collect.android.javarosawrapper.FormController.FailedConstraint) JavaRosaException(org.odk.collect.android.exception.JavaRosaException)

Example 22 with FormController

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

the class RankingListAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(@NonNull final ItemViewHolder holder, int position) {
    FormController formController = Collect.getInstance().getFormController();
    String itemName = String.valueOf(HtmlUtils.textToHtml(formController.getQuestionPrompt(formIndex).getSelectChoiceText(items.get(position))));
    holder.textView.setText(itemName);
}
Also used : FormController(org.odk.collect.android.javarosawrapper.FormController)

Example 23 with FormController

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

the class IdentityPromptViewModelTest method done_setsUserOnAuditEventLogger.

@Test
public void done_setsUserOnAuditEventLogger() {
    FormController formController = mock(FormController.class);
    AuditEventLogger auditEventLogger = mock(AuditEventLogger.class);
    when(formController.getAuditEventLogger()).thenReturn(auditEventLogger);
    IdentityPromptViewModel viewModel = new IdentityPromptViewModel();
    viewModel.formLoaded(formController);
    viewModel.setIdentity("Picard");
    viewModel.done();
    verify(auditEventLogger).setUser("Picard");
}
Also used : FormController(org.odk.collect.android.javarosawrapper.FormController) Test(org.junit.Test)

Example 24 with FormController

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

the class BackgroundAudioViewModelTest method setBackgroundRecordingEnabled_whenFalse_logsEventToAuditLog.

@Test
public void setBackgroundRecordingEnabled_whenFalse_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(false);
    verify(auditEventLogger).logEvent(AuditEvent.AuditEventType.BACKGROUND_AUDIO_DISABLED, true, 1234L);
}
Also used : FormController(org.odk.collect.android.javarosawrapper.FormController) AuditEventLogger(org.odk.collect.android.formentry.audit.AuditEventLogger) Test(org.junit.Test)

Example 25 with FormController

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

the class QuestionWidget method getInstanceFolder.

// region Accessors
/**
 * @deprecated widgets shouldn't need to know about the instance folder. They can use
 * {@link org.odk.collect.android.utilities.QuestionMediaManager} to access media attached
 * to the instance.
 */
@Nullable
@Deprecated
public final String getInstanceFolder() {
    Collect collect = Collect.getInstance();
    if (collect == null) {
        throw new IllegalStateException("Collect application instance is null.");
    }
    FormController formController = collect.getFormController();
    if (formController == null) {
        return null;
    }
    return formController.getInstanceFile().getParent();
}
Also used : FormController(org.odk.collect.android.javarosawrapper.FormController) Collect(org.odk.collect.android.application.Collect) Nullable(androidx.annotation.Nullable)

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