Android Saripaar


Source link: https://github.com/ragunathjawahar/android-saripaar

Android Saripaar v2

??????? - sari-paar (Tamil for "to check", "verify" or "validate")

Android Saripaar is a simple, feature-rich and powerful rule-based UI form validation library for Android. It is the SIMPLEST UI validation library available for Android.

Why Android Saripaar?

  • Built on top of Apache Commons Validator, a validation framework with proven track record on the web, desktop and mobile platforms.
  • Declarative style validation using Annotations.
  • Extensible, now allows Custom Annotations.
  • Synchronous and Asynchronous validations, you don't have to worry about threading.
  • Supports both BURST and IMMEDIATE modes.
  • Works with Stock Android Widgets, no custom view dependencies.
  • Isolates validation logic using rules.
  • Compatible with other annotation-based libraries and frameworks such as ButterKnife, AndroidAnnotations, RoboGuice, etc.,

Quick Start

Step 1 - Annotate your widgets using Saripaar Annotations

@NotEmpty @Email private EditText emailEditText;  @Password(min = 6, scheme = Password.Scheme.ALPHA_NUMERIC_MIXED_CASE_SYMBOLS) private EditText passwordEditText;  @ConfirmPassword private EditText confirmPasswordEditText;  @Checked(message = "You must agree to the terms.") private CheckBox iAgreeCheckBox;

The annotations are self-explanatory. The @Order annotation is required ONLY when performing ordered validations using Validator.validateTill(View) and Validator.validateBefore(View) or in IMMEDIATE mode.

Step 2 - Instantiate a new Validator

@Override public void onCreate(Bundle savedInstanceState) {

  super.onCreate(savedInstanceState);

  // Code…

validator = new Validator(this);

  validator.setValidationListener(this);

// More code… 
}

You will need a Validator and a ValidationListener for receiving callbacks on validation events.

Step 3 - Implement a ValidationListener

public class RegistrationActivity extends Activity implements ValidationListener {

// Code…

@Override
  public void onValidationSucceeded() {

Toast.makeText(this, "Yay! we got it right!", Toast.LENGTH_SHORT).show();

  
}

@Override
  public void onValidationFailed(List<ValidationError> errors) {

for (ValidationError error : errors) {

 View view = error.getView();

 String message = error.getCollatedErrorMessage(this);

  // Display error messages ;)

 if (view instanceof EditText) {

  ((EditText) view).setError(message);

 
}
 else {

  Toast.makeText(this, message, Toast.LENGTH_LONG).show();

 
}

}

  
}
 
}
  • onValidationSucceeded() - Called when all your views pass all validations.
  • onValidationFailed(List<ValidationError> errors) - Called when there are validation error(s).

Step 4 - Validate

registerButton.setOnClickListener(new OnClickListener() {

@Override
  public void onClick(View v) {

validator.validate();

  
}
 
}
);

The Validator.validate() call runs the validations and returns the result via appropriate callbacks on the ValidationListener. You can run validations on a background AsyncTask by calling the Validator.validate(true) method.

Saripaar X

If you are looking for country-specific annotations, checkout the Saripaar X project. The extensions project is in its early stages and needs contributors. Feel free to contribute.

Maven

<dependency>
  <groupId>com.mobsandgeeks</groupId>
  <artifactId>android-saripaar</artifactId>
  <version>(latest version)</version> </dependency> 

Gradle

dependencies {

  compile 'com.mobsandgeeks:android-saripaar:(latest version)' 
}
 

Snapshots

In your { project_base } /build.gradle file, include the following.

allprojects {

  repositories {

jcenter()

maven {

 url "https://oss.sonatype.org/content/repositories/snapshots/"

}

  
}
 
}
 

ProGuard

Exclude Saripaar classes from obfuscation and minification. Add the following rules to your proguard-rules.pro file.

-keep class com.mobsandgeeks.saripaar.** {
*;
}
 -keep @com.mobsandgeeks.saripaar.annotation.ValidateUsing class * {
*;
}
 

Evolution

For those interested in finding out how v2 evolved from v1, watch this (~20 second) video.

Using Saripaar?

Tweet me with your Google Play URL and I'll add your app to the list :)

Icon App Icon App Icon App
Wikipedia Wikipedia Beta Mizuno Baton
Fetch HealtheMinder MomMe
Feelknit StreetBarz Roast Me
Pipe Snagajob Tatva Moksh Lakshya

Wiki

Please visit the wiki for a complete guide on Android Saripaar.

License

Copyright 2012 - 2015 Mobs & Geeks  Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License. You may obtain a copy of the License at
  http://www.apache.org/licenses/LICENSE-2.0  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 

Saripaar Logo © 2013 - 2015, Mobs & Geeks.

Resources

Update Checker For Google Play.

A pretty floating action menu.

Pick a date or time on Android in style.

SwipeActionAdapter is a library that provides a simple API to create Mailbox-like action when swiping in a ListView. The idea is to make it simple enough to implement while still providing sufficient options to allow you to integrate it with the design of your application.

MagicaSakura is an Android multi theme library which supporting both daily colorful theme and night theme.

Attempting to make convenient for working with ViewPager and PagerAdatper.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes