Search in sources :

Example 11 with QuestionDetails

use of org.odk.collect.android.formentry.questions.QuestionDetails in project collect by opendatakit.

the class DecimalWidgetTest method fifteenDigitValueShouldDisplayAllDigits.

@Test
public // https://docs.oracle.com/javase/7/docs/api/java/lang/Double.html#toString(double)
void fifteenDigitValueShouldDisplayAllDigits() {
    Double fifteenDigitDouble = 999999999999999.;
    String fifteenDigitString = "999999999999999";
    assertSame(15, fifteenDigitString.length());
    when(formEntryPrompt.getAnswerValue()).thenReturn(answerData);
    when(answerData.getValue()).thenReturn(fifteenDigitDouble);
    DecimalWidget decimalWidget = new DecimalWidget(activity, new QuestionDetails(formEntryPrompt));
    assertThat(decimalWidget.getAnswerText(), is(equalTo(fifteenDigitString)));
    decimalWidget = new DecimalWidget(activity, new QuestionDetails(formEntryPrompt));
    assertThat(decimalWidget.getAnswerText(), is(equalTo(fifteenDigitString)));
}
Also used : QuestionDetails(org.odk.collect.android.formentry.questions.QuestionDetails) Test(org.junit.Test) GeneralStringWidgetTest(org.odk.collect.android.widgets.base.GeneralStringWidgetTest)

Example 12 with QuestionDetails

use of org.odk.collect.android.formentry.questions.QuestionDetails in project collect by opendatakit.

the class QuestionWidgetTest method whenQuestionHasAudio_audioButtonUsesIndexAsClipID.

@Test
public void whenQuestionHasAudio_audioButtonUsesIndexAsClipID() throws Exception {
    FormEntryPrompt prompt = new MockFormEntryPromptBuilder().withIndex("i am index").withAudioURI("ref").build();
    WidgetTestActivity activity = CollectHelpers.createThemedActivity(WidgetTestActivity.class);
    TestWidget widget = new TestWidget(activity, new QuestionDetails(prompt));
    AudioButton audioButton = widget.getAudioVideoImageTextLabel().findViewById(R.id.audioButton);
    verify(audioHelper).setAudio(audioButton, new Clip("i am index", "blah.mp3"));
}
Also used : Clip(org.odk.collect.audioclips.Clip) FormEntryPrompt(org.javarosa.form.api.FormEntryPrompt) WidgetTestActivity(org.odk.collect.android.support.WidgetTestActivity) MockFormEntryPromptBuilder(org.odk.collect.android.support.MockFormEntryPromptBuilder) QuestionDetails(org.odk.collect.android.formentry.questions.QuestionDetails) AudioButton(org.odk.collect.android.audio.AudioButton) Test(org.junit.Test)

Example 13 with QuestionDetails

use of org.odk.collect.android.formentry.questions.QuestionDetails in project collect by opendatakit.

the class OSMWidgetTest method createWidget.

private OSMWidget createWidget(FormEntryPrompt prompt) {
    when(prompt.getQuestion()).thenReturn(questionDef);
    when(questionDef.getOsmTags()).thenReturn(ImmutableList.<OSMTag>of());
    return new OSMWidget(widgetActivity, new QuestionDetails(prompt), fakeWaitingForDataRegistry, intentLauncher, formController);
}
Also used : QuestionDetails(org.odk.collect.android.formentry.questions.QuestionDetails)

Example 14 with QuestionDetails

use of org.odk.collect.android.formentry.questions.QuestionDetails in project collect by opendatakit.

the class SelectMultiWidgetTest method createWidget.

@NonNull
@Override
public SelectMultiWidget createWidget() {
    SelectMultiWidget selectMultiWidget = new SelectMultiWidget(activity, new QuestionDetails(formEntryPrompt));
    selectMultiWidget.setFocus(activity);
    return selectMultiWidget;
}
Also used : QuestionDetails(org.odk.collect.android.formentry.questions.QuestionDetails) NonNull(androidx.annotation.NonNull)

Example 15 with QuestionDetails

use of org.odk.collect.android.formentry.questions.QuestionDetails in project collect by opendatakit.

the class WidgetFactory method createWidgetFromPrompt.

