Search in sources :

Example 26 with FormEntryPrompt

use of org.javarosa.form.api.FormEntryPrompt in project collect by opendatakit.

the class AudioWidgetTest method afterSetBinaryData_whenPositionOfClipChanges_updatesPosition.

@Test
public void afterSetBinaryData_whenPositionOfClipChanges_updatesPosition() throws Exception {
    FormEntryPrompt prompt = promptWithAnswer(null);
    File answerFile = questionMediaManager.addAnswerFile(File.createTempFile("blah", ".mp3"));
    Clip expectedClip = getExpectedClip(prompt, answerFile.getName());
    setupMediaPlayerDataSource(expectedClip.getURI(), 322450);
    AudioWidget widget = createWidget(prompt);
    widget.setData(answerFile);
    AudioControllerView audioController = widget.binding.audioPlayer.audioController;
    assertThat(audioController.binding.currentDuration.getText().toString(), is("00:00"));
    audioPlayer.setPosition(expectedClip.getClipID(), 42000);
    assertThat(audioController.binding.currentDuration.getText().toString(), is("00:42"));
}
Also used : Clip(org.odk.collect.audioclips.Clip) FormEntryPrompt(org.javarosa.form.api.FormEntryPrompt) AudioControllerView(org.odk.collect.android.audio.AudioControllerView) File(java.io.File) Test(org.junit.Test)

Example 27 with FormEntryPrompt

use of org.javarosa.form.api.FormEntryPrompt in project collect by opendatakit.

the class AudioWidgetTest method whenRecordingInProgress_updatesDuration.

@Test
public void whenRecordingInProgress_updatesDuration() {
    FormEntryPrompt prompt = promptWithAnswer(null);
    AudioWidget widget = createWidget(prompt);
    recordingRequester.setDuration(prompt.getIndex().toString(), 0);
    assertThat(widget.binding.audioPlayer.recordingDuration.getText(), is("00:00"));
    recordingRequester.setDuration(prompt.getIndex().toString(), 42000);
    assertThat(widget.binding.audioPlayer.recordingDuration.getText(), is("00:42"));
}
Also used : FormEntryPrompt(org.javarosa.form.api.FormEntryPrompt) Test(org.junit.Test)

Example 28 with FormEntryPrompt

use of org.javarosa.form.api.FormEntryPrompt in project collect by opendatakit.

the class AudioWidgetTest method clearAnswer_setsFileAsideForDeleting.

@Test
public void clearAnswer_setsFileAsideForDeleting() throws Exception {
    File answerFile = questionMediaManager.addAnswerFile(File.createTempFile("blah", ".mp3"));
    FormEntryPrompt prompt = promptWithAnswer(new StringData(answerFile.getName()));
    when(prompt.getIndex()).thenReturn(formIndex);
    AudioWidget widget = createWidget(prompt);
    widget.clearAnswer();
    assertThat(questionMediaManager.originalFiles.get("questionIndex"), equalTo(answerFile.getAbsolutePath()));
}
Also used : FormEntryPrompt(org.javarosa.form.api.FormEntryPrompt) StringData(org.javarosa.core.model.data.StringData) File(java.io.File) Test(org.junit.Test)

Example 29 with FormEntryPrompt

use of org.javarosa.form.api.FormEntryPrompt in project collect by opendatakit.

the class AudioWidgetTest method afterSetBinaryData_clickingPlayAndPause_playsAndPausesAudio.

@Test
public void afterSetBinaryData_clickingPlayAndPause_playsAndPausesAudio() throws Exception {
    FormEntryPrompt prompt = promptWithAnswer(null);
    AudioWidget widget = createWidget(prompt);
    File answerFile = questionMediaManager.addAnswerFile(File.createTempFile("blah", ".mp3"));
    Clip expectedClip = getExpectedClip(prompt, answerFile.getName());
    widget.setData(answerFile);
    AudioControllerView audioController = widget.binding.audioPlayer.audioController;
    assertThat(audioController.getVisibility(), is(VISIBLE));
    audioController.binding.play.performClick();
    assertThat(audioPlayer.getCurrentClip(), is(expectedClip));
    audioController.binding.play.performClick();
    assertThat(audioPlayer.getCurrentClip(), is(expectedClip));
    assertThat(audioPlayer.isPaused(), is(true));
    audioController.binding.play.performClick();
    assertThat(audioPlayer.getCurrentClip(), is(expectedClip));
    assertThat(audioPlayer.isPaused(), is(false));
}
Also used : Clip(org.odk.collect.audioclips.Clip) FormEntryPrompt(org.javarosa.form.api.FormEntryPrompt) AudioControllerView(org.odk.collect.android.audio.AudioControllerView) File(java.io.File) Test(org.junit.Test)

Example 30 with FormEntryPrompt

use of org.javarosa.form.api.FormEntryPrompt in project collect by opendatakit.

the class AudioWidgetTest method whenWidgetIsNew_chooseSoundButtonIsNotShown.

@Test
public void whenWidgetIsNew_chooseSoundButtonIsNotShown() {
    FormEntryPrompt prompt = promptWithReadOnly();
    when(prompt.getAppearanceHint()).thenReturn(Appearances.NEW);
    AudioWidget widget = createWidget(prompt);
    assertThat(widget.binding.chooseButton.getVisibility(), equalTo(GONE));
}
Also used : FormEntryPrompt(org.javarosa.form.api.FormEntryPrompt) Test(org.junit.Test)

Aggregations

FormEntryPrompt (org.javarosa.form.api.FormEntryPrompt)114 Test (org.junit.Test)92 MockFormEntryPromptBuilder (org.odk.collect.android.support.MockFormEntryPromptBuilder)45 Clip (org.odk.collect.audioclips.Clip)13 FormIndex (org.javarosa.core.model.FormIndex)10 File (java.io.File)9 SelectChoice (org.javarosa.core.model.SelectChoice)7 StringData (org.javarosa.core.model.data.StringData)7 IFormElement (org.javarosa.core.model.IFormElement)5 QuestionDef (org.javarosa.core.model.QuestionDef)5 FormController (org.odk.collect.android.javarosawrapper.FormController)5 GroupDef (org.javarosa.core.model.GroupDef)4 QuestionDetails (org.odk.collect.android.formentry.questions.QuestionDetails)4 DatePickerDetails (org.odk.collect.android.logic.DatePickerDetails)4 ArrayList (java.util.ArrayList)3 DateData (org.javarosa.core.model.data.DateData)3 IAnswerData (org.javarosa.core.model.data.IAnswerData)3 TreeReference (org.javarosa.core.model.instance.TreeReference)3 LocalDateTime (org.joda.time.LocalDateTime)3 AudioControllerView (org.odk.collect.android.audio.AudioControllerView)3