Skip to content
Wellington Costa edited this page Jan 24, 2018 · 7 revisions

This wiki represents the Convalida docs.

Introduction

Motivation

The main motivation is to facilitate writing and maintenance of Android applications.

In addition, another goal is to increase the developers productivity in Android applications development.

Robert C. Martin wrote in "Clean Code: A Handbook of Agile Software Craftsmanship":

The ratio of time spent reading [code] versus writing is well over 10 to 1. [...] Of course there’s no way to write code without reading it, so making it easy to read actually makes it easier to write.

How?

Using Java annotations, developers can define which the validation rule will be applied to the fields, and let Convalida generates the fields validation code at compile time.

Current supported validation

  • Required Fields
  • E-mail Fields
  • Min/Max Fields
  • Only Number Fields
  • Regex Fields
  • Password Fields
  • Confirm Password Fields

Code sample

Is your Android field validation code easy to write, read, and maintain?

Look at that:

public class SampleActivity extends Activity {

    @NotEmptyValidation(R.string.field_required)
    TextInputLayout nameLayout;

    @OnlyNumberValidation(R.string.only_numbers)
    TextInputLayout ageLayout;

    @EmailValidation(R.string.invalid_email)
    TextInputLayout emailLayout;

    @PasswordValidation(min = 3, errorMessage = R.string.invalid_password)
    TextInputLayout passwordLayout;

    @ConfirmPasswordValidation(R.string.passwords_not_match)
    TextInputLayout confirmPasswordLayout;

    @ValidateOnClick
    Button validateButton;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sample);
        Convalida.init(this);
    }

    @OnValidationSuccess
    public void onValidationSuccess() {
        Toast.makeText("Yay!", Toast.LENGTH_LONG).show();
    }

    // [...]

}
Clone this wiki locally