public QuestionWidget createWidgetFromPrompt(FormEntryPrompt prompt, PermissionsProvider permissionsProvider) {
    String appearance = Appearances.getSanitizedAppearanceHint(prompt);
    QuestionDetails questionDetails = new QuestionDetails(prompt, readOnlyOverride);
    final QuestionWidget questionWidget;
    switch(prompt.getControlType()) {
        case Constants.CONTROL_INPUT:
            switch(prompt.getDataType()) {
                case Constants.DATATYPE_DATE_TIME:
                    questionWidget = new DateTimeWidget(activity, questionDetails, new DateTimeWidgetUtils());
                    break;
                case Constants.DATATYPE_DATE:
                    questionWidget = new DateWidget(activity, questionDetails, new DateTimeWidgetUtils());
                    break;
                case Constants.DATATYPE_TIME:
                    questionWidget = new TimeWidget(activity, questionDetails, new DateTimeWidgetUtils());
                    break;
                case Constants.DATATYPE_DECIMAL:
                    if (appearance.startsWith(Appearances.EX)) {
                        questionWidget = new ExDecimalWidget(activity, questionDetails, waitingForDataRegistry, stringRequester);
                    } else if (appearance.equals(Appearances.BEARING)) {
                        questionWidget = new BearingWidget(activity, questionDetails, waitingForDataRegistry, (SensorManager) activity.getSystemService(Context.SENSOR_SERVICE));
                    } else {
                        questionWidget = new DecimalWidget(activity, questionDetails);
                    }
                    break;
                case Constants.DATATYPE_INTEGER:
                    if (appearance.startsWith(Appearances.EX)) {
                        questionWidget = new ExIntegerWidget(activity, questionDetails, waitingForDataRegistry, stringRequester);
                    } else {
                        questionWidget = new IntegerWidget(activity, questionDetails);
                    }
                    break;
                case Constants.DATATYPE_GEOPOINT:
                    if (hasAppearance(questionDetails.getPrompt(), PLACEMENT_MAP) || hasAppearance(questionDetails.getPrompt(), MAPS)) {
                        questionWidget = new GeoPointMapWidget(activity, questionDetails, waitingForDataRegistry, new ActivityGeoDataRequester(permissionsProvider, activity));
                    } else {
                        questionWidget = new GeoPointWidget(activity, questionDetails, waitingForDataRegistry, new ActivityGeoDataRequester(permissionsProvider, activity));
                    }
                    break;
                case Constants.DATATYPE_GEOSHAPE:
                    questionWidget = new GeoShapeWidget(activity, questionDetails, waitingForDataRegistry, new ActivityGeoDataRequester(permissionsProvider, activity));
                    break;
                case Constants.DATATYPE_GEOTRACE:
                    questionWidget = new GeoTraceWidget(activity, questionDetails, waitingForDataRegistry, MapProvider.getConfigurator(), new ActivityGeoDataRequester(permissionsProvider, activity));
                    break;
                case Constants.DATATYPE_BARCODE:
                    questionWidget = new BarcodeWidget(activity, questionDetails, waitingForDataRegistry, new CameraUtils());
                    break;
                case Constants.DATATYPE_TEXT:
                    String query = prompt.getQuestion().getAdditionalAttribute(null, "query");
                    if (query != null) {
                        questionWidget = getSelectOneWidget(appearance, questionDetails);
                    } else if (appearance.startsWith(Appearances.PRINTER)) {
                        questionWidget = new ExPrinterWidget(activity, questionDetails, waitingForDataRegistry);
                    } else if (appearance.startsWith(Appearances.EX)) {
                        questionWidget = new ExStringWidget(activity, questionDetails, waitingForDataRegistry, stringRequester);
                    } else if (appearance.contains(Appearances.NUMBERS)) {
                        questionWidget = new StringNumberWidget(activity, questionDetails);
                    } else if (appearance.equals(Appearances.URL)) {
                        questionWidget = new UrlWidget(activity, questionDetails, new ExternalWebPageHelper());
                    } else {
                        questionWidget = new StringWidget(activity, questionDetails);
                    }
                    break;
                default:
                    questionWidget = new StringWidget(activity, questionDetails);
                    break;
            }
            break;
        case Constants.CONTROL_FILE_CAPTURE:
            if (appearance.startsWith(Appearances.EX)) {
                questionWidget = new ExArbitraryFileWidget(activity, questionDetails, questionMediaManager, waitingForDataRegistry, fileRequester);
            } else {
                questionWidget = new ArbitraryFileWidget(activity, questionDetails, questionMediaManager, waitingForDataRegistry);
            }
            break;
        case Constants.CONTROL_IMAGE_CHOOSE:
            if (appearance.equals(Appearances.SIGNATURE)) {
                questionWidget = new SignatureWidget(activity, questionDetails, questionMediaManager, waitingForDataRegistry, new StoragePathProvider().getTmpImageFilePath());
            } else if (appearance.contains(Appearances.ANNOTATE)) {
                questionWidget = new AnnotateWidget(activity, questionDetails, questionMediaManager, waitingForDataRegistry, new StoragePathProvider().getTmpImageFilePath());
            } else if (appearance.equals(Appearances.DRAW)) {
                questionWidget = new DrawWidget(activity, questionDetails, questionMediaManager, waitingForDataRegistry, new StoragePathProvider().getTmpImageFilePath());
            } else if (appearance.startsWith(Appearances.EX)) {
                questionWidget = new ExImageWidget(activity, questionDetails, questionMediaManager, waitingForDataRegistry, fileRequester);
            } else {
                questionWidget = new ImageWidget(activity, questionDetails, questionMediaManager, waitingForDataRegistry, new StoragePathProvider().getTmpImageFilePath());
            }
            break;
        case Constants.CONTROL_OSM_CAPTURE:
            questionWidget = new OSMWidget(activity, questionDetails, waitingForDataRegistry, IntentLauncherImpl.INSTANCE, Collect.getInstance().getFormController());
            break;
        case Constants.CONTROL_AUDIO_CAPTURE:
            RecordingRequester recordingRequester = recordingRequesterProvider.create(prompt, useExternalRecorder);
            GetContentAudioFileRequester audioFileRequester = new GetContentAudioFileRequester(activity, IntentLauncherImpl.INSTANCE, waitingForDataRegistry, formEntryViewModel);
            if (appearance.startsWith(Appearances.EX)) {
                questionWidget = new ExAudioWidget(activity, questionDetails, questionMediaManager, audioPlayer, waitingForDataRegistry, fileRequester);
            } else {
                questionWidget = new AudioWidget(activity, questionDetails, questionMediaManager, audioPlayer, recordingRequester, audioFileRequester, new AudioRecorderRecordingStatusHandler(audioRecorder, formEntryViewModel, viewLifecycle));
            }
            break;
        case Constants.CONTROL_VIDEO_CAPTURE:
            if (appearance.startsWith(Appearances.EX)) {
                questionWidget = new ExVideoWidget(activity, questionDetails, questionMediaManager, waitingForDataRegistry, fileRequester);
            } else {
                questionWidget = new VideoWidget(activity, questionDetails, questionMediaManager, waitingForDataRegistry);
            }
            break;
        case Constants.CONTROL_SELECT_ONE:
            questionWidget = getSelectOneWidget(appearance, questionDetails);
            break;
        case Constants.CONTROL_SELECT_MULTI:
            // considered in each widget by calls to ExternalDataUtil.getSearchXPathExpression.
            if (appearance.contains(Appearances.MINIMAL)) {
                questionWidget = new SelectMultiMinimalWidget(activity, questionDetails, waitingForDataRegistry);
            } else if (appearance.contains(Appearances.LIST_NO_LABEL)) {
                questionWidget = new ListMultiWidget(activity, questionDetails, false);
            } else if (appearance.contains(Appearances.LIST)) {
                questionWidget = new ListMultiWidget(activity, questionDetails, true);
            } else if (appearance.contains(Appearances.LABEL)) {
                questionWidget = new LabelWidget(activity, questionDetails);
            } else if (appearance.contains(Appearances.IMAGE_MAP)) {
                questionWidget = new SelectMultiImageMapWidget(activity, questionDetails);
            } else {
                questionWidget = new SelectMultiWidget(activity, questionDetails);
            }
            break;
        case Constants.CONTROL_RANK:
            questionWidget = new RankingWidget(activity, questionDetails);
            break;
        case Constants.CONTROL_TRIGGER:
            questionWidget = new TriggerWidget(activity, questionDetails);
            break;
        case Constants.CONTROL_RANGE:
            if (appearance.startsWith(Appearances.RATING)) {
                questionWidget = new RatingWidget(activity, questionDetails);
            } else {
                switch(prompt.getDataType()) {
                    case Constants.DATATYPE_INTEGER:
                        if (prompt.getQuestion().getAppearanceAttr() != null && prompt.getQuestion().getAppearanceAttr().contains(PICKER_APPEARANCE)) {
                            questionWidget = new RangePickerIntegerWidget(activity, questionDetails);
                        } else {
                            questionWidget = new RangeIntegerWidget(activity, questionDetails);
                        }
                        break;
                    case Constants.DATATYPE_DECIMAL:
                        if (prompt.getQuestion().getAppearanceAttr() != null && prompt.getQuestion().getAppearanceAttr().contains(PICKER_APPEARANCE)) {
                            questionWidget = new RangePickerDecimalWidget(activity, questionDetails);
                        } else {
                            questionWidget = new RangeDecimalWidget(activity, questionDetails);
                        }
                        break;
                    default:
                        questionWidget = new StringWidget(activity, questionDetails);
                        break;
                }
            }
            break;
        default:
            questionWidget = new StringWidget(activity, questionDetails);
            break;
    }
    return questionWidget;
}
Also used : SelectMultiImageMapWidget(org.odk.collect.android.widgets.items.SelectMultiImageMapWidget) RecordingRequester(org.odk.collect.android.widgets.utilities.RecordingRequester) ExternalWebPageHelper(org.odk.collect.android.utilities.ExternalWebPageHelper) ActivityGeoDataRequester(org.odk.collect.android.widgets.utilities.ActivityGeoDataRequester) ListMultiWidget(org.odk.collect.android.widgets.items.ListMultiWidget) DateTimeWidgetUtils(org.odk.collect.android.widgets.utilities.DateTimeWidgetUtils) SelectMultiWidget(org.odk.collect.android.widgets.items.SelectMultiWidget) QuestionDetails(org.odk.collect.android.formentry.questions.QuestionDetails) RankingWidget(org.odk.collect.android.widgets.items.RankingWidget) AudioRecorderRecordingStatusHandler(org.odk.collect.android.widgets.utilities.AudioRecorderRecordingStatusHandler) GetContentAudioFileRequester(org.odk.collect.android.widgets.utilities.GetContentAudioFileRequester) StoragePathProvider(org.odk.collect.android.storage.StoragePathProvider) CameraUtils(org.odk.collect.android.utilities.CameraUtils) SelectMultiMinimalWidget(org.odk.collect.android.widgets.items.SelectMultiMinimalWidget) LabelWidget(org.odk.collect.android.widgets.items.LabelWidget)

