Search in sources :

Example 1 with IntegerData

use of org.javarosa.core.model.data.IntegerData in project collect by opendatakit.

the class ExIntegerWidget method setBinaryData.

/**
 * Allows answer to be set externally in {@link FormEntryActivity}.
 */
@Override
public void setBinaryData(Object answer) {
    IntegerData integerData = ExternalAppsUtils.asIntegerData(answer);
    this.answer.setText(integerData == null ? null : integerData.getValue().toString());
}
Also used : IntegerData(org.javarosa.core.model.data.IntegerData)

Example 2 with IntegerData

use of org.javarosa.core.model.data.IntegerData in project collect by opendatakit.

the class RangeWidgetTest method getAnswerShouldReflectActualValueSetViaSeekBar.

@Test
public void getAnswerShouldReflectActualValueSetViaSeekBar() {
    W widget = getWidget();
    assertNull(widget.getAnswer());
    int progress = Math.abs(random.nextInt()) % widget.getElementCount();
    widget.onProgressChanged(widget.getSeekBar(), progress, true);
    BigDecimal actualValue;
    if (rangeStart.compareTo(rangeEnd) == -1) {
        actualValue = rangeStart.add(new BigDecimal(progress).multiply(rangeStep));
    } else {
        actualValue = rangeStart.subtract(new BigDecimal(progress).multiply(rangeStep));
    }
    IAnswerData answer = widget.getAnswer();
    IAnswerData compareTo;
    if (answer instanceof DecimalData) {
        compareTo = new DecimalData(actualValue.doubleValue());
    } else {
        compareTo = new IntegerData(actualValue.intValue());
    }
    assertEquals(answer.getDisplayText(), compareTo.getDisplayText());
}
Also used : IAnswerData(org.javarosa.core.model.data.IAnswerData) DecimalData(org.javarosa.core.model.data.DecimalData) IntegerData(org.javarosa.core.model.data.IntegerData) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 3 with IntegerData

use of org.javarosa.core.model.data.IntegerData in project javarosa by opendatakit.

the class QuestionDataElementTests method setUp.

public void setUp() throws Exception {
    super.setUp();
    stringData = new StringData("Answer Value");
    integerData = new IntegerData(4);
    stringReference = new IDataReference() {

        String reference = "stringValue";

        public Object getReference() {
            return reference;
        }

        public void setReference(Object reference) {
            this.reference = (String) reference;
        }

        /*
            public boolean referenceMatches(IDataReference reference) {
                return this.reference.equals(reference.getReference());
            }


            public IDataReference clone()  {
                IDataReference newReference = null;
                try {
                    newReference = (IDataReference)this.getClass().newInstance();
                } catch (InstantiationException e) {
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
                newReference.setReference(reference);
                return newReference;
            }
            */
        public void readExternal(DataInputStream in, PrototypeFactory pf) throws IOException, DeserializationException {
        }

        public void writeExternal(DataOutputStream out) throws IOException {
        }
    };
    integerReference = new IDataReference() {

        Integer intReference = new Integer(15);

        public Object getReference() {
            return intReference;
        }

        public void setReference(Object reference) {
            this.intReference = (Integer) reference;
        }

        /*
            public boolean referenceMatches(IDataReference reference) {
                return this.intReference.equals(reference.getReference());
            }


            public IDataReference clone()  {
                IDataReference newReference = null;
                try {
                    newReference = (IDataReference)this.getClass().newInstance();
                } catch (InstantiationException e) {
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
                newReference.setReference(intReference);
                return newReference;
            }
            */
        public void readExternal(DataInputStream in, PrototypeFactory pf) throws IOException, DeserializationException {
        }

        public void writeExternal(DataOutputStream out) throws IOException {
        }
    };
    intElement = new TreeElement("intElement");
    intElement.setValue(integerData);
    stringElement = new TreeElement(stringElementName);
    stringElement.setValue(stringData);
}
Also used : PrototypeFactory(org.javarosa.core.util.externalizable.PrototypeFactory) IDataReference(org.javarosa.core.model.IDataReference) DataOutputStream(java.io.DataOutputStream) IntegerData(org.javarosa.core.model.data.IntegerData) IOException(java.io.IOException) StringData(org.javarosa.core.model.data.StringData) DataInputStream(java.io.DataInputStream) DeserializationException(org.javarosa.core.util.externalizable.DeserializationException) TreeElement(org.javarosa.core.model.instance.TreeElement) AbstractTreeElement(org.javarosa.core.model.instance.AbstractTreeElement)

Example 4 with IntegerData

use of org.javarosa.core.model.data.IntegerData in project javarosa by opendatakit.

the class QuestionDataGroupTests method setUp.

