Search in sources :

Example 1 with InvalidPositiveNumberException

use of org.eyeseetea.malariacare.domain.exception.InvalidPositiveNumberException in project pictureapp by EyeSeeTea.

the class PositiveNumberSingleQuestionView method validateAnswer.

private void validateAnswer(Context context) {
    try {
        PositiveNumber positiveNumber = PositiveNumber.parse(numberPicker.getText().toString());
        hideKeyboard(numberPicker);
        notifyAnswerChanged(String.valueOf(positiveNumber.getValue()));
        Validation.getInstance().removeInputError(numberPicker);
    } catch (InvalidPositiveNumberException e) {
        Validation.getInstance().addinvalidInput(numberPicker, context.getString(R.string.dynamic_error_age));
        numberPicker.setError(context.getString(R.string.dynamic_error_age));
    }
}
Also used : PositiveNumber(org.eyeseetea.malariacare.domain.entity.PositiveNumber) InvalidPositiveNumberException(org.eyeseetea.malariacare.domain.exception.InvalidPositiveNumberException)

Example 2 with InvalidPositiveNumberException

use of org.eyeseetea.malariacare.domain.exception.InvalidPositiveNumberException in project pictureapp by EyeSeeTea.

the class PositiveNumberMultiQuestionView method init.

private void init(final Context context) {
    inflate(context, R.layout.multi_question_tab_positive_int_row, this);
    header = (CustomTextView) findViewById(R.id.row_header_text);
    numberPicker = (CustomEditText) findViewById(R.id.answer);
    Validation.getInstance().addInput(numberPicker);
    numberPicker.addTextChangedListener(new TextWatcher() {

        @Override
        public void afterTextChanged(Editable s) {
            try {
                positiveNumber = PositiveNumber.parse(numberPicker.getText().toString());
                notifyAnswerChanged(String.valueOf(positiveNumber.getValue()));
                Validation.getInstance().removeInputError(numberPicker);
            } catch (InvalidPositiveNumberException e) {
                Validation.getInstance().addinvalidInput(numberPicker, context.getString(R.string.dynamic_error_age));
            }
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }
    });
}
Also used : InvalidPositiveNumberException(org.eyeseetea.malariacare.domain.exception.InvalidPositiveNumberException) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable)

Aggregations

InvalidPositiveNumberException (org.eyeseetea.malariacare.domain.exception.InvalidPositiveNumberException)2 Editable (android.text.Editable)1 TextWatcher (android.text.TextWatcher)1 PositiveNumber (org.eyeseetea.malariacare.domain.entity.PositiveNumber)1