Aggregations

QuestionDetails (org.odk.collect.android.formentry.questions.QuestionDetails)15 Test (org.junit.Test)9 GeneralStringWidgetTest (org.odk.collect.android.widgets.base.GeneralStringWidgetTest)7 FormEntryPrompt (org.javarosa.form.api.FormEntryPrompt)3 MockFormEntryPromptBuilder (org.odk.collect.android.support.MockFormEntryPromptBuilder)3 NonNull (androidx.annotation.NonNull)2 IFormElement (org.javarosa.core.model.IFormElement)2 QuestionDef (org.javarosa.core.model.QuestionDef)2 DatePickerDialog (android.app.DatePickerDialog)1 DatePicker (android.widget.DatePicker)1 DateTime (org.joda.time.DateTime)1 LocalDateTime (org.joda.time.LocalDateTime)1 AudioButton (org.odk.collect.android.audio.AudioButton)1 StoragePathProvider (org.odk.collect.android.storage.StoragePathProvider)1 WidgetTestActivity (org.odk.collect.android.support.WidgetTestActivity)1 CameraUtils (org.odk.collect.android.utilities.CameraUtils)1 ExternalWebPageHelper (org.odk.collect.android.utilities.ExternalWebPageHelper)1 DateTimeWidget (org.odk.collect.android.widgets.DateTimeWidget)1 DateWidget (org.odk.collect.android.widgets.DateWidget)1 GeneralExStringWidgetTest (org.odk.collect.android.widgets.base.GeneralExStringWidgetTest)1