Search in sources :

Example 6 with FormLoaderTask

use of org.odk.collect.android.tasks.FormLoaderTask 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

FormLoaderTask (org.odk.collect.android.tasks.FormLoaderTask)6 Intent (android.content.Intent)3 FormController (org.odk.collect.android.logic.FormController)3 File (java.io.File)2 ProgressDialog (android.app.ProgressDialog)1 DialogInterface (android.content.DialogInterface)1 Uri (android.net.Uri)1 GestureDetector (android.view.GestureDetector)1 OnClickListener (android.view.View.OnClickListener)1 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)1 Disposable (io.reactivex.disposables.Disposable)1 IOException (java.io.IOException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ExecutionException (java.util.concurrent.ExecutionException)1 FormDef (org.javarosa.core.model.FormDef)1 FormIndex (org.javarosa.core.model.FormIndex)1 GDriveConnectionException (org.odk.collect.android.exception.GDriveConnectionException)1 JavaRosaException (org.odk.collect.android.exception.JavaRosaException)1 FormLoaderListener (org.odk.collect.android.listeners.FormLoaderListener)1 FailedConstraint (org.odk.collect.android.logic.FormController.FailedConstraint)1