All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.dwivedi.androidformvalidation.validator.Form Maven / Gradle / Ivy

package com.dwivedi.androidformvalidation.validator;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.widget.EditText;
import android.widget.Toast;

/**
 * 
 * @author Created by Ashish Dwivedi (see
 *         https://github.com/dwivedi/AndroidFormValidation-TheRightWay).
 *         Modified and incorporated to ioc-commons-android-impl by Jesús Lunar
 *         Pérez
 */
public class Form {

	private List mFields = new ArrayList();
	private Context mContext;

	public Form(Context context) {
		this.mContext = context;
	}

	public void addField(Field field) {
		mFields.add(field);
	}

	public boolean isValid() {
		boolean result = true;
		try {
			for (Field field : mFields) {
				result &= field.isValid();
			}
		} catch (FieldValidationException e) {
			result = false;

			EditText textView = e.getTextView();
			textView.requestFocus();
			textView.selectAll();

			FormUtils.showKeyboard(mContext, textView);

			showErrorMessage(e.getMessage());
		}
		return result;
	}

	protected void showErrorMessage(String message) {
		// Crouton.makeText(mActivity, message, Style.ALERT).show();
		Toast.makeText(mContext, message, Toast.LENGTH_LONG).show();
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy