diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 06404d3..0000000 --- a/.gitignore +++ /dev/null @@ -1,74 +0,0 @@ -### Android template -# Built application files -*.apk -*.ap_ - -# Files for the ART/Dalvik VM -*.dex - -# Java class files -*.class - -# Generated files -bin/ -gen/ -out/ - -# Gradle files -.gradle/ -build/ - -# Local configuration file (sdk path, etc) -local.properties - -# Proguard folder generated by Eclipse -proguard/ - -# Log Files -*.log - -# Android Studio Navigation editor temp files -.navigation/ - -# Android Studio captures folder -captures/ - -# IntelliJ -*.iml -.idea/dictionaries -.idea/libraries -.idea/caches -.idea/.name -.idea/assetWizardSettings.xml -.idea/encodings.xml -.idea/compiler.xml -.idea/gradle.xml -.idea/misc.xml -.idea/modules.xml -.idea/runConfigurations.xml -.idea/tasks.xml -.idea/vcs.xml -.idea/workspace.xml - -# Keystore files -# Uncomment the following line if you do not want to check your keystore files in. -#*.jks - -# External native build folder generated in Android Studio 2.2 and later -.externalNativeBuild - -# Google Services (e.g. APIs or Firebase) -google-services.json - -# Freeline -freeline.py -freeline/ -freeline_project_description.json - -# fastlane -fastlane/report.xml -fastlane/Preview.html -fastlane/screenshots -fastlane/test_output -fastlane/readme.md - diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml deleted file mode 100644 index 30aa626..0000000 --- a/.idea/codeStyles/Project.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml deleted file mode 100644 index c90fbe5..0000000 --- a/.idea/inspectionProfiles/Project_Default.xml +++ /dev/null @@ -1,1231 +0,0 @@ - - - - \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index a76c405..0000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,39 +0,0 @@ -Change Log -========== - -Version 1.2.1 *(IN DEVELOPMENT)* --------------------------------- - -Version 1.2.0 *(2018-10-07)* ----------------------------- - -* **CHANGED**: minSdkVersion is now 14 -* **CHANGED**: Converted project to Gradle -* **CHANGED**: Compile with Java 8 syntax - -Version 1.1.2 *(2016-04-23)* ----------------------------- - -* **minSdkVersion is now 8** -* Added spanish translation (#4) -* Updated dependencies - -Version 1.1.1 *(2014-06-01)* ----------------------------- - -* Updated dependencies - -Version 1.1.0 *(2014-02-02)* ----------------------------- - -* **Switched to aar packaging** - -Version 1.0.1 *(2013-12-15)* ----------------------------- - -* Renamed Form.with to Form.create and dropped Activity parameter - -Version 1.0.0 *(2013-12-14)* ----------------------------- - -* Initial release. diff --git a/Jenkinsfile b/Jenkinsfile deleted file mode 100644 index fdb4532..0000000 --- a/Jenkinsfile +++ /dev/null @@ -1,41 +0,0 @@ -pipeline { - options { - buildDiscarder(logRotator(artifactNumToKeepStr: '5', numToKeepStr: '15')) - } - agent any - stages { - stage('Prepare environment') { - steps { - sh "yes | $ANDROID_HOME/tools/bin/sdkmanager --licenses > /dev/null" - } - } - stage('Build') { - steps { - sh './gradlew clean build' - junit allowEmptyResults: true, testResults: '**/build/test-results/testDebugUnitTest/TEST-*.xml' - jacoco classPattern: '**/build/intermediates/javac/debug,**/build/intermediates/javac/debugUnitTest', exclusionPattern: '**/R.class,**/R$*.class,**/BuildConfig.*,**/*$ViewInjector*.*,**/*$ViewBinder*.*', execPattern: '**/testDebugUnitTest.exec' - } - } - stage("Analyze") { - steps { - withSonarQubeEnv('PSDev') { - sh './gradlew sonarqube' - } - timeout(time: 1, unit: 'HOURS') { - waitForQualityGate abortPipeline: false - } - } - } - stage("Deploy") { - steps { - sh './gradlew publish' - zip dir: 'build/m2repository', glob: '', zipFile: 'build/m2repository.zip', archive: true - } - } - } - post { - always { - archiveArtifacts allowEmptyArchive: true, artifacts: '**/build/reports/,sample/build/outputs/apk/debug/sample-debug.apk', fingerprint: true - } - } -} \ No newline at end of file diff --git a/LICENSE.txt b/LICENSE.txt deleted file mode 100644 index d645695..0000000 --- a/LICENSE.txt +++ /dev/null @@ -1,202 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - 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. diff --git a/_config.yml b/_config.yml new file mode 100644 index 0000000..2db94d0 --- /dev/null +++ b/_config.yml @@ -0,0 +1,8 @@ +title: FormValidations +description: FormValidations is an open source library to validate forms in Android apps. +google_analytics: UA-74654-28 +show_downloads: true +theme: jekyll-theme-slate + +gems: + - jekyll-mentions diff --git a/build.gradle b/build.gradle deleted file mode 100644 index adca4dd..0000000 --- a/build.gradle +++ /dev/null @@ -1,42 +0,0 @@ -buildscript { - ext { - // Plugin versions - androidGradlePluginVersion = "3.2.0" - sonarqubeGradlePluginVersion = "2.6.2" - // Dependency versions - appcompatVersion = "28.0.0" - butterknife = "8.8.1" - supportAnnotationsVersion = "28.0.0" - } - repositories { - google() - mavenCentral() - jcenter() - } - dependencies { - classpath "com.android.tools.build:gradle:$androidGradlePluginVersion" - classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:$sonarqubeGradlePluginVersion" - } -} - -allprojects { - group "de.psdev.formvalidations" - version "1.2.1-SNAPSHOT" - - repositories { - google() - mavenCentral() - jcenter() - } - - apply from: rootProject.file('gradle/versioning.gradle') -} - -task clean(type: Delete) { - delete rootProject.buildDir -} - -task wrapper(type: Wrapper) { - gradleVersion = '4.10.2' - distributionType = "all" -} \ No newline at end of file diff --git a/formvalidations/.gitignore b/formvalidations/.gitignore deleted file mode 100644 index 796b96d..0000000 --- a/formvalidations/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build diff --git a/formvalidations/build.gradle b/formvalidations/build.gradle deleted file mode 100644 index bb18ec0..0000000 --- a/formvalidations/build.gradle +++ /dev/null @@ -1,65 +0,0 @@ -apply plugin: 'com.android.library' -apply plugin: "org.sonarqube" -apply from: rootProject.file('gradle/jacoco.gradle') - -project.description = "FormValidations (Library)" - -android { - compileSdkVersion 28 - buildToolsVersion "28.0.3" - - defaultConfig { - minSdkVersion 14 - targetSdkVersion 28 - - versionName project.version - versionCode buildVersionCode() - - buildConfigField 'String', 'GIT_SHA', "\"${gitScmVersion()}\"" - } - - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 - } - - lintOptions { - lintConfig rootProject.file('lint.xml') - } - - testOptions { - unitTests { - includeAndroidResources = true - } - } - - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' - } - } -} - -dependencies { - // Testing - testImplementation 'junit:junit:4.12' - testImplementation 'org.robolectric:robolectric:3.8' - - // Support Annotations - implementation "com.android.support:support-annotations:$supportAnnotationsVersion" -} - -sonarqube { - properties { - property "sonar.projectKey", "$project.group" - property "sonar.projectName", "FormValidations" - property "sonar.exclusions", [].join(',') - property "sonar.scm.provider", "git" - property "sonar.android.lint.report", "build/reports/lint-results.xml" - property "sonar.junit.reportPaths", "build/test-results/testDebugUnitTest" - property "sonar.jacoco.reportPaths", "build/jacoco/testDebugUnitTest.exec" - } -} - -apply from: rootProject.file('gradle/publishMavenLocal.gradle') \ No newline at end of file diff --git a/formvalidations/src/main/AndroidManifest.xml b/formvalidations/src/main/AndroidManifest.xml deleted file mode 100644 index ac88590..0000000 --- a/formvalidations/src/main/AndroidManifest.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/formvalidations/src/main/java/de/psdev/formvalidations/EditTextErrorHandler.java b/formvalidations/src/main/java/de/psdev/formvalidations/EditTextErrorHandler.java deleted file mode 100644 index 20a4543..0000000 --- a/formvalidations/src/main/java/de/psdev/formvalidations/EditTextErrorHandler.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2013 Philip Schiffer - * - * 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. - */ - -package de.psdev.formvalidations; - -import android.support.annotation.NonNull; -import android.widget.EditText; - -public class EditTextErrorHandler implements FormErrorHandler { - - @Override - public void handleError(@NonNull final FieldValidationException e) { - final EditText textView = e.getTextView(); - final String message = e.getMessage(); - textView.setError(message); - } - - @Override - public void resetError(@NonNull final Field field) { - field.getEditText().setError(null); - } -} diff --git a/formvalidations/src/main/java/de/psdev/formvalidations/Field.java b/formvalidations/src/main/java/de/psdev/formvalidations/Field.java deleted file mode 100644 index 55ab377..0000000 --- a/formvalidations/src/main/java/de/psdev/formvalidations/Field.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright 2013 Philip Schiffer - * - * 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. - * - * This file incorporates code covered by the following terms: - * - * The MIT License (MIT) - * - * Copyright (c) 2013 Vitaliy Zasadnyy - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package de.psdev.formvalidations; - -import java.util.LinkedList; -import java.util.List; - -import android.widget.EditText; -import de.psdev.formvalidations.validations.Validation; - -public class Field { - - private final EditText mEditText; - private final List mValidations; - - public static Field using(final EditText editText) { - if(editText == null) { - throw new IllegalArgumentException("EditText field may not be null"); - } - return new Field(editText); - } - - protected Field(final EditText editText) { - mEditText = editText; - mValidations = new LinkedList<>(); - } - - // - - public Field validate(final Validation what) { - mValidations.add(what); - return this; - } - - public EditText getEditText() { - return mEditText; - } - - public boolean isValid() throws FieldValidationException { - for (final Validation validation : mValidations) { - if (!validation.isValid(mEditText.getText().toString())) { - final String errorMessage = validation.getErrorMessage(mEditText.getContext()); - throw new FieldValidationException(errorMessage, mEditText); - } - } - return true; - } - -} diff --git a/formvalidations/src/main/java/de/psdev/formvalidations/FieldValidationException.java b/formvalidations/src/main/java/de/psdev/formvalidations/FieldValidationException.java deleted file mode 100644 index 3255592..0000000 --- a/formvalidations/src/main/java/de/psdev/formvalidations/FieldValidationException.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2013 Philip Schiffer - * - * 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. - * - * This file incorporates code covered by the following terms: - * - * The MIT License (MIT) - * - * Copyright (c) 2013 Vitaliy Zasadnyy - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package de.psdev.formvalidations; - -import android.support.annotation.NonNull; -import android.widget.EditText; - -public class FieldValidationException extends Exception { - - private final EditText mTextView; - - public FieldValidationException(final String message, @NonNull final EditText textView) { - super(message); - mTextView = textView; - } - - @NonNull - public EditText getTextView() { - return mTextView; - } -} diff --git a/formvalidations/src/main/java/de/psdev/formvalidations/Form.java b/formvalidations/src/main/java/de/psdev/formvalidations/Form.java deleted file mode 100644 index 5fe2f99..0000000 --- a/formvalidations/src/main/java/de/psdev/formvalidations/Form.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright 2013 Philip Schiffer - * - * 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. - * - * This file incorporates code covered by the following terms: - * - * The MIT License (MIT) - * - * Copyright (c) 2013 Vitaliy Zasadnyy - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package de.psdev.formvalidations; - -import java.util.ArrayList; -import java.util.List; - -import android.support.annotation.Nullable; -import android.widget.EditText; - -public class Form { - - private final List mFields; - @Nullable - private FormErrorHandler mHandler; - - public static Form create() { - return new Form(); - } - - private Form() { - mFields = new ArrayList<>(); - } - - public Form addField(final Field field) { - mFields.add(field); - return this; - } - - public Form errorHandler(final FormErrorHandler handler) { - mHandler = handler; - return this; - } - - public boolean isValid() { - boolean result = true; - try { - resetErrors(); - for (final Field field : mFields) { - result &= field.isValid(); - } - } catch (final FieldValidationException e) { - result = false; - - final EditText textView = e.getTextView(); - textView.requestFocus(); - textView.selectAll(); - - FormUtils.showKeyboard(textView.getContext(), textView); - - showErrorMessage(e); - } - return result; - } - - public void resetErrors() { - final FormErrorHandler handler = mHandler; - if (handler != null) { - for (final Field field : mFields) { - handler.resetError(field); - } - } - } - - // - - protected void showErrorMessage(final FieldValidationException e) { - if (mHandler != null) { - mHandler.handleError(e); - } - } -} diff --git a/formvalidations/src/main/java/de/psdev/formvalidations/FormErrorHandler.java b/formvalidations/src/main/java/de/psdev/formvalidations/FormErrorHandler.java deleted file mode 100644 index 0df07c6..0000000 --- a/formvalidations/src/main/java/de/psdev/formvalidations/FormErrorHandler.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2013 Philip Schiffer - * - * 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. - */ - -package de.psdev.formvalidations; - -import android.support.annotation.NonNull; - -public interface FormErrorHandler { - void handleError(@NonNull final FieldValidationException e); - - void resetError(@NonNull final Field field); -} diff --git a/formvalidations/src/main/java/de/psdev/formvalidations/FormUtils.java b/formvalidations/src/main/java/de/psdev/formvalidations/FormUtils.java deleted file mode 100644 index 3065ea7..0000000 --- a/formvalidations/src/main/java/de/psdev/formvalidations/FormUtils.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 2013 Philip Schiffer - * - * 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. - * - * This file incorporates code covered by the following terms: - * - * The MIT License (MIT) - * - * Copyright (c) 2013 Vitaliy Zasadnyy - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package de.psdev.formvalidations; - -import android.content.Context; -import android.view.inputmethod.InputMethodManager; -import android.widget.TextView; - -public final class FormUtils { - - private FormUtils() { - } - - public static void showKeyboard(final Context context, final TextView textView) { - final InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); - - if (imm != null) { - // only will trigger it if no physical keyboard is open - imm.showSoftInput(textView, 0); - } - } - - public static void hideKeyboard(final Context context, final TextView textView) { - final InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); - - if (imm != null) { - // only will trigger it if no physical keyboard is open - imm.hideSoftInputFromWindow(textView.getWindowToken(), 0); - } - } -} diff --git a/formvalidations/src/main/java/de/psdev/formvalidations/validations/AlphaNumeric.java b/formvalidations/src/main/java/de/psdev/formvalidations/validations/AlphaNumeric.java deleted file mode 100644 index 73351ec..0000000 --- a/formvalidations/src/main/java/de/psdev/formvalidations/validations/AlphaNumeric.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2013 Philip Schiffer - * - * 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. - */ - -package de.psdev.formvalidations.validations; - -import android.content.Context; -import de.psdev.formvalidations.R; - -public class AlphaNumeric implements Validation { - public static AlphaNumeric build() { - return new AlphaNumeric(); - } - - private AlphaNumeric() { - } - - - @Override - public String getErrorMessage(final Context context) { - return context.getString(R.string.formvalidations_not_alphanumeric); - } - - @Override - public boolean isValid(final String text) { - return text.matches("[0-9a-zA-Z]*"); - } -} diff --git a/formvalidations/src/main/java/de/psdev/formvalidations/validations/InRange.java b/formvalidations/src/main/java/de/psdev/formvalidations/validations/InRange.java deleted file mode 100644 index 0dace71..0000000 --- a/formvalidations/src/main/java/de/psdev/formvalidations/validations/InRange.java +++ /dev/null @@ -1,76 +0,0 @@ - -/* - * Copyright 2013 Philip Schiffer - * - * 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. - * - * This file incorporates code covered by the following terms: - * - * The MIT License (MIT) - * - * Copyright (c) 2013 Vitaliy Zasadnyy - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package de.psdev.formvalidations.validations; - -import android.content.Context; -import de.psdev.formvalidations.R; - -public class InRange implements Validation { - - private final int mMin; - private final int mMax; - - public static Validation build(final int min, final int max) { - return new InRange(min, max); - } - - private InRange(final int min, final int max) { - mMin = min; - mMax = max; - } - - @Override - public String getErrorMessage(final Context context) { - return context.getString(R.string.formvalidations_not_in_range, mMin, mMax); - } - - @Override - public boolean isValid(final String text) { - try { - final int value = Integer.parseInt(text); - if ((value > mMin) && (value < mMax)) { - return true; - } - } catch (final NumberFormatException ignored) { - } - return false; - } -} diff --git a/formvalidations/src/main/java/de/psdev/formvalidations/validations/IsEmail.java b/formvalidations/src/main/java/de/psdev/formvalidations/validations/IsEmail.java deleted file mode 100644 index a57fbc8..0000000 --- a/formvalidations/src/main/java/de/psdev/formvalidations/validations/IsEmail.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2013 Philip Schiffer - * - * 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. - * - * This file incorporates code covered by the following terms: - * - * The MIT License (MIT) - * - * Copyright (c) 2013 Vitaliy Zasadnyy - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package de.psdev.formvalidations.validations; - -import android.content.Context; -import android.util.Patterns; -import de.psdev.formvalidations.R; - -public class IsEmail implements Validation { - - private IsEmail() { - } - - public static Validation build() { - return new IsEmail(); - } - - @Override - public String getErrorMessage(final Context context) { - return context.getString(R.string.formvalidations_not_email); - } - - @Override - public boolean isValid(final String text) { - return Patterns.EMAIL_ADDRESS.matcher(text).matches(); - } -} diff --git a/formvalidations/src/main/java/de/psdev/formvalidations/validations/IsNumber.java b/formvalidations/src/main/java/de/psdev/formvalidations/validations/IsNumber.java deleted file mode 100644 index e309fa2..0000000 --- a/formvalidations/src/main/java/de/psdev/formvalidations/validations/IsNumber.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2013 Philip Schiffer - * - * 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. - */ - -package de.psdev.formvalidations.validations; - -import android.content.Context; -import de.psdev.formvalidations.R; - -public class IsNumber implements Validation { - - public static IsNumber build() { - return new IsNumber(); - } - - private IsNumber() { - } - - @Override - public String getErrorMessage(final Context context) { - return context.getString(R.string.formvalidations_numeric); - } - - @Override - public boolean isValid(final String value) { - return value.matches("[0-9]*"); - } -} diff --git a/formvalidations/src/main/java/de/psdev/formvalidations/validations/IsPositiveInteger.java b/formvalidations/src/main/java/de/psdev/formvalidations/validations/IsPositiveInteger.java deleted file mode 100644 index b5214f2..0000000 --- a/formvalidations/src/main/java/de/psdev/formvalidations/validations/IsPositiveInteger.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2013 Philip Schiffer - * - * 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. - * - * This file incorporates code covered by the following terms: - * - * The MIT License (MIT) - * - * Copyright (c) 2013 Vitaliy Zasadnyy - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package de.psdev.formvalidations.validations; - -import android.content.Context; -import de.psdev.formvalidations.R; - -public class IsPositiveInteger implements Validation { - - public static final String POSITIVE_INT_PATTERN = "\\d+"; - - public static Validation build() { - return new IsPositiveInteger(); - } - - private IsPositiveInteger() { - } - - @Override - public String getErrorMessage(final Context context) { - return context.getString(R.string.formvalidations_not_positive_integer); - } - - @Override - public boolean isValid(final String text) { - return text.matches(POSITIVE_INT_PATTERN); - } -} diff --git a/formvalidations/src/main/java/de/psdev/formvalidations/validations/Length.java b/formvalidations/src/main/java/de/psdev/formvalidations/validations/Length.java deleted file mode 100644 index 3ac44ad..0000000 --- a/formvalidations/src/main/java/de/psdev/formvalidations/validations/Length.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright 2013 Philip Schiffer - * - * 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. - * - * This file incorporates code covered by the following terms: - * - * The MIT License (MIT) - * - * Copyright (c) 2013 Vitaliy Zasadnyy - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package de.psdev.formvalidations.validations; - - -import android.content.Context; -import de.psdev.formvalidations.R; - -public class Length implements Validation { - - private final int mMinLength; - private final int mMaxLength; - - public static Validation min(final int minLength) { - if (minLength <= 0) { - throw new IllegalArgumentException("minLength must be positive"); - } - return new Length(minLength, -1); - } - - public static Validation max(final int maxLength) { - if (maxLength <= 0) { - throw new IllegalArgumentException("maxLength must be positive"); - } - return new Length(-1, maxLength); - } - - public static Validation range(final int minLength, final int maxLength) { - if (minLength <= 0) { - throw new IllegalArgumentException("minLength must be positive"); - } - if (maxLength <= 0) { - throw new IllegalArgumentException("maxLength must be positive"); - } - return new Length(minLength, maxLength); - } - - private Length(final int minLength, final int maxLength) { - mMinLength = minLength; - mMaxLength = maxLength; - } - - @Override - public String getErrorMessage(final Context context) { - if (mMinLength != -1 && mMaxLength != -1) { - return context.getString(R.string.formvalidations_length_range, mMinLength, mMaxLength); - } else if (mMinLength == -1 && mMaxLength != -1) { - return context.getString(R.string.formvalidations_length_max, mMaxLength); - } - return context.getString(R.string.formvalidations_length_min, mMinLength); - } - - @Override - public boolean isValid(final String text) { - if (text == null) { - return false; - } - if (mMinLength > 0 && mMaxLength > 0) { - return text.length() >= mMinLength && text.length() <= mMaxLength; - } - if (mMinLength > 0 && mMaxLength < 0) { - return text.length() >= mMinLength; - } - return text.length() <= mMaxLength; - } -} diff --git a/formvalidations/src/main/java/de/psdev/formvalidations/validations/NotEmpty.java b/formvalidations/src/main/java/de/psdev/formvalidations/validations/NotEmpty.java deleted file mode 100644 index df2c726..0000000 --- a/formvalidations/src/main/java/de/psdev/formvalidations/validations/NotEmpty.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2013 Philip Schiffer - * - * 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. - * - * This file incorporates code covered by the following terms: - * - * The MIT License (MIT) - * - * Copyright (c) 2013 Vitaliy Zasadnyy - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package de.psdev.formvalidations.validations; - - -import android.content.Context; -import android.text.TextUtils; -import de.psdev.formvalidations.R; - -public class NotEmpty implements Validation { - - public static Validation build() { - return new NotEmpty(); - } - - private NotEmpty() { - } - - @Override - public String getErrorMessage(final Context context) { - return context.getString(R.string.formvalidations_empty); - } - - @Override - public boolean isValid(final String text) { - return !TextUtils.isEmpty(text); - } -} diff --git a/formvalidations/src/main/java/de/psdev/formvalidations/validations/Validation.java b/formvalidations/src/main/java/de/psdev/formvalidations/validations/Validation.java deleted file mode 100644 index 9920c07..0000000 --- a/formvalidations/src/main/java/de/psdev/formvalidations/validations/Validation.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2013 Philip Schiffer - * - * 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. - * - * This file incorporates code covered by the following terms: - * - * The MIT License (MIT) - * - * Copyright (c) 2013 Vitaliy Zasadnyy - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package de.psdev.formvalidations.validations; - -import android.content.Context; - -public interface Validation { - - String getErrorMessage(final Context context); - - boolean isValid(String text); - -} diff --git a/formvalidations/src/main/res/values-es/strings.xml b/formvalidations/src/main/res/values-es/strings.xml deleted file mode 100644 index 05ddfb3..0000000 --- a/formvalidations/src/main/res/values-es/strings.xml +++ /dev/null @@ -1,51 +0,0 @@ - - - - - Están permitidos solo números - El campo debe ser entero positivo - No puede estar vacío - La longitud debe estar entre %1$d y %2$d - Longitud mínima %1$d - Longitud máxima %1$d - El valor debe estar entre %1$d y %2$d - Este valor no es un correo electrónico valido - Este valor no es alfanumérico - diff --git a/formvalidations/src/main/res/values/strings.xml b/formvalidations/src/main/res/values/strings.xml deleted file mode 100644 index fdbd48d..0000000 --- a/formvalidations/src/main/res/values/strings.xml +++ /dev/null @@ -1,51 +0,0 @@ - - - - - Only numbers are allowed. - Field should be positive integer - Field cannot be empty - Length must be between %1$d and %2$d - Length must be at least %1$d - Length must be at most %1$d - Value should be between %1$d and %2$d - Value is not valid email address - Value is not alphanumeric - diff --git a/formvalidations/src/test/java/de/psdev/formvalidations/BaseTest.java b/formvalidations/src/test/java/de/psdev/formvalidations/BaseTest.java deleted file mode 100644 index 0437e21..0000000 --- a/formvalidations/src/test/java/de/psdev/formvalidations/BaseTest.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2013 Philip Schiffer - * - * 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. - */ - -package de.psdev.formvalidations; - -import org.junit.runner.RunWith; -import org.robolectric.RobolectricTestRunner; -import org.robolectric.annotation.Config; - -@RunWith(RobolectricTestRunner.class) -@Config(sdk = Config.ALL_SDKS) -public abstract class BaseTest { -} diff --git a/formvalidations/src/test/java/de/psdev/formvalidations/EditTextErrorHandlerTest.java b/formvalidations/src/test/java/de/psdev/formvalidations/EditTextErrorHandlerTest.java deleted file mode 100644 index 95f7736..0000000 --- a/formvalidations/src/test/java/de/psdev/formvalidations/EditTextErrorHandlerTest.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2013 Philip Schiffer - * - * 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. - */ - -package de.psdev.formvalidations; - -import android.app.Activity; -import android.widget.EditText; -import org.junit.Before; -import org.junit.Test; -import org.robolectric.Robolectric; -import org.robolectric.annotation.Config; - -import static org.junit.Assert.*; - -public class EditTextErrorHandlerTest extends BaseTest { - - private static final String ERROR_MESSAGE = "Error message"; - - private EditText mEditText; - private EditTextErrorHandler mEditTextErrorHandler; - - @Before - public void setUp() throws Exception { - final Activity activity = Robolectric.buildActivity(Activity.class).create().get(); - mEditText = new EditText(activity); - mEditTextErrorHandler = new EditTextErrorHandler(); - } - - @Test - public void testHandleAndResetError() throws Exception { - assertNull(mEditText.getError()); - final FieldValidationException e = new FieldValidationException(ERROR_MESSAGE, mEditText); - mEditTextErrorHandler.handleError(e); - assertNotNull(mEditText.getError()); - assertEquals(ERROR_MESSAGE, mEditText.getError()); - mEditTextErrorHandler.resetError(Field.using(mEditText)); - assertNull(mEditText.getError()); - } -} diff --git a/formvalidations/src/test/java/de/psdev/formvalidations/FieldTest.java b/formvalidations/src/test/java/de/psdev/formvalidations/FieldTest.java deleted file mode 100644 index 2bff03d..0000000 --- a/formvalidations/src/test/java/de/psdev/formvalidations/FieldTest.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 2013 Philip Schiffer - * - * 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. - */ - -package de.psdev.formvalidations; - -import android.app.Activity; -import android.widget.EditText; -import de.psdev.formvalidations.validations.NotEmpty; -import org.junit.Before; -import org.junit.Test; -import org.robolectric.Robolectric; -import org.robolectric.annotation.Config; - -import static org.junit.Assert.*; - -public class FieldTest extends BaseTest { - - private Activity mActivity; - - @Before - public void setUp() throws Exception { - mActivity = Robolectric.buildActivity(Activity.class).create().get(); - } - - @Test(expected = IllegalArgumentException.class) - public void testInvalidFieldCreationResultsInException() throws Exception { - Field.using(null); - } - - @Test(expected = FieldValidationException.class) - public void testEmptyFieldIsNotValid() throws Exception { - final EditText editText = new EditText(mActivity); - final Field field = Field.using(editText); - field.validate(NotEmpty.build()); - assertFalse(field.isValid()); - editText.setText("text"); - assertTrue(field.isValid()); - } - - @Test - public void testNotEmptyFieldIsValid() throws Exception { - final EditText editText = new EditText(mActivity); - final Field field = Field.using(editText); - field.validate(NotEmpty.build()); - editText.setText("text"); - assertTrue(field.isValid()); - } - - @Test - public void testGetEditText() throws Exception { - final EditText editText = new EditText(mActivity); - final Field field = Field.using(editText); - assertSame(editText, field.getEditText()); - } -} diff --git a/formvalidations/src/test/java/de/psdev/formvalidations/FormTest.java b/formvalidations/src/test/java/de/psdev/formvalidations/FormTest.java deleted file mode 100644 index 6d1e5e0..0000000 --- a/formvalidations/src/test/java/de/psdev/formvalidations/FormTest.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright 2013 Philip Schiffer - * - * 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. - */ - -package de.psdev.formvalidations; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.util.concurrent.atomic.AtomicBoolean; - -import org.junit.Before; -import org.junit.Test; -import org.robolectric.Robolectric; - -import android.app.Activity; -import android.support.annotation.NonNull; -import android.widget.EditText; -import de.psdev.formvalidations.validations.IsEmail; -import de.psdev.formvalidations.validations.NotEmpty; - -public class FormTest extends BaseTest { - private Activity mActivity; - private Form mForm; - - @Before - public void setUp() throws Exception { - mActivity = Robolectric.buildActivity(Activity.class).create().get(); - mForm = Form.create(); - } - - @Test - public void testFormWithOneFieldIsValid() throws Exception { - final EditText editText = new EditText(mActivity); - mForm.addField(Field.using(editText).validate(NotEmpty.build())); - assertFalse(mForm.isValid()); - editText.setText("Hello"); - assertTrue(mForm.isValid()); - } - - @Test - public void testFormWithMultipleFieldsIsValid() throws Exception { - final EditText fieldOne = new EditText(mActivity); - final EditText fieldTwo = new EditText(mActivity); - mForm.addField(Field.using(fieldOne).validate(NotEmpty.build())); - mForm.addField(Field.using(fieldTwo).validate(NotEmpty.build()).validate(IsEmail.build())); - assertFalse(mForm.isValid()); - fieldOne.setText("Hello"); - assertFalse(mForm.isValid()); - fieldTwo.setText("user@example.org"); - assertTrue(mForm.isValid()); - } - - @Test - public void testFormWithErrorHandler() throws Exception { - final EditText fieldOne = new EditText(mActivity); - final AtomicBoolean resetErrorCalled = new AtomicBoolean(false); - final AtomicBoolean handleErrorCalled = new AtomicBoolean(false); - mForm.addField(Field.using(fieldOne).validate(NotEmpty.build())); - mForm.errorHandler(new FormErrorHandler() { - @Override - public void handleError(@NonNull final FieldValidationException e) { - handleErrorCalled.set(true); - } - - @Override - public void resetError(@NonNull final Field field) { - resetErrorCalled.set(true); - } - }); - assertFalse(mForm.isValid()); - assertTrue(handleErrorCalled.get()); - assertTrue(resetErrorCalled.get()); - } - -} diff --git a/formvalidations/src/test/java/de/psdev/formvalidations/FormUtilsTest.java b/formvalidations/src/test/java/de/psdev/formvalidations/FormUtilsTest.java deleted file mode 100644 index 616f58a..0000000 --- a/formvalidations/src/test/java/de/psdev/formvalidations/FormUtilsTest.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2013 Philip Schiffer - * - * 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. - */ - -package de.psdev.formvalidations; - -import android.app.Activity; -import android.widget.TextView; -import org.junit.Before; -import org.junit.Test; -import org.robolectric.Robolectric; -import org.robolectric.annotation.Config; - -public class FormUtilsTest extends BaseTest { - - private Activity mActivity; - private TextView mTextView; - - @Before - public void setUp() throws Exception { - mActivity = Robolectric.buildActivity(Activity.class).create().get(); - mTextView = new TextView(mActivity); - } - - @Test - public void testShowKeyboard() throws Exception { - FormUtils.showKeyboard(mActivity, mTextView); - } - - @Test - public void testHideKeyboard() throws Exception { - FormUtils.hideKeyboard(mActivity, mTextView); - } -} diff --git a/formvalidations/src/test/java/de/psdev/formvalidations/validations/AlphaNumericTest.java b/formvalidations/src/test/java/de/psdev/formvalidations/validations/AlphaNumericTest.java deleted file mode 100644 index a50a341..0000000 --- a/formvalidations/src/test/java/de/psdev/formvalidations/validations/AlphaNumericTest.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2013 Philip Schiffer - * - * 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. - */ - -package de.psdev.formvalidations.validations; - -import org.junit.Before; -import org.junit.Test; -import org.robolectric.annotation.Config; - -import static org.junit.Assert.*; - -public class AlphaNumericTest extends BaseValidationTest { - - private AlphaNumeric mAlphaNumeric; - - @Before - public void setUp() throws Exception { - mAlphaNumeric = AlphaNumeric.build(); - } - - @Test - public void testGetErrorMessage() throws Exception { - final String errorMessage = mAlphaNumeric.getErrorMessage(mActivity); - assertNotNull(errorMessage); - } - - @Test - public void testNumbersAreValid() throws Exception { - assertTrue(mAlphaNumeric.isValid("123")); - } - - @Test - public void testAsciiTextIsValid() throws Exception { - assertTrue(mAlphaNumeric.isValid("test")); - } - - @Test - public void testNumbersAndAsciiTextAreValid() throws Exception { - assertTrue(mAlphaNumeric.isValid("test123")); - } - - @Test - public void testSpecialCharsAreNotValid() throws Exception { - assertFalse(mAlphaNumeric.isValid("ä")); - assertFalse(mAlphaNumeric.isValid("ö")); - assertFalse(mAlphaNumeric.isValid("ü")); - assertFalse(mAlphaNumeric.isValid("ß")); - } -} diff --git a/formvalidations/src/test/java/de/psdev/formvalidations/validations/BaseValidationTest.java b/formvalidations/src/test/java/de/psdev/formvalidations/validations/BaseValidationTest.java deleted file mode 100644 index e688446..0000000 --- a/formvalidations/src/test/java/de/psdev/formvalidations/validations/BaseValidationTest.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2013 Philip Schiffer - * - * 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. - */ - -package de.psdev.formvalidations.validations; - -import android.app.Activity; -import de.psdev.formvalidations.BaseTest; -import org.junit.Before; -import org.robolectric.Robolectric; - -public abstract class BaseValidationTest extends BaseTest { - - protected Activity mActivity; - - @Before - public void setUpActivity() throws Exception { - mActivity = Robolectric.buildActivity(Activity.class).create().get(); - } -} diff --git a/formvalidations/src/test/java/de/psdev/formvalidations/validations/InRangeTest.java b/formvalidations/src/test/java/de/psdev/formvalidations/validations/InRangeTest.java deleted file mode 100644 index 3a6c87e..0000000 --- a/formvalidations/src/test/java/de/psdev/formvalidations/validations/InRangeTest.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2013 Philip Schiffer - * - * 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. - */ - -package de.psdev.formvalidations.validations; - -import org.junit.Test; -import org.robolectric.annotation.Config; - -import static org.junit.Assert.*; - -public class InRangeTest extends BaseValidationTest { - - @Test - public void testGetErrorMessage() throws Exception { - final Validation validation = InRange.build(2, 4); - final String errorMessage = validation.getErrorMessage(mActivity); - assertNotNull(errorMessage); - assertTrue(errorMessage.contains(Integer.toString(2))); - assertTrue(errorMessage.contains(Integer.toString(4))); - } - - @Test - public void testInRangeIsExclusive() throws Exception { - final Validation validation = InRange.build(2, 4); - assertFalse(validation.isValid("2")); - assertTrue(validation.isValid("3")); - assertFalse(validation.isValid("4")); - } - - @Test - public void testTextIsNotValid() throws Exception { - final Validation validation = InRange.build(2, 4); - assertFalse(validation.isValid("test")); - } -} diff --git a/formvalidations/src/test/java/de/psdev/formvalidations/validations/IsEmailTest.java b/formvalidations/src/test/java/de/psdev/formvalidations/validations/IsEmailTest.java deleted file mode 100644 index 22b5b02..0000000 --- a/formvalidations/src/test/java/de/psdev/formvalidations/validations/IsEmailTest.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2013 Philip Schiffer - * - * 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. - */ - -package de.psdev.formvalidations.validations; - -import org.junit.Before; -import org.junit.Test; -import org.robolectric.annotation.Config; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -public class IsEmailTest extends BaseValidationTest { - - private Validation mIsEmail; - - @Before - public void setUp() throws Exception { - mIsEmail = IsEmail.build(); - } - - @Test - public void testGetErrorMessage() throws Exception { - final String errorMessage = mIsEmail.getErrorMessage(mActivity); - assertNotNull(errorMessage); - } - - @Test - public void testSimpleEmailIsValid() throws Exception { - assertTrue(mIsEmail.isValid("user@example.org")); - } - - @Test - public void testEmailWithPlusIsValid() throws Exception { - assertTrue(mIsEmail.isValid("user+alias@example.org")); - } - - @Test - public void testEmailWithPointsIsValid() throws Exception { - assertTrue(mIsEmail.isValid("user.name@example.org")); - } -} diff --git a/formvalidations/src/test/java/de/psdev/formvalidations/validations/IsNumberTest.java b/formvalidations/src/test/java/de/psdev/formvalidations/validations/IsNumberTest.java deleted file mode 100644 index ed05ac5..0000000 --- a/formvalidations/src/test/java/de/psdev/formvalidations/validations/IsNumberTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2013 Philip Schiffer - * - * 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. - */ - -package de.psdev.formvalidations.validations; - -import org.junit.Before; -import org.junit.Test; -import org.robolectric.annotation.Config; - -import static org.junit.Assert.*; - -public class IsNumberTest extends BaseValidationTest { - - private IsNumber mIsNumber; - - @Before - public void setUp() throws Exception { - mIsNumber = IsNumber.build(); - } - - @Test - public void testGetErrorMessage() throws Exception { - final String errorMessage = mIsNumber.getErrorMessage(mActivity); - assertNotNull(errorMessage); - } - - @Test - public void testNumbersAreValid() throws Exception { - assertTrue(mIsNumber.isValid("1")); - assertTrue(mIsNumber.isValid("12")); - assertTrue(mIsNumber.isValid("123")); - } - - @Test - public void testTextIsNotValid() throws Exception { - assertFalse(mIsNumber.isValid("text")); - } -} diff --git a/formvalidations/src/test/java/de/psdev/formvalidations/validations/IsPositiveIntegerTest.java b/formvalidations/src/test/java/de/psdev/formvalidations/validations/IsPositiveIntegerTest.java deleted file mode 100644 index 6411a83..0000000 --- a/formvalidations/src/test/java/de/psdev/formvalidations/validations/IsPositiveIntegerTest.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2013 Philip Schiffer - * - * 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. - */ - -package de.psdev.formvalidations.validations; - -import org.junit.Before; -import org.junit.Test; -import org.robolectric.annotation.Config; - -import static org.junit.Assert.*; - -public class IsPositiveIntegerTest extends BaseValidationTest { - - private Validation mIsPositiveInteger; - - @Before - public void setUp() throws Exception { - mIsPositiveInteger = IsPositiveInteger.build(); - } - - @Test - public void testGetErrorMessage() throws Exception { - final String errorMessage = mIsPositiveInteger.getErrorMessage(mActivity); - assertNotNull(errorMessage); - } - - @Test - public void testPositiveNumberIsValid() throws Exception { - assertTrue(mIsPositiveInteger.isValid("1")); - } - - @Test - public void testNegativeNumberIsNotValid() throws Exception { - assertFalse(mIsPositiveInteger.isValid("-1")); - } - - @Test - public void testTextIsNotValid() throws Exception { - assertFalse(mIsPositiveInteger.isValid("text")); - } -} diff --git a/formvalidations/src/test/java/de/psdev/formvalidations/validations/LengthTest.java b/formvalidations/src/test/java/de/psdev/formvalidations/validations/LengthTest.java deleted file mode 100644 index bb330eb..0000000 --- a/formvalidations/src/test/java/de/psdev/formvalidations/validations/LengthTest.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright 2013 Philip Schiffer - * - * 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. - */ - -package de.psdev.formvalidations.validations; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; - -public class LengthTest extends BaseValidationTest { - - @Test - public void testMin() throws Exception { - final Validation validation = Length.min(2); - assertFalse(validation.isValid("a")); - assertTrue(validation.isValid("ab")); - } - - @Test - public void testMax() throws Exception { - final Validation validation = Length.max(3); - assertTrue(validation.isValid("abc")); - assertFalse(validation.isValid("abcd")); - } - - @Test - public void testRange() throws Exception { - final Validation validation = Length.range(2, 4); - assertFalse(validation.isValid("a")); - assertTrue(validation.isValid("ab")); - assertTrue(validation.isValid("abc")); - assertTrue(validation.isValid("abcd")); - assertFalse(validation.isValid("abcde")); - } - - @Test - public void testGetErrorMessage() throws Exception { - // Min - final Validation minValidation = Length.min(2); - final String minValidationErrorMessage = minValidation.getErrorMessage(mActivity); - assertNotNull(minValidationErrorMessage); - assertTrue(minValidationErrorMessage.contains("2")); - // Max - final Validation maxValidation = Length.max(5); - final String maxValidationErrorMessage = maxValidation.getErrorMessage(mActivity); - assertNotNull(maxValidationErrorMessage); - assertTrue(maxValidationErrorMessage.contains("5")); - // Range - final Validation rangeValidation = Length.range(2, 5); - final String rangeValidationErrorMessage = rangeValidation.getErrorMessage(mActivity); - assertNotNull(rangeValidationErrorMessage); - assertTrue(rangeValidationErrorMessage.contains("2")); - assertTrue(rangeValidationErrorMessage.contains("5")); - } - - @Test - public void testNullIsNotValid() throws Exception { - final Validation validation = Length.range(2, 4); - assertFalse(validation.isValid(null)); - } - - @Test(expected = IllegalArgumentException.class) - public void testNegativeMinValueIsNotPossible() throws Exception { - Length.min(-1); - } - - @Test(expected = IllegalArgumentException.class) - public void testNegativeMaxValueIsNotPossible() throws Exception { - Length.max(-1); - } - - @Test(expected = IllegalArgumentException.class) - public void testNegativeMinValueRangeIsNotPossible() throws Exception { - Length.range(-1, 1); - } - - @Test(expected = IllegalArgumentException.class) - public void testNegativeMaxValueRangeIsNotPossible() throws Exception { - Length.range(1, -1); - } -} diff --git a/formvalidations/src/test/java/de/psdev/formvalidations/validations/NotEmptyTest.java b/formvalidations/src/test/java/de/psdev/formvalidations/validations/NotEmptyTest.java deleted file mode 100644 index b7601a5..0000000 --- a/formvalidations/src/test/java/de/psdev/formvalidations/validations/NotEmptyTest.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2013 Philip Schiffer - * - * 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. - */ - -package de.psdev.formvalidations.validations; - -import org.junit.Before; -import org.junit.Test; -import org.robolectric.annotation.Config; - -import static org.junit.Assert.*; - -public class NotEmptyTest extends BaseValidationTest { - - private Validation mNotEmpty; - - @Before - public void setUp() throws Exception { - mNotEmpty = NotEmpty.build(); - } - - @Test - public void testGetErrorMessage() throws Exception { - final String errorMessage = mNotEmpty.getErrorMessage(mActivity); - assertNotNull(errorMessage); - } - - @Test - public void testAnyTextIsValid() throws Exception { - assertTrue(mNotEmpty.isValid("anytext")); - } - - @Test - public void testNoTextIsNotValid() throws Exception { - assertFalse(mNotEmpty.isValid("")); - } -} diff --git a/gradle.properties b/gradle.properties deleted file mode 100644 index 559a433..0000000 --- a/gradle.properties +++ /dev/null @@ -1,36 +0,0 @@ -# Project-wide Gradle settings. - -# IDE (e.g. Android Studio) users: -# Gradle settings configured through the IDE *will override* -# any settings specified in this file. - -# For more details on how to configure your build environment visit -# http://www.gradle.org/docs/current/userguide/build_environment.html - -# Specifies the JVM arguments used for the daemon process. -# The setting is particularly useful for tweaking memory settings. -org.gradle.jvmargs=-Xmx4096m - -# When configured, Gradle will run in incubating parallel mode. -# This option should only be used with decoupled projects. More details, visit -# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects -# org.gradle.parallel=true - -# Project info -projectName=FormValidations -projectDescription=FormValidations is an open source library to validate forms in Android apps. -projectUrl=http://psdev.de/FormValidations -projectInceptionYear=2013 -projectScmUrl=https://github.com/PSDev/FormValidations -projectScmConnection=scm:git:git://github.com/PSDev/FormValidations.git -projectScmDeveloperConnection=scm:git:git@github.com:PSDev/FormValidations.git -projectDeveloperName=Philip Schiffer -projectDeveloperEmail=philip.schiffer@gmail.com -projectOrganizationName=PSDev -projectOrganizationUrl=https://psdev.de -projectLicesenseName=Apache License Version 2.0 -projectLicesenseUrl=http://www.apache.org/licenses/LICENSE-2.0.txt -projectIssueManagementSystem=GitHub Issues -projectIssueManagementUrl=https://github.com/PSDev/FormValidations/issues -projectCiManagementSystem=Jenkins -projectCiManagementUrl=https://ci.psdev.de/job/PSDevFormValidations diff --git a/gradle/jacoco.gradle b/gradle/jacoco.gradle deleted file mode 100644 index 148a325..0000000 --- a/gradle/jacoco.gradle +++ /dev/null @@ -1,22 +0,0 @@ -apply plugin: 'jacoco' - -jacoco { - toolVersion = "0.7.9" -} - -android { - testOptions { - unitTests.all { - jacoco { - includeNoLocationClasses = true - excludes = ['**/R.class', - '**/R$*.class', - '**/BuildConfig.*', - '**/Manifest*.*', - '**/*$Lambda$*.*', // Jacoco can not handle several "$" in class name. - 'android/**/*.*' - ] - } - } - } -} \ No newline at end of file diff --git a/gradle/publishMavenLocal.gradle b/gradle/publishMavenLocal.gradle deleted file mode 100644 index 99f9563..0000000 --- a/gradle/publishMavenLocal.gradle +++ /dev/null @@ -1,129 +0,0 @@ -apply plugin: 'maven-publish' -apply plugin: 'signing' - -project.afterEvaluate { - task androidSourcesJar(type: Jar) { - from android.sourceSets.main.java.srcDirs - classifier "sources" - } - - publishing { - publications { - release(MavenPublication) { final MavenPublication mavenPublication -> - groupId project.group - artifactId project.name - version project.version - - artifact bundleReleaseAar - artifact androidSourcesJar - - mavenPublication.pom { pom -> - pom.name = projectName - pom.description = projectDescription - pom.url = projectUrl - pom.inceptionYear = projectInceptionYear - pom.scm { scm -> - scm.url = projectScmUrl - scm.connection = projectScmConnection - scm.developerConnection = projectScmDeveloperConnection - } - pom.developers { - developer { - name = projectDeveloperName - email = projectDeveloperEmail - } - } - pom.organization { - name = projectOrganizationName - url = projectOrganizationUrl - } - pom.licenses { - license { - name = projectLicesenseName - url = projectLicesenseUrl - distribution = "repo" - } - } - pom.issueManagement { - system = projectIssueManagementSystem - url = projectIssueManagementUrl - } - pom.ciManagement { - system = projectCiManagementSystem - url = projectCiManagementUrl - } - pom.withXml { - final Node projectNode = asNode() - // List all compile dependencies and write to POM - final Node dependenciesNode = projectNode.appendNode('dependencies') - final compileConfiguration = configurations.getByName('releaseRuntimeClasspath') - compileConfiguration.allDependencies.each { final Dependency dependency -> - final noGroup = dependency.group == null - final noVersion = dependency.version == null - final noName = dependency.name == null - final invalidName = dependency.name == "unspecified" - final invalidDependency = noGroup || noVersion || noName || invalidName - if (invalidDependency) { - // ignore invalid dependencies - return - } - - final dependencyNode = dependenciesNode.appendNode('dependency') - dependencyNode.appendNode('groupId', dependency.group) - dependencyNode.appendNode('artifactId', dependency.name) - dependencyNode.appendNode('version', dependency.version) - def firstFileNameExtension = "jar" - if (dependency instanceof ExternalModuleDependency) { - final dependencyFiles = compileConfiguration.files(dependency) - final firstFile = dependencyFiles.first() - final firstFileName = firstFile.name - firstFileNameExtension = firstFileName.substring(firstFileName.lastIndexOf(".") + 1) - } else if (dependency instanceof ProjectDependency) { - firstFileNameExtension = "aar" - } - if (firstFileNameExtension != "jar") { - dependencyNode.appendNode('type', firstFileNameExtension) - } - - if (!dependency.transitive) { - // If this dependency is transitive, we should force exclude all its dependencies them from the POM - final exclusionNode = dependencyNode.appendNode('exclusions').appendNode('exclusion') - exclusionNode.appendNode('groupId', '*') - exclusionNode.appendNode('artifactId', '*') - } else if (!dependency.properties.excludeRules.empty) { - // Otherwise add specified exclude rules - final exclusionsNode = dependencyNode.appendNode('exclusions') - dependency.properties.excludeRules.each { final ExcludeRule rule -> - final exclusionNode = exclusionsNode.appendNode('exclusion') - exclusionNode.appendNode('groupId', rule.group ?: '*') - exclusionNode.appendNode('artifactId', rule.module ?: '*') - } - } - } - } - - } - } - } - repositories { - maven { - url "$rootProject.buildDir/m2repository" - } - maven { - credentials { - username rootProject.properties['sonatypeUsername'] - password rootProject.properties['sonatypePassword'] - } - if (project.version.endsWith('-SNAPSHOT')) { - url "https://oss.sonatype.org/content/repositories/snapshots/" - } else { - url "https://oss.sonatype.org/service/local/staging/deploy/maven2/" - } - } - } - } - signing { - useGpgCmd() - sign publishing.publications - } -} diff --git a/gradle/versioning.gradle b/gradle/versioning.gradle deleted file mode 100644 index e9715aa..0000000 --- a/gradle/versioning.gradle +++ /dev/null @@ -1,17 +0,0 @@ -import java.text.SimpleDateFormat - -ext { - gitScmVersion = { - final cmd = "git rev-parse --verify --short=7 HEAD" - final proc = cmd.execute([], project.projectDir) - proc.text.trim() - } - buildVersionCode = { - def (major, minor, patch) = version.toString().toLowerCase().tokenize('.') - patch = patch.replaceAll("[^0-9]", "") - - (major, minor, patch) = [major, minor, patch].collect { it.toInteger() } - - (major * 1000000) + (minor * 1000) + (patch); - } -} \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar deleted file mode 100644 index 29953ea..0000000 Binary files a/gradle/wrapper/gradle-wrapper.jar and /dev/null differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties deleted file mode 100644 index d76b502..0000000 --- a/gradle/wrapper/gradle-wrapper.properties +++ /dev/null @@ -1,5 +0,0 @@ -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew deleted file mode 100755 index cccdd3d..0000000 --- a/gradlew +++ /dev/null @@ -1,172 +0,0 @@ -#!/usr/bin/env sh - -############################################################################## -## -## Gradle start up script for UN*X -## -############################################################################## - -# Attempt to set APP_HOME -# Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi -done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null - -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" - -# Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" - -warn () { - echo "$*" -} - -die () { - echo - echo "$*" - echo - exit 1 -} - -# OS specific support (must be 'true' or 'false'). -cygwin=false -msys=false -darwin=false -nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; -esac - -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar - -# Determine the Java command to use to start the JVM. -if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - if [ ! -x "$JAVACMD" ] ; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." - fi -else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." -fi - -# Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi -fi - -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi - -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi - # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" - fi - i=$((i+1)) - done - case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac -fi - -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=$(save "$@") - -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" - -# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong -if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then - cd "$(dirname "$0")" -fi - -exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat deleted file mode 100644 index f955316..0000000 --- a/gradlew.bat +++ /dev/null @@ -1,84 +0,0 @@ -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto init - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega diff --git a/README.md b/index.md similarity index 84% rename from README.md rename to index.md index 5dd3162..73cc8c6 100644 --- a/README.md +++ b/index.md @@ -1,126 +1,128 @@ -FormValidations [![Build Status](https://ci.psdev.de/job/PSDevFormValidations/badge/icon)](https://ci.psdev.de/job/PSDevFormValidations/) [![Coverage](https://sonar.psdev.de/api/project_badges/measure?project=de.psdev.formvalidations&metric=coverage)](https://sonar.psdev.de/dashboard?id=de.psdev.formvalidations) [![Lines of Code](https://sonar.psdev.de/api/project_badges/measure?project=de.psdev.formvalidations&metric=ncloc)](https://sonar.psdev.de/dashboard?id=de.psdev.formvalidations) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/de.psdev.formvalidations/formvalidations/badge.svg)](https://maven-badges.herokuapp.com/maven-central/de.psdev.formvalidations/formvalidations) -=============== - -FormValidations is an open source library to validate forms in Android apps. - -Available validations ---------------------- -* AlphaNumeric - checks if a fields value only contains alpha-numeric characters -* InRange - checks if a fields value is an integer and in a given range (```min < value < max```) -* IsEmail - checks if a fields value is a valid email -* IsNumber - checks if a felds value is a number -* IsPositiveInteger - checks if fields value is an integer and greater than zero (```value > 0```) -* Length - checks if a fields value is a given length (min, max or both) -* NotEmpty - checks if field is not blank - -You can easily create your own validations, just implement the ```de.psdev.formvalidations.validations.Validation``` interface. - -Error handlers --------------- - -* `EditTextErrorHandler` - displays the validation error on the `EditText` using the `setError` method - -You can easily create your own error handlers, just implement the ```de.psdev.formvalidations.FormErrorHandler``` interface. - -Sample usage ------------- - -Create validation form and add some validations -```java -final Form mForm = Form.create(); -mForm.addField(Field.using(mNameEditText).validate(NotEmpty.build())); -mForm.addField(Field.using(mEmailEditText).validate(NotEmpty.build()).validate(IsEmail.build())); -mForm.addField(Field.using(mAgeEditText).validate(InRange.build(0, 120))); -mForm.errorHandler(new EditTextErrorHandler()); -``` - -Check if the form is valid -```java -private void submit() { - if (mForm.isValid()) { - Toast.makeText(this, "Form is valid", Toast.LENGTH_SHORT).show(); - } -} -``` - -Checkout the sample project for the full usage example. - -Download --------- - -Download [the latest Release][1] or grab via Maven: - -```xml - - de.psdev.formvalidations - formvalidations - 1.2.0 - aar - -``` -or Gradle: -```groovy -implementation 'de.psdev.formvalidations:formvalidations:1.2.0' -``` - -Sample ------- - -You can get the latest sample from [Jenkins][2] - -Credits -------- - -This library is based on [z-validations][3] by [Vitaliy Zasadnyy][4]. - -Contributors ------------- - -Thank you to all the contributors of this project, namely: - -- [Cristian Hernandez](https://github.com/PSDev/FormValidations/commits?author=devcodaltec) - -License -------- - - Copyright 2013 Philip Schiffer - - 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. - - This library incorporates code covered by the following terms: - - The MIT License (MIT) - - Copyright (c) 2013 Vitaliy Zasadnyy - - Permission is hereby granted, free of charge, to any person obtaining a copy of - this software and associated documentation files (the "Software"), to deal in - the Software without restriction, including without limitation the rights to - use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - the Software, and to permit persons to whom the Software is furnished to do so, - subject to the following conditions: - - The above copyright notice and this permission notice shall be included in all - copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -[1]: https://github.com/PSDev/FormValidations/releases -[2]: https://ci.psdev.de/job/PSDevFormValidations/lastSuccessfulBuild/artifact/sample/build/outputs/apk/debug/ -[3]: https://github.com/zasadnyy/z-validations -[4]: http://about.me/vitaliy.zasadnyy +FormValidations +=============== + +[![Build Status](https://ci.psdev.de/job/PSDevFormValidations/badge/icon)](https://ci.psdev.de/job/PSDevFormValidations/) [![Coverage](https://sonar.psdev.de/api/project_badges/measure?project=de.psdev.formvalidations&metric=coverage)](https://sonar.psdev.de/dashboard?id=de.psdev.formvalidations) [![Lines of Code](https://sonar.psdev.de/api/project_badges/measure?project=de.psdev.formvalidations&metric=ncloc)](https://sonar.psdev.de/dashboard?id=de.psdev.formvalidations) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/de.psdev.formvalidations/formvalidations/badge.svg)](https://maven-badges.herokuapp.com/maven-central/de.psdev.formvalidations/formvalidations) + +FormValidations is an open source library to validate forms in Android apps. + +Available validations +--------------------- +* AlphaNumeric - checks if a fields value only contains alpha-numeric characters +* InRange - checks if a fields value is an integer and in a given range (```min < value < max```) +* IsEmail - checks if a fields value is a valid email +* IsNumber - checks if a felds value is a number +* IsPositiveInteger - checks if fields value is an integer and greater than zero (```value > 0```) +* Length - checks if a fields value is a given length (min, max or both) +* NotEmpty - checks if field is not blank + +You can easily create your own validations, just implement the ```de.psdev.formvalidations.validations.Validation``` interface. + +Error handlers +-------------- + +* `EditTextErrorHandler` - displays the validation error on the `EditText` using the `setError` method + +You can easily create your own error handlers, just implement the ```de.psdev.formvalidations.FormErrorHandler``` interface. + +Sample usage +------------ + +Create validation form and add some validations +```java +final Form mForm = Form.create(); +mForm.addField(Field.using(mNameEditText).validate(NotEmpty.build())); +mForm.addField(Field.using(mEmailEditText).validate(NotEmpty.build()).validate(IsEmail.build())); +mForm.addField(Field.using(mAgeEditText).validate(InRange.build(0, 120))); +mForm.errorHandler(new EditTextErrorHandler()); +``` + +Check if the form is valid +```java +private void submit() { + if (mForm.isValid()) { + Toast.makeText(this, "Form is valid", Toast.LENGTH_SHORT).show(); + } +} +``` + +Checkout the sample project for the full usage example. + +Download +-------- + +Download [the latest Release][1] or grab via Maven: + +```xml + + de.psdev.formvalidations + formvalidations + 1.2.0 + aar + +``` +or Gradle: +```groovy +implementation 'de.psdev.formvalidations:formvalidations:1.2.0' +``` + +Sample +------ + +You can get the latest sample from [Jenkins][2] + +Credits +------- + +This library is based on [z-validations][3] by [Vitaliy Zasadnyy][4]. + +Contributors +------------ + +Thank you to all the contributors of this project, namely: + +- [Cristian Hernandez](https://github.com/PSDev/FormValidations/commits?author=devcodaltec) + +License +------- + + Copyright 2013 Philip Schiffer + + 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. + + This library incorporates code covered by the following terms: + + The MIT License (MIT) + + Copyright (c) 2013 Vitaliy Zasadnyy + + Permission is hereby granted, free of charge, to any person obtaining a copy of + this software and associated documentation files (the "Software"), to deal in + the Software without restriction, including without limitation the rights to + use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + the Software, and to permit persons to whom the Software is furnished to do so, + subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +[1]: https://github.com/PSDev/FormValidations/releases +[2]: https://ci.psdev.de/job/PSDevFormValidations/lastSuccessfulBuild/artifact/sample/build/outputs/apk/debug/ +[3]: https://github.com/zasadnyy/z-validations +[4]: http://about.me/vitaliy.zasadnyy diff --git a/lint.xml b/lint.xml deleted file mode 100644 index 32b07d4..0000000 --- a/lint.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - \ No newline at end of file diff --git a/sample/.gitignore b/sample/.gitignore deleted file mode 100644 index 796b96d..0000000 --- a/sample/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build diff --git a/sample/build.gradle b/sample/build.gradle deleted file mode 100644 index 55e92a3..0000000 --- a/sample/build.gradle +++ /dev/null @@ -1,42 +0,0 @@ -apply plugin: 'com.android.application' - -android { - compileSdkVersion 28 - buildToolsVersion "28.0.3" - - defaultConfig { - applicationId 'de.psdev.formvalidations.sample' - minSdkVersion 14 - targetSdkVersion 28 - - versionName project.version - versionCode buildVersionCode() - - buildConfigField 'String', 'GIT_SHA', "\"${gitScmVersion()}\"" - } - - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 - } - - lintOptions { - lintConfig rootProject.file('lint.xml') - } - - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' - } - } -} - -dependencies { - implementation project(':formvalidations') - - implementation "com.android.support:appcompat-v7:$appcompatVersion" - - implementation "com.jakewharton:butterknife:$butterknife" - annotationProcessor "com.jakewharton:butterknife-compiler:$butterknife" -} diff --git a/sample/src/main/AndroidManifest.xml b/sample/src/main/AndroidManifest.xml deleted file mode 100644 index cf18702..0000000 --- a/sample/src/main/AndroidManifest.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/sample/src/main/java/de/psdev/formvalidations/sample/SampleActivity.java b/sample/src/main/java/de/psdev/formvalidations/sample/SampleActivity.java deleted file mode 100644 index 8c973ca..0000000 --- a/sample/src/main/java/de/psdev/formvalidations/sample/SampleActivity.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Copyright 2013 Philip Schiffer - * - * 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. - * - * This file incorporates code covered by the following terms: - * - * The MIT License (MIT) - * - * Copyright (c) 2013 Vitaliy Zasadnyy - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package de.psdev.formvalidations.sample; - -import android.app.Activity; -import android.content.Intent; -import android.net.Uri; -import android.os.Bundle; -import android.view.Menu; -import android.view.MenuItem; -import android.view.inputmethod.EditorInfo; -import android.widget.Button; -import android.widget.EditText; -import android.widget.Toast; -import butterknife.BindView; -import butterknife.ButterKnife; -import de.psdev.formvalidations.EditTextErrorHandler; -import de.psdev.formvalidations.Field; -import de.psdev.formvalidations.Form; -import de.psdev.formvalidations.FormUtils; -import de.psdev.formvalidations.validations.InRange; -import de.psdev.formvalidations.validations.IsEmail; -import de.psdev.formvalidations.validations.NotEmpty; - -public class SampleActivity extends Activity { - - private static final String GITHUB_PAGE = "https://github.com/PSDev/FormValidations"; - - // View injections - @BindView(R.id.name) - EditText mName; - @BindView(R.id.email) - EditText mEmail; - @BindView(R.id.age) - EditText mAge; - @BindView(R.id.submit) - Button mSubmit; - - // Form used for validation - private Form mForm; - - @Override - protected void onCreate(final Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_sample); - - initFields(); - initValidationForm(); - initCallbacks(); - } - - @Override - public boolean onCreateOptionsMenu(final Menu menu) { - getMenuInflater().inflate(R.menu.sample, menu); - return true; - } - - @Override - public boolean onOptionsItemSelected(final MenuItem item) { - switch (item.getItemId()) { - case R.id.action_github: - openGitHub(); - return true; - default: - return super.onOptionsItemSelected(item); - } - } - - private void initFields() { - ButterKnife.bind(this); - } - - private void initValidationForm() { - mForm = Form.create(); - mForm.addField(Field.using(mName).validate(NotEmpty.build())); - mForm.addField(Field.using(mEmail).validate(NotEmpty.build()).validate(IsEmail.build())); - mForm.addField(Field.using(mAge).validate(InRange.build(0, 120))); - mForm.errorHandler(new EditTextErrorHandler()); - } - - private void initCallbacks() { - mAge.setOnEditorActionListener((view, actionId, event) -> { - if (actionId == EditorInfo.IME_ACTION_DONE) { - submit(); - return true; - } - return false; - }); - - mSubmit.setOnClickListener(view -> submit()); - } - - private void submit() { - FormUtils.hideKeyboard(this, mAge); - if (mForm.isValid()) { - Toast.makeText(this, R.string.sample_activity_form_is_valid, Toast.LENGTH_LONG).show(); - } - } - - private void openGitHub() { - final Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(GITHUB_PAGE)); - startActivity(browserIntent); - } - -} diff --git a/sample/src/main/res/drawable-hdpi/ic_launcher.png b/sample/src/main/res/drawable-hdpi/ic_launcher.png deleted file mode 100644 index 5457bb6..0000000 Binary files a/sample/src/main/res/drawable-hdpi/ic_launcher.png and /dev/null differ diff --git a/sample/src/main/res/drawable-mdpi/ic_launcher.png b/sample/src/main/res/drawable-mdpi/ic_launcher.png deleted file mode 100644 index fa7e30c..0000000 Binary files a/sample/src/main/res/drawable-mdpi/ic_launcher.png and /dev/null differ diff --git a/sample/src/main/res/drawable-xhdpi/ic_launcher.png b/sample/src/main/res/drawable-xhdpi/ic_launcher.png deleted file mode 100644 index ac2b51c..0000000 Binary files a/sample/src/main/res/drawable-xhdpi/ic_launcher.png and /dev/null differ diff --git a/sample/src/main/res/drawable-xxhdpi/ic_launcher.png b/sample/src/main/res/drawable-xxhdpi/ic_launcher.png deleted file mode 100644 index d8488a0..0000000 Binary files a/sample/src/main/res/drawable-xxhdpi/ic_launcher.png and /dev/null differ diff --git a/sample/src/main/res/drawable-xxxhdpi/ic_launcher.png b/sample/src/main/res/drawable-xxxhdpi/ic_launcher.png deleted file mode 100644 index cf53c7f..0000000 Binary files a/sample/src/main/res/drawable-xxxhdpi/ic_launcher.png and /dev/null differ diff --git a/sample/src/main/res/layout/activity_sample.xml b/sample/src/main/res/layout/activity_sample.xml deleted file mode 100644 index 8503f2a..0000000 --- a/sample/src/main/res/layout/activity_sample.xml +++ /dev/null @@ -1,106 +0,0 @@ - - - - - - - - - - - -