Search in sources :

Example 1 with QuickRule

use of com.mobsandgeeks.saripaar.QuickRule in project android-saripaar by ragunathjawahar.

the class RemoveRulesActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_remove_rules);
    // UI References
    mEmailEditText = (EditText) findViewById(R.id.emailEditText);
    mAddQuickRuleRadioButton = (RadioButton) findViewById(R.id.addQuickRuleRadioButton);
    mRemoveRulesRadioButton = (RadioButton) findViewById(R.id.removeRulesRadioButton);
    mResultTextView = (TextView) findViewById(R.id.resultTextView);
    mSaripaarButton = (Button) findViewById(R.id.saripaarButton);
    // Validator
    mValidator = new Validator(this);
    // Event listeners
    mSaripaarButton.setOnClickListener(this);
    mValidator.setValidationListener(this);
    mAddQuickRuleRadioButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            mValidator.put(mEmailEditText, new QuickRule<EditText>() {

                @Override
                public boolean isValid(EditText editText) {
                    String email = editText.getText().toString();
                    return email.endsWith("mobsandgeeks.com");
                }

                @Override
                public String getMessage(Context context) {
                    return "Only allow emails from \"mobsandgeeks.com\" :P";
                }
            });
        }
    });
    mRemoveRulesRadioButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            mValidator.removeRules(mEmailEditText);
        }
    });
}
Also used : QuickRule(com.mobsandgeeks.saripaar.QuickRule) EditText(android.widget.EditText) Context(android.content.Context) Validator(com.mobsandgeeks.saripaar.Validator) CompoundButton(android.widget.CompoundButton)

Aggregations

Context (android.content.Context)1 CompoundButton (android.widget.CompoundButton)1 EditText (android.widget.EditText)1 QuickRule (com.mobsandgeeks.saripaar.QuickRule)1 Validator (com.mobsandgeeks.saripaar.Validator)1