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);
}
}
}
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)));
}
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)));
}
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)));
}
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());
}
Aggregations