Skip to content

Commit

Permalink
Add EAN13 validator
Browse files Browse the repository at this point in the history
  • Loading branch information
itchix committed Jun 30, 2015
1 parent 28cbf7c commit 0016692
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
7 changes: 5 additions & 2 deletions app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@
</content>
<orderEntry type="jdk" jdkName="Android API 21 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="commons-validator-1.4.0" level="project" />
<orderEntry type="library" exported="" name="commons-beanutils-1.8.3" level="project" />
<orderEntry type="library" exported="" name="support-annotations-22.2.0" level="project" />
<orderEntry type="library" exported="" name="recyclerview-v7-22.2.0" level="project" />
<orderEntry type="library" exported="" name="zxing-1.7.2" level="project" />
Expand All @@ -107,11 +109,12 @@
<orderEntry type="library" exported="" name="androidasync-2.1.6" level="project" />
<orderEntry type="library" exported="" name="jackson-core-2.5.0" level="project" />
<orderEntry type="library" exported="" name="core-1.7.2" level="project" />
<orderEntry type="library" exported="" name="ion-2.1.6" level="project" />
<orderEntry type="library" exported="" name="support-v4-22.2.0" level="project" />
<orderEntry type="library" exported="" name="ion-2.1.6" level="project" />
<orderEntry type="library" exported="" name="sugar-1.3.1" level="project" />
<orderEntry type="library" exported="" name="library-2.4.0" level="project" />
<orderEntry type="library" exported="" name="commons-digester-1.8" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-22.2.0" level="project" />
<orderEntry type="library" exported="" name="library-2.4.0" level="project" />
<orderEntry type="library" exported="" name="gson-2.3" level="project" />
<orderEntry type="library" exported="" name="jsoup-1.8.2" level="project" />
<orderEntry type="library" exported="" name="jackson-databind-2.5.0" level="project" />
Expand Down
6 changes: 4 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "openfoodfacts.github.scrachx.openfood"
minSdkVersion 15
targetSdkVersion 21
versionCode 4
versionName "0.1.3"
versionCode 5
versionName "0.1.4"
}
buildTypes {
release {
Expand Down Expand Up @@ -53,6 +53,8 @@ dependencies {

compile files('libs/jackson-core-2.5.0.jar')

compile 'commons-validator:commons-validator:1.4.0'

compile 'net.steamcrafted:load-toast:1.0.6'

compile 'me.dm7.barcodescanner:zxing:1.7.2'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package openfoodfacts.github.scrachx.openfood.fragments;

import android.app.Activity;

import android.app.Fragment;
import android.content.Intent;
import org.apache.commons.validator.routines.checkdigit.EAN13CheckDigit;

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand Down Expand Up @@ -33,7 +35,11 @@ public void onClick(View v){
if(barCode_text.getText().toString().isEmpty()){
Toast.makeText(getActivity(), getResources().getString(R.string.txtBarcodeRequire), Toast.LENGTH_LONG).show();
}else{
goToProduct();
if(EAN13CheckDigit.EAN13_CHECK_DIGIT.isValid(barCode_text.getText().toString()) && (!barCode_text.getText().toString().substring(0,3).contains("977") || !barCode_text.getText().toString().substring(0,3).contains("978") || !barCode_text.getText().toString().substring(0,3).contains("979"))) {
goToProduct();
}else{
Toast.makeText(getActivity(), getResources().getString(R.string.txtBarcodeNotValid), Toast.LENGTH_LONG).show();
}
}
}
});
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,5 @@
<string name="txtAllsent">Produits envoy茅s</string>
<string name="txtAbout">Les photos que vous envoyez sont publi茅es sous la licence libre Creative Commons Attribution et partage 脿 l\'identitque.</string>
<string name="txtPalm">Le produit ne contient pas d\'huile de palme</string>
<string name="txtBarcodeNotValid">Code barre non valide</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
<string name="txtAbout">The pictures you send are published under the free licence Creative Commons Attribution and ShareAlike.</string>
<string name="txtAllsent">Products sent</string>
<string name="txtPalm">The product does not contain any palm oil</string>
<string name="txtBarcodeNotValid">Barcode not valid</string>

<style name="DefaultButtonText">
<item name="android:layout_width">fill_parent</item>
Expand Down

0 comments on commit 0016692

Please sign in to comment.