Skip to content
Open
28 changes: 28 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,31 @@ android {
dependencies {
compile 'com.android.support:support-v4:23.3.0'
}
/**
* When running in Travis, you may add custom environment variable GITHUB_OAUTH2TOKEN and do something like:
* ./gradlew violationCommentsToGitHub -DGITHUB_PULLREQUESTID=$TRAVIS_PULL_REQUEST -DGITHUB_OAUTH2TOKEN=$GITHUB_OAUTH2TOKEN
* Or define username/password variables:
* ./gradlew violationCommentsToGitHub -DGITHUB_PULLREQUESTID=$TRAVIS_PULL_REQUEST -DGITHUB_USERNAME=$GITHUB_USERNAME -DGITHUB_PASSWORD=$GITHUB_PASSWORD
*/
//apply plugin: "se.bjurr.violations.violation-comments-to-github-gradle-plugin"
//task violationCommentsToGitHub(type: se.bjurr.violations.comments.github.plugin.gradle.ViolationCommentsToGitHubTask) {
// repositoryOwner = "tomasbjerre";
// repositoryName = "violations-test"
// pullRequestId = System.properties['GITHUB_PULLREQUESTID']
// username = System.properties['GITHUB_USERNAME']
// password = System.properties['GITHUB_PASSWORD']
// oAuth2Token = System.properties['GITHUB_OAUTH2TOKEN']
// gitHubUrl = "https://api.github.com/"
// createCommentWithAllSingleFileComments = true
// createSingleFileComments = true
// commentOnlyChangedContent = true
// violations = [
// ["FINDBUGS", ".", ".*/findbugs/.*\\.xml\$"],
// ["PMD", ".", ".*/pmd/.*\\.xml\$"],
// ["CHECKSTYLE", ".", ".*/checkstyle/.*\\.xml\$"],
// ["JSHINT", ".", ".*/jshint/.*\\.xml\$"],
// ["CSSLINT", ".", ".*/csslint/.*\\.xml\$"]
// ]
//}
//sdasdsa
//dsds
5 changes: 4 additions & 1 deletion app/checkci.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ task checkstyle(type: Checkstyle) {
reports {
xml.enabled = true
html.enabled = false
xml {
destination "${project.buildDir}/reports/checkstyle/checkstyle.xml"
}
}
}

Expand Down Expand Up @@ -81,7 +84,7 @@ task checkci {
description 'Run Check CI'
group 'checkci'

println "Please check reports in http://ci-pro.framgia.vn"
//println "Please check reports in http://ci-pro.framgia.vn"
}

checkci.dependsOn 'checkstyle', 'findbugs', 'pmd', 'lint'
Expand Down
44 changes: 26 additions & 18 deletions app/src/main/java/com/manhnv/validation/EmailVerifier.java
Original file line number Diff line number Diff line change
@@ -1,43 +1,51 @@
package com.manhnv.validation;

import android.text.TextUtils;
import android.widget.TextView;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import android.widget.TextView;

public class EmailVerifier extends RequiredVerifier {
private String mEmailPattern;
private Pattern pattern;
private Matcher matcher;
private static final String EMAIL_PATTERN =
"^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";

public EmailVerifier(TextView field, String filedName) {
super(field, filedName);
setMessage(ERROR_CODE_EMAIL, " is not valide");
setMessage(ERROR_CODE_EMAIL, " is not validate");
pattern = Pattern.compile(EMAIL_PATTERN);
}

@Override
public boolean verify() {
String email = getText();
boolean isValide = super.verify();
if (!isValide)
return isValide;
else if (!validate(email)) {
// else if(!RegularExpressionUtils.isEmail(email)) {
isValide = false;
boolean isValidate = super.verify();
if (!isValidate) {
return isValidate;
} else if (!validate(email)) {
isValidate = false;
setErrorCode(ERROR_CODE_EMAIL);
} else {
isValide = true;
isValidate = true;
setErrorCode(SUCCESS_CODE);
}
return isValide;
return isValidate;
}

public void setEmailPattern(String emailPattern) {
if (TextUtils.isEmpty(emailPattern)) {
return;
}
mEmailPattern = emailPattern;
pattern = Pattern.compile(emailPattern);
}
private Pattern pattern;
private Matcher matcher;
private static final String EMAIL_PATTERN =
"^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";

/**
* Validate hex with regular expression
*
* @param hex
* hex for validation
*
* @param hex hex for validation
* @return true valid hex, false invalid hex
*/
private boolean validate(String hex) {
Expand Down
41 changes: 19 additions & 22 deletions app/src/main/java/com/manhnv/validation/IVerifier.java
Original file line number Diff line number Diff line change
@@ -1,69 +1,66 @@
package com.manhnv.validation;

public interface IVerifier {
public static final int SUCCESS_CODE = -1;
public static final int ERROR_CODE_REQUIRED = 0;
public static final int ERROR_CODE_MIN = 1;
public static final int ERROR_CODE_MAX = 2;
public static final int ERROR_CODE_EMAIL = 3;
public static final int ERROR_CODE_NUMBER = 4;
public static final int ERROR_CODE_FUTURE = 5;
public static final int ERROR_CODE_FROM_DATE = 6;
public static final int ERROR_CODE_TO_DATE = 7;
int SUCCESS_CODE = -1;
int ERROR_CODE_REQUIRED = 0;
int ERROR_CODE_MIN = 1;
int ERROR_CODE_MAX = 2;
int ERROR_CODE_EMAIL = 3;
int ERROR_CODE_NUMBER = 4;
int ERROR_CODE_FUTURE = 5;
int ERROR_CODE_FROM_DATE = 6;
int ERROR_CODE_TO_DATE = 7;

/**
* do validate action in here
*
*
* @return true: validated success<br>
* false: validated fail
* false: validated fail
*/
boolean verify();

/**
* error message will be show on
* {@linkplain #android.widget.TextView.setError(CharSequence error)}
*
*
* @return if user define his message {@link #setErrorMessage(String)} -> show this message<br>
* if not show default message field name + message
* if not show default message field name + message
* @see android.widget.EditText#setError(CharSequence)
*/
String getErrorMessage();

/**
* using to show error message and you can know what field is invalid
*
*
* @return field name (pass in constructor by user)
*/
String getFieldName();

/**
* belong to type of verifier: email, phone, blank ...
*
* @param error
*
* @return String fit with error code
*/
String getErrorMessage(int error);

/**
* belong to type of verifier: email, phone, blank ...
*
*
* @return code of error
*/
int getErrorCode();

/**
* {@linkplain #android.widget.TextView.setError(CharSequence error)}
* @see android.widget.EditText#setError(CharSequence)
*/
void showError();

/**
* {@linkplain #android.widget.TextView.setError(CharSequence error)} setError(null)
* @see android.widget.EditText#setError(CharSequence)
*/
void hideError();

/**
* user defined his message
*
* @param message
*/
void setErrorMessage(String message);
}
11 changes: 5 additions & 6 deletions app/src/main/java/com/manhnv/validation/RequiredVerifier.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package com.manhnv.validation;

import java.util.HashMap;
import java.util.Map;

import android.text.TextUtils;
import android.widget.TextView;
import java.util.HashMap;
import java.util.Map;

public class RequiredVerifier implements IVerifier {
private TextView field;
Expand All @@ -29,9 +28,9 @@ public boolean verify() {
setErrorCode(SUCCESS_CODE);
return true;
}
boolean isValidate = getText().toString().trim().length() != 0;
boolean isValidate = !TextUtils.isEmpty(getText().toString().trim());
if (!isValidate) {
errorCode = ERROR_CODE_REQUIRED;
setErrorCode(ERROR_CODE_REQUIRED);
} else {
setErrorCode(SUCCESS_CODE);
}
Expand All @@ -41,7 +40,7 @@ public boolean verify() {
@Override
public String getErrorMessage() {
return !TextUtils.isEmpty(userDefinedMessage) ? userDefinedMessage
: getErrorMessage(getErrorCode());
: getErrorMessage(getErrorCode());
}

public String getErrorMessage(int error) {
Expand Down
14 changes: 7 additions & 7 deletions app/src/main/java/com/manhnv/validation/VerifierBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

public class VerifierBuilder {
List<IVerifier> verifiers;
IVerifier inValide;
IVerifier inValid;

public VerifierBuilder() {
verifiers = new ArrayList<IVerifier>();
Expand Down Expand Up @@ -35,11 +35,11 @@ public boolean verify() {
verifier.hideError();
if (!verifier.verify()) {
verifier.showError();
inValide = verifier;
inValid = verifier;
return false;
}
}
inValide = null;
inValid = null;
return true;
}

Expand All @@ -49,9 +49,9 @@ public boolean verify() {
* @return error message
*/
public String getErrorMessage() {
if (inValide == null)
if (inValid == null)
return null;
return inValide.getErrorMessage();
return inValid.getErrorMessage();
}

/**
Expand All @@ -60,8 +60,8 @@ public String getErrorMessage() {
* @return code
*/
public int getErrorCode() {
if (inValide == null)
if (inValid == null)
return -1;
return inValide.getErrorCode();
return inValid.getErrorCode();
}
}
6 changes: 5 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
classpath 'com.android.tools.build:gradle:2.2.2'
// classpath "se.bjurr.violations:violation-comments-to-github-gradle-plugin:1.11-SNAPSHOT"
}
}

allprojects {
repositories {
jcenter()
maven {
url "https://plugins.gradle.org/m2/"
}
}
}
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Mon Dec 28 10:00:20 PST 2015
#Mon Aug 29 14:22:56 ICT 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
1 change: 1 addition & 0 deletions test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"a":"123", "b":2}