Skip to content

Commit a570bd9

Browse files
author
Rajeev kumar
committed
Android AwesomeValidation Library tutorial by tutorialwing.com. This is initial commit.
0 parents  commit a570bd9

File tree

34 files changed

+801
-0
lines changed

34 files changed

+801
-0
lines changed

.gitignore

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/workspace.xml
5+
/.idea/libraries
6+
.DS_Store
7+
/build
8+
/captures
9+
.externalNativeBuild

.idea/compiler.xml

+21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/copyright/profiles_settings.xml

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/dictionaries/Rajeevkumar.xml

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/encodings.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/gradle.xml

+18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

+89
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations.xml

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

app/build.gradle

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 25
5+
buildToolsVersion "25.0.2"
6+
defaultConfig {
7+
applicationId "com.tutorialwing.formvalidationawesomelibrary"
8+
minSdkVersion 17
9+
targetSdkVersion 25
10+
versionCode 1
11+
versionName "1.0"
12+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13+
}
14+
buildTypes {
15+
release {
16+
minifyEnabled false
17+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18+
}
19+
}
20+
}
21+
22+
dependencies {
23+
compile fileTree(dir: 'libs', include: ['*.jar'])
24+
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
25+
exclude group: 'com.android.support', module: 'support-annotations'
26+
})
27+
compile 'com.android.support:appcompat-v7:25.1.0'
28+
testCompile 'junit:junit:4.12'
29+
30+
compile 'com.basgeekball:awesome-validation:2.0'
31+
}

app/proguard-rules.pro

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in /Users/Rajeevkumar/Library/Android/sdk/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.tutorialwing.formvalidationawesomelibrary;
2+
3+
import android.content.Context;
4+
import android.support.test.InstrumentationRegistry;
5+
import android.support.test.runner.AndroidJUnit4;
6+
7+
import org.junit.Test;
8+
import org.junit.runner.RunWith;
9+
10+
import static org.junit.Assert.*;
11+
12+
/**
13+
* Instrumentation test, which will execute on an Android device.
14+
*
15+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
16+
*/
17+
@RunWith(AndroidJUnit4.class)
18+
public class ExampleInstrumentedTest {
19+
@Test
20+
public void useAppContext() throws Exception {
21+
// Context of the app under test.
22+
Context appContext = InstrumentationRegistry.getTargetContext();
23+
24+
assertEquals("com.tutorialwing.formvalidationawesomelibrary", appContext.getPackageName());
25+
}
26+
}

app/src/main/AndroidManifest.xml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest package="com.tutorialwing.formvalidationawesomelibrary"
3+
xmlns:android="http://schemas.android.com/apk/res/android">
4+
5+
<application
6+
android:allowBackup="true"
7+
android:icon="@mipmap/ic_launcher"
8+
android:label="@string/app_name"
9+
android:supportsRtl="true"
10+
android:theme="@style/AppTheme">
11+
<activity android:name=".MainActivity">
12+
<intent-filter>
13+
<action android:name="android.intent.action.MAIN"/>
14+
15+
<category android:name="android.intent.category.LAUNCHER"/>
16+
</intent-filter>
17+
</activity>
18+
</application>
19+
20+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
package com.tutorialwing.formvalidationawesomelibrary;
2+
3+
import android.os.Bundle;
4+
import android.support.v7.app.AppCompatActivity;
5+
import android.util.Patterns;
6+
import android.view.View;
7+
import android.widget.Button;
8+
import android.widget.EditText;
9+
import android.widget.Toast;
10+
11+
import com.basgeekball.awesomevalidation.AwesomeValidation;
12+
import com.basgeekball.awesomevalidation.ValidationStyle;
13+
import com.basgeekball.awesomevalidation.utility.RegexTemplate;
14+
import com.google.common.collect.Range;
15+
16+
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
17+
18+
private EditText name;
19+
20+
private EditText email;
21+
private EditText confirmEmail;
22+
23+
private EditText password;
24+
private EditText confirmPassword;
25+
26+
private EditText phone;
27+
private EditText age;
28+
29+
private Button submit;
30+
31+
private AwesomeValidation awesomeValidation;
32+
33+
@Override
34+
protected void onCreate(Bundle savedInstanceState) {
35+
super.onCreate(savedInstanceState);
36+
setContentView(R.layout.activity_main);
37+
38+
awesomeValidation = new AwesomeValidation(ValidationStyle.BASIC);
39+
//// or
40+
// awesomeValidation = new AwesomeValidation(COLORATION);
41+
// awesomeValidation.setColor(Color.YELLOW); // optional, default color is RED if not set
42+
//// or
43+
// awesomeValidation = new AwesomeValidation(UNDERLABEL);
44+
// awesomeValidation.setContext(this); // mandatory for UNDERLABEL style
45+
//// or
46+
// AwesomeValidation mAwesomeValidation = new AwesomeValidation(TEXT_INPUT_LAYOUT);
47+
48+
initView();
49+
}
50+
51+
private void initView() {
52+
name = (EditText) findViewById(R.id.etName);
53+
email = (EditText) findViewById(R.id.etEmail);
54+
confirmEmail = (EditText) findViewById(R.id.etConfirmEmail);
55+
password = (EditText) findViewById(R.id.etPassword);
56+
confirmPassword = (EditText) findViewById(R.id.etConfirmPassword);
57+
phone = (EditText) findViewById(R.id.etPhone);
58+
age = (EditText) findViewById(R.id.etAge);
59+
60+
submit = (Button) findViewById(R.id.submit);
61+
submit.setOnClickListener(this);
62+
63+
addValidationToViews();
64+
}
65+
66+
private void addValidationToViews() {
67+
68+
awesomeValidation.addValidation(this, R.id.etName, RegexTemplate.NOT_EMPTY, R.string.invalid_name);
69+
70+
awesomeValidation.addValidation(this, R.id.etEmail, Patterns.EMAIL_ADDRESS, R.string.invalid_email);
71+
awesomeValidation.addValidation(this, R.id.etConfirmEmail, R.id.etEmail, R.string.invalid_confirm_email);
72+
73+
String regexPassword = ".{8,}";
74+
awesomeValidation.addValidation(this, R.id.etPassword, regexPassword, R.string.invalid_password);
75+
awesomeValidation.addValidation(this, R.id.etConfirmPassword, R.id.etPassword, R.string.invalid_confirm_password);
76+
77+
awesomeValidation.addValidation(this, R.id.etPhone, "^[+]?[0-9]{10,13}$", R.string.invalid_phone);
78+
awesomeValidation.addValidation(this, R.id.etAge, Range.closed(12, 60), R.string.invalid_age);
79+
}
80+
81+
private void submitForm() {
82+
// Validate the form...
83+
if (awesomeValidation.validate()) {
84+
// Here, we are sure that form is successfully validated. So, do your stuffs now...
85+
Toast.makeText(this, "Form Validated Successfully", Toast.LENGTH_LONG).show();
86+
}
87+
}
88+
89+
90+
@Override
91+
public void onClick(View v) {
92+
switch (v.getId()) {
93+
case R.id.submit:
94+
submitForm();
95+
break;
96+
}
97+
}
98+
}

0 commit comments

Comments
 (0)