当前位置: 首页 > 软件库 > 手机/移动开发 > >

android-saripaar

UI form validation library for Android
授权协议 Apache-2.0 License
开发语言 Java
所属分类 手机/移动开发
软件类型 开源软件
地区 不详
投 递 者 公孙俭
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

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 usingValidator.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.

  • android-saripaar 是一个基于规则的Android UI输入验证库,通过Annotation来标注验证规则。号称是最简单的Android UI验证规则库。 Saripaar特性: 使用Annotation标注的生命性规则 可扩展性 支持同步/异步验证,无线担心线程问题 使用简单,只需下载 jar包,放到项目的libs目录下即可 使用规则来隔离验证逻辑 兼容其他Annotation框架

  • github地址:https://github.com/ragunathjawahar/android-saripaar 1,添加依赖 compile 'com.mobsandgeeks:android-saripaar:2.0.3' 2,为组件添加注解,例如: @Order(1) @NotEmpty(message = "用户名不能为空") @Length(min=6,

  • 地址:https://github.com/ragunathjawahar/android-saripaar 步骤1:使用注解 @NotEmpty @Email private EditText emailEditText; @Password(min = 6, scheme = Password.Scheme.ALPHA_NUMERIC_MIXED_CASE_SYMBOLS) private

  • (披露:我是作者) Saripaar v2允许您定义自定义注释. 这是你做的事情. 步骤1如下定义您的自定义注释.确保您有一个RUNTIME保留策略,并且您的注释必须针对FIELD元素类型.消息和messageResId属性是必需的,因此请注意名称和类型. @ValidateUsing(HaggleRule.class) @Retention(RetentionPolicy.RUNTIME) @T

  • 最近在使用saripaar的时候,当提示错误信息时,发现只有白色的框,没有文字提示,研究很久,原来是字体颜色和错误提示框的背景颜色是一样的,所以给人一种感觉就是字体没有设置成功,解决方法就是改一下字体颜色就Ok了。 /**   * 根据sdk版本不同设置错误提示字体颜色   *    * @param error   * @return   */  private CharSequence set

 相关资料
  • JNI绑定 Android上的Java资源 WebView代码组织

  • Native.js for Android封装一条通过JS语法直接调用Native Java接口通道,通过plus.android可调用几乎所有的系统API。 方法: currentWebview: 获取当前Webview窗口对象的native层实例对象 newObject: 创建实例对象 getAttribute: 获取对象(类对象/实例对象)的属性值 setAttribute: 设置对象(类对

  • Android++ 是一个免费的 Visual Studio 扩展,用于支持在 Visual Studio 上开发和调试原生的 Android 应用,主要基于 NDK 的 C/C++ 应用。同时包括可订制的发布、资源管理以及集成了 Java 源码编译。

  • Android(安卓)是一种基于Linux内核的自由及开放源代码的操作系统,主要使用于移动设备,如智能手机和平板电脑,由美国谷歌公司和开放手机联盟领导及开发。Android操作系统最初由Andy Rubin开发,主要支持手机。2005年8月由谷歌收购注资。2007年11月,谷歌与84家硬件制造商、软件开发商及电信营运商组建开放手机联盟共同研发改良Android系统。随后谷歌以Apache许可证的授

  • Android(安卓)是一种基于Linux内核的自由及开放源代码的操作系统,主要使用于移动设备,如智能手机和平板电脑,由美国谷歌公司和开放手机联盟领导及开发。Android操作系统最初由Andy Rubin开发,主要支持手机。2005年8月由谷歌收购注资。2007年11月,谷歌与84家硬件制造商、软件开发商及电信营运商组建开放手机联盟共同研发改良Android系统。随后谷歌以Apache许可证的授

  • 简介 该库提供J2SE的Swing、AWT等类的安卓实现,引用该库便能在Android上运行J2SE应用程序。 该库实现大多数必需功能,但不是全部的J2SE。 成功示例HomeCenter服务器,该服务器基于J2SE,同时完全运行于Android之上。 使用指引 该库依赖于开源工程HomeCenter。 它不含Activity,需另建Android工程,并引用本库。 Activity和res需作为

  • 前言 少年时我们追求激情,成熟后却迷恋平庸,在我们寻找,伤害,背离之后,还能一如既往的相信爱情,这是一种勇气,每个人都有属于自己的一片森林,迷失的人迷失了,相逢的人会再相逢。 没有人觉得自己差人一等,也没有人一直喜欢居于他人之下,身为一个Android程序员,只有不断的学习,不断的付出自己的努力,自己的汗水,自己的时间,才能让自己进步,学无止境。就上篇而言,我接着来讲一下Android面试时And

  • 我的应用程序上有WebView,我在android 7.0上从用户那里得到了许多相同的错误,同时膨胀了WebView片段。 错误日志: Android看法充气异常:二进制XML文件行#8:二进制XML文件行#8:错误充气类android。网络工具包。网络视图导致:android。看法充气异常:二进制XML文件行#8:充气类android时出错。网络工具包。网络视图 网络视图片段布局: 我从这些设备