Search in sources :

Example 1 with AudioRecorderRecordingStatusHandler

use of org.odk.collect.android.widgets.utilities.AudioRecorderRecordingStatusHandler 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)1 StoragePathProvider (org.odk.collect.android.storage.StoragePathProvider)1 CameraUtils (org.odk.collect.android.utilities.CameraUtils)1 ExternalWebPageHelper (org.odk.collect.android.utilities.ExternalWebPageHelper)1 LabelWidget (org.odk.collect.android.widgets.items.LabelWidget)1 ListMultiWidget (org.odk.collect.android.widgets.items.ListMultiWidget)1 RankingWidget (org.odk.collect.android.widgets.items.RankingWidget)1 SelectMultiImageMapWidget (org.odk.collect.android.widgets.items.SelectMultiImageMapWidget)1 SelectMultiMinimalWidget (org.odk.collect.android.widgets.items.SelectMultiMinimalWidget)1 SelectMultiWidget (org.odk.collect.android.widgets.items.SelectMultiWidget)1 ActivityGeoDataRequester (org.odk.collect.android.widgets.utilities.ActivityGeoDataRequester)1 AudioRecorderRecordingStatusHandler (org.odk.collect.android.widgets.utilities.AudioRecorderRecordingStatusHandler)1 DateTimeWidgetUtils (org.odk.collect.android.widgets.utilities.DateTimeWidgetUtils)1 GetContentAudioFileRequester (org.odk.collect.android.widgets.utilities.GetContentAudioFileRequester)1 RecordingRequester (org.odk.collect.android.widgets.utilities.RecordingRequester)1