in Android/app/src/main/java/com/harvard/studyappmodule/activitybuilder/StepsBuilder.java [681:1041]
private static ArrayList<QuestionStep> getformquestion(
Context context, RealmList<Steps> formsteps, Realm realm) {
ArrayList<QuestionStep> formquesteps = new ArrayList<>();
for (int i = 0; i < formsteps.size(); i++) {
if (!formsteps.get(i).getKey().contains("_addMoreEnabled")) {
switch (formsteps.get(i).getResultType()) {
case "scale":
ScaleAnswerFormat scaleFormat =
new ScaleAnswerFormat(
ChoiceAnswerFormatCustom.CustomAnswerStyle.Scale,
formsteps.get(i).getFormat().getStep(),
formsteps.get(i).getFormat().getMinValue(),
formsteps.get(i).getFormat().getMaxValue(),
formsteps.get(i).getFormat().isVertical(),
formsteps.get(i).getFormat().getMaxDesc(),
formsteps.get(i).getFormat().getMinDesc(),
formsteps.get(i).getFormat().getMaxImage(),
formsteps.get(i).getFormat().getMinImage(),
formsteps.get(i).getFormat().getDefaultValue());
QuestionStepCustom scaleStep =
new QuestionStepCustom(
formsteps.get(i).getKey(),
context.getResources().getString(R.string.survey),
scaleFormat);
scaleStep.setAnswerFormat1(scaleFormat);
scaleStep.setTitle(formsteps.get(i).getTitle());
scaleStep.setText(formsteps.get(i).getText().replaceAll("(\r\n|\n)", "<br />"));
scaleStep.setOptional(formsteps.get(i).isSkippable());
formquesteps.add(scaleStep);
break;
case "continuousScale":
ContinousScaleAnswerFormat continousScaleFormat =
new ContinousScaleAnswerFormat(
ChoiceAnswerFormatCustom.CustomAnswerStyle.Scale,
formsteps.get(i).getFormat().getMaxFractionDigits(),
formsteps.get(i).getFormat().getMinValue(),
formsteps.get(i).getFormat().getMaxValue(),
formsteps.get(i).getFormat().isVertical(),
formsteps.get(i).getFormat().getMaxDesc(),
formsteps.get(i).getFormat().getMinDesc(),
formsteps.get(i).getFormat().getMaxImage(),
formsteps.get(i).getFormat().getMinImage(),
formsteps.get(i).getFormat().getDefaultValue());
QuestionStepCustom continousscaleStep =
new QuestionStepCustom(
formsteps.get(i).getKey(),
context.getResources().getString(R.string.survey),
continousScaleFormat);
continousscaleStep.setAnswerFormat1(continousScaleFormat);
continousscaleStep.setTitle(formsteps.get(i).getTitle());
continousscaleStep.setText(
formsteps.get(i).getText().replaceAll("(\r\n|\n)", "<br />"));
continousscaleStep.setOptional(formsteps.get(i).isSkippable());
formquesteps.add(continousscaleStep);
break;
case "textScale":
ChoiceTextExclusive[] textScaleChoices =
new ChoiceTextExclusive[formsteps.get(i).getFormat().getTextChoices().size()];
for (int j = 0; j < formsteps.get(i).getFormat().getTextChoices().size(); j++) {
textScaleChoices[j] =
new ChoiceTextExclusive(
formsteps.get(i).getFormat().getTextChoices().get(j).getText(),
formsteps.get(i).getFormat().getTextChoices().get(j).getValue(),
formsteps.get(i).getFormat().getTextChoices().get(j).getDetail(),
formsteps.get(i).getFormat().getTextChoices().get(j).isExclusive(),
null);
}
ScaleTextAnswerFormat scaleTextFormat =
new ScaleTextAnswerFormat(
ChoiceAnswerFormatCustom.CustomAnswerStyle.ScaleText,
textScaleChoices,
formsteps.get(i).getFormat().getDefaultValue(),
formsteps.get(i).getFormat().isVertical());
QuestionStepCustom scaleTextStep =
new QuestionStepCustom(
formsteps.get(i).getKey(),
context.getResources().getString(R.string.survey),
scaleTextFormat);
scaleTextStep.setAnswerFormat1(scaleTextFormat);
scaleTextStep.setTitle(formsteps.get(i).getTitle());
scaleTextStep.setText(formsteps.get(i).getText().replaceAll("(\r\n|\n)", "<br />"));
scaleTextStep.setOptional(formsteps.get(i).isSkippable());
formquesteps.add(scaleTextStep);
break;
case "valuePicker":
QuestionStepCustom valuepicker = new QuestionStepCustom(formsteps.get(i).getKey());
Choice[] valuechoice = new Choice[formsteps.get(i).getFormat().getTextChoices().size()];
for (int j = 0; j < formsteps.get(i).getFormat().getTextChoices().size(); j++) {
valuechoice[j] =
new Choice(
formsteps.get(i).getFormat().getTextChoices().get(j).getText(),
formsteps.get(i).getFormat().getTextChoices().get(j).getValue(),
formsteps.get(i).getFormat().getTextChoices().get(j).getDetail());
}
ChoiceAnswerFormatCustom pickerformat =
new ChoiceAnswerFormatCustom(
AnswerFormatCustom.CustomAnswerStyle.valuePicker, valuepicker, valuechoice);
valuepicker.setTitle(formsteps.get(i).getTitle());
valuepicker.setText(formsteps.get(i).getText().replaceAll("(\r\n|\n)", "<br />"));
valuepicker.setAnswerFormat1(pickerformat);
valuepicker.setOptional(formsteps.get(i).isSkippable());
formquesteps.add(valuepicker);
break;
case "imageChoice":
QuestionStepCustom multichoiceStep = new QuestionStepCustom(formsteps.get(i).getKey());
ChoiceCustomImage[] choicechoices =
new ChoiceCustomImage[formsteps.get(i).getFormat().getImageChoices().size()];
for (int j = 0; j < formsteps.get(i).getFormat().getImageChoices().size(); j++) {
choicechoices[j] =
new ChoiceCustomImage(
formsteps.get(i).getFormat().getImageChoices().get(j).getText(),
formsteps.get(i).getFormat().getImageChoices().get(j).getValue(),
formsteps.get(i).getFormat().getImageChoices().get(j).getImage(),
formsteps.get(i).getFormat().getImageChoices().get(j).getSelectedImage());
}
MultiChoiceImageAnswerFormat multichoiceFormat =
new MultiChoiceImageAnswerFormat(
ChoiceAnswerFormatCustom.CustomAnswerStyle.MultipleImageChoice, choicechoices);
multichoiceStep.setTitle(formsteps.get(i).getTitle());
multichoiceStep.setText(formsteps.get(i).getText().replaceAll("(\r\n|\n)", "<br />"));
multichoiceStep.setAnswerFormat1(multichoiceFormat);
multichoiceStep.setOptional(formsteps.get(i).isSkippable());
formquesteps.add(multichoiceStep);
break;
case "textChoice":
if (formsteps.get(i).getFormat().getSelectionStyle().equalsIgnoreCase("Single")) {
QuestionStepCustom multiStep = new QuestionStepCustom(formsteps.get(i).getKey());
ChoiceText[] choices =
new ChoiceText[formsteps.get(i).getFormat().getTextChoices().size()];
for (int j = 0; j < formsteps.get(i).getFormat().getTextChoices().size(); j++) {
choices[j] =
new ChoiceText(
formsteps.get(i).getFormat().getTextChoices().get(j).getText(),
formsteps.get(i).getFormat().getTextChoices().get(j).getValue(),
formsteps.get(i).getFormat().getTextChoices().get(j).getDetail(),
formsteps.get(i).getFormat().getTextChoices().get(j).getOther());
}
SingleChoiceTextAnswerFormat choiceAnswerFormat =
new SingleChoiceTextAnswerFormat(
AnswerFormatCustom.CustomAnswerStyle.SingleTextChoice, choices);
multiStep.setTitle(formsteps.get(i).getTitle());
multiStep.setText(formsteps.get(i).getText().replaceAll("(\r\n|\n)", "<br />"));
multiStep.setAnswerFormat1(choiceAnswerFormat);
multiStep.setOptional(formsteps.get(i).isSkippable());
formquesteps.add(multiStep);
} else {
ChoiceTextExclusive[] choices =
new ChoiceTextExclusive[formsteps.get(i).getFormat().getTextChoices().size()];
for (int j = 0; j < formsteps.get(i).getFormat().getTextChoices().size(); j++) {
choices[j] =
new ChoiceTextExclusive(
formsteps.get(i).getFormat().getTextChoices().get(j).getText(),
formsteps.get(i).getFormat().getTextChoices().get(j).getValue(),
formsteps.get(i).getFormat().getTextChoices().get(j).getDetail(),
formsteps.get(i).getFormat().getTextChoices().get(j).isExclusive(),
formsteps.get(i).getFormat().getTextChoices().get(j).getOther());
}
MultiChoiceTextAnswerFormat choiceAnswerFormat =
new MultiChoiceTextAnswerFormat(
AnswerFormatCustom.CustomAnswerStyle.MultipleTextChoice, choices);
QuestionStepCustom multiStep = new QuestionStepCustom(formsteps.get(i).getKey());
multiStep.setTitle(formsteps.get(i).getTitle());
multiStep.setText(formsteps.get(i).getText().replaceAll("(\r\n|\n)", "<br />"));
multiStep.setAnswerFormat1(choiceAnswerFormat);
multiStep.setOptional(formsteps.get(i).isSkippable());
formquesteps.add(multiStep);
}
break;
case "boolean":
QuestionStep booleanStep = new QuestionStep(formsteps.get(i).getKey());
booleanStep.setTitle(formsteps.get(i).getTitle());
booleanStep.setText(formsteps.get(i).getText().replaceAll("(\r\n|\n)", "<br />"));
booleanStep.setAnswerFormat(
new BooleanAnswerFormat(
context.getResources().getString(R.string.true_text),
context.getResources().getString(R.string.false_text)));
booleanStep.setOptional(formsteps.get(i).isSkippable());
formquesteps.add(booleanStep);
break;
case "numeric":
ChoiceAnswerFormatCustom answerFormat;
if (formsteps.get(i).getFormat().getStyle().equalsIgnoreCase("Integer")) {
if (formsteps.get(i).getFormat().getMinValue() == 0
&& formsteps.get(i).getFormat().getMaxValue() == 0) {
realm.beginTransaction();
formsteps.get(i).getFormat().setMaxValue(Integer.MAX_VALUE);
realm.commitTransaction();
}
answerFormat =
new IntegerUnitAnswerFormat(
formsteps.get(i).getFormat().getMinValue(),
formsteps.get(i).getFormat().getMaxValue(),
formsteps.get(i).getFormat().getUnit());
} else {
if (formsteps.get(i).getFormat().getMinValue() == 0
&& formsteps.get(i).getFormat().getMaxValue() == 0) {
answerFormat =
new DecimalUnitAnswerFormat(
formsteps.get(i).getFormat().getMinValue(),
Float.MAX_VALUE,
formsteps.get(i).getFormat().getUnit());
} else {
answerFormat =
new DecimalUnitAnswerFormat(
formsteps.get(i).getFormat().getMinValue(),
formsteps.get(i).getFormat().getMaxValue(),
formsteps.get(i).getFormat().getUnit());
}
}
QuestionStepCustom numericItem =
new QuestionStepCustom(
formsteps.get(i).getKey(), formsteps.get(i).getTitle(), answerFormat);
numericItem.setText(formsteps.get(i).getText().replaceAll("(\r\n|\n)", "<br />"));
numericItem.setPlaceholder(formsteps.get(i).getFormat().getPlaceholder());
numericItem.setAnswerFormat1(answerFormat);
numericItem.setOptional(formsteps.get(i).isSkippable());
formquesteps.add(numericItem);
break;
case "timeOfDay":
QuestionStepCustom timeOfDayStep =
new QuestionStepCustom(
formsteps.get(i).getKey(), context.getResources().getString(R.string.survey));
DateAnswerformatCustom customChoiceAnswerFormat =
new DateAnswerformatCustom(AnswerFormatCustom.DateAnswerStyle.TimeOfDay);
timeOfDayStep.setAnswerFormat1(customChoiceAnswerFormat);
timeOfDayStep.setPlaceholder(context.getResources().getString(R.string.enter_time));
timeOfDayStep.setTitle(formsteps.get(i).getTitle());
timeOfDayStep.setText(formsteps.get(i).getText().replaceAll("(\r\n|\n)", "<br />"));
timeOfDayStep.setOptional(formsteps.get(i).isSkippable());
formquesteps.add(timeOfDayStep);
break;
case "date":
SimpleDateFormat simpleDateFormat = AppController.getDateFormatForApi();
Date mindate = null;
Date maxdate = null;
Date defaultval = null;
try {
mindate = simpleDateFormat.parse(formsteps.get(i).getFormat().getMinDate());
maxdate = simpleDateFormat.parse(formsteps.get(i).getFormat().getMaxDate());
if (formsteps.get(i).getFormat().getDefaultValue() != null
&& !formsteps.get(i).getFormat().getDefaultValue().equalsIgnoreCase("")) {
defaultval = simpleDateFormat.parse(formsteps.get(i).getFormat().getDefaultValue());
} else {
defaultval = Calendar.getInstance().getTime();
}
} catch (Exception e) {
Logger.log(e);
}
DateAnswerformatCustom dateFormat;
if (formsteps.get(i).getFormat().getStyle().equalsIgnoreCase("Date")) {
if (maxdate != null) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(maxdate);
calendar.set(Calendar.HOUR, 23);
calendar.set(Calendar.MINUTE, 59);
calendar.set(Calendar.SECOND, 59);
maxdate = calendar.getTime();
}
dateFormat =
new DateAnswerformatCustom(
AnswerFormatCustom.DateAnswerStyle.Date,
defaultval,
mindate,
maxdate,
formsteps.get(i).getFormat().getDateRange());
} else {
dateFormat =
new DateAnswerformatCustom(
AnswerFormatCustom.DateAnswerStyle.DateAndTime,
defaultval,
mindate,
maxdate,
formsteps.get(i).getFormat().getDateRange());
}
QuestionStepCustom dateFormatItem =
new QuestionStepCustom(
formsteps.get(i).getKey(), formsteps.get(i).getTitle(), dateFormat);
dateFormatItem.setText(formsteps.get(i).getText().replaceAll("(\r\n|\n)", "<br />"));
dateFormatItem.setAnswerFormat1(dateFormat);
dateFormatItem.setOptional(formsteps.get(i).isSkippable());
formquesteps.add(dateFormatItem);
break;
case "text":
TextAnswerFormatRegex textAnswerFormat =
new TextAnswerFormatRegex(
formsteps.get(i).getFormat().getMaxLength(),
formsteps.get(i).getFormat().getValidationRegex(),
formsteps.get(i).getFormat().getInvalidMessage());
textAnswerFormat.setIsMultipleLines(formsteps.get(i).getFormat().isMultipleLines());
QuestionStepCustom textstep =
new QuestionStepCustom(
formsteps.get(i).getKey(), formsteps.get(i).getTitle(), textAnswerFormat);
textstep.setText(formsteps.get(i).getText().replaceAll("(\r\n|\n)", "<br />"));
textstep.setPlaceholder(formsteps.get(i).getFormat().getPlaceholder());
textstep.setAnswerFormat1(textAnswerFormat);
textstep.setOptional(formsteps.get(i).isSkippable());
formquesteps.add(textstep);
break;
case "email":
EmailAnswerFormatCustom emailformat = new EmailAnswerFormatCustom(255);
QuestionStepCustom emailstep =
new QuestionStepCustom(
formsteps.get(i).getKey(), formsteps.get(i).getTitle(), emailformat);
emailstep.setText(formsteps.get(i).getText().replaceAll("(\r\n|\n)", "<br />"));
emailstep.setPlaceholder(formsteps.get(i).getFormat().getPlaceholder());
emailstep.setOptional(formsteps.get(i).isSkippable());
formquesteps.add(emailstep);
break;
case "timeInterval":
QuestionStepCustom timeIntervalStep =
new QuestionStepCustom(
formsteps.get(i).getKey(), context.getResources().getString(R.string.survey));
TimeIntervalAnswerFormat timeIntervalAnswerFormat =
new TimeIntervalAnswerFormat(
ChoiceAnswerFormatCustom.CustomAnswerStyle.TimeInterval,
formsteps.get(i).getFormat().getStep(),
formsteps.get(i).getFormat().getDefaultValue());
timeIntervalStep.setAnswerFormat1(timeIntervalAnswerFormat);
timeIntervalStep.setTitle(formsteps.get(i).getTitle());
timeIntervalStep.setText(formsteps.get(i).getText().replaceAll("(\r\n|\n)", "<br />"));
timeIntervalStep.setOptional(formsteps.get(i).isSkippable());
formquesteps.add(timeIntervalStep);
break;
case "height":
QuestionStepCustom heightStep =
new QuestionStepCustom(
formsteps.get(i).getKey(), context.getResources().getString(R.string.survey));
HeightAnswerFormat heightAnswerFormat =
new HeightAnswerFormat(
ChoiceAnswerFormatCustom.CustomAnswerStyle.Height,
formsteps.get(i).getFormat().getPlaceholder(),
formsteps.get(i).getFormat().getMeasurementSystem());
heightStep.setAnswerFormat1(heightAnswerFormat);
heightStep.setTitle(formsteps.get(i).getTitle());
heightStep.setText(formsteps.get(i).getText().replaceAll("(\r\n|\n)", "<br />"));
heightStep.setOptional(formsteps.get(i).isSkippable());
formquesteps.add(heightStep);
break;
case "location":
QuestionStepCustom locationStep =
new QuestionStepCustom(
formsteps.get(i).getKey(), context.getResources().getString(R.string.survey));
LocationAnswerFormat locationAnswerFormat =
new LocationAnswerFormat(
ChoiceAnswerFormatCustom.CustomAnswerStyle.Location,
formsteps.get(i).getFormat().isUseCurrentLocation());
locationStep.setAnswerFormat1(locationAnswerFormat);
locationStep.setPlaceholder(context.getResources().getString(R.string.enter_location));
locationStep.setTitle(formsteps.get(i).getTitle());
locationStep.setText(formsteps.get(i).getText().replaceAll("(\r\n|\n)", "<br />"));
locationStep.setOptional(formsteps.get(i).isSkippable());
formquesteps.add(locationStep);
break;
}
}
}
return formquesteps;
}