Back to project page Joetz-Android-V2.
The source code is released under:
GNU General Public License
If you think the Android project Joetz-Android-V2 listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.example.jens.myapplication.domain.binding; //from w ww . j a va2 s .c om import android.widget.EditText; import com.example.jens.myapplication.domain.Person; import com.example.jens.myapplication.domain.converter.MyStringParser; import com.example.jens.myapplication.domain.validator.PersonValidator; import com.example.jens.myapplication.sam.JoetzApplication; import com.example.jens.myapplication.util.MyMonths; import org.joda.time.DateTime; import java.util.List; /** * Created by Sam on 29/10/2014. */ public class PersonValidatorBinding extends ValidatorBinding<PersonValidator> { public static final int FIELD_EMAIL = 0; public static final int FIELD_FIRST_NAME = 1; public static final int FIELD_LAST_NAME = 2; public static final int FIELD_DATE_OF_BIRTH = 3; public static final int FIELD_STREET = 4; public static final int FIELD_POSTAL_CODE = 5; public static final int FIELD_CITY = 6; public static final int FIELD_PHONE = 7; public static final int FIELD_RIJKSREGISTERNUMMER = 8; public static final int FIELD_BOND_AANSLUITINGSNUMMER = 9; public static final int FIELD_BOND_CODE_GERECHTIGDE = 10; public static final int FIELD_HOUSE_NUMBER = 11; public static final int FIELD_BUS = 12; public PersonValidatorBinding(PersonValidator validator, EditText view, int field, String itemName) { super(validator, view, field, itemName); } public PersonValidatorBinding(PersonValidator validator, EditText view, int field, String itemName, boolean required){ super(validator, view, field, itemName, required); } @Override protected void setValue(String value) { Person p = validator.getObj(); switch(field){ case FIELD_EMAIL: p.setEmail(value); break; case FIELD_FIRST_NAME: p.setFirstName(value); break; case FIELD_LAST_NAME: p.setLastName(value); break; //Possibly add parser for dob in the future. for now dont set it this way. case FIELD_STREET: p.setStreet(value); break; case FIELD_HOUSE_NUMBER: p.setHouseNumber(MyStringParser.parseInt(value)); break; case FIELD_BUS: p.setBus(value); break; case FIELD_POSTAL_CODE: p.setPostalCode(MyStringParser.parseInt(value)); break; case FIELD_CITY: p.setCity(value); break; case FIELD_PHONE: p.setPhone(value); break; case FIELD_RIJKSREGISTERNUMMER: p.setRijksRegisterNummer(value); break; case FIELD_BOND_AANSLUITINGSNUMMER: p.setBondAansluitingsNr(value); break; case FIELD_BOND_CODE_GERECHTIGDE: p.setBondCodeGerechtigde(value); break; } } @Override public void fillValue() { Person p = validator.getObj(); switch(field){ case FIELD_EMAIL: view.setText(p.getEmail()); break; case FIELD_FIRST_NAME: view.setText(p.getFirstName()); break; case FIELD_LAST_NAME: view.setText(p.getLastName()); break; case FIELD_DATE_OF_BIRTH: DateTime dob = p.getDateOfBirth(); if(dob == null){ return; } String monthString = JoetzApplication.getContext().getString(MyMonths.getMonthShortResId(dob.getMonthOfYear())); view.setText(dob.getDayOfMonth() + " " + monthString + " " + dob.getYear()); break; case FIELD_STREET: view.setText(p.getStreet()); break; case FIELD_HOUSE_NUMBER: view.setText( p.getHouseNumber() < 1 ? "" : String.valueOf(p.getHouseNumber())); break; case FIELD_BUS: view.setText(p.getBus()); break; case FIELD_POSTAL_CODE: view.setText( p.getPostalCode() < 1 ? "" : String.valueOf(p.getPostalCode())); break; case FIELD_CITY: view.setText(p.getCity()); break; case FIELD_PHONE: view.setText(p.getPhone()); break; case FIELD_RIJKSREGISTERNUMMER: view.setText(p.getRijksRegisterNummer()); break; case FIELD_BOND_AANSLUITINGSNUMMER: view.setText(p.getBondAansluitingsNr()); break; case FIELD_BOND_CODE_GERECHTIGDE: view.setText(p.getBondCodeGerechtigde()); break; } } @Override protected ValidationTask createTask(int field) { switch(field){ case FIELD_EMAIL: return new ValidationTask() { @Override public List<Integer> validate(List<Integer> errors) { return validator.validateEmail(errors); } }; case FIELD_FIRST_NAME: return new ValidationTask() { @Override public List<Integer> validate(List<Integer> errors) { return validator.validateFirstName(errors); } }; case FIELD_LAST_NAME: return new ValidationTask() { @Override public List<Integer> validate(List<Integer> errors) { return validator.validateLastName(errors); } }; case FIELD_DATE_OF_BIRTH: return new ValidationTask() { @Override public List<Integer> validate(List<Integer> errors) { return validator.validateDateOfBirth(errors); } }; case FIELD_STREET: return new ValidationTask() { @Override public List<Integer> validate(List<Integer> errors) { return validator.validateStreet(errors); } }; case FIELD_HOUSE_NUMBER: return new ValidationTask() { @Override public List<Integer> validate(List<Integer> errors) { return validator.validateHouseNumber(errors); } }; case FIELD_BUS: return new ValidationTask() { @Override public List<Integer> validate(List<Integer> errors) { return validator.validateBus(errors); } }; case FIELD_POSTAL_CODE: return new ValidationTask() { @Override public List<Integer> validate(List<Integer> errors) { return validator.validatePostalCode(errors); } }; case FIELD_CITY: return new ValidationTask() { @Override public List<Integer> validate(List<Integer> errors) { return validator.validateCity(errors); } }; case FIELD_PHONE: return new ValidationTask() { @Override public List<Integer> validate(List<Integer> errors) { return validator.validatePhone(errors); } }; case FIELD_RIJKSREGISTERNUMMER: return new ValidationTask() { @Override public List<Integer> validate(List<Integer> errors) { return validator.validateRijksRegisterNummer(errors); } }; case FIELD_BOND_AANSLUITINGSNUMMER: return new ValidationTask() { @Override public List<Integer> validate(List<Integer> errors) { return validator.validateBondAansluitingsNummer(errors); } }; case FIELD_BOND_CODE_GERECHTIGDE: return new ValidationTask() { @Override public List<Integer> validate(List<Integer> errors) { return validator.validateBondCodeGerechtigde(errors); } }; } return null; } }