use of org.odk.collect.android.dao.ItemsetDao in project collect by opendatakit.
the class FormEntryPromptUtils method getAnswerText.
public static String getAnswerText(FormEntryPrompt fep, Context context, FormController formController) {
IAnswerData data = fep.getAnswerValue();
final String appearance = fep.getQuestion().getAppearanceAttr();
if (data instanceof SelectMultiData) {
StringBuilder b = new StringBuilder();
String sep = "";
for (Selection value : (List<Selection>) data.getValue()) {
b.append(sep);
sep = ", ";
b.append(fep.getSelectItemText(value));
}
return b.toString();
}
if (data instanceof DateTimeData) {
return DateTimeUtils.getDateTimeLabel((Date) data.getValue(), DateTimeUtils.getDatePickerDetails(appearance), true, context);
}
if (data instanceof DateData) {
return DateTimeUtils.getDateTimeLabel((Date) data.getValue(), DateTimeUtils.getDatePickerDetails(appearance), false, context);
}
if (data != null && appearance != null && appearance.contains("thousands-sep")) {
try {
final BigDecimal answerAsDecimal = new BigDecimal(fep.getAnswerText());
DecimalFormat df = new DecimalFormat();
df.setGroupingSize(3);
df.setGroupingUsed(true);
df.setMaximumFractionDigits(Integer.MAX_VALUE);
// Use . as decimal marker for consistency with DecimalWidget
DecimalFormatSymbols customFormat = new DecimalFormatSymbols();
customFormat.setDecimalSeparator('.');
if (df.getDecimalFormatSymbols().getGroupingSeparator() == '.') {
customFormat.setGroupingSeparator(' ');
}
df.setDecimalFormatSymbols(customFormat);
return df.format(answerAsDecimal);
} catch (NumberFormatException e) {
return fep.getAnswerText();
}
}
if (data != null && data.getValue() != null && fep.getDataType() == DATATYPE_TEXT && fep.getQuestion().getAdditionalAttribute(null, "query") != null) {
// ItemsetWidget
return new ItemsetDao().getItemLabel(fep.getAnswerValue().getDisplayText(), formController.getMediaFolder().getAbsolutePath(), formController.getLanguage());
}
return fep.getAnswerText();
}
Aggregations