Search in sources :

Example 1 with MediaUtils

use of org.odk.collect.android.utilities.MediaUtils in project collect by opendatakit.

the class ExImageWidgetTest method setup.

@Before
public void setup() {
    mediaUtils = mock(MediaUtils.class);
    CollectHelpers.overrideAppDependencyModule(new AppDependencyModule() {

        @Override
        public MediaUtils providesMediaUtils(IntentLauncher intentLauncher) {
            return mediaUtils;
        }
    });
    when(mediaUtils.isImageFile(any())).thenReturn(true);
}
Also used : IntentLauncher(org.odk.collect.androidshared.system.IntentLauncher) MediaUtils(org.odk.collect.android.utilities.MediaUtils) AppDependencyModule(org.odk.collect.android.injection.config.AppDependencyModule) Before(org.junit.Before)

Example 2 with MediaUtils

use of org.odk.collect.android.utilities.MediaUtils in project collect by opendatakit.

the class VideoWidgetTest method buttonsShouldLaunchCorrectIntents.

@Test
public void buttonsShouldLaunchCorrectIntents() {
    MediaUtils mediaUtils = mock(MediaUtils.class);
    CollectHelpers.overrideAppDependencyModule(new AppDependencyModule() {

        @Override
        public MediaUtils providesMediaUtils(IntentLauncher intentLauncher) {
            return mediaUtils;
        }
    });
    stubAllRuntimePermissionsGranted(true);
    Intent intent = getIntentLaunchedByClick(R.id.capture_video);
    assertActionEquals(MediaStore.ACTION_VIDEO_CAPTURE, intent);
    intent = getIntentLaunchedByClick(R.id.choose_video);
    assertActionEquals(Intent.ACTION_GET_CONTENT, intent);
    assertTypeEquals("video/*", intent);
    getIntentLaunchedByClick(R.id.play_video);
    verify(mediaUtils).openFile(any(), any(), any());
}
Also used : IntentLauncher(org.odk.collect.androidshared.system.IntentLauncher) MediaUtils(org.odk.collect.android.utilities.MediaUtils) Intent(android.content.Intent) AppDependencyModule(org.odk.collect.android.injection.config.AppDependencyModule) Test(org.junit.Test) FileWidgetTest(org.odk.collect.android.widgets.base.FileWidgetTest)

Example 3 with MediaUtils

use of org.odk.collect.android.utilities.MediaUtils in project collect by opendatakit.

the class ArbitraryFileWidgetTest method setup.

@Before
public void setup() {
    mediaUtils = mock(MediaUtils.class);
    CollectHelpers.overrideAppDependencyModule(new AppDependencyModule() {

        @Override
        public MediaUtils providesMediaUtils(IntentLauncher intentLauncher) {
            return mediaUtils;
        }
    });
    when(mediaUtils.isAudioFile(any())).thenReturn(true);
}
Also used : IntentLauncher(org.odk.collect.androidshared.system.IntentLauncher) MediaUtils(org.odk.collect.android.utilities.MediaUtils) AppDependencyModule(org.odk.collect.android.injection.config.AppDependencyModule) Before(org.junit.Before)

Example 4 with MediaUtils

use of org.odk.collect.android.utilities.MediaUtils in project collect by opendatakit.

the class FormSaveViewModelTest method setup.

@Before
public void setup() {
    // Useful given some methods will execute AsyncTasks
    Robolectric.getBackgroundThreadScheduler().pause();
    formController = mock(FormController.class);
    logger = mock(AuditEventLogger.class);
    mediaUtils = mock(MediaUtils.class);
    Analytics analytics = mock(Analytics.class);
    when(formController.getAuditEventLogger()).thenReturn(logger);
    when(logger.isChangeReasonRequired()).thenReturn(false);
    audioRecorder = mock(AudioRecorder.class);
    currentProjectProvider = mock(CurrentProjectProvider.class);
    when(currentProjectProvider.getCurrentProject()).thenReturn(Project.Companion.getDEMO_PROJECT());
    viewModel = new FormSaveViewModel(savedStateHandle, () -> CURRENT_TIME, formSaver, mediaUtils, analytics, scheduler, audioRecorder, currentProjectProvider);
    viewModel.formLoaded(formController);
}
Also used : FormController(org.odk.collect.android.javarosawrapper.FormController) CurrentProjectProvider(org.odk.collect.android.projects.CurrentProjectProvider) FormSaveViewModel(org.odk.collect.android.formentry.saving.FormSaveViewModel) MediaUtils(org.odk.collect.android.utilities.MediaUtils) AudioRecorder(org.odk.collect.audiorecorder.recording.AudioRecorder) Analytics(org.odk.collect.analytics.Analytics) Before(org.junit.Before)

Example 5 with MediaUtils

use of org.odk.collect.android.utilities.MediaUtils in project collect by opendatakit.

the class AudioVideoImageTextLabelTest method whenVideoFileClicked_ShouldMediaUtilsBeCalled.

@Test
public void whenVideoFileClicked_ShouldMediaUtilsBeCalled() {
    MediaUtils mediaUtils = mock(MediaUtils.class);
    File videoFile = mock(File.class);
    when(videoFile.exists()).thenReturn(true);
    AudioVideoImageTextLabel audioVideoImageTextLabel = new AudioVideoImageTextLabel(activity);
    audioVideoImageTextLabel.setVideo(videoFile);
    audioVideoImageTextLabel.setMediaUtils(mediaUtils);
    audioVideoImageTextLabel.getVideoButton().performClick();
    verify(mediaUtils).openFile(activity, videoFile, "video/*");
}
Also used : MediaUtils(org.odk.collect.android.utilities.MediaUtils) AudioVideoImageTextLabel(org.odk.collect.android.formentry.questions.AudioVideoImageTextLabel) File(java.io.File) Test(org.junit.Test)

Aggregations

MediaUtils (org.odk.collect.android.utilities.MediaUtils)8 Before (org.junit.Before)6 AppDependencyModule (org.odk.collect.android.injection.config.AppDependencyModule)6 IntentLauncher (org.odk.collect.androidshared.system.IntentLauncher)6 Test (org.junit.Test)2 Intent (android.content.Intent)1 File (java.io.File)1 Analytics (org.odk.collect.analytics.Analytics)1 AudioVideoImageTextLabel (org.odk.collect.android.formentry.questions.AudioVideoImageTextLabel)1 FormSaveViewModel (org.odk.collect.android.formentry.saving.FormSaveViewModel)1 FormController (org.odk.collect.android.javarosawrapper.FormController)1 CurrentProjectProvider (org.odk.collect.android.projects.CurrentProjectProvider)1 FileWidgetTest (org.odk.collect.android.widgets.base.FileWidgetTest)1 AudioRecorder (org.odk.collect.audiorecorder.recording.AudioRecorder)1