Search in sources :

Example 1 with AudioHelper

use of org.odk.collect.android.audio.AudioHelper in project collect by opendatakit.

the class ChoicesRecyclerViewTest method whenChoiceSelectedInSelectOneNoButtonsMode_shouldTryToPlayAudio.

@Test
public void whenChoiceSelectedInSelectOneNoButtonsMode_shouldTryToPlayAudio() {
    List<SelectChoice> items = getTestChoices();
    setUpFormEntryPrompt(items, "no-buttons");
    SelectItemClickListener listener = mock(SelectItemClickListener.class);
    AudioHelper audioHelper = mock(AudioHelper.class);
    SelectOneListAdapter adapter = spy(new SelectOneListAdapter(null, listener, activityController.get(), items, formEntryPrompt, null, audioHelper, 0, 1, true, mock(MediaUtils.class)));
    initRecyclerView(adapter, false);
    // Select AAA
    clickChoice(0);
    verify(adapter).playAudio(any());
}
Also used : SelectChoice(org.javarosa.core.model.SelectChoice) SelectItemClickListener(org.odk.collect.android.listeners.SelectItemClickListener) SelectOneListAdapter(org.odk.collect.android.adapters.SelectOneListAdapter) AudioHelper(org.odk.collect.android.audio.AudioHelper) Test(org.junit.Test)

Example 2 with AudioHelper

use of org.odk.collect.android.audio.AudioHelper in project collect by opendatakit.

the class ChoicesRecyclerViewTest method whenChoiceSelectedInSelectMultiNoButtonsMode_shouldTryToPlayAudio.

@Test
public void whenChoiceSelectedInSelectMultiNoButtonsMode_shouldTryToPlayAudio() {
    List<SelectChoice> items = getTestChoices();
    setUpFormEntryPrompt(items, "no-buttons");
    SelectItemClickListener listener = mock(SelectItemClickListener.class);
    AudioHelper audioHelper = mock(AudioHelper.class);
    SelectMultipleListAdapter adapter = spy(new SelectMultipleListAdapter(new ArrayList<>(), listener, activityController.get(), items, formEntryPrompt, null, audioHelper, 0, 1, true, mock(MediaUtils.class)));
    initRecyclerView(adapter, false);
    // Select AAA
    clickChoice(0);
    verify(adapter).playAudio(any());
}
Also used : SelectChoice(org.javarosa.core.model.SelectChoice) SelectMultipleListAdapter(org.odk.collect.android.adapters.SelectMultipleListAdapter) ArrayList(java.util.ArrayList) SelectItemClickListener(org.odk.collect.android.listeners.SelectItemClickListener) AudioHelper(org.odk.collect.android.audio.AudioHelper) Test(org.junit.Test)

Example 3 with AudioHelper

use of org.odk.collect.android.audio.AudioHelper in project collect by opendatakit.

the class ChoicesRecyclerViewTest method setUp.

@Before
public void setUp() throws InvalidReferenceException {
    audioHelper = mock(AudioHelper.class);
    activityController = CollectHelpers.buildThemedActivity(WidgetTestActivity.class);
    Activity activity = activityController.get();
    FrameLayout frameLayout = new FrameLayout(activity);
    activity.setContentView(frameLayout);
    activityController.create().start().visible();
    recyclerView = new ChoicesRecyclerView(activity);
    frameLayout.addView(recyclerView);
    populateRecyclerView(recyclerView);
    setUpReferenceManager();
}
Also used : FrameLayout(android.widget.FrameLayout) WidgetTestActivity(org.odk.collect.android.support.WidgetTestActivity) WidgetTestActivity(org.odk.collect.android.support.WidgetTestActivity) Activity(android.app.Activity) AudioHelper(org.odk.collect.android.audio.AudioHelper) Before(org.junit.Before)

Example 4 with AudioHelper

use of org.odk.collect.android.audio.AudioHelper in project collect by opendatakit.

the class ChoicesRecyclerViewTest method whenButtonsModeIsUsed_shouldViewAndItsElementsBeLongClickableToSupportRemovingAnswers.

@Test
public void whenButtonsModeIsUsed_shouldViewAndItsElementsBeLongClickableToSupportRemovingAnswers() {
    List<SelectChoice> items = getTestChoices();
    setUpFormEntryPrompt(items, "");
    SelectItemClickListener listener = mock(SelectItemClickListener.class);
    SelectMultipleListAdapter adapter = new SelectMultipleListAdapter(new ArrayList<>(), listener, activityController.get(), items, formEntryPrompt, null, null, 0, 1, false, mock(MediaUtils.class));
    initRecyclerView(adapter, false);
    AudioVideoImageTextLabel view = (AudioVideoImageTextLabel) getChoiceView(0);
    File file = mock(File.class);
    when(file.exists()).thenReturn(true);
    view.setImage(file, mock(ImageLoader.class));
    view.setVideo(file);
    AudioHelper audioHelper = mock(AudioHelper.class);
    MutableLiveData<Boolean> isPlaying = new MutableLiveData<>(false);
    when(audioHelper.setAudio(any(AudioButton.class), any())).thenReturn(isPlaying);
    view.setAudio("file://audio.mp3", audioHelper);
    assertThat(view.isLongClickable(), is(true));
    assertThat(view.getImageView().isLongClickable(), is(true));
    assertThat(view.getVideoButton().isLongClickable(), is(true));
    assertThat(view.getAudioButton().isLongClickable(), is(true));
    assertThat(view.getLabelTextView().isLongClickable(), is(true));
}
Also used : SelectChoice(org.javarosa.core.model.SelectChoice) MediaUtils(org.odk.collect.android.utilities.MediaUtils) SelectItemClickListener(org.odk.collect.android.listeners.SelectItemClickListener) AudioHelper(org.odk.collect.android.audio.AudioHelper) SelectMultipleListAdapter(org.odk.collect.android.adapters.SelectMultipleListAdapter) MutableLiveData(androidx.lifecycle.MutableLiveData) AudioButton(org.odk.collect.android.audio.AudioButton) AudioVideoImageTextLabel(org.odk.collect.android.formentry.questions.AudioVideoImageTextLabel) ImageLoader(org.odk.collect.imageloader.ImageLoader) File(java.io.File) Test(org.junit.Test)

Aggregations

AudioHelper (org.odk.collect.android.audio.AudioHelper)4 SelectChoice (org.javarosa.core.model.SelectChoice)3 Test (org.junit.Test)3 SelectItemClickListener (org.odk.collect.android.listeners.SelectItemClickListener)3 SelectMultipleListAdapter (org.odk.collect.android.adapters.SelectMultipleListAdapter)2 Activity (android.app.Activity)1 FrameLayout (android.widget.FrameLayout)1 MutableLiveData (androidx.lifecycle.MutableLiveData)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1 SelectOneListAdapter (org.odk.collect.android.adapters.SelectOneListAdapter)1 AudioButton (org.odk.collect.android.audio.AudioButton)1 AudioVideoImageTextLabel (org.odk.collect.android.formentry.questions.AudioVideoImageTextLabel)1 WidgetTestActivity (org.odk.collect.android.support.WidgetTestActivity)1 MediaUtils (org.odk.collect.android.utilities.MediaUtils)1 ImageLoader (org.odk.collect.imageloader.ImageLoader)1