Search in sources :

Example 1 with ReferenceManager

use of org.javarosa.core.reference.ReferenceManager in project collect by opendatakit.

the class AnnotateWidgetTest method whenPromptHasDefaultAnswer_showsInImageView.

@Test
public void whenPromptHasDefaultAnswer_showsInImageView() throws Exception {
    String imagePath = File.createTempFile("default", ".bmp").getAbsolutePath();
    ReferenceManager referenceManager = setupFakeReferenceManager(singletonList(new Pair<>(DrawWidgetTest.DEFAULT_IMAGE_ANSWER, imagePath)));
    CollectHelpers.overrideAppDependencyModule(new AppDependencyModule() {

        @Override
        public ReferenceManager providesReferenceManager() {
            return referenceManager;
        }

        @Override
        public ImageLoader providesImageLoader() {
            return new SynchronousImageLoader();
        }
    });
    formEntryPrompt = new MockFormEntryPromptBuilder().withAnswerDisplayText(DrawWidgetTest.DEFAULT_IMAGE_ANSWER).build();
    AnnotateWidget widget = createWidget();
    ImageView imageView = widget.getImageView();
    assertThat(imageView, notNullValue());
    Drawable drawable = imageView.getDrawable();
    assertThat(drawable, notNullValue());
    String loadedPath = shadowOf(((BitmapDrawable) drawable).getBitmap()).getCreatedFromPath();
    assertThat(loadedPath, equalTo(imagePath));
}
Also used : SynchronousImageLoader(org.odk.collect.android.widgets.support.SynchronousImageLoader) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) RandomString(net.bytebuddy.utility.RandomString) AppDependencyModule(org.odk.collect.android.injection.config.AppDependencyModule) MockFormEntryPromptBuilder(org.odk.collect.android.support.MockFormEntryPromptBuilder) ImageView(android.widget.ImageView) BitmapDrawable(android.graphics.drawable.BitmapDrawable) ImageLoader(org.odk.collect.imageloader.ImageLoader) SynchronousImageLoader(org.odk.collect.android.widgets.support.SynchronousImageLoader) CollectHelpers.setupFakeReferenceManager(org.odk.collect.android.support.CollectHelpers.setupFakeReferenceManager) ReferenceManager(org.javarosa.core.reference.ReferenceManager) CollectHelpers.overrideReferenceManager(org.odk.collect.android.support.CollectHelpers.overrideReferenceManager) Pair(androidx.core.util.Pair) Test(org.junit.Test) FileWidgetTest(org.odk.collect.android.widgets.base.FileWidgetTest)

Example 2 with ReferenceManager

use of org.javarosa.core.reference.ReferenceManager in project collect by opendatakit.

the class SelectOneWidgetTest method overrideDependencyModule.

private void overrideDependencyModule() throws Exception {
    ReferenceManager referenceManager = setupFakeReferenceManager(REFERENCES);
    CollectHelpers.overrideAppDependencyModule(new AppDependencyModule() {

        @Override
        public ReferenceManager providesReferenceManager() {
            return referenceManager;
        }

        @Override
        public AudioHelperFactory providesAudioHelperFactory(Scheduler scheduler) {
            return context -> audioHelper;
        }

        @Override
        public Analytics providesAnalytics(Application application) {
            return analytics;
        }

        @Override
        public SoftKeyboardController provideSoftKeyboardController() {
            return mock(SoftKeyboardController.class);
        }
    });
}
Also used : AudioHelperFactory(org.odk.collect.android.formentry.media.AudioHelperFactory) Scheduler(org.odk.collect.async.Scheduler) AppDependencyModule(org.odk.collect.android.injection.config.AppDependencyModule) SoftKeyboardController(org.odk.collect.android.utilities.SoftKeyboardController) Application(android.app.Application) Analytics(org.odk.collect.analytics.Analytics) CollectHelpers.setupFakeReferenceManager(org.odk.collect.android.support.CollectHelpers.setupFakeReferenceManager) ReferenceManager(org.javarosa.core.reference.ReferenceManager)

Example 3 with ReferenceManager

use of org.javarosa.core.reference.ReferenceManager in project collect by opendatakit.

the class SelectMultiWidgetTest method overrideDependencyModule.

private void overrideDependencyModule() throws Exception {
    ReferenceManager referenceManager = setupFakeReferenceManager(REFERENCES);
    CollectHelpers.overrideAppDependencyModule(new AppDependencyModule() {

        @Override
        public ReferenceManager providesReferenceManager() {
            return referenceManager;
        }

        @Override
        public AudioHelperFactory providesAudioHelperFactory(Scheduler scheduler) {
            return context -> audioHelper;
        }

        @Override
        public Analytics providesAnalytics(Application application) {
            return analytics;
        }

        @Override
        public SoftKeyboardController provideSoftKeyboardController() {
            return mock(SoftKeyboardController.class);
        }
    });
}
Also used : AudioHelperFactory(org.odk.collect.android.formentry.media.AudioHelperFactory) Scheduler(org.odk.collect.async.Scheduler) AppDependencyModule(org.odk.collect.android.injection.config.AppDependencyModule) SoftKeyboardController(org.odk.collect.android.utilities.SoftKeyboardController) Application(android.app.Application) Analytics(org.odk.collect.analytics.Analytics) CollectHelpers.setupFakeReferenceManager(org.odk.collect.android.support.CollectHelpers.setupFakeReferenceManager) ReferenceManager(org.javarosa.core.reference.ReferenceManager)

