AwesomeValidation


Source link: https://github.com/thyrlian/AwesomeValidation

AwesomeValidation

Introduction

Implement validation for Android within only 3 steps. Developers should focus on their awesome code, and let the library do the boilerplate. And what's more, this could help keep your layout file clean.

Steps

  1. Declare validation style;
  2. Add validations;
  3. Set a point when to trigger validation.

Sample code

// Step 1: designate a style AwesomeValidation mAwesomeValidation = new AwesomeValidation(BASIC);
 // or AwesomeValidation mAwesomeValidation = new AwesomeValidation(COLORATION);
 mAwesomeValidation.setColor(Color.YELLOW);
  // optional, default color is RED if not set // or AwesomeValidation mAwesomeValidation = new AwesomeValidation(UNDERLABEL);
 mAwesomeValidation.setContext(this);
  // mandatory for UNDERLABEL style // or AwesomeValidation mAwesomeValidation = new AwesomeValidation(TEXT_INPUT_LAYOUT);
  // Step 2: add validations // support regex string, java.util.regex.Pattern and Guava#Range // you can pass resource or string mAwesomeValidation.addValidation(activity, R.id.edt_name, "[a-zA-Z\\s]+", R.string.err_name);
 mAwesomeValidation.addValidation(activity, R.id.edt_tel, RegexTemplate.TELEPHONE, R.string.err_tel);
 mAwesomeValidation.addValidation(activity, R.id.edt_email, android.util.Patterns.EMAIL_ADDRESS, R.string.err_email);
 mAwesomeValidation.addValidation(activity, R.id.edt_year, Range.closed(1900, Calendar.getInstance().get(Calendar.YEAR)), R.string.err_year);
 mAwesomeValidation.addValidation(activity, R.id.edt_height, Range.closed(0.0f, 2.72f), R.string.err_height);
 // or mAwesomeValidation.addValidation(editText, "regex", "Error info");
  // to validate TextInputLayout, pass the TextInputLayout, not the embedded EditText AwesomeValidation mAwesomeValidation = new AwesomeValidation(TEXT_INPUT_LAYOUT);
 mAwesomeValidation.addValidation(activity, R.id.til_email, Patterns.EMAIL_ADDRESS, R.string.err_email);
  // to validate the confirmation of another field String regexPassword = "(?=.*[a-z])(?=.*[A-Z])(?=.*[\\d])(?=.*[~`!@#\\$%\\^&\\*\\(\\)\\-_\\+=\\{
\\
}
\\[\\]\\|\\;:\"<>,./\\?]).{
8,
}
"; mAwesomeValidation.addValidation(activity, R.id.edt_password, regexPassword, R.string.err_password);
 // to validate a confirmation field (don't validate any rule other than confirmation on confirmation field) mAwesomeValidation.addValidation(activity, R.id.edt_password_confirmation, R.id.edt_password, R.string.err_password_confirmation);
  // Step 3: set a trigger findViewById(R.id.btn_done).setOnClickListener(new View.OnClickListener() {

  @Override
  public void onClick(View v) {

mAwesomeValidation.validate();

  
}
 
}
);
  // Optional: remove validation failure information findViewById(R.id.btn_clr).setOnClickListener(new View.OnClickListener() {

  @Override
  public void onClick(View v) {

mAwesomeValidation.clear();

  
}
 
}
);

It works perfectly with Fragment, but please pay attention to Fragment's lifecycle. You should set the validate() inside Fragment's onActivityCreated instead of onCreateView or any other early stage.

Import as dependency

For Gradle it's so easy: just add below compile line to your module's build.gradle (it's available on JCenter).

dependencies {

  compile 'com.basgeekball:awesome-validation:2.0' 
}

Screenshots

Release guide

  • Update version number in build.gradle, gradle.properties and README
  • Run ./gradlew clean build generateRelease to generate release zip file
  • Run ./gradlew bintrayUpload to create a new version in bintray
  • Upload release zip file manually to bintray, make sure to check ' Explode this archive'

License

Copyright (c) 2014-2016 Jing Li. See the LICENSE file for license rights and limitations (MIT).

Resources

This library allows you to send simple data from WebView to Java. Sends the data via url.

Arc Layout is a view group with which you can add a arc-shaped container in your layout. Two main variables are the direction and the curvature of the arc.

Custom implementation of NavigationView for using custom layout for navigation items and header.

Getting location updates requires lots of bolierplate code in Android, You need to take care of

  • Google Play services availablity Check
  • Update Google play Service Dialog
  • Creation of GoogleApiClient and its callbacks connected,disconnected etc.
  • Stopping and releasing resources for location updates
  • Handling Location permission scenarios
  • Checking Location services are On or Off
  • Getting lastknown location is not so easy either
  • Fallback to last known location if not getting location after certain duration

Android-EasyLocation does all this stuff in background, so that you can concentrate on your business logic than handling all above

Stops the user from keep using the App after a period of time based on app build time. Mainly to have control preview versions handed out using e.g.: hockeyapp or fabric.

Simple lifecycle for your MVWhatever on Android. No kidding.

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