Skip to content

Commit

Permalink
Added license + cleaned up code + updated example withouth the need o…
Browse files Browse the repository at this point in the history
…f having the style attribute.
  • Loading branch information
Andrea Baccega committed Jun 7, 2012
1 parent bfce498 commit b81e45f
Show file tree
Hide file tree
Showing 35 changed files with 91 additions and 79 deletions.
8 changes: 8 additions & 0 deletions LICENSE
@@ -0,0 +1,8 @@
The MIT License (MIT)
Copyright (c) 2012 Andrea Baccega <me@andreabaccega.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3 changes: 0 additions & 3 deletions exampleproject/res/layout/example_allowempty.xml
Expand Up @@ -2,12 +2,9 @@
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:editTextFormExample="http://schemas.android.com/apk/res/com.andreabaccega.edittextformexample"
android:id="@+id/et"
style="@android:style/Widget.EditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"

android:hint="@string/hint_phone"
android:inputType="phone"

editTextFormExample:emptyAllowed="true"
editTextFormExample:testType="phone" />
2 changes: 0 additions & 2 deletions exampleproject/res/layout/example_alpha.xml
Expand Up @@ -2,8 +2,6 @@
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:editTextFormExample="http://schemas.android.com/apk/res/com.andreabaccega.edittextformexample"
android:id="@+id/et"
style="@android:style/Widget.EditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"

editTextFormExample:testType="alpha" />
3 changes: 0 additions & 3 deletions exampleproject/res/layout/example_creditcard.xml
Expand Up @@ -2,11 +2,8 @@
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:editTextFormExample="http://schemas.android.com/apk/res/com.andreabaccega.edittextformexample"
android:id="@+id/et"
style="@android:style/Widget.EditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"

android:hint="@string/hint_creditcard"
android:inputType="number"

editTextFormExample:testType="creditCard" />
3 changes: 0 additions & 3 deletions exampleproject/res/layout/example_domainname.xml
Expand Up @@ -2,10 +2,7 @@
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:editTextFormExample="http://schemas.android.com/apk/res/com.andreabaccega.edittextformexample"
android:id="@+id/et"
style="@android:style/Widget.EditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"

android:hint="@string/hint_domainname"

editTextFormExample:testType="domainName" />
3 changes: 0 additions & 3 deletions exampleproject/res/layout/example_email.xml
Expand Up @@ -2,11 +2,8 @@
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:editTextFormExample="http://schemas.android.com/apk/res/com.andreabaccega.edittextformexample"
android:id="@+id/et"
style="@android:style/Widget.EditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"

android:hint="@string/hint_email"
android:inputType="textEmailAddress"

editTextFormExample:testType="email" />
3 changes: 0 additions & 3 deletions exampleproject/res/layout/example_email_or_creditcard.xml
Expand Up @@ -2,11 +2,8 @@
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:editTextFormExample="http://schemas.android.com/apk/res/com.andreabaccega.edittextformexample"
android:id="@+id/et"
style="@android:style/Widget.EditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"

android:hint="@string/hint_emailorcredit"
android:inputType="textEmailAddress"

editTextFormExample:testType="nocheck" />
4 changes: 0 additions & 4 deletions exampleproject/res/layout/example_ipaddress.xml
Expand Up @@ -2,11 +2,7 @@
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:editTextFormExample="http://schemas.android.com/apk/res/com.andreabaccega.edittextformexample"
android:id="@+id/et"
style="@android:style/Widget.EditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"

android:hint="@string/hint_ipaddress"


editTextFormExample:testType="ipAddress" />
2 changes: 0 additions & 2 deletions exampleproject/res/layout/example_nocheck.xml
Expand Up @@ -5,7 +5,5 @@
style="@android:style/Widget.EditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"

android:hint="@string/hint_nocheck"

editTextFormExample:testType="nocheck" />
2 changes: 0 additions & 2 deletions exampleproject/res/layout/example_numeric.xml
Expand Up @@ -2,9 +2,7 @@
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:editTextFormExample="http://schemas.android.com/apk/res/com.andreabaccega.edittextformexample"
android:id="@+id/et"
style="@android:style/Widget.EditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"

