Search in sources :

Example 21 with Clip

use of org.odk.collect.audioclips.Clip in project collect by opendatakit.

the class PromptAutoplayerTest method whenPromptHasAutoplayAudio_playsAudio.

@Test
public void whenPromptHasAutoplayAudio_playsAudio() {
    FormEntryPrompt prompt = new MockFormEntryPromptBuilder().withAudioURI(REFERENCES.get(0).first).withAdditionalAttribute("autoplay", "audio").build();
    assertThat(autoplayer.autoplayIfNeeded(prompt), equalTo(true));
    verify(audioHelper).playInOrder(asList(new Clip(prompt.getIndex().toString(), REFERENCES.get(0).second)));
}
Also used : Clip(org.odk.collect.audioclips.Clip) FormEntryPrompt(org.javarosa.form.api.FormEntryPrompt) MockFormEntryPromptBuilder(org.odk.collect.android.support.MockFormEntryPromptBuilder) Test(org.junit.Test)

Example 22 with Clip

use of org.odk.collect.audioclips.Clip in project collect by opendatakit.

the class PromptAutoplayerTest method whenPromptHasAutoplayAudio_andIsSelectOne_withMinimalAppearance_playsPromptAudio.

@Test
public void whenPromptHasAutoplayAudio_andIsSelectOne_withMinimalAppearance_playsPromptAudio() throws Exception {
    FormEntryPrompt prompt = new MockFormEntryPromptBuilder().withControlType(Constants.CONTROL_SELECT_ONE).withAppearance(MINIMAL).withAudioURI(REFERENCES.get(0).first).withAdditionalAttribute("autoplay", "audio").withSelectChoices(asList(new SelectChoice("1", "1"), new SelectChoice("2", "2"))).withSpecialFormSelectChoiceText(asList(new Pair<>(FormEntryCaption.TEXT_FORM_AUDIO, REFERENCES.get(1).first), new Pair<>(FormEntryCaption.TEXT_FORM_AUDIO, REFERENCES.get(2).first))).build();
    assertThat(autoplayer.autoplayIfNeeded(prompt), equalTo(true));
    verify(audioHelper).playInOrder(asList(new Clip(prompt.getIndex().toString(), REFERENCES.get(0).second)));
}
Also used : Clip(org.odk.collect.audioclips.Clip) FormEntryPrompt(org.javarosa.form.api.FormEntryPrompt) SelectChoice(org.javarosa.core.model.SelectChoice) MockFormEntryPromptBuilder(org.odk.collect.android.support.MockFormEntryPromptBuilder) Test(org.junit.Test)

Example 23 with Clip

use of org.odk.collect.audioclips.Clip in project collect by opendatakit.

the class QuestionWidgetTest method whenQuestionHasAudio_audioButtonUsesIndexAsClipID.

@Test
public void whenQuestionHasAudio_audioButtonUsesIndexAsClipID() throws Exception {
    FormEntryPrompt prompt = new MockFormEntryPromptBuilder().withIndex("i am index").withAudioURI("ref").build();
    WidgetTestActivity activity = CollectHelpers.createThemedActivity(WidgetTestActivity.class);
    TestWidget widget = new TestWidget(activity, new QuestionDetails(prompt));
    AudioButton audioButton = widget.getAudioVideoImageTextLabel().findViewById(R.id.audioButton);
    verify(audioHelper).setAudio(audioButton, new Clip("i am index", "blah.mp3"));
}
Also used : Clip(org.odk.collect.audioclips.Clip) FormEntryPrompt(org.javarosa.form.api.FormEntryPrompt) WidgetTestActivity(org.odk.collect.android.support.WidgetTestActivity) MockFormEntryPromptBuilder(org.odk.collect.android.support.MockFormEntryPromptBuilder) QuestionDetails(org.odk.collect.android.formentry.questions.QuestionDetails) AudioButton(org.odk.collect.android.audio.AudioButton) Test(org.junit.Test)

Example 24 with Clip

use of org.odk.collect.audioclips.Clip in project collect by opendatakit.

the class PromptAutoplayer method getSelectClips.

private List<Clip> getSelectClips(FormEntryPrompt prompt) {
    if (appearanceDoesNotShowControls(Appearances.getSanitizedAppearanceHint(prompt))) {
        return emptyList();
    }
    List<Clip> selectClips = new ArrayList<>();
    int controlType = prompt.getControlType();
    if (controlType == Constants.CONTROL_SELECT_ONE || controlType == Constants.CONTROL_SELECT_MULTI) {
        List<SelectChoice> selectChoices = prompt.getSelectChoices();
        for (SelectChoice choice : selectChoices) {
            String selectURI = getPlayableAudioURI(prompt, choice, referenceManager);
            if (selectURI != null) {
                Clip clip = new Clip(getClipID(prompt, choice), selectURI);
                selectClips.add(clip);
            }
        }
    }
    return selectClips;
}
Also used : Clip(org.odk.collect.audioclips.Clip) SelectChoice(org.javarosa.core.model.SelectChoice) ArrayList(java.util.ArrayList)

Example 25 with Clip

use of org.odk.collect.audioclips.Clip in project collect by opendatakit.

the class SelectMultiWidgetTest method whenChoicesHaveAudio_audioButtonUsesIndexAsClipID.

@Test
public void whenChoicesHaveAudio_audioButtonUsesIndexAsClipID() throws Exception {
    formEntryPrompt = new MockFormEntryPromptBuilder().withIndex("i am index").withSelectChoices(asList(new SelectChoice("1", "1"), new SelectChoice("2", "2"))).withSpecialFormSelectChoiceText(asList(new Pair<>(FormEntryCaption.TEXT_FORM_AUDIO, REFERENCES.get(0).first), new Pair<>(FormEntryCaption.TEXT_FORM_AUDIO, REFERENCES.get(1).first))).build();
    populateRecyclerView(getWidget());
    verify(audioHelper).setAudio(any(AudioButton.class), eq(new Clip("i am index 0", REFERENCES.get(0).second)));
    verify(audioHelper).setAudio(any(AudioButton.class), eq(new Clip("i am index 1", REFERENCES.get(1).second)));
}
Also used : Clip(org.odk.collect.audioclips.Clip) SelectChoice(org.javarosa.core.model.SelectChoice) MockFormEntryPromptBuilder(org.odk.collect.android.support.MockFormEntryPromptBuilder) AudioButton(org.odk.collect.android.audio.AudioButton) Pair(androidx.core.util.Pair) GeneralSelectMultiWidgetTest(org.odk.collect.android.widgets.base.GeneralSelectMultiWidgetTest) Test(org.junit.Test)

Aggregations

Clip (org.odk.collect.audioclips.Clip)27 Test (org.junit.Test)21 FormEntryPrompt (org.javarosa.form.api.FormEntryPrompt)15 MockFormEntryPromptBuilder (org.odk.collect.android.support.MockFormEntryPromptBuilder)12 SelectChoice (org.javarosa.core.model.SelectChoice)10 File (java.io.File)5 AudioControllerView (org.odk.collect.android.audio.AudioControllerView)5 AudioButton (org.odk.collect.android.audio.AudioButton)3 QuestionDetails (org.odk.collect.android.formentry.questions.QuestionDetails)3 SuppressLint (android.annotation.SuppressLint)2 Context (android.content.Context)2 MediaMetadataRetriever (android.media.MediaMetadataRetriever)2 TypedValue (android.util.TypedValue)2 View (android.view.View)2 Pair (androidx.core.util.Pair)2 MaterialAlertDialogBuilder (com.google.android.material.dialog.MaterialAlertDialogBuilder)2 ArrayList (java.util.ArrayList)2 IAnswerData (org.javarosa.core.model.data.IAnswerData)2 StringData (org.javarosa.core.model.data.StringData)2 R (org.odk.collect.android.R)2