Search in sources :

Example 41 with FormController

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));
    }
}
Also used : FormController(org.odk.collect.android.javarosawrapper.FormController)

Example 42 with FormController

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;
    }
}
Also used : FormController(org.odk.collect.android.javarosawrapper.FormController) Bundle(android.os.Bundle) File(java.io.File) JavaRosaException(org.odk.collect.android.exception.JavaRosaException)

Example 43 with FormController

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;
    }
}
Also used : FormController(org.odk.collect.android.javarosawrapper.FormController) IntentFilter(android.content.IntentFilter) PlayServicesChecker(org.odk.collect.android.utilities.PlayServicesChecker)

Example 44 with FormController

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);
                }
            }
        });
    }
}
Also used : FormController(org.odk.collect.android.javarosawrapper.FormController) RepeatsInFieldListException(org.odk.collect.android.javarosawrapper.RepeatsInFieldListException) ODKView(org.odk.collect.android.formentry.ODKView) FormEndView(org.odk.collect.android.formentry.FormEndView) View(android.view.View) WebView(android.webkit.WebView) AudioControllerView(org.odk.collect.android.audio.AudioControllerView) TextView(android.widget.TextView)

Example 45 with FormController

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;
    }
}
Also used : FormController(org.odk.collect.android.javarosawrapper.FormController)

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