Search in sources :

Example 71 with FormEntryPrompt

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

the class FormEntryActivity method showView.

/**
 * Displays the View specified by the parameter 'next', animating both the
 * current view and next appropriately given the AnimationType. Also updates
 * the progress bar.
 */
public void showView(View next, AnimationType from) {
    invalidateOptionsMenu();
    // disable notifications...
    if (inAnimation != null) {
        inAnimation.setAnimationListener(null);
    }
    if (outAnimation != null) {
        outAnimation.setAnimationListener(null);
    }
    // by createView()
    switch(from) {
        case RIGHT:
            inAnimation = loadAnimation(this, R.anim.push_left_in);
            outAnimation = loadAnimation(this, R.anim.push_left_out);
            // if animation is left or right then it was a swipe, and we want to re-save on
            // entry
            autoSaved = false;
            break;
        case LEFT:
            inAnimation = loadAnimation(this, R.anim.push_right_in);
            outAnimation = loadAnimation(this, R.anim.push_right_out);
            autoSaved = false;
            break;
        case FADE:
            inAnimation = loadAnimation(this, R.anim.fade_in);
            outAnimation = loadAnimation(this, R.anim.fade_out);
            break;
    }
    // complete setup for animations...
    inAnimation.setAnimationListener(this);
    outAnimation.setAnimationListener(this);
    if (!areAnimationsEnabled(this)) {
        inAnimation.setDuration(0);
        outAnimation.setDuration(0);
    }
    // drop keyboard before transition...
    if (currentView != null) {
        softKeyboardController.hideSoftKeyboard(currentView);
    }
    RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    // adjust which view is in the layout container...
    View staleView = currentView;
    currentView = next;
    swipeHandler.setOdkView(getCurrentViewIfODKView());
    questionHolder.addView(currentView, lp);
    animationCompletionSet = 0;
    if (staleView != null) {
        // start OutAnimation for transition...
        staleView.startAnimation(outAnimation);
        // and remove the old view (MUST occur after start of animation!!!)
        questionHolder.removeView(staleView);
    } else {
        animationCompletionSet = 2;
    }
    // start InAnimation for transition...
    currentView.startAnimation(inAnimation);
    FormController formController = getFormController();
    if (formController.getEvent() == FormEntryController.EVENT_QUESTION || formController.getEvent() == FormEntryController.EVENT_GROUP || formController.getEvent() == FormEntryController.EVENT_REPEAT) {
        try {
            FormEntryPrompt[] prompts = getFormController().getQuestionPrompts();
            for (FormEntryPrompt p : prompts) {
                List<TreeElement> attrs = p.getBindAttributes();
                for (int i = 0; i < attrs.size(); i++) {
                    if (!autoSaved && "saveIncomplete".equals(attrs.get(i).getName())) {
                        analytics.logEvent(SAVE_INCOMPLETE, "saveIncomplete", AnalyticsUtils.getFormHash(Collect.getInstance().getFormController()));
                        saveForm(false, false, null, false);
                        autoSaved = true;
                    }
                }
            }
        } catch (RepeatsInFieldListException e) {
            createErrorDialog(e.getMessage(), false);
        }
    }
}
Also used : FormController(org.odk.collect.android.javarosawrapper.FormController) LayoutParams(android.view.ViewGroup.LayoutParams) FormEntryPrompt(org.javarosa.form.api.FormEntryPrompt) RepeatsInFieldListException(org.odk.collect.android.javarosawrapper.RepeatsInFieldListException) RelativeLayout(android.widget.RelativeLayout) ODKView(org.odk.collect.android.formentry.ODKView) FormEndView(org.odk.collect.android.formentry.FormEndView) View(android.view.View) WebView(android.webkit.WebView) AudioControllerView(org.odk.collect.android.audio.AudioControllerView) TextView(android.widget.TextView) FailedConstraint(org.odk.collect.android.javarosawrapper.FormController.FailedConstraint) TreeElement(org.javarosa.core.model.instance.TreeElement)

Example 72 with FormEntryPrompt

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

the class PromptAutoplayerTest method whenPromptHasAutoplayAudio_butNoAudioURI_andIsSelectOne_playsAllSelectAudioInOrder.

@Test
public void whenPromptHasAutoplayAudio_butNoAudioURI_andIsSelectOne_playsAllSelectAudioInOrder() {
    FormEntryPrompt prompt = new MockFormEntryPromptBuilder().withControlType(Constants.CONTROL_SELECT_ONE).withAdditionalAttribute("autoplay", "audio").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();
    assertThat(autoplayer.autoplayIfNeeded(prompt), equalTo(true));
    verify(audioHelper).playInOrder(asList(new Clip(prompt.getIndex().toString() + " 0", REFERENCES.get(0).second), new Clip(prompt.getIndex().toString() + " 1", REFERENCES.get(1).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 73 with FormEntryPrompt

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

the class PromptAutoplayerTest method whenPromptHasAutoplayAudio_andIsSelectMultiple_playsAllAudioInOrder.

@Test
public void whenPromptHasAutoplayAudio_andIsSelectMultiple_playsAllAudioInOrder() {
    FormEntryPrompt prompt = new MockFormEntryPromptBuilder().withControlType(Constants.CONTROL_SELECT_MULTI).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), new Clip(prompt.getIndex().toString() + " 0", REFERENCES.get(1).second), new Clip(prompt.getIndex().toString() + " 1", REFERENCES.get(2).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 74 with FormEntryPrompt

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

the class PromptAutoplayerTest method whenPromptHasAutoplayAudio_withDifferentCapitalization_playsAudio.

@Test
public void whenPromptHasAutoplayAudio_withDifferentCapitalization_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 75 with FormEntryPrompt

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

the class PromptAutoplayerTest method whenPromptHasAutoplayAudio_butNoAudioURI_returnsFalse.

@Test
public void whenPromptHasAutoplayAudio_butNoAudioURI_returnsFalse() {
    FormEntryPrompt prompt = new MockFormEntryPromptBuilder().withAudioURI(null).withAdditionalAttribute("autoplay", "audio").build();
    assertThat(autoplayer.autoplayIfNeeded(prompt), equalTo(false));
    verify(audioHelper, never()).playInOrder(any());
}
Also used : FormEntryPrompt(org.javarosa.form.api.FormEntryPrompt) MockFormEntryPromptBuilder(org.odk.collect.android.support.MockFormEntryPromptBuilder) 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