Skip to content

Commit

Permalink
updated anyline 3.11
Browse files Browse the repository at this point in the history
added nativeBarcodeScanning Option
  • Loading branch information
Jonas committed Apr 12, 2017
1 parent 3ccb922 commit 7520efa
Show file tree
Hide file tree
Showing 24 changed files with 326 additions and 147 deletions.
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,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.10.0@aar'
compile 'io.anyline:anylinesdk:3.11.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
28 changes: 15 additions & 13 deletions android/src/main/java/com/anyline/reactnative/AnylineSDKPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Base64;

import com.facebook.react.ReactInstanceManager;
import com.facebook.react.bridge.Callback;
Expand All @@ -20,7 +17,6 @@
import org.json.JSONException;
import org.json.JSONObject;

import java.io.ByteArrayOutputStream;

class AnylineSDKPlugin extends ReactContextBaseJavaModule implements ResultReporter.OnResultListener {

Expand All @@ -30,6 +26,7 @@ class AnylineSDKPlugin extends ReactContextBaseJavaModule implements ResultRepor
public static final String EXTRA_SCAN_MODE = "EXTRA_SCAN_MODE";
public static final String EXTRA_ERROR_MESSAGE = "EXTRA_ERROR_MESSAGE";
public static final String EXTRA_OCR_CONFIG_JSON = "EXTRA_OCR_CONFIG_JSON";
public static final String EXTRA_ENABLE_BARCODE_SCANNING = "EXTRA_ENABLE_BARCODE_SCANNING";

public static final int RESULT_CANCELED = 0;
public static final int RESULT_OK = 1;
Expand All @@ -38,10 +35,11 @@ class AnylineSDKPlugin extends ReactContextBaseJavaModule implements ResultRepor

public static final int DIGITAL_METER = 3;
public static final int ANALOG_METER = 4;
public static final int ANYLINE_OCR = 5;
public static final int BARCODE = 6;
public static final int ANYLINE_MRZ = 7;
public static final int ANYLINE_DOCUMENT = 8;
public static final int AUTO_ANALOG_DIGITAL_METER = 5;
public static final int ANYLINE_OCR = 6;
public static final int BARCODE = 7;
public static final int ANYLINE_MRZ = 8;
public static final int ANYLINE_DOCUMENT = 9;


private JSONObject configObject;
Expand Down Expand Up @@ -69,6 +67,9 @@ public void setupScanViewWithConfigJson(String config, String scanMode, Callback


switch (scanMode) {
case "AUTO_ANALOG_DIGITAL_METER":
scan(EnergyActivity.class, config, scanMode, AUTO_ANALOG_DIGITAL_METER);
break;
case "DIGITAL_METER":
scan(EnergyActivity.class, config, scanMode, DIGITAL_METER);
break;
Expand Down Expand Up @@ -96,17 +97,18 @@ public void setupScanViewWithConfigJson(String config, String scanMode, Callback
private void scan(Class<?> activityToStart, String config, String scanMode, int requestCode) {

Intent intent = new Intent(getCurrentActivity(), activityToStart);
Activity currentActivity = getCurrentActivity();


try {
configObject = new JSONObject(config);

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

license = configObject.get("license").toString();
if (configObject.has("nativeBarcodeEnabled")) {
intent.putExtra(EXTRA_ENABLE_BARCODE_SCANNING, configObject.getBoolean("nativeBarcodeEnabled"));
}

} catch (JSONException e) {
onErrorCallback.invoke("JSON ERROR: " + e);
Expand All @@ -119,7 +121,7 @@ private void scan(Class<?> activityToStart, String config, String scanMode, int
try {
intent.putExtra(EXTRA_OCR_CONFIG_JSON, configObject.get("ocr").toString());
} catch (JSONException e) {

e.printStackTrace();
}

if (scanMode != null) {
Expand All @@ -128,7 +130,7 @@ private void scan(Class<?> activityToStart, String config, String scanMode, int
ResultReporter.setListener(this);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

currentActivity.startActivityForResult(intent, requestCode);
reactContext.startActivityForResult(intent, requestCode, intent.getExtras());

}

Expand Down
48 changes: 26 additions & 22 deletions android/src/main/java/com/anyline/reactnative/EnergyActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@
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.core.RunFailure;
import at.nineyards.anyline.modules.barcode.NativeBarcodeResultListener;
import at.nineyards.anyline.modules.energy.EnergyResult;
import at.nineyards.anyline.modules.energy.EnergyResultListener;
Expand All @@ -52,6 +50,7 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

String scanModeString = getIntent().getStringExtra(AnylineSDKPlugin.EXTRA_SCAN_MODE);
Boolean enableBarcodeScanning = getIntent().getBooleanExtra(AnylineSDKPlugin.EXTRA_ENABLE_BARCODE_SCANNING, false);

energyScanView = new EnergyScanView(this, null);

Expand All @@ -72,15 +71,19 @@ protected void onCreate(Bundle savedInstanceState) {

anylineUIConfig = new AnylineUIConfig(this, jsonObject);

energyScanView.enableBarcodeDetection(true, new NativeBarcodeResultListener() {
@Override
public void onBarcodesReceived(SparseArray<Barcode> sparseArray) {
Log.d(TAG, enableBarcodeScanning.toString());
if (enableBarcodeScanning) {
energyScanView.enableBarcodeDetection(true, new NativeBarcodeResultListener() {
@Override
public void onBarcodesReceived(SparseArray<Barcode> sparseArray) {

if (sparseArray.size() > 0) {
lastDetectedBarcodeValue = sparseArray.valueAt(0).displayValue;
if (sparseArray.size() > 0) {
lastDetectedBarcodeValue = sparseArray.valueAt(0).displayValue;
}
}
}
});
});
}

// Creating a new RelativeLayout
final RelativeLayout relativeLayout = new RelativeLayout(this);

Expand Down Expand Up @@ -117,19 +120,20 @@ public void onBarcodesReceived(SparseArray<Barcode> sparseArray) {
}

Integer modeIndex = modes.indexOf(scanModeString);
RadioButton button = radioButtons[modeIndex];
button.setChecked(true);

radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
View button = group.findViewById(checkedId);
String mode = modes.get(group.indexOfChild(button));
energyScanView.setScanMode(EnergyScanView.ScanMode.valueOf(mode));
energyScanView.startScanning();
}
});

if (modeIndex >= 0) {
RadioButton button = radioButtons[modeIndex];
button.setChecked(true);

radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
View button = group.findViewById(checkedId);
String mode = modes.get(group.indexOfChild(button));
energyScanView.setScanMode(EnergyScanView.ScanMode.valueOf(mode));
energyScanView.startScanning();
}
});
}
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
Expand Down
52 changes: 52 additions & 0 deletions android/src/main/res/layout/activity_scan_document.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" xmlns:app="http://schemas.android.com/apk/res-auto">

<at.nineyards.anyline.modules.document.DocumentScanView
android:id="@+id/document_scan_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:api_2_enabled="false"
/>

<ImageView
android:id="@+id/image_result"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:adjustViewBounds="true"/>

<ImageView
android:id="@+id/full_image"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:adjustViewBounds="true"/>

<FrameLayout
android:id="@+id/error_message_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:visibility="gone"
tools:visibility="visible"
>

<TextView
android:id="@+id/error_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="16dp"
android:textColor="@android:color/primary_text_dark"
android:gravity="center"
android:layout_margin="24dp"
android:layout_gravity="center"
android:background="@android:color/background_dark"
tools:text="Error: image to dark! but I am very very very long and you can not read me" />

</FrameLayout>
</RelativeLayout>
33 changes: 33 additions & 0 deletions android/src/main/res/values/anyline_sdk_plugin_strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<resources>
<string name="error_unkown_scan_mode">Unkown scan mode: </string>
<string name="error_invalid_json_data">Config json is invalid.</string>
<string name="error_invalid_segment_config">Semgent config not valid. Must have equal amount of titles and modes.</string>
<string name="error_accessing_camera">Error while accessing camera.</string>
<string name="error_licence_invalid">Error: Anyline license invalid.</string>
<string name="error_occured">An error occured.</string>

<string name="document_advanced_outline_detection">Advanced Outline Detection</string>
<string name="document_fast_outline_detection">Fast Outline Detection</string>
<string name="document_error_not_sharp">Document is not sharp. Please hold the camera steadily and ensure the document is in focus</string>
<string name="document_error_skew_too_high">Document is skewed. Place the camera directly above the document</string>
<string name="document_error_outline_not_found">Could not detect document outline</string>

<string name="document_error_glare_detected">Please remove the glare</string>
<string name="document_error_too_dark">The image is too dark. Please ensure there is enough light</string>
<string name="document_error_unknown">Unknown Failure</string>
<string name="document_picture_error">Error scanning full document:\n</string>
<string name="document_preview_success">Scanning full document. Please hold still</string>
<string name="document_picture_success">Document scanned successfully</string>
<string name="document_using_fast_mode">Switched to fast detection mode</string>
<string name="document_using_advanced_mode">Switched to advanced detection mode</string>
<string name="document_processing_picture_header">Processing</string>
<string name="document_processing_picture">Processing the Picture. Please wait</string>
<string name="document_error_shake">Shake detected</string>
<string name="document_error_closer">Come closer</string>
<string name="document_error_format">Unrecognised format</string>
<string name="document_image_saved_to">Image saved to</string>

<string name="document_processing">Processing</string>
<string name="document_processing_picture_please_wait">Processing the picture. Please wait.</string>

</resources>
6 changes: 6 additions & 0 deletions android/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="scrabble_green">#327466</color>
<color name="anyline_blue_darker">#AA007ACC</color>
<color name="anyline_red">#AAE53F16</color>
</resources>
10 changes: 10 additions & 0 deletions android/src/main/res/values/com_crashlytics_export_strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<resources xmlns:tools="http://schemas.android.com/tools">
<!--
This file is automatically generated by Crashlytics to uniquely
identify individual builds of your Android application.
Do NOT modify, delete, or commit to source control!
-->
<string tools:ignore="UnusedResources,TypographyDashes" name="com.crashlytics.android.build_id" translatable="false">2ca91258-5574-41ce-8686-74008a61f765</string>
</resources>
4 changes: 4 additions & 0 deletions android/src/main/res/values/integers.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer name="error_message_delay">2000</integer>
</resources>
18 changes: 10 additions & 8 deletions example/Anyline/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@ def enableSeparateBuildPerCPUArchitecture = false
def enableProguardInReleaseBuilds = false

android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
compileSdkVersion 25
buildToolsVersion "23.0.2"

defaultConfig {
applicationId "com.anyline-ocr-react-native-module"
minSdkVersion 16
targetSdkVersion 22
applicationId "com.anyline"
minSdkVersion 17
targetSdkVersion 23
versionCode 1
versionName "1.0"
ndk {
Expand All @@ -107,7 +107,6 @@ android {
buildTypes {
release {
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
// applicationVariants are e.g. debug, release
Expand All @@ -125,14 +124,17 @@ android {
}
}

android.packagingOptions {
pickFirst('lib/*/libgnustl_shared.so')
}

dependencies {
compile project(':react-native-vector-icons')
compile project(':react-native-permissions')
compile project(':react-native-android-permissions')
compile project(':anyline-ocr-react-native-module')
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:23.0.1"
compile "com.facebook.react:react-native:+" // From node_modules
compile 'com.android.support:appcompat-v7:23.0.1'
}

// Run this once to be able to run the application with BUCK
Expand Down
48 changes: 21 additions & 27 deletions example/Anyline/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,32 +1,26 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.anyline-ocr-react-native-module"
android:versionCode="1"
android:versionName="1.0">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="22" />

package="com.anyline"
android:versionCode="1"
android:versionName="1.0">
<uses-permission android:name="android.permission.VIBRATE" />
<application
android:name=".MainApplication"
android:allowBackup="true"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
android:name=".MainApplication"
android:allowBackup="true"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:theme="@style/AppTheme"
android:screenOrientation="portrait">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity"/>
</application>

</manifest>
Loading

0 comments on commit 7520efa

Please sign in to comment.