Skip to content

Commit

Permalink
init commit 3.10
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonas committed Mar 20, 2017
1 parent 495cd0d commit 3d2a29c
Show file tree
Hide file tree
Showing 40 changed files with 574 additions and 526 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ Available settings:
“ANALOG_METER”
“DIGITAL_METER”
“BARCODE”
“ANYLINE_OCR”
“MRZ”
```
### onResult Function
Expand Down
8 changes: 1 addition & 7 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ buildscript {
}
}

repositories {
//add the anyline maven repo
maven { url 'https://anylinesdk.blob.core.windows.net/maven/'}
}


allprojects {
repositories {
jcenter()
Expand Down Expand Up @@ -63,7 +57,7 @@ repositories {
dependencies {
compile fileTree(dir: "libs", include: ["*.jar"])
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'io.anyline:anylinesdk:3.9.0@aar'
compile 'io.anyline:anylinesdk:3.10.0@aar'
compile 'com.google.android.gms:play-services-vision:10.0.1'
compile 'com.android.support:design:25.1.0'
compile "com.facebook.react:react-native:+" // From node_modules
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@

import android.app.Activity;
import android.content.Intent;
import android.graphics.PointF;
import android.os.Bundle;
import android.util.Log;
import android.view.WindowManager;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.List;

import at.nineyards.anyline.camera.CameraController;
import at.nineyards.anyline.camera.CameraOpenListener;

Expand Down Expand Up @@ -79,5 +85,39 @@ public void onBackPressed() {
super.onBackPressed();
}

protected String jsonForOutline(List<PointF> pointList) {

JSONObject upLeft = new JSONObject();
JSONObject upRight = new JSONObject();
JSONObject downRight = new JSONObject();
JSONObject downLeft = new JSONObject();
JSONObject outline = new JSONObject();

try {
upLeft.put("x", pointList.get(0).x);
upLeft.put("y", pointList.get(0).y);

upRight.put("x", pointList.get(1).x);
upRight.put("y", pointList.get(1).y);

downRight.put("x", pointList.get(2).x);
downRight.put("y", pointList.get(2).y);

downLeft.put("x", pointList.get(3).x);
downLeft.put("y", pointList.get(3).y);

outline.put("upLeft", upLeft);
outline.put("upRight", upRight);
outline.put("downRight", downRight);
outline.put("downLeft", downLeft);


} catch (JSONException e) {
Log.d(TAG, e.toString());
e.printStackTrace();
}

return outline.toString();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@
import java.util.List;
import java.util.UUID;

import at.nineyards.anyline.modules.ocr.AnylineOcrResultListener;
import at.nineyards.anyline.camera.AnylineViewConfig;
import at.nineyards.anyline.modules.ocr.AnylineOcrConfig;
import at.nineyards.anyline.modules.ocr.AnylineOcrError;
import at.nineyards.anyline.modules.ocr.AnylineOcrListener;
import at.nineyards.anyline.modules.ocr.AnylineOcrResult;
import at.nineyards.anyline.modules.ocr.AnylineOcrScanView;
import at.nineyards.anyline.util.AssetUtil;
Expand Down Expand Up @@ -114,27 +113,19 @@ protected void onPause() {
private void initAnyline() {
anylineOcrScanView.setCameraOpenListener(this);

anylineOcrScanView.initAnyline(licenseKey, new AnylineOcrListener() {
@Override
public void onReport(String identifier, Object value) {
}

@Override
public boolean onTextOutlineDetected(List<PointF> list) {
return !drawTextOutline;
}
anylineOcrScanView.initAnyline(licenseKey, new AnylineOcrResultListener() {

@Override
public void onResult(AnylineOcrResult result) {

JSONObject jsonResult = new JSONObject();

try {
jsonResult.put("text", result.getText().trim());
jsonResult.put("text", result.getResult().trim());

File imageFile = TempFileUtil.createTempFileCheckCache(AnylineOcrActivity.this,
UUID.randomUUID().toString(), ".jpg");
result.getImage().save(imageFile, 90);
result.getCutoutImage().save(imageFile, 90);
jsonResult.put("imagePath", imageFile.getAbsolutePath());

} catch (IOException e) {
Expand All @@ -154,9 +145,6 @@ public void onResult(AnylineOcrResult result) {
}
}

@Override
public void onAbortRun(AnylineOcrError code, String message) {
}
});

anylineOcrScanView.getAnylineController().setWorkerThreadUncaughtExceptionHandler(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class AnylineSDKPlugin extends ReactContextBaseJavaModule implements ResultRepor
private JSONObject configObject;
private ReactApplicationContext reactContext;
private String license;
private String options;
private JSONObject options;
private Callback onResultCallback;
private Callback onErrorCallback;
private ReactInstanceManager mReactInstanceManager;
Expand Down Expand Up @@ -101,15 +101,19 @@ private void scan(Class<?> activityToStart, String config, String scanMode, int

try {
configObject = new JSONObject(config);

//Hacky -> force cancelOnResult = true
options = configObject.getJSONObject("options");
options.put("cancelOnResult", true);

license = configObject.get("license").toString();
options = configObject.get("options").toString();

} catch (JSONException e) {
onErrorCallback.invoke("JSON ERROR: " + e);
}

intent.putExtra(EXTRA_LICENSE_KEY, license);
intent.putExtra(EXTRA_CONFIG_JSON, options);
intent.putExtra(EXTRA_CONFIG_JSON, options.toString());

//Check if OCR
try {
Expand All @@ -131,27 +135,6 @@ private void scan(Class<?> activityToStart, String config, String scanMode, int
@Override
public void onResult(Object result, boolean isFinalResult) {
if (result instanceof JSONObject) {
try {
//ImagePath as Base64
String imagePath = ((JSONObject) result).getString("imagePath");
Bitmap bm = BitmapFactory.decodeFile(imagePath);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.JPEG, 100, baos); //bm is the bitmap object
byte[] b = baos.toByteArray();
String encodedImage = Base64.encodeToString(b, Base64.DEFAULT);
((JSONObject) result).put("cutoutBase64", encodedImage);

//FullImagePath as Base64
String fullImagePath = ((JSONObject) result).getString("fullImagePath");
Bitmap bmFull = BitmapFactory.decodeFile(fullImagePath);
ByteArrayOutputStream baosFull = new ByteArrayOutputStream();
bmFull.compress(Bitmap.CompressFormat.JPEG, 100, baosFull); //bm is the bitmap object
byte[] bFull = baosFull.toByteArray();
String encodedImageFull = Base64.encodeToString(bFull, Base64.DEFAULT);
((JSONObject) result).put("fullImageBase64", encodedImageFull);
} catch (JSONException e) {

}
onResultCallback.invoke(result.toString());
} else if (result instanceof JSONArray) {
onResultCallback.invoke(result.toString());
Expand All @@ -167,7 +150,7 @@ public void onError(String error) {
}

@Override
public void onCancel(){
public void onCancel() {
onErrorCallback.invoke("Canceled");
}
}
19 changes: 15 additions & 4 deletions android/src/main/java/com/anyline/reactnative/BarcodeActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import at.nineyards.anyline.camera.AnylineViewConfig;
import at.nineyards.anyline.models.AnylineImage;
import at.nineyards.anyline.modules.barcode.BarcodeResult;
import at.nineyards.anyline.modules.barcode.BarcodeResultListener;
import at.nineyards.anyline.modules.barcode.BarcodeScanView;
import at.nineyards.anyline.util.TempFileUtil;
Expand Down Expand Up @@ -66,20 +67,30 @@ private void initAnyline() {

barcodeScanView.initAnyline(licenseKey, new BarcodeResultListener() {
@Override
public void onResult(String result, BarcodeScanView.BarcodeFormat format, AnylineImage resultImage) {
public void onResult(BarcodeResult result) {


JSONObject jsonResult = new JSONObject();
try {

jsonResult.put("value", result);
jsonResult.put("format", format.toString());
jsonResult.put("value", result.getResult());
jsonResult.put("format", result.getBarcodeFormat());
jsonResult.put("outline", jsonForOutline(result.getOutline()));
jsonResult.put("confidence", result.getConfidence());


File imageFile = TempFileUtil.createTempFileCheckCache(BarcodeActivity.this,
UUID.randomUUID().toString(), ".jpg");

resultImage.save(imageFile, 90);
result.getCutoutImage().save(imageFile, 90);
jsonResult.put("imagePath", imageFile.getAbsolutePath());

imageFile = TempFileUtil.createTempFileCheckCache(BarcodeActivity.this,
UUID.randomUUID().toString(), ".jpg");
result.getFullImage().save(imageFile, 90);
jsonResult.put("fullImagePath", imageFile.getAbsolutePath());


} catch (IOException e) {
Log.e(TAG, "Image file could not be saved.", e);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import at.nineyards.anyline.camera.CameraController;
import at.nineyards.anyline.camera.CameraOpenListener;
import at.nineyards.anyline.models.AnylineImage;
import at.nineyards.anyline.modules.document.DocumentResult;
import at.nineyards.anyline.modules.document.DocumentResultListener;
import at.nineyards.anyline.modules.document.DocumentScanView;

Expand Down Expand Up @@ -109,13 +110,16 @@ protected void onCreate(Bundle savedInstanceState) {
// initialize Anyline with the license key and a Listener that is called if a result is found
documentScanView.initAnyline(licenseKey, new DocumentResultListener() {
@Override
public void onResult(AnylineImage transformedImage, AnylineImage fullFrame, List<PointF> documentOutline) {
public void onResult(DocumentResult documentResult) {

// handle the result document images here
if (progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss();
}

AnylineImage transformedImage = documentResult.getResult();
AnylineImage fullFrame = documentResult.getFullImage();

imageViewResult.setImageBitmap(Bitmap.createScaledBitmap(transformedImage.getBitmap(), 100, 160, false));

/**
Expand Down Expand Up @@ -152,6 +156,9 @@ public void onResult(AnylineImage transformedImage, AnylineImage fullFrame, List
JSONObject jsonResult = new JSONObject();
try {
jsonResult.put("imagePath", outFile.getAbsolutePath());
jsonResult.put("outline", jsonForOutline(documentResult.getOutline()));
jsonResult.put("confidence", documentResult.getConfidence());

} catch (Exception jsonException) {
//should not be possible
Log.e(TAG, "Error while putting image path to json.", jsonException);
Expand Down
26 changes: 16 additions & 10 deletions android/src/main/java/com/anyline/reactnative/EnergyActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import android.widget.RadioGroup;
import android.widget.RelativeLayout;

import com.google.android.gms.vision.barcode.Barcode;

import org.json.JSONException;
import org.json.JSONObject;

Expand All @@ -27,10 +29,12 @@
import java.util.ArrayList;
import java.util.UUID;

import at.nineyards.anyline.AnylineDebugListener;
import at.nineyards.anyline.camera.AnylineViewConfig;
import at.nineyards.anyline.camera.CameraController;
import at.nineyards.anyline.models.AnylineImage;
import at.nineyards.anyline.core.RunFailure;
import at.nineyards.anyline.modules.barcode.NativeBarcodeResultListener;
import at.nineyards.anyline.modules.energy.EnergyResult;
import at.nineyards.anyline.modules.energy.EnergyResultListener;
import at.nineyards.anyline.modules.energy.EnergyScanView;
import at.nineyards.anyline.util.TempFileUtil;
Expand Down Expand Up @@ -70,7 +74,7 @@ protected void onCreate(Bundle savedInstanceState) {

energyScanView.enableBarcodeDetection(true, new NativeBarcodeResultListener() {
@Override
public void onBarcodesReceived(SparseArray<com.google.android.gms.vision.barcode.Barcode> sparseArray) {
public void onBarcodesReceived(SparseArray<Barcode> sparseArray) {

if (sparseArray.size() > 0) {
lastDetectedBarcodeValue = sparseArray.valueAt(0).displayValue;
Expand Down Expand Up @@ -101,12 +105,11 @@ public void onBarcodesReceived(SparseArray<com.google.android.gms.vision.barcode
radioGroup = new RadioGroup(this);
radioGroup.setOrientation(RadioGroup.VERTICAL);

int currentApiVersion = android.os.Build.VERSION.SDK_INT;
for (int i = 0; i < titles.size(); i++) {
radioButtons[i] = new RadioButton(this);
radioButtons[i].setText(titles.get(i));

if (currentApiVersion >= Build.VERSION_CODES.LOLLIPOP) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
radioButtons[i].setButtonTintList(ColorStateList.valueOf(anylineUIConfig.getTintColor()));
}

Expand Down Expand Up @@ -181,11 +184,11 @@ private void initAnyline() {
energyScanView.initAnyline(licenseKey, new EnergyResultListener() {

@Override
public void onResult(EnergyScanView.ScanMode scanMode, String result,
AnylineImage resultImage, AnylineImage fullImage) {
public void onResult(EnergyResult energyResult) {


JSONObject jsonResult = new JSONObject();
EnergyScanView.ScanMode scanMode = energyResult.getScanMode();

try {
switch (scanMode) {
Expand Down Expand Up @@ -213,18 +216,21 @@ public void onResult(EnergyScanView.ScanMode scanMode, String result,
}

jsonResult.put("scanMode", scanMode.toString());
jsonResult.put("reading", result);
jsonResult.put("reading", energyResult.getResult());
jsonResult.put("barcodeResult", lastDetectedBarcodeValue);
jsonResult.put("outline", jsonForOutline(energyResult.getOutline()));
jsonResult.put("confidence", energyResult.getConfidence());

File imageFile = TempFileUtil.createTempFileCheckCache(EnergyActivity.this,
UUID.randomUUID().toString(), ".jpg");

resultImage.save(imageFile, 90);
energyResult.getCutoutImage().save(imageFile, 90);
jsonResult.put("imagePath", imageFile.getAbsolutePath());

if (fullImage != null) {
if (energyResult.getFullImage() != null) {
imageFile = TempFileUtil.createTempFileCheckCache(EnergyActivity.this,
UUID.randomUUID().toString(), ".jpg");
fullImage.save(imageFile, 90);
energyResult.getFullImage().save(imageFile, 90);
jsonResult.put("fullImagePath", imageFile.getAbsolutePath());
}

Expand Down
Loading

0 comments on commit 3d2a29c

Please sign in to comment.