-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
455 additions
and
782 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,85 @@ | ||
<a href='https://bintray.com/eddmash/maven/validation/1.0.0/link'><img src='https://api.bintray.com/packages/eddmash/maven/validation/images/download.svg?version=1.0.0'></a> | ||
<a href='https://bintray.com/eddmash/maven/validation?source=watch' alt='Get automatic notifications about new "validation" versions'><img src='https://www.bintray.com/docs/images/bintray_badge_color.png'></a> | ||
# Validation | ||
A extendable validation library for android. | ||
|
||
Android validation library documentation! | ||
----------------------------------------- | ||
|
||
A lightweight and extensible android validation library. | ||
|
||
It uses simple, straightforward validation methods with a focus on readable and concise syntax. | ||
|
||
Installation | ||
------------ | ||
|
||
using Maven. | ||
|
||
``` | ||
<dependency> | ||
<groupId>com.eddmash</groupId> | ||
<artifactId>validation</artifactId> | ||
<version>1.0.13</version> | ||
<type>pom</type> | ||
</dependency> | ||
``` | ||
|
||
using Gradle. | ||
|
||
``` | ||
compile 'com.eddmash:validation:1.0.13' | ||
``` | ||
|
||
Usage | ||
----- | ||
Using this library boils down to this steps | ||
|
||
- Create a validator object | ||
|
||
``` | ||
// validator takes Context(Activity) object as argument | ||
Validator validator = new Validator(this); | ||
``` | ||
|
||
- Add validation checks to the validator | ||
|
||
``` | ||
// the view objects to validate | ||
EditText nameEditText = (EditText) view.findViewById(R.id.name); | ||
Spinner ageSpinner = (Spinner) view.findViewById(R.id.spinner); | ||
// ... using check objects | ||
validator.addCheck(new NotEmptyCheck(nameEditText, "name cannot be blank"); | ||
validator.addCheck(new NotEmptyCheck(ageSpinner, "age cannot be blank"); | ||
``` | ||
`Learn more about available checks <com/eddmash/validation/checks/package-index>` | ||
|
||
- Validate and Handle the errors | ||
|
||
|
||
To run the validations invole the validators | ||
`validate() <ValidatorInterface.validate()>` method. | ||
|
||
This method returns ``true`` if the validation passed or ``false`` if the validations failed. | ||
|
||
Incase of validation failure, the validation errors can be accessed via the | ||
`getErrors() <ValidatorInterface.getErrors()>` method. | ||
|
||
This library comes with a convenience `ErrorRenderer <ErrorRenderer>`, which can be used | ||
to easily display the validation errors. | ||
|
||
``` | ||
// the layout where we display any validation errors | ||
LinearLayout errorSpace = (LinearLayout) findViewById(R.id.error_base); | ||
errorSpace.removeAllViews();// clear space first | ||
if (validator.validate()) { | ||
// .. code to perform if validation passes | ||
} else { | ||
// show the errors if validation failed | ||
// we use the renderer class to handle the display | ||
ErrorRenderer errorRenderer = new ErrorRenderer(this, validator); | ||
errorRenderer.render(errorSpace); | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Checks | ||
###### | ||
.. toctree:: | ||
:maxdepth: 2 | ||
:titlesonly: | ||
|
||
com/eddmash/validation/checks/package-index |
30 changes: 30 additions & 0 deletions
30
docs/source/com/eddmash/validation/ExampleInstrumentedTest.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
.. java:import:: android.content Context | ||
.. java:import:: android.support.test InstrumentationRegistry | ||
.. java:import:: android.support.test.runner AndroidJUnit4 | ||
.. java:import:: org.junit Test | ||
.. java:import:: org.junit.runner RunWith | ||
ExampleInstrumentedTest | ||
======================= | ||
|
||
.. java:package:: com.eddmash.validation | ||
:noindex: | ||
|
||
.. java:type:: @RunWith public class ExampleInstrumentedTest | ||
Instrumentation test, which will execute on an Android device. | ||
|
||
**See also:** \ `Testing documentation <http://d.android.com/tools/testing>`_\ | ||
|
||
Methods | ||
------- | ||
useAppContext | ||
^^^^^^^^^^^^^ | ||
|
||
.. java:method:: @Test public void useAppContext() throws Exception | ||
:outertype: ExampleInstrumentedTest | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
.. java:import:: org.junit Test | ||
ExampleUnitTest | ||
=============== | ||
|
||
.. java:package:: com.eddmash.validation | ||
:noindex: | ||
|
||
.. java:type:: public class ExampleUnitTest | ||
Example local unit test, which will execute on the development machine (host). | ||
|
||
**See also:** \ `Testing documentation <http://d.android.com/tools/testing>`_\ | ||
|
||
Methods | ||
------- | ||
addition_isCorrect | ||
^^^^^^^^^^^^^^^^^^ | ||
|
||
.. java:method:: @Test public void addition_isCorrect() throws Exception | ||
:outertype: ExampleUnitTest | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
ValidationListener | ||
================== | ||
|
||
.. java:package:: com.eddmash.validation | ||
:noindex: | ||
|
||
.. java:type:: interface ValidationListener | ||
Interface definition for callbacks to be invoked when the validation state has changed. | ||
|
||
Methods | ||
------- | ||
onValidationFailed | ||
^^^^^^^^^^^^^^^^^^ | ||
|
||
.. java:method:: void onValidationFailed() | ||
:outertype: ValidationListener | ||
|
||
Invoked when validation failed | ||
|
||
onValidationSuccess | ||
^^^^^^^^^^^^^^^^^^^ | ||
|
||
.. java:method:: void onValidationSuccess() | ||
:outertype: ValidationListener | ||
|
||
Invoked when the validation passed successfully. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.