public void setUp() throws Exception {
    super.setUp();
    stringData = new StringData("Answer Value");
    integerData = new IntegerData(4);
    stringReference = new IDataReference() {

        String reference = "stringValue";

        public Object getReference() {
            return reference;
        }

        public void setReference(Object reference) {
            this.reference = (String) reference;
        }

        /*
            public boolean referenceMatches(IDataReference reference) {
                return this.reference.equals(reference.getReference());
            }


            public IDataReference clone()  {
                IDataReference newReference = null;
                try {
                    newReference = (IDataReference)this.getClass().newInstance();
                } catch (InstantiationException e) {
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
                newReference.setReference(reference);
                return newReference;
            }
            */
        public void readExternal(DataInputStream in, PrototypeFactory pf) throws IOException, DeserializationException {
        }

        public void writeExternal(DataOutputStream out) throws IOException {
        }
    };
    integerReference = new IDataReference() {

        Integer intReference = new Integer(15);

        public Object getReference() {
            return intReference;
        }

        public void setReference(Object reference) {
            this.intReference = (Integer) reference;
        }

        /*
            public boolean referenceMatches(IDataReference reference) {
                return this.intReference.equals(reference.getReference());
            }


            public IDataReference clone()  {
                IDataReference newReference = null;
                try {
                    newReference = (IDataReference)this.getClass().newInstance();
                } catch (InstantiationException e) {
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
                newReference.setReference(intReference);
                return newReference;
            }
            */
        public void readExternal(DataInputStream in, PrototypeFactory pf) throws IOException, DeserializationException {
        }

        public void writeExternal(DataOutputStream out) throws IOException {
        }
    };
    intElement = new TreeElement("intElement");
    intElement.setValue(integerData);
    stringElement = new TreeElement(stringElementName);
    stringElement.setValue(stringData);
    group = new TreeElement(groupName);
}
Also used : PrototypeFactory(org.javarosa.core.util.externalizable.PrototypeFactory) IDataReference(org.javarosa.core.model.IDataReference) DataOutputStream(java.io.DataOutputStream) IntegerData(org.javarosa.core.model.data.IntegerData) IOException(java.io.IOException) StringData(org.javarosa.core.model.data.StringData) DataInputStream(java.io.DataInputStream) DeserializationException(org.javarosa.core.util.externalizable.DeserializationException) TreeElement(org.javarosa.core.model.instance.TreeElement) AbstractTreeElement(org.javarosa.core.model.instance.AbstractTreeElement)

Example 5 with IntegerData

use of org.javarosa.core.model.data.IntegerData in project javarosa by opendatakit.

the class XFormAnswerDataSerializerTest method setUp.

public void setUp() throws Exception {
    super.setUp();
    stringData = new StringData(stringDataValue);
    stringElement.setValue(stringData);
    integerData = new IntegerData(integerDataValue);
    intElement.setValue(integerData);
    dateData = new DateData(dateDataValue);
    dateElement.setValue(dateData);
    timeData = new TimeData(timeDataValue);
    timeElement.setValue(timeData);
    serializer = new XFormAnswerDataSerializer();
}
Also used : XFormAnswerDataSerializer(org.javarosa.xform.util.XFormAnswerDataSerializer) DateData(org.javarosa.core.model.data.DateData) TimeData(org.javarosa.core.model.data.TimeData) IntegerData(org.javarosa.core.model.data.IntegerData) StringData(org.javarosa.core.model.data.StringData)

Aggregations

IntegerData (org.javarosa.core.model.data.IntegerData)13 StringData (org.javarosa.core.model.data.StringData)7 DateData (org.javarosa.core.model.data.DateData)4 DecimalData (org.javarosa.core.model.data.DecimalData)4 TimeData (org.javarosa.core.model.data.TimeData)4 Date (java.util.Date)3 DateTimeData (org.javarosa.core.model.data.DateTimeData)3 LongData (org.javarosa.core.model.data.LongData)3 TreeElement (org.javarosa.core.model.instance.TreeElement)3 DataInputStream (java.io.DataInputStream)2 DataOutputStream (java.io.DataOutputStream)2 IOException (java.io.IOException)2 IDataReference (org.javarosa.core.model.IDataReference)2 BooleanData (org.javarosa.core.model.data.BooleanData)2 GeoPointData (org.javarosa.core.model.data.GeoPointData)2 GeoShapeData (org.javarosa.core.model.data.GeoShapeData)2 GeoTraceData (org.javarosa.core.model.data.GeoTraceData)2 IAnswerData (org.javarosa.core.model.data.IAnswerData)2 SelectMultiData (org.javarosa.core.model.data.SelectMultiData)2 SelectOneData (org.javarosa.core.model.data.SelectOneData)2