use of org.odk.collect.android.widgets.interfaces.WidgetDataReceiver in project collect by opendatakit.
the class FormEntryActivity method setWidgetData.
public void setWidgetData(Object data) {
ODKView currentViewIfODKView = getCurrentViewIfODKView();
if (currentViewIfODKView != null) {
boolean set = false;
for (QuestionWidget widget : currentViewIfODKView.getWidgets()) {
if (widget instanceof WidgetDataReceiver) {
if (waitingForDataRegistry.isWaitingForData(widget.getFormEntryPrompt().getIndex())) {
try {
((WidgetDataReceiver) widget).setData(data);
waitingForDataRegistry.cancelWaitingForData();
} catch (Exception e) {
Timber.e(e);
ToastUtils.showLongToast(this, currentViewIfODKView.getContext().getString(R.string.error_attaching_binary_file, e.getMessage()));
}
set = true;
break;
}
}
}
if (!set) {
Timber.e("Attempting to return data to a widget or set of widgets not looking for data");
}
}
}
use of org.odk.collect.android.widgets.interfaces.WidgetDataReceiver in project collect by opendatakit.
the class BinaryWidgetTest method settingANewAnswerShouldRemoveTheOldAnswer.
@Test
public void settingANewAnswerShouldRemoveTheOldAnswer() {
A answer = getInitialAnswer();
when(formEntryPrompt.getAnswerText()).thenReturn(answer.getDisplayText());
W widget = getSpyWidget();
A newAnswer = getNextAnswer();
Object binaryData = createBinaryData(newAnswer);
((WidgetDataReceiver) widget).setData(binaryData);
IAnswerData answerData = widget.getAnswer();
assertNotNull(answerData);
assertEquals(answerData.getDisplayText(), newAnswer.getDisplayText());
}
use of org.odk.collect.android.widgets.interfaces.WidgetDataReceiver in project collect by opendatakit.
the class BinaryWidgetTest method getAnswerShouldReturnCorrectAnswerAfterBeingSet.
@Test
public void getAnswerShouldReturnCorrectAnswerAfterBeingSet() {
W widget = getSpyWidget();
assertNull(widget.getAnswer());
A answer = getNextAnswer();
Object binaryData = createBinaryData(answer);
((WidgetDataReceiver) widget).setData(binaryData);
IAnswerData answerData = widget.getAnswer();
assertNotNull(answerData);
assertEquals(answerData.getDisplayText(), answer.getDisplayText());
}
Aggregations