Search in sources :

Example 1 with ImageLoader

use of org.odk.collect.imageloader.ImageLoader 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 ImageLoader

use of org.odk.collect.imageloader.ImageLoader 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 3 with ImageLoader

use of org.odk.collect.imageloader.ImageLoader in project collect by opendatakit.

the class SignatureWidgetTest 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();
    SignatureWidget 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 4 with ImageLoader

use of org.odk.collect.imageloader.ImageLoader in project collect by opendatakit.

the class DrawWidgetTest method whenPromptHasCurrentAnswer_showsInImageView.

@Test
public void whenPromptHasCurrentAnswer_showsInImageView() throws Exception {
    CollectHelpers.overrideAppDependencyModule(new AppDependencyModule() {

        @Override
        public ImageLoader providesImageLoader() {
            return new SynchronousImageLoader();
        }
    });
    String imagePath = File.createTempFile("current", ".bmp").getAbsolutePath();
    currentFile = new File(imagePath);
    formEntryPrompt = new MockFormEntryPromptBuilder().withAnswerDisplayText(USER_SPECIFIED_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) AppDependencyModule(org.odk.collect.android.injection.config.AppDependencyModule) RandomString(net.bytebuddy.utility.RandomString) 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) File(java.io.File) Test(org.junit.Test) FileWidgetTest(org.odk.collect.android.widgets.base.FileWidgetTest)

Example 5 with ImageLoader

use of org.odk.collect.imageloader.ImageLoader in project collect by opendatakit.

the class AnnotateWidgetTest method whenPromptHasCurrentAnswer_showsInImageView.

@Test
public void whenPromptHasCurrentAnswer_showsInImageView() throws Exception {
    CollectHelpers.overrideAppDependencyModule(new AppDependencyModule() {

        @Override
        public ImageLoader providesImageLoader() {
            return new SynchronousImageLoader();
        }
    });
    String imagePath = File.createTempFile("current", ".bmp").getAbsolutePath();
    currentFile = new File(imagePath);
    formEntryPrompt = new MockFormEntryPromptBuilder().withAnswerDisplayText(DrawWidgetTest.USER_SPECIFIED_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) AppDependencyModule(org.odk.collect.android.injection.config.AppDependencyModule) RandomString(net.bytebuddy.utility.RandomString) 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) File(java.io.File) Test(org.junit.Test) FileWidgetTest(org.odk.collect.android.widgets.base.FileWidgetTest)

Aggregations

ImageView (android.widget.ImageView)8 RandomString (net.bytebuddy.utility.RandomString)8 Test (org.junit.Test)8 AppDependencyModule (org.odk.collect.android.injection.config.AppDependencyModule)8 MockFormEntryPromptBuilder (org.odk.collect.android.support.MockFormEntryPromptBuilder)8 FileWidgetTest (org.odk.collect.android.widgets.base.FileWidgetTest)8 SynchronousImageLoader (org.odk.collect.android.widgets.support.SynchronousImageLoader)8 ImageLoader (org.odk.collect.imageloader.ImageLoader)8 BitmapDrawable (android.graphics.drawable.BitmapDrawable)7 Drawable (android.graphics.drawable.Drawable)7 Pair (androidx.core.util.Pair)4 File (java.io.File)4 ReferenceManager (org.javarosa.core.reference.ReferenceManager)4 CollectHelpers.setupFakeReferenceManager (org.odk.collect.android.support.CollectHelpers.setupFakeReferenceManager)4 CollectHelpers.overrideReferenceManager (org.odk.collect.android.support.CollectHelpers.overrideReferenceManager)1