use of org.eyeseetea.malariacare.views.question.IMultiQuestionView in project pictureapp by EyeSeeTea.
the class DynamicTabAdapter method initializeNavigationButtons.
private void initializeNavigationButtons(View navigationButtonsHolder) {
ImageButton button = (ImageButton) navigationButtonsHolder.findViewById(R.id.next_btn);
((LinearLayout) button.getParent()).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (isClicked) {
Log.d(TAG, "onClick ignored to avoid double click");
return;
}
Log.d(TAG, "onClicked");
isClicked = true;
boolean questionsWithError = false;
for (IMultiQuestionView multiquestionView : mMultiQuestionViews) {
if (((CommonQuestionView) multiquestionView).isActive() && multiquestionView.hasError()) {
questionsWithError = true;
break;
}
}
Log.d(TAG, "Questions with failed validation " + failedValidations);
if (failedValidations == 0 && !questionsWithError) {
TableRow currentRow = (TableRow) tableLayout.getChildAt(0);
if (!readOnly && currentRow != null && currentRow.getChildAt(0) instanceof ImageRadioButtonSingleQuestionView) {
navigationController.isMovingToForward = true;
ImageRadioButtonSingleQuestionView imageRadioButtonSingleQuestionView = (ImageRadioButtonSingleQuestionView) currentRow.getChildAt(0);
ImageRadioButtonOption selectedOptionView = imageRadioButtonSingleQuestionView.getSelectedOptionView();
if (selectedOptionView != null) {
final Question question = navigationController.getCurrentQuestion();
Option selectedOption = selectedOptionView.getOption();
Question counterQuestion = question.findCounterByOption(selectedOption);
if ((mReviewMode && isCounterValueEqualToMax(question, selectedOption))) {
saveOptionValue(selectedOptionView, selectedOptionView.getOption(), question, true);
} else if (counterQuestion != null) {
showConfirmCounter(selectedOptionView, selectedOptionView.getOption(), question, counterQuestion);
} else {
finishOrNext();
}
} else {
isClicked = false;
}
} else {
finishOrNext();
}
} else if (navigationController.getCurrentQuestion().hasCompulsoryNotAnswered() || mDynamicTabAdapterStrategy.isMultiQuestionByVariant(navigationController.getCurrentTab().getType())) {
UIMessagesStrategy.getInstance().showCompulsoryUnansweredToast();
isClicked = false;
return;
} else {
isClicked = false;
}
}
});
button = (ImageButton) navigationButtonsHolder.findViewById(R.id.back_btn);
// Save the numberpicker value in the DB, and continue to the next screen.
((LinearLayout) button.getParent()).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
previous();
}
});
}
use of org.eyeseetea.malariacare.views.question.IMultiQuestionView in project pictureapp by EyeSeeTea.
the class DynamicTabAdapter method renderQuestion.
public void renderQuestion(View rowView, int tabType, Question screenQuestion) {
TableRow tableRow;
IQuestionViewFactory questionViewFactory;
questionViewFactory = (Tab.isMultiQuestionTab(tabType) || mDynamicTabAdapterStrategy.isMultiQuestionByVariant(tabType)) ? new MultiQuestionViewFactory() : new SingleQuestionViewFactory();
// Se get the value from Session
int visibility = View.GONE;
Survey survey = new SurveyFragmentStrategy().getRenderSurvey(screenQuestion);
if (!screenQuestion.isHiddenBySurveyAndHeader(survey) || !Tab.isMultiQuestionTab(tabType)) {
visibility = View.VISIBLE;
}
Value value = screenQuestion.getValueBySession();
tableRow = new TableRow(context);
IQuestionView questionView = questionViewFactory.getView(context, screenQuestion.getOutput());
if (questionView != null) {
if (questionView instanceof IMultiQuestionView) {
mMultiQuestionViews.add((IMultiQuestionView) questionView);
((IMultiQuestionView) questionView).setHeader(Utils.getInternationalizedString(screenQuestion.getForm_name()));
}
addTagQuestion(screenQuestion, (View) questionView);
configureLayoutParams(tabType, tableRow, (LinearLayout) questionView);
questionView.setHelpText(Utils.getInternationalizedString(screenQuestion.getHelp_text()));
questionView.setEnabled(!readOnly);
if (questionView instanceof IImageQuestionView) {
((IImageQuestionView) questionView).setImage(screenQuestion.getInternationalizedPath());
}
mDynamicTabAdapterStrategy.renderParticularSurvey(screenQuestion, survey, questionView);
if (questionView instanceof AOptionQuestionView) {
((AOptionQuestionView) questionView).setQuestion(screenQuestion);
List<Option> options = screenQuestion.getAnswer().getOptions();
((AOptionQuestionView) questionView).setOptions(options);
}
mDynamicTabAdapterStrategy.instanceOfSingleQuestion(questionView, screenQuestion);
if (!readOnly) {
configureAnswerChangedListener(questionView);
mDynamicTabAdapterStrategy.configureAnswerChangedListener(this, questionView);
}
if (reloadingQuestionFromInvalidOption) {
reloadingQuestionFromInvalidOption = false;
} else {
questionView.setValue(value);
}
setupNavigationByQuestionView(rowView.getRootView(), questionView);
tableRow.addView((View) questionView);
swipeTouchListener.addTouchableView(rowView);
swipeTouchListener.addTouchableView(tableRow);
swipeTouchListener.addTouchableView((View) questionView);
swipeTouchListener.addClickableView((View) questionView);
setVisibilityAndAddRow(tableRow, screenQuestion, visibility);
}
}
use of org.eyeseetea.malariacare.views.question.IMultiQuestionView in project pictureapp by EyeSeeTea.
the class DynamicTabAdapter method showOrHideChildren.
/**
* Hide or show the childen question from a given question, if is necessary it reloads the
* children questions values or refreshing the children questions answer component
*
* this code will be delete when DynamicTabAdapter refactoring will be completed
*
* @param question is the parent question
*/
private void showOrHideChildren(Question question) {
if (!question.hasChildren()) {
return;
}
for (int i = 0, j = tableLayout.getChildCount(); i < j; i++) {
View view = tableLayout.getChildAt(i);
if (view instanceof TableRow) {
TableRow row = (TableRow) view;
View targetView = row.getChildAt(0);
if (targetView instanceof IMultiQuestionView || targetView instanceof IQuestionView) {
Question rowQuestion = (Question) targetView.getTag();
if (rowQuestion == null) {
continue;
}
List<Question> questionChildren = question.getChildren();
if (questionChildren != null && questionChildren.size() > 0) {
for (Question childQuestion : questionChildren) {
// if the table row question is child of the modified question...
toggleChild(row, rowQuestion, childQuestion);
}
}
}
}
}
}
Aggregations