Search in sources :

Example 1 with FormLoaderListener

use of org.odk.collect.android.listeners.FormLoaderListener in project collect by opendatakit.

the class FormNavigationTest method testIndices.

private void testIndices(String formName, String[] expectedIndices) throws ExecutionException, InterruptedException {
    try {
        copyToStorage(formName);
    } catch (IOException e) {
        Timber.i(e);
    }
    FormLoaderTask formLoaderTask = new FormLoaderTask(formPath(formName), null, null);
    formLoaderTask.setFormLoaderListener(new FormLoaderListener() {

        @Override
        public void loadingComplete(FormLoaderTask task, FormDef fd, String warningMsg) {
            try {
                // form and then swiping back once. Verify the expected indices before and after each swipe.
                for (int i = 0; i < expectedIndices.length - 1; i++) {
                    FormController formController = task.getFormController();
                    // check the current index
                    assertEquals(expectedIndices[i], formController.getFormIndex().toString());
                    if (i < expectedIndices.length - 2) {
                        formController.stepToNextScreenEvent();
                    } else {
                        formController.stepToPreviousScreenEvent();
                    }
                    // check the index again after navigating
                    assertEquals(expectedIndices[i + 1], formController.getFormIndex().toString());
                }
            } catch (Exception e) {
                Timber.i(e);
            }
        }

        @Override
        public void loadingError(String errorMsg) {
        }

        @Override
        public void onProgressStep(String stepMessage) {
        }
    });
    formLoaderTask.execute(formPath(formName)).get();
}
Also used : FormController(org.odk.collect.android.javarosawrapper.FormController) FormDef(org.javarosa.core.model.FormDef) FormLoaderListener(org.odk.collect.android.listeners.FormLoaderListener) IOException(java.io.IOException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) FormLoaderTask(org.odk.collect.android.tasks.FormLoaderTask)

Example 2 with FormLoaderListener

use of org.odk.collect.android.listeners.FormLoaderListener in project collect by opendatakit.

the class FormNavigationTestCase method testIndices.

private void testIndices(String formName, String[] expectedIndices) throws ExecutionException, InterruptedException {
    try {
        copyToSdCard(formName);
    } catch (IOException e) {
        Timber.i(e);
    }
    FormLoaderTask formLoaderTask = new FormLoaderTask(formPath(formName), null, null);
    formLoaderTask.setFormLoaderListener(new FormLoaderListener() {

        @Override
        public void loadingComplete(FormLoaderTask task, FormDef fd) {
            try {
                // form and then swiping back once. Verify the expected indices before and after each swipe.
                for (int i = 0; i < expectedIndices.length - 1; i++) {
                    FormController formController = task.getFormController();
                    // check the current index
                    assertEquals(expectedIndices[i], formController.getFormIndex().toString());
                    if (i < expectedIndices.length - 2) {
                        formController.stepToNextScreenEvent();
                    } else {
                        formController.stepToPreviousScreenEvent();
                    }
                    // check the index again after navigating
                    assertEquals(expectedIndices[i + 1], formController.getFormIndex().toString());
                }
            } catch (Exception e) {
                Timber.i(e);
            }
        }

        @Override
        public void loadingError(String errorMsg) {
        }

        @Override
        public void onProgressStep(String stepMessage) {
        }
    });
    formLoaderTask.execute(formPath(formName)).get();
}
Also used : FormController(org.odk.collect.android.logic.FormController) FormDef(org.javarosa.core.model.FormDef) FormLoaderListener(org.odk.collect.android.listeners.FormLoaderListener) IOException(java.io.IOException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) FormLoaderTask(org.odk.collect.android.tasks.FormLoaderTask)

Aggregations

IOException (java.io.IOException)2 ExecutionException (java.util.concurrent.ExecutionException)2 FormDef (org.javarosa.core.model.FormDef)2 FormLoaderListener (org.odk.collect.android.listeners.FormLoaderListener)2 FormLoaderTask (org.odk.collect.android.tasks.FormLoaderTask)2 FormController (org.odk.collect.android.javarosawrapper.FormController)1 FormController (org.odk.collect.android.logic.FormController)1