editTextFormExample:testType="numeric" />
<!-- Note: for a better user interaction you should use android:inputType. It was intentionally left back in this example. -->
3 changes: 0 additions & 3 deletions exampleproject/res/layout/example_phone.xml
Expand Up @@ -2,11 +2,8 @@
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:editTextFormExample="http://schemas.android.com/apk/res/com.andreabaccega.edittextformexample"
android:id="@+id/et"
style="@android:style/Widget.EditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"

android:hint="@string/hint_phone"
android:inputType="phone"

editTextFormExample:testType="phone" />
2 changes: 0 additions & 2 deletions exampleproject/res/layout/example_phone_custommessages.xml
Expand Up @@ -2,10 +2,8 @@
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:editTextFormExample="http://schemas.android.com/apk/res/com.andreabaccega.edittextformexample"
android:id="@+id/et"
style="@android:style/Widget.EditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"

android:hint="@string/hint_phone"
android:inputType="phone"
editTextFormExample:testErrorString="@string/custom_test_error_phone"
Expand Down
2 changes: 0 additions & 2 deletions exampleproject/res/layout/example_regexp.xml
Expand Up @@ -2,10 +2,8 @@
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:editTextFormExample="http://schemas.android.com/apk/res/com.andreabaccega.edittextformexample"
android:id="@+id/et"
style="@android:style/Widget.EditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"

editTextFormExample:customRegexp="^[a]{2,}$"
editTextFormExample:testErrorString="@string/custom_error_regexp"
editTextFormExample:testType="regexp" />
3 changes: 0 additions & 3 deletions exampleproject/res/layout/example_weburl.xml
Expand Up @@ -2,11 +2,8 @@
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:editTextFormExample="http://schemas.android.com/apk/res/com.andreabaccega.edittextformexample"
android:id="@+id/et"
style="@android:style/Widget.EditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"

android:hint="@string/hint_weburl"
android:inputType="textEmailAddress"

editTextFormExample:testType="webUrl" />
Expand Up @@ -4,7 +4,6 @@
import com.andreabaccega.edittextformexample.utils.ListItem;
import com.andreabaccega.edittextformexample.utils.SimpleListItem;

import android.app.Activity;
import android.app.ListActivity;
import android.os.Bundle;
import android.util.Log;
Expand All @@ -13,7 +12,6 @@
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;