Example 4 with ReferenceManager

use of org.javarosa.core.reference.ReferenceManager in project collect by opendatakit.

the class DrawWidgetTest method whenPromptHasDefaultAnswer_showsInImageView.

@Test
public void whenPromptHasDefaultAnswer_showsInImageView() throws Exception {
    String imagePath = File.createTempFile("default", ".bmp").getAbsolutePath();
    ReferenceManager referenceManager = setupFakeReferenceManager(singletonList(new Pair<>(DrawWidgetTest.DEFAULT_IMAGE_ANSWER, imagePath)));
    CollectHelpers.overrideAppDependencyModule(new AppDependencyModule() {

        @Override
        public ReferenceManager providesReferenceManager() {
            return referenceManager;
        }

        @Override
        public ImageLoader providesImageLoader() {
            return new SynchronousImageLoader();
        }
    });
    formEntryPrompt = new MockFormEntryPromptBuilder().withAnswerDisplayText(DEFAULT_IMAGE_ANSWER).build();
    DrawWidget widget = createWidget();
    ImageView imageView = widget.getImageView();
    assertThat(imageView, notNullValue());
    Drawable drawable = imageView.getDrawable();
    assertThat(drawable, notNullValue());
    String loadedPath = shadowOf(((BitmapDrawable) drawable).getBitmap()).getCreatedFromPath();
    assertThat(loadedPath, equalTo(imagePath));
}
Also used : SynchronousImageLoader(org.odk.collect.android.widgets.support.SynchronousImageLoader) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) RandomString(net.bytebuddy.utility.RandomString) AppDependencyModule(org.odk.collect.android.injection.config.AppDependencyModule) MockFormEntryPromptBuilder(org.odk.collect.android.support.MockFormEntryPromptBuilder) ImageView(android.widget.ImageView) BitmapDrawable(android.graphics.drawable.BitmapDrawable) ImageLoader(org.odk.collect.imageloader.ImageLoader) SynchronousImageLoader(org.odk.collect.android.widgets.support.SynchronousImageLoader) CollectHelpers.setupFakeReferenceManager(org.odk.collect.android.support.CollectHelpers.setupFakeReferenceManager) ReferenceManager(org.javarosa.core.reference.ReferenceManager) Pair(androidx.core.util.Pair) Test(org.junit.Test) FileWidgetTest(org.odk.collect.android.widgets.base.FileWidgetTest)

Example 5 with ReferenceManager

use of org.javarosa.core.reference.ReferenceManager in project collect by opendatakit.

the class QuestionWidgetTest method overrideDependencyModule.

private void overrideDependencyModule() throws Exception {
    ReferenceManager referenceManager = setupFakeReferenceManager(asList(new Pair<>("ref", "blah.mp3")));
    CollectHelpers.overrideAppDependencyModule(new AppDependencyModule() {

        @Override
        public ReferenceManager providesReferenceManager() {
            return referenceManager;
        }

        @Override
        public AudioHelperFactory providesAudioHelperFactory(Scheduler scheduler) {
            return context -> audioHelper;
        }

        @Override
        public Analytics providesAnalytics(Application application) {
            return analytics;
        }
    });
}
Also used : AudioHelperFactory(org.odk.collect.android.formentry.media.AudioHelperFactory) Scheduler(org.odk.collect.async.Scheduler) AppDependencyModule(org.odk.collect.android.injection.config.AppDependencyModule) Application(android.app.Application) Analytics(org.odk.collect.analytics.Analytics) CollectHelpers.setupFakeReferenceManager(org.odk.collect.android.support.CollectHelpers.setupFakeReferenceManager) ReferenceManager(org.javarosa.core.reference.ReferenceManager) Pair(androidx.core.util.Pair)

Aggregations

ReferenceManager (org.javarosa.core.reference.ReferenceManager)10 CollectHelpers.setupFakeReferenceManager (org.odk.collect.android.support.CollectHelpers.setupFakeReferenceManager)9 AppDependencyModule (org.odk.collect.android.injection.config.AppDependencyModule)8 Pair (androidx.core.util.Pair)6 ImageView (android.widget.ImageView)4 RandomString (net.bytebuddy.utility.RandomString)4 Test (org.junit.Test)4 MockFormEntryPromptBuilder (org.odk.collect.android.support.MockFormEntryPromptBuilder)4 FileWidgetTest (org.odk.collect.android.widgets.base.FileWidgetTest)4 SynchronousImageLoader (org.odk.collect.android.widgets.support.SynchronousImageLoader)4 ImageLoader (org.odk.collect.imageloader.ImageLoader)4 Application (android.app.Application)3 BitmapDrawable (android.graphics.drawable.BitmapDrawable)3 Drawable (android.graphics.drawable.Drawable)3 Analytics (org.odk.collect.analytics.Analytics)3 AudioHelperFactory (org.odk.collect.android.formentry.media.AudioHelperFactory)3 Scheduler (org.odk.collect.async.Scheduler)3 SoftKeyboardController (org.odk.collect.android.utilities.SoftKeyboardController)2 Reference (org.javarosa.core.reference.Reference)1 Before (org.junit.Before)1