Search in sources :

Example 36 with FormController

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

the class FormEntryActivity method onSaveInstanceState.

@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putString(KEY_FORMPATH, formPath);
    FormController formController = getFormController();
    if (formController != null) {
        if (formController.getInstanceFile() != null) {
            outState.putString(KEY_INSTANCEPATH, getAbsoluteInstancePath());
        }
        outState.putString(KEY_XPATH, formController.getXPath(formController.getFormIndex()));
        FormIndex waiting = formController.getIndexWaitingForData();
        if (waiting != null) {
            outState.putString(KEY_XPATH_WAITING_FOR_DATA, formController.getXPath(waiting));
        }
        // save the instance to a temp path...
        nonblockingCreateSavePointData();
    }
    outState.putBoolean(NEWFORM, false);
    outState.putString(KEY_ERROR, errorMessage);
    outState.putString(KEY_SAVE_NAME, saveName);
    outState.putBoolean(KEY_AUTO_SAVED, autoSaved);
    outState.putBoolean(KEY_READ_PHONE_STATE_PERMISSION_REQUEST_NEEDED, readPhoneStatePermissionRequestNeeded);
    outState.putBoolean(KEY_LOCATION_PERMISSIONS_GRANTED, locationPermissionsPreviouslyGranted);
}
Also used : FormController(org.odk.collect.android.javarosawrapper.FormController) FormIndex(org.javarosa.core.model.FormIndex)

Example 37 with FormController

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

the class FormEntryActivity method onResume.

@Override
protected void onResume() {
    super.onResume();
    activityDisplayed();
    String navigation = settingsProvider.getUnprotectedSettings().getString(KEY_NAVIGATION);
    showNavigationButtons = navigation.contains(ProjectKeys.NAVIGATION_BUTTONS);
    findViewById(R.id.buttonholder).setVisibility(showNavigationButtons ? View.VISIBLE : View.GONE);
    if (showNavigationButtons) {
        updateNavigationButtonVisibility();
    }
    if (errorMessage != null) {
        if (alertDialog != null && !alertDialog.isShowing()) {
            createErrorDialog(errorMessage, true);
        } else {
            return;
        }
    }
    FormController formController = getFormController();
    if (formController != null && !formEntryViewModel.isFormControllerSet()) {
        Timber.e("FormController set in App but not ViewModel");
    }
    if (formLoaderTask != null) {
        formLoaderTask.setFormLoaderListener(this);
        if (formController == null && formLoaderTask.getStatus() == AsyncTask.Status.FINISHED) {
            FormController fec = formLoaderTask.getFormController();
            if (fec != null) {
                if (!readPhoneStatePermissionRequestNeeded) {
                    loadingComplete(formLoaderTask, formLoaderTask.getFormDef(), null);
                }
            } else {
                DialogFragmentUtils.dismissDialog(FormLoadingDialogFragment.class, getSupportFragmentManager());
                FormLoaderTask t = formLoaderTask;
                formLoaderTask = null;
                t.cancel(true);
                t.destroy();
                // there is no formController -- fire MainMenu activity?
                startActivity(new Intent(this, MainMenuActivity.class));
            }
        }
    } else {
        if (formController == null) {
            // there is no formController -- fire MainMenu activity?
            startActivity(new Intent(this, MainMenuActivity.class));
            finish();
            return;
        }
    }
}
Also used : FormController(org.odk.collect.android.javarosawrapper.FormController) Intent(android.content.Intent) FormLoaderTask(org.odk.collect.android.tasks.FormLoaderTask)

Example 38 with FormController

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

the class FormHierarchyActivity method jumpToHierarchyStartIndex.

/**
 * Goes to the start of the hierarchy view based on where the user came from.
 * Backs out until the index is at the beginning of a repeat group or the beginning of the form.
 */
private void jumpToHierarchyStartIndex() {
    FormController formController = Collect.getInstance().getFormController();
    FormIndex startIndex = formController.getFormIndex();
    // If we're not at the first level, we're inside a repeated group so we want to only
    // display everything enclosed within that group.
    contextGroupRef = null;
    // Save the index to the screen itself, before potentially moving into it.
    screenIndex = startIndex;
    // node to display.
    if (formController.isDisplayableGroup(startIndex)) {
        contextGroupRef = formController.getFormIndex().getReference();
        formController.stepToNextEvent(FormController.STEP_INTO_GROUP);
    } else {
        FormIndex potentialStartIndex = getPreviousLevel(startIndex);
        // Step back until we hit a displayable group or the beginning.
        while (!isScreenEvent(formController, potentialStartIndex)) {
            potentialStartIndex = getPreviousLevel(potentialStartIndex);
        }
        screenIndex = potentialStartIndex;
        // Otherwise we're at a displayable group.
        if (screenIndex == null) {
            screenIndex = FormIndex.createBeginningOfFormIndex();
        }
        formController.jumpToIndex(screenIndex);
        // Now test again. This should be true at this point or we're at the beginning.
        if (formController.isDisplayableGroup(formController.getFormIndex())) {
            contextGroupRef = formController.getFormIndex().getReference();
            formController.stepToNextEvent(FormController.STEP_INTO_GROUP);
        } else {
        // Let contextGroupRef be null.
        }
    }
}
Also used : FormController(org.odk.collect.android.javarosawrapper.FormController) FormIndex(org.javarosa.core.model.FormIndex)

Example 39 with FormController

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

the class FormHierarchyActivity method onBackPressed.

/**
 * When the device back button is pressed, go back to the previous activity, NOT the previous
 * level in the hierarchy as the "Go Up" button does.
 */
@Override
public void onBackPressed() {
    FormController formController = Collect.getInstance().getFormController();
    if (formController != null) {
        formController.getAuditEventLogger().flush();
        navigateToTheLastRelevantIndex(formController);
    }
    onBackPressedWithoutLogger();
}
Also used : FormController(org.odk.collect.android.javarosawrapper.FormController)

Example 40 with FormController

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

the class FormHierarchyActivity method goUpLevel.

/**
 * Navigates "up" in the form hierarchy.
 */
protected void goUpLevel() {
    FormController formController = Collect.getInstance().getFormController();
    // we will go back up to the previous screen.
    if (shouldShowRepeatGroupPicker()) {
        // Exit the picker.
        repeatGroupPickerIndex = null;
    } else {
        // Enter the picker if coming from a repeat group.
        int event = formController.getEvent(screenIndex);
        if (event == FormEntryController.EVENT_REPEAT || event == FormEntryController.EVENT_PROMPT_NEW_REPEAT) {
            repeatGroupPickerIndex = screenIndex;
        }
        formController.stepToOuterScreenEvent();
    }
    refreshView(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