public class EditTextFormExampleActivity extends ListActivity implements OnItemClickListener {

Expand Down
Expand Up @@ -7,8 +7,6 @@
import com.andreabaccega.widget.FormEditText;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
Expand All @@ -23,6 +21,7 @@ public class EmailOrCreditCard extends Activity {
private TextView tvExplanation;
private TextView tvTitle;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_examplegeneric);
Expand Down Expand Up @@ -53,6 +52,7 @@ public CiaoValidator() {
super("You should enter 'ciao' here");
}

@Override
public boolean isValid(EditText et) {
return TextUtils.equals(et.getText(), "ciao");
}
Expand Down
Expand Up @@ -22,6 +22,7 @@ public class LayoutExampleActivity extends Activity {
private FrameLayout flContainer;
private TextView tvExplanation;
private TextView tvTitle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_examplegeneric);
Expand Down
Expand Up @@ -4,8 +4,6 @@
import com.andreabaccega.widget.FormEditText;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
Expand All @@ -20,6 +18,7 @@ public class ProgrammaticActivity extends Activity {
private TextView tvExplanation;
private TextView tvTitle;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_examplegeneric);
Expand All @@ -41,6 +40,7 @@ public CiaoValidator() {
super("You should enter 'ciao' here");
}

@Override
public boolean isValid(EditText et) {
return TextUtils.equals(et.getText(), "ciao");
}
Expand Down
@@ -1,10 +1,7 @@
package com.andreabaccega.edittextformexample.utils;

import com.andreabaccega.edittextformexample.LayoutExampleActivity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;

public class LayoutListItem extends ListItem {
private int layoutRes;
Expand Down
@@ -1,11 +1,5 @@
package com.andreabaccega.formedittextvalidator;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.regex.Pattern;

import android.widget.EditText;

/**
Expand Down
@@ -1,8 +1,13 @@
package com.andreabaccega.formedittextvalidator;

import android.text.TextUtils;

import android.widget.EditText;

/**
* This validator takes care of validating the edittext. The input will be valid only if the number is a valid credit card.
* @author Andrea Baccega <me@andreabaccega.com>
*
*/
public class CreditCardValidator extends Validator{
public CreditCardValidator(String _customErrorMessage) {
super(_customErrorMessage);
Expand Down
@@ -1,9 +1,12 @@
package com.andreabaccega.formedittextvalidator;

import java.util.regex.Pattern;

import android.widget.EditText;

/**
* This is a dummy validator. It just returns true on each input.
* @author Andrea Baccega <me@andreabaccega.com>
*
*/
public class DummyValidator extends Validator {
public DummyValidator() {
super(null);
Expand Down
Expand Up @@ -5,6 +5,12 @@
import android.os.Build;
import android.util.Patterns;

/**
* This validates an email using regexps.
* Note that if an email passes the validation with this validator it doesn't mean it's a valid email - it means it's a valid email <storng>format</strong>
* @author Andrea Baccega <me@andreabaccega.com>
*
*/
public class EmailValidator extends PatternValidator{
public EmailValidator(String _customErrorMessage) {
super(_customErrorMessage, Build.VERSION.SDK_INT>=8?Patterns.EMAIL_ADDRESS:Pattern.compile(
Expand Down
Expand Up @@ -3,6 +3,11 @@
import android.text.TextUtils;
import android.widget.EditText;

/**
* A simple validator that validates the field only if the field is not empty.
* @author Andrea Baccega <me@andreabaccega.com>
*
*/
public class EmptyValidator extends Validator {
public EmptyValidator(String message) {
super(message);
Expand Down
Expand Up @@ -5,6 +5,11 @@
import android.os.Build;
import android.util.Patterns;

/**
* Validates the ipaddress. The regexp was taken from the android source code.
* @author Andrea Baccega <me@andreabaccega.com>
*
*/
public class IpAddressValidator extends PatternValidator{
public IpAddressValidator(String _customErrorMessage) {
super(_customErrorMessage, Build.VERSION.SDK_INT>=8?Patterns.IP_ADDRESS:Pattern.compile(
Expand Down
Expand Up @@ -4,8 +4,13 @@
import java.util.Arrays;
import java.util.List;

import android.widget.EditText;

/**
* Abstract class for a multivalidator.
* @see AndValidator
* @see OrValidator
* @author Andrea Baccega <me@andreabaccega.com>
*
*/
public abstract class MultiValidator extends Validator {
protected final List<Validator> validators;
public MultiValidator(String message, Validator ...validators) {
Expand Down
Expand Up @@ -2,6 +2,11 @@

import android.widget.EditText;

/**
* It's a validator that applies the "NOT" logical operator to the validator passed in the constructor.
* @author Andrea Baccega <me@andreabaccega.com>
*
*/
public class NotValidator extends Validator{
private Validator v;
public NotValidator(String errorMessage, Validator _v) {
Expand Down
Expand Up @@ -3,6 +3,11 @@
import android.text.TextUtils;
import android.widget.EditText;

/**
* A validator that returns true only if the input field contains only numbers.
* @author Andrea Baccega <me@andreabaccega.com>
*
*/
public class NumericValidator extends Validator{
public NumericValidator(String _customErrorMessage) {
super(_customErrorMessage);
Expand Down
@@ -1,10 +1,5 @@
package com.andreabaccega.formedittextvalidator;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Pattern;

import android.widget.EditText;

/**
Expand Down
@@ -1,15 +1,24 @@
package com.andreabaccega.formedittextvalidator;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import android.widget.EditText;

/**
* Base class for regexp based validators.
* @see DomainValidator
* @see EmailValidator
* @see IpAddressValidator
* @see PhoneValidator
* @see WebUrlValidator
* @see RegexpValidator
* @author Andrea Baccega <me@andreabaccega.com>
*
*/
public class PatternValidator extends Validator{
private Pattern pattern;
public PatternValidator(String _customErrorMessage, Pattern _pattern) {
super(_customErrorMessage);
if (_pattern == null) throw new IllegalArgumentException("matcher must not be null");
if (_pattern == null) throw new IllegalArgumentException("_pattern must not be null");
pattern = _pattern;
}

Expand Down

0 comments on commit b81e45f

Please sign in to comment.