Search in sources :

Example 1 with WidgetDataReceiver

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");
        }
    }
}
Also used : ODKView(org.odk.collect.android.formentry.ODKView) WidgetDataReceiver(org.odk.collect.android.widgets.interfaces.WidgetDataReceiver) QuestionWidget(org.odk.collect.android.widgets.QuestionWidget) RepeatsInFieldListException(org.odk.collect.android.javarosawrapper.RepeatsInFieldListException) JavaRosaException(org.odk.collect.android.exception.JavaRosaException)

Example 2 with WidgetDataReceiver

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());
}
Also used : IAnswerData(org.javarosa.core.model.data.IAnswerData) WidgetDataReceiver(org.odk.collect.android.widgets.interfaces.WidgetDataReceiver) Test(org.junit.Test)

Example 3 with WidgetDataReceiver

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());
}
Also used : IAnswerData(org.javarosa.core.model.data.IAnswerData) WidgetDataReceiver(org.odk.collect.android.widgets.interfaces.WidgetDataReceiver) Test(org.junit.Test)

Aggregations

WidgetDataReceiver (org.odk.collect.android.widgets.interfaces.WidgetDataReceiver)3 IAnswerData (org.javarosa.core.model.data.IAnswerData)2 Test (org.junit.Test)2 JavaRosaException (org.odk.collect.android.exception.JavaRosaException)1 ODKView (org.odk.collect.android.formentry.ODKView)1 RepeatsInFieldListException (org.odk.collect.android.javarosawrapper.RepeatsInFieldListException)1 QuestionWidget (org.odk.collect.android.widgets.QuestionWidget)1